admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | ''' |
| 3 | Created 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 | |
| 22 | MininetCliDriver is the basic driver which will handle the Mininet functions |
| 23 | ''' |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 24 | import traceback |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 25 | import pexpect |
| 26 | import struct |
| 27 | import fcntl |
| 28 | import os |
| 29 | import signal |
| 30 | import re |
| 31 | import sys |
| 32 | import core.teston |
| 33 | sys.path.append("../") |
Jon Hall | 1ccf82c | 2014-10-15 14:55:16 -0400 | [diff] [blame] | 34 | from math import pow |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 35 | from drivers.common.cli.emulatordriver import Emulator |
| 36 | from drivers.common.clidriver import CLI |
| 37 | |
| 38 | class MininetCliDriver(Emulator): |
| 39 | ''' |
Jon Hall | 41f40e8 | 2014-04-08 16:43:17 -0700 | [diff] [blame] | 40 | MininetCliDriver is the basic driver which will handle the Mininet functions |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 41 | ''' |
| 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 Hall | 41f40e8 | 2014-04-08 16:43:17 -0700 | [diff] [blame] | 49 | ''' |
| 50 | Here the main is the TestON instance after creating all the log handles. |
| 51 | ''' |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 52 | 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 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 60 | if self.handle : |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 61 | main.log.info(self.name+": Clearing any residual state or processes") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 62 | self.handle.sendline("sudo mn -c") |
admin | f939f8b | 2014-04-03 17:22:56 -0700 | [diff] [blame] | 63 | i=self.handle.expect(['password\sfor\s','Cleanup\scomplete',pexpect.EOF,pexpect.TIMEOUT],120) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 64 | if i==0: |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 65 | main.log.info(self.name+": Sending sudo password") |
admin | f939f8b | 2014-04-03 17:22:56 -0700 | [diff] [blame] | 66 | self.handle.sendline(self.pwd) |
| 67 | i=self.handle.expect(['%s:'%(self.user),'\$',pexpect.EOF,pexpect.TIMEOUT],120) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 68 | if i==1: |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 69 | main.log.info(self.name+": Clean") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 70 | elif i==2: |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 71 | main.log.error(self.name+": Connection terminated") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 72 | elif i==3: #timeout |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 73 | main.log.error(self.name+": Something while cleaning MN took too long... " ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 74 | |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 75 | main.log.info(self.name+": building fresh mininet") |
admin | beea003 | 2014-01-23 14:54:13 -0800 | [diff] [blame] | 76 | #### for reactive/PARP enabled tests |
shahshreya | f4d4d0c | 2014-10-10 12:11:10 -0700 | [diff] [blame] | 77 | cmdString = "sudo mn " + self.options['arg1'] + " " + self.options['arg2'] + " --mac --controller " + self.options['controller'] + " " + self.options['arg3'] |
Jon Hall | 1ccf82c | 2014-10-15 14:55:16 -0400 | [diff] [blame] | 78 | |
| 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 |
shahshreya | f4d4d0c | 2014-10-10 12:11:10 -0700 | [diff] [blame] | 86 | #cmdString = "sudo mn " + self.options['arg1'] + " " + self.options['arg2'] + " --mac --arp --controller " + self.options['controller'] + " " + self.options['arg3'] |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 87 | self.handle.sendline(cmdString) |
Jon Hall | 333fa8c | 2014-04-11 11:24:58 -0700 | [diff] [blame] | 88 | self.handle.expect(["sudo mn",pexpect.EOF,pexpect.TIMEOUT]) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 89 | while 1: |
| 90 | i=self.handle.expect(['mininet>','\*\*\*','Exception',pexpect.EOF,pexpect.TIMEOUT],300) |
| 91 | if i==0: |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 92 | main.log.info(self.name+": mininet built") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 93 | return main.TRUE |
| 94 | if i==1: |
Jon Hall | 1645caa | 2014-11-18 16:27:14 -0500 | [diff] [blame] | 95 | self.handle.expect(["\n",pexpect.EOF,pexpect.TIMEOUT]) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 96 | main.log.info(self.handle.before) |
| 97 | elif i==2: |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 98 | main.log.error(self.name+": Launching mininet failed...") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 99 | return main.FALSE |
| 100 | elif i==3: |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 101 | main.log.error(self.name+": Connection timeout") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 102 | return main.FALSE |
| 103 | elif i==4: #timeout |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 104 | main.log.error(self.name+": Something took too long... " ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 105 | return main.FALSE |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 106 | #if utilities.assert_matches(expect=patterns,actual=resultCommand,onpass="Network is being launched",onfail="Network launching is being failed "): |
| 107 | return main.TRUE |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 108 | 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") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 111 | return main.FALSE |
Jon Hall | 1ccf82c | 2014-10-15 14:55:16 -0400 | [diff] [blame] | 112 | |
| 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 Hall | 3848172 | 2014-11-04 16:50:05 -0500 | [diff] [blame] | 118 | count = 0 |
Jon Hall | 1ccf82c | 2014-10-15 14:55:16 -0400 | [diff] [blame] | 119 | while(k <= depth-1): |
Jon Hall | 3848172 | 2014-11-04 16:50:05 -0500 | [diff] [blame] | 120 | count = count + pow(fanout,k) |
Jon Hall | 1ccf82c | 2014-10-15 14:55:16 -0400 | [diff] [blame] | 121 | k = k+1 |
Jon Hall | 3848172 | 2014-11-04 16:50:05 -0500 | [diff] [blame] | 122 | num_switches = count |
Jon Hall | 1ccf82c | 2014-10-15 14:55:16 -0400 | [diff] [blame] | 123 | 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 Hall | 3848172 | 2014-11-04 16:50:05 -0500 | [diff] [blame] | 127 | count = count + pow(fanout,k) |
Jon Hall | 1ccf82c | 2014-10-15 14:55:16 -0400 | [diff] [blame] | 128 | k = k+1 |
Jon Hall | 3848172 | 2014-11-04 16:50:05 -0500 | [diff] [blame] | 129 | num_links = count * fanout |
Jon Hall | 1ccf82c | 2014-10-15 14:55:16 -0400 | [diff] [blame] | 130 | #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 Hall | 1645caa | 2014-11-18 16:27:14 -0500 | [diff] [blame] | 149 | def pingall(self, timeout=300): |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 150 | ''' |
Jon Hall | 41f40e8 | 2014-04-08 16:43:17 -0700 | [diff] [blame] | 151 | Verifies the reachability of the hosts using pingall command. |
Jon Hall | 1645caa | 2014-11-18 16:27:14 -0500 | [diff] [blame] | 152 | 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 |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 156 | ''' |
| 157 | if self.handle : |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 158 | main.log.info(self.name+": Checking reachabilty to the hosts using pingall") |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 159 | try: |
Jon Hall | 1645caa | 2014-11-18 16:27:14 -0500 | [diff] [blame] | 160 | response = self.execute(cmd="pingall",prompt="mininet>",timeout=int(timeout)) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 161 | except pexpect.EOF: |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 162 | main.log.error(self.name + ": EOF exception found") |
| 163 | main.log.error(self.name + ": " + self.handle.before) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 164 | 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 Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 172 | if re.search(pattern,response): |
| 173 | main.log.info(self.name+": All hosts are reachable") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 174 | return main.TRUE |
| 175 | else: |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 176 | main.log.error(self.name+": Unable to reach all the hosts") |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 177 | 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>") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 182 | return main.FALSE |
| 183 | else : |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 184 | main.log.error(self.name+": Connection failed to the host") |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 185 | main.cleanup() |
| 186 | main.exit() |
admin | aeedddd | 2013-08-02 15:14:15 -0700 | [diff] [blame] | 187 | |
| 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) |
admin | 530b4c9 | 2013-08-14 16:54:35 -0700 | [diff] [blame] | 194 | command = args["SRC"] + " fping -i 100 -t 20 -C 1 -q "+args["TARGET"] |
admin | aeedddd | 2013-08-02 15:14:15 -0700 | [diff] [blame] | 195 | self.handle.sendline(command) |
Jon Hall | 333fa8c | 2014-04-11 11:24:58 -0700 | [diff] [blame] | 196 | self.handle.expect([args["TARGET"],pexpect.EOF,pexpect.TIMEOUT]) |
| 197 | self.handle.expect(["mininet",pexpect.EOF,pexpect.TIMEOUT]) |
admin | aeedddd | 2013-08-02 15:14:15 -0700 | [diff] [blame] | 198 | response = self.handle.before |
| 199 | if re.search(":\s-" ,response): |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 200 | main.log.info(self.name+": Ping fail") |
admin | aeedddd | 2013-08-02 15:14:15 -0700 | [diff] [blame] | 201 | return main.FALSE |
admin | 530b4c9 | 2013-08-14 16:54:35 -0700 | [diff] [blame] | 202 | elif re.search(":\s\d{1,2}\.\d\d", response): |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 203 | main.log.info(self.name+": Ping good!") |
admin | aeedddd | 2013-08-02 15:14:15 -0700 | [diff] [blame] | 204 | return main.TRUE |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 205 | main.log.info(self.name+": Install fping on mininet machine... ") |
| 206 | main.log.info(self.name+": \n---\n"+response) |
admin | aeedddd | 2013-08-02 15:14:15 -0700 | [diff] [blame] | 207 | return main.FALSE |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 208 | |
| 209 | def pingHost(self,**pingParams): |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 210 | ''' |
| 211 | Ping from one mininet host to another |
| 212 | Currently the only supported Params: SRC and TARGET |
| 213 | ''' |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 214 | args = utilities.parse_args(["SRC","TARGET"],**pingParams) |
| 215 | #command = args["SRC"] + " ping -" + args["CONTROLLER"] + " " +args ["TARGET"] |
Jon Hall | 0819fd9 | 2014-05-23 12:08:13 -0700 | [diff] [blame] | 216 | command = args["SRC"] + " ping "+args ["TARGET"]+" -c 1 -i 1 -W 8" |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 217 | try: |
Jon Hall | 6e18c7b | 2014-04-23 16:26:33 -0700 | [diff] [blame] | 218 | 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 Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 230 | 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 Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 235 | 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 Hall | 6e18c7b | 2014-04-23 16:26:33 -0700 | [diff] [blame] | 238 | main.log.info(self.name+": no packets lost, host is reachable") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 239 | main.last_result = main.TRUE |
| 240 | return main.TRUE |
| 241 | else : |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 242 | main.log.error(self.name+": PACKET LOST, HOST IS NOT REACHABLE") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 243 | main.last_result = main.FALSE |
| 244 | return main.FALSE |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 245 | |
| 246 | def checkIP(self,host): |
| 247 | ''' |
Jon Hall | 41f40e8 | 2014-04-08 16:43:17 -0700 | [diff] [blame] | 248 | Verifies the host's ip configured or not. |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 249 | ''' |
| 250 | if self.handle : |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 251 | 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() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 258 | |
| 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})" |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 260 | #pattern = "inet addr:10.0.0.6" |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 261 | #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") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 264 | return main.TRUE |
| 265 | else: |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 266 | main.log.error(self.name+": Host IP not found") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 267 | return main.FALSE |
| 268 | else : |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 269 | main.log.error(self.name+": Connection failed to the host") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 270 | |
| 271 | def verifySSH(self,**connectargs): |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 272 | 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() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 283 | 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 |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 290 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 291 | |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 292 | |
| 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 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 331 | def getMacAddress(self,host): |
| 332 | ''' |
Jon Hall | 41f40e8 | 2014-04-08 16:43:17 -0700 | [diff] [blame] | 333 | Verifies the host's ip configured or not. |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 334 | ''' |
| 335 | if self.handle : |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 336 | 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() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 343 | |
Ahmed El-Hassany | f720e20 | 2014-04-04 16:11:36 -0700 | [diff] [blame] | 344 | 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 Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 347 | main.log.info(self.name+": Mac-Address of Host "+ host + " is " + mac_address) |
Ahmed El-Hassany | f720e20 | 2014-04-04 16:11:36 -0700 | [diff] [blame] | 348 | return mac_address |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 349 | else : |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 350 | main.log.error(self.name+": Connection failed to the host") |
Ahmed El-Hassany | fd32918 | 2014-04-10 11:38:16 -0700 | [diff] [blame] | 351 | |
| 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 Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 357 | try: |
| 358 | response = self.execute(cmd=host+" ifconfig " + interface, |
Ahmed El-Hassany | fd32918 | 2014-04-10 11:38:16 -0700 | [diff] [blame] | 359 | prompt="mininet>",timeout=10) |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 360 | 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-Hassany | fd32918 | 2014-04-10 11:38:16 -0700 | [diff] [blame] | 365 | |
| 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 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 377 | def getIPAddress(self,host): |
| 378 | ''' |
Jon Hall | 41f40e8 | 2014-04-08 16:43:17 -0700 | [diff] [blame] | 379 | Verifies the host's ip configured or not. |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 380 | ''' |
| 381 | if self.handle : |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 382 | 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() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 389 | |
| 390 | pattern = "inet\saddr:(\d+\.\d+\.\d+\.\d+)" |
| 391 | ip_address_search = re.search(pattern, response) |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 392 | main.log.info(self.name+": IP-Address of Host "+host +" is "+ip_address_search.group(1)) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 393 | return ip_address_search.group(1) |
| 394 | else : |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 395 | main.log.error(self.name+": Connection failed to the host") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 396 | |
Ahmed El-Hassany | fd32918 | 2014-04-10 11:38:16 -0700 | [diff] [blame] | 397 | 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 Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 403 | 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-Hassany | fd32918 | 2014-04-10 11:38:16 -0700 | [diff] [blame] | 410 | 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 Hall | c1a1d24 | 2014-07-21 16:03:33 -0700 | [diff] [blame] | 415 | return str(result.group(0)) |
Ahmed El-Hassany | fd32918 | 2014-04-10 11:38:16 -0700 | [diff] [blame] | 416 | else: |
| 417 | main.log.error("Connection failed to the host") |
| 418 | |
admin | 2580a0e | 2014-07-29 11:24:34 -0700 | [diff] [blame] | 419 | 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-Hassany | fd32918 | 2014-04-10 11:38:16 -0700 | [diff] [blame] | 436 | def getInterfaces(self, node): |
| 437 | ''' |
| 438 | return information dict about interfaces connected to the node |
| 439 | ''' |
| 440 | if self.handle : |
Jon Hall | 3848172 | 2014-11-04 16:50:05 -0500 | [diff] [blame] | 441 | cmd = 'py "\\n".join(["name=%s,mac=%s,ip=%s,enabled=%s" % (i.name, i.MAC(), i.IP(), i.isUp())' |
Ahmed El-Hassany | fd32918 | 2014-04-10 11:38:16 -0700 | [diff] [blame] | 442 | cmd += ' for i in %s.intfs.values()])' % node |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 443 | 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-Hassany | fd32918 | 2014-04-10 11:38:16 -0700 | [diff] [blame] | 450 | return response |
| 451 | else: |
| 452 | main.log.error("Connection failed to the node") |
| 453 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 454 | def dump(self): |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 455 | main.log.info(self.name+": Dump node info") |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 456 | 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-Hassany | d1f7170 | 2014-04-04 16:12:45 -0700 | [diff] [blame] | 463 | return response |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 464 | |
| 465 | def intfs(self): |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 466 | main.log.info(self.name+": List interfaces") |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 467 | 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 Hall | 668ed80 | 2014-04-08 17:17:59 -0700 | [diff] [blame] | 474 | return response |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 475 | |
| 476 | def net(self): |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 477 | main.log.info(self.name+": List network connections") |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 478 | 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 Hall | 668ed80 | 2014-04-08 17:17:59 -0700 | [diff] [blame] | 485 | return response |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 486 | ''' |
| 487 | def iperf(self,host1,host2): |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 488 | main.log.info(self.name+": Simple iperf TCP test between two (optionally specified) hosts") |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 489 | try: |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 490 | 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 Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 495 | 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 Hall | 668ed80 | 2014-04-08 17:17:59 -0700 | [diff] [blame] | 500 | return response |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 501 | ''' |
| 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() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 520 | |
| 521 | def iperfudp(self): |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 522 | main.log.info(self.name+": Simple iperf TCP test between two (optionally specified) hosts") |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 523 | 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 Hall | 668ed80 | 2014-04-08 17:17:59 -0700 | [diff] [blame] | 530 | return response |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 531 | |
| 532 | def nodes(self): |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 533 | main.log.info(self.name+": List all nodes.") |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 534 | 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 Hall | 668ed80 | 2014-04-08 17:17:59 -0700 | [diff] [blame] | 541 | return response |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 542 | |
| 543 | def pingpair(self): |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 544 | main.log.info(self.name+": Ping between first two hosts") |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 545 | 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() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 552 | |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 553 | #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") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 556 | main.last_result = main.TRUE |
| 557 | return main.TRUE |
| 558 | else : |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 559 | main.log.error(self.name+": PACKET LOST, HOSTS NOT REACHABLE") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 560 | 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 | ''' |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 567 | 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 Hall | 3848172 | 2014-11-04 16:50:05 -0500 | [diff] [blame] | 571 | main.log.info("Bring link between '"+ end1 +"' and '" + end2 + "' '" + option + "'") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 572 | command = "link "+str(end1) + " " + str(end2)+ " " + str(option) |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 573 | try: |
Jon Hall | e80ef8c | 2014-04-29 15:29:13 -0700 | [diff] [blame] | 574 | #response = self.execute(cmd=command,prompt="mininet>",timeout=10) |
| 575 | self.handle.sendline(command) |
| 576 | self.handle.expect("mininet>") |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 577 | 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() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 582 | return main.TRUE |
| 583 | |
| 584 | |
admin | 530b4c9 | 2013-08-14 16:54:35 -0700 | [diff] [blame] | 585 | def yank(self,**yankargs): |
admin | aeedddd | 2013-08-02 15:14:15 -0700 | [diff] [blame] | 586 | ''' |
admin | 530b4c9 | 2013-08-14 16:54:35 -0700 | [diff] [blame] | 587 | yank a mininet switch interface to a host |
admin | aeedddd | 2013-08-02 15:14:15 -0700 | [diff] [blame] | 588 | ''' |
admin | 530b4c9 | 2013-08-14 16:54:35 -0700 | [diff] [blame] | 589 | main.log.info('Yank the switch interface attached to a host') |
| 590 | args = utilities.parse_args(["SW","INTF"],**yankargs) |
admin | aeedddd | 2013-08-02 15:14:15 -0700 | [diff] [blame] | 591 | 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 Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 594 | 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() |
admin | aeedddd | 2013-08-02 15:14:15 -0700 | [diff] [blame] | 601 | 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') |
admin | 530b4c9 | 2013-08-14 16:54:35 -0700 | [diff] [blame] | 608 | args = utilities.parse_args(["SW","INTF"],**plugargs) |
admin | aeedddd | 2013-08-02 15:14:15 -0700 | [diff] [blame] | 609 | 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 Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 612 | 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() |
admin | aeedddd | 2013-08-02 15:14:15 -0700 | [diff] [blame] | 619 | return main.TRUE |
| 620 | |
| 621 | |
| 622 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 623 | def dpctl(self,**dpctlargs): |
| 624 | ''' |
Jon Hall | 41f40e8 | 2014-04-08 16:43:17 -0700 | [diff] [blame] | 625 | Run dpctl command on all switches. |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 626 | ''' |
| 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 Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 632 | 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() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 639 | 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 Hall | ec3c21e | 2014-11-10 22:22:37 -0500 | [diff] [blame] | 650 | return version |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 651 | |
Jon Hall | ec3c21e | 2014-11-10 22:22:37 -0500 | [diff] [blame] | 652 | 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 | ''' |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 659 | command = "sh ovs-vsctl get-controller "+str(sw) |
| 660 | try: |
Jon Hall | ec3c21e | 2014-11-10 22:22:37 -0500 | [diff] [blame] | 661 | response = self.execute(cmd=command, prompt="mininet>", timeout=10) |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 662 | if response: |
Jon Hall | ec3c21e | 2014-11-10 22:22:37 -0500 | [diff] [blame] | 663 | return response |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 664 | 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() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 671 | |
| 672 | def assign_sw_controller(self,**kwargs): |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 673 | ''' |
| 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 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 684 | sw = args["SW"] if args["SW"] != None else "" |
admin | 530b4c9 | 2013-08-14 16:54:35 -0700 | [diff] [blame] | 685 | ptcpA = int(args["PORT1"])+int(sw) if args["PORT1"] != None else "" |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 686 | 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 Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 696 | 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() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 709 | |
Jon Hall | 0819fd9 | 2014-05-23 12:08:13 -0700 | [diff] [blame] | 710 | 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 Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 726 | 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 Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 738 | command = "addswitch " + str( sw ) + " " + str( dpid ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 739 | 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 Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 766 | command = "delswitch " + str( sw ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 767 | 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 Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 796 | command = "addlink " + str( node1 ) + " " + str( node2 ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 797 | 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 Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 825 | command = "dellink " + str( node1 ) + " " + str( node2 ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 826 | 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 Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 857 | command = "addhost " + str( hostname ) + " " + str( switch ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 858 | 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 Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 888 | command = "delhost " + str( hostname ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 889 | 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 Hall | 0819fd9 | 2014-05-23 12:08:13 -0700 | [diff] [blame] | 907 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 908 | def disconnect(self): |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 909 | main.log.info(self.name+": Disconnecting mininet...") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 910 | response = '' |
| 911 | if self.handle: |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 912 | try: |
| 913 | response = self.execute(cmd="exit",prompt="(.*)",timeout=120) |
| 914 | response = self.execute(cmd="exit",prompt="(.*)",timeout=120) |
Jon Hall | e80ef8c | 2014-04-29 15:29:13 -0700 | [diff] [blame] | 915 | self.handle.sendline("sudo mn -c") |
shahshreya | 328c2a7 | 2014-11-17 10:19:50 -0800 | [diff] [blame] | 916 | response = main.TRUE |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 917 | 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() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 922 | else : |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 923 | main.log.error(self.name+": Connection failed to the host") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 924 | response = main.FALSE |
| 925 | return response |
admin | 0752993 | 2013-11-22 14:58:28 -0800 | [diff] [blame] | 926 | |
| 927 | def arping(self, src, dest, destmac): |
| 928 | self.handle.sendline('') |
Jon Hall | 333fa8c | 2014-04-11 11:24:58 -0700 | [diff] [blame] | 929 | self.handle.expect(["mininet",pexpect.EOF,pexpect.TIMEOUT]) |
admin | 0752993 | 2013-11-22 14:58:28 -0800 | [diff] [blame] | 930 | |
| 931 | self.handle.sendline(src + ' arping ' + dest) |
| 932 | try: |
Jon Hall | 333fa8c | 2014-04-11 11:24:58 -0700 | [diff] [blame] | 933 | self.handle.expect([destmac,pexpect.EOF,pexpect.TIMEOUT]) |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 934 | main.log.info(self.name+": ARP successful") |
Jon Hall | 333fa8c | 2014-04-11 11:24:58 -0700 | [diff] [blame] | 935 | self.handle.expect(["mininet",pexpect.EOF,pexpect.TIMEOUT]) |
admin | 0752993 | 2013-11-22 14:58:28 -0800 | [diff] [blame] | 936 | return main.TRUE |
| 937 | except: |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 938 | main.log.warn(self.name+": ARP FAILURE") |
Jon Hall | 333fa8c | 2014-04-11 11:24:58 -0700 | [diff] [blame] | 939 | self.handle.expect(["mininet",pexpect.EOF,pexpect.TIMEOUT]) |
admin | 0752993 | 2013-11-22 14:58:28 -0800 | [diff] [blame] | 940 | return main.FALSE |
| 941 | |
| 942 | def decToHex(num): |
| 943 | return hex(num).split('x')[1] |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 944 | |
| 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: |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 961 | 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-Hassany | b6545eb | 2014-08-01 11:32:10 -0700 | [diff] [blame] | 967 | 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) |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 972 | 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("") |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 993 | 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 Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 995 | self.handle.sendline("") |
| 996 | self.handle.expect("mininet>") |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 997 | 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 Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1028 | self.handle.expect("mininet>") |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 1029 | 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 Hall | 3d87d50 | 2014-10-17 18:37:42 -0400 | [diff] [blame] | 1043 | 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 Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1053 | #main.log.debug("Switches_json string: ", switches_json) |
Jon Hall | 3d87d50 | 2014-10-17 18:37:42 -0400 | [diff] [blame] | 1054 | output = {"switches":[]} |
| 1055 | for switch in topo.graph.switches: #iterate through the MN topology and pull out switches and and port info |
Jon Hall | 3d87d50 | 2014-10-17 18:37:42 -0400 | [diff] [blame] | 1056 | ports = [] |
| 1057 | for port in switch.ports.values(): |
Jon Hall | 3d87d50 | 2014-10-17 18:37:42 -0400 | [diff] [blame] | 1058 | 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 Hall | 3d87d50 | 2014-10-17 18:37:42 -0400 | [diff] [blame] | 1060 | |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1061 | #print "mn" |
Jon Hall | 3d87d50 | 2014-10-17 18:37:42 -0400 | [diff] [blame] | 1062 | #print json.dumps(output, sort_keys=True,indent=4,separators=(',', ': ')) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1063 | #print "onos" |
| 1064 | #print json.dumps(switches_json, sort_keys=True,indent=4,separators=(',', ': ')) |
Jon Hall | 3d87d50 | 2014-10-17 18:37:42 -0400 | [diff] [blame] | 1065 | |
| 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 Hall | 3848172 | 2014-11-04 16:50:05 -0500 | [diff] [blame] | 1072 | #print "List of Mininet switch DPID's" |
Jon Hall | 3d87d50 | 2014-10-17 18:37:42 -0400 | [diff] [blame] | 1073 | #print mnDPIDs |
| 1074 | if switches_json == "":#if rest call fails |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1075 | main.log.error(self.name + ".compare_switches(): Empty JSON object given from ONOS") |
Jon Hall | 3d87d50 | 2014-10-17 18:37:42 -0400 | [diff] [blame] | 1076 | return main.FALSE |
| 1077 | onos=switches_json |
| 1078 | onosDPIDs=[] |
| 1079 | for switch in onos: |
Jon Hall | 3848172 | 2014-11-04 16:50:05 -0500 | [diff] [blame] | 1080 | if switch['available'] == True: |
| 1081 | onosDPIDs.append(switch['id'].replace(":",'').replace("of",'')) |
| 1082 | #else: |
| 1083 | #print "Switch is unavailable:" |
| 1084 | #print switch |
Jon Hall | 3d87d50 | 2014-10-17 18:37:42 -0400 | [diff] [blame] | 1085 | onosDPIDs.sort() |
Jon Hall | 3848172 | 2014-11-04 16:50:05 -0500 | [diff] [blame] | 1086 | #print "List of ONOS switch DPID's" |
Jon Hall | 3d87d50 | 2014-10-17 18:37:42 -0400 | [diff] [blame] | 1087 | #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 Hall | 72cf1dc | 2014-10-20 21:04:50 -0400 | [diff] [blame] | 1102 | 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 Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 1113 | #FIXME: this does not look for extra ports in ONOS, only checks that ONOS has what is in MN |
Jon Hall | 72cf1dc | 2014-10-20 21:04:50 -0400 | [diff] [blame] | 1114 | import json |
| 1115 | from numpy import uint64 |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1116 | ports_results = main.TRUE |
Jon Hall | 72cf1dc | 2014-10-20 21:04:50 -0400 | [diff] [blame] | 1117 | output = {"switches":[]} |
| 1118 | for switch in topo.graph.switches: #iterate through the MN topology and pull out switches and and port info |
Jon Hall | 72cf1dc | 2014-10-20 21:04:50 -0400 | [diff] [blame] | 1119 | ports = [] |
| 1120 | for port in switch.ports.values(): |
| 1121 | #print port.hw_addr.toStr(separator = '') |
Jon Hall | 39f29df | 2014-11-04 19:30:21 -0500 | [diff] [blame] | 1122 | 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 Hall | 72cf1dc | 2014-10-20 21:04:50 -0400 | [diff] [blame] | 1135 | |
| 1136 | |
| 1137 | ################ports############# |
Jon Hall | 39f29df | 2014-11-04 19:30:21 -0500 | [diff] [blame] | 1138 | for mn_switch in output['switches']: |
Jon Hall | 72cf1dc | 2014-10-20 21:04:50 -0400 | [diff] [blame] | 1139 | mn_ports = [] |
| 1140 | onos_ports = [] |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1141 | switch_result = main.TRUE |
Jon Hall | 39f29df | 2014-11-04 19:30:21 -0500 | [diff] [blame] | 1142 | for port in mn_switch['ports']: |
Jon Hall | 3848172 | 2014-11-04 16:50:05 -0500 | [diff] [blame] | 1143 | if port['enabled'] == True: |
| 1144 | mn_ports.append(port['of_port']) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1145 | #else: #DEBUG only |
| 1146 | # main.log.warn("Port %s on switch %s is down" % ( str(port['of_port']) , str(mn_switch['name'])) ) |
Jon Hall | 72cf1dc | 2014-10-20 21:04:50 -0400 | [diff] [blame] | 1147 | for onos_switch in ports_json: |
Jon Hall | 3848172 | 2014-11-04 16:50:05 -0500 | [diff] [blame] | 1148 | #print "Iterating through a new switch as seen by ONOS" |
| 1149 | #print onos_switch |
| 1150 | if onos_switch['device']['available'] == True: |
Jon Hall | 39f29df | 2014-11-04 19:30:21 -0500 | [diff] [blame] | 1151 | if onos_switch['device']['id'].replace(':','').replace("of", '') == mn_switch['dpid']: |
Jon Hall | 3848172 | 2014-11-04 16:50:05 -0500 | [diff] [blame] | 1152 | for port in onos_switch['ports']: |
| 1153 | if port['isEnabled']: |
| 1154 | #print "Iterating through available ports on the switch" |
| 1155 | #print port |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1156 | 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 Hall | 1645caa | 2014-11-18 16:27:14 -0500 | [diff] [blame] | 1165 | #else: #DEBUG |
| 1166 | # main.log.warn("Port %s on switch %s is down" % ( str(port['port']) , str(onos_switch['device']['id'])) ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1167 | break |
Jon Hall | 72cf1dc | 2014-10-20 21:04:50 -0400 | [diff] [blame] | 1168 | 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 Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1173 | 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 Hall | 3848172 | 2014-11-04 16:50:05 -0500 | [diff] [blame] | 1177 | |
Jon Hall | 72cf1dc | 2014-10-20 21:04:50 -0400 | [diff] [blame] | 1178 | #TODO: handle other reserved port numbers besides LOCAL |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1179 | #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 Hall | 72cf1dc | 2014-10-20 21:04:50 -0400 | [diff] [blame] | 1183 | #don't set results to true here as this is just one of many checks and it might override a failure |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1184 | 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 Hall | 39f29df | 2014-11-04 19:30:21 -0500 | [diff] [blame] | 1200 | main.log.report("The list of ports for switch %s(%s) does not match:" % (mn_switch['name'], mn_switch['dpid']) ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1201 | 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 Hall | 72cf1dc | 2014-10-20 21:04:50 -0400 | [diff] [blame] | 1205 | |
| 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 Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 1218 | #FIXME: this does not look for extra links in ONOS, only checks that ONOS has what is in MN |
Jon Hall | 72cf1dc | 2014-10-20 21:04:50 -0400 | [diff] [blame] | 1219 | 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 Hall | 3848172 | 2014-11-04 16:50:05 -0500 | [diff] [blame] | 1224 | # print "Iterating though switches as seen by Mininet" |
| 1225 | # print switch |
Jon Hall | 72cf1dc | 2014-10-20 21:04:50 -0400 | [diff] [blame] | 1226 | 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 Hall | 3848172 | 2014-11-04 16:50:05 -0500 | [diff] [blame] | 1233 | 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 Hall | 72cf1dc | 2014-10-20 21:04:50 -0400 | [diff] [blame] | 1237 | link_results = main.TRUE |
| 1238 | else: |
| 1239 | link_results = main.FALSE |
Jon Hall | 3848172 | 2014-11-04 16:50:05 -0500 | [diff] [blame] | 1240 | main.log.report("Mininet has %i bidirectional links and ONOS has %i unidirectional links" % (len(mn_links), len(onos) )) |
Jon Hall | 72cf1dc | 2014-10-20 21:04:50 -0400 | [diff] [blame] | 1241 | |
| 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 Hall | 3848172 | 2014-11-04 16:50:05 -0500 | [diff] [blame] | 1247 | for link in mn_links: |
Jon Hall | 72cf1dc | 2014-10-20 21:04:50 -0400 | [diff] [blame] | 1248 | #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 Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1287 | main.log.warn('The port numbers do not match for ' +str(link) +\ |
Jon Hall | 72cf1dc | 2014-10-20 21:04:50 -0400 | [diff] [blame] | 1288 | ' 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 Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1298 | main.log.warn('The port numbers do not match for ' +str(link) +\ |
Jon Hall | 72cf1dc | 2014-10-20 21:04:50 -0400 | [diff] [blame] | 1299 | ' 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 Hall | 62df924 | 2014-10-22 12:20:17 -0400 | [diff] [blame] | 1310 | return link_results |
Jon Hall | 72cf1dc | 2014-10-20 21:04:50 -0400 | [diff] [blame] | 1311 | |
| 1312 | |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1313 | 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>") |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 1323 | |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1324 | handle_py = self.handle.before |
| 1325 | handle_py = handle_py.split("]\r\n",1)[1] |
| 1326 | handle_py = handle_py.rstrip() |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 1327 | |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1328 | self.handle.sendline("") |
| 1329 | self.handle.expect("mininet>") |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 1330 | |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1331 | 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 |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 1337 | |
Jon Hall | 3848172 | 2014-11-04 16:50:05 -0500 | [diff] [blame] | 1338 | |
| 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 Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1345 | try: |
| 1346 | self.handle.sendline("") |
| 1347 | self.handle.expect("mininet>") |
Jon Hall | 3848172 | 2014-11-04 16:50:05 -0500 | [diff] [blame] | 1348 | |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1349 | self.handle.sendline("update") |
| 1350 | self.handle.expect("update") |
| 1351 | self.handle.expect("mininet>") |
Jon Hall | 3848172 | 2014-11-04 16:50:05 -0500 | [diff] [blame] | 1352 | |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1353 | self.handle.sendline("") |
| 1354 | self.handle.expect("mininet>") |
Jon Hall | 3848172 | 2014-11-04 16:50:05 -0500 | [diff] [blame] | 1355 | |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1356 | 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 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 1363 | if __name__ != "__main__": |
| 1364 | import sys |
| 1365 | sys.modules[__name__] = MininetCliDriver() |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 1366 | |