基于openvswitch+Docker构建SDN网络测试环境 (使用ovs-docker进行构建)

这是一篇之前写的笔记,主要记录了使用openvswitch + Docker 等进行一个小型的SDN网络搭建的操作步骤。由于
之前临时有其他任务,耽搁了一下,最近开始重新整理,并计划开发一个简单的Python脚本,简化该网络的创建过程。
同时希望该脚本可以和控制器的程序进行融合,方便未来可以和docker更容易的结合在一起。项目地址:DockerSDN。

以下内容或许存在问题,如果在实现过程中发现问题,可与我联系,谢谢、

Date: 2018.7.9
Auther: joliu [email protected]

  • OpenFlow
    • basic knowlege
  • OVS command
    • how to add flow table to open vSwitch
    • how to bind dockers to vSwitch

Install ovs and mininet

learn details about this

Install Docker

Use DaoCloud accelerator

curl -sSL https://get.daocloud.io/docker | sh

Change Docker registry to Aliyun

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://xxxxxxx.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

请替换https://xxxxxxx.mirror.aliyuncs.com,详细配置内容参见我的另外一篇随笔CentOS7使用阿里源安装最新版Docker

Get Basic Docker Image

docker pull alpine

Exercise 1

Create Three Container

docker run -d -i --name RouterA --net=none --privileged alpine sh
docker run -d -i --name RouterB --net=none --privileged alpine sh
docker run -d -i --name RouterC --net=none --privileged alpine sh

Check Containers' Status

[typh@localhost ~]$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS              PORTS               NAMES
37b9ca888f03        alpine              "sh"                About a minute ago   Up About a minute                       RouterC
f1604beb380f        alpine              "sh"                About a minute ago   Up About a minute                       RouterB
3b3c52c5a582        alpine              "sh"                3 minutes ago        Up 3 minutes 

Create Virtual Network Bridge

sudo ovs-vsctl add-br vnbr

Set Protocols

ovs-vsctl set bridge br0 protocols=OpenFlow13

Check the brige is added

[typh@localhost ~]$ sudo ovs-vsctl show
d9d42750-7b9b-4688-adf9-d07f619e9bac
    Bridge vnbr
        Port vnbr
            Interface vnbr
                type: internal
    ovs_version: "2.5.0"

Add Network Port

sudo ovs-docker add-port vnbr eth0 RouterA --ipaddress="10.0.1.1/24"
sudo ovs-docker add-port vnbr eth0 RouterB --ipaddress="10.0.1.2/24"
sudo ovs-docker add-port vnbr eth0 RouterC --ipaddress="10.0.3.1"

Check The Status of vnbr

[typh@localhost ~]$ sudo ovs-vsctl show
d9d42750-7b9b-4688-adf9-d07f619e9bac
    Bridge vnbr
        Port vnbr
            Interface vnbr
                type: internal
        Port "facad1a218c64_l"
            Interface "facad1a218c64_l"
        Port "d48d429fe1894_l"
            Interface "d48d429fe1894_l"
        Port "12437ccb4eab4_l"
            Interface "12437ccb4eab4_l"
    ovs_version: "2.5.0"

Set OpenFlow Port ID

sudo ovs-vsctl set interface facad1a218c64_l ofport_request=100
sudo ovs-vsctl set interface d48d429fe1894_l ofport_request=200
sudo ovs-vsctl set interface 12437ccb4eab4_l ofport_request=300

Connect to ODL Controller

sudo ovs-vsctl set-controller vnbr tcp:127.0.0.1:6633

Check the Connections with Controller

d9d42750-7b9b-4688-adf9-d07f619e9bac
    Bridge vnbr
        Controller "tcp:127.0.0.1:6633"
            is_connected: true
        Port vnbr
            Interface vnbr
                type: internal
        Port "facad1a218c64_l"
            Interface "facad1a218c64_l"
        Port "d48d429fe1894_l"
            Interface "d48d429fe1894_l"
        Port "12437ccb4eab4_l"
            Interface "12437ccb4eab4_l"
    ovs_version: "2.5.0"

Test the connection between the two host By PING

docker exec -it RouterA ping -c 4 10.0.1.2

Generally, they cannot connect with the other.

Add Flows

sudo ovs-ofctl add-flow vnbr "priority=1 idle_timeout=0,in_port=1,actions=output:2"
sudo ovs-ofctl add-flow vnbr "priority=2 idle_timeout=0,in_port=1,actions=output:1"

Get the Flows from vSwitch

ovs-ofctl -O OpenFlow13 dump-flows vnbr

Test Again.

docker exec -it RouterA ping -c 4 10.0.1.2

Example of the successful result.

[master@MiWiFi-R3-srv ~]$ sudo docker exec -it RouterA ping -c 4 10.0.1.2
PING 10.0.1.2 (10.0.1.2): 56 data bytes
64 bytes from 10.0.1.2: seq=0 ttl=64 time=0.062 ms
64 bytes from 10.0.1.2: seq=1 ttl=64 time=0.061 ms
64 bytes from 10.0.1.2: seq=2 ttl=64 time=0.086 ms
64 bytes from 10.0.1.2: seq=3 ttl=64 time=0.078 ms

--- 10.0.1.2 ping statistics ---
4 packets transmitted, 4 packets received, 0% packet loss
round-trip min/avg/max = 0.061/0.071/0.086 ms

Start karaf

feature:install odl-restconf odl-l2switch-switch odl-mdsal-apidocs odl-dlux-all

转载于:https://www.cnblogs.com/NinWoo/p/9649007.html

你可能感兴趣的:(基于openvswitch+Docker构建SDN网络测试环境 (使用ovs-docker进行构建))