hyperhq / runv

Hypervisor-based Runtime for OCI
Apache License 2.0
826 stars 129 forks source link

Enable ovs #307

Closed HuKeping closed 8 years ago

HuKeping commented 8 years ago

Enable ovs bridge to runv

Rework the AddToBridge function to make it as an router:

HuKeping commented 8 years ago

The test result is:

# docker run -ti -d --net=none busybox sleep 1000000
f0ded245223673433b8cb51f3044a01550430dd215e2ac0b09d290af0bf5bf32
# docker run -ti -d --net=none busybox sleep 1000000
acd270933e320b06fd52b1ae735f8245385f98a4d9eadc6a9c11557a2118c467

docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
acd270933e32        busybox             "sleep 1000000"     7 seconds ago       Up 5 seconds                            kickass_banach
f0ded2452236        busybox             "sleep 1000000"     10 seconds ago      Up 8 seconds                            angry_mccarthy

# docker exec -ti kickass_banach ifconfig
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:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

# docker exec -ti angry_mccarthy ifconfig
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:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

# ps aux | grep listener
root     25045  0.0  0.0 293032 13308 pts/19   Sl+  16:35   0:00 containerd-nslistener
root     25083  0.0  0.0 359624 12900 pts/19   Sl+  16:35   0:00 containerd-nslistener
root     25127  0.0  0.0  15960   948 pts/24   S+   16:35   0:00 grep --color=auto listener

./ovs-runv.sh 25045
+ set -e
+ unset DOCKER_CONTENT_TRUST
+ PID=25045
+ Bridge=ovs-hukp-br0
+ ln -s /proc/25045/ns/net /var/run/netns/25045
+ ip link add A type veth peer name B
+ ovs-vsctl add-port ovs-hukp-br0 A
+ ip link set A up
+ ip link set B netns 25045
+ ip netns exec 25045 ip link set dev B name eth0
+ ip netns exec 25045 ip link set eth0 address 12:34:56:78:9a:bc
+ ip netns exec 25045 ip addr add 10.1.0.2/16 dev eth0
+ ip netns exec 25045 ip link set eth0 up

./ovs-runv-2.sh 25083
+ set -e
+ unset DOCKER_CONTENT_TRUST
+ PID=25083
+ Bridge=ovs-hukp-br0
+ ln -s /proc/25083/ns/net /var/run/netns/25083
+ ip link add AA type veth peer name BB
+ ovs-vsctl add-port ovs-hukp-br0 AA
+ ip link set AA up
+ ip link set BB netns 25083
+ ip netns exec 25083 ip link set dev BB name eth0
+ ip netns exec 25083 ip link set eth0 address 12:34:56:78:9a:bc
+ ip netns exec 25083 ip addr add 10.1.0.3/16 dev eth0
+ ip netns exec 25083 ip link set eth0 up

docker exec -ti kickass_banach ifconfig
eth0      Link encap:Ethernet  HWaddr 52:54:A4:8B:99:A2  
          inet addr:10.1.0.3  Bcast:0.0.0.0  Mask:255.255.0.0
          inet6 addr: fe80::5054:a4ff:fe8b:99a2/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1 errors:0 dropped:0 overruns:0 frame:0
          TX packets:7 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:86 (86.0 B)  TX bytes:578 (578.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:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

docker exec -ti angry_mccarthy ifconfig
eth0      Link encap:Ethernet  HWaddr 52:54:B6:C4:EA:71  
          inet addr:10.1.0.2  Bcast:0.0.0.0  Mask:255.255.0.0
          inet6 addr: fe80::5054:b6ff:fec4:ea71/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1 errors:0 dropped:0 overruns:0 frame:0
          TX packets:7 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:86 (86.0 B)  TX bytes:578 (578.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:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

# ping 10.1.0.2 -c 1
PING 10.1.0.2 (10.1.0.2) 56(84) bytes of data.
64 bytes from 10.1.0.2: icmp_seq=1 ttl=64 time=0.276 ms

--- 10.1.0.2 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.276/0.276/0.276/0.000 ms

# ping 10.1.0.3. -c 1
PING 10.1.0.3 (10.1.0.3) 56(84) bytes of data.
64 bytes from 10.1.0.3: icmp_seq=1 ttl=64 time=0.504 ms

--- 10.1.0.3 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.504/0.504/0.504/0.000 ms
gao-feng commented 8 years ago

LGTM, thanks!