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