- @staticmethod
- def tap_dump(node, name=None):
- """Get all TAP interface data from the given node, or data about
- a specific TAP interface.
-
- TODO: Move to Tap.py
-
- :param node: VPP node to get data from.
- :param name: Optional name of a specific TAP interface.
- :type node: dict
- :type name: str
- :returns: Dictionary of information about a specific TAP interface, or
- a List of dictionaries containing all TAP data for the given node.
- :rtype: dict or list
- """
- cmd = 'sw_interface_tap_v2_dump'
- err_msg = 'Failed to get TAP dump on host {host}'.format(
- host=node['host'])
- with PapiExecutor(node) as papi_exec:
- details = papi_exec.add(cmd).get_details(err_msg)
-
- def process_tap_dump(tap_dump):
- """Process tap dump.
-
- :param tap_dump: Tap interface dump.
- :type tap_dump: dict
- :returns: Processed tap interface dump.
- :rtype: dict
- """
- tap_dump['dev_name'] = tap_dump['dev_name'].rstrip('\x00')
- tap_dump['host_if_name'] = tap_dump['host_if_name'].rstrip('\x00')
- tap_dump['host_namespace'] = \
- tap_dump['host_namespace'].rstrip('\x00')
- tap_dump['host_mac_addr'] = \
- L2Util.bin_to_mac(tap_dump['host_mac_addr'])
- tap_dump['host_ip4_addr'] = \
- inet_ntop(AF_INET, tap_dump['host_ip4_addr'])
- tap_dump['host_ip6_addr'] = \
- inet_ntop(AF_INET6, tap_dump['host_ip6_addr'])
- return tap_dump
-
- data = list() if name is None else dict()
- for tap_dump in details:
- if name is None:
- data.append(process_tap_dump(tap_dump))
- elif tap_dump.get('dev_name').rstrip('\x00') == name:
- data = process_tap_dump(tap_dump)
- break
-
- logger.debug('TAP data:\n{tap_data}'.format(tap_data=data))
- return data
-