def test_p2p_subif_creation_1k(self): """create 1k of p2p subifs""" self.logger.info("FFP_TEST_START_0001") macs = [] clients = 1000 mac = int("dead00000000", 16) for i in range(1, clients + 1): try: macs.append(':'.join(re.findall('..', '{:02x}'.format(mac + i)))) self.vapi.create_p2pethernet_subif(self.pg2.sw_if_index, mactobinary(macs[i - 1]), i) except Exception: self.logger.info("Failed to create subif %d %s" % (i, macs[i - 1])) raise intfs = self.vapi.cli("show interface").split("\n") count = 0 for intf in intfs: if intf.startswith('pg2.'): count += 1 self.assertEqual(count, clients) self.logger.info("FFP_TEST_FINISH_0001")
def remove_vpp_config(self): cip = socket.inet_pton(socket.AF_INET, self.client_ip) cmac = mactobinary(self.client_mac) self.unconfig() self.test.vapi.pppoe_add_del_session(cip, cmac, session_id=self.session_id, decap_vrf_id=self.decap_vrf_id, is_add=0)
def configure_ipv4_neighbors(self): """For every remote host assign neighbor's MAC to IPv4 addresses. :param vrf_id: The FIB table / VRF ID. (Default value = 0) """ for host in self._remote_hosts: macn = mactobinary(host.mac) ipn = host.ip4n self.test.vapi.ip_neighbor_add_del(self.sw_if_index, macn, ipn)
def add_vpp_config(self): cip = socket.inet_pton(socket.AF_INET, self.client_ip) cmac = mactobinary(self.client_mac) r = self.test.vapi.pppoe_add_del_session( cip, cmac, session_id=self.session_id, decap_vrf_id=self.decap_vrf_id) self.set_sw_if_index(r.sw_if_index) self.generate_remote_hosts()
def __init__(self, test, sw_if_index, mac_addr, nbr_addr, af=AF_INET, is_static=False, is_no_fib_entry=0): self._test = test self.sw_if_index = sw_if_index self.mac_addr = mactobinary(mac_addr) self.af = af self.is_static = is_static self.is_no_fib_entry = is_no_fib_entry self.nbr_addr = nbr_addr self.nbr_addr_n = inet_pton(af, nbr_addr)
def find_nbr(test, sw_if_index, ip_addr, is_static=0, inet=AF_INET, mac=None): nbrs = test.vapi.ip_neighbor_dump(sw_if_index, is_ipv6=1 if AF_INET6 == inet else 0) if inet == AF_INET: s = 4 else: s = 16 nbr_addr = inet_pton(inet, ip_addr) for n in nbrs: if nbr_addr == n.ip_address[:s] \ and is_static == n.is_static: if mac: if n.mac_address == mactobinary(mac): return True else: return True return False
def test_mac_to_binary(self): mac = 'aa:bb:cc:dd:ee:ff' b = mactobinary(mac) mac2 = binarytomac(b) self.assertEqual(type(mac), type(mac2)) self.assertEqual(mac2, mac)
def test_bond_traffic(self): """ Bond traffic test """ # topology # # RX-> TX-> # # pg2 ------+ +------pg0 (slave) # | | # BondEthernet0 (10.10.10.1) # | | # pg3 ------+ +------pg1 (slave) # # create interface (BondEthernet0) # self.logger.info("create bond") bond0_mac = "02:fe:38:30:59:3c" mac = mactobinary(bond0_mac) bond0 = VppBondInterface(self, mode=3, lb=1, use_custom_mac=1, mac_address=mac) bond0.add_vpp_config() bond0.admin_up() bond0_addr = socket.inet_pton(socket.AF_INET, "10.10.10.1") self.vapi.sw_interface_add_del_address(bond0.sw_if_index, bond0_addr, 24) self.pg2.config_ip4() self.pg2.resolve_arp() self.pg3.config_ip4() self.pg3.resolve_arp() self.logger.info(self.vapi.cli("show interface")) self.logger.info(self.vapi.cli("show interface address")) self.logger.info(self.vapi.cli("show ip arp")) # enslave pg0 and pg1 to BondEthernet0 self.logger.info("bond enslave interface pg0 to BondEthernet0") bond0.enslave_vpp_bond_interface(sw_if_index=self.pg0.sw_if_index, is_passive=0, is_long_timeout=0) self.logger.info("bond enslave interface pg1 to BondEthernet0") bond0.enslave_vpp_bond_interface(sw_if_index=self.pg1.sw_if_index, is_passive=0, is_long_timeout=0) # verify both slaves in BondEthernet0 if_dump = self.vapi.sw_interface_slave_dump(bond0.sw_if_index) self.assertTrue(self.pg0.is_interface_config_in_dump(if_dump)) self.assertTrue(self.pg1.is_interface_config_in_dump(if_dump)) # generate a packet from pg2 -> BondEthernet0 -> pg1 # BondEthernet0 TX hashes this packet to pg1 p2 = (Ether(src=bond0_mac, dst=self.pg2.local_mac) / IP(src=self.pg2.local_ip4, dst="10.10.10.12") / UDP(sport=1235, dport=1235) / Raw('\xa5' * 100)) self.pg2.add_stream(p2) # generate a packet from pg3 -> BondEthernet0 -> pg0 # BondEthernet0 TX hashes this packet to pg0 # notice the ip address and ports are different than p2 packet p3 = (Ether(src=bond0_mac, dst=self.pg3.local_mac) / IP(src=self.pg3.local_ip4, dst="10.10.10.11") / UDP(sport=1234, dport=1234) / Raw('\xa5' * 100)) self.pg3.add_stream(p3) self.pg_enable_capture(self.pg_interfaces) # set up the static arp entries pointing to the BondEthernet0 interface # so that it does not try to resolve the ip address self.logger.info( self.vapi.cli( "set ip arp static BondEthernet0 10.10.10.12 abcd.abcd.0002")) self.logger.info( self.vapi.cli( "set ip arp static BondEthernet0 10.10.10.11 abcd.abcd.0004")) # clear the interface counters self.logger.info(self.vapi.cli("clear interfaces")) self.pg_start() self.logger.info("check the interface counters") # verify counters # BondEthernet0 tx bytes = 284 intfs = self.vapi.cli("show interface BondEthernet0").split("\n") found = 0 for intf in intfs: if "tx bytes" in intf and "284" in intf: found = 1 self.assertEqual(found, 1) # BondEthernet0 tx bytes = 284 intfs = self.vapi.cli("show interface BondEthernet0").split("\n") found = 0 for intf in intfs: if "tx bytes" in intf and "284" in intf: found = 1 self.assertEqual(found, 1) # pg2 rx bytes = 142 intfs = self.vapi.cli("show interface pg2").split("\n") found = 0 for intf in intfs: if "rx bytes" in intf and "142" in intf: found = 1 self.assertEqual(found, 1) # pg3 rx bytes = 142 intfs = self.vapi.cli("show interface pg3").split("\n") found = 0 for intf in intfs: if "rx bytes" in intf and "142" in intf: found = 1 self.assertEqual(found, 1) bond0.remove_vpp_config()
def create_p2p_ethernet(self, parent_if, sub_id, remote_mac): p2p = VppP2PSubint(self, parent_if, sub_id, mactobinary(remote_mac)) p2p.admin_up() p2p.config_ip4() return p2p
def delete_p2p_ethernet(self, parent_if, remote_mac): self.vapi.delete_p2pethernet_subif(parent_if.sw_if_index, mactobinary(remote_mac))
def create_p2p_ethernet(self, parent_if, sub_id, remote_mac): p2p = VppP2PSubint(self, parent_if, sub_id, mactobinary(remote_mac)) self.p2p_sub_ifs.append(p2p)
def set_mac(self, mac): self._local_mac = mac self._local_ip6_ll = mk_ll_addr(mac) self.test.vapi.sw_interface_set_mac_address( self.sw_if_index, mactobinary(self._local_mac))
def bin_mac(self): """ MAC address """ return mactobinary(self._mac)