blob: 85b732d971642a96ab1354ed5e0a3d6285bb3de4 [file] [log] [blame]
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07001"""
2Copyright 2016 Open Networking Foundation (ONF)
3
4Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
5the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
6or 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-lin4f80c492015-09-15 14:34:42 -070021
22def checkRouteNum( main, routeNumExpected ):
Jon Hall6e9897d2016-02-29 14:41:32 -080023 import time
pingping-lin4f80c492015-09-15 14:34:42 -070024 main.step( "Check routes installed" )
Jon Hall6e9897d2016-02-29 14:41:32 -080025 wait = int( main.params['timers']['PathAvailable'] )
pingping-lin4f80c492015-09-15 14:34:42 -070026 main.log.info( "Route number expected:" )
27 main.log.info( routeNumExpected )
28 main.log.info( "Route number from ONOS CLI:" )
29
Devin Lim142b5342017-07-20 15:22:39 -070030 routeNumActual = main.Cluster.active( 0 ).CLI.ipv4RouteNumber()
Jon Hall6e9897d2016-02-29 14:41:32 -080031 if routeNumActual != routeNumExpected:
32 time.sleep( wait )
Devin Lim142b5342017-07-20 15:22:39 -070033 routeNumActual = main.Cluster.active( 0 ).CLI.ipv4RouteNumber()
pingping-lin4f80c492015-09-15 14:34:42 -070034 main.log.info( routeNumActual )
35 utilities.assertEquals( \
36 expect = routeNumExpected, actual = routeNumActual,
pingping-linb3ebd3f2015-09-28 22:17:05 -070037 onpass = "Route number is correct!",
38 onfail = "Route number is wrong!" )
pingping-lin4f80c492015-09-15 14:34:42 -070039
40def checkM2SintentNum( main, intentNumExpected ):
Jon Hall6e9897d2016-02-29 14:41:32 -080041 import time
pingping-lin4f80c492015-09-15 14:34:42 -070042 main.step( "Check M2S intents installed" )
Jon Hall6e9897d2016-02-29 14:41:32 -080043 wait = int( main.params['timers']['PathAvailable'] )
Devin Lim142b5342017-07-20 15:22:39 -070044 jsonResult = main.Cluster.active( 0 ).CLI.intents( jsonFormat = True, summary = True,
45 TYPE = "multiPointToSinglePoint" )
Jon Hall2aa16562017-05-23 11:26:46 -070046 try:
47 intentNumActual = jsonResult['installed']
48 except TypeError as e:
49 intentNumActual = -1
50 main.log.error( e )
Jon Hall6e9897d2016-02-29 14:41:32 -080051 if intentNumActual != intentNumExpected:
52 time.sleep( wait )
Devin Lim142b5342017-07-20 15:22:39 -070053 jsonResult = main.Cluster.active( 0 ).CLI.intents( jsonFormat = True, summary = True,
54 TYPE = "multiPointToSinglePoint" )
Jon Hall2aa16562017-05-23 11:26:46 -070055 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-lin4f80c492015-09-15 14:34:42 -070062 utilities.assertEquals( \
63 expect = intentNumExpected, actual = intentNumActual,
pingping-linb3ebd3f2015-09-28 22:17:05 -070064 onpass = "M2S intent number is correct!",
65 onfail = "M2S intent number is wrong!" )
pingping-lin4f80c492015-09-15 14:34:42 -070066
pingping-lin8244a3b2015-09-16 13:36:56 -070067def checkP2PintentNum( main, intentNumExpected ):
Jon Hall6e9897d2016-02-29 14:41:32 -080068 import time
pingping-lin8244a3b2015-09-16 13:36:56 -070069 main.step( "Check P2P intents installed" )
Jon Hall6e9897d2016-02-29 14:41:32 -080070 wait = int( main.params['timers']['PathAvailable'] )
Devin Lim142b5342017-07-20 15:22:39 -070071 jsonResult = main.Cluster.active( 0 ).CLI.intents( jsonFormat = True, summary = True,
72 TYPE = "pointToPoint" )
Jon Hall2aa16562017-05-23 11:26:46 -070073 try:
74 intentNumActual = jsonResult['installed']
75 except TypeError as e:
76 intentNumActual = -1
77 main.log.error( e )
Jon Hall6e9897d2016-02-29 14:41:32 -080078
79 if intentNumActual != intentNumExpected:
80 time.sleep( wait )
Devin Lim142b5342017-07-20 15:22:39 -070081 jsonResult = main.Cluster.active( 0 ).CLI.intents( jsonFormat = True, summary = True,
82 TYPE = "pointToPoint" )
Jon Hall2aa16562017-05-23 11:26:46 -070083 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-lin8244a3b2015-09-16 13:36:56 -070090 utilities.assertEquals( \
91 expect = intentNumExpected, actual = intentNumActual,
pingping-linb3ebd3f2015-09-28 22:17:05 -070092 onpass = "P2P intent number is correct!",
93 onfail = "P2P intent number is wrong!" )
pingping-linbab7f8a2015-09-21 17:33:36 -070094
95def checkFlowNum( main, switch, flowNumExpected ):
Jon Hall6e9897d2016-02-29 14:41:32 -080096 import time
pingping-linbab7f8a2015-09-21 17:33:36 -070097 main.step( "Check flow entry number in " + switch )
Jon Hall6e9897d2016-02-29 14:41:32 -080098 wait = int( main.params['timers']['PathAvailable'] )
Jon Hall2aa16562017-05-23 11:26:46 -070099 main.log.info( "Flow number expected: {}".format( flowNumExpected ) )
pingping-linbab7f8a2015-09-21 17:33:36 -0700100 flowNumActual = main.Mininet.getSwitchFlowCount( switch )
Jon Hall6e9897d2016-02-29 14:41:32 -0800101 if flowNumActual != flowNumExpected :
102 time.sleep( wait )
103 flowNumActual = main.Mininet.getSwitchFlowCount( switch )
Jon Hall2aa16562017-05-23 11:26:46 -0700104 main.log.info( "Flow number actual: {}".format( flowNumActual ) )
pingping-linbab7f8a2015-09-21 17:33:36 -0700105 utilities.assertEquals( \
106 expect = flowNumExpected, actual = flowNumActual,
pingping-linb3ebd3f2015-09-28 22:17:05 -0700107 onpass = "Flow number in " + switch + " is correct!",
108 onfail = "Flow number in " + switch + " is wrong!" )
pingping-linbab7f8a2015-09-21 17:33:36 -0700109
pingping-lin829428d2015-09-22 20:50:00 -0700110
alisone4121a92016-11-22 16:31:36 -0800111def pingSpeakerToPeer( main, speakers = [ "spk1" ],
112 peers = [ "peer64514", "peer64515", "peer64516" ],
pingping-lin829428d2015-09-22 20:50:00 -0700113 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-lin5bb663b2015-09-24 11:47:50 -0700124 main.cleanup()
pingping-lin829428d2015-09-22 20:50:00 -0700125 main.exit()
126 if len( peers ) == 0:
127 main.log.error( "Parameter speakers can not be empty." )
pingping-lin5bb663b2015-09-24 11:47:50 -0700128 main.cleanup()
pingping-lin829428d2015-09-22 20:50:00 -0700129 main.exit()
130
131 if expectAllSuccess:
pingping-lin060d2872015-09-29 18:16:29 -0700132 main.step( "BGP speakers ping peers, expect all tests to succeed" )
pingping-lin829428d2015-09-22 20:50:00 -0700133 else:
pingping-lin060d2872015-09-29 18:16:29 -0700134 main.step( "BGP speakers ping peers, expect all tests to fail" )
pingping-lin829428d2015-09-22 20:50:00 -0700135
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-lin5bb663b2015-09-24 11:47:50 -0700154 main.cleanup()
pingping-lin829428d2015-09-22 20:50:00 -0700155 main.exit()
156
157
alisone4121a92016-11-22 16:31:36 -0800158def pingHostToHost( main,
159 hosts = [ "h64514", "h64515", "h64516" ],
pingping-lin829428d2015-09-22 20:50:00 -0700160 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 Hall6e9897d2016-02-29 14:41:32 -0800168 main.step( "Check ping between each host pair, expect all to succede=" +
169 str( expectAllSuccess ) )
pingping-lin829428d2015-09-22 20:50:00 -0700170 if len( hosts ) == 0:
171 main.log.error( "Parameter hosts can not be empty." )
pingping-lin5bb663b2015-09-24 11:47:50 -0700172 main.cleanup()
pingping-lin829428d2015-09-22 20:50:00 -0700173 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-lin581a3662015-09-29 17:43:39 -0700195 '''
pingping-lin829428d2015-09-22 20:50:00 -0700196 if result == False:
197 main.cleanup()
198 main.exit()
pingping-lin581a3662015-09-29 17:43:39 -0700199 '''
pingping-lin829428d2015-09-22 20:50:00 -0700200