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>
---
 ryu/flags.py                       |    8 +++++-
 ryu/lib/xflow/netflow_collector.py |   54 ++++++++++++++++++++++++++++++++++++
 2 files changed, 61 insertions(+), 1 deletion(-)
 create mode 100644 ryu/lib/xflow/netflow_collector.py

diff --git a/ryu/flags.py b/ryu/flags.py
index 533f7de..4a0a2d7 100644
--- a/ryu/flags.py
+++ b/ryu/flags.py
@@ -40,5 +40,11 @@ CONF.register_cli_opts([
                'context'),
     cfg.StrOpt('quantum-controller-addr', default=None,
                help='openflow method:address:port to set controller of'
-               'ovs bridge')
+               'ovs bridge'),
+
+    # lib/xflow/netflow_collector
+    cfg.StrOpt('netflow-listen-host', default='',
+               help='netflow listen host'),
+    cfg.IntOpt('netflow-listen-port', default=2055,
+               help='netflow listen port')
 ])
diff --git a/ryu/lib/xflow/netflow_collector.py 
b/ryu/lib/xflow/netflow_collector.py
new file mode 100644
index 0000000..cf1e34b
--- /dev/null
+++ b/ryu/lib/xflow/netflow_collector.py
@@ -0,0 +1,54 @@
+# 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
+
+from oslo.config import cfg
+from gevent import socket
+from ryu.base import app_manager
+from ryu.controller import event
+from ryu.lib.xflow import netflow
+
+
+CONF = cfg.CONF
+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 _recv_loop(self):
+        while 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((CONF.netflow_listen_host,
+                        CONF.netflow_listen_port))
+        gevent.spawn_later(0, self._recv_loop)
-- 
1.7.9.5


------------------------------------------------------------------------------
Symantec Endpoint Protection 12 positioned as A LEADER in The Forrester  
Wave(TM): Endpoint Security, Q1 2013 and "remains a good choice" in the  
endpoint security space. For insight on selecting the right partner to 
tackle endpoint security challenges, access the full report. 
http://p.sf.net/sfu/symantec-dev2dev
_______________________________________________
Ryu-devel mailing list
Ryu-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to