-
Notifications
You must be signed in to change notification settings - Fork 74
/
ofnet_flow_test.go
245 lines (216 loc) · 9.75 KB
/
ofnet_flow_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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
package ofnet
import (
"fmt"
"net"
"strings"
"testing"
)
// test portVlan and DSCP flows on all four forwarding modes
func TestOfnetPortDscpFlow(t *testing.T) {
testOfnetPortDscpFlow(t, vrtrAgents[0], "vrtrBridge0")
testOfnetPortDscpFlow(t, vxlanAgents[0], "vxlanBridge0")
testOfnetPortDscpFlow(t, vlanAgents[0], "vlanBridge0")
// FIXME: vlrouter test fails while deleting the local endpoint
// testOfnetPortDscpFlow(t, vlrtrAgents[0], "vlrtrBridge0")
}
// Test adding local endpoint and verify port vlan flow and dscp flow
func testOfnetPortDscpFlow(t *testing.T, agent *OfnetAgent, brName string) {
macAddr, _ := net.ParseMAC(fmt.Sprintf("02:02:0B:0B:02:02"))
ipAddr := net.ParseIP(fmt.Sprintf("11.11.2.2"))
ipv6Addr := net.ParseIP(fmt.Sprintf("2017::2:2"))
endpoint := EndpointInfo{
PortNo: 14,
MacAddr: macAddr,
Vlan: 1,
IpAddr: ipAddr,
Ipv6Addr: ipv6Addr,
Dscp: 10,
}
// Install the local endpoint
err := agent.AddLocalEndpoint(endpoint)
if err != nil {
t.Fatalf("Error installing endpoint: %+v. Err: %v", endpoint, err)
return
}
// get the flow entries
flowList, err := ofctlFlowDump(brName)
if err != nil {
t.Errorf("Error getting flow entries. Err: %v", err)
}
// verify port flow
portVlanFlowMatch := fmt.Sprintf("priority=10,in_port=14 actions=write_metadata:0x100000000/0xff00000000")
if agent.dpName == "vxlan" {
portVlanFlowMatch = fmt.Sprintf("priority=10,in_port=14 actions=push_vlan:0x8100,set_field:4097->vlan_vid,write_metadata:0x100000000/0xff00000000")
}
if !ofctlFlowMatch(flowList, VLAN_TBL_ID, portVlanFlowMatch) {
fmt.Printf("Flows:\n%v", strings.Join(flowList, "\n"))
t.Fatalf("Could not find the flow %s on ovs %s", portVlanFlowMatch, brName)
}
// verify dscp v4 flow
dscpv4FlowMatch := fmt.Sprintf("priority=100,ip,in_port=14 actions=set_field:10->ip_dscp,write_metadata:0x100000000/0xff00000000")
if agent.dpName == "vxlan" {
dscpv4FlowMatch = fmt.Sprintf("priority=100,ip,in_port=14 actions=set_field:10->ip_dscp,push_vlan:0x8100,set_field:4097->vlan_vid,write_metadata:0x100000000/0xff00000000")
}
if !ofctlFlowMatch(flowList, VLAN_TBL_ID, dscpv4FlowMatch) {
fmt.Printf("Flows:\n%v", strings.Join(flowList, "\n"))
t.Fatalf("Could not find the flow %s on ovs %s", dscpv4FlowMatch, brName)
}
// verify dscp v6 flow
dscpv6FlowMatch := fmt.Sprintf("priority=100,ipv6,in_port=14 actions=set_field:10->ip_dscp,write_metadata:0x100000000/0xff00000000")
if agent.dpName == "vxlan" {
dscpv6FlowMatch = fmt.Sprintf("priority=100,ipv6,in_port=14 actions=set_field:10->ip_dscp,push_vlan:0x8100,set_field:4097->vlan_vid,write_metadata:0x100000000/0xff00000000")
}
if !ofctlFlowMatch(flowList, VLAN_TBL_ID, dscpv6FlowMatch) {
fmt.Printf("Flows:\n%v", strings.Join(flowList, "\n"))
t.Fatalf("Could not find the flow %s on ovs %s", dscpv6FlowMatch, brName)
}
// update the endpoint with new DSCP value
endpointInfo := EndpointInfo{
PortNo: 14,
Dscp: 20,
}
// Install the local endpoint
err = agent.UpdateLocalEndpoint(endpointInfo)
if err != nil {
t.Fatalf("Error updating endpoint: %+v. Err: %v", endpointInfo, err)
return
}
// get the flow entries
flowList, err = ofctlFlowDump(brName)
if err != nil {
t.Errorf("Error getting flow entries. Err: %v", err)
}
// verify dscp v4 flow
dscpv4FlowMatch = fmt.Sprintf("priority=100,ip,in_port=14 actions=set_field:20->ip_dscp,write_metadata:0x100000000/0xff00000000")
if agent.dpName == "vxlan" {
dscpv4FlowMatch = fmt.Sprintf("priority=100,ip,in_port=14 actions=set_field:20->ip_dscp,push_vlan:0x8100,set_field:4097->vlan_vid,write_metadata:0x100000000/0xff00000000")
}
if !ofctlFlowMatch(flowList, VLAN_TBL_ID, dscpv4FlowMatch) {
fmt.Printf("Flows:\n%v", strings.Join(flowList, "\n"))
t.Fatalf("Could not find the flow %s on ovs %s", dscpv4FlowMatch, brName)
}
// verify dscp v6 flow
dscpv6FlowMatch = fmt.Sprintf("priority=100,ipv6,in_port=14 actions=set_field:20->ip_dscp,write_metadata:0x100000000/0xff00000000")
if agent.dpName == "vxlan" {
dscpv6FlowMatch = fmt.Sprintf("priority=100,ipv6,in_port=14 actions=set_field:20->ip_dscp,push_vlan:0x8100,set_field:4097->vlan_vid,write_metadata:0x100000000/0xff00000000")
}
if !ofctlFlowMatch(flowList, VLAN_TBL_ID, dscpv6FlowMatch) {
fmt.Printf("Flows:\n%v", strings.Join(flowList, "\n"))
t.Fatalf("Could not find the flow %s on ovs %s", dscpv6FlowMatch, brName)
}
// Clear DSCP value
endpointInfo = EndpointInfo{
PortNo: 14,
Dscp: 0,
}
// Install the local endpoint
err = agent.UpdateLocalEndpoint(endpointInfo)
if err != nil {
t.Fatalf("Error updating endpoint: %+v. Err: %v", endpointInfo, err)
return
}
// get the flow entries
flowList, err = ofctlFlowDump(brName)
if err != nil {
t.Errorf("Error getting flow entries. Err: %v", err)
}
// verify port flow still exists
portVlanFlowMatch = fmt.Sprintf("priority=10,in_port=14 actions=write_metadata:0x100000000/0xff00000000")
if agent.dpName == "vxlan" {
portVlanFlowMatch = fmt.Sprintf("priority=10,in_port=14 actions=push_vlan:0x8100,set_field:4097->vlan_vid,write_metadata:0x100000000/0xff00000000")
}
if !ofctlFlowMatch(flowList, VLAN_TBL_ID, portVlanFlowMatch) {
fmt.Printf("Flows:\n%v", strings.Join(flowList, "\n"))
t.Fatalf("Could not find the flow %s on ovs %s", portVlanFlowMatch, brName)
}
// verify dscp v4 flow is removed
dscpv4FlowMatch = fmt.Sprintf("priority=100,ip,in_port=14 actions=set_field:20->ip_dscp,write_metadata:0x100000000/0xff00000000")
if agent.dpName == "vxlan" {
dscpv4FlowMatch = fmt.Sprintf("priority=100,ip,in_port=14 actions=set_field:20->ip_dscp,push_vlan:0x8100,set_field:4097->vlan_vid,write_metadata:0x100000000/0xff00000000")
}
if ofctlFlowMatch(flowList, VLAN_TBL_ID, dscpv4FlowMatch) {
fmt.Printf("Flows:\n%v", strings.Join(flowList, "\n"))
t.Fatalf("Flow %s is still present on ovs %s", dscpv4FlowMatch, brName)
}
// verify dscp v6 flow is removed
dscpv6FlowMatch = fmt.Sprintf("priority=100,ipv6,in_port=14 actions=set_field:20->ip_dscp,write_metadata:0x100000000/0xff00000000")
if agent.dpName == "vxlan" {
dscpv6FlowMatch = fmt.Sprintf("priority=100,ipv6,in_port=14 actions=set_field:20->ip_dscp,push_vlan:0x8100,set_field:4097->vlan_vid,write_metadata:0x100000000/0xff00000000")
}
if ofctlFlowMatch(flowList, VLAN_TBL_ID, dscpv6FlowMatch) {
fmt.Printf("Flows:\n%v", strings.Join(flowList, "\n"))
t.Fatalf("Flow %s is still present on ovs %s", dscpv6FlowMatch, brName)
}
// Set new DSCP value
endpointInfo = EndpointInfo{
PortNo: 14,
Dscp: 30,
}
// Install the local endpoint
err = agent.UpdateLocalEndpoint(endpointInfo)
if err != nil {
t.Fatalf("Error updating endpoint: %+v. Err: %v", endpointInfo, err)
return
}
// get the flow entries
flowList, err = ofctlFlowDump(brName)
if err != nil {
t.Errorf("Error getting flow entries. Err: %v", err)
}
// verify dscp v4 flow
dscpv4FlowMatch = fmt.Sprintf("priority=100,ip,in_port=14 actions=set_field:30->ip_dscp,write_metadata:0x100000000/0xff00000000")
if agent.dpName == "vxlan" {
dscpv4FlowMatch = fmt.Sprintf("priority=100,ip,in_port=14 actions=set_field:30->ip_dscp,push_vlan:0x8100,set_field:4097->vlan_vid,write_metadata:0x100000000/0xff00000000")
}
if !ofctlFlowMatch(flowList, VLAN_TBL_ID, dscpv4FlowMatch) {
fmt.Printf("Flows:\n%v", strings.Join(flowList, "\n"))
t.Fatalf("Could not find the flow %s on ovs %s", dscpv4FlowMatch, brName)
}
// verify dscp v6 flow
dscpv6FlowMatch = fmt.Sprintf("priority=100,ipv6,in_port=14 actions=set_field:30->ip_dscp,write_metadata:0x100000000/0xff00000000")
if agent.dpName == "vxlan" {
dscpv6FlowMatch = fmt.Sprintf("priority=100,ipv6,in_port=14 actions=set_field:30->ip_dscp,push_vlan:0x8100,set_field:4097->vlan_vid,write_metadata:0x100000000/0xff00000000")
}
if !ofctlFlowMatch(flowList, VLAN_TBL_ID, dscpv6FlowMatch) {
fmt.Printf("Flows:\n%v", strings.Join(flowList, "\n"))
t.Fatalf("Could not find the flow %s on ovs %s", dscpv6FlowMatch, brName)
}
// remove the endpoint
err = agent.RemoveLocalEndpoint(14)
if err != nil {
t.Fatalf("Error removing endpoint port %d. Err: %v", 14, err)
return
}
// get the flow entries
flowList, err = ofctlFlowDump(brName)
if err != nil {
t.Errorf("Error getting flow entries. Err: %v", err)
}
// verify port flow is removed
portVlanFlowMatch = fmt.Sprintf("priority=10,in_port=14 actions=write_metadata:0x100000000/0xff00000000")
if agent.dpName == "vxlan" {
portVlanFlowMatch = fmt.Sprintf("priority=10,in_port=14 actions=push_vlan:0x8100,set_field:4097->vlan_vid,write_metadata:0x100000000/0xff00000000")
}
if ofctlFlowMatch(flowList, VLAN_TBL_ID, portVlanFlowMatch) {
fmt.Printf("Flows:\n%v", strings.Join(flowList, "\n"))
t.Fatalf("Flow %s is still present on ovs %s", portVlanFlowMatch, brName)
}
// verify dscp v4 flow is removed
dscpv4FlowMatch = fmt.Sprintf("priority=100,ip,in_port=14 actions=set_field:30->ip_dscp,write_metadata:0x100000000/0xff00000000")
if agent.dpName == "vxlan" {
dscpv4FlowMatch = fmt.Sprintf("priority=100,ip,in_port=14 actions=set_field:30->ip_dscp,push_vlan:0x8100,set_field:4097->vlan_vid,write_metadata:0x100000000/0xff00000000")
}
if ofctlFlowMatch(flowList, VLAN_TBL_ID, dscpv4FlowMatch) {
fmt.Printf("Flows:\n%v", strings.Join(flowList, "\n"))
t.Fatalf("Flow %s is still present on ovs %s", dscpv4FlowMatch, brName)
}
// verify dscp v6 flow is removed
dscpv6FlowMatch = fmt.Sprintf("priority=100,ipv6,in_port=14 actions=set_field:30->ip_dscp,write_metadata:0x100000000/0xff00000000")
if agent.dpName == "vxlan" {
dscpv6FlowMatch = fmt.Sprintf("priority=100,ipv6,in_port=14 actions=set_field:30->ip_dscp,push_vlan:0x8100,set_field:4097->vlan_vid,write_metadata:0x100000000/0xff00000000")
}
if ofctlFlowMatch(flowList, VLAN_TBL_ID, dscpv6FlowMatch) {
fmt.Printf("Flows:\n%v", strings.Join(flowList, "\n"))
t.Fatalf("Flow %s is still present on ovs %s", dscpv6FlowMatch, brName)
}
}