3 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
5 * This program and the accompanying materials are made available under the
6 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7 * and is available at http://www.eclipse.org/legal/epl-v10.html
10 package org.opendaylight.controller.forwardingrulesmanager;
12 import java.net.InetAddress;
13 import java.net.UnknownHostException;
14 import java.util.ArrayList;
15 import java.util.HashSet;
16 import java.util.List;
19 import org.junit.Assert;
20 import org.junit.Test;
21 import org.opendaylight.controller.forwardingrulesmanager.FlowConfig;
22 import org.opendaylight.controller.forwardingrulesmanager.FlowEntry;
23 import org.opendaylight.controller.sal.action.Action;
24 import org.opendaylight.controller.sal.action.ActionType;
25 import org.opendaylight.controller.sal.action.Controller;
26 import org.opendaylight.controller.sal.action.Flood;
27 import org.opendaylight.controller.sal.action.Output;
28 import org.opendaylight.controller.sal.action.PopVlan;
29 import org.opendaylight.controller.sal.action.SetDlDst;
30 import org.opendaylight.controller.sal.action.SetNwDst;
31 import org.opendaylight.controller.sal.action.SetVlanId;
32 import org.opendaylight.controller.sal.core.Node;
33 import org.opendaylight.controller.sal.core.NodeConnector;
34 import org.opendaylight.controller.sal.flowprogrammer.Flow;
35 import org.opendaylight.controller.sal.match.Match;
36 import org.opendaylight.controller.sal.match.MatchType;
37 import org.opendaylight.controller.sal.utils.EtherTypes;
38 import org.opendaylight.controller.sal.utils.IPProtocols;
39 import org.opendaylight.controller.sal.utils.NodeConnectorCreator;
40 import org.opendaylight.controller.sal.utils.NodeCreator;
42 public class frmTest {
45 public void testFlowEntryInstall() throws UnknownHostException{
46 Node node = NodeCreator.createOFNode(1L);
47 FlowEntry pol = new FlowEntry("polTest", null, getSampleFlowV6(node),
49 FlowEntry pol2 = new FlowEntry("polTest2", null, getSampleFlowV6(node),
51 FlowEntryInstall fei = new FlowEntryInstall(pol, null);
52 FlowEntryInstall fei2 = new FlowEntryInstall(pol, null);
53 FlowEntryInstall fei3 = new FlowEntryInstall(pol2, null);
54 Assert.assertTrue(fei.getOriginal().equals(pol));
55 Assert.assertTrue(fei.getInstall().equals(pol));
56 Assert.assertTrue(fei.getFlowName().equals(pol.getFlowName()));
57 Assert.assertTrue(fei.getGroupName().equals(pol.getGroupName()));
58 Assert.assertTrue(fei.getNode().equals(pol.getNode()));
59 Assert.assertFalse(fei.isDeletePending());
61 Assert.assertTrue(fei.isDeletePending());
62 Assert.assertNull(fei.getContainerFlow());
63 Assert.assertTrue(fei.equalsByNodeAndName(pol.getNode(), pol.getFlowName()));
65 Assert.assertTrue(fei.equals(fei2));
66 fei2.getOriginal().setFlowName("polTest2");
67 Assert.assertFalse(fei.equals(null));
68 Assert.assertFalse(fei.equals(fei3));
72 public void testFlowEntryCreation() throws UnknownHostException {
73 Node node = NodeCreator.createOFNode(1L);
74 FlowEntry pol = new FlowEntry("polTest", null, getSampleFlowV6(node),
76 Assert.assertTrue(pol.getFlow().equals(getSampleFlowV6(node)));
80 public void testFlowEntrySetGet() throws UnknownHostException {
81 Node node = NodeCreator.createOFNode(1L);
82 Node node2 = NodeCreator.createOFNode(2L);
83 FlowEntry pol = new FlowEntry("polTest", null, getSampleFlowV6(node),
85 pol.setGroupName("polTest2");
86 pol.setFlowName("flowName");
87 Assert.assertTrue(pol.getFlowName().equals("flowName"));
88 Assert.assertTrue(pol.getGroupName().equals("polTest2"));
90 Assert.assertTrue(pol.getNode().equals(node2));
91 Assert.assertTrue(pol.equalsByNodeAndName(node2, "flowName"));
95 public void testFlowEntryEquality() throws UnknownHostException {
96 Node node = NodeCreator.createOFNode(1L);
97 Node node2 = NodeCreator.createOFNode(1L);
98 FlowEntry pol = new FlowEntry("polTest", null, getSampleFlowV6(node),
100 FlowEntry pol2 = new FlowEntry("polTest", null, getSampleFlowV6(node),
102 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(
260 IPProtocols.TCP.toString()));
261 Assert.assertFalse(frmC.equals(frmC3));
262 frmC3.setProtocol(IPProtocols.TCP.toString());
264 Assert.assertFalse(frmC.equals(flowC));
265 frmC.setNode(Node.fromString(Node.NodeIDType.OPENFLOW,
267 Assert.assertTrue(frmC.getNode()
268 .equals(Node.fromString(Node.NodeIDType.OPENFLOW,
270 Assert.assertFalse(frmC.equals(frmC3));
271 frmC3.setNode(Node.fromString(Node.NodeIDType.OPENFLOW,
274 Assert.assertFalse(frmC.equals(flowC));
275 frmC.setTosBits("0");
276 Assert.assertTrue(frmC.getTosBits().equals("0"));
277 Assert.assertFalse(frmC.equals(frmC3));
278 frmC3.setTosBits("0");
280 Assert.assertFalse(frmC.equals(flowC));
281 frmC.setDstPort("100");
282 Assert.assertTrue(frmC.getDstPort().equals("100"));
283 Assert.assertFalse(frmC.equals(frmC3));
284 frmC3.setDstPort("100");
286 Assert.assertFalse(frmC.equals(flowC));
287 frmC.setSrcPort("8080");
288 Assert.assertTrue(frmC.getSrcPort().equals("8080"));
289 Assert.assertFalse(frmC.equals(frmC3));
290 frmC3.setSrcPort("8080");
292 Assert.assertFalse(frmC.equals(flowC));
293 frmC.setVlanId("100");
294 Assert.assertTrue(frmC.getVlanId().equals("100"));
295 Assert.assertFalse(frmC.equals(frmC3));
296 frmC3.setVlanId("100");
298 Assert.assertFalse(frmC.equals(flowC));
299 frmC.setVlanPriority("0");
300 Assert.assertTrue(frmC.getVlanPriority().equals("0"));
301 Assert.assertFalse(frmC.equals(frmC3));
302 frmC3.setVlanPriority("0");
304 Assert.assertFalse(frmC.equals(flowC));
305 frmC.setIdleTimeout("300");
306 Assert.assertTrue(frmC.getIdleTimeout().equals("300"));
307 Assert.assertFalse(frmC.equals(frmC3));
308 frmC3.setIdleTimeout("300");
310 Assert.assertFalse(frmC.equals(flowC));
311 frmC.setHardTimeout("1000");
312 Assert.assertTrue(frmC.getHardTimeout().equals("1000"));
313 Assert.assertFalse(frmC.equals(frmC3));
314 frmC3.setHardTimeout("1000");
316 // Assert.assertFalse(frmC.equals(flowC));
317 Assert.assertTrue(actions.equals(frmC.getActions()));
319 FlowConfig frmC2 = new FlowConfig(frmC);
321 Assert.assertFalse(frmC2.equals(frmC));
322 frmC2.setDynamic(false);
323 Assert.assertFalse(frmC2.equals(frmC));
324 frmC2.setDynamic(true);
325 Assert.assertTrue(frmC2.equals(frmC));
326 //Assert.assertFalse(frmC2.equals(frmC3));
327 flowC.setDynamic(true);
328 Assert.assertTrue(flowC.equals(frmC));
329 Assert.assertTrue(flowC.isStatusSuccessful());
330 flowC.setStatus("Invalid");
331 Assert.assertFalse(flowC.isStatusSuccessful());
333 flowC.getActions().add(ActionType.DROP.toString());
334 Assert.assertFalse(flowC.equals(frmC));
335 Assert.assertFalse(flowC.isIPv6());
336 flowC.setDstIp("2001:420:281:1004:407a:57f4:4d15:c355");
337 Assert.assertTrue(flowC.isIPv6());
338 flowC.setSrcIp("2001:420:281:1004:407a:57f4:4d15:c355");
339 Assert.assertTrue(flowC.isIPv6());
341 Long id = (Long) flowC.getNode().getID();
342 Assert.assertTrue(id.toString().equals("1"));
347 public void testFlowConfigNextHopValidity() throws UnknownHostException{
348 FlowConfig fc = new FlowConfig();
349 Assert.assertFalse(fc.isOutputNextHopValid(null));
350 Assert.assertFalse(fc.isOutputNextHopValid("abc"));
351 Assert.assertFalse(fc.isOutputNextHopValid("1.1.1"));
352 Assert.assertFalse(fc.isOutputNextHopValid("1.1.1.1/49"));
354 Assert.assertTrue(fc.isOutputNextHopValid("1.1.1.1"));
355 Assert.assertTrue(fc.isOutputNextHopValid("1.1.1.1/32"));
356 Assert.assertTrue(fc.isOutputNextHopValid("2001:420:281:1004:407a:57f4:4d15:c355"));
361 public void testFlowConfigEqualities() throws UnknownHostException{
362 FlowConfig fc = new FlowConfig();
363 FlowConfig fc2 = new FlowConfig();
365 fc.setNode(Node.fromString(Node.NodeIDType.OPENFLOW,
367 Assert.assertFalse(fc.onNode(Node.fromString(Node.NodeIDType.OPENFLOW,
369 Assert.assertTrue(fc.onNode(Node.fromString(Node.NodeIDType.OPENFLOW,
372 Assert.assertTrue(fc.isByNameAndNodeIdEqual(
374 Node.fromString(Node.NodeIDType.OPENFLOW, "1")));
375 Assert.assertFalse(fc.isByNameAndNodeIdEqual(
377 Node.fromString(Node.NodeIDType.OPENFLOW, "0")));
378 Assert.assertFalse(fc.isByNameAndNodeIdEqual(
380 Node.fromString(Node.NodeIDType.OPENFLOW, "1")));
382 Assert.assertFalse(fc.isByNameAndNodeIdEqual(fc2));
383 fc2.setName("flow1");
384 Assert.assertFalse(fc.isByNameAndNodeIdEqual(fc2));
385 fc2.setNode(Node.fromString(Node.NodeIDType.OPENFLOW,
387 Assert.assertFalse(fc.isByNameAndNodeIdEqual(fc2));
388 fc2.setNode(Node.fromString(Node.NodeIDType.OPENFLOW,
390 Assert.assertTrue(fc.isByNameAndNodeIdEqual(fc2));
394 public void testStatusToggle() throws UnknownHostException{
395 FlowConfig fc = new FlowConfig();
397 Assert.assertTrue(fc.installInHw());
399 Assert.assertFalse(fc.installInHw());
401 Assert.assertTrue(fc.installInHw());
405 public void testGetFlowEntry() throws UnknownHostException {
406 FlowConfig fc2 = createSampleFlowConfig();
407 FlowEntry fe = fc2.getFlowEntry();
408 Assert.assertNotNull(fe);
412 public void testGetFlow() throws UnknownHostException {
413 FlowConfig fc = new FlowConfig();
414 fc.setActions(createSampleActionList());
415 Flow flow = fc.getFlow();
416 Assert.assertNotNull(flow);
420 public void testL2AddressValid() {
421 FlowConfig fc = new FlowConfig();
422 Assert.assertFalse(fc.isL2AddressValid(null));
423 Assert.assertFalse(fc.isL2AddressValid("11"));
424 Assert.assertFalse(fc.isL2AddressValid("00:A0:C9:14:C8:"));
425 Assert.assertFalse(fc.isL2AddressValid("000:A01:C9:14:C8:211"));
427 Assert.assertTrue(fc.isL2AddressValid("00:A0:C9:14:C8:29"));
431 public void testValid() throws UnknownHostException {
432 StringBuffer sb = new StringBuffer();
434 FlowConfig fc2 = createSampleFlowConfig();
435 Assert.assertTrue(fc2.isValid(null, sb));
437 FlowConfig fc = new FlowConfig();
438 Assert.assertFalse(fc.isValid(null, sb));
439 Assert.assertTrue(sb.toString().contains("Name is null"));
441 fc.setName("Config");
442 Assert.assertFalse(fc.isValid(null, sb));
443 Assert.assertTrue(sb.toString().contains("Node is null"));
445 fc.setNode(Node.fromString(Node.NodeIDType.OPENFLOW,
447 Assert.assertTrue(fc.isValid(null, sb));
449 fc.setPriority("-1");
450 Assert.assertFalse(fc.isValid(null, sb));
451 Assert.assertTrue(sb.toString().contains(
452 "is not in the range 0 - 65535"));
455 fc.setPriority("100000");
456 Assert.assertFalse(fc.isValid(null, sb));
457 Assert.assertTrue(sb.toString().contains(
458 "is not in the range 0 - 65535"));
460 fc.setPriority("2000");
461 Assert.assertTrue(fc.isValid(null, sb));
464 fc.setIngressPort("-1");
465 Assert.assertFalse(fc.isValid(null, sb));
467 .assertTrue(sb.toString().contains(
468 "is not valid for the Switch"));
469 fc.setIngressPort("100");
470 Assert.assertTrue(fc.isValid(null, sb));
472 fc.setVlanId(("-1"));
473 Assert.assertFalse(fc.isValid(null, sb));
474 Assert.assertTrue(sb.toString()
475 .contains("is not in the range 0 - 4095"));
477 fc.setVlanId("5000");
478 Assert.assertFalse(fc.isValid(null, sb));
479 Assert.assertTrue(sb.toString()
480 .contains("is not in the range 0 - 4095"));
482 Assert.assertTrue(fc.isValid(null, sb));
483 fc.setVlanPriority("-1");
484 Assert.assertFalse(fc.isValid(null, sb));
485 Assert.assertTrue(sb.toString().contains("is not in the range 0 - 7"));
487 fc.setVlanPriority("9");
488 Assert.assertFalse(fc.isValid(null, sb));
489 Assert.assertTrue(sb.toString().contains("is not in the range 0 - 7"));
490 fc.setVlanPriority("5");
491 Assert.assertTrue(fc.isValid(null, sb));
493 fc.setEtherType("-1");
494 Assert.assertFalse(fc.isValid(null, sb));
495 Assert.assertTrue(sb.toString().contains("Ethernet type"));
497 fc.setEtherType("0xfffff");
498 Assert.assertFalse(fc.isValid(null, sb));
499 Assert.assertTrue(sb.toString().contains("Ethernet type"));
500 fc.setEtherType("0x800");
501 Assert.assertTrue(fc.isValid(null, sb));
504 Assert.assertFalse(fc.isValid(null, sb));
505 Assert.assertTrue(sb.toString().contains("IP ToS bits"));
508 Assert.assertFalse(fc.isValid(null, sb));
509 Assert.assertTrue(sb.toString().contains("IP ToS bits"));
511 Assert.assertTrue(fc.isValid(null, sb));
514 Assert.assertFalse(fc.isValid(null, sb));
515 Assert.assertTrue(sb.toString().contains("Transport source port"));
517 fc.setSrcPort("0xfffff");
518 Assert.assertFalse(fc.isValid(null, sb));
519 Assert.assertTrue(sb.toString().contains("Transport source port"));
520 fc.setSrcPort("0x00ff");
521 Assert.assertTrue(fc.isValid(null, sb));
524 Assert.assertFalse(fc.isValid(null, sb));
525 Assert.assertTrue(sb.toString().contains("Transport destination port"));
527 fc.setDstPort("0xfffff");
528 Assert.assertFalse(fc.isValid(null, sb));
529 Assert.assertTrue(sb.toString().contains("Transport destination port"));
530 fc.setDstPort("0x00ff");
531 Assert.assertTrue(fc.isValid(null, sb));
534 Assert.assertFalse(fc.isValid(null, sb));
535 Assert.assertTrue(sb.toString().contains("Ethernet source address"));
537 fc.setSrcMac("00:A0:C9:14:C8:29");
538 Assert.assertTrue(fc.isValid(null, sb));
541 Assert.assertFalse(fc.isValid(null, sb));
542 Assert.assertTrue(sb.toString()
543 .contains("Ethernet destination address"));
544 fc.setDstMac("00:A0:C9:22:AB:11");
545 Assert.assertTrue(fc.isValid(null, sb));
548 Assert.assertFalse(fc.isValid(null, sb));
549 Assert.assertTrue(sb.toString().contains("IP source address"));
550 fc.setSrcIp("2001:420:281:1004:407a:57f4:4d15:c355");
551 Assert.assertFalse(fc.isValid(null, sb));
552 Assert.assertTrue(sb.toString().contains(
553 "Type mismatch between Ethernet & Src IP"));
555 fc.setEtherType("0x86dd");
556 Assert.assertTrue(fc.isValid(null, sb));
559 fc.setSrcIp("1.1.1.1");
560 Assert.assertFalse(fc.isValid(null, sb));
561 Assert.assertTrue(sb.toString().contains(
562 "Type mismatch between Ethernet & Src IP"));
563 fc.setEtherType("0x800");
564 Assert.assertTrue(fc.isValid(null, sb));
567 Assert.assertFalse(fc.isValid(null, sb));
568 Assert.assertTrue(sb.toString().contains("IP destination address"));
569 fc.setDstIp("2001:420:281:1004:407a:57f4:4d15:c355");
570 Assert.assertFalse(fc.isValid(null, sb));
571 Assert.assertTrue(sb.toString().contains(
572 "Type mismatch between Ethernet & Dst IP"));
574 fc.setEtherType("0x86dd");
575 fc.setSrcIp("2001:420:281:1004:407a:57f4:4d15:c355");
576 Assert.assertTrue(fc.isValid(null, sb));
579 fc.setDstIp("2.2.2.2");
580 Assert.assertFalse(fc.isValid(null, sb));
581 Assert.assertTrue(sb.toString().contains(
582 "Type mismatch between Ethernet & Dst IP"));
583 fc.setEtherType("0x800");
584 fc.setSrcIp("1.1.1.1");
585 Assert.assertTrue(fc.isValid(null, sb));
587 fc.setEtherType(null);
588 fc.setSrcIp("2001:420:281:1004:407a:57f4:4d15:c355");
589 Assert.assertFalse(fc.isValid(null, sb));
590 Assert.assertTrue(sb.toString().contains("IP Src Dest Type mismatch"));
591 fc.setSrcIp("1.1.1.1");
592 fc.setIdleTimeout("-1");
593 Assert.assertFalse(fc.isValid(null, sb));
594 Assert.assertTrue(sb.toString().contains("Idle Timeout value"));
596 fc.setIdleTimeout("0xfffff");
597 Assert.assertFalse(fc.isValid(null, sb));
598 Assert.assertTrue(sb.toString().contains("Idle Timeout value"));
599 fc.setIdleTimeout("10");
600 Assert.assertTrue(fc.isValid(null, sb));
602 fc.setHardTimeout("-1");
603 Assert.assertFalse(fc.isValid(null, sb));
604 Assert.assertTrue(sb.toString().contains("Hard Timeout value"));
605 fc.setHardTimeout("0xfffff");
606 Assert.assertFalse(fc.isValid(null, sb));
607 Assert.assertTrue(sb.toString().contains("Hard Timeout value"));
608 fc.setHardTimeout("10");
609 Assert.assertTrue(fc.isValid(null, sb));
613 private FlowConfig createSampleFlowConfig() throws UnknownHostException {
614 ArrayList<String> actions;
615 actions = createSampleActionList();
616 //actions.add(ActionType.CONTROLLER.toString());
617 FlowConfig flowConfig =
618 new FlowConfig("true", "Config1",
619 Node.fromString(Node.NodeIDType.OPENFLOW,
620 "1"), "100", "0", "60", "2", "100",
621 "0", "0x0800", "00:A0:C9:14:C8:29",
622 "00:A0:C9:22:AB:11", IPProtocols.TCP.toString(), "0",
623 "1.2.3.4", "2.2.2.2", "8080", "100", "300", "1000",
629 private ArrayList<String> createSampleActionList() {
630 ArrayList<String> actions = new ArrayList<String>();
631 actions.add(ActionType.DROP.toString());
632 actions.add(ActionType.LOOPBACK.toString());
633 actions.add(ActionType.FLOOD.toString());
634 actions.add(ActionType.SW_PATH.toString());
635 actions.add(ActionType.HW_PATH.toString());
636 actions.add(ActionType.SET_VLAN_PCP.toString()+"=1");
637 actions.add(ActionType.SET_VLAN_ID.toString()+"=1");
638 actions.add(ActionType.POP_VLAN.toString());
639 actions.add(ActionType.SET_DL_SRC.toString()+"=00:A0:C1:AB:22:11");
640 actions.add(ActionType.SET_DL_DST.toString()+"=00:B1:C1:00:AA:BB");
641 actions.add(ActionType.SET_NW_SRC.toString()+"=1.1.1.1");
642 actions.add(ActionType.SET_NW_DST.toString()+"=2.2.2.2");
643 actions.add(ActionType.CONTROLLER.toString());
644 actions.add(ActionType.SET_NW_TOS.toString()+"1");
645 actions.add(ActionType.SET_TP_SRC.toString()+"60");
646 actions.add(ActionType.SET_TP_DST.toString()+"8080");
647 actions.add(ActionType.SET_NEXT_HOP.toString()+"=1.1.1.1");
652 private Flow getSampleFlowV6(Node node) throws UnknownHostException {
653 NodeConnector port = NodeConnectorCreator.createOFNodeConnector(
655 NodeConnector oport = NodeConnectorCreator.createOFNodeConnector(
657 byte srcMac[] = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78,
658 (byte) 0x9a, (byte) 0xbc };
659 byte dstMac[] = { (byte) 0x1a, (byte) 0x2b, (byte) 0x3c, (byte) 0x4d,
660 (byte) 0x5e, (byte) 0x6f };
661 byte newMac[] = { (byte) 0x11, (byte) 0xaa, (byte) 0xbb, (byte) 0x34,
662 (byte) 0x9a, (byte) 0xee };
663 InetAddress srcIP = InetAddress
664 .getByName("2001:420:281:1004:407a:57f4:4d15:c355");
665 InetAddress dstIP = InetAddress
666 .getByName("2001:420:281:1004:e123:e688:d655:a1b0");
667 InetAddress ipMask = InetAddress
668 .getByName("ffff:ffff:ffff:ffff:0:0:0:0");
669 InetAddress ipMask2 = InetAddress
670 .getByName("ffff:ffff:ffff:ffff:ffff:ffff:ffff:0");
671 InetAddress newIP = InetAddress.getByName("2056:650::a1b0");
672 short ethertype = EtherTypes.IPv6.shortValue();
673 short vlan = (short) 27;
674 byte vlanPr = (byte) 3;
676 byte proto = IPProtocols.UDP.byteValue();
677 short src = (short) 5500;
681 * Create a SAL Flow aFlow
683 Match match = new Match();
684 match.setField(MatchType.IN_PORT, port);
685 match.setField(MatchType.DL_SRC, srcMac);
686 match.setField(MatchType.DL_DST, dstMac);
687 match.setField(MatchType.DL_TYPE, ethertype);
688 match.setField(MatchType.DL_VLAN, vlan);
689 match.setField(MatchType.DL_VLAN_PR, vlanPr);
690 match.setField(MatchType.NW_SRC, srcIP, ipMask);
691 match.setField(MatchType.NW_DST, dstIP, ipMask2);
692 match.setField(MatchType.NW_TOS, tos);
693 match.setField(MatchType.NW_PROTO, proto);
694 match.setField(MatchType.TP_SRC, src);
695 match.setField(MatchType.TP_DST, dst);
697 List<Action> actions = new ArrayList<Action>();
698 actions.add(new Controller());
699 actions.add(new SetVlanId(5));
700 actions.add(new SetDlDst(newMac));
701 actions.add(new SetNwDst(newIP));
702 actions.add(new Output(oport));
703 actions.add(new PopVlan());
704 actions.add(new Flood());
706 actions.add(new Controller());
708 Flow flow = new Flow(match, actions);
709 flow.setPriority((short) 300);
710 flow.setHardTimeout((short) 240);