blob: e80c803072d7246d1ed57c48620c02e9545e20d5 [file] [log] [blame]
Jonathan Hart23701d12014-04-03 10:45:48 -07001package net.onrc.onos.core.util;
HIGUCHI Yutad8dc9c02013-08-04 06:16:30 +09002
3import static org.junit.Assert.assertEquals;
4import net.floodlightcontroller.util.MACAddress;
Jonathan Hart23701d12014-04-03 10:45:48 -07005import net.onrc.onos.core.util.FlowEntryAction;
6import net.onrc.onos.core.util.IPv4;
7import net.onrc.onos.core.util.Port;
8import net.onrc.onos.core.util.FlowEntryAction.ActionEnqueue;
9import net.onrc.onos.core.util.FlowEntryAction.ActionOutput;
10import net.onrc.onos.core.util.FlowEntryAction.ActionSetEthernetAddr;
11import net.onrc.onos.core.util.FlowEntryAction.ActionSetIPv4Addr;
12import net.onrc.onos.core.util.FlowEntryAction.ActionSetIpToS;
13import net.onrc.onos.core.util.FlowEntryAction.ActionSetTcpUdpPort;
14import net.onrc.onos.core.util.FlowEntryAction.ActionSetVlanId;
15import net.onrc.onos.core.util.FlowEntryAction.ActionSetVlanPriority;
16import net.onrc.onos.core.util.FlowEntryAction.ActionStripVlan;
HIGUCHI Yutad8dc9c02013-08-04 06:16:30 +090017
18import org.junit.Test;
19
20public class FlowEntryActionTest {
21
22 @Test
23 public void testSetActionOutputActionOutput(){
24 FlowEntryAction act = new FlowEntryAction();
Yuta HIGUCHI382827f2013-10-14 16:06:43 -070025 ActionOutput actout = new FlowEntryAction.ActionOutput(new Port((short)42));
HIGUCHI Yutad8dc9c02013-08-04 06:16:30 +090026 act.setActionOutput(actout);
27
28 assertEquals("action output",FlowEntryAction.ActionValues.ACTION_OUTPUT , act.actionType());
29 assertEquals("actionOutput port should be the same", actout.port(), act.actionOutput().port());
30 assertEquals("actionOutput maxlen should be the same", actout.maxLen(), act.actionOutput().maxLen());
31
32 FlowEntryAction act_copy = new FlowEntryAction(act);
33 FlowEntryAction act_copy2 = new FlowEntryAction(act.toString());
34
35 assertEquals("toString must match between copies", act.toString(),
36 act_copy.toString());
37 assertEquals("toString must match between copies", act.toString(),
38 act_copy2.toString());
39 }
40
41 @Test
42 public void testSetActionOutputPort(){
43 FlowEntryAction act = new FlowEntryAction();
44 act.setActionOutput(new Port((short)42));
45
46 FlowEntryAction act_copy = new FlowEntryAction(act);
47 FlowEntryAction act_copy2 = new FlowEntryAction(act.toString());
48
49 assertEquals("toString must match between copies", act.toString(),
50 act_copy.toString());
51 assertEquals("toString must match between copies", act.toString(),
52 act_copy2.toString());
53 }
54
55 @Test
56 public void testSetActionOutputToController(){
57 FlowEntryAction act = new FlowEntryAction();
58 act.setActionOutputToController((short)0);
59
60 FlowEntryAction act_copy = new FlowEntryAction();
61 act_copy.setActionOutput(new Port(Port.PortValues.PORT_CONTROLLER));
62 ;
63 FlowEntryAction act_copy2 = new FlowEntryAction(act.toString());
64
65 assertEquals("toString must match between copies", act.toString(),
66 act_copy.toString());
67 assertEquals("toString must match between copies", act.toString(),
68 act_copy2.toString());
69 }
70
71 @Test
72 public void testSetActionSetVlanIdActionSetVlanId(){
73 FlowEntryAction act = new FlowEntryAction();
Yuta HIGUCHI382827f2013-10-14 16:06:43 -070074 ActionSetVlanId actVlan = new FlowEntryAction.ActionSetVlanId((short)42);
HIGUCHI Yutad8dc9c02013-08-04 06:16:30 +090075 act.setActionSetVlanId(actVlan);
76
77 assertEquals("action type",FlowEntryAction.ActionValues.ACTION_SET_VLAN_VID , act.actionType());
78 assertEquals("vlanid should be the same", actVlan.vlanId(), act.actionSetVlanId().vlanId());
79
80 FlowEntryAction act_copy = new FlowEntryAction(act);
81 FlowEntryAction act_copy2 = new FlowEntryAction(act.toString());
82
83 assertEquals("toString must match between copies", act.toString(),
84 act_copy.toString());
85 assertEquals("toString must match between copies", act.toString(),
86 act_copy2.toString());
87 }
88
89 @Test
90 public void testSetActionSetVlanIdShort(){
91 FlowEntryAction act = new FlowEntryAction();
92 act.setActionSetVlanId((short)42);
93
94 FlowEntryAction act_copy = new FlowEntryAction(act);
95 FlowEntryAction act_copy2 = new FlowEntryAction(act.toString());
96
97 assertEquals("toString must match between copies", act.toString(),
98 act_copy.toString());
99 assertEquals("toString must match between copies", act.toString(),
100 act_copy2.toString());
101 }
102
103 @Test
104 public void testSetActionSetVlanPriorityActionSetVlanPriority(){
105 FlowEntryAction act = new FlowEntryAction();
Yuta HIGUCHI382827f2013-10-14 16:06:43 -0700106 ActionSetVlanPriority actVlan = new FlowEntryAction.ActionSetVlanPriority((byte)42);
HIGUCHI Yutad8dc9c02013-08-04 06:16:30 +0900107 act.setActionSetVlanPriority(actVlan);
108
109 assertEquals("action type",FlowEntryAction.ActionValues.ACTION_SET_VLAN_PCP , act.actionType());
110 assertEquals("vlan priority should be the same", actVlan.vlanPriority(), act.actionSetVlanPriority().vlanPriority());
111
112 FlowEntryAction act_copy = new FlowEntryAction(act);
113 FlowEntryAction act_copy2 = new FlowEntryAction(act.toString());
114
115 assertEquals("toString must match between copies", act.toString(),
116 act_copy.toString());
117 assertEquals("toString must match between copies", act.toString(),
118 act_copy2.toString());
119 }
120
121 @Test
122 public void testSetActionSetVlanPriorityByte(){
123 FlowEntryAction act = new FlowEntryAction();
124 act.setActionSetVlanPriority((byte)42);
125
126 FlowEntryAction act_copy = new FlowEntryAction(act);
127 FlowEntryAction act_copy2 = new FlowEntryAction(act.toString());
128
129 assertEquals("toString must match between copies", act.toString(),
130 act_copy.toString());
131 assertEquals("toString must match between copies", act.toString(),
132 act_copy2.toString());
133 }
134
135 @Test
136 public void testSetActionStripVlanActionStripVlan(){
137 FlowEntryAction act = new FlowEntryAction();
Yuta HIGUCHI382827f2013-10-14 16:06:43 -0700138 ActionStripVlan actVlan = new FlowEntryAction.ActionStripVlan();
HIGUCHI Yutad8dc9c02013-08-04 06:16:30 +0900139 act.setActionStripVlan(actVlan);
140
141 assertEquals("action type",FlowEntryAction.ActionValues.ACTION_STRIP_VLAN , act.actionType());
142 assertEquals("vlanid should be the same", actVlan.stripVlan(), act.actionStripVlan().stripVlan());
143
144 FlowEntryAction act_copy = new FlowEntryAction(act);
145 FlowEntryAction act_copy2 = new FlowEntryAction(act.toString());
146
147 assertEquals("toString must match between copies", act.toString(),
148 act_copy.toString());
149 assertEquals("toString must match between copies", act.toString(),
150 act_copy2.toString());
151 }
152
153 @Test
154 public void testSetActionStripVlanBoolean(){
155 FlowEntryAction act = new FlowEntryAction();
156 act.setActionStripVlan(true);
157
158 FlowEntryAction act_copy = new FlowEntryAction(act);
159 FlowEntryAction act_copy2 = new FlowEntryAction(act.toString());
160
161 assertEquals("toString must match between copies", act.toString(),
162 act_copy.toString());
163 assertEquals("toString must match between copies", act.toString(),
164 act_copy2.toString());
165 }
166
167 @Test
168 public void testSetActionSetEthernetSrcAddrActionSetEthernetAddr(){
169 FlowEntryAction act = new FlowEntryAction();
170 byte[] mac = { 1, 2, 3, 4, 5, 6 };
Yuta HIGUCHI382827f2013-10-14 16:06:43 -0700171 ActionSetEthernetAddr setEth = new FlowEntryAction.ActionSetEthernetAddr(new MACAddress(mac));
HIGUCHI Yutad8dc9c02013-08-04 06:16:30 +0900172 act.setActionSetEthernetSrcAddr( setEth );
173
174 assertEquals("action type",FlowEntryAction.ActionValues.ACTION_SET_DL_SRC , act.actionType());
175 assertEquals("addr should be the same", setEth.addr(), act.actionSetEthernetSrcAddr().addr());
176
177
178 FlowEntryAction act_copy = new FlowEntryAction(act);
179 FlowEntryAction act_copy2 = new FlowEntryAction(act.toString());
180
181 assertEquals("toString must match between copies", act.toString(),
182 act_copy.toString());
183 assertEquals("toString must match between copies", act.toString(),
184 act_copy2.toString());
185 }
186
187 @Test
188 public void testSetActionSetEthernetSrcAddrMACAddress(){
189 FlowEntryAction act = new FlowEntryAction();
190 byte[] mac = { 1, 2, 3, 4, 5, 6 };
191 act.setActionSetEthernetSrcAddr(new MACAddress(mac));
192
193 FlowEntryAction act_copy = new FlowEntryAction(act);
194 FlowEntryAction act_copy2 = new FlowEntryAction(act.toString());
195
196 assertEquals("toString must match between copies", act.toString(),
197 act_copy.toString());
198 assertEquals("toString must match between copies", act.toString(),
199 act_copy2.toString());
200 }
201
202 @Test
203 public void testSetActionSetEthernetDstAddrActionSetEthernetAddr(){
204 FlowEntryAction act = new FlowEntryAction();
205 byte[] mac = { 1, 2, 3, 4, 5, 6 };
Yuta HIGUCHI382827f2013-10-14 16:06:43 -0700206 ActionSetEthernetAddr setEth = new FlowEntryAction.ActionSetEthernetAddr(new MACAddress(mac));
HIGUCHI Yutad8dc9c02013-08-04 06:16:30 +0900207 act.setActionSetEthernetDstAddr( setEth );
208
209 assertEquals("action type",FlowEntryAction.ActionValues.ACTION_SET_DL_DST , act.actionType());
210 assertEquals("addr should be the same", setEth.addr(), act.actionSetEthernetDstAddr().addr());
211
212 FlowEntryAction act_copy = new FlowEntryAction(act);
213 FlowEntryAction act_copy2 = new FlowEntryAction(act.toString());
214
215 assertEquals("toString must match between copies", act.toString(),
216 act_copy.toString());
217 assertEquals("toString must match between copies", act.toString(),
218 act_copy2.toString());
219 }
220
221 @Test
222 public void testSetActionSetEthernetDstAddrMACAddress(){
223 FlowEntryAction act = new FlowEntryAction();
224 byte[] mac = { 1, 2, 3, 4, 5, 6 };
225 act.setActionSetEthernetDstAddr(new MACAddress(mac));
226
227 FlowEntryAction act_copy = new FlowEntryAction(act);
228 FlowEntryAction act_copy2 = new FlowEntryAction(act.toString());
229
230 assertEquals("toString must match between copies", act.toString(),
231 act_copy.toString());
232 assertEquals("toString must match between copies", act.toString(),
233 act_copy2.toString());
234 }
235
236 @Test
237 public void testSetActionSetIPv4SrcAddrActionSetIPv4Addr(){
238 FlowEntryAction act = new FlowEntryAction();
Yuta HIGUCHI382827f2013-10-14 16:06:43 -0700239 ActionSetIPv4Addr setIp = new FlowEntryAction.ActionSetIPv4Addr(new IPv4("127.0.0.1"));
HIGUCHI Yutad8dc9c02013-08-04 06:16:30 +0900240 act.setActionSetIPv4SrcAddr( setIp );
241
242 assertEquals("action type",FlowEntryAction.ActionValues.ACTION_SET_NW_SRC , act.actionType());
243 assertEquals("addr should be the same", setIp.addr(), act.actionSetIPv4SrcAddr().addr());
244
245 FlowEntryAction act_copy = new FlowEntryAction(act);
246 FlowEntryAction act_copy2 = new FlowEntryAction(act.toString());
247
248
249 assertEquals("toString must match between copies", act.toString(),
250 act_copy.toString());
251 assertEquals("toString must match between copies", act.toString(),
252 act_copy2.toString());
253 }
254
255 @Test
256 public void testSetActionSetIPv4SrcAddrIPv4(){
257 FlowEntryAction act = new FlowEntryAction();
258 act.setActionSetIPv4SrcAddr(new IPv4("127.0.0.1"));
259
260 FlowEntryAction act_copy = new FlowEntryAction(act);
261 FlowEntryAction act_copy2 = new FlowEntryAction(act.toString());
262
263 assertEquals("toString must match between copies", act.toString(),
264 act_copy.toString());
265 assertEquals("toString must match between copies", act.toString(),
266 act_copy2.toString());
267 }
268
269 @Test
270 public void testSetActionSetIPv4DstAddrActionSetIPv4Addr(){
271 FlowEntryAction act = new FlowEntryAction();
Yuta HIGUCHI382827f2013-10-14 16:06:43 -0700272 ActionSetIPv4Addr setIp = new FlowEntryAction.ActionSetIPv4Addr(new IPv4("127.0.0.1"));
HIGUCHI Yutad8dc9c02013-08-04 06:16:30 +0900273 act.setActionSetIPv4DstAddr( setIp );
274
275 assertEquals("action type",FlowEntryAction.ActionValues.ACTION_SET_NW_DST , act.actionType());
276 assertEquals("addr should be the same", setIp.addr(), act.actionSetIPv4DstAddr().addr());
277
278 FlowEntryAction act_copy = new FlowEntryAction(act);
279 FlowEntryAction act_copy2 = new FlowEntryAction(act.toString());
280
281 assertEquals("toString must match between copies", act.toString(),
282 act_copy.toString());
283 assertEquals("toString must match between copies", act.toString(),
284 act_copy2.toString());
285 }
286
287 @Test
288 public void testSetActionSetIPv4DstAddrIPv4(){
289 FlowEntryAction act = new FlowEntryAction();
290 act.setActionSetIPv4DstAddr(new IPv4("127.0.0.1"));
291
292 FlowEntryAction act_copy = new FlowEntryAction(act);
293 FlowEntryAction act_copy2 = new FlowEntryAction(act.toString());
294
295 assertEquals("toString must match between copies", act.toString(),
296 act_copy.toString());
297 assertEquals("toString must match between copies", act.toString(),
298 act_copy2.toString());
299 }
300
301 @Test
302 public void testSetActionSetIpToSActionSetIpToS(){
303 FlowEntryAction act = new FlowEntryAction();
Yuta HIGUCHI382827f2013-10-14 16:06:43 -0700304 ActionSetIpToS setIpTos = new FlowEntryAction.ActionSetIpToS((byte)42);
HIGUCHI Yutad8dc9c02013-08-04 06:16:30 +0900305 act.setActionSetIpToS( setIpTos );
306
307 assertEquals("action type",FlowEntryAction.ActionValues.ACTION_SET_NW_TOS , act.actionType());
308 assertEquals("tos should be the same", setIpTos.ipToS(), act.actionSetIpToS().ipToS());
309
310 FlowEntryAction act_copy = new FlowEntryAction(act);
311 FlowEntryAction act_copy2 = new FlowEntryAction(act.toString());
312
313 assertEquals("toString must match between copies", act.toString(),
314 act_copy.toString());
315 assertEquals("toString must match between copies", act.toString(),
316 act_copy2.toString());
317 }
318
319 @Test
320 public void testSetActionSetIpToSByte(){
321 FlowEntryAction act = new FlowEntryAction();
322 act.setActionSetIpToS((byte)1);
323
324 FlowEntryAction act_copy = new FlowEntryAction(act);
325 FlowEntryAction act_copy2 = new FlowEntryAction(act.toString());
326
327 assertEquals("toString must match between copies", act.toString(),
328 act_copy.toString());
329 assertEquals("toString must match between copies", act.toString(),
330 act_copy2.toString());
331 }
332
333 @Test
334 public void testSetActionSetTcpUdpSrcPortActionSetTcpUdpPort(){
335 FlowEntryAction act = new FlowEntryAction();
Yuta HIGUCHI382827f2013-10-14 16:06:43 -0700336 ActionSetTcpUdpPort setPorts = new FlowEntryAction.ActionSetTcpUdpPort((short)42);
HIGUCHI Yutad8dc9c02013-08-04 06:16:30 +0900337 act.setActionSetTcpUdpSrcPort( setPorts );
338
339 assertEquals("action type",FlowEntryAction.ActionValues.ACTION_SET_TP_SRC , act.actionType());
340 assertEquals("port should be the same", setPorts.port(), act.actionSetTcpUdpSrcPort().port());
341
342 FlowEntryAction act_copy = new FlowEntryAction(act);
343 FlowEntryAction act_copy2 = new FlowEntryAction(act.toString());
344
345 assertEquals("toString must match between copies", act.toString(),
346 act_copy.toString());
347 assertEquals("toString must match between copies", act.toString(),
348 act_copy2.toString());
349 }
350
351 @Test
352 public void testSetActionSetTcpUdpSrcPortShort(){
353 FlowEntryAction act = new FlowEntryAction();
354 act.setActionSetTcpUdpSrcPort((short)1);
355
356 FlowEntryAction act_copy = new FlowEntryAction(act);
357 FlowEntryAction act_copy2 = new FlowEntryAction(act.toString());
358
359 assertEquals("toString must match between copies", act.toString(),
360 act_copy.toString());
361 assertEquals("toString must match between copies", act.toString(),
362 act_copy2.toString());
363 }
364
365 @Test
366 public void testSetActionSetTcpUdpDstPortActionSetTcpUdpPort(){
367 FlowEntryAction act = new FlowEntryAction();
Yuta HIGUCHI382827f2013-10-14 16:06:43 -0700368 ActionSetTcpUdpPort setPorts = new FlowEntryAction.ActionSetTcpUdpPort((short)42);
HIGUCHI Yutad8dc9c02013-08-04 06:16:30 +0900369 act.setActionSetTcpUdpDstPort( setPorts );
370
371 assertEquals("action type",FlowEntryAction.ActionValues.ACTION_SET_TP_DST , act.actionType());
372 assertEquals("port should be the same", setPorts.port(), act.actionSetTcpUdpDstPort().port());
373
374 FlowEntryAction act_copy = new FlowEntryAction(act);
375 FlowEntryAction act_copy2 = new FlowEntryAction(act.toString());
376
377 assertEquals("toString must match between copies", act.toString(),
378 act_copy.toString());
379 assertEquals("toString must match between copies", act.toString(),
380 act_copy2.toString());
381 }
382
383 @Test
384 public void testSetActionSetTcpUdpDstPortShort(){
385 FlowEntryAction act = new FlowEntryAction();
386 act.setActionSetTcpUdpDstPort((short)1);
387
388 FlowEntryAction act_copy = new FlowEntryAction(act);
389 FlowEntryAction act_copy2 = new FlowEntryAction(act.toString());
390
391 assertEquals("toString must match between copies", act.toString(),
392 act_copy.toString());
393 assertEquals("toString must match between copies", act.toString(),
394 act_copy2.toString());
395 }
396
397 @Test
398 public void testSetActionEnqueueActionEnqueue(){
399 FlowEntryAction act = new FlowEntryAction();
Yuta HIGUCHI382827f2013-10-14 16:06:43 -0700400 ActionEnqueue enq = new FlowEntryAction.ActionEnqueue(new Port((short)42), 1);
HIGUCHI Yutad8dc9c02013-08-04 06:16:30 +0900401 act.setActionEnqueue( enq );
402
403 assertEquals("action type",FlowEntryAction.ActionValues.ACTION_ENQUEUE , act.actionType());
404 assertEquals("port should be the same", enq.port(), act.actionEnqueue().port());
405 assertEquals("queue id should be the same", enq.queueId(), act.actionEnqueue().queueId());
406
407 FlowEntryAction act_copy = new FlowEntryAction(act);
408 FlowEntryAction act_copy2 = new FlowEntryAction(act.toString());
409
410 assertEquals("toString must match between copies", act.toString(),
411 act_copy.toString());
412 assertEquals("toString must match between copies", act.toString(),
413 act_copy2.toString());
414 }
415
416 @Test
417 public void testSetActionEnqueuePortInt(){
418 FlowEntryAction act = new FlowEntryAction();
419 act.setActionEnqueue(new Port((short)42), 1);
420
421 FlowEntryAction act_copy = new FlowEntryAction(act);
422 FlowEntryAction act_copy2 = new FlowEntryAction(act.toString());
423
424 assertEquals("toString must match between copies", act.toString(),
425 act_copy.toString());
426 assertEquals("toString must match between copies", act.toString(),
427 act_copy2.toString());
428 }
429
430}