This is a sample application to learn how to handle netflow events.

Signed-off-by: OHMURA Kei <[email protected]>
---
 ryu/app/netflow_dumper.py |   53 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)
 create mode 100644 ryu/app/netflow_dumper.py

diff --git a/ryu/app/netflow_dumper.py b/ryu/app/netflow_dumper.py
new file mode 100644
index 0000000..33c622d
--- /dev/null
+++ b/ryu/app/netflow_dumper.py
@@ -0,0 +1,53 @@
+# 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 logging
+import socket
+import struct
+
+from ryu.base import app_manager
+from ryu.controller.handler import set_ev_cls
+from 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)
-- 
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to