blob: 10e46a7e44a077b0cbb9a1793a2a9f42b4dea0e3 [file] [log] [blame]
adminbae64d82013-08-01 10:50:15 -07001#!/usr/bin/env python
Jon Hall7eb38402015-01-08 17:19:54 -08002"""
adminbae64d82013-08-01 10:50:15 -07003Created on 26-Oct-2012
4
Jon Hallbe6dfc42015-01-12 17:37:25 -08005author: Anil Kumar ( anilkumar.s@paxterrasolutions.com )
adminbae64d82013-08-01 10:50:15 -07006
7
Jon Hall7eb38402015-01-08 17:19:54 -08008TestON is free software: you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation, either version 2 of the License, or
11( at your option ) any later version.
adminbae64d82013-08-01 10:50:15 -070012
Jon Hall7eb38402015-01-08 17:19:54 -080013TestON is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
adminbae64d82013-08-01 10:50:15 -070017
Jon Hall7eb38402015-01-08 17:19:54 -080018You should have received a copy of the GNU General Public License
19along with TestON. If not, see <http://www.gnu.org/licenses/>.
adminbae64d82013-08-01 10:50:15 -070020
21
Jon Hallbe6dfc42015-01-12 17:37:25 -080022MininetCliDriver is the basic driver which will handle the Mininet functions
23
Jon Hall272a4db2015-01-12 17:43:48 -080024Some functions rely on STS module. To install this,
25 git clone https://github.com/jhall11/sts.git
26
Jon Hallbe6dfc42015-01-12 17:37:25 -080027Some functions rely on a modified version of Mininet. These functions
28should all be noted in the comments. To get this MN version run these commands
29from within your Mininet folder:
Jon Hall272a4db2015-01-12 17:43:48 -080030 git remote add jhall11 https://github.com/jhall11/mininet.git
Jon Hallbe6dfc42015-01-12 17:37:25 -080031 git fetch jhall11
Jon Hall272a4db2015-01-12 17:43:48 -080032 git checkout -b dynamic_topo remotes/jhall11/dynamic_topo
Jon Hallbe6dfc42015-01-12 17:37:25 -080033 git pull
34
Jon Hall272a4db2015-01-12 17:43:48 -080035
36 Note that you may need to run 'sudo make develop' if your mnexec.c file
Jon Hallbe6dfc42015-01-12 17:37:25 -080037changed when switching branches."""
admin2a9548d2014-06-17 14:08:07 -070038import traceback
adminbae64d82013-08-01 10:50:15 -070039import pexpect
adminbae64d82013-08-01 10:50:15 -070040import re
41import sys
Jon Hall7eb38402015-01-08 17:19:54 -080042sys.path.append( "../" )
Jon Hall1ccf82c2014-10-15 14:55:16 -040043from math import pow
adminbae64d82013-08-01 10:50:15 -070044from drivers.common.cli.emulatordriver import Emulator
adminbae64d82013-08-01 10:50:15 -070045
Jon Hall7eb38402015-01-08 17:19:54 -080046
47class MininetCliDriver( Emulator ):
48
49 """
50 MininetCliDriver is the basic driver which will handle
51 the Mininet functions"""
52 def __init__( self ):
53 super( Emulator, self ).__init__()
adminbae64d82013-08-01 10:50:15 -070054 self.handle = self
Jon Hall7eb38402015-01-08 17:19:54 -080055 self.wrapped = sys.modules[ __name__ ]
adminbae64d82013-08-01 10:50:15 -070056 self.flag = 0
57
Jon Hall7eb38402015-01-08 17:19:54 -080058 def connect( self, **connectargs ):
59 """
60 Here the main is the TestON instance after creating
61 all the log handles."""
adminbae64d82013-08-01 10:50:15 -070062 for key in connectargs:
Jon Hall7eb38402015-01-08 17:19:54 -080063 vars( self )[ key ] = connectargs[ key ]
Jon Hallfbc828e2015-01-06 17:30:19 -080064
Jon Hall7eb38402015-01-08 17:19:54 -080065 self.name = self.options[ 'name' ]
66 self.handle = super(
67 MininetCliDriver,
68 self ).connect(
69 user_name=self.user_name,
70 ip_address=self.ip_address,
71 port=None,
72 pwd=self.pwd )
Jon Hallfbc828e2015-01-06 17:30:19 -080073
adminbae64d82013-08-01 10:50:15 -070074 self.ssh_handle = self.handle
Jon Hallfbc828e2015-01-06 17:30:19 -080075
Jon Hall7eb38402015-01-08 17:19:54 -080076 if self.handle:
77 main.log.info(
78 self.name +
79 ": Clearing any residual state or processes" )
80 self.handle.sendline( "sudo mn -c" )
81 i = self.handle.expect( [ 'password\sfor\s',
82 'Cleanup\scomplete',
83 pexpect.EOF,
84 pexpect.TIMEOUT ],
85 120 )
86 if i == 0:
87 main.log.info( self.name + ": Sending sudo password" )
88 self.handle.sendline( self.pwd )
89 i = self.handle.expect( [ '%s:' % ( self.user ),
90 '\$',
91 pexpect.EOF,
92 pexpect.TIMEOUT ],
93 120 )
94 if i == 1:
95 main.log.info( self.name + ": Clean" )
96 elif i == 2:
97 main.log.error( self.name + ": Connection terminated" )
98 elif i == 3: # timeout
99 main.log.error(
100 self.name +
101 ": Something while cleaning MN took too long... " )
Jon Hallfbc828e2015-01-06 17:30:19 -0800102
Jon Hall7eb38402015-01-08 17:19:54 -0800103 main.log.info( self.name + ": building fresh mininet" )
104 # for reactive/PARP enabled tests
105 cmdString = "sudo mn " + self.options[ 'arg1' ] +\
106 " " + self.options[ 'arg2' ] +\
107 " --mac --controller " +\
108 self.options[ 'controller' ] + " " +\
109 self.options[ 'arg3' ]
Jon Hallfbc828e2015-01-06 17:30:19 -0800110
Jon Hall7eb38402015-01-08 17:19:54 -0800111 argList = self.options[ 'arg1' ].split( "," )
Jon Hall1ccf82c2014-10-15 14:55:16 -0400112 global topoArgList
Jon Hall7eb38402015-01-08 17:19:54 -0800113 topoArgList = argList[ 0 ].split( " " )
114 argList = map( int, argList[ 1: ] )
115 topoArgList = topoArgList[ 1: ] + argList
Jon Hallfbc828e2015-01-06 17:30:19 -0800116
Jon Hall7eb38402015-01-08 17:19:54 -0800117 self.handle.sendline( cmdString )
118 self.handle.expect( [ "sudo mn", pexpect.EOF, pexpect.TIMEOUT ] )
119 while True:
120 i = self.handle.expect( [ 'mininet>',
121 '\*\*\*',
122 'Exception',
123 pexpect.EOF,
124 pexpect.TIMEOUT ],
125 300 )
126 if i == 0:
127 main.log.info( self.name + ": mininet built" )
adminbae64d82013-08-01 10:50:15 -0700128 return main.TRUE
Jon Hall7eb38402015-01-08 17:19:54 -0800129 if i == 1:
130 self.handle.expect(
131 [ "\n", pexpect.EOF, pexpect.TIMEOUT ] )
132 main.log.info( self.handle.before )
133 elif i == 2:
134 main.log.error(
135 self.name +
136 ": Launching mininet failed..." )
adminbae64d82013-08-01 10:50:15 -0700137 return main.FALSE
Jon Hall7eb38402015-01-08 17:19:54 -0800138 elif i == 3:
139 main.log.error( self.name + ": Connection timeout" )
adminbae64d82013-08-01 10:50:15 -0700140 return main.FALSE
Jon Hall7eb38402015-01-08 17:19:54 -0800141 elif i == 4: # timeout
142 main.log.error(
143 self.name +
144 ": Something took too long... " )
adminbae64d82013-08-01 10:50:15 -0700145 return main.FALSE
adminbae64d82013-08-01 10:50:15 -0700146 return main.TRUE
Jon Hall7eb38402015-01-08 17:19:54 -0800147 else: # if no handle
148 main.log.error(
149 self.name +
150 ": Connection failed to the host " +
151 self.user_name +
152 "@" +
153 self.ip_address )
154 main.log.error( self.name + ": Failed to connect to the Mininet" )
adminbae64d82013-08-01 10:50:15 -0700155 return main.FALSE
Jon Hallfbc828e2015-01-06 17:30:19 -0800156
Jon Hall7eb38402015-01-08 17:19:54 -0800157 def num_switches_n_links( self, topoType, depth, fanout ):
Jon Hall1ccf82c2014-10-15 14:55:16 -0400158 if topoType == 'tree':
Jon Hall7eb38402015-01-08 17:19:54 -0800159 # In tree topology, if fanout arg is not given, by default it is 2
160 if fanout is None:
Jon Hall1ccf82c2014-10-15 14:55:16 -0400161 fanout = 2
162 k = 0
Jon Hall38481722014-11-04 16:50:05 -0500163 count = 0
Jon Hall7eb38402015-01-08 17:19:54 -0800164 while( k <= depth - 1 ):
165 count = count + pow( fanout, k )
166 k = k + 1
Jon Hall38481722014-11-04 16:50:05 -0500167 num_switches = count
Jon Hall7eb38402015-01-08 17:19:54 -0800168 while( k <= depth - 2 ):
169 # depth-2 gives you only core links and not considering
170 # edge links as seen by ONOS. If all the links including
171 # edge links are required, do depth-1
172 count = count + pow( fanout, k )
173 k = k + 1
Jon Hall38481722014-11-04 16:50:05 -0500174 num_links = count * fanout
Jon Hall7eb38402015-01-08 17:19:54 -0800175 # print "num_switches for %s(%d,%d) = %d and links=%d" %(
176 # topoType,depth,fanout,num_switches,num_links )
Jon Hallfbc828e2015-01-06 17:30:19 -0800177
Jon Hall7eb38402015-01-08 17:19:54 -0800178 elif topoType == 'linear':
179 # In linear topology, if fanout or num_hosts_per_sw is not given,
180 # by default it is 1
181 if fanout is None:
Jon Hall1ccf82c2014-10-15 14:55:16 -0400182 fanout = 1
183 num_switches = depth
184 num_hosts_per_sw = fanout
185 total_num_hosts = num_switches * num_hosts_per_sw
Jon Hall7eb38402015-01-08 17:19:54 -0800186 num_links = total_num_hosts + ( num_switches - 1 )
187 print "num_switches for %s(%d,%d) = %d and links=%d" %\
188 ( topoType, depth, fanout, num_switches, num_links )
Jon Hall1ccf82c2014-10-15 14:55:16 -0400189 topoDict = {}
Jon Hall7eb38402015-01-08 17:19:54 -0800190 topoDict = {
191 "num_switches": int( num_switches ),
192 "num_corelinks": int( num_links ) }
Jon Hall1ccf82c2014-10-15 14:55:16 -0400193 return topoDict
194
Jon Hall7eb38402015-01-08 17:19:54 -0800195 def calculate_sw_and_links( self ):
196 topoDict = self.num_switches_n_links( *topoArgList )
Jon Hall1ccf82c2014-10-15 14:55:16 -0400197 return topoDict
198
Jon Hall7eb38402015-01-08 17:19:54 -0800199 def pingall( self, timeout=300 ):
200 """
201 Verifies the reachability of the hosts using pingall command.
202 Optional parameter timeout allows you to specify how long to
203 wait for pingall to complete
204 Returns:
205 main.TRUE if pingall completes with no pings dropped
206 otherwise main.FALSE"""
207 if self.handle:
208 main.log.info(
209 self.name +
210 ": Checking reachabilty to the hosts using pingall" )
Jon Hall6094a362014-04-11 14:46:56 -0700211 try:
Jon Hall7eb38402015-01-08 17:19:54 -0800212 response = self.execute(
213 cmd="pingall",
214 prompt="mininet>",
215 timeout=int( timeout ) )
Jon Hallb1290e82014-11-18 16:17:48 -0500216 except pexpect.EOF:
Jon Hall7eb38402015-01-08 17:19:54 -0800217 main.log.error( self.name + ": EOF exception found" )
218 main.log.error( self.name + ": " + self.handle.before )
Jon Hallb1290e82014-11-18 16:17:48 -0500219 main.cleanup()
220 main.exit()
221 except pexpect.TIMEOUT:
Jon Hall7eb38402015-01-08 17:19:54 -0800222 # We may not want to kill the test if pexpect times out
223 main.log.error( self.name + ": TIMEOUT exception found" )
224 main.log.error( self.name +
225 ": " +
226 str( self.handle.before ) )
227 # NOTE: mininet's pingall rounds, so we will check the number of
228 # passed and number of failed
229 pattern = "Results\:\s0\%\sdropped\s\(" +\
230 "(?P<passed>[\d]+)/(?P=passed)"
231 if re.search( pattern, response ):
232 main.log.info( self.name + ": All hosts are reachable" )
adminbae64d82013-08-01 10:50:15 -0700233 return main.TRUE
234 else:
Jon Hall7eb38402015-01-08 17:19:54 -0800235 main.log.error( self.name + ": Unable to reach all the hosts" )
236 main.log.info( "Pingall ouput: " + str( response ) )
237 # NOTE: Send ctrl-c to make sure pingall is done
238 self.handle.send( "\x03" )
239 self.handle.expect( "Interrupt" )
240 self.handle.expect( "mininet>" )
adminbae64d82013-08-01 10:50:15 -0700241 return main.FALSE
Jon Hall7eb38402015-01-08 17:19:54 -0800242 else:
243 main.log.error( self.name + ": Connection failed to the host" )
Jon Hallb1290e82014-11-18 16:17:48 -0500244 main.cleanup()
245 main.exit()
adminaeedddd2013-08-02 15:14:15 -0700246
Jon Hall7eb38402015-01-08 17:19:54 -0800247 def fpingHost( self, **pingParams ):
248 """
249 Uses the fping package for faster pinging...
250 *requires fping to be installed on machine running mininet"""
251 args = utilities.parse_args( [ "SRC", "TARGET" ], **pingParams )
252 command = args[ "SRC" ] + \
253 " fping -i 100 -t 20 -C 1 -q " + args[ "TARGET" ]
254 self.handle.sendline( command )
255 self.handle.expect(
256 [ args[ "TARGET" ], pexpect.EOF, pexpect.TIMEOUT ] )
257 self.handle.expect( [ "mininet", pexpect.EOF, pexpect.TIMEOUT ] )
258 response = self.handle.before
259 if re.search( ":\s-", response ):
260 main.log.info( self.name + ": Ping fail" )
adminaeedddd2013-08-02 15:14:15 -0700261 return main.FALSE
Jon Hall7eb38402015-01-08 17:19:54 -0800262 elif re.search( ":\s\d{1,2}\.\d\d", response ):
263 main.log.info( self.name + ": Ping good!" )
adminaeedddd2013-08-02 15:14:15 -0700264 return main.TRUE
Jon Hall7eb38402015-01-08 17:19:54 -0800265 main.log.info( self.name + ": Install fping on mininet machine... " )
266 main.log.info( self.name + ": \n---\n" + response )
adminaeedddd2013-08-02 15:14:15 -0700267 return main.FALSE
Jon Hallfbc828e2015-01-06 17:30:19 -0800268
Jon Hall7eb38402015-01-08 17:19:54 -0800269 def pingHost( self, **pingParams ):
270 """
271 Ping from one mininet host to another
272 Currently the only supported Params: SRC and TARGET"""
273 args = utilities.parse_args( [ "SRC", "TARGET" ], **pingParams )
274 command = args[ "SRC" ] + " ping " + \
275 args[ "TARGET" ] + " -c 1 -i 1 -W 8"
Jon Hall6094a362014-04-11 14:46:56 -0700276 try:
Jon Hall7eb38402015-01-08 17:19:54 -0800277 main.log.warn( "Sending: " + command )
278 self.handle.sendline( command )
279 i = self.handle.expect( [ command, pexpect.TIMEOUT ] )
Jon Hall6e18c7b2014-04-23 16:26:33 -0700280 if i == 1:
Jon Hall7eb38402015-01-08 17:19:54 -0800281 main.log.error(
282 self.name +
283 ": timeout when waiting for response from mininet" )
284 main.log.error( "response: " + str( self.handle.before ) )
285 i = self.handle.expect( [ "mininet>", pexpect.TIMEOUT ] )
Jon Hall6e18c7b2014-04-23 16:26:33 -0700286 if i == 1:
Jon Hall7eb38402015-01-08 17:19:54 -0800287 main.log.error(
288 self.name +
289 ": timeout when waiting for response from mininet" )
290 main.log.error( "response: " + str( self.handle.before ) )
Jon Hall6e18c7b2014-04-23 16:26:33 -0700291 response = self.handle.before
Jon Hallfbc828e2015-01-06 17:30:19 -0800292 except pexpect.EOF:
Jon Hall7eb38402015-01-08 17:19:54 -0800293 main.log.error( self.name + ": EOF exception found" )
294 main.log.error( self.name + ": " + self.handle.before )
Jon Hall6094a362014-04-11 14:46:56 -0700295 main.cleanup()
296 main.exit()
Jon Hall7eb38402015-01-08 17:19:54 -0800297 main.log.info( self.name + ": Ping Response: " + response )
298 if re.search( ',\s0\%\spacket\sloss', response ):
299 main.log.info( self.name + ": no packets lost, host is reachable" )
Jon Hallfbc828e2015-01-06 17:30:19 -0800300 main.last_result = main.TRUE
adminbae64d82013-08-01 10:50:15 -0700301 return main.TRUE
Jon Hall7eb38402015-01-08 17:19:54 -0800302 else:
303 main.log.error(
304 self.name +
305 ": PACKET LOST, HOST IS NOT REACHABLE" )
adminbae64d82013-08-01 10:50:15 -0700306 main.last_result = main.FALSE
307 return main.FALSE
Jon Hallfbc828e2015-01-06 17:30:19 -0800308
Jon Hall7eb38402015-01-08 17:19:54 -0800309 def checkIP( self, host ):
310 """
311 Verifies the host's ip configured or not."""
312 if self.handle:
Jon Hall6094a362014-04-11 14:46:56 -0700313 try:
Jon Hall7eb38402015-01-08 17:19:54 -0800314 response = self.execute(
315 cmd=host +
316 " ifconfig",
317 prompt="mininet>",
318 timeout=10 )
Jon Hallfbc828e2015-01-06 17:30:19 -0800319 except pexpect.EOF:
Jon Hall7eb38402015-01-08 17:19:54 -0800320 main.log.error( self.name + ": EOF exception found" )
321 main.log.error( self.name + ": " + self.handle.before )
Jon Hall6094a362014-04-11 14:46:56 -0700322 main.cleanup()
323 main.exit()
adminbae64d82013-08-01 10:50:15 -0700324
Jon Hall7eb38402015-01-08 17:19:54 -0800325 pattern = "inet\s(addr|Mask):([0-1]{1}[0-9]{1,2}|" +\
326 "2[0-4][0-9]|25[0-5]|[0-9]{1,2}).([0-1]{1}" +\
327 "[0-9]{1,2}|2[0-4][0-9]|25[0-5]|[0-9]{1,2})." +\
328 "([0-1]{1}[0-9]{1,2}|2[0-4][0-9]|25[0-5]|" +\
329 "[0-9]{1,2}).([0-1]{1}[0-9]{1,2}|2[0-4]" +\
330 "[0-9]|25[0-5]|[0-9]{1,2})"
331 # pattern = "inet addr:10.0.0.6"
332 if re.search( pattern, response ):
333 main.log.info( self.name + ": Host Ip configured properly" )
adminbae64d82013-08-01 10:50:15 -0700334 return main.TRUE
335 else:
Jon Hall7eb38402015-01-08 17:19:54 -0800336 main.log.error( self.name + ": Host IP not found" )
adminbae64d82013-08-01 10:50:15 -0700337 return main.FALSE
Jon Hall7eb38402015-01-08 17:19:54 -0800338 else:
339 main.log.error( self.name + ": Connection failed to the host" )
Jon Hallfbc828e2015-01-06 17:30:19 -0800340
Jon Hall7eb38402015-01-08 17:19:54 -0800341 def verifySSH( self, **connectargs ):
Jon Hall6094a362014-04-11 14:46:56 -0700342 try:
Jon Hall7eb38402015-01-08 17:19:54 -0800343 response = self.execute(
344 cmd="h1 /usr/sbin/sshd -D&",
345 prompt="mininet>",
346 timeout=10 )
347 response = self.execute(
348 cmd="h4 /usr/sbin/sshd -D&",
349 prompt="mininet>",
350 timeout=10 )
Jon Hall6094a362014-04-11 14:46:56 -0700351 for key in connectargs:
Jon Hall7eb38402015-01-08 17:19:54 -0800352 vars( self )[ key ] = connectargs[ key ]
353 response = self.execute(
354 cmd="xterm h1 h4 ",
355 prompt="mininet>",
356 timeout=10 )
Jon Hallfbc828e2015-01-06 17:30:19 -0800357 except pexpect.EOF:
Jon Hall7eb38402015-01-08 17:19:54 -0800358 main.log.error( self.name + ": EOF exception found" )
359 main.log.error( self.name + ": " + self.handle.before )
Jon Hall6094a362014-04-11 14:46:56 -0700360 main.cleanup()
361 main.exit()
adminbae64d82013-08-01 10:50:15 -0700362 import time
Jon Hall7eb38402015-01-08 17:19:54 -0800363 time.sleep( 20 )
adminbae64d82013-08-01 10:50:15 -0700364 if self.flag == 0:
365 self.flag = 1
366 return main.FALSE
Jon Hall7eb38402015-01-08 17:19:54 -0800367 else:
adminbae64d82013-08-01 10:50:15 -0700368 return main.TRUE
shahshreyae6c7cf42014-11-26 16:39:01 -0800369
Jon Hall7eb38402015-01-08 17:19:54 -0800370 def changeIP( self, host, intf, newIP, newNetmask ):
371 """
372 Changes the ip address of a host on the fly
373 Ex: h2 ifconfig h2-eth0 10.0.1.2 netmask 255.255.255.0"""
shahshreyae6c7cf42014-11-26 16:39:01 -0800374 if self.handle:
375 try:
Jon Hall7eb38402015-01-08 17:19:54 -0800376 cmd = host + " ifconfig " + intf + " " + \
377 newIP + " " + 'netmask' + " " + newNetmask
378 self.handle.sendline( cmd )
379 self.handle.expect( "mininet>" )
shahshreyae6c7cf42014-11-26 16:39:01 -0800380 response = self.handle.before
Jon Hall7eb38402015-01-08 17:19:54 -0800381 main.log.info( "response = " + response )
382 main.log.info(
383 "Ip of host " +
384 host +
385 " changed to new IP " +
386 newIP )
shahshreyae6c7cf42014-11-26 16:39:01 -0800387 return main.TRUE
388 except pexpect.EOF:
Jon Hall7eb38402015-01-08 17:19:54 -0800389 main.log.error( self.name + ": EOF exception found" )
390 main.log.error( self.name + ": " + self.handle.before )
shahshreyae6c7cf42014-11-26 16:39:01 -0800391 return main.FALSE
392
Jon Hall7eb38402015-01-08 17:19:54 -0800393 def changeDefaultGateway( self, host, newGW ):
394 """
395 Changes the default gateway of a host
396 Ex: h1 route add default gw 10.0.1.2"""
shahshreyae6c7cf42014-11-26 16:39:01 -0800397 if self.handle:
398 try:
Jon Hall7eb38402015-01-08 17:19:54 -0800399 cmd = host + " route add default gw " + newGW
400 self.handle.sendline( cmd )
401 self.handle.expect( "mininet>" )
shahshreyae6c7cf42014-11-26 16:39:01 -0800402 response = self.handle.before
Jon Hall7eb38402015-01-08 17:19:54 -0800403 main.log.info( "response = " + response )
404 main.log.info(
405 "Default gateway of host " +
406 host +
407 " changed to " +
408 newGW )
shahshreyae6c7cf42014-11-26 16:39:01 -0800409 return main.TRUE
410 except pexpect.EOF:
Jon Hall7eb38402015-01-08 17:19:54 -0800411 main.log.error( self.name + ": EOF exception found" )
412 main.log.error( self.name + ": " + self.handle.before )
shahshreyae6c7cf42014-11-26 16:39:01 -0800413 return main.FALSE
Jon Hallfbc828e2015-01-06 17:30:19 -0800414
Jon Hall7eb38402015-01-08 17:19:54 -0800415 def addStaticMACAddress( self, host, GW, macaddr ):
416 """
417 Changes the mac address of a geateway host"""
shahshreyad0c80432014-12-04 16:56:05 -0800418 if self.handle:
419 try:
Jon Hall7eb38402015-01-08 17:19:54 -0800420 # h1 arp -s 10.0.1.254 00:00:00:00:11:11
421 cmd = host + " arp -s " + GW + " " + macaddr
422 self.handle.sendline( cmd )
423 self.handle.expect( "mininet>" )
shahshreyad0c80432014-12-04 16:56:05 -0800424 response = self.handle.before
Jon Hall7eb38402015-01-08 17:19:54 -0800425 main.log.info( "response = " + response )
426 main.log.info(
427 "Mac adrress of gateway " +
428 GW +
429 " changed to " +
430 macaddr )
shahshreyad0c80432014-12-04 16:56:05 -0800431 return main.TRUE
432 except pexpect.EOF:
Jon Hall7eb38402015-01-08 17:19:54 -0800433 main.log.error( self.name + ": EOF exception found" )
434 main.log.error( self.name + ": " + self.handle.before )
shahshreyad0c80432014-12-04 16:56:05 -0800435 return main.FALSE
436
Jon Hall7eb38402015-01-08 17:19:54 -0800437 def verifyStaticGWandMAC( self, host ):
438 """
439 Verify if the static gateway and mac address assignment"""
shahshreyad0c80432014-12-04 16:56:05 -0800440 if self.handle:
441 try:
Jon Hall7eb38402015-01-08 17:19:54 -0800442 # h1 arp -an
443 cmd = host + " arp -an "
444 self.handle.sendline( cmd )
445 self.handle.expect( "mininet>" )
shahshreyad0c80432014-12-04 16:56:05 -0800446 response = self.handle.before
Jon Hall7eb38402015-01-08 17:19:54 -0800447 main.log.info( host + " arp -an = " + response )
shahshreyad0c80432014-12-04 16:56:05 -0800448 return main.TRUE
449 except pexpect.EOF:
Jon Hall7eb38402015-01-08 17:19:54 -0800450 main.log.error( self.name + ": EOF exception found" )
451 main.log.error( self.name + ": " + self.handle.before )
shahshreyad0c80432014-12-04 16:56:05 -0800452 return main.FALSE
453
Jon Hall7eb38402015-01-08 17:19:54 -0800454 def getMacAddress( self, host ):
455 """
456 Verifies the host's ip configured or not."""
457 if self.handle:
Jon Hall6094a362014-04-11 14:46:56 -0700458 try:
Jon Hall7eb38402015-01-08 17:19:54 -0800459 response = self.execute(
460 cmd=host +
461 " ifconfig",
462 prompt="mininet>",
463 timeout=10 )
Jon Hallfbc828e2015-01-06 17:30:19 -0800464 except pexpect.EOF:
Jon Hall7eb38402015-01-08 17:19:54 -0800465 main.log.error( self.name + ": EOF exception found" )
466 main.log.error( self.name + ": " + self.handle.before )
Jon Hall6094a362014-04-11 14:46:56 -0700467 main.cleanup()
468 main.exit()
adminbae64d82013-08-01 10:50:15 -0700469
Ahmed El-Hassanyf720e202014-04-04 16:11:36 -0700470 pattern = r'HWaddr\s([0-9A-F]{2}[:-]){5}([0-9A-F]{2})'
Jon Hall7eb38402015-01-08 17:19:54 -0800471 mac_address_search = re.search( pattern, response, re.I )
472 mac_address = mac_address_search.group().split( " " )[ 1 ]
473 main.log.info(
474 self.name +
475 ": Mac-Address of Host " +
476 host +
477 " is " +
478 mac_address )
Ahmed El-Hassanyfd329182014-04-10 11:38:16 -0700479 return mac_address
480 else:
Jon Hall7eb38402015-01-08 17:19:54 -0800481 main.log.error( self.name + ": Connection failed to the host" )
Ahmed El-Hassanyfd329182014-04-10 11:38:16 -0700482
Jon Hall7eb38402015-01-08 17:19:54 -0800483 def getInterfaceMACAddress( self, host, interface ):
484 """
485 Return the IP address of the interface on the given host"""
486 if self.handle:
Jon Hall6094a362014-04-11 14:46:56 -0700487 try:
Jon Hall7eb38402015-01-08 17:19:54 -0800488 response = self.execute( cmd=host + " ifconfig " + interface,
489 prompt="mininet>", timeout=10 )
Jon Hallfbc828e2015-01-06 17:30:19 -0800490 except pexpect.EOF:
Jon Hall7eb38402015-01-08 17:19:54 -0800491 main.log.error( self.name + ": EOF exception found" )
492 main.log.error( self.name + ": " + self.handle.before )
493 main.cleanup()
494 main.exit()
495
496 pattern = r'HWaddr\s([0-9A-F]{2}[:-]){5}([0-9A-F]{2})'
497 mac_address_search = re.search( pattern, response, re.I )
498 if mac_address_search is None:
499 main.log.info( "No mac address found in %s" % response )
500 return main.FALSE
501 mac_address = mac_address_search.group().split( " " )[ 1 ]
502 main.log.info(
503 "Mac-Address of " +
504 host +
505 ":" +
506 interface +
507 " is " +
508 mac_address )
509 return mac_address
510 else:
511 main.log.error( "Connection failed to the host" )
512
513 def getIPAddress( self, host ):
514 """
515 Verifies the host's ip configured or not."""
516 if self.handle:
517 try:
518 response = self.execute(
519 cmd=host +
520 " ifconfig",
521 prompt="mininet>",
522 timeout=10 )
523 except pexpect.EOF:
524 main.log.error( self.name + ": EOF exception found" )
525 main.log.error( self.name + ": " + self.handle.before )
Jon Hall6094a362014-04-11 14:46:56 -0700526 main.cleanup()
527 main.exit()
adminbae64d82013-08-01 10:50:15 -0700528
529 pattern = "inet\saddr:(\d+\.\d+\.\d+\.\d+)"
Jon Hall7eb38402015-01-08 17:19:54 -0800530 ip_address_search = re.search( pattern, response )
531 main.log.info(
532 self.name +
533 ": IP-Address of Host " +
534 host +
535 " is " +
536 ip_address_search.group( 1 ) )
537 return ip_address_search.group( 1 )
538 else:
539 main.log.error( self.name + ": Connection failed to the host" )
Jon Hallfbc828e2015-01-06 17:30:19 -0800540
Jon Hall7eb38402015-01-08 17:19:54 -0800541 def getSwitchDPID( self, switch ):
542 """
543 return the datapath ID of the switch"""
544 if self.handle:
Ahmed El-Hassanyfd329182014-04-10 11:38:16 -0700545 cmd = "py %s.dpid" % switch
Jon Hall6094a362014-04-11 14:46:56 -0700546 try:
Jon Hall7eb38402015-01-08 17:19:54 -0800547 response = self.execute(
548 cmd=cmd,
549 prompt="mininet>",
550 timeout=10 )
Jon Hallfbc828e2015-01-06 17:30:19 -0800551 except pexpect.EOF:
Jon Hall7eb38402015-01-08 17:19:54 -0800552 main.log.error( self.name + ": EOF exception found" )
553 main.log.error( self.name + ": " + self.handle.before )
Jon Hall6094a362014-04-11 14:46:56 -0700554 main.cleanup()
555 main.exit()
Jon Hall28bf54b2014-12-17 16:25:44 -0800556 pattern = r'^(?P<dpid>\w)+'
Jon Hall7eb38402015-01-08 17:19:54 -0800557 result = re.search( pattern, response, re.MULTILINE )
Ahmed El-Hassanyfd329182014-04-10 11:38:16 -0700558 if result is None:
Jon Hall7eb38402015-01-08 17:19:54 -0800559 main.log.info(
560 "Couldn't find DPID for switch %s, found: %s" %
561 ( switch, response ) )
Ahmed El-Hassanyfd329182014-04-10 11:38:16 -0700562 return main.FALSE
Jon Hall7eb38402015-01-08 17:19:54 -0800563 return str( result.group( 0 ) ).lower()
Ahmed El-Hassanyfd329182014-04-10 11:38:16 -0700564 else:
Jon Hall7eb38402015-01-08 17:19:54 -0800565 main.log.error( "Connection failed to the host" )
Ahmed El-Hassanyfd329182014-04-10 11:38:16 -0700566
Jon Hall7eb38402015-01-08 17:19:54 -0800567 def getDPID( self, switch ):
admin2580a0e2014-07-29 11:24:34 -0700568 if self.handle:
Jon Hall7eb38402015-01-08 17:19:54 -0800569 self.handle.sendline( "" )
570 self.expect( "mininet>" )
571 cmd = "py %s.dpid" % switch
admin2580a0e2014-07-29 11:24:34 -0700572 try:
Jon Hall7eb38402015-01-08 17:19:54 -0800573 response = self.execute(
574 cmd=cmd,
575 prompt="mininet>",
576 timeout=10 )
577 self.handle.expect( "mininet>" )
admin2580a0e2014-07-29 11:24:34 -0700578 response = self.handle.before
579 return response
580 except pexpect.EOF:
Jon Hall7eb38402015-01-08 17:19:54 -0800581 main.log.error( self.name + ": EOF exception found" )
582 main.log.error( self.name + ": " + self.handle.before )
admin2580a0e2014-07-29 11:24:34 -0700583 main.cleanup()
584 main.exit()
585
Jon Hall7eb38402015-01-08 17:19:54 -0800586 def getInterfaces( self, node ):
587 """
588 return information dict about interfaces connected to the node"""
589 if self.handle:
590 cmd = 'py "\\n".join(["name=%s,mac=%s,ip=%s,enabled=%s"' +\
591 ' % (i.name, i.MAC(), i.IP(), i.isUp())'
Ahmed El-Hassanyfd329182014-04-10 11:38:16 -0700592 cmd += ' for i in %s.intfs.values()])' % node
Jon Hall6094a362014-04-11 14:46:56 -0700593 try:
Jon Hall7eb38402015-01-08 17:19:54 -0800594 response = self.execute(
595 cmd=cmd,
596 prompt="mininet>",
597 timeout=10 )
Jon Hallfbc828e2015-01-06 17:30:19 -0800598 except pexpect.EOF:
Jon Hall7eb38402015-01-08 17:19:54 -0800599 main.log.error( self.name + ": EOF exception found" )
600 main.log.error( self.name + ": " + self.handle.before )
Jon Hall6094a362014-04-11 14:46:56 -0700601 main.cleanup()
602 main.exit()
Ahmed El-Hassanyfd329182014-04-10 11:38:16 -0700603 return response
604 else:
Jon Hall7eb38402015-01-08 17:19:54 -0800605 main.log.error( "Connection failed to the node" )
Ahmed El-Hassanyfd329182014-04-10 11:38:16 -0700606
Jon Hall7eb38402015-01-08 17:19:54 -0800607 def dump( self ):
608 main.log.info( self.name + ": Dump node info" )
Jon Hall6094a362014-04-11 14:46:56 -0700609 try:
Jon Hall7eb38402015-01-08 17:19:54 -0800610 response = self.execute(
611 cmd='dump',
612 prompt='mininet>',
613 timeout=10 )
Jon Hallfbc828e2015-01-06 17:30:19 -0800614 except pexpect.EOF:
Jon Hall7eb38402015-01-08 17:19:54 -0800615 main.log.error( self.name + ": EOF exception found" )
616 main.log.error( self.name + ": " + self.handle.before )
Jon Hall6094a362014-04-11 14:46:56 -0700617 main.cleanup()
618 main.exit()
Ahmed El-Hassanyd1f71702014-04-04 16:12:45 -0700619 return response
Jon Hallfbc828e2015-01-06 17:30:19 -0800620
Jon Hall7eb38402015-01-08 17:19:54 -0800621 def intfs( self ):
622 main.log.info( self.name + ": List interfaces" )
Jon Hall6094a362014-04-11 14:46:56 -0700623 try:
Jon Hall7eb38402015-01-08 17:19:54 -0800624 response = self.execute(
625 cmd='intfs',
626 prompt='mininet>',
627 timeout=10 )
Jon Hallfbc828e2015-01-06 17:30:19 -0800628 except pexpect.EOF:
Jon Hall7eb38402015-01-08 17:19:54 -0800629 main.log.error( self.name + ": EOF exception found" )
630 main.log.error( self.name + ": " + self.handle.before )
Jon Hall6094a362014-04-11 14:46:56 -0700631 main.cleanup()
632 main.exit()
Jon Hall668ed802014-04-08 17:17:59 -0700633 return response
Jon Hallfbc828e2015-01-06 17:30:19 -0800634
Jon Hall7eb38402015-01-08 17:19:54 -0800635 def net( self ):
636 main.log.info( self.name + ": List network connections" )
Jon Hall6094a362014-04-11 14:46:56 -0700637 try:
Jon Hall7eb38402015-01-08 17:19:54 -0800638 response = self.execute( cmd='net', prompt='mininet>', timeout=10 )
Jon Hallfbc828e2015-01-06 17:30:19 -0800639 except pexpect.EOF:
Jon Hall7eb38402015-01-08 17:19:54 -0800640 main.log.error( self.name + ": EOF exception found" )
641 main.log.error( self.name + ": " + self.handle.before )
Jon Hall6094a362014-04-11 14:46:56 -0700642 main.cleanup()
643 main.exit()
Jon Hall668ed802014-04-08 17:17:59 -0700644 return response
Jon Hall7eb38402015-01-08 17:19:54 -0800645
646 def iperf( self, host1, host2 ):
647 main.log.info(
648 self.name +
649 ": Simple iperf TCP test between two hosts" )
Jon Hall6094a362014-04-11 14:46:56 -0700650 try:
Jon Hall7eb38402015-01-08 17:19:54 -0800651 cmd1 = 'iperf ' + host1 + " " + host2
652 self.handle.sendline( cmd1 )
653 self.handle.expect( "mininet>" )
shahshreyae6c7cf42014-11-26 16:39:01 -0800654 response = self.handle.before
Jon Hall7eb38402015-01-08 17:19:54 -0800655 if re.search( 'Results:', response ):
656 main.log.info( self.name + ": iperf test succssful" )
shahshreyae6c7cf42014-11-26 16:39:01 -0800657 return main.TRUE
658 else:
Jon Hall7eb38402015-01-08 17:19:54 -0800659 main.log.error( self.name + ": iperf test failed" )
660 return main.FALSE
shahshreyae6c7cf42014-11-26 16:39:01 -0800661 except pexpect.EOF:
Jon Hall7eb38402015-01-08 17:19:54 -0800662 main.log.error( self.name + ": EOF exception found" )
663 main.log.error( self.name + ": " + self.handle.before )
shahshreyae6c7cf42014-11-26 16:39:01 -0800664 main.cleanup()
665 main.exit()
Jon Hallfbc828e2015-01-06 17:30:19 -0800666
Jon Hall7eb38402015-01-08 17:19:54 -0800667 def iperfudp( self ):
668 main.log.info(
669 self.name +
670 ": Simple iperf TCP test between two " +
671 "(optionally specified) hosts" )
Jon Hall6094a362014-04-11 14:46:56 -0700672 try:
Jon Hall7eb38402015-01-08 17:19:54 -0800673 response = self.execute(
674 cmd='iperfudp',
675 prompt='mininet>',
676 timeout=10 )
Jon Hallfbc828e2015-01-06 17:30:19 -0800677 except pexpect.EOF:
Jon Hall7eb38402015-01-08 17:19:54 -0800678 main.log.error( self.name + ": EOF exception found" )
679 main.log.error( self.name + ": " + self.handle.before )
Jon Hall6094a362014-04-11 14:46:56 -0700680 main.cleanup()
681 main.exit()
Jon Hall668ed802014-04-08 17:17:59 -0700682 return response
Jon Hallfbc828e2015-01-06 17:30:19 -0800683
Jon Hall7eb38402015-01-08 17:19:54 -0800684 def nodes( self ):
685 main.log.info( self.name + ": List all nodes." )
Jon Hall6094a362014-04-11 14:46:56 -0700686 try:
Jon Hall7eb38402015-01-08 17:19:54 -0800687 response = self.execute(
688 cmd='nodes',
689 prompt='mininet>',
690 timeout=10 )
Jon Hallfbc828e2015-01-06 17:30:19 -0800691 except pexpect.EOF:
Jon Hall7eb38402015-01-08 17:19:54 -0800692 main.log.error( self.name + ": EOF exception found" )
693 main.log.error( self.name + ": " + self.handle.before )
Jon Hall6094a362014-04-11 14:46:56 -0700694 main.cleanup()
695 main.exit()
Jon Hall668ed802014-04-08 17:17:59 -0700696 return response
Jon Hallfbc828e2015-01-06 17:30:19 -0800697
Jon Hall7eb38402015-01-08 17:19:54 -0800698 def pingpair( self ):
699 main.log.info( self.name + ": Ping between first two hosts" )
Jon Hall6094a362014-04-11 14:46:56 -0700700 try:
Jon Hall7eb38402015-01-08 17:19:54 -0800701 response = self.execute(
702 cmd='pingpair',
703 prompt='mininet>',
704 timeout=20 )
Jon Hallfbc828e2015-01-06 17:30:19 -0800705 except pexpect.EOF:
Jon Hall7eb38402015-01-08 17:19:54 -0800706 main.log.error( self.name + ": EOF exception found" )
707 main.log.error( self.name + ": " + self.handle.before )
Jon Hall6094a362014-04-11 14:46:56 -0700708 main.cleanup()
709 main.exit()
Jon Hallfbc828e2015-01-06 17:30:19 -0800710
Jon Hall7eb38402015-01-08 17:19:54 -0800711 if re.search( ',\s0\%\spacket\sloss', response ):
712 main.log.info( self.name + ": Ping between two hosts SUCCESSFUL" )
Jon Hallfbc828e2015-01-06 17:30:19 -0800713 main.last_result = main.TRUE
adminbae64d82013-08-01 10:50:15 -0700714 return main.TRUE
Jon Hall7eb38402015-01-08 17:19:54 -0800715 else:
716 main.log.error( self.name + ": PACKET LOST, HOSTS NOT REACHABLE" )
adminbae64d82013-08-01 10:50:15 -0700717 main.last_result = main.FALSE
718 return main.FALSE
Jon Hallfbc828e2015-01-06 17:30:19 -0800719
Jon Hall7eb38402015-01-08 17:19:54 -0800720 def link( self, **linkargs ):
721 """
722 Bring link( s ) between two nodes up or down"""
723 args = utilities.parse_args( [ "END1", "END2", "OPTION" ], **linkargs )
724 end1 = args[ "END1" ] if args[ "END1" ] is not None else ""
725 end2 = args[ "END2" ] if args[ "END2" ] is not None else ""
726 option = args[ "OPTION" ] if args[ "OPTION" ] is not None else ""
727 main.log.info(
728 "Bring link between '" +
729 end1 +
730 "' and '" +
731 end2 +
732 "' '" +
733 option +
734 "'" )
735 command = "link " + \
736 str( end1 ) + " " + str( end2 ) + " " + str( option )
Jon Hall6094a362014-04-11 14:46:56 -0700737 try:
Jon Hall7eb38402015-01-08 17:19:54 -0800738 self.handle.sendline( command )
739 self.handle.expect( "mininet>" )
Jon Hallfbc828e2015-01-06 17:30:19 -0800740 except pexpect.EOF:
Jon Hall7eb38402015-01-08 17:19:54 -0800741 main.log.error( self.name + ": EOF exception found" )
742 main.log.error( self.name + ": " + self.handle.before )
Jon Hall6094a362014-04-11 14:46:56 -0700743 main.cleanup()
744 main.exit()
adminbae64d82013-08-01 10:50:15 -0700745 return main.TRUE
Jon Hallfbc828e2015-01-06 17:30:19 -0800746
Jon Hall7eb38402015-01-08 17:19:54 -0800747 def yank( self, **yankargs ):
748 """
749 yank a mininet switch interface to a host"""
750 main.log.info( 'Yank the switch interface attached to a host' )
751 args = utilities.parse_args( [ "SW", "INTF" ], **yankargs )
752 sw = args[ "SW" ] if args[ "SW" ] is not None else ""
753 intf = args[ "INTF" ] if args[ "INTF" ] is not None else ""
754 command = "py " + str( sw ) + '.detach("' + str(intf) + '")'
Jon Hall6094a362014-04-11 14:46:56 -0700755 try:
Jon Hall7eb38402015-01-08 17:19:54 -0800756 response = self.execute(
757 cmd=command,
758 prompt="mininet>",
759 timeout=10 )
Jon Hallfbc828e2015-01-06 17:30:19 -0800760 except pexpect.EOF:
Jon Hall7eb38402015-01-08 17:19:54 -0800761 main.log.error( self.name + ": EOF exception found" )
762 main.log.error( self.name + ": " + self.handle.before )
Jon Hall6094a362014-04-11 14:46:56 -0700763 main.cleanup()
764 main.exit()
adminaeedddd2013-08-02 15:14:15 -0700765 return main.TRUE
766
Jon Hall7eb38402015-01-08 17:19:54 -0800767 def plug( self, **plugargs ):
768 """
769 plug the yanked mininet switch interface to a switch"""
770 main.log.info( 'Plug the switch interface attached to a switch' )
771 args = utilities.parse_args( [ "SW", "INTF" ], **plugargs )
772 sw = args[ "SW" ] if args[ "SW" ] is not None else ""
773 intf = args[ "INTF" ] if args[ "INTF" ] is not None else ""
774 command = "py " + str( sw ) + '.attach("' + str(intf) + '")'
Jon Hall6094a362014-04-11 14:46:56 -0700775 try:
Jon Hall7eb38402015-01-08 17:19:54 -0800776 response = self.execute(
777 cmd=command,
778 prompt="mininet>",
779 timeout=10 )
Jon Hallfbc828e2015-01-06 17:30:19 -0800780 except pexpect.EOF:
Jon Hall7eb38402015-01-08 17:19:54 -0800781 main.log.error( self.name + ": EOF exception found" )
782 main.log.error( self.name + ": " + self.handle.before )
Jon Hall6094a362014-04-11 14:46:56 -0700783 main.cleanup()
784 main.exit()
adminbae64d82013-08-01 10:50:15 -0700785 return main.TRUE
Jon Hallfbc828e2015-01-06 17:30:19 -0800786
Jon Hall7eb38402015-01-08 17:19:54 -0800787 def dpctl( self, **dpctlargs ):
788 """
789 Run dpctl command on all switches."""
790 main.log.info( 'Run dpctl command on all switches' )
791 args = utilities.parse_args( [ "CMD", "ARGS" ], **dpctlargs )
792 cmd = args[ "CMD" ] if args[ "CMD" ] is not None else ""
793 cmdargs = args[ "ARGS" ] if args[ "ARGS" ] is not None else ""
794 command = "dpctl " + cmd + " " + str( cmdargs )
795 try:
796 response = self.execute(
797 cmd=command,
798 prompt="mininet>",
799 timeout=10 )
800 except pexpect.EOF:
801 main.log.error( self.name + ": EOF exception found" )
802 main.log.error( self.name + ": " + self.handle.before )
803 main.cleanup()
804 main.exit()
805 return main.TRUE
Jon Hallfbc828e2015-01-06 17:30:19 -0800806
Jon Hall7eb38402015-01-08 17:19:54 -0800807 def get_version( self ):
808 file_input = path + '/lib/Mininet/INSTALL'
809 version = super( Mininet, self ).get_version()
adminbae64d82013-08-01 10:50:15 -0700810 pattern = 'Mininet\s\w\.\w\.\w\w*'
Jon Hall7eb38402015-01-08 17:19:54 -0800811 for line in open( file_input, 'r' ).readlines():
812 result = re.match( pattern, line )
adminbae64d82013-08-01 10:50:15 -0700813 if result:
Jon Hall7eb38402015-01-08 17:19:54 -0800814 version = result.group( 0 )
Jon Hallec3c21e2014-11-10 22:22:37 -0500815 return version
adminbae64d82013-08-01 10:50:15 -0700816
Jon Hall7eb38402015-01-08 17:19:54 -0800817 def get_sw_controller( self, sw ):
818 """
Jon Hallec3c21e2014-11-10 22:22:37 -0500819 Parameters:
820 sw: The name of an OVS switch. Example "s1"
821 Return:
Jon Hall7eb38402015-01-08 17:19:54 -0800822 The output of the command from the mininet cli
823 or main.FALSE on timeout"""
824 command = "sh ovs-vsctl get-controller " + str( sw )
admin2a9548d2014-06-17 14:08:07 -0700825 try:
Jon Hall7eb38402015-01-08 17:19:54 -0800826 response = self.execute(
827 cmd=command,
828 prompt="mininet>",
829 timeout=10 )
admin2a9548d2014-06-17 14:08:07 -0700830 if response:
Jon Hallec3c21e2014-11-10 22:22:37 -0500831 return response
admin2a9548d2014-06-17 14:08:07 -0700832 else:
833 return main.FALSE
834 except pexpect.EOF:
Jon Hall7eb38402015-01-08 17:19:54 -0800835 main.log.error( self.name + ": EOF exception found" )
836 main.log.error( self.name + ": " + self.handle.before )
admin2a9548d2014-06-17 14:08:07 -0700837 main.cleanup()
838 main.exit()
adminbae64d82013-08-01 10:50:15 -0700839
Jon Hall7eb38402015-01-08 17:19:54 -0800840 def assign_sw_controller( self, **kwargs ):
841 """
842 count is only needed if there is more than 1 controller"""
843 args = utilities.parse_args( [ "COUNT" ], **kwargs )
844 count = args[ "COUNT" ] if args != {} else 1
Jon Hallf89c8552014-04-02 13:14:06 -0700845
846 argstring = "SW"
Jon Hall7eb38402015-01-08 17:19:54 -0800847 for j in range( count ):
848 argstring = argstring + ",IP" + \
849 str( j + 1 ) + ",PORT" + str( j + 1 )
850 args = utilities.parse_args( argstring.split( "," ), **kwargs )
Jon Hallf89c8552014-04-02 13:14:06 -0700851
Jon Hall7eb38402015-01-08 17:19:54 -0800852 sw = args[ "SW" ] if args[ "SW" ] is not None else ""
853 ptcpA = int( args[ "PORT1" ] ) + \
854 int( sw ) if args[ "PORT1" ] is not None else ""
855 ptcpB = "ptcp:" + str( ptcpA ) if ptcpA != "" else ""
Jon Hallfbc828e2015-01-06 17:30:19 -0800856
Jon Hall7eb38402015-01-08 17:19:54 -0800857 command = "sh ovs-vsctl set-controller s" + \
858 str( sw ) + " " + ptcpB + " "
859 for j in range( count ):
860 i = j + 1
861 args = utilities.parse_args(
862 [ "IP" + str( i ), "PORT" + str( i ) ], **kwargs )
863 ip = args[
864 "IP" +
865 str( i ) ] if args[
866 "IP" +
867 str( i ) ] is not None else ""
868 port = args[
869 "PORT" +
870 str( i ) ] if args[
871 "PORT" +
872 str( i ) ] is not None else ""
873 tcp = "tcp:" + str( ip ) + ":" + str( port ) + \
874 " " if ip != "" else ""
Jon Hallf89c8552014-04-02 13:14:06 -0700875 command = command + tcp
Jon Hall6094a362014-04-11 14:46:56 -0700876 try:
Jon Hall7eb38402015-01-08 17:19:54 -0800877 self.execute( cmd=command, prompt="mininet>", timeout=5 )
Jon Hall6094a362014-04-11 14:46:56 -0700878 except pexpect.EOF:
Jon Hall7eb38402015-01-08 17:19:54 -0800879 main.log.error( self.name + ": EOF exception found" )
880 main.log.error( self.name + ": " + self.handle.before )
Jon Hall6094a362014-04-11 14:46:56 -0700881 main.cleanup()
882 main.exit()
883 except:
Jon Hall7eb38402015-01-08 17:19:54 -0800884 main.log.info( self.name + ":" * 50 )
Jon Hall6094a362014-04-11 14:46:56 -0700885 main.log.error( traceback.print_exc() )
Jon Hall7eb38402015-01-08 17:19:54 -0800886 main.log.info(":" * 50 )
Jon Hall6094a362014-04-11 14:46:56 -0700887 main.cleanup()
888 main.exit()
adminbae64d82013-08-01 10:50:15 -0700889
Jon Hall7eb38402015-01-08 17:19:54 -0800890 def delete_sw_controller( self, sw ):
891 """
892 Removes the controller target from sw"""
893 command = "sh ovs-vsctl del-controller " + str( sw )
Jon Hall0819fd92014-05-23 12:08:13 -0700894 try:
Jon Hall7eb38402015-01-08 17:19:54 -0800895 response = self.execute(
896 cmd=command,
897 prompt="mininet>",
898 timeout=10 )
Jon Hallfbc828e2015-01-06 17:30:19 -0800899 except pexpect.EOF:
Jon Hall7eb38402015-01-08 17:19:54 -0800900 main.log.error( self.name + ": EOF exception found" )
901 main.log.error( self.name + ": " + self.handle.before )
Jon Hall0819fd92014-05-23 12:08:13 -0700902 main.cleanup()
903 main.exit()
904 else:
Jon Hall7eb38402015-01-08 17:19:54 -0800905 main.log.info( response )
Jon Hall0819fd92014-05-23 12:08:13 -0700906
Jon Hallb1290e82014-11-18 16:17:48 -0500907 def add_switch( self, sw, **kwargs ):
Jon Hall7eb38402015-01-08 17:19:54 -0800908 """
Jon Hallb1290e82014-11-18 16:17:48 -0500909 adds a switch to the mininet topology
Jon Hallbe6dfc42015-01-12 17:37:25 -0800910 NOTE: This uses a custom mn function. MN repo should be on
Jon Hall272a4db2015-01-12 17:43:48 -0800911 dynamic_topo branch
Jon Hallb1290e82014-11-18 16:17:48 -0500912 NOTE: cannot currently specify what type of switch
913 required params:
914 switchname = name of the new switch as a string
915 optional keyvalues:
916 dpid = "dpid"
917 returns: main.FASLE on an error, else main.TRUE
Jon Hall7eb38402015-01-08 17:19:54 -0800918 """
919 dpid = kwargs.get( 'dpid', '' )
Jon Hallffb386d2014-11-21 13:43:38 -0800920 command = "addswitch " + str( sw ) + " " + str( dpid )
Jon Hallb1290e82014-11-18 16:17:48 -0500921 try:
Jon Hall7eb38402015-01-08 17:19:54 -0800922 response = self.execute(
923 cmd=command,
924 prompt="mininet>",
925 timeout=10 )
926 if re.search( "already exists!", response ):
927 main.log.warn( response )
Jon Hallb1290e82014-11-18 16:17:48 -0500928 return main.FALSE
Jon Hall7eb38402015-01-08 17:19:54 -0800929 elif re.search( "Error", response ):
930 main.log.warn( response )
Jon Hallb1290e82014-11-18 16:17:48 -0500931 return main.FALSE
Jon Hall7eb38402015-01-08 17:19:54 -0800932 elif re.search( "usage:", response ):
933 main.log.warn( response )
Jon Hallb1290e82014-11-18 16:17:48 -0500934 return main.FALSE
935 else:
936 return main.TRUE
937 except pexpect.EOF:
Jon Hall7eb38402015-01-08 17:19:54 -0800938 main.log.error( self.name + ": EOF exception found" )
939 main.log.error( self.name + ": " + self.handle.before )
Jon Hallb1290e82014-11-18 16:17:48 -0500940 main.cleanup()
941 main.exit()
942
943 def del_switch( self, sw ):
Jon Hall7eb38402015-01-08 17:19:54 -0800944 """
Jon Hallbe6dfc42015-01-12 17:37:25 -0800945 delete a switch from the mininet topology
946 NOTE: This uses a custom mn function. MN repo should be on
Jon Hall272a4db2015-01-12 17:43:48 -0800947 dynamic_topo branch
Jon Hallbe6dfc42015-01-12 17:37:25 -0800948 required params:
Jon Hallb1290e82014-11-18 16:17:48 -0500949 switchname = name of the switch as a string
Jon Hallbe6dfc42015-01-12 17:37:25 -0800950 returns: main.FASLE on an error, else main.TRUE"""
Jon Hallffb386d2014-11-21 13:43:38 -0800951 command = "delswitch " + str( sw )
Jon Hallb1290e82014-11-18 16:17:48 -0500952 try:
Jon Hall7eb38402015-01-08 17:19:54 -0800953 response = self.execute(
954 cmd=command,
955 prompt="mininet>",
956 timeout=10 )
957 if re.search( "no switch named", response ):
958 main.log.warn( response )
Jon Hallb1290e82014-11-18 16:17:48 -0500959 return main.FALSE
Jon Hall7eb38402015-01-08 17:19:54 -0800960 elif re.search( "Error", response ):
961 main.log.warn( response )
Jon Hallb1290e82014-11-18 16:17:48 -0500962 return main.FALSE
Jon Hall7eb38402015-01-08 17:19:54 -0800963 elif re.search( "usage:", response ):
964 main.log.warn( response )
Jon Hallb1290e82014-11-18 16:17:48 -0500965 return main.FALSE
966 else:
967 return main.TRUE
968 except pexpect.EOF:
Jon Hall7eb38402015-01-08 17:19:54 -0800969 main.log.error( self.name + ": EOF exception found" )
970 main.log.error( self.name + ": " + self.handle.before )
Jon Hallb1290e82014-11-18 16:17:48 -0500971 main.cleanup()
972 main.exit()
973
974 def add_link( self, node1, node2 ):
Jon Hall7eb38402015-01-08 17:19:54 -0800975 """
976 add a link to the mininet topology
Jon Hallbe6dfc42015-01-12 17:37:25 -0800977 NOTE: This uses a custom mn function. MN repo should be on
Jon Hall272a4db2015-01-12 17:43:48 -0800978 dynamic_topo branch
Jon Hall7eb38402015-01-08 17:19:54 -0800979 NOTE: cannot currently specify what type of link
980 required params:
981 node1 = the string node name of the first endpoint of the link
982 node2 = the string node name of the second endpoint of the link
983 returns: main.FASLE on an error, else main.TRUE"""
Jon Hallffb386d2014-11-21 13:43:38 -0800984 command = "addlink " + str( node1 ) + " " + str( node2 )
Jon Hallb1290e82014-11-18 16:17:48 -0500985 try:
Jon Hall7eb38402015-01-08 17:19:54 -0800986 response = self.execute(
987 cmd=command,
988 prompt="mininet>",
989 timeout=10 )
990 if re.search( "doesnt exist!", response ):
991 main.log.warn( response )
Jon Hallb1290e82014-11-18 16:17:48 -0500992 return main.FALSE
Jon Hall7eb38402015-01-08 17:19:54 -0800993 elif re.search( "Error", response ):
994 main.log.warn( response )
Jon Hallb1290e82014-11-18 16:17:48 -0500995 return main.FALSE
Jon Hall7eb38402015-01-08 17:19:54 -0800996 elif re.search( "usage:", response ):
997 main.log.warn( response )
Jon Hallb1290e82014-11-18 16:17:48 -0500998 return main.FALSE
999 else:
1000 return main.TRUE
1001 except pexpect.EOF:
Jon Hall7eb38402015-01-08 17:19:54 -08001002 main.log.error( self.name + ": EOF exception found" )
1003 main.log.error( self.name + ": " + self.handle.before )
Jon Hallb1290e82014-11-18 16:17:48 -05001004 main.cleanup()
1005 main.exit()
1006
1007 def del_link( self, node1, node2 ):
Jon Hall7eb38402015-01-08 17:19:54 -08001008 """
1009 delete a link from the mininet topology
Jon Hallbe6dfc42015-01-12 17:37:25 -08001010 NOTE: This uses a custom mn function. MN repo should be on
Jon Hall272a4db2015-01-12 17:43:48 -08001011 dynamic_topo branch
Jon Hall7eb38402015-01-08 17:19:54 -08001012 required params:
1013 node1 = the string node name of the first endpoint of the link
1014 node2 = the string node name of the second endpoint of the link
1015 returns: main.FASLE on an error, else main.TRUE"""
Jon Hallffb386d2014-11-21 13:43:38 -08001016 command = "dellink " + str( node1 ) + " " + str( node2 )
Jon Hallb1290e82014-11-18 16:17:48 -05001017 try:
Jon Hall7eb38402015-01-08 17:19:54 -08001018 response = self.execute(
1019 cmd=command,
1020 prompt="mininet>",
1021 timeout=10 )
1022 if re.search( "no node named", response ):
1023 main.log.warn( response )
Jon Hallb1290e82014-11-18 16:17:48 -05001024 return main.FALSE
Jon Hall7eb38402015-01-08 17:19:54 -08001025 elif re.search( "Error", response ):
1026 main.log.warn( response )
Jon Hallb1290e82014-11-18 16:17:48 -05001027 return main.FALSE
Jon Hall7eb38402015-01-08 17:19:54 -08001028 elif re.search( "usage:", response ):
1029 main.log.warn( response )
Jon Hallb1290e82014-11-18 16:17:48 -05001030 return main.FALSE
1031 else:
1032 return main.TRUE
1033 except pexpect.EOF:
Jon Hall7eb38402015-01-08 17:19:54 -08001034 main.log.error( self.name + ": EOF exception found" )
1035 main.log.error( self.name + ": " + self.handle.before )
Jon Hallb1290e82014-11-18 16:17:48 -05001036 main.cleanup()
1037 main.exit()
1038
1039 def add_host( self, hostname, **kwargs ):
Jon Hall7eb38402015-01-08 17:19:54 -08001040 """
Jon Hallb1290e82014-11-18 16:17:48 -05001041 Add a host to the mininet topology
Jon Hallbe6dfc42015-01-12 17:37:25 -08001042 NOTE: This uses a custom mn function. MN repo should be on
Jon Hall272a4db2015-01-12 17:43:48 -08001043 dynamic_topo branch
Jon Hallb1290e82014-11-18 16:17:48 -05001044 NOTE: cannot currently specify what type of host
1045 required params:
1046 hostname = the string hostname
1047 optional key-value params
1048 switch = "switch name"
1049 returns: main.FASLE on an error, else main.TRUE
Jon Hall7eb38402015-01-08 17:19:54 -08001050 """
1051 switch = kwargs.get( 'switch', '' )
Jon Hallffb386d2014-11-21 13:43:38 -08001052 command = "addhost " + str( hostname ) + " " + str( switch )
Jon Hallb1290e82014-11-18 16:17:48 -05001053 try:
Jon Hall7eb38402015-01-08 17:19:54 -08001054 response = self.execute(
1055 cmd=command,
1056 prompt="mininet>",
1057 timeout=10 )
1058 if re.search( "already exists!", response ):
1059 main.log.warn( response )
Jon Hallb1290e82014-11-18 16:17:48 -05001060 return main.FALSE
Jon Hall7eb38402015-01-08 17:19:54 -08001061 elif re.search( "doesnt exists!", response ):
1062 main.log.warn( response )
Jon Hallb1290e82014-11-18 16:17:48 -05001063 return main.FALSE
Jon Hall7eb38402015-01-08 17:19:54 -08001064 elif re.search( "Error", response ):
1065 main.log.warn( response )
Jon Hallb1290e82014-11-18 16:17:48 -05001066 return main.FALSE
Jon Hall7eb38402015-01-08 17:19:54 -08001067 elif re.search( "usage:", response ):
1068 main.log.warn( response )
Jon Hallb1290e82014-11-18 16:17:48 -05001069 return main.FALSE
1070 else:
1071 return main.TRUE
1072 except pexpect.EOF:
Jon Hall7eb38402015-01-08 17:19:54 -08001073 main.log.error( self.name + ": EOF exception found" )
1074 main.log.error( self.name + ": " + self.handle.before )
Jon Hallb1290e82014-11-18 16:17:48 -05001075 main.cleanup()
1076 main.exit()
1077
1078 def del_host( self, hostname ):
Jon Hall7eb38402015-01-08 17:19:54 -08001079 """
1080 delete a host from the mininet topology
Jon Hallbe6dfc42015-01-12 17:37:25 -08001081 NOTE: This uses a custom mn function. MN repo should be on
Jon Hall272a4db2015-01-12 17:43:48 -08001082 dynamic_topo branch
Jon Hall7eb38402015-01-08 17:19:54 -08001083 NOTE: this uses a custom mn function
1084 required params:
1085 hostname = the string hostname
1086 returns: main.FASLE on an error, else main.TRUE"""
Jon Hallffb386d2014-11-21 13:43:38 -08001087 command = "delhost " + str( hostname )
Jon Hallb1290e82014-11-18 16:17:48 -05001088 try:
Jon Hall7eb38402015-01-08 17:19:54 -08001089 response = self.execute(
1090 cmd=command,
1091 prompt="mininet>",
1092 timeout=10 )
1093 if re.search( "no host named", response ):
1094 main.log.warn( response )
Jon Hallb1290e82014-11-18 16:17:48 -05001095 return main.FALSE
Jon Hall7eb38402015-01-08 17:19:54 -08001096 elif re.search( "Error", response ):
1097 main.log.warn( response )
Jon Hallb1290e82014-11-18 16:17:48 -05001098 return main.FALSE
Jon Hall7eb38402015-01-08 17:19:54 -08001099 elif re.search( "usage:", response ):
1100 main.log.warn( response )
Jon Hallb1290e82014-11-18 16:17:48 -05001101 return main.FALSE
1102 else:
1103 return main.TRUE
1104 except pexpect.EOF:
Jon Hall7eb38402015-01-08 17:19:54 -08001105 main.log.error( self.name + ": EOF exception found" )
1106 main.log.error( self.name + ": " + self.handle.before )
Jon Hallb1290e82014-11-18 16:17:48 -05001107 main.cleanup()
1108 main.exit()
Jon Hall0819fd92014-05-23 12:08:13 -07001109
Jon Hall7eb38402015-01-08 17:19:54 -08001110 def disconnect( self ):
1111 main.log.info( self.name + ": Disconnecting mininet..." )
adminbae64d82013-08-01 10:50:15 -07001112 response = ''
1113 if self.handle:
Jon Hall6094a362014-04-11 14:46:56 -07001114 try:
Jon Hall7eb38402015-01-08 17:19:54 -08001115 response = self.execute(
1116 cmd="exit",
1117 prompt="(.*)",
1118 timeout=120 )
1119 response = self.execute(
1120 cmd="exit",
1121 prompt="(.*)",
1122 timeout=120 )
1123 self.handle.sendline( "sudo mn -c" )
shahshreya328c2a72014-11-17 10:19:50 -08001124 response = main.TRUE
Jon Hallfbc828e2015-01-06 17:30:19 -08001125 except pexpect.EOF:
Jon Hall7eb38402015-01-08 17:19:54 -08001126 main.log.error( self.name + ": EOF exception found" )
1127 main.log.error( self.name + ": " + self.handle.before )
Jon Hall6094a362014-04-11 14:46:56 -07001128 main.cleanup()
1129 main.exit()
Jon Hall7eb38402015-01-08 17:19:54 -08001130 else:
1131 main.log.error( self.name + ": Connection failed to the host" )
adminbae64d82013-08-01 10:50:15 -07001132 response = main.FALSE
Jon Hallfbc828e2015-01-06 17:30:19 -08001133 return response
1134
Jon Hall7eb38402015-01-08 17:19:54 -08001135 def arping( self, src, dest, destmac ):
1136 self.handle.sendline( '' )
1137 self.handle.expect( [ "mininet", pexpect.EOF, pexpect.TIMEOUT ] )
admin07529932013-11-22 14:58:28 -08001138
Jon Hall7eb38402015-01-08 17:19:54 -08001139 self.handle.sendline( src + ' arping ' + dest )
admin07529932013-11-22 14:58:28 -08001140 try:
Jon Hall7eb38402015-01-08 17:19:54 -08001141 self.handle.expect( [ destmac, pexpect.EOF, pexpect.TIMEOUT ] )
1142 main.log.info( self.name + ": ARP successful" )
1143 self.handle.expect( [ "mininet", pexpect.EOF, pexpect.TIMEOUT ] )
admin07529932013-11-22 14:58:28 -08001144 return main.TRUE
1145 except:
Jon Hall7eb38402015-01-08 17:19:54 -08001146 main.log.warn( self.name + ": ARP FAILURE" )
1147 self.handle.expect( [ "mininet", pexpect.EOF, pexpect.TIMEOUT ] )
admin07529932013-11-22 14:58:28 -08001148 return main.FALSE
1149
Jon Hall7eb38402015-01-08 17:19:54 -08001150 def decToHex( self, num ):
1151 return hex( num ).split( 'x' )[ 1 ]
Jon Hallfbc828e2015-01-06 17:30:19 -08001152
Jon Hall7eb38402015-01-08 17:19:54 -08001153 def getSwitchFlowCount( self, switch ):
1154 """
1155 return the Flow Count of the switch"""
admin2a9548d2014-06-17 14:08:07 -07001156 if self.handle:
1157 cmd = "sh ovs-ofctl dump-aggregate %s" % switch
1158 try:
Jon Hall7eb38402015-01-08 17:19:54 -08001159 response = self.execute(
1160 cmd=cmd,
1161 prompt="mininet>",
1162 timeout=10 )
admin2a9548d2014-06-17 14:08:07 -07001163 except pexpect.EOF:
Jon Hall7eb38402015-01-08 17:19:54 -08001164 main.log.error( self.name + ": EOF exception found" )
1165 main.log.error( self.name + " " + self.handle.before )
admin2a9548d2014-06-17 14:08:07 -07001166 main.cleanup()
1167 main.exit()
1168 pattern = "flow_count=(\d+)"
Jon Hall7eb38402015-01-08 17:19:54 -08001169 result = re.search( pattern, response, re.MULTILINE )
admin2a9548d2014-06-17 14:08:07 -07001170 if result is None:
Jon Hall7eb38402015-01-08 17:19:54 -08001171 main.log.info(
1172 "Couldn't find flows on switch %s, found: %s" %
1173 ( switch, response ) )
admin2a9548d2014-06-17 14:08:07 -07001174 return main.FALSE
Jon Hall7eb38402015-01-08 17:19:54 -08001175 return result.group( 1 )
admin2a9548d2014-06-17 14:08:07 -07001176 else:
Jon Hall7eb38402015-01-08 17:19:54 -08001177 main.log.error( "Connection failed to the Mininet host" )
Jon Hallfbc828e2015-01-06 17:30:19 -08001178
Jon Hall7eb38402015-01-08 17:19:54 -08001179 def check_flows( self, sw, dump_format=None ):
Ahmed El-Hassanyb6545eb2014-08-01 11:32:10 -07001180 if dump_format:
Jon Hall7eb38402015-01-08 17:19:54 -08001181 command = "sh ovs-ofctl -F " + \
1182 dump_format + " dump-flows " + str( sw )
Ahmed El-Hassanyb6545eb2014-08-01 11:32:10 -07001183 else:
Jon Hall7eb38402015-01-08 17:19:54 -08001184 command = "sh ovs-ofctl dump-flows " + str( sw )
admin2a9548d2014-06-17 14:08:07 -07001185 try:
Jon Hall7eb38402015-01-08 17:19:54 -08001186 response = self.execute(
1187 cmd=command,
1188 prompt="mininet>",
1189 timeout=10 )
admin2a9548d2014-06-17 14:08:07 -07001190 return response
1191 except pexpect.EOF:
Jon Hall7eb38402015-01-08 17:19:54 -08001192 main.log.error( self.name + ": EOF exception found" )
1193 main.log.error( self.name + ": " + self.handle.before )
admin2a9548d2014-06-17 14:08:07 -07001194 main.cleanup()
1195 main.exit()
1196 else:
Jon Hall7eb38402015-01-08 17:19:54 -08001197 main.log.info( response )
admin2a9548d2014-06-17 14:08:07 -07001198
Jon Hall7eb38402015-01-08 17:19:54 -08001199 def start_tcpdump( self, filename, intf="eth0", port="port 6633" ):
1200 """
1201 Runs tpdump on an intferface and saves the file
1202 intf can be specified, or the default eth0 is used"""
admin2a9548d2014-06-17 14:08:07 -07001203 try:
Jon Hall7eb38402015-01-08 17:19:54 -08001204 self.handle.sendline( "" )
1205 self.handle.expect( "mininet>" )
1206 self.handle.sendline(
1207 "sh sudo tcpdump -n -i " +
1208 intf +
1209 " " +
1210 port +
1211 " -w " +
1212 filename.strip() +
1213 " &" )
1214 self.handle.sendline( "" )
1215 i = self.handle.expect( [ 'No\ssuch\device',
1216 'listening\son',
1217 pexpect.TIMEOUT,
1218 "mininet>" ],
1219 timeout=10 )
1220 main.log.warn( self.handle.before + self.handle.after )
1221 self.handle.sendline( "" )
1222 self.handle.expect( "mininet>" )
admin2a9548d2014-06-17 14:08:07 -07001223 if i == 0:
Jon Hall7eb38402015-01-08 17:19:54 -08001224 main.log.error(
1225 self.name +
1226 ": tcpdump - No such device exists. " +
1227 "tcpdump attempted on: " +
1228 intf )
admin2a9548d2014-06-17 14:08:07 -07001229 return main.FALSE
1230 elif i == 1:
Jon Hall7eb38402015-01-08 17:19:54 -08001231 main.log.info( self.name + ": tcpdump started on " + intf )
admin2a9548d2014-06-17 14:08:07 -07001232 return main.TRUE
1233 elif i == 2:
Jon Hall7eb38402015-01-08 17:19:54 -08001234 main.log.error(
1235 self.name +
1236 ": tcpdump command timed out! Check interface name," +
1237 " given interface was: " +
1238 intf )
admin2a9548d2014-06-17 14:08:07 -07001239 return main.FALSE
Jon Hall7eb38402015-01-08 17:19:54 -08001240 elif i == 3:
1241 main.log.info( self.name + ": " + self.handle.before )
admin2a9548d2014-06-17 14:08:07 -07001242 return main.TRUE
1243 else:
Jon Hall7eb38402015-01-08 17:19:54 -08001244 main.log.error( self.name + ": tcpdump - unexpected response" )
admin2a9548d2014-06-17 14:08:07 -07001245 return main.FALSE
1246 except pexpect.EOF:
Jon Hall7eb38402015-01-08 17:19:54 -08001247 main.log.error( self.name + ": EOF exception found" )
1248 main.log.error( self.name + ": " + self.handle.before )
admin2a9548d2014-06-17 14:08:07 -07001249 main.cleanup()
1250 main.exit()
1251 except:
Jon Hall7eb38402015-01-08 17:19:54 -08001252 main.log.info( self.name + ":" * 50 )
admin2a9548d2014-06-17 14:08:07 -07001253 main.log.error( traceback.print_exc() )
Jon Hall7eb38402015-01-08 17:19:54 -08001254 main.log.info(":" * 50 )
admin2a9548d2014-06-17 14:08:07 -07001255 main.cleanup()
1256 main.exit()
1257
Jon Hall7eb38402015-01-08 17:19:54 -08001258 def stop_tcpdump( self ):
admin2a9548d2014-06-17 14:08:07 -07001259 "pkills tcpdump"
1260 try:
Jon Hall7eb38402015-01-08 17:19:54 -08001261 self.handle.sendline( "sh sudo pkill tcpdump" )
1262 self.handle.expect( "mininet>" )
1263 self.handle.sendline( "" )
1264 self.handle.expect( "mininet>" )
admin2a9548d2014-06-17 14:08:07 -07001265 except pexpect.EOF:
Jon Hall7eb38402015-01-08 17:19:54 -08001266 main.log.error( self.name + ": EOF exception found" )
1267 main.log.error( self.name + ": " + self.handle.before )
admin2a9548d2014-06-17 14:08:07 -07001268 main.cleanup()
1269 main.exit()
1270 except:
Jon Hall7eb38402015-01-08 17:19:54 -08001271 main.log.info( self.name + ":" * 50 )
admin2a9548d2014-06-17 14:08:07 -07001272 main.log.error( traceback.print_exc() )
Jon Hall7eb38402015-01-08 17:19:54 -08001273 main.log.info(":" * 50 )
admin2a9548d2014-06-17 14:08:07 -07001274 main.cleanup()
1275 main.exit()
1276
Jon Hall7eb38402015-01-08 17:19:54 -08001277 def compare_switches( self, topo, switches_json ):
1278 """
1279 Compare mn and onos switches
1280 topo: sts TestONTopology object
1281 switches_json: parsed json object from the onos devices api
Jon Hall3d87d502014-10-17 18:37:42 -04001282
Jon Hall7eb38402015-01-08 17:19:54 -08001283 This uses the sts TestONTopology object"""
1284 # main.log.debug( "Switches_json string: ", switches_json )
1285 output = { "switches": [] }
1286 # iterate through the MN topology and pull out switches and and port
1287 # info
1288 for switch in topo.graph.switches:
Jon Hall3d87d502014-10-17 18:37:42 -04001289 ports = []
1290 for port in switch.ports.values():
Jon Hall7eb38402015-01-08 17:19:54 -08001291 ports.append( { 'of_port': port.port_no,
1292 'mac': str( port.hw_addr ).replace( '\'',
1293 ''),
1294 'name': port.name } )
1295 output[ 'switches' ].append( {
1296 "name": switch.name,
1297 "dpid": str( switch.dpid ).zfill( 16 ),
1298 "ports": ports } )
Jon Hall3d87d502014-10-17 18:37:42 -04001299
Jon Hall7eb38402015-01-08 17:19:54 -08001300 # print "mn"
1301 # print json.dumps( output,
1302 # sort_keys=True,
1303 # indent=4,
1304 # separators=( ',', ': ' ) )
1305 # print "onos"
1306 # print json.dumps( switches_json,
1307 # sort_keys=True,
1308 # indent=4,
1309 # separators=( ',', ': ' ) )
Jon Hall3d87d502014-10-17 18:37:42 -04001310
1311 # created sorted list of dpid's in MN and ONOS for comparison
Jon Hall7eb38402015-01-08 17:19:54 -08001312 mnDPIDs = []
1313 for switch in output[ 'switches' ]:
1314 mnDPIDs.append( switch[ 'dpid' ].lower() )
Jon Hall3d87d502014-10-17 18:37:42 -04001315 mnDPIDs.sort()
Jon Hall7eb38402015-01-08 17:19:54 -08001316 # print "List of Mininet switch DPID's"
1317 # print mnDPIDs
1318 if switches_json == "": # if rest call fails
1319 main.log.error(
1320 self.name +
1321 ".compare_switches(): Empty JSON object given from ONOS" )
Jon Hall3d87d502014-10-17 18:37:42 -04001322 return main.FALSE
Jon Hall7eb38402015-01-08 17:19:54 -08001323 onos = switches_json
1324 onosDPIDs = []
Jon Hall3d87d502014-10-17 18:37:42 -04001325 for switch in onos:
Jon Hall7eb38402015-01-08 17:19:54 -08001326 if switch[ 'available' ]:
1327 onosDPIDs.append(
1328 switch[ 'id' ].replace(
1329 ":",
1330 '' ).replace(
1331 "of",
1332 '' ).lower() )
1333 # else:
1334 # print "Switch is unavailable:"
1335 # print switch
Jon Hall3d87d502014-10-17 18:37:42 -04001336 onosDPIDs.sort()
Jon Hall7eb38402015-01-08 17:19:54 -08001337 # print "List of ONOS switch DPID's"
1338 # print onosDPIDs
Jon Hall3d87d502014-10-17 18:37:42 -04001339
Jon Hall7eb38402015-01-08 17:19:54 -08001340 if mnDPIDs != onosDPIDs:
Jon Hall3d87d502014-10-17 18:37:42 -04001341 switch_results = main.FALSE
Jon Hall7eb38402015-01-08 17:19:54 -08001342 main.log.report( "Switches in MN but not in ONOS:" )
1343 list1 = [ switch for switch in mnDPIDs if switch not in onosDPIDs ]
1344 main.log.report( str( list1 ) )
1345 main.log.report( "Switches in ONOS but not in MN:" )
1346 list2 = [ switch for switch in onosDPIDs if switch not in mnDPIDs ]
1347 main.log.report(str( list2 ) )
1348 else: # list of dpid's match in onos and mn
Jon Hall3d87d502014-10-17 18:37:42 -04001349 switch_results = main.TRUE
1350 return switch_results
1351
Jon Hall7eb38402015-01-08 17:19:54 -08001352 def compare_ports( self, topo, ports_json ):
1353 """
Jon Hall72cf1dc2014-10-20 21:04:50 -04001354 Compare mn and onos ports
1355 topo: sts TestONTopology object
1356 ports_json: parsed json object from the onos ports api
1357
Jon Hallfbc828e2015-01-06 17:30:19 -08001358 Dependencies:
Jon Hall72cf1dc2014-10-20 21:04:50 -04001359 1. This uses the sts TestONTopology object
1360 2. numpy - "sudo pip install numpy"
1361
Jon Hall7eb38402015-01-08 17:19:54 -08001362 """
1363 # FIXME: this does not look for extra ports in ONOS, only checks that
1364 # ONOS has what is in MN
Jon Hall72cf1dc2014-10-20 21:04:50 -04001365 from numpy import uint64
Jon Hallb1290e82014-11-18 16:17:48 -05001366 ports_results = main.TRUE
Jon Hall7eb38402015-01-08 17:19:54 -08001367 output = { "switches": [] }
1368 # iterate through the MN topology and pull out switches and and port
1369 # info
1370 for switch in topo.graph.switches:
Jon Hall72cf1dc2014-10-20 21:04:50 -04001371 ports = []
1372 for port in switch.ports.values():
Jon Hall7eb38402015-01-08 17:19:54 -08001373 # print port.hw_addr.toStr( separator='' )
Jon Hall39f29df2014-11-04 19:30:21 -05001374 tmp_port = {}
Jon Hall7eb38402015-01-08 17:19:54 -08001375 tmp_port[ 'of_port' ] = port.port_no
1376 tmp_port[ 'mac' ] = str( port.hw_addr ).replace( '\'', '' )
1377 tmp_port[ 'name' ] = port.name
1378 tmp_port[ 'enabled' ] = port.enabled
Jon Hall39f29df2014-11-04 19:30:21 -05001379
Jon Hall7eb38402015-01-08 17:19:54 -08001380 ports.append( tmp_port )
Jon Hall39f29df2014-11-04 19:30:21 -05001381 tmp_switch = {}
Jon Hall7eb38402015-01-08 17:19:54 -08001382 tmp_switch[ 'name' ] = switch.name
1383 tmp_switch[ 'dpid' ] = str( switch.dpid ).zfill( 16 )
1384 tmp_switch[ 'ports' ] = ports
Jon Hall39f29df2014-11-04 19:30:21 -05001385
Jon Hall7eb38402015-01-08 17:19:54 -08001386 output[ 'switches' ].append( tmp_switch )
Jon Hall72cf1dc2014-10-20 21:04:50 -04001387
Jon Hall7eb38402015-01-08 17:19:54 -08001388 # PORTS
1389 for mn_switch in output[ 'switches' ]:
Jon Hall72cf1dc2014-10-20 21:04:50 -04001390 mn_ports = []
1391 onos_ports = []
Jon Hallb1290e82014-11-18 16:17:48 -05001392 switch_result = main.TRUE
Jon Hall7eb38402015-01-08 17:19:54 -08001393 for port in mn_switch[ 'ports' ]:
1394 if port[ 'enabled' ]:
1395 mn_ports.append( port[ 'of_port' ] )
Jon Hall72cf1dc2014-10-20 21:04:50 -04001396 for onos_switch in ports_json:
Jon Hall7eb38402015-01-08 17:19:54 -08001397 # print "Iterating through a new switch as seen by ONOS"
1398 # print onos_switch
1399 if onos_switch[ 'device' ][ 'available' ]:
1400 if onos_switch[ 'device' ][ 'id' ].replace(
1401 ':',
1402 '' ).replace(
1403 "of",
1404 '' ) == mn_switch[ 'dpid' ]:
1405 for port in onos_switch[ 'ports' ]:
1406 if port[ 'isEnabled' ]:
1407 if port[ 'port' ] == 'local':
1408 # onos_ports.append( 'local' )
1409 onos_ports.append( long( uint64( -2 ) ) )
Jon Hallb1290e82014-11-18 16:17:48 -05001410 else:
Jon Hall7eb38402015-01-08 17:19:54 -08001411 onos_ports.append( int( port[ 'port' ] ) )
Jon Hallb1290e82014-11-18 16:17:48 -05001412 break
Jon Hall7eb38402015-01-08 17:19:54 -08001413 mn_ports.sort( key=float )
1414 onos_ports.sort( key=float )
1415 # print "\nPorts for Switch %s:" % ( mn_switch[ 'name' ] )
1416 # print "\tmn_ports[] = ", mn_ports
1417 # print "\tonos_ports[] = ", onos_ports
Jon Hallb1290e82014-11-18 16:17:48 -05001418 mn_ports_log = mn_ports
1419 onos_ports_log = onos_ports
Jon Hall7eb38402015-01-08 17:19:54 -08001420 mn_ports = [ x for x in mn_ports ]
1421 onos_ports = [ x for x in onos_ports ]
Jon Hall38481722014-11-04 16:50:05 -05001422
Jon Hall7eb38402015-01-08 17:19:54 -08001423 # TODO: handle other reserved port numbers besides LOCAL
1424 # NOTE: Reserved ports
1425 # Local port: -2 in Openflow, ONOS shows 'local', we store as
1426 # long( uint64( -2 ) )
Jon Hallb1290e82014-11-18 16:17:48 -05001427 for mn_port in mn_ports_log:
1428 if mn_port in onos_ports:
Jon Hall7eb38402015-01-08 17:19:54 -08001429 # don't set results to true here as this is just one of
1430 # many checks and it might override a failure
1431 mn_ports.remove( mn_port )
1432 onos_ports.remove( mn_port )
1433 # NOTE: OVS reports this as down since there is no link
Jon Hallb1290e82014-11-18 16:17:48 -05001434 # So ignoring these for now
Jon Hall7eb38402015-01-08 17:19:54 -08001435 # TODO: Come up with a better way of handling these
Jon Hallb1290e82014-11-18 16:17:48 -05001436 if 65534 in mn_ports:
Jon Hall7eb38402015-01-08 17:19:54 -08001437 mn_ports.remove( 65534 )
1438 if long( uint64( -2 ) ) in onos_ports:
1439 onos_ports.remove( long( uint64( -2 ) ) )
1440 if len( mn_ports ): # the ports of this switch don't match
Jon Hallb1290e82014-11-18 16:17:48 -05001441 switch_result = main.FALSE
Jon Hall7eb38402015-01-08 17:19:54 -08001442 main.log.warn( "Ports in MN but not ONOS: " + str( mn_ports ) )
1443 if len( onos_ports ): # the ports of this switch don't match
Jon Hallb1290e82014-11-18 16:17:48 -05001444 switch_result = main.FALSE
Jon Hall7eb38402015-01-08 17:19:54 -08001445 main.log.warn(
1446 "Ports in ONOS but not MN: " +
1447 str( onos_ports ) )
Jon Hallb1290e82014-11-18 16:17:48 -05001448 if switch_result == main.FALSE:
Jon Hall7eb38402015-01-08 17:19:54 -08001449 main.log.report(
1450 "The list of ports for switch %s(%s) does not match:" %
1451 ( mn_switch[ 'name' ], mn_switch[ 'dpid' ] ) )
1452 main.log.warn( "mn_ports[] = " + str( mn_ports_log ) )
1453 main.log.warn( "onos_ports[] = " + str( onos_ports_log ) )
Jon Hallb1290e82014-11-18 16:17:48 -05001454 ports_results = ports_results and switch_result
1455 return ports_results
Jon Hall72cf1dc2014-10-20 21:04:50 -04001456
Jon Hall7eb38402015-01-08 17:19:54 -08001457 def compare_links( self, topo, links_json ):
1458 """
1459 Compare mn and onos links
1460 topo: sts TestONTopology object
1461 links_json: parsed json object from the onos links api
Jon Hall72cf1dc2014-10-20 21:04:50 -04001462
Jon Hall7eb38402015-01-08 17:19:54 -08001463 This uses the sts TestONTopology object"""
1464 # FIXME: this does not look for extra links in ONOS, only checks that
1465 # ONOS has what is in MN
Jon Hall72cf1dc2014-10-20 21:04:50 -04001466 link_results = main.TRUE
Jon Hall7eb38402015-01-08 17:19:54 -08001467 output = { "switches": [] }
Jon Hall72cf1dc2014-10-20 21:04:50 -04001468 onos = links_json
Jon Hall7eb38402015-01-08 17:19:54 -08001469 # iterate through the MN topology and pull out switches and and port
1470 # info
1471 for switch in topo.graph.switches:
Jon Hall38481722014-11-04 16:50:05 -05001472 # print "Iterating though switches as seen by Mininet"
1473 # print switch
Jon Hall72cf1dc2014-10-20 21:04:50 -04001474 ports = []
1475 for port in switch.ports.values():
Jon Hall7eb38402015-01-08 17:19:54 -08001476 # print port.hw_addr.toStr( separator='' )
1477 ports.append( { 'of_port': port.port_no,
1478 'mac': str( port.hw_addr ).replace( '\'',
1479 ''),
1480 'name': port.name } )
1481 output[ 'switches' ].append( {
1482 "name": switch.name,
1483 "dpid": str( switch.dpid ).zfill( 16 ),
1484 "ports": ports } )
1485 # LINKS
Jon Hall72cf1dc2014-10-20 21:04:50 -04001486
Jon Hall7eb38402015-01-08 17:19:54 -08001487 mn_links = [
1488 link for link in topo.patch_panel.network_links if (
1489 link.port1.enabled and link.port2.enabled ) ]
1490 if 2 * len( mn_links ) == len( onos ):
Jon Hall72cf1dc2014-10-20 21:04:50 -04001491 link_results = main.TRUE
1492 else:
1493 link_results = main.FALSE
Jon Hall7eb38402015-01-08 17:19:54 -08001494 main.log.report(
1495 "Mininet has %i bidirectional links and " +
1496 "ONOS has %i unidirectional links" %
1497 ( len( mn_links ), len( onos ) ) )
Jon Hall72cf1dc2014-10-20 21:04:50 -04001498
Jon Hall7eb38402015-01-08 17:19:54 -08001499 # iterate through MN links and check if an ONOS link exists in
1500 # both directions
1501 # NOTE: Will currently only show mn links as down if they are
1502 # cut through STS. We can either do everything through STS or
1503 # wait for up_network_links and down_network_links to be
1504 # fully implemented.
Jon Hallfbc828e2015-01-06 17:30:19 -08001505 for link in mn_links:
Jon Hall7eb38402015-01-08 17:19:54 -08001506 # print "Link: %s" % link
1507 # TODO: Find a more efficient search method
Jon Hall72cf1dc2014-10-20 21:04:50 -04001508 node1 = None
1509 port1 = None
1510 node2 = None
1511 port2 = None
1512 first_dir = main.FALSE
1513 second_dir = main.FALSE
Jon Hall7eb38402015-01-08 17:19:54 -08001514 for switch in output[ 'switches' ]:
1515 # print "Switch: %s" % switch[ 'name' ]
1516 if switch[ 'name' ] == link.node1.name:
1517 node1 = switch[ 'dpid' ]
1518 for port in switch[ 'ports' ]:
1519 if str( port[ 'name' ] ) == str( link.port1 ):
1520 port1 = port[ 'of_port' ]
Jon Hall72cf1dc2014-10-20 21:04:50 -04001521 if node1 is not None and node2 is not None:
1522 break
Jon Hall7eb38402015-01-08 17:19:54 -08001523 if switch[ 'name' ] == link.node2.name:
1524 node2 = switch[ 'dpid' ]
1525 for port in switch[ 'ports' ]:
1526 if str( port[ 'name' ] ) == str( link.port2 ):
1527 port2 = port[ 'of_port' ]
Jon Hall72cf1dc2014-10-20 21:04:50 -04001528 if node1 is not None and node2 is not None:
1529 break
1530
Jon Hall72cf1dc2014-10-20 21:04:50 -04001531 for onos_link in onos:
Jon Hall7eb38402015-01-08 17:19:54 -08001532 onos_node1 = onos_link[ 'src' ][ 'device' ].replace(
1533 ":",
1534 '' ).replace(
1535 "of",
1536 '' )
1537 onos_node2 = onos_link[ 'dst' ][ 'device' ].replace(
1538 ":",
1539 '' ).replace(
1540 "of",
1541 '' )
1542 onos_port1 = onos_link[ 'src' ][ 'port' ]
1543 onos_port2 = onos_link[ 'dst' ][ 'port' ]
Jon Hall72cf1dc2014-10-20 21:04:50 -04001544
Jon Hall72cf1dc2014-10-20 21:04:50 -04001545 # check onos link from node1 to node2
Jon Hall7eb38402015-01-08 17:19:54 -08001546 if str( onos_node1 ) == str( node1 ) and str(
1547 onos_node2 ) == str( node2 ):
1548 if int( onos_port1 ) == int( port1 ) and int(
1549 onos_port2 ) == int( port2 ):
Jon Hall72cf1dc2014-10-20 21:04:50 -04001550 first_dir = main.TRUE
1551 else:
Jon Hall7eb38402015-01-08 17:19:54 -08001552 main.log.warn(
1553 'The port numbers do not match for ' +
1554 str( link ) +
1555 ' between ONOS and MN. When cheking ONOS for ' +
1556 'link %s/%s -> %s/%s' %
1557 ( node1,
1558 port1,
1559 node2,
1560 port2 ) +
1561 ' ONOS has the values %s/%s -> %s/%s' %
1562 ( onos_node1,
1563 onos_port1,
1564 onos_node2,
1565 onos_port2 ) )
Jon Hall72cf1dc2014-10-20 21:04:50 -04001566
1567 # check onos link from node2 to node1
Jon Hall7eb38402015-01-08 17:19:54 -08001568 elif ( str( onos_node1 ) == str( node2 ) and
1569 str( onos_node2 ) == str( node1 ) ):
1570 if ( int( onos_port1 ) == int( port2 )
1571 and int( onos_port2 ) == int( port1 ) ):
Jon Hall72cf1dc2014-10-20 21:04:50 -04001572 second_dir = main.TRUE
1573 else:
Jon Hall7eb38402015-01-08 17:19:54 -08001574 main.log.warn(
1575 'The port numbers do not match for ' +
1576 str( link ) +
1577 ' between ONOS and MN. When cheking ONOS for ' +
1578 'link %s/%s -> %s/%s' %
1579 ( node2,
1580 port2,
1581 node1,
1582 port1 ) +
1583 ' ONOS has the values %s/%s -> %s/%s' %
1584 ( onos_node2,
1585 onos_port2,
1586 onos_node1,
1587 onos_port1 ) )
1588 else: # this is not the link you're looking for
Jon Hall72cf1dc2014-10-20 21:04:50 -04001589 pass
1590 if not first_dir:
Jon Hall7eb38402015-01-08 17:19:54 -08001591 main.log.report(
1592 'ONOS does not have the link %s/%s -> %s/%s' %
1593 ( node1, port1, node2, port2 ) )
Jon Hall72cf1dc2014-10-20 21:04:50 -04001594 if not second_dir:
Jon Hall7eb38402015-01-08 17:19:54 -08001595 main.log.report(
1596 'ONOS does not have the link %s/%s -> %s/%s' %
1597 ( node2, port2, node1, port1 ) )
Jon Hall72cf1dc2014-10-20 21:04:50 -04001598 link_results = link_results and first_dir and second_dir
Jon Hall62df9242014-10-22 12:20:17 -04001599 return link_results
Jon Hall72cf1dc2014-10-20 21:04:50 -04001600
Jon Hall7eb38402015-01-08 17:19:54 -08001601 def get_hosts( self ):
1602 """
1603 Returns a list of all hosts
1604 Don't ask questions just use it"""
1605 self.handle.sendline( "" )
1606 self.handle.expect( "mininet>" )
Jon Hall72cf1dc2014-10-20 21:04:50 -04001607
Jon Hall7eb38402015-01-08 17:19:54 -08001608 self.handle.sendline( "py [ host.name for host in net.hosts ]" )
1609 self.handle.expect( "mininet>" )
admin2a9548d2014-06-17 14:08:07 -07001610
andrewonlab3f0a4af2014-10-17 12:25:14 -04001611 handle_py = self.handle.before
Jon Hall7eb38402015-01-08 17:19:54 -08001612 handle_py = handle_py.split( "]\r\n", 1 )[ 1 ]
andrewonlab3f0a4af2014-10-17 12:25:14 -04001613 handle_py = handle_py.rstrip()
admin2a9548d2014-06-17 14:08:07 -07001614
Jon Hall7eb38402015-01-08 17:19:54 -08001615 self.handle.sendline( "" )
1616 self.handle.expect( "mininet>" )
admin2a9548d2014-06-17 14:08:07 -07001617
Jon Hall7eb38402015-01-08 17:19:54 -08001618 host_str = handle_py.replace( "]", "" )
1619 host_str = host_str.replace( "'", "" )
1620 host_str = host_str.replace( "[", "" )
1621 host_list = host_str.split( "," )
andrewonlab3f0a4af2014-10-17 12:25:14 -04001622
Jon Hallfbc828e2015-01-06 17:30:19 -08001623 return host_list
adminbae64d82013-08-01 10:50:15 -07001624
Jon Hall7eb38402015-01-08 17:19:54 -08001625 def update( self ):
1626 """
1627 updates the port address and status information for
1628 each port in mn"""
1629 # TODO: Add error checking. currently the mininet command has no output
1630 main.log.info( "Updateing MN port information" )
Jon Hallb1290e82014-11-18 16:17:48 -05001631 try:
Jon Hall7eb38402015-01-08 17:19:54 -08001632 self.handle.sendline( "" )
1633 self.handle.expect( "mininet>" )
Jon Hall38481722014-11-04 16:50:05 -05001634
Jon Hall7eb38402015-01-08 17:19:54 -08001635 self.handle.sendline( "update" )
1636 self.handle.expect( "update" )
1637 self.handle.expect( "mininet>" )
Jon Hall38481722014-11-04 16:50:05 -05001638
Jon Hall7eb38402015-01-08 17:19:54 -08001639 self.handle.sendline( "" )
1640 self.handle.expect( "mininet>" )
Jon Hall38481722014-11-04 16:50:05 -05001641
Jon Hallb1290e82014-11-18 16:17:48 -05001642 return main.TRUE
1643 except pexpect.EOF:
Jon Hall7eb38402015-01-08 17:19:54 -08001644 main.log.error( self.name + ": EOF exception found" )
1645 main.log.error( self.name + ": " + self.handle.before )
Jon Hallb1290e82014-11-18 16:17:48 -05001646 main.cleanup()
1647 main.exit()
1648
adminbae64d82013-08-01 10:50:15 -07001649if __name__ != "__main__":
1650 import sys
Jon Hall7eb38402015-01-08 17:19:54 -08001651 sys.modules[ __name__ ] = MininetCliDriver()