ARP¶
Example:
#!/usr/bin/python
import emu_path
from trex.emu.api import *
import pprint
c = EMUClient(server='localhost',
sync_port=4510,
verbose_level= "error",
logger=None,
sync_timeout=None)
port = 0
mac = Mac('00:00:00:70:00:01')
ipv4 = Ipv4('1.1.1.3')
ipv4_dg = Ipv4('1.1.1.1')
emu_client = EMUClientObj(mac = mac.V(),
ipv4 = ipv4.V(),
ipv4_dg = ipv4_dg.V(),
plugs = {'arp': {'enable': True}})
ns_key = EMUNamespaceKey(vport = port)
c_key = EMUClientKey(ns_key, mac.V())
emu_ns = EMUNamespaceObj(ns_key = ns_key,
clients = emu_client)
profile = EMUProfile(ns = emu_ns, def_ns_plugs = {'ipv6':{}})
# MAKE sure the TRex server is in --software mode promiscuous and to get multicast enabled
# trex_c.connect()
# trex_c.acquire(ports = my_ports)
# trex_c.set_port_attr(promiscuous=True) << get all the packets
# # move the mode to service mode in case DHCP is enabled
# trex_c.set_service_mode(ports = my_ports, enabled = False, filtered = True, mask = (NO_TCP_UDP_MASK | DHCP_MASK ))
#
# connect and load profile
c.connect()
c.load_profile(profile = profile)
# print tables of namespaces and clients
print("Show all emu ns and clients:")
c.print_all_ns_clients(max_ns_show = 1, max_c_show = 10)
# send gratuitous arp
print("Let's enable gratuitous arp")
c.arp.cmd_query(c_key, garp = True)
# show arp cache
res = c.arp.show_cache(ns_key)
print("Arp cache:")
for r in res:
pprint.pprint(r)
# arp counters
print('Arp counters:')
res = c.arp.get_counters(ns_key, zero = True, verbose = False)
pprint.pprint(res)
- class trex.emu.emu_plugins.emu_plugin_arp.ARPPlugin(emu_client)[source]¶
Defines arp plugin RFC 826
Init ArpPlugin.
- parameters
- emu_client: EMUClient
Valid emu client.
- INIT_JSON_NS = {'arp': {}}¶
- Parameters
Empty.
- INIT_JSON_CLIENT = {'arp': {'timer': 60, 'timer_disable': False}}¶
- Parameters
- timer: uint32
Arp timer.
- timer_disable: bool
Is timer disable.
- get_counters(ns_key, cnt_filter=None, zero=True, verbose=True)[source]¶
Get the ARP counters of a namespace.
- Parameters
- ns_key:
trex.emu.trex_emu_profile.EMUNamespaceKey EMUNamespaceKey
- cnt_filter: list
List of counters types as strings. i.e: [‘INFO’, ‘ERROR’, ‘WARNING’]. Default is None, means no filter. If verbosity is off, this filter can’t be used.
- zero: bool
Get zero values, default is True.
- verbose: bool
Show verbose version of each counter, default is True.
- ns_key:
- Returns
Dictionary of all wanted counters. When verbose is True, each plugin contains a list of counter dictionaries.
{'pluginName': [{'help': 'Explanation 1', 'info': 'INFO', 'name': 'counterOne', 'unit': 'pkts', 'value': 8, 'zero': False}, {'help': 'Explanation 2', 'info': 'ERROR', 'name': 'counterTwo', 'unit': 'pkts', 'value': 6, 'zero': False}]}
When verbose is False, each plugins returns a dictionary of counterName, value pairs.
{'pluginName': {'counterOne': 8, 'counterTwo': 6}}
- Raises
TRexError
- clear_counters(ns_key)[source]¶
Clear the ARP counters of a namespace.
- Parameters
- ns_key:
trex.emu.trex_emu_profile.EMUNamespaceKey EMUNamespaceKey
- ns_key:
- Returns
- Boolean indicating if clearing was successful.
True: Clearing was successful.
False: Clearing was not successful.
- Raises
TRexError
- get_cfg(ns_key)[source]¶
Get arp configurations.
- parameters
- ns_key: EMUNamespaceKey
- returns
- dict :{“enable”: true}
- set_cfg(ns_key, enable)[source]¶
Set arp configurations.
- parameters
- ns_key: EMUNamespaceKey
- enable: bool
True for enabling arp.
- returns
bool : True on success.
- cmd_query(c_key, garp)[source]¶
Query command for arp.
- parameters
- c_key: EMUClientKey
- garp: bool
True for gratuitous arp.
- returns
bool : True on success.
- show_cache(ns_key)[source]¶
get arp cache (per namespace) shared by all clients
- parameters
- ns_key: EMUNamespaceKey
- returns
- list : List of cache records looks like:[{‘mac’: [68, 3, 0, 23, 0, 1], ‘refc’: 0, ‘resolve’: True, ‘ipv4’: [10, 111, 168, 31], ‘state’: ‘Learned’},{‘mac’: [68, 3, 0, 23, 0, 2], ‘refc’: 0, ‘resolve’: True, ‘ipv4’: [10, 111, 168, 32], ‘state’: ‘Learned’}]Notice - addresses are in bytes arrays.
- tear_down_ns(ns_key)¶
This function will be called before removing this plugin from namespace.
- parameters
- ns_key: EMUNamespaceKey
- trex.emu.emu_plugins.emu_plugin_arp.wraps(func)¶
Replaces functools.wraps in order to undo wrapping.
Can be used to preserve the decorated function’s signature in the documentation generated by Sphinx.