blob: 42920243c203a59114ac805297b50bc1fcafbd59 [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-linffca7e22015-11-13 15:43:08 -080021
22def checkRouteNum( main, routeNumExpected ):
Jon Hall6e9897d2016-02-29 14:41:32 -080023 import time
pingping-linffca7e22015-11-13 15:43:08 -080024 main.step( "Check routes installed" )
Jon Hall6e9897d2016-02-29 14:41:32 -080025 wait = int( main.params['timers']['PathAvailable'] )
pingping-linffca7e22015-11-13 15:43:08 -080026 main.log.info( "Route number expected:" )
27 main.log.info( routeNumExpected )
28 main.log.info( "Route number from ONOS CLI:" )
29
suibin zhang464f19e2016-05-24 08:55:10 -070030 routeNumActual = main.ONOScli1.ipv4RouteNumber()
Jon Hall6e9897d2016-02-29 14:41:32 -080031 if routeNumActual != routeNumExpected:
32 time.sleep( wait )
suibin zhang464f19e2016-05-24 08:55:10 -070033 routeNumActual = main.ONOScli1.ipv4RouteNumber()
pingping-linffca7e22015-11-13 15:43:08 -080034 main.log.info( routeNumActual )
35 utilities.assertEquals( \
36 expect = routeNumExpected, actual = routeNumActual,
37 onpass = "Route number is correct!",
38 onfail = "Route number is wrong!" )
39
40def checkM2SintentNum( main, intentNumExpected ):
Jon Hall6e9897d2016-02-29 14:41:32 -080041 import time
pingping-linffca7e22015-11-13 15:43:08 -080042 main.step( "Check M2S intents installed" )
Jon Hall6e9897d2016-02-29 14:41:32 -080043 wait = int( main.params['timers']['PathAvailable'] )
pingping-linffca7e22015-11-13 15:43:08 -080044 main.log.info( "Intent number expected:" )
45 main.log.info( intentNumExpected )
46 main.log.info( "Intent number from ONOS CLI:" )
suibin zhang464f19e2016-05-24 08:55:10 -070047 jsonResult = main.ONOScli1.intents( jsonFormat = True, summary = True,
pingping-linffca7e22015-11-13 15:43:08 -080048 TYPE = "multiPointToSinglePoint" )
49 intentNumActual = jsonResult['installed']
Jon Hall6e9897d2016-02-29 14:41:32 -080050 if intentNumActual != intentNumExpected:
51 time.sleep( wait )
suibin zhang464f19e2016-05-24 08:55:10 -070052 jsonResult = main.ONOScli1.intents( jsonFormat = True, summary = True,
Jon Hall6e9897d2016-02-29 14:41:32 -080053 TYPE = "multiPointToSinglePoint" )
54 intentNumActual = jsonResult['installed']
pingping-linffca7e22015-11-13 15:43:08 -080055 main.log.info( intentNumActual )
56 utilities.assertEquals( \
57 expect = intentNumExpected, actual = intentNumActual,
58 onpass = "M2S intent number is correct!",
59 onfail = "M2S intent number is wrong!" )
60
61def checkP2PintentNum( main, intentNumExpected ):
Jon Hall6e9897d2016-02-29 14:41:32 -080062 import time
pingping-linffca7e22015-11-13 15:43:08 -080063 main.step( "Check P2P intents installed" )
Jon Hall6e9897d2016-02-29 14:41:32 -080064 wait = int( main.params['timers']['PathAvailable'] )
pingping-linffca7e22015-11-13 15:43:08 -080065 main.log.info( "Intent number expected:" )
66 main.log.info( intentNumExpected )
67 main.log.info( "Intent number from ONOS CLI:" )
suibin zhang464f19e2016-05-24 08:55:10 -070068 jsonResult = main.ONOScli1.intents( jsonFormat = True, summary = True,
pingping-linffca7e22015-11-13 15:43:08 -080069 TYPE = "pointToPoint" )
70 intentNumActual = jsonResult['installed']
Jon Hall6e9897d2016-02-29 14:41:32 -080071
72 if intentNumActual != intentNumExpected:
73 time.sleep( wait )
suibin zhang464f19e2016-05-24 08:55:10 -070074 jsonResult = main.ONOScli1.intents( jsonFormat = True, summary = True,
Jon Hall6e9897d2016-02-29 14:41:32 -080075 TYPE = "pointToPoint" )
76 intentNumActual = jsonResult['installed']
pingping-linffca7e22015-11-13 15:43:08 -080077 main.log.info( intentNumActual )
78 utilities.assertEquals( \
79 expect = intentNumExpected, actual = intentNumActual,
80 onpass = "P2P intent number is correct!",
81 onfail = "P2P intent number is wrong!" )
82
83def checkFlowNum( main, switch, flowNumExpected ):
Jon Hall6e9897d2016-02-29 14:41:32 -080084 import time
pingping-linffca7e22015-11-13 15:43:08 -080085 main.step( "Check flow entry number in " + switch )
Jon Hall6e9897d2016-02-29 14:41:32 -080086 wait = int( main.params['timers']['PathAvailable'] )
pingping-linffca7e22015-11-13 15:43:08 -080087 main.log.info( "Flow number expected:" )
88 main.log.info( flowNumExpected )
89 main.log.info( "Flow number actual:" )
90 flowNumActual = main.Mininet.getSwitchFlowCount( switch )
Jon Hall6e9897d2016-02-29 14:41:32 -080091 if flowNumActual != flowNumExpected :
92 time.sleep( wait )
93 flowNumActual = main.Mininet.getSwitchFlowCount( switch )
pingping-linffca7e22015-11-13 15:43:08 -080094 main.log.info( flowNumActual )
95 utilities.assertEquals( \
96 expect = flowNumExpected, actual = flowNumActual,
97 onpass = "Flow number in " + switch + " is correct!",
98 onfail = "Flow number in " + switch + " is wrong!" )
99
100
101def pingSpeakerToPeer( main, speakers = ["speaker1"],
pingping-lined7a26b2015-12-15 19:03:57 -0800102 peers = ["pr64514", "pr64515", "pr64516"],
pingping-linffca7e22015-11-13 15:43:08 -0800103 expectAllSuccess = True ):
104 """
105 Carry out ping test between each BGP speaker and peer pair
106 Optional argument:
107 * speakers - BGP speakers
108 * peers - BGP peers
109 * expectAllSuccess - boolean indicating if you expect all results
110 succeed if True, otherwise expect all results fail if False
111 """
112 if len( speakers ) == 0:
113 main.log.error( "Parameter speakers can not be empty." )
114 main.cleanup()
115 main.exit()
116 if len( peers ) == 0:
117 main.log.error( "Parameter speakers can not be empty." )
118 main.cleanup()
119 main.exit()
120
121 if expectAllSuccess:
122 main.step( "BGP speakers ping peers, expect all tests to succeed" )
123 else:
124 main.step( "BGP speakers ping peers, expect all tests to fail" )
125
126 result = True
127 if expectAllSuccess:
128 for speaker in speakers:
129 for peer in peers:
130 tmpResult = main.Mininet.pingHost( src = speaker,
131 target = peer )
132 result = result and ( tmpResult == main.TRUE )
133 else:
134 for speaker in speakers:
135 for peer in peers:
136 tmpResult = main.Mininet.pingHost( src = speaker,
137 target = peer )
138
139 utilities.assert_equals( expect = True, actual = result,
140 onpass = "Ping test results are expected",
141 onfail = "Ping test results are Not expected" )
142
143 if result == False:
144 main.cleanup()
145 main.exit()
146
147
148def pingHostToHost( main, hosts = ["host64514", "host64515", "host64516"],
149 expectAllSuccess = True ):
150 """
151 Carry out ping test between each BGP host pair
152 Optional argument:
153 * hosts - hosts behind BGP peer routers
154 * expectAllSuccess - boolean indicating if you expect all results
155 succeed if True, otherwise expect all results fail if False
156 """
Jon Hall6e9897d2016-02-29 14:41:32 -0800157 main.step( "Check ping between each host pair, expect all to succede=" +
158 str( expectAllSuccess ) )
pingping-linffca7e22015-11-13 15:43:08 -0800159 if len( hosts ) == 0:
160 main.log.error( "Parameter hosts can not be empty." )
161 main.cleanup()
162 main.exit()
163
164 result = True
165 if expectAllSuccess:
166 for srcHost in hosts:
167 for targetHost in hosts:
168 if srcHost != targetHost:
169 tmpResult = main.Mininet.pingHost( src = srcHost,
170 target = targetHost )
171 result = result and ( tmpResult == main.TRUE )
172 else:
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.FALSE )
179
180 utilities.assert_equals( expect = True, actual = result,
181 onpass = "Ping test results are expected",
182 onfail = "Ping test results are Not expected" )
183
184 '''
185 if result == False:
186 main.cleanup()
187 main.exit()
188 '''
189