SHOW:
|
|
- or go back to the newest paste.
| 1 | ############################################################### | |
| 2 | # This installs OpenvSwitch, KVM, Git(Hub) and an OpenFlow # | |
| 3 | # Controller FloodLight (optional). It also downloads a 16Mb # | |
| 4 | # linux-0.2.img.bz2 file that from http://wiki.qemu.org that # | |
| 5 | # is great for testing networking since it is so lightweight # | |
| 6 | # you can simulate lots of VMs running in nested a hypervisors# | |
| 7 | # on your laptop or older desktop rather than needing a server# | |
| 8 | # for learning or labbing. This is for *Ubuntu* only since it # | |
| 9 | # is using apt-get for pkg management. # | |
| 10 | # This is NOT for anything other than labbing and testing but # | |
| 11 | # the KVM and OpenvSwitch install would run production easily.# | |
| 12 | # Feel free to use this however you like. Python is a great # | |
| 13 | # language for infrastrcuture applications. It has clean # | |
| 14 | # abstraction leaving it easy to read but also has the power # | |
| 15 | # of object oriented programming. This wil install a fully # | |
| 16 | # working Software Defined Networking (SDN) and OpenFlow # | |
| 17 | # lab in a few minutes. See the accompanying post # | |
| 18 | # I recommend starting in a VM using VMware Fusion as the # | |
| 19 | # first option only becuase it seems to deal with OVS better # | |
| 20 | # than VirtualBox but both work. I would also recommend using # | |
| 21 | # snapshots heavily. Install your base Linux 12.04 build and # | |
| 22 | # then take a snapshot in case you have problems with the # | |
| 23 | # App you can rollback to the original snapshot and start over# | |
| 24 | # Comments at Twitters @networkstatic, Thanks-Brent Salisbury # | |
| 25 | ############################################################### | |
| 26 | - | #http://networkstatic.net/openflow-and-openvswitch-sdn-lab-scripted-in-minutes |
| 26 | + | #http://networkstatic.net/openflow-openvswitch-and-kvm-sdn-lab-installation-app/ |
| 27 | #!/usr/bin/python | |
| 28 | import subprocess | |
| 29 | import os | |
| 30 | import time | |
| 31 | ||
| 32 | def git(): | |
| 33 | #Install Git | |
| 34 | gitProc = subprocess.Popen('apt-get install -y git', shell=True, stdin=None, executable="/bin/bash")
| |
| 35 | gitProc.wait() | |
| 36 | print("Finished installing Git")
| |
| 37 | ||
| 38 | def kvm(): | |
| 39 | #Install KVM | |
| 40 | kvmProc = subprocess.Popen('apt-get install -y kvm qemu-kvm', shell=True, stdin=None, executable="/bin/bash")
| |
| 41 | kvmProc.wait() | |
| 42 | print("Finished installing KVM")
| |
| 43 | ||
| 44 | def OVSinst(): | |
| 45 | #Download and compile the OpenvSwitch unless a directory name openvswitch exists. | |
| 46 | #This Git pulls latest dev snapshot from main the branch @ git://openvswitch.org/openvswitch. | |
| 47 | if os.path.exists('openvswitch'):
| |
| 48 | print('It appears you already have cloned openvswitch, skipping the clone')
| |
| 49 | if not os.path.exists('openvswitch'):
| |
| 50 | print('Cloning OVS from GitHub and then compiling the code, may take a few minutes...')
| |
| 51 | ovs0Proc = subprocess.Popen("""apt-get install -y git python-simplejson python-qt4 python-twisted-conch automake autoconf
| |
| 52 | gcc uml-utilities libtool build-essential git pkg-config linux-headers-`uname -r`""", shell=True, stdin=None, executable="/bin/bash") | |
| 53 | ovs0Proc.wait() | |
| 54 | ovs1Proc = subprocess.Popen('apt-get install -y openvswitch-controller', shell=True, stdin=None, executable="/bin/bash")
| |
| 55 | ovs1Proc.wait() | |
| 56 | ovs2Proc = subprocess.Popen(' git clone git://openvswitch.org/openvswitch', shell=True, stdin=None, executable="/bin/bash")
| |
| 57 | ovs2Proc.wait() | |
| 58 | os.chdir("openvswitch")
| |
| 59 | ovs4Proc = subprocess.Popen('./boot.sh', shell=True, stdin=None, executable="/bin/bash")
| |
| 60 | ovs4Proc.wait() | |
| 61 | ovs5Proc = subprocess.Popen('./configure --with-linux=/lib/modules/`uname -r`/build', shell=True, stdin=None, executable="/bin/bash")
| |
| 62 | ovs5Proc.wait() | |
| 63 | ovs6Proc = subprocess.Popen('make && make install', shell=True, stdin=None, executable="/bin/bash")
| |
| 64 | ovs6Proc.wait() | |
| 65 | ovs7Proc = subprocess.Popen('insmod datapath/linux/openvswitch.ko', shell=True, stdin=None, executable="/bin/bash")
| |
| 66 | ovs7Proc.wait() | |
| 67 | ovs8Proc = subprocess.Popen('insmod datapath/linux/brcompat.ko', shell=True, stdin=None, executable="/bin/bash")
| |
| 68 | ovs8Proc.wait() | |
| 69 | ovs9Proc = subprocess.Popen('mkdir -p /usr/local/etc/openvswitch', shell=True, stdin=None, executable="/bin/bash")
| |
| 70 | ovs9Proc.wait() | |
| 71 | ovs10Proc = subprocess.Popen('ovsdb-tool create /usr/local/etc/openvswitch/conf.db vswitchd/vswitch.ovsschema', shell=True, stdin=None, executable="/bin/bash")
| |
| 72 | ovs10Proc.wait() | |
| 73 | ovs11Proc = subprocess.Popen("""ovsdb-server /usr/local/etc/openvswitch/conf.db \
| |
| 74 | --remote=punix:/usr/local/var/run/openvswitch/db.sock \ | |
| 75 | --remote=db:Open_vSwitch,manager_options \ | |
| 76 | --private-key=db:SSL,private_key \ | |
| 77 | --certificate=db:SSL,certificate \ | |
| 78 | --bootstrap-ca-cert=db:SSL,ca_cert --pidfile --detach --log-file""", shell=True, stdin=None, executable="/bin/bash") | |
| 79 | ovs11Proc.wait() | |
| 80 | ovs12Proc = subprocess.Popen('ovs-vsctl --no-wait init', shell=True, stdin=None, executable="/bin/bash")
| |
| 81 | ovs12Proc.wait() | |
| 82 | ovs13Proc = subprocess.Popen('ovs-vswitchd --pidfile --detach', shell=True, stdin=None, executable="/bin/bash")
| |
| 83 | ovs13Proc.wait() | |
| 84 | os.chdir("../")
| |
| 85 | ||
| 86 | def ovsVXinst(): | |
| 87 | #Download and compile the VXLan OpenvSwitch unless a directory name ovs-vxlan exists. | |
| 88 | if os.path.exists('ovs-vxlan'):
| |
| 89 | print('It appears you already have cloned ovs-vxlan, skipping the clone')
| |
| 90 | if not os.path.exists('ovs-vxlan'):
| |
| 91 | print('Cloning OVS from GitHub and then compiling the code, may take a few minutes...')
| |
| 92 | ovs0Proc = subprocess.Popen("""apt-get install -y git python-simplejson python-qt4 python-twisted-conch automake autoconf
| |
| 93 | gcc uml-utilities libtool build-essential git pkg-config linux-headers-`uname -r`""", shell=True, stdin=None, executable="/bin/bash") | |
| 94 | ovs0Proc.wait() | |
| 95 | ovs1Proc = subprocess.Popen('apt-get install -y openvswitch-controller', shell=True, stdin=None, executable="/bin/bash")
| |
| 96 | ovs1Proc.wait() | |
| 97 | ovs2Proc = subprocess.Popen('git clone https://github.com/mestery/ovs-vxlan.git', shell=True, stdin=None, executable="/bin/bash")
| |
| 98 | ovs2Proc.wait() | |
| 99 | os.chdir("ovs-vxlan")
| |
| 100 | ovs3Proc = subprocess.Popen('git checkout vxlan', shell=True, stdin=None, executable="/bin/bash")
| |
| 101 | ovs3Proc.wait() | |
| 102 | ovs4Proc = subprocess.Popen('./boot.sh', shell=True, stdin=None, executable="/bin/bash")
| |
| 103 | ovs4Proc.wait() | |
| 104 | ovs5Proc = subprocess.Popen('./configure --with-linux=/lib/modules/`uname -r`/build', shell=True, stdin=None, executable="/bin/bash")
| |
| 105 | ovs5Proc.wait() | |
| 106 | ovs6Proc = subprocess.Popen('make && make install', shell=True, stdin=None, executable="/bin/bash")
| |
| 107 | ovs6Proc.wait() | |
| 108 | ovs7Proc = subprocess.Popen('insmod datapath/linux/openvswitch.ko', shell=True, stdin=None, executable="/bin/bash")
| |
| 109 | ovs7Proc.wait() | |
| 110 | ovs8Proc = subprocess.Popen('insmod datapath/linux/brcompat.ko', shell=True, stdin=None, executable="/bin/bash")
| |
| 111 | ovs8Proc.wait() | |
| 112 | ovs9Proc = subprocess.Popen('mkdir -p /usr/local/etc/openvswitch', shell=True, stdin=None, executable="/bin/bash")
| |
| 113 | ovs9Proc.wait() | |
| 114 | ovs10Proc = subprocess.Popen('ovsdb-tool create /usr/local/etc/openvswitch/conf.db vswitchd/vswitch.ovsschema', shell=True, stdin=None, executable="/bin/bash")
| |
| 115 | ovs10Proc.wait() | |
| 116 | ovs11Proc = subprocess.Popen("""ovsdb-server /usr/local/etc/openvswitch/conf.db \
| |
| 117 | --remote=punix:/usr/local/var/run/openvswitch/db.sock \ | |
| 118 | --remote=db:Open_vSwitch,manager_options \ | |
| 119 | --private-key=db:SSL,private_key \ | |
| 120 | --certificate=db:SSL,certificate \ | |
| 121 | --bootstrap-ca-cert=db:SSL,ca_cert --pidfile --detach --log-file""", shell=True, stdin=None, executable="/bin/bash") | |
| 122 | ovs11Proc.wait() | |
| 123 | ovs12Proc = subprocess.Popen('ovs-vsctl --no-wait init', shell=True, stdin=None, executable="/bin/bash")
| |
| 124 | ovs12Proc.wait() | |
| 125 | ovs13Proc = subprocess.Popen('ovs-vswitchd --pidfile --detach', shell=True, stdin=None, executable="/bin/bash")
| |
| 126 | ovs13Proc.wait() | |
| 127 | os.chdir("../")
| |
| 128 | ||
| 129 | def OVSinstOF(): | |
| 130 | #Download and compile the VXLan OpenvSwitch unless a directory name ovs-vxlan exists. | |
| 131 | if os.path.exists('ovs-vxlan'):
| |
| 132 | print('It appears you already have cloned ovs-vxlan, skipping the clone')
| |
| 133 | if not os.path.exists('ovs-vxlan'):
| |
| 134 | print('Cloning OVS from GitHub and then compiling the code, may take a few minutes...')
| |
| 135 | ovsf1Proc = subprocess.Popen("""apt-get install -y git python-simplejson python-qt4 python-twisted-conch automake autoconf
| |
| 136 | gcc uml-utilities libtool build-essential git pkg-config linux-headers-`uname -r`""", shell=True, stdin=None, executable="/bin/bash") | |
| 137 | ovsf1Proc.wait() | |
| 138 | ovsf2Proc = subprocess.Popen('git clone https://github.com/mestery/ovs-vxlan.git', shell=True, stdin=None, executable="/bin/bash")
| |
| 139 | ovsf2Proc.wait() | |
| 140 | os.chdir("ovs-vxlan")
| |
| 141 | ovsf3Proc = subprocess.Popen('git checkout vxlan', shell=True, stdin=None, executable="/bin/bash")
| |
| 142 | ovsf3Proc.wait() | |
| 143 | ovsf4Proc = subprocess.Popen('./boot.sh', shell=True, stdin=None, executable="/bin/bash")
| |
| 144 | ovsf4Proc.wait() | |
| 145 | ovsf5Proc = subprocess.Popen('./configure --with-linux=/lib/modules/`uname -r`/build', shell=True, stdin=None, executable="/bin/bash")
| |
| 146 | ovsf5Proc.wait() | |
| 147 | ovsf6Proc = subprocess.Popen('make && make install', shell=True, stdin=None, executable="/bin/bash")
| |
| 148 | ovsf6Proc.wait() | |
| 149 | ovsf7Proc = subprocess.Popen('insmod datapath/linux/openvswitch.ko', shell=True, stdin=None, executable="/bin/bash")
| |
| 150 | ovsf7Proc.wait() | |
| 151 | ovsf8Proc = subprocess.Popen('insmod datapath/linux/brcompat.ko', shell=True, stdin=None, executable="/bin/bash")
| |
| 152 | ovsf8Proc.wait() | |
| 153 | ovsf9Proc = subprocess.Popen('mkdir -p /usr/local/etc/openvswitch', shell=True, stdin=None, executable="/bin/bash")
| |
| 154 | ovsf9Proc.wait() | |
| 155 | ovsf10Proc = subprocess.Popen('ovsdb-tool create /usr/local/etc/openvswitch/conf.db vswitchd/vswitch.ovsschema', shell=True, stdin=None, executable="/bin/bash")
| |
| 156 | ovsf10Proc.wait() | |
| 157 | ovsf11Proc = subprocess.Popen("""ovsdb-server /usr/local/etc/openvswitch/conf.db \
| |
| 158 | --remote=punix:/usr/local/var/run/openvswitch/db.sock \ | |
| 159 | --remote=db:Open_vSwitch,manager_options \ | |
| 160 | --private-key=db:SSL,private_key \ | |
| 161 | --certificate=db:SSL,certificate \ | |
| 162 | --bootstrap-ca-cert=db:SSL,ca_cert --pidfile --detach --log-file""", shell=True, stdin=None, executable="/bin/bash") | |
| 163 | ovsf11Proc.wait() | |
| 164 | ovsf12Proc = subprocess.Popen('ovs-vsctl --no-wait init', shell=True, stdin=None, executable="/bin/bash")
| |
| 165 | ovsf12Proc.wait() | |
| 166 | ovsf13Proc = subprocess.Popen('ovs-vswitchd --pidfile --detach', shell=True, stdin=None, executable="/bin/bash")
| |
| 167 | ovsf13Proc.wait() | |
| 168 | os.chdir("../")
| |
| 169 | ||
| 170 | def images(): | |
| 171 | img = ('linux-0.2.img')
| |
| 172 | print('Checking if the Host Linux Image ' + img + ' exists')
| |
| 173 | if os.path.exists(img): | |
| 174 | print(img + ' is already in the current working directory, delete if a partial download\n') | |
| 175 | else: | |
| 176 | print('Downloading ' + img + ' from http://wiki.qemu.org/Testing approximately 8Mb')
| |
| 177 | lnxDlProc = subprocess.Popen('wget http://wiki.qemu.org/download/linux-0.2.img.bz2', shell=True, stdin=None, executable="/bin/bash")
| |
| 178 | lnxDlProc.wait() | |
| 179 | bunzipProc = subprocess.Popen('bunzip2 linux-0.2.img.bz2', shell=True, stdin=None, executable="/bin/bash")
| |
| 180 | bunzipProc.wait() | |
| 181 | ||
| 182 | def etcifup(): | |
| 183 | print('Adding OVS interface script /etc/ovs-ifup')
| |
| 184 | fhup = ('/etc/ovs-ifup')
| |
| 185 | if os.path.exists(fhup): | |
| 186 | print('file /etc/ovs-ifup exists skipping')
| |
| 187 | else: | |
| 188 | print ('Adding /etc/ovs-ifup')
| |
| 189 | ovsup = ("""#!/bin/sh
| |
| 190 | switch='br-int' | |
| 191 | /sbin/ifconfig $1 0.0.0.0 up promisc | |
| 192 | ovs-vsctl add-port ${switch} $1""")
| |
| 193 | ovsupf = open('/etc/ovs-ifup', 'w')
| |
| 194 | ovsupf.write(ovsup) | |
| 195 | ovsupf.close() | |
| 196 | os.chmod('/etc/ovs-ifup', 0755)
| |
| 197 | ||
| 198 | def etcifdown(): | |
| 199 | print('Adding OVS interface script /etc/ovs-ifdown')
| |
| 200 | fhdown = ('/etc/ovs-ifdown')
| |
| 201 | if os.path.exists(fhdown): | |
| 202 | print('file /etc/ovs-ifdown exists skipping')
| |
| 203 | else: | |
| 204 | print ('Adding /etc/ovs-ifdown')
| |
| 205 | ovsdown = ("""#!/bin/sh
| |
| 206 | switch='br-int' | |
| 207 | /sbin/ifconfig $1 0.0.0.0 down | |
| 208 | ovs-vsctl del-port ${switch} $1""")
| |
| 209 | ovsdownf = open('/etc/ovs-ifdown', 'w')
| |
| 210 | ovsdownf.write(ovsdown) | |
| 211 | ovsdownf.close() | |
| 212 | os.chmod('/etc/ovs-ifdown', 0755)
| |
| 213 | ||
| 214 | def OVSconf(): | |
| 215 | print('Adding an OpenvSwitch bridged interface br-int')
| |
| 216 | ovsCnf1Proc = subprocess.Popen('ovs-vsctl add-br br-int', shell=True, stdin=None, executable="/bin/bash")
| |
| 217 | ovsCnf1Proc.wait() | |
| 218 | ovsCnf2Proc = subprocess.Popen('ovs-vsctl add-port br-int eth0', shell=True, stdin=None, executable="/bin/bash")
| |
| 219 | ovsCnf2Proc.wait() | |
| 220 | ||
| 221 | def ovsOFconf(strIP): | |
| 222 | print('Adding an OpenvSwitch bridged interface br-int and Attaching to an OF Controller')
| |
| 223 | ovsOFconf1Proc = subprocess.Popen('sudo ovs-vsctl add-br br-int', shell=True, stdin=None, executable="/bin/bash")
| |
| 224 | ovsOFconf1Proc.wait() | |
| 225 | ovsOFconf2Proc = subprocess.Popen('sudo ovs-vsctl add-port br-int eth0', shell=True, stdin=None, executable="/bin/bash")
| |
| 226 | ovsOFconf2Proc.wait() | |
| 227 | ovsOFconf3Proc = subprocess.Popen('sudo ovs-vsctl set-controller br-int tcp:' + strIP + ':6633', shell=True, stdin=None, executable="/bin/bash")
| |
| 228 | ovsOFconf3Proc.wait() | |
| 229 | ||
| 230 | def IPaddrs(strGW, strIP, strNetMask): | |
| 231 | print ('Moving Default Gateway to use (br-int) using --> ' + strGW)
| |
| 232 | print ('Moving IP address on Eth0 to (br-int) for OpenvSwitch to use --> ' +strIP)
| |
| 233 | ipbrProc = subprocess.Popen('ifconfig br-int ' + strIP + ' netmask 255.255.255.0', shell=True, stdin=None, executable="/bin/bash")
| |
| 234 | ipbrProc.wait() | |
| 235 | gwProc = subprocess.Popen('route add default gw ' + strGW + ' br-int', shell=True, stdin=None, executable="/bin/bash")
| |
| 236 | gwProc.wait() | |
| 237 | ipdelProc = subprocess.Popen('ifconfig eth0 0', shell=True, stdin=None, executable="/bin/bash")
| |
| 238 | ipdelProc.wait() | |
| 239 | ||
| 240 | def floodlight(): | |
| 241 | imgfl = ('floodlight.jar')
| |
| 242 | jreProc = subprocess.Popen('apt-get install -y default-jre python-dev curl', shell=True, stdin=None, executable="/bin/bash")
| |
| 243 | jreProc.wait() | |
| 244 | if os.path.exists(imgfl): | |
| 245 | print('It appears you already have already downloaded floodlight.jar')
| |
| 246 | print(imgfl + ' is already in the current working directory\n redownload or delete if a partial download now Installing deps..') | |
| 247 | devnull = open('/dev/null', 'w')
| |
| 248 | subprocess.Popen('xterm -e java -jar floodlight.jar & > /dev/null', shell=True, stdin=None, stderr=devnull, executable="/bin/bash")
| |
| 249 | devnull.close() | |
| 250 | print('Floodlight OpenFlow Controller Started in a new Xterm console')
| |
| 251 | if not os.path.exists(imgfl): | |
| 252 | print('Cloning OVS from GitHub and then compiling the code, may take a few minutes...')
| |
| 253 | print('Installing openjdk6 and cloning Floodlight from GitHub')
| |
| 254 | gitflProc = subprocess.Popen('wget http://floodlight.openflowhub.org/files/floodlight.jar', shell=True, stdin=None, executable="/bin/bash")
| |
| 255 | gitflProc.wait() | |
| 256 | devnull = open('/dev/null', 'w')
| |
| 257 | subprocess.Popen('xterm -e java -jar floodlight.jar & > /dev/null', shell=True, stdin=None, stderr=devnull, executable="/bin/bash")
| |
| 258 | devnull.close() | |
| 259 | print('Floodlight OpenFlow Controller Started in a new Xterm console')
| |
| 260 | ||
| 261 | def pox(): | |
| 262 | #Download and compile the VXLan OpenvSwitch unless a directory name ovs-vxlan exists. | |
| 263 | if os.path.exists('pox'):
| |
| 264 | print('It appears you already have cloned POX, skipping the clone')
| |
| 265 | if not os.path.exists('pox'):
| |
| 266 | print('Cloning POX from GitHub and then compiling the code, may take a few minutes...')
| |
| 267 | print('Pox requires Python 2.7 to run')
| |
| 268 | gitPoxProc = subprocess.Popen('git clone http://github.com/noxrepo/pox', shell=True, stdin=None, executable="/bin/bash")
| |
| 269 | gitPoxProc.wait() | |
| 270 | devnull = open('/dev/null', 'w')
| |
| 271 | subprocess.Popen('xterm -e python pox/pox.py forwarding.l2_learning web.webcore &', shell=True, stdin=None, stderr=devnull, executable="/bin/bash")
| |
| 272 | devnull.close() | |
| 273 | print('POX OpenFlow Controller Started using the forwarding.l2_learning in a new Xterm console')
| |
| 274 | ||
| 275 | def boot(): | |
| 276 | print ('Installation complete! The text above has instructions, Happy Labbing!\nBooting a VM in 10 seconds. Press Control+C to abort.')
| |
| 277 | time.sleep(15) | |
| 278 | devnull = open('/dev/null', 'w')
| |
| 279 | gitPoxProc = subprocess.Popen('kvm -m 128 -net nic,macaddr=33:22:22:00:cc:01 -net tap,script=/etc/ovs-ifup,downscript=/etc/ovs-ifdown -hda linux-0.2.img &', shell=True, stdin=None, stderr=devnull, executable="/bin/bash")
| |
| 280 | devnull.close() | |
| 281 | ||
| 282 | def msgEof(): | |
| 283 | print("""############################################################################
| |
| 284 | # Installation complete! Now start a VM or run the bash script in the post.# | |
| 285 | ############################################################################ | |
| 286 | # Copy and paste all three lines into the console from the SAME directory # | |
| 287 | # you installed the script from that has the downloaded "linux-0.2.img" # | |
| 288 | # image. Do this with in the Ubuntu GUI. Then in the window give it an # | |
| 289 | # address on your subnet and a default gateway in the VM that boots in the # | |
| 290 | # QEMU window that pops up. Break out of the QEMU window inside VirtualBox # | |
| 291 | # use alt + control + command a few times to free the mouse pointer. # | |
| 292 | # Example IP--> ** ifconfig eth0 192.168.1.20 netmask 255.255.255.0 ** # | |
| 293 | # Example Default Gateway-->** route add default gateway 192.168.1.1 ** # | |
| 294 | # To start a VM copy and paste this into the console # | |
| 295 | ############################################################################ | |
| 296 | #Use unique Mac addresses for hosts e.g. cc:10, cc:11 see details in post # | |
| 297 | ############################################################################ | |
| 298 | Examples to copy and paste (Notice unique MAC addresses on each VM 01, 02, 03) | |
| 299 | kvm -m 128 -net nic,macaddr=22:22:22:00:cc:01 -net tap,script=/etc/ovs-ifup,downscript=/etc/ovs-ifdown -hda linux-0.2.img & | |
| 300 | kvm -m 128 -net nic,macaddr=22:22:22:00:cc:02 -net tap,script=/etc/ovs-ifup,downscript=/etc/ovs-ifdown -hda linux-0.2.img & | |
| 301 | kvm -m 128 -net nic,macaddr=22:22:22:00:cc:03 -net tap,script=/etc/ovs-ifup,downscript=/etc/ovs-ifdown -hda linux-0.2.img & | |
| 302 | Booting one VM with a MAC address of AA:AA:12:34:56:78 as an example. | |
| 303 | When it boots you give it an IP address and gatewat as explanined above. | |
| 304 | Type 'ovs-vsctl show' to the the VNIC (tap0) and OVS configuration | |
| 305 | ################################################################################ | |
| 306 | # -More information about what you can do with this Lab at: # | |
| 307 | - | # http://networkstatic.net/openflow-and-openvswitch-sdn-lab-scripted-in-minutes# |
| 307 | + | # http://networkstatic.net/openflow-openvswitch-and-kvm-sdn-lab-installation-app/# |
| 308 | # Comments at Twitters @networkstatic, Thanks- Brent Salisbury # | |
| 309 | ################################################################################""") | |
| 310 | ||
| 311 | def floodEof(strIP): | |
| 312 | print("""############################################################################
| |
| 313 | # Installation complete! Now start a VM or run the bash script in the post.# | |
| 314 | ############################################################################ | |
| 315 | # Copy and paste all three lines into the console from the SAME directory # | |
| 316 | # you installed the script from that has the downloaded "linux-0.2.img" # | |
| 317 | # image. Do this with in the Ubuntu GUI. Then in the window give it an # | |
| 318 | # address on your subnet and a default gateway in the VM that boots in the # | |
| 319 | # QEMU window that pops up. Break out of the QEMU window inside VirtualBox # | |
| 320 | # use alt + control + command a few times to free the mouse pointer. # | |
| 321 | # Example IP--> **ifconfig eth0 192.168.1.20 netmask 255.255.255.0** # | |
| 322 | # Example Default Gateway-->**route add default gateway 192.168.1.1** # | |
| 323 | # To start a VM copy and paste this into the console # | |
| 324 | ############################################################################ | |
| 325 | #Use unique Mac addresses for hosts e.g. cc:10, cc:11 see details in post # | |
| 326 | ############################################################################ | |
| 327 | Examples to copy and paste (Notice unique MAC addresses on each VM 01, 02, 03) | |
| 328 | kvm -m 128 -net nic,macaddr=22:22:22:00:cc:01 -net tap,script=/etc/ovs-ifup,downscript=/etc/ovs-ifdown -hda linux-0.2.img & | |
| 329 | kvm -m 128 -net nic,macaddr=22:22:22:00:cc:02 -net tap,script=/etc/ovs-ifup,downscript=/etc/ovs-ifdown -hda linux-0.2.img & | |
| 330 | kvm -m 128 -net nic,macaddr=22:22:22:00:cc:03 -net tap,script=/etc/ovs-ifup,downscript=/etc/ovs-ifdown -hda linux-0.2.img & | |
| 331 | Booting one VM with a MAC address of AA:AA:12:34:56:78 as an example. | |
| 332 | When it boots you give it an IP address and gatewat as explanined above. | |
| 333 | Type 'ovs-vsctl show' to the the VNIC (tap0) and OVS configuration | |
| 334 | ############################################################################ | |
| 335 | # FloodLight Controller running at http://"""+strIP+""":8080/ui/index.html # | |
| 336 | # Put the URL above in a web browser to see the web UI # | |
| 337 | ################################################################################ | |
| 338 | # -More information about what you can do with this Lab at: # | |
| 339 | - | # http://networkstatic.net/openflow-and-openvswitch-sdn-lab-scripted-in-minutes# |
| 339 | + | # http://networkstatic.net/openflow-openvswitch-and-kvm-sdn-lab-installation-app/ # |
| 340 | # Comments at Twitters @networkstatic, Thanks- Brent Salisbury # | |
| 341 | ################################################################################""") | |
| 342 | ||
| 343 | def poxEof(): | |
| 344 | print("""############################################################################
| |
| 345 | # Installation complete! Now start a VM or run the bash script in the post.# | |
| 346 | ############################################################################ | |
| 347 | # Copy and paste all three lines into the console from the SAME directory # | |
| 348 | # you installed the script from that has the downloaded "linux-0.2.img" # | |
| 349 | # image. Do this with in the Ubuntu GUI. Then in the window give it an # | |
| 350 | # address on your subnet and a default gateway in the VM that boots in the # | |
| 351 | # QEMU window that pops up. Break out of the QEMU window inside VirtualBox # | |
| 352 | # use alt + control + command a few times to free the mouse pointer. # | |
| 353 | # Example IP--> **ifconfig eth0 192.168.1.20 netmask 255.255.255.0** # | |
| 354 | # Example Default Gateway-->**route add default gateway 192.168.1.1** # | |
| 355 | # To start a VM copy and paste this into the console # | |
| 356 | ############################################################################ | |
| 357 | #Use unique Mac addresses for hosts e.g. cc:10, cc:11 see details in post # | |
| 358 | ############################################################################ | |
| 359 | Examples to copy and paste (Notice unique MAC addresses on each VM 01, 02, 03) | |
| 360 | kvm -m 128 -net nic,macaddr=22:22:22:00:cc:01 -net tap,script=/etc/ovs-ifup,downscript=/etc/ovs-ifdown -hda linux-0.2.img & | |
| 361 | kvm -m 128 -net nic,macaddr=22:22:22:00:cc:02 -net tap,script=/etc/ovs-ifup,downscript=/etc/ovs-ifdown -hda linux-0.2.img & | |
| 362 | kvm -m 128 -net nic,macaddr=22:22:22:00:cc:03 -net tap,script=/etc/ovs-ifup,downscript=/etc/ovs-ifdown -hda linux-0.2.img & | |
| 363 | Booting one VM with a MAC address of AA:AA:12:34:56:78 as an example. | |
| 364 | When it boots you give it an IP address and gatewat as explanined above. | |
| 365 | Type 'ovs-vsctl show' to the the VNIC (tap0) and OVS configuration | |
| 366 | ################################################################################ | |
| 367 | # -More information about what you can do with this Lab at: # | |
| 368 | - | # http://networkstatic.net/openflow-and-openvswitch-sdn-lab-scripted-in-minutes# |
| 368 | + | # http://networkstatic.net/openflow-openvswitch-and-kvm-sdn-lab-installation-app/ # |
| 369 | # Comments at Twitters @networkstatic, Thanks- Brent Salisbury # | |
| 370 | ################################################################################""") | |
| 371 | ||
| 372 | def vxEof(): | |
| 373 | print("""############################################################################
| |
| 374 | # Installation complete! Now start a VM or run the bash script in the post.# | |
| 375 | ############################################################################ | |
| 376 | # Copy and paste all three lines into the console from the SAME directory # | |
| 377 | # you installed the script from that has the downloaded "linux-0.2.img" # | |
| 378 | # image. Do this with in the Ubuntu GUI. Then in the window give it an # | |
| 379 | # address on your subnet and a default gateway in the VM that boots in the # | |
| 380 | # QEMU window that pops up. Break out of the QEMU window inside VirtualBox # | |
| 381 | # use alt + control + command a few times to free the mouse pointer. # | |
| 382 | # Example IP--> **ifconfig eth0 192.168.1.20 netmask 255.255.255.0** # | |
| 383 | # Example Default Gateway-->**route add default gateway 192.168.1.1** # | |
| 384 | # To start a VM copy and paste this into the console # | |
| 385 | ############################################################################ | |
| 386 | #Use unique Mac addresses for hosts e.g. cc:10, cc:11 see details in post # | |
| 387 | ############################################################################ | |
| 388 | Examples to copy and paste (Notice unique MAC addresses on each VM 01, 02, 03) | |
| 389 | kvm -m 128 -net nic,macaddr=22:22:22:00:cc:01 -net tap,script=/etc/ovs-ifup,downscript=/etc/ovs-ifdown -hda linux-0.2.img & | |
| 390 | kvm -m 128 -net nic,macaddr=22:22:22:00:cc:02 -net tap,script=/etc/ovs-ifup,downscript=/etc/ovs-ifdown -hda linux-0.2.img & | |
| 391 | kvm -m 128 -net nic,macaddr=22:22:22:00:cc:03 -net tap,script=/etc/ovs-ifup,downscript=/etc/ovs-ifdown -hda linux-0.2.img & | |
| 392 | Booting one VM with a MAC address of AA:AA:12:34:56:78 as an example. | |
| 393 | When it boots you give it an IP address and gatewat as explanined above. | |
| 394 | Type 'ovs-vsctl show' to the the VNIC (tap0) and OVS configuration | |
| 395 | ################################################################################ | |
| 396 | # -More information about what you can do with this Lab at: # | |
| 397 | - | # http://networkstatic.net/openflow-and-openvswitch-sdn-lab-scripted-in-minutes# |
| 397 | + | # http://networkstatic.net/openflow-openvswitch-and-kvm-sdn-lab-installation-app/ # |
| 398 | # Comments at Twitters @networkstatic, Thanks- Brent Salisbury # | |
| 399 | ################################################################################""") | |
| 400 | ||
| 401 | def main(): | |
| 402 | opt = input("""#####################################################################
| |
| 403 | # This is for lab and learning purposes only to simplify getting # | |
| 404 | # a lab to learn OpenFlow, OpenvSwitch and KVM. The usage is # | |
| 405 | # documented at http://networkstatic.net. I recommend doing these # | |
| 406 | # lab installations with a VM snapshot to rollback to in # | |
| 407 | # case a setting doesnt fit your install. This will only work on # | |
| 408 | # Ubuntu Linux that has connectivity to the Internet. # | |
| 409 | # For the Impatient :) There are four install builds: # | |
| 410 | # 1) *Base install* KVM & OpenvSwitch, Git(hub), Test Kernel image. # | |
| 411 | # 2) Base + FloodLight OpenFlow Controller (Java -Open Source). # | |
| 412 | # 3) Base + POX OpenFlow Controller (Python -Open Source). # | |
| 413 | # 4) Base + OpenvSwitch v1.8.90 with VXlan encapsulation support. # | |
| 414 | ##################################################################### | |
| 415 | # Press *1* to install the KVM & OpenvSwitch Lab: # | |
| 416 | # Option 1 includes Git(GitHub), KVM, OpenvSwitch, a 16Mb # | |
| 417 | # test guest host image and configures OpenvSwitch for use. # | |
| 418 | # This will only run on *Ubuntu* since it uses apt-get for packages.# | |
| 419 | # Run this from the command line in a VM. It will run on a # | |
| 420 | # physical host but will likely cut you off an SSH session since # | |
| 421 | # it changes your eth0 IP to the new OpenvSwitch br-int interface. # | |
| 422 | ##################################################################### | |
| 423 | # Press *2* for the base applications along with the Floodlight # | |
| 424 | # OpenFlow Controller. The controller and OpenvSwitch processes # | |
| 425 | # are started in the application and OpenvSwitch is attached. # | |
| 426 | ##################################################################### | |
| 427 | # Press *3* for the base applications along with the Floodlight # | |
| 428 | # OpenFlow Controller. The controller and OpenvSwitch processes # | |
| 429 | # are started in the application and OpenvSwitch is attached to # | |
| 430 | # the controller by the App. # | |
| 431 | ##################################################################### | |
| 432 | # Press *4* for the base applications with a developmentatl build # | |
| 433 | # of OpenvSwitch that includes the VXLan L2 encapsulation. # | |
| 434 | # This OVS build comes from Mestery at Cisco and Pfaff at Nacira # | |
| 435 | # and is getting pulled from GitHub. This option includes the # | |
| 436 | # OpenvSwitch OF controller with it. # | |
| 437 | Here is a tutorial for configuring VXLan tunnels if you choose #4 # | |
| 438 | http://networkstatic.net/configuring-vxlan-and-gre-tunnels-on-openvswitch/ | |
| 439 | ##################################################################### | |
| 440 | # At then end of the App one example VM is booted at the end of the # | |
| 441 | # program. If the inststall fails, tshoot and restore your orig VM # | |
| 442 | # Installation host does not support HW virtualization KVM defaults # | |
| 443 | # to QEMU which is why it is nice using this small Linux Kernel # | |
| 444 | # since all we need for testing applications is something that has # | |
| 445 | # a client IP stack/functionality. Run the app as root e.g. # | |
| 446 | # "$sudo passwd root" set a passwd then "su" and 'python script.py' # | |
| 447 | ##################################################################### | |
| 448 | # Labs that can be used when you have your VMs up can be found here:# | |
| 449 | # http://networkstatic.net/openflow-starter-tutorial-lab-1/ # | |
| 450 | # This works very well with VMware Fusion from my testing, I have # | |
| 451 | # seen some issues with VirtualBox talking outside of the VMs spun # | |
| 452 | # up, but you really just need the VMs talking to eachother with # | |
| 453 | # to do labs with an OpenFlow controller. VM Fusion is g2g tho. I # | |
| 454 | # havent tested on a Linux or Windows host yet but it should work # | |
| 455 | # fine on both as Python is cross platform goodness. Cheers! -Brent # | |
| 456 | ##################################################################### | |
| 457 | """'\nEnter Option 1, 2, 3 or 4 (Control+C to quit): ') | |
| 458 | print('')
| |
| 459 | if opt == 1: | |
| 460 | print('Installing SDN Lab #1..\n')
| |
| 461 | #Install Lab for KVM and OpenvSwitch testing. | |
| 462 | #Get the default gateway | |
| 463 | GW = subprocess.check_output("""route -n | grep 'UG[ \t]' | awk '{print $2}'""", shell=True)
| |
| 464 | strGW = GW.strip() | |
| 465 | #Get the IP address bound to eth0 we will move this to br0 | |
| 466 | IP = subprocess.check_output("""ifconfig eth0 | awk '/inet addr/ {split ($2,A,":"); print A[2]}'""", shell=True)
| |
| 467 | strIP = IP.strip() | |
| 468 | Netmask = subprocess.check_output("""ifconfig eth0 | sed -rn '2s/ .*:(.*)$/\1/p'""", shell=True)
| |
| 469 | strNetMask = Netmask.strip() | |
| 470 | git() | |
| 471 | kvm() | |
| 472 | OVSinst() | |
| 473 | images() | |
| 474 | etcifup() | |
| 475 | etcifdown() | |
| 476 | OVSconf() | |
| 477 | IPaddrs(strGW, strIP, strNetMask) | |
| 478 | msgEof() | |
| 479 | boot() | |
| 480 | ||
| 481 | elif opt == 2: | |
| 482 | #Install Lab w/FloodLight Controller OpenFlow along with KVM and OpenvSwitch | |
| 483 | print('Installing SDN Lab #2...\n')
| |
| 484 | # the main code goes here | |
| 485 | #Get the default gateway | |
| 486 | GW = subprocess.check_output("""route -n | grep 'UG[ \t]' | awk '{print $2}'""", shell=True)
| |
| 487 | strGW = GW.strip() | |
| 488 | #Get the IP address bound to eth0 we will move this to br0 | |
| 489 | IP = subprocess.check_output("""ifconfig eth0 | awk '/inet addr/ {split ($2,A,":"); print A[2]}'""", shell=True)
| |
| 490 | strIP = IP.strip() | |
| 491 | Netmask = subprocess.check_output("""ifconfig eth0 | sed -rn '2s/ .*:(.*)$/\1/p'""", shell=True)
| |
| 492 | strNetMask = Netmask.strip() | |
| 493 | git() | |
| 494 | kvm() | |
| 495 | OVSinstOF() | |
| 496 | images() | |
| 497 | etcifup() | |
| 498 | etcifdown() | |
| 499 | ovsOFconf(strIP) | |
| 500 | IPaddrs(strGW, strIP, strNetMask) | |
| 501 | floodlight() | |
| 502 | floodEof(strIP) | |
| 503 | boot() | |
| 504 | ||
| 505 | elif opt == 3: | |
| 506 | #Install Lab w/POX Controller OpenFlow along with KVM and OpenvSwitch | |
| 507 | print('Installing SDN Lab #3...\n')
| |
| 508 | # the main code goes here | |
| 509 | #Get the default gateway | |
| 510 | GW = subprocess.check_output("""route -n | grep 'UG[ \t]' | awk '{print $2}'""", shell=True)
| |
| 511 | strGW = GW.strip() | |
| 512 | #Get the IP address bound to eth0 we will move this to br0 | |
| 513 | IP = subprocess.check_output("""ifconfig eth0 | awk '/inet addr/ {split ($2,A,":"); print A[2]}'""", shell=True)
| |
| 514 | strIP = IP.strip() | |
| 515 | Netmask = subprocess.check_output("""ifconfig eth0 | sed -rn '2s/ .*:(.*)$/\1/p'""", shell=True)
| |
| 516 | strNetMask = Netmask.strip() | |
| 517 | git() | |
| 518 | kvm() | |
| 519 | OVSinstOF() | |
| 520 | ovsOFconf(strIP) | |
| 521 | images() | |
| 522 | etcifup() | |
| 523 | etcifdown() | |
| 524 | ovsOFconf(strIP) | |
| 525 | IPaddrs(strGW, strIP, strNetMask) | |
| 526 | pox() | |
| 527 | poxEof() | |
| 528 | boot() | |
| 529 | ||
| 530 | elif opt == 4: | |
| 531 | print('Installing SDN Lab #4..\n')
| |
| 532 | #Install Lab for KVM and OpenvSwitch testing. | |
| 533 | #Get the default gateway | |
| 534 | GW = subprocess.check_output("""route -n | grep 'UG[ \t]' | awk '{print $2}'""", shell=True)
| |
| 535 | strGW = GW.strip() | |
| 536 | #Get the IP address bound to eth0 we will move this to br0 | |
| 537 | IP = subprocess.check_output("""ifconfig eth0 | awk '/inet addr/ {split ($2,A,":"); print A[2]}'""", shell=True)
| |
| 538 | strIP = IP.strip() | |
| 539 | Netmask = subprocess.check_output("""ifconfig eth0 | sed -rn '2s/ .*:(.*)$/\1/p'""", shell=True)
| |
| 540 | strNetMask = Netmask.strip() | |
| 541 | git() | |
| 542 | kvm() | |
| 543 | ovsVXinst() | |
| 544 | images() | |
| 545 | etcifup() | |
| 546 | etcifdown() | |
| 547 | OVSconf() | |
| 548 | IPaddrs(strGW, strIP, strNetMask) | |
| 549 | vxEof() | |
| 550 | boot() | |
| 551 | ||
| 552 | else: | |
| 553 | exit() | |
| 554 | ||
| 555 | ||
| 556 | if __name__ == "__main__": | |
| 557 | main() |