Skip to content

Latest commit

 

History

History
232 lines (149 loc) · 8 KB

README-SDN-SETUP.rdoc

File metadata and controls

232 lines (149 loc) · 8 KB

Setup a RYU, mininet, and Open vSwitch environment

To simulate an SDN network, I previously ran the SDNHub virtual appliance, (found here: sdnhub.org/tutorials/sdn-tutorial-vm/) and configured a simulated SDN network using mininet.

Build a custom VM to simulate and SDN network

After I managed to mess up the SDNHub appliance several times, I decided to build a minimal VM to run the things I care about. Here is how to build that environment:

1.) update your Ubuntu 14.04 VM

% sudo apt-get update
% sudo apt-get upgrade

2.) install openvswitch

% sudo apt-get install openvswitch-switch

3.) install mininet

% sudo apt-get install mininet

4.) get the python utils you will need to install ryu

% sudo apt-get install python-pbr  python-py python-six python-oslo.config \
   python-eventlet python-lxml python-netaddr       python-paramiko    \
   python-routes   python-webob python-sphinx       python-pip

5.) install ryu from source

% sudo apt-get install git 
% git clone https://github.com/osrg/ryu.git
% cd ryu
% sudo python ./setup.py install

Install Ryu REST router and Mininet

0.) After you get the VM running, install a clean copy of ryu from source:

% git clone git://github.com/osrg/ryu.git
% cd ryu
% sudo python ./setup.py install

After you have a clean ryu install, you can run ryu apps like this:

ryu-manager ryu.app.rest_router

but… ryu without an SDN network is not very interesting, so the next step is to get mininet configured to create a simulated SDN network

1.) Run Mininet with a custom config that roughly corresponds to our setup. Place the topo-3sw-6hosts.py from the switchboard/sdn directory of this fine Ruby-On-Rails app into the mininet directory on the SDNHub VM (i.e. the mn directory), and then

cd ./mn
sudo mn --clean
sudo mn --custom ./topo-3sw-6hosts.py --topo mytopo --mac --controller remote --switch ovsk

You can check to make sure things worked by asking mininet to describe the network:

mininet> net
c0
s1 lo:  s1-eth1:h1-eth0 s1-eth2:h2-eth0 s1-eth3:s2-eth1
s2 lo:  s2-eth1:s1-eth3 s2-eth2:h3-eth0 s2-eth3:h4-eth0 s2-eth4:s3-eth1
s3 lo:  s3-eth1:s2-eth4 s3-eth2:h5-eth0 s3-eth3:h6-eth0
h1 h1-eth0:s1-eth1
h2 h2-eth0:s1-eth2
h3 h3-eth0:s2-eth2
h4 h4-eth0:s2-eth3
h5 h5-eth0:s3-eth2
h6 h6-eth0:s3-eth3

Here is how to ask about an individual host state:

mininet> h1 ip link show
132: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN mode DEFAULT 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
139: h1-eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
    link/ether 00:00:00:00:00:01 brd ff:ff:ff:ff:ff:ff

2.) Make sure the switches are all going to speak openflow 1.3 by issuing these commands:

% sudo ovs-vsctl set Bridge s1 protocols=OpenFlow13
% sudo ovs-vsctl set Bridge s2 protocols=OpenFlow13
% sudo ovs-vsctl set Bridge s3 protocols=OpenFlow13

3.) Now delete the IPs set on each host automatically by mininet, and assign addresses that correspond to our real SDN network. From mininet issue these commands:

h1 ip addr del 10.0.0.1/8 dev h1-eth0
h2 ip addr del 10.0.0.2/8 dev h2-eth0
h3 ip addr del 10.0.0.3/8 dev h3-eth0
h4 ip addr del 10.0.0.4/8 dev h4-eth0
h5 ip addr del 10.0.0.5/8 dev h5-eth0
h6 ip addr del 10.0.0.6/8 dev h6-eth0

h1 ip addr add 172.16.96.18/25 dev h1-eth0
h2 ip addr add 172.16.96.16/25 dev h2-eth0
h3 ip addr add 172.16.8.66/26 dev h3-eth0
h4 ip addr add 172.16.8.67/26 dev h4-eth0
h5 ip addr add 172.16.8.2/26 dev h5-eth0
h6 ip addr add 172.16.8.3/26 dev h6-eth0

4.) Now you can run the RYU rest router:

ryu-manager --verbose ryu.app.rest_router

You can tell it is working when this REST call made on the SDNHub VM

$ curl "http://localhost:8080/router/all"

returns this:

[{"internal_network": [{}], "switch_id": "0000000000000001"}, 
{"internal_network": [{}], "switch_id": "0000000000000002"}, 
{"internal_network": [{}], "switch_id": "0000000000000003"}]

nothing is configured yet, but ryu is working

5.) In mininet, set default routes for the hosts:

mininet> h1 ip route add default via 172.16.96.120
mininet> h2 ip route add default via 172.16.96.120
mininet> h3 ip route add default via 172.16.8.75
mininet> h4 ip route add default via 172.16.8.75
mininet> h5 ip route add default via 172.16.8.15
mininet> h6 ip route add default via 172.16.8.15

6.) Now we can configure the SDN switches. First, add routes for the host networks. This could be done from Switchboard, or you can do it by hand via curl commands.

curl -X POST -d '{"address":"172.16.96.120/25"}' http://localhost:8080/router/0000000000000001
curl -X POST -d '{"address":"172.16.8.75/26"}' http://localhost:8080/router/0000000000000002
curl -X POST -d '{"address":"172.16.8.15/26"}' http://localhost:8080/router/0000000000000003

set up the routes for the networks that interconnect the switches:

curl -X POST -d '{"address":"172.16.47.1/30"}' http://localhost:8080/router/0000000000000001
curl -X POST -d '{"address":"172.16.47.2/30"}' http://localhost:8080/router/0000000000000002
curl -X POST -d '{"address":"172.16.47.5/30"}' http://localhost:8080/router/0000000000000002
curl -X POST -d '{"address":"172.16.47.6/30"}' http://localhost:8080/router/0000000000000003

and add default routes between the switches

curl -X POST -d '{"gateway": "172.16.47.2"}' http://localhost:8080/router/0000000000000001
curl -X POST -d '{"gateway": "172.16.47.1"}' http://localhost:8080/router/0000000000000002
curl -X POST -d '{"gateway": "172.16.47.5"}' http://localhost:8080/router/0000000000000003

add a static route from s2 to s3

curl -X POST -d '{"destination": "172.16.8.0/26", "gateway": "172.16.47.6"}' http://localhost:8080/router/0000000000000002

7.) In mininet, you should now be able to ping between hosts connected to different SDN switches

mininet> h1 ping 172.16.8.66

8.) To save on the tedium of copypasta mininet config commands for the hosts in the future you can use the config-ip script to override the default IP assignments that mininet made, and set up the hosts’ default routes.

Copy config-ip from the switchboard/sdn directory to the directory where you put topo-3sw-6hosts.py and run mininet something like this:

sudo mn --clean
sudo mn --custom topo-3sw-6hosts.py --topo mytopo --mac --controller remote \
        --switch ovsk --pre config-ip

9.) See more examples in rest-curl source/documentation and at osrg.github.io/ryu-book/en/html/rest_router.html

10.) Including VLAN tagged networks

Suppose you want to simulate a scenario with a mixture of un-tagged traffic and vlan-tagged addresses/routes. To test this scenario, there is a set of config and start scripts in the SDN subdirectory. Here are the parts to look at:

a shell script that launches mininet and configures it:

start-mn-vlan-3sw-6hosts

the topology file

vlan-topo-3sw-6hosts.py

the configuration for mininet after the topology has been built

vlan-3sw-6hosts-config-ip

The idea here is to have one set of hosts and routes that are untagged and another set that are tagged as being on vlan 2.

The un-tagged hosts and routes are h2, h4 and h6 (connected to sw1, sw2, and sw3 respectively). The hosts living on VLAN 2 are h1, h3, and h5 (connected to sw1, sw2, and sw3 respectively).

Note that some fancy footwork is required to add a network dev and address in mininet for the vlan; that is what is going on here in the config-ip file:

h1 ip link add link h1-eth0 name h1-eth0.2 type vlan id 2
h3 ip link add link h3-eth0 name h3-eth0.2 type vlan id 2
h5 ip link add link h5-eth0 name h5-eth0.2 type vlan id 2
py "add our official network addresses for VLAN"
h1 ip addr add 172.17.96.18/25 dev h1-eth0.2
h3 ip addr add 172.17.8.66/26 dev h3-eth0.2
h5 ip addr add 172.17.8.2/26 dev h5-eth0.2
py "mark the VLAN links as up"
h1 ip link set dev h1-eth0.2 up
h3 ip link set dev h3-eth0.2 up
h5 ip link set dev h5-eth0.2 up

The even numbered hosts are configured as in the non-vlan example.