Thanks for your comments. 2013/2/5 FUJITA Tomonori <fujita.tomon...@lab.ntt.co.jp>: > On Tue, 5 Feb 2013 18:40:12 +0900 > OHMURA Kei <ohmura....@lab.ntt.co.jp> wrote: > >> This gets a netflow packet and sends it to the other >> applications. Each application can use this to get netflow >> messages as an event. >> >> Signed-off-by: OHMURA Kei <ohmura....@lab.ntt.co.jp> >> --- >> bin/ryu-manager | 1 + >> ryu/lib/xflow/netflow_collector.py | 64 >> ++++++++++++++++++++++++++++++++++++ >> 2 files changed, 65 insertions(+) >> create mode 100644 ryu/lib/xflow/netflow_collector.py >> >> diff --git a/bin/ryu-manager b/bin/ryu-manager >> index fca9329..61c5b4d 100755 >> --- a/bin/ryu-manager >> +++ b/bin/ryu-manager >> @@ -33,6 +33,7 @@ from ryu import utils >> from ryu.app import wsgi >> from ryu.base.app_manager import AppManager >> from ryu.controller import controller >> +from ryu.lib.xflow import netflow_collector >> >> # TODO: >> # Right now, we have our own patched copy of ovs python bindings >> diff --git a/ryu/lib/xflow/netflow_collector.py >> b/ryu/lib/xflow/netflow_collector.py >> new file mode 100644 >> index 0000000..ad70dcc >> --- /dev/null >> +++ b/ryu/lib/xflow/netflow_collector.py >> @@ -0,0 +1,64 @@ >> +# Copyright (C) 2013 Nippon Telegraph and Telephone Corporation. >> +# >> +# Licensed under the Apache License, Version 2.0 (the "License"); >> +# you may not use this file except in compliance with the License. >> +# You may obtain a copy of the License at >> +# >> +# http://www.apache.org/licenses/LICENSE-2.0 >> +# >> +# Unless required by applicable law or agreed to in writing, software >> +# distributed under the License is distributed on an "AS IS" BASIS, >> +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or >> +# implied. >> +# See the License for the specific language governing permissions and >> +# limitations under the License. >> + >> + >> +import gevent >> +import gflags >> +import logging >> + >> +from gevent import socket >> +from ryu.base import app_manager >> +from ryu.controller import event >> +from ryu.lib.xflow import netflow >> + >> +LOG = logging.getLogger('ryu.lib.netflow_collector') >> + >> +NETFLOW_EV_DISPATCHER = 'netflow' >> + >> +FLAGS = gflags.FLAGS >> +gflags.DEFINE_string('netflow_listen_host', '', 'netflow listen host') >> +gflags.DEFINE_integer('netflow_listen_port', 9996, 'netflow listen port') >> + >> +BUFSIZE = 8192 # Should we use flexible length? >> + >> + >> +class EventNetFlow(event.EventBase): >> + def __init__(self, msg): >> + super(EventNetFlow, self).__init__() >> + self.msg = msg >> + >> + >> +class NetFlowCollector(app_manager.RyuApp): >> + def __init__(self): >> + super(NetFlowCollector, self).__init__() >> + self.name = 'netflow_collector' >> + self.is_active = True >> + self._start_recv() >> + >> + def close(self): >> + self.is_active = False >> + gevent.joinall([self.thread]) > > For what?
I think that it's not necessary. I'll remove it. > >> + def _recv_loop(self): >> + while self.is_active: >> + (data, addrport) = self.sock.recvfrom(BUFSIZE) >> + msg = netflow.NetFlow.parser(data) >> + if msg: >> + self.send_event_to_observers(EventNetFlow(msg)) > > A msg includes the information about which switch sent this netflow > packet? 'addrport' includes IP address of the switch. I'll add 'addrport' to the EventNetFlow class. > >> + def _start_recv(self): >> + self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) >> + self.sock.bind((FLAGS.netflow_listen_host, >> FLAGS.netflow_listen_port)) >> + self.thread = gevent.spawn_later(0, self._recv_loop) >> -- >> 1.7.9.5 >> >> >> ------------------------------------------------------------------------------ >> Free Next-Gen Firewall Hardware Offer >> Buy your Sophos next-gen firewall before the end March 2013 >> and get the hardware for free! Learn more. >> http://p.sf.net/sfu/sophos-d2d-feb >> _______________________________________________ >> Ryu-devel mailing list >> Ryu-devel@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/ryu-devel > > ------------------------------------------------------------------------------ > Free Next-Gen Firewall Hardware Offer > Buy your Sophos next-gen firewall before the end March 2013 > and get the hardware for free! Learn more. > http://p.sf.net/sfu/sophos-d2d-feb > _______________________________________________ > Ryu-devel mailing list > Ryu-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/ryu-devel ------------------------------------------------------------------------------ Free Next-Gen Firewall Hardware Offer Buy your Sophos next-gen firewall before the end March 2013 and get the hardware for free! Learn more. http://p.sf.net/sfu/sophos-d2d-feb _______________________________________________ Ryu-devel mailing list Ryu-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ryu-devel