[ovs-dev] [PATCH] ovn: Convenient tool decoding ofproto/trace output for ovn lflows

Han Zhou zhouhan at gmail.com
Tue Mar 21 19:21:18 UTC 2017


A python script to decode ofproto/trace output to add ovn lflow
information inline.

Signed-off-by: Han Zhou <zhouhan at gmail.com>
---
 manpages.mk                    |  4 ++
 ovn/utilities/automake.mk      | 15 +++++--
 ovn/utilities/ovn-detrace.1.in | 29 +++++++++++++
 ovn/utilities/ovn-detrace.in   | 94 ++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 138 insertions(+), 4 deletions(-)
 create mode 100644 ovn/utilities/ovn-detrace.1.in
 create mode 100755 ovn/utilities/ovn-detrace.in

diff --git a/manpages.mk b/manpages.mk
index 742bd66..ced19c0 100644
--- a/manpages.mk
+++ b/manpages.mk
@@ -1,5 +1,9 @@
 # Generated automatically -- do not modify!    -*- buffer-read-only: t -*-
 
+ovn/utilities/ovn-detrace.py: \
+	ovn/utilities/ovn-detrace.py.in
+ovn/utilities/ovn-detrace.py.in:
+
 ovn/utilities/ovn-sbctl.8: \
 	ovn/utilities/ovn-sbctl.8.in \
 	lib/common.man \
diff --git a/ovn/utilities/automake.mk b/ovn/utilities/automake.mk
index 08e48ea..b96f9bf 100644
--- a/ovn/utilities/automake.mk
+++ b/ovn/utilities/automake.mk
@@ -6,14 +6,18 @@ man_MANS += \
     ovn/utilities/ovn-ctl.8 \
     ovn/utilities/ovn-nbctl.8 \
     ovn/utilities/ovn-sbctl.8 \
-    ovn/utilities/ovn-trace.8
+    ovn/utilities/ovn-trace.8 \
+    ovn/utilities/ovn-detrace.1
 
-MAN_ROOTS += ovn/utilities/ovn-sbctl.8.in
+MAN_ROOTS += \
+    ovn/utilities/ovn-sbctl.8.in \
+    ovn/utilities/ovn-detrace.1.in
 
 # Docker drivers
 bin_SCRIPTS += \
     ovn/utilities/ovn-docker-overlay-driver \
-    ovn/utilities/ovn-docker-underlay-driver
+    ovn/utilities/ovn-docker-underlay-driver \
+    ovn/utilities/ovn-detrace
 
 EXTRA_DIST += \
     ovn/utilities/ovn-ctl \
@@ -22,13 +26,16 @@ EXTRA_DIST += \
     ovn/utilities/ovn-docker-underlay-driver \
     ovn/utilities/ovn-nbctl.8.xml \
     ovn/utilities/ovn-trace.8.xml \
+    ovn/utilities/ovn-detrace.in \
     ovn/utilities/ovndb-servers.ocf
 
 CLEANFILES += \
     ovn/utilities/ovn-ctl.8 \
     ovn/utilities/ovn-nbctl.8 \
     ovn/utilities/ovn-sbctl.8 \
-    ovn/utilities/ovn-trace.8
+    ovn/utilities/ovn-trace.8 \
+    ovn/utilities/ovn-detrace.1 \
+    ovn/utilities/ovn-detrace
 
 # ovn-nbctl
 bin_PROGRAMS += ovn/utilities/ovn-nbctl
diff --git a/ovn/utilities/ovn-detrace.1.in b/ovn/utilities/ovn-detrace.1.in
new file mode 100644
index 0000000..2f74fd7
--- /dev/null
+++ b/ovn/utilities/ovn-detrace.1.in
@@ -0,0 +1,29 @@
+.TH ovn\-detrace 1 "@VERSION@" "Open vSwitch" "Open vSwitch Manual"
+.
+.SH NAME
+ovn\-detrace \- convert ``ovs\-appctl ofproto/trace'' output to combine
+OVN logical flow information.
+.
+.SH SYNOPSIS
+\fBovn\-detrace < \fIfile\fR
+.so lib/common-syn.man
+.
+.SH DESCRIPTION
+The \fBovn\-detrace\fR program reads \fBovs\-appctl ofproto/trace\fR output on
+stdin, looking for cookies, and expand each cookie with corresponding OVN logical
+flows.
+.PP
+.
+.SH "OPTIONS"
+.so lib/common.man
+.
+.IP "\fB\-\-db=\fIserver\fR"
+The OVSDB database remote to contact.  If the \fBOVN_SB_DB\fR
+environment variable is set, its value is used as the default.
+Otherwise, the default is \fBunix:@RUNDIR@/db.sock\fR, but this
+default is unlikely to be useful outside of single-machine OVN test
+environments.
+.
+.SH "SEE ALSO"
+.
+.BR ovs\-appctl (8), ovn\-sbctl (8), ovn\-trace (8)
diff --git a/ovn/utilities/ovn-detrace.in b/ovn/utilities/ovn-detrace.in
new file mode 100755
index 0000000..ea85484
--- /dev/null
+++ b/ovn/utilities/ovn-detrace.in
@@ -0,0 +1,94 @@
+#! /usr/bin/env @PYTHON@
+#
+# Copyright (c) 2017 eBay Inc.
+#
+# 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 getopt
+import re
+import subprocess
+import sys
+
+argv0 = sys.argv[0]
+
+
+def usage():
+    print """\
+%(argv0)s:
+usage: %(argv0)s < FILE
+where FILE is output from ovs-appctl ofproto/trace.
+
+The following options are also available:
+  -h, --help                  display this help message
+  -V, --version               display version information
+  --db=DATABASE               connect to DATABASE\
+""" % {'argv0': argv0}
+    sys.exit(0)
+
+
+def reformat(lflow):
+    return re.sub(r'\s+[,\)]', '', lflow, 0)
+
+
+def main():
+    try:
+        options, args = getopt.gnu_getopt(sys.argv[1:], 'hV',
+                                          ['help', 'version', 'db='])
+    except getopt.GetoptError, geo:
+        sys.stderr.write("%s: %s\n" % (argv0, geo.msg))
+        sys.exit(1)
+
+    db_opt = None
+    for key, value in options:
+        if key in ['-h', '--help']:
+            usage()
+        elif key in ['-V', '--version']:
+            print "%s (Open vSwitch) @VERSION@" % argv0
+        elif key in ['--db']:
+            db_opt = key + '=' + value
+        else:
+            sys.exit(0)
+
+    if len(args) != 0:
+        sys.stderr.write("%s: non-option argument not supported "
+                         "(use --help for help)\n" % argv0)
+        sys.exit(1)
+
+    regex = re.compile(r'^.*cookie 0x([0-9a-fA-F]+)')
+    while True:
+        line = sys.stdin.readline()
+        print line.strip()
+        if line == "":
+            break
+
+        m = regex.match(line)
+        if m:
+            cookie = m.group(1)
+            cmd_args = ['ovn-sbctl']
+            if db_opt:
+                cmd_args.append(db_opt)
+            cmd_args.extend(['lflow-list', cookie])
+            lflow = subprocess.check_output(cmd_args)
+            if lflow:
+                for l in lflow.splitlines():
+                    l = reformat(l)
+                    print "\t* " + l
+
+
+if __name__ == "__main__":
+    main()
+
+
+# Local variables:
+# mode: python
+# End:
-- 
2.1.0



More information about the dev mailing list