openstack 网络环境模拟

背景环境

moni.png

环境介绍:
上述环境是模拟openstack网络环境,分为外网区域、计算节点区域、网络节点区域;外网区域主要模拟外网的网关和路由,计算节点区域模拟openstack计算节点物理机器,网络节点区域模拟openstack网络节点物理机器
计算节点区域和外网交换机,通过vlan206、vlan1000、vlan2000连接到外网交换机,其中valn206是外网浮动ip网段的ip,vlan1000为私网10.10.10.0/24,vlan2000位私网192.168.16.0/24
网络节点区域和外网交换机,br-int通过vlan1000,vlan2000连接外网交换机连接,br-public通过vlan206连接外网交换机
外网区域是计算节点和网络节点网关所在地,同时该区域连接外网接口enp0s8,计算节点和网络节点通过外围区域上外网
ubuntun操作系统区域,是ubuntu系统安装的系统的机器,上述环境是在一个机器中模拟所有节点情况。

环境搭建脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
ovs-vsctl add-br br-int-1
ovs-vsctl add-br br-int-2
ovs-vsctl add-br sw
ovs-vsctl add-br br-public

ip netns add vm1
ip netns add vm2
ip netns add dhcp1
ip netns add dhcp2
ip netns add router
ip netn add gw

ovs-vsctl add-port br-int-1 vm1-eth0 tag=1000 -- set Interface vm1-eth0 type=internal
ip link set vm1-eth0 netns vm1
ip netns exec vm1 ifconfig vm1-eth0 10.10.10.10/24 up
ip netns exec vm1 route add default gw 10.10.10.1
ip netns exec vm1 ifconfig lo up

ovs-vsctl add-port br-int-1 vm2-eth0 tag=2000 -- set Interface vm2-eth0 type=internal
ip link set vm2-eth0 netns vm2
ip netns exec vm2 ifconfig vm2-eth0 192.168.16.10/24 up
ip netns exec vm2 route add default gw 192.168.16.1
ip netns exec vm2 ifconfig lo up

ovs-vsctl add-port br-int-2 dhcp1-tap tag=1000 -- set Interface dhcp1-tap type=internal
ip link set dhcp1-tap netns dhcp1
ip netns exec dhcp1 ifconfig dhcp1-tap 10.10.10.2/24 up
ip netns exec dhcp1 ifconfig lo up

ovs-vsctl add-port br-int-2 dhcp2-tap tag=2000 -- set Interface dhcp2-tap type=internal
ip link set dhcp2-tap netns dhcp2
ip netns exec dhcp2 ifconfig dhcp2-tap 192.168.16.2/24 up
ip netns exec dhcp2 ifconfig lo up

ovs-vsctl add-port br-int-2 router-tap1 tag=1000 -- set Interface router-tap1 type=internal
ip link set router-tap1 netns router
ip netns exec router ifconfig router-tap1 10.10.10.1/24 up
ip netns exec router ifconfig lo up

ovs-vsctl add-port br-int-2 router-tap2 tag=2000 -- set Interface router-tap2 type=internal
ip link set router-tap2 netns router
ip netns exec router ifconfig router-tap2 192.168.16.1/24 up
ip netns exec router ifconfig lo up


ovs-vsctl add-port br-int-1 trunk_int1 trunks=1000,2000,206 -- set Interface trunk_int1 type=patch options:peer=trunk_sw1
ovs-vsctl add-port sw trunk_sw1 trunks=1000,2000,206 -- set Interface trunk_sw1 type=patch options:peer=trunk_int1


ovs-vsctl add-port br-int-2 trunk_int2 trunks=1000,2000 -- set Interface trunk_int2 type=patch options:peer=trunk_sw2
ovs-vsctl add-port sw trunk_sw2 trunks=1000,2000 -- set Interface trunk_sw2 type=patch options:peer=trunk_int2


ovs-vsctl add-port br-public router-qg tag=206 -- set Interface router-qg type=internal
ip link set router-qg netns router
ip netns exec router ifconfig router-qg 192.168.206.11/24 up
ip netns exec router ifconfig lo up



ovs-vsctl add-port sw provider-gw tag=206 -- set Interface provider-gw type=internal
ip link set provider-gw netns gw
ip netns exec gw ifconfig provider-gw 192.168.206.254/24 up
ip netns exec gw ifconfig lo up



ovs-vsctl add-port br-public trunk_pub trunks=206 -- set Interface trunk_pub type=patch options:peer=trunk_sw3
ovs-vsctl add-port sw trunk_sw3 trunks=206 -- set Interface trunk_sw3 type=patch options:peer=trunk_pub


ifconfig br-public 192.168.206.10/24 up
ip netns exec router route add default gw 192.168.206.254


ovs-vsctl add-br br-ex
ovs-vsctl add-port br-ex ex-gw -- set Interface ex-gw type=internal
ip link set ex-gw netns gw
ip netns exec gw ifconfig ex-gw 10.30.10.100/24 up
ip netns exec gw ifconfig lo up
ip netns exec gw route add default gw 10.30.10.1


ip netns exec gw iptables -t nat -A POSTROUTING -s 192.168.206.0/24 -o ex-gw -j MASQUERADE

ovs-vsctl add-port br-ex enp0s8
ip addr flush dev enp0s8
ifconfig br-ex 10.30.10.145/24
route add default gw 10.30.10.1


ip netns exec router sysctl net.ipv4.ip_forward=1
ip netns exec gw sysctl net.ipv4.ip_forward=1

ip netns exec router iptables -t nat -A POSTROUTING -s 10.10.10.0/24 -o router-qg -j MASQUERADE
ip netns exec router iptables -t nat -A POSTROUTING -s 192.168.16.0/24 -o router-qg -j MASQUERADE

环境搭建完成后查看ovs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
root@controller-VirtualBox:~# ovs-vsctl show
73065536-d00b-440c-a02f-b8d33ef05ee1
Bridge "br-int-1"
Port "br-int-1"
Interface "br-int-1"
type: internal
Port "vm2-eth0"
tag: 2000
Interface "vm2-eth0"
type: internal
Port "trunk_int1"
trunks: [206, 1000, 2000]
Interface "trunk_int1"
type: patch
options: {peer="trunk_sw1"}
Port "vm1-eth0"
tag: 1000
Interface "vm1-eth0"
type: internal
Bridge br-public
Port trunk_pub
trunks: [206]
Interface trunk_pub
type: patch
options: {peer="trunk_sw3"}
Port router-qg
tag: 206
Interface router-qg
type: internal
Port br-public
Interface br-public
type: internal
Bridge sw
Port "trunk_sw3"
trunks: [206]
Interface "trunk_sw3"
type: patch
options: {peer=trunk_pub}
Port provider-gw
tag: 206
Interface provider-gw
type: internal
Port "trunk_sw2"
trunks: [1000, 2000]
Interface "trunk_sw2"
type: patch
options: {peer="trunk_int2"}
Port "trunk_sw1"
trunks: [206, 1000, 2000]
Interface "trunk_sw1"
type: patch
options: {peer="trunk_int1"}
Port sw
Interface sw
type: internal
Bridge "br-int-2"
Port "br-int-2"
Interface "br-int-2"
type: internal
Port "dhcp1-tap"
tag: 1000
Interface "dhcp1-tap"
type: internal
Port "router-tap1"
tag: 1000
Interface "router-tap1"
type: internal
Port "router-tap2"
tag: 2000
Interface "router-tap2"
type: internal
Port "trunk_int2"
trunks: [1000, 2000]
Interface "trunk_int2"
type: patch
options: {peer="trunk_sw2"}
Port "dhcp2-tap"
tag: 2000
Interface "dhcp2-tap"
type: internal
Bridge br-ex
Port "enp0s8"
Interface "enp0s8"
Port ex-gw
Interface ex-gw
type: internal
Port br-ex
Interface br-ex
type: internal
ovs_version: "2.5.2"