-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathovn_ovs_topology.sh
executable file
·175 lines (143 loc) · 6.13 KB
/
ovn_ovs_topology.sh
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/bin/bash
#Stop execution if any error in encountered
set -e
#Assumes that the system has RHEL 9
DIR=~/
function install_dpdk {
dnf install git meson python3-pip
pip3 install pyelftools
#Clone and install DPDK, OVS, OVN
cd $DIR
wget https://fast.dpdk.org/rel/dpdk-21.11.2.tar.xz
tar xf dpdk-21.11.2.tar.xz
export DPDK_DIR=$DIR/dpdk-stable-21.11.2
cd $DPDK_DIR
export DPDK_BUILD=$DPDK_DIR/build
meson build
ninja -C build
ninja -C build install
ldconfig
}
function config_path {
export PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig
export PATH=$PATH:/usr/local/share/openvswitch/scripts
export DB_SOCK=/usr/local/var/run/openvswitch/db.sock
export PATH=$PATH:/usr/local/share/ovn/scripts
export PYTHONPATH=/usr/local/share/openvswitch/python
export LD_LIBRARY_PATH=/usr/local/lib64
}
function install_ovs_ovn {
cd $DIR
#Build and install OVS with DPDK shared libraries
git clone https://github.com/openvswitch/ovs.git
cd ovs && ./boot.sh
./configure --with-dpdk=shared
make; make install
ovs-ctl start
cd $DIR #Build and install OVN
git clone https://github.com/ovn-org/ovn.git
cd ovn && ./boot.sh; ./configure --with-ovs-source=$DIR/ovs
make; make install
ovs-vsctl set open . external_ids:ovn-remote="unix:/usr/local/var/run/ovn/ovnsb_db.sock"
}
function install_frr {
#Build and install FRR
dnf groupinstall "Development Tools" -y
subscription-manager register --username=rh-ee-spk --password=Redhat27
dnf install python3-requests -y
dnf install python3-pip -y
subscription-manager repos --disable rhel-9-for-x86_64-appstream-beta-rpms
subscription-manager repos --disable rhel-9-for-x86_64-baseos-beta-rpms
dnf install json-c-devel.x86_64 elfutils-libelf-devel.x86_64 python3-devel.x86_64 readline-devel.x86_64 libcap-devel.x86_64 byacc.x86_64 patch python3-sphinx.noarch python3-pytest.noarch texinfo nmap cmake pcre2-devel -y
dnf install protobuf.x86_64 protobuf-c.x86_64 protobuf-c-compiler.x86_64 protobuf-c-devel.x86_64 protobuf-compiler.x8_64 -y
cd $DIR
git clone https://github.com/CESNET/libyang.git
cd libyang
git checkout v2.0.0
mkdir build; cd build
dnf install cmake doxygen pcre2-devel -y
cmake -D CMAKE_INSTALL_PREFIX:PATH=/usr -D CMAKE_BUILD_TYPE:String="Release" ..
make
make install
dnf install readline readline-devel.x86_64 libcap libcap-devel.x86_64 -y
cd $DIR
git clone https://github.com/FRRouting/frr.git
cd frr
./bootstrap.sh
./configure --prefix=/usr --localstatedir=/var/run/frr --sbindir=/usr/lib/frr --sysconfdir=/etc/frr --enable-pimd --enable-watchfrr --enable-fpm --enable-protobuf
make && make install
#configuration
cp -r /usr/local/src/frr/tools/etc/frr/ /etc/frr
adduser frr
groupadd frrvty
chown -r frr:frr /etc/frr
chown frr:frrvty /etc/frr/vtysh.conf
cp tools/frr.service /etc/systemd/system
}
#DONE
# OVN - 1 router, 1 switch
# OVS - Namespace connecting to OVS using veth interfaces
# OVN: sw0-port1 -- sw0 --- lr0 --- Public --- ln-public ~~~~~~ br-ex
# OVS: sw0-port1 ~~~~~ veth0 -- br-int -- br-ex -- eno2 ~~~~~~~ ln-public
# NS - red: eth0-r ~~~~~ veth0
# NS - green: acts as a external network, NS - red acts as a VM in system with OVS OVN.
#Create network namespace
function create_topo {
ip netns list
ip netns add red
ip link add eth0-r type veth peer name veth-r
ip link set eth0-r netns red
ovs-vsctl --may-exist add-br br-int
ip link set veth-r up
ip netns exec red ip link
ovs-vsctl add-port br-int veth-r
ovs-vsctl set interface veth-r external_ids:iface-id=sw0-port1
ovs-vsctl show
ip netns exec red ip link set dev lo up
ip netns exec red ip link set dev eth0-r up
ip netns exec red ip address add 10.0.0.2/24 dev eth0-r
ip netns exec red ip addr
mac_red=$(ip netns exec red ip a show dev eth0-r | grep ether | awk -F " " '{print $2}')
echo "MAC: $mac_red"
ip netns add green
ip link add eth0-g type veth peer name veth-g
ip link set eth0-g netns green
ip netns exec green ip link set dev lo up
ip netns exec green ip link set dev eth0-g up
ip netns exec green ip a a 5.5.5.4/24 dev eth0-g
ovs-vsctl add-br br-ex
ovs-vsctl add-port br-ex veth-g
ovs-vsctl add-port br-ex patch-br-ex-br-int -- set interface patch-br-ex-br-int type=patch options:peer=patch-br-int-br-ex -- add-port br-int patch-br-int-br-ex -- set interface patch-br-int-br-ex type=patch options:peer=patch-br-ex-br-int
vlan_tag=0
#OVN topology
ovn-nbctl ls-add sw0
ovn-nbctl set logical_switch sw0 other_config:subnet="10.0.0.0/24" other_config:exclude_ips="10.0.0.1"
ovn-nbctl lsp-add sw0 sw0-port1
ovn-nbctl lsp-set-addresses sw0-port1 "${mac_red} 10.0.0.2"
ovn-nbctl lsp-add sw0 lrp0-attachment
ovn-nbctl lsp-set-type lrp0-attachment router
ovn-nbctl lsp-set-options lrp0-attachment router-port=lrp0
ovn-nbctl lsp-set-addresses lrp0-attachment router
ovn-nbctl lr-add lr0
ovn-nbctl lrp-add lr0 lrp0 00:00:00:00:ff:01 10.0.0.1/24
ovn-nbctl lrp-add lr0 lr0-public 0a:00:20:20:12:13 5.5.5.1/24
ovn-nbctl ls-add public
ovn-nbctl lsp-add public ln-public "" $vlan_tag
ovn-nbctl lsp-set-type ln-public localnet
ovn-nbctl lsp-set-addresses ln-public unknown
ovn-nbctl lsp-set-options ln-public network_name=public
ovn-nbctl clear logical_switch_Port ln-public parent_name
ovn-nbctl lsp-add public public-lr0
ovn-nbctl lsp-set-type public-lr0 router
ovn-nbctl lsp-set-addresses public-lr0 router
ovn-nbctl lsp-set-options public-lr0 router-port=lr0-public
mgmt_ip=`hostname -I | awk '{print $1}'`
ovs-vsctl set open . external_ids:ovn-bridge-mappings="public:br-ex"
ovs-vsctl set open . external_ids:ovn-encap-type=geneve
ovs-vsctl set open . external_ids:ovn-encap-ip=$mgmt_ip
ip netns exec red ip r a default via 10.0.0.1 dev eth0-r
#On the external network
ip netns exec green ip r a 192.168.0.0/24 via 5.5.5.1 dev eth0-g
#Ping between external network(green) to netns red should work
ip netns exec red ping 5.5.5.4
}