1 package org.opendaylight.openflowplugin.openflow.md.util;
3 import org.junit.AfterClass;
4 import org.junit.Assert;
5 import org.junit.BeforeClass;
7 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.OutputPortValues;
9 import java.util.HashMap;
13 * @author: Kamal Rameshan (kramesha@cisco.com)
16 public class OpenflowPortsUtilTest {
17 private static Map<String, Long> mapOF10Ports;
18 private static Map<String, Long> mapOF13Ports;
19 private static Map<OpenflowVersion, Map<String, Long>> mapVersionToPorts;
22 public static void setupClass() {
23 OpenflowPortsUtil.init();
25 mapOF10Ports = new HashMap<String, Long>();
26 mapOF10Ports.put(OutputPortValues.MAX.toString(), 65280L);
27 mapOF10Ports.put(OutputPortValues.INPORT.toString(), 65528L);
28 mapOF10Ports.put(OutputPortValues.TABLE.toString(), 65529L);
29 mapOF10Ports.put(OutputPortValues.NORMAL.toString(), 65530L);
30 mapOF10Ports.put(OutputPortValues.FLOOD.toString(), 65531L);
31 mapOF10Ports.put(OutputPortValues.ALL.toString(), 65532L);
32 mapOF10Ports.put(OutputPortValues.CONTROLLER.toString(), 65533L);
33 mapOF10Ports.put(OutputPortValues.LOCAL.toString(), 65534L);
34 mapOF10Ports.put(OutputPortValues.NONE.toString(), 65535L);
36 mapOF13Ports = new HashMap<String, Long>();
37 mapOF13Ports.put(OutputPortValues.MAX.toString(), 4294967040L);
38 mapOF13Ports.put(OutputPortValues.INPORT.toString(), 4294967288L);
39 mapOF13Ports.put(OutputPortValues.TABLE.toString(), 4294967289L);
40 mapOF13Ports.put(OutputPortValues.NORMAL.toString(), 4294967290L);
41 mapOF13Ports.put(OutputPortValues.FLOOD.toString(), 4294967291L);
42 mapOF13Ports.put(OutputPortValues.ALL.toString(), 4294967292L);
43 mapOF13Ports.put(OutputPortValues.CONTROLLER.toString(), 4294967293L);
44 mapOF13Ports.put(OutputPortValues.LOCAL.toString(), 4294967294L);
45 mapOF13Ports.put(OutputPortValues.ANY.toString(), 4294967295L);
47 mapVersionToPorts = new HashMap<OpenflowVersion, Map<String, Long>>();
48 mapVersionToPorts.put(OpenflowVersion.OF10, mapOF10Ports);
49 mapVersionToPorts.put(OpenflowVersion.OF13, mapOF13Ports);
54 public static void tearDownClass() {
55 OpenflowPortsUtil.close();
58 mapVersionToPorts.clear();
62 private void matchGetLogicalName(OpenflowVersion version, String logicalName) {
63 Assert.assertEquals("Controller reserve port not matching to logical-name for "+ version,
65 OpenflowPortsUtil.getPortLogicalName(version, mapVersionToPorts.get(version).get(logicalName)));
69 private void matchGetPortfromLogicalName(OpenflowVersion version, String logicalName) {
70 Assert.assertEquals("Controller reserve port not matching to logical-name for "+ version,
71 mapVersionToPorts.get(version).get(logicalName), OpenflowPortsUtil.getPortFromLogicalName(version, logicalName));
75 public void testGetPortLogicalName() {
77 matchGetLogicalName(OpenflowVersion.OF10, OutputPortValues.MAX.toString());
78 matchGetLogicalName(OpenflowVersion.OF10, OutputPortValues.INPORT.toString());
79 matchGetLogicalName(OpenflowVersion.OF10, OutputPortValues.TABLE.toString());
80 matchGetLogicalName(OpenflowVersion.OF10, OutputPortValues.NORMAL.toString());
81 matchGetLogicalName(OpenflowVersion.OF10, OutputPortValues.FLOOD.toString());
82 matchGetLogicalName(OpenflowVersion.OF10, OutputPortValues.ALL.toString());
83 matchGetLogicalName(OpenflowVersion.OF10, OutputPortValues.CONTROLLER.toString());
84 matchGetLogicalName(OpenflowVersion.OF10, OutputPortValues.LOCAL.toString());
85 matchGetLogicalName(OpenflowVersion.OF10, OutputPortValues.NONE.toString());
87 matchGetLogicalName(OpenflowVersion.OF13, OutputPortValues.MAX.toString());
88 matchGetLogicalName(OpenflowVersion.OF13, OutputPortValues.INPORT.toString());
89 matchGetLogicalName(OpenflowVersion.OF13, OutputPortValues.TABLE.toString());
90 matchGetLogicalName(OpenflowVersion.OF13, OutputPortValues.NORMAL.toString());
91 matchGetLogicalName(OpenflowVersion.OF13, OutputPortValues.FLOOD.toString());
92 matchGetLogicalName(OpenflowVersion.OF13, OutputPortValues.ALL.toString());
93 matchGetLogicalName(OpenflowVersion.OF13, OutputPortValues.CONTROLLER.toString());
94 matchGetLogicalName(OpenflowVersion.OF13, OutputPortValues.LOCAL.toString());
95 matchGetLogicalName(OpenflowVersion.OF13, OutputPortValues.ANY.toString());
97 Assert.assertNull("Invalid port number should return a null",
98 OpenflowPortsUtil.getPortLogicalName(OpenflowVersion.OF10, 99999L));
100 Assert.assertNull("Invalid port number should return a null",
101 OpenflowPortsUtil.getPortLogicalName(OpenflowVersion.OF13, 99999L));
106 public void testGetPortFromLogicalName() {
108 matchGetPortfromLogicalName(OpenflowVersion.OF10, OutputPortValues.MAX.toString());
109 matchGetPortfromLogicalName(OpenflowVersion.OF10, OutputPortValues.INPORT.toString());
110 matchGetPortfromLogicalName(OpenflowVersion.OF10, OutputPortValues.TABLE.toString());
111 matchGetPortfromLogicalName(OpenflowVersion.OF10, OutputPortValues.NORMAL.toString());
112 matchGetPortfromLogicalName(OpenflowVersion.OF10, OutputPortValues.FLOOD.toString());
113 matchGetPortfromLogicalName(OpenflowVersion.OF10, OutputPortValues.ALL.toString());
114 matchGetPortfromLogicalName(OpenflowVersion.OF10, OutputPortValues.CONTROLLER.toString());
115 matchGetPortfromLogicalName(OpenflowVersion.OF10, OutputPortValues.LOCAL.toString());
116 matchGetPortfromLogicalName(OpenflowVersion.OF10, OutputPortValues.NONE.toString());
118 matchGetPortfromLogicalName(OpenflowVersion.OF13, OutputPortValues.MAX.toString());
119 matchGetPortfromLogicalName(OpenflowVersion.OF13, OutputPortValues.INPORT.toString());
120 matchGetPortfromLogicalName(OpenflowVersion.OF13, OutputPortValues.TABLE.toString());
121 matchGetPortfromLogicalName(OpenflowVersion.OF13, OutputPortValues.NORMAL.toString());
122 matchGetPortfromLogicalName(OpenflowVersion.OF13, OutputPortValues.FLOOD.toString());
123 matchGetPortfromLogicalName(OpenflowVersion.OF13, OutputPortValues.ALL.toString());
124 matchGetPortfromLogicalName(OpenflowVersion.OF13, OutputPortValues.CONTROLLER.toString());
125 matchGetPortfromLogicalName(OpenflowVersion.OF13, OutputPortValues.LOCAL.toString());
126 matchGetPortfromLogicalName(OpenflowVersion.OF13, OutputPortValues.ANY.toString());
128 Assert.assertNull("Invalid port logical name should return a null",
129 OpenflowPortsUtil.getPortFromLogicalName(OpenflowVersion.OF10, "abc"));
131 Assert.assertNull("Invalid port logical name should return a null",
132 OpenflowPortsUtil.getPortFromLogicalName(OpenflowVersion.OF13, "abc"));