Browse code

In worlddump, cover all supported version of OpenFlow protocol by ovs-ofctl

Currently ovs-ofctl command is executed for only default ofp version
(OpenFlow10).
Some Neutron's plugin uses OpenFlow13 and in that case ovs-ofctl fails.
This chage allows us to get ovs info for all ofp versions supported by ovs.
And adds dump by dump-ports and dump-ports-desc.

Change-Id: I2d3c42835a5ad0f5ebf540e8127762f466347c9c

fumihiko kakuma authored on 2016/03/08 20:55:01
Showing 1 changed files
... ...
@@ -76,6 +76,24 @@ def _header(name):
76 76
     print
77 77
 
78 78
 
79
+# This method gets a max openflow version supported by openvswitch.
80
+# For example 'ovs-ofctl --version' displays the following:
81
+#
82
+#     ovs-ofctl (Open vSwitch) 2.0.2
83
+#     Compiled Dec  9 2015 14:08:08
84
+#     OpenFlow versions 0x1:0x4
85
+#
86
+# The above shows that openvswitch supports from OpenFlow11 to OpenFlow13.
87
+# This method gets max version searching 'OpenFlow versions 0x1:0x'.
88
+# And return a version value converted to an integer type.
89
+def _get_ofp_version():
90
+    process = subprocess.Popen(['ovs-ofctl', '--version'], stdout=subprocess.PIPE)
91
+    stdout, _ = process.communicate()
92
+    find_str = 'OpenFlow versions 0x1:0x'
93
+    offset = stdout.find(find_str)
94
+    return int(stdout[offset + len(find_str):-1]) - 1
95
+
96
+
79 97
 def disk_space():
80 98
     # the df output
81 99
     _header("File System Summary")
... ...
@@ -143,11 +161,16 @@ def ovs_dump():
143 143
     # grenade), so there is no single place to determine the bridge names from.
144 144
     # Hardcode for now.
145 145
     bridges = ('br-int', 'br-tun', 'br-ex')
146
+    ofctl_cmds = ('show', 'dump-ports-desc', 'dump-ports', 'dump-flows')
147
+    ofp_max = _get_ofp_version()
148
+    vers = 'OpenFlow10'
149
+    for i in range(ofp_max + 1):
150
+        vers += ',OpenFlow1' + str(i)
146 151
     _dump_cmd("sudo ovs-vsctl show")
147
-    for bridge in bridges:
148
-        _dump_cmd("sudo ovs-ofctl show %s" % bridge)
149
-    for bridge in bridges:
150
-        _dump_cmd("sudo ovs-ofctl dump-flows %s" % bridge)
152
+    for ofctl_cmd in ofctl_cmds:
153
+        for bridge in bridges:
154
+            args = {'vers': vers, 'cmd': ofctl_cmd, 'bridge': bridge}
155
+            _dump_cmd("sudo ovs-ofctl --protocols=%(vers)s %(cmd)s %(bridge)s" % args)
151 156
 
152 157
 
153 158
 def process_list():