-
Notifications
You must be signed in to change notification settings - Fork 61
/
logical_router_static_route_test.go
191 lines (176 loc) · 4.87 KB
/
logical_router_static_route_test.go
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
package goovn
import (
"testing"
"github.com/stretchr/testify/assert"
)
const (
LR2 = "lr2"
IPPREFIX = "10.0.0.1/24"
NEXTHOP = "10.3.0.1"
)
var nextHop2 = "10.3.0.2"
func TestLogicalRouterStaticRoute(t *testing.T) {
ovndbapi := getOVNClient(DBNB)
cmd, err := ovndbapi.LRAdd(LR2, nil)
if err != nil {
t.Fatal(err)
}
err = ovndbapi.Execute(cmd)
if err != nil {
t.Fatal(err)
}
t.Logf("Add router %s Done", LR2)
// verify router create
lrs, err := ovndbapi.LRGet(LR2)
if err != nil {
t.Fatal(err)
}
if len(lrs) != 1 {
t.Fatalf("lr not created %v", lrs)
}
//lr string, ip_prefix string, nexthop string, output_port *string, policy *string, external_ids map[string]string
cmd, err = ovndbapi.LRSRAdd(LR2, IPPREFIX, NEXTHOP, nil, nil, nil)
if err != nil {
t.Fatal(err)
}
err = ovndbapi.Execute(cmd)
if err != nil {
t.Fatalf("Adding static route to lr2 failed with err %v", err)
}
t.Logf("Adding static route %s via %s to LRouter %s Done", IPPREFIX, NEXTHOP, LR2)
// verify static route addition to lr2
lrsr, err := ovndbapi.LRSRList(LR2)
if err != nil {
t.Fatal(err)
}
if len(lrsr) == 0 {
t.Fatalf("Static Route %s not created in %s", IPPREFIX, LR2)
}
assert.Equal(t, true, lrsr[0].IPPrefix == IPPREFIX, "Added static route to lr2")
// add static route IPPREFIX via nextHop2
cmd, err = ovndbapi.LRSRAdd(LR2, IPPREFIX, nextHop2, nil, nil, nil)
if err != nil {
t.Fatal(err)
}
err = ovndbapi.Execute(cmd)
if err != nil {
t.Fatalf("Adding static route to lr2 failed with err %v", err)
}
t.Logf("Adding static route %s via %s to LRouter %s Done", IPPREFIX, nextHop2, LR2)
// verify static route addition to lr2 via nexthop2
lrsr, err = ovndbapi.LRSRList(LR2)
if err != nil {
t.Fatal(err)
}
if len(lrsr) < 2 {
t.Fatalf("Static Route %s via %s not created in %s", IPPREFIX, nextHop2, LR2)
}
found := false
var secondSr *LogicalRouterStaticRoute
for _, sr := range lrsr {
if sr.Nexthop == nextHop2 && sr.IPPrefix == IPPREFIX {
found = true
secondSr = sr
}
}
assert.Equal(t, true, found, "Added second static route to lr2")
// delete static route via nextHop2
cmd, err = ovndbapi.LRSRDelByUUID(LR2, secondSr.UUID)
if err != nil {
t.Fatal(err)
}
err = ovndbapi.Execute(cmd)
if err != nil {
t.Fatalf("Deleting static route from lr2 via %s failed with err %v", nextHop2, err)
}
t.Logf("Deleted static route %s via %s from LRouter %s", IPPREFIX, nextHop2, LR2)
// verify static route via nexthop2 delete from lr2
lrsr, err = ovndbapi.LRSRList(LR2)
if err != nil {
t.Fatal(err)
}
found = false
for _, sr := range lrsr {
if sr.Nexthop == nextHop2 && sr.IPPrefix == IPPREFIX {
found = true
}
}
assert.Equal(t, false, found, "Deleted second static route from lr2")
// Delete the static route from lr2
cmd, err = ovndbapi.LRSRDel(LR2, IPPREFIX, nil, nil, nil)
if err != nil {
t.Fatal(err)
}
err = ovndbapi.Execute(cmd)
if err != nil {
t.Fatalf("Deleting static route from lr2 failed with err %v", err)
}
t.Logf("Deleting static route %s from LRouter %s Done", IPPREFIX, LR2)
// verify static route delete from lr2
lrsr, err = ovndbapi.LRSRList(LR2)
if err != nil {
t.Fatal(err)
}
if len(lrsr) != 0 {
t.Fatalf("Static Route %s not deleted in %s", IPPREFIX, LR2)
}
assert.Equal(t, true, len(lrsr) == 0, "Deleted static route from lr2")
// Add static route with policy and output_port.
outputPort := "lsp1"
policy := "src-ip"
cmd, err = ovndbapi.LRSRAdd(LR2, IPPREFIX, NEXTHOP, &outputPort, &policy, nil)
if err != nil {
t.Fatal(err)
}
err = ovndbapi.Execute(cmd)
if err != nil {
t.Fatalf("Adding static route to lr2 failed with err %v", err)
}
lrsr, err = ovndbapi.LRSRList(LR2)
if err != nil {
t.Fatal(err)
}
if len(lrsr) < 1 {
t.Fatalf("Static Route %s using %s with policy %s not created in %s", IPPREFIX, outputPort, policy, LR2)
}
assert.Equal(t, outputPort, *lrsr[0].OutputPort)
assert.Equal(t, policy, *lrsr[0].Policy)
// Delete the static route with outputPort specified
cmd, err = ovndbapi.LRSRDel(LR2, IPPREFIX, nil, &outputPort, nil)
if err != nil {
t.Fatal(err)
}
err = ovndbapi.Execute(cmd)
if err != nil {
t.Fatalf("Deleting static route from lr2 failed with err %v", err)
}
t.Logf("Deleting static route %s from LRouter %s Done", IPPREFIX, LR2)
lrsr, err = ovndbapi.LRSRList(LR2)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, true, len(lrsr) == 0, "Deleted static route from lr2")
// Delete the router
cmd, err = ovndbapi.LRDel(LR2)
if err != nil {
t.Fatal(err)
}
err = ovndbapi.Execute(cmd)
if err != nil {
t.Fatal(err)
}
t.Logf("Delete router %s Done", LR2)
// verify router delete
lrs, err = ovndbapi.LRGet(LR2)
if err != nil {
t.Fatal(err)
}
if len(lrs) != 0 {
t.Fatalf("lr not deleted %v", lrs)
}
// verify static route list for non-existing routers
lrsr, err = ovndbapi.LRSRList(FAKENOROUTER)
if err != nil {
assert.EqualError(t, ErrorNotFound, err.Error())
}
}