IPv6¶
Example:
#!/usr/bin/python
import emu_path
from trex.emu.api import *
from trex.emu.trex_emu_conversions import Mac, Ipv4
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_dg = Ipv4('1.1.1.3'), Ipv4('1.1.1.1')
emu_client = EMUClientObj(mac = mac.V(),
ipv4 = ipv4.V(),
ipv4_dg = ipv4_dg.V())
ns_key = EMUNamespaceKey(vport = port)
emu_ns = EMUNamespaceObj(ns_key = ns_key,
clients = emu_client)
profile = EMUProfile(ns = emu_ns, def_ns_plugs = {'ipv6':{}})
# connect
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)
# add mld
mlds = [
[0xFF,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0],
[0xFF,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,1],
[0xFF,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,2],
[0xFF,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,3],
[0xFF,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,4],
]
print("Adding mlds...")
c.ipv6.add_mld(ns_key, ipv6_vec = mlds)
# show mld * Notice data from API always return as list of bytes *
res = c.ipv6.iter_mld(ns_key)
print("Mld before remove:" )
pprint.pprint(res)
# remove mld
print('Removing %s' % mlds[1:3])
c.ipv6.remove_mld(ns_key, ipv6_vec = mlds[1:3])
# show updated mld
res = c.ipv6.iter_mld(ns_key)
print("Mld after remove:")
pprint.pprint(res)
# ipv6 counters
print('IPv6 counters:')
res = c.ipv6.get_counters(ns_key, zero = True, verbose = False)
pprint.pprint(res)
- class trex.emu.emu_plugins.emu_plugin_ipv6.IPV6Plugin(emu_client)[source]¶
Defines ipv6 plugin
RFC 4443: Internet Control Message Protocol (ICMPv6) for the Internet Protocol Version 6 (IPv6) RFC 4861: Neighbor Discovery for IP Version 6 (IPv6) RFC 4862: IPv6 Stateless Address Autoconfiguration.
not implemented:
RFC4941: random local ipv6 using md5
- INIT_JSON_NS = {'ipv6': {'dmac': [1, 2, 3, 4, 5, 6], 'mtu': 1500, 'vec': [[244, 0, 0, 0], [244, 0, 0, 1]], 'version': 1}}¶
- Parameters
- mtu: uint16
Maximun transmission unit.
- dmac: [6]byte
Designator mac. IMPORTANT !!
- vec: list of [16]byte
IPv4 vector representing multicast addresses.
- version: uint16
The init version, 1 or 2 (default). It learns the version from the first Query.
- INIT_JSON_CLIENT = {'ipv6': {'nd_timer': 29, 'nd_timer_disable': False}}¶
- Parameters
- nd_timer: uint32
IPv6-nd timer.
- nd_timer_disable: bool
Enable/Disable IPv6-nd timer.
- get_counters(ns_key, cnt_filter=None, zero=True, verbose=True)[source]¶
Get the IPV6 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 IPV6 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 IPv6 configuration from namespace.
- parameters
- ns_key: EMUNamespaceKey
- return
- dict: IPv6 configuration like:{‘dmac’: [0, 0, 0, 112, 0, 1], ‘version’: 2, ‘mtu’: 1500}
- set_cfg(ns_key, mtu, dmac)[source]¶
Set IPv6 configuration on namespcae.
- parameters
- ns_key: EMUNamespaceKey
- mtu: int
MTU for ipv6 plugin.
- dmac: list of bytes
Designator mac for ipv6 plugin.
- remove_mld_sg(ns_key, g_vec, s_vec)[source]¶
Remove (g,s) multicast addresses in namespace.
- parameters
- ns_key: EMUNamespaceKey
- g_vec: list of lists of bytes
Groups IPv6 addresses (multicast)
- s_vec: list of lists of bytes
Sources of IPv6 addresses. one source for each group the size of the vectors should be the same
example 1 g_vec = [ip1.V(),ip1.V()] s_vec = [ip2.V(),ip3.V()] this will remove (g=ip1.V(),s=ip2.V()) (g=ip1.V(),s=ip3.V())
- returns
bool : True on success.
- add_mld_sg(ns_key, g_vec, s_vec)[source]¶
Add multicast (g,s) addresses in namespace.
- parameters
- ns_key: EMUNamespaceKey
- g_vec: list of lists of bytes
Groups IPv4 addresses.
- s_vec: list of lists of bytes
Sources of IPv4 addresses. one source for each group
example 1 g_vec = [ip1.V(),ip1.V()] s_vec = [ip2.V(),ip3.V()] this will add (g=ip1.V(),s=ip2.V()) (g=ip1.V(),s=ip3.V()) the vectors should be in the same side and the there is no limit (it will be pushed in the fastest way to the server)
- returns
bool : True on success.
- add_mld(ns_key, ipv6_vec)[source]¶
Add mld to ipv6 plugin. For MLDv2 this is g,* meaning accept all the sources
- parameters
- ns_key: EMUNamespaceKey
- ipv6_vec: list of lists of bytes
List of ipv6 addresses. Must be a valid ipv6 mld address. .e.g.[[0xff,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,1] ]
- add_gen_mld(ns_key, ipv6_start, ipv6_count=1)[source]¶
Add mld to ipv6 plugin, generating sequence of addresses.
- parameters
- ns_key: EMUNamespaceKey
- ipv6_start: lists of bytes
ipv6 addresses to start from. Must be a valid ipv6 mld addresses.
- ipv6_count: int
- ipv6 addresses to addi.e -> ipv6_start = [0, .., 0] and ipv6_count = 2 ->[[0, .., 0], [0, .., 1]].
- remove_mld(ns_key, ipv6_vec)[source]¶
Remove mld from ipv6 plugin.
- parameters
- ns_key: EMUNamespaceKey
- ipv6_vec: list of lists of bytes
List of ipv6 addresses. Must be a valid ipv6 mld address.
- add_gen_mc_sg(ns_key, g_start, g_count=1, s_start=None, s_count=1)[source]¶
Add multicast addresses (g,s) in namespace, generating sequence of addresses.
- parameters
- ns_key: EMUNamespaceKey
- g_start: lists of bytes
IPv6 address of the first multicast address.
- g_count: int
- Amount of ips to continue from g_start, defaults to 0.
- s_start: lists of bytes
IPv6 address of the first source group
- s_count: int
Amount of ips for sources in each group
for example (using ipv4 address) g_start = [1, 0, 0, 0] ,g_count = 2, s_start=[2, 0, 0, 0], s_count=1 (g,s) ([1, 0, 0, 0], [2, 0, 0, 0]) ([1, 0, 0, 1], [2, 0, 0, 0])
- returns
bool : True on success.
- remove_gen_mc_sg(ns_key, g_start, g_count=1, s_start=None, s_count=1)[source]¶
remove multicast addresses (g,s) in namespace, generating sequence of addresses.
- parameters
- ns_key: EMUNamespaceKey
- g_start: lists of bytes
IPv6 address of the first multicast address.
- g_count: int
- Amount of ips to continue from g_start, defaults to 0.
- s_start: lists of bytes
IPv6 address of the first source group
- s_count: int
Amount of ips for sources in each group
for example (using ipv4 address) g_start = [1, 0, 0, 0] , g_count = 2,s_start=[2, 0, 0, 0],s_count=1 (g,s) ([1, 0, 0, 0], [2, 0, 0, 0]) ([1, 0, 0, 1], [2, 0, 0, 0])
- returns
bool : True on success.
- remove_gen_mld(ns_key, ipv6_start, ipv6_count=1)[source]¶
Remove mld from ipv6 plugin.
- parameters
- ns_key: EMUNamespaceKey
- ipv6_start: lists of bytes
ipv6 address to start from.
- ipv6_count: int
- ipv6 addresses to addi.e -> ipv6_start = [0, .., 0] and ipv6_count = 2 ->[[0, .., 0], [0, .., 1]].
- iter_mld(ns_key, ipv6_amount=None)[source]¶
Iterates over current mld’s in ipv6 plugin.
- parameters
- ns_key: EMUNamespaceKey
- ipv6_amount: int
Amount of ipv6 addresses to fetch, defaults to None means all.
- returns
- list: List of ipv6 addresses dict:{‘refc’: 100, ‘management’: False, ‘ipv6’: [255, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]}
- remove_all_mld(ns_key)[source]¶
- Remove all user created mld(s) from ipv6 plugin.
- parameters
- ns_key: EMUNamespaceKey
- show_cache(ns_key)[source]¶
Return ipv6 cache for a given namespace.
- parameters
- ns_key: EMUNamespaceKey
- returns
- list: list of ipv6 cache records[{‘ipv6’: list of 16 bytes,‘refc’: int,‘state’: string,‘resolve’: bool,‘mac’: list of 6 bytes}].
- start_ping(c_key, amount=None, pace=None, dst=None, src=None, timeout=None, payload_size=None)[source]¶
Start pinging, sending Echo Requests.
- Parameters
- c_key: EMUClientKey
- amount: int
Amount of Echo Requests to send.
- pace: float
Pace in which to send the packets in pps (packets per second).
- dst: list of bytes
Destination IPv6. For example: [0x20, 0x01, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8a, 0x2e, 0x03, 0x70, 0x73, 0x34]
- src: list of bytes
Source IPv6. User must own this IPv6 in order to be able to ping with it.
- timeout: int
Time to collect the results in seconds, starting when the last Echo Request is sent.
- payload_size: int
Size of the ICMP payload, in bytes.
- Returns
(RPC Response, TRexError), one of the entries is None.
- get_ping_stats(c_key, zero=True)[source]¶
Get the stats of an active ping.
- Parameters
- c_key: EMUClientKey
- zero: boolean
Get values that equal zero aswell.
- Returns
(RPC Response, TRexError), one of the entries is None.
- stop_ping(c_key)[source]¶
Stop an ongoing ping.
- Parameters
- c_key: EMUClientKey
- Returns
(RPC Response, TRexError), one of the entries is None.
- trex.emu.emu_plugins.emu_plugin_ipv6.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.