blob: 5a21d48a91a05dd669d12a227774d6fc3d81617b [file] [log] [blame]
Andrew809df1c2014-06-27 14:28:53 -07001
2class RCOnosSanity :
3
4 def __init__(self) :
5 self.default = ''
6
7#*****************************************************************************************************************************************************************************************
8#Test startup
9#Tests the startup of Zookeeper1, RamCloud1, and ONOS1 to be certain that all started up successfully
10 def CASE1(self,main) : #Check to be sure ZK, Cass, and ONOS are up, then get ONOS version
11 import time
12 main.ONOS.start()
13 time.sleep(20)
Andrew04677bd2014-07-01 14:31:01 -070014 main.ONOS.rest_stop()
Andrew809df1c2014-06-27 14:28:53 -070015 main.ONOS.start_rest()
16 test= main.ONOS.rest_status()
17 if test == main.FALSE:
18 main.ONOS.start_rest()
19 main.ONOS.get_version()
20 main.log.report("Started Zookeeper, RamCloud, and ONOS")
21 main.case("Checking if the startup was clean...")
22 main.step("Testing Zookeeper Status")
23 data = main.ONOS.zk_status()
24 utilities.assert_equals(expect=main.TRUE,actual=data,onpass="Zookeeper is up!",onfail="Zookeeper is down...")
25 main.step("Testing Ramcloud Coord Status")
26 data = main.ONOS.rcc_status()
27 utilities.assert_equals(expect=main.TRUE,actual=data,onpass="Ramcloud Coord is up!",onfail="Ramcloud Coord is down...")
28 main.step("Testing Ramcloud Server Status")
29 data = main.ONOS.rcs_status()
30 utilities.assert_equals(expect=main.TRUE,actual=data,onpass="Ramcloud Server is up!",onfail="Ramcloud Server is down...")
31 main.step("Testing ONOS Status")
32 data = main.ONOS.status()
33 utilities.assert_equals(expect=main.TRUE,actual=data,onpass="ONOS is up!",onfail="ONOS is down...")
34 main.step("Testing Rest Status")
35 data = main.ONOS.rest_status()
36 utilities.assert_equals(expect=main.TRUE,actual=data,onpass="REST is up!",onfail="REST is down...")
37
38#**********************************************************************************************************************************************************************************************
39#Assign Controllers
40#This test first checks the ip of a mininet host, to be certain that the mininet exists(Host is defined #inParams as <CASE1><destination>).
41#Then the program assignes each ONOS instance a single controller to a switch(To be the initial master), then #assigns all controllers.
42
43 def CASE2(self,main) : #Make sure mininet exists, then assign controllers to switches
44 import time
Jon Hallca8792c2014-07-16 09:40:13 -070045 main.log.report("Check if mininet started properly, then assign the switches to ONOS")
Andrew809df1c2014-06-27 14:28:53 -070046 main.case("Checking if one MN host exists")
47 main.step("Host IP Checking using checkIP")
48 result = main.Mininet.checkIP(main.params['CASE1']['destination'])
49 main.step("Verifying the result")
50 utilities.assert_equals(expect=main.TRUE,actual=result,onpass="Host IP address configured",onfail="Host IP address not configured")
51 main.step("assigning ONOS controller to switches")
52 for i in range(25):
53 if i < 15:
54 j=i+1
55 main.Mininet.assign_sw_controller(sw=str(j),ip1=main.params['CTRL']['ip1'],port1=main.params['CTRL']['port1'])
56 else:
57 j=i+16
58 main.Mininet.assign_sw_controller(sw=str(j),ip1=main.params['CTRL']['ip1'],port1=main.params['CTRL']['port1'])
Andrew04677bd2014-07-01 14:31:01 -070059 #time.sleep(1)
Andrew809df1c2014-06-27 14:28:53 -070060 main.Mininet.get_sw_controller("s1")
61
62# **********************************************************************************************************************************************************************************************
63#Add Flows
64#Deletes any remnant flows from any previous test, add flows from the file labeled <FLOWDEF>, then runs the #check flow test
65
66 def CASE3(self,main) : #Delete any remnant flows, then add flows, and time how long it takes flow tables to update
67 main.log.report("Delete any flows from previous tests, then add flows from FLOWDEF file, then wait for switch flow tables to update")
68 import time
69 main.case("Taking care of these flows!")
70 main.step("Cleaning out any leftover flows...")
71 main.ONOS.delete_flow(main.params['INTENTS']['rem'], main.params['FLOWDEF'])
72 strtTime = time.time()
73 main.ONOS.add_flow(main.params['INTENTS']['add'], main.params['FLOWDEF'])
74 main.case("Checking flows")
75
76 count = 1
77 i = 6
78 while i < 16 :
79 main.log.info("\n\t\t\t\th"+str(i)+" IS PINGING h"+str(i+25) )
80 ping = main.Mininet.pingHost(SRC="h"+str(i),TARGET="h"+str(i+25))
81 if ping == main.FALSE and count < 9:
82 count = count + 1
83 i = 6
84 main.log.info("Ping failed, making attempt number "+str(count)+" in 2 seconds")
85 time.sleep(2)
86 elif ping == main.FALSE and count ==9:
87 main.log.error("Ping test failed")
88 i = 17
89 result = main.FALSE
90 elif ping == main.TRUE:
91 i = i + 1
92 result = main.TRUE
93 endTime = time.time()
94 if result == main.TRUE:
95 main.log.report("\tTime to add flows: "+str(round(endTime-strtTime,2))+" seconds")
96 else:
97 main.log.report("\tFlows failed check")
98
99 result2 = main.ONOS.check_status_report(main.params['RestIP'],main.params['NR_Switches'],main.params['NR_Links'])
100 main.step("Verifying the result")
101 utilities.assert_equals(expect=main.TRUE,actual=result,onpass="Flow check PASS",onfail="Flow check FAIL")
102
Andrew809df1c2014-06-27 14:28:53 -0700103##########*****************************************************
104 def CASE4(self,main) :
105 main.log.report("Remove ONOS 2,3,4 then ping until all hosts are reachable or fail after 6 attempts")
106 import time
107 for i in range(25):
108 if i < 15:
109 j=i+1
110 main.Mininet.assign_sw_controller(sw=str(j),ip1=main.params['CTRL']['ip1'],port1=main.params['CTRL']['port1'])
111 else:
112 j=i+16
113 main.Mininet.assign_sw_controller(sw=str(j),ip1=main.params['CTRL']['ip1'],port1=main.params['CTRL']['port1'])
114 strtTime = time.time()
115 result = main.ONOS.check_status_report(main.params['RestIP'],main.params['NR_Switches'],main.params['NR_Links'])
116 for i in range(10):
117 if result == main.FALSE:
118 time.sleep(5)
119 result = main.ONOS.check_status_report(main.params['RestIP'],main.params['NR_Switches'],main.params['NR_Links'])
120 else:
121 break
122 count = 1
123 i = 6
124 while i < 16 :
125 main.log.info("\n\t\t\t\th"+str(i)+" IS PINGING h"+str(i+25) )
126 ping = main.Mininet.pingHost(src="h"+str(i),target="h"+str(i+25))
127 if ping == main.FALSE and count < 6:
128 count = count + 1
129 i = 6
130 main.log.info("Ping failed, making attempt number "+str(count)+" in 2 seconds")
131 time.sleep(2)
132 elif ping == main.FALSE and count ==6:
133 main.log.error("Ping test failed")
134 i = 17
135 result = main.FALSE
136 elif ping == main.TRUE:
137 i = i + 1
138 result = main.TRUE
139 endTime = time.time()
140 if result == main.TRUE:
141 main.log.report("\tTime to complete ping test: "+str(round(endTime-strtTime,2))+" seconds")
142 else:
143 main.log.report("\tPING TEST FAIL")
144 utilities.assert_equals(expect=main.TRUE,actual=result,onpass="NO PACKET LOSS, HOST IS REACHABLE",onfail="PACKET LOST, HOST IS NOT REACHABLE")
145 time.sleep(10)
146
147# **********************************************************************************************************************************************************************************************
148#This test case restores the controllers removed by Case 4 then performs a ping test.
149
150 def CASE5(self,main) :
151 main.log.report("Restore ONOS 2,3,4 then ping until all hosts are reachable or fail after 6 attempts")
152 import time
153 for i in range(25):
154 if i < 15:
155 j=i+1
156 main.Mininet.assign_sw_controller(sw=str(j),ip1=main.params['CTRL']['ip1'],port1=main.params['CTRL']['port1'])
157 else:
158 j=i+16
159 main.Mininet.assign_sw_controller(sw=str(j),ip1=main.params['CTRL']['ip1'],port1=main.params['CTRL']['port1'])
160 strtTime = time.time()
161 result = main.ONOS.check_status_report(main.params['RestIP'],main.params['NR_Switches'],main.params['NR_Links'])
162 for i in range(2):
163 if result == main.FALSE:
164 time.sleep(5)
165 result = main.ONOS.check_status_report(main.params['RestIP'],main.params['NR_Switches'],main.params['NR_Links'])
166 else:
167 break
168 count = 1
169 i = 6
170 while i < 16 :
171 main.log.info("\n\t\t\t\th"+str(i)+" IS PINGING h"+str(i+25) )
172 ping = main.Mininet.pingHost(src="h"+str(i),target="h"+str(i+25))
173 if ping == main.FALSE and count < 6:
174 count = count + 1
175 i = 6
176 main.log.info("Ping failed, making attempt number "+str(count)+" in 2 seconds")
177 time.sleep(2)
178 elif ping == main.FALSE and count ==6:
179 main.log.error("Ping test failed")
180 i = 17
181 result = main.FALSE
182 elif ping == main.TRUE:
183 i = i + 1
184 result = main.TRUE
185 endTime = time.time()
186 if result == main.TRUE:
187 main.log.report("\tTime to complete ping test: "+str(round(endTime-strtTime,2))+" seconds")
188 else:
189 main.log.report("\tPING TEST FAILED")
190 utilities.assert_equals(expect=main.TRUE,actual=result,onpass="NO PACKET LOSS, HOST IS REACHABLE",onfail="PACKET LOST, HOST IS NOT REACHABLE")
191# #**********************************************************************************************************************************************************************************************
192#Brings a link that all flows pass through in the mininet down, then runs a ping test to view reroute time
193
194 def CASE6(self,main) :
195 main.log.report("Bring Link between s1 and s2 down, then ping until all hosts are reachable or fail after 10 attempts")
196 import time
197 main.case("Bringing Link down... ")
198 result = main.Mininet.link(END1=main.params['LINK']['begin'],END2=main.params['LINK']['end'],OPTION="down")
199 utilities.assert_equals(expect=main.TRUE,actual=result,onpass="Link DOWN!",onfail="Link not brought down...")
200
201 strtTime = time.time()
202 result = main.ONOS.check_status_report(main.params['RestIP'],main.params['NR_Switches'],str(int(main.params['NR_Links'])-2))
203 for i in range(2):
204 if result == main.FALSE:
205 time.sleep(5)
206 result = main.ONOS.check_status_report(main.params['RestIP'],main.params['NR_Switches'],str(int(main.params['NR_Links'])-2))
207 else:
208 break
209 count = 1
210 i = 6
211 while i < 16 :
212 main.log.info("\n\t\t\t\th"+str(i)+" IS PINGING h"+str(i+25) )
213 ping = main.Mininet.pingHost(src="h"+str(i),target="h"+str(i+25))
214 if ping == main.FALSE and count < 10:
215 count = count + 1
216 main.log.info("Ping failed, making attempt number "+str(count)+" in 2 seconds")
217 i = 6
218 time.sleep(2)
219 elif ping == main.FALSE and count == 10:
220 main.log.error("Ping test failed")
221 i = 17
222 result = main.FALSE
223 elif ping == main.TRUE:
224 i = i + 1
225 result = main.TRUE
226 endTime = time.time()
227 if result == main.TRUE:
228 main.log.report("\tTime to complete ping test: "+str(round(endTime-strtTime,2))+" seconds")
229 else:
230 main.log.report("\tPING TEST FAILED")
231 utilities.assert_equals(expect=main.TRUE,actual=result,onpass="NO PACKET LOSS, HOST IS REACHABLE",onfail="PACKET LOST, HOST IS NOT REACHABLE")
232# #**********************************************************************************************************************************************************************************************
233#Brings the link that Case 6 took down back up, then runs a ping test to view reroute time
234
235 def CASE7(self,main) :
236 main.log.report("Bring Link between s1 and s2 up, then ping until all hosts are reachable or fail after 10 attempts")
237 import time
238 main.case("Bringing Link up... ")
239 result = main.Mininet.link(END1=main.params['LINK']['begin'],END2=main.params['LINK']['end'],OPTION="up")
240 utilities.assert_equals(expect=main.TRUE,actual=result,onpass="Link UP!",onfail="Link not brought up...")
241 strtTime = time.time()
242 result = main.ONOS.check_status_report(main.params['RestIP'],main.params['NR_Switches'],main.params['NR_Links'])
243 for i in range(2):
244 if result == main.FALSE:
245 time.sleep(5)
246 result = main.ONOS.check_status_report(main.params['RestIP'],main.params['NR_Switches'],main.params['NR_Links'])
247 else:
248 break
249 strtTime = time.time()
250 count = 1
251 i = 6
252 while i < 16 :
253 main.log.info("\n\t\t\t\th"+str(i)+" IS PINGING h"+str(i+25) )
254 ping = main.Mininet.pingHost(src="h"+str(i),target="h"+str(i+25))
255 if ping == main.FALSE and count < 10:
256 count = count + 1
257 main.log.info("Ping failed, making attempt number "+str(count)+" in 2 seconds")
258 i = 6
259 time.sleep(2)
260 elif ping == main.FALSE and count ==10:
261 main.log.error("Ping test failed")
262 i = 17
263 result = main.FALSE
264 elif ping == main.TRUE:
265 i = i + 1
266 result = main.TRUE
267 endTime = time.time()
268 if result == main.TRUE:
269 main.log.report("\tTime to complete ping test: "+str(round(endTime-strtTime,2))+" seconds")
270 else:
271 main.log.report("\tPING TESTS FAILED")
272 utilities.assert_equals(expect=main.TRUE,actual=result,onpass="NO PACKET LOSS, HOST IS REACHABLE",onfail="PACKET LOST, HOST IS NOT REACHABLE")
273# #******************************************************************************************************************************************************************
274# Test Device Discovery function by yanking s6:s6-eth0 interface and re-plug it into a switch
275
276 def CASE21(self,main) :
277 import json
278 main.log.report("Test device discovery function, by attach, detach, move host h1 from s1->s6->s1. Per mininet naming, switch port the host attaches will remain as 's1-eth1' throughout the test.")
279 main.log.report("Check initially hostMAC/IP exist on the mininet...")
280 host = main.params['YANK']['hostname']
281 mac = main.params['YANK']['hostmac']
282 hostip = main.params['YANK']['hostip']
283 RestIP1 = main.params['RESTCALL']['restIP1']
284 RestPort = main.params['RESTCALL']['restPort']
285 url = main.params['RESTCALL']['restURL']
286
287 t_topowait = 0
288 t_restwait = 10
289 main.log.report( "Wait time from topo change to ping set to " + str(t_topowait))
290 main.log.report( "Wait time from ping to rest call set to " + str(t_restwait))
291 #print "host=" + host + "; RestIP=" + RestIP1 + "; RestPort=" + str(RestPort)
292 time.sleep(t_topowait)
293 main.log.info("\n\t\t\t\t ping issue one ping from " + str(host) + " to generate arp to switch. Ping result is not important" )
294 ping = main.Mininet.pingHost(SRC = str(host),TARGET = "10.0.0.254")
295 time.sleep(t_restwait)
296 Reststatus, Switch, Port, MAC = main.ONOS.find_host(RestIP1,RestPort,url, hostip)
297 main.log.report("Number of host with IP=10.0.0.1 found by ONOS is: " + str(Reststatus))
298 if Reststatus == 1:
299 main.log.report("\t PASSED - Found host IP = " + hostip + "; MAC = " + "".join(MAC) + "; attached to switchDPID = " + "".join(Switch) + "; at port = " + "".join(Port))
300 result1 = main.TRUE
301 elif Reststatus > 1:
302 main.log.report("\t FAILED - Host " + host + " with MAC:" + mac + " has " + str(Reststatus) + " duplicated IP addresses. FAILED")
303 main.log.report("switches are: " + "; ".join(Switch))
304 main.log.report("Ports are: " + "; ".join(Port))
305 main.log.report("MACs are: " + "; ".join(MAC))
306 result1 = main.FALSE
307 else:
308 main.log.report("\t FAILED - Host " + host + " with MAC:" + mac + " does not exist. FAILED")
309 result1 = main.FALSE
310 ##### Step to yank out "s1-eth1" from s1, which is on autoONOS1 #####
311 main.log.report("Yank out s1-eth1")
312 main.step("Yankout s6-eth1 (link to h1) from s1")
313 result = main.Mininet.yank(SW=main.params['YANK']['sw1'],INTF=main.params['YANK']['intf'])
314 time.sleep(t_topowait)
315 utilities.assert_equals(expect=main.TRUE,actual=result,onpass="Yank command suceeded",onfail="Yank command failed...")
316
317 main.log.info("\n\t\t\t\t ping issue one ping from" + str(host) + "to generate arp to switch. Ping result is not important" )
318 ping = main.Mininet.pingHost(SRC = str(host),TARGET = "10.0.0.254")
319 time.sleep(t_restwait)
320 Reststatus, Switch, Port, MAC = main.ONOS.find_host(RestIP1,RestPort,url, hostip)
321
322 main.log.report("Number of host with IP=10.0.0.1 found by ONOS is: " + str(Reststatus))
323 if Reststatus == 1:
324 main.log.report("\tFAILED - Found host IP = " + hostip + "; MAC = " + "".join(MAC) + "; attached to switchDPID = " + "".join(Switch) + "; at port = " + "".join(Port))
325 result2 = main.FALSE
326 elif Reststatus > 1:
327 main.log.report("\t FAILED - Host " + host + " with MAC:" + str(mac) + " has " + str(Reststatus) + " duplicated IP addresses. FAILED")
328 main.log.report("switches are: " + "; ".join(Switch))
329 main.log.report("Ports are: " + "; ".join(Port))
330 main.log.report("MACs are: " + "; ".join(MAC))
331 result2 = main.FALSE
332 else:
333 main.log.report("\t PASSED - Host " + host + " with MAC:" + str(mac) + " does not exist. PASSED - host is not supposed to be attached to the switch.")
334 result2 = main.TRUE
335
336 ##### Step to plug "s1-eth1" to s6, which is on autoONOS3 ######
337 main.log.report("Plug s1-eth1 into s6")
338 main.step("Plug s1-eth1 to s6")
339 result = main.Mininet.plug(SW=main.params['PLUG']['sw6'],INTF=main.params['PLUG']['intf'])
340 time.sleep(t_topowait)
341 utilities.assert_equals(expect=main.TRUE,actual=result,onpass="Plug command suceeded",onfail="Plug command failed...")
342 main.log.info("\n\t\t\t\t ping issue one ping from" + str(host) + "to generate arp to switch. Ping result is not important" )
343
344 ping = main.Mininet.pingHost(src = str(host),target = "10.0.0.254")
345 time.sleep(t_restwait)
346 Reststatus, Switch, Port, MAC = main.ONOS.find_host(RestIP1,RestPort,url, hostip)
347
348 main.log.report("Number of host with IP=10.0.0.1 found by ONOS is: " + str(Reststatus))
349 if Reststatus == 1:
350 main.log.report("\tPASSED - Found host IP = " + hostip + "; MAC = " + "".join(MAC) + "; attached to switchDPID = " + "".join(Switch) + "; at port = " + "".join(Port))
351 result3 = main.TRUE
352 elif Reststatus > 1:
353 main.log.report("\t FAILED - Host " + host + " with MAC:" + str(mac) + " has " + str(Reststatus) + " duplicated IP addresses. FAILED")
354 main.log.report("switches are: " + "; ".join(Switch))
355 main.log.report("Ports are: " + "; ".join(Port))
356 main.log.report("MACs are: " + "; ".join(MAC))
357 result3 = main.FALSE
358 else:
359 main.log.report("\t FAILED - Host " + host + " with MAC:" + str(mac) + " does not exist. FAILED")
360 result3 = main.FALSE
361
362 ###### Step to put interface "s1-eth1" back to s1"#####
363 main.log.report("Move s1-eth1 back on to s1")
364 main.step("Move s1-eth1 back to s1")
365 result = main.Mininet.yank(SW=main.params['YANK']['sw6'],INTF=main.params['YANK']['intf'])
366 time.sleep(t_topowait)
367 result = main.Mininet.plug(SW=main.params['PLUG']['sw1'],INTF=main.params['PLUG']['intf'])
368 utilities.assert_equals(expect=main.TRUE,actual=result,onpass="Yank/Plug command suceeded",onfail="Yank/Plug command failed...")
369 main.log.info("\n\t\t\t\t ping issue one ping from" + str(host) + "to generate arp to switch. Ping result is not important" )
370
371 ping = main.Mininet.pingHost(src = str(host),target = "10.0.0.254")
372 time.sleep(t_restwait)
373 Reststatus, Switch, Port, MAC = main.ONOS.find_host(RestIP1,RestPort,url, hostip)
374
375 main.log.report("Number of host with IP=10.0.0.1 found by ONOS is: " + str(Reststatus))
376 if Reststatus == 1:
377 main.log.report("\tPASSED - Found host IP = " + hostip + "; MAC = " + "".join(MAC) + "; attached to switchDPID = " + "".join(Switch) + "; at port = " + "".join(Port))
378 result4 = main.TRUE
379 elif Reststatus > 1:
380 main.log.report("\t FAILED - Host " + host + " with MAC:" + str(mac) + " has " + str(Reststatus) + " duplicated IP addresses. FAILED")
381 main.log.report("switches are: " + "; ".join(Switch))
382 main.log.report("Ports are: " + "; ".join(Port))
383 main.log.report("MACs are: " + "; ".join(MAC))
384 result4 = main.FALSE
385 else:
386 main.log.report("\t FAILED -Host " + host + " with MAC:" + str(mac) + " does not exist. FAILED")
387 result4 = main.FALSE
388
389 result = result1 and result2 and result3 and result4
390 utilities.assert_equals(expect=main.TRUE,actual=result,onpass="DEVICE DISCOVERY TEST PASSED PLUG/UNPLUG/MOVE TEST",onfail="DEVICE DISCOVERY TEST FAILED")
391
392# Run a pure ping test.
393
394 def CASE31(self, main):
395 main.log.report("Performing Ping Test")
396 count = 1
397 i = 6
398 while i < 16 :
399 main.log.info("\n\t\t\t\th"+str(i)+" IS PINGING h"+str(i+25) )
400 strtTime = time.time()
401 ping = main.Mininet.pingHost(src="h"+str(i),target="h"+str(i+25))
402 if ping == main.FALSE and count < 6:
403 count = count + 1
404 i = 6
405 main.log.info("Ping failed, making attempt number "+str(count)+" in 2 seconds")
406 time.sleep(2)
407 elif ping == main.FALSE and count ==6:
408 main.log.error("Ping test failed")
409 i = 17
410 result = main.FALSE
411 elif ping == main.TRUE:
412 i = i + 1
413 result = main.TRUE
414 endTime = time.time()
415 if result == main.TRUE:
416 main.log.report("\tTime to complete ping test: "+str(round(endTime-strtTime,2))+" seconds")
417 else:
418 main.log.report("\tPING TEST FAIL")
419 utilities.assert_equals(expect=main.TRUE,actual=result,onpass="NO PACKET LOSS, HOST IS REACHABLE",onfail="PACKET LOST, HOST IS NOT REACHABLE")
420
421
422 def CASE200(self, main):
423 '''
424 POSTS 2 pre-set intents to the REST server and compares the REST server output to expected flows.
425 '''
426 import time
427 import requests
428 import json
429 import re
430 main.case("Testing Rest Status")
431
432 #----------------------
433
434 main.log.report("Starting Rest API Only Test")
435 main.log.report("Rest IP used: " + main.params['RestIP'])
436 restcall1 = "http://"+ main.params['RESTCALL']['restIP1'] + ":" + main.params['RESTCALL']['restPort'] + main.params['RESTCALL']['restURL']
437 restcall2 = "http://"+ main.params['RESTCALL']['restIP1'] + ":" + main.params['RESTCALL']['restPort'] + main.params['RESTCALL']['restURL2']
438 restcall3 = "http://"+ main.params['RESTCALL']['restIP1'] + ":" + main.params['RESTCALL']['restPort'] + main.params['RESTCALL']['restURL3']
439 restcall4 = "http://"+ main.params['RESTCALL']['restIP1'] + ":" + main.params['RESTCALL']['restPort'] + main.params['RESTCALL']['restURL4']
440
441 main.log.report("Rest Calls used: " + restcall1)
442 main.log.report("Rest Calls used: " + restcall2)
443 main.log.report("Rest Calls used: " + restcall3)
444 main.log.report("Rest Calls used: " + restcall4)
445
446 url = main.params['RESTTEST']['url']
447 #headers = main.params['RESTTEST']['head']
448 headers = {'Content-type': 'application/json', 'Accept': 'application/json'}
449 expSrcMac = main.params['RESTTEST']['srcMac']
450 expDstMac = main.params['RESTTEST']['dstMac']
451 expSrcSwitch = main.params['RESTTEST']['srcSwitch']
452 expDstSwitch = main.params['RESTTEST']['dstSwitch']
453 srcPort = main.params['RESTTEST']['srcPort']
454 dstPort = main.params['RESTTEST']['dstPort']
455 intID = int(main.params['RESTTEST']['intID'])
456
457 intent = [{'intent_id': '%d' %(intID),'intent_type':'shortest_intent_type','intent_op':'add','srcSwitch':expSrcSwitch,'srcPort':int(srcPort),'srcMac':expSrcMac,'dstSwitch':expDstSwitch,'dstPort':int(dstPort),'dstMac':expDstMac}]
458 r = requests.post(url, data=json.dumps(intent, sort_keys=True), headers = headers)
459
460 intent = [{'intent_id': '%d' %(intID+10),'intent_type':'shortest_intent_type','intent_op':'add','srcSwitch':expDstSwitch,'srcPort':int(dstPort),'srcMac':expDstMac,'dstSwitch':expSrcSwitch,'dstPort':int(srcPort),'dstMac':expSrcMac}]
461 r = requests.post(url, data=json.dumps(intent, sort_keys=True), headers = headers)
462
463 count = 0
464 main.step("Getting JSON...")
465 #r1 = main.ONOS.get_json_string(restcall1, expSrcSwitch, expDstSwitch, expSrcMac, expDstMac, srcPort, dstPort, intID)
466 r1 = main.ONOS.get_json(restcall1)
467 if re.search(expSrcSwitch, str(r1)) and re.search(expDstSwitch, str(r1)):
468 main.log.report("Restcall: "+restcall1)
469 main.log.report("Expected SrcSwitch "+expSrcSwitch+" found")
470 main.log.report("Expected DstSwitch "+expDstSwitch+" found")
471 count = count+1
472 #r2 = main.ONOS.get_json_string(restcall2, expSrcSwitch, expDstSwitch, expSrcMac, expDstMac, srcPort, dstPort, intID)
473 r2 = main.ONOS.get_json(restcall2)
474 if re.search("u\'srcMac\': u\'"+expSrcMac+"\'", str(r2)) and re.search("u\'dstMac\': u\'"+expDstMac+"\'", str(r2)):
475 main.log.report("Restcall: "+restcall2)
476 main.log.report("Expected SrcMac "+expSrcMac+" found")
477 main.log.report("Expected DstMac "+expDstMac+" found")
478 if re.search("u\'srcSwitchDpid\': u\'"+expSrcSwitch+"\'", str(r2)) and re.search("u\'dstSwitchDpid\': u\'"+expDstSwitch+"\'", str(r2)):
479 main.log.report("Expected SrcSwitch "+expSrcSwitch+" found")
480 main.log.report("Expected DstSwitch "+expDstSwitch+" found")
481 if re.search("u\'srcPortNumber\': u\'"+srcPort+"\'", str(r2)) and re.search("u\'dstPortNumber\': u\'"+dstPort+"\'", str(r2)):
482 main.log.report("Expected SrcPort "+srcPort+" found")
483 main.log.report("Expected DstPort "+dstPort+" found")
484 count = count+1
485 else:
486 main.log.report("Expected SrcPort "+srcPort+" NOT found")
487 main.log.report("Expected DstPort "+dstPort+" NOT found")
488 else:
489 main.log.report("Expected SrcSwitch "+expSrcSwitch+" NOT found")
490 main.log.report("Expected DstSwitch "+expDstSwitch+" NOT found")
491 else:
492 main.log.report("Expected SrcMac "+expSrcMac+" NOT found")
493 main.log.report("Expected DstMac "+expDstMac+" NOT found")
494 if count != 2:
495 main.log.report("Actual data: "+str(r2))
496
497 #r3 = main.ONOS.get_json_string(restcall3, expSrcSwitch, expDstSwitch, expSrcMac, expDstMac, srcPort, dstPort, intID)
498 r3 = main.ONOS.get_json(restcall3)
499 if re.search("", str(r3)):
500 main.log.report("Restcall: "+restcall3)
501 count = count+1
502
503 #r4 = main.ONOS.get_json_string(restcall4, expSrcSwitch, expDstSwitch, expSrcMac, expDstMac, srcPort, dstPort, intID)
504 r4 = main.ONOS.get_json(restcall4)
505 if re.search(expSrcSwitch, str(r4)) and re.search(expDstSwitch, str(r4)):
506 main.log.report("Restcall: "+restcall4)
507 main.log.report("Expected SrcSwitch: "+expSrcSwitch+" found")
508 main.log.report("Expected DstSwitch: "+expDstSwitch+" found")
509 count = count+1
510 else:
511 main.log.report("Expected SrcSwitch: "+expSrcSwitch+" NOT found")
512 main.log.report("Expected DstSwitch: "+expDstSwitch+" NOT found")
513
514 utilities.assert_equals(expect=4,actual=count,onpass="REST API test passed!",onfail="REST API test failed...")
515