Matteo Scandolo | a229eca | 2017-08-08 13:05:28 -0700 | [diff] [blame] | 1 | |
| 2 | # Copyright 2017-present Open Networking Foundation |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | |
macauley | 1c0b6c4 | 2015-08-06 18:13:56 +0800 | [diff] [blame] | 17 | """ |
| 18 | This case test VM routing on same VNID |
| 19 | """ |
| 20 | |
| 21 | import logging |
| 22 | |
| 23 | from oftest import config |
| 24 | import oftest.base_tests as base_tests |
| 25 | import ofp |
| 26 | from oftest.testutils import * |
| 27 | from accton_util import * |
| 28 | |
| 29 | NW1_ACCESS_LPORT=0x10001 |
| 30 | NW2_ACCESS_LPORT=0x10002 |
| 31 | NW1_NEWORK_LPORT=0x10003 |
macauley | 97a0f63 | 2015-08-07 17:03:39 +0800 | [diff] [blame] | 32 | NW2_NEWORK_LPORT=0x10003 |
macauley | 1c0b6c4 | 2015-08-06 18:13:56 +0800 | [diff] [blame] | 33 | |
| 34 | NW1_VRF=1 |
| 35 | NW2_VRF=2 |
| 36 | NW_VRF=[NW1_VRF, NW2_VRF] |
| 37 | SWITCH_VRF=0 |
| 38 | assert(NW1_VRF!=SWITCH_VRF) |
| 39 | assert(NW2_VRF!=SWITCH_VRF) |
| 40 | NW1_VNID=1 |
| 41 | NW2_VNID=2 |
| 42 | NW_VNID=[NW1_VNID, NW2_VNID] |
| 43 | |
| 44 | |
| 45 | NW1_VLAN = 2 |
| 46 | NW2_VLAN = 3 |
| 47 | NW_VLAN=[NW1_VLAN, NW2_VLAN] |
| 48 | SWITCH_VLAN=1 |
| 49 | |
| 50 | #SWITCH_INTF_MAC = from feature.replay, because each switch is not the same, |
| 51 | # current we just can use switch CPU MAC, due to tunnel terminator |
| 52 | # have no way to set mac |
| 53 | #SWITCH_INTF_MAC_STR |
| 54 | SWITCH_IP=0XC0A80101 #192.168.1.1 |
| 55 | SWITCH_IP_STR=convertIP4toStr(SWITCH_IP) |
| 56 | #H1 for NW1, H2 for NW2 |
| 57 | #remember for chip limitaion, it can't have nexthop |
| 58 | #has same vid, port but diff dst_mac |
| 59 | VXLAN_TNL_H1_IP=0XC0A80202#192.168.2.2 |
| 60 | VXLAN_TNL_H1_IP_STR=convertIP4toStr(VXLAN_TNL_H1_IP) |
| 61 | VXLAN_TNL_H1_MAC=[0x00, 0x31, 0x31, 0x31, 0x31, 0x31] #like router MAC |
| 62 | VXLAN_TNL_H1_MAC_STR=convertMACtoStr(VXLAN_TNL_H1_MAC) |
| 63 | VXLAN_TNL_H2_IP=0XC0A80303#192.168.3.3 |
| 64 | VXLAN_TNL_H2_IP_STR=convertIP4toStr(VXLAN_TNL_H2_IP) |
| 65 | VXLAN_TNL_H2_MAC=[0x00, 0x31, 0x31, 0x31, 0x31, 0x31] #like router MAC |
| 66 | VXLAN_TNL_H2_MAC_STR=convertMACtoStr(VXLAN_TNL_H2_MAC) |
| 67 | VXLAN_TNL_H_R_MAC=[0x00, 0x31, 0x31, 0x31, 0x31, 0x31] |
| 68 | VXLAN_TNL_H_R_MAC_STR=convertMACtoStr(VXLAN_TNL_H_R_MAC) |
| 69 | VXLAN_TNL_H_R_NHP_ID=1 |
| 70 | |
| 71 | NW1_VM1_IP = 0XC0A80101 |
| 72 | NW1_VM1_IP_STR = convertIP4toStr(NW1_VM1_IP) |
| 73 | NW1_VM1_MAC=[0x00, 0x11, 0x11, 0x11, 0x11, 0x11] |
| 74 | NW1_VM1_MAC_STR=convertMACtoStr(NW1_VM1_MAC) |
| 75 | NW1_VM2_IP = 0XC0A80201 |
| 76 | NW1_VM2_IP_STR = convertIP4toStr(NW1_VM2_IP) |
| 77 | NW1_VM2_MAC=[0x00, 0x12, 0x12, 0x12, 0x12, 0x12] |
| 78 | NW1_VM2_MAC_STR=convertMACtoStr(NW1_VM2_MAC) |
| 79 | NW2_VM1_IP = 0XC0A80101 |
| 80 | NW2_VM1_IP_STR = convertIP4toStr(NW2_VM1_IP) |
| 81 | NW2_VM1_MAC=[0x00, 0x21, 0x21, 0x21, 0x21, 0x21] |
| 82 | NW2_VM1_MAC_STR=convertMACtoStr(NW2_VM1_MAC) |
| 83 | NW2_VM2_IP = 0XC0A80201 |
| 84 | NW2_VM2_IP_STR = convertIP4toStr(NW2_VM2_IP) |
| 85 | NW2_VM2_MAC=[0x00, 0x22, 0x22, 0x22, 0x22, 0x22] |
| 86 | NW2_VM2_MAC_STR=convertMACtoStr(NW2_VM2_MAC) |
| 87 | |
| 88 | NW1_GW_MAC=[0x00, 0x00, 0x00, 0x00, 0x11, 0x11] |
| 89 | NW1_GW_MAC_STR=convertMACtoStr(NW1_GW_MAC) |
| 90 | NW1_ROUTE1 =NW1_VM1_IP |
| 91 | NW1_ROUTE1_STR =NW1_VM1_IP_STR |
| 92 | NW1_ROUTE1_NEXT_HOP_MAC=NW1_VM1_MAC |
| 93 | NW1_ROUTE2 =NW1_VM2_IP |
| 94 | NW1_ROUTE2_NEXT_HOP_MAC=NW1_VM2_MAC |
| 95 | NW1_ROUTE2_STR =NW1_VM2_IP_STR |
| 96 | NW1_GW_ROUTE =[NW1_ROUTE1, NW1_ROUTE2] |
| 97 | NW1_GW_ROUTE_STR=[NW1_ROUTE1_STR, NW1_ROUTE2_STR] |
| 98 | NW1_GW_ROUTE_NHP=[NW1_ROUTE1_NEXT_HOP_MAC, NW1_ROUTE2_NEXT_HOP_MAC] |
| 99 | |
| 100 | NW2_GW_MAC=[0x00, 0x00, 0x00, 0x00, 0x22, 0x22] |
| 101 | NW2_GW_MAC_STR=convertMACtoStr(NW2_GW_MAC) |
| 102 | NW2_ROUTE1 =NW2_VM1_IP |
| 103 | NW2_ROUTE1_STR =NW2_VM1_IP_STR |
| 104 | NW2_ROUTE1_NEXT_HOP_MAC=NW2_VM1_MAC |
| 105 | NW2_ROUTE2 =NW2_VM2_IP |
| 106 | NW2_ROUTE2_STR =NW2_VM1_IP_STR |
| 107 | NW2_ROUTE2_NEXT_HOP_MAC=NW2_VM2_MAC |
| 108 | NW2_GW_ROUT_STR=[NW2_ROUTE1_STR, NW2_ROUTE2_STR] |
| 109 | |
| 110 | NW_GW_MAC=[NW1_GW_MAC, NW2_GW_MAC] |
| 111 | NW_GW_MAC_STR=[NW1_GW_MAC_STR, NW2_GW_MAC_STR] |
| 112 | |
| 113 | |
| 114 | #make sure array has same length |
| 115 | assert(len(NW_GW_MAC) == len(NW_GW_MAC_STR)) |
| 116 | assert(len(NW_GW_MAC) == len(NW_VLAN)) |
| 117 | |
| 118 | class vrouterSameVNIRouting(base_tests.SimpleDataPlane): |
| 119 | """ |
| 120 | Topology: |
| 121 | === switch inner pipeline |
| 122 | --- switch forn port physical link |
| 123 | R: router |
| 124 | NP:netowrk port |
| 125 | AP:Access port |
| 126 | LP:loopback port |
| 127 | H1(VM1/VM2) -- R ----------- NP ==== AP --- LP |
| 128 | H2 -- |
| 129 | |
| 130 | VM1(192.168.1.1, NW1_VNID) <--> VM2(192.168.2.1, NW1_VNID) |
| 131 | VM1(192.168.1.1, NW2_VNID) <--> VM2(192.168.2.1, NW2_VNID) |
| 132 | |
| 133 | Inner operation: |
| 134 | (decap/encap vxlan header)NP==(bridge inner DMAC)==AP(VNID->VLANID)----(VLANID->VRF)LP |
| 135 | |
| 136 | |
| 137 | |
| 138 | """ |
| 139 | def runTest(self): |
| 140 | delete_all_flows(self.controller) |
| 141 | delete_all_groups(self.controller) |
| 142 | |
| 143 | ACCESS_PORT=config["port_map"].keys()[0] |
| 144 | NETWORK_PORT=config["port_map"].keys()[1] |
| 145 | LOOPBACK_PORT=config["port_map"].keys()[2] |
| 146 | print "access %ld, network %ld, loopback %ld"%(ACCESS_PORT, NETWORK_PORT, LOOPBACK_PORT) |
| 147 | """ add vxlan config""" |
| 148 | feature_reply=get_featureReplay(self) |
| 149 | SWITCH_INTF_MAC_STR, SWITCH_INTF_MAC=getSwitchCpuMACFromDPID(feature_reply.datapath_id) |
| 150 | #add vni |
| 151 | vni_config_xml=get_vni_config_xml(vni_id=NW1_VNID, mcast_ipv4=None, next_hop_id=None) |
| 152 | logging.info("config VNI %lx", NW1_VNID); |
| 153 | assert(send_edit_config(config["switch_ip"], vni_config_xml) == True) |
| 154 | vni_config_xml=get_vni_config_xml(vni_id=NW2_VNID, mcast_ipv4=None, next_hop_id=None) |
| 155 | logging.info("config VNI %lx", NW2_VNID); |
| 156 | assert(send_edit_config(config["switch_ip"], vni_config_xml) == True) |
| 157 | #add access port |
| 158 | vtap_conf_xml=get_vtap_lport_config_xml(dp_id=feature_reply.datapath_id, |
| 159 | lport=NW1_ACCESS_LPORT, phy_port=ACCESS_PORT, |
| 160 | vlan=NW1_VLAN, vnid=NW1_VNID) |
| 161 | logging.info("config VTAP 0x%lx, PHY %d, VID %d, VNID %lx", NW1_ACCESS_LPORT, ACCESS_PORT, NW1_VLAN, NW1_VNID); |
| 162 | assert(send_edit_config(config["switch_ip"], vtap_conf_xml) == True) |
| 163 | vtap_conf_xml=get_vtap_lport_config_xml(dp_id=feature_reply.datapath_id, |
| 164 | lport=NW2_ACCESS_LPORT, phy_port=ACCESS_PORT, |
| 165 | vlan=NW2_VLAN, vnid=NW2_VNID) |
| 166 | logging.info("config VTAP 0x%lx, PHY %d, VID %d, VNID %lx", NW2_ACCESS_LPORT, ACCESS_PORT, NW1_VLAN, NW1_VNID); |
| 167 | assert(send_edit_config(config["switch_ip"], vtap_conf_xml) == True) |
| 168 | #create next hop and network port for H1 |
| 169 | next_hop_conf_xml=get_next_hop_config_xml(next_hop_id=VXLAN_TNL_H_R_NHP_ID, |
| 170 | dst_mac=VXLAN_TNL_H_R_MAC_STR, |
| 171 | phy_port=NETWORK_PORT, |
| 172 | vlan=SWITCH_VLAN) |
| 173 | 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); |
| 174 | assert(send_edit_config(config["switch_ip"], next_hop_conf_xml)==True) |
| 175 | #create network port |
| 176 | vtep_conf_xml=get_vtep_lport_config_xml(dp_id=feature_reply.datapath_id, |
| 177 | lport=NW1_NEWORK_LPORT, |
| 178 | src_ip=SWITCH_IP_STR, dst_ip=VXLAN_TNL_H1_IP_STR, |
| 179 | next_hop_id=VXLAN_TNL_H_R_NHP_ID, |
| 180 | vnid=NW1_VNID) |
| 181 | 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); |
| 182 | assert(send_edit_config(config["switch_ip"], vtep_conf_xml) == True) |
| 183 | |
| 184 | vtep_conf_xml=get_vtep_lport_config_xml(dp_id=feature_reply.datapath_id, |
| 185 | lport=NW2_NEWORK_LPORT, |
| 186 | src_ip=SWITCH_IP_STR, dst_ip=VXLAN_TNL_H1_IP_STR, |
| 187 | next_hop_id=VXLAN_TNL_H_R_NHP_ID, |
| 188 | vnid=NW2_VNID) |
| 189 | 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); |
| 190 | assert(send_edit_config(config["switch_ip"], vtep_conf_xml) == True) |
| 191 | |
macauley | 1c0b6c4 | 2015-08-06 18:13:56 +0800 | [diff] [blame] | 192 | """add routing flow""" |
| 193 | #add port table to have vxlan ability |
| 194 | add_port_table_flow(self.controller) |
| 195 | #add l2 interface group |
castroflavio | dd17147 | 2015-12-08 13:55:58 -0500 | [diff] [blame] | 196 | add_one_l2_interface_group(self.controller, NETWORK_PORT, vlan_id=SWITCH_VLAN, is_tagged=True, send_barrier=False) |
macauley | 1c0b6c4 | 2015-08-06 18:13:56 +0800 | [diff] [blame] | 197 | for i in range(len(NW_VLAN)): |
castroflavio | dd17147 | 2015-12-08 13:55:58 -0500 | [diff] [blame] | 198 | add_one_l2_interface_group(self.controller, LOOPBACK_PORT, vlan_id=NW_VLAN[i], is_tagged=True, send_barrier=False) |
macauley | 1c0b6c4 | 2015-08-06 18:13:56 +0800 | [diff] [blame] | 199 | |
| 200 | #add vlan flow table |
| 201 | add_one_vlan_table_flow(self.controller, NETWORK_PORT, SWITCH_VLAN, vrf=SWITCH_VRF, flag=VLAN_TABLE_FLAG_ONLY_BOTH) |
| 202 | |
| 203 | for i in range(len(NW_VLAN)): |
| 204 | add_one_vlan_table_flow(self.controller, LOOPBACK_PORT, NW_VLAN[i], vrf=NW_VRF[i], flag=VLAN_TABLE_FLAG_ONLY_TAG) |
| 205 | #add vxlan bridge flow |
| 206 | add_overlay_bridge_flow(self.controller, NW1_GW_MAC, NW1_VNID, NW1_ACCESS_LPORT, False, False) |
| 207 | add_overlay_bridge_flow(self.controller, NW2_GW_MAC, NW2_VNID, NW2_ACCESS_LPORT, False, False) |
| 208 | add_overlay_bridge_flow(self.controller, NW1_VM1_MAC, NW1_VNID, NW1_NEWORK_LPORT, False, False) |
| 209 | add_overlay_bridge_flow(self.controller, NW1_VM2_MAC, NW1_VNID, NW1_NEWORK_LPORT, False, False) |
| 210 | add_overlay_bridge_flow(self.controller, NW2_VM1_MAC, NW2_VNID, NW2_NEWORK_LPORT, False, False) |
| 211 | add_overlay_bridge_flow(self.controller, NW2_VM2_MAC, NW2_VNID, NW2_NEWORK_LPORT, False, False) |
| 212 | |
| 213 | #add termination flow |
| 214 | add_termination_flow(self.controller, NETWORK_PORT, 0x0800, SWITCH_INTF_MAC, SWITCH_VLAN) |
| 215 | for i in range(len(NW_VLAN)): |
| 216 | add_termination_flow(self.controller, LOOPBACK_PORT, 0x0800, NW_GW_MAC[i], NW_VLAN[i]) |
| 217 | |
| 218 | """ |
| 219 | Add Network Route, NW1 |
| 220 | 192.168.1.1 |
| 221 | 192.168.2.1 |
| 222 | """ |
| 223 | 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) |
| 224 | add_unicast_routing_flow(self.controller, 0x0800, NW1_ROUTE1, 0, l3_msg.group_id, NW1_VRF) |
| 225 | 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) |
| 226 | add_unicast_routing_flow(self.controller, 0x0800, NW1_ROUTE2, 0, l3_msg.group_id, NW1_VRF) |
| 227 | """ |
| 228 | Add Network Route, NW2 |
| 229 | 192.168.1.1 |
| 230 | 192.168.2.1 |
| 231 | """ |
| 232 | 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) |
| 233 | add_unicast_routing_flow(self.controller, 0x0800, NW2_ROUTE1, 0, l3_msg.group_id, NW2_VRF) |
| 234 | 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) |
| 235 | add_unicast_routing_flow(self.controller, 0x0800, NW2_ROUTE2, 0, l3_msg.group_id, NW2_VRF) |
| 236 | |
| 237 | |
| 238 | """ |
| 239 | Send paket to verify, NW1 |
| 240 | """ |
| 241 | #tx packet on network lport |
| 242 | inner_pkt = simple_udp_packet(pktlen=100 |
| 243 | , eth_src = NW1_VM1_MAC_STR |
| 244 | , eth_dst=NW1_GW_MAC_STR |
| 245 | , ip_dst =NW1_VM2_IP_STR |
| 246 | , ip_src =NW1_VM1_IP_STR |
| 247 | , ip_ttl =64) |
| 248 | vxlan_pkt = simple_vxlan_packet(eth_dst=SWITCH_INTF_MAC_STR |
| 249 | ,eth_src=VXLAN_TNL_H_R_MAC_STR |
| 250 | ,vnid=NW1_VNID |
| 251 | ,ip_dst= SWITCH_IP_STR |
| 252 | ,ip_src=VXLAN_TNL_H1_IP_STR |
| 253 | ,inner_payload=inner_pkt) |
| 254 | self.dataplane.send(NETWORK_PORT, str(vxlan_pkt)) |
| 255 | #verify rx on access port |
| 256 | inner_pkt = simple_udp_packet(pktlen=104 |
| 257 | , eth_src= NW1_VM1_MAC_STR |
| 258 | , eth_dst=NW1_GW_MAC_STR |
| 259 | , dl_vlan_enable=True |
| 260 | , vlan_vid=NW1_VLAN |
| 261 | , ip_dst =NW1_VM2_IP_STR |
| 262 | , ip_src =NW1_VM1_IP_STR |
| 263 | , ip_ttl =64) |
| 264 | verify_packet(self, str(inner_pkt), ACCESS_PORT) |
| 265 | verify_no_other_packets(self) |
| 266 | |
| 267 | #tx on loopback port |
| 268 | self.dataplane.send(LOOPBACK_PORT, str(inner_pkt)) |
| 269 | #verify rx on loopback port |
| 270 | inner_pkt = simple_udp_packet(pktlen=104 |
| 271 | , eth_src=NW1_GW_MAC_STR |
| 272 | , eth_dst=NW1_VM2_MAC_STR |
| 273 | , dl_vlan_enable=True |
| 274 | , vlan_vid=NW1_VLAN |
| 275 | , ip_dst =NW1_VM2_IP_STR |
| 276 | , ip_src =NW1_VM1_IP_STR |
| 277 | , ip_ttl =63) |
| 278 | verify_packet(self, str(inner_pkt), LOOPBACK_PORT) |
| 279 | verify_no_other_packets(self) |
| 280 | #tx on access port |
| 281 | self.dataplane.send(ACCESS_PORT, str(inner_pkt)) |
| 282 | #verify rx on network port |
| 283 | inner_pkt = simple_udp_packet(pktlen=100 |
| 284 | , eth_src=NW1_GW_MAC_STR |
| 285 | , eth_dst=NW1_VM2_MAC_STR |
| 286 | , ip_dst =NW1_VM2_IP_STR |
| 287 | , ip_src =NW1_VM1_IP_STR |
| 288 | , ip_ttl =63) |
| 289 | vxlan_pkt = simple_vxlan_packet(eth_src=SWITCH_INTF_MAC_STR |
| 290 | ,eth_dst=VXLAN_TNL_H_R_MAC_STR |
| 291 | ,vnid=NW1_VNID |
| 292 | ,ip_dst=VXLAN_TNL_H1_IP_STR |
| 293 | ,ip_src=SWITCH_IP_STR |
| 294 | ,inner_payload=inner_pkt) |
| 295 | verify_packet(self, inner_pkt, NETWORK_PORT) |
| 296 | verify_no_other_packets(self) |
| 297 | |
| 298 | |
| 299 | """ |
| 300 | Send paket to verify, NW2 |
| 301 | """ |
| 302 | #tx packet on network lport |
| 303 | inner_pkt = simple_udp_packet(pktlen=100 |
| 304 | , eth_src = NW2_VM1_MAC_STR |
| 305 | , eth_dst=NW2_GW_MAC_STR |
| 306 | , ip_dst =NW2_VM2_IP_STR |
| 307 | , ip_src =NW2_VM1_IP_STR |
| 308 | , ip_ttl =64) |
| 309 | vxlan_pkt = simple_vxlan_packet(eth_dst=SWITCH_INTF_MAC_STR |
| 310 | ,eth_src=VXLAN_TNL_H_R_MAC_STR |
| 311 | ,vnid=NW2_VNID |
| 312 | ,ip_dst= SWITCH_IP_STR |
| 313 | ,ip_src=VXLAN_TNL_H1_IP_STR |
| 314 | ,inner_payload=inner_pkt) |
| 315 | self.dataplane.send(NETWORK_PORT, str(vxlan_pkt)) |
| 316 | #verify rx on access port |
| 317 | inner_pkt = simple_udp_packet(pktlen=104 |
| 318 | , eth_src= NW2_VM1_MAC_STR |
| 319 | , eth_dst=NW2_GW_MAC_STR |
| 320 | , dl_vlan_enable=True |
| 321 | , vlan_vid=NW2_VLAN |
| 322 | , ip_dst =NW2_VM2_IP_STR |
| 323 | , ip_src =NW2_VM1_IP_STR |
| 324 | , ip_ttl =64) |
| 325 | verify_packet(self, str(inner_pkt), ACCESS_PORT) |
| 326 | verify_no_other_packets(self) |
| 327 | |
| 328 | #tx on loopback port |
| 329 | self.dataplane.send(LOOPBACK_PORT, str(inner_pkt)) |
| 330 | #verify rx on loopback port |
| 331 | inner_pkt = simple_udp_packet(pktlen=104 |
| 332 | , eth_src=NW2_GW_MAC_STR |
| 333 | , eth_dst=NW2_VM2_MAC_STR |
| 334 | , dl_vlan_enable=True |
| 335 | , vlan_vid=NW2_VLAN |
| 336 | , ip_dst =NW2_VM2_IP_STR |
| 337 | , ip_src =NW2_VM1_IP_STR |
| 338 | , ip_ttl =63) |
| 339 | verify_packet(self, str(inner_pkt), LOOPBACK_PORT) |
| 340 | verify_no_other_packets(self) |
| 341 | #tx on access port |
| 342 | self.dataplane.send(ACCESS_PORT, str(inner_pkt)) |
| 343 | #verify rx on network port |
| 344 | inner_pkt = simple_udp_packet(pktlen=100 |
| 345 | , eth_src=NW2_GW_MAC_STR |
| 346 | , eth_dst=NW2_VM2_MAC_STR |
| 347 | , ip_dst =NW2_VM2_IP_STR |
| 348 | , ip_src =NW2_VM1_IP_STR |
| 349 | , ip_ttl =63) |
| 350 | vxlan_pkt = simple_vxlan_packet(eth_src=SWITCH_INTF_MAC_STR |
| 351 | ,eth_dst=VXLAN_TNL_H_R_MAC_STR |
| 352 | ,vnid=NW2_VNID |
| 353 | ,ip_dst=VXLAN_TNL_H1_IP_STR |
| 354 | ,ip_src=SWITCH_IP_STR |
| 355 | ,inner_payload=inner_pkt) |
| 356 | verify_packet(self, inner_pkt, NETWORK_PORT) |
| 357 | verify_no_other_packets(self) |
| 358 | |
| 359 | """clear all flow/group and configuration |
| 360 | """ |
| 361 | delete_all_flows(self.controller) |
| 362 | delete_all_groups(self.controller) |
| 363 | """ del vxlan config""" |
| 364 | #delete access port |
| 365 | vtap_conf_xml=get_vtap_lport_config_xml(dp_id=feature_reply.datapath_id, |
| 366 | lport=NW1_ACCESS_LPORT, phy_port=ACCESS_PORT, |
| 367 | vlan=NW1_VLAN, vnid=NW1_VNID, operation="delete") |
| 368 | logging.info("delete config VTAP 0x%lx, PHY %d, VID %d, VNID %lx", NW1_ACCESS_LPORT, ACCESS_PORT, NW1_VLAN, NW1_VNID); |
| 369 | assert(send_edit_config(config["switch_ip"], vtap_conf_xml) == True) |
| 370 | vtap_conf_xml=get_vtap_lport_config_xml(dp_id=feature_reply.datapath_id, |
| 371 | lport=NW2_ACCESS_LPORT, phy_port=ACCESS_PORT, |
| 372 | vlan=NW2_VLAN, vnid=NW2_VNID, operation="delete") |
| 373 | logging.info("delete config VTAP 0x%lx, PHY %d, VID %d, VNID %lx", NW2_ACCESS_LPORT, ACCESS_PORT, NW1_VLAN, NW1_VNID); |
| 374 | assert(send_edit_config(config["switch_ip"], vtap_conf_xml) == True) |
| 375 | #delete network port |
| 376 | vtep_conf_xml=get_vtep_lport_config_xml(dp_id=feature_reply.datapath_id, |
| 377 | lport=NW1_NEWORK_LPORT, |
| 378 | src_ip=SWITCH_IP_STR, dst_ip=VXLAN_TNL_H1_IP_STR, |
| 379 | next_hop_id=VXLAN_TNL_H_R_NHP_ID, |
| 380 | vnid=NW1_VNID, operation="delete") |
| 381 | 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); |
| 382 | assert(send_edit_config(config["switch_ip"], vtep_conf_xml) == True) |
| 383 | |
macauley | 97a0f63 | 2015-08-07 17:03:39 +0800 | [diff] [blame] | 384 | if NW1_NEWORK_LPORT != NW2_NEWORK_LPORT: |
| 385 | vtep_conf_xml=get_vtep_lport_config_xml(dp_id=feature_reply.datapath_id, |
| 386 | lport=NW2_NEWORK_LPORT, |
| 387 | src_ip=SWITCH_IP_STR, dst_ip=VXLAN_TNL_H1_IP_STR, |
| 388 | next_hop_id=VXLAN_TNL_H_R_NHP_ID, |
| 389 | vnid=NW2_VNID, operation="delete") |
| 390 | 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); |
| 391 | assert(send_edit_config(config["switch_ip"], vtep_conf_xml) == True) |
| 392 | |
macauley | 1c0b6c4 | 2015-08-06 18:13:56 +0800 | [diff] [blame] | 393 | #delete next hop and network port for H1 |
| 394 | next_hop_conf_xml=get_next_hop_config_xml(next_hop_id=VXLAN_TNL_H_R_NHP_ID, |
| 395 | dst_mac=VXLAN_TNL_H_R_MAC_STR, |
| 396 | phy_port=NETWORK_PORT, |
| 397 | vlan=SWITCH_VLAN, operation="delete") |
| 398 | 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); |
| 399 | assert(send_edit_config(config["switch_ip"], next_hop_conf_xml)==True) |
| 400 | #del vni |
| 401 | vni_config_xml=get_vni_config_xml(vni_id=NW1_VNID, mcast_ipv4=None, next_hop_id=None, operation="delete") |
| 402 | logging.info("delete config VNI %lx", NW1_VNID); |
| 403 | assert(send_edit_config(config["switch_ip"], vni_config_xml) == True) |
| 404 | vni_config_xml=get_vni_config_xml(vni_id=NW2_VNID, mcast_ipv4=None, next_hop_id=None, operation="delete") |
| 405 | logging.info("delete config VNI %lx", NW2_VNID); |
| 406 | assert(send_edit_config(config["switch_ip"], vni_config_xml) == True) |
| 407 | |
| 408 | #for routing on different VNID, it can't have same subnet. |
| 409 | TNW1_ACCESS_LPORT=0x10001 |
| 410 | TNW2_ACCESS_LPORT=0x10002 |
| 411 | TNW1_NEWORK_LPORT=0x10003 |
| 412 | TNW2_NEWORK_LPORT=0x10004 |
| 413 | |
| 414 | TNW1_VRF=2 #all shall the same |
| 415 | TNW2_VRF=2 |
| 416 | TNW_VRF=[TNW1_VRF, TNW2_VRF] |
| 417 | TSWITCH_VRF=0 #let switch different from VM |
| 418 | assert(TNW2_VRF!=TSWITCH_VRF) |
| 419 | assert(TNW1_VRF!=TSWITCH_VRF) |
| 420 | |
| 421 | TNW1_VNID=1 |
| 422 | TNW2_VNID=2 |
| 423 | TNW_VNID=[TNW1_VNID, TNW2_VNID] |
| 424 | |
| 425 | TNW1_VLAN = 2 |
| 426 | TNW2_VLAN = 3 |
| 427 | TNW_VLAN=[TNW1_VLAN, TNW2_VLAN] |
| 428 | assert(TNW1_VLAN!=SWITCH_VLAN) |
| 429 | assert(TNW2_VLAN!=SWITCH_VLAN) |
| 430 | #the subnet shall not the same, because they all NW use same VRF |
| 431 | TNW1_VM1_IP = 0XC0A80101 #192.168.1.1 |
| 432 | TNW1_VM1_IP_STR = convertIP4toStr(TNW1_VM1_IP) |
| 433 | TNW1_VM1_MAC=[0x00, 0x11, 0x11, 0x11, 0x11, 0x11] |
| 434 | TNW1_VM1_MAC_STR=convertMACtoStr(TNW1_VM1_MAC) |
| 435 | TNW1_VM2_IP = 0XC0A80201 #192.168.2.1 |
| 436 | TNW1_VM2_IP_STR = convertIP4toStr(TNW1_VM2_IP) |
| 437 | TNW1_VM2_MAC=[0x00, 0x12, 0x12, 0x12, 0x12, 0x12] |
| 438 | TNW1_VM2_MAC_STR=convertMACtoStr(TNW1_VM2_MAC) |
| 439 | TNW2_VM1_IP = 0XC0A80301 #192.168.3.1 |
| 440 | TNW2_VM1_IP_STR = convertIP4toStr(TNW2_VM1_IP) |
| 441 | TNW2_VM1_MAC=[0x00, 0x21, 0x21, 0x21, 0x21, 0x21] |
| 442 | TNW2_VM1_MAC_STR=convertMACtoStr(TNW2_VM1_MAC) |
| 443 | TNW2_VM2_IP = 0XC0A80401 #192.168.4.1 |
| 444 | TNW2_VM2_IP_STR = convertIP4toStr(TNW2_VM2_IP) |
| 445 | TNW2_VM2_MAC=[0x00, 0x22, 0x22, 0x22, 0x22, 0x22] |
| 446 | TNW2_VM2_MAC_STR=convertMACtoStr(TNW2_VM2_MAC) |
| 447 | |
| 448 | TNW1_GW_MAC=[0x00, 0x00, 0x00, 0x00, 0x11, 0x11] |
| 449 | TNW1_GW_MAC_STR=convertMACtoStr(TNW1_GW_MAC) |
| 450 | TNW1_ROUTE1 =TNW1_VM1_IP |
| 451 | TNW1_ROUTE1_STR =TNW1_VM1_IP_STR |
| 452 | TNW1_ROUTE1_NEXT_HOP_MAC=TNW1_VM1_MAC |
| 453 | TNW1_ROUTE2 =TNW1_VM2_IP |
| 454 | TNW1_ROUTE2_NEXT_HOP_MAC=TNW1_VM2_MAC |
| 455 | TNW1_ROUTE2_STR =TNW1_VM2_IP_STR |
| 456 | TNW1_GW_ROUTE =[TNW1_ROUTE1, TNW1_ROUTE2] |
| 457 | TNW1_GW_ROUTE_STR=[TNW1_ROUTE1_STR, TNW1_ROUTE2_STR] |
| 458 | TNW1_GW_ROUTE_NHP=[TNW1_ROUTE1_NEXT_HOP_MAC, TNW1_ROUTE2_NEXT_HOP_MAC] |
| 459 | |
| 460 | TNW2_GW_MAC=[0x00, 0x00, 0x00, 0x00, 0x22, 0x22] |
| 461 | TNW2_GW_MAC_STR=convertMACtoStr(TNW2_GW_MAC) |
| 462 | TNW2_ROUTE1 =TNW2_VM1_IP |
| 463 | TNW2_ROUTE1_STR =TNW2_VM1_IP_STR |
| 464 | TNW2_ROUTE1_NEXT_HOP_MAC=TNW2_VM1_MAC |
| 465 | TNW2_ROUTE2 =TNW2_VM2_IP |
| 466 | TNW2_ROUTE2_STR =TNW2_VM1_IP_STR |
| 467 | TNW2_ROUTE2_NEXT_HOP_MAC=TNW2_VM2_MAC |
| 468 | TNW2_GW_ROUT_STR=[TNW2_ROUTE1_STR, TNW2_ROUTE2_STR] |
| 469 | |
| 470 | TNW_GW_MAC=[TNW1_GW_MAC, TNW2_GW_MAC] |
| 471 | TNW_GW_MAC_STR=[TNW1_GW_MAC_STR, TNW2_GW_MAC_STR] |
| 472 | |
| 473 | |
| 474 | |
| 475 | class vrouterDiffVnidRouting(base_tests.SimpleDataPlane): |
| 476 | """ |
| 477 | Topology: |
| 478 | === switch inner pipeline |
| 479 | --- switch forn port physical link |
| 480 | R: router |
| 481 | NP:netowrk port |
| 482 | AP:Access port |
| 483 | LP:loopback port |
| 484 | H1(VM1/VM2) -- R ----------- NP ==== AP --- LP |
| 485 | H2 -- |
| 486 | |
| 487 | VM1(192.168.1.1, NW1_VNID) <--> VM2(192.168.2.1, NW1_VNID) |
| 488 | VM1(192.168.1.1, NW2_VNID) <--> VM2(192.168.2.1, NW2_VNID) |
| 489 | |
| 490 | Inner operation: |
| 491 | (decap/encap vxlan header)NP==(bridge inner DMAC)==AP(VNID->VLANID)----(VLANIDx->same VRF)LP |
| 492 | |
| 493 | """ |
| 494 | def runTest(self): |
| 495 | delete_all_flows(self.controller) |
| 496 | delete_all_groups(self.controller) |
| 497 | |
| 498 | ACCESS_PORT=config["port_map"].keys()[0] |
| 499 | NETWORK_PORT=config["port_map"].keys()[1] |
| 500 | LOOPBACK_PORT=config["port_map"].keys()[2] |
| 501 | print "access %ld, network %ld, loopback %ld"%(ACCESS_PORT, NETWORK_PORT, LOOPBACK_PORT) |
| 502 | """ add vxlan config""" |
| 503 | feature_reply=get_featureReplay(self) |
| 504 | SWITCH_INTF_MAC_STR, SWITCH_INTF_MAC=getSwitchCpuMACFromDPID(feature_reply.datapath_id) |
| 505 | #add vni |
| 506 | vni_config_xml=get_vni_config_xml(vni_id=TNW1_VNID, mcast_ipv4=None, next_hop_id=None) |
| 507 | logging.info("config VNI %lx", TNW1_VNID); |
| 508 | assert(send_edit_config(config["switch_ip"], vni_config_xml) == True) |
| 509 | vni_config_xml=get_vni_config_xml(vni_id=TNW2_VNID, mcast_ipv4=None, next_hop_id=None) |
| 510 | logging.info("config VNI %lx", TNW2_VNID); |
| 511 | assert(send_edit_config(config["switch_ip"], vni_config_xml) == True) |
| 512 | #add access port |
| 513 | vtap_conf_xml=get_vtap_lport_config_xml(dp_id=feature_reply.datapath_id, |
| 514 | lport=TNW1_ACCESS_LPORT, phy_port=ACCESS_PORT, |
| 515 | vlan=TNW1_VLAN, vnid=TNW1_VNID) |
| 516 | logging.info("config VTAP 0x%lx, PHY %d, VID %d, VNID %lx", TNW1_ACCESS_LPORT, ACCESS_PORT, TNW1_VLAN, TNW1_VNID); |
| 517 | assert(send_edit_config(config["switch_ip"], vtap_conf_xml) == True) |
| 518 | vtap_conf_xml=get_vtap_lport_config_xml(dp_id=feature_reply.datapath_id, |
| 519 | lport=TNW2_ACCESS_LPORT, phy_port=ACCESS_PORT, |
| 520 | vlan=TNW2_VLAN, vnid=TNW2_VNID) |
| 521 | logging.info("config VTAP 0x%lx, PHY %d, VID %d, VNID %lx", TNW2_ACCESS_LPORT, ACCESS_PORT, TNW1_VLAN, NW1_VNID); |
| 522 | assert(send_edit_config(config["switch_ip"], vtap_conf_xml) == True) |
| 523 | #create next hop and network port for H1 |
| 524 | next_hop_conf_xml=get_next_hop_config_xml(next_hop_id=VXLAN_TNL_H_R_NHP_ID, |
| 525 | dst_mac=VXLAN_TNL_H_R_MAC_STR, |
| 526 | phy_port=NETWORK_PORT, |
| 527 | vlan=SWITCH_VLAN) |
| 528 | 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); |
| 529 | assert(send_edit_config(config["switch_ip"], next_hop_conf_xml)==True) |
| 530 | #create network port |
| 531 | vtep_conf_xml=get_vtep_lport_config_xml(dp_id=feature_reply.datapath_id, |
| 532 | lport=TNW1_NEWORK_LPORT, |
| 533 | src_ip=SWITCH_IP_STR, dst_ip=VXLAN_TNL_H1_IP_STR, |
| 534 | next_hop_id=VXLAN_TNL_H_R_NHP_ID, |
| 535 | vnid=TNW1_VNID) |
| 536 | 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); |
| 537 | assert(send_edit_config(config["switch_ip"], vtep_conf_xml) == True) |
| 538 | |
| 539 | vtep_conf_xml=get_vtep_lport_config_xml(dp_id=feature_reply.datapath_id, |
| 540 | lport=TNW2_NEWORK_LPORT, |
| 541 | src_ip=SWITCH_IP_STR, dst_ip=VXLAN_TNL_H1_IP_STR, |
| 542 | next_hop_id=VXLAN_TNL_H_R_NHP_ID, |
| 543 | vnid=TNW2_VNID) |
| 544 | 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); |
| 545 | assert(send_edit_config(config["switch_ip"], vtep_conf_xml) == True) |
| 546 | |
| 547 | |
| 548 | """add routing flow""" |
| 549 | #add port table to have vxlan ability |
| 550 | add_port_table_flow(self.controller) |
| 551 | #add l2 interface group |
castroflavio | dd17147 | 2015-12-08 13:55:58 -0500 | [diff] [blame] | 552 | add_one_l2_interface_group(self.controller, NETWORK_PORT, vlan_id=SWITCH_VLAN, is_tagged=True, send_barrier=False) |
macauley | 1c0b6c4 | 2015-08-06 18:13:56 +0800 | [diff] [blame] | 553 | for i in range(len(TNW_VLAN)): |
castroflavio | dd17147 | 2015-12-08 13:55:58 -0500 | [diff] [blame] | 554 | add_one_l2_interface_group(self.controller, LOOPBACK_PORT, vlan_id=TNW_VLAN[i], is_tagged=True, send_barrier=False) |
macauley | 1c0b6c4 | 2015-08-06 18:13:56 +0800 | [diff] [blame] | 555 | |
| 556 | #add vlan flow table |
| 557 | add_one_vlan_table_flow(self.controller, NETWORK_PORT, SWITCH_VLAN, vrf=SWITCH_VRF, flag=VLAN_TABLE_FLAG_ONLY_BOTH) |
| 558 | for i in range(len(TNW_VLAN)): |
| 559 | add_one_vlan_table_flow(self.controller, LOOPBACK_PORT, TNW_VLAN[i], vrf=TNW_VRF[i], flag=VLAN_TABLE_FLAG_ONLY_TAG) |
| 560 | |
| 561 | #add vxlan bridge flow |
| 562 | add_overlay_bridge_flow(self.controller, TNW1_GW_MAC, TNW1_VNID, TNW1_ACCESS_LPORT, False, False) |
| 563 | add_overlay_bridge_flow(self.controller, TNW2_GW_MAC, TNW2_VNID, TNW2_ACCESS_LPORT, False, False) |
| 564 | add_overlay_bridge_flow(self.controller, TNW1_VM1_MAC, TNW1_VNID, TNW1_NEWORK_LPORT, False, False) |
| 565 | add_overlay_bridge_flow(self.controller, TNW1_VM2_MAC, TNW1_VNID, TNW1_NEWORK_LPORT, False, False) |
| 566 | add_overlay_bridge_flow(self.controller, TNW2_VM1_MAC, TNW2_VNID, TNW2_NEWORK_LPORT, False, False) |
| 567 | add_overlay_bridge_flow(self.controller, TNW2_VM2_MAC, TNW2_VNID, TNW2_NEWORK_LPORT, False, False) |
| 568 | |
| 569 | #add termination flow |
| 570 | add_termination_flow(self.controller, NETWORK_PORT, 0x0800, SWITCH_INTF_MAC, SWITCH_VLAN) |
| 571 | for i in range(len(TNW_VLAN)): |
| 572 | add_termination_flow(self.controller, LOOPBACK_PORT, 0x0800, TNW_GW_MAC[i], TNW_VLAN[i]) |
| 573 | |
| 574 | """ |
| 575 | Add Network Route, TNW1 |
| 576 | 192.168.1.1 |
| 577 | 192.168.2.1 |
| 578 | """ |
| 579 | 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) |
| 580 | add_unicast_routing_flow(self.controller, 0x0800, TNW1_ROUTE1, 0, l3_msg.group_id, TNW1_VRF) |
| 581 | 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) |
| 582 | add_unicast_routing_flow(self.controller, 0x0800, TNW1_ROUTE2, 0, l3_msg.group_id, TNW1_VRF) |
| 583 | """ |
| 584 | Add Network Route, TNW2 |
| 585 | 192.168.1.1 |
| 586 | 192.168.2.1 |
| 587 | """ |
| 588 | 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) |
| 589 | add_unicast_routing_flow(self.controller, 0x0800, TNW2_ROUTE1, 0, l3_msg.group_id, TNW2_VRF) |
| 590 | 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) |
| 591 | add_unicast_routing_flow(self.controller, 0x0800, TNW2_ROUTE2, 0, l3_msg.group_id, TNW2_VRF) |
| 592 | |
| 593 | |
| 594 | """ |
| 595 | Send paket to verify, TNW1 |
| 596 | """ |
| 597 | #tx packet on network lport |
| 598 | inner_pkt = simple_udp_packet(pktlen=100 |
| 599 | , eth_src = TNW1_VM1_MAC_STR |
| 600 | , eth_dst=TNW1_GW_MAC_STR |
| 601 | , ip_dst =TNW1_VM2_IP_STR |
| 602 | , ip_src =TNW1_VM1_IP_STR |
| 603 | , ip_ttl =64) |
| 604 | vxlan_pkt = simple_vxlan_packet(eth_dst=SWITCH_INTF_MAC_STR |
| 605 | ,eth_src=VXLAN_TNL_H_R_MAC_STR |
| 606 | ,vnid=TNW1_VNID |
| 607 | ,ip_dst= SWITCH_IP_STR |
| 608 | ,ip_src=VXLAN_TNL_H1_IP_STR |
| 609 | ,inner_payload=inner_pkt) |
| 610 | self.dataplane.send(NETWORK_PORT, str(vxlan_pkt)) |
| 611 | #verify rx on access port |
| 612 | inner_pkt = simple_udp_packet(pktlen=104 |
| 613 | , eth_src= TNW1_VM1_MAC_STR |
| 614 | , eth_dst=TNW1_GW_MAC_STR |
| 615 | , dl_vlan_enable=True |
| 616 | , vlan_vid=TNW1_VLAN |
| 617 | , ip_dst =TNW1_VM2_IP_STR |
| 618 | , ip_src =TNW1_VM1_IP_STR |
| 619 | , ip_ttl =64) |
| 620 | verify_packet(self, str(inner_pkt), ACCESS_PORT) |
| 621 | verify_no_other_packets(self) |
| 622 | |
| 623 | #tx on loopback port |
| 624 | self.dataplane.send(LOOPBACK_PORT, str(inner_pkt)) |
| 625 | #verify rx on loopback port |
| 626 | inner_pkt = simple_udp_packet(pktlen=104 |
| 627 | , eth_src=TNW1_GW_MAC_STR |
| 628 | , eth_dst=TNW1_VM2_MAC_STR |
| 629 | , dl_vlan_enable=True |
| 630 | , vlan_vid=TNW1_VLAN |
| 631 | , ip_dst =TNW1_VM2_IP_STR |
| 632 | , ip_src =TNW1_VM1_IP_STR |
| 633 | , ip_ttl =63) |
| 634 | verify_packet(self, str(inner_pkt), LOOPBACK_PORT) |
| 635 | verify_no_other_packets(self) |
| 636 | #tx on access port |
| 637 | self.dataplane.send(ACCESS_PORT, str(inner_pkt)) |
| 638 | #verify rx on network port |
| 639 | inner_pkt = simple_udp_packet(pktlen=100 |
| 640 | , eth_src=TNW1_GW_MAC_STR |
| 641 | , eth_dst=TNW1_VM2_MAC_STR |
| 642 | , ip_dst =TNW1_VM2_IP_STR |
| 643 | , ip_src =TNW1_VM1_IP_STR |
| 644 | , ip_ttl =63) |
| 645 | vxlan_pkt = simple_vxlan_packet(eth_src=SWITCH_INTF_MAC_STR |
| 646 | ,eth_dst=VXLAN_TNL_H_R_MAC_STR |
| 647 | ,vnid=TNW1_VNID |
| 648 | ,ip_dst=VXLAN_TNL_H1_IP_STR |
| 649 | ,ip_src=SWITCH_IP_STR |
| 650 | ,inner_payload=inner_pkt) |
| 651 | verify_packet(self, inner_pkt, NETWORK_PORT) |
| 652 | verify_no_other_packets(self) |
| 653 | |
| 654 | |
| 655 | """ |
| 656 | Send paket to verify, NW2 |
| 657 | """ |
| 658 | #tx packet on network lport |
| 659 | inner_pkt = simple_udp_packet(pktlen=100 |
| 660 | , eth_src = TNW2_VM1_MAC_STR |
| 661 | , eth_dst=TNW2_GW_MAC_STR |
| 662 | , ip_dst =TNW2_VM2_IP_STR |
| 663 | , ip_src =TNW2_VM1_IP_STR |
| 664 | , ip_ttl =64) |
| 665 | vxlan_pkt = simple_vxlan_packet(eth_dst=SWITCH_INTF_MAC_STR |
| 666 | ,eth_src=VXLAN_TNL_H_R_MAC_STR |
| 667 | ,vnid=TNW2_VNID |
| 668 | ,ip_dst= SWITCH_IP_STR |
| 669 | ,ip_src=VXLAN_TNL_H1_IP_STR |
| 670 | ,inner_payload=inner_pkt) |
| 671 | self.dataplane.send(NETWORK_PORT, str(vxlan_pkt)) |
| 672 | #verify rx on access port |
| 673 | inner_pkt = simple_udp_packet(pktlen=104 |
| 674 | , eth_src= TNW2_VM1_MAC_STR |
| 675 | , eth_dst=TNW2_GW_MAC_STR |
| 676 | , dl_vlan_enable=True |
| 677 | , vlan_vid=TNW2_VLAN |
| 678 | , ip_dst =TNW2_VM2_IP_STR |
| 679 | , ip_src =TNW2_VM1_IP_STR |
| 680 | , ip_ttl =64) |
| 681 | verify_packet(self, str(inner_pkt), ACCESS_PORT) |
| 682 | verify_no_other_packets(self) |
| 683 | |
| 684 | #tx on loopback port |
| 685 | self.dataplane.send(LOOPBACK_PORT, str(inner_pkt)) |
| 686 | #verify rx on loopback port |
| 687 | inner_pkt = simple_udp_packet(pktlen=104 |
| 688 | , eth_src=TNW2_GW_MAC_STR |
| 689 | , eth_dst=TNW2_VM2_MAC_STR |
| 690 | , dl_vlan_enable=True |
| 691 | , vlan_vid=TNW2_VLAN |
| 692 | , ip_dst =TNW2_VM2_IP_STR |
| 693 | , ip_src =TNW2_VM1_IP_STR |
| 694 | , ip_ttl =63) |
| 695 | verify_packet(self, str(inner_pkt), LOOPBACK_PORT) |
| 696 | verify_no_other_packets(self) |
| 697 | #tx on access port |
| 698 | self.dataplane.send(ACCESS_PORT, str(inner_pkt)) |
| 699 | #verify rx on network port |
| 700 | inner_pkt = simple_udp_packet(pktlen=100 |
| 701 | , eth_src=TNW2_GW_MAC_STR |
| 702 | , eth_dst=TNW2_VM2_MAC_STR |
| 703 | , ip_dst =TNW2_VM2_IP_STR |
| 704 | , ip_src =TNW2_VM1_IP_STR |
| 705 | , ip_ttl =63) |
| 706 | vxlan_pkt = simple_vxlan_packet(eth_src=SWITCH_INTF_MAC_STR |
| 707 | ,eth_dst=VXLAN_TNL_H_R_MAC_STR |
| 708 | ,vnid=TNW2_VNID |
| 709 | ,ip_dst=VXLAN_TNL_H1_IP_STR |
| 710 | ,ip_src=SWITCH_IP_STR |
| 711 | ,inner_payload=inner_pkt) |
| 712 | verify_packet(self, inner_pkt, NETWORK_PORT) |
| 713 | verify_no_other_packets(self) |
| 714 | |
| 715 | |
| 716 | """clear all flow/group and configuration |
| 717 | """ |
| 718 | delete_all_flows(self.controller) |
| 719 | delete_all_groups(self.controller) |
| 720 | """ del vxlan config""" |
| 721 | #delete access port |
| 722 | vtap_conf_xml=get_vtap_lport_config_xml(dp_id=feature_reply.datapath_id, |
| 723 | lport=TNW1_ACCESS_LPORT, phy_port=ACCESS_PORT, |
| 724 | vlan=TNW1_VLAN, vnid=TNW1_VNID, operation="delete") |
| 725 | logging.info("delete config VTAP 0x%lx, PHY %d, VID %d, VNID %lx", TNW1_ACCESS_LPORT, ACCESS_PORT, TNW1_VLAN, TNW1_VNID); |
| 726 | assert(send_edit_config(config["switch_ip"], vtap_conf_xml) == True) |
| 727 | vtap_conf_xml=get_vtap_lport_config_xml(dp_id=feature_reply.datapath_id, |
| 728 | lport=TNW2_ACCESS_LPORT, phy_port=ACCESS_PORT, |
| 729 | vlan=TNW2_VLAN, vnid=TNW2_VNID, operation="delete") |
| 730 | logging.info("delete config VTAP 0x%lx, PHY %d, VID %d, VNID %lx", TNW2_ACCESS_LPORT, ACCESS_PORT, TNW1_VLAN, TNW1_VNID); |
| 731 | assert(send_edit_config(config["switch_ip"], vtap_conf_xml) == True) |
| 732 | #delete network port |
| 733 | vtep_conf_xml=get_vtep_lport_config_xml(dp_id=feature_reply.datapath_id, |
| 734 | lport=TNW1_NEWORK_LPORT, |
| 735 | src_ip=SWITCH_IP_STR, dst_ip=VXLAN_TNL_H1_IP_STR, |
| 736 | next_hop_id=VXLAN_TNL_H_R_NHP_ID, |
| 737 | vnid=TNW1_VNID, operation="delete") |
| 738 | 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); |
| 739 | assert(send_edit_config(config["switch_ip"], vtep_conf_xml) == True) |
| 740 | |
| 741 | vtep_conf_xml=get_vtep_lport_config_xml(dp_id=feature_reply.datapath_id, |
| 742 | lport=TNW2_NEWORK_LPORT, |
| 743 | src_ip=SWITCH_IP_STR, dst_ip=VXLAN_TNL_H1_IP_STR, |
| 744 | next_hop_id=VXLAN_TNL_H_R_NHP_ID, |
| 745 | vnid=TNW2_VNID, operation="delete") |
| 746 | 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); |
| 747 | assert(send_edit_config(config["switch_ip"], vtep_conf_xml) == True) |
| 748 | #delete next hop and network port for H1 |
| 749 | next_hop_conf_xml=get_next_hop_config_xml(next_hop_id=VXLAN_TNL_H_R_NHP_ID, |
| 750 | dst_mac=VXLAN_TNL_H_R_MAC_STR, |
| 751 | phy_port=NETWORK_PORT, |
| 752 | vlan=SWITCH_VLAN, operation="delete") |
| 753 | 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); |
| 754 | assert(send_edit_config(config["switch_ip"], next_hop_conf_xml)==True) |
| 755 | #del vni |
| 756 | vni_config_xml=get_vni_config_xml(vni_id=TNW1_VNID, mcast_ipv4=None, next_hop_id=None, operation="delete") |
| 757 | logging.info("delete config VNI %lx", TNW1_VNID); |
| 758 | assert(send_edit_config(config["switch_ip"], vni_config_xml) == True) |
| 759 | vni_config_xml=get_vni_config_xml(vni_id=TNW2_VNID, mcast_ipv4=None, next_hop_id=None, operation="delete") |
| 760 | logging.info("delete config VNI %lx", TNW2_VNID); |
| 761 | assert(send_edit_config(config["switch_ip"], vni_config_xml) == True) |
| 762 | |
| 763 | class vrouterNetconfSetUnset(base_tests.SimpleDataPlane): |
| 764 | def runTest(self): |
| 765 | ACCESS_PORT=config["port_map"].keys()[0] |
| 766 | NETWORK_PORT=config["port_map"].keys()[1] |
| 767 | LOOPBACK_PORT=config["port_map"].keys()[2] |
| 768 | print "access %ld, network %ld, loopback %ld"%(ACCESS_PORT, NETWORK_PORT, LOOPBACK_PORT) |
| 769 | """ add vxlan config""" |
| 770 | feature_reply=get_featureReplay(self) |
| 771 | SWITCH_INTF_MAC_STR, SWITCH_INTF_MAC=getSwitchCpuMACFromDPID(feature_reply.datapath_id) |
| 772 | #add vni |
| 773 | vni_config_xml=get_vni_config_xml(vni_id=NW1_VNID, mcast_ipv4=None, next_hop_id=None) |
| 774 | logging.info("config VNI %lx", NW1_VNID); |
| 775 | assert(send_edit_config(config["switch_ip"], vni_config_xml) == True) |
| 776 | vni_config_xml=get_vni_config_xml(vni_id=NW2_VNID, mcast_ipv4=None, next_hop_id=None) |
| 777 | logging.info("config VNI %lx", NW2_VNID); |
| 778 | assert(send_edit_config(config["switch_ip"], vni_config_xml) == True) |
| 779 | #add access port |
| 780 | vtap_conf_xml=get_vtap_lport_config_xml(dp_id=feature_reply.datapath_id, |
| 781 | lport=NW1_ACCESS_LPORT, phy_port=ACCESS_PORT, |
| 782 | vlan=NW1_VLAN, vnid=NW1_VNID) |
| 783 | logging.info("config VTAP 0x%lx, PHY %d, VID %d, VNID %lx", NW1_ACCESS_LPORT, ACCESS_PORT, NW1_VLAN, NW1_VNID); |
| 784 | assert(send_edit_config(config["switch_ip"], vtap_conf_xml) == True) |
| 785 | vtap_conf_xml=get_vtap_lport_config_xml(dp_id=feature_reply.datapath_id, |
| 786 | lport=NW2_ACCESS_LPORT, phy_port=ACCESS_PORT, |
| 787 | vlan=NW2_VLAN, vnid=NW2_VNID) |
| 788 | logging.info("config VTAP 0x%lx, PHY %d, VID %d, VNID %lx", NW2_ACCESS_LPORT, ACCESS_PORT, NW1_VLAN, NW1_VNID); |
| 789 | assert(send_edit_config(config["switch_ip"], vtap_conf_xml) == True) |
| 790 | #create next hop and network port for H1 |
| 791 | next_hop_conf_xml=get_next_hop_config_xml(next_hop_id=VXLAN_TNL_H_R_NHP_ID, |
| 792 | dst_mac=VXLAN_TNL_H_R_MAC_STR, |
| 793 | phy_port=NETWORK_PORT, |
| 794 | vlan=SWITCH_VLAN) |
| 795 | 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); |
| 796 | assert(send_edit_config(config["switch_ip"], next_hop_conf_xml)==True) |
| 797 | #create network port |
| 798 | vtep_conf_xml=get_vtep_lport_config_xml(dp_id=feature_reply.datapath_id, |
| 799 | lport=NW1_NEWORK_LPORT, |
| 800 | src_ip=SWITCH_IP_STR, dst_ip=VXLAN_TNL_H1_IP_STR, |
| 801 | next_hop_id=VXLAN_TNL_H_R_NHP_ID, |
| 802 | vnid=NW1_VNID) |
| 803 | 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); |
| 804 | assert(send_edit_config(config["switch_ip"], vtep_conf_xml) == True) |
| 805 | |
| 806 | vtep_conf_xml=get_vtep_lport_config_xml(dp_id=feature_reply.datapath_id, |
| 807 | lport=NW2_NEWORK_LPORT, |
| 808 | src_ip=SWITCH_IP_STR, dst_ip=VXLAN_TNL_H1_IP_STR, |
| 809 | next_hop_id=VXLAN_TNL_H_R_NHP_ID, |
| 810 | vnid=NW2_VNID) |
| 811 | 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); |
| 812 | assert(send_edit_config(config["switch_ip"], vtep_conf_xml) == True) |
| 813 | |
| 814 | """clear all flow/group and configuration |
| 815 | """ |
| 816 | """ del vxlan config""" |
| 817 | #delete access port |
| 818 | vtap_conf_xml=get_vtap_lport_config_xml(dp_id=feature_reply.datapath_id, |
| 819 | lport=NW1_ACCESS_LPORT, phy_port=ACCESS_PORT, |
| 820 | vlan=NW1_VLAN, vnid=NW1_VNID, operation="delete") |
| 821 | logging.info("delete config VTAP 0x%lx, PHY %d, VID %d, VNID %lx", NW1_ACCESS_LPORT, ACCESS_PORT, NW1_VLAN, NW1_VNID); |
| 822 | assert(send_edit_config(config["switch_ip"], vtap_conf_xml) == True) |
| 823 | vtap_conf_xml=get_vtap_lport_config_xml(dp_id=feature_reply.datapath_id, |
| 824 | lport=NW2_ACCESS_LPORT, phy_port=ACCESS_PORT, |
| 825 | vlan=NW2_VLAN, vnid=NW2_VNID, operation="delete") |
| 826 | logging.info("delete config VTAP 0x%lx, PHY %d, VID %d, VNID %lx", NW2_ACCESS_LPORT, ACCESS_PORT, NW1_VLAN, NW1_VNID); |
| 827 | assert(send_edit_config(config["switch_ip"], vtap_conf_xml) == True) |
| 828 | #delete network port |
| 829 | vtep_conf_xml=get_vtep_lport_config_xml(dp_id=feature_reply.datapath_id, |
| 830 | lport=NW1_NEWORK_LPORT, |
| 831 | src_ip=SWITCH_IP_STR, dst_ip=VXLAN_TNL_H1_IP_STR, |
| 832 | next_hop_id=VXLAN_TNL_H_R_NHP_ID, |
| 833 | vnid=NW1_VNID, operation="delete") |
| 834 | 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); |
| 835 | assert(send_edit_config(config["switch_ip"], vtep_conf_xml) == True) |
| 836 | |
| 837 | vtep_conf_xml=get_vtep_lport_config_xml(dp_id=feature_reply.datapath_id, |
| 838 | lport=NW2_NEWORK_LPORT, |
| 839 | src_ip=SWITCH_IP_STR, dst_ip=VXLAN_TNL_H1_IP_STR, |
| 840 | next_hop_id=VXLAN_TNL_H_R_NHP_ID, |
| 841 | vnid=NW2_VNID, operation="delete") |
| 842 | 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); |
| 843 | assert(send_edit_config(config["switch_ip"], vtep_conf_xml) == True) |
| 844 | #delete next hop and network port for H1 |
| 845 | next_hop_conf_xml=get_next_hop_config_xml(next_hop_id=VXLAN_TNL_H_R_NHP_ID, |
| 846 | dst_mac=VXLAN_TNL_H_R_MAC_STR, |
| 847 | phy_port=NETWORK_PORT, |
| 848 | vlan=SWITCH_VLAN, operation="delete") |
| 849 | 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); |
| 850 | assert(send_edit_config(config["switch_ip"], next_hop_conf_xml)==True) |
| 851 | #del vni |
| 852 | vni_config_xml=get_vni_config_xml(vni_id=NW1_VNID, mcast_ipv4=None, next_hop_id=None, operation="delete") |
| 853 | logging.info("delete config VNI %lx", NW1_VNID); |
| 854 | assert(send_edit_config(config["switch_ip"], vni_config_xml) == True) |
| 855 | vni_config_xml=get_vni_config_xml(vni_id=NW2_VNID, mcast_ipv4=None, next_hop_id=None, operation="delete") |
| 856 | logging.info("delete config VNI %lx", NW2_VNID); |
| 857 | assert(send_edit_config(config["switch_ip"], vni_config_xml) == True) |