IGMP¶
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(),
plugs = {'igmp': {}})
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 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)
mcs = [[224,0,0,0], [224,1,0,0], [224,2,0,0], [224,3,0,0]]
# add multicast addresses
print("Adding multicasts: %s" % mcs)
c.igmp.add_mc(ns_key, mcs)
# show multicast addresses * Notice data from API always return as list of bytes *
res = c.igmp.iter_mc(ns_key)
print("Current multicasts:")
for i, mc in enumerate(res, start = 1):
print('Multicast #{0}: {1}'.format(i, mc))
# remove some multicast addresses
print('Removing mcs: {0}'.format(mcs[1:3]))
c.igmp.remove_mc(ns_key, mcs[1:3])
# show multicast addresses after removeal
print('After removal, current mcs:')
res = c.igmp.iter_mc(ns_key)
for i, mc in enumerate(res, start = 1):
print('Multicast #{0}: {1}'.format(i, mc))
# igmp counters
print('IGMP counters:')
res = c.igmp.get_counters(ns_key, zero = True, verbose = False)
pprint.pprint(res)
- class trex.emu.emu_plugins.emu_plugin_igmp.IGMPPlugin(emu_client)[source]¶
Defines igmp plugin
- Supports IPv4 IGMP v3/v2 RFC3376
v3 supports the folowing filters
Exclude {}, meaning include all sources (*)
Include a vector of sources. The API is add/remove [(g,s1),(g,s2)..] meaning include to mc-group g a source s1 and s2 the mode would be INCLUDE {s1,s2}
To change mode (include all [1] to include filter sources [2]) there is a need to remove and add the group again
The implementation is in the namespace domain (shared for all the clients on the same network) One client ipv4/mac is the designator to answer the queries for all the clients.
Scale
unlimited number of groups
~1k sources per group (in case of INCLUDE)
Don’t forget to set the designator client
The API does not support a rate policing so if you push a big vector it will be pushed in the fastest way to the DUT
Init IGMPPlugin.
- parameters
- emu_client: EMUClient
Valid emu client.
- INIT_JSON_NS = {'igmp': {'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. (Required)
- dmac: [6]byte
Designator mac. IMPORTANT !! can be set by the API set_cfg too
- vec: list of [4]byte
IPv4 vector representing multicast addresses.
- version: uint16
The init version of IGMP 2 or 3 (default). After the first query it learns the version from the Query.
- INIT_JSON_CLIENT = {'igmp': {}}¶
- Parameters
Empty.
- get_counters(ns_key, cnt_filter=None, zero=True, verbose=True)[source]¶
Get the IGMP 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 IGMP 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 igmp configurations.
- parameters
- ns_key: EMUNamespaceKey
- returns
- dict :{“dmac”: [0, 0, 0, 0, 0, 0],“version”: 3,“mtu”: 1500}
- set_cfg(ns_key, mtu, dmac)[source]¶
Set arp configurations in namespace.
- parameters
- ns_key: EMUNamespaceKey
- mtu: bool
True for enabling arp.
- dmac: list of bytes
Designator mac.
- returns
bool : True on success.
- remove_mc_sg(ns_key, g_vec, s_vec)[source]¶
Remove multicast 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 = [[239,1,1,1],[239,1,1,2]] s_vec = [[10,0,0,1],[10,0,0,2]] this will remove (g=[239,1,1,1],s=[10,0,0,1]) (g=[239,1,1,2],s=[10,0,0,2]) example 2 g_vec = [[239,1,1,1],[239,1,1,1]] s_vec = [[10,0,0,1],[10,0,0,2]] this will remove (g=[239,1,1,1],s=[10,0,0,1]) (g=[239,1,1,1],s=[10,0,0,2])
- returns
bool : True on success.
- add_mc_sg(ns_key, g_vec, s_vec)[source]¶
Add multicast(s,g) 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 = [[239,1,1,1],[239,1,1,2]] s_vec = [[10,0,0,1],[10,0,0,2]] this will add (g=[239,1,1,1],s=[10,0,0,1]) (g=[239,1,1,2],s=[10,0,0,2]) example 2 g_vec = [[239,1,1,1],[239,1,1,1]] s_vec = [[10,0,0,1],[10,0,0,2]] this will add (g=[239,1,1,1],s=[10,0,0,1]) (g=[239,1,1,1],s=[10,0,0,2]) 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_mc(ns_key, ipv4_vec)[source]¶
Add multicast addresses in namespace.
- parameters
- ns_key: EMUNamespaceKey
- ipv4_vec: list of lists of bytes
IPv4 addresses. for IGMPv3 this is g,* meaning accept all the sources
- returns
bool : True on success.
- add_gen_mc(ns_key, ipv4_start, ipv4_count=1)[source]¶
Add multicast addresses in namespace, generating sequence of addresses.
- parameters
- ns_key: EMUNamespaceKey
- ipv4_start: lists of bytes
IPv4 address of the first multicast address.
- ipv4_count: int
- Amount of ips to continue from ipv4_start, defaults to 0.i.e: ipv4_start = [1, 0, 0, 0] , ipv4_count = 2 -> [[1, 0, 0, 0], [1, 0, 0, 1]]
- returns
bool : True on success.
- add_gen_mc_sg(ns_key, g_start, g_count=1, s_start=None, s_count=1)[source]¶
Add multicast addresses in namespace, generating sequence of addresses.
- parameters
- ns_key: EMUNamespaceKey
- g_start: lists of bytes
IPv4 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
IPv4 address of the first source group
- s_count: int
Amount of ips for sources in each group
for example 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 in namespace, generating sequence of addresses.
- parameters
- ns_key: EMUNamespaceKey
- g_start: lists of bytes
IPv4 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
IPv4 address of the first source group
- s_count: int
Amount of ips for sources in each group
for example 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_mc(ns_key, ipv4_vec)[source]¶
Remove multicast addresses in namespace.
- parameters
- ns_key: EMUNamespaceKey
- ipv4_vec: list of lists of bytes
IPv4 multicast addresses.
- returns
bool : True on success.
- remove_gen_mc(ns_key, ipv4_start, ipv4_count=1)[source]¶
- Remove multicast addresses in namespace, generating sequence of addresses.
- parameters
- ns_key: EMUNamespaceKey
- ipv4_start: list of bytes
IPv4 address of the first multicast address.
- ipv4_count: int
- Amount of ips to continue from ipv4_start, defaults to 0.i.e: ipv4_start = [1, 0, 0, 0] , ipv4_count = 2 -> [[1, 0, 0, 0], [1, 0, 0, 1]]
- returns
bool : True on success.
- iter_mc(ns_key, ipv4_amount=None)[source]¶
Iterate multicast addresses in namespace.
- parameters
- ns_key: EMUNamespaceKey
- ipv4_count: int
Amount of ips to get from emu server, defaults to None means all.
- returns
list : List of ips as list of bytes. i.e: [[224, 0, 0, 1], [224, 0, 0, 1]]
- remove_all_mc(ns_key)[source]¶
Remove all multicast addresses in namespace.
- parameters
- ns_key: EMUNamespaceKey
- return
bool : True on success.
- tear_down_ns(ns_key)[source]¶
- This function will be called before removing this plugin from namespace
- parameters
ns_key: EMUNamespaceKey see
trex.emu.trex_emu_profile.EMUNamespaceKey
- trex.emu.emu_plugins.emu_plugin_igmp.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.