Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 1 | """ |
| 2 | Copyright 2016 Open Networking Foundation (ONF) |
| 3 | |
| 4 | Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>, |
| 5 | the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>, |
| 6 | or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg> |
| 7 | |
| 8 | TestON is free software: you can redistribute it and/or modify |
| 9 | it under the terms of the GNU General Public License as published by |
| 10 | the Free Software Foundation, either version 2 of the License, or |
| 11 | (at your option) any later version. |
| 12 | |
| 13 | TestON is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with TestON. If not, see <http://www.gnu.org/licenses/>. |
| 20 | """ |
pingping-lin | ffca7e2 | 2015-11-13 15:43:08 -0800 | [diff] [blame] | 21 | |
| 22 | def checkRouteNum( main, routeNumExpected ): |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 23 | import time |
pingping-lin | ffca7e2 | 2015-11-13 15:43:08 -0800 | [diff] [blame] | 24 | main.step( "Check routes installed" ) |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 25 | wait = int( main.params['timers']['PathAvailable'] ) |
pingping-lin | ffca7e2 | 2015-11-13 15:43:08 -0800 | [diff] [blame] | 26 | main.log.info( "Route number expected:" ) |
| 27 | main.log.info( routeNumExpected ) |
| 28 | main.log.info( "Route number from ONOS CLI:" ) |
| 29 | |
suibin zhang | 464f19e | 2016-05-24 08:55:10 -0700 | [diff] [blame] | 30 | routeNumActual = main.ONOScli1.ipv4RouteNumber() |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 31 | if routeNumActual != routeNumExpected: |
| 32 | time.sleep( wait ) |
suibin zhang | 464f19e | 2016-05-24 08:55:10 -0700 | [diff] [blame] | 33 | routeNumActual = main.ONOScli1.ipv4RouteNumber() |
pingping-lin | ffca7e2 | 2015-11-13 15:43:08 -0800 | [diff] [blame] | 34 | main.log.info( routeNumActual ) |
| 35 | utilities.assertEquals( \ |
| 36 | expect = routeNumExpected, actual = routeNumActual, |
| 37 | onpass = "Route number is correct!", |
| 38 | onfail = "Route number is wrong!" ) |
| 39 | |
| 40 | def checkM2SintentNum( main, intentNumExpected ): |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 41 | import time |
pingping-lin | ffca7e2 | 2015-11-13 15:43:08 -0800 | [diff] [blame] | 42 | main.step( "Check M2S intents installed" ) |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 43 | wait = int( main.params['timers']['PathAvailable'] ) |
pingping-lin | ffca7e2 | 2015-11-13 15:43:08 -0800 | [diff] [blame] | 44 | main.log.info( "Intent number expected:" ) |
| 45 | main.log.info( intentNumExpected ) |
| 46 | main.log.info( "Intent number from ONOS CLI:" ) |
suibin zhang | 464f19e | 2016-05-24 08:55:10 -0700 | [diff] [blame] | 47 | jsonResult = main.ONOScli1.intents( jsonFormat = True, summary = True, |
pingping-lin | ffca7e2 | 2015-11-13 15:43:08 -0800 | [diff] [blame] | 48 | TYPE = "multiPointToSinglePoint" ) |
| 49 | intentNumActual = jsonResult['installed'] |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 50 | if intentNumActual != intentNumExpected: |
| 51 | time.sleep( wait ) |
suibin zhang | 464f19e | 2016-05-24 08:55:10 -0700 | [diff] [blame] | 52 | jsonResult = main.ONOScli1.intents( jsonFormat = True, summary = True, |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 53 | TYPE = "multiPointToSinglePoint" ) |
| 54 | intentNumActual = jsonResult['installed'] |
pingping-lin | ffca7e2 | 2015-11-13 15:43:08 -0800 | [diff] [blame] | 55 | main.log.info( intentNumActual ) |
| 56 | utilities.assertEquals( \ |
| 57 | expect = intentNumExpected, actual = intentNumActual, |
| 58 | onpass = "M2S intent number is correct!", |
| 59 | onfail = "M2S intent number is wrong!" ) |
| 60 | |
| 61 | def checkP2PintentNum( main, intentNumExpected ): |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 62 | import time |
pingping-lin | ffca7e2 | 2015-11-13 15:43:08 -0800 | [diff] [blame] | 63 | main.step( "Check P2P intents installed" ) |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 64 | wait = int( main.params['timers']['PathAvailable'] ) |
pingping-lin | ffca7e2 | 2015-11-13 15:43:08 -0800 | [diff] [blame] | 65 | main.log.info( "Intent number expected:" ) |
| 66 | main.log.info( intentNumExpected ) |
| 67 | main.log.info( "Intent number from ONOS CLI:" ) |
suibin zhang | 464f19e | 2016-05-24 08:55:10 -0700 | [diff] [blame] | 68 | jsonResult = main.ONOScli1.intents( jsonFormat = True, summary = True, |
pingping-lin | ffca7e2 | 2015-11-13 15:43:08 -0800 | [diff] [blame] | 69 | TYPE = "pointToPoint" ) |
| 70 | intentNumActual = jsonResult['installed'] |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 71 | |
| 72 | if intentNumActual != intentNumExpected: |
| 73 | time.sleep( wait ) |
suibin zhang | 464f19e | 2016-05-24 08:55:10 -0700 | [diff] [blame] | 74 | jsonResult = main.ONOScli1.intents( jsonFormat = True, summary = True, |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 75 | TYPE = "pointToPoint" ) |
| 76 | intentNumActual = jsonResult['installed'] |
pingping-lin | ffca7e2 | 2015-11-13 15:43:08 -0800 | [diff] [blame] | 77 | main.log.info( intentNumActual ) |
| 78 | utilities.assertEquals( \ |
| 79 | expect = intentNumExpected, actual = intentNumActual, |
| 80 | onpass = "P2P intent number is correct!", |
| 81 | onfail = "P2P intent number is wrong!" ) |
| 82 | |
| 83 | def checkFlowNum( main, switch, flowNumExpected ): |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 84 | import time |
pingping-lin | ffca7e2 | 2015-11-13 15:43:08 -0800 | [diff] [blame] | 85 | main.step( "Check flow entry number in " + switch ) |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 86 | wait = int( main.params['timers']['PathAvailable'] ) |
pingping-lin | ffca7e2 | 2015-11-13 15:43:08 -0800 | [diff] [blame] | 87 | main.log.info( "Flow number expected:" ) |
| 88 | main.log.info( flowNumExpected ) |
| 89 | main.log.info( "Flow number actual:" ) |
| 90 | flowNumActual = main.Mininet.getSwitchFlowCount( switch ) |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 91 | if flowNumActual != flowNumExpected : |
| 92 | time.sleep( wait ) |
| 93 | flowNumActual = main.Mininet.getSwitchFlowCount( switch ) |
pingping-lin | ffca7e2 | 2015-11-13 15:43:08 -0800 | [diff] [blame] | 94 | main.log.info( flowNumActual ) |
| 95 | utilities.assertEquals( \ |
| 96 | expect = flowNumExpected, actual = flowNumActual, |
| 97 | onpass = "Flow number in " + switch + " is correct!", |
| 98 | onfail = "Flow number in " + switch + " is wrong!" ) |
| 99 | |
| 100 | |
| 101 | def pingSpeakerToPeer( main, speakers = ["speaker1"], |
pingping-lin | ed7a26b | 2015-12-15 19:03:57 -0800 | [diff] [blame] | 102 | peers = ["pr64514", "pr64515", "pr64516"], |
pingping-lin | ffca7e2 | 2015-11-13 15:43:08 -0800 | [diff] [blame] | 103 | expectAllSuccess = True ): |
| 104 | """ |
| 105 | Carry out ping test between each BGP speaker and peer pair |
| 106 | Optional argument: |
| 107 | * speakers - BGP speakers |
| 108 | * peers - BGP peers |
| 109 | * expectAllSuccess - boolean indicating if you expect all results |
| 110 | succeed if True, otherwise expect all results fail if False |
| 111 | """ |
| 112 | if len( speakers ) == 0: |
| 113 | main.log.error( "Parameter speakers can not be empty." ) |
| 114 | main.cleanup() |
| 115 | main.exit() |
| 116 | if len( peers ) == 0: |
| 117 | main.log.error( "Parameter speakers can not be empty." ) |
| 118 | main.cleanup() |
| 119 | main.exit() |
| 120 | |
| 121 | if expectAllSuccess: |
| 122 | main.step( "BGP speakers ping peers, expect all tests to succeed" ) |
| 123 | else: |
| 124 | main.step( "BGP speakers ping peers, expect all tests to fail" ) |
| 125 | |
| 126 | result = True |
| 127 | if expectAllSuccess: |
| 128 | for speaker in speakers: |
| 129 | for peer in peers: |
| 130 | tmpResult = main.Mininet.pingHost( src = speaker, |
| 131 | target = peer ) |
| 132 | result = result and ( tmpResult == main.TRUE ) |
| 133 | else: |
| 134 | for speaker in speakers: |
| 135 | for peer in peers: |
| 136 | tmpResult = main.Mininet.pingHost( src = speaker, |
| 137 | target = peer ) |
| 138 | |
| 139 | utilities.assert_equals( expect = True, actual = result, |
| 140 | onpass = "Ping test results are expected", |
| 141 | onfail = "Ping test results are Not expected" ) |
| 142 | |
| 143 | if result == False: |
| 144 | main.cleanup() |
| 145 | main.exit() |
| 146 | |
| 147 | |
| 148 | def pingHostToHost( main, hosts = ["host64514", "host64515", "host64516"], |
| 149 | expectAllSuccess = True ): |
| 150 | """ |
| 151 | Carry out ping test between each BGP host pair |
| 152 | Optional argument: |
| 153 | * hosts - hosts behind BGP peer routers |
| 154 | * expectAllSuccess - boolean indicating if you expect all results |
| 155 | succeed if True, otherwise expect all results fail if False |
| 156 | """ |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 157 | main.step( "Check ping between each host pair, expect all to succede=" + |
| 158 | str( expectAllSuccess ) ) |
pingping-lin | ffca7e2 | 2015-11-13 15:43:08 -0800 | [diff] [blame] | 159 | if len( hosts ) == 0: |
| 160 | main.log.error( "Parameter hosts can not be empty." ) |
| 161 | main.cleanup() |
| 162 | main.exit() |
| 163 | |
| 164 | result = True |
| 165 | if expectAllSuccess: |
| 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.TRUE ) |
| 172 | else: |
| 173 | for srcHost in hosts: |
| 174 | for targetHost in hosts: |
| 175 | if srcHost != targetHost: |
| 176 | tmpResult = main.Mininet.pingHost( src = srcHost, |
| 177 | target = targetHost ) |
| 178 | result = result and ( tmpResult == main.FALSE ) |
| 179 | |
| 180 | utilities.assert_equals( expect = True, actual = result, |
| 181 | onpass = "Ping test results are expected", |
| 182 | onfail = "Ping test results are Not expected" ) |
| 183 | |
| 184 | ''' |
| 185 | if result == False: |
| 186 | main.cleanup() |
| 187 | main.exit() |
| 188 | ''' |
| 189 | |