def _mc_sg_gen(self, ns_key, g_vec, s_vec, cmd): ver_args = [ { 'name': 'ns_key', 'arg': ns_key, 't': EMUNamespaceKey }, { 'name': 'g_vec', 'arg': g_vec, 't': 'ipv4_mc', 'allow_list': True }, { 'name': 's_vec', 'arg': s_vec, 't': 'ipv4', 'allow_list': True }, ] EMUValidator.verify(ver_args) # convert g_vec1 = [Ipv4(ip, mc=True) for ip in g_vec] g_vec1 = [ipv4.V() for ipv4 in g_vec1] # convert s_vec1 = [Ipv4(ip) for ip in s_vec] s_vec1 = [ipv4.V() for ipv4 in s_vec1] if len(s_vec1) != len(g_vec1): raise TRexError( 'Validation error, len of g and s vector should be the same ') return self.emu_c._send_plugin_cmd_to_ns(cmd, ns_key, vec=conv(g_vec1, s_vec1))
def remove_mc(self, ns_key, ipv4_vec): """ Remove multicast addresses in namespace. :parameters: ns_key: EMUNamespaceKey see :class:`trex.emu.trex_emu_profile.EMUNamespaceKey` ipv4_vec: list of lists of bytes IPv4 multicast addresses. :returns: bool : True on success. """ ver_args = [ { 'name': 'ns_key', 'arg': ns_key, 't': EMUNamespaceKey }, { 'name': 'ipv4_vec', 'arg': ipv4_vec, 't': 'ipv4_mc', 'allow_list': True }, ] EMUValidator.verify(ver_args) ipv4_vec = [Ipv4(ip, mc=True) for ip in ipv4_vec] ipv4_vec = [ipv4.V() for ipv4 in ipv4_vec] return self.emu_c._send_plugin_cmd_to_ns('igmp_ns_remove', ns_key, vec=ipv4_vec)
def create_profile(self, ns_size, clients_size, plug, mac, ipv4, dg, ipv6): empty_ipv4 = '0.0.0.0' mac_obj = Mac(mac) mac_as_bytes = mac_obj.V() PLUGS_MAP = { 'ipv4': { 'def_c': { 'arp': { 'enable': True }, 'icmp': {} }, }, 'igmp': { 'def_c': { 'arp': { 'enable': True }, 'icmp': {}, 'igmp': { 'dmac': mac_as_bytes } } }, 'ipv6': { 'def_c': { 'ipv6': {} }, 'def_ns': { 'ipv6': { 'dmac': mac_as_bytes } }, 'ipv4': empty_ipv4, 'dg': empty_ipv4 }, 'dhcpv4': { 'def_c': { 'arp': { 'enable': True }, 'icmp': {}, 'dhcp': {} }, 'ipv4': empty_ipv4 }, 'dhcpv6': { 'def_c': { 'ipv6': {}, 'dhcpv6': {} }, 'def_ns': { 'ipv6': { 'dmac': mac_as_bytes } }, 'ipv4': empty_ipv4, 'dg': empty_ipv4 }, 'dot1x': { 'def_c': { 'dot1x': {} }, 'def_ns': {}, }, 'all': { 'def_c': { 'arp': { 'enable': True }, 'icmp': {}, 'igmp': { 'dmac': mac_as_bytes }, 'ipv6': {}, 'dhcpv6': {}, 'dot1x': {} }, 'def_ns': { 'ipv6': { 'dmac': mac_as_bytes } }, 'ipv4': empty_ipv4, 'dg': empty_ipv4 } } if plug is not None: plug_info = PLUGS_MAP[plug] self.def_ns_plugs = plug_info.get('def_ns') self.def_c_plugs = plug_info.get('def_c') ipv4, dg = plug_info.get('ipv4', ipv4), plug_info.get('dg', dg) ns_list = [] # create different namespace each time vport, tci, tpid = 0, [0, 0], [0, 0] for i in range(vport, ns_size + vport): ns_key = EMUNamespaceKey(vport=i, tci=tci, tpid=tpid) ns = EMUNamespaceObj(ns_key=ns_key, def_c_plugs=self.def_c_plugs) mac = Mac(mac) ipv4 = Ipv4(ipv4) dg = Ipv4(dg) ipv6 = Ipv6(ipv6) # create a different client each time for j in range(clients_size): client = EMUClientObj( mac=mac[j].V(), ipv4=ipv4[j].V(), ipv4_dg=dg.V(), ipv6=ipv6[j].V(), ) ns.add_clients(client) ns_list.append(ns) return EMUProfile(ns=ns_list, def_ns_plugs=self.def_ns_plugs)
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) c.connect() mac_1, mac_2 = Mac('00:00:00:70:00:01'), Mac('00:00:00:70:00:02') ipv4_1, ipv4_2 = Ipv4('1.1.1.3'), Ipv4('1.1.1.4') ipv4_dg = Ipv4('1.1.1.1') emu_client1 = EMUClientObj(mac=mac_1.V(), ipv4=ipv4_1.V(), ipv4_dg=ipv4_dg.V()) # plugins only for c2, will override default c2_plugs = {'arp': {'timer': 30}, 'igmp': {}} emu_client2 = EMUClientObj(mac=mac_2.V(), ipv4=ipv4_2.V(), ipv4_dg=ipv4_dg.V(), plugs=c2_plugs) # Default plugin for all clients in the ns def_c_plugs = { 'arp': {
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
def is_valid_ipv4_mc(addr): return Ipv4.is_valid(addr, mc = True)
def is_valid_ipv4(addr): return Ipv4.is_valid(addr, mc = False)