--netflow_collector.py--import eventlet
import socketfrom ryu.base import app_managerfrom ryu.controller import 
eventfrom ryu.lib.xflow import netflowfrom ryu.lib import hub

NETFLOW_EV_DISPATCHER='netflow'BUFSIZE = 65535  # Should we use flexible length?

class EventNetFlow(event.EventBase):    def __init__(self, msg, addrport):      
  super(EventNetFlow, self).__init__()        self.msg = msg        self.addr, 
self.port = addrport

class NetFlowCollector(app_manager.RyuApp):    def __init__(self):        
super(NetFlowCollector, self).__init__()        self.name = 'netflow_collector' 
       self._start_recv()
    def start(self):        return self.thread
    def _recv_loop(self):        print 'Mpes'        while True:            
self.sock.setblocking(True)            (data, addrport) = 
self.sock.recvfrom(BUFSIZE)            msg = netflow.NetFlow.parser(data)       
     if msg:                    self.send_event_to_observers(EventNetFlow(msg, 
addrport))
    def _start_recv(self):        self.sock = socket.socket(socket.AF_INET, 
socket.SOCK_DGRAM)        self.sock.bind(('20.1.1.1',                        
9999))        self.thread=hub.spawn_after(1,self._recv_loop)
#I have used default addresses.
--netflow_dumper.py--import loggingimport socketimport struct
from ryu.lib import hubfrom ryu.base import app_managerfrom 
ryu.controller.handler import set_ev_clsfrom ryu.lib.xflow import 
netflow_collector
LOG = logging.getLogger('ryu.app.netflow_dumper')

class NetFlowDumper(app_manager.RyuApp):    _CONTEXTS = {        
'netflow_collector': netflow_collector.NetFlowCollector    }
    def __init__(self, *args, **kwargs):        super(NetFlowDumper, 
self).__init__(*args, **kwargs)


    def ipaddr_to_str(self, ip):        return 
socket.inet_ntoa(struct.pack('!I', ip))
    @set_ev_cls(netflow_collector.EventNetFlow,                
netflow_collector.NETFLOW_EV_DISPATCHER)    def dump_flow(self, ev):        msg 
= ev.msg        LOG.info('NetFlow V%d containing %d flows', msg.version,        
         msg.count)
        flows = msg.flows
        for i in range(msg.count):            LOG.info('Flow%d: %s -> %s ', i,  
                   self.ipaddr_to_str(flows[i].srcaddr),                     
self.ipaddr_to_str(flows[i].dstaddr))            LOG.info('%d packets and %d 
bytes in the flow',                     flows[i].dpkts, flows[i].doctets)

Thanks a lot for your feedback.Finally i changed self.thread in hub.spawn 
instead of gevent_spawn and i overrode start method to return self.thread. 

    Iwase Yusuke <[email protected]> schrieb am 3:07 Dienstag, 25.Oktober 
2016:
 

 Hi,

Please make your problem more clear...

"netflow_collector" is the module and "netflow_dumper" is the Ryu application
you have developed, right?

For writing your own Ryu application, please confirm your application inherits
app_manager.RyuApp class first.
  http://ryu.readthedocs.io/en/latest/writing_ryu_app.html#start-writing

And, if your application will run without OpenFlow, please returns a thread
object at start() method in your application, which thread will be the main
thread of your application and ryu-manager will wait this thread.
By the default, RyuApp.start() does not return any thread, and ryu-manager
will terminate immediately without waiting.
  https://github.com/osrg/ryu/blob/master/ryu/base/app_manager.py#L174-L178


Thanks,
Iwase


On 2016年10月25日 00:50, Mar Ade wrote:
> Hello i have put netflow_collector in xflow file and i am trying to use 
> netflow_dumper but the problem is that when i call ryu-manager with netflow 
> dumper , it is initiating and then it terminates without waiting netflow 
> packets.Any ideas?Thanks in advance,Marinos
>
>
>
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, SlashDot.org! http://sdm.link/slashdot
>
>
>
> _______________________________________________
> Ryu-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/ryu-devel
>


   
------------------------------------------------------------------------------
The Command Line: Reinvented for Modern Developers
Did the resurgence of CLI tooling catch you by surprise?
Reconnect with the command line and become more productive. 
Learn the new .NET and ASP.NET CLI. Get your free copy!
http://sdm.link/telerik
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to