pingping-lin | ea32cf8 | 2015-10-08 22:37:37 -0700 | [diff] [blame] | 1 | |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame^] | 2 | def checkRouteNum( main, routeNumExpected, ONOScli="ONOScli1" ): |
| 3 | import time |
pingping-lin | ea32cf8 | 2015-10-08 22:37:37 -0700 | [diff] [blame] | 4 | main.step( "Check routes installed" ) |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame^] | 5 | wait = int( main.params['timers']['PathAvailable'] ) |
pingping-lin | ea32cf8 | 2015-10-08 22:37:37 -0700 | [diff] [blame] | 6 | main.log.info( "Route number expected:" ) |
| 7 | main.log.info( routeNumExpected ) |
| 8 | main.log.info( "Route number from ONOS CLI:" ) |
| 9 | |
pingping-lin | 3f932a7 | 2015-10-09 16:44:50 -0700 | [diff] [blame] | 10 | if ONOScli == "ONOScli1": |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame^] | 11 | cli = main.ONOScli1 |
pingping-lin | a14c7c8 | 2015-10-09 15:44:36 -0700 | [diff] [blame] | 12 | else: |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame^] | 13 | cli = main.ONOScli2 |
| 14 | routeNumActual = cli.ipv4RouteNumber() |
| 15 | if routeNumActual != routeNumExpected: |
| 16 | time.sleep( wait ) |
| 17 | routeNumActual = cli.ipv4RouteNumber() |
pingping-lin | a14c7c8 | 2015-10-09 15:44:36 -0700 | [diff] [blame] | 18 | |
pingping-lin | ea32cf8 | 2015-10-08 22:37:37 -0700 | [diff] [blame] | 19 | main.log.info( routeNumActual ) |
| 20 | utilities.assertEquals( \ |
| 21 | expect = routeNumExpected, actual = routeNumActual, |
| 22 | onpass = "Route number is correct!", |
| 23 | onfail = "Route number is wrong!" ) |
| 24 | |
pingping-lin | a14c7c8 | 2015-10-09 15:44:36 -0700 | [diff] [blame] | 25 | def checkM2SintentNum( main, intentNumExpected, ONOScli = "ONOScli1" ): |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame^] | 26 | import time |
pingping-lin | ea32cf8 | 2015-10-08 22:37:37 -0700 | [diff] [blame] | 27 | main.step( "Check M2S intents installed" ) |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame^] | 28 | wait = int( main.params['timers']['PathAvailable'] ) |
pingping-lin | ea32cf8 | 2015-10-08 22:37:37 -0700 | [diff] [blame] | 29 | main.log.info( "Intent number expected:" ) |
| 30 | main.log.info( intentNumExpected ) |
| 31 | main.log.info( "Intent number from ONOS CLI:" ) |
pingping-lin | a14c7c8 | 2015-10-09 15:44:36 -0700 | [diff] [blame] | 32 | if ONOScli == "ONOScli1": |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame^] | 33 | cli = main.ONOScli1 |
pingping-lin | a14c7c8 | 2015-10-09 15:44:36 -0700 | [diff] [blame] | 34 | else: |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame^] | 35 | cli = main.ONOScli2 |
| 36 | jsonResult = cli.intents( jsonFormat = True, summary = True, |
| 37 | TYPE = "multiPointToSinglePoint" ) |
pingping-lin | ea32cf8 | 2015-10-08 22:37:37 -0700 | [diff] [blame] | 38 | intentNumActual = jsonResult['installed'] |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame^] | 39 | if intentNumActual != intentNumExpected: |
| 40 | time.sleep( wait ) |
| 41 | jsonResult = cli.intents( jsonFormat = True, summary = True, |
| 42 | TYPE = "multiPointToSinglePoint" ) |
| 43 | intentNumActual = jsonResult['installed'] |
pingping-lin | ea32cf8 | 2015-10-08 22:37:37 -0700 | [diff] [blame] | 44 | main.log.info( intentNumActual ) |
| 45 | utilities.assertEquals( \ |
| 46 | expect = intentNumExpected, actual = intentNumActual, |
| 47 | onpass = "M2S intent number is correct!", |
| 48 | onfail = "M2S intent number is wrong!" ) |
| 49 | |
pingping-lin | a14c7c8 | 2015-10-09 15:44:36 -0700 | [diff] [blame] | 50 | def checkP2PintentNum( main, intentNumExpected, ONOScli = "ONOScli1" ): |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame^] | 51 | import time |
pingping-lin | ea32cf8 | 2015-10-08 22:37:37 -0700 | [diff] [blame] | 52 | main.step( "Check P2P intents installed" ) |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame^] | 53 | wait = int( main.params['timers']['PathAvailable'] ) |
pingping-lin | ea32cf8 | 2015-10-08 22:37:37 -0700 | [diff] [blame] | 54 | main.log.info( "Intent number expected:" ) |
| 55 | main.log.info( intentNumExpected ) |
| 56 | main.log.info( "Intent number from ONOS CLI:" ) |
pingping-lin | a14c7c8 | 2015-10-09 15:44:36 -0700 | [diff] [blame] | 57 | if ONOScli == "ONOScli1": |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame^] | 58 | cli = main.ONOScli1 |
pingping-lin | a14c7c8 | 2015-10-09 15:44:36 -0700 | [diff] [blame] | 59 | else: |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame^] | 60 | cli = main.ONOScli2 |
| 61 | jsonResult = cli.intents( jsonFormat = True, summary = True, |
| 62 | TYPE = "pointToPoint" ) |
pingping-lin | ea32cf8 | 2015-10-08 22:37:37 -0700 | [diff] [blame] | 63 | intentNumActual = jsonResult['installed'] |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame^] | 64 | |
| 65 | if intentNumActual != intentNumExpected: |
| 66 | time.sleep( wait ) |
| 67 | jsonResult = cli.intents( jsonFormat = True, summary = True, |
| 68 | TYPE = "pointToPoint" ) |
| 69 | intentNumActual = jsonResult['installed'] |
pingping-lin | ea32cf8 | 2015-10-08 22:37:37 -0700 | [diff] [blame] | 70 | main.log.info( intentNumActual ) |
| 71 | utilities.assertEquals( \ |
| 72 | expect = intentNumExpected, actual = intentNumActual, |
| 73 | onpass = "P2P intent number is correct!", |
| 74 | onfail = "P2P intent number is wrong!" ) |
| 75 | |
| 76 | def checkFlowNum( main, switch, flowNumExpected ): |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame^] | 77 | import time |
pingping-lin | ea32cf8 | 2015-10-08 22:37:37 -0700 | [diff] [blame] | 78 | main.step( "Check flow entry number in " + switch ) |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame^] | 79 | wait = int( main.params['timers']['PathAvailable'] ) |
pingping-lin | ea32cf8 | 2015-10-08 22:37:37 -0700 | [diff] [blame] | 80 | main.log.info( "Flow number expected:" ) |
| 81 | main.log.info( flowNumExpected ) |
| 82 | main.log.info( "Flow number actual:" ) |
| 83 | flowNumActual = main.Mininet.getSwitchFlowCount( switch ) |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame^] | 84 | if flowNumActual != flowNumExpected : |
| 85 | time.sleep( wait ) |
| 86 | flowNumActual = main.Mininet.getSwitchFlowCount( switch ) |
pingping-lin | ea32cf8 | 2015-10-08 22:37:37 -0700 | [diff] [blame] | 87 | main.log.info( flowNumActual ) |
| 88 | utilities.assertEquals( \ |
| 89 | expect = flowNumExpected, actual = flowNumActual, |
| 90 | onpass = "Flow number in " + switch + " is correct!", |
| 91 | onfail = "Flow number in " + switch + " is wrong!" ) |
| 92 | |
| 93 | |
| 94 | def pingSpeakerToPeer( main, speakers = ["speaker1"], |
| 95 | peers = ["peer64514", "peer64515", "peer64516"], |
| 96 | expectAllSuccess = True ): |
| 97 | """ |
| 98 | Carry out ping test between each BGP speaker and peer pair |
| 99 | Optional argument: |
| 100 | * speakers - BGP speakers |
| 101 | * peers - BGP peers |
| 102 | * expectAllSuccess - boolean indicating if you expect all results |
| 103 | succeed if True, otherwise expect all results fail if False |
| 104 | """ |
| 105 | if len( speakers ) == 0: |
| 106 | main.log.error( "Parameter speakers can not be empty." ) |
| 107 | main.cleanup() |
| 108 | main.exit() |
| 109 | if len( peers ) == 0: |
| 110 | main.log.error( "Parameter speakers can not be empty." ) |
| 111 | main.cleanup() |
| 112 | main.exit() |
| 113 | |
| 114 | if expectAllSuccess: |
| 115 | main.step( "BGP speakers ping peers, expect all tests to succeed" ) |
| 116 | else: |
| 117 | main.step( "BGP speakers ping peers, expect all tests to fail" ) |
| 118 | |
| 119 | result = True |
| 120 | if expectAllSuccess: |
| 121 | for speaker in speakers: |
| 122 | for peer in peers: |
| 123 | tmpResult = main.Mininet.pingHost( src = speaker, |
| 124 | target = peer ) |
| 125 | result = result and ( tmpResult == main.TRUE ) |
| 126 | else: |
| 127 | for speaker in speakers: |
| 128 | for peer in peers: |
| 129 | tmpResult = main.Mininet.pingHost( src = speaker, |
| 130 | target = peer ) |
| 131 | |
| 132 | utilities.assert_equals( expect = True, actual = result, |
| 133 | onpass = "Ping test results are expected", |
| 134 | onfail = "Ping test results are Not expected" ) |
| 135 | |
| 136 | if result == False: |
| 137 | main.cleanup() |
| 138 | main.exit() |
| 139 | |
| 140 | |
| 141 | def pingHostToHost( main, hosts = ["host64514", "host64515", "host64516"], |
| 142 | expectAllSuccess = True ): |
| 143 | """ |
| 144 | Carry out ping test between each BGP host pair |
| 145 | Optional argument: |
| 146 | * hosts - hosts behind BGP peer routers |
| 147 | * expectAllSuccess - boolean indicating if you expect all results |
| 148 | succeed if True, otherwise expect all results fail if False |
| 149 | """ |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame^] | 150 | main.step( "Check ping between each host pair, expect all to succede=" + |
| 151 | str( expectAllSuccess ) ) |
pingping-lin | ea32cf8 | 2015-10-08 22:37:37 -0700 | [diff] [blame] | 152 | if len( hosts ) == 0: |
| 153 | main.log.error( "Parameter hosts can not be empty." ) |
| 154 | main.cleanup() |
| 155 | main.exit() |
| 156 | |
| 157 | result = True |
| 158 | if expectAllSuccess: |
| 159 | for srcHost in hosts: |
| 160 | for targetHost in hosts: |
| 161 | if srcHost != targetHost: |
| 162 | tmpResult = main.Mininet.pingHost( src = srcHost, |
| 163 | target = targetHost ) |
| 164 | result = result and ( tmpResult == main.TRUE ) |
| 165 | else: |
| 166 | for srcHost in hosts: |
| 167 | for targetHost in hosts: |
| 168 | if srcHost != targetHost: |
| 169 | tmpResult = main.Mininet.pingHost( src = srcHost, |
| 170 | target = targetHost ) |
| 171 | result = result and ( tmpResult == main.FALSE ) |
| 172 | |
| 173 | utilities.assert_equals( expect = True, actual = result, |
| 174 | onpass = "Ping test results are expected", |
| 175 | onfail = "Ping test results are Not expected" ) |
| 176 | |
| 177 | ''' |
| 178 | if result == False: |
| 179 | main.cleanup() |
| 180 | main.exit() |
| 181 | ''' |
| 182 | |
| 183 | |
| 184 | def setupTunnel( main, srcIp, srcPort, dstIp, dstPort ): |
| 185 | """ |
| 186 | Create a tunnel from Mininet host to host outside Mininet |
| 187 | """ |
| 188 | main.step( "Set up tunnel from Mininet node " + |
| 189 | str( srcIp ) + ":" + str( srcPort ) + " to ONOS node " |
| 190 | + str(dstIp) + ":" + str(dstPort) ) |
| 191 | forwarding = '%s:%s:%s:%s' % ( srcIp, srcPort, dstIp, dstPort ) |
| 192 | command = 'ssh -nNT -o "PasswordAuthentication no" \ |
| 193 | -o "StrictHostKeyChecking no" -l sdn -L %s %s & ' % ( forwarding, dstIp ) |
| 194 | |
| 195 | |
| 196 | tunnelResult = main.TRUE |
| 197 | tunnelResult = main.Mininet.node( "root", command ) |
| 198 | utilities.assert_equals( expect = True, |
| 199 | actual = ( "PasswordAuthentication" in tunnelResult ), |
| 200 | onpass = "Created tunnel succeeded", |
| 201 | onfail = "Create tunnel failed" ) |
| 202 | if ( "PasswordAuthentication" not in tunnelResult ) : |
| 203 | main.cleanup() |
| 204 | main.exit() |
| 205 | |