blob: fe3b1e29a9cb7f0649d1f64338b91015963c43df [file] [log] [blame]
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07001"""
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -07002Copyright 2016 Open Networking Foundation ( ONF )
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07003
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
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070011 ( at your option ) any later version.
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -070012
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 -070021def checkRouteNum( main, routeNumExpected ):
Jon Hall6e9897d2016-02-29 14:41:32 -080022 import time
pingping-lin4f80c492015-09-15 14:34:42 -070023 main.step( "Check routes installed" )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070024 wait = int( main.params[ 'timers' ][ 'PathAvailable' ] )
pingping-lin4f80c492015-09-15 14:34:42 -070025 main.log.info( "Route number expected:" )
26 main.log.info( routeNumExpected )
27 main.log.info( "Route number from ONOS CLI:" )
28
Devin Lim142b5342017-07-20 15:22:39 -070029 routeNumActual = main.Cluster.active( 0 ).CLI.ipv4RouteNumber()
Jon Hall6e9897d2016-02-29 14:41:32 -080030 if routeNumActual != routeNumExpected:
31 time.sleep( wait )
Devin Lim142b5342017-07-20 15:22:39 -070032 routeNumActual = main.Cluster.active( 0 ).CLI.ipv4RouteNumber()
pingping-lin4f80c492015-09-15 14:34:42 -070033 main.log.info( routeNumActual )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070034 utilities.assertEquals(
35 expect=routeNumExpected, actual=routeNumActual,
36 onpass="Route number is correct!",
37 onfail="Route number is wrong!" )
38
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" )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070043 wait = int( main.params[ 'timers' ][ 'PathAvailable' ] )
44 jsonResult = main.Cluster.active( 0 ).CLI.intents( jsonFormat=True, summary=True,
45 TYPE="multiPointToSinglePoint" )
Jon Hall2aa16562017-05-23 11:26:46 -070046 try:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070047 intentNumActual = jsonResult[ 'installed' ]
Jon Hall2aa16562017-05-23 11:26:46 -070048 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 )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070053 jsonResult = main.Cluster.active( 0 ).CLI.intents( jsonFormat=True, summary=True,
54 TYPE="multiPointToSinglePoint" )
Jon Hall2aa16562017-05-23 11:26:46 -070055 try:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070056 intentNumActual = jsonResult[ 'installed' ]
Jon Hall2aa16562017-05-23 11:26:46 -070057 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 Ronquillo23fb2162017-09-15 14:59:57 -070062 utilities.assertEquals(
63 expect=intentNumExpected, actual=intentNumActual,
64 onpass="M2S intent number is correct!",
65 onfail="M2S intent number is wrong!" )
66
pingping-lin4f80c492015-09-15 14:34:42 -070067
pingping-lin8244a3b2015-09-16 13:36:56 -070068def checkP2PintentNum( main, intentNumExpected ):
Jon Hall6e9897d2016-02-29 14:41:32 -080069 import time
pingping-lin8244a3b2015-09-16 13:36:56 -070070 main.step( "Check P2P intents installed" )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070071 wait = int( main.params[ 'timers' ][ 'PathAvailable' ] )
72 jsonResult = main.Cluster.active( 0 ).CLI.intents( jsonFormat=True, summary=True,
73 TYPE="pointToPoint" )
Jon Hall2aa16562017-05-23 11:26:46 -070074 try:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070075 intentNumActual = jsonResult[ 'installed' ]
Jon Hall2aa16562017-05-23 11:26:46 -070076 except TypeError as e:
77 intentNumActual = -1
78 main.log.error( e )
Jon Hall6e9897d2016-02-29 14:41:32 -080079
80 if intentNumActual != intentNumExpected:
81 time.sleep( wait )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070082 jsonResult = main.Cluster.active( 0 ).CLI.intents( jsonFormat=True, summary=True,
83 TYPE="pointToPoint" )
Jon Hall2aa16562017-05-23 11:26:46 -070084 try:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070085 intentNumActual = jsonResult[ 'installed' ]
Jon Hall2aa16562017-05-23 11:26:46 -070086 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 Ronquillo23fb2162017-09-15 14:59:57 -070091 utilities.assertEquals(
92 expect=intentNumExpected, actual=intentNumActual,
93 onpass="P2P intent number is correct!",
94 onfail="P2P intent number is wrong!" )
95
pingping-linbab7f8a2015-09-21 17:33:36 -070096
97def checkFlowNum( main, switch, flowNumExpected ):
Jon Hall6e9897d2016-02-29 14:41:32 -080098 import time
pingping-linbab7f8a2015-09-21 17:33:36 -070099 main.step( "Check flow entry number in " + switch )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700100 wait = int( main.params[ 'timers' ][ 'PathAvailable' ] )
Jon Hall2aa16562017-05-23 11:26:46 -0700101 main.log.info( "Flow number expected: {}".format( flowNumExpected ) )
pingping-linbab7f8a2015-09-21 17:33:36 -0700102 flowNumActual = main.Mininet.getSwitchFlowCount( switch )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700103 if flowNumActual != flowNumExpected:
Jon Hall6e9897d2016-02-29 14:41:32 -0800104 time.sleep( wait )
105 flowNumActual = main.Mininet.getSwitchFlowCount( switch )
Jon Hall2aa16562017-05-23 11:26:46 -0700106 main.log.info( "Flow number actual: {}".format( flowNumActual ) )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700107 utilities.assertEquals(
108 expect=flowNumExpected, actual=flowNumActual,
109 onpass="Flow number in " + switch + " is correct!",
110 onfail="Flow number in " + switch + " is wrong!" )
pingping-linbab7f8a2015-09-21 17:33:36 -0700111
pingping-lin829428d2015-09-22 20:50:00 -0700112
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700113def pingSpeakerToPeer( main, speakers=[ "spk1" ],
114 peers=[ "peer64514", "peer64515", "peer64516" ],
115 expectAllSuccess=True ):
pingping-lin829428d2015-09-22 20:50:00 -0700116 """
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 Lim44075962017-08-11 10:56:37 -0700126 main.cleanAndExit()
pingping-lin829428d2015-09-22 20:50:00 -0700127 if len( peers ) == 0:
128 main.log.error( "Parameter speakers can not be empty." )
Devin Lim44075962017-08-11 10:56:37 -0700129 main.cleanAndExit()
pingping-lin829428d2015-09-22 20:50:00 -0700130
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:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700140 tmpResult = main.Mininet.pingHost( src=speaker,
141 target=peer )
pingping-lin829428d2015-09-22 20:50:00 -0700142 result = result and ( tmpResult == main.TRUE )
143 else:
144 for speaker in speakers:
145 for peer in peers:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700146 tmpResult = main.Mininet.pingHost( src=speaker,
147 target=peer )
pingping-lin829428d2015-09-22 20:50:00 -0700148
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700149 utilities.assert_equals( expect=True, actual=result,
150 onpass="Ping test results are expected",
151 onfail="Ping test results are Not expected" )
pingping-lin829428d2015-09-22 20:50:00 -0700152
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700153 if not result:
You Wang7880b372019-02-27 16:50:47 -0800154 main.cleanAndExit( alarm=False )
pingping-lin829428d2015-09-22 20:50:00 -0700155
156
alisone4121a92016-11-22 16:31:36 -0800157def pingHostToHost( main,
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700158 hosts=[ "h64514", "h64515", "h64516" ],
159 expectAllSuccess=True ):
pingping-lin829428d2015-09-22 20:50:00 -0700160 """
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 Hall6e9897d2016-02-29 14:41:32 -0800167 main.step( "Check ping between each host pair, expect all to succede=" +
168 str( expectAllSuccess ) )
pingping-lin829428d2015-09-22 20:50:00 -0700169 if len( hosts ) == 0:
170 main.log.error( "Parameter hosts can not be empty." )
Devin Lim44075962017-08-11 10:56:37 -0700171 main.cleanAndExit()
pingping-lin829428d2015-09-22 20:50:00 -0700172
173 result = True
174 if expectAllSuccess:
175 for srcHost in hosts:
176 for targetHost in hosts:
177 if srcHost != targetHost:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700178 tmpResult = main.Mininet.pingHost( src=srcHost,
179 target=targetHost )
pingping-lin829428d2015-09-22 20:50:00 -0700180 result = result and ( tmpResult == main.TRUE )
181 else:
182 for srcHost in hosts:
183 for targetHost in hosts:
184 if srcHost != targetHost:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700185 tmpResult = main.Mininet.pingHost( src=srcHost,
186 target=targetHost )
pingping-lin829428d2015-09-22 20:50:00 -0700187 result = result and ( tmpResult == main.FALSE )
188
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700189 utilities.assert_equals( expect=True, actual=result,
190 onpass="Ping test results are expected",
191 onfail="Ping test results are Not expected" )
pingping-lin829428d2015-09-22 20:50:00 -0700192
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700193 """
pingping-lin829428d2015-09-22 20:50:00 -0700194 if result == False:
Devin Lim44075962017-08-11 10:56:37 -0700195 main.cleanAndExit()
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700196 """