blob: 8c166389ee171de01d4a6f3db7e9460c43805812 [file] [log] [blame]
pingping-lin86d9f512015-08-17 18:29:41 -07001# Testing the functionality of SDN-IP with single ONOS instance
2class SDNIPfunction:
3
4 def __init__(self):
5 self.default = ''
6 global branchName
7
8
9 # This case is to setup ONOS
10 def CASE100(self, main):
11 """
12 CASE100 is to compile ONOS and install it
13 Startup sequence:
14 cell <name>
15 onos-verify-cell
16 git pull
17 mvn clean install
18 onos-package
19 onos-install -f
20 onos-wait-for-start
21 """
22 main.case("Setting up test environment")
23
24 cellName = main.params[ 'ENV' ][ 'cellName' ]
25 ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
26
27 main.step("Applying cell variable to environment")
28 cellResult = main.ONOSbench.setCell(cellName)
29 verifyResult = main.ONOSbench.verifyCell()
30
31 branchName = main.ONOSbench.getBranchName()
32 main.log.info("ONOS is on branch: " + branchName)
33
34 main.log.report("Uninstalling ONOS")
35 main.ONOSbench.onosUninstall(ONOS1Ip)
36
37 # cleanInstallResult = main.TRUE
38 # gitPullResult = main.TRUE
39
40 main.step("Git pull")
41 gitPullResult = main.ONOSbench.gitPull()
42
43 main.step("Using mvn clean install")
44 if gitPullResult == main.TRUE:
45 cleanInstallResult = main.ONOSbench.cleanInstall(mciTimeout=1000)
46 else:
47 main.log.warn("Did not pull new code so skipping mvn " +
48 "clean install")
49 cleanInstallResult = main.TRUE
50
51 main.ONOSbench.getVersion(report=True)
52
53 main.step("Creating ONOS package")
54 packageResult = main.ONOSbench.onosPackage(opTimeout=500)
55
56 main.step("Installing ONOS package")
57 onos1InstallResult = main.ONOSbench.onosInstall(options="-f",
58 node=ONOS1Ip)
59
60 main.step("Checking if ONOS is up yet")
61 for i in range(2):
62 onos1Isup = main.ONOSbench.isup(ONOS1Ip, timeout=420)
63 if onos1Isup:
64 break
65 if not onos1Isup:
66 main.log.report("ONOS1 didn't start!")
67
68 cliResult = main.ONOScli.startOnosCli(ONOS1Ip,
69 commandlineTimeout=100, onosStartTimeout=600)
70
71 case1Result = (cleanInstallResult and packageResult and
72 cellResult and verifyResult and
73 onos1InstallResult and
74 onos1Isup and cliResult)
75
76 utilities.assert_equals(expect=main.TRUE, actual=case1Result,
77 onpass="ONOS startup successful",
78 onfail="ONOS startup NOT successful")
79
80 if case1Result == main.FALSE:
81 main.cleanup()
82 main.exit()
83
84 def CASE4(self, main):
85 """
86 Test the SDN-IP functionality
87 allRoutesExpected: all expected routes for all BGP peers
88 routeIntentsExpected: all expected MultiPointToSinglePointIntent \
89 intents
90 bgpIntentsExpected: expected PointToPointIntent intents
91 allRoutesActual: all routes from ONOS LCI
92 routeIntentsActual: actual MultiPointToSinglePointIntent intents from \
93 ONOS CLI
94 bgpIntentsActual: actual PointToPointIntent intents from ONOS CLI
95 """
96 import json
97 import time
98 from operator import eq
99 from time import localtime, strftime
100
101 main.case("This case is to testing the functionality of SDN-IP with \
102 single ONOS instance")
103 SDNIPJSONFILEPATH = \
104 "/home/admin/ONOS/tools/package/config/sdnip.json"
105 # all expected routes for all BGP peers
106 allRoutesExpected = []
107 main.step("Start to generate routes for all BGP peers")
108 main.log.info("Generate prefixes for host3")
109 prefixesHost3 = main.QuaggaCliHost3.generatePrefixes(3, 10)
110 main.log.info(prefixesHost3)
111 # generate route with next hop
112 for prefix in prefixesHost3:
113 allRoutesExpected.append(prefix + "/" + "192.168.20.1")
114 routeIntentsExpectedHost3 = \
115 main.QuaggaCliHost3.generateExpectedOnePeerRouteIntents(
116 prefixesHost3, "192.168.20.1", "00:00:00:00:02:02",
117 SDNIPJSONFILEPATH)
118
119 main.log.info("Generate prefixes for host4")
120 prefixesHost4 = main.QuaggaCliHost4.generatePrefixes(4, 10)
121 main.log.info(prefixesHost4)
122 # generate route with next hop
123 for prefix in prefixesHost4:
124 allRoutesExpected.append(prefix + "/" + "192.168.30.1")
125 routeIntentsExpectedHost4 = \
126 main.QuaggaCliHost4.generateExpectedOnePeerRouteIntents(
127 prefixesHost4, "192.168.30.1", "00:00:00:00:03:01",
128 SDNIPJSONFILEPATH)
129
130 main.log.info("Generate prefixes for host5")
131 prefixesHost5 = main.QuaggaCliHost5.generatePrefixes(5, 10)
132 main.log.info(prefixesHost5)
133 for prefix in prefixesHost5:
134 allRoutesExpected.append(prefix + "/" + "192.168.60.2")
135 routeIntentsExpectedHost5 = \
136 main.QuaggaCliHost5.generateExpectedOnePeerRouteIntents(
137 prefixesHost5, "192.168.60.1", "00:00:00:00:06:02",
138 SDNIPJSONFILEPATH)
139
140 routeIntentsExpected = routeIntentsExpectedHost3 + \
141 routeIntentsExpectedHost4 + routeIntentsExpectedHost5
142
143 main.step("Get links in the network")
144 listResult = main.ONOScli.links(jsonFormat=False)
145 main.log.info(listResult)
146 main.log.info("Activate sdn-ip application")
147 main.ONOScli.activateApp("org.onosproject.sdnip")
148 # wait sdn-ip to finish installing connectivity intents, and the BGP
149 # paths in data plane are ready.
150 time.sleep(int(main.params[ 'timers' ][ 'SdnIpSetup' ]))
151
152 main.step("Login all BGP peers and add routes into peers")
153
154 main.log.info("Login Quagga CLI on host3")
155 main.QuaggaCliHost3.loginQuagga("1.168.30.2")
156 main.log.info("Enter configuration model of Quagga CLI on host3")
157 main.QuaggaCliHost3.enterConfig(64514)
158 main.log.info("Add routes to Quagga on host3")
159 main.QuaggaCliHost3.addRoutes(prefixesHost3, 1)
160
161 main.log.info("Login Quagga CLI on host4")
162 main.QuaggaCliHost4.loginQuagga("1.168.30.3")
163 main.log.info("Enter configuration model of Quagga CLI on host4")
164 main.QuaggaCliHost4.enterConfig(64516)
165 main.log.info("Add routes to Quagga on host4")
166 main.QuaggaCliHost4.addRoutes(prefixesHost4, 1)
167
168 main.log.info("Login Quagga CLI on host5")
169 main.QuaggaCliHost5.loginQuagga("1.168.30.5")
170 main.log.info("Enter configuration model of Quagga CLI on host5")
171 main.QuaggaCliHost5.enterConfig(64521)
172 main.log.info("Add routes to Quagga on host5")
173 main.QuaggaCliHost5.addRoutes(prefixesHost5, 1)
174
175 for i in range(101, 201):
176 prefixesHostX = main.QuaggaCliHost.generatePrefixes(str(i), 10)
177 main.log.info(prefixesHostX)
178 for prefix in prefixesHostX:
179 allRoutesExpected.append(prefix + "/" + "192.168.40."
180 + str(i - 100))
181
182 routeIntentsExpectedHostX = \
183 main.QuaggaCliHost.generateExpectedOnePeerRouteIntents(
184 prefixesHostX, "192.168.40." + str(i - 100),
185 "00:00:%02d:00:00:90" % (i - 101), SDNIPJSONFILEPATH)
186 routeIntentsExpected = routeIntentsExpected + \
187 routeIntentsExpectedHostX
188
189 main.log.info("Login Quagga CLI on host" + str(i))
190 QuaggaCliHostX = getattr(main, ('QuaggaCliHost' + str(i)))
191 QuaggaCliHostX.loginQuagga("1.168.30." + str(i))
192 main.log.info(
193 "Enter configuration model of Quagga CLI on host" + str(i))
194 QuaggaCliHostX.enterConfig(65000 + i - 100)
195 main.log.info("Add routes to Quagga on host" + str(i))
196 QuaggaCliHostX.addRoutes(prefixesHostX, 1)
197 # wait Quagga to finish delivery all routes to each other and to sdn-ip,
198 # plus finish installing all intents.
199 time.sleep(int(main.params[ 'timers' ][ 'RouteDelivery' ]))
200 time.sleep(int(main.params[ 'timers' ][ 'PathAvailable' ]))
201 # get routes inside SDN-IP
202 getRoutesResult = main.ONOScli.routes(jsonFormat=True)
203
204 allRoutesActual = \
205 main.QuaggaCliHost3.extractActualRoutesMaster(getRoutesResult)
206
207 allRoutesStrExpected = str(sorted(allRoutesExpected))
208 allRoutesStrActual = str(allRoutesActual).replace('u', "")
209 main.step("Check routes installed")
210 main.log.info("Routes expected:")
211 main.log.info(allRoutesStrExpected)
212 main.log.info("Routes get from ONOS CLI:")
213 main.log.info(allRoutesStrActual)
214 utilities.assertEquals(
215 expect=allRoutesStrExpected, actual=allRoutesStrActual,
216 onpass="***Routes in SDN-IP are correct!***",
217 onfail="***Routes in SDN-IP are wrong!***")
218
219 getIntentsResult = main.ONOScli.intents(jsonFormat=True)
220
221 main.step("Check MultiPointToSinglePointIntent intents installed")
222 # routeIntentsExpected are generated when generating routes
223 # get route intents from ONOS CLI
224 routeIntentsActualNum = \
225 main.QuaggaCliHost3.extractActualRouteIntentNum(getIntentsResult)
226 routeIntentsExpectedNum = 1030
227 main.log.info("MultiPointToSinglePoint Intent Num expected is:")
228 main.log.info(routeIntentsExpectedNum)
229 main.log.info("MultiPointToSinglePoint Intent NUM Actual is:")
230 main.log.info(routeIntentsActualNum)
231 utilities.assertEquals(
232 expect=True,
233 actual=eq(routeIntentsExpectedNum, routeIntentsActualNum),
234 onpass="***MultiPointToSinglePoint Intent Num in SDN-IP is \
235 correct!***",
236 onfail="***MultiPointToSinglePoint Intent Num in SDN-IP is \
237 wrong!***")
238
239 main.step("Check BGP PointToPointIntent intents installed")
240
241 bgpIntentsActualNum = \
242 main.QuaggaCliHost3.extractActualBgpIntentNum(getIntentsResult)
243 bgpIntentsExpectedNum = 624
244 main.log.info("bgpIntentsExpected num is:")
245 main.log.info(bgpIntentsExpectedNum)
246 main.log.info("bgpIntentsActual num is:")
247 main.log.info(bgpIntentsActualNum)
248 utilities.assertEquals(
249 expect=True,
250 actual=eq(bgpIntentsExpectedNum, bgpIntentsActualNum),
251 onpass="***PointToPointIntent Intent Num in SDN-IP are correct!***",
252 onfail="***PointToPointIntent Intent Num in SDN-IP are wrong!***")
253
254 #============================= Ping Test ========================
255 pingTestScript = "~/SDNIP/test-tools/CASE4-ping-as2host.sh"
256 pingTestResultsFile = \
257 "~/SDNIP/TestOnEnv/log/CASE4-ping-results-before-delete-routes-"\
258 + strftime("%Y-%m-%d_%H:%M:%S", localtime()) + ".txt"
259 pingTestResults = main.QuaggaCliHost.pingTest(
260 "1.168.30.100", pingTestScript, pingTestResultsFile)
261 main.log.info(pingTestResults)
262 # wait to finish the ping test
263 time.sleep(int(main.params[ 'timers' ][ 'PingTestWithRoutes' ]))
264
265 #============================= Deleting Routes ==================
266 main.step("Check deleting routes installed")
267 main.QuaggaCliHost3.deleteRoutes(prefixesHost3, 1)
268 main.QuaggaCliHost4.deleteRoutes(prefixesHost4, 1)
269 main.QuaggaCliHost5.deleteRoutes(prefixesHost5, 1)
270
271 for i in range(101, 201):
272 prefixesHostX = main.QuaggaCliHost.generatePrefixes(str(i), 10)
273 main.log.info(prefixesHostX)
274 QuaggaCliHostX = getattr(main, ('QuaggaCliHost' + str(i)))
275 QuaggaCliHostX.deleteRoutes(prefixesHostX, 1)
276 # wait Quagga to finish delivery all routes to each other and to sdn-ip,
277 # plus finish un-installing all intents.
278 time.sleep(int(main.params[ 'timers' ][ 'RouteDelivery' ]))
279 time.sleep(int(main.params[ 'timers' ][ 'PathAvailable' ]))
280
281 getRoutesResult = main.ONOScli.routes(jsonFormat=True)
282 allRoutesActual = \
283 main.QuaggaCliHost3.extractActualRoutesMaster(getRoutesResult)
284 main.log.info("allRoutes_actual = ")
285 main.log.info(allRoutesActual)
286
287 utilities.assertEquals(
288 expect="[]", actual=str(allRoutesActual),
289 onpass="***Route number in SDN-IP is 0, correct!***",
290 onfail="***Routes number in SDN-IP is not 0, wrong!***")
291
292 main.step("Check intents after deleting routes")
293 getIntentsResult = main.ONOScli.intents(jsonFormat=True)
294 routeIntentsActualNum = \
295 main.QuaggaCliHost3.extractActualRouteIntentNum(
296 getIntentsResult)
297 main.log.info("route Intents Actual Num is: ")
298 main.log.info(routeIntentsActualNum)
299 utilities.assertEquals(
300 expect=0, actual=routeIntentsActualNum,
301 onpass="***MultiPointToSinglePoint Intent Num in SDN-IP is 0, \
302 correct!***",
303 onfail="***MultiPointToSinglePoint Intent Num in SDN-IP is not 0, \
304 wrong!***")
305
306 pingTestScript = "~/SDNIP/test-tools/CASE4-ping-as2host.sh"
307 pingTestResultsFile = \
308 "~/SDNIP/TestOnEnv/log/CASE4-ping-results-after-delete-routes-"\
309 + strftime("%Y-%m-%d_%H:%M:%S", localtime()) + ".txt"
310 pingTestResults = main.QuaggaCliHost.pingTest(
311 "1.168.30.100", pingTestScript, pingTestResultsFile)
312 main.log.info(pingTestResults)
313 # wait to finish the ping test
314 time.sleep(int(main.params[ 'timers' ][ 'PingTestWithoutRoutes' ]))