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