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