blob: a2842137576990a66251ead22661e9eb4c730b21 [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." )
Devin Lim44075962017-08-11 10:56:37 -0700124 main.cleanAndExit()
pingping-lin829428d2015-09-22 20:50:00 -0700125 if len( peers ) == 0:
126 main.log.error( "Parameter speakers can not be empty." )
Devin Lim44075962017-08-11 10:56:37 -0700127 main.cleanAndExit()
pingping-lin829428d2015-09-22 20:50:00 -0700128
129 if expectAllSuccess:
pingping-lin060d2872015-09-29 18:16:29 -0700130 main.step( "BGP speakers ping peers, expect all tests to succeed" )
pingping-lin829428d2015-09-22 20:50:00 -0700131 else:
pingping-lin060d2872015-09-29 18:16:29 -0700132 main.step( "BGP speakers ping peers, expect all tests to fail" )
pingping-lin829428d2015-09-22 20:50:00 -0700133
134 result = True
135 if expectAllSuccess:
136 for speaker in speakers:
137 for peer in peers:
138 tmpResult = main.Mininet.pingHost( src = speaker,
139 target = peer )
140 result = result and ( tmpResult == main.TRUE )
141 else:
142 for speaker in speakers:
143 for peer in peers:
144 tmpResult = main.Mininet.pingHost( src = speaker,
145 target = peer )
146
147 utilities.assert_equals( expect = True, actual = result,
148 onpass = "Ping test results are expected",
149 onfail = "Ping test results are Not expected" )
150
151 if result == False:
Devin Lim44075962017-08-11 10:56:37 -0700152 main.cleanAndExit()
pingping-lin829428d2015-09-22 20:50:00 -0700153
154
alisone4121a92016-11-22 16:31:36 -0800155def pingHostToHost( main,
156 hosts = [ "h64514", "h64515", "h64516" ],
pingping-lin829428d2015-09-22 20:50:00 -0700157 expectAllSuccess = True ):
158 """
159 Carry out ping test between each BGP host pair
160 Optional argument:
161 * hosts - hosts behind BGP peer routers
162 * expectAllSuccess - boolean indicating if you expect all results
163 succeed if True, otherwise expect all results fail if False
164 """
Jon Hall6e9897d2016-02-29 14:41:32 -0800165 main.step( "Check ping between each host pair, expect all to succede=" +
166 str( expectAllSuccess ) )
pingping-lin829428d2015-09-22 20:50:00 -0700167 if len( hosts ) == 0:
168 main.log.error( "Parameter hosts can not be empty." )
Devin Lim44075962017-08-11 10:56:37 -0700169 main.cleanAndExit()
pingping-lin829428d2015-09-22 20:50:00 -0700170
171 result = True
172 if expectAllSuccess:
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.TRUE )
179 else:
180 for srcHost in hosts:
181 for targetHost in hosts:
182 if srcHost != targetHost:
183 tmpResult = main.Mininet.pingHost( src = srcHost,
184 target = targetHost )
185 result = result and ( tmpResult == main.FALSE )
186
187 utilities.assert_equals( expect = True, actual = result,
188 onpass = "Ping test results are expected",
189 onfail = "Ping test results are Not expected" )
190
pingping-lin581a3662015-09-29 17:43:39 -0700191 '''
pingping-lin829428d2015-09-22 20:50:00 -0700192 if result == False:
Devin Lim44075962017-08-11 10:56:37 -0700193 main.cleanAndExit()
pingping-lin581a3662015-09-29 17:43:39 -0700194 '''
pingping-lin829428d2015-09-22 20:50:00 -0700195