blob: a3c75405f7e953b9b23f4619b995135669374001 [file] [log] [blame]
pingping-lin26990f02015-11-30 15:48:06 -08001
Jon Hall6e9897d2016-02-29 14:41:32 -08002def checkRouteNum( main, routeNumExpected, ONOScli="ONOScli1" ):
3 import time
pingping-lin26990f02015-11-30 15:48:06 -08004 main.step( "Check routes installed" )
Jon Hall6e9897d2016-02-29 14:41:32 -08005 wait = int( main.params['timers']['PathAvailable'] )
pingping-lin26990f02015-11-30 15:48:06 -08006 main.log.info( "Route number expected:" )
7 main.log.info( routeNumExpected )
8 main.log.info( "Route number from ONOS CLI:" )
9
10 if ONOScli == "ONOScli1":
Jon Hall6e9897d2016-02-29 14:41:32 -080011 cli = main.ONOScli1
pingping-lin26990f02015-11-30 15:48:06 -080012 else:
Jon Hall6e9897d2016-02-29 14:41:32 -080013 cli = main.ONOScli2
14 routeNumActual = cli.ipv4RouteNumber()
15 if routeNumActual != routeNumExpected:
16 time.sleep( wait )
17 routeNumActual = cli.ipv4RouteNumber()
pingping-lin26990f02015-11-30 15:48:06 -080018
19 main.log.info( routeNumActual )
20 utilities.assertEquals( \
21 expect = routeNumExpected, actual = routeNumActual,
22 onpass = "Route number is correct!",
23 onfail = "Route number is wrong!" )
24
25def checkM2SintentNum( main, intentNumExpected, ONOScli = "ONOScli1" ):
Jon Hall6e9897d2016-02-29 14:41:32 -080026 import time
pingping-lin26990f02015-11-30 15:48:06 -080027 main.step( "Check M2S intents installed" )
Jon Hall6e9897d2016-02-29 14:41:32 -080028 wait = int( main.params['timers']['PathAvailable'] )
pingping-lin26990f02015-11-30 15:48:06 -080029 main.log.info( "Intent number expected:" )
30 main.log.info( intentNumExpected )
31 main.log.info( "Intent number from ONOS CLI:" )
32 if ONOScli == "ONOScli1":
Jon Hall6e9897d2016-02-29 14:41:32 -080033 cli = main.ONOScli1
pingping-lin26990f02015-11-30 15:48:06 -080034 else:
Jon Hall6e9897d2016-02-29 14:41:32 -080035 cli = main.ONOScli2
36 jsonResult = cli.intents( jsonFormat = True, summary = True,
37 TYPE = "multiPointToSinglePoint" )
pingping-lin26990f02015-11-30 15:48:06 -080038 intentNumActual = jsonResult['installed']
Jon Hall6e9897d2016-02-29 14:41:32 -080039 if intentNumActual != intentNumExpected:
40 time.sleep( wait )
41 jsonResult = cli.intents( jsonFormat = True, summary = True,
42 TYPE = "multiPointToSinglePoint" )
43 intentNumActual = jsonResult['installed']
pingping-lin26990f02015-11-30 15:48:06 -080044 main.log.info( intentNumActual )
45 utilities.assertEquals( \
46 expect = intentNumExpected, actual = intentNumActual,
47 onpass = "M2S intent number is correct!",
48 onfail = "M2S intent number is wrong!" )
49
50def checkP2PintentNum( main, intentNumExpected, ONOScli = "ONOScli1" ):
Jon Hall6e9897d2016-02-29 14:41:32 -080051 import time
pingping-lin26990f02015-11-30 15:48:06 -080052 main.step( "Check P2P intents installed" )
Jon Hall6e9897d2016-02-29 14:41:32 -080053 wait = int( main.params['timers']['PathAvailable'] )
pingping-lin26990f02015-11-30 15:48:06 -080054 main.log.info( "Intent number expected:" )
55 main.log.info( intentNumExpected )
56 main.log.info( "Intent number from ONOS CLI:" )
57 if ONOScli == "ONOScli1":
Jon Hall6e9897d2016-02-29 14:41:32 -080058 cli = main.ONOScli1
pingping-lin26990f02015-11-30 15:48:06 -080059 else:
Jon Hall6e9897d2016-02-29 14:41:32 -080060 cli = main.ONOScli2
61 jsonResult = cli.intents( jsonFormat = True, summary = True,
62 TYPE = "pointToPoint" )
pingping-lin26990f02015-11-30 15:48:06 -080063 intentNumActual = jsonResult['installed']
Jon Hall6e9897d2016-02-29 14:41:32 -080064
65 if intentNumActual != intentNumExpected:
66 time.sleep( wait )
67 jsonResult = cli.intents( jsonFormat = True, summary = True,
68 TYPE = "pointToPoint" )
69 intentNumActual = jsonResult['installed']
pingping-lin26990f02015-11-30 15:48:06 -080070 main.log.info( intentNumActual )
71 utilities.assertEquals( \
72 expect = intentNumExpected, actual = intentNumActual,
73 onpass = "P2P intent number is correct!",
74 onfail = "P2P intent number is wrong!" )
75
76def checkFlowNum( main, switch, flowNumExpected ):
Jon Hall6e9897d2016-02-29 14:41:32 -080077 import time
pingping-lin26990f02015-11-30 15:48:06 -080078 main.step( "Check flow entry number in " + switch )
Jon Hall6e9897d2016-02-29 14:41:32 -080079 wait = int( main.params['timers']['PathAvailable'] )
pingping-lin26990f02015-11-30 15:48:06 -080080 main.log.info( "Flow number expected:" )
81 main.log.info( flowNumExpected )
82 main.log.info( "Flow number actual:" )
83 flowNumActual = main.Mininet.getSwitchFlowCount( switch )
Jon Hall6e9897d2016-02-29 14:41:32 -080084 if flowNumActual != flowNumExpected :
85 time.sleep( wait )
86 flowNumActual = main.Mininet.getSwitchFlowCount( switch )
pingping-lin26990f02015-11-30 15:48:06 -080087 main.log.info( flowNumActual )
88 utilities.assertEquals( \
89 expect = flowNumExpected, actual = flowNumActual,
90 onpass = "Flow number in " + switch + " is correct!",
91 onfail = "Flow number in " + switch + " is wrong!" )
92
93
94def pingSpeakerToPeer( main, speakers = ["speaker1"],
pingping-lin14776632015-12-16 12:05:30 -080095 peers = ["pr64514", "pr64515", "pr64516"],
pingping-lin26990f02015-11-30 15:48:06 -080096 expectAllSuccess = True ):
97 """
98 Carry out ping test between each BGP speaker and peer pair
99 Optional argument:
100 * speakers - BGP speakers
101 * peers - BGP peers
102 * expectAllSuccess - boolean indicating if you expect all results
103 succeed if True, otherwise expect all results fail if False
104 """
105 if len( speakers ) == 0:
106 main.log.error( "Parameter speakers can not be empty." )
107 main.cleanup()
108 main.exit()
109 if len( peers ) == 0:
110 main.log.error( "Parameter speakers can not be empty." )
111 main.cleanup()
112 main.exit()
113
114 if expectAllSuccess:
115 main.step( "BGP speakers ping peers, expect all tests to succeed" )
116 else:
117 main.step( "BGP speakers ping peers, expect all tests to fail" )
118
119 result = True
120 if expectAllSuccess:
121 for speaker in speakers:
122 for peer in peers:
123 tmpResult = main.Mininet.pingHost( src = speaker,
124 target = peer )
125 result = result and ( tmpResult == main.TRUE )
126 else:
127 for speaker in speakers:
128 for peer in peers:
129 tmpResult = main.Mininet.pingHost( src = speaker,
130 target = peer )
131
132 utilities.assert_equals( expect = True, actual = result,
133 onpass = "Ping test results are expected",
134 onfail = "Ping test results are Not expected" )
135
136 if result == False:
137 main.cleanup()
138 main.exit()
139
140
141def pingHostToHost( main, hosts = ["host64514", "host64515", "host64516"],
142 expectAllSuccess = True ):
143 """
144 Carry out ping test between each BGP host pair
145 Optional argument:
146 * hosts - hosts behind BGP peer routers
147 * expectAllSuccess - boolean indicating if you expect all results
148 succeed if True, otherwise expect all results fail if False
149 """
Jon Hall6e9897d2016-02-29 14:41:32 -0800150 main.step( "Check ping between each host pair, expect all to succede=" +
151 str( expectAllSuccess ) )
pingping-lin26990f02015-11-30 15:48:06 -0800152 if len( hosts ) == 0:
153 main.log.error( "Parameter hosts can not be empty." )
154 main.cleanup()
155 main.exit()
156
157 result = True
158 if expectAllSuccess:
159 for srcHost in hosts:
160 for targetHost in hosts:
161 if srcHost != targetHost:
162 tmpResult = main.Mininet.pingHost( src = srcHost,
163 target = targetHost )
164 result = result and ( tmpResult == main.TRUE )
165 else:
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.FALSE )
172
173 utilities.assert_equals( expect = True, actual = result,
174 onpass = "Ping test results are expected",
175 onfail = "Ping test results are Not expected" )
176
177 '''
178 if result == False:
179 main.cleanup()
180 main.exit()
181 '''
182
183
184def setupTunnel( main, srcIp, srcPort, dstIp, dstPort ):
185 """
186 Create a tunnel from Mininet host to host outside Mininet
187 """
188 main.step( "Set up tunnel from Mininet node " +
189 str( srcIp ) + ":" + str( srcPort ) + " to ONOS node "
190 + str(dstIp) + ":" + str(dstPort) )
191 forwarding = '%s:%s:%s:%s' % ( srcIp, srcPort, dstIp, dstPort )
192 command = 'ssh -nNT -o "PasswordAuthentication no" \
193 -o "StrictHostKeyChecking no" -l sdn -L %s %s & ' % ( forwarding, dstIp )
194
195
196 tunnelResult = main.TRUE
197 tunnelResult = main.Mininet.node( "root", command )
198 utilities.assert_equals( expect = True,
199 actual = ( "PasswordAuthentication" in tunnelResult ),
200 onpass = "Created tunnel succeeded",
201 onfail = "Create tunnel failed" )
202 if ( "PasswordAuthentication" not in tunnelResult ) :
203 main.cleanup()
204 main.exit()
205