blob: 92ec3123a9f9c21bfb2d179d3c7867b4463f1816 [file] [log] [blame]
adminbae64d82013-08-01 10:50:15 -07001#!/usr/bin/env python
2'''
3Created on 26-Oct-2012
4
5@author: Anil Kumar (anilkumar.s@paxterrasolutions.com)
6
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
21
22MininetCliDriver is the basic driver which will handle the Mininet functions
23'''
admin2a9548d2014-06-17 14:08:07 -070024import traceback
adminbae64d82013-08-01 10:50:15 -070025import pexpect
26import struct
27import fcntl
28import os
29import signal
30import re
31import sys
32import core.teston
33sys.path.append("../")
Jon Hall1ccf82c2014-10-15 14:55:16 -040034from math import pow
adminbae64d82013-08-01 10:50:15 -070035from drivers.common.cli.emulatordriver import Emulator
36from drivers.common.clidriver import CLI
37
38class MininetCliDriver(Emulator):
39 '''
Jon Hall41f40e82014-04-08 16:43:17 -070040 MininetCliDriver is the basic driver which will handle the Mininet functions
adminbae64d82013-08-01 10:50:15 -070041 '''
42 def __init__(self):
43 super(Emulator, self).__init__()
44 self.handle = self
45 self.wrapped = sys.modules[__name__]
46 self.flag = 0
47
48 def connect(self, **connectargs):
Jon Hall41f40e82014-04-08 16:43:17 -070049 '''
50 Here the main is the TestON instance after creating all the log handles.
51 '''
adminbae64d82013-08-01 10:50:15 -070052 for key in connectargs:
53 vars(self)[key] = connectargs[key]
54
55 self.name = self.options['name']
56 self.handle = super(MininetCliDriver, self).connect(user_name = self.user_name, ip_address = self.ip_address,port = None, pwd = self.pwd)
57
58 self.ssh_handle = self.handle
59
adminbae64d82013-08-01 10:50:15 -070060 if self.handle :
Jon Hallf2942ce2014-04-10 16:00:16 -070061 main.log.info(self.name+": Clearing any residual state or processes")
adminbae64d82013-08-01 10:50:15 -070062 self.handle.sendline("sudo mn -c")
adminf939f8b2014-04-03 17:22:56 -070063 i=self.handle.expect(['password\sfor\s','Cleanup\scomplete',pexpect.EOF,pexpect.TIMEOUT],120)
adminbae64d82013-08-01 10:50:15 -070064 if i==0:
Jon Hallf2942ce2014-04-10 16:00:16 -070065 main.log.info(self.name+": Sending sudo password")
adminf939f8b2014-04-03 17:22:56 -070066 self.handle.sendline(self.pwd)
67 i=self.handle.expect(['%s:'%(self.user),'\$',pexpect.EOF,pexpect.TIMEOUT],120)
adminbae64d82013-08-01 10:50:15 -070068 if i==1:
Jon Hallf2942ce2014-04-10 16:00:16 -070069 main.log.info(self.name+": Clean")
adminbae64d82013-08-01 10:50:15 -070070 elif i==2:
Jon Hallf2942ce2014-04-10 16:00:16 -070071 main.log.error(self.name+": Connection terminated")
adminbae64d82013-08-01 10:50:15 -070072 elif i==3: #timeout
Jon Hallf2942ce2014-04-10 16:00:16 -070073 main.log.error(self.name+": Something while cleaning MN took too long... " )
adminbae64d82013-08-01 10:50:15 -070074
Jon Hallf2942ce2014-04-10 16:00:16 -070075 main.log.info(self.name+": building fresh mininet")
adminbeea0032014-01-23 14:54:13 -080076 #### for reactive/PARP enabled tests
shahshreyaf4d4d0c2014-10-10 12:11:10 -070077 cmdString = "sudo mn " + self.options['arg1'] + " " + self.options['arg2'] + " --mac --controller " + self.options['controller'] + " " + self.options['arg3']
Jon Hall1ccf82c2014-10-15 14:55:16 -040078
79 argList = self.options['arg1'].split(",")
80 global topoArgList
81 topoArgList = argList[0].split(" ")
82 argList = map(int, argList[1:])
83 topoArgList = topoArgList[1:] + argList
84
85 #### for proactive flow with static ARP entries
shahshreyaf4d4d0c2014-10-10 12:11:10 -070086 #cmdString = "sudo mn " + self.options['arg1'] + " " + self.options['arg2'] + " --mac --arp --controller " + self.options['controller'] + " " + self.options['arg3']
adminbae64d82013-08-01 10:50:15 -070087 self.handle.sendline(cmdString)
Jon Hall333fa8c2014-04-11 11:24:58 -070088 self.handle.expect(["sudo mn",pexpect.EOF,pexpect.TIMEOUT])
adminbae64d82013-08-01 10:50:15 -070089 while 1:
90 i=self.handle.expect(['mininet>','\*\*\*','Exception',pexpect.EOF,pexpect.TIMEOUT],300)
91 if i==0:
Jon Hallf2942ce2014-04-10 16:00:16 -070092 main.log.info(self.name+": mininet built")
adminbae64d82013-08-01 10:50:15 -070093 return main.TRUE
94 if i==1:
Jon Hall1645caa2014-11-18 16:27:14 -050095 self.handle.expect(["\n",pexpect.EOF,pexpect.TIMEOUT])
adminbae64d82013-08-01 10:50:15 -070096 main.log.info(self.handle.before)
97 elif i==2:
Jon Hallf2942ce2014-04-10 16:00:16 -070098 main.log.error(self.name+": Launching mininet failed...")
adminbae64d82013-08-01 10:50:15 -070099 return main.FALSE
100 elif i==3:
Jon Hallf2942ce2014-04-10 16:00:16 -0700101 main.log.error(self.name+": Connection timeout")
adminbae64d82013-08-01 10:50:15 -0700102 return main.FALSE
103 elif i==4: #timeout
Jon Hallf2942ce2014-04-10 16:00:16 -0700104 main.log.error(self.name+": Something took too long... " )
adminbae64d82013-08-01 10:50:15 -0700105 return main.FALSE
adminbae64d82013-08-01 10:50:15 -0700106 #if utilities.assert_matches(expect=patterns,actual=resultCommand,onpass="Network is being launched",onfail="Network launching is being failed "):
107 return main.TRUE
Jon Hallf2942ce2014-04-10 16:00:16 -0700108 else:#if no handle
109 main.log.error(self.name+": Connection failed to the host "+self.user_name+"@"+self.ip_address)
110 main.log.error(self.name+": Failed to connect to the Mininet")
adminbae64d82013-08-01 10:50:15 -0700111 return main.FALSE
Jon Hall1ccf82c2014-10-15 14:55:16 -0400112
113 def num_switches_n_links(self,topoType,depth,fanout):
114 if topoType == 'tree':
115 if fanout is None: #In tree topology, if fanout arg is not given, by default it is 2
116 fanout = 2
117 k = 0
Jon Hall38481722014-11-04 16:50:05 -0500118 count = 0
Jon Hall1ccf82c2014-10-15 14:55:16 -0400119 while(k <= depth-1):
Jon Hall38481722014-11-04 16:50:05 -0500120 count = count + pow(fanout,k)
Jon Hall1ccf82c2014-10-15 14:55:16 -0400121 k = k+1
Jon Hall38481722014-11-04 16:50:05 -0500122 num_switches = count
Jon Hall1ccf82c2014-10-15 14:55:16 -0400123 while(k <= depth-2):
124 '''depth-2 gives you only core links and not considering edge links as seen by ONOS
125 If all the links including edge links are required, do depth-1
126 '''
Jon Hall38481722014-11-04 16:50:05 -0500127 count = count + pow(fanout,k)
Jon Hall1ccf82c2014-10-15 14:55:16 -0400128 k = k+1
Jon Hall38481722014-11-04 16:50:05 -0500129 num_links = count * fanout
Jon Hall1ccf82c2014-10-15 14:55:16 -0400130 #print "num_switches for %s(%d,%d) = %d and links=%d" %(topoType,depth,fanout,num_switches,num_links)
131
132 elif topoType =='linear':
133 if fanout is None: #In linear topology, if fanout or num_hosts_per_sw is not given, by default it is 1
134 fanout = 1
135 num_switches = depth
136 num_hosts_per_sw = fanout
137 total_num_hosts = num_switches * num_hosts_per_sw
138 num_links = total_num_hosts + (num_switches - 1)
139 print "num_switches for %s(%d,%d) = %d and links=%d" %(topoType,depth,fanout,num_switches,num_links)
140 topoDict = {}
141 topoDict = {"num_switches":int(num_switches), "num_corelinks":int(num_links)}
142 return topoDict
143
144
145 def calculate_sw_and_links(self):
146 topoDict = self.num_switches_n_links(*topoArgList)
147 return topoDict
148
Jon Hall1645caa2014-11-18 16:27:14 -0500149 def pingall(self, timeout=300):
adminbae64d82013-08-01 10:50:15 -0700150 '''
Jon Hall41f40e82014-04-08 16:43:17 -0700151 Verifies the reachability of the hosts using pingall command.
Jon Hall1645caa2014-11-18 16:27:14 -0500152 Optional parameter timeout allows you to specify how long to wait for pingall to complete
153 Returns:
154 main.TRUE if pingall completes with no pings dropped
155 otherwise main.FALSE
adminbae64d82013-08-01 10:50:15 -0700156 '''
157 if self.handle :
Jon Hallf2942ce2014-04-10 16:00:16 -0700158 main.log.info(self.name+": Checking reachabilty to the hosts using pingall")
Jon Hall6094a362014-04-11 14:46:56 -0700159 try:
Jon Hall1645caa2014-11-18 16:27:14 -0500160 response = self.execute(cmd="pingall",prompt="mininet>",timeout=int(timeout))
Jon Hallb1290e82014-11-18 16:17:48 -0500161 except pexpect.EOF:
Jon Hall6094a362014-04-11 14:46:56 -0700162 main.log.error(self.name + ": EOF exception found")
163 main.log.error(self.name + ": " + self.handle.before)
Jon Hallb1290e82014-11-18 16:17:48 -0500164 main.cleanup()
165 main.exit()
166 except pexpect.TIMEOUT:
167 #We may not want to kill the test if pexpect times out
168 main.log.error(self.name + ": TIMEOUT exception found")
169 main.log.error(self.name + ": " + str(self.handle.before) )
170 #NOTE: mininet's pingall rounds, so we will check the number of passed and number of failed
171 pattern = "Results\:\s0\%\sdropped\s\((?P<passed>[\d]+)/(?P=passed)"
Jon Hallf2942ce2014-04-10 16:00:16 -0700172 if re.search(pattern,response):
173 main.log.info(self.name+": All hosts are reachable")
adminbae64d82013-08-01 10:50:15 -0700174 return main.TRUE
175 else:
Jon Hallf2942ce2014-04-10 16:00:16 -0700176 main.log.error(self.name+": Unable to reach all the hosts")
Jon Hallb1290e82014-11-18 16:17:48 -0500177 main.log.info("Pingall ouput: " + str(response))
178 #NOTE: Send ctrl-c to make sure pingall is done
179 self.handle.send("\x03")
180 self.handle.expect("Interrupt")
181 self.handle.expect("mininet>")
adminbae64d82013-08-01 10:50:15 -0700182 return main.FALSE
183 else :
Jon Hallf2942ce2014-04-10 16:00:16 -0700184 main.log.error(self.name+": Connection failed to the host")
Jon Hallb1290e82014-11-18 16:17:48 -0500185 main.cleanup()
186 main.exit()
adminaeedddd2013-08-02 15:14:15 -0700187
188 def fpingHost(self,**pingParams):
189 '''
190 Uses the fping package for faster pinging...
191 *requires fping to be installed on machine running mininet
192 '''
193 args = utilities.parse_args(["SRC","TARGET"],**pingParams)
admin530b4c92013-08-14 16:54:35 -0700194 command = args["SRC"] + " fping -i 100 -t 20 -C 1 -q "+args["TARGET"]
adminaeedddd2013-08-02 15:14:15 -0700195 self.handle.sendline(command)
Jon Hall333fa8c2014-04-11 11:24:58 -0700196 self.handle.expect([args["TARGET"],pexpect.EOF,pexpect.TIMEOUT])
197 self.handle.expect(["mininet",pexpect.EOF,pexpect.TIMEOUT])
adminaeedddd2013-08-02 15:14:15 -0700198 response = self.handle.before
199 if re.search(":\s-" ,response):
Jon Hallf2942ce2014-04-10 16:00:16 -0700200 main.log.info(self.name+": Ping fail")
adminaeedddd2013-08-02 15:14:15 -0700201 return main.FALSE
admin530b4c92013-08-14 16:54:35 -0700202 elif re.search(":\s\d{1,2}\.\d\d", response):
Jon Hallf2942ce2014-04-10 16:00:16 -0700203 main.log.info(self.name+": Ping good!")
adminaeedddd2013-08-02 15:14:15 -0700204 return main.TRUE
Jon Hallf2942ce2014-04-10 16:00:16 -0700205 main.log.info(self.name+": Install fping on mininet machine... ")
206 main.log.info(self.name+": \n---\n"+response)
adminaeedddd2013-08-02 15:14:15 -0700207 return main.FALSE
adminbae64d82013-08-01 10:50:15 -0700208
209 def pingHost(self,**pingParams):
Jon Hallf2942ce2014-04-10 16:00:16 -0700210 '''
211 Ping from one mininet host to another
212 Currently the only supported Params: SRC and TARGET
213 '''
adminbae64d82013-08-01 10:50:15 -0700214 args = utilities.parse_args(["SRC","TARGET"],**pingParams)
215 #command = args["SRC"] + " ping -" + args["CONTROLLER"] + " " +args ["TARGET"]
Jon Hall0819fd92014-05-23 12:08:13 -0700216 command = args["SRC"] + " ping "+args ["TARGET"]+" -c 1 -i 1 -W 8"
Jon Hall6094a362014-04-11 14:46:56 -0700217 try:
Jon Hall6e18c7b2014-04-23 16:26:33 -0700218 main.log.warn("Sending: " + command)
219 #response = self.execute(cmd=command,prompt="mininet",timeout=10 )
220 self.handle.sendline(command)
221 i = self.handle.expect([command,pexpect.TIMEOUT])
222 if i == 1:
223 main.log.error(self.name + ": timeout when waiting for response from mininet")
224 main.log.error("response: " + str(self.handle.before))
225 i = self.handle.expect(["mininet>",pexpect.TIMEOUT])
226 if i == 1:
227 main.log.error(self.name + ": timeout when waiting for response from mininet")
228 main.log.error("response: " + str(self.handle.before))
229 response = self.handle.before
Jon Hall6094a362014-04-11 14:46:56 -0700230 except pexpect.EOF:
231 main.log.error(self.name + ": EOF exception found")
232 main.log.error(self.name + ": " + self.handle.before)
233 main.cleanup()
234 main.exit()
Jon Hallf2942ce2014-04-10 16:00:16 -0700235 main.log.info(self.name+": Ping Response: "+ response )
236 #if utilities.assert_matches(expect=',\s0\%\spacket\sloss',actual=response,onpass="No Packet loss",onfail="Host is not reachable"):
237 if re.search(',\s0\%\spacket\sloss',response):
Jon Hall6e18c7b2014-04-23 16:26:33 -0700238 main.log.info(self.name+": no packets lost, host is reachable")
adminbae64d82013-08-01 10:50:15 -0700239 main.last_result = main.TRUE
240 return main.TRUE
241 else :
Jon Hallf2942ce2014-04-10 16:00:16 -0700242 main.log.error(self.name+": PACKET LOST, HOST IS NOT REACHABLE")
adminbae64d82013-08-01 10:50:15 -0700243 main.last_result = main.FALSE
244 return main.FALSE
adminbae64d82013-08-01 10:50:15 -0700245
246 def checkIP(self,host):
247 '''
Jon Hall41f40e82014-04-08 16:43:17 -0700248 Verifies the host's ip configured or not.
adminbae64d82013-08-01 10:50:15 -0700249 '''
250 if self.handle :
Jon Hall6094a362014-04-11 14:46:56 -0700251 try:
252 response = self.execute(cmd=host+" ifconfig",prompt="mininet>",timeout=10)
253 except pexpect.EOF:
254 main.log.error(self.name + ": EOF exception found")
255 main.log.error(self.name + ": " + self.handle.before)
256 main.cleanup()
257 main.exit()
adminbae64d82013-08-01 10:50:15 -0700258
259 pattern = "inet\s(addr|Mask):([0-1]{1}[0-9]{1,2}|2[0-4][0-9]|25[0-5]|[0-9]{1,2}).([0-1]{1}[0-9]{1,2}|2[0-4][0-9]|25[0-5]|[0-9]{1,2}).([0-1]{1}[0-9]{1,2}|2[0-4][0-9]|25[0-5]|[0-9]{1,2}).([0-1]{1}[0-9]{1,2}|2[0-4][0-9]|25[0-5]|[0-9]{1,2})"
admin2a9548d2014-06-17 14:08:07 -0700260 #pattern = "inet addr:10.0.0.6"
Jon Hallf2942ce2014-04-10 16:00:16 -0700261 #if utilities.assert_matches(expect=pattern,actual=response,onpass="Host Ip configured properly",onfail="Host IP not found") :
262 if re.search(pattern,response):
263 main.log.info(self.name+": Host Ip configured properly")
adminbae64d82013-08-01 10:50:15 -0700264 return main.TRUE
265 else:
Jon Hallf2942ce2014-04-10 16:00:16 -0700266 main.log.error(self.name+": Host IP not found")
adminbae64d82013-08-01 10:50:15 -0700267 return main.FALSE
268 else :
Jon Hallf2942ce2014-04-10 16:00:16 -0700269 main.log.error(self.name+": Connection failed to the host")
adminbae64d82013-08-01 10:50:15 -0700270
271 def verifySSH(self,**connectargs):
Jon Hall6094a362014-04-11 14:46:56 -0700272 try:
273 response = self.execute(cmd="h1 /usr/sbin/sshd -D&",prompt="mininet>",timeout=10)
274 response = self.execute(cmd="h4 /usr/sbin/sshd -D&",prompt="mininet>",timeout=10)
275 for key in connectargs:
276 vars(self)[key] = connectargs[key]
277 response = self.execute(cmd="xterm h1 h4 ",prompt="mininet>",timeout=10)
278 except pexpect.EOF:
279 main.log.error(self.name + ": EOF exception found")
280 main.log.error(self.name + ": " + self.handle.before)
281 main.cleanup()
282 main.exit()
adminbae64d82013-08-01 10:50:15 -0700283 import time
284 time.sleep(20)
285 if self.flag == 0:
286 self.flag = 1
287 return main.FALSE
288 else :
289 return main.TRUE
shahshreyae6c7cf42014-11-26 16:39:01 -0800290
adminbae64d82013-08-01 10:50:15 -0700291
shahshreyae6c7cf42014-11-26 16:39:01 -0800292
293
294 def changeIP(self,host,intf,newIP,newNetmask):
295 '''
296 Changes the ip address of a host on the fly
297 Ex: h2 ifconfig h2-eth0 10.0.1.2 netmask 255.255.255.0
298 '''
299 if self.handle:
300 try:
301 cmd = host+" ifconfig "+intf+" "+newIP+" "+newNetMask
302 self.handle.sendline(cmd)
303 self.handle.expect("mininet>")
304 response = self.handle.before
305 main.log.info("Ip of host "+host+" changed to new IP "+newIP)
306 return main.TRUE
307 except pexpect.EOF:
308 main.log.error(self.name + ": EOF exception found")
309 main.log.error(self.name + ": " + self.handle.before)
310 return main.FALSE
311
312 def changeDefaultGateway(self,host,newGW):
313 '''
314 Changes the default gateway of a host
315 Ex: h1 route add default gw 10.0.1.2
316 '''
317 if self.handle:
318 try:
319 cmd = host+" route add default gw "+newGW
320 self.handle.sendline(cmd)
321 self.handle.expect("mininet>")
322 response = self.handle.before
323 main.log.info("Default gateway of host "+host+" changed to "+newGW)
324 return main.TRUE
325 except pexpect.EOF:
326 main.log.error(self.name + ": EOF exception found")
327 main.log.error(self.name + ": " + self.handle.before)
328 return main.FALSE
329
330
adminbae64d82013-08-01 10:50:15 -0700331 def getMacAddress(self,host):
332 '''
Jon Hall41f40e82014-04-08 16:43:17 -0700333 Verifies the host's ip configured or not.
adminbae64d82013-08-01 10:50:15 -0700334 '''
335 if self.handle :
Jon Hall6094a362014-04-11 14:46:56 -0700336 try:
337 response = self.execute(cmd=host+" ifconfig",prompt="mininet>",timeout=10)
338 except pexpect.EOF:
339 main.log.error(self.name + ": EOF exception found")
340 main.log.error(self.name + ": " + self.handle.before)
341 main.cleanup()
342 main.exit()
adminbae64d82013-08-01 10:50:15 -0700343
Ahmed El-Hassanyf720e202014-04-04 16:11:36 -0700344 pattern = r'HWaddr\s([0-9A-F]{2}[:-]){5}([0-9A-F]{2})'
345 mac_address_search = re.search(pattern, response, re.I)
346 mac_address = mac_address_search.group().split(" ")[1]
Jon Hallf2942ce2014-04-10 16:00:16 -0700347 main.log.info(self.name+": Mac-Address of Host "+ host + " is " + mac_address)
Ahmed El-Hassanyf720e202014-04-04 16:11:36 -0700348 return mac_address
adminbae64d82013-08-01 10:50:15 -0700349 else :
Jon Hallf2942ce2014-04-10 16:00:16 -0700350 main.log.error(self.name+": Connection failed to the host")
Ahmed El-Hassanyfd329182014-04-10 11:38:16 -0700351
352 def getInterfaceMACAddress(self,host, interface):
353 '''
354 Return the IP address of the interface on the given host
355 '''
356 if self.handle :
Jon Hall6094a362014-04-11 14:46:56 -0700357 try:
358 response = self.execute(cmd=host+" ifconfig " + interface,
Ahmed El-Hassanyfd329182014-04-10 11:38:16 -0700359 prompt="mininet>",timeout=10)
Jon Hall6094a362014-04-11 14:46:56 -0700360 except pexpect.EOF:
361 main.log.error(self.name + ": EOF exception found")
362 main.log.error(self.name + ": " + self.handle.before)
363 main.cleanup()
364 main.exit()
Ahmed El-Hassanyfd329182014-04-10 11:38:16 -0700365
366 pattern = r'HWaddr\s([0-9A-F]{2}[:-]){5}([0-9A-F]{2})'
367 mac_address_search = re.search(pattern, response, re.I)
368 if mac_address_search is None:
369 main.log.info("No mac address found in %s" % response)
370 return main.FALSE
371 mac_address = mac_address_search.group().split(" ")[1]
372 main.log.info("Mac-Address of "+ host + ":"+ interface + " is " + mac_address)
373 return mac_address
374 else:
375 main.log.error("Connection failed to the host")
376
adminbae64d82013-08-01 10:50:15 -0700377 def getIPAddress(self,host):
378 '''
Jon Hall41f40e82014-04-08 16:43:17 -0700379 Verifies the host's ip configured or not.
adminbae64d82013-08-01 10:50:15 -0700380 '''
381 if self.handle :
Jon Hall6094a362014-04-11 14:46:56 -0700382 try:
383 response = self.execute(cmd=host+" ifconfig",prompt="mininet>",timeout=10)
384 except pexpect.EOF:
385 main.log.error(self.name + ": EOF exception found")
386 main.log.error(self.name + ": " + self.handle.before)
387 main.cleanup()
388 main.exit()
adminbae64d82013-08-01 10:50:15 -0700389
390 pattern = "inet\saddr:(\d+\.\d+\.\d+\.\d+)"
391 ip_address_search = re.search(pattern, response)
Jon Hallf2942ce2014-04-10 16:00:16 -0700392 main.log.info(self.name+": IP-Address of Host "+host +" is "+ip_address_search.group(1))
adminbae64d82013-08-01 10:50:15 -0700393 return ip_address_search.group(1)
394 else :
Jon Hallf2942ce2014-04-10 16:00:16 -0700395 main.log.error(self.name+": Connection failed to the host")
adminbae64d82013-08-01 10:50:15 -0700396
Ahmed El-Hassanyfd329182014-04-10 11:38:16 -0700397 def getSwitchDPID(self,switch):
398 '''
399 return the datapath ID of the switch
400 '''
401 if self.handle :
402 cmd = "py %s.dpid" % switch
Jon Hall6094a362014-04-11 14:46:56 -0700403 try:
404 response = self.execute(cmd=cmd,prompt="mininet>",timeout=10)
405 except pexpect.EOF:
406 main.log.error(self.name + ": EOF exception found")
407 main.log.error(self.name + ": " + self.handle.before)
408 main.cleanup()
409 main.exit()
Ahmed El-Hassanyfd329182014-04-10 11:38:16 -0700410 pattern = r'^(?P<dpid>\d)+'
411 result = re.search(pattern, response, re.MULTILINE)
412 if result is None:
413 main.log.info("Couldn't find DPID for switch '', found: %s" % (switch, response))
414 return main.FALSE
Jon Hallc1a1d242014-07-21 16:03:33 -0700415 return str(result.group(0))
Ahmed El-Hassanyfd329182014-04-10 11:38:16 -0700416 else:
417 main.log.error("Connection failed to the host")
418
admin2580a0e2014-07-29 11:24:34 -0700419 def getDPID(self, switch):
420 if self.handle:
421 self.handle.sendline("")
422 self.expect("mininet>")
423 cmd = "py %s.dpid" %switch
424 try:
425 response = self.execute(cmd=cmd,prompt="mininet>",timeout=10)
426 self.handle.expect("mininet>")
427 response = self.handle.before
428 return response
429 except pexpect.EOF:
430 main.log.error(self.name + ": EOF exception found")
431 main.log.error(self.name + ": " + self.handle.before)
432 main.cleanup()
433 main.exit()
434
435
Ahmed El-Hassanyfd329182014-04-10 11:38:16 -0700436 def getInterfaces(self, node):
437 '''
438 return information dict about interfaces connected to the node
439 '''
440 if self.handle :
Jon Hall38481722014-11-04 16:50:05 -0500441 cmd = 'py "\\n".join(["name=%s,mac=%s,ip=%s,enabled=%s" % (i.name, i.MAC(), i.IP(), i.isUp())'
Ahmed El-Hassanyfd329182014-04-10 11:38:16 -0700442 cmd += ' for i in %s.intfs.values()])' % node
Jon Hall6094a362014-04-11 14:46:56 -0700443 try:
444 response = self.execute(cmd=cmd,prompt="mininet>",timeout=10)
445 except pexpect.EOF:
446 main.log.error(self.name + ": EOF exception found")
447 main.log.error(self.name + ": " + self.handle.before)
448 main.cleanup()
449 main.exit()
Ahmed El-Hassanyfd329182014-04-10 11:38:16 -0700450 return response
451 else:
452 main.log.error("Connection failed to the node")
453
adminbae64d82013-08-01 10:50:15 -0700454 def dump(self):
Jon Hallf2942ce2014-04-10 16:00:16 -0700455 main.log.info(self.name+": Dump node info")
Jon Hall6094a362014-04-11 14:46:56 -0700456 try:
457 response = self.execute(cmd = 'dump',prompt = 'mininet>',timeout = 10)
458 except pexpect.EOF:
459 main.log.error(self.name + ": EOF exception found")
460 main.log.error(self.name + ": " + self.handle.before)
461 main.cleanup()
462 main.exit()
Ahmed El-Hassanyd1f71702014-04-04 16:12:45 -0700463 return response
adminbae64d82013-08-01 10:50:15 -0700464
465 def intfs(self):
Jon Hallf2942ce2014-04-10 16:00:16 -0700466 main.log.info(self.name+": List interfaces")
Jon Hall6094a362014-04-11 14:46:56 -0700467 try:
468 response = self.execute(cmd = 'intfs',prompt = 'mininet>',timeout = 10)
469 except pexpect.EOF:
470 main.log.error(self.name + ": EOF exception found")
471 main.log.error(self.name + ": " + self.handle.before)
472 main.cleanup()
473 main.exit()
Jon Hall668ed802014-04-08 17:17:59 -0700474 return response
adminbae64d82013-08-01 10:50:15 -0700475
476 def net(self):
Jon Hallf2942ce2014-04-10 16:00:16 -0700477 main.log.info(self.name+": List network connections")
Jon Hall6094a362014-04-11 14:46:56 -0700478 try:
479 response = self.execute(cmd = 'net',prompt = 'mininet>',timeout = 10)
480 except pexpect.EOF:
481 main.log.error(self.name + ": EOF exception found")
482 main.log.error(self.name + ": " + self.handle.before)
483 main.cleanup()
484 main.exit()
Jon Hall668ed802014-04-08 17:17:59 -0700485 return response
shahshreyae6c7cf42014-11-26 16:39:01 -0800486 '''
487 def iperf(self,host1,host2):
Jon Hallf2942ce2014-04-10 16:00:16 -0700488 main.log.info(self.name+": Simple iperf TCP test between two (optionally specified) hosts")
Jon Hall6094a362014-04-11 14:46:56 -0700489 try:
shahshreyae6c7cf42014-11-26 16:39:01 -0800490 if not host1 and not host2:
491 response = self.execute(cmd = 'iperf',prompt = 'mininet>',timeout = 10)
492 else:
493 cmd1 = 'iperf '+ host1 + " " + host2
494 response = self.execute(cmd = cmd1, prompt = '>',timeout = 20)
Jon Hall6094a362014-04-11 14:46:56 -0700495 except pexpect.EOF:
496 main.log.error(self.name + ": EOF exception found")
497 main.log.error(self.name + ": " + self.handle.before)
498 main.cleanup()
499 main.exit()
Jon Hall668ed802014-04-08 17:17:59 -0700500 return response
shahshreyae6c7cf42014-11-26 16:39:01 -0800501 '''
502 def iperf(self,host1,host2):
503 main.log.info(self.name+": Simple iperf TCP test between two hosts")
504 try:
505 cmd1 = 'iperf '+ host1 + " " + host2
506 self.handle.sendline(cmd1)
507 self.handle.expect("mininet>")
508 response = self.handle.before
509 if re.search('Results:',response):
510 main.log.info(self.name+": iperf test succssful")
511 return main.TRUE
512 else:
513 main.log.error(self.name+": iperf test failed")
514 return main.FALSE
515 except pexpect.EOF:
516 main.log.error(self.name + ": EOF exception found")
517 main.log.error(self.name + ": " + self.handle.before)
518 main.cleanup()
519 main.exit()
adminbae64d82013-08-01 10:50:15 -0700520
521 def iperfudp(self):
Jon Hallf2942ce2014-04-10 16:00:16 -0700522 main.log.info(self.name+": Simple iperf TCP test between two (optionally specified) hosts")
Jon Hall6094a362014-04-11 14:46:56 -0700523 try:
524 response = self.execute(cmd = 'iperfudp',prompt = 'mininet>',timeout = 10)
525 except pexpect.EOF:
526 main.log.error(self.name + ": EOF exception found")
527 main.log.error(self.name + ": " + self.handle.before)
528 main.cleanup()
529 main.exit()
Jon Hall668ed802014-04-08 17:17:59 -0700530 return response
adminbae64d82013-08-01 10:50:15 -0700531
532 def nodes(self):
Jon Hallf2942ce2014-04-10 16:00:16 -0700533 main.log.info(self.name+": List all nodes.")
Jon Hall6094a362014-04-11 14:46:56 -0700534 try:
535 response = self.execute(cmd = 'nodes',prompt = 'mininet>',timeout = 10)
536 except pexpect.EOF:
537 main.log.error(self.name + ": EOF exception found")
538 main.log.error(self.name + ": " + self.handle.before)
539 main.cleanup()
540 main.exit()
Jon Hall668ed802014-04-08 17:17:59 -0700541 return response
adminbae64d82013-08-01 10:50:15 -0700542
543 def pingpair(self):
Jon Hallf2942ce2014-04-10 16:00:16 -0700544 main.log.info(self.name+": Ping between first two hosts")
Jon Hall6094a362014-04-11 14:46:56 -0700545 try:
546 response = self.execute(cmd = 'pingpair',prompt = 'mininet>',timeout = 20)
547 except pexpect.EOF:
548 main.log.error(self.name + ": EOF exception found")
549 main.log.error(self.name + ": " + self.handle.before)
550 main.cleanup()
551 main.exit()
adminbae64d82013-08-01 10:50:15 -0700552
Jon Hallf2942ce2014-04-10 16:00:16 -0700553 #if utilities.assert_matches(expect='0% packet loss',actual=response,onpass="No Packet loss",onfail="Hosts not reachable"):
554 if re.search(',\s0\%\spacket\sloss',response):
555 main.log.info(self.name+": Ping between two hosts SUCCESSFUL")
adminbae64d82013-08-01 10:50:15 -0700556 main.last_result = main.TRUE
557 return main.TRUE
558 else :
Jon Hallf2942ce2014-04-10 16:00:16 -0700559 main.log.error(self.name+": PACKET LOST, HOSTS NOT REACHABLE")
adminbae64d82013-08-01 10:50:15 -0700560 main.last_result = main.FALSE
561 return main.FALSE
562
563 def link(self,**linkargs):
564 '''
565 Bring link(s) between two nodes up or down
566 '''
adminbae64d82013-08-01 10:50:15 -0700567 args = utilities.parse_args(["END1","END2","OPTION"],**linkargs)
568 end1 = args["END1"] if args["END1"] != None else ""
569 end2 = args["END2"] if args["END2"] != None else ""
570 option = args["OPTION"] if args["OPTION"] != None else ""
Jon Hall38481722014-11-04 16:50:05 -0500571 main.log.info("Bring link between '"+ end1 +"' and '" + end2 + "' '" + option + "'")
adminbae64d82013-08-01 10:50:15 -0700572 command = "link "+str(end1) + " " + str(end2)+ " " + str(option)
Jon Hall6094a362014-04-11 14:46:56 -0700573 try:
Jon Halle80ef8c2014-04-29 15:29:13 -0700574 #response = self.execute(cmd=command,prompt="mininet>",timeout=10)
575 self.handle.sendline(command)
576 self.handle.expect("mininet>")
Jon Hall6094a362014-04-11 14:46:56 -0700577 except pexpect.EOF:
578 main.log.error(self.name + ": EOF exception found")
579 main.log.error(self.name + ": " + self.handle.before)
580 main.cleanup()
581 main.exit()
adminbae64d82013-08-01 10:50:15 -0700582 return main.TRUE
583
584
admin530b4c92013-08-14 16:54:35 -0700585 def yank(self,**yankargs):
adminaeedddd2013-08-02 15:14:15 -0700586 '''
admin530b4c92013-08-14 16:54:35 -0700587 yank a mininet switch interface to a host
adminaeedddd2013-08-02 15:14:15 -0700588 '''
admin530b4c92013-08-14 16:54:35 -0700589 main.log.info('Yank the switch interface attached to a host')
590 args = utilities.parse_args(["SW","INTF"],**yankargs)
adminaeedddd2013-08-02 15:14:15 -0700591 sw = args["SW"] if args["SW"] !=None else ""
592 intf = args["INTF"] if args["INTF"] != None else ""
593 command = "py "+ str(sw) + '.detach("' + str(intf) + '")'
Jon Hall6094a362014-04-11 14:46:56 -0700594 try:
595 response = self.execute(cmd=command,prompt="mininet>",timeout=10)
596 except pexpect.EOF:
597 main.log.error(self.name + ": EOF exception found")
598 main.log.error(self.name + ": " + self.handle.before)
599 main.cleanup()
600 main.exit()
adminaeedddd2013-08-02 15:14:15 -0700601 return main.TRUE
602
603 def plug(self, **plugargs):
604 '''
605 plug the yanked mininet switch interface to a switch
606 '''
607 main.log.info('Plug the switch interface attached to a switch')
admin530b4c92013-08-14 16:54:35 -0700608 args = utilities.parse_args(["SW","INTF"],**plugargs)
adminaeedddd2013-08-02 15:14:15 -0700609 sw = args["SW"] if args["SW"] !=None else ""
610 intf = args["INTF"] if args["INTF"] != None else ""
611 command = "py "+ str(sw) + '.attach("' + str(intf) + '")'
Jon Hall6094a362014-04-11 14:46:56 -0700612 try:
613 response = self.execute(cmd=command,prompt="mininet>",timeout=10)
614 except pexpect.EOF:
615 main.log.error(self.name + ": EOF exception found")
616 main.log.error(self.name + ": " + self.handle.before)
617 main.cleanup()
618 main.exit()
adminaeedddd2013-08-02 15:14:15 -0700619 return main.TRUE
620
621
622
adminbae64d82013-08-01 10:50:15 -0700623 def dpctl(self,**dpctlargs):
624 '''
Jon Hall41f40e82014-04-08 16:43:17 -0700625 Run dpctl command on all switches.
adminbae64d82013-08-01 10:50:15 -0700626 '''
627 main.log.info('Run dpctl command on all switches')
628 args = utilities.parse_args(["CMD","ARGS"],**dpctlargs)
629 cmd = args["CMD"] if args["CMD"] != None else ""
630 cmdargs = args["ARGS"] if args["ARGS"] != None else ""
631 command = "dpctl "+cmd + " " + str(cmdargs)
Jon Hall6094a362014-04-11 14:46:56 -0700632 try:
633 response = self.execute(cmd=command,prompt="mininet>",timeout=10)
634 except pexpect.EOF:
635 main.log.error(self.name + ": EOF exception found")
636 main.log.error(self.name + ": " + self.handle.before)
637 main.cleanup()
638 main.exit()
adminbae64d82013-08-01 10:50:15 -0700639 return main.TRUE
640
641
642 def get_version(self):
643 file_input = path+'/lib/Mininet/INSTALL'
644 version = super(Mininet, self).get_version()
645 pattern = 'Mininet\s\w\.\w\.\w\w*'
646 for line in open(file_input,'r').readlines():
647 result = re.match(pattern, line)
648 if result:
649 version = result.group(0)
Jon Hallec3c21e2014-11-10 22:22:37 -0500650 return version
adminbae64d82013-08-01 10:50:15 -0700651
Jon Hallec3c21e2014-11-10 22:22:37 -0500652 def get_sw_controller(self, sw):
653 '''
654 Parameters:
655 sw: The name of an OVS switch. Example "s1"
656 Return:
657 The output of the command from the mininet cli or main.FALSE on timeout
658 '''
admin2a9548d2014-06-17 14:08:07 -0700659 command = "sh ovs-vsctl get-controller "+str(sw)
660 try:
Jon Hallec3c21e2014-11-10 22:22:37 -0500661 response = self.execute(cmd=command, prompt="mininet>", timeout=10)
admin2a9548d2014-06-17 14:08:07 -0700662 if response:
Jon Hallec3c21e2014-11-10 22:22:37 -0500663 return response
admin2a9548d2014-06-17 14:08:07 -0700664 else:
665 return main.FALSE
666 except pexpect.EOF:
667 main.log.error(self.name + ": EOF exception found")
668 main.log.error(self.name + ": " + self.handle.before)
669 main.cleanup()
670 main.exit()
adminbae64d82013-08-01 10:50:15 -0700671
672 def assign_sw_controller(self,**kwargs):
Jon Hallf89c8552014-04-02 13:14:06 -0700673 '''
674 count is only needed if there is more than 1 controller
675 '''
676 args = utilities.parse_args(["COUNT"],**kwargs)
677 count = args["COUNT"] if args!={} else 1
678
679 argstring = "SW"
680 for j in range(count):
681 argstring = argstring + ",IP" + str(j+1) + ",PORT" + str(j+1)
682 args = utilities.parse_args(argstring.split(","),**kwargs)
683
adminbae64d82013-08-01 10:50:15 -0700684 sw = args["SW"] if args["SW"] != None else ""
admin530b4c92013-08-14 16:54:35 -0700685 ptcpA = int(args["PORT1"])+int(sw) if args["PORT1"] != None else ""
Jon Hallf89c8552014-04-02 13:14:06 -0700686 ptcpB = "ptcp:"+str(ptcpA) if ptcpA != "" else ""
687
688 command = "sh ovs-vsctl set-controller s" + str(sw) + " " + ptcpB + " "
689 for j in range(count):
690 i=j+1
691 args = utilities.parse_args(["IP"+str(i),"PORT"+str(i)],**kwargs)
692 ip = args["IP"+str(i)] if args["IP"+str(i)] != None else ""
693 port = args["PORT" + str(i)] if args["PORT" + str(i)] != None else ""
694 tcp = "tcp:" + str(ip) + ":" + str(port) + " " if ip != "" else ""
695 command = command + tcp
Jon Hall6094a362014-04-11 14:46:56 -0700696 try:
697 self.execute(cmd=command,prompt="mininet>",timeout=5)
698 except pexpect.EOF:
699 main.log.error(self.name + ": EOF exception found")
700 main.log.error(self.name + ": " + self.handle.before)
701 main.cleanup()
702 main.exit()
703 except:
704 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
705 main.log.error( traceback.print_exc() )
706 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
707 main.cleanup()
708 main.exit()
adminbae64d82013-08-01 10:50:15 -0700709
Jon Hall0819fd92014-05-23 12:08:13 -0700710 def delete_sw_controller(self,sw):
711 '''
712 Removes the controller target from sw
713 '''
714
715 command = "sh ovs-vsctl del-controller "+str(sw)
716 try:
717 response = self.execute(cmd=command,prompt="mininet>",timeout=10)
718 except pexpect.EOF:
719 main.log.error(self.name + ": EOF exception found")
720 main.log.error(self.name + ": " + self.handle.before)
721 main.cleanup()
722 main.exit()
723 else:
724 main.log.info(response)
725
Jon Hallb1290e82014-11-18 16:17:48 -0500726 def add_switch( self, sw, **kwargs ):
727 '''
728 adds a switch to the mininet topology
729 NOTE: this uses a custom mn function
730 NOTE: cannot currently specify what type of switch
731 required params:
732 switchname = name of the new switch as a string
733 optional keyvalues:
734 dpid = "dpid"
735 returns: main.FASLE on an error, else main.TRUE
736 '''
737 dpid = kwargs.get('dpid', '')
Jon Hallffb386d2014-11-21 13:43:38 -0800738 command = "addswitch " + str( sw ) + " " + str( dpid )
Jon Hallb1290e82014-11-18 16:17:48 -0500739 try:
740 response = self.execute(cmd=command,prompt="mininet>",timeout=10)
741 if re.search("already exists!", response):
742 main.log.warn(response)
743 return main.FALSE
744 elif re.search("Error", response):
745 main.log.warn(response)
746 return main.FALSE
747 elif re.search("usage:", response):
748 main.log.warn(response)
749 return main.FALSE
750 else:
751 return main.TRUE
752 except pexpect.EOF:
753 main.log.error(self.name + ": EOF exception found")
754 main.log.error(self.name + ": " + self.handle.before)
755 main.cleanup()
756 main.exit()
757
758 def del_switch( self, sw ):
759 '''
760 delete a switch from the mininet topology
761 NOTE: this uses a custom mn function
762 required params:
763 switchname = name of the switch as a string
764 returns: main.FASLE on an error, else main.TRUE
765 '''
Jon Hallffb386d2014-11-21 13:43:38 -0800766 command = "delswitch " + str( sw )
Jon Hallb1290e82014-11-18 16:17:48 -0500767 try:
768 response = self.execute(cmd=command,prompt="mininet>",timeout=10)
769 if re.search("no switch named", response):
770 main.log.warn(response)
771 return main.FALSE
772 elif re.search("Error", response):
773 main.log.warn(response)
774 return main.FALSE
775 elif re.search("usage:", response):
776 main.log.warn(response)
777 return main.FALSE
778 else:
779 return main.TRUE
780 except pexpect.EOF:
781 main.log.error(self.name + ": EOF exception found")
782 main.log.error(self.name + ": " + self.handle.before)
783 main.cleanup()
784 main.exit()
785
786 def add_link( self, node1, node2 ):
787 '''
788 add a link to the mininet topology
789 NOTE: this uses a custom mn function
790 NOTE: cannot currently specify what type of link
791 required params:
792 node1 = the string node name of the first endpoint of the link
793 node2 = the string node name of the second endpoint of the link
794 returns: main.FASLE on an error, else main.TRUE
795 '''
Jon Hallffb386d2014-11-21 13:43:38 -0800796 command = "addlink " + str( node1 ) + " " + str( node2 )
Jon Hallb1290e82014-11-18 16:17:48 -0500797 try:
798 response = self.execute(cmd=command,prompt="mininet>",timeout=10)
799 if re.search("doesnt exist!", response):
800 main.log.warn(response)
801 return main.FALSE
802 elif re.search("Error", response):
803 main.log.warn(response)
804 return main.FALSE
805 elif re.search("usage:", response):
806 main.log.warn(response)
807 return main.FALSE
808 else:
809 return main.TRUE
810 except pexpect.EOF:
811 main.log.error(self.name + ": EOF exception found")
812 main.log.error(self.name + ": " + self.handle.before)
813 main.cleanup()
814 main.exit()
815
816 def del_link( self, node1, node2 ):
817 '''
818 delete a link from the mininet topology
819 NOTE: this uses a custom mn function
820 required params:
821 node1 = the string node name of the first endpoint of the link
822 node2 = the string node name of the second endpoint of the link
823 returns: main.FASLE on an error, else main.TRUE
824 '''
Jon Hallffb386d2014-11-21 13:43:38 -0800825 command = "dellink " + str( node1 ) + " " + str( node2 )
Jon Hallb1290e82014-11-18 16:17:48 -0500826 try:
827 response = self.execute(cmd=command,prompt="mininet>",timeout=10)
828 if re.search("no node named", response):
829 main.log.warn(response)
830 return main.FALSE
831 elif re.search("Error", response):
832 main.log.warn(response)
833 return main.FALSE
834 elif re.search("usage:", response):
835 main.log.warn(response)
836 return main.FALSE
837 else:
838 return main.TRUE
839 except pexpect.EOF:
840 main.log.error(self.name + ": EOF exception found")
841 main.log.error(self.name + ": " + self.handle.before)
842 main.cleanup()
843 main.exit()
844
845 def add_host( self, hostname, **kwargs ):
846 '''
847 Add a host to the mininet topology
848 NOTE: this uses a custom mn function
849 NOTE: cannot currently specify what type of host
850 required params:
851 hostname = the string hostname
852 optional key-value params
853 switch = "switch name"
854 returns: main.FASLE on an error, else main.TRUE
855 '''
856 switch = kwargs.get('switch', '')
Jon Hallffb386d2014-11-21 13:43:38 -0800857 command = "addhost " + str( hostname ) + " " + str( switch )
Jon Hallb1290e82014-11-18 16:17:48 -0500858 try:
859 response = self.execute(cmd=command,prompt="mininet>",timeout=10)
860 if re.search("already exists!", response):
861 main.log.warn(response)
862 return main.FALSE
863 elif re.search("doesnt exists!", response):
864 main.log.warn(response)
865 return main.FALSE
866 elif re.search("Error", response):
867 main.log.warn(response)
868 return main.FALSE
869 elif re.search("usage:", response):
870 main.log.warn(response)
871 return main.FALSE
872 else:
873 return main.TRUE
874 except pexpect.EOF:
875 main.log.error(self.name + ": EOF exception found")
876 main.log.error(self.name + ": " + self.handle.before)
877 main.cleanup()
878 main.exit()
879
880 def del_host( self, hostname ):
881 '''
882 delete a host from the mininet topology
883 NOTE: this uses a custom mn function
884 required params:
885 hostname = the string hostname
886 returns: main.FASLE on an error, else main.TRUE
887 '''
Jon Hallffb386d2014-11-21 13:43:38 -0800888 command = "delhost " + str( hostname )
Jon Hallb1290e82014-11-18 16:17:48 -0500889 try:
890 response = self.execute(cmd=command,prompt="mininet>",timeout=10)
891 if re.search("no host named", response):
892 main.log.warn(response)
893 return main.FALSE
894 elif re.search("Error", response):
895 main.log.warn(response)
896 return main.FALSE
897 elif re.search("usage:", response):
898 main.log.warn(response)
899 return main.FALSE
900 else:
901 return main.TRUE
902 except pexpect.EOF:
903 main.log.error(self.name + ": EOF exception found")
904 main.log.error(self.name + ": " + self.handle.before)
905 main.cleanup()
906 main.exit()
Jon Hall0819fd92014-05-23 12:08:13 -0700907
adminbae64d82013-08-01 10:50:15 -0700908 def disconnect(self):
Jon Hallf2942ce2014-04-10 16:00:16 -0700909 main.log.info(self.name+": Disconnecting mininet...")
adminbae64d82013-08-01 10:50:15 -0700910 response = ''
911 if self.handle:
Jon Hall6094a362014-04-11 14:46:56 -0700912 try:
913 response = self.execute(cmd="exit",prompt="(.*)",timeout=120)
914 response = self.execute(cmd="exit",prompt="(.*)",timeout=120)
Jon Halle80ef8c2014-04-29 15:29:13 -0700915 self.handle.sendline("sudo mn -c")
shahshreya328c2a72014-11-17 10:19:50 -0800916 response = main.TRUE
Jon Hall6094a362014-04-11 14:46:56 -0700917 except pexpect.EOF:
918 main.log.error(self.name + ": EOF exception found")
919 main.log.error(self.name + ": " + self.handle.before)
920 main.cleanup()
921 main.exit()
adminbae64d82013-08-01 10:50:15 -0700922 else :
Jon Hallf2942ce2014-04-10 16:00:16 -0700923 main.log.error(self.name+": Connection failed to the host")
adminbae64d82013-08-01 10:50:15 -0700924 response = main.FALSE
925 return response
admin07529932013-11-22 14:58:28 -0800926
927 def arping(self, src, dest, destmac):
928 self.handle.sendline('')
Jon Hall333fa8c2014-04-11 11:24:58 -0700929 self.handle.expect(["mininet",pexpect.EOF,pexpect.TIMEOUT])
admin07529932013-11-22 14:58:28 -0800930
931 self.handle.sendline(src + ' arping ' + dest)
932 try:
Jon Hall333fa8c2014-04-11 11:24:58 -0700933 self.handle.expect([destmac,pexpect.EOF,pexpect.TIMEOUT])
Jon Hallf2942ce2014-04-10 16:00:16 -0700934 main.log.info(self.name+": ARP successful")
Jon Hall333fa8c2014-04-11 11:24:58 -0700935 self.handle.expect(["mininet",pexpect.EOF,pexpect.TIMEOUT])
admin07529932013-11-22 14:58:28 -0800936 return main.TRUE
937 except:
Jon Hallf2942ce2014-04-10 16:00:16 -0700938 main.log.warn(self.name+": ARP FAILURE")
Jon Hall333fa8c2014-04-11 11:24:58 -0700939 self.handle.expect(["mininet",pexpect.EOF,pexpect.TIMEOUT])
admin07529932013-11-22 14:58:28 -0800940 return main.FALSE
941
942 def decToHex(num):
943 return hex(num).split('x')[1]
admin2a9548d2014-06-17 14:08:07 -0700944
945 def getSwitchFlowCount(self, switch):
946 '''
947 return the Flow Count of the switch
948 '''
949 if self.handle:
950 cmd = "sh ovs-ofctl dump-aggregate %s" % switch
951 try:
952 response = self.execute(cmd=cmd, prompt="mininet>", timeout=10)
953 except pexpect.EOF:
954 main.log.error(self.name + ": EOF exception found")
955 main.log.error(self.name + " " + self.handle.before)
956 main.cleanup()
957 main.exit()
958 pattern = "flow_count=(\d+)"
959 result = re.search(pattern, response, re.MULTILINE)
960 if result is None:
admin2a9548d2014-06-17 14:08:07 -0700961 main.log.info("Couldn't find flows on switch '', found: %s" % (switch, response))
962 return main.FALSE
963 return result.group(1)
964 else:
965 main.log.error("Connection failed to the Mininet host")
966
Ahmed El-Hassanyb6545eb2014-08-01 11:32:10 -0700967 def check_flows(self, sw, dump_format=None):
968 if dump_format:
969 command = "sh ovs-ofctl -F " + dump_format + " dump-flows " + str(sw)
970 else:
971 command = "sh ovs-ofctl dump-flows "+str(sw)
admin2a9548d2014-06-17 14:08:07 -0700972 try:
973 response=self.execute(cmd=command,prompt="mininet>",timeout=10)
974 return response
975 except pexpect.EOF:
976 main.log.error(self.name + ": EOF exception found")
977 main.log.error(self.name + ": " + self.handle.before)
978 main.cleanup()
979 main.exit()
980 else:
981 main.log.info(response)
982
983 def start_tcpdump(self, filename, intf = "eth0", port = "port 6633"):
984 '''
985 Runs tpdump on an intferface and saves the file
986 intf can be specified, or the default eth0 is used
987 '''
988 try:
989 self.handle.sendline("")
990 self.handle.expect("mininet>")
991 self.handle.sendline("sh sudo tcpdump -n -i "+ intf + " " + port + " -w " + filename.strip() + " &")
992 self.handle.sendline("")
admin2a9548d2014-06-17 14:08:07 -0700993 i=self.handle.expect(['No\ssuch\device','listening\son',pexpect.TIMEOUT,"mininet>"],timeout=10)
994 main.log.warn(self.handle.before + self.handle.after)
Jon Hallb1290e82014-11-18 16:17:48 -0500995 self.handle.sendline("")
996 self.handle.expect("mininet>")
admin2a9548d2014-06-17 14:08:07 -0700997 if i == 0:
998 main.log.error(self.name + ": tcpdump - No such device exists. tcpdump attempted on: " + intf)
999 return main.FALSE
1000 elif i == 1:
1001 main.log.info(self.name + ": tcpdump started on " + intf)
1002 return main.TRUE
1003 elif i == 2:
1004 main.log.error(self.name + ": tcpdump command timed out! Check interface name, given interface was: " + intf)
1005 return main.FALSE
1006 elif i ==3:
1007 main.log.info(self.name +": " + self.handle.before)
1008 return main.TRUE
1009 else:
1010 main.log.error(self.name + ": tcpdump - unexpected response")
1011 return main.FALSE
1012 except pexpect.EOF:
1013 main.log.error(self.name + ": EOF exception found")
1014 main.log.error(self.name + ": " + self.handle.before)
1015 main.cleanup()
1016 main.exit()
1017 except:
1018 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1019 main.log.error( traceback.print_exc() )
1020 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1021 main.cleanup()
1022 main.exit()
1023
1024 def stop_tcpdump(self):
1025 "pkills tcpdump"
1026 try:
1027 self.handle.sendline("sh sudo pkill tcpdump")
Jon Hallb1290e82014-11-18 16:17:48 -05001028 self.handle.expect("mininet>")
admin2a9548d2014-06-17 14:08:07 -07001029 self.handle.sendline("")
1030 self.handle.expect("mininet>")
1031 except pexpect.EOF:
1032 main.log.error(self.name + ": EOF exception found")
1033 main.log.error(self.name + ": " + self.handle.before)
1034 main.cleanup()
1035 main.exit()
1036 except:
1037 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1038 main.log.error( traceback.print_exc() )
1039 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1040 main.cleanup()
1041 main.exit()
1042
Jon Hall3d87d502014-10-17 18:37:42 -04001043 def compare_switches(self, topo, switches_json):
1044 '''
1045 Compare mn and onos switches
1046 topo: sts TestONTopology object
1047 switches_json: parsed json object from the onos devices api
1048
1049 This uses the sts TestONTopology object
1050
1051 '''
1052 import json
Jon Hall42db6dc2014-10-24 19:03:48 -04001053 #main.log.debug("Switches_json string: ", switches_json)
Jon Hall3d87d502014-10-17 18:37:42 -04001054 output = {"switches":[]}
1055 for switch in topo.graph.switches: #iterate through the MN topology and pull out switches and and port info
Jon Hall3d87d502014-10-17 18:37:42 -04001056 ports = []
1057 for port in switch.ports.values():
Jon Hall3d87d502014-10-17 18:37:42 -04001058 ports.append({'of_port': port.port_no, 'mac': str(port.hw_addr).replace('\'',''), 'name': port.name})
1059 output['switches'].append({"name": switch.name, "dpid": str(switch.dpid).zfill(16), "ports": ports })
Jon Hall3d87d502014-10-17 18:37:42 -04001060
Jon Hall42db6dc2014-10-24 19:03:48 -04001061 #print "mn"
Jon Hall3d87d502014-10-17 18:37:42 -04001062 #print json.dumps(output, sort_keys=True,indent=4,separators=(',', ': '))
Jon Hall42db6dc2014-10-24 19:03:48 -04001063 #print "onos"
1064 #print json.dumps(switches_json, sort_keys=True,indent=4,separators=(',', ': '))
Jon Hall3d87d502014-10-17 18:37:42 -04001065
1066
1067 # created sorted list of dpid's in MN and ONOS for comparison
1068 mnDPIDs=[]
1069 for switch in output['switches']:
1070 mnDPIDs.append(switch['dpid'])
1071 mnDPIDs.sort()
Jon Hall38481722014-11-04 16:50:05 -05001072 #print "List of Mininet switch DPID's"
Jon Hall3d87d502014-10-17 18:37:42 -04001073 #print mnDPIDs
1074 if switches_json == "":#if rest call fails
Jon Hall42db6dc2014-10-24 19:03:48 -04001075 main.log.error(self.name + ".compare_switches(): Empty JSON object given from ONOS")
Jon Hall3d87d502014-10-17 18:37:42 -04001076 return main.FALSE
1077 onos=switches_json
1078 onosDPIDs=[]
1079 for switch in onos:
Jon Hall38481722014-11-04 16:50:05 -05001080 if switch['available'] == True:
1081 onosDPIDs.append(switch['id'].replace(":",'').replace("of",''))
1082 #else:
1083 #print "Switch is unavailable:"
1084 #print switch
Jon Hall3d87d502014-10-17 18:37:42 -04001085 onosDPIDs.sort()
Jon Hall38481722014-11-04 16:50:05 -05001086 #print "List of ONOS switch DPID's"
Jon Hall3d87d502014-10-17 18:37:42 -04001087 #print onosDPIDs
1088
1089 if mnDPIDs!=onosDPIDs:
1090 switch_results = main.FALSE
1091 main.log.report( "Switches in MN but not in ONOS:")
1092 main.log.report( str([switch for switch in mnDPIDs if switch not in onosDPIDs]))
1093 main.log.report( "Switches in ONOS but not in MN:")
1094 main.log.report( str([switch for switch in onosDPIDs if switch not in mnDPIDs]))
1095 else:#list of dpid's match in onos and mn
1096 #main.log.report("DEBUG: The dpid's of the switches in Mininet and ONOS match")
1097 switch_results = main.TRUE
1098 return switch_results
1099
1100
1101
Jon Hall72cf1dc2014-10-20 21:04:50 -04001102 def compare_ports(self, topo, ports_json):
1103 '''
1104 Compare mn and onos ports
1105 topo: sts TestONTopology object
1106 ports_json: parsed json object from the onos ports api
1107
1108 Dependencies:
1109 1. This uses the sts TestONTopology object
1110 2. numpy - "sudo pip install numpy"
1111
1112 '''
Jon Hall1c9e8732014-10-27 19:29:27 -04001113 #FIXME: this does not look for extra ports in ONOS, only checks that ONOS has what is in MN
Jon Hall72cf1dc2014-10-20 21:04:50 -04001114 import json
1115 from numpy import uint64
Jon Hallb1290e82014-11-18 16:17:48 -05001116 ports_results = main.TRUE
Jon Hall72cf1dc2014-10-20 21:04:50 -04001117 output = {"switches":[]}
1118 for switch in topo.graph.switches: #iterate through the MN topology and pull out switches and and port info
Jon Hall72cf1dc2014-10-20 21:04:50 -04001119 ports = []
1120 for port in switch.ports.values():
1121 #print port.hw_addr.toStr(separator = '')
Jon Hall39f29df2014-11-04 19:30:21 -05001122 tmp_port = {}
1123 tmp_port['of_port'] = port.port_no
1124 tmp_port['mac'] = str(port.hw_addr).replace('\'','')
1125 tmp_port['name'] = port.name
1126 tmp_port['enabled'] = port.enabled
1127
1128 ports.append(tmp_port)
1129 tmp_switch = {}
1130 tmp_switch['name'] = switch.name
1131 tmp_switch['dpid'] = str(switch.dpid).zfill(16)
1132 tmp_switch['ports'] = ports
1133
1134 output['switches'].append(tmp_switch)
Jon Hall72cf1dc2014-10-20 21:04:50 -04001135
1136
1137 ################ports#############
Jon Hall39f29df2014-11-04 19:30:21 -05001138 for mn_switch in output['switches']:
Jon Hall72cf1dc2014-10-20 21:04:50 -04001139 mn_ports = []
1140 onos_ports = []
Jon Hallb1290e82014-11-18 16:17:48 -05001141 switch_result = main.TRUE
Jon Hall39f29df2014-11-04 19:30:21 -05001142 for port in mn_switch['ports']:
Jon Hall38481722014-11-04 16:50:05 -05001143 if port['enabled'] == True:
1144 mn_ports.append(port['of_port'])
Jon Hallb1290e82014-11-18 16:17:48 -05001145 #else: #DEBUG only
1146 # main.log.warn("Port %s on switch %s is down" % ( str(port['of_port']) , str(mn_switch['name'])) )
Jon Hall72cf1dc2014-10-20 21:04:50 -04001147 for onos_switch in ports_json:
Jon Hall38481722014-11-04 16:50:05 -05001148 #print "Iterating through a new switch as seen by ONOS"
1149 #print onos_switch
1150 if onos_switch['device']['available'] == True:
Jon Hall39f29df2014-11-04 19:30:21 -05001151 if onos_switch['device']['id'].replace(':','').replace("of", '') == mn_switch['dpid']:
Jon Hall38481722014-11-04 16:50:05 -05001152 for port in onos_switch['ports']:
1153 if port['isEnabled']:
1154 #print "Iterating through available ports on the switch"
1155 #print port
Jon Hallb1290e82014-11-18 16:17:48 -05001156 if port['port'] == 'local':
1157 #onos_ports.append('local')
1158 onos_ports.append(long(uint64(-2)))
1159 else:
1160 onos_ports.append(int(port['port']))
1161 '''
1162 else: #This is likely a new reserved port implemented
1163 main.log.error("unkown port '" + str(port['port']) )
1164 '''
Jon Hall1645caa2014-11-18 16:27:14 -05001165 #else: #DEBUG
1166 # main.log.warn("Port %s on switch %s is down" % ( str(port['port']) , str(onos_switch['device']['id'])) )
Jon Hallb1290e82014-11-18 16:17:48 -05001167 break
Jon Hall72cf1dc2014-10-20 21:04:50 -04001168 mn_ports.sort(key=float)
1169 onos_ports.sort(key=float)
1170 #print "\nPorts for Switch %s:" % (switch['name'])
1171 #print "\tmn_ports[] = ", mn_ports
1172 #print "\tonos_ports[] = ", onos_ports
Jon Hallb1290e82014-11-18 16:17:48 -05001173 mn_ports_log = mn_ports
1174 onos_ports_log = onos_ports
1175 mn_ports = [x for x in mn_ports]
1176 onos_ports = [x for x in onos_ports]
Jon Hall38481722014-11-04 16:50:05 -05001177
Jon Hall72cf1dc2014-10-20 21:04:50 -04001178 #TODO: handle other reserved port numbers besides LOCAL
Jon Hallb1290e82014-11-18 16:17:48 -05001179 #NOTE: Reserved ports
1180 # Local port: -2 in Openflow, ONOS shows 'local', we store as long(uint64(-2))
1181 for mn_port in mn_ports_log:
1182 if mn_port in onos_ports:
Jon Hall72cf1dc2014-10-20 21:04:50 -04001183 #don't set results to true here as this is just one of many checks and it might override a failure
Jon Hallb1290e82014-11-18 16:17:48 -05001184 mn_ports.remove(mn_port)
1185 onos_ports.remove(mn_port)
1186 #NOTE: OVS reports this as down since there is no link
1187 # So ignoring these for now
1188 #TODO: Come up with a better way of handling these
1189 if 65534 in mn_ports:
1190 mn_ports.remove(65534)
1191 if long(uint64(-2)) in onos_ports:
1192 onos_ports.remove( long(uint64(-2)) )
1193 if len(mn_ports): #the ports of this switch don't match
1194 switch_result = main.FALSE
1195 main.log.warn("Ports in MN but not ONOS: " + str(mn_ports) )
1196 if len(onos_ports): #the ports of this switch don't match
1197 switch_result = main.FALSE
1198 main.log.warn("Ports in ONOS but not MN: " + str(onos_ports) )
1199 if switch_result == main.FALSE:
Jon Hall39f29df2014-11-04 19:30:21 -05001200 main.log.report("The list of ports for switch %s(%s) does not match:" % (mn_switch['name'], mn_switch['dpid']) )
Jon Hallb1290e82014-11-18 16:17:48 -05001201 main.log.warn("mn_ports[] = " + str(mn_ports_log))
1202 main.log.warn("onos_ports[] = " + str(onos_ports_log))
1203 ports_results = ports_results and switch_result
1204 return ports_results
Jon Hall72cf1dc2014-10-20 21:04:50 -04001205
1206
1207
1208
1209 def compare_links(self, topo, links_json):
1210 '''
1211 Compare mn and onos links
1212 topo: sts TestONTopology object
1213 links_json: parsed json object from the onos links api
1214
1215 This uses the sts TestONTopology object
1216
1217 '''
Jon Hall1c9e8732014-10-27 19:29:27 -04001218 #FIXME: this does not look for extra links in ONOS, only checks that ONOS has what is in MN
Jon Hall72cf1dc2014-10-20 21:04:50 -04001219 import json
1220 link_results = main.TRUE
1221 output = {"switches":[]}
1222 onos = links_json
1223 for switch in topo.graph.switches: #iterate through the MN topology and pull out switches and and port info
Jon Hall38481722014-11-04 16:50:05 -05001224 # print "Iterating though switches as seen by Mininet"
1225 # print switch
Jon Hall72cf1dc2014-10-20 21:04:50 -04001226 ports = []
1227 for port in switch.ports.values():
1228 #print port.hw_addr.toStr(separator = '')
1229 ports.append({'of_port': port.port_no, 'mac': str(port.hw_addr).replace('\'',''), 'name': port.name})
1230 output['switches'].append({"name": switch.name, "dpid": str(switch.dpid).zfill(16), "ports": ports })
1231 #######Links########
1232
Jon Hall38481722014-11-04 16:50:05 -05001233 mn_links = [link for link in topo.patch_panel.network_links if (link.port1.enabled and link.port2.enabled)]
1234 #print "mn_links:"
1235 #print mn_links
1236 if 2*len(mn_links) == len(onos):
Jon Hall72cf1dc2014-10-20 21:04:50 -04001237 link_results = main.TRUE
1238 else:
1239 link_results = main.FALSE
Jon Hall38481722014-11-04 16:50:05 -05001240 main.log.report("Mininet has %i bidirectional links and ONOS has %i unidirectional links" % (len(mn_links), len(onos) ))
Jon Hall72cf1dc2014-10-20 21:04:50 -04001241
1242
1243 # iterate through MN links and check if an ONOS link exists in both directions
1244 # NOTE: Will currently only show mn links as down if they are cut through STS.
1245 # We can either do everything through STS or wait for up_network_links
1246 # and down_network_links to be fully implemented.
Jon Hall38481722014-11-04 16:50:05 -05001247 for link in mn_links:
Jon Hall72cf1dc2014-10-20 21:04:50 -04001248 #print "Link: %s" % link
1249 #TODO: Find a more efficient search method
1250 node1 = None
1251 port1 = None
1252 node2 = None
1253 port2 = None
1254 first_dir = main.FALSE
1255 second_dir = main.FALSE
1256 for switch in output['switches']:
1257 #print "Switch: %s" % switch['name']
1258 if switch['name'] == link.node1.name:
1259 node1 = switch['dpid']
1260 for port in switch['ports']:
1261 if str(port['name']) == str(link.port1):
1262 port1 = port['of_port']
1263 if node1 is not None and node2 is not None:
1264 break
1265 if switch['name'] == link.node2.name:
1266 node2 = switch['dpid']
1267 for port in switch['ports']:
1268 if str(port['name']) == str(link.port2):
1269 port2 = port['of_port']
1270 if node1 is not None and node2 is not None:
1271 break
1272
1273
1274 for onos_link in onos:
1275 onos_node1 = onos_link['src']['device'].replace(":",'').replace("of", '')
1276 onos_node2 = onos_link['dst']['device'].replace(":",'').replace("of", '')
1277 onos_port1 = onos_link['src']['port']
1278 onos_port2 = onos_link['dst']['port']
1279
1280 #print "Checking ONOS for link %s/%s -> %s/%s and" % (node1, port1, node2, port2)
1281 #print "Checking ONOS for link %s/%s -> %s/%s" % (node2, port2, node1, port1)
1282 # check onos link from node1 to node2
1283 if str(onos_node1) == str(node1) and str(onos_node2) == str(node2):
1284 if int(onos_port1) == int(port1) and int(onos_port2) == int(port2):
1285 first_dir = main.TRUE
1286 else:
Jon Hallb1290e82014-11-18 16:17:48 -05001287 main.log.warn('The port numbers do not match for ' +str(link) +\
Jon Hall72cf1dc2014-10-20 21:04:50 -04001288 ' between ONOS and MN. When cheking ONOS for link '+\
1289 '%s/%s -> %s/%s' % (node1, port1, node2, port2)+\
1290 ' ONOS has the values %s/%s -> %s/%s' %\
1291 (onos_node1, onos_port1, onos_node2, onos_port2))
1292
1293 # check onos link from node2 to node1
1294 elif ( str(onos_node1) == str(node2) and str(onos_node2) == str(node1) ):
1295 if ( int(onos_port1) == int(port2) and int(onos_port2) == int(port1) ):
1296 second_dir = main.TRUE
1297 else:
Jon Hallb1290e82014-11-18 16:17:48 -05001298 main.log.warn('The port numbers do not match for ' +str(link) +\
Jon Hall72cf1dc2014-10-20 21:04:50 -04001299 ' between ONOS and MN. When cheking ONOS for link '+\
1300 '%s/%s -> %s/%s' % (node2, port2, node1, port1)+\
1301 ' ONOS has the values %s/%s -> %s/%s' %\
1302 (onos_node2, onos_port2, onos_node1, onos_port1))
1303 else:#this is not the link you're looking for
1304 pass
1305 if not first_dir:
1306 main.log.report('ONOS does not have the link %s/%s -> %s/%s' % (node1, port1, node2, port2))
1307 if not second_dir:
1308 main.log.report('ONOS does not have the link %s/%s -> %s/%s' % (node2, port2, node1, port1))
1309 link_results = link_results and first_dir and second_dir
Jon Hall62df9242014-10-22 12:20:17 -04001310 return link_results
Jon Hall72cf1dc2014-10-20 21:04:50 -04001311
1312
andrewonlab3f0a4af2014-10-17 12:25:14 -04001313 def get_hosts(self):
1314 '''
1315 Returns a list of all hosts
1316 Don't ask questions just use it
1317 '''
1318 self.handle.sendline("")
1319 self.handle.expect("mininet>")
1320
1321 self.handle.sendline("py [ host.name for host in net.hosts ]")
1322 self.handle.expect("mininet>")
admin2a9548d2014-06-17 14:08:07 -07001323
andrewonlab3f0a4af2014-10-17 12:25:14 -04001324 handle_py = self.handle.before
1325 handle_py = handle_py.split("]\r\n",1)[1]
1326 handle_py = handle_py.rstrip()
admin2a9548d2014-06-17 14:08:07 -07001327
andrewonlab3f0a4af2014-10-17 12:25:14 -04001328 self.handle.sendline("")
1329 self.handle.expect("mininet>")
admin2a9548d2014-06-17 14:08:07 -07001330
andrewonlab3f0a4af2014-10-17 12:25:14 -04001331 host_str = handle_py.replace("]", "")
1332 host_str = host_str.replace("'", "")
1333 host_str = host_str.replace("[", "")
1334 host_list = host_str.split(",")
1335
1336 return host_list
adminbae64d82013-08-01 10:50:15 -07001337
Jon Hall38481722014-11-04 16:50:05 -05001338
1339 def update(self):
1340 '''
1341 updates the port address and status information for each port in mn
1342 '''
1343 #TODO: Add error checking. currently the mininet command has no output
1344 main.log.info("Updateing MN port information")
Jon Hallb1290e82014-11-18 16:17:48 -05001345 try:
1346 self.handle.sendline("")
1347 self.handle.expect("mininet>")
Jon Hall38481722014-11-04 16:50:05 -05001348
Jon Hallb1290e82014-11-18 16:17:48 -05001349 self.handle.sendline("update")
1350 self.handle.expect("update")
1351 self.handle.expect("mininet>")
Jon Hall38481722014-11-04 16:50:05 -05001352
Jon Hallb1290e82014-11-18 16:17:48 -05001353 self.handle.sendline("")
1354 self.handle.expect("mininet>")
Jon Hall38481722014-11-04 16:50:05 -05001355
Jon Hallb1290e82014-11-18 16:17:48 -05001356 return main.TRUE
1357 except pexpect.EOF:
1358 main.log.error(self.name + ": EOF exception found")
1359 main.log.error(self.name + ": " + self.handle.before)
1360 main.cleanup()
1361 main.exit()
1362
adminbae64d82013-08-01 10:50:15 -07001363if __name__ != "__main__":
1364 import sys
1365 sys.modules[__name__] = MininetCliDriver()
admin2a9548d2014-06-17 14:08:07 -07001366