9 import inputsVcontainer
13 import tenant_2EPG_SFC
14 import tenant_3EPG_SFC
15 import tenant_3EPG_demo
18 # Manifested constants
20 #class RestMethods_e(Enum):
34 # Function Implimentations
37 #===============================================================================#
38 def printTestCase(desc):
41 for key in sorted(testCases_ga.keys()):
42 print key, ": ", testCases_ga[key][1]
44 for key2 in sorted(testCases2_ga.keys()):
45 print key2, ": ", testCases2_ga[key2][3]
47 return constants.OK_STR
49 #===============================================================================#
50 def getTopology(desc):
53 #url = 'http://127.0.0.1:8181/restconf/config/network-topology:network-topology'
54 url = 'http://127.0.0.1:8181/restconf/operational/network-topology:network-topology'
56 # Send the GET request
57 resp = util.requestGET(url)
59 if resp == constants.ERROR_STR:
60 print "ERROR: getTopology() failed"
65 #===============================================================================#
66 def registerEndpointLocation_acl(desc):
69 nodeId1 = util.getOvsdbNodeIdByName("sw1")
71 if nodeId1 == constants.ERROR_STR:
72 return constants.ERROR_STR
74 nodeId2 = util.getOvsdbNodeIdByName("sw2")
75 if nodeId1 == constants.ERROR_STR:
76 return constants.ERROR_STR
78 for inputData in inputsGBP.get_endpoint_location_data(nc_id1, nc_id2, nodeId1, nodeId2):
79 result = util.runRequestPOST(inputsGBP.get_endpoint_location_uri(), json.dumps(inputData), sys._getframe().f_code.co_name)
83 #===============================================================================#
84 def registerEndpointLocation_sfc(desc):
85 nc_id1 = "vethl-h35-2"
86 nc_id2 = "vethl-h36-4"
87 nodeId1 = util.getOvsdbNodeIdByName("sw1")
89 if nodeId1 == constants.ERROR_STR:
90 return constants.ERROR_STR
92 nodeId2 = util.getOvsdbNodeIdByName("sw6")
93 if nodeId1 == constants.ERROR_STR:
94 return constants.ERROR_STR
96 for inputData in tenant_2EPG_SFC.get_endpoint_location_data(nc_id1, nc_id2, nodeId1, nodeId2):
97 result = util.runRequestPOST(inputsGBP.get_endpoint_location_uri(), json.dumps(inputData), sys._getframe().f_code.co_name)
101 #===============================================================================#
102 def registerEndpointLocation_3epg_sfc(desc):
103 nc_id1 = "vethl-h35-2"
104 nc_id2 = "vethl-h36-4"
105 nc_id3 = "vethl-h37-2"
107 nodeId1 = util.getOvsdbNodeIdByName("sw1")
108 if nodeId1 == constants.ERROR_STR:
109 return constants.ERROR_STR
111 nodeId2 = util.getOvsdbNodeIdByName("sw6")
112 if nodeId1 == constants.ERROR_STR:
113 return constants.ERROR_STR
115 nodeId3 = util.getOvsdbNodeIdByName("sw7")
116 if nodeId1 == constants.ERROR_STR:
117 return constants.ERROR_STR
119 for inputData in tenant_3EPG_SFC.get_endpoint_location_data(nc_id1, nc_id2, nc_id3, nodeId1, nodeId2, nodeId3):
120 result = util.runRequestPOST(inputsGBP.get_endpoint_location_uri(), json.dumps(inputData), sys._getframe().f_code.co_name)
124 #===============================================================================#
125 def registerEndpointLocation_3epg_sfc_acl(desc):
126 nc_id1a = "vethl-h35-2"
127 nc_id1b = "vethl-h35-3"
128 nc_id2a = "vethl-h36-4"
129 nc_id2b = "vethl-h36-5"
130 nc_id3a = "vethl-h37-2"
131 nc_id3b = "vethl-h37-3"
133 nodeId1 = util.getOvsdbNodeIdByName("sw1")
134 if nodeId1 == constants.ERROR_STR:
135 return constants.ERROR_STR
137 nodeId2 = util.getOvsdbNodeIdByName("sw6")
138 if nodeId1 == constants.ERROR_STR:
139 return constants.ERROR_STR
141 nodeId3 = util.getOvsdbNodeIdByName("sw7")
142 if nodeId1 == constants.ERROR_STR:
143 return constants.ERROR_STR
145 for inputData in tenant_3EPG_demo.get_endpoint_location_data(nc_id1a, nc_id1b, nc_id2a, nc_id2b, nc_id3a, nc_id3b, nodeId1, nodeId2, nodeId3):
146 result = util.runRequestPOST(inputsGBP.get_endpoint_location_uri(), json.dumps(inputData), sys._getframe().f_code.co_name)
150 #===============================================================================#
151 BRIDGE_REF_P="/network-topology:network-topology/network-topology:topology[network-topology:topology-id='ovsdb:1']/network-topology:node[network-topology:node-id='%s']"
152 TP_REF_P="/network-topology:network-topology/network-topology:topology[network-topology:topology-id='ovsdb:1']/network-topology:node[network-topology:node-id='%s']/network-topology:termination-point[network-topology:tp-id='%s']"
153 def epMigrationDemo(desc):
155 fabricId = "fabric:1"
156 mac = "00:00:00:00:35:03"
158 resp = util.runRequestGET(inputsFabric.get_epList_uri(), sys._getframe().f_code.co_name)
159 if resp == constants.ERROR_STR:
160 print "ERROR: getOvsdbNodeIdByName() failed"
161 return constants.ERROR_STR
166 endpointResp=json.loads(resp)
167 if endpointResp.has_key("endpoints"):
168 endpoints = endpointResp["endpoints"]
169 if endpoints.has_key("endpoint"):
170 for endpoint in endpoints["endpoint"]:
171 if endpoint["ip-address"] == ip:
172 eplist.append(endpoint["endpoint-uuid"])
173 logicLocation = endpoint["logic-location"]
174 lswId = logicLocation["node-id"]
175 lport = logicLocation["tp-id"]
178 result = util.runRequestPOST(inputsFabric.get_unregister_endpoint_uri(), json.dumps(inputsFabric.get_unregister_endpoint_data("fabric:1", eplist)), sys._getframe().f_code.co_name)
181 fabricId = "fabric:1"
182 mac = "00:00:00:00:35:04"
186 nodeid = util.getOvsdbNodeIdByName("sw6")
187 nodeRef = BRIDGE_REF_P % (nodeid)
188 tpRef = TP_REF_P % (nodeid, port)
190 if nodeid == constants.ERROR_STR:
191 return constants.ERROR_STR
193 result = util.runRequestPOST(inputsFabric.get_register_endpoint_uri(), json.dumps(inputsFabric.get_register_endpoint_data(fabricId, mac, ip, gw, lswId, lport, nodeRef, tpRef)), sys._getframe().f_code.co_name)
197 #===============================================================================#
198 testCases_ga = {'0': (printTestCase, 'Print test case table'),
199 'p1': (getTopology, 'Print Topology'),
200 'vc05': (registerEndpointLocation_acl, 'Register endpoint locations for Layer 3 ULN with ACL'),
201 'vc052': (registerEndpointLocation_sfc, 'Register endpoint locations for Layer 3 ULN with SFC'),
202 'vc053': (registerEndpointLocation_3epg_sfc, 'Register endpoint locations for 3EPG-Layer3-ULN with SFC'),
203 'vc054': (registerEndpointLocation_3epg_sfc_acl, 'Register 6 endpoints locations for 3EPG-Layer3-ULN with SFC'),
204 'vc064': (epMigrationDemo, 'EP Migration from h35-3 on sw1 to h35-4 on sw6'),
209 inputsFabric.fa001Url_gc,
210 inputsFabric.rpc_compose_fabric_data(),
213 inputsFabric.fa002Url_gc,
214 inputsFabric.rpc_create_logic_switch_data("lsw001", 100, "fabric:1"),
215 'Create LSW on Fabric'),
217 inputsFabric.fa003Url_gc,
218 inputsFabric.rpc_create_logic_router_data("lr001", "fabric:1"),
219 'Create LR on Fabric'),
221 inputsVcontainer.vc001Url_gc,
222 inputsVcontainer.rpc_create_vcontainer_data(inputsCommon.tenant1Id_gc, "fabric:1"),
223 'create vcontainer with one Fabric'),
225 inputsVcontainer.vc002Url_gc,
226 inputsVcontainer.rpc_netnode_create_lsw_data(inputsCommon.tenant1Id_gc, "fabric:1"),
227 'Create NetNode LSW'),
229 inputsVcontainer.vc003Url_gc,
230 inputsVcontainer.rpc_netnode_create_lr_data(inputsCommon.tenant1Id_gc, "fabric:1"),
231 'Create NetNode LR'),
233 inputsGBP.get_tenant_uri(inputsCommon.tenant1Id_gc),
234 inputsGBP.get_tenant_data_layer3_acl(inputsCommon.tenant1Id_gc),
235 'Create tenant policy for a Layer 3 ULN with ACL'),
237 inputsGBP.get_tenant_uri(inputsCommon.tenant1Id_gc),
238 inputsGBP.get_tenant_data_layer2_acl(inputsCommon.tenant1Id_gc),
239 'Create tenant of Layer 2 ULN with ACL'),
241 inputsGBP.get_tenant_uri(inputsCommon.tenant1Id_gc),
242 tenant_2EPG_SFC.get_tenant_data(inputsCommon.tenant1Id_gc),
243 'Create tenant of Layer 3 ULN with SFC'),
245 inputsGBP.get_tenant_uri(inputsCommon.tenant1Id_gc),
246 tenant_3EPG_SFC.get_tenant_data(inputsCommon.tenant1Id_gc),
247 'Create 3-EPG tenant of Layer 3 ULN with SFC'),
249 inputsGBP.get_tenant_uri(inputsCommon.tenant1Id_gc),
250 tenant_3EPG_demo.get_tenant_data(inputsCommon.tenant1Id_gc),
251 'Create 3-EPG tenant of Layer 3 ULN with SFC and ACL and 6 endpoints'),
252 'vc04': (post_data_array_c,
253 inputsGBP.get_endpoint_uri(),
254 inputsGBP.get_endpoint_data_layer3(inputsCommon.tenant1Id_gc),
255 'Register endpoints for Layer 3 ULN with ACL'),
257 inputsGBP.get_endpoint_uri(),
258 inputsGBP.get_endpoint_data(inputsCommon.tenant1Id_gc),
259 'Register endpoints on Layer 2 ULN with ACL'),
260 'vc042': (post_data_array_c,
261 inputsGBP.get_endpoint_uri(),
262 tenant_2EPG_SFC.get_endpoint_data(inputsCommon.tenant1Id_gc),
263 'Register endpoints for Layer 3 ULN with SFC'),
264 'vc043': (post_data_array_c,
265 inputsGBP.get_endpoint_uri(),
266 tenant_3EPG_SFC.get_endpoint_data(inputsCommon.tenant1Id_gc),
267 'Register endpoints for 3EPG-Layer3-ULN with SFC'),
268 'vc044': (post_data_array_c,
269 inputsGBP.get_endpoint_uri(),
270 tenant_3EPG_demo.get_endpoint_data(inputsCommon.tenant1Id_gc),
271 'Register 6 endpoints for 3EPG-Layer3-ULN with SFC and ACL'),
272 'vc051': (post_data_array_c,
273 inputsGBP.get_endpoint_location_uri(),
274 inputsGBP.get_endpoint_location_data_old(),
275 'Register endpoint locations for Layer 3 ULN with ACL in sanity environment (i.e., no ovs running)'),
277 inputsGBP.get_unreg_endpoint_uri(),
278 inputsGBP.get_unreg_endpoint_data_layer3(),
279 'Unregister endpoints on Layer 3 ULN'),
281 inputsGBP.get_tenant_uri(inputsCommon.tenant1Id_gc),
283 'Delete tenant of Layer 3 ULN'),
285 inputsGBP.getLogicalNetworksUri_gc,
287 'Get the logical network entities for all tenants on the uln-mapper side'),
289 inputsGBP.getUlnUri_gc,
291 'Get ULN on the GBP Faas renderer side'),
293 inputsGBP.getMappedEntities_gc,
295 'Get mapped IDs on the GBP FAAS renderer side'),
297 inputsSFC.get_acl_uri(),
301 inputsSFC.get_invmgr_uri(),
305 inputsSFC.get_sfcList_uri(),
309 inputsSFC.get_sfList_uri(),
313 inputsSFC.get_sffList_uri(),
315 'Get service function forwarder(SFF) list'),
317 inputsSFC.get_sfpList_uri(),
319 'Get service function paths'),
321 inputsFabric.get_epList_uri(),
323 'Get registered endpoint list'),
325 inputsSFC.get_acl_uri(),
326 inputsSFC.get_acl_data(),
329 inputsSFC.get_acl_uri(),
330 inputsSFC.get_acl_data2(),
341 opts, args = getopt.getopt(argv,"hi:o:t:n:",["ifile=","ofile=","testcase=", "netnode="])
342 except getopt.GetoptError:
343 print 'test.py -i <inputfile> -o <outputfile>'
345 for opt, arg in opts:
347 print 'test.py -i <inputfile> -o <outputfile> -t <num>'
349 elif opt in ("-i", "--ifile"):
351 elif opt in ("-o", "--ofile"):
353 elif opt in ("-t", "--testcase"):
357 assert False, "unhandled option"
359 #workName = raw_input('Please enter a work name:')
360 res = util.setupAuthentication()
362 if res != constants.OK_STR:
365 if testNum in testCases2_ga.keys():
366 print testCases2_ga[testNum][3]
367 if testCases2_ga[testNum][0] == put_c:
368 result = util.runRequestPUT(testCases2_ga[testNum][1], json.dumps(testCases2_ga[testNum][2]), sys._getframe().f_code.co_name)
369 elif testCases2_ga[testNum][0] == post_c:
370 #print json.dumps(testCases2_ga[testNum][2])
371 result = util.runRequestPOST(testCases2_ga[testNum][1], json.dumps(testCases2_ga[testNum][2]), sys._getframe().f_code.co_name)
372 elif testCases2_ga[testNum][0] == post_data_array_c:
373 #print json.dumps(testCases2_ga[testNum][2])
374 for inputData in (testCases2_ga[testNum][2]):
375 result = util.runRequestPOST(testCases2_ga[testNum][1], json.dumps(inputData), sys._getframe().f_code.co_name)
376 elif testCases2_ga[testNum][0] == get_c:
377 result = util.runRequestGET(testCases2_ga[testNum][1], sys._getframe().f_code.co_name)
379 elif testCases2_ga[testNum][0] == delete_c:
380 result = util.runRequestDELETE(testCases2_ga[testNum][1], sys._getframe().f_code.co_name)
383 result = testCases_ga[testNum][0](testCases_ga[testNum][1])
387 #===============================================================================#
390 if __name__ == "__main__":