Wednesday, June 15, 2016

Linux Port Information

ubuntuport

Linux Port Information

What ports enabled in the Server.

root@kiloceilo:~# netstat -atun
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 192.168.122.1:53        0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:9696            0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:6080            0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:516             0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:8773            0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:8774            0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:8775            0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:9191            0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:44040           0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:8777            0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:9292            0.0.0.0:*               LISTEN

What services running in the port.

介紹lsof,這個指令對搞系統的來說應該要跟ls一樣熟。 為了強化大家的記憶,我就多說點lsof的背景,英文內涵為list open files。 為何用open file,對每個session來講都會產生一個port,在kernel中稱它為file。 這點我們可以透過ulimit -a查看,open file項,顯示1024表示最多1024個連線,這是可以被優化的。
現在我們可以將lsof指令記得更熟了吧。

root@kiloceilo:~# ulimit -a
.
.
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024

我們來查查8773port是什麼,nova-api。

root@kiloceilo:~# lsof -n -i4TCP:8773 | grep LISTEN
nova-api 3911 root    6u  IPv4  20035      0t0  TCP *:8773 (LISTEN)
nova-api 4271 root    6u  IPv4  20035      0t0  TCP *:8773 (LISTEN)
nova-api 4274 root    6u  IPv4  20035      0t0  TCP *:8773 (LISTEN)
nova-api 4294 root    6u  IPv4  20035      0t0  TCP *:8773 (LISTEN)
nova-api 4295 root    6u  IPv4  20035      0t0  TCP *:8773 (LISTEN)
nova-api 4300 root    6u  IPv4  20035      0t0  TCP *:8773 (LISTEN)
nova-api 4303 root    6u  IPv4  20035      0t0  TCP *:8773 (LISTEN)

Ignore protocol filter

lsof -n -i:80 | grep LISTEN

To check how many connection to mysql. Here we ignore some repeating. From localhost, by other hostname or ip address. 我們可以透過這個指令查到,服務與服務間,host與服務間的連線狀態,藉以了解整個系統的架構為何。

root@kiloceilo:~# lsof -i@127.0.0.1:mysql
COMMAND    PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
mysqld    2389 mysql   31u  IPv4  20443      0t0  TCP localhost:mysql->localhost:36602 (ESTABLISHED)
mysqld    2389 mysql   32u  IPv4  22561      0t0  TCP localhost:mysql->localhost:36607 (ESTABLISHED)
apache2   2931 stack   17u  IPv4  20721      0t0  TCP localhost:36613->localhost:mysql (ESTABLISHED)
apache2   2941 stack   17u  IPv4  20871      0t0  TCP localhost:36708->localhost:mysql (ESTABLISHED)
python    3832  root    3u  IPv4  20442      0t0  TCP localhost:36602->localhost:mysql (ESTABLISHED)
python    3832  root   17u  IPv4  66758      0t0  TCP localhost:36800->localhost:mysql (ESTABLISHED)
python    3832  root   18u  IPv4  58123      0t0  TCP localhost:36792->localhost:mysql (ESTABLISHED)
nova-cert 3838  root    4u  IPv4  20715      0t0  TCP localhost:36611->localhost:mysql (ESTABLISHED)
nova-sche 3844  root    4u  IPv4  20718      0t0  TCP localhost:36612->localhost:mysql (ESTABLISHED)
nova-sche 3844  root    5u  IPv4  22159      0t0  TCP localhost:36620->localhost:mysql (ESTABLISHED)
nova-cons 3853  root    4u  IPv4  22113      0t0  TCP localhost:36610->localhost:mysql (ESTABLISHED)
ceilomete 3860  root    5u  IPv4  28262      0t0  TCP localhost:36736->localhost:mysql (ESTABLISHED)
ceilomete 3870  root    8u  IPv4  20834      0t0  TCP localhost:36695->localhost:mysql (ESTABLISHED)
glance-re 3935  root    8u  IPv4  22471      0t0  TCP localhost:36709->localhost:mysql (ESTABLISHED)
glance-re 3942  root    8u  IPv4  48805      0t0  TCP localhost:36775->localhost:mysql (ESTABLISHED)
glance-re 3948  root    8u  IPv4  72908      0t0  TCP localhost:36818->localhost:mysql (ESTABLISHED)
nova-cond 4074  root    6u  IPv4  22110      0t0  TCP localhost:36607->localhost:mysql (ESTABLISHED)
nova-cond 4076  root    6u  IPv4  22564      0t0  TCP localhost:36608->localhost:mysql (ESTABLISHED)
nova-api  4261  root   11u  IPv4  20842      0t0  TCP localhost:36700->localhost:mysql (ESTABLISHED)
nova-api  4262  root   11u  IPv4  29859      0t0  TCP localhost:36734->localhost:mysql (ESTABLISHED)

You can replace 127.0.0.1 to any other host you are intrested or just ignore this parameter.

Obtaning what service connected to rabbitmq.

root@kiloceilo:~# lsof -i@172.16.235.128:amqp
.
.

nova-cert 3838     root    5u  IPv4  22158      0t0  TCP 172.16.235.128:53157->172.16.235.128:amqp (ESTABLISHED)
python    3841     root   17u  IPv4  20373      0t0  TCP 172.16.235.128:53139->172.16.235.128:amqp (ESTABLISHED)
python    3843     root    7u  IPv4  19765      0t0  TCP 172.16.235.128:53121->172.16.235.128:amqp (ESTABLISHED)
python    3843     root    8u  IPv4  19769      0t0  TCP 172.16.235.128:53123->172.16.235.128:amqp (ESTABLISHED)
nova-sche 3844     root    6u  IPv4  22160      0t0  TCP 172.16.235.128:53159->172.16.235.128:amqp (ESTABLISHED)
python    3851     root    4u  IPv4  20553      0t0  TCP 172.16.235.128:53124->172.16.235.128:amqp (ESTABLISHED)
python    3851     root    5u  IPv4  20554      0t0  TCP 172.16.235.128:53125->172.16.235.128:amqp (ESTABLISHED)
python    3851     root    6u  IPv4  20555      0t0  TCP 172.16.235.128:53126->172.16.235.128:amqp (ESTABLISHED)
python    3851     root    7u  IPv4  21078      0t0  TCP 172.16.235.128:53266->172.16.235.128:amqp (ESTABLISHED)
nova-cons 3853     root    5u  IPv4  22574      0t0  TCP 172.16.235.128:53153->172.16.235.128:amqp (ESTABLISHED)
ceilomete 3859     root    4u  IPv4  20496      0t0  TCP 172.16.235.128:53114->172.16.235.128:amqp (ESTABLISHED)
ceilomete 3860     root    4u  IPv4  22072      0t0  TCP 172.16.235.128:53141->172.16.235.128:amqp (ESTABLISHED)
ceilomete 3860     root    7u  IPv4  29971      0t0  TCP 172.16.235.128:53275->172.16.235.128:amqp (ESTABLISHED)
ceilomete 3861     root    6u  IPv4  23066      0t0  TCP 172.16.235.128:53248->172.16.235.128:amqp (ESTABLISHED)
neutron-v 3862     root    4u  IPv4  18934      0t0  TCP 172.16.235.128:53127->172.16.235.128:amqp (ESTABLISHED)
neutron-v 3862     root    5u  IPv4  18935      0t0  TCP 172.16.235.128:53128->172.16.235.128:amqp (ESTABLISHED)
neutron-v 3862     root    6u  IPv4  27042      0t0  TCP 172.16.235.128:53267->172.16.235.128:amqp (ESTABLISHED)
neutron-v 3862     root    9u  IPv4  21166      0t0  TCP 172.16.235.128:53268->172.16.235.128:amqp (ESTABLISHED)
nova-comp 3871     root    4u  IPv4  22605      0t0  TCP 172.16.235.128:53163->172.16.235.128:amqp (ESTABLISHED)
nova-comp 3871     root    5u  IPv4  22608      0t0  TCP 172.16.235.128:53164->172.16.235.128:amqp (ESTABLISHED)
nova-comp 3871     root   18u  IPv4  22929      0t0  TCP 172.16.235.128:53208->172.16.235.128:amqp (ESTABLISHED)
nova-comp 3871     root   21u  IPv4  58069      0t0  TCP 172.16.235.128:53329->172.16.235.128:amqp (ESTABLISHED)
ceilomete 3872     root   11u  IPv4  49675      0t0  TCP 172.16.235.128:53321->172.16.235.128:amqp (ESTABLISHED)
ceilomete 3917     root    5u  IPv4  19754      0t0  TCP 172.16.235.128:53116->172.16.235.128:amqp (ESTABLISHED)
nova-cond 4074     root    7u  IPv4  20722      0t0  TCP 172.16.235.128:53154->172.16.235.128:amqp (ESTABLISHED)
nova-cond 4074     root    9u  IPv4  22609      0t0  TCP 172.16.235.128:53165->172.16.235.128:amqp (ESTABLISHED)
nova-cond 4075     root    7u  IPv4  20723      0t0  TCP 172.16.235.128:53155->172.16.235.128:amqp (ESTABLISHED)
nova-api  4262     root   12u  IPv4  29861      0t0  TCP 172.16.235.128:53273->172.16.235.128:amqp (ESTABLISHED)

172.16.235.128:53208->172.16.235.128:amqp表示,由nova-compute發起的連線(port number53208),連到amqp。

Sunday, June 12, 2016

Playing Openvswitch And Namespace: Veth-pairs, Internal Port, Bridge, Vlan, Vxlan, DHCP, and L3 Routing Tutorial

playingvswitchNS

OpenVswitch And Namespace Playing

thanks for

https://read01.com/GQRaP2.html

本篇文章主要是手動完成vswitch, namespace達成以下設定

  1. veth-pairs, internal port and vswitch bridge連結方法
  2. Vlan setting
  3. VXlan setting
  4. DHCP service
  5. L3 routing service。

讀完這篇大家大概就會對OpenStack Neutron的DHCP,L3 routing,與OpenStack中vswitch, namespace 與device的觀念更加清晰。 我的做法跟OpenStack Neutron的做法是有差異的,但主要我想做的事是,經過此教學,可以對Neutron有跟深的感覺,當你想到neutron怎麼運作時,可以透過本文章的教學來做聯想。

這篇文章很重要,但我寫得很亂,因為最近實在太忙了.....

或許,我可以找個時間,好好描述一下OpenStack Neutron是怎麼做的。

install vswitch

apt-get install openvswitch-switch

Two Namespeces connected by a Vswitch Bridge

  1. two namespace (foonet, bobnet)
  2. one v bridge (ovsbr)
  3. connect to bridge and communication each other
ip netns add foonet
ip netns add bobnet
ovs-vsctl add-br ovsbr

create a wire, just a real line/wire, two endpoint is called eth0-foo and veth-foo. Furthermore, we will discuss use vswitch port not line/wire. The difference is if you use port two namespace can be connected but line/wire cannot connect.

ip link add eth0-foo type veth peer name veth-foo

where weth peer is defined to connect to bridge/switch.

connect the line to foonet

ip link set eth0-foo netns foonet

connect the line to switch by using ovs-vsctl, since it's vswitch.

ovs-vsctl add-port ovsbr veth-foo

Connect to bobnet

ip link add eth0-bob type veth peer name veth-bob
ip link set eth0-bob netns bobnet
ovs-vsctl add-port ovsbr veth-bob

start to config foonet

To check the initial state of the foonet and exit it

root@openvswitch:~# ip netns exec foonet bash
root@openvswitch:~# ifconfig
root@openvswitch:~#
exit

Config lo device first

root@openvswitch:~# ip netns exec foonet ip link set dev lo up
root@openvswitch:~# ip netns exec foonet 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:0
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

config eth0-foo, where the must the same with you defined before, or it will fail to create it.

ip netns exec foonet ip link set dev eth0-foo up

Check config eth0-foo. In actually, the definition of eth0-foo is just as tap-xx, qvo-xx as OpenStack defined. So it's very clear, how to imagine the tap-device in OpenStack.

root@openvswitch:~# ip netns exec foonet ifconfig
eth0-foo  Link encap:Ethernet  HWaddr 6a:49:62:e1:5b:47
          UP 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)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
 .
 .

Assign an IP to it. and check the result.

root@openvswitch:~# ip netns exec foonet ip address add 10.0.0.10/24 dev eth0-foo
root@openvswitch:~# ip netns exec foonet ifconfig
eth0-foo  Link encap:Ethernet  HWaddr 6a:49:62:e1:5b:47
          inet addr:10.0.0.10  Bcast:0.0.0.0  Mask:255.255.255.0
          UP 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)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
root@openvswitch:~# ip netns exec bobnet ip link set dev lo up
ip netns exec bobnet ip link set dev eth0-bob up
ip netns exec bobnet ip address add 10.0.0.11/24 dev eth0-bob

Ping each other

Now you can log into foonet, and ping bobnet. It should be not connected each other, since they are different namespace.

ip netns exec bobnet bash
root@openvswitch:~# ping 10.0.0.10
PING 10.0.0.10 (10.0.0.10) 56(84) bytes of data.
^C

http://www.rendoumi.com/yong-open-vswitch-de-nei-bu-duan-kou-lian-jie-liang-ge-namespace/ No need to line/wire, just claim an interface eth1 or neth1. Then binds to namespace and bridge with same interface. It can ping each other now. ovs-vsctl add-port br0 nnneth1 -- set Interface eth1 type=internal ip link set nnneth1 netns ns1 where nnneth1 can be think as a port not a wire. This is called internal mode.

Directly connect two Namespaces

create 2 namespace, dir1net and dir2net

root@openvswitch:~# ip netns add dir1net
root@openvswitch:~# ip netns add dir2net

create a line

ip link add eth0-dir type veth peer name veth-dir

Link them

root@openvswitch:~# ip link set eth0-dir netns dir1net
root@openvswitch:~# ip link set veth-dir netns dir2net

Create Line/Wire, adding two side to two namespace and assign network ip address.

root@openvswitch:~# ip netns exec dir1net ip link set dev eth0-dir up
root@openvswitch:~# ip netns exec dir2net ip link set dev veth-dir up

root@openvswitch:~# ip netns exec dir1net ip address add 10.0.0.10/24 dev eth0-dir
root@openvswitch:~# ip netns exec dir2net ip address add 10.0.0.11/24 dev veth-dir

Test connection, it should be connect and we can reuse 10.0.0.11 compare to our previous setting, bobnet, since it's network namespace.

root@openvswitch:~# ip netns exec dir1net bash
root@openvswitch:~# ping 10.0.0.11
PING 10.0.0.11 (10.0.0.11) 56(84) bytes of data.
64 bytes from 10.0.0.11: icmp_seq=1 ttl=64 time=0.046 ms
root@openvswitch:~# ip netns
dir2net
dir1net
bobnet
foonet

Trying Vlan

之前的方式我們採用veth-pairs的做法,現在我們來試試看internal port的做法。這做法不用產生,line/wire,直接用產生的port,如下範例為vlan100, 直接放到bridge與namespace中,就像port插入一般,而非veth-pair有兩個端的做法。 這兩種方法有一些不同,
1. veth-pairs的做法,在同一個bridge相連是不會通的。
2. internal port的做法在同一個bridge中相連是會通的,透過vlan tag的方式做隔離。
OpenStack主要是採用internal port的做法,因此我們接下來我們試試看這種做法。

ovs-vsctl add-br vlanxbr
ip netns add vlan100net
ip netns add vlan200net
ovs-vsctl add-port vlanbr vlan100 tag=100 -- set interface vlan100 type=internal
ifconfig vlan10 192.168.10.254 netmask 255.255.255.0
ip link set vlan100 netns vlan100net
ovs-vsctl add-port vlanxbr vlan200 tag=200 -- set interface vlan200 type=internal
ip link set vlan200 netns vlan200net
root@openvswitch:~# ip netns exec vlan100net ip address add 10.0.0.10/24 dev vlan100
root@openvswitch:~# ip netns exec vlan200net ip address add 10.0.0.11/24 dev vlan200
root@openvswitch:~# ip netns exec vlan100net ip link set dev vlan100 up
root@openvswitch:~# ip netns exec vlan200net ip link set dev vlan200 up
ip netns exec vlan100net ip link set dev lo up
ip netns exec vlan200net ip link set dev lo up

now we construct vlan110net for vlan tag=100, we need to check the inter-connection between different vlan. This way is called "internal port" used by OpenStack.

ip netns add vlan110net
ovs-vsctl add-port vlanbr vlan110 tag=100 -- set interface vlan110 type=internal
ip link set vlan110 netns vlan110net
ip netns exec vlan110net ip address add 10.0.0.12/24 dev vlan110
ip netns exec vlan110net ip link set dev lo up
ip netns exec vlan110net ip link set vlan110 up

Don't forget to bring vlan100 up.

Test vlan tag 100 and 200 inter-connection.

root@openvswitch:~# ip netns exec vlan110net bash
root@openvswitch:~# ping 10.0.0.10
PING 10.0.0.10 (10.0.0.10) 56(84) bytes of data.
64 bytes from 10.0.0.10: icmp_seq=1 ttl=64 time=0.918 ms

root@openvswitch:~# ping 10.0.0.11
PING 10.0.0.11 (10.0.0.11) 56(84) bytes of data.
^C

The result is same vlan can interconection each other but different vlan tag.

Reboot Problem

To show all the command, that is help for understanding the OpenStack Neutron.

ovsdb-tool -mm show-log /etc/openvswitch/conf.db

But it contains only ovs-vsctl commands.

Rebooting will clean all setting !!!!

Trying Vxlan

Environment

host1:172.16.235.128 host2:172.16.235.168

VXlan is working on connecting to other node. In local node we use Vlan

  1. test vlan tag 10 in host1
  2. test vlan tag 10 in host2
  3. use vxlan inter-connection with tag10
  4. ping in n1 to n2
  5. change host2 to tag 20
  6. use vxlan inter-connection
  7. ping in n1 to n2
  8. n3 with tag10, as n1, and connet to n2

Repeat the process to build vlan 100 in both localhost. Adding the following vxlan commmand

In host1

ovs-vsctl add-br vlanbr
ip netns add vlan100-1net
ovs-vsctl add-port vlanbr vlan100 tag=100 -- set interface vlan100 type=internal
ip link set vlan100 netns vlan100-1net
ip netns exec vlan100-1net ip address add 10.0.0.10/24 dev vlan100
ip netns exec vlan100-1net ip link set dev lo up
ip netns exec vlan100-1net ip link set dev vlan100 up

In host2

ovs-vsctl add-br vlanbr
ip netns add vlan100-2net
ovs-vsctl add-port vlanbr vlan100 tag=100 -- set interface vlan100 type=internal
ip link set vlan100 netns vlan100-2net
ip netns exec vlan100-2net ip address add 10.0.0.11/24 dev vlan100
ip netns exec vlan100-2net ip link set dev lo up
ip netns exec vlan100-2net ip link set dev vlan100 up

To host1 and ping vlan100-2net

ping 10.0.0.11

Not Connected.

We add VXlan that enabling the connection between hosts. In host1:

ovs-vsctl add-port vlanbr vxlan0 -- set interface vxlan0 type=vxlan options:remote_ip=172.16.235.168

In host2:

ovs-vsctl add-port vlanbr vxlan0 -- set interface vxlan0 type=vxlan options:remote_ip=172.16.235.128
root@ovsvxlan1:~# ip netns exec vlan100-1net bash
root@ovsvxlan1:~# ping 10.0.0.11
PING 10.0.0.11 (10.0.0.11) 56(84) bytes of data.
64 bytes from 10.0.0.11: icmp_seq=1 ttl=64 time=1.79 ms
64 bytes from 10.0.0.11: icmp_seq=2 ttl=64 time=0.557 ms

It works.

Adding vlan tag 200 in Host2 with networking 10.0.0.21 as before. And it shoud be cannot connected.

root@ovsvxlan1:~# ping 10.0.0.21
PING 10.0.0.21 (10.0.0.21) 56(84) bytes of data.
^C

Adding tag 100 to host2 with networking 10.0.0.15. In host1: with vlan tag 100 and acrross node via vxlan.

root@ovsvxlan1:~# ping 10.0.0.15
PING 10.0.0.15 (10.0.0.15) 56(84) bytes of data.
64 bytes from 10.0.0.15: icmp_seq=1 ttl=64 time=2.10 ms
64 bytes from 10.0.0.15: icmp_seq=2 ttl=64 time=0.814 ms
64 bytes from 10.0.0.15: icmp_seq=3 ttl=64 time=0.477 ms

In Host2: with vlan tag 100 in local node.

root@ovsvxlan2:~# ip netns exec vlan100-2net bash
root@ovsvxlan2:~# ping 10.0.0.15
PING 10.0.0.15 (10.0.0.15) 56(84) bytes of data.
64 bytes from 10.0.0.15: icmp_seq=1 ttl=64 time=0.906 ms
64 bytes from 10.0.0.15: icmp_seq=2 ttl=64 time=0.061 ms

Trying DHCP

In host1

apt-get install dnsmasq

create dhcp namespace

ip netns add dhcpnet
ovs-vsctl add-port vlanbr dhcp100 tag=100 -- set interface dhcp100 type=internal
ip link set dhcp100 netns dhcpnet
ip netns exec dhcpnet ip address add 10.0.0.100/24 dev dhcp100
ip netns exec dhcpnet ip link set dev lo up
ip netns exec dhcpnet ip link set dev dhcp100 up

In openstack the ip address in dhcp namespace is 10.0.0.2, if subnet is 10.0.0.0/24.

launch dnsmasq.

ip netns exec dhcpnet dnsmasq --interface=dhcp100 --dhcp-range=10.0.0.5,10.0.0.150,12h

We will imporve this setting in further discussion.

In Host2 and go to namespace with tag100

ip netns exec vlan100-2net bash

release the original ip.

dhclient -r vlan100

Check network.

root@ovsvxlan2:~# ifconfig
vlan100   Link encap:Ethernet  HWaddr 02:6f:fd:6d:69:3e
          inet6 addr: fe80::6f:fdff:fe6d:693e/64 Scope:Link
          UP BROADCAST RUNNING  MTU:1500  Metric:1
          RX packets:77 errors:0 dropped:0 overruns:0 frame:0
          TX packets:166 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:8865 (8.8 KB)  TX bytes:47100 (47.1 KB)

get IP from dnsmasq

dhclient vlan100

The result is:

root@ovsvxlan2:~# ifconfig
.
.
vlan100   Link encap:Ethernet  HWaddr 02:6f:fd:6d:69:3e
          inet addr:10.0.0.41  Bcast:10.0.0.255  Mask:255.255.255.0
          inet6 addr: fe80::6f:fdff:fe6d:693e/64 Scope:Link
          UP BROADCAST RUNNING  MTU:1500  Metric:1
          RX packets:79 errors:0 dropped:0 overruns:0 frame:0
          TX packets:168 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:9552 (9.5 KB)  TX bytes:47784 (47.7 KB)

We get new ip 10.0.0.41 from dnsmasq. You can also test other namespace with tag 100 in host1.

We talk alot about namespace. In this simulation, we don't have a real VM but use namespace instead. Namespace is greate for simulation.

Trying Routing

Create an external bridge to internet for routing namespace used. The idea is, any namespace/VM setting the gateway to routing namespace, 10.0.0.1. And the traffic flow to routing namespace with 10.0.0.1 and it then nat forward to another nic to internet.

We cannot just use eth0, since we will create namespace device that will connect to bridge. So eth0 is a device we need to make it becoming a bridge, so that the namespace device can connect to.
That's why you will see br-ex in OpenStack. We put internet device eth0 on br-ex, and namespace device connects to br-ex too. We share the same br-ex, so as our experence using internal port we can connect to internet now.

ovs-vsctl add-br br-ex
ovs-vsctl add-port br-ex eth0

ovs-vsctl add-port br-ex tap0 tag=100
ifconfig eth0 0
ifconfig br-ex 172.16.235.128 netmask 255.255.255.0 up
route add default gw 172.16.235.2 dev br-ex metric 100

where 172.16.236.2 is host gateway, you can get from host commands

root@ovsvxlan1:~# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         172.16.235.2    0.0.0.0         UG    100    0        0 br-ex

Now we create an routeing namespace with 2 nics, one in vlanbr that connect by same tenant used. Another in br-ex that go to internet. We set the IP of routing namespace to 10.0.0.1 and route gateway to 172.16.235.2

ip netns add routernet
ovs-vsctl add-port vlanbr tapex tag=100 -- set interface tapex type=internal
ip link set tapex netns routernet
ip netns exec routernet ip address add 10.0.0.1/24 dev tapex
ip netns exec routernet ip link set dev tapex up

ovs-vsctl add-port br-ex tapexex -- set interface tapexex type=internal
ip link set tapexex netns routernet
ip netns exec routernet ip link set dev tapexex up

Inside routernet

Given an external IP, 172.16.235.3, that can connect to 172.16.236.2 gateway, and setup default gw.

Chceck route -n, if the default routeing existed, that will route non-subnet packet to gateway via device.

ip netns exec routernet bash


ifconfig tapexex 172.16.235.3
route add default gw 172.16.235.2 dev tapexex

Define the dev to go out is necessary, since we have two nic device. The routing table shows in routernet namespace

root@ovsvxlan1:~# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         172.16.235.2    0.0.0.0         UG    0      0        0 tapexex
10.0.0.0        *               255.255.255.0   U     0      0        0 tapex
172.16.235.0    *               255.255.255.0   U     0      0        0 tapexex

set up SNAT Routing in routernet. Clean all ip table is necessary, since we tune back the network environment into initail clean state.

iptables --flush
iptables --table nat --flush
iptables --delete
iptables --table nat --delete-chain
echo "1" > /proc/sys/net/ipv4/ip_forward
iptables --table nat --append POSTROUTING --out-interface tapexex -j MASQUERADE
iptables --append FORWARD --in-interface tapex -j ACCEPT

Where out-interface* tapexex is internet device, and in-interface tapex is internal network device.

Set up resolve(routingnet)

root@ovsvxlan1:~# cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 8.8.8.8

You can ping 172.16.234.2 gateway first, and to intenet by ping 8.8.8.8, 168.95.1.1 or www.google.com.

root@ovsvxlan1:~# ping 172.16.235.2
PING 172.16.235.2 (172.16.235.2) 56(84) bytes of data.
64 bytes from 172.16.235.2: icmp_seq=1 ttl=128 time=0.723 ms
^C
--- 172.16.235.2 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.723/0.723/0.723/0.000 ms
root@ovsvxlan1:~# ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=128 time=52.2 ms
^C
--- 8.8.8.8 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 52.216/52.216/52.216/0.000 ms
root@ovsvxlan1:~# ping www.google.com
PING www.google.com (74.125.203.99) 56(84) bytes of data.
64 bytes from th-in-f99.1e100.net (74.125.203.99): icmp_seq=1 ttl=128 time=45.8 ms
^C
--- www.google.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 45.819/45.819/45.819/0.000 ms

In vlan100-3net

ip netns exec vlan100-3net bash

adding routing, to make sure all non-subnet packet routes to default gateway 10.0.0.1.

route add default gw 10.0.0.1

The routing talbe shows

root@ovsvxlan2:~# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         10.0.0.1        0.0.0.0         UG    0      0        0 vlan100

You might clean previous routing table by using

route del -net xxxxx netmask xxxx

modify resolve.conf (vlan100-3net). If you set up dnsmasq with nameserver parameter, you will not modify this file, that will dicuss later.

root@ovsvxlan2:~# cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 8.8.8.8
nameserver 10.0.0.100
search localdomain

ping google.com

root@ovsvxlan2:~# ping www.google.com.tw
PING www.google.com.tw (74.125.204.94) 56(84) bytes of data.
64 bytes from ti-in-f94.1e100.net (74.125.204.94): icmp_seq=1 ttl=127 time=67.8 ms
64 bytes from ti-in-f94.1e100.net (74.125.204.94): icmp_seq=2 ttl=127 time=51.3 ms

After DHCP, Now L3 routing has done.

We now complete DHCP and L3-routing, it's a very simple simulation compared to OpenStack used.
And the point is we got feeling about how OpenStack works.

More about DHCP

We simple introduce how to setup DHCP, and alot of manually process to make the traffic go to internet including change nameserver and routing gateway. You can setup Dnsmasq server with the following parameters that will help you No need to setup anything in VM/namespace, the network is still connect to internet.

In dhcpnet kill the old dnsmasq process.

dnsmasq --interface=dhcp100 --dhcp-range=10.0.0.5,10.0.0.150,12h --server=8.8.8.8 --dhcp-option=option:router,10.0.0.1

In namespace vlan100-3net

ip netns exec vlan100-3net bash

dhclient -r vlan100-3
dhclient vlan100-3

show the route gateway

root@ovsvxlan2:~# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         10.0.0.1        0.0.0.0         UG    0      0        0 vlan100-3
10.0.0.0        0.0.0.0         255.255.255.0   U     0      0        0 vlan100-3

Result

root@ovsvxlan2:~# ping www.google.com
PING www.google.com (64.233.187.103) 56(84) bytes of data.
64 bytes from tj-in-f103.1e100.net (64.233.187.103): icmp_seq=1 ttl=127 time=52.8 ms

Everything works well while gateway and nameserver to dnsmasq.

Conclusion

  1. Use namespace insteads of VM
  2. Using internal port is better than veth-pair, since openstack use intenal port.
  3. The default setting of Interal port to bridge provides you inter-connnection betwen two namespace , but veth-pair is not
  4. Internal port can be seperate by using vlan tag, as OpenStack used.
  5. DHCP howto
  6. Dnsmasq daemon can be launched in namespace. Namespace is so powerful.
  7. namespace dnsmasq will not confuse with localhost dnsmasq, since its in namespace.
  8. L3 Routing howto
  9. L3 Routing need two nics and with NAT setting. Take care the routing setting to internet.
  10. More detailed setting about DHCP including nameserver, and gateway to provide more easy used environment for VM/namespace.
  11. No persistence setting for namespace and openvswitch. All setting must reconfig, localrc, after host reboot, so as OpenStack.

Using Allowd-Address-Pairs in OpenStack

addresspair

Arbitrry IPs setting in VM by using allowed-address-pairs

這是一個很特別的Case,客戶需要的是提供他們的虛機可以在不知道IP的狀況下啟動,並可連通。
我們知道,在OpenStack中IP跟MAC是有Iptable綁定的,任意更改IP都會導致VM對外連網不通。
透過allowed-address-pairs的設定,IP任意變更都可以對外連網了。

在Devstack中執行一下指令,即可開始使用openstack client的工具。

source openrc admin admin
or 
source openrc admin demo

We now use demo user.

To get MacAddress By vm id

Method 1

stack@kiloceilo:~/devstack$ nova list
+--------------------------------------+-------+--------+------------+-------------+------------------+
| ID                                   | Name  | Status | Task State | Power State | Networks         |
+--------------------------------------+-------+--------+------------+-------------+------------------+
| 76a7cc1c-2395-46dc-9082-860ba086e6b8 | test5 | ACTIVE | -          | Running     | private=10.0.0.4 |
+--------------------------------------+-------+--------+------------+-------------+------------------+
stack@kiloceilo:~/devstack$ virsh dumpxml 4|grep mac
    <partition>/machine</partition>
    <type arch='x86_64' machine='pc-i440fx-trusty'>hvm</type>
      <mac address='fa:16:3e:28:d8:c2'/>

Method 2

to get mac address, it's hard to find a cli to get mac address by a simple way. So using a --debug mode to get http response is a better way.

stack@kiloceilo:~/devstack$ nova --debug show 76a7cc1c-2395-46dc-9082-860ba086e6b8
.
.
.

RESP BODY: {"server": {"status": "ACTIVE", "updated": "2016-06-08T07:27:39Z", "hostId": "66b3d5bcf0238e5c02f41ceae66e09a90624594b499b5ef2a52470de", "OS-EXT-SRV-ATTR:host": "kiloceilo", "addresses": {"private": [{"OS-EXT-IPS-MAC:mac_addr": "fa:16:3e:28:d8:c2"

stack@kiloceilo:~/devstack$ neutron port-list
+--------------------------------------+------+-------------------+-------------------------------------------------------------------------------------+
| id                                   | name | mac_address       | fixed_ips                                                                           |
+--------------------------------------+------+-------------------+-------------------------------------------------------------------------------------+
| 0155e3e5-1139-46c1-97a6-54baabf9615e |      | fa:16:3e:be:57:b1 | {"subnet_id": "4f10c5ce-7cf3-481f-af7c-e7ff80a700dc", "ip_address": "172.16.235.3"} |
| 01ca3998-19ae-4b9c-b9bc-1a7e53dff980 |      | fa:16:3e:7b:c6:a5 | {"subnet_id": "ccdb4f67-568b-47a0-b652-c1d8b8d66135", "ip_address": "10.0.0.2"}     |
| 19bae3c4-0b9e-43da-bf05-bd8c84066a10 |      | fa:16:3e:fe:cc:77 | {"subnet_id": "ccdb4f67-568b-47a0-b652-c1d8b8d66135", "ip_address": "10.0.0.1"}     |
| 39dc97e5-6652-43e4-a20a-75a69c8f77d2 |      | fa:16:3e:28:d8:c2 | {"subnet_id": "ccdb4f67-568b-47a0-b652-c1d8b8d66135", "ip_address": "10.0.0.4"}     |

Into Instance from VNC

ping 10.0.0.1 

It's connected well.

ifconfig eth0 10.0.0.5

The network cannot connect to 10.0.0.1

Test allowed-address-pairs

Using above command neutron port-list and find out mac address fa:16:3e:28:d8:c2.

stack@kiloceilo:~/devstack$ neutron port-update 39dc97e5-6652-43e4-a20a-75a69c8f77d2 --allowed-address-pairs type=dict list=true mac_address=fa:16:3e:28:d8:c2,ip_address=10.0.0.0/24
Updated port: 39dc97e5-6652-43e4-a20a-75a69c8f77d2

If you just want some ip addresses not a subnet, try this.

neutron port-update af47ddc2-d6db-4a4d-a922-6e6efcab4737 --allowed-address-pairs type=dict list=true ip_address=172.18.58.94 ip_address=172.18.58.95

Into instnace and change ip to

ifconfig eth0 10.0.0.5

and ping gateway

ping 10.0.0.1

Now it connect to gateway, whatever ip address you set in instance.

Test 2: Launch another VM and Ping with eachother with an arbitrary IP.

In instance1: we modify IP to 10.0.0.100. In instance2(new): the IP is 10.0.0.5, given by neutron.

case 1: instance1 ping instance2(10.0.0.5): connected case 2: instance2 ping instance1(10.0.0.100): connected case 3: instance2 ping previous instance1 IP(10.0.0.4): not connected

The result is satisfied with our expectation.

Up date Ip address

After we assign IP=10.0.0.100, the openstack still not update to it. So we need to update it by following command.

neutron port-update 39dc97e5-6652-43e4-a20a-75a69c8f77d2 --request-format=json --fixed_ips type=dict list=true subnet_id=ccdb4f67-568b-47a0-b652-c1d8b8d66135,ip_address=10.0.0.100
Updated port: 39dc97e5-6652-43e4-a20a-75a69c8f77d2

One can get all the information from the following commands to get port_id and subnet_id according to mac address

neuton port-list 

To check result, now system has been modifed to 10.0.0.100.

 nova list
+--------------------------------------+-------+---------+------------+-------------+--------------------------------+
| ID                                   | Name  | Status  | Task State | Power State | Networks                       |
+--------------------------------------+-------+---------+------------+-------------+--------------------------------+
| 76a7cc1c-2395-46dc-9082-860ba086e6b8 | test5 | ACTIVE  | -          | Running     | private=10.0.0.100             |
| f0ae5328-b858-46c4-ad47-84a8c6d3002e | test6 | SHUTOFF | -          | Shutdown    | private=10.0.0.5, 172.16.235.9 |
+--------------------------------------+-------+---------+------------+-------------+--------------------------------+

After update this, Rebooting the VM will get new ip persistently, and you don't need to set static file in VM.

HOw it works

It works on chain IPtables. First if

neutron port-update 39dc97e5-6652-43e4-a20a-75a69c8f77d2 --allowed-address-pairs type=dict list=true mac_address=fa:16:3e:28:d8:c2,ip_address=10.0.0.111
sudo iptables -nvL
.
.
.
Chain neutron-openvswi-s39dc97e5-6 (1 references)
 pkts bytes target     prot opt in     out     source               destination
    0     0 RETURN     all  --  *      *       10.0.0.111           0.0.0.0/0            MAC FA:16:3E:28:D8:C2 /* Allow traffic from defined IP/MAC pairs. */
    0     0 RETURN     all  --  *      *       10.0.0.101           0.0.0.0/0            MAC FA:16:3E:28:D8:C2 /* Allow traffic from defined IP/MAC pairs. */
    0     0 DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0            /* Drop traffic without an IP/MAC allow rule. */
.
.
.
 

if set 10.0.0.0/24.

neutron port-update 39dc97e5-6652-43e4-a20a-75a69c8f77d2 --allowed-address-pairs type=dict list=true mac_address=fa:16:3e:28:d8:c2,ip_address=10.0.0.0/24
sudo iptables -nvL
.
.

Chain neutron-openvswi-s39dc97e5-6 (1 references)
 pkts bytes target     prot opt in     out     source               destination
    0     0 RETURN     all  --  *      *       10.0.0.0/24          0.0.0.0/0            MAC FA:16:3E:28:D8:C2 /* Allow traffic from defined IP/MAC pairs. */
    0     0 RETURN     all  --  *      *       10.0.0.101           0.0.0.0/0            MAC FA:16:3E:28:D8:C2 /* Allow traffic from defined IP/MAC pairs. */
    0     0 DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0            /* Drop traffic without an IP/MAC allow rule. */

Some useful command

stack@kiloceilo:~/devstack$ nova show 76a7cc1c-2395-46dc-9082-860ba086e6b8
+--------------------------------------+----------------------------------------------------------------+
| Property                             | Value                                                          |
+--------------------------------------+----------------------------------------------------------------+
| OS-DCF:diskConfig                    | AUTO                                                           |
| OS-EXT-AZ:availability_zone          | nova                                                           |
| OS-EXT-SRV-ATTR:host                 | kiloceilo                                                      |
| OS-EXT-SRV-ATTR:hypervisor_hostname  | kiloceilo                                                      |
| OS-EXT-SRV-ATTR:instance_name        | instance-00000003                                              |
| OS-EXT-STS:power_state               | 1                                                              |
| OS-EXT-STS:task_state                | -                                                              |
| OS-EXT-STS:vm_state                  | active                                                         |
| OS-SRV-USG:launched_at               | 2016-06-08T07:27:38.000000                                     |
| OS-SRV-USG:terminated_at             | -                                                              |
| accessIPv4                           |                                                                |
| accessIPv6                           |                                                                |
| config_drive                         | True                                                           |
| created                              | 2016-06-08T07:27:31Z                                           |
| flavor                               | m1.tiny (1)                                                    |
| hostId                               | 66b3d5bcf0238e5c02f41ceae66e09a90624594b499b5ef2a52470de       |
| id                                   | 76a7cc1c-2395-46dc-9082-860ba086e6b8                           |
| image                                | cirros-0.3.3-x86_64-uec (def244bc-7291-45cb-b336-005e90b61d00) |
| key_name                             | -                                                              |
| metadata                             | {}                                                             |
| name                                 | test5                                                          |
| os-extended-volumes:volumes_attached | []                                                             |
| private network                      | 10.0.0.4                                                       |
| progress                             | 0                                                              |
| security_groups                      | default                                                        |
| status                               | ACTIVE                                                         |
| tenant_id                            | e07408c60a9e44b6b38161aaa3f776ae                               |
| updated                              | 2016-06-08T07:27:39Z                                           |
| user_id                              | 606dca546499433a915459e2db358e14                               |
+--------------------------------------+----------------------------------------------------------------+
nova start 76a7cc1c-2395-46dc-9082-860ba086e6b8
Request to start server f0ae5328-b858-46c4-ad47-84a8c6d3002e has been accepted.
stack@kiloceilo:~/devstack$ nova list
+--------------------------------------+-------+--------+------------+-------------+------------------+
| ID                                   | Name  | Status | Task State | Power State | Networks         |
+--------------------------------------+-------+--------+------------+-------------+------------------+
| 76a7cc1c-2395-46dc-9082-860ba086e6b8 | test5 | ACTIVE | -          | Running     | private=10.0.0.4 |
| f0ae5328-b858-46c4-ad47-84a8c6d3002e | test6 | ACTIVE | -          | Running     | private=10.0.0.5 |
+--------------------------------------+-------+--------+------------+-------------+------------------+
neutron port-update PORT_UUID --request-format=json --fixed_ips type=dict list=true subnet_id=SUBNET_UUID,ip_address=IPADDR
stack@kiloceilo:~/devstack$ neutron agent-list
+--------------------------------------+--------------------+-----------+-------+----------------+---------------------------+
| id                                   | agent_type         | host      | alive | admin_state_up | binary                    |
+--------------------------------------+--------------------+-----------+-------+----------------+---------------------------+
| 75e3d39f-2be9-48f4-8b98-364d4e13fc32 | Metadata agent     | kiloceilo | :-)   | True           | neutron-metadata-agent    |
| 8eb719d1-767b-41d0-aa76-e9d19b886057 | DHCP agent         | kiloceilo | :-)   | True           | neutron-dhcp-agent        |
| e2147851-c150-4227-a9b9-42dbcedc0303 | Open vSwitch agent | kiloceilo | :-)   | True           | neutron-openvswitch-agent |
| eb602c1e-97c2-4e04-a3a4-39e3be503170 | L3 agent           | kiloceilo | :-)   | True           | neutron-vpn-agent         |
+--------------------------------------+--------------------+-----------+-------+----------------+---------------------------+

You can see more detailed infomation through neutron agent-show command.

stack@kiloceilo:~/devstack$ neutron agent-show 8eb719d1-767b-41d0-aa76-e9d19b886057
+---------------------+----------------------------------------------------------+
| Field               | Value                                                    |
+---------------------+----------------------------------------------------------+
| admin_state_up      | True                                                     |
| agent_type          | DHCP agent                                               |
| alive               | True                                                     |
| binary              | neutron-dhcp-agent                                       |
| configurations      | {                                                        |
|                     |      "subnets": 1,                                       |
|                     |      "use_namespaces": true,                             |
|                     |      "dhcp_lease_duration": 86400,                       |
|                     |      "dhcp_driver": "neutron.agent.linux.dhcp.Dnsmasq",  |
|                     |      "networks": 1,                                      |
|                     |      "ports": 5                                          |
|                     | }                                                        |
| created_at          | 2016-05-04 04:19:32                                      |
| description         |                                                          |
| heartbeat_timestamp | 2016-06-09 14:12:16                                      |
| host                | kiloceilo                                                |
| id                  | 8eb719d1-767b-41d0-aa76-e9d19b886057                     |
| started_at          | 2016-06-09 14:10:16                                      |
| topic               | dhcp_agent                                               |
+---------------------+----------------------------------------------------------+

To see all the vswitch bridge, we shall have 3 bridges, br-ex, br-int, br-tun. Now we can see what stuff connected to each of 3 bridges; respectively.

stack@kiloceilo:~/devstack$ sudo ovs-vsctl list-br
br-ex
br-int
br-tun

To see more detailed information of bridge

stack@kiloceilo:~/devstack$ sudo ovs-vsctl list-ports br-ex
eth0
phy-br-ex
stack@kiloceilo:~/devstack$ sudo ovs-vsctl list-ports br-tun
patch-int

To see more detailed about br-int. Ingration bridge is most important bridge that could be connect all the resources, including VM, router, and external bridge. This commands show the tap-device

stack@kiloceilo:~/devstack$ sudo ovs-vsctl list-ports br-int
int-br-ex
patch-tun
qg-0155e3e5-11
qr-19bae3c4-0b
qvo39dc97e5-66
qvo820d2836-00
tap01ca3998-19
tapad1f4818-b1
tapb8ce74b5-cb

solved qg, qr, tap01, tap39

To see what we contains the network-namespace

stack@kiloceilo:~/devstack$ ip netns
qrouter-f8cfe243-5908-4003-a776-59ce891e5d80
qdhcp-2b696172-5599-4663-85bd-42de265e56df
stack@kiloceilo:~/devstack$ sudo ip netns exec qdhcp-2b696172-5599-4663-85bd-42de265e56df ip a
.
.
.
5: tap01ca3998-19: <BROADCAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default
    link/ether fa:16:3e:7b:c6:a5 brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.2/24 brd 10.0.0.255 scope global tap01ca3998-19
       valid_lft forever preferred_lft forever
    inet6 fe80::f816:3eff:fe7b:c6a5/64 scope link
       valid_lft forever preferred_lft forever

10.0.0.2 is the ip address of the dhcp service and with tap device tap01ca3998-19 that also shown in sudo ovs-vsctl list-ports br-int that connectd to br-int.

Enter namespace

ip netns exec qrxxxxx bash
ifconfig
.
.
lo
.
tapxxxxx
.
.

You then enter the namespace, type ifconfig, you will see the tapdevice as eth0. It's a good concept to say what is tapdevice.

To check the vrouter.

stack@kiloceilo:~/devstack$ sudo ip netns exec qrouter-f8cfe243-5908-4003-a776-59ce891e5d80 ip a
.
.
6: qg-0155e3e5-11: <BROADCAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default
    link/ether fa:16:3e:be:57:b1 brd ff:ff:ff:ff:ff:ff
    inet 172.16.235.3/24 brd 172.16.235.255 scope global qg-0155e3e5-11
       valid_lft forever preferred_lft forever
    inet 172.16.235.9/32 brd 172.16.235.9 scope global qg-0155e3e5-11
       valid_lft forever preferred_lft forever
    inet6 fe80::f816:3eff:febe:57b1/64 scope link
       valid_lft forever preferred_lft forever
8: qr-19bae3c4-0b: <BROADCAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default
    link/ether fa:16:3e:fe:cc:77 brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.1/24 brd 10.0.0.255 scope global qr-19bae3c4-0b
       valid_lft forever preferred_lft forever
    inet6 fe80::f816:3eff:fefe:cc77/64 scope link
       valid_lft forever preferred_lft forever

The router contains the tap device qr-19bae3c4-0b and with IP **10.0.0.1.

That means, you can connect to VM and ping both of these two IP, you can get response.

where qgxxxx shoud be the floating ip bridge.

where is the VM tap

If you know mac address, you can then get tap-device name by using ifconfig shown as followed

stack@kiloceilo:~/devstack$ ifconfig
.
.
tap39dc97e5-66 Link encap:Ethernet  HWaddr fe:16:3e:28:d8:c2
          inet6 addr: fe80::fc16:3eff:fe28:d8c2/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:11 errors:0 dropped:0 overruns:0 frame:0
          TX packets:19 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:500
          RX bytes:1324 (1.3 KB)  TX bytes:1835 (1.8 KB)

However, you will not see the tap device in vswitch, since it connect to linux bridge. So we should check the linux bridge.

stack@kiloceilo:~/devstack$ brctl show
bridge name bridge id       STP enabled interfaces
qbr39dc97e5-66      8000.fa3282c953c0   no      qvb39dc97e5-66
                            tap39dc97e5-66
qbr820d2836-00      8000.525767799304   no      qvb820d2836-00
                            tap820d2836-00
virbr0      8000.000000000000   yes

we get tap devce tap39dc97e5-66.

We can plot the architect according to the command.

qbr is linux bridge qvxx and tapxx, qr, and qg are tap device (link)

stack@kiloceilo:~/devstack$ sudo ovs-vsctl show
a466163f-4f0a-40a2-bd0c-1a98781fe02c
    Bridge br-tun
        fail_mode: secure
        Port br-tun
            Interface br-tun
                type: internal
        Port patch-int
            Interface patch-int
                type: patch
                options: {peer=patch-tun}
    Bridge br-ex
        Port phy-br-ex
            Interface phy-br-ex
                type: patch
    .
    .
    .

Check packet

stack@kiloceilo:~/devstack$ sudo ovs-ofctl dump-flows br-tun
NXST_FLOW reply (xid=0x4):
 cookie=0x0, duration=3145.114s, table=0, n_packets=244, n_bytes=31473, idle_age=11, priority=1,in_port=1 actions=resubmit(,2)
 cookie=0x0, duration=3144.903s, table=0, n_packets=0, n_bytes=0, idle_age=3144, priority=0 actions=drop
 cookie=0x0, duration=3144.647s, table=2, n_packets=2, n_bytes=684, idle_age=766, priority=0,dl_dst=00:00:00:00:00:00/01:00:00:00:00:00 actions=resubmit(,20)
 cookie=0x0, duration=3144.567s, table=2, n_packets=242, n_bytes=30789, idle_age=11, priority=0,dl_dst=01:00:00:00:00:00/01:00:00:00:00:00 actions=resubmit(,22)
 cookie=0x0, duration=3144.451s, table=3, n_packets=0, n_bytes=0, idle_age=3144, priority=0 actions=drop

How to get tap linked between each other

For VM, you must lunch VM, you then can see the relation between tap and qv device. but ip link cannot display namespace side information.

ip -d link show
.
.
.
13: qbr39dc97e5-66: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default
    link/ether ba:4b:ab:b0:d4:ba brd ff:ff:ff:ff:ff:ff promiscuity 0
    bridge
14: qvo39dc97e5-66: <BROADCAST,MULTICAST,PROMISC,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master ovs-system state UP mode DEFAULT group default qlen 1000
    link/ether 0a:fa:4d:59:5f:41 brd ff:ff:ff:ff:ff:ff promiscuity 2
    veth
15: qvb39dc97e5-66: <BROADCAST,MULTICAST,PROMISC,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master qbr39dc97e5-66 state UP mode DEFAULT group default qlen 1000
    link/ether ba:4b:ab:b0:d4:ba brd ff:ff:ff:ff:ff:ff promiscuity 2
    veth
16: qbr820d2836-00: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default
    link/ether a6:34:a6:b1:fc:8b brd ff:ff:ff:ff:ff:ff promiscuity 0
    bridge
17: qvo820d2836-00: <BROADCAST,MULTICAST,PROMISC,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master ovs-system state UP mode DEFAULT group default qlen 1000
    link/ether 1a:0f:ab:1e:d7:d9 brd ff:ff:ff:ff:ff:ff promiscuity 2
    veth
18: qvb820d2836-00: <BROADCAST,MULTICAST,PROMISC,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master qbr820d2836-00 state UP mode DEFAULT group default qlen 1000
    link/ether a6:34:a6:b1:fc:8b brd ff:ff:ff:ff:ff:ff promiscuity 2
    veth
19: tap39dc97e5-66: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master qbr39dc97e5-66 state UNKNOWN mode DEFAULT group default qlen 500
    link/ether fe:16:3e:28:d8:c2 brd ff:ff:ff:ff:ff:ff promiscuity 1
    tun
20: tap820d2836-00: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master qbr820d2836-00 state UNKNOWN mode DEFAULT group default qlen 500
    link/ether fe:16:3e:53:02:80 brd ff:ff:ff:ff:ff:ff promiscuity 1
    tun

where tap39dc97e5-66 get the Macaddress, belong to VM, and master connect to qbr39dc97e5-66. And qvb39dc97e5-66 connect to qbr39dc97e5-66.

You can also see the link in namespace.

sudo ip netns exec qrouter-f8cfe243-5908-4003-a776-59ce891e5d80 ip -d link show
.
.
7: qg-0155e3e5-11: <BROADCAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN mode DEFAULT group default
    link/ether fa:16:3e:be:57:b1 brd ff:ff:ff:ff:ff:ff promiscuity 1
8: qr-19bae3c4-0b: <BROADCAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN mode DEFAULT group default
    link/ether fa:16:3e:fe:cc:77 brd ff:ff:ff:ff:ff:ff promiscuity 1
stack@kiloceilo:~/devstack$ sudo ip netns exec qdhcp-2b696172-5599-4663-85bd-42de265e56df ip -d link show
.
.
5: tap01ca3998-19: <BROADCAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN mode DEFAULT group default
    link/ether fa:16:3e:7b:c6:a5 brd ff:ff:ff:ff:ff:ff promiscuity 1

So stange tap01caxxx is binded in br-int, it should be not in namespace, not consistence shown in qrouterxx.

v-Router

Check V-router's iptables. And we can see how the floating IP, 172.16.23.9, adding to VM, 10.0.0.5 by using IPtables in namespace with snat and dnat. And How dose the cloudinit, 169.254.169.254 works.

sudo ip netns exec qrouter-f8cfe243-5908-4003-a776-59ce891e5d80 iptables -t nat -S
-P PREROUTING ACCEPT
-P INPUT ACCEPT
-P OUTPUT ACCEPT
-P POSTROUTING ACCEPT
-N neutron-postrouting-bottom
-N neutron-vpn-agen-OUTPUT
-N neutron-vpn-agen-POSTROUTING
-N neutron-vpn-agen-PREROUTING
-N neutron-vpn-agen-float-snat
-N neutron-vpn-agen-snat
-A PREROUTING -j neutron-vpn-agen-PREROUTING
-A OUTPUT -j neutron-vpn-agen-OUTPUT
-A POSTROUTING -j neutron-vpn-agen-POSTROUTING
-A POSTROUTING -j neutron-postrouting-bottom
-A neutron-postrouting-bottom -m comment --comment "Perform source NAT on outgoing traffic." -j neutron-vpn-agen-snat
-A neutron-vpn-agen-OUTPUT -d 172.16.235.9/32 -j DNAT --to-destination 10.0.0.5
-A neutron-vpn-agen-PREROUTING -d 169.254.169.254/32 -i qr-+ -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 9697
-A neutron-vpn-agen-float-snat -s 10.0.0.5/32 -j SNAT --to-source 172.16.235.9
.
.

And 172.16.235.9 is locate in tap qg-0155e3e5-11, where you can use ip a to check it in namespace.

DHCP

One can use ps command to realize the dnsmasq information.

ps aux|grep dnsmasq
.
.
libvirt+   3210  0.0  0.0  28212  2368 ?        S    05:28   0:00 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf
nobody    15768  0.0  0.0  29756  2368 ?        S    09:02   0:00 dnsmasq --no-hosts --no-resolv --strict-order --bind-interfaces --interface=tap01ca3998-19 --except-interface=lo --pid-file=/opt/stack/data/neutron/dhcp/2b696172-5599-4663-85bd-42de265e56df/pid --dhcp-hostsfile=/opt/stack/data/neutron/dhcp/2b696172-5599-4663-85bd-42de265e56df/host --addn-hosts=/opt/stack/data/neutron/dhcp/2b696172-5599-4663-85bd-42de265e56df/addn_hosts --dhcp-optsfile=/opt/stack/data/neutron/dhcp/2b696172-5599-4663-85bd-42de265e56df/opts --dhcp-leasefile=/opt/stack/data/neutron/dhcp/2b696172-5599-4663-85bd-42de265e56df/leases --dhcp-range=set:tag0,10.0.0.0,static,86400s --dhcp-lease-max=256 --conf-file= --domain=openstacklocal

We also obtain the tapdevice by using this command.

DHCP Mac and IP table is here.

stack@kiloceilo:~/devstack$ cat /opt/stack/data/neutron/dhcp/2b696172-5599-4663-85bd-42de265e56df/host
fa:16:3e:28:d8:c2,host-10-0-0-101.openstacklocal,10.0.0.101
fa:16:3e:53:02:80,host-10-0-0-5.openstacklocal,10.0.0.5
fa:16:3e:7b:c6:a5,host-10-0-0-2.openstacklocal,10.0.0.2
fa:16:3e:b8:be:a1,host-10-0-0-3.openstacklocal,10.0.0.3
fa:16:3e:fe:cc:77,host-10-0-0-1.openstacklocal,10.0.0.1

where .1.2 is router and dhcp IP.

To check port with vm_id and so on (great)

We can check qvoxx that bind to VM, the following command will show the qvoxx binds to which VM and VM's Mac address. It's very useful tool that can show all VMs.

sudo ovs-vsctl get Interface qvo820d2836-00 external_ids
{attached-mac="fa:16:3e:53:02:80", iface-id="820d2836-00d7-4f37-847f-344972fc246e", iface-status=active, vm-uuid="f0ae5328-b858-46c4-ad47-84a8c6d3002e"}

and in port

sudo ovs-vsctl get Interface qvo820d2836-00 ofport
6

List all port and name

root@openvswitch:~# ovs-vsctl -- --columns=name,ofport list Interface
name                : ovsbr
ofport              : 65534

name                : veth-foo
ofport              : 1

name                : veth-bob
ofport              : 2

To see port status and ..

root@openvswitch:~# ovs-ofctl show ovsbr
OFPT_FEATURES_REPLY (xid=0x2): dpid:00004aab5354d446
n_tables:254, n_buffers:256
capabilities: FLOW_STATS TABLE_STATS PORT_STATS QUEUE_STATS ARP_MATCH_IP
actions: OUTPUT SET_VLAN_VID SET_VLAN_PCP STRIP_VLAN SET_DL_SRC SET_DL_DST SET_NW_SRC SET_NW_DST SET_NW_TOS SET_TP_SRC SET_TP_DST ENQUEUE
 1(veth-foo): addr:7a:ac:ca:b0:07:b7
     config:     PORT_DOWN
     state:      LINK_DOWN
     current:    10GB-FD COPPER
     speed: 10000 Mbps now, 0 Mbps max
 2(veth-bob): addr:c2:14:a7:54:ce:67
     config:     PORT_DOWN
     state:      LINK_DOWN
     current:    10GB-FD COPPER
     speed: 10000 Mbps now, 0 Mbps max
 LOCAL(ovsbr): addr:52:f0:77:8a:c2:41
     config:     PORT_DOWN
     state:      LINK_DOWN
     speed: 0 Mbps now, 0 Mbps max