def __init__(self, test, src, dst, vni, mcast_itf=None): """ Create VXLAN-GBP Tunnel interface """ super(VppVxlanGbpTunnel, self).__init__(test) self.src = VppIpAddress(src) self.dst = VppIpAddress(dst) self.vni = vni self.mcast_itf = mcast_itf
def __init__(self, test, interface, peer_addr, local_addr=None, af=AF_INET, desired_min_tx=300000, required_min_rx=300000, detect_mult=3, sha1_key=None, bfd_key_id=None, is_tunnel=False): self._test = test self._interface = interface self._af = af if local_addr: self._local_addr = VppIpAddress(local_addr) else: self._local_addr = None self._peer_addr = VppIpAddress(peer_addr) self._desired_min_tx = desired_min_tx self._required_min_rx = required_min_rx self._detect_mult = detect_mult self._sha1_key = sha1_key if bfd_key_id is not None: self._bfd_key_id = bfd_key_id else: self._bfd_key_id = randint(0, 255) self._is_tunnel = is_tunnel
def create_vxlan_gbp_flood_test_bd(cls, vni, n_ucast_tunnels): # Create 2 ucast vxlan tunnels under bd ip_range_start = 10 ip_range_end = ip_range_start + n_ucast_tunnels next_hop_address = cls.pg0.remote_ip4 for dest_ip4 in ip4_range(cls.pg0.remote_ip4, ip_range_start, ip_range_end): # add host route so dest_ip4n will not be resolved rip = VppIpRoute(cls, dest_ip4, 32, [VppRoutePath(next_hop_address, INVALID_INDEX)], register=False) rip.add_vpp_config() r = cls.vapi.vxlan_gbp_tunnel_add_del(tunnel={ 'src': VppIpAddress(cls.pg0.local_ip4).encode(), 'dst': VppIpAddress(dest_ip4).encode(), 'vni': vni, 'instance': INVALID_INDEX, 'mcast_sw_if_index': INVALID_INDEX, 'mode': 1, }, is_add=1) cls.vapi.sw_interface_set_l2_bridge(rx_sw_if_index=r.sw_if_index, bd_id=vni)
def find_vxlan_gbp_tunnel(test, src, dst, vni): vsrc = VppIpAddress(src) vdst = VppIpAddress(dst) ts = test.vapi.vxlan_gbp_tunnel_dump(INDEX_INVALID) for t in ts: if vsrc == t.tunnel.src and \ vdst == t.tunnel.dst and \ t.tunnel.vni == vni: return t.tunnel.sw_if_index return INDEX_INVALID
def setUpClass(cls): super(TestVxlanGbp, cls).setUpClass() try: cls.dport = 48879 cls.flags = 0x88 cls.gpflags = 0x0 cls.sclass = 0 # Create 2 pg interfaces. cls.create_pg_interfaces(range(4)) for pg in cls.pg_interfaces: pg.admin_up() # Configure IPv4 addresses on VPP pg0. cls.pg0.config_ip4() # Resolve MAC address for VPP's IP address on pg0. cls.pg0.resolve_arp() # Create VXLAN GBP VTEP on VPP pg0, and put vxlan_gbp_tunnel0 and # pg1 into BD. cls.single_tunnel_bd = 1 r = cls.vapi.vxlan_gbp_tunnel_add_del(tunnel={ 'src': VppIpAddress(cls.pg0.local_ip4).encode(), 'dst': VppIpAddress(cls.pg0.remote_ip4).encode(), 'vni': cls.single_tunnel_bd, 'instance': INVALID_INDEX, 'mcast_sw_if_index': INVALID_INDEX, 'mode': 1, }, is_add=1) cls.vapi.sw_interface_set_l2_bridge(rx_sw_if_index=r.sw_if_index, bd_id=cls.single_tunnel_bd) cls.vapi.sw_interface_set_l2_bridge( rx_sw_if_index=cls.pg1.sw_if_index, bd_id=cls.single_tunnel_bd) # Setup vni 2 to test multicast flooding cls.n_ucast_tunnels = 2 # Setup vni 3 to test unicast flooding cls.ucast_flood_bd = 3 cls.create_vxlan_gbp_flood_test_bd(cls.ucast_flood_bd, cls.n_ucast_tunnels) cls.vapi.sw_interface_set_l2_bridge( rx_sw_if_index=cls.pg3.sw_if_index, bd_id=cls.ucast_flood_bd) except Exception: super(TestVxlanGbp, cls).tearDownClass() raise
def __init__(self, test, src, dst, vni, mcast_itf=None, mode=None): """ Create VXLAN-GBP Tunnel interface """ super(VppVxlanGbpTunnel, self).__init__(test) self.src = VppIpAddress(src) self.dst = VppIpAddress(dst) self.vni = vni self.mcast_itf = mcast_itf if not mode: self.mode = (VppEnum.vl_api_vxlan_gbp_api_tunnel_mode_t. VXLAN_GBP_API_TUNNEL_MODE_L2) else: self.mode = mode
def create_vxlan_gbp_flood_test_bd(cls, vni, n_ucast_tunnels): # Create 2 ucast vxlan tunnels under bd ip_range_start = 10 ip_range_end = ip_range_start + n_ucast_tunnels next_hop_address = cls.pg0.remote_ip4n for dest_ip4 in ip4_range(cls.pg0.remote_ip4, ip_range_start, ip_range_end): # add host route so dest_ip4n will not be resolved vip = VppIpAddress(dest_ip4) cls.vapi.ip_add_del_route(vip.bytes, 32, next_hop_address) r = cls.vapi.vxlan_gbp_tunnel_add_del(VppIpAddress( cls.pg0.local_ip4).encode(), vip.encode(), vni=vni) cls.vapi.sw_interface_set_l2_bridge(r.sw_if_index, bd_id=vni)
def set_sw_if_index(self, sw_if_index): self._sw_if_index = sw_if_index self.generate_remote_hosts() self._local_ip4 = VppIpPrefix("172.16.%u.1" % self.sw_if_index, 24) self._local_ip4_subnet = "172.16.%u.0" % self.sw_if_index self._local_ip4_bcast = "172.16.%u.255" % self.sw_if_index self.has_ip4_config = False self.ip4_table_id = 0 self._local_ip6 = VppIpPrefix("fd01:%x::1" % self.sw_if_index, 64) self.has_ip6_config = False self.ip6_table_id = 0 self._local_addr = {socket.AF_INET: self.local_ip4, socket.AF_INET6: self.local_ip6} self._remote_addr = {socket.AF_INET: self.remote_ip4, socket.AF_INET6: self.remote_ip6} r = self.test.vapi.sw_interface_dump(sw_if_index=self.sw_if_index) for intf in r: if intf.sw_if_index == self.sw_if_index: self._name = intf.interface_name.split(b'\0', 1)[0].decode('utf8') self._local_mac = bytes(intf.l2_address) self._dump = intf break else: raise Exception( "Could not find interface with sw_if_index %d " "in interface dump %s" % (self.sw_if_index, moves.reprlib.repr(r))) self._local_ip6_ll = VppIpAddress(mk_ll_addr(self.local_mac)) self._remote_ip6_ll = mk_ll_addr(self.remote_mac)
def add_del_arp_term_hosts(self, entries, bd_id=1, is_add=1, is_ipv6=0): for e in entries: ip = e.ip4 if is_ipv6 == 0 else e.ip6 self.vapi.bd_ip_mac_add_del(bd_id=bd_id, mac=VppMacAddress(e.mac).encode(), ip=VppIpAddress(ip).encode(), is_ipv6=is_ipv6, is_add=is_add)
def __init__(self, test, src, dst, vni, mcast_itf=None, mode=None, is_ipv6=None, encap_table_id=None, instance=0xffffffff): """ Create VXLAN-GBP Tunnel interface """ super(VppVxlanGbpTunnel, self).__init__(test) self.src = VppIpAddress(src) self.dst = VppIpAddress(dst) self.vni = vni self.mcast_itf = mcast_itf self.ipv6 = is_ipv6 self.encap_table_id = encap_table_id self.instance = instance if not mode: self.mode = (VppEnum.vl_api_vxlan_gbp_api_tunnel_mode_t. VXLAN_GBP_API_TUNNEL_MODE_L2) else: self.mode = mode
def find_bridge_domain_arp_entry(test, bd_id, mac, ip): vmac = MACAddress(mac) vip = VppIpAddress(ip) if vip.version == 4: n = 4 else: n = 16 arps = test.vapi.bd_ip_mac_dump(bd_id) for arp in arps: # do IP addr comparison too once .api is fixed... if vmac.packed == arp.mac_address and \ vip.bytes == arp.ip_address[:n]: return True return False
def __init__(self, test, bd, mac, ip): self._test = test self.bd = bd self.mac = MACAddress(mac) self.ip = VppIpAddress(ip)
def set_mac(self, mac): self._local_mac = str(mac) self._local_ip6_ll = VppIpAddress(mk_ll_addr(self._local_mac)) self.test.vapi.sw_interface_set_mac_address( self.sw_if_index, mac.packed)