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