From b52716b27ffa107e5d1e4647dcbcbabf07d4459e Mon Sep 17 00:00:00 2001 From: Volodymyr Samotiy Date: Wed, 29 Jun 2016 15:55:37 +0300 Subject: [PATCH] Add bv-ptctl, minor bug fixes, documentation updates Change-Id: Idf2dbb63f2b588fecce04bfb27e3d31c9dfd0cbf --- README.md | 170 ++++++-- broadview_lib/config/pt.py | 6 +- broadview_lib/pt/pt_parser.py | 30 +- broadview_lib/tools/bv-ptctl.py | 688 ++++++++++++++++++++++++++++++++ broadview_lib/tools/examples.sh | 62 ++- 5 files changed, 898 insertions(+), 58 deletions(-) create mode 100644 broadview_lib/tools/bv-ptctl.py diff --git a/README.md b/README.md index 26017db..ec28997 100644 --- a/README.md +++ b/README.md @@ -34,16 +34,16 @@ flows. The actual use-counts vary depending on the chip set. More information on BroadView, BST, and what they provide can be found at: -Code and documentation: https://github.com/Broadcom-Switch/BroadView-Instrumentation -Product information: https://www.broadcom.com/products/ethernet-communication-and-switching/switching/broadview +* Code and documentation: https://github.com/Broadcom-Switch/BroadView-Instrumentation +* Product information: https://www.broadcom.com/products/ethernet-communication-and-switching/switching/broadview ## BroadView Agent and broadview-lib A BroadView agent is software running on platforms that support BroadView. It exposes a JSON-RPC, REST-like API for configuring the agent to report statistics -such a BST. It also report statistics to agents or collectors that are designed -to receive these reports. These reports are also transmitted using JSON-RPC. -All connections to and from the agent are based on HTTP 1.1. +such as BST. It also report statistics to agents or collectors that are +designed to receive these reports. These reports are also transmitted using +JSON-RPC. All connections to and from the agent are based on HTTP 1.1. broadview-lib is designed to provide the underlying infrastructure that is needed for the development of Python applications that interact with a @@ -62,28 +62,60 @@ broadview-lib consists of two components. One is a set of classes that can be used to configure BroadView. The other is an API that parses content sent by BroadView agents and presents it as Python objects. -broadview-lib is, like BroadView itself, designed to be extensible. In this -release, the BroadView BST component is supported. Future releases will add -support for additional BroadView components as they become available. +broadview-lib is, like BroadView itself, designed to be extensible. Currently +the BroadView BST and PacketTrace components are supported. Future releases +will add support for additional BroadView components as they become available. # Tools -broadview-lib includes bv-bstctl.py, which is a command line application that -can be used to configure BroadView BST. It also provides an example usage of -both the configuration and BST parsing APIs in broadview-lib. For usage -information, please type: +broadview-lib includes command line tools that make use of broadview-lib to +to issue supported commands for querying and configuring BroadView. Each +command line tool is paired to a specific component of BroadView (BST, +PacketTrace, etc). -python bv-bstcfg.py help +Each of these commands supports a "help" argument that will print usage +information. For commands that retrieve a JSON response from the agent, +the JSON response will be written to stdout. +The file examples.sh in the tools directory contains example invocations +of the supported commands. -bv-bstctl.py writes its output to stdout in JSON format. +Each of the commands provides example usage of broadview-lib APIs and thus +can be used as inspiration for your own broadview-lib applications. -The file examples.sh in the tools directory contains usage example for the -bv-bstcfg application and can be used to exercise bv-bsctl. +### bv-bstctl.py + +A command line application that can be used to configure BroadView BST. + +### bv-ptctl.py + +A command line application that can be used to configure BroadView PacketTrace. + +### bv-ctl.py + +A command line application that can be used to issue general BroadView +commands for querying the supported features of BroadView, etc. # Classes -The following describes the major classes in the library. +The following describes the major classes in the library. + +## General + +The broadview.py file in config contains general configuration classes for +BroadView. + +The following briefly summarizes these classes. For example usage, see the +unit test code in broadview.py, or the bv-ctl.py application. + +### GetSwitchProperties + +This command is used to retrieve the switch properties. + +### GetSystemFeature + +This command is used to retrieve the current configuration of the System +module on the Agent. ## BST Configuration and Data Gathering @@ -109,17 +141,17 @@ the configuration of thresholds for the various statistics (realms) that are supported by BST. The following is a list of these subclasses, one for each supported BST realm: -device - ConfigureDeviceThreshold -egress-cpu-queue - ConfigureEgressCpuQueueThreshold -egress-rqe-queue - ConfigureEgressRqeQueueThreshold -egress-port-service-pool - ConfigureEgressPortServicePoolThreshold -egress-service-pool - ConfigureEgressServicePoolThreshold -egress-uc-queue - ConfigureEgressUcQueueThreshold -egress-uc-queue-group - ConfigureEgressUcQueueGroupThreshold -egress-mc-queue - ConfigureEgressMcQueueThreshold -ingress-port-priority-group - ConfigureIngressPortPriorityGroupThreshold -ingress-port-service-pool - ConfigureIngressPortServicePoolThreshold -ingress-service-pool - ConfigureIngressServicePoolThreshold +* device - ConfigureDeviceThreshold +* egress-cpu-queue - ConfigureEgressCpuQueueThreshold +* egress-rqe-queue - ConfigureEgressRqeQueueThreshold +* egress-port-service-pool - ConfigureEgressPortServicePoolThreshold +* egress-service-pool - ConfigureEgressServicePoolThreshold +* egress-uc-queue - ConfigureEgressUcQueueThreshold +* egress-uc-queue-group - ConfigureEgressUcQueueGroupThreshold +* egress-mc-queue - ConfigureEgressMcQueueThreshold +* ingress-port-priority-group - ConfigureIngressPortPriorityGroupThreshold +* ingress-port-service-pool - ConfigureIngressPortServicePoolThreshold +* ingress-service-pool - ConfigureIngressServicePoolThreshold ### ClearBSTStatistics @@ -152,6 +184,88 @@ The class BSTParser (found in bst/bst_parser.py) accepts the JSON payload that is sent by a BroadView agent for BST notifications and responses that contain BST threshold reports. +## Packet Trace Configuration + +The pt.py file in config contains various classes that wrap the BroadView +packet trace protocol. + +The following briefly summarizes these classes. For example usage, see the +unit test code in pt.py, or the bv-ptctl.py application. + +### ConfigurePacketTraceFeature + +This class can be used to provide general configuration of the BroadView +packet trace component. + +### ConfigurePacketTraceDropReason + +This command configures the agent to send a copy of dropped packets and/or +trace-profile to requestor asynchronously. + +### CancelPacketTraceProfile + +This command is used to cancel the trace-profile request previously initiated +by GetPacketTraceProfile. + +### CancelPacketTraceLAGResolution + +This command is used to cancel the lag-resolution request previously +initiated by GetPacketTraceLAGResolution. + +### CancelPacketTraceECMPResolution + +This command is used to cancel the ecmp-resolution request previously +initiated by GetPacketTraceECMPResolution. + +### CancelPacketTraceSendDropPacket + +This command is used to cancel the send-dropped-packet request for a given +list of ports. This command allows canceling of send-dropped-packet request +for multiple drop reasons at a time. + +### CancelPacketTraceDropCounterReport + +This command is used to cancel the drop-counter-report request for a given +list of ports. This command allows canceling of drop-counter-report request +for multiple drop reasons at a time. + +### GetPacketTraceFeature + +This command is used to retrieve the current configuration of the Packet Trace +functionality on the Agent + +### GetPacketTraceLAGResolution + +This command is used to retrieve the LAG resolution for the given packet. + +### GetPacketTraceECMPResolution + +This command is used to retrieve the ECMP resolution for the given packet. + +### GetPacketTraceProfile + +This command is used to retrieve the trace-profile for the given packet. + +### GetPacketTraceDropReason + +This command is used to retrieve the current configured drop reasons on the +Broadcom ASIC. + +### GetPacketTraceDropCounterReport + +This command is used to retrieve the drop counter-report. + +### GetPacketTraceSupportedDropReasons + +This command is used to retrieve the supported drop reasons on the Broadcom +ASIC. + +## PTParser Object + +The class PTParser (found in pt/pt_parser.py) accepts the JSON payload +that is sent by a BroadView agent for PacketTrace, and converts this +payload into Python objects. It provides an API for accessing these objects. + ## Unit tests To ensure that broadview-lib is decoupled from any (and all) OpenStack diff --git a/broadview_lib/config/pt.py b/broadview_lib/config/pt.py index 98ef76f..d1bc8c2 100644 --- a/broadview_lib/config/pt.py +++ b/broadview_lib/config/pt.py @@ -355,7 +355,7 @@ class GetPacketTraceLAGResolution(AgentAPI): params["packet"] = self.__packet params["port-list"] = self.__port_list params["collection-interval"] = self.__collection_interval - params["drop-packet"] = self.__drop_packet = 1 if self.__drop_packet else 0 + params["drop-packet"] = 1 if self.__drop_packet else 0 ret["asic-id"] = self.__asic_id ret["params"] = params @@ -414,7 +414,7 @@ class GetPacketTraceECMPResolution(AgentAPI): params["packet"] = self.__packet params["port-list"] = self.__port_list params["collection-interval"] = self.__collection_interval - params["drop-packet"] = self.__drop_packet = 1 if self.__drop_packet else 0 + params["drop-packet"] = 1 if self.__drop_packet else 0 ret["asic-id"] = self.__asic_id ret["params"] = params @@ -473,7 +473,7 @@ class GetPacketTraceProfile(AgentAPI): params["packet"] = self.__packet params["port-list"] = self.__port_list params["collection-interval"] = self.__collection_interval - params["drop-packet"] = self.__drop_packet = 1 if self.__drop_packet else 0 + params["drop-packet"] = 1 if self.__drop_packet else 0 ret["asic-id"] = self.__asic_id ret["params"] = params diff --git a/broadview_lib/pt/pt_parser.py b/broadview_lib/pt/pt_parser.py index ae22711..22d71d4 100644 --- a/broadview_lib/pt/pt_parser.py +++ b/broadview_lib/pt/pt_parser.py @@ -66,7 +66,11 @@ class PTParser(): def _handlePacketTraceProfile(self, data): ret = True - report = data["report"] + try: + report = data["report"] + except: + ret = False + report = [] for x in report: t = packet_trace_profile.PacketTraceProfile() if "port" in x: @@ -92,7 +96,11 @@ class PTParser(): def _handlePacketTraceLAGResolution(self, data): ret = True - report = data["report"] + try: + report = data["report"] + except: + ret = False + report = [] for x in report: t = packet_trace_lag_resolution.PacketTraceLAGResolution() if "port" in x: @@ -113,7 +121,11 @@ class PTParser(): def _handlePacketTraceECMPResolution(self, data): ret = True - report = data["report"] + try: + report = data["report"] + except: + report = [] + ret = False for x in report: t = packet_trace_ecmp_resolution.PacketTraceECMPResolution() if "port" in x: @@ -134,7 +146,11 @@ class PTParser(): def _handlePacketTraceDropReason(self, data): ret = True - report = data["result"] + try: + report = data["result"] + except: + report = [] + ret = False for x in report: t = packet_trace_drop_reason.PacketTraceDropReason() ret = t.parse(x) @@ -164,7 +180,11 @@ class PTParser(): def _handlePacketTraceDropCounterReport(self, data): ret = True - report = data["report"] + try: + report = data["report"] + except: + ret = False + report = [] for x in report: t = packet_trace_drop_counter_report.PacketTraceDropCounterReport() ret = t.parse(x) diff --git a/broadview_lib/tools/bv-ptctl.py b/broadview_lib/tools/bv-ptctl.py new file mode 100644 index 0000000..fdc9a0c --- /dev/null +++ b/broadview_lib/tools/bv-ptctl.py @@ -0,0 +1,688 @@ +#!/usr/bin/python + +# (C) Copyright Broadcom Corporation 2016 +# +# 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. + +from broadview_lib.config.pt import * +import sys +import json + +class PTCommand(): + def __init__(self): + self._timeout = 30 + self.__cmds = { + "cfg-feature" : self.handleCfgFeature, + "cfg-drop-reason" : self.handleUnimplemented, + "cancel-profile" : self.handleCancelProfile, + "cancel-lag-resolution" : self.handleCancelLAGResolution, + "cancel-ecmp-resolution" : self.handleCancelECMPResolution, + "cancel-send-drop-packet" : self.handleUnimplemented, + "cancel-drop-counter-report" : self.handleUnimplemented, + "get-feature" : self.handleGetFeature, + "get-lag-resolution" : self.handleGetLAGResolution, + "get-ecmp-resolution" : self.handleGetECMPResolution, + "get-profile" : self.handleGetProfile, + "get-drop-reason" : self.handleUnimplemented, + "get-drop-counter-report" : self.handleUnimplemented, + "get-supported-drop-reasons" : self.handleUnimplemented, + "help": self.handleHelp, + } + + self.__help = { + "cfg-feature" : self.helpCfgFeature, + "cfg-drop-reason" : self.helpUnimplemented, + "cancel-profile" : self.helpCancelProfile, + "cancel-lag-resolution" : self.helpCancelLAGResolution, + "cancel-ecmp-resolution" : self.helpCancelECMPResolution, + "cancel-send-drop-packet" : self.helpUnimplemented, + "cancel-drop-counter-report" : self.helpUnimplemented, + "get-feature" : self.helpGetFeature, + "get-lag-resolution" : self.helpGetLAGResolution, + "get-ecmp-resolution" : self.helpGetECMPResolution, + "get-profile" : self.helpGetProfile, + "get-drop-reason" : self.helpUnimplemented, + "get-drop-counter-report" : self.helpUnimplemented, + "get-supported-drop-reasons" : self.helpUnimplemented, + } + + def getTimeout(self, args): + timeout = 30 + usage = False + for x in args: + if "timeout:" in x: + v = x.split(":") + if len(v) == 2: + timeout = int(v[1]) + else: + print "invalid timeout" + usage = True + return usage, timeout + + def getASICHostPort(self, args): + usage = False + asic = "1" + port = 8080 + host = None + + for x in args: + if "asic-id:" in x: + v = x.split(":") + if len(v) == 2: + asic = v[1] + else: + print "invalid asic-id" + usage = True + if "host:" in x: + v = x.split(":") + if len(v) == 2: + host = v[1] + else: + print "invalid host" + usage = True + if "port:" in x: + v = x.split(":") + if len(v) == 2: + port = int(v[1]) + else: + print "invalid port" + usage = True + + if host == None: + # host is required + print "missing host" + usage = True + + return usage, asic, host, port + + def usage(self): + print "usage: %s cmd host:ipv4 [timeout:seconds] [port:port] [asic-id:id] [args]" % (sys.argv[0]) + print + print "Commands:" + print + for key, val in self.__help.iteritems(): + print + val(key) + + def handleHelp(self, args): + usage = True + + if len(args): + cmd = args[0] + if cmd in self.__help: + self.__help[cmd](cmd) + usage = None + + return usage, None + + def handleUnimplemented(self, args): + usage = True + ret = None + return usage, ret + + def helpUnimplemented(self, name): + print name + print + print "The {} command is currently not supported and may become deprecated".format(name) + + def handleCfgFeature(self, args): + usage = False + usage, asic, host, port = self.getASICHostPort(args) + usage, self._timeout = self.getTimeout(args) + if not usage: + x = ConfigurePacketTraceFeature(host, port) + x.setASIC(asic) + x.setEnable("enable" in args) + status = x.send(timeout=self._timeout) + if status != 200: + print "failure: %d" % (status) + + ret = None + return usage, ret + + def helpCfgFeature(self, name): + print name, "[args]" + print + print "args:" + print + print " enable" + + def handleCfgDropReason(self, args): + usage = False + usage, asic, host, port = self.getASICHostPort(args) + if not usage: + x = ConfigurePacketTraceDropReason(host, port) + for arg in args: + if "reason:" in arg: + v = arg.split(":") + if len(v) == 2: + v2 = v[1].split(",") + reason = [] + for y in v2: + reason.append(x) + x.setReason(reason) + else: + print "invalid reason: bad argument count" + usage = True + elif "port-list:" in arg: + v = arg.split(":") + if len(v) == 2: + v2 = v[1].split(",") + port_list = [] + for y in v2: + port_list.append(x) + x.setPortList(port_list) + else: + print "invalid port-list: bad argument count" + usage = True + elif "send-dropped-packet:" in arg: + v = arg.split(":") + if len(v) == 2: + x.setSendDroppedPacket(v[1] == 1) + else: + print "invalid send-dropped-packet: bad argument count" + usage = True + elif "trace-profile:" in arg: + v = arg.split(":") + if len(v) == 2: + x.setTraceProfile(int(v[1]) == 1) + else: + print "invalid trace-profile: bad argument count" + usage = True + elif "packet-count:" in arg: + v = arg.split(":") + if len(v) == 2: + x.setPacketCount(int(v[1])) + else: + print "invalid packet-count: bad argument count" + usage = True + elif "packet-threshold:" in arg: + v = arg.split(":") + if len(v) == 2: + x.setPacketThreshold(int(v[1])) + else: + print "invalid packet-threshold: bad argument count" + usage = True + + x.setASIC(asic) + status = x.send(self._timeout) + if status != 200: + print "failure: %d" % (status) + + ret = None + return usage, ret + + def helpCfgDropReason(self, name): + print name, "[args]" + print + print "args:" + print + print " reason:reason[,reason][,reason]...[,reason]" + print " port-list:port[,port][,port]...[,port]" + print " send-dropped-packet:[0|1]" + print " trace-profile:[0|1]" + print " packet-count:n" + print " packet-threshold:n" + + def handleCancelProfile(self, args): + usage = False + usage, asic, host, port = self.getASICHostPort(args) + if not usage: + x = CancelPacketTraceProfile(host, port) + x.setASIC(asic) + status = x.send(self._timeout) + if status != 200: + print "failure: %d" % (status) + + ret = None + return usage, ret + + def helpCancelProfile(self, name): + print name + + def handleCancelLAGResolution(self, args): + usage = False + usage, asic, host, port = self.getASICHostPort(args) + if not usage: + x = CancelPacketTraceLAGResolution(host, port) + x.setASIC(asic) + status = x.send(self._timeout) + if status != 200: + print "failure: %d" % (status) + + ret = None + return usage, ret + + def helpCancelLAGResolution(self, name): + print name + + def handleCancelECMPResolution(self, args): + usage = False + usage, asic, host, port = self.getASICHostPort(args) + if not usage: + x = CancelPacketTraceECMPResolution(host, port) + x.setASIC(asic) + status = x.send(self._timeout) + if status != 200: + print "failure: %d" % (status) + + ret = None + return usage, ret + + def helpCancelECMPResolution(self, name): + print name + + def handleCancelSendDropPacket(self, args): + usage = False + usage, asic, host, port = self.getASICHostPort(args) + if not usage: + x = CancelPacketTraceSendDropPacket(host, port) + for arg in args: + if "drop-reason:" in arg: + v = arg.split(":") + if len(v) == 2: + v2 = v[1].split(",") + reason = [] + for y in v2: + reason.append(x) + x.setDropReason(reason) + else: + print "invalid drop-reason: bad argument count" + usage = True + elif "port-list:" in arg: + v = arg.split(":") + if len(v) == 2: + v2 = v[1].split(",") + port_list = [] + for y in v2: + port_list.append(x) + x.setPortList(port_list) + else: + print "invalid port-list: bad argument count" + usage = True + + x.setASIC(asic) + status = x.send(self._timeout) + if status != 200: + print "failure: %d" % (status) + + ret = None + return usage, ret + + def helpCancelSendDropPacket(self, name): + print name, "[args]" + print + print "args:" + print + print " drop-reason:reason[,reason][,reason]...[,reason]" + print " port-list:port[,port][,port]...[,port]" + + def handleCancelDropCounterReport(self, args): + usage = False + usage, asic, host, port = self.getASICHostPort(args) + if not usage: + x = CancelPacketTraceDropCounterReport(host, port) + for arg in args: + if "drop-reason:" in arg: + v = arg.split(":") + if len(v) == 2: + v2 = v[1].split(",") + reason = [] + for y in v2: + reason.append(x) + x.setDropReason(reason) + else: + print "invalid drop-reason: bad argument count" + usage = True + elif "port-list:" in arg: + v = arg.split(":") + if len(v) == 2: + v2 = v[1].split(",") + port_list = [] + for y in v2: + port_list.append(x) + x.setPortList(port_list) + else: + print "invalid port-list: bad argument count" + usage = True + + x.setASIC(asic) + status = x.send(self._timeout) + if status != 200: + print "failure: %d" % (status) + + ret = None + return usage, ret + + def helpCancelDropCounterReport(self, name): + print name, "[args]" + print + print "args:" + print + print " drop-reason:reason[,reason][,reason]...[,reason]" + print " port-list:port[,port][,port]...[,port]" + + def handleGetFeature(self, args): + usage = False + usage, asic, host, port = self.getASICHostPort(args) + if not usage: + x = GetPacketTraceFeature(host, port) + x.setASIC(asic) + status = x.send(self._timeout) + if status == 200: + ret = json.dumps(x.getJSON()) + print ret + else: + print "failure: %d" % (status) + + ret = None + return usage, ret + + def helpGetFeature(self, name): + print name + + def handleGetLAGResolution(self, args): + usage = False + usage, asic, host, port = self.getASICHostPort(args) + if not usage: + x = GetPacketTraceLAGResolution(host, port) + for arg in args: + if "drop-packet:" in arg: + v = arg.split(":") + if len(v) == 2: + x.setDropPacket(int(v[1]) == 1) + else: + print "invalid drop-packet: bad argument count" + usage = True + elif "packet:" in arg: + v = arg.split(":") + if len(v) == 2: + x.setPacket(v[1]) + else: + print "invalid packet: bad argument count" + usage = True + elif "port-list:" in arg: + v = arg.split(":") + if len(v) == 2: + v2 = v[1].split(",") + port_list = [] + for y in v2: + port_list.append(x) + x.setPortList(port_list) + else: + print "invalid port-list: bad argument count" + usage = True + elif "collection-interval:" in arg: + v = arg.split(":") + if len(v) == 2: + x.setCollectionInterval(int(v[1])) + else: + print "invalid collection-interval: bad argument count" + usage = True + + x.setASIC(asic) + status = x.send(self._timeout) + if status == 200: + ret = json.dumps(x.getJSON()) + print ret + else: + print "failure: %d" % (status) + + ret = None + return usage, ret + + def helpGetLAGResolution(self, name): + print name, "[args]" + print + print "args:" + print + print " packet: packet" + print " port-list:port[,port][,port]...[,port]" + print " collection-interval: interval" + print " drop-packet: [0|1]" + + def handleGetECMPResolution(self, args): + usage = False + usage, asic, host, port = self.getASICHostPort(args) + if not usage: + x = GetPacketTraceECMPResolution(host, port) + for arg in args: + if "drop-packet:" in arg: + v = arg.split(":") + if len(v) == 2: + x.setDropPacket(int(v[1]) == 1) + else: + print "invalid drop-packet: bad argument count" + usage = True + elif "packet:" in arg: + v = arg.split(":") + if len(v) == 2: + x.setPacket(v[1]) + else: + print "invalid packet: bad argument count" + usage = True + elif "port-list:" in arg: + v = arg.split(":") + if len(v) == 2: + v2 = v[1].split(",") + port_list = [] + for y in v2: + port_list.append(x) + x.setPortList(port_list) + else: + print "invalid port-list: bad argument count" + usage = True + elif "collection-interval:" in arg: + v = arg.split(":") + if len(v) == 2: + x.setCollectionInterval(int(v[1])) + else: + print "invalid collection-interval: bad argument count" + usage = True + + x.setASIC(asic) + status = x.send(self._timeout) + if status == 200: + ret = json.dumps(x.getJSON()) + print ret + else: + print "failure: %d" % (status) + + ret = None + return usage, ret + + def helpGetECMPResolution(self, name): + print name, "[args]" + print + print "args:" + print + print " packet: packet" + print " port-list:port[,port][,port]...[,port]" + print " collection-interval: interval" + print " drop-packet: [0|1]" + + def handleGetProfile(self, args): + usage = False + usage, asic, host, port = self.getASICHostPort(args) + if not usage: + x = GetPacketTraceProfile(host, port) + for arg in args: + v = arg.split(":") + if "drop-packet:" in arg: + v = arg.split(":") + if len(v) == 2: + x.setDropPacket(int(v[1]) == 1) + else: + print "invalid drop-packet: bad argument count" + usage = True + elif "packet:" in arg: + v = arg.split(":") + if len(v) == 2: + x.setPacket(v[1]) + else: + print "invalid packet: bad argument count" + usage = True + elif "port-list:" in arg: + v = arg.split(":") + if len(v) == 2: + v2 = v[1].split(",") + port_list = [] + for y in v2: + port_list.append(x) + x.setPortList(port_list) + else: + print "invalid port-list: bad argument count" + usage = True + elif "collection-interval:" in arg: + v = arg.split(":") + if len(v) == 2: + x.setCollectionInterval(int(v[1])) + else: + print "invalid collection-interval: bad argument count" + usage = True + + x.setASIC(asic) + status = x.send(self._timeout) + if status == 200: + ret = json.dumps(x.getJSON()) + print ret + else: + print "failure: %d" % (status) + + ret = None + return usage, ret + + def helpGetProfile(self, name): + print name, "[args]" + print + print "args:" + print + print " packet: packet" + print " port-list:port[,port][,port]...[,port]" + print " collection-interval: interval" + print " drop-packet: [0|1]" + + def handleGetDropReason(self, args): + usage = False + usage, asic, host, port = self.getASICHostPort(args) + if not usage: + x = GetPacketTraceDropReason(host, port) + x.setASIC(asic) + status = x.send(self._timeout) + if status == 200: + ret = json.dumps(x.getJSON()) + print ret + else: + print "failure: %d" % (status) + + ret = None + return usage, ret + + def helpGetDropReason(self, name): + print name + + def handleGetDropCounterReport(self, args): + usage = False + usage, asic, host, port = self.getASICHostPort(args) + if not usage: + x = GetPacketTraceDropCounterReport(host, port) + for arg in args: + if "drop-reason:" in arg: + v = arg.split(":") + if len(v) == 2: + v2 = v[1].split(",") + reason = [] + for y in v2: + reason.append(x) + x.setDropReason(reason) + else: + print "invalid drop-reason: bad argument count" + usage = True + elif "port-list:" in arg: + v = arg.split(":") + if len(v) == 2: + v2 = v[1].split(",") + port_list = [] + for y in v2: + port_list.append(x) + x.setPortList(port_list) + else: + print "invalid port-list: bad argument count" + usage = True + elif "collection-interval:" in arg: + v = arg.split(":") + if len(v) == 2: + x.setCollectionInterval(int(v[1])) + else: + print "invalid collection-interval: bad argument count" + + x.setASIC(asic) + status = x.send(self._timeout) + if status == 200: + ret = json.dumps(x.getJSON()) + print ret + else: + print "failure: %d" % (status) + + ret = None + return usage, ret + + def helpGetDropCounterReport(self, name): + print name, "[args]" + print + print "args:" + print + print " drop-reason:reason[,reason][,reason]...[,reason]" + print " port-list:port[,port][,port]...[,port]" + print " collection-interval:interval" + + def handleGetSupportedDropReasons(self, args): + usage = False + usage, asic, host, port = self.getASICHostPort(args) + if not usage: + x = GetPacketTraceSupportedDropReasons(host, port) + x.setASIC(asic) + status = x.send(self._timeout) + if status == 200: + ret = json.dumps(x.getJSON()) + print ret + else: + print "failure: %d" % (status) + + ret = None + return usage, ret + + def helpGetSupportedDropReasons(self, name): + print name + + def isCmd(self, cmd): + return cmd in self.__cmds + + def handle(self, args): + usage = True + ret = {} + status = False + if len(args): + cmd = args.pop(0) + if self.isCmd(cmd): + usage, ret = self.__cmds[cmd](args) + return usage, ret + +def main(argv): + x = PTCommand() + usage, ret = x.handle(argv) + if usage: + x.usage() + +if __name__ == "__main__": + main(sys.argv[1:]) diff --git a/broadview_lib/tools/examples.sh b/broadview_lib/tools/examples.sh index d222d07..bf26255 100644 --- a/broadview_lib/tools/examples.sh +++ b/broadview_lib/tools/examples.sh @@ -15,46 +15,64 @@ host=10.14.244.128 port=8082 -echo "********** get-switch-properties **********" -python bv-ctl.py get-switch-properties timeout:30 host:$host port:$port echo "********** get-system-feature **********" python bv-ctl.py get-system-feature timeout:30 host:$host port:$port -echo "********** cfg-feature **********" +echo "********** get-switch-properties **********" +python bv-ctl.py get-switch-properties timeout:30 host:$host port:$port + +echo "********** bst cfg-feature **********" python bv-bstctl.py cfg-feature timeout:30 host:$host port:$port enable send_async_reports -echo "********** get-feature **********" +echo "********** bst get-feature **********" python bv-bstctl.py get-feature host:$host port:$port -echo "********** cfg-tracking **********" +echo "********** bst cfg-tracking **********" python bv-bstctl.py cfg-tracking host:$host port:$port track_ingress_port_priority_group -echo "********** get-tracking **********" +echo "********** bst get-tracking **********" python bv-bstctl.py get-tracking host:$host port:$port -echo "********** clr-statistics **********" +echo "********** bst clr-statistics **********" python bv-bstctl.py clr-statistics host:$host port:$port -echo "********** clr-thresholds **********" +echo "********** bst clr-thresholds **********" python bv-bstctl.py clr-thresholds host:$host port:$port -echo "********** cfg-thresholds **********" +echo "********** bst cfg-thresholds **********" python bv-bstctl.py get-thresholds host:$host port:$port include_ingress_port_priority_group include_ingress_port_service_pool include_ingress_service_pool include_egress_port_service_pool include_egress_service_pool -echo "********** get-report **********" +echo "********** bst get-report **********" python bv-bstctl.py get-report host:$host port:$port include_ingress_port_priority_group include_ingress_port_service_pool include_ingress_service_pool include_egress_port_service_pool include_egress_service_pool -echo "********** cfg-thresholds device **********" +echo "********** bst cfg-thresholds device **********" python bv-bstctl.py cfg-thresholds host:$host port:$port device:10100 -echo "********** cfg-thresholds egress-cpu-queue **********" +echo "********** bst cfg-thresholds egress-cpu-queue **********" python bv-bstctl.py cfg-thresholds host:$host port:$port egress-cpu-queue:5:20202 -echo "********** cfg-thresholds egress-rqe-queue **********" +echo "********** bst cfg-thresholds egress-rqe-queue **********" python bv-bstctl.py cfg-thresholds host:$host port:$port egress-rqe-queue:6:30130 -echo "********** cfg-thresholds egress-port-service-pool **********" +echo "********** bst cfg-thresholds egress-port-service-pool **********" python bv-bstctl.py cfg-thresholds host:$host port:$port egress-port-service-pool:"2":2:204556:30000:40000:5000 -echo "********** cfg-thresholds egress-service-pool **********" +echo "********** bst cfg-thresholds egress-service-pool **********" python bv-bstctl.py cfg-thresholds host:$host port:$port egress-service-pool:2:30:40:50 -echo "********** cfg-thresholds egress-uc-queue **********" +echo "********** bst cfg-thresholds egress-uc-queue **********" python bv-bstctl.py cfg-thresholds host:$host port:$port egress-uc-queue:5:20200 -echo "********** cfg-thresholds egress-uc-queue-group **********" +echo "********** bst cfg-thresholds egress-uc-queue-group **********" python bv-bstctl.py cfg-thresholds host:$host port:$port egress-uc-queue-group:5:204 -echo "********** cfg-thresholds egress-mc-queue **********" +echo "********** bst cfg-thresholds egress-mc-queue **********" python bv-bstctl.py cfg-thresholds host:$host port:$port egress-mc-queue:5:204:10500 -echo "********** cfg-thresholds ingress-port-priority-group **********" +echo "********** bst cfg-thresholds ingress-port-priority-group **********" python bv-bstctl.py cfg-thresholds host:$host port:$port ingress-port-priority-group:"5":2:20456:40404 -echo "********** cfg-thresholds ingress-port-service-pool **********" +echo "********** bst cfg-thresholds ingress-port-service-pool **********" python bv-bstctl.py cfg-thresholds host:$host port:$port ingress-port-service-pool:"4":2:50505 -echo "********** cfg-thresholds ingress-service-pool **********" +echo "********** bst cfg-thresholds ingress-service-pool **********" python bv-bstctl.py cfg-thresholds host:$host port:$port ingress-service-pool:2:56783 -# + +echo "********** pt cfg-feature **********" +python bv-ptctl.py cfg-feature timeout:30 host:$host port:$port enable +echo "********** pt get-feature **********" +python bv-ptctl.py get-feature timeout:30 host:$host port:$port +echo "********** pt cfg-feature **********" +python bv-ptctl.py cfg-feature timeout:30 host:$host port:$port disable +echo "********** pt get-feature **********" +python bv-ptctl.py get-feature timeout:30 host:$host port:$port +echo "********** pt cancel-profile **********" +python bv-ptctl.py cancel-profile timeout:30 host:$host port:$port +echo "********** pt cancel-lag-resolution **********" +python bv-ptctl.py cancel-lag-resolution timeout:30 host:$host port:$port +echo "********** pt cancel-ecmp-resolution **********" +python bv-ptctl.py cancel-ecmp-resolution timeout:30 host:$host port:$port +echo "********** pt get-profile **********" +python bv-ptctl.py get-profile drop-packet:1 collection-interval:45 timeout:30 host:$host port:$port +