diff options
Diffstat (limited to 'resources/libraries/python')
-rw-r--r-- | resources/libraries/python/InterfaceUtil.py | 40 | ||||
-rw-r--r-- | resources/libraries/python/Trace.py | 24 | ||||
-rw-r--r-- | resources/libraries/python/topology.py | 24 |
3 files changed, 83 insertions, 5 deletions
diff --git a/resources/libraries/python/InterfaceUtil.py b/resources/libraries/python/InterfaceUtil.py index 14473ee4d4..aeb54be86a 100644 --- a/resources/libraries/python/InterfaceUtil.py +++ b/resources/libraries/python/InterfaceUtil.py @@ -53,7 +53,45 @@ class InterfaceUtil(object): cmd = 'ip link set {} {}'.format(interface, state) exec_cmd_no_error(node, cmd, sudo=True) else: - raise Exception('Unknown NodeType: "{}"'.format(node['type'])) + raise Exception('Node {} has unknown NodeType: "{}"'. + format(node['host'], node['type'])) + + @staticmethod + def set_interface_ethernet_mtu(node, interface, mtu): + """Set Ethernet MTU for specified interface. + + Function can be used only for TGs. + + :param node: node where the interface is + :param interface: interface name + :param mtu: MTU to set + :type node: dict + :type interface: str + :type mtu: int + :return: nothing + """ + if node['type'] == NodeType.DUT: + ValueError('Node {}: Setting Ethernet MTU for interface ' + 'on DUT nodes not supported', node['host']) + elif node['type'] == NodeType.TG: + cmd = 'ip link set {} mtu {}'.format(interface, mtu) + exec_cmd_no_error(node, cmd, sudo=True) + else: + raise ValueError('Node {} has unknown NodeType: "{}"'. + format(node['host'], node['type'])) + + @staticmethod + def set_default_ethernet_mtu_on_all_interfaces_on_node(node): + """Set default Ethernet MTU on all interfaces on node. + + Function can be used only for TGs. + + :param node: node where to set default MTU + :type node: dict + :return: nothing + """ + for ifc in node['interfaces'].values(): + InterfaceUtil.set_interface_ethernet_mtu(node, ifc['name'], 1500) @staticmethod def vpp_node_interfaces_ready_wait(node, timeout=10): diff --git a/resources/libraries/python/Trace.py b/resources/libraries/python/Trace.py new file mode 100644 index 0000000000..8168b909ea --- /dev/null +++ b/resources/libraries/python/Trace.py @@ -0,0 +1,24 @@ +# Copyright (c) 2016 Cisco and/or its affiliates. +# 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 resources.libraries.python.VatExecutor import VatExecutor +from resources.libraries.python.topology import NodeType + +class Trace(object): + + @staticmethod + def show_packet_trace_on_all_duts(nodes): + for node in nodes.values(): + if node['type'] == NodeType.DUT: + vat = VatExecutor() + vat.execute_script("show_trace.vat", node, json_out=False) diff --git a/resources/libraries/python/topology.py b/resources/libraries/python/topology.py index e2c069fc98..75542ad070 100644 --- a/resources/libraries/python/topology.py +++ b/resources/libraries/python/topology.py @@ -257,6 +257,7 @@ class Topology(object): format(ifc, if_mac)) ifc['name'] = interface_dict["interface_name"] ifc['vpp_sw_index'] = interface_dict["sw_if_index"] + ifc['mtu'] = interface_dict["mtu"] def update_vpp_interface_data_on_node(self, node): """Update vpp generated interface data for a given node in DICT__nodes @@ -347,14 +348,31 @@ class Topology(object): """ for port in node['interfaces'].values(): port_name = port.get('name') - if port_name is None: - continue if port_name == interface: return port.get('vpp_sw_index') return None @staticmethod + def get_interface_mtu(node, interface): + """Get interface MTU. + + Returns physical layer MTU (max. size of Ethernet frame). + :param node: Node to get interface MTU on. + :param interface: Interface name. + :type node: dict + :type interface: str + :return: MTU or None if not found. + :rtype: int + """ + for port in node['interfaces'].values(): + port_name = port.get('name') + if port_name == interface: + return port.get('mtu') + + return None + + @staticmethod def get_interface_mac_by_port_key(node, port_key): """Get MAC address for the interface based on port key. @@ -382,8 +400,6 @@ class Topology(object): """ for port in node['interfaces'].values(): port_name = port.get('name') - if port_name is None: - continue if port_name == interface: return port.get('mac_address') |