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("../") |
| 34 | from drivers.common.cli.emulatordriver import Emulator |
| 35 | from drivers.common.clidriver import CLI |
| 36 | |
| 37 | class MininetCliDriver(Emulator): |
| 38 | ''' |
Jon Hall | 41f40e8 | 2014-04-08 16:43:17 -0700 | [diff] [blame] | 39 | MininetCliDriver is the basic driver which will handle the Mininet functions |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 40 | ''' |
| 41 | def __init__(self): |
| 42 | super(Emulator, self).__init__() |
| 43 | self.handle = self |
| 44 | self.wrapped = sys.modules[__name__] |
| 45 | self.flag = 0 |
| 46 | |
| 47 | def connect(self, **connectargs): |
Jon Hall | 41f40e8 | 2014-04-08 16:43:17 -0700 | [diff] [blame] | 48 | ''' |
| 49 | Here the main is the TestON instance after creating all the log handles. |
| 50 | ''' |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 51 | for key in connectargs: |
| 52 | vars(self)[key] = connectargs[key] |
| 53 | |
| 54 | self.name = self.options['name'] |
| 55 | self.handle = super(MininetCliDriver, self).connect(user_name = self.user_name, ip_address = self.ip_address,port = None, pwd = self.pwd) |
| 56 | |
| 57 | self.ssh_handle = self.handle |
| 58 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 59 | if self.handle : |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 60 | main.log.info(self.name+": Clearing any residual state or processes") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 61 | self.handle.sendline("sudo mn -c") |
admin | f939f8b | 2014-04-03 17:22:56 -0700 | [diff] [blame] | 62 | 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] | 63 | if i==0: |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 64 | main.log.info(self.name+": Sending sudo password") |
admin | f939f8b | 2014-04-03 17:22:56 -0700 | [diff] [blame] | 65 | self.handle.sendline(self.pwd) |
| 66 | i=self.handle.expect(['%s:'%(self.user),'\$',pexpect.EOF,pexpect.TIMEOUT],120) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 67 | if i==1: |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 68 | main.log.info(self.name+": Clean") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 69 | elif i==2: |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 70 | main.log.error(self.name+": Connection terminated") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 71 | elif i==3: #timeout |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 72 | main.log.error(self.name+": Something while cleaning MN took too long... " ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 73 | |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 74 | main.log.info(self.name+": building fresh mininet") |
admin | beea003 | 2014-01-23 14:54:13 -0800 | [diff] [blame] | 75 | #### for reactive/PARP enabled tests |
admin | 0752993 | 2013-11-22 14:58:28 -0800 | [diff] [blame] | 76 | cmdString = "sudo mn " + self.options['arg1'] + " " + self.options['arg2'] + " --mac --controller " + self.options['controller'] |
admin | beea003 | 2014-01-23 14:54:13 -0800 | [diff] [blame] | 77 | #### for proactive flow with static ARP entries |
| 78 | #cmdString = "sudo mn " + self.options['arg1'] + " " + self.options['arg2'] + " --mac --arp --controller " + self.options['controller'] |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 79 | self.handle.sendline(cmdString) |
Jon Hall | 333fa8c | 2014-04-11 11:24:58 -0700 | [diff] [blame] | 80 | self.handle.expect(["sudo mn",pexpect.EOF,pexpect.TIMEOUT]) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 81 | while 1: |
| 82 | i=self.handle.expect(['mininet>','\*\*\*','Exception',pexpect.EOF,pexpect.TIMEOUT],300) |
| 83 | if i==0: |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 84 | main.log.info(self.name+": mininet built") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 85 | return main.TRUE |
| 86 | if i==1: |
Jon Hall | 333fa8c | 2014-04-11 11:24:58 -0700 | [diff] [blame] | 87 | self.handle.expect(["\n",pexpect.EOF,pexpect.TIMEOUT]) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 88 | main.log.info(self.handle.before) |
| 89 | elif i==2: |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 90 | main.log.error(self.name+": Launching mininet failed...") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 91 | return main.FALSE |
| 92 | elif i==3: |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 93 | main.log.error(self.name+": Connection timeout") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 94 | return main.FALSE |
| 95 | elif i==4: #timeout |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 96 | main.log.error(self.name+": Something took too long... " ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 97 | return main.FALSE |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 98 | #if utilities.assert_matches(expect=patterns,actual=resultCommand,onpass="Network is being launched",onfail="Network launching is being failed "): |
| 99 | return main.TRUE |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 100 | else:#if no handle |
| 101 | main.log.error(self.name+": Connection failed to the host "+self.user_name+"@"+self.ip_address) |
| 102 | main.log.error(self.name+": Failed to connect to the Mininet") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 103 | return main.FALSE |
| 104 | |
| 105 | def pingall(self): |
| 106 | ''' |
Jon Hall | 41f40e8 | 2014-04-08 16:43:17 -0700 | [diff] [blame] | 107 | Verifies the reachability of the hosts using pingall command. |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 108 | ''' |
| 109 | if self.handle : |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 110 | main.log.info(self.name+": Checking reachabilty to the hosts using pingall") |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 111 | try: |
Jon Hall | efa4fa1 | 2014-04-14 11:40:21 -0700 | [diff] [blame] | 112 | response = self.execute(cmd="pingall",prompt="mininet>",timeout=120) |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 113 | except pexpect.EOF: |
| 114 | main.log.error(self.name + ": EOF exception found") |
| 115 | main.log.error(self.name + ": " + self.handle.before) |
| 116 | main.cleanup() |
| 117 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 118 | pattern = 'Results\:\s0\%\sdropped\s\(0\/\d+\slost\)\s*$' |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 119 | #if utilities.assert_matches(expect=pattern,actual=response,onpass="All hosts are reaching",onfail="Unable to reach all the hosts"): |
| 120 | if re.search(pattern,response): |
| 121 | main.log.info(self.name+": All hosts are reachable") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 122 | return main.TRUE |
| 123 | else: |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 124 | main.log.error(self.name+": Unable to reach all the hosts") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 125 | return main.FALSE |
| 126 | else : |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 127 | main.log.error(self.name+": Connection failed to the host") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 128 | return main.FALSE |
admin | aeedddd | 2013-08-02 15:14:15 -0700 | [diff] [blame] | 129 | |
| 130 | def fpingHost(self,**pingParams): |
| 131 | ''' |
| 132 | Uses the fping package for faster pinging... |
| 133 | *requires fping to be installed on machine running mininet |
| 134 | ''' |
| 135 | args = utilities.parse_args(["SRC","TARGET"],**pingParams) |
admin | 530b4c9 | 2013-08-14 16:54:35 -0700 | [diff] [blame] | 136 | command = args["SRC"] + " fping -i 100 -t 20 -C 1 -q "+args["TARGET"] |
admin | aeedddd | 2013-08-02 15:14:15 -0700 | [diff] [blame] | 137 | self.handle.sendline(command) |
Jon Hall | 333fa8c | 2014-04-11 11:24:58 -0700 | [diff] [blame] | 138 | self.handle.expect([args["TARGET"],pexpect.EOF,pexpect.TIMEOUT]) |
| 139 | self.handle.expect(["mininet",pexpect.EOF,pexpect.TIMEOUT]) |
admin | aeedddd | 2013-08-02 15:14:15 -0700 | [diff] [blame] | 140 | response = self.handle.before |
| 141 | if re.search(":\s-" ,response): |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 142 | main.log.info(self.name+": Ping fail") |
admin | aeedddd | 2013-08-02 15:14:15 -0700 | [diff] [blame] | 143 | return main.FALSE |
admin | 530b4c9 | 2013-08-14 16:54:35 -0700 | [diff] [blame] | 144 | elif re.search(":\s\d{1,2}\.\d\d", response): |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 145 | main.log.info(self.name+": Ping good!") |
admin | aeedddd | 2013-08-02 15:14:15 -0700 | [diff] [blame] | 146 | return main.TRUE |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 147 | main.log.info(self.name+": Install fping on mininet machine... ") |
| 148 | main.log.info(self.name+": \n---\n"+response) |
admin | aeedddd | 2013-08-02 15:14:15 -0700 | [diff] [blame] | 149 | return main.FALSE |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 150 | |
| 151 | def pingHost(self,**pingParams): |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 152 | ''' |
| 153 | Ping from one mininet host to another |
| 154 | Currently the only supported Params: SRC and TARGET |
| 155 | ''' |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 156 | args = utilities.parse_args(["SRC","TARGET"],**pingParams) |
| 157 | #command = args["SRC"] + " ping -" + args["CONTROLLER"] + " " +args ["TARGET"] |
Jon Hall | 0819fd9 | 2014-05-23 12:08:13 -0700 | [diff] [blame] | 158 | command = args["SRC"] + " ping "+args ["TARGET"]+" -c 1 -i 1 -W 8" |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 159 | try: |
Jon Hall | 6e18c7b | 2014-04-23 16:26:33 -0700 | [diff] [blame] | 160 | main.log.warn("Sending: " + command) |
| 161 | #response = self.execute(cmd=command,prompt="mininet",timeout=10 ) |
| 162 | self.handle.sendline(command) |
| 163 | i = self.handle.expect([command,pexpect.TIMEOUT]) |
| 164 | if i == 1: |
| 165 | main.log.error(self.name + ": timeout when waiting for response from mininet") |
| 166 | main.log.error("response: " + str(self.handle.before)) |
| 167 | i = self.handle.expect(["mininet>",pexpect.TIMEOUT]) |
| 168 | if i == 1: |
| 169 | main.log.error(self.name + ": timeout when waiting for response from mininet") |
| 170 | main.log.error("response: " + str(self.handle.before)) |
| 171 | response = self.handle.before |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 172 | except pexpect.EOF: |
| 173 | main.log.error(self.name + ": EOF exception found") |
| 174 | main.log.error(self.name + ": " + self.handle.before) |
| 175 | main.cleanup() |
| 176 | main.exit() |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 177 | main.log.info(self.name+": Ping Response: "+ response ) |
| 178 | #if utilities.assert_matches(expect=',\s0\%\spacket\sloss',actual=response,onpass="No Packet loss",onfail="Host is not reachable"): |
| 179 | if re.search(',\s0\%\spacket\sloss',response): |
Jon Hall | 6e18c7b | 2014-04-23 16:26:33 -0700 | [diff] [blame] | 180 | main.log.info(self.name+": no packets lost, host is reachable") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 181 | main.last_result = main.TRUE |
| 182 | return main.TRUE |
| 183 | else : |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 184 | main.log.error(self.name+": PACKET LOST, HOST IS NOT REACHABLE") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 185 | main.last_result = main.FALSE |
| 186 | return main.FALSE |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 187 | |
| 188 | def checkIP(self,host): |
| 189 | ''' |
Jon Hall | 41f40e8 | 2014-04-08 16:43:17 -0700 | [diff] [blame] | 190 | Verifies the host's ip configured or not. |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 191 | ''' |
| 192 | if self.handle : |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 193 | try: |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 194 | self.handle.sendline("") |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 195 | response = self.execute(cmd=host+" ifconfig",prompt="mininet>",timeout=10) |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 196 | print(str(self.handle.before)) |
| 197 | print(str(self.handle.after)) |
| 198 | print(response) |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 199 | except pexpect.EOF: |
| 200 | main.log.error(self.name + ": EOF exception found") |
| 201 | main.log.error(self.name + ": " + self.handle.before) |
| 202 | main.cleanup() |
| 203 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 204 | |
| 205 | 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] | 206 | #pattern = "inet addr:10.0.0.6" |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 207 | #if utilities.assert_matches(expect=pattern,actual=response,onpass="Host Ip configured properly",onfail="Host IP not found") : |
| 208 | if re.search(pattern,response): |
| 209 | main.log.info(self.name+": Host Ip configured properly") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 210 | return main.TRUE |
| 211 | else: |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 212 | main.log.error(self.name+": Host IP not found") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 213 | return main.FALSE |
| 214 | else : |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 215 | main.log.error(self.name+": Connection failed to the host") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 216 | |
| 217 | def verifySSH(self,**connectargs): |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 218 | try: |
| 219 | response = self.execute(cmd="h1 /usr/sbin/sshd -D&",prompt="mininet>",timeout=10) |
| 220 | response = self.execute(cmd="h4 /usr/sbin/sshd -D&",prompt="mininet>",timeout=10) |
| 221 | for key in connectargs: |
| 222 | vars(self)[key] = connectargs[key] |
| 223 | response = self.execute(cmd="xterm h1 h4 ",prompt="mininet>",timeout=10) |
| 224 | except pexpect.EOF: |
| 225 | main.log.error(self.name + ": EOF exception found") |
| 226 | main.log.error(self.name + ": " + self.handle.before) |
| 227 | main.cleanup() |
| 228 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 229 | import time |
| 230 | time.sleep(20) |
| 231 | if self.flag == 0: |
| 232 | self.flag = 1 |
| 233 | return main.FALSE |
| 234 | else : |
| 235 | return main.TRUE |
| 236 | |
| 237 | def getMacAddress(self,host): |
| 238 | ''' |
Jon Hall | 41f40e8 | 2014-04-08 16:43:17 -0700 | [diff] [blame] | 239 | Verifies the host's ip configured or not. |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 240 | ''' |
| 241 | if self.handle : |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 242 | try: |
| 243 | response = self.execute(cmd=host+" ifconfig",prompt="mininet>",timeout=10) |
| 244 | except pexpect.EOF: |
| 245 | main.log.error(self.name + ": EOF exception found") |
| 246 | main.log.error(self.name + ": " + self.handle.before) |
| 247 | main.cleanup() |
| 248 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 249 | |
Ahmed El-Hassany | f720e20 | 2014-04-04 16:11:36 -0700 | [diff] [blame] | 250 | pattern = r'HWaddr\s([0-9A-F]{2}[:-]){5}([0-9A-F]{2})' |
| 251 | mac_address_search = re.search(pattern, response, re.I) |
| 252 | mac_address = mac_address_search.group().split(" ")[1] |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 253 | 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] | 254 | return mac_address |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 255 | else : |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 256 | main.log.error(self.name+": Connection failed to the host") |
Ahmed El-Hassany | fd32918 | 2014-04-10 11:38:16 -0700 | [diff] [blame] | 257 | |
| 258 | def getInterfaceMACAddress(self,host, interface): |
| 259 | ''' |
| 260 | Return the IP address of the interface on the given host |
| 261 | ''' |
| 262 | if self.handle : |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 263 | try: |
| 264 | response = self.execute(cmd=host+" ifconfig " + interface, |
Ahmed El-Hassany | fd32918 | 2014-04-10 11:38:16 -0700 | [diff] [blame] | 265 | prompt="mininet>",timeout=10) |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 266 | except pexpect.EOF: |
| 267 | main.log.error(self.name + ": EOF exception found") |
| 268 | main.log.error(self.name + ": " + self.handle.before) |
| 269 | main.cleanup() |
| 270 | main.exit() |
Ahmed El-Hassany | fd32918 | 2014-04-10 11:38:16 -0700 | [diff] [blame] | 271 | |
| 272 | pattern = r'HWaddr\s([0-9A-F]{2}[:-]){5}([0-9A-F]{2})' |
| 273 | mac_address_search = re.search(pattern, response, re.I) |
| 274 | if mac_address_search is None: |
| 275 | main.log.info("No mac address found in %s" % response) |
| 276 | return main.FALSE |
| 277 | mac_address = mac_address_search.group().split(" ")[1] |
| 278 | main.log.info("Mac-Address of "+ host + ":"+ interface + " is " + mac_address) |
| 279 | return mac_address |
| 280 | else: |
| 281 | main.log.error("Connection failed to the host") |
| 282 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 283 | def getIPAddress(self,host): |
| 284 | ''' |
Jon Hall | 41f40e8 | 2014-04-08 16:43:17 -0700 | [diff] [blame] | 285 | Verifies the host's ip configured or not. |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 286 | ''' |
| 287 | if self.handle : |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 288 | try: |
| 289 | response = self.execute(cmd=host+" ifconfig",prompt="mininet>",timeout=10) |
| 290 | except pexpect.EOF: |
| 291 | main.log.error(self.name + ": EOF exception found") |
| 292 | main.log.error(self.name + ": " + self.handle.before) |
| 293 | main.cleanup() |
| 294 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 295 | |
| 296 | pattern = "inet\saddr:(\d+\.\d+\.\d+\.\d+)" |
| 297 | ip_address_search = re.search(pattern, response) |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 298 | 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] | 299 | return ip_address_search.group(1) |
| 300 | else : |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 301 | main.log.error(self.name+": Connection failed to the host") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 302 | |
Ahmed El-Hassany | fd32918 | 2014-04-10 11:38:16 -0700 | [diff] [blame] | 303 | def getSwitchDPID(self,switch): |
| 304 | ''' |
| 305 | return the datapath ID of the switch |
| 306 | ''' |
| 307 | if self.handle : |
| 308 | cmd = "py %s.dpid" % switch |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 309 | try: |
| 310 | response = self.execute(cmd=cmd,prompt="mininet>",timeout=10) |
| 311 | except pexpect.EOF: |
| 312 | main.log.error(self.name + ": EOF exception found") |
| 313 | main.log.error(self.name + ": " + self.handle.before) |
| 314 | main.cleanup() |
| 315 | main.exit() |
Ahmed El-Hassany | fd32918 | 2014-04-10 11:38:16 -0700 | [diff] [blame] | 316 | pattern = r'^(?P<dpid>\d)+' |
| 317 | result = re.search(pattern, response, re.MULTILINE) |
| 318 | if result is None: |
| 319 | main.log.info("Couldn't find DPID for switch '', found: %s" % (switch, response)) |
| 320 | return main.FALSE |
| 321 | return int(result.group('dpid')) |
| 322 | else: |
| 323 | main.log.error("Connection failed to the host") |
| 324 | |
| 325 | def getInterfaces(self, node): |
| 326 | ''' |
| 327 | return information dict about interfaces connected to the node |
| 328 | ''' |
| 329 | if self.handle : |
| 330 | cmd = 'py "\\n".join(["name=%s,mac=%s,ip=%s,isUp=%s" % (i.name, i.MAC(), i.IP(), i.isUp())' |
| 331 | cmd += ' for i in %s.intfs.values()])' % node |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 332 | try: |
| 333 | response = self.execute(cmd=cmd,prompt="mininet>",timeout=10) |
| 334 | except pexpect.EOF: |
| 335 | main.log.error(self.name + ": EOF exception found") |
| 336 | main.log.error(self.name + ": " + self.handle.before) |
| 337 | main.cleanup() |
| 338 | main.exit() |
Ahmed El-Hassany | fd32918 | 2014-04-10 11:38:16 -0700 | [diff] [blame] | 339 | return response |
| 340 | else: |
| 341 | main.log.error("Connection failed to the node") |
| 342 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 343 | def dump(self): |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 344 | main.log.info(self.name+": Dump node info") |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 345 | try: |
| 346 | response = self.execute(cmd = 'dump',prompt = 'mininet>',timeout = 10) |
| 347 | except pexpect.EOF: |
| 348 | main.log.error(self.name + ": EOF exception found") |
| 349 | main.log.error(self.name + ": " + self.handle.before) |
| 350 | main.cleanup() |
| 351 | main.exit() |
Ahmed El-Hassany | d1f7170 | 2014-04-04 16:12:45 -0700 | [diff] [blame] | 352 | return response |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 353 | |
| 354 | def intfs(self): |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 355 | main.log.info(self.name+": List interfaces") |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 356 | try: |
| 357 | response = self.execute(cmd = 'intfs',prompt = 'mininet>',timeout = 10) |
| 358 | except pexpect.EOF: |
| 359 | main.log.error(self.name + ": EOF exception found") |
| 360 | main.log.error(self.name + ": " + self.handle.before) |
| 361 | main.cleanup() |
| 362 | main.exit() |
Jon Hall | 668ed80 | 2014-04-08 17:17:59 -0700 | [diff] [blame] | 363 | return response |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 364 | |
| 365 | def net(self): |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 366 | main.log.info(self.name+": List network connections") |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 367 | try: |
| 368 | response = self.execute(cmd = 'net',prompt = 'mininet>',timeout = 10) |
| 369 | except pexpect.EOF: |
| 370 | main.log.error(self.name + ": EOF exception found") |
| 371 | main.log.error(self.name + ": " + self.handle.before) |
| 372 | main.cleanup() |
| 373 | main.exit() |
Jon Hall | 668ed80 | 2014-04-08 17:17:59 -0700 | [diff] [blame] | 374 | return response |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 375 | |
| 376 | def iperf(self): |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 377 | 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] | 378 | try: |
| 379 | response = self.execute(cmd = 'iperf',prompt = 'mininet>',timeout = 10) |
| 380 | except pexpect.EOF: |
| 381 | main.log.error(self.name + ": EOF exception found") |
| 382 | main.log.error(self.name + ": " + self.handle.before) |
| 383 | main.cleanup() |
| 384 | main.exit() |
Jon Hall | 668ed80 | 2014-04-08 17:17:59 -0700 | [diff] [blame] | 385 | return response |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 386 | |
| 387 | def iperfudp(self): |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 388 | 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] | 389 | try: |
| 390 | response = self.execute(cmd = 'iperfudp',prompt = 'mininet>',timeout = 10) |
| 391 | except pexpect.EOF: |
| 392 | main.log.error(self.name + ": EOF exception found") |
| 393 | main.log.error(self.name + ": " + self.handle.before) |
| 394 | main.cleanup() |
| 395 | main.exit() |
Jon Hall | 668ed80 | 2014-04-08 17:17:59 -0700 | [diff] [blame] | 396 | return response |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 397 | |
| 398 | def nodes(self): |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 399 | main.log.info(self.name+": List all nodes.") |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 400 | try: |
| 401 | response = self.execute(cmd = 'nodes',prompt = 'mininet>',timeout = 10) |
| 402 | except pexpect.EOF: |
| 403 | main.log.error(self.name + ": EOF exception found") |
| 404 | main.log.error(self.name + ": " + self.handle.before) |
| 405 | main.cleanup() |
| 406 | main.exit() |
Jon Hall | 668ed80 | 2014-04-08 17:17:59 -0700 | [diff] [blame] | 407 | return response |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 408 | |
| 409 | def pingpair(self): |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 410 | main.log.info(self.name+": Ping between first two hosts") |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 411 | try: |
| 412 | response = self.execute(cmd = 'pingpair',prompt = 'mininet>',timeout = 20) |
| 413 | except pexpect.EOF: |
| 414 | main.log.error(self.name + ": EOF exception found") |
| 415 | main.log.error(self.name + ": " + self.handle.before) |
| 416 | main.cleanup() |
| 417 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 418 | |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 419 | #if utilities.assert_matches(expect='0% packet loss',actual=response,onpass="No Packet loss",onfail="Hosts not reachable"): |
| 420 | if re.search(',\s0\%\spacket\sloss',response): |
| 421 | main.log.info(self.name+": Ping between two hosts SUCCESSFUL") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 422 | main.last_result = main.TRUE |
| 423 | return main.TRUE |
| 424 | else : |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 425 | main.log.error(self.name+": PACKET LOST, HOSTS NOT REACHABLE") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 426 | main.last_result = main.FALSE |
| 427 | return main.FALSE |
| 428 | |
| 429 | def link(self,**linkargs): |
| 430 | ''' |
| 431 | Bring link(s) between two nodes up or down |
| 432 | ''' |
| 433 | main.log.info('Bring link(s) between two nodes up or down') |
| 434 | args = utilities.parse_args(["END1","END2","OPTION"],**linkargs) |
| 435 | end1 = args["END1"] if args["END1"] != None else "" |
| 436 | end2 = args["END2"] if args["END2"] != None else "" |
| 437 | option = args["OPTION"] if args["OPTION"] != None else "" |
| 438 | command = "link "+str(end1) + " " + str(end2)+ " " + str(option) |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 439 | try: |
Jon Hall | e80ef8c | 2014-04-29 15:29:13 -0700 | [diff] [blame] | 440 | #response = self.execute(cmd=command,prompt="mininet>",timeout=10) |
| 441 | self.handle.sendline(command) |
| 442 | self.handle.expect("mininet>") |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 443 | except pexpect.EOF: |
| 444 | main.log.error(self.name + ": EOF exception found") |
| 445 | main.log.error(self.name + ": " + self.handle.before) |
| 446 | main.cleanup() |
| 447 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 448 | return main.TRUE |
| 449 | |
| 450 | |
admin | 530b4c9 | 2013-08-14 16:54:35 -0700 | [diff] [blame] | 451 | def yank(self,**yankargs): |
admin | aeedddd | 2013-08-02 15:14:15 -0700 | [diff] [blame] | 452 | ''' |
admin | 530b4c9 | 2013-08-14 16:54:35 -0700 | [diff] [blame] | 453 | yank a mininet switch interface to a host |
admin | aeedddd | 2013-08-02 15:14:15 -0700 | [diff] [blame] | 454 | ''' |
admin | 530b4c9 | 2013-08-14 16:54:35 -0700 | [diff] [blame] | 455 | main.log.info('Yank the switch interface attached to a host') |
| 456 | args = utilities.parse_args(["SW","INTF"],**yankargs) |
admin | aeedddd | 2013-08-02 15:14:15 -0700 | [diff] [blame] | 457 | sw = args["SW"] if args["SW"] !=None else "" |
| 458 | intf = args["INTF"] if args["INTF"] != None else "" |
| 459 | command = "py "+ str(sw) + '.detach("' + str(intf) + '")' |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 460 | try: |
| 461 | response = self.execute(cmd=command,prompt="mininet>",timeout=10) |
| 462 | except pexpect.EOF: |
| 463 | main.log.error(self.name + ": EOF exception found") |
| 464 | main.log.error(self.name + ": " + self.handle.before) |
| 465 | main.cleanup() |
| 466 | main.exit() |
admin | aeedddd | 2013-08-02 15:14:15 -0700 | [diff] [blame] | 467 | return main.TRUE |
| 468 | |
| 469 | def plug(self, **plugargs): |
| 470 | ''' |
| 471 | plug the yanked mininet switch interface to a switch |
| 472 | ''' |
| 473 | main.log.info('Plug the switch interface attached to a switch') |
admin | 530b4c9 | 2013-08-14 16:54:35 -0700 | [diff] [blame] | 474 | args = utilities.parse_args(["SW","INTF"],**plugargs) |
admin | aeedddd | 2013-08-02 15:14:15 -0700 | [diff] [blame] | 475 | sw = args["SW"] if args["SW"] !=None else "" |
| 476 | intf = args["INTF"] if args["INTF"] != None else "" |
| 477 | command = "py "+ str(sw) + '.attach("' + str(intf) + '")' |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 478 | try: |
| 479 | response = self.execute(cmd=command,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() |
admin | aeedddd | 2013-08-02 15:14:15 -0700 | [diff] [blame] | 485 | return main.TRUE |
| 486 | |
| 487 | |
| 488 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 489 | def dpctl(self,**dpctlargs): |
| 490 | ''' |
Jon Hall | 41f40e8 | 2014-04-08 16:43:17 -0700 | [diff] [blame] | 491 | Run dpctl command on all switches. |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 492 | ''' |
| 493 | main.log.info('Run dpctl command on all switches') |
| 494 | args = utilities.parse_args(["CMD","ARGS"],**dpctlargs) |
| 495 | cmd = args["CMD"] if args["CMD"] != None else "" |
| 496 | cmdargs = args["ARGS"] if args["ARGS"] != None else "" |
| 497 | command = "dpctl "+cmd + " " + str(cmdargs) |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 498 | try: |
| 499 | response = self.execute(cmd=command,prompt="mininet>",timeout=10) |
| 500 | except pexpect.EOF: |
| 501 | main.log.error(self.name + ": EOF exception found") |
| 502 | main.log.error(self.name + ": " + self.handle.before) |
| 503 | main.cleanup() |
| 504 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 505 | return main.TRUE |
| 506 | |
| 507 | |
| 508 | def get_version(self): |
| 509 | file_input = path+'/lib/Mininet/INSTALL' |
| 510 | version = super(Mininet, self).get_version() |
| 511 | pattern = 'Mininet\s\w\.\w\.\w\w*' |
| 512 | for line in open(file_input,'r').readlines(): |
| 513 | result = re.match(pattern, line) |
| 514 | if result: |
| 515 | version = result.group(0) |
| 516 | return version |
| 517 | |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 518 | def get_sw_controller_sanity(self, sw): |
| 519 | command = "sh ovs-vsctl get-controller "+str(sw) |
| 520 | try: |
| 521 | response = self.execute(cmd=command,prompt="mininet>",timeout=10) |
| 522 | if response: |
| 523 | return main.TRUE |
| 524 | else: |
| 525 | return main.FALSE |
| 526 | except pexpect.EOF: |
| 527 | main.log.error(self.name + ": EOF exception found") |
| 528 | main.log.error(self.name + ": " + self.handle.before) |
| 529 | main.cleanup() |
| 530 | main.exit() |
| 531 | else: |
| 532 | main.log.info(response) |
| 533 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 534 | def get_sw_controller(self,sw): |
| 535 | command = "sh ovs-vsctl get-controller "+str(sw) |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 536 | try: |
| 537 | response = self.execute(cmd=command,prompt="mininet>",timeout=10) |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 538 | print(response) |
| 539 | if response: |
| 540 | return response |
| 541 | else: |
| 542 | return main.FALSE |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 543 | except pexpect.EOF: |
| 544 | main.log.error(self.name + ": EOF exception found") |
| 545 | main.log.error(self.name + ": " + self.handle.before) |
| 546 | main.cleanup() |
| 547 | main.exit() |
| 548 | else: |
| 549 | main.log.info(response) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 550 | |
| 551 | def assign_sw_controller(self,**kwargs): |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 552 | ''' |
| 553 | count is only needed if there is more than 1 controller |
| 554 | ''' |
| 555 | args = utilities.parse_args(["COUNT"],**kwargs) |
| 556 | count = args["COUNT"] if args!={} else 1 |
| 557 | |
| 558 | argstring = "SW" |
| 559 | for j in range(count): |
| 560 | argstring = argstring + ",IP" + str(j+1) + ",PORT" + str(j+1) |
| 561 | args = utilities.parse_args(argstring.split(","),**kwargs) |
| 562 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 563 | sw = args["SW"] if args["SW"] != None else "" |
admin | 530b4c9 | 2013-08-14 16:54:35 -0700 | [diff] [blame] | 564 | ptcpA = int(args["PORT1"])+int(sw) if args["PORT1"] != None else "" |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 565 | ptcpB = "ptcp:"+str(ptcpA) if ptcpA != "" else "" |
| 566 | |
| 567 | command = "sh ovs-vsctl set-controller s" + str(sw) + " " + ptcpB + " " |
| 568 | for j in range(count): |
| 569 | i=j+1 |
| 570 | args = utilities.parse_args(["IP"+str(i),"PORT"+str(i)],**kwargs) |
| 571 | ip = args["IP"+str(i)] if args["IP"+str(i)] != None else "" |
| 572 | port = args["PORT" + str(i)] if args["PORT" + str(i)] != None else "" |
| 573 | tcp = "tcp:" + str(ip) + ":" + str(port) + " " if ip != "" else "" |
| 574 | command = command + tcp |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 575 | try: |
| 576 | self.execute(cmd=command,prompt="mininet>",timeout=5) |
| 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() |
| 582 | except: |
| 583 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 584 | main.log.error( traceback.print_exc() ) |
| 585 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 586 | main.cleanup() |
| 587 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 588 | |
Jon Hall | 0819fd9 | 2014-05-23 12:08:13 -0700 | [diff] [blame] | 589 | def delete_sw_controller(self,sw): |
| 590 | ''' |
| 591 | Removes the controller target from sw |
| 592 | ''' |
| 593 | |
| 594 | command = "sh ovs-vsctl del-controller "+str(sw) |
| 595 | try: |
| 596 | response = self.execute(cmd=command,prompt="mininet>",timeout=10) |
| 597 | except pexpect.EOF: |
| 598 | main.log.error(self.name + ": EOF exception found") |
| 599 | main.log.error(self.name + ": " + self.handle.before) |
| 600 | main.cleanup() |
| 601 | main.exit() |
| 602 | else: |
| 603 | main.log.info(response) |
| 604 | |
| 605 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 606 | def disconnect(self): |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 607 | main.log.info(self.name+": Disconnecting mininet...") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 608 | response = '' |
| 609 | if self.handle: |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 610 | try: |
| 611 | response = self.execute(cmd="exit",prompt="(.*)",timeout=120) |
| 612 | response = self.execute(cmd="exit",prompt="(.*)",timeout=120) |
Jon Hall | e80ef8c | 2014-04-29 15:29:13 -0700 | [diff] [blame] | 613 | self.handle.sendline("sudo mn -c") |
Jon Hall | 6094a36 | 2014-04-11 14:46:56 -0700 | [diff] [blame] | 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 | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 619 | else : |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 620 | main.log.error(self.name+": Connection failed to the host") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 621 | response = main.FALSE |
| 622 | return response |
admin | 0752993 | 2013-11-22 14:58:28 -0800 | [diff] [blame] | 623 | |
| 624 | def arping(self, src, dest, destmac): |
| 625 | self.handle.sendline('') |
Jon Hall | 333fa8c | 2014-04-11 11:24:58 -0700 | [diff] [blame] | 626 | self.handle.expect(["mininet",pexpect.EOF,pexpect.TIMEOUT]) |
admin | 0752993 | 2013-11-22 14:58:28 -0800 | [diff] [blame] | 627 | |
| 628 | self.handle.sendline(src + ' arping ' + dest) |
| 629 | try: |
Jon Hall | 333fa8c | 2014-04-11 11:24:58 -0700 | [diff] [blame] | 630 | self.handle.expect([destmac,pexpect.EOF,pexpect.TIMEOUT]) |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 631 | main.log.info(self.name+": ARP successful") |
Jon Hall | 333fa8c | 2014-04-11 11:24:58 -0700 | [diff] [blame] | 632 | self.handle.expect(["mininet",pexpect.EOF,pexpect.TIMEOUT]) |
admin | 0752993 | 2013-11-22 14:58:28 -0800 | [diff] [blame] | 633 | return main.TRUE |
| 634 | except: |
Jon Hall | f2942ce | 2014-04-10 16:00:16 -0700 | [diff] [blame] | 635 | main.log.warn(self.name+": ARP FAILURE") |
Jon Hall | 333fa8c | 2014-04-11 11:24:58 -0700 | [diff] [blame] | 636 | self.handle.expect(["mininet",pexpect.EOF,pexpect.TIMEOUT]) |
admin | 0752993 | 2013-11-22 14:58:28 -0800 | [diff] [blame] | 637 | return main.FALSE |
| 638 | |
| 639 | def decToHex(num): |
| 640 | return hex(num).split('x')[1] |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 641 | |
| 642 | def getSwitchFlowCount(self, switch): |
| 643 | ''' |
| 644 | return the Flow Count of the switch |
| 645 | ''' |
| 646 | if self.handle: |
| 647 | cmd = "sh ovs-ofctl dump-aggregate %s" % switch |
| 648 | try: |
| 649 | response = self.execute(cmd=cmd, prompt="mininet>", timeout=10) |
| 650 | except pexpect.EOF: |
| 651 | main.log.error(self.name + ": EOF exception found") |
| 652 | main.log.error(self.name + " " + self.handle.before) |
| 653 | main.cleanup() |
| 654 | main.exit() |
| 655 | pattern = "flow_count=(\d+)" |
| 656 | result = re.search(pattern, response, re.MULTILINE) |
| 657 | if result is None: |
| 658 | print "no flow on switch print test" |
| 659 | main.log.info("Couldn't find flows on switch '', found: %s" % (switch, response)) |
| 660 | return main.FALSE |
| 661 | return result.group(1) |
| 662 | else: |
| 663 | main.log.error("Connection failed to the Mininet host") |
| 664 | |
| 665 | def check_flows(self, sw): |
| 666 | command = "sh ovs-ofctl dump-flows "+str(sw) |
| 667 | try: |
| 668 | response=self.execute(cmd=command,prompt="mininet>",timeout=10) |
| 669 | return response |
| 670 | except pexpect.EOF: |
| 671 | main.log.error(self.name + ": EOF exception found") |
| 672 | main.log.error(self.name + ": " + self.handle.before) |
| 673 | main.cleanup() |
| 674 | main.exit() |
| 675 | else: |
| 676 | main.log.info(response) |
| 677 | |
| 678 | def start_tcpdump(self, filename, intf = "eth0", port = "port 6633"): |
| 679 | ''' |
| 680 | Runs tpdump on an intferface and saves the file |
| 681 | intf can be specified, or the default eth0 is used |
| 682 | ''' |
| 683 | try: |
| 684 | self.handle.sendline("") |
| 685 | self.handle.expect("mininet>") |
| 686 | self.handle.sendline("sh sudo tcpdump -n -i "+ intf + " " + port + " -w " + filename.strip() + " &") |
| 687 | self.handle.sendline("") |
| 688 | self.handle.sendline("") |
| 689 | i=self.handle.expect(['No\ssuch\device','listening\son',pexpect.TIMEOUT,"mininet>"],timeout=10) |
| 690 | main.log.warn(self.handle.before + self.handle.after) |
| 691 | if i == 0: |
| 692 | main.log.error(self.name + ": tcpdump - No such device exists. tcpdump attempted on: " + intf) |
| 693 | return main.FALSE |
| 694 | elif i == 1: |
| 695 | main.log.info(self.name + ": tcpdump started on " + intf) |
| 696 | return main.TRUE |
| 697 | elif i == 2: |
| 698 | main.log.error(self.name + ": tcpdump command timed out! Check interface name, given interface was: " + intf) |
| 699 | return main.FALSE |
| 700 | elif i ==3: |
| 701 | main.log.info(self.name +": " + self.handle.before) |
| 702 | return main.TRUE |
| 703 | else: |
| 704 | main.log.error(self.name + ": tcpdump - unexpected response") |
| 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() |
| 711 | except: |
| 712 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 713 | main.log.error( traceback.print_exc() ) |
| 714 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 715 | main.cleanup() |
| 716 | main.exit() |
| 717 | |
| 718 | def stop_tcpdump(self): |
| 719 | "pkills tcpdump" |
| 720 | try: |
| 721 | self.handle.sendline("sh sudo pkill tcpdump") |
| 722 | self.handle.sendline("") |
| 723 | self.handle.sendline("") |
| 724 | self.handle.expect("mininet>") |
| 725 | except pexpect.EOF: |
| 726 | main.log.error(self.name + ": EOF exception found") |
| 727 | main.log.error(self.name + ": " + self.handle.before) |
| 728 | main.cleanup() |
| 729 | main.exit() |
| 730 | except: |
| 731 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 732 | main.log.error( traceback.print_exc() ) |
| 733 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 734 | main.cleanup() |
| 735 | main.exit() |
| 736 | |
| 737 | |
| 738 | |
| 739 | |
| 740 | |
| 741 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 742 | |
| 743 | if __name__ != "__main__": |
| 744 | import sys |
| 745 | sys.modules[__name__] = MininetCliDriver() |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 746 | |