in ptf/sairif.py [0:0]
def runTest(self):
print("\nsubPortTunnelTest()")
iport = self.port26
iport_dev = self.dev_port26
eport = self.port27
eport_dev = self.dev_port27
vlan_id = 999
tun_vni = 2000
tun_ip = "30.30.30.1"
lpb_ip = "30.30.30.10"
vm_ip = "100.100.1.1"
customer_ip = "100.100.2.1"
tun_mac = "00:aa:aa:aa:aa:aa"
tun_term_mac = "00:bb:bb:bb:bb:bb"
customer_mac = "00:ee:ee:ee:ee:ee"
try:
# underlay configuration
uvrf = sai_thrift_create_virtual_router(self.client)
# overlay configuration
ovrf = sai_thrift_create_virtual_router(self.client)
# underlay loopback RIF for tunnel
urif_lpb = sai_thrift_create_router_interface(
self.client,
type=SAI_ROUTER_INTERFACE_TYPE_LOOPBACK,
virtual_router_id=uvrf)
# route to tunnel termination IP
urif = sai_thrift_create_router_interface(
self.client,
type=SAI_ROUTER_INTERFACE_TYPE_SUB_PORT,
virtual_router_id=uvrf,
port_id=eport,
outer_vlan_id=vlan_id)
# overlay RIF
orif = sai_thrift_create_router_interface(
self.client,
type=SAI_ROUTER_INTERFACE_TYPE_PORT,
virtual_router_id=ovrf,
port_id=iport)
# encapsulation configuration
encap_tunnel_map = sai_thrift_create_tunnel_map(
self.client, type=SAI_TUNNEL_MAP_TYPE_VIRTUAL_ROUTER_ID_TO_VNI)
decap_tunnel_map = sai_thrift_create_tunnel_map(
self.client, type=SAI_TUNNEL_MAP_TYPE_VNI_TO_VIRTUAL_ROUTER_ID)
encap_tunnel_map_entry = sai_thrift_create_tunnel_map_entry(
self.client,
tunnel_map=encap_tunnel_map,
tunnel_map_type=SAI_TUNNEL_MAP_TYPE_VIRTUAL_ROUTER_ID_TO_VNI,
virtual_router_id_key=ovrf,
vni_id_value=tun_vni)
decap_tunnel_map_entry = sai_thrift_create_tunnel_map_entry(
self.client,
tunnel_map=encap_tunnel_map,
tunnel_map_type=SAI_TUNNEL_MAP_TYPE_VNI_TO_VIRTUAL_ROUTER_ID,
virtual_router_id_value=ovrf,
vni_id_key=tun_vni)
encap_maps = sai_thrift_object_list_t(
count=1, idlist=[encap_tunnel_map])
decap_maps = sai_thrift_object_list_t(
count=1, idlist=[decap_tunnel_map])
tunnel = sai_thrift_create_tunnel(
self.client,
type=SAI_TUNNEL_TYPE_VXLAN,
encap_src_ip=sai_ipaddress(lpb_ip),
encap_mappers=encap_maps,
decap_mappers=decap_maps,
encap_ttl_mode=SAI_TUNNEL_TTL_MODE_PIPE_MODEL,
decap_ttl_mode=SAI_TUNNEL_TTL_MODE_PIPE_MODEL,
underlay_interface=urif_lpb)
tunnel_term = sai_thrift_create_tunnel_term_table_entry(
self.client,
tunnel_type=SAI_TUNNEL_TYPE_VXLAN,
action_tunnel_id=tunnel,
vr_id=uvrf,
type=SAI_TUNNEL_TERM_TABLE_ENTRY_TYPE_P2P,
src_ip=sai_ipaddress(tun_ip),
dst_ip=sai_ipaddress(lpb_ip))
# route from VM to customer
onhop = sai_thrift_create_next_hop(self.client,
ip=sai_ipaddress(customer_ip),
router_interface_id=orif,
type=SAI_NEXT_HOP_TYPE_IP)
onbor = sai_thrift_neighbor_entry_t(
rif_id=orif, ip_address=sai_ipaddress(customer_ip))
sai_thrift_create_neighbor_entry(self.client,
onbor,
dst_mac_address=customer_mac,
no_host_route=True)
customer_route = sai_thrift_route_entry_t(
vr_id=ovrf, destination=sai_ipprefix(customer_ip + '/32'))
sai_thrift_create_route_entry(
self.client, customer_route, next_hop_id=onhop)
# route from customer to VM
tunnel_nhop = sai_thrift_create_next_hop(
self.client,
type=SAI_NEXT_HOP_TYPE_TUNNEL_ENCAP,
tunnel_id=tunnel,
ip=sai_ipaddress(tun_ip),
tunnel_mac=tun_mac,
tunnel_vni=tun_vni)
vm_route = sai_thrift_route_entry_t(
vr_id=ovrf, destination=sai_ipprefix(vm_ip + '/32'))
sai_thrift_create_route_entry(
self.client, vm_route, next_hop_id=tunnel_nhop)
unhop = sai_thrift_create_next_hop(self.client,
ip=sai_ipaddress(tun_ip),
router_interface_id=urif,
type=SAI_NEXT_HOP_TYPE_IP)
unbor = sai_thrift_neighbor_entry_t(
rif_id=urif, ip_address=sai_ipaddress(tun_ip))
sai_thrift_create_neighbor_entry(self.client,
unbor,
dst_mac_address=tun_term_mac,
no_host_route=True)
tunnel_route = sai_thrift_route_entry_t(
vr_id=uvrf, destination=sai_ipprefix(tun_ip + '/32'))
sai_thrift_create_route_entry(
self.client, tunnel_route, next_hop_id=unhop)
pkt = simple_tcp_packet(eth_dst=ROUTER_MAC,
eth_src=customer_mac,
ip_dst=vm_ip,
ip_src=customer_ip,
ip_id=108,
ip_ttl=64)
inner_pkt = simple_tcp_packet(eth_dst=tun_mac,
eth_src=ROUTER_MAC,
ip_dst=vm_ip,
ip_src=customer_ip,
ip_id=108,
ip_ttl=63)
vxlan_pkt = Mask(
simple_vxlan_packet(eth_dst=tun_term_mac,
eth_src=ROUTER_MAC,
ip_dst=tun_ip,
ip_src=lpb_ip,
ip_id=0,
ip_ttl=64,
ip_flags=0x2,
dl_vlan_enable=True,
vlan_vid=vlan_id,
with_udp_chksum=False,
vxlan_vni=tun_vni,
inner_frame=inner_pkt))
vxlan_pkt.set_do_not_care_scapy(UDP, 'sport')
print("Sending packet to VM")
send_packet(self, iport_dev, pkt)
verify_packet(self, vxlan_pkt, eport_dev)
print("\tOK")
pkt = simple_tcp_packet(eth_dst=customer_mac,
eth_src=ROUTER_MAC,
ip_dst=customer_ip,
ip_src=vm_ip,
ip_id=108,
ip_ttl=63)
inner_pkt = simple_tcp_packet(eth_dst=ROUTER_MAC,
eth_src=tun_mac,
ip_dst=customer_ip,
ip_src=vm_ip,
ip_id=108,
ip_ttl=64)
vxlan_pkt = simple_vxlan_packet(eth_dst=ROUTER_MAC,
eth_src=tun_term_mac,
ip_dst=lpb_ip,
ip_src=tun_ip,
ip_id=0,
ip_ttl=64,
ip_flags=0x2,
dl_vlan_enable=True,
vlan_vid=vlan_id,
with_udp_chksum=False,
vxlan_vni=tun_vni,
inner_frame=inner_pkt)
print("Sending packet to customer")
send_packet(self, eport_dev, vxlan_pkt)
verify_packet(self, pkt, iport_dev)
print("\tOK")
finally:
sai_thrift_remove_route_entry(self.client, tunnel_route)
sai_thrift_remove_neighbor_entry(self.client, unbor)
sai_thrift_remove_next_hop(self.client, unhop)
sai_thrift_remove_route_entry(self.client, vm_route)
sai_thrift_remove_next_hop(self.client, tunnel_nhop)
sai_thrift_remove_route_entry(self.client, customer_route)
sai_thrift_remove_neighbor_entry(self.client, onbor)
sai_thrift_remove_next_hop(self.client, onhop)
sai_thrift_remove_tunnel_term_table_entry(self.client, tunnel_term)
sai_thrift_remove_tunnel(self.client, tunnel)
sai_thrift_remove_tunnel_map_entry(
self.client, decap_tunnel_map_entry)
sai_thrift_remove_tunnel_map_entry(
self.client, encap_tunnel_map_entry)
sai_thrift_remove_tunnel_map(self.client, decap_tunnel_map)
sai_thrift_remove_tunnel_map(self.client, encap_tunnel_map)
sai_thrift_remove_router_interface(self.client, orif)
sai_thrift_remove_router_interface(self.client, urif)
sai_thrift_remove_router_interface(self.client, urif_lpb)
sai_thrift_remove_virtual_router(self.client, ovrf)
sai_thrift_remove_virtual_router(self.client, uvrf)