diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst new file mode 100644 index 0000000..e5eb444 --- /dev/null +++ b/CONTRIBUTING.rst @@ -0,0 +1,17 @@ +If you would like to contribute to the development of OpenStack, you must +follow the steps in this page: + + http://docs.openstack.org/infra/manual/developers.html + +If you already have a good understanding of how the system works and your +OpenStack accounts are set up, you can skip to the development workflow +section of this documentation to learn how changes to OpenStack should be +submitted for review via the Gerrit tool: + + http://docs.openstack.org/infra/manual/developers.html#development-workflow + +Pull requests submitted through GitHub will be ignored. + +Bugs should be filed on Launchpad, not GitHub: + + https://bugs.launchpad.net/broadview-lib \ No newline at end of file diff --git a/HACKING.rst b/HACKING.rst new file mode 100644 index 0000000..0855853 --- /dev/null +++ b/HACKING.rst @@ -0,0 +1,4 @@ +broadview-lib Style Commandments +=============================================== + +Read the OpenStack Style Commandments http://docs.openstack.org/developer/hacking/ \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..67db858 --- /dev/null +++ b/LICENSE @@ -0,0 +1,175 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..90f8a7a --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,6 @@ +include AUTHORS +include ChangeLog +exclude .gitignore +exclude .gitreview + +global-exclude *.pyc \ No newline at end of file diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..26017db --- /dev/null +++ b/README.rst @@ -0,0 +1,176 @@ +# Overview + +`broadview-lib` is a library that provides an interface to Broadcom's +BroadView instrumentation functionality. + +## What is BroadView? + +BroadView is an open source software suite that enables advanced analytics in +next-generation networks. Troubleshooting network problems and ensuring +application SLAs are very complex tasks. In cloud networks, overlay +technologies reduce visibility into packet flows, thereby making it even more +difficult to analyze issues and ensure SLAs. OpenStack projects such as +Monasca provide monitoring-as-a-service to deliver usage metrics from +applications and tenant networks; however, underlay monitoring is not +supported. Ensuring application SLAs requires overlay mapping to the underlay, +and optimal performance of underlay infrastructure is essential. + +BroadView-based solutions enable programmable access to underlay monitoring, +facilitating applications to gather advanced analytics in a highly scalable +manner. + +Buffer Statistics Tracking (BST) is one of the most important features for +enabling rich congestion analytics. Network Traffic is bursty by nature and +microbursts occur when there is transient congestion. Microbursts are difficult +to detect using traditional port drop counts. Broadcom silicon provides the +ability to monitor MMU buffer utilization counts as part of the BST feature. +It provides network administrators and applications improved telemetry on +the usage of various ingress and egress buffers, without disrupting regular +packet forwarding operations. There are thousands of counters available across +various ports, port groups, and service pools that can be utilized by the +applications for instantaneous monitoring in a scalable way. BST tracks +ingress-, egress-, and device-based use-counts for both unicast and multicast +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 + +## 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. + +broadview-lib is designed to provide the underlying infrastructure that is +needed for the development of Python applications that interact with a +BroadView agent. Using broadview-lib, a Python application can configure a +BroadView agent and make calls on the agent to perform various tasks. +broadview-lib also provides classes that can parse notifications and data sent +to an application by a BroadView agent. broadview-lib can be thought of as +presenting an object-model above the JSON-RPC protocol of the BroadView agent. + +As such, broadview-lib forms the basis of other contributions that integrate +BroadView functionality into OpenStack, and represents an OpenStack-neutral +view of BroadView's API. The library can be used by other projects outside of +OpenStack, if desired. + +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. + +# 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: + +python bv-bstcfg.py help + + +bv-bstctl.py writes its output to stdout in JSON format. + +The file examples.sh in the tools directory contains usage example for the +bv-bstcfg application and can be used to exercise bv-bsctl. + +# Classes + +The following describes the major classes in the library. + +## BST Configuration and Data Gathering + +The bst.py file in config contains various configuration and data gathering +classes. + +The following briefly summarizes these classes. For example usage, see the +unit test code in bst.py, or the bv-bstctl.py application. + +### ConfigureBSTFeature + +This class can be used to provide general configuration of the BroadView BST +component. + +### ConfigureBSTTracking + +This class is used to enable or disable the tracking of various BST statistics. + +### ConfigureBSTThresholds + +This base class is inherited by the several subclasses, each which allow for +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 + +### ClearBSTStatistics + +This class supports the resetting of all BST statistics in the agent. + +### ClearBSTThresholds + +This class supports the resetting of all BST thresholds in the agent. + +### GetBSTFeature + +This class reports the various settings of the BroadView BST component. + +### GetBSTTracking + +This class reports the tracking settings for the BroadView BST component. +The tracking status of each supported realm is reported. + +### GetBSTThresholds + +This class reports the threshold settings for the various BST realms. + +### GetBSTReport + +This class reports the current buffer statistics for the specified realms. + +## BST Object + +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. + +## Unit tests + +To ensure that broadview-lib is decoupled from any (and all) OpenStack +dependencies, unit tests are implemented by each of the individual Python +modules using the Python unittest framework. + +# License + +(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. + diff --git a/babel.cfg b/babel.cfg new file mode 100644 index 0000000..efceab8 --- /dev/null +++ b/babel.cfg @@ -0,0 +1 @@ +[python: **.py] diff --git a/broadview_lib/__init__.py b/broadview_lib/__init__.py new file mode 100644 index 0000000..6b227e8 --- /dev/null +++ b/broadview_lib/__init__.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- + +# 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 pbr.version +# +# +#__version__ = pbr.version.VersionInfo( +# 'broadview_lib').version_string() diff --git a/broadview_lib/bst/__init__.py b/broadview_lib/bst/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/broadview_lib/bst/bst_parser.py b/broadview_lib/bst/bst_parser.py new file mode 100644 index 0000000..b156884 --- /dev/null +++ b/broadview_lib/bst/bst_parser.py @@ -0,0 +1,1271 @@ +# (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. + +import devicedata +import egress_cpu_queue +import egress_rqe_queue +import egress_uc_queue +import egress_mc_queue +import egress_service_pool +import egress_port_service_pool +import egress_uc_queue_group +import ingress_port_priority_group +import ingress_port_service_pool +import ingress_service_pool +import time +import unittest + +class ReportTypes: + Report, Trigger, Threshold = range(3) + +class BSTParser(): + def __init__(self): + self.__reportType = None + self.__devicedata = None + self.__ingress_port_priority_group = [] + self.__ingress_port_service_pool = [] + self.__ingress_service_pool = [] + self.__egress_cpu_queue = [] + self.__egress_mc_queue = [] + self.__egress_port_service_pool = [] + self.__egress_rqe_queue = [] + self.__egress_service_pool = [] + self.__egress_uc_queue = [] + self.__egress_uc_queue_group = [] + + self.__handlers = { + "device": self.handleDeviceRealm, + "ingress-port-priority-group": self.handleIngressPortPriorityGroupRealm, + "ingress-port-service-pool": self.handleIngressPortServicePoolRealm, + "ingress-service-pool": self.handleIngressServicePoolRealm, + "egress-cpu-queue": self.handleEgressCPUQueueRealm, + "egress-mc-queue": self.handleEgressMcQueueRealm, + "egress-port-service-pool": self.handleEgressPortServicePoolRealm, + "egress-rqe-queue": self.handleEgressRQEQueueRealm, + "egress-service-pool": self.handleEgressServicePoolRealm, + "egress-uc-queue": self.handleEgressUcQueueRealm, + "egress-uc-queue-group": self.handleEgressUcQueueGroupRealm } + + def getReportType(self): + return self.__reportType + + def getASICId(self): + return self.__asicId; + + def getTimestamp(self): + return self.__timestamp; + + def __repr__(self): + return "BST" + + def handleDeviceRealm(self, data): + self.__devicedata = devicedata.DeviceData() + self.__devicedata.parse(data) + + def getDeviceData(self): + return self.__devicedata + + def handleIngressPortPriorityGroupRealm(self, data): + for x in data: + t = ingress_port_priority_group.IngressPortPriorityGroup() + if "port" in x: + port = x["port"] + else: + port = None + t.parse(x["data"], port) + self.__ingress_port_priority_group.append(t) + + def getIngressPortPriorityGroup(self): + return self.__ingress_port_priority_group + + def handleIngressPortServicePoolRealm(self, data): + for x in data: + t = ingress_port_service_pool.IngressPortServicePool() + if "port" in x: + port = x["port"] + else: + port = None + t.parse(x["data"], port) + self.__ingress_port_service_pool.append(t) + + def getIngressPortServicePool(self): + return self.__ingress_port_service_pool + + def handleIngressServicePoolRealm(self, data): + t = ingress_service_pool.IngressServicePool() + t.parse(data) + self.__ingress_service_pool.append(t) + + def getIngressServicePool(self): + return self.__ingress_service_pool + + def handleEgressCPUQueueRealm(self, data): + t = egress_cpu_queue.EgressCPUQueue() + t.parse(data) + self.__egress_cpu_queue.append(t) + + def getEgressCPUQueue(self): + return self.__egress_cpu_queue + + def handleEgressMcQueueRealm(self, data): + t = egress_mc_queue.EgressMcQueue() + t.parse(data) + self.__egress_mc_queue.append(t) + + def getEgressMcQueue(self): + return self.__egress_mc_queue + + def handleEgressPortServicePoolRealm(self, data): + for x in data: + t = egress_port_service_pool.EgressPortServicePool() + if "port" in x: + port = x["port"] + else: + port = None + t.parse(x["data"], port) + self.__egress_port_service_pool.append(t) + + def getEgressPortServicePool(self): + return self.__egress_port_service_pool + + def handleEgressRQEQueueRealm(self, data): + t = egress_rqe_queue.EgressRQEQueue() + t.parse(data) + self.__egress_rqe_queue.append(t) + + def getEgressRQEQueue(self): + return self.__egress_rqe_queue + + def handleEgressServicePoolRealm(self, data): + t = egress_service_pool.EgressServicePool() + t.parse(data) + self.__egress_service_pool.append(t) + + def getEgressServicePool(self): + return self.__egress_service_pool + + def handleEgressUcQueueRealm(self, data): + t = egress_uc_queue.EgressUcQueue() + t.parse(data) + self.__egress_uc_queue.append(t) + + def getEgressUcQueue(self): + return self.__egress_uc_queue + + def handleEgressUcQueueGroupRealm(self, data): + t = egress_uc_queue_group.EgressUcQueueGroup() + t.parse(data) + self.__egress_uc_queue_group.append(t) + + def getEgressUcQueueGroup(self): + return self.__egress_uc_queue_group + + def dispatchParser(self, report): + ret = True + if report["realm"] in self.__handlers: + ret = self.__handlers[report["realm"]](report["data"]) + return ret + + def process(self, data): + + ret = True + if self.valid(data): + if data["method"] == "get-bst-report": + self.__reportType = ReportTypes.Report + elif data["method"] == "trigger-report": + self.__reportType = ReportTypes.Trigger + elif data["method"] == "get-bst-thresholds": + self.__reportType = ReportTypes.Threshold + else: + ret = False + + if ret: + self.__asicId = data["asic-id"] + x = data["time-stamp"].strip() + self.__timestamp = time.strptime(x, "%Y-%m-%d - %H:%M:%S") + for x in data["report"]: + ret = self.dispatchParser(x) + if ret == False: + break + return ret + + def valid(self, data): + ret = True + keys = ["jsonrpc", "method", + "asic-id", "version", + "time-stamp", "report"] + + for x in keys: + if not x in data: + ret = False + break + + if ret: + if data["method"] != "get-bst-report" and \ + data["method"] != "trigger-report" and \ + data["method"] != "get-bst-thresholds": + ret = False + return ret + +class TestParser(unittest.TestCase): + + def setUp(self): + self.bst_report = { + "jsonrpc": "2.0", + "method": "get-bst-report", + "asic-id": "20", + "version": "1", + "time-stamp": "2014-11-18 - 00:15:04 ", + "report": [ + { + "realm": "device", + "data": 46 + }, { + "realm": "ingress-port-priority-group", + "data": [{ + "port": "2", + "data": [[5, 45500, 44450]] + }, { + "port": "3", + "data": [[6, 25500, 24450]] + }] + }, { + "realm": "ingress-port-service-pool", + "data": [{ + "port": "2", + "data": [[5, 324]] + }, { + "port": "3", + "data": [[6, 366]] + }] + }, { + "realm": "ingress-service-pool", + "data": [[1, 3240], [2, 3660]] + }, { + "realm": "egress-cpu-queue", + "data": [[3, 4566, 0]] + }, { + "realm": "egress-mc-queue", + "data": [[1, "1", 34, 89], [2, "4", 1244, 0], [3, "5", 0, 3]] + }, { + "realm": "egress-port-service-pool", + "data": [{ + "port": "2", + "data": [[5, 0, 324, 0]] + }, { + "port": "3", + "data": [[6, 0, 366, 0]] + }] + }, { + "realm": "egress-rqe-queue", + "data": [[2, 3333, 4444], [5, 25, 45]] + }, { + "realm": "egress-service-pool", + "data": [[2, 0, 0, 3240], [3, 3660, 0, 0]] + }, { + "realm": "egress-uc-queue", + "data": [[6, "0", 1111]] + }, { + "realm": "egress-uc-queue-group", + "data": [[6, 2222]] + }] + } + + self.trigger = { + "jsonrpc": "2.0", + "method": "trigger-report", + "asic-id": "20", + "version": "1", + "time-stamp": "2014-11-18 - 00:13:08 ", + "realm": "ingress-port-priority-group", + "counter": "um-share-buffer-count", + "port": "2", + "priority-group": "5", + "report": [ + { + "realm": "device", + "data": 46 + }, { + "realm": "ingress-port-priority-group", + + "data": [{ + "port": "2", + "data": [[5, 45500, 44450]] + }, { + "port": "3", + "data": [[6, 25500, 24450]] + }] + }, { + "realm": "ingress-port-service-pool", + "data": [{ + "port": "2", + "data": [[5, 324]] + }, { + "port": "3", + "data": [[6, 366]] + }] + }, { + "realm": "ingress-service-pool", + "data": [[1, 3240], [2, 3660]] + }, { + "realm": "egress-cpu-queue", + "data": [[3, 4566, 0]] + }, { + "realm": "egress-mc-queue", + "data": [[1, "1", 34, 89], [2, "4", 1244, 0], [3, "5", 0, 3]] + }, { + "realm": "egress-port-service-pool", + "data": [{ + "port": "2", + "data": [[5, 0, 324, 0]] + }, { + "port": "3", + "data": [[6, 0, 366, 0]] + }] + }, { + "realm": "egress-rqe-queue", + "data": [[2, 3333, 4444], [5, 25, 45]] + }, { + "realm": "egress-service-pool", + "data": [[2, 0, 0, 3240], [3, 3660, 0, 0]] + }, { + "realm": "egress-uc-queue", + "data": [[6, "0", 1111]] + }, { + "realm": "egress-uc-queue-group", + "data": [[6, 2222]] + }] + } + + self.thresholds = { + "jsonrpc": "2.0", + "method": "get-bst-thresholds", + "asic-id": "20", + "version": "1", + "time-stamp": "2014-11-14 - 00:15:04 ", + "report": [ + { + "realm": "device", + "data": 46 + }, { + "realm": "ingress-port-priority-group", + "data": [{ + "port": "2", + "data": [[5, 45500, 44450]] + }, { + "port": "3", + "data": [[6, 25500, 24450]] + }] + }, { + "realm": "ingress-port-service-pool", + "data": [{ + "port": "2", + "data": [[5, 324]] + }, { + "port": "3", + "data": [[6, 366]] + }] + }, { + "realm": "ingress-service-pool", + "data": [[1, 3240], [2, 3660]] + }, { + "realm": "egress-cpu-queue", + "data": [[3, 4566, 0]] + }, { + "realm": "egress-mc-queue", + "data": [[1, "1", 34, 89], [2, "4", 1244, 0], [3, "5", 0, 3]] + }, { + "realm": "egress-port-service-pool", + "data": [{ + "port": "2", + "data": [[5, 0, 324, 0]] + }, { + "port": "3", + "data": [[6, 0, 366, 0]] + }] + }, { + "realm": "egress-rqe-queue", + "data": [[2, 3333, 4444], [5, 25, 45]] + }, { + "realm": "egress-service-pool", + "data": [[2, 0, 0, 3240], [3, 3660, 0, 0]] + }, { + "realm": "egress-uc-queue", + "data": [[6, "0", 1111]] + }, { + "realm": "egress-uc-queue-group", + "data": [[6, 2222]] + }] + } + + def test_bst_report(self): + rep = BSTParser() + rep.process(self.bst_report) + val = rep.getReportType() + self.assertEqual(val, ReportTypes.Report) + + val = rep.getDeviceData() + self.assertEqual(val.getValue(), 46) + + val = rep.getIngressPortPriorityGroup() + + it = iter(val) + try: + n = next(it) + except: + self.assertEqual(False, True) + + subit = iter(n) + try: + n = next(subit) + except: + self.assertEqual(False, True) + + self.assertEqual(n.getPriorityGroup(), 5) + self.assertEqual(n.getUmShareBufferCount(), 45500) + self.assertEqual(n.getUmHeadroomBufferCount(), 44450) + self.assertEqual(n.getPort(), "2") + + try: + n = next(it) + except: + self.assertEqual(False, True) + + + subit = iter(n) + try: + n = next(subit) + except: + self.assertEqual(False, True) + + self.assertEqual(n.getPriorityGroup(), 6) + self.assertEqual(n.getUmShareBufferCount(), 25500) + self.assertEqual(n.getUmHeadroomBufferCount(), 24450) + self.assertEqual(n.getPort(), "3") + + val = rep.getIngressPortServicePool() + + it = iter(val) + try: + n = next(it) + except: + self.assertEqual(False, True) + + + subit = iter(n) + try: + n = next(subit) + except: + self.assertEqual(False, True) + + self.assertEqual(n.getServicePool(), 5) + self.assertEqual(n.getUmShareBufferCount(), 324) + self.assertEqual(n.getPort(), "2") + + try: + n = next(it) + except: + self.assertEqual(False, True) + + subit = iter(n) + try: + n = next(subit) + except: + self.assertEqual(False, True) + + self.assertEqual(n.getPort(), "3") + self.assertEqual(n.getServicePool(), 6) + self.assertEqual(n.getUmShareBufferCount(), 366) + + val = rep.getIngressServicePool() + + it = iter(val) + try: + n = next(it) + except: + self.assertEqual(False, True) + + subit = iter(n) + try: + n = next(subit) + except: + self.assertEqual(False, True) + + self.assertEqual(n.getServicePool(), 1) + self.assertEqual(n.getUmShareBufferCount(), 3240) + + try: + n = next(subit) + except: + self.assertEqual(False, True) + + self.assertEqual(n.getServicePool(), 2) + self.assertEqual(n.getUmShareBufferCount(), 3660) + + val = rep.getEgressCPUQueue() + + it = iter(val) + try: + n = next(it) + except: + self.assertEqual(False, True) + + subit = iter(n) + try: + n = next(subit) + except: + self.assertEqual(False, True) + + self.assertEqual(n.getQueue(), 3) + self.assertEqual(n.getCPUBufferCount(), 4566) + self.assertEqual(n.getCPUQueueEntries(), 0) + + val = rep.getEgressMcQueue() + + it = iter(val) + try: + n = next(it) + except: + self.assertEqual(False, True) + + subit = iter(n) + try: + n = next(subit) + except: + self.assertEqual(False, True) + + self.assertEqual(n.getQueue(), 1) + self.assertEqual(n.getMCBufferCount(), 34) + self.assertEqual(n.getMCQueueEntries(), 89) + + try: + n = next(subit) + except: + self.assertEqual(False, True) + + self.assertEqual(n.getQueue(), 2) + self.assertEqual(n.getMCBufferCount(), 1244) + self.assertEqual(n.getMCQueueEntries(), 0) + + try: + n = next(subit) + except: + self.assertEqual(False, True) + + self.assertEqual(n.getQueue(), 3) + self.assertEqual(n.getMCBufferCount(), 0) + self.assertEqual(n.getMCQueueEntries(), 3) + + val = rep.getEgressPortServicePool() + + it = iter(val) + + try: + n = next(it) + except: + self.assertEqual(False, True) + + subit = iter(n) + try: + n = next(subit) + except: + self.assertEqual(False, True) + + self.assertEqual(n.getServicePool(), 5) + self.assertEqual(n.getUmShareBufferCount(), 0) + self.assertEqual(n.getMCShareBufferCount(), 324) + self.assertEqual(n.getMCShareQueueEntries(), 0) + self.assertEqual(n.getPort(), "2") + + + try: + n = next(it) + except: + self.assertEqual(False, True) + + subit = iter(n) + try: + n = next(subit) + except: + self.assertEqual(False, True) + + self.assertEqual(n.getServicePool(), 6) + self.assertEqual(n.getUmShareBufferCount(), 0) + self.assertEqual(n.getMCShareBufferCount(), 366) + self.assertEqual(n.getMCShareQueueEntries(), 0) + self.assertEqual(n.getPort(), "3") + + val = rep.getEgressRQEQueue() + + it = iter(val) + try: + n = next(it) + except: + self.assertEqual(False, True) + + subit = iter(n) + try: + n = next(subit) + except: + self.assertEqual(False, True) + + self.assertEqual(n.getQueue(), 2) + self.assertEqual(n.getRQEBufferCount(), 3333) + self.assertEqual(n.getRQEQueueEntries(), 4444) + + try: + n = next(subit) + except: + self.assertEqual(False, True) + + self.assertEqual(n.getQueue(), 5) + self.assertEqual(n.getRQEBufferCount(), 25) + self.assertEqual(n.getRQEQueueEntries(), 45) + + val = rep.getEgressServicePool() + + it = iter(val) + try: + n = next(it) + except: + self.assertEqual(False, True) + + subit = iter(n) + try: + n = next(subit) + except: + self.assertEqual(False, True) + + self.assertEqual(n.getServicePool(), 2) + self.assertEqual(n.getUmShareBufferCount(), 0) + self.assertEqual(n.getMCShareBufferCount(), 0) + self.assertEqual(n.getMCShareQueueEntries(), 3240) + + try: + n = next(subit) + except: + self.assertEqual(False, True) + + self.assertEqual(n.getServicePool(), 3) + self.assertEqual(n.getUmShareBufferCount(), 3660) + self.assertEqual(n.getMCShareBufferCount(), 0) + self.assertEqual(n.getMCShareQueueEntries(), 0) + + val = rep.getEgressUcQueue() + + it = iter(val) + try: + n = next(it) + except: + self.assertEqual(False, True) + + subit = iter(n) + try: + n = next(subit) + except: + self.assertEqual(False, True) + + self.assertEqual(n.getQueue(), 6) + self.assertEqual(n.getPort(), "0") + self.assertEqual(n.getUcQueueBufferCount(), 1111) + + val = rep.getEgressUcQueueGroup() + + it = iter(val) + try: + n = next(it) + except: + self.assertEqual(False, True) + + subit = iter(n) + try: + n = next(subit) + except: + self.assertEqual(False, True) + + self.assertEqual(n.getQueueGroup(), 6) + self.assertEqual(n.getUcBufferCount(), 2222) + + def test_trigger(self): + rep = BSTParser() + rep.process(self.trigger) + val = rep.getReportType() + self.assertEqual(val, ReportTypes.Trigger) + + val = rep.getDeviceData() + self.assertEqual(val.getValue(), 46) + + val = rep.getIngressPortPriorityGroup() + + it = iter(val) + try: + n = next(it) + except: + self.assertEqual(False, True) + + subit = iter(n) + try: + n = next(subit) + except: + self.assertEqual(False, True) + + self.assertEqual(n.getPriorityGroup(), 5) + self.assertEqual(n.getUmShareBufferCount(), 45500) + self.assertEqual(n.getUmHeadroomBufferCount(), 44450) + self.assertEqual(n.getPort(), "2") + + try: + n = next(it) + except: + self.assertEqual(False, True) + + subit = iter(n) + try: + n = next(subit) + except: + self.assertEqual(False, True) + + self.assertEqual(n.getPriorityGroup(), 6) + self.assertEqual(n.getUmShareBufferCount(), 25500) + self.assertEqual(n.getUmHeadroomBufferCount(), 24450) + self.assertEqual(n.getPort(), "3") + + val = rep.getIngressPortServicePool() + + it = iter(val) + try: + n = next(it) + except: + self.assertEqual(False, True) + + subit = iter(n) + try: + n = next(subit) + except: + self.assertEqual(False, True) + + self.assertEqual(n.getServicePool(), 5) + self.assertEqual(n.getUmShareBufferCount(), 324) + self.assertEqual(n.getPort(), "2") + + try: + n = next(it) + except: + self.assertEqual(False, True) + + subit = iter(n) + try: + n = next(subit) + except: + self.assertEqual(False, True) + + self.assertEqual(n.getServicePool(), 6) + self.assertEqual(n.getUmShareBufferCount(), 366) + self.assertEqual(n.getPort(), "3") + + val = rep.getIngressServicePool() + + it = iter(val) + try: + n = next(it) + except: + self.assertEqual(False, True) + + subit = iter(n) + try: + n = next(subit) + except: + self.assertEqual(False, True) + + self.assertEqual(n.getServicePool(), 1) + self.assertEqual(n.getUmShareBufferCount(), 3240) + + try: + n = next(subit) + except: + self.assertEqual(False, True) + + self.assertEqual(n.getServicePool(), 2) + self.assertEqual(n.getUmShareBufferCount(), 3660) + + val = rep.getEgressCPUQueue() + + it = iter(val) + try: + n = next(it) + except: + self.assertEqual(False, True) + + subit = iter(n) + try: + n = next(subit) + except: + self.assertEqual(False, True) + + self.assertEqual(n.getQueue(), 3) + self.assertEqual(n.getCPUBufferCount(), 4566) + self.assertEqual(n.getCPUQueueEntries(), 0) + + val = rep.getEgressMcQueue() + + it = iter(val) + try: + n = next(it) + except: + self.assertEqual(False, True) + + subit = iter(n) + try: + n = next(subit) + except: + self.assertEqual(False, True) + + self.assertEqual(n.getQueue(), 1) + self.assertEqual(n.getMCBufferCount(), 34) + self.assertEqual(n.getMCQueueEntries(), 89) + + try: + n = next(subit) + except: + self.assertEqual(False, True) + + self.assertEqual(n.getQueue(), 2) + self.assertEqual(n.getMCBufferCount(), 1244) + self.assertEqual(n.getMCQueueEntries(), 0) + + try: + n = next(subit) + except: + self.assertEqual(False, True) + + self.assertEqual(n.getQueue(), 3) + self.assertEqual(n.getMCBufferCount(), 0) + self.assertEqual(n.getMCQueueEntries(), 3) + + val = rep.getEgressPortServicePool() + + it = iter(val) + + try: + n = next(it) + except: + self.assertEqual(False, True) + + subit = iter(n) + try: + n = next(subit) + except: + self.assertEqual(False, True) + + self.assertEqual(n.getServicePool(), 5) + self.assertEqual(n.getUmShareBufferCount(), 0) + self.assertEqual(n.getMCShareBufferCount(), 324) + self.assertEqual(n.getMCShareQueueEntries(), 0) + self.assertEqual(n.getPort(), "2") + + try: + n = next(it) + except: + self.assertEqual(False, True) + + subit = iter(n) + try: + n = next(subit) + except: + self.assertEqual(False, True) + + self.assertEqual(n.getServicePool(), 6) + self.assertEqual(n.getUmShareBufferCount(), 0) + self.assertEqual(n.getMCShareBufferCount(), 366) + self.assertEqual(n.getMCShareQueueEntries(), 0) + self.assertEqual(n.getPort(), "3") + + val = rep.getEgressRQEQueue() + + it = iter(val) + try: + n = next(it) + except: + self.assertEqual(False, True) + + subit = iter(n) + try: + n = next(subit) + except: + self.assertEqual(False, True) + + self.assertEqual(n.getQueue(), 2) + self.assertEqual(n.getRQEBufferCount(), 3333) + self.assertEqual(n.getRQEQueueEntries(), 4444) + + try: + n = next(subit) + except: + self.assertEqual(False, True) + + self.assertEqual(n.getQueue(), 5) + self.assertEqual(n.getRQEBufferCount(), 25) + self.assertEqual(n.getRQEQueueEntries(), 45) + + val = rep.getEgressServicePool() + + it = iter(val) + try: + n = next(it) + except: + self.assertEqual(False, True) + + subit = iter(n) + try: + n = next(subit) + except: + self.assertEqual(False, True) + + self.assertEqual(n.getServicePool(), 2) + self.assertEqual(n.getUmShareBufferCount(), 0) + self.assertEqual(n.getMCShareBufferCount(), 0) + self.assertEqual(n.getMCShareQueueEntries(), 3240) + + try: + n = next(subit) + except: + self.assertEqual(False, True) + + self.assertEqual(n.getServicePool(), 3) + self.assertEqual(n.getUmShareBufferCount(), 3660) + self.assertEqual(n.getMCShareBufferCount(), 0) + self.assertEqual(n.getMCShareQueueEntries(), 0) + + val = rep.getEgressUcQueue() + + it = iter(val) + try: + n = next(it) + except: + self.assertEqual(False, True) + + subit = iter(n) + try: + n = next(subit) + except: + self.assertEqual(False, True) + + self.assertEqual(n.getQueue(), 6) + self.assertEqual(n.getPort(), "0") + self.assertEqual(n.getUcQueueBufferCount(), 1111) + + val = rep.getEgressUcQueueGroup() + + it = iter(val) + try: + n = next(it) + except: + self.assertEqual(False, True) + + subit = iter(n) + try: + n = next(subit) + except: + self.assertEqual(False, True) + + self.assertEqual(n.getQueueGroup(), 6) + self.assertEqual(n.getUcBufferCount(), 2222) + + def test_thresholds(self): + rep = BSTParser() + rep.process(self.thresholds) + val = rep.getReportType() + self.assertEqual(val, ReportTypes.Threshold) + + val = rep.getDeviceData() + self.assertEqual(val.getValue(), 46) + + val = rep.getIngressPortPriorityGroup() + + it = iter(val) + try: + n = next(it) + except: + self.assertEqual(False, True) + + subit = iter(n) + try: + n = next(subit) + except: + self.assertEqual(False, True) + + self.assertEqual(n.getPriorityGroup(), 5) + self.assertEqual(n.getUmShareBufferCount(), 45500) + self.assertEqual(n.getUmHeadroomBufferCount(), 44450) + self.assertEqual(n.getPort(), "2") + + try: + n = next(it) + except: + self.assertEqual(False, True) + + subit = iter(n) + try: + n = next(subit) + except: + self.assertEqual(False, True) + + self.assertEqual(n.getPriorityGroup(), 6) + self.assertEqual(n.getUmShareBufferCount(), 25500) + self.assertEqual(n.getUmHeadroomBufferCount(), 24450) + self.assertEqual(n.getPort(), "3") + + val = rep.getIngressPortServicePool() + + it = iter(val) + try: + n = next(it) + except: + self.assertEqual(False, True) + + subit = iter(n) + try: + n = next(subit) + except: + self.assertEqual(False, True) + + self.assertEqual(n.getServicePool(), 5) + self.assertEqual(n.getUmShareBufferCount(), 324) + self.assertEqual(n.getPort(), "2") + + try: + n = next(it) + except: + self.assertEqual(False, True) + + subit = iter(n) + try: + n = next(subit) + except: + self.assertEqual(False, True) + + self.assertEqual(n.getServicePool(), 6) + self.assertEqual(n.getUmShareBufferCount(), 366) + self.assertEqual(n.getPort(), "3") + + val = rep.getIngressServicePool() + + it = iter(val) + try: + n = next(it) + except: + self.assertEqual(False, True) + + subit = iter(n) + try: + n = next(subit) + except: + self.assertEqual(False, True) + + self.assertEqual(n.getServicePool(), 1) + self.assertEqual(n.getUmShareBufferCount(), 3240) + + try: + n = next(subit) + except: + self.assertEqual(False, True) + + self.assertEqual(n.getServicePool(), 2) + self.assertEqual(n.getUmShareBufferCount(), 3660) + + val = rep.getEgressCPUQueue() + + it = iter(val) + try: + n = next(it) + except: + self.assertEqual(False, True) + + subit = iter(n) + try: + n = next(subit) + except: + self.assertEqual(False, True) + + self.assertEqual(n.getQueue(), 3) + self.assertEqual(n.getCPUBufferCount(), 4566) + self.assertEqual(n.getCPUQueueEntries(), 0) + + val = rep.getEgressMcQueue() + + it = iter(val) + try: + n = next(it) + except: + self.assertEqual(False, True) + + subit = iter(n) + try: + n = next(subit) + except: + self.assertEqual(False, True) + + self.assertEqual(n.getQueue(), 1) + self.assertEqual(n.getMCBufferCount(), 34) + self.assertEqual(n.getMCQueueEntries(), 89) + + try: + n = next(subit) + except: + self.assertEqual(False, True) + + self.assertEqual(n.getQueue(), 2) + self.assertEqual(n.getMCBufferCount(), 1244) + self.assertEqual(n.getMCQueueEntries(), 0) + + try: + n = next(subit) + except: + self.assertEqual(False, True) + + self.assertEqual(n.getQueue(), 3) + self.assertEqual(n.getMCBufferCount(), 0) + self.assertEqual(n.getMCQueueEntries(), 3) + + val = rep.getEgressPortServicePool() + + it = iter(val) + + try: + n = next(it) + except: + self.assertEqual(False, True) + + subit = iter(n) + try: + n = next(subit) + except: + self.assertEqual(False, True) + + self.assertEqual(n.getServicePool(), 5) + self.assertEqual(n.getUmShareBufferCount(), 0) + self.assertEqual(n.getMCShareBufferCount(), 324) + self.assertEqual(n.getMCShareQueueEntries(), 0) + self.assertEqual(n.getPort(), "2") + + try: + n = next(it) + except: + self.assertEqual(False, True) + + subit = iter(n) + try: + n = next(subit) + except: + self.assertEqual(False, True) + + self.assertEqual(n.getServicePool(), 6) + self.assertEqual(n.getUmShareBufferCount(), 0) + self.assertEqual(n.getMCShareBufferCount(), 366) + self.assertEqual(n.getMCShareQueueEntries(), 0) + self.assertEqual(n.getPort(), "3") + + val = rep.getEgressRQEQueue() + + it = iter(val) + try: + n = next(it) + except: + self.assertEqual(False, True) + + subit = iter(n) + try: + n = next(subit) + except: + self.assertEqual(False, True) + + self.assertEqual(n.getQueue(), 2) + self.assertEqual(n.getRQEBufferCount(), 3333) + self.assertEqual(n.getRQEQueueEntries(), 4444) + + try: + n = next(subit) + except: + self.assertEqual(False, True) + + self.assertEqual(n.getQueue(), 5) + self.assertEqual(n.getRQEBufferCount(), 25) + self.assertEqual(n.getRQEQueueEntries(), 45) + + val = rep.getEgressServicePool() + + it = iter(val) + try: + n = next(it) + except: + self.assertEqual(False, True) + + subit = iter(n) + try: + n = next(subit) + except: + self.assertEqual(False, True) + + self.assertEqual(n.getServicePool(), 2) + self.assertEqual(n.getUmShareBufferCount(), 0) + self.assertEqual(n.getMCShareBufferCount(), 0) + self.assertEqual(n.getMCShareQueueEntries(), 3240) + + try: + n = next(subit) + except: + self.assertEqual(False, True) + + self.assertEqual(n.getServicePool(), 3) + self.assertEqual(n.getUmShareBufferCount(), 3660) + self.assertEqual(n.getMCShareBufferCount(), 0) + self.assertEqual(n.getMCShareQueueEntries(), 0) + + val = rep.getEgressUcQueue() + + it = iter(val) + try: + n = next(it) + except: + self.assertEqual(False, True) + + subit = iter(n) + try: + n = next(subit) + except: + self.assertEqual(False, True) + + self.assertEqual(n.getQueue(), 6) + self.assertEqual(n.getPort(), "0") + self.assertEqual(n.getUcQueueBufferCount(), 1111) + + val = rep.getEgressUcQueueGroup() + + it = iter(val) + try: + n = next(it) + except: + self.assertEqual(False, True) + + subit = iter(n) + try: + n = next(subit) + except: + self.assertEqual(False, True) + + self.assertEqual(n.getQueueGroup(), 6) + self.assertEqual(n.getUcBufferCount(), 2222) + +if __name__ == "__main__": + unittest.main() diff --git a/broadview_lib/bst/cpubuffercount.py b/broadview_lib/bst/cpubuffercount.py new file mode 100644 index 0000000..2357c2d --- /dev/null +++ b/broadview_lib/bst/cpubuffercount.py @@ -0,0 +1,25 @@ +# (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. + +class CPUBufferCount(): + def __init__(self): + pass + + def __repr__(self): + return "cpu-buffer-count" + + def parse(self, data): + self.value = data[1] + self.isPercent = False + diff --git a/broadview_lib/bst/cpuqueueentries.py b/broadview_lib/bst/cpuqueueentries.py new file mode 100644 index 0000000..91339f0 --- /dev/null +++ b/broadview_lib/bst/cpuqueueentries.py @@ -0,0 +1,25 @@ +# (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. + +class CPUQueueEntries(): + def __init__(self): + pass + + def __repr__(self): + return "cpu-queue-entries" + + def parse(self, data): + self.value = data[2] + self.isPercent = False + diff --git a/broadview_lib/bst/devicedata.py b/broadview_lib/bst/devicedata.py new file mode 100644 index 0000000..24a339c --- /dev/null +++ b/broadview_lib/bst/devicedata.py @@ -0,0 +1,34 @@ +# (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. + +class DeviceData(): + def __init__(self): + self.__value = None + self.__isPercent = False + + def getValue(self): + return self.__value + + def getIsPercent(self): + return self.__isPercent + + def __repr__(self): + return "device" + + def parse(self, data, port=None): + self.__value = int(data) + # XXX how can we tell if this is a percentage? + self.__isPercent = False + + diff --git a/broadview_lib/bst/egress_cpu_queue.py b/broadview_lib/bst/egress_cpu_queue.py new file mode 100644 index 0000000..5584e6b --- /dev/null +++ b/broadview_lib/bst/egress_cpu_queue.py @@ -0,0 +1,59 @@ +# (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. + +import cpubuffercount +import cpuqueueentries + +class EgressCPUQueueEntry(): + def __init__(self): + self._queue = None + self._cpubuffercount = cpubuffercount.CPUBufferCount() + self._cpuqueueentries = cpuqueueentries.CPUQueueEntries() + + def getQueue(self): + return self._queue + + def getCPUBufferCount(self): + return self._cpubuffercount.value + + def getCPUQueueEntries(self): + return self._cpuqueueentries.value + +class EgressCPUQueue(): + def __init__(self): + self.__table = [] + + def __repr__(self): + return "egress-cpu-queue" + + def __iter__(self): + self.__n = 0 + return self + + def next(self): + if self.__n >= len(self.__table): + raise StopIteration + else: + n = self.__n + self.__n += 1 + return self.__table[n] + + def parse(self, data): + for x in data: + val = EgressCPUQueueEntry() + val._queue = x[0] + val._cpubuffercount.parse(x) + val._cpuqueueentries.parse(x) + self.__table.append(val) + diff --git a/broadview_lib/bst/egress_mc_queue.py b/broadview_lib/bst/egress_mc_queue.py new file mode 100644 index 0000000..77a4aa7 --- /dev/null +++ b/broadview_lib/bst/egress_mc_queue.py @@ -0,0 +1,65 @@ +# (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. + +import mcbuffercount +import mcqueueentries + +class EgressMcQueueEntry(): + def __init__(self): + self._queue = None + self._port = None + self._mcbuffercount = mcbuffercount.McBufferCount() + self._mcqueueentries = mcqueueentries.McQueueEntries() + + def getQueue(self): + return self._queue + + def getPort(self): + return self._port + + def getMCBufferCount(self): + return self._mcbuffercount.value + + def getMCQueueEntries(self): + return self._mcqueueentries.value + +class EgressMcQueue(): + def __init__(self): + self.__table = [] + + def __repr__(self): + return "egress-mc-queue" + + def __iter__(self): + self.__n = 0 + return self + + def next(self): + if self.__n >= len(self.__table): + raise StopIteration + else: + n = self.__n + self.__n += 1 + return self.__table[n] + + def parse(self, data): + for x in data: + val = EgressMcQueueEntry() + val._queue = x[0] + val._port = x[1] + val._mcbuffercount.parse(x) + val._mcqueueentries.parse(x) + self.__table.append(val) + + diff --git a/broadview_lib/bst/egress_port_service_pool.py b/broadview_lib/bst/egress_port_service_pool.py new file mode 100644 index 0000000..d6cc7de --- /dev/null +++ b/broadview_lib/bst/egress_port_service_pool.py @@ -0,0 +1,73 @@ +# (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. + +import ucsharebuffercount +import umsharebuffercount +import mcsharebuffercount +import mcsharequeueentries + +class EgressPortServicePoolEntry(): + def __init__(self): + self._port = None + self._servicePool = None + self._umsharebuffercount = umsharebuffercount.UmShareBufferCount() + self._mcsharebuffercount = mcsharebuffercount.McShareBufferCount() + self._mcsharequeueentries = mcsharequeueentries.McShareQueueEntries() + + def getPort(self): + return self._port + + def getUmShareBufferCount(self): + return self._umsharebuffercount.value + + def getMCShareBufferCount(self): + return self._mcsharebuffercount.value + + def getMCShareQueueEntries(self): + return self._mcsharequeueentries.value + + def getServicePool(self): + return self._servicePool + +class EgressPortServicePool(): + def __init__(self): + self.__table = [] + + def __iter__(self): + self.__n = 0 + return self + + def next(self): + if self.__n >= len(self.__table): + raise StopIteration + else: + n = self.__n + self.__n += 1 + return self.__table[n] + + def __repr__(self): + return "egress-port-service-pool" + + def parse(self, data, port=None): + for x in data: + val = EgressPortServicePoolEntry() + if port: + val._port = port + val._servicePool = x[0] + val._umsharebuffercount.parse(x) + val._mcsharebuffercount.parse(x) + val._mcsharequeueentries.parse(x) + + self.__table.append(val) + diff --git a/broadview_lib/bst/egress_rqe_queue.py b/broadview_lib/bst/egress_rqe_queue.py new file mode 100644 index 0000000..fee5557 --- /dev/null +++ b/broadview_lib/bst/egress_rqe_queue.py @@ -0,0 +1,60 @@ +# (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. + +import rqebuffercount +import rqequeueentries + +class EgressRQEQueueEntry(): + def __init__(self): + self._queue = None + self._rqebuffercount = rqebuffercount.RQEBufferCount() + self._rqequeueentries = rqequeueentries.RQEQueueEntries() + + def getQueue(self): + return self._queue + + def getRQEBufferCount(self): + return self._rqebuffercount.value + + def getRQEQueueEntries(self): + return self._rqequeueentries.value + +class EgressRQEQueue(): + def __init__(self): + self.__table = [] + + def __repr__(self): + return "egress-rqe-queue" + + def __iter__(self): + self.__n = 0 + return self + + def next(self): + if self.__n >= len(self.__table): + raise StopIteration + else: + n = self.__n + self.__n += 1 + return self.__table[n] + + def parse(self, data): + for x in data: + val = EgressRQEQueueEntry() + val._queue = x[0] + val._rqebuffercount.parse(x) + val._rqequeueentries.parse(x) + self.__table.append(val) + + diff --git a/broadview_lib/bst/egress_service_pool.py b/broadview_lib/bst/egress_service_pool.py new file mode 100644 index 0000000..2c413b9 --- /dev/null +++ b/broadview_lib/bst/egress_service_pool.py @@ -0,0 +1,67 @@ +# (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. + +import umsharebuffercount +import mcsharebuffercount +import mcsharequeueentries + +class EgressServicePoolEntry(): + def __init__(self): + self.__servicePool = None + self._umsharebuffercount = umsharebuffercount.UmShareBufferCount() + self._mcsharebuffercount = mcsharebuffercount.McShareBufferCount() + self._mcsharequeueentries = mcsharequeueentries.McShareQueueEntries() + + def getServicePool(self): + return self._servicePool + + def getUmShareBufferCount(self): + return self._umsharebuffercount.value + + def getMCShareBufferCount(self): + return self._mcsharebuffercount.value + + def getMCShareQueueEntries(self): + return self._mcsharequeueentries.value + +class EgressServicePool(): + def __init__(self): + self.__table = [] + + def __repr__(self): + return "egress-service-pool" + + def __iter__(self): + self.__n = 0 + return self + + def next(self): + if self.__n >= len(self.__table): + raise StopIteration + else: + n = self.__n + self.__n += 1 + return self.__table[n] + + def parse(self, data): + for x in data: + val = EgressServicePoolEntry() + val._servicePool = x[0] + val._umsharebuffercount.parse(x) + val._mcsharebuffercount.parse(x) + val._mcsharequeueentries.parse(x) + self.__table.append(val) + + + diff --git a/broadview_lib/bst/egress_uc_queue.py b/broadview_lib/bst/egress_uc_queue.py new file mode 100644 index 0000000..797065f --- /dev/null +++ b/broadview_lib/bst/egress_uc_queue.py @@ -0,0 +1,60 @@ +# (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. + +import ucqueuebuffercount + +class EgressUcQueueEntry(): + def __init__(self): + self._queue = None + self._port = None + self._ucqueuebuffercount = ucqueuebuffercount.UcQueueBufferCount() + + def getQueue(self): + return self._queue + + def getPort(self): + return self._port + + def getUcQueueBufferCount(self): + return self._ucqueuebuffercount.value + +class EgressUcQueue(): + def __init__(self): + self.__table = [] + + def __repr__(self): + return "egress-uc-queue" + + def __iter__(self): + self.__n = 0 + return self + + def next(self): + if self.__n >= len(self.__table): + raise StopIteration + else: + n = self.__n + self.__n += 1 + return self.__table[n] + + def parse(self, data): + for x in data: + val = EgressUcQueueEntry() + val._queue = x[0] + val._port = x[1] + val._ucqueuebuffercount.parse(x) + self.__table.append(val) + + + diff --git a/broadview_lib/bst/egress_uc_queue_group.py b/broadview_lib/bst/egress_uc_queue_group.py new file mode 100644 index 0000000..602ea16 --- /dev/null +++ b/broadview_lib/bst/egress_uc_queue_group.py @@ -0,0 +1,55 @@ +# (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. + +import ucbuffercount + +class EgressUcQueueGroupEntry(): + def __init__(self): + self._queueGroup = None + self._ucbuffercount = ucbuffercount.UcBufferCount() + + def getQueueGroup(self): + return self._queueGroup + + def getUcBufferCount(self): + return self._ucbuffercount.value + +class EgressUcQueueGroup(): + def __init__(self): + self.__table = [] + + def __repr__(self): + return "egress-uc-queue-group" + + def __iter__(self): + self.__n = 0 + return self + + def next(self): + if self.__n >= len(self.__table): + raise StopIteration + else: + n = self.__n + self.__n += 1 + return self.__table[n] + + def parse(self, data): + for x in data: + val = EgressUcQueueGroupEntry() + val._queueGroup = x[0] + val._ucbuffercount.parse(x) + self.__table.append(val) + + + diff --git a/broadview_lib/bst/ingress_port_priority_group.py b/broadview_lib/bst/ingress_port_priority_group.py new file mode 100644 index 0000000..96e04df --- /dev/null +++ b/broadview_lib/bst/ingress_port_priority_group.py @@ -0,0 +1,64 @@ +# (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. + +import umsharebuffercount +import umheadroombuffercount + +class IngressPortPriorityGroupEntry(): + def __init__(self): + self._port = None + self._priorityGroup = None + self._umsharebuffercount = umsharebuffercount.UmShareBufferCount() + self._umheadroombuffercount = umheadroombuffercount.UmHeadroomBufferCount() + + def getPort(self): + return self._port + + def getPriorityGroup(self): + return self._priorityGroup + + def getUmShareBufferCount(self): + return self._umsharebuffercount.value + + def getUmHeadroomBufferCount(self): + return self._umheadroombuffercount.value + +class IngressPortPriorityGroup(): + def __init__(self): + self.__table = [] + + def __iter__(self): + self.__n = 0 + return self + + def next(self): + if self.__n >= len(self.__table): + raise StopIteration + else: + n = self.__n + self.__n += 1 + return self.__table[n] + + def __repr__(self): + return "ingress-port-priority-group" + + def parse(self, data, port=None): + for x in data: + val = IngressPortPriorityGroupEntry() + if port != None: + val._port = port + val._priorityGroup = x[0] + val._umsharebuffercount.parse(x) + val._umheadroombuffercount.parse(x) + self.__table.append(val) diff --git a/broadview_lib/bst/ingress_port_service_pool.py b/broadview_lib/bst/ingress_port_service_pool.py new file mode 100644 index 0000000..eebd3d5 --- /dev/null +++ b/broadview_lib/bst/ingress_port_service_pool.py @@ -0,0 +1,58 @@ +# (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. + +import umsharebuffercount + +class IngressPortServicePoolEntry(): + def __init__(self): + self._port = None + self._servicePool = None + self._umsharebuffercount = umsharebuffercount.UmShareBufferCount() + + def getPort(self): + return self._port + + def getServicePool(self): + return self._servicePool + + def getUmShareBufferCount(self): + return self._umsharebuffercount.value + +class IngressPortServicePool(): + def __init__(self): + self.__table = [] + + def __iter__(self): + self.__n = 0 + return self + + def next(self): + if self.__n >= len(self.__table): + raise StopIteration + else: + n = self.__n + self.__n += 1 + return self.__table[n] + + def __repr__(self): + return "ingress-port-service-pool" + + def parse(self, data, port=None): + for x in data: + val = IngressPortServicePoolEntry() + if port: + val._port = port + val._servicePool = x[0] + val._umsharebuffercount.parse(x) + self.__table.append(val) diff --git a/broadview_lib/bst/ingress_service_pool.py b/broadview_lib/bst/ingress_service_pool.py new file mode 100644 index 0000000..e87c4f3 --- /dev/null +++ b/broadview_lib/bst/ingress_service_pool.py @@ -0,0 +1,52 @@ +# (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. + +import umsharebuffercount + +class IngressServicePoolEntry(): + def __init__(self): + self._servicePool = None + self._umsharebuffercount = umsharebuffercount.UmShareBufferCount() + + def getServicePool(self): + return self._servicePool + + def getUmShareBufferCount(self): + return self._umsharebuffercount.value + +class IngressServicePool(): + def __init__(self): + self.__table = [] + + def __iter__(self): + self.__n = 0 + return self + + def next(self): + if self.__n >= len(self.__table): + raise StopIteration + else: + n = self.__n + self.__n += 1 + return self.__table[n] + + def __repr__(self): + return "ingress-service-pool" + + def parse(self, data): + for x in data: + val = IngressServicePoolEntry() + val._servicePool = x[0] + val._umsharebuffercount.parse(x) + self.__table.append(val) diff --git a/broadview_lib/bst/mcbuffercount.py b/broadview_lib/bst/mcbuffercount.py new file mode 100644 index 0000000..f337294 --- /dev/null +++ b/broadview_lib/bst/mcbuffercount.py @@ -0,0 +1,24 @@ +# (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. + +class McBufferCount(): + def __init__(self): + pass + + def __repr__(self): + return "mc-buffer-count" + + def parse(self, data): + self.value = data[2] + self.isPercentage = False diff --git a/broadview_lib/bst/mcqueueentries.py b/broadview_lib/bst/mcqueueentries.py new file mode 100644 index 0000000..b92fb9b --- /dev/null +++ b/broadview_lib/bst/mcqueueentries.py @@ -0,0 +1,25 @@ +# (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. + +class McQueueEntries(): + def __init__(self): + pass + + def __repr__(self): + return "mc-queue-entries" + + def parse(self, data): + self.value = data[3] + self.isPercentage = False + diff --git a/broadview_lib/bst/mcsharebuffercount.py b/broadview_lib/bst/mcsharebuffercount.py new file mode 100644 index 0000000..b195a61 --- /dev/null +++ b/broadview_lib/bst/mcsharebuffercount.py @@ -0,0 +1,31 @@ +# (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. + +class McShareBufferCount(): + def __init__(self): + self.value = None + self.isPercentage = False + + def getValue(self): + return self.value + + def getIsPercentage(self): + return self._isPercentage + + def __repr__(self): + return "mc-share-buffer-count" + + def parse(self, data): + self.value = data[2] + self.isPercent = False diff --git a/broadview_lib/bst/mcsharequeueentries.py b/broadview_lib/bst/mcsharequeueentries.py new file mode 100644 index 0000000..9e7f325 --- /dev/null +++ b/broadview_lib/bst/mcsharequeueentries.py @@ -0,0 +1,32 @@ +# (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. + +class McShareQueueEntries(): + def __init__(self): + self.value = None + self.isPercentage = False + + def getValue(self): + return self.value + + def getIsPercentage(self): + return self._isPercentage + + def __repr__(self): + return "mc-share-queue-entries" + + def parse(self, data): + self.value = data[3] + self.isPercent = False + diff --git a/broadview_lib/bst/rqebuffercount.py b/broadview_lib/bst/rqebuffercount.py new file mode 100644 index 0000000..e7800d4 --- /dev/null +++ b/broadview_lib/bst/rqebuffercount.py @@ -0,0 +1,32 @@ +# (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. + +class RQEBufferCount(): + def __init__(self): + self.value = None + self.isPercent = False + + def getValue(self): + return self.value + + def getIsPercent(self): + return self.isPercent + + def __repr__(self): + return "rqe-buffer-count" + + def parse(self, data): + self.value = data[1] + self.isPercent = False + diff --git a/broadview_lib/bst/rqequeueentries.py b/broadview_lib/bst/rqequeueentries.py new file mode 100644 index 0000000..779e387 --- /dev/null +++ b/broadview_lib/bst/rqequeueentries.py @@ -0,0 +1,25 @@ +# (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. + +class RQEQueueEntries(): + def __init__(self): + pass + + def __repr__(self): + return "rqe-queue-entries" + + def parse(self, data): + self.value = data[2] + self.isPercent = False + diff --git a/broadview_lib/bst/ucbuffercount.py b/broadview_lib/bst/ucbuffercount.py new file mode 100644 index 0000000..b486629 --- /dev/null +++ b/broadview_lib/bst/ucbuffercount.py @@ -0,0 +1,25 @@ +# (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. + +class UcBufferCount(): + def __init__(self): + pass + + def __repr__(self): + return "uc-buffer-count" + + def parse(self, data): + self.value = data[1] + self.isPercentage = False + diff --git a/broadview_lib/bst/ucqueuebuffercount.py b/broadview_lib/bst/ucqueuebuffercount.py new file mode 100644 index 0000000..f77033b --- /dev/null +++ b/broadview_lib/bst/ucqueuebuffercount.py @@ -0,0 +1,32 @@ +# (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. + +class UcQueueBufferCount(): + def __init__(self): + self.value = None + self.isPercentage = False + + def getValue(self): + return self.value + + def getIsPercentage(self): + return self.isPercentage + + def __repr__(self): + return "uc-buffer-count" + + def parse(self, data): + self.value = data[2] + self.isPercentage = False + diff --git a/broadview_lib/bst/ucsharebuffercount.py b/broadview_lib/bst/ucsharebuffercount.py new file mode 100644 index 0000000..b69b550 --- /dev/null +++ b/broadview_lib/bst/ucsharebuffercount.py @@ -0,0 +1,24 @@ +# (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. + +class UcShareBufferCount(): + def __init__(self): + pass + + def __repr__(self): + return "uc-share-buffer-count" + + def parse(self, data): + self.value = data[1] + self.isPercent = False diff --git a/broadview_lib/bst/umheadroombuffercount.py b/broadview_lib/bst/umheadroombuffercount.py new file mode 100644 index 0000000..061a709 --- /dev/null +++ b/broadview_lib/bst/umheadroombuffercount.py @@ -0,0 +1,26 @@ +# (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. + +class UmHeadroomBufferCount(): + def __init__(self): + pass + + def __repr__(self): + return "um-headroom-buffer-count" + + def parse(self, data): + self.value = data[2] + self.percent = False + + diff --git a/broadview_lib/bst/umsharebuffercount.py b/broadview_lib/bst/umsharebuffercount.py new file mode 100644 index 0000000..27cc9d7 --- /dev/null +++ b/broadview_lib/bst/umsharebuffercount.py @@ -0,0 +1,33 @@ +# (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. + +class UmShareBufferCount(): + def __init__(self): + self.value = None + self.isPercentage = False + + def getValue(self): + return self.value + + def getIsPercentage(self): + return self._isPercentage + + def __repr__(self): + return "um-share-buffer-count" + + def parse(self, data): + self.value = data[1] + self.isPercentage = False + + diff --git a/broadview_lib/config/__init__.py b/broadview_lib/config/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/broadview_lib/config/agentapi.py b/broadview_lib/config/agentapi.py new file mode 100644 index 0000000..7b2e160 --- /dev/null +++ b/broadview_lib/config/agentapi.py @@ -0,0 +1,65 @@ +# (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. + +import json +from collections import OrderedDict +from agentconnection import AgentConnection + +class AgentAPI(object): + __serial = 1 + def __init__(self): + self.__httpMethod = "POST" + self.__feature = None + self.__host = None + self.__port = None + self.__payload = None + + def setHost(self, host): + self.__host = host + + def getHost(self): + return self.__host + + def setPort(self, port): + self.__port = port + + def getPort(self): + return self.__port + + def setHttpMethod(self, method): + self.__httpMethod = method + + def getHttpMethod(self): + return self.__httpMethod + + def setFeature(self, feature): + self.__feature = feature + + def getFeature(self): + return self.__feature + + def _send(self, o): + self.__payload = {} + self.__payload["jsonrpc"] = "2.0" + self.__payload["asic-id"] = o["asic-id"] + self.__payload["method"] = o["method"] + self.__payload["params"] = o["params"] + self.__payload["id"] = AgentAPI.__serial + AgentAPI.__serial = AgentAPI.__serial + 1 + conn = AgentConnection(self.__host, self.__port, self.__feature) + return conn.makeRequest(self) + + def getjson(self): + x = json.dumps(OrderedDict(self.__payload)) + return x diff --git a/broadview_lib/config/agentconnection.py b/broadview_lib/config/agentconnection.py new file mode 100644 index 0000000..9eb2d05 --- /dev/null +++ b/broadview_lib/config/agentconnection.py @@ -0,0 +1,104 @@ +#/***************************************************************************** +#* +#* (C) Copyright Broadcom Corporation 2015 +#* +#* 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 requests +import sys +import urllib +from xml.etree import ElementTree +import json + +class RequestFailed(Exception): + ''' + class to represent a failed RESTful call + ''' + def __init__(self, url, http_code, open_code, open_msg): + self._url = url + self._http_code = int(http_code) + self._open_code = int(open_code) + self._open_msg = open_msg + + def __str__(self): + return repr((self._url, self._http_code, self._open_code, self._open_msg)) + +class AgentConnection(): + def __init__(self, host, port, feature): + self.host = host + self.port = port + self.feature = feature # e.g., "bst" + + def _is_ok(self, r): + return r.status_code == 200 + + def _raise_fail_if(self, url, r): + if not self._is_ok(r): + try: + j = r.json()["status"] + except: + try: + t = ElementTree.fromstring(r) + j = {"response_code": r.status_code, + "error_code": 0, + "msg": "XML failure response from web server"} + + except: + j = {"response_code": r.status_code, + "error_code": 0, + "msg": "Unparsable response from web server"} + + raise RequestFailed(url, j["response_code"], j["error_code"], j["msg"]) + + def makeRequest(self, request): + + headers = {"Content-Type": "application/json"} + + isGet = False + if request.getHttpMethod() == "GET": + isGet = True + + if False and isGet: + payload = request.getjson().encode("utf-8") + if self.feature: + url = "http://%s:%d/broadview/%s/%s%s%s" % (self.host, self.port, self.feature, request.getHttpMethod(), "?req=", payload) + else: + url = "http://%s:%d/broadview/%s%s%s" % (self.host, self.port, request.getHttpMethod(), "?req=", payload) + r = requests.get(url, headers=headers) + else: + payload = request.getjson().encode("utf-8") + if self.feature: + url = "http://%s:%d/broadview/%s/%s" % (self.host, self.port, self.feature, request.getHttpMethod()) + else: + url = "http://%s:%d/broadview/%s" % (self.host, self.port, request.getHttpMethod()) + if isGet: + r = requests.get(url, data=payload, headers=headers) + else: + r = requests.post(url, data=payload, headers=headers) + + json_data = {} + if r.status_code == 200: + try: + # Data can come back with leading.trailing spaces, which trips + # up requests' json parser. So get as test, string, and let + # Python json do the parsing + + json_data = json.loads(r.text.strip()) + except: + pass + + self._raise_fail_if(url, r) + return (r.status_code, json_data) + diff --git a/broadview_lib/config/broadviewconfig.py b/broadview_lib/config/broadviewconfig.py new file mode 100644 index 0000000..22169c8 --- /dev/null +++ b/broadview_lib/config/broadviewconfig.py @@ -0,0 +1,73 @@ +# (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. + +import ConfigParser +import json +import unittest + +class BroadViewBSTSwitches(): + cfg = None + bst_switches = None + + def __init__(self): + if not BroadViewBSTSwitches.bst_switches: + try: + BroadViewBSTSwitches.cfg = ConfigParser.ConfigParser() + BroadViewBSTSwitches.cfg.read("/etc/broadviewswitches.conf") + BroadViewBSTSwitches.bst_switches = json.loads(BroadViewBSTSwitches.cfg.get("topology", "bst_switches")) + except: + pass + + def __len__(self): + if BroadViewBSTSwitches.bst_switches: + return len(BroadViewBSTSwitches.bst_switches) + else: + return 0 + + def get(self, i): + ret = None + if i >= 0 and i < len(BroadViewBSTSwitches.bst_switches): + ret = BroadViewBSTSwitches.bst_switches[i] + return ret + + def __iter__(self): + self.__n = 0 + return self + + def next(self): + if BroadViewBSTSwitches.bst_switches == None: + raise StopIteration + + if self.__n >= len(BroadViewBSTSwitches.bst_switches): + raise StopIteration + else: + n = self.__n + self.__n += 1 + return BroadViewBSTSwitches.bst_switches[n] + +class TestBSTSwitches(unittest.TestCase): + + def test1(self): + x = BroadViewBSTSwitches() + + for y in x: + self.assertTrue("ip" in y) + self.assertTrue("port" in y) + self.assertTrue("description" in y) + self.assertTrue("asics" in y) + +if __name__ == "__main__": + unittest.main() + + diff --git a/broadview_lib/config/bst.py b/broadview_lib/config/bst.py new file mode 100644 index 0000000..b2d83e0 --- /dev/null +++ b/broadview_lib/config/bst.py @@ -0,0 +1,1218 @@ +# (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 agentapi import AgentAPI +from broadview_lib.bst.bst_parser import BSTParser +from broadview_lib.config.broadviewconfig import BroadViewBSTSwitches +import unittest + +class ConfigureBSTFeature(AgentAPI): + def __init__(self, host, port): + super(ConfigureBSTFeature, self).__init__() + self.setFeature("bst") + self.setHttpMethod("POST") + self.setHost(host) + self.setPort(port) + self.__bst_enable = False + self.__send_async_reports = False + self.__collection_interval = 60 + self.__stat_in_percentage = False + self.__stat_units_in_cells = False + self.__trigger_rate_limit = 1 + self.__trigger_rate_limit_interval = 1 + self.__send_snapshot_on_trigger = True + self.__async_full_reports = False + self.__asic_id = "1" + + def setEnable(self, val): + self.__bst_enable = val + + def setSendAsyncReports(self, val): + self.__send_async_reports = val + + def setCollectionInterval(self, val): + self.__collection_interval = val + + def setStatInPercentage(self, val): + self.__stat_in_percentage = val + + def setStatUnitsInCells(self, val): + self.__stat_units_in_cells = val + + def setTriggerRateLimit(self, val): + self.__trigger_rate_limit = val + + def setTriggerRateLimitInterval(self, val): + self.__trigger_rate_limit_interval = val + + def setSendSnapshotOnTrigger(self, val): + self.__send_snapshot_on_trigger = val + + def setAsyncFullReports(self, val): + self.__async_full_reports = val + + def setASIC(self, val): + self.__asic_id = val + + def send(self): + status, json = self._send(self.toDict()) + return status + + + def toDict(self): + ret = {} + params = {} + params["bst-enable"] = 1 if self.__bst_enable else 0 + params["send-async-reports"] = 1 if self.__send_async_reports else 0 + params["collection-interval"] = self.__collection_interval + params["stat-in-percentage"] = 1 if self.__stat_in_percentage else 0 + params["stat-units-in-cells"] = 1 if self.__stat_units_in_cells else 0 + params["trigger-rate-limit"] = self.__trigger_rate_limit + params["trigger-rate-limit-interval"] = self.__trigger_rate_limit_interval + params["send-snapshot-on-trigger"] = 1 if self.__send_snapshot_on_trigger else 0 + params["async-full-reports"] = 1 if self.__async_full_reports else 0 + ret["asic-id"] = self.__asic_id + ret["params"] = params + ret["method"] = "configure-bst-feature" + return ret + +class ConfigureBSTTracking(AgentAPI): + def __init__(self, host, port): + super(ConfigureBSTTracking, self).__init__() + self.setFeature("bst") + self.setHttpMethod("POST") + self.setHost(host) + self.setPort(port) + self.__track_peak_stats = False + self.__track_ingress_port_priority_group = False + self.__track_ingress_port_service_pool = False + self.__track_ingress_service_pool = False + self.__track_egress_port_service_pool = False + self.__track_egress_service_pool = False + self.__track_egress_uc_queue = False + self.__track_egress_uc_queue_group = False + self.__track_egress_mc_queue = False + self.__track_egress_cpu_queue = False + self.__track_egress_rqe_queue = False + self.__track_device = False + self.__asic_id = "1" + + def setTrackPeakStats(self, val): + self.__track_peak_stats = val + + def setTrackIngressPortPriorityGroup(self, val): + self.__track_ingress_port_priority_group = val + + def setTrackIngressPortServicePool(self, val): + self.__track_ingress_port_service_pool = val + + def setTrackIngressServicePool(self, val): + self.__track_ingress_service_pool = val + + def setTrackEgressPortServicePool(self, val): + self.__track_egress_port_service_pool = val + + def setTrackEgressServicePool(self, val): + self.__track_egress_service_pool = val + + def setTrackEgressUcQueue(self, val): + self.__track_egress_uc_queue = val + + def setTrackEgressUcQueueGroup(self, val): + self.__track_egress_uc_queue_group = val + + def setTrackEgressMcQueue(self, val): + self.__track_egress_mc_queue = val + + def setTrackEgressCPUQueue(self, val): + self.__track_egress_cpu_queue = val + + def setTrackEgressRQEQueue(self, val): + self.__track_egress_rqe_queue = val + + def setTrackDevice(self, val): + self.__track_device = val + + def setASIC(self, val): + self.__asic_id = val + + def send(self): + status, json = self._send(self.toDict()) + return status + + def toDict(self): + ret = {} + params = {} + params["track-peak-stats"] = 1 if self.__track_peak_stats else 0 + params["track-ingress-port-priority-group"] = 1 if self.__track_ingress_port_priority_group else 0 + params["track-ingress-port-service-pool"] = 1 if self.__track_ingress_port_service_pool else 0 + params["track-ingress-service-pool"] = 1 if self.__track_ingress_service_pool else 0 + params["track-egress-port-service-pool"] = 1 if self.__track_egress_port_service_pool else 0 + params["track-egress-service-pool"] = 1 if self.__track_egress_service_pool else 0 + params["track-egress-uc-queue"] = 1 if self.__track_egress_uc_queue else 0 + params["track-egress-uc-queue-group"] = 1 if self.__track_egress_uc_queue_group else 0 + params["track-egress-mc-queue"] = 1 if self.__track_egress_mc_queue else 0 + params["track-egress-cpu-queue"] = 1 if self.__track_egress_cpu_queue else 0 + params["track-egress-rqe-queue"] = 1 if self.__track_egress_rqe_queue else 0 + params["track-device"] = 1 if self.__track_device else 0 + ret["asic-id"] = self.__asic_id + ret["params"] = params + ret["method"] = "configure-bst-tracking" + return ret + +class ConfigureBSTThresholds(AgentAPI): + def __init__(self, host, port): + super(ConfigureBSTThresholds, self).__init__() + self.setFeature("bst") + self.setHost(host) + self.setPort(port) + self.__asic_id = "1" + self.__params = {} + + def setASIC(self, val): + self.__asic_id = val + + def setParams(self, params): + self.__params = params + + def send(self): + status, json = self._send(self.toDict()) + return status + + def toDict(self): + ret = {} + params = {} + ret["asic-id"] = self.__asic_id + ret["params"] = self.getParams() + ret["method"] = "configure-bst-thresholds" + return ret + +class ConfigureDeviceThreshold(ConfigureBSTThresholds): + def __init__(self, host, port, threshold): + super(ConfigureDeviceThreshold, self).__init__(host, port) + self.__realm = "device" + self.__threshold = threshold + + def getParams(self): + ret = {} + ret["realm"] = self.__realm + ret["threshold"] = self.__threshold + return ret + +class ConfigureEgressCpuQueueThreshold(ConfigureBSTThresholds): + def __init__(self, host, port, queue, threshold): + super(ConfigureEgressCpuQueueThreshold, self).__init__(host, port) + self.__realm = "egress-cpu-queue" + self.__queue = queue + self.__threshold = threshold + + def getParams(self): + ret = {} + ret["realm"] = self.__realm + ret["queue"] = self.__queue + ret["cpu-threshold"] = self.__threshold + return ret + +class ConfigureEgressRqeQueueThreshold(ConfigureBSTThresholds): + def __init__(self, host, port, queue, threshold): + super(ConfigureEgressRqeQueueThreshold, self).__init__(host, port) + self.__realm = "egress-rqe-queue" + self.__queue = queue + self.__threshold = threshold + + def getParams(self): + ret = {} + ret["realm"] = self.__realm + ret["queue"] = self.__queue + ret["rqe-threshold"] = self.__threshold + return ret + +class ConfigureEgressPortServicePoolThreshold(ConfigureBSTThresholds): + def __init__(self, host, port, + eport, + servicePool, + ucShareThreshold, + umShareThreshold, + mcShareThreshold, + mcShareQueueEntriesThreshold): + super(ConfigureEgressPortServicePoolThreshold, self).__init__(host, port) + self.__realm = "egress-port-service-pool" + self.__port = eport + self.__servicePool = servicePool + self.__ucShareThreshold = ucShareThreshold + self.__umShareThreshold = umShareThreshold + self.__mcShareThreshold = mcShareThreshold + self.__mcShareQueueEntriesThreshold = mcShareQueueEntriesThreshold + + def getParams(self): + ret = {} + ret["realm"] = self.__realm + ret["port"] = self.__port + ret["service-pool"] = self.__servicePool + ret["uc-share-threshold"] = self.__ucShareThreshold + ret["um-share-threshold"] = self.__umShareThreshold + ret["mc-share-threshold"] = self.__mcShareThreshold + ret["mc-share-queue-entries-threshold"] = self.__mcShareQueueEntriesThreshold + return ret + +class ConfigureEgressServicePoolThreshold(ConfigureBSTThresholds): + def __init__(self, host, port, + servicePool, + umShareThreshold, + mcShareThreshold, + mcShareQueueEntriesThreshold): + super(ConfigureEgressServicePoolThreshold, self).__init__(host, port) + self.__realm = "egress-service-pool" + self.__servicePool = servicePool + self.__umShareThreshold = umShareThreshold + self.__mcShareThreshold = mcShareThreshold + self.__mcShareQueueEntriesThreshold = mcShareQueueEntriesThreshold + + def getParams(self): + ret = {} + ret["realm"] = self.__realm + ret["service-pool"] = self.__servicePool + ret["um-share-threshold"] = self.__umShareThreshold + ret["mc-share-threshold"] = self.__mcShareThreshold + ret["mc-share-queue-entries-threshold"] = self.__mcShareQueueEntriesThreshold + return ret + +class ConfigureEgressUcQueueThreshold(ConfigureBSTThresholds): + def __init__(self, host, port, queue, threshold): + super(ConfigureEgressUcQueueThreshold, self).__init__(host, port) + self.__realm = "egress-uc-queue" + self.__queue = queue + self.__threshold = threshold + + def getParams(self): + ret = {} + ret["realm"] = self.__realm + ret["queue"] = self.__queue + ret["uc-threshold"] = self.__threshold + return ret + +class ConfigureEgressUcQueueGroupThreshold(ConfigureBSTThresholds): + def __init__(self, host, port, queueGroup, threshold): + super(ConfigureEgressUcQueueGroupThreshold, self).__init__(host, port) + self.__realm = "egress-uc-queue-group" + self.__queueGroup = queueGroup + self.__threshold = threshold + + def getParams(self): + ret = {} + ret["realm"] = self.__realm + ret["queue-group"] = self.__queueGroup + ret["uc-threshold"] = self.__threshold + return ret + +class ConfigureEgressMcQueueThreshold(ConfigureBSTThresholds): + def __init__(self, host, port, + queue, + mcQueueEntriesThreshold, + mcThreshold): + super(ConfigureEgressMcQueueThreshold, self).__init__(host, port) + self.__realm = "egress-mc-queue" + self.__queue = queue + self.__mcQueueEntriesThreshold = mcQueueEntriesThreshold + self.__mcThreshold = mcThreshold + + def getParams(self): + ret = {} + ret["realm"] = self.__realm + ret["queue"] = self.__queue + ret["mc-queue-entries-threshold"] = self.__mcQueueEntriesThreshold + ret["mc-threshold"] = self.__mcThreshold + return ret + +class ConfigureIngressPortPriorityGroupThreshold(ConfigureBSTThresholds): + def __init__(self, host, port, + eport, + priorityGroup, + umShareThreshold, + umHeadroomThreshold): + super(ConfigureIngressPortPriorityGroupThreshold, self).__init__(host, port) + self.__realm = "ingress-port-priority-group" + self.__port = eport + self.__priorityGroup = priorityGroup + self.__umShareThreshold = umShareThreshold + self.__umHeadroomThreshold = umHeadroomThreshold + + def getParams(self): + ret = {} + ret["realm"] = self.__realm + ret["port"] = self.__port + ret["priority-group"] = self.__priorityGroup + ret["um-share-threshold"] = self.__umShareThreshold + ret["um-headroom-threshold"] = self.__umHeadroomThreshold + return ret + +class ConfigureIngressPortServicePoolThreshold(ConfigureBSTThresholds): + def __init__(self, host, port, + eport, + servicePool, + threshold): + super(ConfigureIngressPortServicePoolThreshold, self).__init__(host, port) + self.__realm = "ingress-port-service-pool" + self.__port = eport + self.__servicePool = servicePool + self.__threshold = threshold + + def getParams(self): + ret = {} + ret["realm"] = self.__realm + ret["port"] = self.__port + ret["service-pool"] = self.__servicePool + ret["um-share-threshold"] = self.__threshold + return ret + +class ConfigureIngressServicePoolThreshold(ConfigureBSTThresholds): + def __init__(self, host, port, servicePool, threshold): + super(ConfigureIngressServicePoolThreshold, self).__init__(host, port) + self.__realm = "ingress-service-pool" + self.__servicePool = servicePool + self.__threshold = threshold + + def getParams(self): + ret = {} + ret["realm"] = self.__realm + ret["service-pool"] = self.__servicePool + ret["um-share-threshold"] = self.__threshold + return ret + +class ClearBSTStatistics(AgentAPI): + def __init__(self, host, port): + super(ClearBSTStatistics, self).__init__() + self.setFeature("bst") + self.setHttpMethod("POST") + self.setHost(host) + self.setPort(port) + self.__asic_id = "1" + + def setASIC(self, val): + self.__asic_id = val + + def send(self): + status, json = self._send(self.toDict()) + return status + + def toDict(self): + ret = {} + params = {} + ret["asic-id"] = self.__asic_id + ret["params"] = params + ret["method"] = "clear-bst-statistics" + return ret + +class ClearBSTThresholds(AgentAPI): + def __init__(self, host, port): + super(ClearBSTThresholds, self).__init__() + self.setFeature("bst") + self.setHttpMethod("POST") + self.setHost(host) + self.setPort(port) + self.__asic_id = "1" + + def setASIC(self, val): + self.__asic_id = val + + def send(self): + status, json = self._send(self.toDict()) + return status + + def toDict(self): + ret = {} + params = {} + ret["asic-id"] = self.__asic_id + ret["params"] = params + ret["method"] = "clear-bst-thresholds" + return ret + +''' + +Status/Reporting Requests + +''' + +class GetBSTFeature(AgentAPI): + def __init__(self, host, port): + super(GetBSTFeature, self).__init__() + self.setFeature("bst") + self.setHttpMethod("POST") + self.setHost(host) + self.setPort(port) + self.__bst_enable = False + self.__version = 1 + self.__send_async_reports = False + self.__collection_interval = 200 + self.__stat_in_percentage = False + self.__stat_units_in_cells = False + self.__trigger_rate_limit = False + self.__trigger_rate_limit_interval = 0 + self.__send_snapshot_on_trigger = False + self.__asic_id = "1" + self.__json = None + + def getEnable(self): + return self.__bst_enable + + def getSendAsyncReports(self): + return self.__send_async_reports + + def getCollectionInterval(self): + return self.__collection_interval + + def getStatInPercentage(self): + return self.__stat_in_percentage + + def getStatUnitsInCells(self): + return self.__stat_units_in_cells + + def getTriggerRateLimit(self): + return self.__trigger_rate_limit + + def getTriggerRateLimitInterval(self): + return self.__trigger_rate_limit_interval + + def getSendSnapshotOnTrigger(self): + return self.__send_snapshot_on_trigger + + def getAsyncFullReports(self): + return self.__async_full_reports + + def getASIC(self): + return self.__asic_id + + def setASIC(self, val): + self.__asic_id = val + + def getJSON(self): + return self.__json + + def send(self): + status, json = self._send(self.toDict()) + if status == 200: + self.__version = json["version"] + res = json["result"] + self.__json = res + self.__bst_enable = res["bst-enable"] == 1 + self.__send_async_reports = res["send-async-reports"] == 1 + self.__collection_interval = res["collection-interval"] + # XXX self.__stat_in_percentage = res["stat-in-percentage"] == 1 + self.__stat_units_in_cells = res["stat-units-in-cells"] == 1 + self.__trigger_rate_limit = res["trigger-rate-limit"] == 1 + self.__trigger_rate_limit_interval = res["trigger-rate-limit-interval"] + self.__send_snapshot_on_trigger = res["send-snapshot-on-trigger"] == 1 + return status + + def toDict(self): + ret = {} + params = {} + ret["asic-id"] = self.__asic_id + ret["params"] = params + ret["method"] = "get-bst-feature" + return ret + +class GetBSTTracking(AgentAPI): + def __init__(self, host, port): + super(GetBSTTracking, self).__init__() + self.setFeature("bst") + self.setHttpMethod("POST") + self.setHost(host) + self.setPort(port) + self.__track_peak_stats = False + self.__track_ingress_port_priority_group = False + self.__track_ingress_port_service_pool = False + self.__track_ingress_service_pool = False + self.__track_egress_port_service_pool = False + self.__track_egress_service_pool = False + self.__track_egress_uc_queue = False + self.__track_egress_uc_queue_group = False + self.__track_egress_mc_queue = False + self.__track_egress_cpu_queue = False + self.__track_egress_rqe_queue = False + self.__track_device = False + self.__asic_id = "1" + self.__json = None + + def getTrackPeakStats(self): + return self.__track_peak_stats + + def getTrackIngressPortPriorityGroup(self): + return self.__track_ingress_port_priority_group + + def getTrackIngressPortServicePool(self): + return self.__track_ingress_port_service_pool + + def getTrackIngressServicePool(self): + return self.__track_ingress_service_pool + + def getTrackEgressPortServicePool(self): + return self.__track_egress_port_service_pool + + def getTrackEgressServicePool(self): + return self.__track_egress_service_pool + + def getTrackEgressUcQueue(self): + return self.__track_egress_uc_queue + + def getTrackEgressUcQueueGroup(self): + return self.__track_egress_uc_queue_group + + def getTrackEgressMcQueue(self): + return self.__track_egress_mc_queue + + def getTrackEgressCPUQueue(self): + return self.__track_egress_cpu_queue + + def getTrackEgressRQEQueue(self): + return self.__track_egress_rqe_queue + + def getTrackDevice(self): + return self.__track_device + + def getASIC(self): + return self.__asic_id + + def setASIC(self, val): + self.__asic_id = val + + def getJSON(self): + return self.__json + + def send(self): + status, json = self._send(self.toDict()) + if status == 200: + self.__version = json["version"] + res = json["result"] + self.__json = res + self.__track_peak_stats = res["track-peak-stats"] == 1 + self.__track_ingress_port_priority_group = res["track-ingress-port-priority-group"] == 1 + self.__track_ingress_port_service_pool = res["track-ingress-port-service-pool"] == 1 + self.__track_ingress_service_pool = res["track-ingress-service-pool"] == 1 + self.__track_egress_port_service_pool = res["track-egress-port-service-pool"] == 1 + self.__track_egress_service_pool = res["track-egress-service-pool"] == 1 + self.__track_egress_uc_queue = res["track-egress-uc-queue"] == 1 + self.__track_egress_uc_queue_group = res["track-egress-uc-queue-group"] == 1 + self.__track_egress_mc_queue = res["track-egress-mc-queue"] == 1 + self.__track_egress_cpu_queue = res["track-egress-cpu-queue"] == 1 + self.__track_egress_rqe_queue = res["track-egress-rqe-queue"] == 1 + self.__track_device = res["track-device"] == 1 + return status + + def toDict(self): + ret = {} + params = {} + ret["asic-id"] = self.__asic_id + ret["params"] = params + ret["method"] = "get-bst-tracking" + return ret + +class GetBSTThresholds(AgentAPI): + def __init__(self, host, port): + super(GetBSTThresholds, self).__init__() + self.setFeature("bst") + self.setHttpMethod("POST") + self.setHost(host) + self.setPort(port) + self.__include_ingress_port_priority_group = False + self.__include_ingress_port_service_pool = False + self.__include_ingress_service_pool = False + self.__include_egress_port_service_pool = False + self.__include_egress_service_pool = False + self.__include_egress_uc_queue = False + self.__include_egress_uc_queue_group = False + self.__include_egress_mc_queue = False + self.__include_egress_cpu_queue = False + self.__include_egress_rqe_queue = False + self.__include_device = False + self.__asic_id = "1" + + def setIncludeIngressPortPriorityGroup(self, val): + self.__include_ingress_port_priority_group = val + + def setIncludeIngressPortServicePool(self, val): + self.__include_ingress_port_service_pool = val + + def setIncludeIngressServicePool(self, val): + self.__include_ingress_service_pool = val + + def setIncludeEgressPortServicePool(self, val): + self.__include_egress_port_service_pool = val + + def setIncludeEgressServicePool(self, val): + self.__include_egress_service_pool = val + + def setIncludeEgressUcQueue(self, val): + self.__include_egress_uc_queue = val + + def setIncludeEgressUcQueueGroup(self, val): + self.__include_egress_uc_queue_group = val + + def setIncludeEgressMcQueue(self, val): + self.__include_egress_mc_queue = val + + def setIncludeEgressCPUQueue(self, val): + self.__include_egress_cpu_queue = val + + def setIncludeEgressRQEQueue(self, val): + self.__include_egress_rqe_queue = val + + def setIncludeDevice(self, val): + self.__include_device = val + + def setASIC(self, val): + self.__asic_id = val + + def getJSON(self): + return self.__json + + def send(self): + rep = None + status, json = self._send(self.toDict()) + if status == 200: + rep = BSTParser() + self.__json = json["report"] + rep.process(json) + return status, rep + + def toDict(self): + ret = {} + params = {} + params["include-ingress-port-priority-group"] = 1 if self.__include_ingress_port_priority_group else 0 + params["include-ingress-port-service-pool"] = 1 if self.__include_ingress_port_service_pool else 0 + params["include-ingress-service-pool"] = 1 if self.__include_ingress_service_pool else 0 + params["include-egress-port-service-pool"] = 1 if self.__include_egress_port_service_pool else 0 + params["include-egress-service-pool"] = 1 if self.__include_egress_service_pool else 0 + params["include-egress-uc-queue"] = 1 if self.__include_egress_uc_queue else 0 + params["include-egress-uc-queue-group"] = 1 if self.__include_egress_uc_queue_group else 0 + params["include-egress-mc-queue"] = 1 if self.__include_egress_mc_queue else 0 + params["include-egress-cpu-queue"] = 1 if self.__include_egress_cpu_queue else 0 + params["include-egress-rqe-queue"] = 1 if self.__include_egress_rqe_queue else 0 + params["include-device"] = 1 if self.__include_device else 0 + + ret["asic-id"] = self.__asic_id + ret["params"] = params + ret["method"] = "get-bst-thresholds" + return ret + +class GetBSTReport(AgentAPI): + def __init__(self, host, port): + super(GetBSTReport, self).__init__() + self.setFeature("bst") + self.setHttpMethod("POST") + self.setHost(host) + self.setPort(port) + self.__include_ingress_port_priority_group = False + self.__include_ingress_port_service_pool = False + self.__include_ingress_service_pool = False + self.__include_egress_port_service_pool = False + self.__include_egress_service_pool = False + self.__include_egress_uc_queue = False + self.__include_egress_uc_queue_group = False + self.__include_egress_mc_queue = False + self.__include_egress_cpu_queue = False + self.__include_egress_rqe_queue = False + self.__include_device = False + self.__asic_id = "1" + self.__json = None + + def setIncludeIngressPortPriorityGroup(self, val): + self.__include_ingress_port_priority_group = val + + def setIncludeIngressPortServicePool(self, val): + self.__include_ingress_port_service_pool = val + + def setIncludeIngressServicePool(self, val): + self.__include_ingress_service_pool = val + + def setIncludeEgressPortServicePool(self, val): + self.__include_egress_port_service_pool = val + + def setIncludeEgressServicePool(self, val): + self.__include_egress_service_pool = val + + def setIncludeEgressUcQueue(self, val): + self.__include_egress_uc_queue = val + + def setIncludeEgressUcQueueGroup(self, val): + self.__include_egress_uc_queue_group = val + + def setIncludeEgressMcQueue(self, val): + self.__include_egress_mc_queue = val + + def setIncludeEgressCPUQueue(self, val): + self.__include_egress_cpu_queue = val + + def setIncludeEgressRQEQueue(self, val): + self.__include_egress_rqe_queue = val + + def setIncludeDevice(self, val): + self.__include_device = val + + def setASIC(self, val): + self.__asic_id = val + + def getJSON(self): + return self.__json + + def send(self): + status, json = self._send(self.toDict()) + rep = None + if status == 200: + self.__json = json["report"] + rep = BSTParser() + rep.process(json) + else: + pass + return status, rep + + def toDict(self): + ret = {} + params = {} + params["include-ingress-port-priority-group"] = 1 if self.__include_ingress_port_priority_group else 0 + params["include-ingress-port-service-pool"] = 1 if self.__include_ingress_port_service_pool else 0 + params["include-ingress-service-pool"] = 1 if self.__include_ingress_service_pool else 0 + params["include-egress-port-service-pool"] = 1 if self.__include_egress_port_service_pool else 0 + params["include-egress-service-pool"] = 1 if self.__include_egress_service_pool else 0 + params["include-egress-uc-queue"] = 1 if self.__include_egress_uc_queue else 0 + params["include-egress-uc-queue-group"] = 1 if self.__include_egress_uc_queue_group else 0 + params["include-egress-mc-queue"] = 1 if self.__include_egress_mc_queue else 0 + params["include-egress-cpu-queue"] = 1 if self.__include_egress_cpu_queue else 0 + params["include-egress-rqe-queue"] = 1 if self.__include_egress_rqe_queue else 0 + params["include-device"] = 1 if self.__include_device else 0 + ret["asic-id"] = self.__asic_id + ret["params"] = params + ret["method"] = "get-bst-report" + return ret + +class TestBSTAPIParams(unittest.TestCase): + + def setUp(self): + pass + + def test_ConfigureBSTFeature(self): + + sw = BroadViewBSTSwitches() + if len(sw): + for x in sw: + host = x["ip"] + port = x["port"] + break + else: + host = "192.168.3.1" + port = 8080 + + x = ConfigureBSTFeature(host, port) + d = x.toDict() + self.assertTrue("asic-id" in d) + self.assertTrue("params" in d) + self.assertTrue("method" in d) + self.assertTrue(x.getFeature() == "bst") + self.assertTrue(x.getHttpMethod() == "POST") + self.assertTrue(x.getHost() == host) + self.assertTrue(x.getPort() == port) + self.assertTrue(d["asic-id"] == "1") + self.assertTrue(d["method"] == "configure-bst-feature") + + params = d["params"] + self.assertEqual(params["bst-enable"], False) + self.assertEqual(params["send-async-reports"], False) + self.assertEqual(params["collection-interval"], 60) + self.assertEqual(params["stat-in-percentage"], False) + self.assertEqual(params["stat-units-in-cells"], False) + self.assertEqual(params["trigger-rate-limit"], 1) + self.assertEqual(params["trigger-rate-limit-interval"], 1) + self.assertEqual(params["send-snapshot-on-trigger"], True) + self.assertEqual(params["async-full-reports"], False) + + x.setEnable(True) + x.setSendAsyncReports(True) + x.setCollectionInterval(120) + x.setStatInPercentage(True) + x.setStatUnitsInCells(True) + x.setTriggerRateLimit(15) + x.setTriggerRateLimitInterval(99) + x.setSendSnapshotOnTrigger(False) + x.setAsyncFullReports(True) + d = x.toDict() + + params = d["params"] + self.assertEqual(params["bst-enable"], True) + self.assertEqual(params["send-async-reports"], True) + self.assertEqual(params["collection-interval"], 120) + self.assertEqual(params["stat-in-percentage"], True) + self.assertEqual(params["stat-units-in-cells"], True) + self.assertEqual(params["trigger-rate-limit"], 15) + self.assertEqual(params["trigger-rate-limit-interval"], 99) + self.assertEqual(params["send-snapshot-on-trigger"], False) + self.assertEqual(params["async-full-reports"], True) + + def test_ConfigureBSTTracking(self): + host = "192.168.3.1" + port = 8080 + x = ConfigureBSTTracking(host, port) + d = x.toDict() + self.assertTrue("asic-id" in d) + self.assertTrue("params" in d) + self.assertTrue("method" in d) + self.assertTrue(x.getFeature() == "bst") + self.assertTrue(x.getHttpMethod() == "POST") + self.assertTrue(x.getHost() == host) + self.assertTrue(x.getPort() == port) + self.assertTrue(d["asic-id"] == "1") + self.assertTrue(d["method"] == "configure-bst-tracking") + + params = d["params"] + + self.assertEqual(params["track-peak-stats"], False) + self.assertEqual(params["track-ingress-port-priority-group"], False) + self.assertEqual(params["track-ingress-port-service-pool"], False) + self.assertEqual(params["track-ingress-service-pool"], False) + self.assertEqual(params["track-egress-port-service-pool"], False) + self.assertEqual(params["track-egress-service-pool"], False) + self.assertEqual(params["track-egress-uc-queue"], False) + self.assertEqual(params["track-egress-uc-queue-group"], False) + self.assertEqual(params["track-egress-mc-queue"], False) + self.assertEqual(params["track-egress-cpu-queue"], False) + self.assertEqual(params["track-egress-rqe-queue"], False) + self.assertEqual(params["track-device"], False) + + x.setTrackPeakStats(True) + x.setTrackIngressPortPriorityGroup(True) + x.setTrackIngressPortServicePool(True) + x.setTrackIngressServicePool(True) + x.setTrackEgressPortServicePool(True) + x.setTrackEgressServicePool(True) + x.setTrackEgressUcQueue(True) + x.setTrackEgressUcQueueGroup(True) + x.setTrackEgressMcQueue(True) + x.setTrackEgressCPUQueue(True) + x.setTrackEgressRQEQueue(True) + x.setTrackDevice(True) + x.setASIC("3") + + d = x.toDict() + self.assertTrue(d["asic-id"] == "3") + + params = d["params"] + + self.assertEqual(params["track-peak-stats"], True) + self.assertEqual(params["track-ingress-port-priority-group"], True) + self.assertEqual(params["track-ingress-port-service-pool"], True) + self.assertEqual(params["track-ingress-service-pool"], True) + self.assertEqual(params["track-egress-port-service-pool"], True) + self.assertEqual(params["track-egress-service-pool"], True) + self.assertEqual(params["track-egress-uc-queue"], True) + self.assertEqual(params["track-egress-uc-queue-group"], True) + self.assertEqual(params["track-egress-mc-queue"], True) + self.assertEqual(params["track-egress-cpu-queue"], True) + self.assertEqual(params["track-egress-rqe-queue"], True) + self.assertEqual(params["track-device"], True) + + def test_ClearBSTStatistics(self): + host = "192.168.3.1" + port = 8080 + x = ClearBSTStatistics(host, port) + d = x.toDict() + self.assertTrue("asic-id" in d) + self.assertTrue("params" in d) + self.assertTrue("method" in d) + self.assertTrue(x.getFeature() == "bst") + self.assertTrue(x.getHttpMethod() == "POST") + self.assertTrue(x.getHost() == host) + self.assertTrue(x.getPort() == port) + self.assertTrue(d["asic-id"] == "1") + self.assertTrue(d["method"] == "clear-bst-statistics") + self.assertTrue(not d["params"]) # assert empty + + x.setASIC("3") + + d = x.toDict() + self.assertTrue(d["asic-id"] == "3") + + def test_ClearBSTThresholds(self): + host = "192.168.3.1" + port = 8080 + x = ClearBSTThresholds(host, port) + d = x.toDict() + self.assertTrue("asic-id" in d) + self.assertTrue("params" in d) + self.assertTrue("method" in d) + self.assertTrue(x.getFeature() == "bst") + self.assertTrue(x.getHttpMethod() == "POST") + self.assertTrue(x.getHost() == host) + self.assertTrue(x.getPort() == port) + self.assertTrue(d["asic-id"] == "1") + self.assertTrue(d["method"] == "clear-bst-thresholds") + self.assertTrue(not d["params"]) # assert empty + + x.setASIC("3") + + d = x.toDict() + self.assertTrue(d["asic-id"] == "3") + + def test_GetBSTThresholds(self): + host = "192.168.3.1" + port = 8080 + x = GetBSTThresholds(host, port) + d = x.toDict() + self.assertTrue("asic-id" in d) + self.assertTrue("params" in d) + self.assertTrue("method" in d) + self.assertTrue(x.getFeature() == "bst") + self.assertTrue(x.getHttpMethod() == "POST") + self.assertTrue(x.getHost() == host) + self.assertTrue(x.getPort() == port) + self.assertTrue(d["asic-id"] == "1") + self.assertTrue(d["method"] == "get-bst-thresholds") + + x.setASIC("3") + + d = x.toDict() + self.assertTrue(d["asic-id"] == "3") + + def test_GetBSTFeature(self): + host = "192.168.3.1" + port = 8080 + x = GetBSTFeature(host, port) + d = x.toDict() + self.assertTrue("asic-id" in d) + self.assertTrue("params" in d) + self.assertTrue("method" in d) + self.assertTrue(x.getFeature() == "bst") + self.assertTrue(x.getHttpMethod() == "POST") + self.assertTrue(x.getHost() == host) + self.assertTrue(x.getPort() == port) + self.assertTrue(d["asic-id"] == "1") + self.assertTrue(d["method"] == "get-bst-feature") + self.assertTrue(not d["params"]) # assert empty + + x.setASIC("3") + + d = x.toDict() + self.assertTrue(d["asic-id"] == "3") + + def test_GetBSTReport(self): + host = "192.168.3.1" + port = 8080 + x = GetBSTReport(host, port) + d = x.toDict() + self.assertTrue("asic-id" in d) + self.assertTrue("params" in d) + self.assertTrue("method" in d) + self.assertTrue(x.getFeature() == "bst") + self.assertTrue(x.getHttpMethod() == "POST") + self.assertTrue(x.getHost() == host) + self.assertTrue(x.getPort() == port) + self.assertTrue(d["asic-id"] == "1") + self.assertTrue(d["method"] == "get-bst-report") + + x.setASIC("3") + + d = x.toDict() + self.assertTrue(d["asic-id"] == "3") + + + def test_ConfigureDeviceThreshold(self): + host = "192.168.3.1" + port = 8080 + x = ConfigureDeviceThreshold(host, port, 10000) + d = x.toDict() + self.assertTrue("asic-id" in d) + self.assertTrue("params" in d) + self.assertTrue("method" in d) + self.assertTrue(d["asic-id"] == "1") + self.assertTrue(d["method"] == "configure-bst-thresholds") + parms = x.getParams() + self.assertTrue(parms["realm"] == "device") + self.assertTrue(parms["threshold"] == 10000) + + def test_ConfigureEgressCpuQueueThreshold(self): + host = "192.168.3.1" + port = 8080 + x = ConfigureEgressCpuQueueThreshold(host, port, 5, 10000) + d = x.toDict() + self.assertTrue("asic-id" in d) + self.assertTrue("params" in d) + self.assertTrue("method" in d) + self.assertTrue(d["asic-id"] == "1") + self.assertTrue(d["method"] == "configure-bst-thresholds") + parms = x.getParams() + self.assertTrue(parms["realm"] == "egress-cpu-queue") + self.assertTrue(parms["queue"] == 5) + self.assertTrue(parms["cpu-threshold"] == 10000) + + def test_ConfigureEgressRqeQueueThreshold(self): + host = "192.168.3.1" + port = 8080 + x = ConfigureEgressRqeQueueThreshold(host, port, 5, 10000) + d = x.toDict() + self.assertTrue("asic-id" in d) + self.assertTrue("params" in d) + self.assertTrue("method" in d) + self.assertTrue(d["asic-id"] == "1") + self.assertTrue(d["method"] == "configure-bst-thresholds") + parms = x.getParams() + self.assertTrue(parms["realm"] == "egress-rqe-queue") + self.assertTrue(parms["queue"] == 5) + self.assertTrue(parms["rqe-threshold"] == 10000) + + def test_ConfigureEgressPortServicePoolThreshold(self): + host = "192.168.3.1" + port = 8080 + x = ConfigureEgressPortServicePoolThreshold(host, port, "2", 5, 100, 200, 300, 400) + d = x.toDict() + self.assertTrue("asic-id" in d) + self.assertTrue("params" in d) + self.assertTrue("method" in d) + self.assertTrue(d["asic-id"] == "1") + self.assertTrue(d["method"] == "configure-bst-thresholds") + parms = x.getParams() + self.assertTrue(parms["realm"] == "egress-port-service-pool") + self.assertTrue(parms["port"] == "2") + self.assertTrue(parms["service-pool"] == 5) + self.assertTrue(parms["uc-share-threshold"] == 100) + self.assertTrue(parms["um-share-threshold"] == 200) + self.assertTrue(parms["mc-share-threshold"] == 300) + self.assertTrue(parms["mc-share-queue-entries-threshold"] == 400) + + def test_ConfigureEgressServicePoolThreshold(self): + host = "192.168.3.1" + port = 8080 + x = ConfigureEgressServicePoolThreshold(host, port, 5, 100, 200, 300) + d = x.toDict() + self.assertTrue("asic-id" in d) + self.assertTrue("params" in d) + self.assertTrue("method" in d) + self.assertTrue(d["asic-id"] == "1") + self.assertTrue(d["method"] == "configure-bst-thresholds") + parms = x.getParams() + self.assertTrue(parms["realm"] == "egress-service-pool") + self.assertTrue(parms["service-pool"] == 5) + self.assertTrue(parms["um-share-threshold"] == 100) + self.assertTrue(parms["mc-share-threshold"] == 200) + self.assertTrue(parms["mc-share-queue-entries-threshold"] == 300) + + def test_ConfigureEgressUcQueueThreshold(self): + host = "192.168.3.1" + port = 8080 + x = ConfigureEgressUcQueueThreshold(host, port, 5, 100) + d = x.toDict() + self.assertTrue("asic-id" in d) + self.assertTrue("params" in d) + self.assertTrue("method" in d) + self.assertTrue(d["asic-id"] == "1") + self.assertTrue(d["method"] == "configure-bst-thresholds") + parms = x.getParams() + self.assertTrue(parms["realm"] == "egress-uc-queue") + self.assertTrue(parms["queue"] == 5) + self.assertTrue(parms["uc-threshold"] == 100) + + def test_ConfigureEgressUcQueueGroupThreshold(self): + host = "192.168.3.1" + port = 8080 + x = ConfigureEgressUcQueueGroupThreshold(host, port, 7, 200) + d = x.toDict() + self.assertTrue("asic-id" in d) + self.assertTrue("params" in d) + self.assertTrue("method" in d) + self.assertTrue(d["asic-id"] == "1") + self.assertTrue(d["method"] == "configure-bst-thresholds") + parms = x.getParams() + self.assertTrue(parms["realm"] == "egress-uc-queue-group") + self.assertTrue(parms["queue-group"] == 7) + self.assertTrue(parms["uc-threshold"] == 200) + + def test_ConfigureEgressMcQueueThreshold(self): + host = "192.168.3.1" + port = 8080 + x = ConfigureEgressMcQueueThreshold(host, port, 7, 100, 200) + d = x.toDict() + self.assertTrue("asic-id" in d) + self.assertTrue("params" in d) + self.assertTrue("method" in d) + self.assertTrue(d["asic-id"] == "1") + self.assertTrue(d["method"] == "configure-bst-thresholds") + parms = x.getParams() + self.assertTrue(parms["realm"] == "egress-mc-queue") + self.assertTrue(parms["queue"] == 7) + self.assertTrue(parms["mc-queue-entries-threshold"] == 100) + self.assertTrue(parms["mc-threshold"] == 200) + + def test_ConfigureEgressMcQueueThreshold(self): + host = "192.168.3.1" + port = 8080 + x = ConfigureEgressMcQueueThreshold(host, port, 7, 100, 200) + d = x.toDict() + self.assertTrue("asic-id" in d) + self.assertTrue("params" in d) + self.assertTrue("method" in d) + self.assertTrue(d["asic-id"] == "1") + self.assertTrue(d["method"] == "configure-bst-thresholds") + parms = x.getParams() + self.assertTrue(parms["realm"] == "egress-mc-queue") + self.assertTrue(parms["queue"] == 7) + self.assertTrue(parms["mc-queue-entries-threshold"] == 100) + self.assertTrue(parms["mc-threshold"] == 200) + + def test_ConfigureIngressPortPriorityGroupThreshold(self): + host = "192.168.3.1" + port = 8080 + x = ConfigureIngressPortPriorityGroupThreshold(host, port, "3", 7, 100, 200) + d = x.toDict() + self.assertTrue("asic-id" in d) + self.assertTrue("params" in d) + self.assertTrue("method" in d) + self.assertTrue(d["asic-id"] == "1") + self.assertTrue(d["method"] == "configure-bst-thresholds") + parms = x.getParams() + self.assertTrue(parms["realm"] == "ingress-port-priority-group") + self.assertTrue(parms["port"] == "3") + self.assertTrue(parms["priority-group"] == 7) + self.assertTrue(parms["um-share-threshold"] == 100) + self.assertTrue(parms["um-headroom-threshold"] == 200) + + def test_ConfigureIngressPortServicePoolThreshold(self): + host = "192.168.3.1" + port = 8080 + x = ConfigureIngressPortServicePoolThreshold(host, port, "3", 7, 100) + d = x.toDict() + self.assertTrue("asic-id" in d) + self.assertTrue("params" in d) + self.assertTrue("method" in d) + self.assertTrue(d["asic-id"] == "1") + self.assertTrue(d["method"] == "configure-bst-thresholds") + parms = x.getParams() + self.assertTrue(parms["realm"] == "ingress-port-service-pool") + self.assertTrue(parms["port"] == "3") + self.assertTrue(parms["service-pool"] == 7) + self.assertTrue(parms["um-share-threshold"] == 100) + + def test_ConfigureIngressServicePoolThreshold(self): + host = "192.168.3.1" + port = 8080 + x = ConfigureIngressServicePoolThreshold(host, port, 7, 200) + d = x.toDict() + self.assertTrue("asic-id" in d) + self.assertTrue("params" in d) + self.assertTrue("method" in d) + self.assertTrue(d["asic-id"] == "1") + self.assertTrue(d["method"] == "configure-bst-thresholds") + parms = x.getParams() + self.assertTrue(parms["realm"] == "ingress-service-pool") + self.assertTrue(parms["service-pool"] == 7) + self.assertTrue(parms["um-share-threshold"] == 200) + +if __name__ == "__main__": + unittest.main() diff --git a/broadview_lib/tests/__init__.py b/broadview_lib/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/broadview_lib/tests/base.py b/broadview_lib/tests/base.py new file mode 100644 index 0000000..185fd6f --- /dev/null +++ b/broadview_lib/tests/base.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- + +# Copyright 2010-2011 OpenStack Foundation +# Copyright (c) 2013 Hewlett-Packard Development Company, L.P. +# +# 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 oslotest import base + + +class TestCase(base.BaseTestCase): + + """Test case base class for all unit tests.""" \ No newline at end of file diff --git a/broadview_lib/tests/test_broadview_lib.py b/broadview_lib/tests/test_broadview_lib.py new file mode 100644 index 0000000..79de1bb --- /dev/null +++ b/broadview_lib/tests/test_broadview_lib.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- + +# 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. + +""" +test_broadview_lib +---------------------------------- + +Tests for `broadview_lib` module. +""" + +from broadview_lib.tests import base + + +class TestBroadview_lib(base.TestCase): + + def test_something(self): + pass diff --git a/broadview_lib/tools/bv-bstctl.py b/broadview_lib/tools/bv-bstctl.py new file mode 100644 index 0000000..d2e376d --- /dev/null +++ b/broadview_lib/tools/bv-bstctl.py @@ -0,0 +1,563 @@ +# (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.bst import * +from broadview_lib.config.broadviewconfig import BroadViewBSTSwitches +import sys +import unittest + +class BSTConfigCommand(): + def __init__(self): + self.__cmds = { + "cfg-feature" : self.handleCfgFeature, + "cfg-tracking" : self.handleCfgTracking, + "cfg-thresholds" : self.handleCfgThresholds, + "clr-statistics" : self.handleClrStatistics, + "clr-thresholds" : self.handleClrThresholds, + "get-feature" : self.handleGetFeature, + "get-tracking" : self.handleGetTracking, + "get-thresholds" : self.handleGetThresholds, + "get-report" : self.handleGetReport, + "help": self.handleHelp, + } + + self.__help = { + "cfg-feature" : self.helpCfgFeature, + "cfg-tracking" : self.helpCfgTracking, + "cfg-thresholds" : self.helpCfgThresholds, + "clr-statistics" : self.helpClrStatistics, + "clr-thresholds" : self.helpClrThresholds, + "get-feature" : self.helpGetFeature, + "get-tracking" : self.helpGetTracking, + "get-thresholds" : self.helpGetThresholds, + "get-report" : self.helpGetReport, + } + + 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 [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 handleCfgFeature(self, args): + usage = False + usage, asic, host, port = self.getASICHostPort(args) + if not usage: + x = ConfigureBSTFeature(host, port) + x.setASIC(asic) + x.setEnable("enable" in args) + x.setSendAsyncReports("send_async_reports" in args) + for arg in args: + if "collection_interval:" in arg: + v = arg.split(":") + if len(v) == 2: + x.setCollectionInterval(int(v[1])) + else: + print "invalid set-collection-interval argument" + usage = True + elif "trigger_rate_limit:" in arg: + v = arg.split(":") + if len(v) == 2: + x.setTriggerRateLimit(int(v[1])) + else: + print "invalid trigger_rate_limit argument" + usage = True + elif "trigger_rate_limit_interval:" in arg: + v = arg.split(":") + if len(v) == 2: + x.setTriggerRateLimitInterval(int(v[1])) + else: + print "invalid trigger_rate_limit_interval argument" + usage = True + + x.setStatInPercentage("stat_in_percentage" in args) + x.setStatUnitsInCells("stat_units_in_cells" in args) + x.setSendSnapshotOnTrigger("send_snapshot_on_trigger" in args) + x.setAsyncFullReports("async_full_reports" in args) + status = x.send() + 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" + print " send_async_reports" + print " collection_interval:val" + print " stat_in_percentage" + print " stat_units_in_cells" + print " trigger_rate_limit:val" + print " trigger_rate_limit_interval:val" + print " send_snapshot_on_trigger" + print " async_full_reports" + + def handleCfgTracking(self, args): + usage = False + usage, asic, host, port = self.getASICHostPort(args) + if not usage: + x = ConfigureBSTTracking(host, port) + x.setASIC(asic) + x.setTrackPeakStats("track_peak_stats" in args) + x.setTrackIngressPortPriorityGroup("track_ingress_port_priority_group" in args) + x.setTrackIngressPortServicePool("track_ingress_port_service_pool" in args) + x.setTrackIngressServicePool("track_ingress_service_pool" in args) + x.setTrackEgressPortServicePool("track_egress_port_service_pool" in args) + x.setTrackEgressServicePool("track_egress_service_pool" in args) + x.setTrackEgressUcQueue("track_egress_uc_queue" in args) + x.setTrackEgressUcQueueGroup("track_egress_uc_queue_group" in args) + x.setTrackEgressMcQueue("track_egress_mc_queue" in args) + x.setTrackEgressCPUQueue("track_egress_cpu_queue" in args) + x.setTrackEgressRQEQueue("track_egress_rqe_queue" in args) + x.setTrackDevice("track_device" in args) + status = x.send() + if status != 200: + print "failure: %d" % (status) + + ret = None + return usage, ret + + def helpCfgTracking(self, name): + print name, "[args]" + print + print "args:" + print + print " track_peak_stats" + print " track_ingress_port_priority_group" + print " track_ingress_port_service_pool" + print " track_ingress_service_pool" + print " track_egress_port_service_pool" + print " track_egress_service_pool" + print " track_egress_uc_queue" + print " track_egress_uc_queue_group" + print " track_egress_mc_queue" + print " track_egress_cpu_queue" + print " track_egress_rqe_queue" + print " track_device" + + def handleCfgThresholds(self, args): + usage = False + usage, asic, host, port = self.getASICHostPort(args) + if not usage: + for arg in args: + if "device:" in arg: + v = arg.split(":") + if len(v) == 2: + x = ConfigureDeviceThreshold(host, port, int(v[1])) + x.setASIC(asic) + status = x.send() + if status != 200: + print "failure: %d" % (status) + else: + print "invalid device: bad argument count" + usage = True + elif "egress-cpu-queue:" in arg: + v = arg.split(":") + if len(v) == 3: + x = ConfigureEgressCpuQueueThreshold(host, port, + int(v[1]), + int(v[2])) + x.setASIC(asic) + status = x.send() + if status != 200: + print "failure: %d" % (status) + else: + print "invalid egress-cpu-queue: bad argument count" + usage = True + elif "egress-rqe-queue:" in arg: + v = arg.split(":") + if len(v) == 3: + x = ConfigureEgressRqeQueueThreshold(host, port, + int(v[1]), + int(v[2])) + x.setASIC(asic) + status = x.send() + if status != 200: + print "failure: %d" % (status) + else: + print "invalid egress-rqe-queue: bad argument count" + usage = True + elif "egress-port-service-pool:" in arg: + v = arg.split(":") + if len(v) == 7: + x = ConfigureEgressPortServicePoolThreshold(host, port, + v[1], + int(v[2]), + int(v[3]), + int(v[4]), + int(v[5]), + int(v[6])) + x.setASIC(asic) + status = x.send() + if status != 200: + print "failure: %d" % (status) + else: + print "invalid egress-port-service-pool: bad argument count" + usage = True + elif "egress-service-pool:" in arg: + v = arg.split(":") + if len(v) == 5: + x = ConfigureEgressServicePoolThreshold(host, port, + int(v[1]), + int(v[2]), + int(v[3]), + int(v[4])) + x.setASIC(asic) + status = x.send() + if status != 200: + print "failure: %d" % (status) + else: + print "invalid egress-service-pool: bad argument count" + usage = True + elif "egress-uc-queue:" in arg: + v = arg.split(":") + if len(v) == 3: + x = ConfigureEgressUcQueueThreshold(host, port, + int(v[1]), + int(v[2])) + x.setASIC(asic) + status = x.send() + if status != 200: + print "failure: %d" % (status) + else: + print "invalid egress-uc-queue: bad argument count" + usage = True + elif "egress-uc-queue-group:" in arg: + v = arg.split(":") + if len(v) == 3: + x = ConfigureEgressUcQueueGroupThreshold(host, port, + int(v[1]), + int(v[2])) + x.setASIC(asic) + status = x.send() + if status != 200: + print "failure: %d" % (status) + else: + print "invalid egress-uc-queue-group: bad argument count" + usage = True + elif "egress-mc-queue:" in arg: + v = arg.split(":") + if len(v) == 4: + x = ConfigureEgressMcQueueThreshold(host, port, + int(v[1]), + int(v[2]), + int(v[3])) + x.setASIC(asic) + status = x.send() + if status != 200: + print "failure: %d" % (status) + else: + print "invalid egress-mc-queue-group: bad argument count" + usage = True + elif "ingress-port-priority-group:" in arg: + v = arg.split(":") + if len(v) == 5: + x = ConfigureIngressPortPriorityGroupThreshold(host, port, + v[1], + int(v[2]), + int(v[3]), + int(v[4])) + x.setASIC(asic) + status = x.send() + if status != 200: + print "failure: %d" % (status) + else: + print "invalid ingress-port-priority-group: bad argument count" + usage = True + elif "ingress-port-service-pool:" in arg: + v = arg.split(":") + if len(v) == 4: + x = ConfigureIngressPortServicePoolThreshold(host, port, + v[1], + int(v[2]), + int(v[3])) + x.setASIC(asic) + status = x.send() + if status != 200: + print "failure: %d" % (status) + else: + print "invalid ingress-port-service-pool: bad argument count" + usage = True + elif "ingress-service-pool:" in arg: + v = arg.split(":") + if len(v) == 3: + x = ConfigureIngressServicePoolThreshold(host, port, + int(v[1]), + int(v[2])) + x.setASIC(asic) + status = x.send() + if status != 200: + print "failure: %d" % (status) + else: + print "invalid ingress-service-pool: bad argument count" + usage = True + + ret = None + return usage, ret + + def helpCfgThresholds(self, name): + print name, "[args]" + print "Any number of the following args can be used in any combination." + print + print "Format of each argument is realm:arg1:arg2:...:argn" + print + print "args:" + print + print " device:threshold" + print " egress-cpu-queue:queue:cpu-threshold" + print " egress-rqe-queue:queue:rqe-threshold" + print " egress-port-service-pool:port:service-pool:uc-share-threshold:um-share-threshold:mc-share-threshold:mc-share-queue-entries-threshold" + print " egress-service-pool:service-pool:um-share-threshold:mc-share-threshold:mc-share-queue-entries-threshold" + print " egress-uc-queue:queue:uc-threshold" + print " egress-uc-queue-group:queue-group:uc-threshold" + print " egress-mc-queue:queue:mc-queue-entries-threshold" + print " ingress-port-priority-group:port:priority-group:um-share-threshold:um-headroom-threshold" + print " ingress-port-service-pool:port:service-pool:um-share-threshold" + print " ingress-service-pool:service-pool:um-share-threshold" + + def handleClrStatistics(self, args): + usage = False + usage, asic, host, port = self.getASICHostPort(args) + if not usage: + x = ClearBSTStatistics(host, port) + x.setASIC(asic) + status = x.send() + if status != 200: + print "failure: %d" % (status) + + ret = None + return usage, ret + + def helpClrStatistics(self, name): + print name + + def handleClrThresholds(self, args): + usage = False + usage, asic, host, port = self.getASICHostPort(args) + if not usage: + x = ClearBSTThresholds(host, port) + x.setASIC(asic) + status = x.send() + if status != 200: + print "failure: %d" % (status) + + ret = None + return usage, ret + + def helpClrThresholds(self, name): + print name + + def handleGetFeature(self, args): + usage = False + ret = None + usage, asic, host, port = self.getASICHostPort(args) + if not usage: + x = GetBSTFeature(host, port) + x.setASIC(asic) + status = x.send() + if status == 200: + ret = x.getJSON() + print ret + else: + print "failure: %d" % (status) + + return usage, ret + + def helpGetFeature(self, name): + print name + + def handleGetTracking(self, args): + usage = False + ret = None + usage, asic, host, port = self.getASICHostPort(args) + if not usage: + x = GetBSTTracking(host, port) + x.setASIC(asic) + status = x.send() + if status == 200: + ret = x.getJSON() + print ret + else: + print "failure: %d" % (status) + return usage, ret + + def helpGetTracking(self, name): + print name + + def handleGetThresholds(self, args): + usage = False + ret = None + usage, asic, host, port = self.getASICHostPort(args) + if not usage: + x = GetBSTThresholds(host, port) + x.setASIC(asic) + x.setIncludeIngressPortPriorityGroup("include_ingress_port_priority_group" in args) + x.setIncludeIngressPortServicePool("include_ingress_port_service_pool" in args) + x.setIncludeIngressServicePool("include_ingress_service_pool" in args) + x.setIncludeEgressPortServicePool("include_egress_port_service_pool" in args) + x.setIncludeEgressServicePool("include_egress_service_pool" in args) + x.setIncludeEgressUcQueue("include_egress_uc_queue" in args) + x.setIncludeEgressUcQueueGroup("include_egress_uc_queue_group" in args) + x.setIncludeEgressMcQueue("include_egress_mc_queue" in args) + x.setIncludeEgressCPUQueue("include_egress_cpu_queue" in args) + x.setIncludeEgressRQEQueue("include_egress_rqe_queue" in args) + x.setIncludeDevice("include_device" in args) + + status, rep = x.send() + if status == 200: + ret = x.getJSON() + print ret + else: + print "failure: %d" % (status) + + return usage, ret + + def helpGetThresholds(self, name): + print name, "[args]" + print + print "args:" + print + print " include_ingress_port_priority_group" + print " include_ingress_port_service_pool" + print " include_ingress_service_pool" + print " include_egress_port_service_pool" + print " include_egress_service_pool" + print " include_egress_uc_queue" + print " include_egress_uc_queue_group" + print " include_egress_mc_queue" + print " include_egress_cpu_queue" + print " include_egress_rqe_queue" + print " include_device" + + def handleGetReport(self, args): + usage = False + ret = None + usage, asic, host, port = self.getASICHostPort(args) + if not usage: + + x = GetBSTReport(host, port) + x.setASIC(asic) + x.setIncludeIngressPortPriorityGroup("include_ingress_port_priority_group" in args) + x.setIncludeIngressPortServicePool("include_ingress_port_service_pool" in args) + x.setIncludeIngressServicePool("include_ingress_service_pool" in args) + x.setIncludeEgressPortServicePool("include_egress_port_service_pool" in args) + x.setIncludeEgressServicePool("include_egress_service_pool" in args) + x.setIncludeEgressUcQueue("include_egress_uc_queue" in args) + x.setIncludeEgressUcQueueGroup("include_egress_uc_queue_group" in args) + x.setIncludeEgressMcQueue("include_egress_mc_queue" in args) + x.setIncludeEgressCPUQueue("include_egress_cpu_queue" in args) + x.setIncludeEgressRQEQueue("include_egress_rqe_queue" in args) + x.setIncludeDevice("include_device" in args) + + status, rep = x.send() + if status == 200: + ret = x.getJSON() + print ret + else: + print "failure: %d" % (status) + + return usage, ret + + def helpGetReport(self, name): + print name, "[args]" + print + print "args:" + print + print " include_ingress_port_priority_group" + print " include_ingress_port_service_pool" + print " include_ingress_service_pool" + print " include_egress_port_service_pool" + print " include_egress_service_pool" + print " include_egress_uc_queue" + print " include_egress_uc_queue_group" + print " include_egress_mc_queue" + print " include_egress_cpu_queue" + print " include_egress_rqe_queue" + print " include_device" + + 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 = BSTConfigCommand() + 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 new file mode 100644 index 0000000..5a27728 --- /dev/null +++ b/broadview_lib/tools/examples.sh @@ -0,0 +1,53 @@ +# (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. + +echo "********** cfg-feature **********" +python bv-bstctl.py cfg-feature host:10.14.244.128 enable send_async_reports +echo "********** get-feature **********" +python bv-bstctl.py get-feature host:10.14.244.128 +echo "********** cfg-tracking **********" +python bv-bstctl.py cfg-tracking host:10.14.244.128 track_ingress_port_priority_group +echo "********** get-tracking **********" +python bv-bstctl.py get-tracking host:10.14.244.128 +echo "********** clr-statistics **********" +python bv-bstctl.py clr-statistics host:10.14.244.128 +echo "********** clr-thresholds **********" +python bv-bstctl.py clr-thresholds host:10.14.244.128 +echo "********** cfg-thresholds **********" +python bv-bstctl.py get-thresholds host:10.14.244.128 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 **********" +python bv-bstctl.py get-report host:10.14.244.128 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 **********" +python bv-bstctl.py cfg-thresholds host:10.14.244.128 device:10100 +echo "********** cfg-thresholds egress-cpu-queue **********" +python bv-bstctl.py cfg-thresholds host:10.14.244.128 egress-cpu-queue:5:20202 +echo "********** cfg-thresholds egress-rqe-queue **********" +python bv-bstctl.py cfg-thresholds host:10.14.244.128 egress-rqe-queue:6:30130 +echo "********** cfg-thresholds egress-port-service-pool **********" +python bv-bstctl.py cfg-thresholds host:10.14.244.128 egress-port-service-pool:"2":2:204556:30000:40000:5000 +echo "********** cfg-thresholds egress-service-pool **********" +python bv-bstctl.py cfg-thresholds host:10.14.244.128 egress-service-pool:2:30:40:50 +echo "********** cfg-thresholds egress-uc-queue **********" +python bv-bstctl.py cfg-thresholds host:10.14.244.128 egress-uc-queue:5:20200 +echo "********** cfg-thresholds egress-uc-queue-group **********" +python bv-bstctl.py cfg-thresholds host:10.14.244.128 egress-uc-queue-group:5:204 +echo "********** cfg-thresholds egress-mc-queue **********" +python bv-bstctl.py cfg-thresholds host:10.14.244.128 egress-mc-queue:5:204:10500 +echo "********** cfg-thresholds ingress-port-priority-group **********" +python bv-bstctl.py cfg-thresholds host:10.14.244.128 ingress-port-priority-group:"5":2:20456:40404 +echo "********** cfg-thresholds ingress-port-service-pool **********" +python bv-bstctl.py cfg-thresholds host:10.14.244.128 ingress-port-service-pool:"4":2:50505 +echo "********** cfg-thresholds ingress-service-pool **********" +python bv-bstctl.py cfg-thresholds host:10.14.244.128 ingress-service-pool:2:56783 +# diff --git a/doc/source/conf.py b/doc/source/conf.py new file mode 100644 index 0000000..e9aea91 --- /dev/null +++ b/doc/source/conf.py @@ -0,0 +1,75 @@ +# -*- coding: utf-8 -*- +# 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 os +import sys + +sys.path.insert(0, os.path.abspath('../..')) +# -- General configuration ---------------------------------------------------- + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones. +extensions = [ + 'sphinx.ext.autodoc', + #'sphinx.ext.intersphinx', + 'oslosphinx' +] + +# autodoc generation is a bit aggressive and a nuisance when doing heavy +# text edit cycles. +# execute "export SPHINX_DEBUG=1" in your terminal to disable + +# The suffix of source filenames. +source_suffix = '.rst' + +# The master toctree document. +master_doc = 'index' + +# General information about the project. +project = u'broadview-lib' +copyright = u'2013, OpenStack Foundation' + +# If true, '()' will be appended to :func: etc. cross-reference text. +add_function_parentheses = True + +# If true, the current module name will be prepended to all description +# unit titles (such as .. function::). +add_module_names = True + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = 'sphinx' + +# -- Options for HTML output -------------------------------------------------- + +# The theme to use for HTML and HTML Help pages. Major themes that come with +# Sphinx are currently 'default' and 'sphinxdoc'. +# html_theme_path = ["."] +# html_theme = '_theme' +# html_static_path = ['static'] + +# Output file base name for HTML help builder. +htmlhelp_basename = '%sdoc' % project + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, author, documentclass +# [howto/manual]). +latex_documents = [ + ('index', + '%s.tex' % project, + u'%s Documentation' % project, + u'OpenStack Foundation', 'manual'), +] + +# Example configuration for intersphinx: refer to the Python standard library. +#intersphinx_mapping = {'http://docs.python.org/': None} \ No newline at end of file diff --git a/doc/source/contributing.rst b/doc/source/contributing.rst new file mode 100644 index 0000000..ed77c12 --- /dev/null +++ b/doc/source/contributing.rst @@ -0,0 +1,4 @@ +============ +Contributing +============ +.. include:: ../../CONTRIBUTING.rst \ No newline at end of file diff --git a/doc/source/index.rst b/doc/source/index.rst new file mode 100644 index 0000000..e12c2e4 --- /dev/null +++ b/doc/source/index.rst @@ -0,0 +1,24 @@ +.. broadview-lib documentation master file, created by + sphinx-quickstart on Tue Jul 9 22:26:36 2013. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + +Welcome to broadview-lib's documentation! +======================================================== + +Contents: + +.. toctree:: + :maxdepth: 2 + + readme + installation + usage + contributing + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` diff --git a/doc/source/installation.rst b/doc/source/installation.rst new file mode 100644 index 0000000..a6adf16 --- /dev/null +++ b/doc/source/installation.rst @@ -0,0 +1,12 @@ +============ +Installation +============ + +At the command line:: + + $ pip install broadview-lib + +Or, if you have virtualenvwrapper installed:: + + $ mkvirtualenv broadview-lib + $ pip install broadview-lib \ No newline at end of file diff --git a/doc/source/readme.rst b/doc/source/readme.rst new file mode 100644 index 0000000..38ba804 --- /dev/null +++ b/doc/source/readme.rst @@ -0,0 +1 @@ +.. include:: ../../README.rst \ No newline at end of file diff --git a/doc/source/usage.rst b/doc/source/usage.rst new file mode 100644 index 0000000..ae50ffc --- /dev/null +++ b/doc/source/usage.rst @@ -0,0 +1,7 @@ +======== +Usage +======== + +To use broadview-lib in a project:: + + import broadview_lib \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..59b1755 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,5 @@ +# The order of packages is significant, because pip processes them in the order +# of appearance. Changing the order has an impact on the overall integration +# process, which may cause wedges in the gate later. + +pbr>=1.6 \ No newline at end of file diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..d49ef0f --- /dev/null +++ b/setup.cfg @@ -0,0 +1,46 @@ +[metadata] +name = broadview-lib +summary = OpenStack broadview-lib provides an API for interaction with Broadcom BroadView agents +description-file = + README.rst +author = OpenStack +author-email = openstack-dev@lists.openstack.org +home-page = http://www.openstack.org/ +classifier = + Environment :: OpenStack + Intended Audience :: Information Technology + Intended Audience :: System Administrators + License :: OSI Approved :: Apache Software License + Operating System :: POSIX :: Linux + Programming Language :: Python + Programming Language :: Python :: 2 + Programming Language :: Python :: 2.7 + Programming Language :: Python :: 3 + Programming Language :: Python :: 3.3 + Programming Language :: Python :: 3.4 + +[files] +packages = + broadview_lib + +[build_sphinx] +source-dir = doc/source +build-dir = doc/build +all_files = 1 + +[upload_sphinx] +upload-dir = doc/build/html + +[compile_catalog] +directory = broadview-lib/locale +domain = broadview-lib + +[update_catalog] +domain = broadview-lib +output_dir = broadview-lib/locale +input_file = broadview-lib/locale/broadview-lib.pot + +[extract_messages] +keywords = _ gettext ngettext l_ lazy_gettext +mapping_file = babel.cfg +output_file = broadview-lib/locale/broadview-lib.pot \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..4b34a0a --- /dev/null +++ b/setup.py @@ -0,0 +1,29 @@ +# Copyright (c) 2013 Hewlett-Packard Development Company, L.P. +# +# 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. + +# THIS FILE IS MANAGED BY THE GLOBAL REQUIREMENTS REPO - DO NOT EDIT +import setuptools + +# In python < 2.7.4, a lazy loading of package `pbr` will break +# setuptools if some other modules registered functions in `atexit`. +# solution from: http://bugs.python.org/issue15881#msg170215 +try: + import multiprocessing # noqa +except ImportError: + pass + +setuptools.setup( + setup_requires=['pbr'], + pbr=True) \ No newline at end of file diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 0000000..c05be4b --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1,14 @@ +# The order of packages is significant, because pip processes them in the order +# of appearance. Changing the order has an impact on the overall integration +# process, which may cause wedges in the gate later. + +hacking<0.11,>=0.10.0 + +coverage>=3.6 +python-subunit>=0.0.18 +sphinx!=1.2.0,!=1.3b1,<1.3,>=1.1.2 +oslosphinx>=2.5.0 # Apache-2.0 +oslotest>=1.10.0 # Apache-2.0 +testrepository>=0.0.18 +testscenarios>=0.4 +testtools>=1.4.0 \ No newline at end of file diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..9fd5faa --- /dev/null +++ b/tox.ini @@ -0,0 +1,60 @@ +[tox] +minversion = 1.8 +envlist = py34-constraints,py27-constraints,pypy-constraints,pep8-constraints +skipsdist = True + +[testenv] +usedevelop = True +install_command = + constraints: {[testenv:common-constraints]install_command} + pip install -U {opts} {packages} +setenv = + VIRTUAL_ENV={envdir} +deps = -r{toxinidir}/test-requirements.txt +commands = python setup.py test --slowest --testr-args='{posargs}' + +[testenv:common-constraints] +install_command = pip install -c{env:UPPER_CONSTRAINTS_FILE:https://git.openstack.org/cgit/openstack/requirements/plain/upper-constraints.txt} {opts} {packages} + +[testenv:pep8] +commands = flake8 {posargs} + +[testenv:pep8-constraints] +install_command = {[testenv:common-constraints]install_command} +commands = flake8 {posargs} + +[testenv:venv] +commands = {posargs} + +[testenv:venv-constraints] +install_command = {[testenv:common-constraints]install_command} +commands = {posargs} + +[testenv:cover] +commands = python setup.py test --coverage --testr-args='{posargs}' + +[testenv:cover-constraints] +install_command = {[testenv:common-constraints]install_command} +commands = python setup.py test --coverage --testr-args='{posargs}' + +[testenv:docs] +commands = python setup.py build_sphinx + +[testenv:docs-constraints] +install_command = {[testenv:common-constraints]install_command} +commands = python setup.py build_sphinx + +[testenv:debug] +commands = oslo_debug_helper {posargs} + +[testenv:debug-constraints] +install_command = {[testenv:common-constraints]install_command} +commands = oslo_debug_helper {posargs} + +[flake8] +# E123, E125 skipped as they are invalid PEP-8. + +show-source = True +ignore = E123,E125 +builtins = _ +exclude=.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build \ No newline at end of file