add application
diff --git a/application_example/virtualRouter.py b/application_example/virtualRouter.py
new file mode 100755
index 0000000..166b67f
--- /dev/null
+++ b/application_example/virtualRouter.py
@@ -0,0 +1,840 @@
+"""
+This case test VM routing on same VNID
+"""
+
+import logging
+
+from oftest import config
+import oftest.base_tests as base_tests
+import ofp
+from oftest.testutils import *
+from accton_util import *
+
+NW1_ACCESS_LPORT=0x10001
+NW2_ACCESS_LPORT=0x10002
+NW1_NEWORK_LPORT=0x10003
+NW2_NEWORK_LPORT=0x10004
+
+NW1_VRF=1
+NW2_VRF=2
+NW_VRF=[NW1_VRF, NW2_VRF]
+SWITCH_VRF=0
+assert(NW1_VRF!=SWITCH_VRF)
+assert(NW2_VRF!=SWITCH_VRF)
+NW1_VNID=1
+NW2_VNID=2
+NW_VNID=[NW1_VNID, NW2_VNID]
+
+
+NW1_VLAN = 2
+NW2_VLAN = 3
+NW_VLAN=[NW1_VLAN, NW2_VLAN]
+SWITCH_VLAN=1
+
+#SWITCH_INTF_MAC = from feature.replay, because each switch is not the same,
+# current we just can use switch CPU MAC, due to tunnel terminator
+# have no way to set mac
+#SWITCH_INTF_MAC_STR
+SWITCH_IP=0XC0A80101 #192.168.1.1
+SWITCH_IP_STR=convertIP4toStr(SWITCH_IP)
+#H1 for NW1, H2 for NW2
+#remember for chip limitaion, it can't have nexthop
+#has same vid, port but diff dst_mac
+VXLAN_TNL_H1_IP=0XC0A80202#192.168.2.2
+VXLAN_TNL_H1_IP_STR=convertIP4toStr(VXLAN_TNL_H1_IP)
+VXLAN_TNL_H1_MAC=[0x00, 0x31, 0x31, 0x31, 0x31, 0x31] #like router MAC
+VXLAN_TNL_H1_MAC_STR=convertMACtoStr(VXLAN_TNL_H1_MAC)
+VXLAN_TNL_H2_IP=0XC0A80303#192.168.3.3
+VXLAN_TNL_H2_IP_STR=convertIP4toStr(VXLAN_TNL_H2_IP)
+VXLAN_TNL_H2_MAC=[0x00, 0x31, 0x31, 0x31, 0x31, 0x31] #like router MAC
+VXLAN_TNL_H2_MAC_STR=convertMACtoStr(VXLAN_TNL_H2_MAC)
+VXLAN_TNL_H_R_MAC=[0x00, 0x31, 0x31, 0x31, 0x31, 0x31]
+VXLAN_TNL_H_R_MAC_STR=convertMACtoStr(VXLAN_TNL_H_R_MAC)
+VXLAN_TNL_H_R_NHP_ID=1
+
+NW1_VM1_IP = 0XC0A80101
+NW1_VM1_IP_STR = convertIP4toStr(NW1_VM1_IP)
+NW1_VM1_MAC=[0x00, 0x11, 0x11, 0x11, 0x11, 0x11]
+NW1_VM1_MAC_STR=convertMACtoStr(NW1_VM1_MAC)
+NW1_VM2_IP = 0XC0A80201
+NW1_VM2_IP_STR = convertIP4toStr(NW1_VM2_IP)
+NW1_VM2_MAC=[0x00, 0x12, 0x12, 0x12, 0x12, 0x12]
+NW1_VM2_MAC_STR=convertMACtoStr(NW1_VM2_MAC)
+NW2_VM1_IP = 0XC0A80101
+NW2_VM1_IP_STR = convertIP4toStr(NW2_VM1_IP)
+NW2_VM1_MAC=[0x00, 0x21, 0x21, 0x21, 0x21, 0x21]
+NW2_VM1_MAC_STR=convertMACtoStr(NW2_VM1_MAC)
+NW2_VM2_IP = 0XC0A80201
+NW2_VM2_IP_STR = convertIP4toStr(NW2_VM2_IP)
+NW2_VM2_MAC=[0x00, 0x22, 0x22, 0x22, 0x22, 0x22]
+NW2_VM2_MAC_STR=convertMACtoStr(NW2_VM2_MAC)
+
+NW1_GW_MAC=[0x00, 0x00, 0x00, 0x00, 0x11, 0x11]
+NW1_GW_MAC_STR=convertMACtoStr(NW1_GW_MAC)
+NW1_ROUTE1 =NW1_VM1_IP
+NW1_ROUTE1_STR =NW1_VM1_IP_STR
+NW1_ROUTE1_NEXT_HOP_MAC=NW1_VM1_MAC
+NW1_ROUTE2 =NW1_VM2_IP
+NW1_ROUTE2_NEXT_HOP_MAC=NW1_VM2_MAC
+NW1_ROUTE2_STR =NW1_VM2_IP_STR
+NW1_GW_ROUTE =[NW1_ROUTE1, NW1_ROUTE2]
+NW1_GW_ROUTE_STR=[NW1_ROUTE1_STR, NW1_ROUTE2_STR]
+NW1_GW_ROUTE_NHP=[NW1_ROUTE1_NEXT_HOP_MAC, NW1_ROUTE2_NEXT_HOP_MAC]
+
+NW2_GW_MAC=[0x00, 0x00, 0x00, 0x00, 0x22, 0x22]
+NW2_GW_MAC_STR=convertMACtoStr(NW2_GW_MAC)
+NW2_ROUTE1 =NW2_VM1_IP
+NW2_ROUTE1_STR =NW2_VM1_IP_STR
+NW2_ROUTE1_NEXT_HOP_MAC=NW2_VM1_MAC
+NW2_ROUTE2 =NW2_VM2_IP
+NW2_ROUTE2_STR =NW2_VM1_IP_STR
+NW2_ROUTE2_NEXT_HOP_MAC=NW2_VM2_MAC
+NW2_GW_ROUT_STR=[NW2_ROUTE1_STR, NW2_ROUTE2_STR]
+
+NW_GW_MAC=[NW1_GW_MAC, NW2_GW_MAC]
+NW_GW_MAC_STR=[NW1_GW_MAC_STR, NW2_GW_MAC_STR]
+
+
+#make sure array has same length
+assert(len(NW_GW_MAC) == len(NW_GW_MAC_STR))
+assert(len(NW_GW_MAC) == len(NW_VLAN))
+
+class vrouterSameVNIRouting(base_tests.SimpleDataPlane):
+ """
+ Topology:
+ === switch inner pipeline
+ --- switch forn port physical link
+ R: router
+ NP:netowrk port
+ AP:Access port
+ LP:loopback port
+ H1(VM1/VM2) -- R ----------- NP ==== AP --- LP
+ H2 --
+
+ VM1(192.168.1.1, NW1_VNID) <--> VM2(192.168.2.1, NW1_VNID)
+ VM1(192.168.1.1, NW2_VNID) <--> VM2(192.168.2.1, NW2_VNID)
+
+ Inner operation:
+ (decap/encap vxlan header)NP==(bridge inner DMAC)==AP(VNID->VLANID)----(VLANID->VRF)LP
+
+
+
+ """
+ def runTest(self):
+ delete_all_flows(self.controller)
+ delete_all_groups(self.controller)
+
+ ACCESS_PORT=config["port_map"].keys()[0]
+ NETWORK_PORT=config["port_map"].keys()[1]
+ LOOPBACK_PORT=config["port_map"].keys()[2]
+ print "access %ld, network %ld, loopback %ld"%(ACCESS_PORT, NETWORK_PORT, LOOPBACK_PORT)
+ """ add vxlan config"""
+ feature_reply=get_featureReplay(self)
+ SWITCH_INTF_MAC_STR, SWITCH_INTF_MAC=getSwitchCpuMACFromDPID(feature_reply.datapath_id)
+ #add vni
+ vni_config_xml=get_vni_config_xml(vni_id=NW1_VNID, mcast_ipv4=None, next_hop_id=None)
+ logging.info("config VNI %lx", NW1_VNID);
+ assert(send_edit_config(config["switch_ip"], vni_config_xml) == True)
+ vni_config_xml=get_vni_config_xml(vni_id=NW2_VNID, mcast_ipv4=None, next_hop_id=None)
+ logging.info("config VNI %lx", NW2_VNID);
+ assert(send_edit_config(config["switch_ip"], vni_config_xml) == True)
+ #add access port
+ vtap_conf_xml=get_vtap_lport_config_xml(dp_id=feature_reply.datapath_id,
+ lport=NW1_ACCESS_LPORT, phy_port=ACCESS_PORT,
+ vlan=NW1_VLAN, vnid=NW1_VNID)
+ logging.info("config VTAP 0x%lx, PHY %d, VID %d, VNID %lx", NW1_ACCESS_LPORT, ACCESS_PORT, NW1_VLAN, NW1_VNID);
+ assert(send_edit_config(config["switch_ip"], vtap_conf_xml) == True)
+ vtap_conf_xml=get_vtap_lport_config_xml(dp_id=feature_reply.datapath_id,
+ lport=NW2_ACCESS_LPORT, phy_port=ACCESS_PORT,
+ vlan=NW2_VLAN, vnid=NW2_VNID)
+ logging.info("config VTAP 0x%lx, PHY %d, VID %d, VNID %lx", NW2_ACCESS_LPORT, ACCESS_PORT, NW1_VLAN, NW1_VNID);
+ assert(send_edit_config(config["switch_ip"], vtap_conf_xml) == True)
+ #create next hop and network port for H1
+ next_hop_conf_xml=get_next_hop_config_xml(next_hop_id=VXLAN_TNL_H_R_NHP_ID,
+ dst_mac=VXLAN_TNL_H_R_MAC_STR,
+ phy_port=NETWORK_PORT,
+ vlan=SWITCH_VLAN)
+ logging.info("config NextHop %d, DST_MAC %s, PHY %d, VLAN %d", VXLAN_TNL_H_R_NHP_ID, VXLAN_TNL_H_R_MAC_STR, NETWORK_PORT, SWITCH_VLAN);
+ assert(send_edit_config(config["switch_ip"], next_hop_conf_xml)==True)
+ #create network port
+ vtep_conf_xml=get_vtep_lport_config_xml(dp_id=feature_reply.datapath_id,
+ lport=NW1_NEWORK_LPORT,
+ src_ip=SWITCH_IP_STR, dst_ip=VXLAN_TNL_H1_IP_STR,
+ next_hop_id=VXLAN_TNL_H_R_NHP_ID,
+ vnid=NW1_VNID)
+ logging.info("config VTEP 0x%lx, VNID=%lu, SRC_IP %s, DST_IP %s, NEXTHOP_ID %d", NW1_NEWORK_LPORT, NW1_VNID, SWITCH_IP, VXLAN_TNL_H1_IP_STR, VXLAN_TNL_H_R_NHP_ID);
+ assert(send_edit_config(config["switch_ip"], vtep_conf_xml) == True)
+
+ vtep_conf_xml=get_vtep_lport_config_xml(dp_id=feature_reply.datapath_id,
+ lport=NW2_NEWORK_LPORT,
+ src_ip=SWITCH_IP_STR, dst_ip=VXLAN_TNL_H1_IP_STR,
+ next_hop_id=VXLAN_TNL_H_R_NHP_ID,
+ vnid=NW2_VNID)
+ logging.info("config VTEP 0x%lx, VNID=%lu, SRC_IP %s, DST_IP %s, NEXTHOP_ID %d", NW2_NEWORK_LPORT, NW2_VNID, SWITCH_IP, VXLAN_TNL_H1_IP_STR, VXLAN_TNL_H_R_NHP_ID);
+ assert(send_edit_config(config["switch_ip"], vtep_conf_xml) == True)
+
+
+ """add routing flow"""
+ #add port table to have vxlan ability
+ add_port_table_flow(self.controller)
+ #add l2 interface group
+ add_one_l2_interface_grouop(self.controller, NETWORK_PORT, vlan_id=SWITCH_VLAN, is_tagged=True, send_barrier=False)
+ for i in range(len(NW_VLAN)):
+ add_one_l2_interface_grouop(self.controller, LOOPBACK_PORT, vlan_id=NW_VLAN[i], is_tagged=True, send_barrier=False)
+
+ #add vlan flow table
+ add_one_vlan_table_flow(self.controller, NETWORK_PORT, SWITCH_VLAN, vrf=SWITCH_VRF, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
+
+ for i in range(len(NW_VLAN)):
+ add_one_vlan_table_flow(self.controller, LOOPBACK_PORT, NW_VLAN[i], vrf=NW_VRF[i], flag=VLAN_TABLE_FLAG_ONLY_TAG)
+ #add vxlan bridge flow
+ add_overlay_bridge_flow(self.controller, NW1_GW_MAC, NW1_VNID, NW1_ACCESS_LPORT, False, False)
+ add_overlay_bridge_flow(self.controller, NW2_GW_MAC, NW2_VNID, NW2_ACCESS_LPORT, False, False)
+ add_overlay_bridge_flow(self.controller, NW1_VM1_MAC, NW1_VNID, NW1_NEWORK_LPORT, False, False)
+ add_overlay_bridge_flow(self.controller, NW1_VM2_MAC, NW1_VNID, NW1_NEWORK_LPORT, False, False)
+ add_overlay_bridge_flow(self.controller, NW2_VM1_MAC, NW2_VNID, NW2_NEWORK_LPORT, False, False)
+ add_overlay_bridge_flow(self.controller, NW2_VM2_MAC, NW2_VNID, NW2_NEWORK_LPORT, False, False)
+
+ #add termination flow
+ add_termination_flow(self.controller, NETWORK_PORT, 0x0800, SWITCH_INTF_MAC, SWITCH_VLAN)
+ for i in range(len(NW_VLAN)):
+ add_termination_flow(self.controller, LOOPBACK_PORT, 0x0800, NW_GW_MAC[i], NW_VLAN[i])
+
+ """
+ Add Network Route, NW1
+ 192.168.1.1
+ 192.168.2.1
+ """
+ l3_msg=add_l3_unicast_group(self.controller, LOOPBACK_PORT, vlanid=NW1_VLAN, id=0x1001, src_mac=NW1_GW_MAC, dst_mac=NW1_ROUTE1_NEXT_HOP_MAC)
+ add_unicast_routing_flow(self.controller, 0x0800, NW1_ROUTE1, 0, l3_msg.group_id, NW1_VRF)
+ l3_msg=add_l3_unicast_group(self.controller, LOOPBACK_PORT, vlanid=NW1_VLAN, id=0x1002, src_mac=NW1_GW_MAC, dst_mac=NW1_ROUTE2_NEXT_HOP_MAC)
+ add_unicast_routing_flow(self.controller, 0x0800, NW1_ROUTE2, 0, l3_msg.group_id, NW1_VRF)
+ """
+ Add Network Route, NW2
+ 192.168.1.1
+ 192.168.2.1
+ """
+ l3_msg=add_l3_unicast_group(self.controller, LOOPBACK_PORT, vlanid=NW2_VLAN, id=0x2001, src_mac=NW2_GW_MAC, dst_mac=NW2_ROUTE1_NEXT_HOP_MAC)
+ add_unicast_routing_flow(self.controller, 0x0800, NW2_ROUTE1, 0, l3_msg.group_id, NW2_VRF)
+ l3_msg=add_l3_unicast_group(self.controller, LOOPBACK_PORT, vlanid=NW2_VLAN, id=0x2002, src_mac=NW2_GW_MAC, dst_mac=NW2_ROUTE2_NEXT_HOP_MAC)
+ add_unicast_routing_flow(self.controller, 0x0800, NW2_ROUTE2, 0, l3_msg.group_id, NW2_VRF)
+
+
+ """
+ Send paket to verify, NW1
+ """
+ #tx packet on network lport
+ inner_pkt = simple_udp_packet(pktlen=100
+ , eth_src = NW1_VM1_MAC_STR
+ , eth_dst=NW1_GW_MAC_STR
+ , ip_dst =NW1_VM2_IP_STR
+ , ip_src =NW1_VM1_IP_STR
+ , ip_ttl =64)
+ vxlan_pkt = simple_vxlan_packet(eth_dst=SWITCH_INTF_MAC_STR
+ ,eth_src=VXLAN_TNL_H_R_MAC_STR
+ ,vnid=NW1_VNID
+ ,ip_dst= SWITCH_IP_STR
+ ,ip_src=VXLAN_TNL_H1_IP_STR
+ ,inner_payload=inner_pkt)
+ self.dataplane.send(NETWORK_PORT, str(vxlan_pkt))
+ #verify rx on access port
+ inner_pkt = simple_udp_packet(pktlen=104
+ , eth_src= NW1_VM1_MAC_STR
+ , eth_dst=NW1_GW_MAC_STR
+ , dl_vlan_enable=True
+ , vlan_vid=NW1_VLAN
+ , ip_dst =NW1_VM2_IP_STR
+ , ip_src =NW1_VM1_IP_STR
+ , ip_ttl =64)
+ verify_packet(self, str(inner_pkt), ACCESS_PORT)
+ verify_no_other_packets(self)
+
+ #tx on loopback port
+ self.dataplane.send(LOOPBACK_PORT, str(inner_pkt))
+ #verify rx on loopback port
+ inner_pkt = simple_udp_packet(pktlen=104
+ , eth_src=NW1_GW_MAC_STR
+ , eth_dst=NW1_VM2_MAC_STR
+ , dl_vlan_enable=True
+ , vlan_vid=NW1_VLAN
+ , ip_dst =NW1_VM2_IP_STR
+ , ip_src =NW1_VM1_IP_STR
+ , ip_ttl =63)
+ verify_packet(self, str(inner_pkt), LOOPBACK_PORT)
+ verify_no_other_packets(self)
+ #tx on access port
+ self.dataplane.send(ACCESS_PORT, str(inner_pkt))
+ #verify rx on network port
+ inner_pkt = simple_udp_packet(pktlen=100
+ , eth_src=NW1_GW_MAC_STR
+ , eth_dst=NW1_VM2_MAC_STR
+ , ip_dst =NW1_VM2_IP_STR
+ , ip_src =NW1_VM1_IP_STR
+ , ip_ttl =63)
+ vxlan_pkt = simple_vxlan_packet(eth_src=SWITCH_INTF_MAC_STR
+ ,eth_dst=VXLAN_TNL_H_R_MAC_STR
+ ,vnid=NW1_VNID
+ ,ip_dst=VXLAN_TNL_H1_IP_STR
+ ,ip_src=SWITCH_IP_STR
+ ,inner_payload=inner_pkt)
+ verify_packet(self, inner_pkt, NETWORK_PORT)
+ verify_no_other_packets(self)
+
+
+ """
+ Send paket to verify, NW2
+ """
+ #tx packet on network lport
+ inner_pkt = simple_udp_packet(pktlen=100
+ , eth_src = NW2_VM1_MAC_STR
+ , eth_dst=NW2_GW_MAC_STR
+ , ip_dst =NW2_VM2_IP_STR
+ , ip_src =NW2_VM1_IP_STR
+ , ip_ttl =64)
+ vxlan_pkt = simple_vxlan_packet(eth_dst=SWITCH_INTF_MAC_STR
+ ,eth_src=VXLAN_TNL_H_R_MAC_STR
+ ,vnid=NW2_VNID
+ ,ip_dst= SWITCH_IP_STR
+ ,ip_src=VXLAN_TNL_H1_IP_STR
+ ,inner_payload=inner_pkt)
+ self.dataplane.send(NETWORK_PORT, str(vxlan_pkt))
+ #verify rx on access port
+ inner_pkt = simple_udp_packet(pktlen=104
+ , eth_src= NW2_VM1_MAC_STR
+ , eth_dst=NW2_GW_MAC_STR
+ , dl_vlan_enable=True
+ , vlan_vid=NW2_VLAN
+ , ip_dst =NW2_VM2_IP_STR
+ , ip_src =NW2_VM1_IP_STR
+ , ip_ttl =64)
+ verify_packet(self, str(inner_pkt), ACCESS_PORT)
+ verify_no_other_packets(self)
+
+ #tx on loopback port
+ self.dataplane.send(LOOPBACK_PORT, str(inner_pkt))
+ #verify rx on loopback port
+ inner_pkt = simple_udp_packet(pktlen=104
+ , eth_src=NW2_GW_MAC_STR
+ , eth_dst=NW2_VM2_MAC_STR
+ , dl_vlan_enable=True
+ , vlan_vid=NW2_VLAN
+ , ip_dst =NW2_VM2_IP_STR
+ , ip_src =NW2_VM1_IP_STR
+ , ip_ttl =63)
+ verify_packet(self, str(inner_pkt), LOOPBACK_PORT)
+ verify_no_other_packets(self)
+ #tx on access port
+ self.dataplane.send(ACCESS_PORT, str(inner_pkt))
+ #verify rx on network port
+ inner_pkt = simple_udp_packet(pktlen=100
+ , eth_src=NW2_GW_MAC_STR
+ , eth_dst=NW2_VM2_MAC_STR
+ , ip_dst =NW2_VM2_IP_STR
+ , ip_src =NW2_VM1_IP_STR
+ , ip_ttl =63)
+ vxlan_pkt = simple_vxlan_packet(eth_src=SWITCH_INTF_MAC_STR
+ ,eth_dst=VXLAN_TNL_H_R_MAC_STR
+ ,vnid=NW2_VNID
+ ,ip_dst=VXLAN_TNL_H1_IP_STR
+ ,ip_src=SWITCH_IP_STR
+ ,inner_payload=inner_pkt)
+ verify_packet(self, inner_pkt, NETWORK_PORT)
+ verify_no_other_packets(self)
+
+ """clear all flow/group and configuration
+ """
+ delete_all_flows(self.controller)
+ delete_all_groups(self.controller)
+ """ del vxlan config"""
+ #delete access port
+ vtap_conf_xml=get_vtap_lport_config_xml(dp_id=feature_reply.datapath_id,
+ lport=NW1_ACCESS_LPORT, phy_port=ACCESS_PORT,
+ vlan=NW1_VLAN, vnid=NW1_VNID, operation="delete")
+ logging.info("delete config VTAP 0x%lx, PHY %d, VID %d, VNID %lx", NW1_ACCESS_LPORT, ACCESS_PORT, NW1_VLAN, NW1_VNID);
+ assert(send_edit_config(config["switch_ip"], vtap_conf_xml) == True)
+ vtap_conf_xml=get_vtap_lport_config_xml(dp_id=feature_reply.datapath_id,
+ lport=NW2_ACCESS_LPORT, phy_port=ACCESS_PORT,
+ vlan=NW2_VLAN, vnid=NW2_VNID, operation="delete")
+ logging.info("delete config VTAP 0x%lx, PHY %d, VID %d, VNID %lx", NW2_ACCESS_LPORT, ACCESS_PORT, NW1_VLAN, NW1_VNID);
+ assert(send_edit_config(config["switch_ip"], vtap_conf_xml) == True)
+ #delete network port
+ vtep_conf_xml=get_vtep_lport_config_xml(dp_id=feature_reply.datapath_id,
+ lport=NW1_NEWORK_LPORT,
+ src_ip=SWITCH_IP_STR, dst_ip=VXLAN_TNL_H1_IP_STR,
+ next_hop_id=VXLAN_TNL_H_R_NHP_ID,
+ vnid=NW1_VNID, operation="delete")
+ logging.info("delete config VTEP 0x%lx, VNID=%lu, SRC_IP %s, DST_IP %s, NEXTHOP_ID %d", NW1_NEWORK_LPORT, NW1_VNID, SWITCH_IP, VXLAN_TNL_H1_IP_STR, VXLAN_TNL_H_R_NHP_ID);
+ assert(send_edit_config(config["switch_ip"], vtep_conf_xml) == True)
+
+ vtep_conf_xml=get_vtep_lport_config_xml(dp_id=feature_reply.datapath_id,
+ lport=NW2_NEWORK_LPORT,
+ src_ip=SWITCH_IP_STR, dst_ip=VXLAN_TNL_H1_IP_STR,
+ next_hop_id=VXLAN_TNL_H_R_NHP_ID,
+ vnid=NW2_VNID, operation="delete")
+ logging.info("delete config VTEP 0x%lx, VNID=%lu, SRC_IP %s, DST_IP %s, NEXTHOP_ID %d", NW2_NEWORK_LPORT, NW2_VNID, SWITCH_IP, VXLAN_TNL_H1_IP_STR, VXLAN_TNL_H_R_NHP_ID);
+ assert(send_edit_config(config["switch_ip"], vtep_conf_xml) == True)
+ #delete next hop and network port for H1
+ next_hop_conf_xml=get_next_hop_config_xml(next_hop_id=VXLAN_TNL_H_R_NHP_ID,
+ dst_mac=VXLAN_TNL_H_R_MAC_STR,
+ phy_port=NETWORK_PORT,
+ vlan=SWITCH_VLAN, operation="delete")
+ logging.info("delete config NextHop %d, DST_MAC %s, PHY %d, VLAN %d", VXLAN_TNL_H_R_NHP_ID, VXLAN_TNL_H_R_MAC_STR, NETWORK_PORT, SWITCH_VLAN);
+ assert(send_edit_config(config["switch_ip"], next_hop_conf_xml)==True)
+ #del vni
+ vni_config_xml=get_vni_config_xml(vni_id=NW1_VNID, mcast_ipv4=None, next_hop_id=None, operation="delete")
+ logging.info("delete config VNI %lx", NW1_VNID);
+ assert(send_edit_config(config["switch_ip"], vni_config_xml) == True)
+ vni_config_xml=get_vni_config_xml(vni_id=NW2_VNID, mcast_ipv4=None, next_hop_id=None, operation="delete")
+ logging.info("delete config VNI %lx", NW2_VNID);
+ assert(send_edit_config(config["switch_ip"], vni_config_xml) == True)
+
+#for routing on different VNID, it can't have same subnet.
+TNW1_ACCESS_LPORT=0x10001
+TNW2_ACCESS_LPORT=0x10002
+TNW1_NEWORK_LPORT=0x10003
+TNW2_NEWORK_LPORT=0x10004
+
+TNW1_VRF=2 #all shall the same
+TNW2_VRF=2
+TNW_VRF=[TNW1_VRF, TNW2_VRF]
+TSWITCH_VRF=0 #let switch different from VM
+assert(TNW2_VRF!=TSWITCH_VRF)
+assert(TNW1_VRF!=TSWITCH_VRF)
+
+TNW1_VNID=1
+TNW2_VNID=2
+TNW_VNID=[TNW1_VNID, TNW2_VNID]
+
+TNW1_VLAN = 2
+TNW2_VLAN = 3
+TNW_VLAN=[TNW1_VLAN, TNW2_VLAN]
+assert(TNW1_VLAN!=SWITCH_VLAN)
+assert(TNW2_VLAN!=SWITCH_VLAN)
+#the subnet shall not the same, because they all NW use same VRF
+TNW1_VM1_IP = 0XC0A80101 #192.168.1.1
+TNW1_VM1_IP_STR = convertIP4toStr(TNW1_VM1_IP)
+TNW1_VM1_MAC=[0x00, 0x11, 0x11, 0x11, 0x11, 0x11]
+TNW1_VM1_MAC_STR=convertMACtoStr(TNW1_VM1_MAC)
+TNW1_VM2_IP = 0XC0A80201 #192.168.2.1
+TNW1_VM2_IP_STR = convertIP4toStr(TNW1_VM2_IP)
+TNW1_VM2_MAC=[0x00, 0x12, 0x12, 0x12, 0x12, 0x12]
+TNW1_VM2_MAC_STR=convertMACtoStr(TNW1_VM2_MAC)
+TNW2_VM1_IP = 0XC0A80301 #192.168.3.1
+TNW2_VM1_IP_STR = convertIP4toStr(TNW2_VM1_IP)
+TNW2_VM1_MAC=[0x00, 0x21, 0x21, 0x21, 0x21, 0x21]
+TNW2_VM1_MAC_STR=convertMACtoStr(TNW2_VM1_MAC)
+TNW2_VM2_IP = 0XC0A80401 #192.168.4.1
+TNW2_VM2_IP_STR = convertIP4toStr(TNW2_VM2_IP)
+TNW2_VM2_MAC=[0x00, 0x22, 0x22, 0x22, 0x22, 0x22]
+TNW2_VM2_MAC_STR=convertMACtoStr(TNW2_VM2_MAC)
+
+TNW1_GW_MAC=[0x00, 0x00, 0x00, 0x00, 0x11, 0x11]
+TNW1_GW_MAC_STR=convertMACtoStr(TNW1_GW_MAC)
+TNW1_ROUTE1 =TNW1_VM1_IP
+TNW1_ROUTE1_STR =TNW1_VM1_IP_STR
+TNW1_ROUTE1_NEXT_HOP_MAC=TNW1_VM1_MAC
+TNW1_ROUTE2 =TNW1_VM2_IP
+TNW1_ROUTE2_NEXT_HOP_MAC=TNW1_VM2_MAC
+TNW1_ROUTE2_STR =TNW1_VM2_IP_STR
+TNW1_GW_ROUTE =[TNW1_ROUTE1, TNW1_ROUTE2]
+TNW1_GW_ROUTE_STR=[TNW1_ROUTE1_STR, TNW1_ROUTE2_STR]
+TNW1_GW_ROUTE_NHP=[TNW1_ROUTE1_NEXT_HOP_MAC, TNW1_ROUTE2_NEXT_HOP_MAC]
+
+TNW2_GW_MAC=[0x00, 0x00, 0x00, 0x00, 0x22, 0x22]
+TNW2_GW_MAC_STR=convertMACtoStr(TNW2_GW_MAC)
+TNW2_ROUTE1 =TNW2_VM1_IP
+TNW2_ROUTE1_STR =TNW2_VM1_IP_STR
+TNW2_ROUTE1_NEXT_HOP_MAC=TNW2_VM1_MAC
+TNW2_ROUTE2 =TNW2_VM2_IP
+TNW2_ROUTE2_STR =TNW2_VM1_IP_STR
+TNW2_ROUTE2_NEXT_HOP_MAC=TNW2_VM2_MAC
+TNW2_GW_ROUT_STR=[TNW2_ROUTE1_STR, TNW2_ROUTE2_STR]
+
+TNW_GW_MAC=[TNW1_GW_MAC, TNW2_GW_MAC]
+TNW_GW_MAC_STR=[TNW1_GW_MAC_STR, TNW2_GW_MAC_STR]
+
+
+
+class vrouterDiffVnidRouting(base_tests.SimpleDataPlane):
+ """
+ Topology:
+ === switch inner pipeline
+ --- switch forn port physical link
+ R: router
+ NP:netowrk port
+ AP:Access port
+ LP:loopback port
+ H1(VM1/VM2) -- R ----------- NP ==== AP --- LP
+ H2 --
+
+ VM1(192.168.1.1, NW1_VNID) <--> VM2(192.168.2.1, NW1_VNID)
+ VM1(192.168.1.1, NW2_VNID) <--> VM2(192.168.2.1, NW2_VNID)
+
+ Inner operation:
+ (decap/encap vxlan header)NP==(bridge inner DMAC)==AP(VNID->VLANID)----(VLANIDx->same VRF)LP
+
+ """
+ def runTest(self):
+ delete_all_flows(self.controller)
+ delete_all_groups(self.controller)
+
+ ACCESS_PORT=config["port_map"].keys()[0]
+ NETWORK_PORT=config["port_map"].keys()[1]
+ LOOPBACK_PORT=config["port_map"].keys()[2]
+ print "access %ld, network %ld, loopback %ld"%(ACCESS_PORT, NETWORK_PORT, LOOPBACK_PORT)
+ """ add vxlan config"""
+ feature_reply=get_featureReplay(self)
+ SWITCH_INTF_MAC_STR, SWITCH_INTF_MAC=getSwitchCpuMACFromDPID(feature_reply.datapath_id)
+ #add vni
+ vni_config_xml=get_vni_config_xml(vni_id=TNW1_VNID, mcast_ipv4=None, next_hop_id=None)
+ logging.info("config VNI %lx", TNW1_VNID);
+ assert(send_edit_config(config["switch_ip"], vni_config_xml) == True)
+ vni_config_xml=get_vni_config_xml(vni_id=TNW2_VNID, mcast_ipv4=None, next_hop_id=None)
+ logging.info("config VNI %lx", TNW2_VNID);
+ assert(send_edit_config(config["switch_ip"], vni_config_xml) == True)
+ #add access port
+ vtap_conf_xml=get_vtap_lport_config_xml(dp_id=feature_reply.datapath_id,
+ lport=TNW1_ACCESS_LPORT, phy_port=ACCESS_PORT,
+ vlan=TNW1_VLAN, vnid=TNW1_VNID)
+ logging.info("config VTAP 0x%lx, PHY %d, VID %d, VNID %lx", TNW1_ACCESS_LPORT, ACCESS_PORT, TNW1_VLAN, TNW1_VNID);
+ assert(send_edit_config(config["switch_ip"], vtap_conf_xml) == True)
+ vtap_conf_xml=get_vtap_lport_config_xml(dp_id=feature_reply.datapath_id,
+ lport=TNW2_ACCESS_LPORT, phy_port=ACCESS_PORT,
+ vlan=TNW2_VLAN, vnid=TNW2_VNID)
+ logging.info("config VTAP 0x%lx, PHY %d, VID %d, VNID %lx", TNW2_ACCESS_LPORT, ACCESS_PORT, TNW1_VLAN, NW1_VNID);
+ assert(send_edit_config(config["switch_ip"], vtap_conf_xml) == True)
+ #create next hop and network port for H1
+ next_hop_conf_xml=get_next_hop_config_xml(next_hop_id=VXLAN_TNL_H_R_NHP_ID,
+ dst_mac=VXLAN_TNL_H_R_MAC_STR,
+ phy_port=NETWORK_PORT,
+ vlan=SWITCH_VLAN)
+ logging.info("config NextHop %d, DST_MAC %s, PHY %d, VLAN %d", VXLAN_TNL_H_R_NHP_ID, VXLAN_TNL_H_R_MAC_STR, NETWORK_PORT, SWITCH_VLAN);
+ assert(send_edit_config(config["switch_ip"], next_hop_conf_xml)==True)
+ #create network port
+ vtep_conf_xml=get_vtep_lport_config_xml(dp_id=feature_reply.datapath_id,
+ lport=TNW1_NEWORK_LPORT,
+ src_ip=SWITCH_IP_STR, dst_ip=VXLAN_TNL_H1_IP_STR,
+ next_hop_id=VXLAN_TNL_H_R_NHP_ID,
+ vnid=TNW1_VNID)
+ logging.info("config VTEP 0x%lx, VNID=%lu, SRC_IP %s, DST_IP %s, NEXTHOP_ID %d", TNW1_NEWORK_LPORT, TNW1_VNID, SWITCH_IP, VXLAN_TNL_H1_IP_STR, VXLAN_TNL_H_R_NHP_ID);
+ assert(send_edit_config(config["switch_ip"], vtep_conf_xml) == True)
+
+ vtep_conf_xml=get_vtep_lport_config_xml(dp_id=feature_reply.datapath_id,
+ lport=TNW2_NEWORK_LPORT,
+ src_ip=SWITCH_IP_STR, dst_ip=VXLAN_TNL_H1_IP_STR,
+ next_hop_id=VXLAN_TNL_H_R_NHP_ID,
+ vnid=TNW2_VNID)
+ logging.info("config VTEP 0x%lx, VNID=%lu, SRC_IP %s, DST_IP %s, NEXTHOP_ID %d", TNW2_NEWORK_LPORT, TNW2_VNID, SWITCH_IP, VXLAN_TNL_H1_IP_STR, VXLAN_TNL_H_R_NHP_ID);
+ assert(send_edit_config(config["switch_ip"], vtep_conf_xml) == True)
+
+
+ """add routing flow"""
+ #add port table to have vxlan ability
+ add_port_table_flow(self.controller)
+ #add l2 interface group
+ add_one_l2_interface_grouop(self.controller, NETWORK_PORT, vlan_id=SWITCH_VLAN, is_tagged=True, send_barrier=False)
+ for i in range(len(TNW_VLAN)):
+ add_one_l2_interface_grouop(self.controller, LOOPBACK_PORT, vlan_id=TNW_VLAN[i], is_tagged=True, send_barrier=False)
+
+ #add vlan flow table
+ add_one_vlan_table_flow(self.controller, NETWORK_PORT, SWITCH_VLAN, vrf=SWITCH_VRF, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
+ for i in range(len(TNW_VLAN)):
+ add_one_vlan_table_flow(self.controller, LOOPBACK_PORT, TNW_VLAN[i], vrf=TNW_VRF[i], flag=VLAN_TABLE_FLAG_ONLY_TAG)
+
+ #add vxlan bridge flow
+ add_overlay_bridge_flow(self.controller, TNW1_GW_MAC, TNW1_VNID, TNW1_ACCESS_LPORT, False, False)
+ add_overlay_bridge_flow(self.controller, TNW2_GW_MAC, TNW2_VNID, TNW2_ACCESS_LPORT, False, False)
+ add_overlay_bridge_flow(self.controller, TNW1_VM1_MAC, TNW1_VNID, TNW1_NEWORK_LPORT, False, False)
+ add_overlay_bridge_flow(self.controller, TNW1_VM2_MAC, TNW1_VNID, TNW1_NEWORK_LPORT, False, False)
+ add_overlay_bridge_flow(self.controller, TNW2_VM1_MAC, TNW2_VNID, TNW2_NEWORK_LPORT, False, False)
+ add_overlay_bridge_flow(self.controller, TNW2_VM2_MAC, TNW2_VNID, TNW2_NEWORK_LPORT, False, False)
+
+ #add termination flow
+ add_termination_flow(self.controller, NETWORK_PORT, 0x0800, SWITCH_INTF_MAC, SWITCH_VLAN)
+ for i in range(len(TNW_VLAN)):
+ add_termination_flow(self.controller, LOOPBACK_PORT, 0x0800, TNW_GW_MAC[i], TNW_VLAN[i])
+
+ """
+ Add Network Route, TNW1
+ 192.168.1.1
+ 192.168.2.1
+ """
+ l3_msg=add_l3_unicast_group(self.controller, LOOPBACK_PORT, vlanid=TNW1_VLAN, id=0x1001, src_mac=TNW1_GW_MAC, dst_mac=TNW1_ROUTE1_NEXT_HOP_MAC)
+ add_unicast_routing_flow(self.controller, 0x0800, TNW1_ROUTE1, 0, l3_msg.group_id, TNW1_VRF)
+ l3_msg=add_l3_unicast_group(self.controller, LOOPBACK_PORT, vlanid=TNW1_VLAN, id=0x1002, src_mac=TNW1_GW_MAC, dst_mac=TNW1_ROUTE2_NEXT_HOP_MAC)
+ add_unicast_routing_flow(self.controller, 0x0800, TNW1_ROUTE2, 0, l3_msg.group_id, TNW1_VRF)
+ """
+ Add Network Route, TNW2
+ 192.168.1.1
+ 192.168.2.1
+ """
+ l3_msg=add_l3_unicast_group(self.controller, LOOPBACK_PORT, vlanid=TNW2_VLAN, id=0x2001, src_mac=TNW1_GW_MAC, dst_mac=TNW2_ROUTE1_NEXT_HOP_MAC)
+ add_unicast_routing_flow(self.controller, 0x0800, TNW2_ROUTE1, 0, l3_msg.group_id, TNW2_VRF)
+ l3_msg=add_l3_unicast_group(self.controller, LOOPBACK_PORT, vlanid=TNW2_VLAN, id=0x2002, src_mac=TNW2_GW_MAC, dst_mac=TNW2_ROUTE2_NEXT_HOP_MAC)
+ add_unicast_routing_flow(self.controller, 0x0800, TNW2_ROUTE2, 0, l3_msg.group_id, TNW2_VRF)
+
+
+ """
+ Send paket to verify, TNW1
+ """
+ #tx packet on network lport
+ inner_pkt = simple_udp_packet(pktlen=100
+ , eth_src = TNW1_VM1_MAC_STR
+ , eth_dst=TNW1_GW_MAC_STR
+ , ip_dst =TNW1_VM2_IP_STR
+ , ip_src =TNW1_VM1_IP_STR
+ , ip_ttl =64)
+ vxlan_pkt = simple_vxlan_packet(eth_dst=SWITCH_INTF_MAC_STR
+ ,eth_src=VXLAN_TNL_H_R_MAC_STR
+ ,vnid=TNW1_VNID
+ ,ip_dst= SWITCH_IP_STR
+ ,ip_src=VXLAN_TNL_H1_IP_STR
+ ,inner_payload=inner_pkt)
+ self.dataplane.send(NETWORK_PORT, str(vxlan_pkt))
+ #verify rx on access port
+ inner_pkt = simple_udp_packet(pktlen=104
+ , eth_src= TNW1_VM1_MAC_STR
+ , eth_dst=TNW1_GW_MAC_STR
+ , dl_vlan_enable=True
+ , vlan_vid=TNW1_VLAN
+ , ip_dst =TNW1_VM2_IP_STR
+ , ip_src =TNW1_VM1_IP_STR
+ , ip_ttl =64)
+ verify_packet(self, str(inner_pkt), ACCESS_PORT)
+ verify_no_other_packets(self)
+
+ #tx on loopback port
+ self.dataplane.send(LOOPBACK_PORT, str(inner_pkt))
+ #verify rx on loopback port
+ inner_pkt = simple_udp_packet(pktlen=104
+ , eth_src=TNW1_GW_MAC_STR
+ , eth_dst=TNW1_VM2_MAC_STR
+ , dl_vlan_enable=True
+ , vlan_vid=TNW1_VLAN
+ , ip_dst =TNW1_VM2_IP_STR
+ , ip_src =TNW1_VM1_IP_STR
+ , ip_ttl =63)
+ verify_packet(self, str(inner_pkt), LOOPBACK_PORT)
+ verify_no_other_packets(self)
+ #tx on access port
+ self.dataplane.send(ACCESS_PORT, str(inner_pkt))
+ #verify rx on network port
+ inner_pkt = simple_udp_packet(pktlen=100
+ , eth_src=TNW1_GW_MAC_STR
+ , eth_dst=TNW1_VM2_MAC_STR
+ , ip_dst =TNW1_VM2_IP_STR
+ , ip_src =TNW1_VM1_IP_STR
+ , ip_ttl =63)
+ vxlan_pkt = simple_vxlan_packet(eth_src=SWITCH_INTF_MAC_STR
+ ,eth_dst=VXLAN_TNL_H_R_MAC_STR
+ ,vnid=TNW1_VNID
+ ,ip_dst=VXLAN_TNL_H1_IP_STR
+ ,ip_src=SWITCH_IP_STR
+ ,inner_payload=inner_pkt)
+ verify_packet(self, inner_pkt, NETWORK_PORT)
+ verify_no_other_packets(self)
+
+
+ """
+ Send paket to verify, NW2
+ """
+ #tx packet on network lport
+ inner_pkt = simple_udp_packet(pktlen=100
+ , eth_src = TNW2_VM1_MAC_STR
+ , eth_dst=TNW2_GW_MAC_STR
+ , ip_dst =TNW2_VM2_IP_STR
+ , ip_src =TNW2_VM1_IP_STR
+ , ip_ttl =64)
+ vxlan_pkt = simple_vxlan_packet(eth_dst=SWITCH_INTF_MAC_STR
+ ,eth_src=VXLAN_TNL_H_R_MAC_STR
+ ,vnid=TNW2_VNID
+ ,ip_dst= SWITCH_IP_STR
+ ,ip_src=VXLAN_TNL_H1_IP_STR
+ ,inner_payload=inner_pkt)
+ self.dataplane.send(NETWORK_PORT, str(vxlan_pkt))
+ #verify rx on access port
+ inner_pkt = simple_udp_packet(pktlen=104
+ , eth_src= TNW2_VM1_MAC_STR
+ , eth_dst=TNW2_GW_MAC_STR
+ , dl_vlan_enable=True
+ , vlan_vid=TNW2_VLAN
+ , ip_dst =TNW2_VM2_IP_STR
+ , ip_src =TNW2_VM1_IP_STR
+ , ip_ttl =64)
+ verify_packet(self, str(inner_pkt), ACCESS_PORT)
+ verify_no_other_packets(self)
+
+ #tx on loopback port
+ self.dataplane.send(LOOPBACK_PORT, str(inner_pkt))
+ #verify rx on loopback port
+ inner_pkt = simple_udp_packet(pktlen=104
+ , eth_src=TNW2_GW_MAC_STR
+ , eth_dst=TNW2_VM2_MAC_STR
+ , dl_vlan_enable=True
+ , vlan_vid=TNW2_VLAN
+ , ip_dst =TNW2_VM2_IP_STR
+ , ip_src =TNW2_VM1_IP_STR
+ , ip_ttl =63)
+ verify_packet(self, str(inner_pkt), LOOPBACK_PORT)
+ verify_no_other_packets(self)
+ #tx on access port
+ self.dataplane.send(ACCESS_PORT, str(inner_pkt))
+ #verify rx on network port
+ inner_pkt = simple_udp_packet(pktlen=100
+ , eth_src=TNW2_GW_MAC_STR
+ , eth_dst=TNW2_VM2_MAC_STR
+ , ip_dst =TNW2_VM2_IP_STR
+ , ip_src =TNW2_VM1_IP_STR
+ , ip_ttl =63)
+ vxlan_pkt = simple_vxlan_packet(eth_src=SWITCH_INTF_MAC_STR
+ ,eth_dst=VXLAN_TNL_H_R_MAC_STR
+ ,vnid=TNW2_VNID
+ ,ip_dst=VXLAN_TNL_H1_IP_STR
+ ,ip_src=SWITCH_IP_STR
+ ,inner_payload=inner_pkt)
+ verify_packet(self, inner_pkt, NETWORK_PORT)
+ verify_no_other_packets(self)
+
+
+ """clear all flow/group and configuration
+ """
+ delete_all_flows(self.controller)
+ delete_all_groups(self.controller)
+ """ del vxlan config"""
+ #delete access port
+ vtap_conf_xml=get_vtap_lport_config_xml(dp_id=feature_reply.datapath_id,
+ lport=TNW1_ACCESS_LPORT, phy_port=ACCESS_PORT,
+ vlan=TNW1_VLAN, vnid=TNW1_VNID, operation="delete")
+ logging.info("delete config VTAP 0x%lx, PHY %d, VID %d, VNID %lx", TNW1_ACCESS_LPORT, ACCESS_PORT, TNW1_VLAN, TNW1_VNID);
+ assert(send_edit_config(config["switch_ip"], vtap_conf_xml) == True)
+ vtap_conf_xml=get_vtap_lport_config_xml(dp_id=feature_reply.datapath_id,
+ lport=TNW2_ACCESS_LPORT, phy_port=ACCESS_PORT,
+ vlan=TNW2_VLAN, vnid=TNW2_VNID, operation="delete")
+ logging.info("delete config VTAP 0x%lx, PHY %d, VID %d, VNID %lx", TNW2_ACCESS_LPORT, ACCESS_PORT, TNW1_VLAN, TNW1_VNID);
+ assert(send_edit_config(config["switch_ip"], vtap_conf_xml) == True)
+ #delete network port
+ vtep_conf_xml=get_vtep_lport_config_xml(dp_id=feature_reply.datapath_id,
+ lport=TNW1_NEWORK_LPORT,
+ src_ip=SWITCH_IP_STR, dst_ip=VXLAN_TNL_H1_IP_STR,
+ next_hop_id=VXLAN_TNL_H_R_NHP_ID,
+ vnid=TNW1_VNID, operation="delete")
+ logging.info("delete config VTEP 0x%lx, VNID=%lu, SRC_IP %s, DST_IP %s, NEXTHOP_ID %d", TNW1_NEWORK_LPORT, TNW1_VNID, SWITCH_IP, VXLAN_TNL_H1_IP_STR, VXLAN_TNL_H_R_NHP_ID);
+ assert(send_edit_config(config["switch_ip"], vtep_conf_xml) == True)
+
+ vtep_conf_xml=get_vtep_lport_config_xml(dp_id=feature_reply.datapath_id,
+ lport=TNW2_NEWORK_LPORT,
+ src_ip=SWITCH_IP_STR, dst_ip=VXLAN_TNL_H1_IP_STR,
+ next_hop_id=VXLAN_TNL_H_R_NHP_ID,
+ vnid=TNW2_VNID, operation="delete")
+ logging.info("delete config VTEP 0x%lx, VNID=%lu, SRC_IP %s, DST_IP %s, NEXTHOP_ID %d", TNW2_NEWORK_LPORT, TNW2_VNID, SWITCH_IP, VXLAN_TNL_H1_IP_STR, VXLAN_TNL_H_R_NHP_ID);
+ assert(send_edit_config(config["switch_ip"], vtep_conf_xml) == True)
+ #delete next hop and network port for H1
+ next_hop_conf_xml=get_next_hop_config_xml(next_hop_id=VXLAN_TNL_H_R_NHP_ID,
+ dst_mac=VXLAN_TNL_H_R_MAC_STR,
+ phy_port=NETWORK_PORT,
+ vlan=SWITCH_VLAN, operation="delete")
+ logging.info("delete config NextHop %d, DST_MAC %s, PHY %d, VLAN %d", VXLAN_TNL_H_R_NHP_ID, VXLAN_TNL_H_R_MAC_STR, NETWORK_PORT, SWITCH_VLAN);
+ assert(send_edit_config(config["switch_ip"], next_hop_conf_xml)==True)
+ #del vni
+ vni_config_xml=get_vni_config_xml(vni_id=TNW1_VNID, mcast_ipv4=None, next_hop_id=None, operation="delete")
+ logging.info("delete config VNI %lx", TNW1_VNID);
+ assert(send_edit_config(config["switch_ip"], vni_config_xml) == True)
+ vni_config_xml=get_vni_config_xml(vni_id=TNW2_VNID, mcast_ipv4=None, next_hop_id=None, operation="delete")
+ logging.info("delete config VNI %lx", TNW2_VNID);
+ assert(send_edit_config(config["switch_ip"], vni_config_xml) == True)
+
+class vrouterNetconfSetUnset(base_tests.SimpleDataPlane):
+ def runTest(self):
+ ACCESS_PORT=config["port_map"].keys()[0]
+ NETWORK_PORT=config["port_map"].keys()[1]
+ LOOPBACK_PORT=config["port_map"].keys()[2]
+ print "access %ld, network %ld, loopback %ld"%(ACCESS_PORT, NETWORK_PORT, LOOPBACK_PORT)
+ """ add vxlan config"""
+ feature_reply=get_featureReplay(self)
+ SWITCH_INTF_MAC_STR, SWITCH_INTF_MAC=getSwitchCpuMACFromDPID(feature_reply.datapath_id)
+ #add vni
+ vni_config_xml=get_vni_config_xml(vni_id=NW1_VNID, mcast_ipv4=None, next_hop_id=None)
+ logging.info("config VNI %lx", NW1_VNID);
+ assert(send_edit_config(config["switch_ip"], vni_config_xml) == True)
+ vni_config_xml=get_vni_config_xml(vni_id=NW2_VNID, mcast_ipv4=None, next_hop_id=None)
+ logging.info("config VNI %lx", NW2_VNID);
+ assert(send_edit_config(config["switch_ip"], vni_config_xml) == True)
+ #add access port
+ vtap_conf_xml=get_vtap_lport_config_xml(dp_id=feature_reply.datapath_id,
+ lport=NW1_ACCESS_LPORT, phy_port=ACCESS_PORT,
+ vlan=NW1_VLAN, vnid=NW1_VNID)
+ logging.info("config VTAP 0x%lx, PHY %d, VID %d, VNID %lx", NW1_ACCESS_LPORT, ACCESS_PORT, NW1_VLAN, NW1_VNID);
+ assert(send_edit_config(config["switch_ip"], vtap_conf_xml) == True)
+ vtap_conf_xml=get_vtap_lport_config_xml(dp_id=feature_reply.datapath_id,
+ lport=NW2_ACCESS_LPORT, phy_port=ACCESS_PORT,
+ vlan=NW2_VLAN, vnid=NW2_VNID)
+ logging.info("config VTAP 0x%lx, PHY %d, VID %d, VNID %lx", NW2_ACCESS_LPORT, ACCESS_PORT, NW1_VLAN, NW1_VNID);
+ assert(send_edit_config(config["switch_ip"], vtap_conf_xml) == True)
+ #create next hop and network port for H1
+ next_hop_conf_xml=get_next_hop_config_xml(next_hop_id=VXLAN_TNL_H_R_NHP_ID,
+ dst_mac=VXLAN_TNL_H_R_MAC_STR,
+ phy_port=NETWORK_PORT,
+ vlan=SWITCH_VLAN)
+ logging.info("config NextHop %d, DST_MAC %s, PHY %d, VLAN %d", VXLAN_TNL_H_R_NHP_ID, VXLAN_TNL_H_R_MAC_STR, NETWORK_PORT, SWITCH_VLAN);
+ assert(send_edit_config(config["switch_ip"], next_hop_conf_xml)==True)
+ #create network port
+ vtep_conf_xml=get_vtep_lport_config_xml(dp_id=feature_reply.datapath_id,
+ lport=NW1_NEWORK_LPORT,
+ src_ip=SWITCH_IP_STR, dst_ip=VXLAN_TNL_H1_IP_STR,
+ next_hop_id=VXLAN_TNL_H_R_NHP_ID,
+ vnid=NW1_VNID)
+ logging.info("config VTEP 0x%lx, VNID=%lu, SRC_IP %s, DST_IP %s, NEXTHOP_ID %d", NW1_NEWORK_LPORT, NW1_VNID, SWITCH_IP, VXLAN_TNL_H1_IP_STR, VXLAN_TNL_H_R_NHP_ID);
+ assert(send_edit_config(config["switch_ip"], vtep_conf_xml) == True)
+
+ vtep_conf_xml=get_vtep_lport_config_xml(dp_id=feature_reply.datapath_id,
+ lport=NW2_NEWORK_LPORT,
+ src_ip=SWITCH_IP_STR, dst_ip=VXLAN_TNL_H1_IP_STR,
+ next_hop_id=VXLAN_TNL_H_R_NHP_ID,
+ vnid=NW2_VNID)
+ logging.info("config VTEP 0x%lx, VNID=%lu, SRC_IP %s, DST_IP %s, NEXTHOP_ID %d", NW2_NEWORK_LPORT, NW2_VNID, SWITCH_IP, VXLAN_TNL_H1_IP_STR, VXLAN_TNL_H_R_NHP_ID);
+ assert(send_edit_config(config["switch_ip"], vtep_conf_xml) == True)
+
+ """clear all flow/group and configuration
+ """
+ """ del vxlan config"""
+ #delete access port
+ vtap_conf_xml=get_vtap_lport_config_xml(dp_id=feature_reply.datapath_id,
+ lport=NW1_ACCESS_LPORT, phy_port=ACCESS_PORT,
+ vlan=NW1_VLAN, vnid=NW1_VNID, operation="delete")
+ logging.info("delete config VTAP 0x%lx, PHY %d, VID %d, VNID %lx", NW1_ACCESS_LPORT, ACCESS_PORT, NW1_VLAN, NW1_VNID);
+ assert(send_edit_config(config["switch_ip"], vtap_conf_xml) == True)
+ vtap_conf_xml=get_vtap_lport_config_xml(dp_id=feature_reply.datapath_id,
+ lport=NW2_ACCESS_LPORT, phy_port=ACCESS_PORT,
+ vlan=NW2_VLAN, vnid=NW2_VNID, operation="delete")
+ logging.info("delete config VTAP 0x%lx, PHY %d, VID %d, VNID %lx", NW2_ACCESS_LPORT, ACCESS_PORT, NW1_VLAN, NW1_VNID);
+ assert(send_edit_config(config["switch_ip"], vtap_conf_xml) == True)
+ #delete network port
+ vtep_conf_xml=get_vtep_lport_config_xml(dp_id=feature_reply.datapath_id,
+ lport=NW1_NEWORK_LPORT,
+ src_ip=SWITCH_IP_STR, dst_ip=VXLAN_TNL_H1_IP_STR,
+ next_hop_id=VXLAN_TNL_H_R_NHP_ID,
+ vnid=NW1_VNID, operation="delete")
+ logging.info("delete config VTEP 0x%lx, VNID=%lu, SRC_IP %s, DST_IP %s, NEXTHOP_ID %d", NW1_NEWORK_LPORT, NW1_VNID, SWITCH_IP, VXLAN_TNL_H1_IP_STR, VXLAN_TNL_H_R_NHP_ID);
+ assert(send_edit_config(config["switch_ip"], vtep_conf_xml) == True)
+
+ vtep_conf_xml=get_vtep_lport_config_xml(dp_id=feature_reply.datapath_id,
+ lport=NW2_NEWORK_LPORT,
+ src_ip=SWITCH_IP_STR, dst_ip=VXLAN_TNL_H1_IP_STR,
+ next_hop_id=VXLAN_TNL_H_R_NHP_ID,
+ vnid=NW2_VNID, operation="delete")
+ logging.info("delete config VTEP 0x%lx, VNID=%lu, SRC_IP %s, DST_IP %s, NEXTHOP_ID %d", NW2_NEWORK_LPORT, NW2_VNID, SWITCH_IP, VXLAN_TNL_H1_IP_STR, VXLAN_TNL_H_R_NHP_ID);
+ assert(send_edit_config(config["switch_ip"], vtep_conf_xml) == True)
+ #delete next hop and network port for H1
+ next_hop_conf_xml=get_next_hop_config_xml(next_hop_id=VXLAN_TNL_H_R_NHP_ID,
+ dst_mac=VXLAN_TNL_H_R_MAC_STR,
+ phy_port=NETWORK_PORT,
+ vlan=SWITCH_VLAN, operation="delete")
+ logging.info("delete config NextHop %d, DST_MAC %s, PHY %d, VLAN %d", VXLAN_TNL_H_R_NHP_ID, VXLAN_TNL_H_R_MAC_STR, NETWORK_PORT, SWITCH_VLAN);
+ assert(send_edit_config(config["switch_ip"], next_hop_conf_xml)==True)
+ #del vni
+ vni_config_xml=get_vni_config_xml(vni_id=NW1_VNID, mcast_ipv4=None, next_hop_id=None, operation="delete")
+ logging.info("delete config VNI %lx", NW1_VNID);
+ assert(send_edit_config(config["switch_ip"], vni_config_xml) == True)
+ vni_config_xml=get_vni_config_xml(vni_id=NW2_VNID, mcast_ipv4=None, next_hop_id=None, operation="delete")
+ logging.info("delete config VNI %lx", NW2_VNID);
+ assert(send_edit_config(config["switch_ip"], vni_config_xml) == True)