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: |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 301 | cmd = host+" ifconfig "+intf+" "+newIP+" "+'netmask'+" "+newNetmask |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 302 | self.handle.sendline(cmd) |
| 303 | self.handle.expect("mininet>") |
| 304 | response = self.handle.before |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 305 | main.log.info("response = "+response) |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 306 | main.log.info("Ip of host "+host+" changed to new IP "+newIP) |
| 307 | return main.TRUE |
| 308 | except pexpect.EOF: |
| 309 | main.log.error(self.name + ": EOF exception found") |
| 310 | main.log.error(self.name + ": " + self.handle.before) |
| 311 | return main.FALSE |
| 312 | |
| 313 | def changeDefaultGateway(self,host,newGW): |
| 314 | ''' |
| 315 | Changes the default gateway of a host |
| 316 | Ex: h1 route add default gw 10.0.1.2 |
| 317 | ''' |
| 318 | if self.handle: |
| 319 | try: |
| 320 | cmd = host+" route add default gw "+newGW |
| 321 | self.handle.sendline(cmd) |
| 322 | self.handle.expect("mininet>") |
| 323 | response = self.handle.before |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 324 | main.log.info("response = "+response) |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 325 | main.log.info("Default gateway of host "+host+" changed to "+newGW) |
| 326 | return main.TRUE |
| 327 | except pexpect.EOF: |
| 328 | main.log.error(self.name + ": EOF exception found") |
| 329 | main.log.error(self.name + ": " + self.handle.before) |
| 330 | return main.FALSE |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 331 | |
| 332 | def addStaticMACAddress(self,host,GW,macaddr): |
| 333 | ''' |
| 334 | Changes the mac address of a geateway host |
| 335 | ''' |
| 336 | if self.handle: |
| 337 | try: |
| 338 | #h1 arp -s 10.0.1.254 00:00:00:00:11:11 |
| 339 | cmd = host+" arp -s "+GW+" "+macaddr |
| 340 | self.handle.sendline(cmd) |
| 341 | self.handle.expect("mininet>") |
| 342 | response = self.handle.before |
| 343 | main.log.info("response = "+response) |
| 344 | main.log.info("Mac adrress of gateway "+GW+" changed to "+macaddr) |
| 345 | return main.TRUE |
| 346 | except pexpect.EOF: |
| 347 | main.log.error(self.name + ": EOF exception found") |
| 348 | main.log.error(self.name + ": " + self.handle.before) |
| 349 | return main.FALSE |
| 350 | |
| 351 | def verifyStaticGWandMAC(self,host): |
| 352 | ''' |
| 353 | Verify if the static gateway and mac address assignment |
| 354 | ''' |
| 355 | if self.handle: |
| 356 | try: |
| 357 | #h1 arp -an |
| 358 | cmd = host+" arp -an " |
| 359 | self.handle.sendline(cmd) |
| 360 | self.handle.expect("mininet>") |
| 361 | response = self.handle.before |
| 362 | main.log.info(host+" arp -an = "+response) |
| 363 | return main.TRUE |
| 364 | except pexpect.EOF: |
| 365 | main.log.error(self.name + ": EOF exception found") |
| 366 | main.log.error(self.name + ": " + self.handle.before) |
| 367 | return main.FALSE |
| 368 | |
| 369 | |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 370 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 371 | def getMacAddress(self,host): |
| 372 | ''' |
Jon Hall | 41f40e8 | 2014-04-08 16:43:17 -0700 | [diff] [blame] | 373 | Verifies the host's ip configured or not. |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 374 | ''' |
| 375 | if self.handle : |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 376 | try: |
| 377 | response = self.execute(cmd=host+" ifconfig",prompt="mininet>",timeout=10) |
| 378 | except pexpect.EOF: |
| 379 | main.log.error(self.name + ": EOF exception found") |
| 380 | main.log.error(self.name + ": " + self.handle.before) |
| 381 | main.cleanup() |
| 382 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 383 | |
Ahmed El-Hassany | f720e20 | 2014-04-04 16:11:36 -0700 | [diff] [blame] | 384 | pattern = r'HWaddr\s([0-9A-F]{2}[:-]){5}([0-9A-F]{2})' |
| 385 | mac_address_search = re.search(pattern, response, re.I) |
| 386 | mac_address = mac_address_search.group().split(" ")[1] |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 387 | 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] | 388 | return mac_address |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 389 | else : |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 390 | main.log.error(self.name+": Connection failed to the host") |
Ahmed El-Hassany | fd32918 | 2014-04-10 11:38:16 -0700 | [diff] [blame] | 391 | |
| 392 | def getInterfaceMACAddress(self,host, interface): |
| 393 | ''' |
| 394 | Return the IP address of the interface on the given host |
| 395 | ''' |
| 396 | if self.handle : |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 397 | try: |
| 398 | response = self.execute(cmd=host+" ifconfig " + interface, |
Ahmed El-Hassany | fd32918 | 2014-04-10 11:38:16 -0700 | [diff] [blame] | 399 | prompt="mininet>",timeout=10) |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 400 | except pexpect.EOF: |
| 401 | main.log.error(self.name + ": EOF exception found") |
| 402 | main.log.error(self.name + ": " + self.handle.before) |
| 403 | main.cleanup() |
| 404 | main.exit() |
Ahmed El-Hassany | fd32918 | 2014-04-10 11:38:16 -0700 | [diff] [blame] | 405 | |
| 406 | pattern = r'HWaddr\s([0-9A-F]{2}[:-]){5}([0-9A-F]{2})' |
| 407 | mac_address_search = re.search(pattern, response, re.I) |
| 408 | if mac_address_search is None: |
| 409 | main.log.info("No mac address found in %s" % response) |
| 410 | return main.FALSE |
| 411 | mac_address = mac_address_search.group().split(" ")[1] |
| 412 | main.log.info("Mac-Address of "+ host + ":"+ interface + " is " + mac_address) |
| 413 | return mac_address |
| 414 | else: |
| 415 | main.log.error("Connection failed to the host") |
| 416 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 417 | def getIPAddress(self,host): |
| 418 | ''' |
Jon Hall | 41f40e8 | 2014-04-08 16:43:17 -0700 | [diff] [blame] | 419 | Verifies the host's ip configured or not. |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 420 | ''' |
| 421 | if self.handle : |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 422 | try: |
| 423 | response = self.execute(cmd=host+" ifconfig",prompt="mininet>",timeout=10) |
| 424 | except pexpect.EOF: |
| 425 | main.log.error(self.name + ": EOF exception found") |
| 426 | main.log.error(self.name + ": " + self.handle.before) |
| 427 | main.cleanup() |
| 428 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 429 | |
| 430 | pattern = "inet\saddr:(\d+\.\d+\.\d+\.\d+)" |
| 431 | ip_address_search = re.search(pattern, response) |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 432 | 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] | 433 | return ip_address_search.group(1) |
| 434 | else : |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 435 | main.log.error(self.name+": Connection failed to the host") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 436 | |
Ahmed El-Hassany | fd32918 | 2014-04-10 11:38:16 -0700 | [diff] [blame] | 437 | def getSwitchDPID(self,switch): |
| 438 | ''' |
| 439 | return the datapath ID of the switch |
| 440 | ''' |
| 441 | if self.handle : |
| 442 | cmd = "py %s.dpid" % switch |
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() |
Jon Hall | 28bf54b | 2014-12-17 16:25:44 -0800 | [diff] [blame] | 450 | pattern = r'^(?P<dpid>\w)+' |
Ahmed El-Hassany | fd32918 | 2014-04-10 11:38:16 -0700 | [diff] [blame] | 451 | result = re.search(pattern, response, re.MULTILINE) |
| 452 | if result is None: |
| 453 | main.log.info("Couldn't find DPID for switch '', found: %s" % (switch, response)) |
| 454 | return main.FALSE |
Jon Hall | 28bf54b | 2014-12-17 16:25:44 -0800 | [diff] [blame] | 455 | return str(result.group(0)).lower() |
Ahmed El-Hassany | fd32918 | 2014-04-10 11:38:16 -0700 | [diff] [blame] | 456 | else: |
| 457 | main.log.error("Connection failed to the host") |
| 458 | |
admin | 2580a0e | 2014-07-29 11:24:34 -0700 | [diff] [blame] | 459 | def getDPID(self, switch): |
| 460 | if self.handle: |
| 461 | self.handle.sendline("") |
| 462 | self.expect("mininet>") |
| 463 | cmd = "py %s.dpid" %switch |
| 464 | try: |
| 465 | response = self.execute(cmd=cmd,prompt="mininet>",timeout=10) |
| 466 | self.handle.expect("mininet>") |
| 467 | response = self.handle.before |
| 468 | return response |
| 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() |
| 474 | |
| 475 | |
Ahmed El-Hassany | fd32918 | 2014-04-10 11:38:16 -0700 | [diff] [blame] | 476 | def getInterfaces(self, node): |
| 477 | ''' |
| 478 | return information dict about interfaces connected to the node |
| 479 | ''' |
| 480 | if self.handle : |
Jon Hall | 3848172 | 2014-11-04 16:50:05 -0500 | [diff] [blame] | 481 | 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] | 482 | cmd += ' for i in %s.intfs.values()])' % node |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 483 | try: |
| 484 | response = self.execute(cmd=cmd,prompt="mininet>",timeout=10) |
| 485 | except pexpect.EOF: |
| 486 | main.log.error(self.name + ": EOF exception found") |
| 487 | main.log.error(self.name + ": " + self.handle.before) |
| 488 | main.cleanup() |
| 489 | main.exit() |
Ahmed El-Hassany | fd32918 | 2014-04-10 11:38:16 -0700 | [diff] [blame] | 490 | return response |
| 491 | else: |
| 492 | main.log.error("Connection failed to the node") |
| 493 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 494 | def dump(self): |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 495 | main.log.info(self.name+": Dump node info") |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 496 | try: |
| 497 | response = self.execute(cmd = 'dump',prompt = 'mininet>',timeout = 10) |
| 498 | except pexpect.EOF: |
| 499 | main.log.error(self.name + ": EOF exception found") |
| 500 | main.log.error(self.name + ": " + self.handle.before) |
| 501 | main.cleanup() |
| 502 | main.exit() |
Ahmed El-Hassany | d1f7170 | 2014-04-04 16:12:45 -0700 | [diff] [blame] | 503 | return response |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 504 | |
| 505 | def intfs(self): |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 506 | main.log.info(self.name+": List interfaces") |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 507 | try: |
| 508 | response = self.execute(cmd = 'intfs',prompt = 'mininet>',timeout = 10) |
| 509 | except pexpect.EOF: |
| 510 | main.log.error(self.name + ": EOF exception found") |
| 511 | main.log.error(self.name + ": " + self.handle.before) |
| 512 | main.cleanup() |
| 513 | main.exit() |
Jon Hall | 668ed80 | 2014-04-08 17:17:59 -0700 | [diff] [blame] | 514 | return response |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 515 | |
| 516 | def net(self): |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 517 | main.log.info(self.name+": List network connections") |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 518 | try: |
| 519 | response = self.execute(cmd = 'net',prompt = 'mininet>',timeout = 10) |
| 520 | except pexpect.EOF: |
| 521 | main.log.error(self.name + ": EOF exception found") |
| 522 | main.log.error(self.name + ": " + self.handle.before) |
| 523 | main.cleanup() |
| 524 | main.exit() |
Jon Hall | 668ed80 | 2014-04-08 17:17:59 -0700 | [diff] [blame] | 525 | return response |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 526 | ''' |
| 527 | def iperf(self,host1,host2): |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 528 | 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] | 529 | try: |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 530 | if not host1 and not host2: |
| 531 | response = self.execute(cmd = 'iperf',prompt = 'mininet>',timeout = 10) |
| 532 | else: |
| 533 | cmd1 = 'iperf '+ host1 + " " + host2 |
| 534 | response = self.execute(cmd = cmd1, prompt = '>',timeout = 20) |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 535 | except pexpect.EOF: |
| 536 | main.log.error(self.name + ": EOF exception found") |
| 537 | main.log.error(self.name + ": " + self.handle.before) |
| 538 | main.cleanup() |
| 539 | main.exit() |
Jon Hall | 668ed80 | 2014-04-08 17:17:59 -0700 | [diff] [blame] | 540 | return response |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 541 | ''' |
| 542 | def iperf(self,host1,host2): |
| 543 | main.log.info(self.name+": Simple iperf TCP test between two hosts") |
| 544 | try: |
| 545 | cmd1 = 'iperf '+ host1 + " " + host2 |
| 546 | self.handle.sendline(cmd1) |
| 547 | self.handle.expect("mininet>") |
| 548 | response = self.handle.before |
| 549 | if re.search('Results:',response): |
| 550 | main.log.info(self.name+": iperf test succssful") |
| 551 | return main.TRUE |
| 552 | else: |
| 553 | main.log.error(self.name+": iperf test failed") |
| 554 | return main.FALSE |
| 555 | except pexpect.EOF: |
| 556 | main.log.error(self.name + ": EOF exception found") |
| 557 | main.log.error(self.name + ": " + self.handle.before) |
| 558 | main.cleanup() |
| 559 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 560 | |
| 561 | def iperfudp(self): |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 562 | 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] | 563 | try: |
| 564 | response = self.execute(cmd = 'iperfudp',prompt = 'mininet>',timeout = 10) |
| 565 | except pexpect.EOF: |
| 566 | main.log.error(self.name + ": EOF exception found") |
| 567 | main.log.error(self.name + ": " + self.handle.before) |
| 568 | main.cleanup() |
| 569 | main.exit() |
Jon Hall | 668ed80 | 2014-04-08 17:17:59 -0700 | [diff] [blame] | 570 | return response |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 571 | |
| 572 | def nodes(self): |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 573 | main.log.info(self.name+": List all nodes.") |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 574 | try: |
| 575 | response = self.execute(cmd = 'nodes',prompt = 'mininet>',timeout = 10) |
| 576 | except pexpect.EOF: |
| 577 | main.log.error(self.name + ": EOF exception found") |
| 578 | main.log.error(self.name + ": " + self.handle.before) |
| 579 | main.cleanup() |
| 580 | main.exit() |
Jon Hall | 668ed80 | 2014-04-08 17:17:59 -0700 | [diff] [blame] | 581 | return response |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 582 | |
| 583 | def pingpair(self): |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 584 | main.log.info(self.name+": Ping between first two hosts") |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 585 | try: |
| 586 | response = self.execute(cmd = 'pingpair',prompt = 'mininet>',timeout = 20) |
| 587 | except pexpect.EOF: |
| 588 | main.log.error(self.name + ": EOF exception found") |
| 589 | main.log.error(self.name + ": " + self.handle.before) |
| 590 | main.cleanup() |
| 591 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 592 | |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 593 | #if utilities.assert_matches(expect='0% packet loss',actual=response,onpass="No Packet loss",onfail="Hosts not reachable"): |
| 594 | if re.search(',\s0\%\spacket\sloss',response): |
| 595 | main.log.info(self.name+": Ping between two hosts SUCCESSFUL") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 596 | main.last_result = main.TRUE |
| 597 | return main.TRUE |
| 598 | else : |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 599 | main.log.error(self.name+": PACKET LOST, HOSTS NOT REACHABLE") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 600 | main.last_result = main.FALSE |
| 601 | return main.FALSE |
| 602 | |
| 603 | def link(self,**linkargs): |
| 604 | ''' |
| 605 | Bring link(s) between two nodes up or down |
| 606 | ''' |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 607 | args = utilities.parse_args(["END1","END2","OPTION"],**linkargs) |
| 608 | end1 = args["END1"] if args["END1"] != None else "" |
| 609 | end2 = args["END2"] if args["END2"] != None else "" |
| 610 | option = args["OPTION"] if args["OPTION"] != None else "" |
Jon Hall | 3848172 | 2014-11-04 16:50:05 -0500 | [diff] [blame] | 611 | main.log.info("Bring link between '"+ end1 +"' and '" + end2 + "' '" + option + "'") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 612 | command = "link "+str(end1) + " " + str(end2)+ " " + str(option) |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 613 | try: |
Jon Hall | e80ef8c | 2014-04-29 15:29:13 -0700 | [diff] [blame] | 614 | #response = self.execute(cmd=command,prompt="mininet>",timeout=10) |
| 615 | self.handle.sendline(command) |
| 616 | self.handle.expect("mininet>") |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 617 | except pexpect.EOF: |
| 618 | main.log.error(self.name + ": EOF exception found") |
| 619 | main.log.error(self.name + ": " + self.handle.before) |
| 620 | main.cleanup() |
| 621 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 622 | return main.TRUE |
| 623 | |
| 624 | |
admin | 530b4c9 | 2013-08-14 16:54:35 -0700 | [diff] [blame] | 625 | def yank(self,**yankargs): |
admin | aeedddd | 2013-08-02 15:14:15 -0700 | [diff] [blame] | 626 | ''' |
admin | 530b4c9 | 2013-08-14 16:54:35 -0700 | [diff] [blame] | 627 | yank a mininet switch interface to a host |
admin | aeedddd | 2013-08-02 15:14:15 -0700 | [diff] [blame] | 628 | ''' |
admin | 530b4c9 | 2013-08-14 16:54:35 -0700 | [diff] [blame] | 629 | main.log.info('Yank the switch interface attached to a host') |
| 630 | args = utilities.parse_args(["SW","INTF"],**yankargs) |
admin | aeedddd | 2013-08-02 15:14:15 -0700 | [diff] [blame] | 631 | sw = args["SW"] if args["SW"] !=None else "" |
| 632 | intf = args["INTF"] if args["INTF"] != None else "" |
| 633 | command = "py "+ str(sw) + '.detach("' + str(intf) + '")' |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 634 | try: |
| 635 | response = self.execute(cmd=command,prompt="mininet>",timeout=10) |
| 636 | except pexpect.EOF: |
| 637 | main.log.error(self.name + ": EOF exception found") |
| 638 | main.log.error(self.name + ": " + self.handle.before) |
| 639 | main.cleanup() |
| 640 | main.exit() |
admin | aeedddd | 2013-08-02 15:14:15 -0700 | [diff] [blame] | 641 | return main.TRUE |
| 642 | |
| 643 | def plug(self, **plugargs): |
| 644 | ''' |
| 645 | plug the yanked mininet switch interface to a switch |
| 646 | ''' |
| 647 | main.log.info('Plug the switch interface attached to a switch') |
admin | 530b4c9 | 2013-08-14 16:54:35 -0700 | [diff] [blame] | 648 | args = utilities.parse_args(["SW","INTF"],**plugargs) |
admin | aeedddd | 2013-08-02 15:14:15 -0700 | [diff] [blame] | 649 | sw = args["SW"] if args["SW"] !=None else "" |
| 650 | intf = args["INTF"] if args["INTF"] != None else "" |
| 651 | command = "py "+ str(sw) + '.attach("' + str(intf) + '")' |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 652 | try: |
| 653 | response = self.execute(cmd=command,prompt="mininet>",timeout=10) |
| 654 | except pexpect.EOF: |
| 655 | main.log.error(self.name + ": EOF exception found") |
| 656 | main.log.error(self.name + ": " + self.handle.before) |
| 657 | main.cleanup() |
| 658 | main.exit() |
admin | aeedddd | 2013-08-02 15:14:15 -0700 | [diff] [blame] | 659 | return main.TRUE |
| 660 | |
| 661 | |
| 662 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 663 | def dpctl(self,**dpctlargs): |
| 664 | ''' |
Jon Hall | 41f40e8 | 2014-04-08 16:43:17 -0700 | [diff] [blame] | 665 | Run dpctl command on all switches. |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 666 | ''' |
| 667 | main.log.info('Run dpctl command on all switches') |
| 668 | args = utilities.parse_args(["CMD","ARGS"],**dpctlargs) |
| 669 | cmd = args["CMD"] if args["CMD"] != None else "" |
| 670 | cmdargs = args["ARGS"] if args["ARGS"] != None else "" |
| 671 | command = "dpctl "+cmd + " " + str(cmdargs) |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 672 | try: |
| 673 | response = self.execute(cmd=command,prompt="mininet>",timeout=10) |
| 674 | except pexpect.EOF: |
| 675 | main.log.error(self.name + ": EOF exception found") |
| 676 | main.log.error(self.name + ": " + self.handle.before) |
| 677 | main.cleanup() |
| 678 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 679 | return main.TRUE |
| 680 | |
| 681 | |
| 682 | def get_version(self): |
| 683 | file_input = path+'/lib/Mininet/INSTALL' |
| 684 | version = super(Mininet, self).get_version() |
| 685 | pattern = 'Mininet\s\w\.\w\.\w\w*' |
| 686 | for line in open(file_input,'r').readlines(): |
| 687 | result = re.match(pattern, line) |
| 688 | if result: |
| 689 | version = result.group(0) |
Jon Hall | ec3c21e | 2014-11-10 22:22:37 -0500 | [diff] [blame] | 690 | return version |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 691 | |
Jon Hall | ec3c21e | 2014-11-10 22:22:37 -0500 | [diff] [blame] | 692 | def get_sw_controller(self, sw): |
| 693 | ''' |
| 694 | Parameters: |
| 695 | sw: The name of an OVS switch. Example "s1" |
| 696 | Return: |
| 697 | The output of the command from the mininet cli or main.FALSE on timeout |
| 698 | ''' |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 699 | command = "sh ovs-vsctl get-controller "+str(sw) |
| 700 | try: |
Jon Hall | ec3c21e | 2014-11-10 22:22:37 -0500 | [diff] [blame] | 701 | response = self.execute(cmd=command, prompt="mininet>", timeout=10) |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 702 | if response: |
Jon Hall | ec3c21e | 2014-11-10 22:22:37 -0500 | [diff] [blame] | 703 | return response |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 704 | else: |
| 705 | return main.FALSE |
| 706 | except pexpect.EOF: |
| 707 | main.log.error(self.name + ": EOF exception found") |
| 708 | main.log.error(self.name + ": " + self.handle.before) |
| 709 | main.cleanup() |
| 710 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 711 | |
| 712 | def assign_sw_controller(self,**kwargs): |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 713 | ''' |
| 714 | count is only needed if there is more than 1 controller |
| 715 | ''' |
| 716 | args = utilities.parse_args(["COUNT"],**kwargs) |
| 717 | count = args["COUNT"] if args!={} else 1 |
| 718 | |
| 719 | argstring = "SW" |
| 720 | for j in range(count): |
| 721 | argstring = argstring + ",IP" + str(j+1) + ",PORT" + str(j+1) |
| 722 | args = utilities.parse_args(argstring.split(","),**kwargs) |
| 723 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 724 | sw = args["SW"] if args["SW"] != None else "" |
admin | 530b4c9 | 2013-08-14 16:54:35 -0700 | [diff] [blame] | 725 | ptcpA = int(args["PORT1"])+int(sw) if args["PORT1"] != None else "" |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 726 | ptcpB = "ptcp:"+str(ptcpA) if ptcpA != "" else "" |
| 727 | |
| 728 | command = "sh ovs-vsctl set-controller s" + str(sw) + " " + ptcpB + " " |
| 729 | for j in range(count): |
| 730 | i=j+1 |
| 731 | args = utilities.parse_args(["IP"+str(i),"PORT"+str(i)],**kwargs) |
| 732 | ip = args["IP"+str(i)] if args["IP"+str(i)] != None else "" |
| 733 | port = args["PORT" + str(i)] if args["PORT" + str(i)] != None else "" |
| 734 | tcp = "tcp:" + str(ip) + ":" + str(port) + " " if ip != "" else "" |
| 735 | command = command + tcp |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 736 | try: |
| 737 | self.execute(cmd=command,prompt="mininet>",timeout=5) |
| 738 | except pexpect.EOF: |
| 739 | main.log.error(self.name + ": EOF exception found") |
| 740 | main.log.error(self.name + ": " + self.handle.before) |
| 741 | main.cleanup() |
| 742 | main.exit() |
| 743 | except: |
| 744 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 745 | main.log.error( traceback.print_exc() ) |
| 746 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 747 | main.cleanup() |
| 748 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 749 | |
Jon Hall | 0819fd9 | 2014-05-23 12:08:13 -0700 | [diff] [blame] | 750 | def delete_sw_controller(self,sw): |
| 751 | ''' |
| 752 | Removes the controller target from sw |
| 753 | ''' |
| 754 | |
| 755 | command = "sh ovs-vsctl del-controller "+str(sw) |
| 756 | try: |
| 757 | response = self.execute(cmd=command,prompt="mininet>",timeout=10) |
| 758 | except pexpect.EOF: |
| 759 | main.log.error(self.name + ": EOF exception found") |
| 760 | main.log.error(self.name + ": " + self.handle.before) |
| 761 | main.cleanup() |
| 762 | main.exit() |
| 763 | else: |
| 764 | main.log.info(response) |
| 765 | |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 766 | def add_switch( self, sw, **kwargs ): |
| 767 | ''' |
| 768 | adds a switch to the mininet topology |
| 769 | NOTE: this uses a custom mn function |
| 770 | NOTE: cannot currently specify what type of switch |
| 771 | required params: |
| 772 | switchname = name of the new switch as a string |
| 773 | optional keyvalues: |
| 774 | dpid = "dpid" |
| 775 | returns: main.FASLE on an error, else main.TRUE |
| 776 | ''' |
| 777 | dpid = kwargs.get('dpid', '') |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 778 | command = "addswitch " + str( sw ) + " " + str( dpid ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 779 | try: |
| 780 | response = self.execute(cmd=command,prompt="mininet>",timeout=10) |
| 781 | if re.search("already exists!", response): |
| 782 | main.log.warn(response) |
| 783 | return main.FALSE |
| 784 | elif re.search("Error", response): |
| 785 | main.log.warn(response) |
| 786 | return main.FALSE |
| 787 | elif re.search("usage:", response): |
| 788 | main.log.warn(response) |
| 789 | return main.FALSE |
| 790 | else: |
| 791 | return main.TRUE |
| 792 | except pexpect.EOF: |
| 793 | main.log.error(self.name + ": EOF exception found") |
| 794 | main.log.error(self.name + ": " + self.handle.before) |
| 795 | main.cleanup() |
| 796 | main.exit() |
| 797 | |
| 798 | def del_switch( self, sw ): |
| 799 | ''' |
| 800 | delete a switch from the mininet topology |
| 801 | NOTE: this uses a custom mn function |
| 802 | required params: |
| 803 | switchname = name of the switch as a string |
| 804 | returns: main.FASLE on an error, else main.TRUE |
| 805 | ''' |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 806 | command = "delswitch " + str( sw ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 807 | try: |
| 808 | response = self.execute(cmd=command,prompt="mininet>",timeout=10) |
| 809 | if re.search("no switch named", response): |
| 810 | main.log.warn(response) |
| 811 | return main.FALSE |
| 812 | elif re.search("Error", response): |
| 813 | main.log.warn(response) |
| 814 | return main.FALSE |
| 815 | elif re.search("usage:", response): |
| 816 | main.log.warn(response) |
| 817 | return main.FALSE |
| 818 | else: |
| 819 | return main.TRUE |
| 820 | except pexpect.EOF: |
| 821 | main.log.error(self.name + ": EOF exception found") |
| 822 | main.log.error(self.name + ": " + self.handle.before) |
| 823 | main.cleanup() |
| 824 | main.exit() |
| 825 | |
| 826 | def add_link( self, node1, node2 ): |
| 827 | ''' |
| 828 | add a link to the mininet topology |
| 829 | NOTE: this uses a custom mn function |
| 830 | NOTE: cannot currently specify what type of link |
| 831 | required params: |
| 832 | node1 = the string node name of the first endpoint of the link |
| 833 | node2 = the string node name of the second endpoint of the link |
| 834 | returns: main.FASLE on an error, else main.TRUE |
| 835 | ''' |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 836 | command = "addlink " + str( node1 ) + " " + str( node2 ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 837 | try: |
| 838 | response = self.execute(cmd=command,prompt="mininet>",timeout=10) |
| 839 | if re.search("doesnt exist!", response): |
| 840 | main.log.warn(response) |
| 841 | return main.FALSE |
| 842 | elif re.search("Error", response): |
| 843 | main.log.warn(response) |
| 844 | return main.FALSE |
| 845 | elif re.search("usage:", response): |
| 846 | main.log.warn(response) |
| 847 | return main.FALSE |
| 848 | else: |
| 849 | return main.TRUE |
| 850 | except pexpect.EOF: |
| 851 | main.log.error(self.name + ": EOF exception found") |
| 852 | main.log.error(self.name + ": " + self.handle.before) |
| 853 | main.cleanup() |
| 854 | main.exit() |
| 855 | |
| 856 | def del_link( self, node1, node2 ): |
| 857 | ''' |
| 858 | delete a link from the mininet topology |
| 859 | NOTE: this uses a custom mn function |
| 860 | required params: |
| 861 | node1 = the string node name of the first endpoint of the link |
| 862 | node2 = the string node name of the second endpoint of the link |
| 863 | returns: main.FASLE on an error, else main.TRUE |
| 864 | ''' |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 865 | command = "dellink " + str( node1 ) + " " + str( node2 ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 866 | try: |
| 867 | response = self.execute(cmd=command,prompt="mininet>",timeout=10) |
| 868 | if re.search("no node named", response): |
| 869 | main.log.warn(response) |
| 870 | return main.FALSE |
| 871 | elif re.search("Error", response): |
| 872 | main.log.warn(response) |
| 873 | return main.FALSE |
| 874 | elif re.search("usage:", response): |
| 875 | main.log.warn(response) |
| 876 | return main.FALSE |
| 877 | else: |
| 878 | return main.TRUE |
| 879 | except pexpect.EOF: |
| 880 | main.log.error(self.name + ": EOF exception found") |
| 881 | main.log.error(self.name + ": " + self.handle.before) |
| 882 | main.cleanup() |
| 883 | main.exit() |
| 884 | |
| 885 | def add_host( self, hostname, **kwargs ): |
| 886 | ''' |
| 887 | Add a host to the mininet topology |
| 888 | NOTE: this uses a custom mn function |
| 889 | NOTE: cannot currently specify what type of host |
| 890 | required params: |
| 891 | hostname = the string hostname |
| 892 | optional key-value params |
| 893 | switch = "switch name" |
| 894 | returns: main.FASLE on an error, else main.TRUE |
| 895 | ''' |
| 896 | switch = kwargs.get('switch', '') |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 897 | command = "addhost " + str( hostname ) + " " + str( switch ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 898 | try: |
| 899 | response = self.execute(cmd=command,prompt="mininet>",timeout=10) |
| 900 | if re.search("already exists!", response): |
| 901 | main.log.warn(response) |
| 902 | return main.FALSE |
| 903 | elif re.search("doesnt exists!", response): |
| 904 | main.log.warn(response) |
| 905 | return main.FALSE |
| 906 | elif re.search("Error", response): |
| 907 | main.log.warn(response) |
| 908 | return main.FALSE |
| 909 | elif re.search("usage:", response): |
| 910 | main.log.warn(response) |
| 911 | return main.FALSE |
| 912 | else: |
| 913 | return main.TRUE |
| 914 | except pexpect.EOF: |
| 915 | main.log.error(self.name + ": EOF exception found") |
| 916 | main.log.error(self.name + ": " + self.handle.before) |
| 917 | main.cleanup() |
| 918 | main.exit() |
| 919 | |
| 920 | def del_host( self, hostname ): |
| 921 | ''' |
| 922 | delete a host from the mininet topology |
| 923 | NOTE: this uses a custom mn function |
| 924 | required params: |
| 925 | hostname = the string hostname |
| 926 | returns: main.FASLE on an error, else main.TRUE |
| 927 | ''' |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 928 | command = "delhost " + str( hostname ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 929 | try: |
| 930 | response = self.execute(cmd=command,prompt="mininet>",timeout=10) |
| 931 | if re.search("no host named", response): |
| 932 | main.log.warn(response) |
| 933 | return main.FALSE |
| 934 | elif re.search("Error", response): |
| 935 | main.log.warn(response) |
| 936 | return main.FALSE |
| 937 | elif re.search("usage:", response): |
| 938 | main.log.warn(response) |
| 939 | return main.FALSE |
| 940 | else: |
| 941 | return main.TRUE |
| 942 | except pexpect.EOF: |
| 943 | main.log.error(self.name + ": EOF exception found") |
| 944 | main.log.error(self.name + ": " + self.handle.before) |
| 945 | main.cleanup() |
| 946 | main.exit() |
Jon Hall | 0819fd9 | 2014-05-23 12:08:13 -0700 | [diff] [blame] | 947 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 948 | def disconnect(self): |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 949 | main.log.info(self.name+": Disconnecting mininet...") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 950 | response = '' |
| 951 | if self.handle: |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 952 | try: |
| 953 | response = self.execute(cmd="exit",prompt="(.*)",timeout=120) |
| 954 | response = self.execute(cmd="exit",prompt="(.*)",timeout=120) |
Jon Hall | e80ef8c | 2014-04-29 15:29:13 -0700 | [diff] [blame] | 955 | self.handle.sendline("sudo mn -c") |
shahshreya | 328c2a7 | 2014-11-17 10:19:50 -0800 | [diff] [blame] | 956 | response = main.TRUE |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 957 | except pexpect.EOF: |
| 958 | main.log.error(self.name + ": EOF exception found") |
| 959 | main.log.error(self.name + ": " + self.handle.before) |
| 960 | main.cleanup() |
| 961 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 962 | else : |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 963 | main.log.error(self.name+": Connection failed to the host") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 964 | response = main.FALSE |
| 965 | return response |
admin | 0752993 | 2013-11-22 14:58:28 -0800 | [diff] [blame] | 966 | |
| 967 | def arping(self, src, dest, destmac): |
| 968 | self.handle.sendline('') |
Jon Hall | 333fa8c | 2014-04-11 11:24:58 -0700 | [diff] [blame] | 969 | self.handle.expect(["mininet",pexpect.EOF,pexpect.TIMEOUT]) |
admin | 0752993 | 2013-11-22 14:58:28 -0800 | [diff] [blame] | 970 | |
| 971 | self.handle.sendline(src + ' arping ' + dest) |
| 972 | try: |
Jon Hall | 333fa8c | 2014-04-11 11:24:58 -0700 | [diff] [blame] | 973 | self.handle.expect([destmac,pexpect.EOF,pexpect.TIMEOUT]) |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 974 | main.log.info(self.name+": ARP successful") |
Jon Hall | 333fa8c | 2014-04-11 11:24:58 -0700 | [diff] [blame] | 975 | self.handle.expect(["mininet",pexpect.EOF,pexpect.TIMEOUT]) |
admin | 0752993 | 2013-11-22 14:58:28 -0800 | [diff] [blame] | 976 | return main.TRUE |
| 977 | except: |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 978 | main.log.warn(self.name+": ARP FAILURE") |
Jon Hall | 333fa8c | 2014-04-11 11:24:58 -0700 | [diff] [blame] | 979 | self.handle.expect(["mininet",pexpect.EOF,pexpect.TIMEOUT]) |
admin | 0752993 | 2013-11-22 14:58:28 -0800 | [diff] [blame] | 980 | return main.FALSE |
| 981 | |
| 982 | def decToHex(num): |
| 983 | return hex(num).split('x')[1] |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 984 | |
| 985 | def getSwitchFlowCount(self, switch): |
| 986 | ''' |
| 987 | return the Flow Count of the switch |
| 988 | ''' |
| 989 | if self.handle: |
| 990 | cmd = "sh ovs-ofctl dump-aggregate %s" % switch |
| 991 | try: |
| 992 | response = self.execute(cmd=cmd, prompt="mininet>", timeout=10) |
| 993 | except pexpect.EOF: |
| 994 | main.log.error(self.name + ": EOF exception found") |
| 995 | main.log.error(self.name + " " + self.handle.before) |
| 996 | main.cleanup() |
| 997 | main.exit() |
| 998 | pattern = "flow_count=(\d+)" |
| 999 | result = re.search(pattern, response, re.MULTILINE) |
| 1000 | if result is None: |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 1001 | main.log.info("Couldn't find flows on switch '', found: %s" % (switch, response)) |
| 1002 | return main.FALSE |
| 1003 | return result.group(1) |
| 1004 | else: |
| 1005 | main.log.error("Connection failed to the Mininet host") |
| 1006 | |
Ahmed El-Hassany | b6545eb | 2014-08-01 11:32:10 -0700 | [diff] [blame] | 1007 | def check_flows(self, sw, dump_format=None): |
| 1008 | if dump_format: |
| 1009 | command = "sh ovs-ofctl -F " + dump_format + " dump-flows " + str(sw) |
| 1010 | else: |
| 1011 | command = "sh ovs-ofctl dump-flows "+str(sw) |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 1012 | try: |
| 1013 | response=self.execute(cmd=command,prompt="mininet>",timeout=10) |
| 1014 | return response |
| 1015 | except pexpect.EOF: |
| 1016 | main.log.error(self.name + ": EOF exception found") |
| 1017 | main.log.error(self.name + ": " + self.handle.before) |
| 1018 | main.cleanup() |
| 1019 | main.exit() |
| 1020 | else: |
| 1021 | main.log.info(response) |
| 1022 | |
| 1023 | def start_tcpdump(self, filename, intf = "eth0", port = "port 6633"): |
| 1024 | ''' |
| 1025 | Runs tpdump on an intferface and saves the file |
| 1026 | intf can be specified, or the default eth0 is used |
| 1027 | ''' |
| 1028 | try: |
| 1029 | self.handle.sendline("") |
| 1030 | self.handle.expect("mininet>") |
| 1031 | self.handle.sendline("sh sudo tcpdump -n -i "+ intf + " " + port + " -w " + filename.strip() + " &") |
| 1032 | self.handle.sendline("") |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 1033 | i=self.handle.expect(['No\ssuch\device','listening\son',pexpect.TIMEOUT,"mininet>"],timeout=10) |
| 1034 | main.log.warn(self.handle.before + self.handle.after) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1035 | self.handle.sendline("") |
| 1036 | self.handle.expect("mininet>") |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 1037 | if i == 0: |
| 1038 | main.log.error(self.name + ": tcpdump - No such device exists. tcpdump attempted on: " + intf) |
| 1039 | return main.FALSE |
| 1040 | elif i == 1: |
| 1041 | main.log.info(self.name + ": tcpdump started on " + intf) |
| 1042 | return main.TRUE |
| 1043 | elif i == 2: |
| 1044 | main.log.error(self.name + ": tcpdump command timed out! Check interface name, given interface was: " + intf) |
| 1045 | return main.FALSE |
| 1046 | elif i ==3: |
| 1047 | main.log.info(self.name +": " + self.handle.before) |
| 1048 | return main.TRUE |
| 1049 | else: |
| 1050 | main.log.error(self.name + ": tcpdump - unexpected response") |
| 1051 | return main.FALSE |
| 1052 | except pexpect.EOF: |
| 1053 | main.log.error(self.name + ": EOF exception found") |
| 1054 | main.log.error(self.name + ": " + self.handle.before) |
| 1055 | main.cleanup() |
| 1056 | main.exit() |
| 1057 | except: |
| 1058 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 1059 | main.log.error( traceback.print_exc() ) |
| 1060 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 1061 | main.cleanup() |
| 1062 | main.exit() |
| 1063 | |
| 1064 | def stop_tcpdump(self): |
| 1065 | "pkills tcpdump" |
| 1066 | try: |
| 1067 | self.handle.sendline("sh sudo pkill tcpdump") |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1068 | self.handle.expect("mininet>") |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 1069 | self.handle.sendline("") |
| 1070 | self.handle.expect("mininet>") |
| 1071 | except pexpect.EOF: |
| 1072 | main.log.error(self.name + ": EOF exception found") |
| 1073 | main.log.error(self.name + ": " + self.handle.before) |
| 1074 | main.cleanup() |
| 1075 | main.exit() |
| 1076 | except: |
| 1077 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 1078 | main.log.error( traceback.print_exc() ) |
| 1079 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 1080 | main.cleanup() |
| 1081 | main.exit() |
| 1082 | |
Jon Hall | 3d87d50 | 2014-10-17 18:37:42 -0400 | [diff] [blame] | 1083 | def compare_switches(self, topo, switches_json): |
| 1084 | ''' |
| 1085 | Compare mn and onos switches |
| 1086 | topo: sts TestONTopology object |
| 1087 | switches_json: parsed json object from the onos devices api |
| 1088 | |
| 1089 | This uses the sts TestONTopology object |
| 1090 | |
| 1091 | ''' |
| 1092 | import json |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1093 | #main.log.debug("Switches_json string: ", switches_json) |
Jon Hall | 3d87d50 | 2014-10-17 18:37:42 -0400 | [diff] [blame] | 1094 | output = {"switches":[]} |
| 1095 | 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] | 1096 | ports = [] |
| 1097 | for port in switch.ports.values(): |
Jon Hall | 3d87d50 | 2014-10-17 18:37:42 -0400 | [diff] [blame] | 1098 | ports.append({'of_port': port.port_no, 'mac': str(port.hw_addr).replace('\'',''), 'name': port.name}) |
| 1099 | 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] | 1100 | |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1101 | #print "mn" |
Jon Hall | 3d87d50 | 2014-10-17 18:37:42 -0400 | [diff] [blame] | 1102 | #print json.dumps(output, sort_keys=True,indent=4,separators=(',', ': ')) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1103 | #print "onos" |
| 1104 | #print json.dumps(switches_json, sort_keys=True,indent=4,separators=(',', ': ')) |
Jon Hall | 3d87d50 | 2014-10-17 18:37:42 -0400 | [diff] [blame] | 1105 | |
| 1106 | |
| 1107 | # created sorted list of dpid's in MN and ONOS for comparison |
| 1108 | mnDPIDs=[] |
| 1109 | for switch in output['switches']: |
Jon Hall | 28bf54b | 2014-12-17 16:25:44 -0800 | [diff] [blame] | 1110 | mnDPIDs.append(switch['dpid'].lower()) |
Jon Hall | 3d87d50 | 2014-10-17 18:37:42 -0400 | [diff] [blame] | 1111 | mnDPIDs.sort() |
Jon Hall | 3848172 | 2014-11-04 16:50:05 -0500 | [diff] [blame] | 1112 | #print "List of Mininet switch DPID's" |
Jon Hall | 3d87d50 | 2014-10-17 18:37:42 -0400 | [diff] [blame] | 1113 | #print mnDPIDs |
| 1114 | if switches_json == "":#if rest call fails |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1115 | 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] | 1116 | return main.FALSE |
| 1117 | onos=switches_json |
| 1118 | onosDPIDs=[] |
| 1119 | for switch in onos: |
Jon Hall | 3848172 | 2014-11-04 16:50:05 -0500 | [diff] [blame] | 1120 | if switch['available'] == True: |
Jon Hall | 28bf54b | 2014-12-17 16:25:44 -0800 | [diff] [blame] | 1121 | onosDPIDs.append(switch['id'].replace(":",'').replace("of",'').lower()) |
Jon Hall | 3848172 | 2014-11-04 16:50:05 -0500 | [diff] [blame] | 1122 | #else: |
| 1123 | #print "Switch is unavailable:" |
| 1124 | #print switch |
Jon Hall | 3d87d50 | 2014-10-17 18:37:42 -0400 | [diff] [blame] | 1125 | onosDPIDs.sort() |
Jon Hall | 3848172 | 2014-11-04 16:50:05 -0500 | [diff] [blame] | 1126 | #print "List of ONOS switch DPID's" |
Jon Hall | 3d87d50 | 2014-10-17 18:37:42 -0400 | [diff] [blame] | 1127 | #print onosDPIDs |
| 1128 | |
| 1129 | if mnDPIDs!=onosDPIDs: |
| 1130 | switch_results = main.FALSE |
| 1131 | main.log.report( "Switches in MN but not in ONOS:") |
| 1132 | main.log.report( str([switch for switch in mnDPIDs if switch not in onosDPIDs])) |
| 1133 | main.log.report( "Switches in ONOS but not in MN:") |
| 1134 | main.log.report( str([switch for switch in onosDPIDs if switch not in mnDPIDs])) |
| 1135 | else:#list of dpid's match in onos and mn |
| 1136 | #main.log.report("DEBUG: The dpid's of the switches in Mininet and ONOS match") |
| 1137 | switch_results = main.TRUE |
| 1138 | return switch_results |
| 1139 | |
| 1140 | |
| 1141 | |
Jon Hall | 72cf1dc | 2014-10-20 21:04:50 -0400 | [diff] [blame] | 1142 | def compare_ports(self, topo, ports_json): |
| 1143 | ''' |
| 1144 | Compare mn and onos ports |
| 1145 | topo: sts TestONTopology object |
| 1146 | ports_json: parsed json object from the onos ports api |
| 1147 | |
| 1148 | Dependencies: |
| 1149 | 1. This uses the sts TestONTopology object |
| 1150 | 2. numpy - "sudo pip install numpy" |
| 1151 | |
| 1152 | ''' |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 1153 | #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] | 1154 | import json |
| 1155 | from numpy import uint64 |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1156 | ports_results = main.TRUE |
Jon Hall | 72cf1dc | 2014-10-20 21:04:50 -0400 | [diff] [blame] | 1157 | output = {"switches":[]} |
| 1158 | 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] | 1159 | ports = [] |
| 1160 | for port in switch.ports.values(): |
| 1161 | #print port.hw_addr.toStr(separator = '') |
Jon Hall | 39f29df | 2014-11-04 19:30:21 -0500 | [diff] [blame] | 1162 | tmp_port = {} |
| 1163 | tmp_port['of_port'] = port.port_no |
| 1164 | tmp_port['mac'] = str(port.hw_addr).replace('\'','') |
| 1165 | tmp_port['name'] = port.name |
| 1166 | tmp_port['enabled'] = port.enabled |
| 1167 | |
| 1168 | ports.append(tmp_port) |
| 1169 | tmp_switch = {} |
| 1170 | tmp_switch['name'] = switch.name |
| 1171 | tmp_switch['dpid'] = str(switch.dpid).zfill(16) |
| 1172 | tmp_switch['ports'] = ports |
| 1173 | |
| 1174 | output['switches'].append(tmp_switch) |
Jon Hall | 72cf1dc | 2014-10-20 21:04:50 -0400 | [diff] [blame] | 1175 | |
| 1176 | |
| 1177 | ################ports############# |
Jon Hall | 39f29df | 2014-11-04 19:30:21 -0500 | [diff] [blame] | 1178 | for mn_switch in output['switches']: |
Jon Hall | 72cf1dc | 2014-10-20 21:04:50 -0400 | [diff] [blame] | 1179 | mn_ports = [] |
| 1180 | onos_ports = [] |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1181 | switch_result = main.TRUE |
Jon Hall | 39f29df | 2014-11-04 19:30:21 -0500 | [diff] [blame] | 1182 | for port in mn_switch['ports']: |
Jon Hall | 3848172 | 2014-11-04 16:50:05 -0500 | [diff] [blame] | 1183 | if port['enabled'] == True: |
| 1184 | mn_ports.append(port['of_port']) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1185 | #else: #DEBUG only |
| 1186 | # 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] | 1187 | for onos_switch in ports_json: |
Jon Hall | 3848172 | 2014-11-04 16:50:05 -0500 | [diff] [blame] | 1188 | #print "Iterating through a new switch as seen by ONOS" |
| 1189 | #print onos_switch |
| 1190 | if onos_switch['device']['available'] == True: |
Jon Hall | 39f29df | 2014-11-04 19:30:21 -0500 | [diff] [blame] | 1191 | if onos_switch['device']['id'].replace(':','').replace("of", '') == mn_switch['dpid']: |
Jon Hall | 3848172 | 2014-11-04 16:50:05 -0500 | [diff] [blame] | 1192 | for port in onos_switch['ports']: |
| 1193 | if port['isEnabled']: |
| 1194 | #print "Iterating through available ports on the switch" |
| 1195 | #print port |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1196 | if port['port'] == 'local': |
| 1197 | #onos_ports.append('local') |
| 1198 | onos_ports.append(long(uint64(-2))) |
| 1199 | else: |
| 1200 | onos_ports.append(int(port['port'])) |
| 1201 | ''' |
| 1202 | else: #This is likely a new reserved port implemented |
| 1203 | main.log.error("unkown port '" + str(port['port']) ) |
| 1204 | ''' |
Jon Hall | 1645caa | 2014-11-18 16:27:14 -0500 | [diff] [blame] | 1205 | #else: #DEBUG |
| 1206 | # 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] | 1207 | break |
Jon Hall | 72cf1dc | 2014-10-20 21:04:50 -0400 | [diff] [blame] | 1208 | mn_ports.sort(key=float) |
| 1209 | onos_ports.sort(key=float) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1210 | #print "\nPorts for Switch %s:" % (mn_switch['name']) |
Jon Hall | 72cf1dc | 2014-10-20 21:04:50 -0400 | [diff] [blame] | 1211 | #print "\tmn_ports[] = ", mn_ports |
| 1212 | #print "\tonos_ports[] = ", onos_ports |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1213 | mn_ports_log = mn_ports |
| 1214 | onos_ports_log = onos_ports |
| 1215 | mn_ports = [x for x in mn_ports] |
| 1216 | onos_ports = [x for x in onos_ports] |
Jon Hall | 3848172 | 2014-11-04 16:50:05 -0500 | [diff] [blame] | 1217 | |
Jon Hall | 72cf1dc | 2014-10-20 21:04:50 -0400 | [diff] [blame] | 1218 | #TODO: handle other reserved port numbers besides LOCAL |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1219 | #NOTE: Reserved ports |
| 1220 | # Local port: -2 in Openflow, ONOS shows 'local', we store as long(uint64(-2)) |
| 1221 | for mn_port in mn_ports_log: |
| 1222 | if mn_port in onos_ports: |
Jon Hall | 72cf1dc | 2014-10-20 21:04:50 -0400 | [diff] [blame] | 1223 | #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] | 1224 | mn_ports.remove(mn_port) |
| 1225 | onos_ports.remove(mn_port) |
| 1226 | #NOTE: OVS reports this as down since there is no link |
| 1227 | # So ignoring these for now |
| 1228 | #TODO: Come up with a better way of handling these |
| 1229 | if 65534 in mn_ports: |
| 1230 | mn_ports.remove(65534) |
| 1231 | if long(uint64(-2)) in onos_ports: |
| 1232 | onos_ports.remove( long(uint64(-2)) ) |
| 1233 | if len(mn_ports): #the ports of this switch don't match |
| 1234 | switch_result = main.FALSE |
| 1235 | main.log.warn("Ports in MN but not ONOS: " + str(mn_ports) ) |
| 1236 | if len(onos_ports): #the ports of this switch don't match |
| 1237 | switch_result = main.FALSE |
| 1238 | main.log.warn("Ports in ONOS but not MN: " + str(onos_ports) ) |
| 1239 | if switch_result == main.FALSE: |
Jon Hall | 39f29df | 2014-11-04 19:30:21 -0500 | [diff] [blame] | 1240 | 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] | 1241 | main.log.warn("mn_ports[] = " + str(mn_ports_log)) |
| 1242 | main.log.warn("onos_ports[] = " + str(onos_ports_log)) |
| 1243 | ports_results = ports_results and switch_result |
| 1244 | return ports_results |
Jon Hall | 72cf1dc | 2014-10-20 21:04:50 -0400 | [diff] [blame] | 1245 | |
| 1246 | |
| 1247 | |
| 1248 | |
| 1249 | def compare_links(self, topo, links_json): |
| 1250 | ''' |
| 1251 | Compare mn and onos links |
| 1252 | topo: sts TestONTopology object |
| 1253 | links_json: parsed json object from the onos links api |
| 1254 | |
| 1255 | This uses the sts TestONTopology object |
| 1256 | |
| 1257 | ''' |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 1258 | #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] | 1259 | import json |
| 1260 | link_results = main.TRUE |
| 1261 | output = {"switches":[]} |
| 1262 | onos = links_json |
| 1263 | 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] | 1264 | # print "Iterating though switches as seen by Mininet" |
| 1265 | # print switch |
Jon Hall | 72cf1dc | 2014-10-20 21:04:50 -0400 | [diff] [blame] | 1266 | ports = [] |
| 1267 | for port in switch.ports.values(): |
| 1268 | #print port.hw_addr.toStr(separator = '') |
| 1269 | ports.append({'of_port': port.port_no, 'mac': str(port.hw_addr).replace('\'',''), 'name': port.name}) |
| 1270 | output['switches'].append({"name": switch.name, "dpid": str(switch.dpid).zfill(16), "ports": ports }) |
| 1271 | #######Links######## |
| 1272 | |
Jon Hall | 3848172 | 2014-11-04 16:50:05 -0500 | [diff] [blame] | 1273 | mn_links = [link for link in topo.patch_panel.network_links if (link.port1.enabled and link.port2.enabled)] |
| 1274 | #print "mn_links:" |
| 1275 | #print mn_links |
| 1276 | if 2*len(mn_links) == len(onos): |
Jon Hall | 72cf1dc | 2014-10-20 21:04:50 -0400 | [diff] [blame] | 1277 | link_results = main.TRUE |
| 1278 | else: |
| 1279 | link_results = main.FALSE |
Jon Hall | 3848172 | 2014-11-04 16:50:05 -0500 | [diff] [blame] | 1280 | 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] | 1281 | |
| 1282 | |
| 1283 | # iterate through MN links and check if an ONOS link exists in both directions |
| 1284 | # NOTE: Will currently only show mn links as down if they are cut through STS. |
| 1285 | # We can either do everything through STS or wait for up_network_links |
| 1286 | # and down_network_links to be fully implemented. |
Jon Hall | 3848172 | 2014-11-04 16:50:05 -0500 | [diff] [blame] | 1287 | for link in mn_links: |
Jon Hall | 72cf1dc | 2014-10-20 21:04:50 -0400 | [diff] [blame] | 1288 | #print "Link: %s" % link |
| 1289 | #TODO: Find a more efficient search method |
| 1290 | node1 = None |
| 1291 | port1 = None |
| 1292 | node2 = None |
| 1293 | port2 = None |
| 1294 | first_dir = main.FALSE |
| 1295 | second_dir = main.FALSE |
| 1296 | for switch in output['switches']: |
| 1297 | #print "Switch: %s" % switch['name'] |
| 1298 | if switch['name'] == link.node1.name: |
| 1299 | node1 = switch['dpid'] |
| 1300 | for port in switch['ports']: |
| 1301 | if str(port['name']) == str(link.port1): |
| 1302 | port1 = port['of_port'] |
| 1303 | if node1 is not None and node2 is not None: |
| 1304 | break |
| 1305 | if switch['name'] == link.node2.name: |
| 1306 | node2 = switch['dpid'] |
| 1307 | for port in switch['ports']: |
| 1308 | if str(port['name']) == str(link.port2): |
| 1309 | port2 = port['of_port'] |
| 1310 | if node1 is not None and node2 is not None: |
| 1311 | break |
| 1312 | |
| 1313 | |
| 1314 | for onos_link in onos: |
| 1315 | onos_node1 = onos_link['src']['device'].replace(":",'').replace("of", '') |
| 1316 | onos_node2 = onos_link['dst']['device'].replace(":",'').replace("of", '') |
| 1317 | onos_port1 = onos_link['src']['port'] |
| 1318 | onos_port2 = onos_link['dst']['port'] |
| 1319 | |
| 1320 | #print "Checking ONOS for link %s/%s -> %s/%s and" % (node1, port1, node2, port2) |
| 1321 | #print "Checking ONOS for link %s/%s -> %s/%s" % (node2, port2, node1, port1) |
| 1322 | # check onos link from node1 to node2 |
| 1323 | if str(onos_node1) == str(node1) and str(onos_node2) == str(node2): |
| 1324 | if int(onos_port1) == int(port1) and int(onos_port2) == int(port2): |
| 1325 | first_dir = main.TRUE |
| 1326 | else: |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1327 | main.log.warn('The port numbers do not match for ' +str(link) +\ |
Jon Hall | 72cf1dc | 2014-10-20 21:04:50 -0400 | [diff] [blame] | 1328 | ' between ONOS and MN. When cheking ONOS for link '+\ |
| 1329 | '%s/%s -> %s/%s' % (node1, port1, node2, port2)+\ |
| 1330 | ' ONOS has the values %s/%s -> %s/%s' %\ |
| 1331 | (onos_node1, onos_port1, onos_node2, onos_port2)) |
| 1332 | |
| 1333 | # check onos link from node2 to node1 |
| 1334 | elif ( str(onos_node1) == str(node2) and str(onos_node2) == str(node1) ): |
| 1335 | if ( int(onos_port1) == int(port2) and int(onos_port2) == int(port1) ): |
| 1336 | second_dir = main.TRUE |
| 1337 | else: |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1338 | main.log.warn('The port numbers do not match for ' +str(link) +\ |
Jon Hall | 72cf1dc | 2014-10-20 21:04:50 -0400 | [diff] [blame] | 1339 | ' between ONOS and MN. When cheking ONOS for link '+\ |
| 1340 | '%s/%s -> %s/%s' % (node2, port2, node1, port1)+\ |
| 1341 | ' ONOS has the values %s/%s -> %s/%s' %\ |
| 1342 | (onos_node2, onos_port2, onos_node1, onos_port1)) |
| 1343 | else:#this is not the link you're looking for |
| 1344 | pass |
| 1345 | if not first_dir: |
| 1346 | main.log.report('ONOS does not have the link %s/%s -> %s/%s' % (node1, port1, node2, port2)) |
| 1347 | if not second_dir: |
| 1348 | main.log.report('ONOS does not have the link %s/%s -> %s/%s' % (node2, port2, node1, port1)) |
| 1349 | link_results = link_results and first_dir and second_dir |
Jon Hall | 62df924 | 2014-10-22 12:20:17 -0400 | [diff] [blame] | 1350 | return link_results |
Jon Hall | 72cf1dc | 2014-10-20 21:04:50 -0400 | [diff] [blame] | 1351 | |
| 1352 | |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1353 | def get_hosts(self): |
| 1354 | ''' |
| 1355 | Returns a list of all hosts |
| 1356 | Don't ask questions just use it |
| 1357 | ''' |
| 1358 | self.handle.sendline("") |
| 1359 | self.handle.expect("mininet>") |
| 1360 | |
| 1361 | self.handle.sendline("py [ host.name for host in net.hosts ]") |
| 1362 | self.handle.expect("mininet>") |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 1363 | |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1364 | handle_py = self.handle.before |
| 1365 | handle_py = handle_py.split("]\r\n",1)[1] |
| 1366 | handle_py = handle_py.rstrip() |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 1367 | |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1368 | self.handle.sendline("") |
| 1369 | self.handle.expect("mininet>") |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 1370 | |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1371 | host_str = handle_py.replace("]", "") |
| 1372 | host_str = host_str.replace("'", "") |
| 1373 | host_str = host_str.replace("[", "") |
| 1374 | host_list = host_str.split(",") |
| 1375 | |
| 1376 | return host_list |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 1377 | |
Jon Hall | 3848172 | 2014-11-04 16:50:05 -0500 | [diff] [blame] | 1378 | |
| 1379 | def update(self): |
| 1380 | ''' |
| 1381 | updates the port address and status information for each port in mn |
| 1382 | ''' |
| 1383 | #TODO: Add error checking. currently the mininet command has no output |
| 1384 | main.log.info("Updateing MN port information") |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1385 | try: |
| 1386 | self.handle.sendline("") |
| 1387 | self.handle.expect("mininet>") |
Jon Hall | 3848172 | 2014-11-04 16:50:05 -0500 | [diff] [blame] | 1388 | |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1389 | self.handle.sendline("update") |
| 1390 | self.handle.expect("update") |
| 1391 | self.handle.expect("mininet>") |
Jon Hall | 3848172 | 2014-11-04 16:50:05 -0500 | [diff] [blame] | 1392 | |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1393 | self.handle.sendline("") |
| 1394 | self.handle.expect("mininet>") |
Jon Hall | 3848172 | 2014-11-04 16:50:05 -0500 | [diff] [blame] | 1395 | |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1396 | return main.TRUE |
| 1397 | except pexpect.EOF: |
| 1398 | main.log.error(self.name + ": EOF exception found") |
| 1399 | main.log.error(self.name + ": " + self.handle.before) |
| 1400 | main.cleanup() |
| 1401 | main.exit() |
| 1402 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 1403 | if __name__ != "__main__": |
| 1404 | import sys |
| 1405 | sys.modules[__name__] = MininetCliDriver() |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 1406 | |