2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.forwardingrulesmanager;
11 import java.net.InetAddress;
12 import java.net.UnknownHostException;
13 import java.util.ArrayList;
14 import java.util.HashSet;
15 import java.util.List;
18 import org.junit.Assert;
19 import org.junit.Test;
20 import org.opendaylight.controller.forwardingrulesmanager.FlowConfig;
21 import org.opendaylight.controller.forwardingrulesmanager.FlowEntry;
22 import org.opendaylight.controller.sal.action.Action;
23 import org.opendaylight.controller.sal.action.ActionType;
24 import org.opendaylight.controller.sal.action.Controller;
25 import org.opendaylight.controller.sal.action.Flood;
26 import org.opendaylight.controller.sal.action.Output;
27 import org.opendaylight.controller.sal.action.PopVlan;
28 import org.opendaylight.controller.sal.action.SetDlDst;
29 import org.opendaylight.controller.sal.action.SetNwDst;
30 import org.opendaylight.controller.sal.action.SetVlanId;
31 import org.opendaylight.controller.sal.core.Node;
32 import org.opendaylight.controller.sal.core.NodeConnector;
33 import org.opendaylight.controller.sal.flowprogrammer.Flow;
34 import org.opendaylight.controller.sal.match.Match;
35 import org.opendaylight.controller.sal.match.MatchType;
36 import org.opendaylight.controller.sal.utils.EtherTypes;
37 import org.opendaylight.controller.sal.utils.IPProtocols;
38 import org.opendaylight.controller.sal.utils.NodeConnectorCreator;
39 import org.opendaylight.controller.sal.utils.NodeCreator;
41 public class frmTest {
44 public void testFlowEntryInstall() throws UnknownHostException {
45 Node node = NodeCreator.createOFNode(1L);
46 FlowEntry pol = new FlowEntry("polTest", null, getSampleFlowV6(node),
48 FlowEntry pol2 = new FlowEntry("polTest2", null, getSampleFlowV6(node),
50 FlowEntryInstall fei = new FlowEntryInstall(pol, null);
51 FlowEntryInstall fei2 = new FlowEntryInstall(pol, null);
52 FlowEntryInstall fei3 = new FlowEntryInstall(pol2, null);
53 Assert.assertTrue(fei.getOriginal().equals(pol));
54 Assert.assertTrue(fei.getInstall().equals(pol));
55 Assert.assertTrue(fei.getFlowName().equals(pol.getFlowName()));
56 Assert.assertTrue(fei.getGroupName().equals(pol.getGroupName()));
57 Assert.assertTrue(fei.getNode().equals(pol.getNode()));
58 Assert.assertFalse(fei.isDeletePending());
60 Assert.assertTrue(fei.isDeletePending());
61 Assert.assertNull(fei.getContainerFlow());
62 Assert.assertTrue(fei.equalsByNodeAndName(pol.getNode(),
65 Assert.assertTrue(fei.equals(fei2));
66 fei2.getOriginal().setFlowName("polTest2");
67 Assert.assertFalse(fei.equals(null));
68 Assert.assertFalse(fei.equals(fei3));
73 public void testFlowEntryCreation() throws UnknownHostException {
74 Node node = NodeCreator.createOFNode(1L);
75 FlowEntry pol = new FlowEntry("polTest", null, getSampleFlowV6(node),
77 Assert.assertTrue(pol.getFlow().equals(getSampleFlowV6(node)));
81 public void testFlowEntrySetGet() throws UnknownHostException {
82 Node node = NodeCreator.createOFNode(1L);
83 Node node2 = NodeCreator.createOFNode(2L);
84 FlowEntry pol = new FlowEntry("polTest", null, getSampleFlowV6(node),
86 pol.setGroupName("polTest2");
87 pol.setFlowName("flowName");
88 Assert.assertTrue(pol.getFlowName().equals("flowName"));
89 Assert.assertTrue(pol.getGroupName().equals("polTest2"));
91 Assert.assertTrue(pol.getNode().equals(node2));
92 Assert.assertTrue(pol.equalsByNodeAndName(node2, "flowName"));
96 public void testFlowEntryEquality() throws UnknownHostException {
97 Node node = NodeCreator.createOFNode(1L);
98 Node node2 = NodeCreator.createOFNode(1L);
99 FlowEntry pol = new FlowEntry("polTest", null, getSampleFlowV6(node),
101 FlowEntry pol2 = new FlowEntry("polTest", null, getSampleFlowV6(node),
103 Assert.assertTrue(pol.equals(pol2));
107 public void testFlowEntryCloning() throws UnknownHostException {
108 Node node = NodeCreator.createOFNode(1L);
109 FlowEntry pol = new FlowEntry("polTest", null, getSampleFlowV6(node),
111 FlowEntry pol2 = pol.clone();
112 Assert.assertTrue(pol.equals(pol2));
116 public void testFlowEntrySet() throws UnknownHostException {
117 Set<FlowEntry> set = new HashSet<FlowEntry>();
119 Node node1 = NodeCreator.createOFNode(1L);
120 Node node2 = NodeCreator.createOFNode(2L);
121 Node node3 = NodeCreator.createOFNode(3L);
123 Match match = new Match();
124 match.setField(MatchType.NW_SRC, InetAddress.getAllByName("1.1.1.1"));
125 match.setField(MatchType.NW_DST, InetAddress.getAllByName("2.2.2.2"));
126 match.setField(MatchType.DL_TYPE, EtherTypes.IPv4.shortValue());
128 List<Action> actionList = new ArrayList<Action>();
129 // actionList.add(new Drop());
131 Flow flow = new Flow(match, actionList);
132 FlowEntry pol1 = new FlowEntry("m1", "same", flow, node1);
133 FlowEntry pol2 = new FlowEntry("m2", "same", flow, node2);
134 FlowEntry pol3 = new FlowEntry("m3", "same", flow, node3);
140 Assert.assertTrue(set.contains(pol1));
141 Assert.assertTrue(set.contains(pol2));
142 Assert.assertTrue(set.contains(pol3));
144 Assert.assertTrue(set.contains(pol1.clone()));
145 Assert.assertTrue(set.contains(pol2.clone()));
146 Assert.assertTrue(set.contains(pol3.clone()));
151 public void testInternalFlow() {
152 FlowConfig flowConfig = new FlowConfig();
153 Assert.assertFalse(flowConfig.isInternalFlow());
154 flowConfig.setName("**Internal");
155 Assert.assertTrue(flowConfig.isInternalFlow());
156 flowConfig.setName("External");
157 Assert.assertFalse(flowConfig.isInternalFlow());
161 public void testFlowConfigCreateSet() throws UnknownHostException {
162 FlowConfig frmC = new FlowConfig();
163 FlowConfig frmC3 = new FlowConfig();
164 Node node = NodeCreator.createOFNode(1L);
165 FlowEntry entry = new FlowEntry("polTest", null, getSampleFlowV6(node),
168 // testing equal function
169 Assert.assertFalse(frmC.equals(null));
170 Assert.assertTrue(frmC.equals(frmC));
171 Assert.assertTrue(frmC.equals(frmC3));
172 Assert.assertFalse(frmC.equals(entry));
173 FlowConfig flowC = createSampleFlowConfig();
174 Assert.assertFalse(frmC.equals(flowC));
175 // testing installInHW
176 Assert.assertTrue(frmC.installInHw());
177 frmC.setInstallInHw(false);
178 Assert.assertFalse(frmC.installInHw());
179 frmC.setInstallInHw(true);
180 Assert.assertTrue(frmC.installInHw());
182 // testing general set and get methods
183 ArrayList<String> actions = createSampleActionList();
184 frmC.setActions(actions);
185 Assert.assertFalse(frmC.equals(frmC3));
186 frmC3.setActions(actions);
188 Assert.assertFalse(frmC.equals(flowC));
190 Assert.assertTrue(frmC.getCookie().equals("0"));
191 Assert.assertFalse(frmC.equals(frmC3));
192 frmC3.setCookie("0");
194 Assert.assertFalse(frmC.equals(flowC));
195 frmC.setDstMac("00:A0:C9:22:AB:11");
196 Assert.assertTrue(frmC.getDstMac().equals("00:A0:C9:22:AB:11"));
197 Assert.assertFalse(frmC.equals(frmC3));
198 frmC3.setDstMac("00:A0:C9:22:AB:11");
200 Assert.assertFalse(frmC.equals(flowC));
201 frmC.setSrcMac("00:A0:C9:14:C8:29");
202 Assert.assertTrue(frmC.getSrcMac().equals("00:A0:C9:14:C8:29"));
203 Assert.assertFalse(frmC.equals(frmC3));
204 frmC3.setSrcMac("00:A0:C9:14:C8:29");
206 Assert.assertFalse(frmC.equals(flowC));
207 frmC.setDynamic(true);
208 Assert.assertTrue(frmC.isDynamic());
209 Assert.assertFalse(frmC.equals(frmC3));
210 frmC3.setDynamic(true);
211 flowC.setDynamic(true);
213 Assert.assertFalse(frmC.equals(flowC));
214 frmC.setEtherType("0x0800");
215 Assert.assertTrue(frmC.getEtherType().equals("0x0800"));
216 Assert.assertFalse(frmC.equals(frmC3));
217 frmC3.setEtherType("0x0800");
219 Assert.assertFalse(frmC.equals(flowC));
220 frmC.setIngressPort("60");
221 Assert.assertTrue(frmC.getIngressPort().equals("60"));
222 Assert.assertFalse(frmC.equals(frmC3));
223 frmC3.setIngressPort("60");
225 Assert.assertFalse(frmC.equals(flowC));
226 frmC.setName("Config1");
227 Assert.assertTrue(frmC.getName().equals("Config1"));
228 Assert.assertFalse(frmC.equals(frmC3));
229 frmC3.setName("Config1");
231 Assert.assertFalse(frmC.equals(flowC));
232 frmC.setDstIp("2.2.2.2");
233 Assert.assertTrue(frmC.getDstIp().equals("2.2.2.2"));
234 Assert.assertFalse(frmC.equals(frmC3));
235 frmC3.setDstIp("2.2.2.2");
237 Assert.assertFalse(frmC.equals(flowC));
238 frmC.setSrcIp("1.2.3.4");
239 Assert.assertTrue(frmC.getSrcIp().equals("1.2.3.4"));
240 Assert.assertFalse(frmC.equals(frmC3));
241 frmC3.setSrcIp("1.2.3.4");
243 Assert.assertFalse(frmC.equals(flowC));
244 Assert.assertFalse(frmC.isPortGroupEnabled());
245 frmC.setPortGroup("2");
246 Assert.assertTrue(frmC.isPortGroupEnabled());
247 Assert.assertTrue(frmC.getPortGroup().equals("2"));
248 Assert.assertFalse(frmC.equals(frmC3));
249 frmC3.setPortGroup("2");
251 Assert.assertFalse(frmC.equals(flowC));
252 frmC.setPriority("100");
253 Assert.assertTrue(frmC.getPriority().equals("100"));
254 Assert.assertFalse(frmC.equals(frmC3));
255 frmC3.setPriority("100");
257 Assert.assertFalse(frmC.equals(flowC));
258 frmC.setProtocol(IPProtocols.TCP.toString());
259 Assert.assertTrue(frmC.getProtocol().equals(IPProtocols.TCP.toString()));
260 Assert.assertFalse(frmC.equals(frmC3));
261 frmC3.setProtocol(IPProtocols.TCP.toString());
263 Assert.assertFalse(frmC.equals(flowC));
264 frmC.setNode(Node.fromString(Node.NodeIDType.OPENFLOW, "1"));
265 Assert.assertTrue(frmC.getNode().equals(
266 Node.fromString(Node.NodeIDType.OPENFLOW, "1")));
267 Assert.assertFalse(frmC.equals(frmC3));
268 frmC3.setNode(Node.fromString(Node.NodeIDType.OPENFLOW, "1"));
270 Assert.assertFalse(frmC.equals(flowC));
271 frmC.setTosBits("0");
272 Assert.assertTrue(frmC.getTosBits().equals("0"));
273 Assert.assertFalse(frmC.equals(frmC3));
274 frmC3.setTosBits("0");
276 Assert.assertFalse(frmC.equals(flowC));
277 frmC.setDstPort("100");
278 Assert.assertTrue(frmC.getDstPort().equals("100"));
279 Assert.assertFalse(frmC.equals(frmC3));
280 frmC3.setDstPort("100");
282 Assert.assertFalse(frmC.equals(flowC));
283 frmC.setSrcPort("8080");
284 Assert.assertTrue(frmC.getSrcPort().equals("8080"));
285 Assert.assertFalse(frmC.equals(frmC3));
286 frmC3.setSrcPort("8080");
288 Assert.assertFalse(frmC.equals(flowC));
289 frmC.setVlanId("100");
290 Assert.assertTrue(frmC.getVlanId().equals("100"));
291 Assert.assertFalse(frmC.equals(frmC3));
292 frmC3.setVlanId("100");
294 Assert.assertFalse(frmC.equals(flowC));
295 frmC.setVlanPriority("0");
296 Assert.assertTrue(frmC.getVlanPriority().equals("0"));
297 Assert.assertFalse(frmC.equals(frmC3));
298 frmC3.setVlanPriority("0");
300 Assert.assertFalse(frmC.equals(flowC));
301 frmC.setIdleTimeout("300");
302 Assert.assertTrue(frmC.getIdleTimeout().equals("300"));
303 Assert.assertFalse(frmC.equals(frmC3));
304 frmC3.setIdleTimeout("300");
306 Assert.assertFalse(frmC.equals(flowC));
307 frmC.setHardTimeout("1000");
308 Assert.assertTrue(frmC.getHardTimeout().equals("1000"));
309 Assert.assertFalse(frmC.equals(frmC3));
310 frmC3.setHardTimeout("1000");
312 // Assert.assertFalse(frmC.equals(flowC));
313 Assert.assertTrue(actions.equals(frmC.getActions()));
315 FlowConfig frmC2 = new FlowConfig(frmC);
317 Assert.assertFalse(frmC2.equals(frmC));
318 frmC2.setDynamic(false);
319 Assert.assertFalse(frmC2.equals(frmC));
320 frmC2.setDynamic(true);
321 Assert.assertTrue(frmC2.equals(frmC));
322 // Assert.assertFalse(frmC2.equals(frmC3));
323 flowC.setDynamic(true);
324 Assert.assertTrue(flowC.equals(frmC));
325 Assert.assertTrue(flowC.isStatusSuccessful());
326 flowC.setStatus("Invalid");
327 Assert.assertFalse(flowC.isStatusSuccessful());
329 flowC.getActions().add(ActionType.DROP.toString());
330 Assert.assertFalse(flowC.equals(frmC));
331 Assert.assertFalse(flowC.isIPv6());
332 flowC.setDstIp("2001:420:281:1004:407a:57f4:4d15:c355");
333 Assert.assertTrue(flowC.isIPv6());
334 flowC.setSrcIp("2001:420:281:1004:407a:57f4:4d15:c355");
335 Assert.assertTrue(flowC.isIPv6());
337 Long id = (Long) flowC.getNode().getID();
338 Assert.assertTrue(id.toString().equals("1"));
343 public void testFlowConfigEqualities() throws UnknownHostException {
344 FlowConfig fc = new FlowConfig();
345 FlowConfig fc2 = new FlowConfig();
347 fc.setNode(Node.fromString(Node.NodeIDType.OPENFLOW, "1"));
348 Assert.assertFalse(fc.onNode(Node.fromString(Node.NodeIDType.OPENFLOW,
350 Assert.assertTrue(fc.onNode(Node.fromString(Node.NodeIDType.OPENFLOW,
353 Assert.assertTrue(fc.isByNameAndNodeIdEqual("flow1",
354 Node.fromString(Node.NodeIDType.OPENFLOW, "1")));
355 Assert.assertFalse(fc.isByNameAndNodeIdEqual("flow1",
356 Node.fromString(Node.NodeIDType.OPENFLOW, "0")));
357 Assert.assertFalse(fc.isByNameAndNodeIdEqual("flow2",
358 Node.fromString(Node.NodeIDType.OPENFLOW, "1")));
360 Assert.assertFalse(fc.isByNameAndNodeIdEqual(fc2));
361 fc2.setName("flow1");
362 Assert.assertFalse(fc.isByNameAndNodeIdEqual(fc2));
363 fc2.setNode(Node.fromString(Node.NodeIDType.OPENFLOW, "0"));
364 Assert.assertFalse(fc.isByNameAndNodeIdEqual(fc2));
365 fc2.setNode(Node.fromString(Node.NodeIDType.OPENFLOW, "1"));
366 Assert.assertTrue(fc.isByNameAndNodeIdEqual(fc2));
370 public void testStatusToggle() throws UnknownHostException {
371 FlowConfig fc = new FlowConfig();
373 Assert.assertTrue(fc.installInHw());
375 Assert.assertFalse(fc.installInHw());
377 Assert.assertTrue(fc.installInHw());
382 public void testGetFlowEntry() throws UnknownHostException {
383 FlowConfig fc2 = createSampleFlowConfig();
384 FlowEntry fe = fc2.getFlowEntry();
385 Assert.assertNotNull(fe);
389 public void testGetFlow() throws UnknownHostException {
390 FlowConfig fc = new FlowConfig();
391 fc.setActions(createSampleActionList());
392 Flow flow = fc.getFlow();
393 Assert.assertNotNull(flow);
397 public void testL2AddressValid() {
398 FlowConfig fc = new FlowConfig();
399 Assert.assertFalse(fc.isL2AddressValid(null));
400 Assert.assertFalse(fc.isL2AddressValid("11"));
401 Assert.assertFalse(fc.isL2AddressValid("00:A0:C9:14:C8:"));
402 Assert.assertFalse(fc.isL2AddressValid("000:A01:C9:14:C8:211"));
404 Assert.assertTrue(fc.isL2AddressValid("00:A0:C9:14:C8:29"));
408 public void testValid() throws UnknownHostException {
409 StringBuffer sb = new StringBuffer();
411 FlowConfig fc2 = createSampleFlowConfig();
412 Assert.assertTrue(fc2.isValid(null, sb));
414 FlowConfig fc = new FlowConfig();
415 Assert.assertFalse(fc.isValid(null, sb));
416 Assert.assertTrue(sb.toString().contains("Name is null"));
418 fc.setName("Config");
419 Assert.assertFalse(fc.isValid(null, sb));
420 Assert.assertTrue(sb.toString().contains("Node is null"));
422 fc.setNode(Node.fromString(Node.NodeIDType.OPENFLOW, "1"));
423 Assert.assertTrue(fc.isValid(null, sb));
425 fc.setPriority("-1");
426 Assert.assertFalse(fc.isValid(null, sb));
427 Assert.assertTrue(sb.toString().contains(
428 "is not in the range 0 - 65535"));
431 fc.setPriority("100000");
432 Assert.assertFalse(fc.isValid(null, sb));
433 Assert.assertTrue(sb.toString().contains(
434 "is not in the range 0 - 65535"));
436 fc.setPriority("2000");
437 Assert.assertTrue(fc.isValid(null, sb));
440 fc.setIngressPort("-1");
441 Assert.assertFalse(fc.isValid(null, sb));
442 Assert.assertTrue(sb.toString().contains("is not valid for the Switch"));
443 fc.setIngressPort("100");
444 Assert.assertTrue(fc.isValid(null, sb));
446 fc.setVlanId(("-1"));
447 Assert.assertFalse(fc.isValid(null, sb));
448 Assert.assertTrue(sb.toString()
449 .contains("is not in the range 0 - 4095"));
451 fc.setVlanId("5000");
452 Assert.assertFalse(fc.isValid(null, sb));
453 Assert.assertTrue(sb.toString()
454 .contains("is not in the range 0 - 4095"));
456 Assert.assertTrue(fc.isValid(null, sb));
457 fc.setVlanPriority("-1");
458 Assert.assertFalse(fc.isValid(null, sb));
459 Assert.assertTrue(sb.toString().contains("is not in the range 0 - 7"));
461 fc.setVlanPriority("9");
462 Assert.assertFalse(fc.isValid(null, sb));
463 Assert.assertTrue(sb.toString().contains("is not in the range 0 - 7"));
464 fc.setVlanPriority("5");
465 Assert.assertTrue(fc.isValid(null, sb));
467 fc.setEtherType("-1");
468 Assert.assertFalse(fc.isValid(null, sb));
469 Assert.assertTrue(sb.toString().contains("Ethernet type"));
471 fc.setEtherType("0xfffff");
472 Assert.assertFalse(fc.isValid(null, sb));
473 Assert.assertTrue(sb.toString().contains("Ethernet type"));
474 fc.setEtherType("0x800");
475 Assert.assertTrue(fc.isValid(null, sb));
478 Assert.assertFalse(fc.isValid(null, sb));
479 Assert.assertTrue(sb.toString().contains("IP ToS bits"));
482 Assert.assertFalse(fc.isValid(null, sb));
483 Assert.assertTrue(sb.toString().contains("IP ToS bits"));
485 Assert.assertTrue(fc.isValid(null, sb));
488 Assert.assertFalse(fc.isValid(null, sb));
489 Assert.assertTrue(sb.toString().contains("Transport source port"));
491 fc.setSrcPort("0xfffff");
492 Assert.assertFalse(fc.isValid(null, sb));
493 Assert.assertTrue(sb.toString().contains("Transport source port"));
494 fc.setSrcPort("0x00ff");
495 Assert.assertTrue(fc.isValid(null, sb));
498 Assert.assertFalse(fc.isValid(null, sb));
499 Assert.assertTrue(sb.toString().contains("Transport destination port"));
501 fc.setDstPort("0xfffff");
502 Assert.assertFalse(fc.isValid(null, sb));
503 Assert.assertTrue(sb.toString().contains("Transport destination port"));
504 fc.setDstPort("0x00ff");
505 Assert.assertTrue(fc.isValid(null, sb));
508 Assert.assertFalse(fc.isValid(null, sb));
509 Assert.assertTrue(sb.toString().contains("Ethernet source address"));
511 fc.setSrcMac("00:A0:C9:14:C8:29");
512 Assert.assertTrue(fc.isValid(null, sb));
515 Assert.assertFalse(fc.isValid(null, sb));
516 Assert.assertTrue(sb.toString()
517 .contains("Ethernet destination address"));
518 fc.setDstMac("00:A0:C9:22:AB:11");
519 Assert.assertTrue(fc.isValid(null, sb));
522 Assert.assertFalse(fc.isValid(null, sb));
523 Assert.assertTrue(sb.toString().contains("IP source address"));
524 fc.setSrcIp("2001:420:281:1004:407a:57f4:4d15:c355");
525 Assert.assertFalse(fc.isValid(null, sb));
526 Assert.assertTrue(sb.toString().contains(
527 "Type mismatch between Ethernet & Src IP"));
529 fc.setEtherType("0x86dd");
530 Assert.assertTrue(fc.isValid(null, sb));
533 fc.setSrcIp("1.1.1.1");
534 Assert.assertFalse(fc.isValid(null, sb));
535 Assert.assertTrue(sb.toString().contains(
536 "Type mismatch between Ethernet & Src IP"));
537 fc.setEtherType("0x800");
538 Assert.assertTrue(fc.isValid(null, sb));
541 Assert.assertFalse(fc.isValid(null, sb));
542 Assert.assertTrue(sb.toString().contains("IP destination address"));
543 fc.setDstIp("2001:420:281:1004:407a:57f4:4d15:c355");
544 Assert.assertFalse(fc.isValid(null, sb));
545 Assert.assertTrue(sb.toString().contains(
546 "Type mismatch between Ethernet & Dst IP"));
548 fc.setEtherType("0x86dd");
549 fc.setSrcIp("2001:420:281:1004:407a:57f4:4d15:c355");
550 Assert.assertTrue(fc.isValid(null, sb));
553 fc.setDstIp("2.2.2.2");
554 Assert.assertFalse(fc.isValid(null, sb));
555 Assert.assertTrue(sb.toString().contains(
556 "Type mismatch between Ethernet & Dst IP"));
557 fc.setEtherType("0x800");
558 fc.setSrcIp("1.1.1.1");
559 Assert.assertTrue(fc.isValid(null, sb));
561 fc.setEtherType(null);
562 fc.setSrcIp("2001:420:281:1004:407a:57f4:4d15:c355");
563 Assert.assertFalse(fc.isValid(null, sb));
564 Assert.assertTrue(sb.toString().contains("IP Src Dest Type mismatch"));
565 fc.setSrcIp("1.1.1.1");
566 fc.setIdleTimeout("-1");
567 Assert.assertFalse(fc.isValid(null, sb));
568 Assert.assertTrue(sb.toString().contains("Idle Timeout value"));
570 fc.setIdleTimeout("0xfffff");
571 Assert.assertFalse(fc.isValid(null, sb));
572 Assert.assertTrue(sb.toString().contains("Idle Timeout value"));
573 fc.setIdleTimeout("10");
574 Assert.assertTrue(fc.isValid(null, sb));
576 fc.setHardTimeout("-1");
577 Assert.assertFalse(fc.isValid(null, sb));
578 Assert.assertTrue(sb.toString().contains("Hard Timeout value"));
579 fc.setHardTimeout("0xfffff");
580 Assert.assertFalse(fc.isValid(null, sb));
581 Assert.assertTrue(sb.toString().contains("Hard Timeout value"));
582 fc.setHardTimeout("10");
583 Assert.assertTrue(fc.isValid(null, sb));
587 private FlowConfig createSampleFlowConfig() throws UnknownHostException {
588 ArrayList<String> actions;
589 actions = createSampleActionList();
590 // actions.add(ActionType.CONTROLLER.toString());
591 FlowConfig flowConfig = new FlowConfig("true", "Config1",
592 Node.fromString(Node.NodeIDType.OPENFLOW, "1"), "100", "0",
593 "60", "2", "100", "0", "0x0800", "00:A0:C9:14:C8:29",
594 "00:A0:C9:22:AB:11", IPProtocols.TCP.toString(), "0",
595 "1.2.3.4", "2.2.2.2", "8080", "100", "300", "1000", actions);
600 private ArrayList<String> createSampleActionList() {
601 ArrayList<String> actions = new ArrayList<String>();
602 actions.add(ActionType.DROP.toString());
603 actions.add(ActionType.LOOPBACK.toString());
604 actions.add(ActionType.FLOOD.toString());
605 actions.add(ActionType.SW_PATH.toString());
606 actions.add(ActionType.HW_PATH.toString());
607 actions.add(ActionType.SET_VLAN_PCP.toString() + "=1");
608 actions.add(ActionType.SET_VLAN_ID.toString() + "=1");
609 actions.add(ActionType.POP_VLAN.toString());
610 actions.add(ActionType.SET_DL_SRC.toString() + "=00:A0:C1:AB:22:11");
611 actions.add(ActionType.SET_DL_DST.toString() + "=00:B1:C1:00:AA:BB");
612 actions.add(ActionType.SET_NW_SRC.toString() + "=1.1.1.1");
613 actions.add(ActionType.SET_NW_DST.toString() + "=2.2.2.2");
614 actions.add(ActionType.CONTROLLER.toString());
615 actions.add(ActionType.SET_NW_TOS.toString() + "1");
616 actions.add(ActionType.SET_TP_SRC.toString() + "60");
617 actions.add(ActionType.SET_TP_DST.toString() + "8080");
618 actions.add(ActionType.SET_NEXT_HOP.toString() + "=1.1.1.1");
623 private Flow getSampleFlowV6(Node node) throws UnknownHostException {
624 NodeConnector port = NodeConnectorCreator.createOFNodeConnector(
626 NodeConnector oport = NodeConnectorCreator.createOFNodeConnector(
628 byte srcMac[] = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78,
629 (byte) 0x9a, (byte) 0xbc };
630 byte dstMac[] = { (byte) 0x1a, (byte) 0x2b, (byte) 0x3c, (byte) 0x4d,
631 (byte) 0x5e, (byte) 0x6f };
632 byte newMac[] = { (byte) 0x11, (byte) 0xaa, (byte) 0xbb, (byte) 0x34,
633 (byte) 0x9a, (byte) 0xee };
634 InetAddress srcIP = InetAddress
635 .getByName("2001:420:281:1004:407a:57f4:4d15:c355");
636 InetAddress dstIP = InetAddress
637 .getByName("2001:420:281:1004:e123:e688:d655:a1b0");
638 InetAddress ipMask = InetAddress
639 .getByName("ffff:ffff:ffff:ffff:0:0:0:0");
640 InetAddress ipMask2 = InetAddress
641 .getByName("ffff:ffff:ffff:ffff:ffff:ffff:ffff:0");
642 InetAddress newIP = InetAddress.getByName("2056:650::a1b0");
643 short ethertype = EtherTypes.IPv6.shortValue();
644 short vlan = (short) 27;
645 byte vlanPr = (byte) 3;
647 byte proto = IPProtocols.UDP.byteValue();
648 short src = (short) 5500;
652 * Create a SAL Flow aFlow
654 Match match = new Match();
655 match.setField(MatchType.IN_PORT, port);
656 match.setField(MatchType.DL_SRC, srcMac);
657 match.setField(MatchType.DL_DST, dstMac);
658 match.setField(MatchType.DL_TYPE, ethertype);
659 match.setField(MatchType.DL_VLAN, vlan);
660 match.setField(MatchType.DL_VLAN_PR, vlanPr);
661 match.setField(MatchType.NW_SRC, srcIP, ipMask);
662 match.setField(MatchType.NW_DST, dstIP, ipMask2);
663 match.setField(MatchType.NW_TOS, tos);
664 match.setField(MatchType.NW_PROTO, proto);
665 match.setField(MatchType.TP_SRC, src);
666 match.setField(MatchType.TP_DST, dst);
668 List<Action> actions = new ArrayList<Action>();
669 actions.add(new Controller());
670 actions.add(new SetVlanId(5));
671 actions.add(new SetDlDst(newMac));
672 actions.add(new SetNwDst(newIP));
673 actions.add(new Output(oport));
674 actions.add(new PopVlan());
675 actions.add(new Flood());
677 actions.add(new Controller());
679 Flow flow = new Flow(match, actions);
680 flow.setPriority((short) 300);
681 flow.setHardTimeout((short) 240);