ofproto-dpif: Implement PACKET_IN in userspace.
[sliver-openvswitch.git] / tests / ofproto-dpif.at
1 AT_BANNER([ofproto-dpif])
2
3 AT_SETUP([ofproto-dpif - resubmit])
4 OVS_VSWITCHD_START
5 AT_DATA([flows.txt], [dnl
6 table=0 in_port=1 priority=1000 icmp actions=output(10),resubmit(2),output(19),resubmit(3),output(21)
7 table=0 in_port=2 priority=1500 icmp actions=output(11),resubmit(,1),output(16),resubmit(2,1),output(18)
8 table=0 in_port=3 priority=2000 icmp actions=output(20)
9 table=1 in_port=1 priority=1000 icmp actions=output(12),resubmit(4,1),output(13),resubmit(3),output(15)
10 table=1 in_port=2 priority=1500 icmp actions=output(17),resubmit(,2)
11 table=1 in_port=3 priority=1500 icmp actions=output(14),resubmit(,2)
12 ])
13 AT_CHECK([ovs-ofctl add-flows br0 flows.txt])
14 AT_CHECK([ovs-appctl ofproto/trace br0 'in_port(1),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=1,tos=0,ttl=128,frag=no),icmp(type=8,code=0)'], [0], [stdout])
15 AT_CHECK([tail -1 stdout], [0],
16   [Datapath actions: 10,11,12,13,14,15,16,17,18,19,20,21
17 ])
18 OVS_VSWITCHD_STOP
19 AT_CLEANUP
20
21 AT_SETUP([ofproto-dpif - registers])
22 OVS_VSWITCHD_START
23 AT_DATA([flows.txt], [dnl
24 in_port=90                 actions=resubmit:2,resubmit:3,resubmit:4,resubmit:91
25 in_port=91                 actions=resubmit:5,resubmit:6,resubmit:7,resubmit:92
26 in_port=92                 actions=resubmit:8,resubmit:9,resubmit:10,resubmit:11
27 in_port=2                  actions=load:0x000db000->NXM_NX_REG0[[]]
28 in_port=3                  actions=load:0xdea->NXM_NX_REG0[[20..31]]
29 in_port=4                  actions=load:0xeef->NXM_NX_REG0[[0..11]]
30 in_port=5                  actions=move:NXM_NX_REG0[[]]->NXM_NX_REG1[[]]
31 in_port=6                  actions=load:0x22222222->NXM_NX_REG2[[]]
32 in_port=7                  actions=move:NXM_NX_REG1[[20..31]]->NXM_NX_REG2[[0..11]]
33 in_port=8                  actions=move:NXM_NX_REG1[[0..11]]->NXM_NX_REG2[[20..31]]
34 in_port=9,reg0=0xdeadbeef  actions=output:20
35 in_port=10,reg1=0xdeadbeef actions=output:21
36 in_port=11,reg2=0xeef22dea actions=output:22
37 ])
38 AT_CHECK([ovs-ofctl add-flows br0 flows.txt])
39 AT_CHECK([ovs-appctl ofproto/trace br0 'in_port(90),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=1,tos=0,ttl=128,frag=no),icmp(type=8,code=0)'], [0], [stdout])
40 AT_CHECK([tail -1 stdout], [0],
41   [Datapath actions: 20,21,22
42 ])
43 OVS_VSWITCHD_STOP
44 AT_CLEANUP
45
46 AT_SETUP([ofproto-dpif - output])
47 OVS_VSWITCHD_START
48 AT_DATA([flows.txt], [dnl
49 in_port=1 actions=resubmit:2,resubmit:3,resubmit:4,resubmit:5,resubmit:6,resubmit:7
50 in_port=2 actions=output:9
51 in_port=3 actions=load:55->NXM_NX_REG0[[]],output:NXM_NX_REG0[[]],load:66->NXM_NX_REG1[[]]
52 in_port=4 actions=output:10,output:NXM_NX_REG0[[]],output:NXM_NX_REG1[[]],output:11
53 in_port=5 actions=load:77->NXM_NX_REG0[[0..15]],load:88->NXM_NX_REG0[[16..31]]
54 in_port=6 actions=output:NXM_NX_REG0[[0..15]],output:NXM_NX_REG0[[16..31]]
55 in_port=7 actions=load:0x110000ff->NXM_NX_REG0[[]],output:NXM_NX_REG0[[]]
56 ])
57 AT_CHECK([ovs-ofctl add-flows br0 flows.txt])
58 AT_CHECK([ovs-appctl ofproto/trace br0 'in_port(1),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=1,tos=0,ttl=128,frag=no),icmp(type=8,code=0)'], [0], [stdout])
59 AT_CHECK([tail -1 stdout], [0],
60   [Datapath actions: 9,55,10,55,66,11,77,88
61 ])
62 OVS_VSWITCHD_STOP
63 AT_CLEANUP
64
65 AT_SETUP([ofproto-dpif - output, OFPP_NONE ingress port])
66 OVS_VSWITCHD_START(
67        [add-port br0 p1 -- set Interface p1 type=dummy --\
68         add-port br0 p2 -- set Interface p2 type=dummy])
69
70 AT_CHECK(
71   [ovs-vsctl \
72         -- get Interface p1 ofport \
73         -- get Interface p2 ofport],
74   [0], [stdout])
75 set `cat stdout`
76 br0=0 p1=$1 p2=$2
77
78 AT_CHECK([ovs-ofctl add-flow br0 action=normal])
79
80 # "in_port" defaults to OFPP_NONE if it's not specified.
81 flow="eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=1,tos=0,ttl=128,frag=no),icmp(type=8,code=0)"
82 AT_CHECK([ovs-appctl ofproto/trace br0 "$flow"], [0], [stdout])
83 actual=`tail -1 stdout | sed 's/Datapath actions: //'`
84
85 expected="$br0,$p1,$p2"
86 AT_CHECK([ovs-dpctl normalize-actions "$flow" "$expected" br0=$br0 p1=$p1 p2=$p2], [0], [stdout])
87 mv stdout expout
88 AT_CHECK([ovs-dpctl normalize-actions "$flow" "$actual" br0=$br0 p1=$p1 p2=$p2], [0], [expout])
89
90 OVS_VSWITCHD_STOP
91 AT_CLEANUP
92
93 AT_SETUP([ofproto-dpif - DSCP])
94 dnl This test assumes port p1 is allocated OpenFlow port number 1.
95 OVS_VSWITCHD_START([add-port br0 p1 -- set Interface p1 type=dummy])
96 AT_DATA([flows.txt], [dnl
97 actions=output:65534,enqueue:1:1,enqueue:1:2,enqueue:1:2,enqueue:1:1,output:1,mod_nw_tos:0,output:1,output:65534
98 ])
99 AT_CHECK([ovs-ofctl add-flows br0 flows.txt])
100 AT_CHECK([ovs-vsctl -- \
101         set Port p1 qos=@newqos --\
102         --id=@newqos create QoS type=linux-htb queues=1=@q1,2=@q2 --\
103         --id=@q1 create Queue dscp=1 --\
104         --id=@q2 create Queue dscp=2], [0], [ignore])
105 AT_CHECK([ovs-appctl ofproto/trace br0 'in_port(9),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=1.1.1.1,dst=2.2.2.2,proto=1,tos=0xff,ttl=128,frag=no),icmp(type=8,code=0)'], [0], [stdout])
106 AT_CHECK([tail -1 stdout], [0],
107   [Datapath actions: dnl
108 0,dnl
109 set(ipv4(src=1.1.1.1,dst=2.2.2.2,proto=1,tos=0x7,ttl=128,frag=no)),set(priority(1)),1,dnl
110 set(ipv4(src=1.1.1.1,dst=2.2.2.2,proto=1,tos=0xb,ttl=128,frag=no)),set(priority(2)),1,dnl
111 1,dnl
112 set(ipv4(src=1.1.1.1,dst=2.2.2.2,proto=1,tos=0x7,ttl=128,frag=no)),set(priority(1)),1,dnl
113 set(ipv4(src=1.1.1.1,dst=2.2.2.2,proto=1,tos=0xff,ttl=128,frag=no)),set(priority(0)),1,dnl
114 set(ipv4(src=1.1.1.1,dst=2.2.2.2,proto=1,tos=0x3,ttl=128,frag=no)),1,dnl
115 0
116 ])
117 OVS_VSWITCHD_STOP
118 AT_CLEANUP
119
120 AT_SETUP([ofproto-dpif - output/flood flags])
121 dnl This test assumes that OpenFlow port numbers are allocated in order
122 dnl starting from one.  It does not necessarily require that they are allocated
123 dnl in the same order that they are named in the database.  Just that the
124 dnl following command guarantees OpenFlow port 65534, and ports 1-7 exist in
125 dnl the bridge.
126 OVS_VSWITCHD_START([dnl
127         add-port br0 p1 -- set Interface p1 type=dummy --\
128         add-port br0 p2 -- set Interface p2 type=dummy --\
129         add-port br0 p3 -- set Interface p3 type=dummy --\
130         add-port br0 p4 -- set Interface p4 type=dummy --\
131         add-port br0 p5 -- set Interface p5 type=dummy --\
132         add-port br0 p6 -- set Interface p6 type=dummy --\
133         add-port br0 p7 -- set Interface p7 type=dummy ])
134
135 AT_DATA([flows.txt], [dnl
136 in_port=1 actions=flood
137 in_port=2 actions=all
138 in_port=3 actions=output:65534,output:1,output:2,output:3,output:4,output:5,output:6,output:7
139 in_port=4 actions=enqueue:65534:1,enqueue:1:1,enqueue:2:1,enqueue:3:2,enqueue:4:1,enqueue:5:1,enqueue:6:1,enqueue:7:1
140 ])
141 AT_CHECK([ovs-ofctl add-flows br0 flows.txt])
142 AT_CHECK([ovs-ofctl mod-port br0 5 noforward])
143 AT_CHECK([ovs-ofctl mod-port br0 6 noflood])
144
145 AT_CHECK([ovs-appctl ofproto/trace br0 'in_port(1),eth(src=00:00:00:00:00:01,dst=00:00:00:00:00:02),eth_type(0x0900)'], [0], [stdout])
146 AT_CHECK([tail -1 stdout \
147 | sed -e 's/Datapath actions: //' | tr ',' '\n' | sort], [0], [dnl
148 0
149 2
150 3
151 4
152 7
153 ])
154
155 AT_CHECK([ovs-appctl ofproto/trace br0 'in_port(2),eth(src=00:00:00:00:00:01,dst=00:00:00:00:00:02),eth_type(0x0900)'], [0], [stdout])
156 AT_CHECK([tail -1 stdout \
157 | sed -e 's/Datapath actions: //' | tr ',' '\n' | sort], [0], [dnl
158 0
159 1
160 3
161 4
162 6
163 7
164 ])
165
166 AT_CHECK([ovs-appctl ofproto/trace br0 'in_port(3),eth(src=00:00:00:00:00:01,dst=00:00:00:00:00:02),eth_type(0x0900)'], [0], [stdout])
167 AT_CHECK([tail -1 stdout], [0],
168   [Datapath actions: 0,1,2,4,6,7
169 ])
170
171 AT_CHECK([ovs-appctl ofproto/trace br0 'in_port(4),eth(src=00:00:00:00:00:01,dst=00:00:00:00:00:02),eth_type(0x0900)'], [0], [stdout])
172 AT_CHECK([tail -1 stdout], [0],
173   [Datapath actions: set(priority(1)),0,1,2,set(priority(2)),3,set(priority(1)),6,7
174 ])
175 OVS_VSWITCHD_STOP
176 AT_CLEANUP
177
178 AT_SETUP([ofproto-dpif - set_tunnel])
179 OVS_VSWITCHD_START
180 AT_DATA([flows.txt], [dnl
181 in_port=90 actions=resubmit:1,resubmit:2,resubmit:3,resubmit:4,resubmit:5
182 in_port=1 actions=set_tunnel:1,output:1
183 in_port=2 actions=set_tunnel:1,output:2
184 in_port=3 actions=set_tunnel:2,set_tunnel:3,output:3
185 in_port=4 actions=set_tunnel:4,set_tunnel:3,output:4
186 in_port=5 actions=set_tunnel:5
187 ])
188 AT_CHECK([ovs-ofctl add-flows br0 flows.txt])
189 AT_CHECK([ovs-appctl ofproto/trace br0 'tun_id(0x1),in_port(90),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=1,tos=0,ttl=128,frag=no),icmp(type=8,code=0)'], [0], [stdout])
190 AT_CHECK([tail -1 stdout], [0],
191   [Datapath actions: set(tun_id(0x1)),1,2,set(tun_id(0x3)),3,4
192 ])
193 OVS_VSWITCHD_STOP
194 AT_CLEANUP
195
196 AT_SETUP([ofproto-dpif - controller])
197 OVS_VSWITCHD_START([dnl
198    add-port br0 p1 -- set Interface p1 type=dummy
199 ])
200
201 AT_CAPTURE_FILE([ofctl_monitor.log])
202 AT_DATA([flows.txt], [dnl
203 cookie=0x0 dl_src=10:11:11:11:11:11 actions=controller
204 cookie=0x1 dl_src=20:22:22:22:22:22 actions=controller,resubmit:80
205 cookie=0x2 dl_src=30:33:33:33:33:33 actions=mod_vlan_vid:15,controller
206
207 cookie=0x3 in_port=80 actions=mod_vlan_vid:80,controller,resubmit:81
208 cookie=0x4 in_port=81 actions=mod_dl_src:80:81:81:81:81:81,controller,resubmit:82
209 cookie=0x5 in_port=82 actions=mod_dl_dst:82:82:82:82:82:82,controller,resubmit:83
210 cookie=0x6 in_port=83 actions=mod_nw_src:83.83.83.83,controller,resubmit:84
211 cookie=0x7 in_port=84 actions=mod_nw_dst:84.84.84.84,controller,resubmit:85
212 cookie=0x8 in_port=85 actions=mod_tp_src:85,controller,resubmit:86
213 cookie=0x9 in_port=86 actions=mod_tp_dst:86,controller,controller
214 ])
215 AT_CHECK([ovs-ofctl add-flows br0 flows.txt])
216
217 dnl Flow miss.
218 AT_CHECK([ovs-ofctl monitor br0 65534 --detach --pidfile 2> ofctl_monitor.log])
219
220 for i in 1 2 3 ; do
221     ovs-appctl netdev-dummy/receive p1 'in_port(1),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=6,tos=0,ttl=64,frag=no),tcp(src=8,dst=9)'
222 done
223
224 OVS_WAIT_UNTIL([ovs-appctl -t ovs-ofctl exit])
225 AT_CHECK([cat ofctl_monitor.log], [0], [dnl
226 OFPT_PACKET_IN (xid=0x0): total_len=60 in_port=1 data_len=60 (unbuffered)
227 priority:0,tunnel:0,in_port:0000,tci(0) mac(50:54:00:00:00:05->50:54:00:00:00:07) type:0800 proto:6 tos:0 ttl:0 ip(192.168.0.1->192.168.0.2) port(8->9) tcp_csum:0
228 dnl
229 OFPT_PACKET_IN (xid=0x0): total_len=60 in_port=1 data_len=60 (unbuffered)
230 priority:0,tunnel:0,in_port:0000,tci(0) mac(50:54:00:00:00:05->50:54:00:00:00:07) type:0800 proto:6 tos:0 ttl:0 ip(192.168.0.1->192.168.0.2) port(8->9) tcp_csum:0
231 dnl
232 OFPT_PACKET_IN (xid=0x0): total_len=60 in_port=1 data_len=60 (unbuffered)
233 priority:0,tunnel:0,in_port:0000,tci(0) mac(50:54:00:00:00:05->50:54:00:00:00:07) type:0800 proto:6 tos:0 ttl:0 ip(192.168.0.1->192.168.0.2) port(8->9) tcp_csum:0
234 ])
235
236 dnl Singleton controller action.
237 AT_CHECK([ovs-ofctl monitor br0 65534 --detach --pidfile 2> ofctl_monitor.log])
238
239 for i in 1 2 3 ; do
240     ovs-appctl netdev-dummy/receive p1 'in_port(1),eth(src=10:11:11:11:11:11,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=6,tos=0,ttl=64,frag=no),tcp(src=8,dst=10)'
241 done
242
243 OVS_WAIT_UNTIL([ovs-appctl -t ovs-ofctl exit])
244 AT_CHECK([cat ofctl_monitor.log], [0], [dnl
245 OFPT_PACKET_IN (xid=0x0): total_len=60 in_port=1 (via action) data_len=60 (unbuffered)
246 priority:0,tunnel:0,in_port:0000,tci(0) mac(10:11:11:11:11:11->50:54:00:00:00:07) type:0800 proto:6 tos:0 ttl:0 ip(192.168.0.1->192.168.0.2) port(8->10) tcp_csum:0
247 dnl
248 OFPT_PACKET_IN (xid=0x0): total_len=60 in_port=1 (via action) data_len=60 (unbuffered)
249 priority:0,tunnel:0,in_port:0000,tci(0) mac(10:11:11:11:11:11->50:54:00:00:00:07) type:0800 proto:6 tos:0 ttl:0 ip(192.168.0.1->192.168.0.2) port(8->10) tcp_csum:0
250 dnl
251 OFPT_PACKET_IN (xid=0x0): total_len=60 in_port=1 (via action) data_len=60 (unbuffered)
252 priority:0,tunnel:0,in_port:0000,tci(0) mac(10:11:11:11:11:11->50:54:00:00:00:07) type:0800 proto:6 tos:0 ttl:0 ip(192.168.0.1->192.168.0.2) port(8->10) tcp_csum:0
253 ])
254
255 dnl Modified controller action.
256 AT_CHECK([ovs-ofctl monitor br0 65534 --detach --pidfile 2> ofctl_monitor.log])
257
258 for i in 1 2 3 ; do
259     ovs-appctl netdev-dummy/receive p1 'in_port(1),eth(src=30:33:33:33:33:33,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=6,tos=0,ttl=64,frag=no),tcp(src=8,dst=10)'
260 done
261
262 OVS_WAIT_UNTIL([ovs-appctl -t ovs-ofctl exit])
263 AT_CHECK([cat ofctl_monitor.log], [0], [dnl
264 OFPT_PACKET_IN (xid=0x0): total_len=64 in_port=1 (via action) data_len=64 (unbuffered)
265 priority:0,tunnel:0,in_port:0000,tci(vlan:15,pcp:0) mac(30:33:33:33:33:33->50:54:00:00:00:07) type:0800 proto:6 tos:0 ttl:0 ip(192.168.0.1->192.168.0.2) port(8->10) tcp_csum:0
266 dnl
267 OFPT_PACKET_IN (xid=0x0): total_len=64 in_port=1 (via action) data_len=64 (unbuffered)
268 priority:0,tunnel:0,in_port:0000,tci(vlan:15,pcp:0) mac(30:33:33:33:33:33->50:54:00:00:00:07) type:0800 proto:6 tos:0 ttl:0 ip(192.168.0.1->192.168.0.2) port(8->10) tcp_csum:0
269 dnl
270 OFPT_PACKET_IN (xid=0x0): total_len=64 in_port=1 (via action) data_len=64 (unbuffered)
271 priority:0,tunnel:0,in_port:0000,tci(vlan:15,pcp:0) mac(30:33:33:33:33:33->50:54:00:00:00:07) type:0800 proto:6 tos:0 ttl:0 ip(192.168.0.1->192.168.0.2) port(8->10) tcp_csum:0
272 ])
273
274 dnl Checksum TCP.
275 AT_CHECK([ovs-ofctl monitor br0 65534 --detach --pidfile 2> ofctl_monitor.log])
276
277 for i in 1 ; do
278     ovs-appctl netdev-dummy/receive p1 'in_port(1),eth(src=20:22:22:22:22:22,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=6,tos=0,ttl=64,frag=no),tcp(src=8,dst=11)'
279 done
280
281 OVS_WAIT_UNTIL([ovs-appctl -t ovs-ofctl exit])
282 AT_CHECK([cat ofctl_monitor.log], [0], [dnl
283 OFPT_PACKET_IN (xid=0x0): total_len=60 in_port=1 (via action) data_len=60 (unbuffered)
284 priority:0,tunnel:0,in_port:0000,tci(0) mac(20:22:22:22:22:22->50:54:00:00:00:07) type:0800 proto:6 tos:0 ttl:0 ip(192.168.0.1->192.168.0.2) port(8->11) tcp_csum:0
285 dnl
286 OFPT_PACKET_IN (xid=0x0): total_len=64 in_port=1 (via action) data_len=64 (unbuffered)
287 priority:0,tunnel:0,in_port:0000,tci(vlan:80,pcp:0) mac(20:22:22:22:22:22->50:54:00:00:00:07) type:0800 proto:6 tos:0 ttl:0 ip(192.168.0.1->192.168.0.2) port(8->11) tcp_csum:0
288 dnl
289 OFPT_PACKET_IN (xid=0x0): total_len=64 in_port=1 (via action) data_len=64 (unbuffered)
290 priority:0,tunnel:0,in_port:0000,tci(vlan:80,pcp:0) mac(80:81:81:81:81:81->50:54:00:00:00:07) type:0800 proto:6 tos:0 ttl:0 ip(192.168.0.1->192.168.0.2) port(8->11) tcp_csum:0
291 dnl
292 OFPT_PACKET_IN (xid=0x0): total_len=64 in_port=1 (via action) data_len=64 (unbuffered)
293 priority:0,tunnel:0,in_port:0000,tci(vlan:80,pcp:0) mac(80:81:81:81:81:81->82:82:82:82:82:82) type:0800 proto:6 tos:0 ttl:0 ip(192.168.0.1->192.168.0.2) port(8->11) tcp_csum:0
294 dnl
295 OFPT_PACKET_IN (xid=0x0): total_len=64 in_port=1 (via action) data_len=64 (unbuffered)
296 priority:0,tunnel:0,in_port:0000,tci(vlan:80,pcp:0) mac(80:81:81:81:81:81->82:82:82:82:82:82) type:0800 proto:6 tos:0 ttl:0 ip(83.83.83.83->192.168.0.2) port(8->11) tcp_csum:1a03
297 dnl
298 OFPT_PACKET_IN (xid=0x0): total_len=64 in_port=1 (via action) data_len=64 (unbuffered)
299 priority:0,tunnel:0,in_port:0000,tci(vlan:80,pcp:0) mac(80:81:81:81:81:81->82:82:82:82:82:82) type:0800 proto:6 tos:0 ttl:0 ip(83.83.83.83->84.84.84.84) port(8->11) tcp_csum:3205
300 dnl
301 OFPT_PACKET_IN (xid=0x0): total_len=64 in_port=1 (via action) data_len=64 (unbuffered)
302 priority:0,tunnel:0,in_port:0000,tci(vlan:80,pcp:0) mac(80:81:81:81:81:81->82:82:82:82:82:82) type:0800 proto:6 tos:0 ttl:0 ip(83.83.83.83->84.84.84.84) port(85->11) tcp_csum:31b8
303 dnl
304 OFPT_PACKET_IN (xid=0x0): total_len=64 in_port=1 (via action) data_len=64 (unbuffered)
305 priority:0,tunnel:0,in_port:0000,tci(vlan:80,pcp:0) mac(80:81:81:81:81:81->82:82:82:82:82:82) type:0800 proto:6 tos:0 ttl:0 ip(83.83.83.83->84.84.84.84) port(85->86) tcp_csum:316d
306 dnl
307 OFPT_PACKET_IN (xid=0x0): total_len=64 in_port=1 (via action) data_len=64 (unbuffered)
308 priority:0,tunnel:0,in_port:0000,tci(vlan:80,pcp:0) mac(80:81:81:81:81:81->82:82:82:82:82:82) type:0800 proto:6 tos:0 ttl:0 ip(83.83.83.83->84.84.84.84) port(85->86) tcp_csum:316d
309 ])
310
311 dnl Checksum UDP.
312 AT_CHECK([ovs-ofctl monitor br0 65534 --detach --pidfile 2> ofctl_monitor.log])
313
314 for i in 1 ; do
315     ovs-appctl netdev-dummy/receive p1 '50 54 00 00 00 07 20 22 22 22 22 22 08 00 45 00 00 1C 00 00 00 00 00 11 00 00 C0 A8 00 01 C0 A8 00 02 00 08 00 0B 00 00 12 34 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00'
316 done
317
318 OVS_WAIT_UNTIL([ovs-appctl -t ovs-ofctl exit])
319 AT_CHECK([cat ofctl_monitor.log], [0], [dnl
320 OFPT_PACKET_IN (xid=0x0): total_len=60 in_port=1 (via action) data_len=60 (unbuffered)
321 priority:0,tunnel:0,in_port:0000,tci(0) mac(20:22:22:22:22:22->50:54:00:00:00:07) type:0800 proto:17 tos:0 ttl:0 ip(192.168.0.1->192.168.0.2) port(8->11) udp_csum:1234
322 dnl
323 OFPT_PACKET_IN (xid=0x0): total_len=64 in_port=1 (via action) data_len=64 (unbuffered)
324 priority:0,tunnel:0,in_port:0000,tci(vlan:80,pcp:0) mac(20:22:22:22:22:22->50:54:00:00:00:07) type:0800 proto:17 tos:0 ttl:0 ip(192.168.0.1->192.168.0.2) port(8->11) udp_csum:1234
325 dnl
326 OFPT_PACKET_IN (xid=0x0): total_len=64 in_port=1 (via action) data_len=64 (unbuffered)
327 priority:0,tunnel:0,in_port:0000,tci(vlan:80,pcp:0) mac(80:81:81:81:81:81->50:54:00:00:00:07) type:0800 proto:17 tos:0 ttl:0 ip(192.168.0.1->192.168.0.2) port(8->11) udp_csum:1234
328 dnl
329 OFPT_PACKET_IN (xid=0x0): total_len=64 in_port=1 (via action) data_len=64 (unbuffered)
330 priority:0,tunnel:0,in_port:0000,tci(vlan:80,pcp:0) mac(80:81:81:81:81:81->82:82:82:82:82:82) type:0800 proto:17 tos:0 ttl:0 ip(192.168.0.1->192.168.0.2) port(8->11) udp_csum:1234
331 dnl
332 OFPT_PACKET_IN (xid=0x0): total_len=64 in_port=1 (via action) data_len=64 (unbuffered)
333 priority:0,tunnel:0,in_port:0000,tci(vlan:80,pcp:0) mac(80:81:81:81:81:81->82:82:82:82:82:82) type:0800 proto:17 tos:0 ttl:0 ip(83.83.83.83->192.168.0.2) port(8->11) udp_csum:2c37
334 dnl
335 OFPT_PACKET_IN (xid=0x0): total_len=64 in_port=1 (via action) data_len=64 (unbuffered)
336 priority:0,tunnel:0,in_port:0000,tci(vlan:80,pcp:0) mac(80:81:81:81:81:81->82:82:82:82:82:82) type:0800 proto:17 tos:0 ttl:0 ip(83.83.83.83->84.84.84.84) port(8->11) udp_csum:4439
337 dnl
338 OFPT_PACKET_IN (xid=0x0): total_len=64 in_port=1 (via action) data_len=64 (unbuffered)
339 priority:0,tunnel:0,in_port:0000,tci(vlan:80,pcp:0) mac(80:81:81:81:81:81->82:82:82:82:82:82) type:0800 proto:17 tos:0 ttl:0 ip(83.83.83.83->84.84.84.84) port(85->11) udp_csum:43ec
340 dnl
341 OFPT_PACKET_IN (xid=0x0): total_len=64 in_port=1 (via action) data_len=64 (unbuffered)
342 priority:0,tunnel:0,in_port:0000,tci(vlan:80,pcp:0) mac(80:81:81:81:81:81->82:82:82:82:82:82) type:0800 proto:17 tos:0 ttl:0 ip(83.83.83.83->84.84.84.84) port(85->86) udp_csum:43a1
343 dnl
344 OFPT_PACKET_IN (xid=0x0): total_len=64 in_port=1 (via action) data_len=64 (unbuffered)
345 priority:0,tunnel:0,in_port:0000,tci(vlan:80,pcp:0) mac(80:81:81:81:81:81->82:82:82:82:82:82) type:0800 proto:17 tos:0 ttl:0 ip(83.83.83.83->84.84.84.84) port(85->86) udp_csum:43a1
346 ])
347
348 AT_CHECK([ovs-ofctl dump-flows br0 | STRIP_DURATION | sort], [0], [dnl
349  cookie=0x0, duration=?s, table=0, n_packets=3, n_bytes=180, dl_src=10:11:11:11:11:11 actions=CONTROLLER:65535
350  cookie=0x1, duration=?s, table=0, n_packets=2, n_bytes=120, dl_src=20:22:22:22:22:22 actions=CONTROLLER:65535,resubmit:80
351  cookie=0x2, duration=?s, table=0, n_packets=3, n_bytes=180, dl_src=30:33:33:33:33:33 actions=mod_vlan_vid:15,CONTROLLER:65535
352  cookie=0x3, duration=?s, table=0, n_packets=2, n_bytes=120, in_port=80 actions=mod_vlan_vid:80,CONTROLLER:65535,resubmit:81
353  cookie=0x4, duration=?s, table=0, n_packets=2, n_bytes=120, in_port=81 actions=mod_dl_src:80:81:81:81:81:81,CONTROLLER:65535,resubmit:82
354  cookie=0x5, duration=?s, table=0, n_packets=2, n_bytes=120, in_port=82 actions=mod_dl_dst:82:82:82:82:82:82,CONTROLLER:65535,resubmit:83
355  cookie=0x6, duration=?s, table=0, n_packets=2, n_bytes=120, in_port=83 actions=mod_nw_src:83.83.83.83,CONTROLLER:65535,resubmit:84
356  cookie=0x7, duration=?s, table=0, n_packets=2, n_bytes=120, in_port=84 actions=mod_nw_dst:84.84.84.84,CONTROLLER:65535,resubmit:85
357  cookie=0x8, duration=?s, table=0, n_packets=2, n_bytes=120, in_port=85 actions=mod_tp_src:85,CONTROLLER:65535,resubmit:86
358  cookie=0x9, duration=?s, table=0, n_packets=2, n_bytes=120, in_port=86 actions=mod_tp_dst:86,CONTROLLER:65535,CONTROLLER:65535
359 NXST_FLOW reply (xid=0x4):
360 ])
361
362 OVS_VSWITCHD_STOP
363 AT_CLEANUP
364
365 AT_SETUP([ofproto-dpif - VLAN handling])
366 OVS_VSWITCHD_START(
367   [set Bridge br0 fail-mode=standalone -- \
368    add-port br0 p1                                  trunks=10,12 -- \
369    add-port br0 p2                           tag=10              -- \
370    add-port br0 p3                           tag=12              \
371                    other-config:priority-tags=true               -- \
372    add-port br0 p4                           tag=12              -- \
373    add-port br0 p5 vlan_mode=native-tagged   tag=10              -- \
374    add-port br0 p6 vlan_mode=native-tagged   tag=10 trunks=10,12 -- \
375    add-port br0 p7 vlan_mode=native-untagged tag=12              -- \
376    add-port br0 p8 vlan_mode=native-untagged tag=12 trunks=10,12 \
377                    other-config:priority-tags=true               -- \
378    set Interface p1 type=dummy -- \
379    set Interface p2 type=dummy -- \
380    set Interface p3 type=dummy -- \
381    set Interface p4 type=dummy -- \
382    set Interface p5 type=dummy -- \
383    set Interface p6 type=dummy -- \
384    set Interface p7 type=dummy -- \
385    set Interface p8 type=dummy --])
386
387 AT_CHECK(
388   [ovs-vsctl \
389         -- get Interface p1 ofport \
390         -- get Interface p2 ofport \
391         -- get Interface p3 ofport \
392         -- get Interface p4 ofport \
393         -- get Interface p5 ofport \
394         -- get Interface p6 ofport \
395         -- get Interface p7 ofport \
396         -- get Interface p8 ofport],
397   [0], [stdout])
398 set `cat stdout`
399 br0=0 p1=$1 p2=$2 p3=$3 p4=$4 p5=$5 p6=$6 p7=$7 p8=$8
400
401 dnl Each of these specifies an in_port, a VLAN VID (or "none"), a VLAN
402 dnl PCP (used if the VID isn't "none") and the expected set of datapath
403 dnl actions.
404 for tuple in \
405         "br0 none 0 drop" \
406         "br0 0    0 drop" \
407         "br0 0    1 drop" \
408         "br0 10   0 p1,p5,p6,p7,p8,pop_vlan,p2" \
409         "br0 10   1 p1,p5,p6,p7,p8,pop_vlan,p2" \
410         "br0 11   0 p5,p7" \
411         "br0 11   1 p5,p7" \
412         "br0 12   0 p1,p5,p6,pop_vlan,p3,p4,p7,p8" \
413         "br0 12   1 p1,p5,p6,pop_vlan,p4,p7,push_vlan(vid=0,pcp=1),p3,p8" \
414         "p1  none 0 drop" \
415         "p1  0    0 drop" \
416         "p1  0    1 drop" \
417         "p1  10   0 br0,p5,p6,p7,p8,pop_vlan,p2" \
418         "p1  10   1 br0,p5,p6,p7,p8,pop_vlan,p2" \
419         "p1  11   0 drop" \
420         "p1  11   1 drop" \
421         "p1  12   0 br0,p5,p6,pop_vlan,p3,p4,p7,p8" \
422         "p1  12   1 br0,p5,p6,pop_vlan,p4,p7,push_vlan(vid=0,pcp=1),p3,p8" \
423         "p2  none 0 push_vlan(vid=10,pcp=0),br0,p1,p5,p6,p7,p8" \
424         "p2  0    0 pop_vlan,push_vlan(vid=10,pcp=0),br0,p1,p5,p6,p7,p8" \
425         "p2  0    1 pop_vlan,push_vlan(vid=10,pcp=1),br0,p1,p5,p6,p7,p8" \
426         "p2  10   0 drop" \
427         "p2  10   1 drop" \
428         "p2  11   0 drop" \
429         "p2  11   1 drop" \
430         "p2  12   0 drop" \
431         "p2  12   1 drop" \
432         "p3  none 0 p4,p7,p8,push_vlan(vid=12,pcp=0),br0,p1,p5,p6" \
433         "p3  0    0 pop_vlan,p4,p7,p8,push_vlan(vid=12,pcp=0),br0,p1,p5,p6" \
434         "p3  0    1 p8,pop_vlan,p4,p7,push_vlan(vid=12,pcp=1),br0,p1,p5,p6" \
435         "p3  10   0 drop" \
436         "p3  10   1 drop" \
437         "p3  11   0 drop" \
438         "p3  11   1 drop" \
439         "p3  12   0 drop" \
440         "p3  12   1 drop" \
441         "p4  none 0 p3,p7,p8,push_vlan(vid=12,pcp=0),br0,p1,p5,p6" \
442         "p4  0    0 pop_vlan,p3,p7,p8,push_vlan(vid=12,pcp=0),br0,p1,p5,p6" \
443         "p4  0    1 p3,p8,pop_vlan,p7,push_vlan(vid=12,pcp=1),br0,p1,p5,p6" \
444         "p4  10   0 drop" \
445         "p4  10   1 drop" \
446         "p4  11   0 drop" \
447         "p4  11   1 drop" \
448         "p4  12   0 drop" \
449         "p4  12   1 drop" \
450         "p5  none 0 p2,push_vlan(vid=10,pcp=0),br0,p1,p6,p7,p8" \
451         "p5  0    0 pop_vlan,p2,push_vlan(vid=10,pcp=0),br0,p1,p6,p7,p8" \
452         "p5  0    1 pop_vlan,p2,push_vlan(vid=10,pcp=1),br0,p1,p6,p7,p8" \
453         "p5  10   0 br0,p1,p6,p7,p8,pop_vlan,p2" \
454         "p5  10   1 br0,p1,p6,p7,p8,pop_vlan,p2" \
455         "p5  11   0 br0,p7" \
456         "p5  11   1 br0,p7" \
457         "p5  12   0 br0,p1,p6,pop_vlan,p3,p4,p7,p8" \
458         "p5  12   1 br0,p1,p6,pop_vlan,p4,p7,push_vlan(vid=0,pcp=1),p3,p8" \
459         "p6  none 0 p2,push_vlan(vid=10,pcp=0),br0,p1,p5,p7,p8" \
460         "p6  0    0 pop_vlan,p2,push_vlan(vid=10,pcp=0),br0,p1,p5,p7,p8" \
461         "p6  0    1 pop_vlan,p2,push_vlan(vid=10,pcp=1),br0,p1,p5,p7,p8" \
462         "p6  10   0 br0,p1,p5,p7,p8,pop_vlan,p2" \
463         "p6  10   1 br0,p1,p5,p7,p8,pop_vlan,p2" \
464         "p6  11   0 drop" \
465         "p6  11   1 drop" \
466         "p6  12   0 br0,p1,p5,pop_vlan,p3,p4,p7,p8" \
467         "p6  12   1 br0,p1,p5,pop_vlan,p4,p7,push_vlan(vid=0,pcp=1),p3,p8" \
468         "p7  none 0 p3,p4,p8,push_vlan(vid=12,pcp=0),br0,p1,p5,p6" \
469         "p7  0    0 pop_vlan,p3,p4,p8,push_vlan(vid=12,pcp=0),br0,p1,p5,p6" \
470         "p7  0    1 p3,p8,pop_vlan,p4,push_vlan(vid=12,pcp=1),br0,p1,p5,p6" \
471         "p7  10   0 br0,p1,p5,p6,p8,pop_vlan,p2" \
472         "p7  10   1 br0,p1,p5,p6,p8,pop_vlan,p2" \
473         "p7  11   0 br0,p5" \
474         "p7  11   1 br0,p5" \
475         "p7  12   0 br0,p1,p5,p6,pop_vlan,p3,p4,p8" \
476         "p7  12   1 br0,p1,p5,p6,pop_vlan,p4,push_vlan(vid=0,pcp=1),p3,p8" \
477         "p8  none 0 p3,p4,p7,push_vlan(vid=12,pcp=0),br0,p1,p5,p6" \
478         "p8  0    0 pop_vlan,p3,p4,p7,push_vlan(vid=12,pcp=0),br0,p1,p5,p6" \
479         "p8  0    1 p3,pop_vlan,p4,p7,push_vlan(vid=12,pcp=1),br0,p1,p5,p6" \
480         "p8  10   0 br0,p1,p5,p6,p7,pop_vlan,p2" \
481         "p8  10   1 br0,p1,p5,p6,p7,pop_vlan,p2" \
482         "p8  11   0 drop" \
483         "p8  11   1 drop" \
484         "p8  12   0 br0,p1,p5,p6,pop_vlan,p3,p4,p7" \
485         "p8  12   1 br0,p1,p5,p6,pop_vlan,p4,p7,push_vlan(vid=0,pcp=1),p3"
486 do
487   set $tuple
488   in_port=$1
489   vlan=$2
490   pcp=$3
491   expected=$4
492
493   eval n_in_port=\$$in_port
494   if test $vlan = none; then
495     flow="in_port($n_in_port),eth(src=50:54:00:00:00:01,dst=ff:ff:ff:ff:ff:ff),eth_type(0xabcd)"
496   else
497     flow="in_port($n_in_port),eth(src=50:54:00:00:00:01,dst=ff:ff:ff:ff:ff:ff),eth_type(0x8100),vlan(vid=$vlan,pcp=$pcp),encap(eth_type(0xabcd))"
498   fi
499
500   echo "----------------------------------------------------------------------"
501   echo "in_port=$in_port vlan=$vlan pcp=$pcp"
502
503   AT_CHECK([ovs-appctl ofproto/trace br0 "$flow"], [0], [stdout])
504   actual=`tail -1 stdout | sed 's/Datapath actions: //'`
505
506   AT_CHECK([ovs-dpctl normalize-actions "$flow" "$expected" br0=$br0 p1=$p1 p2=$p2 p3=$p3 p4=$p4 p5=$p5 p6=$p6 p7=$p7 p8=$p8], [0], [stdout])
507   mv stdout expout
508   AT_CHECK([ovs-dpctl normalize-actions "$flow" "$actual" br0=$br0 p1=$p1 p2=$p2 p3=$p3 p4=$p4 p5=$p5 p6=$p6 p7=$p7 p8=$p8], [0], [expout])
509 done
510
511 OVS_VSWITCHD_STOP
512 AT_CLEANUP
513
514 AT_SETUP([ofproto-dpif - fragment handling])
515 OVS_VSWITCHD_START
516 AT_DATA([flows.txt], [dnl
517 priority=75 tcp ip_frag=no    tp_dst=80 actions=output:1
518 priority=75 tcp ip_frag=first tp_dst=80 actions=output:2
519 priority=75 tcp ip_frag=later tp_dst=80 actions=output:3
520 priority=50 tcp ip_frag=no              actions=output:4
521 priority=50 tcp ip_frag=first           actions=output:5
522 priority=50 tcp ip_frag=later           actions=output:6
523 ])
524 AT_CHECK([ovs-ofctl replace-flows br0 flows.txt])
525
526 base_flow="in_port(90),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=6,tos=0,ttl=128"
527 no_flow="$base_flow,frag=no),tcp(src=12345,dst=80)"
528 first_flow="$base_flow,frag=first),tcp(src=12345,dst=80)"
529 later_flow="$base_flow,frag=later)"
530
531     # mode    no  first  later
532 for tuple in \
533     'normal    1     5      6' \
534     'drop      1  drop   drop' \
535     'nx-match  1     2      6'
536 do
537   set $tuple
538   mode=$1
539   no=$2
540   first=$3
541   later=$4
542
543   AT_CHECK([ovs-ofctl set-frags br0 $mode])
544   for type in no first later; do
545     eval flow=\$${type}_flow exp_output=\$$type
546     AT_CHECK([ovs-appctl ofproto/trace br0 "$flow"], [0], [stdout])
547     AT_CHECK_UNQUOTED([tail -1 stdout], [0], [Datapath actions: $exp_output
548 ])
549   done
550 done
551 OVS_VSWITCHD_STOP
552 AT_CLEANUP
553
554 AT_SETUP([ofproto-dpif - exit])
555 OVS_VSWITCHD_START
556 AT_DATA([flows.txt], [dnl
557 in_port=1 actions=output:10,exit,output:11
558 in_port=2 actions=output:12,resubmit:1,output:12
559 in_port=3 actions=output:13,resubmit:2,output:14
560 ])
561 AT_CHECK([ovs-ofctl add-flows br0 flows.txt])
562 AT_CHECK([ovs-appctl ofproto/trace br0 'in_port(1),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=1,tos=0,ttl=128,frag=no),icmp(type=8,code=0)'], [0], [stdout])
563 AT_CHECK([tail -1 stdout], [0],
564   [Datapath actions: 10
565 ])
566 AT_CHECK([ovs-appctl ofproto/trace br0 'in_port(2),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=1,tos=0,ttl=128,frag=no),icmp(type=8,code=0)'], [0], [stdout])
567 AT_CHECK([tail -1 stdout], [0],
568   [Datapath actions: 12,10
569 ])
570 AT_CHECK([ovs-appctl ofproto/trace br0 'in_port(3),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=1,tos=0,ttl=128,frag=no),icmp(type=8,code=0)'], [0], [stdout])
571 AT_CHECK([tail -1 stdout], [0],
572   [Datapath actions: 13,12,10
573 ])
574 OVS_VSWITCHD_STOP
575 AT_CLEANUP
576
577
578 AT_SETUP([ofproto-dpif - mirroring, select_all])
579 OVS_VSWITCHD_START(
580        [add-port br0 p1 -- set Interface p1 type=dummy --\
581         add-port br0 p2 -- set Interface p2 type=dummy --\
582         add-port br0 p3 -- set Interface p3 type=dummy --\
583         set Bridge br0 mirrors=@m --\
584         --id=@p3 get Port p3 --\
585         --id=@m create Mirror name=mymirror \
586         select_all=true output_port=@p3], [<0>
587 ])
588
589 AT_CHECK(
590   [ovs-vsctl \
591         -- get Interface p1 ofport \
592         -- get Interface p2 ofport \
593         -- get Interface p3 ofport],
594   [0], [stdout])
595 set `cat stdout`
596 p1=$1 p2=$2 p3=$3
597
598 AT_DATA([flows.txt], [dnl
599 in_port=1 actions=output:2
600 in_port=2 actions=output:1
601 ])
602 AT_CHECK([ovs-ofctl add-flows br0 flows.txt])
603
604 flow="in_port($p1),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=1,tos=0,ttl=128,frag=no),icmp(type=8,code=0)"
605 AT_CHECK([ovs-appctl ofproto/trace br0 "$flow"], [0], [stdout])
606 AT_CHECK_UNQUOTED([tail -1 stdout], [0],
607   [Datapath actions: $p2,$p3
608 ])
609
610 flow="in_port($p2),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=1,tos=0,ttl=128,frag=no),icmp(type=8,code=0)"
611 AT_CHECK([ovs-appctl ofproto/trace br0 "$flow"], [0], [stdout])
612 AT_CHECK_UNQUOTED([tail -1 stdout], [0],
613   [Datapath actions: $p1,$p3
614 ])
615
616 OVS_VSWITCHD_STOP
617 AT_CLEANUP
618
619
620 AT_SETUP([ofproto-dpif - mirroring, select_src])
621 OVS_VSWITCHD_START(
622        [add-port br0 p1 -- set Interface p1 type=dummy --\
623         add-port br0 p2 -- set Interface p2 type=dummy --\
624         add-port br0 p3 -- set Interface p3 type=dummy --\
625         set Bridge br0 mirrors=@m --\
626         --id=@p1 get Port p1 -- --id=@p3 get Port p3 --\
627         --id=@m create Mirror name=mymirror \
628         select_src_port=@p1 output_port=@p3], [<0>
629 ])
630
631 AT_CHECK(
632   [ovs-vsctl \
633         -- get Interface p1 ofport \
634         -- get Interface p2 ofport \
635         -- get Interface p3 ofport],
636   [0], [stdout])
637 set `cat stdout`
638 p1=$1 p2=$2 p3=$3
639
640 AT_DATA([flows.txt], [dnl
641 in_port=1 actions=output:2
642 in_port=2 actions=output:1
643 ])
644 AT_CHECK([ovs-ofctl add-flows br0 flows.txt])
645
646 flow="in_port($p1),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=1,tos=0,ttl=128,frag=no),icmp(type=8,code=0)"
647 AT_CHECK([ovs-appctl ofproto/trace br0 "$flow"], [0], [stdout])
648 AT_CHECK_UNQUOTED([tail -1 stdout], [0],
649   [Datapath actions: $p2,$p3
650 ])
651
652 flow="in_port($p2),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=1,tos=0,ttl=128,frag=no),icmp(type=8,code=0)"
653 AT_CHECK([ovs-appctl ofproto/trace br0 "$flow"], [0], [stdout])
654 AT_CHECK_UNQUOTED([tail -1 stdout], [0],
655   [Datapath actions: $p1
656 ])
657 OVS_VSWITCHD_STOP
658 AT_CLEANUP
659
660 AT_SETUP([ofproto-dpif - mirroring, OFPP_NONE ingress port])
661 OVS_VSWITCHD_START(
662        [add-port br0 p1 -- set Interface p1 type=dummy --\
663         add-port br0 p2 -- set Interface p2 type=dummy --\
664         set Bridge br0 mirrors=@m --\
665         --id=@p2 get Port p2 --\
666         --id=@m create Mirror name=mymirror \
667         select_all=true output_port=@p2], [<0>
668 ])
669
670 AT_CHECK(
671   [ovs-vsctl \
672         -- get Interface p1 ofport \
673         -- get Interface p2 ofport],
674   [0], [stdout])
675 set `cat stdout`
676 p1=$1 p2=$2
677
678 AT_CHECK([ovs-ofctl add-flow br0 action=output:1])
679
680 # "in_port" defaults to OFPP_NONE if it's not specified.
681 flow="eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=1,tos=0,ttl=128,frag=no),icmp(type=8,code=0)"
682 AT_CHECK([ovs-appctl ofproto/trace br0 "$flow"], [0], [stdout])
683 AT_CHECK_UNQUOTED([tail -1 stdout], [0],
684   [Datapath actions: $p1,$p2
685 ])
686
687 OVS_VSWITCHD_STOP
688 AT_CLEANUP
689
690
691 AT_SETUP([ofproto-dpif - mirroring, select_dst])
692 OVS_VSWITCHD_START(
693        [add-port br0 p1 -- set Interface p1 type=dummy --\
694         add-port br0 p2 -- set Interface p2 type=dummy --\
695         add-port br0 p3 -- set Interface p3 type=dummy --\
696         set Bridge br0 mirrors=@m --\
697         --id=@p2 get Port p2 -- --id=@p3 get Port p3 --\
698         --id=@m create Mirror name=mymirror \
699         select_dst_port=@p2 output_port=@p3], [<0>
700 ])
701
702 AT_CHECK(
703   [ovs-vsctl \
704         -- get Interface p1 ofport \
705         -- get Interface p2 ofport \
706         -- get Interface p3 ofport],
707   [0], [stdout])
708 set `cat stdout`
709 p1=$1 p2=$2 p3=$3
710
711 AT_DATA([flows.txt], [dnl
712 in_port=1 actions=output:2
713 in_port=2 actions=output:1
714 ])
715 AT_CHECK([ovs-ofctl add-flows br0 flows.txt])
716
717 flow="in_port($p1),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=1,tos=0,ttl=128,frag=no),icmp(type=8,code=0)"
718 AT_CHECK([ovs-appctl ofproto/trace br0 "$flow"], [0], [stdout])
719 AT_CHECK_UNQUOTED([tail -1 stdout], [0],
720   [Datapath actions: $p2,$p3
721 ])
722
723 flow="in_port($p2),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=1,tos=0,ttl=128,frag=no),icmp(type=8,code=0)"
724 AT_CHECK([ovs-appctl ofproto/trace br0 "$flow"], [0], [stdout])
725 AT_CHECK_UNQUOTED([tail -1 stdout], [0],
726   [Datapath actions: $p1
727 ])
728
729 OVS_VSWITCHD_STOP
730 AT_CLEANUP
731
732
733 AT_SETUP([ofproto-dpif - mirroring, select_vlan])
734 OVS_VSWITCHD_START(
735        [add-port br0 p1 -- set Interface p1 type=dummy --\
736         add-port br0 p2 -- set Interface p2 type=dummy --\
737         add-port br0 p3 -- set Interface p3 type=dummy --\
738         set Bridge br0 mirrors=@m --\
739         --id=@p2 get Port p2 -- --id=@p3 get Port p3 --\
740         --id=@m create Mirror name=mymirror \
741         select_all=true select_vlan=11 output_port=@p3], [<0>
742 ])
743
744 AT_CHECK(
745   [ovs-vsctl \
746         -- get Interface p1 ofport \
747         -- get Interface p2 ofport \
748         -- get Interface p3 ofport],
749   [0], [stdout])
750 set `cat stdout`
751 p1=$1 p2=$2 p3=$3
752
753 AT_DATA([flows.txt], [dnl
754 in_port=1, actions=output:2
755 ])
756 AT_CHECK([ovs-ofctl add-flows br0 flows.txt])
757
758 flow="in_port($p1),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=1,tos=0,ttl=128,frag=no),icmp(type=8,code=0)"
759 AT_CHECK([ovs-appctl ofproto/trace br0 "$flow"], [0], [stdout])
760 AT_CHECK_UNQUOTED([tail -1 stdout], [0],
761   [Datapath actions: $p2
762 ])
763
764 flow="in_port($p1),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x8100),vlan(vid=10,pcp=0),encap(eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=1,tos=0,ttl=128,frag=no),icmp(type=8,code=0))"
765 AT_CHECK([ovs-appctl ofproto/trace br0 "$flow"], [0], [stdout])
766 AT_CHECK_UNQUOTED([tail -1 stdout], [0],
767   [Datapath actions: $p2
768 ])
769
770 flow="in_port($p1),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x8100),vlan(vid=11,pcp=0),encap(eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=1,tos=0,ttl=128,frag=no),icmp(type=8,code=0))"
771 AT_CHECK([ovs-appctl ofproto/trace br0 "$flow"], [0], [stdout])
772 AT_CHECK_UNQUOTED([tail -1 stdout], [0],
773   [Datapath actions: $p2,$p3
774 ])
775
776 OVS_VSWITCHD_STOP
777 AT_CLEANUP
778
779
780 AT_SETUP([ofproto-dpif - mirroring, output_port])
781 OVS_VSWITCHD_START(
782        [add-port br0 p1 -- set Interface p1 type=dummy --\
783         add-port br0 p2 -- set Interface p2 type=dummy --\
784         add-port br0 p3 -- set Interface p3 type=dummy --\
785         set Bridge br0 mirrors=@m --\
786         --id=@p3 get Port p3 --\
787         --id=@m create Mirror name=mymirror \
788         select_all=true output_port=@p3], [<0>
789 ])
790
791 AT_CHECK(
792   [ovs-vsctl \
793         -- get Interface p1 ofport \
794         -- get Interface p2 ofport \
795         -- get Interface p3 ofport],
796   [0], [stdout])
797 set `cat stdout`
798 p1=$1 p2=$2 p3=$3
799
800 AT_DATA([flows.txt], [dnl
801 in_port=1 actions=mod_vlan_vid:17,output:2
802 in_port=2 actions=output:1
803 ])
804 AT_CHECK([ovs-ofctl add-flows br0 flows.txt])
805
806 flow="in_port($p1),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=1,tos=0,ttl=128,frag=no),icmp(type=8,code=0)"
807 AT_CHECK([ovs-appctl ofproto/trace br0 "$flow"], [0], [stdout])
808 AT_CHECK_UNQUOTED([tail -1 stdout], [0],
809   [Datapath actions: push_vlan(vid=17,pcp=0),$p2,pop_vlan,$p3
810 ])
811
812 flow="in_port($p2),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=1,tos=0,ttl=128,frag=no),icmp(type=8,code=0)"
813 AT_CHECK([ovs-appctl ofproto/trace br0 "$flow"], [0], [stdout])
814 AT_CHECK_UNQUOTED([tail -1 stdout], [0],
815   [Datapath actions: $p1,$p3
816 ])
817
818 OVS_VSWITCHD_STOP
819 AT_CLEANUP
820
821 AT_SETUP([ofproto-dpif - mirroring, output_vlan])
822 OVS_VSWITCHD_START(
823        [add-port br0 p1 -- set Interface p1 type=dummy --\
824         add-port br0 p2 -- set Interface p2 type=dummy --\
825         set Bridge br0 mirrors=@m --\
826         --id=@m create Mirror name=mymirror \
827         select_all=true output_vlan=12], [<0>
828 ])
829
830 AT_CHECK(
831   [ovs-vsctl \
832         -- get Interface p1 ofport \
833         -- get Interface p2 ofport],
834   [0], [stdout])
835 set `cat stdout`
836 br0=0 p1=$1 p2=$2
837
838 AT_DATA([flows.txt], [dnl
839 in_port=1 actions=output:2
840 in_port=2 actions=mod_vlan_vid:17,output:1
841 ])
842 AT_CHECK([ovs-ofctl add-flows br0 flows.txt])
843
844 flow="in_port($p1),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=1,tos=0,ttl=128,frag=no),icmp(type=8,code=0)"
845 AT_CHECK([ovs-appctl ofproto/trace br0 "$flow"], [0], [stdout])
846 actual=`tail -1 stdout | sed 's/Datapath actions: //'`
847
848 expected="$p2,push_vlan(vid=12,pcp=0),$br0,$p1,$p2"
849 AT_CHECK([ovs-dpctl normalize-actions "$flow" "$expected" br0=$br0 p1=$p1 p2=$p2], [0], [stdout])
850 mv stdout expout
851 AT_CHECK([ovs-dpctl normalize-actions "$flow" "$actual" br0=$br0 p1=$p1 p2=$p2], [0], [expout])
852
853 flow="in_port($p2),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=1,tos=0,ttl=128,frag=no),icmp(type=8,code=0)"
854 AT_CHECK([ovs-appctl ofproto/trace br0 "$flow"], [0], [stdout])
855 actual=`tail -1 stdout | sed 's/Datapath actions: //'`
856
857 expected="push_vlan(vid=17,pcp=0),$p1,pop_vlan,push_vlan(vid=12,pcp=0),$br0,$p1,$p2"
858 AT_CHECK([ovs-dpctl normalize-actions "$flow" "$expected" br0=$br0 p1=$p1 p2=$p2], [0], [stdout])
859 mv stdout expout
860 AT_CHECK([ovs-dpctl normalize-actions "$flow" "$actual" br0=$br0 p1=$p1 p2=$p2], [0], [expout])
861
862 OVS_VSWITCHD_STOP
863 AT_CLEANUP
864
865 m4_define([OFPROTO_TRACE],
866   [flow="$2"
867    AT_CHECK([ovs-appctl ofproto/trace $1 "$flow" $3], [0], [stdout])
868    actual=`tail -1 stdout | sed 's/Datapath actions: //'`
869    expected="$4"
870    AT_CHECK([ovs-dpctl normalize-actions "$flow" "$expected" $5],
871      [0], [stdout])
872    mv stdout expout
873    AT_CHECK([ovs-dpctl normalize-actions "$flow" "$actual" $5],
874      [0], [expout])])
875
876 AT_SETUP([ofproto-dpif - MAC learning])
877 OVS_VSWITCHD_START(
878   [set bridge br0 fail-mode=standalone -- \
879    add-port br0 p1 -- set Interface p1 type=dummy -- \
880    add-port br0 p2 -- set Interface p2 type=dummy -- \
881    add-port br0 p3 -- set Interface p3 type=dummy])
882
883 AT_CHECK(
884   [ovs-vsctl \
885         -- get Interface p1 ofport \
886         -- get Interface p2 ofport \
887         -- get Interface p3 ofport],
888   [0], [stdout])
889 set `cat stdout`
890 br0=0 p1=$1 p2=$2 p3=$3
891 arp='eth_type(0x0806),arp(sip=192.168.0.1,tip=192.168.0.2,op=1,sha=50:54:00:00:00:05,tha=00:00:00:00:00:00)'
892
893 # Trace an ARP packet arriving on p3, to create a MAC learning entry.
894 OFPROTO_TRACE(
895   [br0],
896   [in_port($p3),eth(src=50:54:00:00:00:05,dst=ff:ff:ff:ff:ff:ff),$arp],
897   [-generate],
898   [$br0,$p1,$p2],
899   [br0=$br0 p1=$p1 p2=$p2 p3=$p3])
900
901 # Check for the MAC learning entry.
902 AT_CHECK_UNQUOTED([ovs-appctl fdb/show br0 | sed 's/[[0-9]]$/?/'], [0], [dnl
903  port  VLAN  MAC                Age
904     $p3     0  50:54:00:00:00:05    ?
905 ])
906
907 # Trace a packet arrival destined for the learned MAC.
908 # (This will also learn a MAC.)
909 OFPROTO_TRACE(
910   [br0],
911   [in_port($p1),eth(src=50:54:00:00:00:06,dst=50:54:00:00:00:05),$arp],
912   [-generate],
913   [$p3],
914   [br0=$br0 p1=$p1 p2=$p2 p3=$p3])
915
916 # Check for both MAC learning entries.
917 AT_CHECK_UNQUOTED([ovs-appctl fdb/show br0 | sed 's/[[0-9]]$/?/'], [0], [dnl
918  port  VLAN  MAC                Age
919     $p3     0  50:54:00:00:00:05    ?
920     $p1     0  50:54:00:00:00:06    ?
921 ])
922
923 # Trace a packet arrival that updates the first learned MAC entry.
924 OFPROTO_TRACE(
925   [br0],
926   [in_port($p2),eth(src=50:54:00:00:00:05,dst=ff:ff:ff:ff:ff:ff),$arp],
927   [-generate],
928   [$br0,$p1,$p3],
929   [br0=$br0 p1=$p1 p2=$p2 p3=$p3])
930
931 # Check that the MAC learning entry was updated.
932 AT_CHECK_UNQUOTED([ovs-appctl fdb/show br0 | sed 's/[[0-9]]$/?/'], [0], [dnl
933  port  VLAN  MAC                Age
934     $p1     0  50:54:00:00:00:06    ?
935     $p2     0  50:54:00:00:00:05    ?
936 ])
937
938 # Add another bridge.
939 AT_CHECK(
940   [ovs-vsctl \
941      -- add-br br1 \
942      -- set bridge br1 datapath-type=dummy \
943      -- add-port br1 p4 -- set interface p4 type=dummy \
944      -- add-port br1 p5 -- set interface p5 type=dummy])
945 AT_CHECK(
946   [ovs-vsctl \
947         -- get Interface p4 ofport \
948         -- get Interface p5 ofport],
949   [0], [stdout])
950 set `cat stdout`
951 br1=0 p4=$1 p5=$2
952
953 # Trace some packet arrivals in br1 to create MAC learning entries there too.
954 OFPROTO_TRACE(
955   [br1],
956   [in_port($p4),eth(src=50:54:00:00:00:06,dst=ff:ff:ff:ff:ff:ff),$arp],
957   [-generate],
958   [$br1,$p5],
959   [br1=$br1 p4=$p4 p5=$p5])
960 OFPROTO_TRACE(
961   [br1],
962   [in_port($p5),eth(src=50:54:00:00:00:07,dst=ff:ff:ff:ff:ff:ff),$arp],
963   [-generate],
964   [$br1,$p4],
965   [br1=$br1 p4=$p4 p5=$p5])
966
967 # Check that the MAC learning entries were added.
968 AT_CHECK_UNQUOTED([ovs-appctl fdb/show br1 | sed 's/[[0-9]]$/?/'], [0], [dnl
969  port  VLAN  MAC                Age
970     $p4     0  50:54:00:00:00:06    ?
971     $p5     0  50:54:00:00:00:07    ?
972 ])
973
974 # Delete port p1 and see that its MAC learning entry disappeared, and
975 # that the MAC learning entry for the same MAC was also deleted from br1.
976 AT_CHECK([ovs-vsctl del-port p1])
977 AT_CHECK_UNQUOTED([ovs-appctl fdb/show br0 | sed 's/[[0-9]]$/?/'], [0], [dnl
978  port  VLAN  MAC                Age
979     $p2     0  50:54:00:00:00:05    ?
980 ])
981 AT_CHECK_UNQUOTED([ovs-appctl fdb/show br1 | sed 's/[[0-9]]$/?/'], [0], [dnl
982  port  VLAN  MAC                Age
983     $p5     0  50:54:00:00:00:07    ?
984 ])
985
986 OVS_VSWITCHD_STOP
987 AT_CLEANUP
988
989 dnl Test that basic NetFlow reports flow statistics correctly:
990 dnl - The initial packet of a flow are correctly accounted.
991 dnl - Later packets within a flow are correctly accounted.
992 dnl - Flow actions changing (in this case, due to MAC learning)
993 dnl   cause a record to be sent.
994 AT_SETUP([ofproto-dpif - NetFlow flow expiration])
995
996 AT_SKIP_IF([test "x$RANDOM" = x])
997 NETFLOW_PORT=`expr 32767 + \( $RANDOM % 32767 \)`
998
999 OVS_VSWITCHD_START(
1000   [set Bridge br0 fail-mode=standalone -- \
1001    add-port br0 p1 -- set Interface p1 type=dummy -- \
1002    add-port br0 p2 -- set Interface p2 type=dummy -- \
1003    set Bridge br0 netflow=@nf -- \
1004    --id=@nf create NetFlow targets=\"127.0.0.1:$NETFLOW_PORT\" \
1005      engine_id=1 engine_type=2 active_timeout=30 \
1006      add-id-to-interface=false], [<0>
1007 ])
1008
1009 AT_CHECK([test-netflow --detach --pidfile $NETFLOW_PORT:127.0.0.1 > netflow.log])AT_CAPTURE_FILE([netflow.log])
1010
1011 for delay in 1000 30000; do
1012     ovs-appctl netdev-dummy/receive p1 'in_port(2),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=1,tos=0,ttl=64,frag=no),icmp(type=8,code=0)'
1013     ovs-appctl netdev-dummy/receive p2 'in_port(1),eth(src=50:54:00:00:00:07,dst=50:54:00:00:00:05),eth_type(0x0800),ipv4(src=192.168.0.2,dst=192.168.0.1,proto=1,tos=0,ttl=64,frag=no),icmp(type=0,code=0)'
1014
1015     ovs-appctl time/warp $delay
1016 done
1017
1018 OVS_VSWITCHD_STOP
1019 ovs-appctl -t test-netflow exit
1020
1021 AT_CHECK([[sed -e 's/, uptime [0-9]*//
1022 s/, now [0-9.]*//
1023 s/time \([0-9]*\)\.\.\.\1\b/time <moment>/
1024 s/time [0-9]*\.\.\.[0-9]*/time <range>/
1025 ' netflow.log]], [0],
1026   [header: v5, seq 0, engine 2,1
1027 rec: 192.168.0.1 > 192.168.0.2, if 1 > 65535, 1 pkts, 60 bytes, ICMP 8:0, time <moment>
1028
1029 header: v5, seq 1, engine 2,1
1030 rec: 192.168.0.2 > 192.168.0.1, if 2 > 1, 2 pkts, 120 bytes, ICMP 0:0, time <range>
1031 rec: 192.168.0.1 > 192.168.0.2, if 1 > 2, 1 pkts, 60 bytes, ICMP 8:0, time <moment>
1032 ])
1033 AT_CLEANUP
1034
1035 dnl Test that basic NetFlow reports active expirations correctly.
1036 AT_SETUP([ofproto-dpif - NetFlow active expiration])
1037
1038 AT_SKIP_IF([test "x$RANDOM" = x])
1039 NETFLOW_PORT=`expr 32767 + \( $RANDOM % 32767 \)`
1040
1041 OVS_VSWITCHD_START(
1042   [set Bridge br0 fail-mode=standalone -- \
1043    add-port br0 p1 -- set Interface p1 type=dummy -- \
1044    add-port br0 p2 -- set Interface p2 type=dummy -- \
1045    set Bridge br0 netflow=@nf -- \
1046    --id=@nf create NetFlow targets=\"127.0.0.1:$NETFLOW_PORT\" \
1047      engine_id=1 engine_type=2 active_timeout=10 \
1048      add-id-to-interface=false], [<0>
1049 ])
1050
1051 AT_CHECK([test-netflow --detach --pidfile $NETFLOW_PORT:127.0.0.1 > netflow.log])AT_CAPTURE_FILE([netflow.log])
1052
1053 n=1
1054 while test $n -le 60; do
1055     n=`expr $n + 1`
1056
1057     ovs-appctl netdev-dummy/receive p1 'in_port(2),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=6,tos=0,ttl=64,frag=no),tcp(src=1234,dst=80)'
1058     ovs-appctl netdev-dummy/receive p2 'in_port(1),eth(src=50:54:00:00:00:07,dst=50:54:00:00:00:05),eth_type(0x0800),ipv4(src=192.168.0.2,dst=192.168.0.1,proto=6,tos=0,ttl=64,frag=no),tcp(src=80,dst=1234)'
1059
1060     ovs-appctl time/warp 1000
1061 done
1062
1063 ovs-appctl time/warp 10000
1064
1065 OVS_VSWITCHD_STOP
1066 ovs-appctl -t test-netflow exit
1067
1068 # Count the number of reported packets:
1069 # - From source to destination before MAC learning kicks in (just one).
1070 # - From source to destination after that.
1071 # - From destination to source.
1072 n_learn=0
1073 n_in=0
1074 n_out=0
1075 n_other=0
1076 n_recs=0
1077 none=0
1078 while read line; do
1079     pkts=`echo "$line" | sed 's/.*, \([[0-9]]*\) pkts,.*/\1/'`
1080     case $pkts in
1081          [[0-9]]*) ;;
1082          *) continue ;;
1083     esac
1084
1085     case $line in
1086         "rec: 192.168.0.1 > 192.168.0.2, if 1 > 65535, "*" pkts, "*" bytes, TCP 1234 > 80, time "*)
1087             counter=n_learn
1088             ;;
1089         "rec: 192.168.0.1 > 192.168.0.2, if 1 > 2, "*" pkts, "*" bytes, TCP 1234 > 80, time "*)
1090             counter=n_in
1091             ;;
1092         "rec: 192.168.0.2 > 192.168.0.1, if 2 > 1, "*" pkts, "*" bytes, TCP 80 > 1234, time "*)
1093             counter=n_out
1094             ;;
1095         *)
1096             counter=n_other
1097             ;;
1098     esac
1099     eval $counter=\`expr \$$counter + \$pkts\`
1100     n_recs=`expr $n_recs + 1`
1101 done < netflow.log
1102
1103 # There should be exactly 1 MAC learning packet,
1104 # exactly 59 other packets in that direction,
1105 # and exactly 60 packets in the other direction.
1106 AT_CHECK([echo $n_learn $n_in $n_out $n_other], [0], [1 59 60 0
1107 ])
1108
1109 # There should be 1 expiration for MAC learning,
1110 # at least 5 active and a final expiration in one direction,
1111 # and at least 5 active and a final expiration in the other direction.
1112 echo $n_recs
1113 AT_CHECK([test $n_recs -ge 13])
1114
1115 AT_CLEANUP