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