<s> import time <EOL> from twisted . internet . protocol import DatagramProtocol , ClientCreator <EOL> from twisted . internet import reactor , task , defer <EOL> from twisted . application import service , internet <EOL> from twisted . web . client import getPage <EOL> from tensor . protocol . sflow import protocol <EOL> from tensor . protocol . sflow . protocol import flows , counters <EOL> class DatagramReceiver ( DatagramProtocol ) : <EOL> """<STR_LIT>""" <EOL> def datagramReceived ( self , data , ( host , port ) ) : <EOL> sflow = protocol . Sflow ( data , host ) <EOL> for sample in sflow . samples : <EOL> if isinstance ( sample , protocol . FlowSample ) : <EOL> self . process_flow_sample ( sflow , sample ) <EOL> if isinstance ( sample , protocol . CounterSample ) : <EOL> self . process_counter_sample ( sflow , sample ) <EOL> def process_flow_sample ( self , sflow , flow ) : <EOL> for k , v in flow . flows . items ( ) : <EOL> if isinstance ( v , flows . HeaderSample ) and v . frame : <EOL> reactor . callLater ( <NUM_LIT:0> , self . receive_flow , flow , v . frame , sflow . host ) <EOL> def process_counter_sample ( self , sflow , counter ) : <EOL> for k , v in counter . counters . items ( ) : <EOL> if isinstance ( v , counters . InterfaceCounters ) : <EOL> reactor . callLater ( <NUM_LIT:0> , self . receive_counter , v , sflow . host ) <EOL> elif isinstance ( v , counters . HostCounters ) : <EOL> reactor . callLater ( <NUM_LIT:0> , self . receive_host_counter , v ) <EOL> def receive_flow ( self , flow , sample ) : <EOL> pass <EOL> def receive_counter ( self , counter ) : <EOL> pass <EOL> def receive_host_counter ( self , counter ) : <EOL> pass </s>
