pingping-lin | ffca7e2 | 2015-11-13 15:43:08 -0800 | [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 | ffca7e2 | 2015-11-13 15:43:08 -0800 | [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 | ffca7e2 | 2015-11-13 15:43:08 -0800 | [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 | ffca7e2 | 2015-11-13 15:43:08 -0800 | [diff] [blame] | 14 | main.log.info( routeNumActual ) |
| 15 | utilities.assertEquals( \ |
| 16 | expect = routeNumExpected, actual = routeNumActual, |
| 17 | onpass = "Route number is correct!", |
| 18 | onfail = "Route number is wrong!" ) |
| 19 | |
| 20 | def checkM2SintentNum( main, intentNumExpected ): |
Jon Hall | 17673bf | 2016-03-04 13:01:40 -0800 | [diff] [blame^] | 21 | import time |
pingping-lin | ffca7e2 | 2015-11-13 15:43:08 -0800 | [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 | ffca7e2 | 2015-11-13 15:43:08 -0800 | [diff] [blame] | 24 | main.log.info( "Intent number expected:" ) |
| 25 | main.log.info( intentNumExpected ) |
| 26 | main.log.info( "Intent number from ONOS CLI:" ) |
| 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 | ffca7e2 | 2015-11-13 15:43:08 -0800 | [diff] [blame] | 35 | main.log.info( intentNumActual ) |
| 36 | utilities.assertEquals( \ |
| 37 | expect = intentNumExpected, actual = intentNumActual, |
| 38 | onpass = "M2S intent number is correct!", |
| 39 | onfail = "M2S intent number is wrong!" ) |
| 40 | |
| 41 | def checkP2PintentNum( main, intentNumExpected ): |
Jon Hall | 17673bf | 2016-03-04 13:01:40 -0800 | [diff] [blame^] | 42 | import time |
pingping-lin | ffca7e2 | 2015-11-13 15:43:08 -0800 | [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 | ffca7e2 | 2015-11-13 15:43:08 -0800 | [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 | ffca7e2 | 2015-11-13 15:43:08 -0800 | [diff] [blame] | 57 | main.log.info( intentNumActual ) |
| 58 | utilities.assertEquals( \ |
| 59 | expect = intentNumExpected, actual = intentNumActual, |
| 60 | onpass = "P2P intent number is correct!", |
| 61 | onfail = "P2P intent number is wrong!" ) |
| 62 | |
| 63 | def checkFlowNum( main, switch, flowNumExpected ): |
Jon Hall | 17673bf | 2016-03-04 13:01:40 -0800 | [diff] [blame^] | 64 | import time |
pingping-lin | ffca7e2 | 2015-11-13 15:43:08 -0800 | [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 | ffca7e2 | 2015-11-13 15:43:08 -0800 | [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 | ffca7e2 | 2015-11-13 15:43:08 -0800 | [diff] [blame] | 74 | main.log.info( flowNumActual ) |
| 75 | utilities.assertEquals( \ |
| 76 | expect = flowNumExpected, actual = flowNumActual, |
| 77 | onpass = "Flow number in " + switch + " is correct!", |
| 78 | onfail = "Flow number in " + switch + " is wrong!" ) |
| 79 | |
| 80 | |
| 81 | def pingSpeakerToPeer( main, speakers = ["speaker1"], |
pingping-lin | ed7a26b | 2015-12-15 19:03:57 -0800 | [diff] [blame] | 82 | peers = ["pr64514", "pr64515", "pr64516"], |
pingping-lin | ffca7e2 | 2015-11-13 15:43:08 -0800 | [diff] [blame] | 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." ) |
| 94 | main.cleanup() |
| 95 | main.exit() |
| 96 | if len( peers ) == 0: |
| 97 | main.log.error( "Parameter speakers can not be empty." ) |
| 98 | main.cleanup() |
| 99 | main.exit() |
| 100 | |
| 101 | if expectAllSuccess: |
| 102 | main.step( "BGP speakers ping peers, expect all tests to succeed" ) |
| 103 | else: |
| 104 | main.step( "BGP speakers ping peers, expect all tests to fail" ) |
| 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: |
| 124 | main.cleanup() |
| 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 | ffca7e2 | 2015-11-13 15:43:08 -0800 | [diff] [blame] | 139 | if len( hosts ) == 0: |
| 140 | main.log.error( "Parameter hosts can not be empty." ) |
| 141 | main.cleanup() |
| 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 | |
| 164 | ''' |
| 165 | if result == False: |
| 166 | main.cleanup() |
| 167 | main.exit() |
| 168 | ''' |
| 169 | |