blob: 8d17baae3cca129c9d4874cf20272139348e8dd7 [file] [log] [blame]
Matteo Scandolo48d3d2d2017-08-08 13:05:27 -07001
2# Copyright 2017-present Open Networking Foundation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16
Anil Kumar Sanka1e535c72016-12-21 17:39:20 -080017#copyright 2016-present Ciena Corporation
18#
19# Licensed under the Apache License, Version 2.0 (the "License");
20# you may not use this file except in compliance with the License.
21# You may obtain a copy of the License at
22#
23# http://www.apache.org/licenses/LICENSE-2.0
24#
25# Unless required by applicable law or agreed to in writing, software
26# distributed under the License is distributed on an "AS IS" BASIS,
27# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28# See the License for the specific language governing permissions and
29# limitations under the License.
30#
31import unittest
32from nose.tools import *
33from nose.twistedtools import reactor, deferred
34from twisted.internet import defer
Anil Kumar Sanka1e535c72016-12-21 17:39:20 -080035from OnosCtrl import OnosCtrl
36from OnosFlowCtrl import OnosFlowCtrl
37from OltConfig import OltConfig
38from onosclidriver import OnosCliDriver
39from functools import partial
40#from CordContainer import Onos
41utils_dir = os.path.join( os.path.dirname(os.path.realpath(__file__)), '../utils')
42sys.path.append(utils_dir)
43sys.path.insert(1, '/usr/local/lib/python2.7/dist-packages/requests')
44import time, monotonic
45from CordContainer import Onos
46from OnosLog import OnosLog
47from CordLogger import CordLogger
A R Karthick76a497a2017-04-12 10:59:39 -070048from CordTestUtils import log_test as log
Anil Kumar Sanka1e535c72016-12-21 17:39:20 -080049import os
50import json
51import random
52import collections
53from mininet.net import Mininet
54from mininet.topo import SingleSwitchTopo,LinearTopo,Topo
55from mininet.topolib import TreeTopo
Chetan Gaonker76044232017-01-13 22:51:13 +000056#from mininet.clean import Cleanup
Anil Kumar Sanka1e535c72016-12-21 17:39:20 -080057from mininet.node import Controller, RemoteController, Switch
58from mininet.cli import CLI
59from mininet.log import setLogLevel, info
60from mininet.link import TCLink
61from mininet.util import dumpNodeConnections
62from mininet.node import CPULimitedHost
63log.setLevel('INFO')
64
65class mininet_exchange(unittest.TestCase):
66 app = 'org.onosproject.fwd'
67 controller = os.getenv('ONOS_CONTROLLER_IP') or 'localhost'
68 controller = controller.split(',')[0]
69
70 @classmethod
71 def setUpClass(cls):
72 pass
73
74 @classmethod
75 def tearDownClass(cls):
76 pwd = os.getcwd()
77 log.info('teardown- current working dir is %s'%pwd)
78 os.chdir('/root')
79 cmds = ['rm -r mininet','apt-get remove mininet']
80 for cmd in cmds:
81 os.system(cmd)
82 os.chdir(pwd)
83 log.info('teardown- dir after removing mininet is %s'%os.getcwd())
84 time.sleep(5)
85
86 def setUp(self):
87 self.onos_ctrl = OnosCtrl(self.app)
88 self.onos_ctrl.activate()
89
90 def tearDown(self):
91 self.onos_ctrl = OnosCtrl(self.app)
92 self.onos_ctrl.deactivate()
93
94 def cliEnter(self, controller = None):
95 retries = 0
96 while retries < 30:
97 self.cli = OnosCliDriver(controller = controller, connect = True)
98 if self.cli.handle:
99 break
100 else:
101 retries += 1
102 time.sleep(2)
103
104 def cliExit(self):
105 self.cli.disconnect()
106
107 def test_creation_of_topology(self):
108 try:
109 net = Mininet( topo=None, build=False)
110 h1 = net.addHost( 'h1')
111 h2 = net.addHost( 'h2' )
112 h3 = net.addHost( 'h3' )
113 s1 = net.addSwitch( 's1', dpid="0000000000000201")
114 s2 = net.addSwitch( 's2', dpid="0000000000000202")
115 s3 = net.addSwitch( 's3', dpid="0000000000000203")
116 net.addLink(h1, s1, )
117 net.addLink(h2, s2, )
118 net.addLink(h3, s3, )
119 net.addLink(s1, s2, )
120 net.addLink(s2, s3, )
121 #net.build()
122 net.start()
123 ctrl = net.addController( 'onos', controller=RemoteController, ip=self.controller, port=6653)
124 s1.start( [ctrl] )
125 s2.start( [ctrl] )
126 s3.start( [ctrl] )
127 #CLI(net)
128 for switch in net.switches:
129 log.info('dpid of switch is %s'%switch.dpid)
130 for host in net.hosts:
131 log.info('host %s added with IP addres %s'%(host.name,host.IP()))
132 net.stop()
133 log.info('Successfully created mininet topology and connected to cluster controllers')
134 except Exception as Error:
135 log.info('Got error %s while creating topology'%Error)
136 Cleanup.cleanup()
137 raise
138 Cleanup.cleanup()
139
140 def test_creation_of_single_switch_topology(self,hosts=5):
141 try:
142 topo = SingleSwitchTopo(hosts)
143 net = Mininet(topo=topo )
144 net.start()
145 log.info('Node connections are %s'%dumpNodeConnections(net.hosts))
146 ctrl = net.addController( 'onos', controller=RemoteController, ip=self.controller, port=6653)
147 for switch in net.switches:
148 switch.start( [ctrl] )
149 response = net.pingAll()
150 log.info('Pingall response is %s'%response)
151 assert_equal(response,0.0)
152 net.stop()
153 except Exception as Error:
154 log.info('Got unexpected error %s while creating topology'%Error)
155 Cleanup.cleanup()
156 raise
157 Cleanup.cleanup()
158
159 def test_creation_of_linear_topology(self,switches=5):
160 try:
161 topo = LinearTopo(switches)
162 net = Mininet(topo=topo)
163 net.start()
164 log.info('Node connections are %s'%dumpNodeConnections(net.hosts))
165 ctrl = net.addController( 'onos', controller=RemoteController, ip=self.controller, port=6653)
166 for switch in net.switches:
167 switch.start( [ctrl] )
168 response = net.pingAll()
169 log.info('Pingall response is %s'%response)
170 assert_equal(response,0.0)
171 #CLI(net)
172 net.stop()
173 except Exception as Error:
174 log.info('Got unexpected error %s while creating minine topology'%Error)
175 Cleanup.cleanup()
176 raise
177 Cleanup.cleanup()
178
179 def test_creation_of_tree_topology(self):
180 try:
181 topo = TreeTopo(depth=2,fanout=2)
182 net = Mininet(topo=topo)
183 net.start()
184 ctrl = net.addController( 'onos', controller=RemoteController, ip=self.controller, port=6653)
185 for switch in net.switches:
186 switch.start( [ctrl] )
187 response = net.pingAll()
188 log.info('Pingall response is %s'%response)
189 assert_equal(response,0.0)
190 net.stop()
191 except Exception as Error:
192 log.info('Got unexpected error %s while creating topology'%Error)
193 Cleanup.cleanup()
194 raise
195 Cleanup.cleanup()
196
197 def test_executing_commands_from_mininet_host(self,switches=4):
198 try:
199 topo = LinearTopo(switches)
200 net = Mininet(topo=topo)
201 net.start()
202 ctrl = net.addController( 'onos', controller=RemoteController, ip=self.controller, port=6653)
203 for switch in net.switches:
204 switch.start( [ctrl] )
205 for host in net.hosts:
206 result = host.cmd('ping -c 2', net.switches[0].IP())
207 log.info('Result is %s'%result)
208 res = result.find('icmp_seq')
209 assert_not_equal(res, -1)
210 net.stop()
211 except Exception as Error:
212 Cleanup.cleanup()
213 log.info('Error while creating topology is %s'%Error)
214 raise
215 Cleanup.cleanup()
216
217 def test_verifying_pingall_from_mininet(self,switches=5):
218 try:
219 topo = LinearTopo(switches)
220 net = Mininet(topo=topo)
221 net.start()
222 ctrl = net.addController( 'onos', controller=RemoteController, ip=self.controller, port=6653)
223 for switch in net.switches:
224 log.info('switch is %s'%switch )
225 switch.start([ctrl])
226 response = net.pingAll()
227 log.info('pingAll response is %s'%response)
228 assert_equal(response,0.0)
229 except Exception as Error:
230 log.info('Got unexpected error %s while creating topology'%Error)
231 Cleanup.cleanup()
232 raise
233 Cleanup.cleanup()
234
235 def test_initiating_pingall_from_mininet_with_onos_app_deactivation(self,switches=3):
236 try:
237 topo = LinearTopo(switches)
238 net = Mininet(topo=topo)
239 net.start()
240 ctrl = net.addController( 'onos', controller=RemoteController, ip=self.controller, port=6653)
241 for switch in net.switches:
242 switch.start( [ctrl] )
243 response = net.pingAll()
244 log.info('PingAll response before onos app \'org.onosproject.fwd\' deactivate is %s'%response)
245 assert_equal(response, 0.0)
246 OnosCtrl(self.app).deactivate()
247 response = net.pingAll()
248 log.info('PingAll response after onos app \'org.onosproject.fwd\' deactivate is %s'%response)
249 assert_equal(response, 100.0)
250 net.stop()
251 except Exception as Error:
252 log.info('Got unexpected error %s while creating topology'%Error)
253 Cleanup.cleanup()
254 raise
255 Cleanup.cleanup()
256
257 def test_verifying_mininet_hosts_in_onos_controller(self,switches=4):
258 try:
259 topo = LinearTopo(switches)
260 net = Mininet( topo=topo)
261 net.start()
262 ctrl = net.addController( 'onos', controller=RemoteController, ip=self.controller, port=6653)
263 for switch in net.switches:
264 switch.start( [ctrl] )
265 log.info('mininet all the devices IDs %s'%net.keys())
266 log.info('mininet all the devices details %s'%net.values())
267 log.info('mininet all the devices information %s'%net.items())
268 response = net.pingAll()
269 log.info('pingAll response is %s'%response)
270 assert_equal(response, 0.0)
271 self.cliEnter()
272 hosts = json.loads(self.cli.hosts(jsonFormat = True))
273 log.info('Discovered hosts: %s' %hosts)
274 assert_equal(len(hosts),switches)
275 self.cliExit()
276 except Exception as Error:
277 log.info('Got unexpected error %s while creating topology'%Error)
278 Cleanup.cleanup()
279 raise
280 Cleanup.cleanup()
281
282 def test_verifying_tcp_bandwidth_measure_between_mininet_hosts_using_iperf(self):
283 try:
284 topo = TreeTopo(depth=2,fanout=2)
285 net = Mininet( topo=topo, host=CPULimitedHost, link=TCLink, build=False)
286 net.start()
287 ctrl = net.addController( 'onos', controller=RemoteController, ip=self.controller, port=6653)
288 for switch in net.switches:
289 switch.start( [ctrl] )
290 response = net.pingAll()
291 log.info('PingAll response is %s'%response)
292 bandwidth = net.iperf()
293 log.info('TCP Bandwidth between hosts measured using iperf is %s'%bandwidth)
294 assert_equal(len(bandwidth),2)
295 net.stop()
296 except Exception as Error:
297 log.info('Got unexpected error %s while creating topology'%Error)
298 Cleanup.cleanup()
299 raise
300 Cleanup.cleanup()
301
302 def test_verifying_udp_bandwidth_measure_between_mininet_hosts_using_iperf(self):
303 try:
304 topo = TreeTopo(depth=2,fanout=2)
305 net = Mininet( topo=topo, host=CPULimitedHost, link=TCLink, build=False)
306 net.start()
307 ctrl = net.addController( 'onos', controller=RemoteController, ip=self.controller, port=6653)
308 for switch in net.switches:
309 switch.start( [ctrl] )
310 response = net.pingAll()
311 log.info('pingAll response is %s'%response)
312 bandwidth = net.iperf(l4Type = 'UDP')
313 log.info('UDP Bandwidth between hosts measured using iperf is %s'%bandwidth)
314 assert_equal(len(bandwidth),3)
315 net.stop()
316 except Exception as Error:
317 log.info('Got unexpected error %s while creating topology'%Error)
318 Cleanup.cleanup()
319 raise
320 Cleanup.cleanup()
321
322 def test_verifying_tcp_bandwidth_between_mininet_hosts_using_iperf_with_one_host_removed(self,switches=3):
323 try:
324 topo = LinearTopo(switches)
325 net = Mininet(topo=topo)
326 net.start()
327 ctrl = net.addController( 'onos', controller=RemoteController, ip=self.controller, port=6653)
328 for switch in net.switches:
329 switch.start( [ctrl] )
330 response = net.pingAll()
331 iperf = net.iperf(l4Type='TCP')
332 log.info('Iperf response before host removed is %s'%iperf)
333 assert_equal(len(iperf),2)
334 net.delNode(net.hosts[2])
335 iperf = net.iperf(l4Type='TCP')
336 log.info('Iperf response after host removed is %s'%iperf)
337 assert_equal(len(iperf),2)
338 net.stop()
339 except Exception as Error:
340 log.info('Got unexpected error %s while creating topology'%Error)
341 Cleanup.cleanup()
342 raise
343 Cleanup.cleanup()
344
345 def test_verifying_udp_bandwidth_between_mininet_hosts_using_iperf_with_one_host_removed(self,switches=3):
346 try:
347 topo = LinearTopo(switches)
348 net = Mininet(topo=topo)
349 net.start()
350 ctrl = net.addController( 'onos', controller=RemoteController, ip=self.controller, port=6653)
351 for switch in net.switches:
352 switch.start( [ctrl] )
353 response = net.pingAll()
354 iperf = net.iperf(l4Type='UDP')
355 log.info('Iperf response before host removed is %s'%iperf)
356 assert_equal(len(iperf),3)
357 net.delNode(net.hosts[2])
358 iperf = net.iperf(l4Type='UDP')
359 log.info('Iperf response after host removed is %s'%iperf)
360 assert_equal(len(iperf),3)
361 net.stop()
362 except Exception as Error:
363 log.info('Got unexpected error %s while creating topology'%Error)
364 Cleanup.cleanup()
365 raise
366 Cleanup.cleanup()
367
368 def test_hosts_assigned_with_non_default_ip_address(self):
369 try:
370 net = Mininet( topo=None, controller=RemoteController, host=CPULimitedHost, link=TCLink, build=False)
371 h1 = net.addHost( 'h1', ip='192.168.10.1/24' )
372 h2 = net.addHost( 'h2', ip='192.168.10.10/24' )
373 s1 = net.addSwitch( 's1')
374 s2 = net.addSwitch( 's2')
375 net.addLink(h1, s1, )
376 net.addLink(h2, s2, )
377 net.addLink(s1, s2, )
378 ctrl = net.addController( 'onos', controller=RemoteController, ip=self.controller, port=6653)
379 for switch in net.switches:
380 switch.start( [ctrl] )
381 net.start()
382 assert_equal(net.hosts[0].IP(),'192.168.10.1')
383 assert_equal(net.hosts[1].IP(),'192.168.10.10')
384 response = net.pingAll()
385 log.info('PingAll response is %s'%response)
386 assert_equal(response,0.0)
387 except Exception as Error:
388 log.info('Got unexpected error %s while creating topology'%Error)
389 Cleanup.cleanup()
390 raise
391 Cleanup.cleanup()
392
393 def test_hosts_assigned_with_non_default_ip_address_in_different_subnets(self):
394 try:
395 net = Mininet( topo=None, controller=RemoteController, host=CPULimitedHost, link=TCLink, build=False)
396 h1 = net.addHost( 'h1', ip='192.168.10.10/24' )
397 h2 = net.addHost( 'h2', ip='192.168.20.10/24' )
398 s1 = net.addSwitch( 's1')
399 s2 = net.addSwitch( 's2')
400 net.addLink(h1, s1, )
401 net.addLink(h2, s2, )
402 net.addLink(s1, s2, )
403 net.start()
404 ctrl = net.addController( 'onos', controller=RemoteController, ip=self.controller, port=6653)
405 for switch in net.switches:
406 switch.start( [ctrl] )
407 assert_equal(net.hosts[0].IP(),'192.168.10.10')
408 assert_equal(net.hosts[1].IP(),'192.168.20.10')
409 response = net.pingAll()
410 log.info('pingAll response is %s'%response)
411 assert_equal(response,100.0)
412 except Exception as Error:
413 log.info('Got unexpected error %s while creating topology'%Error)
414 Cleanup.cleanup()
415 raise
416 Cleanup.cleanup()
417
418 def test_verifying_pingall_with_connection_remove_between_switches(self,switches=4):
419 try:
420 topo = LinearTopo(switches)
421 net = Mininet(topo=topo)
422 #net.build()
423 net.start()
424 ctrl = net.addController( 'onos', controller=RemoteController, ip=self.controller, port=6653)
425 for switch in net.switches:
426 switch.start( [ctrl] )
427 response = net.pingAll()
428 log.info('Pingall response before link delete is %s'%response)
429 assert_equal(response,0.0)
430 log.info('Deleting link between switches s1 and s2')
431 net.delLinkBetween(net.switches[0], net.switches[1], )
432 response = net.pingAll()
433 log.info('Pingall response after the link delete is is %s'%response)
434 assert_not_equal(response,0.0)
435 net.stop()
436 except Exception as Error:
437 log.info('Got error %s while creating topology'%Error)
438 Cleanup.cleanup()
439 raise
440 Cleanup.cleanup()
441
442 def test_verifying_pingall_with_removing_one_mininet_host(self,switches=3):
443 try:
444 topo = LinearTopo(switches)
445 net = Mininet(topo=topo)
446 #net.build()
447 net.start()
448 ctrl = net.addController( 'onos', controller=RemoteController, ip=self.controller, port=6653)
449 for switch in net.switches:
450 switch.start( [ctrl] )
451 response = net.pingAll()
452 log.info('Pingall response before host delete is %s'%response)
453 assert_equal(response,0.0)
454 log.info('removing host h2')
455 net.delNode(net.hosts[1])
456 response = net.pingAll()
457 log.info('Pingall response after host delete is %s'%response)
458 assert_equal(response,0)
459 net.stop()
460 except Exception as Error:
461 log.info('Got error %s while creating topology'%Error)
462 Cleanup.cleanup()
463 raise
464 Cleanup.cleanup()
465
466 def test_verifying_pingall_with_removing_one_mininet_switch(self,switches=3):
467 try:
468 topo = LinearTopo(switches)
469 net = Mininet(topo=topo)
470 #net.build()
471 net.start()
472 ctrl = net.addController( 'onos', controller=RemoteController, ip=self.controller, port=6653)
473 for switch in net.switches:
474 switch.start( [ctrl] )
475 response = net.pingAll()
476 log.info('Pingall response before switch delete is %s'%response)
477 assert_equal(response,0.0)
478 log.info('Deleting switch s2')
479 net.delNode(net.switches[1])
480 response = net.pingAll()
481 log.info('Pingall response after switch delete is %s'%response)
482 assert_not_equal(response,0.0)
483 net.stop()
484 except Exception as Error:
485 log.info('Got error %s while creating topology'%Error)
486 Cleanup.cleanup()
487 raise
488 Cleanup.cleanup()
489
490 def test_verifying_mininet_switch_status_in_onos_controller(self,switches=4):
491 try:
492 topo = LinearTopo(switches)
493 net = Mininet(topo=topo, build=False)
494 net.start()
495 ctrl = net.addController( 'onos', controller=RemoteController, ip=self.controller, port=6653)
496 for switch in net.switches:
497 switch.start( [ctrl] )
498 response = net.pingAll()
499 log.info('Pingall response is %s'%response)
500 assert_equal(response,0.0)
501 self.cliEnter()
502 devices = json.loads(self.cli.devices(jsonFormat = True))
503 count = 0
504 switch_ids = []
505 for switch in net.switches:
506 dvcid = 'of:'+switch.dpid
507 switch_ids.append(dvcid)
508 for device in devices:
509 if str(device['id']) in switch_ids:
510 assert_equal(str(device['available']), 'True')
511 count += 1
512 assert_equal(count,switches)
513 self.cliExit()
514 net.stop()
515 except Exception as Error:
516 log.info('Got error %s while creating topology'%Error)
517 Cleanup.cleanup()
518 raise
519 Cleanup.cleanup()
520
521 def test_verify_host_status_in_onos_controller_with_removing_one_mininet_host(self,switches=5):
522 try:
523 topo = LinearTopo(switches)
524 net = Mininet( topo=topo, build=False)
525 net.start()
526 ctrl = net.addController( 'onos', controller=RemoteController, ip=self.controller, port=6653)
527 for switch in net.switches:
528 switch.start( [ctrl] )
529 response = net.pingAll()
530 log.info('pingall response is %s'%response)
531 assert_equal(response,0.0)
532 self.cliEnter()
533 hosts = json.loads(self.cli.hosts(jsonFormat = True))
534 log.info('Discovered Hosts are %s'%hosts)
535 assert_equal(len(hosts),switches)
536 log.info('removing host h2')
537 net.delNode(net.hosts[0])
538 hosts = json.loads(self.cli.hosts(jsonFormat = True))
539 assert_equal(len(hosts),switches-1)
540 self.cliExit()
541 net.stop()
542 except Exception as Error:
543 log.info('Got error %s while creating topology'%Error)
544 Cleanup.cleanup()
545 raise
546 Cleanup.cleanup()
547
548 def test_verifying_pushing_mac_flows_from_onos_controller_to_mininet_switches(self,switches=3):
549 try:
550 topo = LinearTopo(switches)
551 net = Mininet( topo=topo)
552 net.start()
553 egress_mac = RandMAC()._fix()
554 ingress_mac = RandMAC()._fix()
555 egress = 1
556 ingress = 2
557 ctrl = net.addController( 'onos', controller=RemoteController, ip=self.controller, port=6653)
558 for switch in net.switches:
559 switch.start( [ctrl] )
560 response = net.pingAll()
561 log.info('pingAll response is %s'%response)
562 self.cliEnter()
563 devices = json.loads(self.cli.devices(jsonFormat = True))
564 for switch in net.switches:
565 dvcid = 'of:'+switch.dpid
566 flow = OnosFlowCtrl(deviceId = dvcid,
567 egressPort = egress,
568 ingressPort = ingress,
569 ethSrc = ingress_mac,
570 ethDst = egress_mac)
571 result = flow.addFlow()
572 assert_equal(result, True)
573 self.cliExit()
574 net.stop()
575 except Exception as Error:
576 log.info('Got unexpected error %s while creating topology'%Error)
577 Cleanup.cleanup()
578 raise
579 Cleanup.cleanup()
580
581 def test_verifying_pushing_ipv4_flows_from_onos_controller_to_mininet_switches(self,switches=5):
582 try:
583 topo = LinearTopo(switches)
584 net = Mininet( topo=topo)
585 net.start()
586 ctrl = net.addController( 'onos', controller=RemoteController, ip=self.controller, port=6653)
587 for switch in net.switches:
588 switch.start( [ctrl] )
589 egress = 1
590 ingress = 2
591 egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '192.168.30.1' }
592 ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.168.40.1' }
593 response = net.pingAll()
594 log.info('pingAll response is %s'%response)
595 for switch in net.switches:
596 dvcid = 'of:'+switch.dpid
597 flow = OnosFlowCtrl(deviceId = dvcid,
598 egressPort = egress,
599 ingressPort = ingress,
600 ethType = '0x0800',
601 ipSrc = ('IPV4_SRC', ingress_map['ip']+'/32'),
602 ipDst = ('IPV4_DST', egress_map['ip']+'/32')
603 )
604 result = flow.addFlow()
605 assert_equal(result, True)
606 net.stop()
607 except Exception as Error:
608 log.info('Got unexpected error %s while creating topology'%Error)
609 Cleanup.cleanup()
610 raise
611 Cleanup.cleanup()
612
613 def test_verifying_pushing_ipv6_flows_from_onos_controller_to_mininet_switches(self,switches=5):
614 try:
615 topo = LinearTopo(switches)
616 net = Mininet( topo=topo)
617 net.start()
618 ctrl = net.addController( 'onos', controller=RemoteController, ip=self.controller, port=6653)
619 for switch in net.switches:
620 switch.start( [ctrl] )
621 egress = 1
622 ingress = 2
623 egress_map = { 'ether': '00:00:00:00:00:03', 'ipv6': '2001:db8:a0b:12f0:1010:1010:1010:1001' }
624 ingress_map = { 'ether': '00:00:00:00:00:04', 'ipv6': '2001:db8:a0b:12f0:1010:1010:1010:1002' }
625 response = net.pingAll()
626 log.info('pingAll response is %s'%response)
627 for switch in net.switches:
628 dvcid = 'of:'+switch.dpid
629 flow = OnosFlowCtrl(deviceId = dvcid,
630 egressPort = egress,
631 ingressPort = ingress,
632 ethType = '0x86dd',
633 ipSrc = ('IPV6_SRC', ingress_map['ipv6'] + '/48'),
634 ipDst = ('IPV6_DST', egress_map['ipv6'] + '/48')
635 )
636 result = flow.addFlow()
637 assert_equal(result, True)
638 net.stop()
639 except Exception as Error:
640 log.info('Got unexpected error %s while creating topology'%Error)
641 Cleanup.cleanup()
642 raise
643 Cleanup.cleanup()
644
645 def test_topology_created_with_50_switches_in_onos_controller(self,switches=50):
646 try:
647 topo = LinearTopo(switches)
648 net = Mininet(topo=topo)
649 net.start()
650 ctrl = net.addController( 'onos', controller=RemoteController, ip=self.controller, port=6653)
651 for switch in net.switches:
652 switch.start([ctrl])
653 time.sleep(5)
654 self.cliEnter()
655 devices = json.loads(self.cli.devices(jsonFormat = True))
656 device_list = []
657 count = 0
658 for device in devices:
659 device_list.append(str(device['id']))
660 log.info('device list is %s'%device_list)
661 for switch in net.switches:
662 switch_id = 'of:'+switch.dpid
663 if switch_id in device_list:
664 count += 1
665 assert_equal(count,switches)
666 self.cliExit()
667 net.stop()
668 except Exception as Error:
669 log.info('Got unexpected error %s while creating topology'%Error)
670 Cleanup.cleanup()
671 raise
672 Cleanup.cleanup()
673
674 def test_topology_created_with_200_switches_in_onos_controller(self,switches=200):
675 try:
676 topo = LinearTopo(switches)
677 net = Mininet(topo=topo)
678 net.start()
679 ctrl = net.addController( 'onos', controller=RemoteController, ip=self.controller, port=6653)
680 for switch in net.switches:
681 log.info('switch is %s'%switch )
682 switch.start([ctrl])
683 time.sleep(10)
684 self.cliEnter()
685 devices = json.loads(self.cli.devices(jsonFormat = True))
686 device_list = []
687 count = 0
688 for device in devices:
689 device_list.append(str(device['id']))
690 log.info('device list is %s'%device_list)
691 for switch in net.switches:
692 switch_id = 'of:'+switch.dpid
693 if switch_id in device_list:
694 count += 1
695 assert_equal(count,switches)
696 self.cliExit()
697 net.stop()
698 except Exception as Error:
699 log.info('Got unexpected error %s while creating topology'%Error)
700 Cleanup.cleanup()
701 raise
702 Cleanup.cleanup()
703
704 def test_verifying_nodes_removed_in_mininet_status_in_onos_controller(self,switches=50, delete=20):
705 try:
706 topo = LinearTopo(switches)
707 net = Mininet(topo=topo)
708 net.start()
709 o1_ctrl = net.addController( 'onos', controller=RemoteController, ip=self.controller, port=6653)
710 for switch in net.switches:
711 log.info('switch is %s'%switch)
712 switch.start([o1_ctrl])
713 time.sleep(5)
714 self.cliEnter()
715 devices = json.loads(self.cli.devices(jsonFormat = True))
716 device_list = []
717 count = 0
718 for device in devices:
719 device_list.append(str(device['id']))
720 log.info('device list is %s'%device_list)
721 for switch in net.switches:
722 switch_id = 'of:'+switch.dpid
723 if switch_id in device_list:
724 count += 1
725 assert_equal(count,switches)
726 count = 0
727 dltd_list = []
728 for switch in net.switches:
729 log.info('Switch is %s'%switch)
730 dltd_list.append('of:'+switch.dpid)
731 net.delNode(switch)
732 count += 1
733 if count == delete:
734 break
735 log.info('deleted switch dpid\'s %s'%dltd_list)
736 count = 0
737 devices = json.loads(self.cli.devices(jsonFormat = True))
738 for device in devices:
739 if str(device['id']) in dltd_list:
740 assert_equal(str(device['available']), 'False')
741 count += 1
742 assert_equal(count,delete)
743 self.cliExit()
744 net.stop()
745 except Exception as Error:
746 log.info('Got unexpected error %s while creating topology'%Error)
747 Cleanup.cleanup()
748 raise
749 Cleanup.cleanup()