pingping-lin | 4f80c49 | 2015-09-15 14:34:42 -0700 | [diff] [blame] | 1 | |
| 2 | def checkRouteNum( main, routeNumExpected ): |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 3 | import time |
pingping-lin | 4f80c49 | 2015-09-15 14:34:42 -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 | 4f80c49 | 2015-09-15 14:34:42 -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 | |
| 10 | routeNumActual = main.ONOScli.ipv4RouteNumber() |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 11 | if routeNumActual != routeNumExpected: |
| 12 | time.sleep( wait ) |
| 13 | routeNumActual = main.ONOScli.ipv4RouteNumber() |
pingping-lin | 4f80c49 | 2015-09-15 14:34:42 -0700 | [diff] [blame] | 14 | main.log.info( routeNumActual ) |
| 15 | utilities.assertEquals( \ |
| 16 | expect = routeNumExpected, actual = routeNumActual, |
pingping-lin | b3ebd3f | 2015-09-28 22:17:05 -0700 | [diff] [blame] | 17 | onpass = "Route number is correct!", |
| 18 | onfail = "Route number is wrong!" ) |
pingping-lin | 4f80c49 | 2015-09-15 14:34:42 -0700 | [diff] [blame] | 19 | |
| 20 | def checkM2SintentNum( main, intentNumExpected ): |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 21 | import time |
pingping-lin | 4f80c49 | 2015-09-15 14:34:42 -0700 | [diff] [blame] | 22 | main.step( "Check M2S intents installed" ) |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 23 | wait = int( main.params['timers']['PathAvailable'] ) |
pingping-lin | 8244a3b | 2015-09-16 13:36:56 -0700 | [diff] [blame] | 24 | jsonResult = main.ONOScli.intents( jsonFormat = True, summary = True, |
| 25 | TYPE = "multiPointToSinglePoint" ) |
Jon Hall | 2aa1656 | 2017-05-23 11:26:46 -0700 | [diff] [blame] | 26 | try: |
| 27 | intentNumActual = jsonResult['installed'] |
| 28 | except TypeError as e: |
| 29 | intentNumActual = -1 |
| 30 | main.log.error( e ) |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 31 | if intentNumActual != intentNumExpected: |
| 32 | time.sleep( wait ) |
| 33 | jsonResult = main.ONOScli.intents( jsonFormat = True, summary = True, |
| 34 | TYPE = "multiPointToSinglePoint" ) |
Jon Hall | 2aa1656 | 2017-05-23 11:26:46 -0700 | [diff] [blame] | 35 | try: |
| 36 | intentNumActual = jsonResult['installed'] |
| 37 | except TypeError as e: |
| 38 | intentNumActual = -1 |
| 39 | main.log.error( e ) |
| 40 | main.log.info( "Intent number expected: {}".format( intentNumExpected ) ) |
| 41 | main.log.info( "Intent number from ONOS CLI: {}".format( intentNumActual ) ) |
pingping-lin | 4f80c49 | 2015-09-15 14:34:42 -0700 | [diff] [blame] | 42 | utilities.assertEquals( \ |
| 43 | expect = intentNumExpected, actual = intentNumActual, |
pingping-lin | b3ebd3f | 2015-09-28 22:17:05 -0700 | [diff] [blame] | 44 | onpass = "M2S intent number is correct!", |
| 45 | onfail = "M2S intent number is wrong!" ) |
pingping-lin | 4f80c49 | 2015-09-15 14:34:42 -0700 | [diff] [blame] | 46 | |
pingping-lin | 8244a3b | 2015-09-16 13:36:56 -0700 | [diff] [blame] | 47 | def checkP2PintentNum( main, intentNumExpected ): |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 48 | import time |
pingping-lin | 8244a3b | 2015-09-16 13:36:56 -0700 | [diff] [blame] | 49 | main.step( "Check P2P intents installed" ) |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 50 | wait = int( main.params['timers']['PathAvailable'] ) |
pingping-lin | 8244a3b | 2015-09-16 13:36:56 -0700 | [diff] [blame] | 51 | jsonResult = main.ONOScli.intents( jsonFormat = True, summary = True, |
| 52 | TYPE = "pointToPoint" ) |
Jon Hall | 2aa1656 | 2017-05-23 11:26:46 -0700 | [diff] [blame] | 53 | try: |
| 54 | intentNumActual = jsonResult['installed'] |
| 55 | except TypeError as e: |
| 56 | intentNumActual = -1 |
| 57 | main.log.error( e ) |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 58 | |
| 59 | if intentNumActual != intentNumExpected: |
| 60 | time.sleep( wait ) |
| 61 | jsonResult = main.ONOScli.intents( jsonFormat = True, summary = True, |
| 62 | TYPE = "pointToPoint" ) |
Jon Hall | 2aa1656 | 2017-05-23 11:26:46 -0700 | [diff] [blame] | 63 | try: |
| 64 | intentNumActual = jsonResult['installed'] |
| 65 | except TypeError as e: |
| 66 | intentNumActual = -1 |
| 67 | main.log.error( e ) |
| 68 | main.log.info( "Intent number expected: {}".format( intentNumExpected ) ) |
| 69 | main.log.info( "Intent number from ONOS CLI: {}".format( intentNumActual ) ) |
pingping-lin | 8244a3b | 2015-09-16 13:36:56 -0700 | [diff] [blame] | 70 | utilities.assertEquals( \ |
| 71 | expect = intentNumExpected, actual = intentNumActual, |
pingping-lin | b3ebd3f | 2015-09-28 22:17:05 -0700 | [diff] [blame] | 72 | onpass = "P2P intent number is correct!", |
| 73 | onfail = "P2P intent number is wrong!" ) |
pingping-lin | bab7f8a | 2015-09-21 17:33:36 -0700 | [diff] [blame] | 74 | |
| 75 | def checkFlowNum( main, switch, flowNumExpected ): |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 76 | import time |
pingping-lin | bab7f8a | 2015-09-21 17:33:36 -0700 | [diff] [blame] | 77 | main.step( "Check flow entry number in " + switch ) |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 78 | wait = int( main.params['timers']['PathAvailable'] ) |
Jon Hall | 2aa1656 | 2017-05-23 11:26:46 -0700 | [diff] [blame] | 79 | main.log.info( "Flow number expected: {}".format( flowNumExpected ) ) |
pingping-lin | bab7f8a | 2015-09-21 17:33:36 -0700 | [diff] [blame] | 80 | flowNumActual = main.Mininet.getSwitchFlowCount( switch ) |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 81 | if flowNumActual != flowNumExpected : |
| 82 | time.sleep( wait ) |
| 83 | flowNumActual = main.Mininet.getSwitchFlowCount( switch ) |
Jon Hall | 2aa1656 | 2017-05-23 11:26:46 -0700 | [diff] [blame] | 84 | main.log.info( "Flow number actual: {}".format( flowNumActual ) ) |
pingping-lin | bab7f8a | 2015-09-21 17:33:36 -0700 | [diff] [blame] | 85 | utilities.assertEquals( \ |
| 86 | expect = flowNumExpected, actual = flowNumActual, |
pingping-lin | b3ebd3f | 2015-09-28 22:17:05 -0700 | [diff] [blame] | 87 | onpass = "Flow number in " + switch + " is correct!", |
| 88 | onfail = "Flow number in " + switch + " is wrong!" ) |
pingping-lin | bab7f8a | 2015-09-21 17:33:36 -0700 | [diff] [blame] | 89 | |
pingping-lin | 829428d | 2015-09-22 20:50:00 -0700 | [diff] [blame] | 90 | |
alison | e4121a9 | 2016-11-22 16:31:36 -0800 | [diff] [blame] | 91 | def pingSpeakerToPeer( main, speakers = [ "spk1" ], |
| 92 | peers = [ "peer64514", "peer64515", "peer64516" ], |
pingping-lin | 829428d | 2015-09-22 20:50:00 -0700 | [diff] [blame] | 93 | expectAllSuccess = True ): |
| 94 | """ |
| 95 | Carry out ping test between each BGP speaker and peer pair |
| 96 | Optional argument: |
| 97 | * speakers - BGP speakers |
| 98 | * peers - BGP peers |
| 99 | * expectAllSuccess - boolean indicating if you expect all results |
| 100 | succeed if True, otherwise expect all results fail if False |
| 101 | """ |
| 102 | if len( speakers ) == 0: |
| 103 | main.log.error( "Parameter speakers can not be empty." ) |
pingping-lin | 5bb663b | 2015-09-24 11:47:50 -0700 | [diff] [blame] | 104 | main.cleanup() |
pingping-lin | 829428d | 2015-09-22 20:50:00 -0700 | [diff] [blame] | 105 | main.exit() |
| 106 | if len( peers ) == 0: |
| 107 | main.log.error( "Parameter speakers can not be empty." ) |
pingping-lin | 5bb663b | 2015-09-24 11:47:50 -0700 | [diff] [blame] | 108 | main.cleanup() |
pingping-lin | 829428d | 2015-09-22 20:50:00 -0700 | [diff] [blame] | 109 | main.exit() |
| 110 | |
| 111 | if expectAllSuccess: |
pingping-lin | 060d287 | 2015-09-29 18:16:29 -0700 | [diff] [blame] | 112 | main.step( "BGP speakers ping peers, expect all tests to succeed" ) |
pingping-lin | 829428d | 2015-09-22 20:50:00 -0700 | [diff] [blame] | 113 | else: |
pingping-lin | 060d287 | 2015-09-29 18:16:29 -0700 | [diff] [blame] | 114 | main.step( "BGP speakers ping peers, expect all tests to fail" ) |
pingping-lin | 829428d | 2015-09-22 20:50:00 -0700 | [diff] [blame] | 115 | |
| 116 | result = True |
| 117 | if expectAllSuccess: |
| 118 | for speaker in speakers: |
| 119 | for peer in peers: |
| 120 | tmpResult = main.Mininet.pingHost( src = speaker, |
| 121 | target = peer ) |
| 122 | result = result and ( tmpResult == main.TRUE ) |
| 123 | else: |
| 124 | for speaker in speakers: |
| 125 | for peer in peers: |
| 126 | tmpResult = main.Mininet.pingHost( src = speaker, |
| 127 | target = peer ) |
| 128 | |
| 129 | utilities.assert_equals( expect = True, actual = result, |
| 130 | onpass = "Ping test results are expected", |
| 131 | onfail = "Ping test results are Not expected" ) |
| 132 | |
| 133 | if result == False: |
pingping-lin | 5bb663b | 2015-09-24 11:47:50 -0700 | [diff] [blame] | 134 | main.cleanup() |
pingping-lin | 829428d | 2015-09-22 20:50:00 -0700 | [diff] [blame] | 135 | main.exit() |
| 136 | |
| 137 | |
alison | e4121a9 | 2016-11-22 16:31:36 -0800 | [diff] [blame] | 138 | def pingHostToHost( main, |
| 139 | hosts = [ "h64514", "h64515", "h64516" ], |
pingping-lin | 829428d | 2015-09-22 20:50:00 -0700 | [diff] [blame] | 140 | expectAllSuccess = True ): |
| 141 | """ |
| 142 | Carry out ping test between each BGP host pair |
| 143 | Optional argument: |
| 144 | * hosts - hosts behind BGP peer routers |
| 145 | * expectAllSuccess - boolean indicating if you expect all results |
| 146 | succeed if True, otherwise expect all results fail if False |
| 147 | """ |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 148 | main.step( "Check ping between each host pair, expect all to succede=" + |
| 149 | str( expectAllSuccess ) ) |
pingping-lin | 829428d | 2015-09-22 20:50:00 -0700 | [diff] [blame] | 150 | if len( hosts ) == 0: |
| 151 | main.log.error( "Parameter hosts can not be empty." ) |
pingping-lin | 5bb663b | 2015-09-24 11:47:50 -0700 | [diff] [blame] | 152 | main.cleanup() |
pingping-lin | 829428d | 2015-09-22 20:50:00 -0700 | [diff] [blame] | 153 | main.exit() |
| 154 | |
| 155 | result = True |
| 156 | if expectAllSuccess: |
| 157 | for srcHost in hosts: |
| 158 | for targetHost in hosts: |
| 159 | if srcHost != targetHost: |
| 160 | tmpResult = main.Mininet.pingHost( src = srcHost, |
| 161 | target = targetHost ) |
| 162 | result = result and ( tmpResult == main.TRUE ) |
| 163 | else: |
| 164 | for srcHost in hosts: |
| 165 | for targetHost in hosts: |
| 166 | if srcHost != targetHost: |
| 167 | tmpResult = main.Mininet.pingHost( src = srcHost, |
| 168 | target = targetHost ) |
| 169 | result = result and ( tmpResult == main.FALSE ) |
| 170 | |
| 171 | utilities.assert_equals( expect = True, actual = result, |
| 172 | onpass = "Ping test results are expected", |
| 173 | onfail = "Ping test results are Not expected" ) |
| 174 | |
pingping-lin | 581a366 | 2015-09-29 17:43:39 -0700 | [diff] [blame] | 175 | ''' |
pingping-lin | 829428d | 2015-09-22 20:50:00 -0700 | [diff] [blame] | 176 | if result == False: |
| 177 | main.cleanup() |
| 178 | main.exit() |
pingping-lin | 581a366 | 2015-09-29 17:43:39 -0700 | [diff] [blame] | 179 | ''' |
pingping-lin | 829428d | 2015-09-22 20:50:00 -0700 | [diff] [blame] | 180 | |