Example #1
0
    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': 'ipv6_mc',
                'allow_list': True
            },
            {
                'name': 's_vec',
                'arg': s_vec,
                't': 'ipv6',
                'allow_list': True
            },
        ]
        EMUValidator.verify(ver_args)
        # convert
        g_vec1 = [Ipv6(ip, mc=True) for ip in g_vec]
        g_vec1 = [ipv6.V() for ipv6 in g_vec1]

        # convert
        s_vec1 = [Ipv6(ip) for ip in s_vec]
        s_vec1 = [ipv6.V() for ipv6 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))
Example #2
0
 def remove_mld(self, ns_key, ipv6_vec):
     """
     Remove mld from ipv6 plugin. 
     
         :parameters:
             ns_key: EMUNamespaceKey
                 see :class:`trex.emu.trex_emu_profile.EMUNamespaceKey`
             ipv6_vec: list of lists of bytes
                 List of ipv6 addresses. Must be a valid ipv6 mld address.
     """
     ver_args = [
         {
             'name': 'ns_key',
             'arg': ns_key,
             't': EMUNamespaceKey
         },
         {
             'name': 'ipv6_vec',
             'arg': ipv6_vec,
             't': 'ipv6_mc',
             'allow_list': True
         },
     ]
     EMUValidator.verify(ver_args)
     ipv6_vec = [Ipv6(ip, mc=True) for ip in ipv6_vec]
     ipv6_vec = [ipv6.V() for ipv6 in ipv6_vec]
     return self.emu_c._send_plugin_cmd_to_ns('ipv6_mld_ns_remove',
                                              ns_key,
                                              vec=ipv6_vec)
Example #3
0
    def add_mld(self, ns_key, ipv6_vec):
        """
        Add mld to ipv6 plugin. For MLDv2 this is g,* meaning accept all the sources 
        
            :parameters:
                ns_key: EMUNamespaceKey
                    see :class:`trex.emu.trex_emu_profile.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] ]

        """
        ver_args = [
            {
                'name': 'ns_key',
                'arg': ns_key,
                't': EMUNamespaceKey
            },
            {
                'name': 'ipv6_vec',
                'arg': ipv6_vec,
                't': 'ipv6_mc',
                'allow_list': True
            },
        ]
        EMUValidator.verify(ver_args)
        ipv6_vec = [Ipv6(ip, mc=True) for ip in ipv6_vec]
        ipv6_vec = [ipv6.V() for ipv6 in ipv6_vec]
        return self.emu_c._send_plugin_cmd_to_ns('ipv6_mld_ns_add',
                                                 ns_key,
                                                 vec=ipv6_vec)
Example #4
0
    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)
Example #5
0
    def ipv6_show_mld_line(self, line):
        '''IPV6 show mld command\n'''
        parser = parsing_opts.gen_parser(self, "ipv6_show_mld",
                                         self.ipv6_show_mld_line.__doc__,
                                         parsing_opts.EMU_NS_GROUP_NOT_REQ,
                                         parsing_opts.EMU_ALL_NS)

        opts = parser.parse_args(line.split())
        keys_to_headers = [
            {
                'key': 'ipv6',
                'header': 'IPv6'
            },
            {
                'key': 'refc',
                'header': 'Ref.Count'
            },
            {
                'key': 'management',
                'header': 'From RPC'
            },
            {
                'key': 'mode',
                'header': 'Mode'
            },
            {
                'key': 'scnt',
                'header': 'Sources'
            },
            {
                'key': 'svu',
                'header': 'S'
            },
        ]

        args = {
            'title': 'Current mld:',
            'empty_msg': 'There are no mld in namespace',
            'keys_to_headers': keys_to_headers
        }
        if opts.all_ns:
            self.run_on_all_ns(self.iter_mld,
                               print_ns_info=True,
                               func_on_res=self.print_table_by_keys,
                               func_on_res_args=args)
        else:
            self._validate_port(opts)
            ns_key = EMUNamespaceKey(opts.port, opts.vlan, opts.tpid)
            res = self.iter_mld(ns_key)
            # convert
            for i in range(len(res)):
                d = res[i]
                if 'sv' in d:
                    res[i]['scnt'] = len(res)
                    s = ''
                    cnt = 0
                    for ip in res[i]['sv']:
                        s += "[" + Ipv6(ip).S() + "], "
                        cnt += 1
                        if cnt > 4:
                            s += " ..."
                    res[i]['svu'] = s
                else:
                    res[i]['scnt'] = 0
                    res[i]['svu'] = ''

            self.print_table_by_keys(data=res, **args)

        return True
Example #6
0
def is_valid_ipv6_mc(addr):
    return Ipv6.is_valid(addr, mc = True)
Example #7
0
def is_valid_ipv6(addr):
    return Ipv6.is_valid(addr, mc = False)