You are on page 1of 14

1|Page

GI LP SDN TRN MI TRNG


MININET .

Kch bn gi lp :

- Gi lp mi trng trn nn my o Oracle VM VirtualBox


- Thc hin m phng 1 m hnh mng SDN trn mi trng gi lp.
- Thc hin mt s thao tc trn mng gi lp.

1
2|Page

Bc 1 : Download v ci t h iu hnh Ubuntu 16.04 LTS .

http://mirror-fpt-telecom.fpt.net/ubuntu-releases/16.04.2/ubuntu-16.04.2-desktop-
amd64.iso

Bc 2 : Download v ci t Mininet.
git clone git://github.com/mininet/mininet
mininet/util/install.sh a
// Sau khi ci t xong, thc hin test th
sudo mn --test pingall

Bc 3 : Download v ci t Opendayligh Controller.


// Ci t JDK
# sudo add-apt-repository ppa:webupd8team/java
# sudo apt update
# sudo apt install oracle-java8-installer
// kim tra version Java
#java -version
# javac version
// Ci t cc bin mi trng cho java
#sudo apt-get install default-jre -y
#sudo apt-get install default-jdk -y
#sudo apt-get install python-software-properties -y
#sudo add-apt-repository ppa:webupd8team/java -y
#sudo apt-get update -y
#sudo apt-get upgrade -y
#sudo apt install oracle-java8-installer -y
#sudo apt install oracle-java8-set-default -y
#sudo apt-get install openjdk-8-jre -y
#sudo apt-get install openjdk-8-jdk y
// Ci t MAVEN
# sudo apt-get update
# sudo apt-get install maven -y
// check trng thi Maven ci t
# mvn v
//Ci t ODL
#sudo wget -c
https://nexus.opendaylight.org/content/repositories/opendaylight.release/or
g/opendaylight/integration/distribution-karaf/0.5.2-Boron-SR2/distribution-
karaf-0.5.2-Boron-SR2.zip
#sudo unzip distribution-karaf-0.5.2-Boron-SR2.zip
#cd distribution-karaf-0.5.2-Boron-SR2/
#sudo ./bin/karaf
// Ci t cc feature cho ODL:
opendaylight-user@root>feature:install odl-l2switch-switch-ui
opendaylight-user@root> feature:install odl-restconf odl-mdsal-apidocs odl-
dlux-all

2
3|Page

// Qu trnh ci t hon tt !

Bc 4 : Gi lp m hnh mng SDN trn mi trng Mininet v ODL


Controller

Thc hin khi to Topo nh sau :

Thc hin khi ng ODL.


#cd distribution-karaf-0.5.2-Boron-SR2/
#sudo ./bin/karaf

Thc hin khi ng Mininet


minhnh24@minhnh24-VirtualBox:~$ sudo mn --mac --topo single,3 --controller
remote --switch ovsk,protocols=OpenFlow13
*** Creating network
*** Adding controller
Connecting to remote controller at 127.0.0.1:6653
*** Adding hosts:
h1 h2 h3
*** Adding switches:
s1
*** Adding links:
(h1, s1) (h2, s1) (h3, s1)
*** Configuring hosts
h1 h2 h3
*** Starting controller
c0

3
4|Page

*** Starting 1 switches


s1 ...
*** Starting CLI:
mininet>

Test kt ni :
mininet> pingall
*** Ping: testing ping reachability
h1 -> X X
h2 -> X X
h3 -> X X
*** Results: 100% dropped (0/6 received)
mininet>
mininet>
mininet>
mininet> links
h1-eth0<->s1-eth1 (OK OK)
h2-eth0<->s1-eth2 (OK OK)
h3-eth0<->s1-eth3 (OK OK)
mininet> dump
<Host h1: h1-eth0:10.0.0.1 pid=5337>
<Host h2: h2-eth0:10.0.0.2 pid=5340>
<Host h3: h3-eth0:10.0.0.3 pid=5342>
<OVSSwitch{'protocols': 'OpenFlow13'} s1: lo:127.0.0.1,s1-eth1:None,s1-
eth2:None,s1-eth3:None pid=5347>
<RemoteController c0: 127.0.0.1:6653 pid=5330>
mininet> nodes
available nodes are:
c0 h1 h2 h3 s1
mininet> net
h1 h1-eth0:s1-eth1
h2 h2-eth0:s1-eth2
h3 h3-eth0:s1-eth3
s1 lo: s1-eth1:h1-eth0 s1-eth2:h2-eth0 s1-eth3:h3-eth0
c0
mininet> h1 ifconfig -a
h1-eth0 Link encap:Ethernet HWaddr 00:00:00:00:00:01
inet addr:10.0.0.1 Bcast:10.255.255.255 Mask:255.0.0.0
inet6 addr: fe80::200:ff:fe00:1/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:56 errors:0 dropped:32 overruns:0 frame:0
TX packets:15 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:6506 (6.5 KB) TX bytes:990 (990.0 B)

lo Link encap:Local Loopback


inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:2 errors:0 dropped:0 overruns:0 frame:0
TX packets:2 errors:0 dropped:0 overruns:0 carrier:0

4
5|Page

collisions:0 txqueuelen:1
RX bytes:224 (224.0 B) TX bytes:224 (224.0 B)

mininet> h2 ifconfig -a
h2-eth0 Link encap:Ethernet HWaddr 00:00:00:00:00:02
inet addr:10.0.0.2 Bcast:10.255.255.255 Mask:255.0.0.0
inet6 addr: fe80::200:ff:fe00:2/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:56 errors:0 dropped:32 overruns:0 frame:0
TX packets:15 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:6506 (6.5 KB) TX bytes:990 (990.0 B)

lo Link encap:Local Loopback


inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:2 errors:0 dropped:0 overruns:0 frame:0
TX packets:2 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:224 (224.0 B) TX bytes:224 (224.0 B)

mininet> h3 ifconfig -a
h3-eth0 Link encap:Ethernet HWaddr 00:00:00:00:00:03
inet addr:10.0.0.3 Bcast:10.255.255.255 Mask:255.0.0.0
inet6 addr: fe80::200:ff:fe00:3/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:56 errors:0 dropped:32 overruns:0 frame:0
TX packets:15 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:6506 (6.5 KB) TX bytes:990 (990.0 B)

lo Link encap:Local Loopback


inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:2 errors:0 dropped:0 overruns:0 frame:0
TX packets:2 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:224 (224.0 B) TX bytes:224 (224.0 B)

mininet> s1 ifconfig -a
enp0s3 Link encap:Ethernet HWaddr 08:00:27:6f:c0:96
inet addr:192.168.5.104 Bcast:192.168.5.255 Mask:255.255.255.0
inet6 addr: fe80::2911:4fe7:890c:8688/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:14996 errors:0 dropped:0 overruns:0 frame:0
TX packets:3055 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:21203633 (21.2 MB) TX bytes:265240 (265.2 KB)

enp0s8 Link encap:Ethernet HWaddr 08:00:27:a8:90:66


inet addr:192.168.56.101 Bcast:192.168.56.255

5
6|Page

Mask:255.255.255.0
inet6 addr: fe80::175c:1aa4:3f54:5a5d/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:456 errors:0 dropped:0 overruns:0 frame:0
TX packets:95 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:79614 (79.6 KB) TX bytes:13045 (13.0 KB)

lo Link encap:Local Loopback


inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:3964 errors:0 dropped:0 overruns:0 frame:0
TX packets:3964 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:605358 (605.3 KB) TX bytes:605358 (605.3 KB)

ovs-system Link encap:Ethernet HWaddr 2e:a7:c4:52:3e:8f


BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

s1 Link encap:Ethernet HWaddr ea:0b:fb:9c:df:4a


BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

s1-eth1 Link encap:Ethernet HWaddr 5a:b0:31:a8:40:01


inet6 addr: fe80::58b0:31ff:fea8:4001/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:15 errors:0 dropped:0 overruns:0 frame:0
TX packets:56 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:990 (990.0 B) TX bytes:6506 (6.5 KB)

s1-eth2 Link encap:Ethernet HWaddr 82:85:b8:f7:57:5b


inet6 addr: fe80::8085:b8ff:fef7:575b/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:15 errors:0 dropped:0 overruns:0 frame:0
TX packets:56 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:990 (990.0 B) TX bytes:6506 (6.5 KB)

s1-eth3 Link encap:Ethernet HWaddr d6:ac:a5:97:1a:3a


inet6 addr: fe80::d4ac:a5ff:fe97:1a3a/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:15 errors:0 dropped:0 overruns:0 frame:0
TX packets:56 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000

6
7|Page

RX bytes:990 (990.0 B) TX bytes:6506 (6.5 KB)

mininet>
mininet> c0 ifconfig -a
enp0s3 Link encap:Ethernet HWaddr 08:00:27:6f:c0:96
inet addr:192.168.5.104 Bcast:192.168.5.255 Mask:255.255.255.0
inet6 addr: fe80::2911:4fe7:890c:8688/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:15198 errors:0 dropped:0 overruns:0 frame:0
TX packets:3124 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:21224146 (21.2 MB) TX bytes:276334 (276.3 KB)

enp0s8 Link encap:Ethernet HWaddr 08:00:27:a8:90:66


inet addr:192.168.56.101 Bcast:192.168.56.255
Mask:255.255.255.0
inet6 addr: fe80::175c:1aa4:3f54:5a5d/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:663 errors:0 dropped:0 overruns:0 frame:0
TX packets:99 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:109427 (109.4 KB) TX bytes:13641 (13.6 KB)

lo Link encap:Local Loopback


inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:4317 errors:0 dropped:0 overruns:0 frame:0
TX packets:4317 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:626832 (626.8 KB) TX bytes:626832 (626.8 KB)

ovs-system Link encap:Ethernet HWaddr 2e:a7:c4:52:3e:8f


BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

s1 Link encap:Ethernet HWaddr ea:0b:fb:9c:df:4a


BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

s1-eth1 Link encap:Ethernet HWaddr 5a:b0:31:a8:40:01


inet6 addr: fe80::58b0:31ff:fea8:4001/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:15 errors:0 dropped:0 overruns:0 frame:0
TX packets:58 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:990 (990.0 B) TX bytes:6912 (6.9 KB)

7
8|Page

s1-eth2 Link encap:Ethernet HWaddr 82:85:b8:f7:57:5b


inet6 addr: fe80::8085:b8ff:fef7:575b/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:15 errors:0 dropped:0 overruns:0 frame:0
TX packets:58 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:990 (990.0 B) TX bytes:6912 (6.9 KB)

s1-eth3 Link encap:Ethernet HWaddr d6:ac:a5:97:1a:3a


inet6 addr: fe80::d4ac:a5ff:fe97:1a3a/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:15 errors:0 dropped:0 overruns:0 frame:0
TX packets:58 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:990 (990.0 B) TX bytes:6912 (6.9 KB)

mininet>

Bc 5. Thc hin gi lp 1 m trng mng SDN trn Mininet c kt ni n


Controller ODL s dng cng c h tr MiniEdit.

Khi ng MiniEdit
# sudo python mininet/examples/miniedit.py

Thc hin khi to 1 topo mng gi lp trn MiniEdit.

8
9|Page

Thc hin run Mininet.

Thc hin kt ni cc OVS vi Controller.


sudo ovs-vsctl set-controller s1 tcp:127.0.0.1:6633
sudo ovs-vsctl set-controller s2 tcp:127.0.0.1:6633
sudo ovs-vsctl set-controller s3 tcp:127.0.0.1:6633
sudo ovs-vsctl set-controller s4 tcp:127.0.0.1:6633
sudo ovs-vsctl set-controller s5 tcp:127.0.0.1:6633
sudo ovs-vsctl set-controller s6 tcp:127.0.0.1:6633

Thc hin check kt ni :


netstat -an | grep 6633
tcp 0 0 127.0.0.1:45274 127.0.0.1:6633 ESTABLISHED
tcp 0 0 127.0.0.1:45280 127.0.0.1:6633 ESTABLISHED
tcp 0 0 127.0.0.1:45284 127.0.0.1:6633 ESTABLISHED
tcp 0 0 127.0.0.1:45278 127.0.0.1:6633 ESTABLISHED
tcp 0 0 127.0.0.1:45282 127.0.0.1:6633 ESTABLISHED
tcp 0 0 127.0.0.1:45276 127.0.0.1:6633 ESTABLISHED
tcp6 0 0 :::6633 :::* LISTEN
tcp6 0 0 127.0.0.1:6633 127.0.0.1:45284 ESTABLISHED
tcp6 0 0 127.0.0.1:6633 127.0.0.1:45278 ESTABLISHED
tcp6 0 0 127.0.0.1:6633 127.0.0.1:45276 ESTABLISHED
tcp6 0 0 127.0.0.1:6633 127.0.0.1:45274 ESTABLISHED
tcp6 0 0 127.0.0.1:6633 127.0.0.1:45280 ESTABLISHED
tcp6 0 0 127.0.0.1:6633 127.0.0.1:45282 ESTABLISHED

Thc hin kt ni n giao din Web ca ODL theo URL :


http://127.0.0.1:8181/index.html#

Hoc c th truy cp t remote host thng qua a ch My o.

http://192.168.5.104:8181/index.html#

Thc hin ng nhp bng :

Username : admin

Password : admin

9
10 | P a g e

Giao din topology :

10
11 | P a g e

Giao din Nodes:

Bc 6 : Mininet flow analytics

Download v ci t phn mm, khi ng sFlow :


# wget http://www.inmon.com/products/sFlow-RT/sflow-rt.tar.gz
# tar -xvzf sflow-rt.tar.gz
# cd sflow-rt
# ./start.sh
# 2017-03-21T23:14:09+0700 INFO: Listening, sFlow port 6343
# 2017-03-21T23:14:10+0700 INFO: Listening, HTTP port 8008

Thc hin check kt ni :


minhnh24@minhnh24-VirtualBox:~$ netstat -an | grep 8008
tcp6 0 0 :::8008 :::* LISTEN
tcp6 0 7 192.168.5.103:8008 192.168.5.128:51021 ESTABLISHED
minhnh24@minhnh24-VirtualBox:~$

Thc hin start Mininet topo


sudo mn --custom extras/sflow.py --link tc,bw=10 --topo
tree,depth=2,fanout=2
*** No default OpenFlow controller found for default switch!

11
12 | P a g e

*** Falling back to OVS Bridge


*** Creating network
*** Adding controller
*** Adding hosts:
h1 h2 h3 h4
*** Adding switches:
s1 s2 s3
*** Adding links:
(10.00Mbit) *** Error: RTNETLINK answers: No such file or directory
(10.00Mbit) *** Error: RTNETLINK answers: No such file or directory
(s1, s2) (10.00Mbit) *** Error: RTNETLINK answers: No such file or
directory
(10.00Mbit) *** Error: RTNETLINK answers: No such file or directory
(s1, s3) (10.00Mbit) *** Error: RTNETLINK answers: No such file or
directory
(10.00Mbit) *** Error: RTNETLINK answers: No such file or directory
(s2, h1) (10.00Mbit) *** Error: RTNETLINK answers: No such file or
directory
(10.00Mbit) *** Error: RTNETLINK answers: No such file or directory
(s2, h2) (10.00Mbit) *** Error: RTNETLINK answers: No such file or
directory
(10.00Mbit) *** Error: RTNETLINK answers: No such file or directory
(s3, h3) (10.00Mbit) *** Error: RTNETLINK answers: No such file or
directory
(10.00Mbit) *** Error: RTNETLINK answers: No such file or directory
(s3, h4)
*** Configuring hosts
h1 h2 h3 h4
*** Starting controller

*** Starting 3 switches


s1 s2 s3 ...(10.00Mbit) (10.00Mbit) (10.00Mbit) (10.00Mbit) (10.00Mbit)
(10.00Mbit) (10.00Mbit) (10.00Mbit)
*** Enabling sFlow:
s1 s2 s3
*** Sending topology
*** Starting CLI:
mininet> iperf h1 h3
*** Iperf: testing TCP bandwidth between h1 and h3
*** Results: ['9.36 Mbits/sec', '10.5 Mbits/sec']
mininet>
mininet>
mininet>
mininet>
mininet>
mininet> iperf h1 h3
*** Iperf: testing TCP bandwidth between h1 and h3
*** Results: ['9.46 Mbits/sec', '10.1 Mbits/sec']
mininet> pingall
*** Ping: testing ping reachability
h1 -> h2 h3 h4
h2 -> h1 h3 h4
h3 -> h1 h2 h4

12
13 | P a g e

h4 -> h1 h2 h3
*** Results: 0% dropped (12/12 received)
mininet> h1 ping -f h3
PING 10.0.0.3 (10.0.0.3) 56(84) bytes of data.
. ^C
--- 10.0.0.3 ping statistics ---
4664573 packets transmitted, 4664573 received, 0% packet loss, time
534243ms
rtt min/avg/max/mdev = 0.008/0.043/145.194/0.128 ms, pipe 2, ipg/ewma
0.114/0.031 ms
mininet>

Thc hin m trnh duyt v check lu lng :

http://192.168.5.103:8008/agents/html

C th m rng sFlow bng cch nh ngha cc Flow theo di lu lng trn giao
din web realtime.
#!/usr/bin/env python
import requests
import json

rt = 'http://127.0.0.1:8008'

flow = {'keys':'link:inputifindex,ipsource,ipdestination','value':'bytes'}
requests.put(rt+'/flow/pair/json',data=json.dumps(flow))

threshold = {'metric':'pair','value':1000000/8,'byFlow':True,'timeout':1}
requests.put(rt+'/threshold/elephant/json',data=json.dumps(threshold))

eventurl = rt+'/events/json?thresholdID=elephant&maxEvents=10&timeout=60'
eventID = -1
while 1 == 1:
r = requests.get(eventurl + "&eventID=" + str(eventID))
if r.status_code != 200: break
events = r.json()
if len(events) == 0: continue

13
14 | P a g e

eventID = events[0]["eventID"]
events.reverse()
for e in events:
print e['flowKey']

Hng dn nh ngha Flow :

http://blog.sflow.com/2013/08/restflow.html

http://sflow-rt.com/writing_applications.php

14

You might also like