in ptf/sainexthop.py [0:0]
def runTest(self):
print("tunnelVniTest")
vni2 = 5000
service_vm_ip = "200.200.200.2"
service_vtep_ip = "30.30.30.3"
service_vni = 3000
service_vni2 = 4000
try:
urif1 = sai_thrift_create_router_interface(
self.client, type=SAI_ROUTER_INTERFACE_TYPE_PORT,
port_id=self.port25, virtual_router_id=self.uvrf)
uneighbor1 = sai_thrift_neighbor_entry_t(
rif_id=urif1, ip_address=sai_ipaddress(self.tunnel_ip))
sai_thrift_create_neighbor_entry(
self.client, uneighbor1,
dst_mac_address=self.underlay_neighbor_mac)
unhop1 = sai_thrift_create_next_hop(
self.client, ip=sai_ipaddress('10.10.10.1'),
router_interface_id=urif1, type=SAI_NEXT_HOP_TYPE_IP)
tunnel_route1 = sai_thrift_route_entry_t(
vr_id=self.uvrf, destination=sai_ipprefix('10.10.10.1/32'))
sai_thrift_create_route_entry(self.client, tunnel_route1,
next_hop_id=unhop1)
urif2 = sai_thrift_create_router_interface(
self.client, type=SAI_ROUTER_INTERFACE_TYPE_PORT,
port_id=self.port26, virtual_router_id=self.uvrf)
uneighbor2 = sai_thrift_neighbor_entry_t(
rif_id=urif2, ip_address=sai_ipaddress(service_vtep_ip))
sai_thrift_create_neighbor_entry(
self.client, uneighbor2,
dst_mac_address=self.underlay_neighbor_mac2)
unhop2 = sai_thrift_create_next_hop(
self.client, ip=sai_ipaddress('30.30.30.3'),
router_interface_id=urif2, type=SAI_NEXT_HOP_TYPE_IP)
tunnel_route2 = sai_thrift_route_entry_t(
vr_id=self.uvrf, destination=sai_ipprefix('30.30.30.3/32'))
sai_thrift_create_route_entry(self.client, tunnel_route2,
next_hop_id=unhop2)
tunnel_nexthop1 = sai_thrift_create_next_hop(
self.client, type=SAI_NEXT_HOP_TYPE_TUNNEL_ENCAP,
tunnel_id=self.tunnel, ip=sai_ipaddress(self.tunnel_ip),
tunnel_vni=self.vni, tunnel_mac=self.inner_dmac)
tunnel_nexthop2 = sai_thrift_create_next_hop(
self.client, type=SAI_NEXT_HOP_TYPE_TUNNEL_ENCAP,
tunnel_id=self.tunnel, ip=sai_ipaddress(self.tunnel_ip),
tunnel_vni=vni2, tunnel_mac=self.inner_dmac)
self.assertNotEqual(
tunnel_nexthop2, 0,
"Failed to create nexthop to same dest ip with different vni")
tunnel_nexthop3 = sai_thrift_create_next_hop(
self.client, type=SAI_NEXT_HOP_TYPE_TUNNEL_ENCAP,
tunnel_id=self.tunnel, ip=sai_ipaddress(service_vtep_ip),
tunnel_vni=service_vni, tunnel_mac=self.inner_dmac3)
customer_route1 = sai_thrift_route_entry_t(
vr_id=self.ovrf, destination=sai_ipprefix(self.vm_ip+'/32'))
sai_thrift_create_route_entry(self.client, customer_route1,
next_hop_id=tunnel_nexthop1)
customer_route2 = sai_thrift_route_entry_t(
vr_id=self.ovrf, destination=sai_ipprefix(self.vm_ip2+'/32'))
sai_thrift_create_route_entry(self.client, customer_route2,
next_hop_id=tunnel_nexthop2)
customer_route3 = sai_thrift_route_entry_t(
vr_id=self.ovrf, destination=sai_ipprefix(service_vm_ip+'/32'))
sai_thrift_create_route_entry(self.client, customer_route3,
next_hop_id=tunnel_nexthop3)
pkt = simple_tcp_packet(
eth_dst=ROUTER_MAC,
eth_src='00:22:22:22:22:22',
ip_dst=self.vm_ip,
ip_src=self.customer_ip,
ip_id=108,
ip_ttl=64)
inner_pkt = simple_tcp_packet(
eth_dst=self.inner_dmac,
eth_src=ROUTER_MAC,
ip_dst=self.vm_ip,
ip_src=self.customer_ip,
ip_id=108,
ip_ttl=63)
vxlan_pkt = Mask(simple_vxlan_packet(
eth_src=ROUTER_MAC,
eth_dst=self.underlay_neighbor_mac,
ip_id=0,
ip_src=self.my_lb_ip,
ip_dst=self.tunnel_ip,
ip_ttl=64,
ip_flags=0x2,
with_udp_chksum=False,
vxlan_vni=self.vni,
inner_frame=inner_pkt))
vxlan_pkt.set_do_not_care_scapy(UDP, 'sport')
print("Sending packet on port %d to vni %d" %
(self.dev_port24, self.vni))
send_packet(self, self.dev_port24, pkt)
verify_packet(self, vxlan_pkt, self.dev_port25)
pkt = simple_tcp_packet(
eth_dst=ROUTER_MAC,
eth_src='00:22:22:22:22:22',
ip_dst=self.vm_ip2,
ip_src=self.customer_ip,
ip_id=108,
ip_ttl=64)
inner_pkt = simple_tcp_packet(
eth_dst=self.inner_dmac,
eth_src=ROUTER_MAC,
ip_dst=self.vm_ip2,
ip_src=self.customer_ip,
ip_id=108,
ip_ttl=63)
vxlan_pkt = Mask(simple_vxlan_packet(
eth_src=ROUTER_MAC,
eth_dst=self.underlay_neighbor_mac,
ip_id=0,
ip_src=self.my_lb_ip,
ip_dst=self.tunnel_ip,
ip_ttl=64,
ip_flags=0x2,
with_udp_chksum=False,
vxlan_vni=vni2,
inner_frame=inner_pkt))
vxlan_pkt.set_do_not_care_scapy(UDP, 'sport')
print("Sending packet on port %d to vni %d" %
(self.dev_port24, vni2))
send_packet(self, self.dev_port24, pkt)
verify_packet(self, vxlan_pkt, self.dev_port25)
print("Updating nexthop tunnel mac {} -> {}".format(
self.inner_dmac3,
self.inner_dmac4))
sai_thrift_set_next_hop_attribute(
self.client, tunnel_nexthop3, tunnel_mac=self.inner_dmac4)
print(sai_thrift_get_next_hop_attribute(
self.client, tunnel_nexthop3, tunnel_mac=True))
pkt = simple_tcp_packet(
eth_dst=ROUTER_MAC,
eth_src='00:22:22:22:22:22',
ip_dst=service_vm_ip,
ip_src=self.customer_ip,
ip_id=108,
ip_ttl=64)
inner_pkt = simple_tcp_packet(
eth_dst=self.inner_dmac4,
eth_src=ROUTER_MAC,
ip_dst=service_vm_ip,
ip_src=self.customer_ip,
ip_id=108,
ip_ttl=63)
vxlan_pkt = Mask(simple_vxlan_packet(
eth_src=ROUTER_MAC,
eth_dst=self.underlay_neighbor_mac2,
ip_id=0,
ip_src=self.my_lb_ip,
ip_dst=service_vtep_ip,
ip_ttl=64,
ip_flags=0x2,
with_udp_chksum=False,
vxlan_vni=service_vni,
inner_frame=inner_pkt))
vxlan_pkt.set_do_not_care_scapy(UDP, 'sport')
print("Sending packet on port %d to vni %d" %
(self.dev_port24, service_vni))
send_packet(self, self.dev_port24, pkt)
verify_packet(self, vxlan_pkt, self.dev_port26)
pkt = simple_tcp_packet(
eth_dst=ROUTER_MAC,
eth_src='00:22:22:22:22:22',
ip_dst=service_vm_ip,
ip_src=self.customer_ip,
ip_id=108,
ip_ttl=64)
inner_pkt = simple_tcp_packet(
eth_dst=self.inner_dmac4,
eth_src=ROUTER_MAC,
ip_dst=service_vm_ip,
ip_src=self.customer_ip,
ip_id=108,
ip_ttl=63)
vxlan_pkt = Mask(simple_vxlan_packet(
eth_src=ROUTER_MAC,
eth_dst=self.underlay_neighbor_mac2,
ip_id=0,
ip_src=self.my_lb_ip,
ip_dst=service_vtep_ip,
ip_ttl=64,
ip_flags=0x2,
with_udp_chksum=False,
vxlan_vni=service_vni2,
inner_frame=inner_pkt))
print("Updating nexthop tunnel vni {} -> {}".format(service_vni,
service_vni2))
sai_thrift_set_next_hop_attribute(self.client, tunnel_nexthop3,
tunnel_vni=4000)
print(sai_thrift_get_next_hop_attribute(self.client,
tunnel_nexthop3,
tunnel_vni=True))
vxlan_pkt.set_do_not_care_scapy(UDP, 'sport')
print("Sending packet on port %d to vni %d" %
(self.dev_port24, service_vni2))
send_packet(self, self.dev_port24, pkt)
verify_packet(self, vxlan_pkt, self.dev_port26)
finally:
if 'customer_route3' in locals() and customer_route3:
sai_thrift_remove_route_entry(self.client, customer_route3)
if 'customer_route2' in locals() and customer_route2:
sai_thrift_remove_route_entry(self.client, customer_route2)
if 'customer_route1' in locals() and customer_route1:
sai_thrift_remove_route_entry(self.client, customer_route1)
if 'tunnel_nexthop3' in locals() and tunnel_nexthop3:
sai_thrift_remove_next_hop(self.client, tunnel_nexthop3)
if 'tunnel_nexthop2' in locals() and tunnel_nexthop2:
sai_thrift_remove_next_hop(self.client, tunnel_nexthop2)
if 'tunnel_nexthop1' in locals() and tunnel_nexthop1:
sai_thrift_remove_next_hop(self.client, tunnel_nexthop1)
sai_thrift_remove_route_entry(self.client, tunnel_route2)
sai_thrift_remove_route_entry(self.client, tunnel_route1)
sai_thrift_remove_next_hop(self.client, unhop2)
sai_thrift_remove_next_hop(self.client, unhop1)
sai_thrift_remove_neighbor_entry(self.client, uneighbor2)
sai_thrift_remove_neighbor_entry(self.client, uneighbor1)
sai_thrift_remove_router_interface(self.client, urif2)
sai_thrift_remove_router_interface(self.client, urif1)