From patchwork Wed Nov 13 09:52:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dumitru Ceara X-Patchwork-Id: 1194177 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="MoXuREgC"; dkim-atps=neutral Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47Cfzn3YfRz9s7T for ; Wed, 13 Nov 2019 20:52:37 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id DD070111B; Wed, 13 Nov 2019 09:52:12 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 613DF10F2 for ; Wed, 13 Nov 2019 09:52:11 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by smtp1.linuxfoundation.org (Postfix) with ESMTP id F1478623 for ; Wed, 13 Nov 2019 09:52:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573638729; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gXUMDg9J5P0WVFW5A5oQomuAFWQGkSiBWOf+BWFi+oo=; b=MoXuREgC5/bOJH20GuvQeKwxNyVN2WRrI9HvTLtH9FbvEE99HFiKtsdVEv321xfoH3ZXmC rBGZJdUcNSk6AJ7dg1CnD/g4HD6NdiD7RUEvOPrRCXHVGaCI6CIqYXCqvI6ALhWmUd8Moz TF+b00ax4BIYayx/ESaDvnNxCbT1sMA= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-306-Cca-nd3vNHaGkAR_n1z6OA-1; Wed, 13 Nov 2019 04:52:06 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CB353100550E; Wed, 13 Nov 2019 09:52:04 +0000 (UTC) Received: from dceara.remote.csb (ovpn-116-239.ams2.redhat.com [10.36.116.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id CEE815889; Wed, 13 Nov 2019 09:52:03 +0000 (UTC) From: Dumitru Ceara To: dev@openvswitch.org Date: Wed, 13 Nov 2019 10:52:01 +0100 Message-Id: <20191113095159.10768.88680.stgit@dceara.remote.csb> In-Reply-To: <20191113095145.10768.21786.stgit@dceara.remote.csb> References: <20191113095145.10768.21786.stgit@dceara.remote.csb> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: Cca-nd3vNHaGkAR_n1z6OA-1 X-Mimecast-Spam-Score: 0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: hzhou@ovn.org Subject: [ovs-dev] [PATCH v4 ovn 1/3] ovn-detrace: Fix rundir. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org After the separation of OVS and OVN rundirs, the ovn-detrace script hasn't been updated to use the OVN rundir instead of the OVS one. Acked-by: Mark Michelson Signed-off-by: Dumitru Ceara --- utilities/ovn-detrace.in | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/utilities/ovn-detrace.in b/utilities/ovn-detrace.in index c842adc..9471e37 100755 --- a/utilities/ovn-detrace.in +++ b/utilities/ovn-detrace.in @@ -169,16 +169,16 @@ def main(): "(use --help for help)\n" % argv0) sys.exit(1) - ovs_rundir = os.getenv('OVS_RUNDIR', '@RUNDIR@') + ovn_rundir = os.getenv('OVN_RUNDIR', '@OVN_RUNDIR@') if not ovnsb_db: ovnsb_db = os.getenv('OVN_SB_DB') if not ovnsb_db: - ovnsb_db = 'unix:%s/ovnsb_db.sock' % ovs_rundir + ovnsb_db = 'unix:%s/ovnsb_db.sock' % ovn_rundir if not ovnnb_db: ovnnb_db = os.getenv('OVN_NB_DB') if not ovnnb_db: - ovnnb_db = 'unix:%s/ovnnb_db.sock' % ovs_rundir + ovnnb_db = 'unix:%s/ovnnb_db.sock' % ovn_rundir ovsdb_ovnsb = OVSDB(ovnsb_db, 'OVN_Southbound') ovsdb_ovnnb = OVSDB(ovnnb_db, 'OVN_Northbound') From patchwork Wed Nov 13 09:52:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dumitru Ceara X-Patchwork-Id: 1194178 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="AX2T1VXg"; dkim-atps=neutral Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47Cg0k1kkCz9s7T for ; Wed, 13 Nov 2019 20:53:26 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id C70EA1144; Wed, 13 Nov 2019 09:52:29 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id C800F1127 for ; Wed, 13 Nov 2019 09:52:28 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by smtp1.linuxfoundation.org (Postfix) with ESMTP id 61CF8623 for ; Wed, 13 Nov 2019 09:52:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573638747; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=o+qXMRelCI1JPZr9GpN9G+qR6w4oVSBzTB4KcasoCh4=; b=AX2T1VXgSQp+IvgrXY+KUqZg1HzK320GOcMqJsjinqa7D9APzXd66CdhkC4B1fnr3m76ES MBtSRiQfwfdwY5TLP+345+Jg7f6AD7GTGO29yA7cS2OmyA9+B9eqk7ZbaJ5BOO9Sxx/YeO 6VSVnk9SGRvaez5MrODAs+8sdAgMZz0= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-274-nnqK1bZVN8StyUI7ifHItw-1; Wed, 13 Nov 2019 04:52:25 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D796F477; Wed, 13 Nov 2019 09:52:24 +0000 (UTC) Received: from dceara.remote.csb (ovpn-116-239.ams2.redhat.com [10.36.116.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id C03BD60467; Wed, 13 Nov 2019 09:52:23 +0000 (UTC) From: Dumitru Ceara To: dev@openvswitch.org Date: Wed, 13 Nov 2019 10:52:21 +0100 Message-Id: <20191113095210.10768.60140.stgit@dceara.remote.csb> In-Reply-To: <20191113095145.10768.21786.stgit@dceara.remote.csb> References: <20191113095145.10768.21786.stgit@dceara.remote.csb> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-MC-Unique: nnqK1bZVN8StyUI7ifHItw-1 X-Mimecast-Spam-Score: 0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: hzhou@ovn.org Subject: [ovs-dev] [PATCH v4 ovn 2/3] ovn-detrace: Fix line parsing. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org The script was not properly parsing rows containing flows from tables 0-9 because ofproto/trace adds leading whitespace for pretty printing flows. Also, add a check to make sure that the cookie refers to a Logical_Flow before trying to print the record. Signed-off-by: Dumitru Ceara --- utilities/ovn-detrace.in | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/utilities/ovn-detrace.in b/utilities/ovn-detrace.in index 9471e37..accbcd2 100755 --- a/utilities/ovn-detrace.in +++ b/utilities/ovn-detrace.in @@ -184,7 +184,7 @@ def main(): ovsdb_ovnnb = OVSDB(ovnnb_db, 'OVN_Northbound') regex_cookie = re.compile(r'^.*cookie 0x([0-9a-fA-F]+)') - regex_table_id = re.compile(r'^[0-9]+\.') + regex_table_id = re.compile(r'^ *[0-9]+\.') cookie = None while True: line = sys.stdin.readline() @@ -192,8 +192,9 @@ def main(): # print lflow info when the current flow block ends if regex_table_id.match(line) or line.strip() == '': lflow = get_lflow_from_cookie(ovsdb_ovnsb, cookie) - print_lflow(lflow, " * ") - print_lflow_nb_hint(lflow, " * ", ovsdb_ovnnb) + if lflow: + print_lflow(lflow, " * ") + print_lflow_nb_hint(lflow, " * ", ovsdb_ovnnb) cookie = None print line.strip() From patchwork Wed Nov 13 09:52:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dumitru Ceara X-Patchwork-Id: 1194179 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="iLNGXrZy"; dkim-atps=neutral Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47Cg1S6JXYz9sPk for ; Wed, 13 Nov 2019 20:54:04 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 6E39F115C; Wed, 13 Nov 2019 09:52:45 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 1548A115B for ; Wed, 13 Nov 2019 09:52:45 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by smtp1.linuxfoundation.org (Postfix) with ESMTP id 3066D82B for ; Wed, 13 Nov 2019 09:52:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573638763; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LFpzgPzv40L9b5leg5ZFesCXlz/NC0qcZaFBAbAyMBw=; b=iLNGXrZyttdsk2xs1AGYeykaWOpH4mQJkgtThQ4nai92YBcLpO7EIpub/tch6Yr3K147Cf EyX0WuNmsXjH/cVLdQDYSW+Ysfqylere5FqP4V/NFEkxBPlINPVYoYlTcSYAjV2oGT9RV1 I2iYJYtDBidX68iAbdvcJuWo+5boZOU= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-165-4axU-r1nNwy8Cg1NImq9_Q-1; Wed, 13 Nov 2019 04:52:39 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 063E7107ACC8; Wed, 13 Nov 2019 09:52:39 +0000 (UTC) Received: from dceara.remote.csb (ovpn-116-239.ams2.redhat.com [10.36.116.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id 30691602FF; Wed, 13 Nov 2019 09:52:38 +0000 (UTC) From: Dumitru Ceara To: dev@openvswitch.org Date: Wed, 13 Nov 2019 10:52:35 +0100 Message-Id: <20191113095230.10768.63215.stgit@dceara.remote.csb> In-Reply-To: <20191113095145.10768.21786.stgit@dceara.remote.csb> References: <20191113095145.10768.21786.stgit@dceara.remote.csb> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-MC-Unique: 4axU-r1nNwy8Cg1NImq9_Q-1 X-Mimecast-Spam-Score: 0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: hzhou@ovn.org Subject: [ovs-dev] [PATCH v4 ovn 3/3] ovn-detrace: Add support for other types of SB cookies. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org Commit eb25a7da639e ("Improve debuggability of OVN to OpenFlow translations.") added cookies for Port_Binding, Mac_Binding, Multicast_Group, Chassis records to the OpenfFlow entries they generate. Add support for parsing such cookies in ovn-detrace too. Also: - refactor ovn-detrace to allow a more generic way of defining cookie handlers. - properly handle potential collisions between cookie -> UUID mappings. - change print statements to print() calls. - add custom printing functions to simplify prefixing outputs. Acked-by: Mark Michelson Signed-off-by: Dumitru Ceara --- utilities/ovn-detrace.in | 194 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 134 insertions(+), 60 deletions(-) diff --git a/utilities/ovn-detrace.in b/utilities/ovn-detrace.in index accbcd2..c645658 100755 --- a/utilities/ovn-detrace.in +++ b/utilities/ovn-detrace.in @@ -14,6 +14,9 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import print_function + +import functools import getopt import os import re @@ -37,7 +40,7 @@ argv0 = sys.argv[0] def usage(): - print """\ + print("""\ %(argv0)s: usage: %(argv0)s < FILE where FILE is output from ovs-appctl ofproto/trace. @@ -47,9 +50,21 @@ The following options are also available: -V, --version display version information --ovnsb=DATABASE use DATABASE as southbound DB --ovnnb=DATABASE use DATABASE as northbound DB\ -""" % {'argv0': argv0} +""" % {'argv0': argv0}) sys.exit(0) +print_p = functools.partial(print, ' * ') +print_h = functools.partial(print, ' * ') + +def datapath_str(datapath): + return '"%s" (%s)' % (str(datapath.external_ids.get('name')), + datapath.uuid) + +def chassis_str(chassis): + if len(chassis) == 0: + return '' + ch = chassis[0] + return 'chassis-name "%s", chassis-str "%s"' % (ch.name, ch.hostname) class OVSDB(object): @staticmethod @@ -87,59 +102,112 @@ class OVSDB(object): def get_table(self, table_name): return self._idl_conn.tables[table_name] - def _find_row(self, table_name, find): - return next( - (row for row in self.get_table(table_name).rows.values() - if find(row)), None) + def _find_row(self, table_name, find_fn): + return filter(find_fn, self.get_table(table_name).rows.values()) - def _find_row_by_name(self, table_name, value): + def _find_rows_by_name(self, table_name, value): return self._find_row(table_name, lambda row: row.name == value) - def find_row_by_partial_uuid(self, table_name, value): - return self._find_row(table_name, lambda row: value in str(row.uuid)) - - -def get_lflow_from_cookie(ovnsb_db, cookie): - return ovnsb_db.find_row_by_partial_uuid('Logical_Flow', cookie) - - -def print_lflow(lflow, prefix): - ldp_uuid = lflow.logical_datapath.uuid - ldp_name = str(lflow.logical_datapath.external_ids.get('name')) - - print '%sLogical datapath: "%s" (%s) [%s]' % (prefix, - ldp_name, - ldp_uuid, - lflow.pipeline) - print "%sLogical flow: table=%s (%s), priority=%s, " \ - "match=(%s), actions=(%s)" % (prefix, - lflow.table_id, - lflow.external_ids.get('stage-name'), - lflow.priority, - str(lflow.match).strip('"'), - str(lflow.actions).strip('"')) - - -def print_lflow_nb_hint(lflow, prefix, ovnnb_db): - external_ids = lflow.external_ids - if external_ids.get('stage-name') in ['ls_in_acl', - 'ls_out_acl']: - acl_hint = external_ids.get('stage-hint') - if not acl_hint: - return - acl = ovnnb_db.find_row_by_partial_uuid('ACL', acl_hint) - if not acl: - return - output = "%sACL: %s, priority=%s, " \ - "match=(%s), %s" % (prefix, - acl.direction, - acl.priority, - acl.match.strip('"'), - acl.action) - if acl.log: - output += ' (log)' - print output - + def find_rows_by_partial_uuid(self, table_name, value): + return self._find_row(table_name, + lambda row: str(row.uuid).startswith(value)) + +class CookieHandler(object): + def __init__(self, db, table): + self._db = db + self._table = table + + def get_records(self, cookie): + # Adjust cookie to include leading zeroes if needed. + cookie = cookie.zfill(8) + return self._db.find_rows_by_partial_uuid(self._table, cookie) + + def print_record(self, record): + pass + + def print_hint(self, record, db): + pass + +class LogicalFlowHandler(CookieHandler): + def __init__(self, ovnsb_db): + super(LogicalFlowHandler, self).__init__(ovnsb_db, 'Logical_Flow') + + def print_record(self, lflow): + print_p('Logical datapath: %s [%s]' % + (datapath_str(lflow.logical_datapath), lflow.pipeline)) + print_p('Logical flow: table=%s (%s), priority=%s, ' + 'match=(%s), actions=(%s)' % + (lflow.table_id, lflow.external_ids.get('stage-name'), + lflow.priority, + str(lflow.match).strip('"'), + str(lflow.actions).strip('"'))) + + def print_hint(self, lflow, ovnnb_db): + external_ids = lflow.external_ids + if external_ids.get('stage-name') in ['ls_in_acl', + 'ls_out_acl']: + acl_hint = external_ids.get('stage-hint') + if not acl_hint: + return + for i, acl in enumerate( + ovnnb_db.find_rows_by_partial_uuid('ACL', acl_hint)): + if i > 0: + print_h('[Duplicate uuid ACL hint]') + + output = 'ACL: %s, priority=%s, ' \ + 'match=(%s), %s' % (acl.direction, + acl.priority, + acl.match.strip('"'), + acl.action) + if acl.log: + output += ' (log)' + print_h(output) + +class PortBindingHandler(CookieHandler): + def __init__(self, ovnsb_db): + super(PortBindingHandler, self).__init__(ovnsb_db, 'Port_Binding') + + def print_record(self, pb): + print_p('Logical datapath: %s' % (datapath_str(pb.datapath))) + print_p('Port Binding: logical_port "%s", tunnel_key %ld, %s' % + (pb.logical_port, pb.tunnel_key, + chassis_str(pb.chassis))) + +class MacBindingHandler(CookieHandler): + def __init__(self, ovnsb_db): + super(MacBindingHandler, self).__init__(ovnsb_db, 'MAC_Binding') + + def print_record(self, mb): + print_p('Logical datapath: %s' % (datapath_str(mb.datapath))) + print_p('MAC Binding: ip "%s", logical_port "%s", mac "%s"' % + (mb.ip, mb.logical_port, mb.mac)) + +class MulticastGroupHandler(CookieHandler): + def __init__(self, ovnsb_db): + super(MulticastGroupHandler, self).__init__(ovnsb_db, + 'Multicast_Group') + + def print_record(self, mc): + mc_ports = ', '.join([pb.logical_port for pb in mc.ports]) + + print_p('Logical datapath: %s' % (datapath_str(mc.datapath))) + print_p('Multicast Group: name "%s", tunnel_key %ld ports: (%s)' % + (mc.name, mc.tunnel_key, mc_ports)) + +class ChassisHandler(CookieHandler): + def __init__(self, ovnsb_db): + super(ChassisHandler, self).__init__(ovnsb_db, 'Chassis') + + def print_record(self, chassis): + print_p('Chassis: %s' % (chassis_str([chassis]))) + +def print_sb_record_from_cookie(ovnnb_db, ovnsb_db, cookie_handlers, cookie): + for handler in cookie_handlers: + for i, sb_record in enumerate(handler.get_records(cookie)): + if i > 0: + handler.print('[Duplicate uuid cookie]') + handler.print_record(sb_record) + handler.print_hint(sb_record, ovnnb_db) def main(): try: @@ -156,7 +224,7 @@ def main(): if key in ['-h', '--help']: usage() elif key in ['-V', '--version']: - print "%s (Open vSwitch) @VERSION@" % argv0 + print("%s (Open vSwitch) @VERSION@" % argv0) elif key in ['--ovnsb']: ovnsb_db = value elif key in ['--ovnnb']: @@ -183,22 +251,28 @@ def main(): ovsdb_ovnsb = OVSDB(ovnsb_db, 'OVN_Southbound') ovsdb_ovnnb = OVSDB(ovnnb_db, 'OVN_Northbound') + cookie_handlers = [ + LogicalFlowHandler(ovsdb_ovnsb), + PortBindingHandler(ovsdb_ovnsb), + MacBindingHandler(ovsdb_ovnsb), + MulticastGroupHandler(ovsdb_ovnsb), + ChassisHandler(ovsdb_ovnsb) + ] + regex_cookie = re.compile(r'^.*cookie 0x([0-9a-fA-F]+)') regex_table_id = re.compile(r'^ *[0-9]+\.') cookie = None while True: line = sys.stdin.readline() if cookie: - # print lflow info when the current flow block ends + # Print SB record info when the current flow block ends. if regex_table_id.match(line) or line.strip() == '': - lflow = get_lflow_from_cookie(ovsdb_ovnsb, cookie) - if lflow: - print_lflow(lflow, " * ") - print_lflow_nb_hint(lflow, " * ", ovsdb_ovnnb) + print_sb_record_from_cookie(ovsdb_ovnnb, ovsdb_ovnsb, + cookie_handlers, cookie) cookie = None - print line.strip() - if line == "": + print(line.strip()) + if line == '': break m = regex_cookie.match(line)