blob: 7ddd53237f335f6fec5c0a1b8888ac9c6fa0281f [file] [log] [blame]
shahshreyab512cd02015-01-27 17:01:47 -08001
2#Testing the basic functionality of ONOS Next
3#For sanity and driver functionality excercises only.
4
5import time
6import sys
7import os
8import re
9import time
10import json
11
12time.sleep(1)
13class OpticalFunc13:
14 def __init__(self):
15 self.default = ''
16
17 def CASE1(self, main):
18 '''
19 Startup sequence:
20 git pull
21 mvn clean install
22 onos-package
23 cell <name>
24 onos-verify-cell
25 onos-install -f
26 onos-wait-for-start
27 '''
28
29 cell_name = main.params['ENV']['cellName']
30 ONOS1_ip = main.params['CTRL']['ip1']
31 ONOS1_port = main.params['CTRL']['port1']
32
33 main.case("Setting up test environment")
34
35 main.step("Git checkout and pull master and get version")
36 main.ONOSbench.git_checkout("master")
37 git_pull_result = main.ONOSbench.git_pull()
38 print "git_pull_result = ", git_pull_result
39 version_result = main.ONOSbench.get_version()
40 main.log.report(main.ONOSbench.get_version())
41 if git_pull_result == 1:
42 main.step("Using mvn clean & install")
43 clean_install_result = main.ONOSbench.clean_install()
44 #clean_install_result = main.TRUE
45
46 main.step("Applying cell variable to environment")
47 cell_result1 = main.ONOSbench.set_cell(cell_name)
48 verify_result = main.ONOSbench.verify_cell()
49 cell_result2 = main.ONOS2.set_cell(cell_name)
50 #verify_result = main.ONOS2.verify_cell()
51 main.ONOS2.start_onos_cli(ONOS_ip=main.params['CTRL']['ip1'])
52
53 cell_result = cell_result1 and cell_result2
54
55 main.step("Creating ONOS package")
56 package_result = main.ONOSbench.onos_package()
57
58 #main.step("Creating a cell")
59 #cell_create_result = main.ONOSbench.create_cell_file(**************)
60
61 main.step("Installing ONOS package")
62 onos_install_result = main.ONOSbench.onos_install()
63 onos1_isup = main.ONOSbench.isup()
64
65 main.step("Starting ONOS service")
66 start_result = main.ONOSbench.onos_start(ONOS1_ip)
67
68 case1_result = (package_result and\
69 cell_result and verify_result and onos_install_result and\
70 onos1_isup and start_result )
71 utilities.assert_equals(expect=main.TRUE, actual=case1_result,
72 onpass="Test startup successful",
73 onfail="Test startup NOT successful")
74
75 def CASE11(self, main):
76 '''
77 Cleanup sequence:
78 onos-service <node_ip> stop
79 onos-uninstall
80
81 TODO: Define rest of cleanup
82
83 '''
84
85 ONOS1_ip = main.params['CTRL']['ip1']
86
87 main.case("Cleaning up test environment")
88
89 main.step("Testing ONOS kill function")
90 kill_result = main.ONOSbench.onos_kill(ONOS1_ip)
91
92 main.step("Stopping ONOS service")
93 stop_result = main.ONOSbench.onos_stop(ONOS1_ip)
94
95 main.step("Uninstalling ONOS service")
96 uninstall_result = main.ONOSbench.onos_uninstall()
97
98
99 def CASE21(self, main):
100 import time
101 '''
102 On ONOS bench, run this command: ./~/ONOS/tools/test/bin/onos-topo-cfg
103 which starts the rest and copies the links json file to the onos instance
104 Note that in case of Packet Optical, the links are not learnt from the topology, instead the links are learnt
105 from the json config file
106 '''
107 main.log.report("This testcase starts the packet layer topology and REST")
108 main.log.report("_____________________________________________")
109 sart_console_result = main.LincOE1.start_console()
110 optical_mn_script = main.LincOE2.run_optical_mn_script()
111 onos_topo_cfg_result = main.ONOSbench.run_onos_topo_cfg(instance_name = main.params['CTRL']['ip1'], json_file = main.params['OPTICAL']['jsonfile'])
112
113
114
115 def CASE22(self, main):
116 '''
117 Curretly we use, 4 linear switch optical topology and 2 packet layer mininet switches each with one host.
118 Therefore, the roadmCount variable = 4, packetLayerSWCount variable = 2, hostCount =2
119 and this is hardcoded in the testcase. If the topology changes, these hardcoded values need to be changed
120 '''
121
122 main.log.report("This testcase compares the optical+packet topology against what is expected")
123 main.ONOS2.start_onos_cli(ONOS_ip=main.params['CTRL']['ip1'])
124 devices_result = main.ONOS2.devices(json_format = False)
125
126 print "devices_result = ", devices_result
127 devices_linewise = devices_result.split("\n")
128 devices_linewise = devices_linewise[1:-1]
129 roadmCount = 0
130 packetLayerSWCount = 0
131 for line in devices_linewise:
132 components = line.split(",")
133 availability = components[1].split("=")[1]
134 type = components[3].split("=")[1]
135 if availability == 'true' and type == 'ROADM':
136 roadmCount += 1
137 elif availability == 'true' and type =='SWITCH':
138 packetLayerSWCount += 1
139 if roadmCount == 4:
140 print "Number of Optical Switches = %d and is correctly detected" %roadmCount
141 main.log.info ("Number of Optical Switches = " +str(roadmCount) +" and is correctly detected")
142 opticalSW_result = main.TRUE
143 else:
144 print "Number of Optical Switches = %d and is wrong" %roadCount
145 main.log.info ("Number of Optical Switches = " +str(roadmCount) +" and is wrong")
146 opticalSW_result = main.FALSE
147
148 if packetLayerSWCount == 2:
149 print "Number of Packet layer or mininet Switches = %d and is correctly detected" %packetLayerSWCount
150 main.log.info("Number of Packet layer or mininet Switches = " +str(packetLayerSWCount) + " and is correctly detected")
151 packetSW_result = main.TRUE
152 else:
153 print "Number of Packet layer or mininet Switches = %d and is wrong" %packetLayerSWCount
154 main.log.info("Number of Packet layer or mininet Switches = " +str(packetLayerSWCount) + " and is wrong")
155 packetSW_result = main.FALSE
156 print "_________________________________"
157
158 links_result = main.ONOS2.links(json_format = False)
159 print "links_result = ", links_result
160 print "_________________________________"
161
162
163
164 #Discover hosts using pingall
165 pingall_result = main.LincOE2.pingall()
166
167 hosts_result = main.ONOS2.hosts(json_format = False)
168 print "hosts_result = ", hosts_result
169 print "_________________________________"
170 hosts_linewise = hosts_result.split("\n")
171 hosts_linewise = hosts_linewise[1:-1]
172 hostCount = 0
173 for line in hosts_linewise:
174 hostid = line.split(",")[0].split("=")[1]
175 hostCount +=1
176 if hostCount ==2:
177 print "Number of hosts = %d and is correctly detected" %hostCount
178 main.log.info("Number of hosts = " + str(hostCount) +" and is correctly detected")
179 hostDiscovery = main.TRUE
180 else:
181 print "Number of hosts = %d and is wrong" %hostCount
182 main.log.info("Number of hosts = " + str(hostCount) +" and is wrong")
183 hostDiscovery = main.FALSE
184
185 case22_result = opticalSW_result and packetSW_result and hostDiscovery
186 utilities.assert_equals(expect=main.TRUE, actual=case22_result,
187 onpass="Packet optical topology discovery successful",
188 onfail="Packet optical topology discovery failed")
189
190 def CASE23(self, main):
191 import time
192 '''
193 Add bidirectional point intents between 2 packet layer(mininet) devices and
194 ping mininet hosts
195 '''
196 main.log.report("This testcase adds bidirectional point intents between 2 packet layer(mininet) devices and ping mininet hosts")
197 ptp_intent_result = main.ONOS2.add_point_intent("of:0000ffffffff0001", 1, "of:0000ffffffff0002", 1)
198 if ptp_intent_result == main.TRUE:
199 get_intent_result = main.ONOS2.intents()
200 main.log.info("Point to point intent install successful")
201 main.log.info(get_intent_result)
202
203 ptp_intent_result = main.ONOS2.add_point_intent("of:0000ffffffff0002", 1, "of:0000ffffffff0001", 1)
204 if ptp_intent_result == main.TRUE:
205 get_intent_result = main.ONOS2.intents()
206 main.log.info("Point to point intent install successful")
207 main.log.info(get_intent_result)
208
209 time.sleep(10)
210 flowHandle = main.ONOS2.flows()
211 #print "flowHandle = ", flowHandle
212 main.log.info("flows :" + flowHandle)
213 intentHandle = main.ONOS2.intents()
214 main.log.info("intents :" + intentHandle)
215
216 Ping_Result = main.TRUE
217 count = 1
218 main.log.info("\n\nh1 is Pinging h2")
219 ping = main.LincOE2.pingHostOptical(src="h1", target="h2")
220 #ping = main.LincOE2.pinghost()
221 if ping == main.FALSE and count<5:
222 count+=1
223 Ping_Result = main.FALSE
224 main.log.report("Ping between h1 and h2 failed. Making attempt number "+str(count) + " in 2 seconds")
225 time.sleep(2)
226 ping = main.LincOE2.pingHostOptical(src="h1", target="h2")
227 #ping = main.LincOE2.pinghost()
228 elif ping==main.FALSE:
229 main.log.report("All ping attempts between h1 and h2 have failed")
230 Ping_Result = main.FALSE
231 elif ping==main.TRUE:
232 main.log.info("Ping test between h1 and h2 passed!")
233 Ping_Result = main.TRUE
234 else:
235 main.log.info("Unknown error")
236 Ping_Result = main.ERROR
237
238 if Ping_Result==main.FALSE:
239 main.log.report("Point intents for packet optical have not ben installed correctly. Cleaning up")
240 if Ping_Result==main.TRUE:
241 main.log.report("Point Intents for packet optical have been installed correctly")
242
243 case23_result = Ping_Result
244 utilities.assert_equals(expect=main.TRUE, actual=case23_result,
245 onpass="Point intents addition for packet optical and Pingall Test successful",
246 onfail="Point intents addition for packet optical and Pingall Test NOT successful")
247
248