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 testFlowConfigNextHopValidity() throws UnknownHostException {
344 FlowConfig fc = new FlowConfig();
345 Assert.assertFalse(fc.isOutputNextHopValid(null));
346 Assert.assertFalse(fc.isOutputNextHopValid("abc"));
347 Assert.assertFalse(fc.isOutputNextHopValid("1.1.1"));
348 Assert.assertFalse(fc.isOutputNextHopValid("1.1.1.1/49"));
350 Assert.assertTrue(fc.isOutputNextHopValid("1.1.1.1"));
351 Assert.assertTrue(fc.isOutputNextHopValid("1.1.1.1/32"));
353 .isOutputNextHopValid("2001:420:281:1004:407a:57f4:4d15:c355"));
358 public void testFlowConfigEqualities() throws UnknownHostException {
359 FlowConfig fc = new FlowConfig();
360 FlowConfig fc2 = new FlowConfig();
362 fc.setNode(Node.fromString(Node.NodeIDType.OPENFLOW, "1"));
363 Assert.assertFalse(fc.onNode(Node.fromString(Node.NodeIDType.OPENFLOW,
365 Assert.assertTrue(fc.onNode(Node.fromString(Node.NodeIDType.OPENFLOW,
368 Assert.assertTrue(fc.isByNameAndNodeIdEqual("flow1",
369 Node.fromString(Node.NodeIDType.OPENFLOW, "1")));
370 Assert.assertFalse(fc.isByNameAndNodeIdEqual("flow1",
371 Node.fromString(Node.NodeIDType.OPENFLOW, "0")));
372 Assert.assertFalse(fc.isByNameAndNodeIdEqual("flow2",
373 Node.fromString(Node.NodeIDType.OPENFLOW, "1")));
375 Assert.assertFalse(fc.isByNameAndNodeIdEqual(fc2));
376 fc2.setName("flow1");
377 Assert.assertFalse(fc.isByNameAndNodeIdEqual(fc2));
378 fc2.setNode(Node.fromString(Node.NodeIDType.OPENFLOW, "0"));
379 Assert.assertFalse(fc.isByNameAndNodeIdEqual(fc2));
380 fc2.setNode(Node.fromString(Node.NodeIDType.OPENFLOW, "1"));
381 Assert.assertTrue(fc.isByNameAndNodeIdEqual(fc2));
385 public void testStatusToggle() throws UnknownHostException {
386 FlowConfig fc = new FlowConfig();
388 Assert.assertTrue(fc.installInHw());
390 Assert.assertFalse(fc.installInHw());
392 Assert.assertTrue(fc.installInHw());
397 public void testGetFlowEntry() throws UnknownHostException {
398 FlowConfig fc2 = createSampleFlowConfig();
399 FlowEntry fe = fc2.getFlowEntry();
400 Assert.assertNotNull(fe);
404 public void testGetFlow() throws UnknownHostException {
405 FlowConfig fc = new FlowConfig();
406 fc.setActions(createSampleActionList());
407 Flow flow = fc.getFlow();
408 Assert.assertNotNull(flow);
412 public void testL2AddressValid() {
413 FlowConfig fc = new FlowConfig();
414 Assert.assertFalse(fc.isL2AddressValid(null));
415 Assert.assertFalse(fc.isL2AddressValid("11"));
416 Assert.assertFalse(fc.isL2AddressValid("00:A0:C9:14:C8:"));
417 Assert.assertFalse(fc.isL2AddressValid("000:A01:C9:14:C8:211"));
419 Assert.assertTrue(fc.isL2AddressValid("00:A0:C9:14:C8:29"));
423 public void testValid() throws UnknownHostException {
424 StringBuffer sb = new StringBuffer();
426 FlowConfig fc2 = createSampleFlowConfig();
427 Assert.assertTrue(fc2.isValid(null, sb));
429 FlowConfig fc = new FlowConfig();
430 Assert.assertFalse(fc.isValid(null, sb));
431 Assert.assertTrue(sb.toString().contains("Name is null"));
433 fc.setName("Config");
434 Assert.assertFalse(fc.isValid(null, sb));
435 Assert.assertTrue(sb.toString().contains("Node is null"));
437 fc.setNode(Node.fromString(Node.NodeIDType.OPENFLOW, "1"));
438 Assert.assertTrue(fc.isValid(null, sb));
440 fc.setPriority("-1");
441 Assert.assertFalse(fc.isValid(null, sb));
442 Assert.assertTrue(sb.toString().contains(
443 "is not in the range 0 - 65535"));
446 fc.setPriority("100000");
447 Assert.assertFalse(fc.isValid(null, sb));
448 Assert.assertTrue(sb.toString().contains(
449 "is not in the range 0 - 65535"));
451 fc.setPriority("2000");
452 Assert.assertTrue(fc.isValid(null, sb));
455 fc.setIngressPort("-1");
456 Assert.assertFalse(fc.isValid(null, sb));
457 Assert.assertTrue(sb.toString().contains("is not valid for the Switch"));
458 fc.setIngressPort("100");
459 Assert.assertTrue(fc.isValid(null, sb));
461 fc.setVlanId(("-1"));
462 Assert.assertFalse(fc.isValid(null, sb));
463 Assert.assertTrue(sb.toString()
464 .contains("is not in the range 0 - 4095"));
466 fc.setVlanId("5000");
467 Assert.assertFalse(fc.isValid(null, sb));
468 Assert.assertTrue(sb.toString()
469 .contains("is not in the range 0 - 4095"));
471 Assert.assertTrue(fc.isValid(null, sb));
472 fc.setVlanPriority("-1");
473 Assert.assertFalse(fc.isValid(null, sb));
474 Assert.assertTrue(sb.toString().contains("is not in the range 0 - 7"));
476 fc.setVlanPriority("9");
477 Assert.assertFalse(fc.isValid(null, sb));
478 Assert.assertTrue(sb.toString().contains("is not in the range 0 - 7"));
479 fc.setVlanPriority("5");
480 Assert.assertTrue(fc.isValid(null, sb));
482 fc.setEtherType("-1");
483 Assert.assertFalse(fc.isValid(null, sb));
484 Assert.assertTrue(sb.toString().contains("Ethernet type"));
486 fc.setEtherType("0xfffff");
487 Assert.assertFalse(fc.isValid(null, sb));
488 Assert.assertTrue(sb.toString().contains("Ethernet type"));
489 fc.setEtherType("0x800");
490 Assert.assertTrue(fc.isValid(null, sb));
493 Assert.assertFalse(fc.isValid(null, sb));
494 Assert.assertTrue(sb.toString().contains("IP ToS bits"));
497 Assert.assertFalse(fc.isValid(null, sb));
498 Assert.assertTrue(sb.toString().contains("IP ToS bits"));
500 Assert.assertTrue(fc.isValid(null, sb));
503 Assert.assertFalse(fc.isValid(null, sb));
504 Assert.assertTrue(sb.toString().contains("Transport source port"));
506 fc.setSrcPort("0xfffff");
507 Assert.assertFalse(fc.isValid(null, sb));
508 Assert.assertTrue(sb.toString().contains("Transport source port"));
509 fc.setSrcPort("0x00ff");
510 Assert.assertTrue(fc.isValid(null, sb));
513 Assert.assertFalse(fc.isValid(null, sb));
514 Assert.assertTrue(sb.toString().contains("Transport destination port"));
516 fc.setDstPort("0xfffff");
517 Assert.assertFalse(fc.isValid(null, sb));
518 Assert.assertTrue(sb.toString().contains("Transport destination port"));
519 fc.setDstPort("0x00ff");
520 Assert.assertTrue(fc.isValid(null, sb));
523 Assert.assertFalse(fc.isValid(null, sb));
524 Assert.assertTrue(sb.toString().contains("Ethernet source address"));
526 fc.setSrcMac("00:A0:C9:14:C8:29");
527 Assert.assertTrue(fc.isValid(null, sb));
530 Assert.assertFalse(fc.isValid(null, sb));
531 Assert.assertTrue(sb.toString()
532 .contains("Ethernet destination address"));
533 fc.setDstMac("00:A0:C9:22:AB:11");
534 Assert.assertTrue(fc.isValid(null, sb));
537 Assert.assertFalse(fc.isValid(null, sb));
538 Assert.assertTrue(sb.toString().contains("IP source address"));
539 fc.setSrcIp("2001:420:281:1004:407a:57f4:4d15:c355");
540 Assert.assertFalse(fc.isValid(null, sb));
541 Assert.assertTrue(sb.toString().contains(
542 "Type mismatch between Ethernet & Src IP"));
544 fc.setEtherType("0x86dd");
545 Assert.assertTrue(fc.isValid(null, sb));
548 fc.setSrcIp("1.1.1.1");
549 Assert.assertFalse(fc.isValid(null, sb));
550 Assert.assertTrue(sb.toString().contains(
551 "Type mismatch between Ethernet & Src IP"));
552 fc.setEtherType("0x800");
553 Assert.assertTrue(fc.isValid(null, sb));
556 Assert.assertFalse(fc.isValid(null, sb));
557 Assert.assertTrue(sb.toString().contains("IP destination address"));
558 fc.setDstIp("2001:420:281:1004:407a:57f4:4d15:c355");
559 Assert.assertFalse(fc.isValid(null, sb));
560 Assert.assertTrue(sb.toString().contains(
561 "Type mismatch between Ethernet & Dst IP"));
563 fc.setEtherType("0x86dd");
564 fc.setSrcIp("2001:420:281:1004:407a:57f4:4d15:c355");
565 Assert.assertTrue(fc.isValid(null, sb));
568 fc.setDstIp("2.2.2.2");
569 Assert.assertFalse(fc.isValid(null, sb));
570 Assert.assertTrue(sb.toString().contains(
571 "Type mismatch between Ethernet & Dst IP"));
572 fc.setEtherType("0x800");
573 fc.setSrcIp("1.1.1.1");
574 Assert.assertTrue(fc.isValid(null, sb));
576 fc.setEtherType(null);
577 fc.setSrcIp("2001:420:281:1004:407a:57f4:4d15:c355");
578 Assert.assertFalse(fc.isValid(null, sb));
579 Assert.assertTrue(sb.toString().contains("IP Src Dest Type mismatch"));
580 fc.setSrcIp("1.1.1.1");
581 fc.setIdleTimeout("-1");
582 Assert.assertFalse(fc.isValid(null, sb));
583 Assert.assertTrue(sb.toString().contains("Idle Timeout value"));
585 fc.setIdleTimeout("0xfffff");
586 Assert.assertFalse(fc.isValid(null, sb));
587 Assert.assertTrue(sb.toString().contains("Idle Timeout value"));
588 fc.setIdleTimeout("10");
589 Assert.assertTrue(fc.isValid(null, sb));
591 fc.setHardTimeout("-1");
592 Assert.assertFalse(fc.isValid(null, sb));
593 Assert.assertTrue(sb.toString().contains("Hard Timeout value"));
594 fc.setHardTimeout("0xfffff");
595 Assert.assertFalse(fc.isValid(null, sb));
596 Assert.assertTrue(sb.toString().contains("Hard Timeout value"));
597 fc.setHardTimeout("10");
598 Assert.assertTrue(fc.isValid(null, sb));
602 private FlowConfig createSampleFlowConfig() throws UnknownHostException {
603 ArrayList<String> actions;
604 actions = createSampleActionList();
605 // actions.add(ActionType.CONTROLLER.toString());
606 FlowConfig flowConfig = new FlowConfig("true", "Config1",
607 Node.fromString(Node.NodeIDType.OPENFLOW, "1"), "100", "0",
608 "60", "2", "100", "0", "0x0800", "00:A0:C9:14:C8:29",
609 "00:A0:C9:22:AB:11", IPProtocols.TCP.toString(), "0",
610 "1.2.3.4", "2.2.2.2", "8080", "100", "300", "1000", actions);
615 private ArrayList<String> createSampleActionList() {
616 ArrayList<String> actions = new ArrayList<String>();
617 actions.add(ActionType.DROP.toString());
618 actions.add(ActionType.LOOPBACK.toString());
619 actions.add(ActionType.FLOOD.toString());
620 actions.add(ActionType.SW_PATH.toString());
621 actions.add(ActionType.HW_PATH.toString());
622 actions.add(ActionType.SET_VLAN_PCP.toString() + "=1");
623 actions.add(ActionType.SET_VLAN_ID.toString() + "=1");
624 actions.add(ActionType.POP_VLAN.toString());
625 actions.add(ActionType.SET_DL_SRC.toString() + "=00:A0:C1:AB:22:11");
626 actions.add(ActionType.SET_DL_DST.toString() + "=00:B1:C1:00:AA:BB");
627 actions.add(ActionType.SET_NW_SRC.toString() + "=1.1.1.1");
628 actions.add(ActionType.SET_NW_DST.toString() + "=2.2.2.2");
629 actions.add(ActionType.CONTROLLER.toString());
630 actions.add(ActionType.SET_NW_TOS.toString() + "1");
631 actions.add(ActionType.SET_TP_SRC.toString() + "60");
632 actions.add(ActionType.SET_TP_DST.toString() + "8080");
633 actions.add(ActionType.SET_NEXT_HOP.toString() + "=1.1.1.1");
638 private Flow getSampleFlowV6(Node node) throws UnknownHostException {
639 NodeConnector port = NodeConnectorCreator.createOFNodeConnector(
641 NodeConnector oport = NodeConnectorCreator.createOFNodeConnector(
643 byte srcMac[] = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78,
644 (byte) 0x9a, (byte) 0xbc };
645 byte dstMac[] = { (byte) 0x1a, (byte) 0x2b, (byte) 0x3c, (byte) 0x4d,
646 (byte) 0x5e, (byte) 0x6f };
647 byte newMac[] = { (byte) 0x11, (byte) 0xaa, (byte) 0xbb, (byte) 0x34,
648 (byte) 0x9a, (byte) 0xee };
649 InetAddress srcIP = InetAddress
650 .getByName("2001:420:281:1004:407a:57f4:4d15:c355");
651 InetAddress dstIP = InetAddress
652 .getByName("2001:420:281:1004:e123:e688:d655:a1b0");
653 InetAddress ipMask = InetAddress
654 .getByName("ffff:ffff:ffff:ffff:0:0:0:0");
655 InetAddress ipMask2 = InetAddress
656 .getByName("ffff:ffff:ffff:ffff:ffff:ffff:ffff:0");
657 InetAddress newIP = InetAddress.getByName("2056:650::a1b0");
658 short ethertype = EtherTypes.IPv6.shortValue();
659 short vlan = (short) 27;
660 byte vlanPr = (byte) 3;
662 byte proto = IPProtocols.UDP.byteValue();
663 short src = (short) 5500;
667 * Create a SAL Flow aFlow
669 Match match = new Match();
670 match.setField(MatchType.IN_PORT, port);
671 match.setField(MatchType.DL_SRC, srcMac);
672 match.setField(MatchType.DL_DST, dstMac);
673 match.setField(MatchType.DL_TYPE, ethertype);
674 match.setField(MatchType.DL_VLAN, vlan);
675 match.setField(MatchType.DL_VLAN_PR, vlanPr);
676 match.setField(MatchType.NW_SRC, srcIP, ipMask);
677 match.setField(MatchType.NW_DST, dstIP, ipMask2);
678 match.setField(MatchType.NW_TOS, tos);
679 match.setField(MatchType.NW_PROTO, proto);
680 match.setField(MatchType.TP_SRC, src);
681 match.setField(MatchType.TP_DST, dst);
683 List<Action> actions = new ArrayList<Action>();
684 actions.add(new Controller());
685 actions.add(new SetVlanId(5));
686 actions.add(new SetDlDst(newMac));
687 actions.add(new SetNwDst(newIP));
688 actions.add(new Output(oport));
689 actions.add(new PopVlan());
690 actions.add(new Flood());
692 actions.add(new Controller());
694 Flow flow = new Flow(match, actions);
695 flow.setPriority((short) 300);
696 flow.setHardTimeout((short) 240);