forked from shettyg/ovn-namespace
-
Notifications
You must be signed in to change notification settings - Fork 0
/
case5.sh
140 lines (110 loc) · 3.68 KB
/
case5.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
# Logical network:
# 2 LRs - R1, R2 that are connected to each other via LS "join"
# in 20.0.0.0/24 network. R1 has switchess foo (192.168.1.0/24)
# and bar (192.168.2.0/24) connected to it. R2 has alice (172.16.1.0/24)
# R2 is a static (non-distributed) router. R1 and R2 are connected via switch "join"
# Do SNAT south-north
usage () {
cat << EOF
usage: case3.sh COMMAND
Commands:
host1 --chassis=$chassis Run commands for host1. This host has northd running.
host2 --db=tcp:IP:6640 Run commands for host2
EOF
}
host1 () {
echo $1
case $1 in
--chassis=*)
chassis=`expr X"$1" : 'X[^=]*=\(.*\)'`
shift
;;
esac
if [ -z "$chassis" ]; then
echo "chassis not given"
exit 1
fi
ovn-nbctl create Logical_Router name=R1
ovn-nbctl create Logical_Router name=R2 options:chassis=$chassis
ovn-nbctl ls-add foo
ovn-nbctl ls-add bar
ovn-nbctl ls-add alice
ovn-nbctl ls-add join
# Connect foo to R1
ovn-nbctl -- --id=@lrp create Logical_Router_port name=foo \
network=192.168.1.1/24 mac=\"00:00:01:01:02:03\" -- add Logical_Router R1 \
ports @lrp -- lsp-add foo rp-foo
ovn-nbctl set Logical_switch_port rp-foo type=router options:router-port=foo \
addresses=\"00:00:01:01:02:03\"
# Connect bar to R1
ovn-nbctl -- --id=@lrp create Logical_Router_port name=bar \
network=192.168.2.1/24 mac=\"00:00:01:01:02:04\" -- add Logical_Router R1 \
ports @lrp -- lsp-add bar rp-bar
ovn-nbctl set Logical_switch_port rp-bar type=router options:router-port=bar \
addresses=\"00:00:01:01:02:04\"
# Connect alice to R2
ovn-nbctl -- --id=@lrp create Logical_Router_port name=alice \
network=172.16.1.1/24 mac=\"00:00:02:01:02:03\" -- add Logical_Router R2 \
ports @lrp -- lsp-add alice rp-alice
ovn-nbctl set Logical_switch_port rp-alice type=router options:router-port=alice \
addresses=\"00:00:02:01:02:03\"
# Connect R1 to join
ovn-nbctl -- --id=@lrp create Logical_Router_port name=R1_join \
network=20.0.0.1/24 mac=\"00:00:04:01:02:03\" -- add Logical_Router R1 \
ports @lrp -- lsp-add join r1-join
ovn-nbctl set Logical_switch_port r1-join type=router options:router-port=R1_join \
addresses='"00:00:04:01:02:03"'
# Connect R2 to join
ovn-nbctl -- --id=@lrp create Logical_Router_port name=R2_join \
network=20.0.0.2/24 mac=\"00:00:04:01:02:04\" -- add Logical_Router R2 \
ports @lrp -- lsp-add join r2-join
ovn-nbctl set Logical_switch_port r2-join type=router options:router-port=R2_join \
addresses='"00:00:04:01:02:04"'
ovn-nbctl -- --id=@lrt create Logical_Router_Static_Route \
ip_prefix=172.16.1.0/24 nexthop=20.0.0.2 -- add Logical_Router \
R1 static_routes @lrt
ovn-nbctl -- --id=@lrt create Logical_Router_Static_Route \
ip_prefix=192.168.1.0/24 nexthop=20.0.0.1 -- add Logical_Router \
R2 static_routes @lrt
ovn-nbctl -- --id=@lrt create Logical_Router_Static_Route \
ip_prefix=192.168.2.0/24 nexthop=20.0.0.1 -- add Logical_Router \
R2 static_routes @lrt
sh ovn-port.sh add-port foo foo1 192.168.1.2/24 192.168.1.1
sh ovn-port.sh add-port bar bar1 192.168.2.2/24 192.168.2.1
# bar1 can ping alice1 and alice1 receives traffic from 30.0.0.1
ovn-nbctl -- --id=@nat create nat type="snat" logical_ip=192.168.2.2 \
external_ip=30.0.0.1 -- add logical_router R2 nat @nat
}
host2 () {
case $1 in
--db=*)
DB=`expr X"$1" : 'X[^=]*=\(.*\)'`
shift
;;
esac
if [ -z "$DB" ]; then
echo "DB not given"
exit 1
fi
sh ovn-port.sh add-port --db=$DB alice alice1 172.16.1.2/24 172.16.1.1
}
case $1 in
"host1")
shift
host1 "$*"
exit 0
;;
"host2")
shift
host2 "$@"
exit 0
;;
-h | --help)
usage
exit 0
;;
*)
echo >&2 "$UTIL: unknown command \"$1\" (use --help for help)"
exit 1
;;
esac