From patchwork Mon Dec 28 09:24:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: taoyunxiang X-Patchwork-Id: 1420960 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.166.133; helo=hemlock.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=cmss.chinamobile.com Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4D4QbZ635tz9sWC for ; Tue, 29 Dec 2020 05:11:22 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 4755387137; Mon, 28 Dec 2020 18:11:21 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id DSHK4Ol-5QHH; Mon, 28 Dec 2020 18:11:18 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by hemlock.osuosl.org (Postfix) with ESMTP id BD97287132; Mon, 28 Dec 2020 18:11:13 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 5B4DBC1E98; Mon, 28 Dec 2020 18:11:13 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 2A612C1DA3 for ; Mon, 28 Dec 2020 09:26:09 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 0FCFA86C8A for ; Mon, 28 Dec 2020 09:26:09 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id jVUwH9+3Alh4 for ; Mon, 28 Dec 2020 09:26:04 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from cmccmta3.chinamobile.com (cmccmta3.chinamobile.com [221.176.66.81]) by whitealder.osuosl.org (Postfix) with ESMTP id ACF4186C90 for ; Mon, 28 Dec 2020 09:26:03 +0000 (UTC) Received: from spf.mail.chinamobile.com (unknown[172.16.121.3]) by rmmx-syy-dmz-app11-12011 (RichMail) with SMTP id 2eeb5fe9a4a051b-c1bc2; Mon, 28 Dec 2020 17:25:52 +0800 (CST) X-RM-TRANSID: 2eeb5fe9a4a051b-c1bc2 X-RM-TagInfo: emlType=0 X-RM-SPAM-FLAG: 00000000 Received: from yun.localdomain (unknown[112.25.154.146]) by rmsmtp-syy-appsvr02-12002 (RichMail) with SMTP id 2ee25fe9a48a90b-7b8c1; Mon, 28 Dec 2020 17:25:52 +0800 (CST) X-RM-TRANSID: 2ee25fe9a48a90b-7b8c1 From: Tao YunXiang To: ovs-dev@openvswitch.org Date: Mon, 28 Dec 2020 01:24:58 -0800 Message-Id: <20201228092520.11807-41-taoyunxiang@cmss.chinamobile.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201228092520.11807-1-taoyunxiang@cmss.chinamobile.com> References: <8> <20201228092520.11807-1-taoyunxiang@cmss.chinamobile.com> MIME-Version: 1.0 X-Mailman-Approved-At: Mon, 28 Dec 2020 18:10:34 +0000 Cc: Rongyin Subject: [ovs-dev] [PATCH 40/62] ovs_gdb.py: add print ofp buffers in gdb script X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" From: Rongyin This adds the ovs_dump_ifpacts command: (gdb) help ovs_dump_ofpacts Dump all actions in an ofpacts set Usage: ovs_dump_ofpacts : Pointer to set of ofpact structures. : Total length of the set. Example dumping all actions when in the clone_xlate_actions() function: (gdb) ovs_dump_ofpacts actions actions_len (struct ofpact *) 0x561c7be487c8: {type = OFPACT_SET_FIELD, raw = 255 '', len = 24} (struct ofpact *) 0x561c7be487e0: {type = OFPACT_SET_FIELD, raw = 255 '', len = 24} (struct ofpact *) 0x561c7be487f8: {type = OFPACT_SET_FIELD, raw = 255 '', len = 24} (struct ofpact *) 0x561c7be48810: {type = OFPACT_SET_FIELD, raw = 255 '', len = 32} (struct ofpact *) 0x561c7be48830: {type = OFPACT_SET_FIELD, raw = 255 '', len = 24} (struct ofpact *) 0x561c7be48848: {type = OFPACT_RESUBMIT, raw = 38 '&', len = 16} Code Source From: Self Code Description: Add print ofp buffers in gdb script. The details as above. Jira: #[Optional] 市场项目编号(名称):[Optional] --- utilities/gdb/ovs_gdb.py | 75 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/utilities/gdb/ovs_gdb.py b/utilities/gdb/ovs_gdb.py index befc2b4..1111f31 100644 --- a/utilities/gdb/ovs_gdb.py +++ b/utilities/gdb/ovs_gdb.py @@ -55,6 +55,7 @@ # ... # ... # +from __future__ import print_function import gdb import sys import uuid @@ -414,6 +415,39 @@ class ForEachLIST(): # +# Class that will provide an iterator over an OFPACTS. +# +class ForEachOFPACTS(): + def __init__(self, ofpacts, ofpacts_len): + self.ofpact = ofpacts.cast(gdb.lookup_type('struct ofpact').pointer()) + self.length = int(ofpacts_len) + + def __round_up(self, val, round_to): + return int(val) + (round_to - int(val)) % round_to + + def __iter__(self): + return self + + def __next__(self): + if self.ofpact is None or self.length <= 0: + raise StopIteration + + ofpact = self.ofpact + length = self.__round_up(ofpact['len'], 8) + + self.length -= length + self.ofpact = self.ofpact.cast( + gdb.lookup_type('void').pointer()) + length + self.ofpact = self.ofpact.cast( + gdb.lookup_type('struct ofpact').pointer()) + + return ofpact + + def next(self): + return self.__next__() + + +# # Implements the GDB "ovs_dump_bridges" command # class CmdDumpBridge(gdb.Command): @@ -1234,6 +1268,46 @@ class CmdShowUpcall(gdb.Command): # +# Implements the GDB "ovs_dump_ofpacts" command +# +class CmdDumpOfpacts(gdb.Command): + """Dump all actions in an ofpacts set + Usage: ovs_dump_ofpacts + + : Pointer to set of ofpact structures. + : Total length of the set. + + Example dumping all actions when in the clone_xlate_actions() function: + + (gdb) ovs_dump_ofpacts actions actions_len + (struct ofpact *) 0x561c7be487c8: {type = OFPACT_SET_FIELD, raw = 255 '', len = 24} + (struct ofpact *) 0x561c7be487e0: {type = OFPACT_SET_FIELD, raw = 255 '', len = 24} + (struct ofpact *) 0x561c7be487f8: {type = OFPACT_SET_FIELD, raw = 255 '', len = 24} + (struct ofpact *) 0x561c7be48810: {type = OFPACT_SET_FIELD, raw = 255 '', len = 32} + (struct ofpact *) 0x561c7be48830: {type = OFPACT_SET_FIELD, raw = 255 '', len = 24} + (struct ofpact *) 0x561c7be48848: {type = OFPACT_RESUBMIT, raw = 38 '&', len = 16} + """ + def __init__(self): + super(CmdDumpOfpacts, self).__init__("ovs_dump_ofpacts", + gdb.COMMAND_DATA) + + def invoke(self, arg, from_tty): + arg_list = gdb.string_to_argv(arg) + + if len(arg_list) != 2: + print("usage: ovs_dump_ofpacts ") + return + + ofpacts = gdb.parse_and_eval(arg_list[0]).cast( + gdb.lookup_type('struct ofpact').pointer()) + + length = gdb.parse_and_eval(arg_list[1]) + + for node in ForEachOFPACTS(ofpacts, length): + print("(struct ofpact *) {}: {}".format(node, node.dereference())) + + +# # Initialize all GDB commands # CmdDumpBridge() @@ -1244,6 +1318,7 @@ CmdDumpDpNetdevPorts() CmdDumpDpProvider() CmdDumpNetdev() CmdDumpNetdevProvider() +CmdDumpOfpacts() CmdDumpOvsList() CmdDumpSimap() CmdDumpSmap()