Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/nfstream/plugin.py: 75%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

8 statements  

1""" 

2------------------------------------------------------------------------------------------------------------------------ 

3plugin.py 

4Copyright (C) 2019-22 - NFStream Developers 

5This file is part of NFStream, a Flexible Network Data Analysis Framework (https://www.nfstream.org/). 

6NFStream is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 

7License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later 

8version. 

9NFStream is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 

10of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 

11You should have received a copy of the GNU Lesser General Public License along with NFStream. 

12If not, see <http://www.gnu.org/licenses/>. 

13------------------------------------------------------------------------------------------------------------------------ 

14""" 

15 

16 

17class NFPlugin(object): 

18 """NFPlugin class: Main entry point to extend NFStream""" 

19 

20 def __init__(self, **kwargs): 

21 """ 

22 NFPlugin Parameters: 

23 kwargs : user defined named arguments that will be stored as Plugin attributes 

24 """ 

25 for key, value in kwargs.items(): 

26 setattr(self, key, value) 

27 

28 def on_init(self, packet, flow): 

29 """ 

30 on_init(self, obs, flow): Method called at flow creation. 

31 You must initiate your udps values if you plan to compute ones. 

32 Example: ------------------------------------------------------- 

33 flow.udps.magic_message = "NO" 

34 if packet.raw_size == 40: 

35 flow.udps.packet_40_count = 1 

36 else: 

37 flow.udps.packet_40_count = 0 

38 ---------------------------------------------------------------- 

39 """ 

40 

41 def on_update(self, packet, flow): 

42 """ 

43 on_update(self, obs, flow): Method called to update each flow with its belonging packet. 

44 Example: ------------------------------------------------------- 

45 if packet.raw_size == 40: 

46 flow.udps.packet_40_count += 1 

47 ---------------------------------------------------------------- 

48 """ 

49 

50 def on_expire(self, flow): 

51 """ 

52 on_expire(self, flow): Method called at flow expiration. 

53 Example: ------------------------------------------------------- 

54 if flow.udps.packet_40_count >= 10: 

55 flow.udps.magic_message = "YES" 

56 ---------------------------------------------------------------- 

57 """ 

58 

59 def cleanup(self): 

60 """ 

61 cleanup(self): Method called for plugin cleanup. 

62 Example: ------------------------------------------------------- 

63 del self.large_dict_passed_as_plugin_attribute 

64 ---------------------------------------------------------------- 

65 """