import java.util.HashSet;
import java.util.List;
import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
import org.junit.Assert;
import org.junit.Test;
-import org.opendaylight.controller.forwardingrulesmanager.FlowConfig;
-import org.opendaylight.controller.forwardingrulesmanager.FlowEntry;
import org.opendaylight.controller.sal.action.Action;
import org.opendaylight.controller.sal.action.ActionType;
import org.opendaylight.controller.sal.action.Controller;
import org.opendaylight.controller.sal.action.SetDlDst;
import org.opendaylight.controller.sal.action.SetNwDst;
import org.opendaylight.controller.sal.action.SetVlanId;
+import org.opendaylight.controller.sal.core.ContainerFlow;
import org.opendaylight.controller.sal.core.Node;
import org.opendaylight.controller.sal.core.NodeConnector;
import org.opendaylight.controller.sal.flowprogrammer.Flow;
import org.opendaylight.controller.sal.utils.IPProtocols;
import org.opendaylight.controller.sal.utils.NodeConnectorCreator;
import org.opendaylight.controller.sal.utils.NodeCreator;
+import org.opendaylight.controller.sal.utils.Status;
public class frmTest {
@Test
public void testFlowEntryInstall() throws UnknownHostException {
Node node = NodeCreator.createOFNode(1L);
- FlowEntry pol = new FlowEntry("polTest", null, getSampleFlowV6(node),
- node);
- FlowEntry pol2 = new FlowEntry("polTest2", null, getSampleFlowV6(node),
- node);
- FlowEntryInstall fei = new FlowEntryInstall(pol, null);
- FlowEntryInstall fei2 = new FlowEntryInstall(pol, null);
- FlowEntryInstall fei3 = new FlowEntryInstall(pol2, null);
+ FlowEntry pol = new FlowEntry("polTest", null, getSampleFlowV6(node), node);
+ FlowEntry pol2 = new FlowEntry("polTest2", null, getSampleFlowV6(node), node);
+ FlowEntryInstall fei = new FlowEntryInstall(pol.clone(), null);
+ FlowEntryInstall fei2 = new FlowEntryInstall(pol.clone(), null);
+ FlowEntryInstall fei3 = new FlowEntryInstall(pol2.clone(), null);
Assert.assertTrue(fei.getOriginal().equals(pol));
Assert.assertTrue(fei.getInstall().equals(pol));
Assert.assertTrue(fei.getFlowName().equals(pol.getFlowName()));
fei.toBeDeleted();
Assert.assertTrue(fei.isDeletePending());
Assert.assertNull(fei.getContainerFlow());
- Assert.assertTrue(fei.equalsByNodeAndName(pol.getNode(),
- pol.getFlowName()));
+ Assert.assertTrue(fei.equalsByNodeAndName(pol.getNode(), pol.getFlowName()));
Assert.assertTrue(fei.equals(fei2));
- fei2.getOriginal().setFlowName("polTest2");
Assert.assertFalse(fei.equals(null));
- Assert.assertFalse(fei.equals(fei3));
+ Assert.assertTrue(fei.equals(fei3));
}
@Test
public void testFlowEntryCreation() throws UnknownHostException {
Node node = NodeCreator.createOFNode(1L);
- FlowEntry pol = new FlowEntry("polTest", null, getSampleFlowV6(node),
- node);
+ FlowEntry pol = new FlowEntry("polTest", null, getSampleFlowV6(node), node);
Assert.assertTrue(pol.getFlow().equals(getSampleFlowV6(node)));
}
public void testFlowEntrySetGet() throws UnknownHostException {
Node node = NodeCreator.createOFNode(1L);
Node node2 = NodeCreator.createOFNode(2L);
- FlowEntry pol = new FlowEntry("polTest", null, getSampleFlowV6(node),
- node);
+ FlowEntry pol = new FlowEntry("polTest", null, getSampleFlowV6(node), node);
pol.setGroupName("polTest2");
pol.setFlowName("flowName");
Assert.assertTrue(pol.getFlowName().equals("flowName"));
public void testFlowEntryEquality() throws UnknownHostException {
Node node = NodeCreator.createOFNode(1L);
Node node2 = NodeCreator.createOFNode(1L);
- FlowEntry pol = new FlowEntry("polTest", null, getSampleFlowV6(node),
- node);
- FlowEntry pol2 = new FlowEntry("polTest", null, getSampleFlowV6(node),
- node2);
+ FlowEntry pol = new FlowEntry("polTest", null, getSampleFlowV6(node), node);
+ FlowEntry pol2 = new FlowEntry("polTest", null, getSampleFlowV6(node), node2);
Assert.assertTrue(pol.equals(pol2));
}
+ @Test
+ public void testFlowEntryCollision() throws UnknownHostException {
+ // Create 2 equal FlowEntry objects
+ Node node1 = NodeCreator.createOFNode(1L);
+ Node node2 = NodeCreator.createOFNode(1L);
+ FlowEntry fe1 = new FlowEntry("Junit", "flow1", getSampleFlowV6(node1), node1);
+ FlowEntry fe2 = new FlowEntry("Junit", "flow2", getSampleFlowV6(node2), node1);
+
+ // Check equality in FlowEntry and parameters
+ Assert.assertTrue(fe1.getFlow().getMatch().equals(fe2.getFlow().getMatch()));
+ Assert.assertTrue(fe1.getFlow().getMatch().getMatches() == fe2.getFlow().getMatch().getMatches());
+ Assert.assertTrue(fe1.getFlow().getMatch().hashCode() == fe2.getFlow().getMatch().hashCode());
+ Assert.assertTrue(fe1.getFlow().hashCode() == fe2.getFlow().hashCode());
+ Assert.assertTrue(fe1.equals(fe2));
+ Assert.assertTrue(fe1.hashCode() == fe2.hashCode());
+
+ // Change priority field for fe2, verify inequality
+ fe2.getFlow().setPriority((short)1000);
+
+ // Verify FlowEntry works as key in collection
+ ConcurrentMap<FlowEntry, FlowEntry> map = new ConcurrentHashMap<FlowEntry, FlowEntry>();
+ Assert.assertTrue(null == map.put(fe1, fe1));
+ Assert.assertTrue(fe1.clone().equals(map.put(fe1.clone(), fe1.clone())));
+ Assert.assertTrue(map.get(fe1.clone()).equals(fe1.clone()));
+ Assert.assertTrue(map.keySet().contains(fe1.clone()));
+ Assert.assertTrue(map.containsKey(fe1));
+
+ // Remove key
+ map.remove(fe1);
+ Assert.assertTrue(map.isEmpty());
+ Assert.assertFalse(map.containsKey(fe1));
+
+ // Verify cloned object as key
+ map.put(fe1.clone(), fe1.clone());
+ Assert.assertTrue(map.containsKey(fe1));
+
+ // Verify different key is not present
+ Assert.assertFalse(map.containsKey(fe2));
+
+ // Add different key
+ map.put(fe2.clone(), fe2.clone());
+ Assert.assertTrue(map.size() == 2);
+ Assert.assertTrue(map.containsKey(fe1));
+ Assert.assertTrue(map.containsKey(fe2));
+
+ // Make fe2 equal to fe1 again
+ fe2.getFlow().setPriority((short)300);
+ Assert.assertTrue(fe2.equals(fe1));
+ Assert.assertTrue(map.containsKey(fe2));
+
+ // Clean up
+ map.clear();
+ }
+
+ @Test
+ public void testFlowEntryInstallCollision() throws UnknownHostException {
+ // Create 2 equal FlowEntryInstall objects
+ Node node1 = NodeCreator.createOFNode(1L);
+ Node node2 = NodeCreator.createOFNode(1L);
+ FlowEntry fe1 = new FlowEntry("Junit", "flow1", getSampleFlowV6(node1), node1);
+ FlowEntry fe2 = new FlowEntry("Junit", "flow2", getSampleFlowV6(node2), node1);
+ ContainerFlow cf1 = null;
+ ContainerFlow cf2 = null;
+ FlowEntryInstall fei1 = new FlowEntryInstall(fe1, cf1);
+ FlowEntryInstall fei2 = new FlowEntryInstall(fe2, cf2);
+
+ // Check equality in FlowEntry and parameters
+ Assert.assertTrue(fei1.equals(fei2));
+ Assert.assertTrue(fei1.hashCode() == fei2.hashCode());
+
+ // Verify FlowEntryInstall works as key in collection
+ ConcurrentMap<FlowEntryInstall, FlowEntryInstall> map =
+ new ConcurrentHashMap<FlowEntryInstall, FlowEntryInstall>();
+ Assert.assertTrue(null == map.put(fei1, fei1));
+ Assert.assertTrue(map.get(fei1).equals(fei2));
+ Assert.assertTrue(map.keySet().contains(fei1));
+ Assert.assertTrue(map.keySet().contains(fei2));
+ Assert.assertTrue(map.containsKey(fei1));
+
+ // Remove key
+ map.remove(fei1);
+ Assert.assertTrue(map.isEmpty());
+ Assert.assertFalse(map.containsKey(fei1));
+
+ // Verify cloned object as key
+ map.put(fei1, fei1);
+ Assert.assertTrue(map.containsKey(fei1));
+
+ // Change fei2, change relevant hashcode info
+ fei2.getInstall().getFlow().setPriority((short)301);
+ Assert.assertFalse(fei1.equals(fei2));
+ Assert.assertFalse(fei1.hashCode() == fei2.hashCode());
+
+
+ // Verify different key is not present
+ Assert.assertFalse(map.containsKey(fei2));
+
+ // Add different key
+ map.put(fei2, fei2);
+ Assert.assertTrue(map.size() == 2);
+ Assert.assertTrue(map.containsKey(fei1));
+ Assert.assertTrue(map.containsKey(fei2));
+
+ // Make fei2 equal to fei1 again
+ fei2.getInstall().getFlow().setPriority((short)300);
+ Assert.assertTrue(fei2.equals(fei1));
+ Assert.assertTrue(map.containsKey(fei2));
+
+ // Clean up
+ map.clear();
+ }
+
@Test
public void testFlowEntryCloning() throws UnknownHostException {
Node node = NodeCreator.createOFNode(1L);
- FlowEntry pol = new FlowEntry("polTest", null, getSampleFlowV6(node),
- node);
+ FlowEntry pol = new FlowEntry("polTest", null, getSampleFlowV6(node), node);
FlowEntry pol2 = pol.clone();
Assert.assertTrue(pol.equals(pol2));
}
public void testInternalFlow() {
FlowConfig flowConfig = new FlowConfig();
Assert.assertFalse(flowConfig.isInternalFlow());
- flowConfig.setName("**Internal");
+ flowConfig.setName("__Internal__");
+ Status status = flowConfig.validate();
+ Assert.assertFalse(status.isSuccess());
+ Assert.assertTrue(status.getDescription().contains("name"));
Assert.assertTrue(flowConfig.isInternalFlow());
flowConfig.setName("External");
Assert.assertFalse(flowConfig.isInternalFlow());
FlowConfig frmC = new FlowConfig();
FlowConfig frmC3 = new FlowConfig();
Node node = NodeCreator.createOFNode(1L);
- FlowEntry entry = new FlowEntry("polTest", null, getSampleFlowV6(node),
- node);
+ FlowEntry entry = new FlowEntry("polTest", null, getSampleFlowV6(node), node);
// testing equal function
Assert.assertFalse(frmC.equals(null));
Assert.assertFalse(frmC.equals(flowC));
frmC.setNode(Node.fromString(Node.NodeIDType.OPENFLOW, "1"));
- Assert.assertTrue(frmC.getNode().equals(
- Node.fromString(Node.NodeIDType.OPENFLOW, "1")));
+ Assert.assertTrue(frmC.getNode().equals(Node.fromString(Node.NodeIDType.OPENFLOW, "1")));
Assert.assertFalse(frmC.equals(frmC3));
frmC3.setNode(Node.fromString(Node.NodeIDType.OPENFLOW, "1"));
}
- @Test
- public void testFlowConfigNextHopValidity() throws UnknownHostException {
- FlowConfig fc = new FlowConfig();
- Assert.assertFalse(fc.isOutputNextHopValid(null));
- Assert.assertFalse(fc.isOutputNextHopValid("abc"));
- Assert.assertFalse(fc.isOutputNextHopValid("1.1.1"));
- Assert.assertFalse(fc.isOutputNextHopValid("1.1.1.1/49"));
-
- Assert.assertTrue(fc.isOutputNextHopValid("1.1.1.1"));
- Assert.assertTrue(fc.isOutputNextHopValid("1.1.1.1/32"));
- Assert.assertTrue(fc
- .isOutputNextHopValid("2001:420:281:1004:407a:57f4:4d15:c355"));
-
- }
-
@Test
public void testFlowConfigEqualities() throws UnknownHostException {
FlowConfig fc = new FlowConfig();
FlowConfig fc2 = new FlowConfig();
fc.setName("flow1");
fc.setNode(Node.fromString(Node.NodeIDType.OPENFLOW, "1"));
- Assert.assertFalse(fc.onNode(Node.fromString(Node.NodeIDType.OPENFLOW,
- "0")));
- Assert.assertTrue(fc.onNode(Node.fromString(Node.NodeIDType.OPENFLOW,
- "1")));
-
- Assert.assertTrue(fc.isByNameAndNodeIdEqual("flow1",
- Node.fromString(Node.NodeIDType.OPENFLOW, "1")));
- Assert.assertFalse(fc.isByNameAndNodeIdEqual("flow1",
- Node.fromString(Node.NodeIDType.OPENFLOW, "0")));
- Assert.assertFalse(fc.isByNameAndNodeIdEqual("flow2",
- Node.fromString(Node.NodeIDType.OPENFLOW, "1")));
+ Assert.assertFalse(fc.onNode(Node.fromString(Node.NodeIDType.OPENFLOW, "0")));
+ Assert.assertTrue(fc.onNode(Node.fromString(Node.NodeIDType.OPENFLOW, "1")));
+
+ Assert.assertTrue(fc.isByNameAndNodeIdEqual("flow1", Node.fromString(Node.NodeIDType.OPENFLOW, "1")));
+ Assert.assertFalse(fc.isByNameAndNodeIdEqual("flow1", Node.fromString(Node.NodeIDType.OPENFLOW, "0")));
+ Assert.assertFalse(fc.isByNameAndNodeIdEqual("flow2", Node.fromString(Node.NodeIDType.OPENFLOW, "1")));
Assert.assertFalse(fc.isByNameAndNodeIdEqual(fc2));
fc2.setName("flow1");
@Test
public void testStatusToggle() throws UnknownHostException {
+ // default is install in Hw
FlowConfig fc = new FlowConfig();
- fc.toggleStatus();
- Assert.assertTrue(fc.installInHw());
- fc.toggleStatus();
+ fc.toggleInstallation();
Assert.assertFalse(fc.installInHw());
- fc.toggleStatus();
+ fc.toggleInstallation();
Assert.assertTrue(fc.installInHw());
+ fc.toggleInstallation();
+ Assert.assertFalse(fc.installInHw());
}
@Test
public void testValid() throws UnknownHostException {
- StringBuffer sb = new StringBuffer();
- sb.setLength(0);
FlowConfig fc2 = createSampleFlowConfig();
- Assert.assertTrue(fc2.isValid(null, sb));
+ Assert.assertTrue(fc2.validate().isSuccess());
FlowConfig fc = new FlowConfig();
- Assert.assertFalse(fc.isValid(null, sb));
- Assert.assertTrue(sb.toString().contains("Name is null"));
+ Status status = fc.validate();
+ Assert.assertFalse(status.isSuccess());
+ Assert.assertTrue(status.getDescription().contains("Invalid name"));
fc.setName("Config");
- Assert.assertFalse(fc.isValid(null, sb));
- Assert.assertTrue(sb.toString().contains("Node is null"));
+ status = fc.validate();
+ Assert.assertFalse(status.isSuccess());
+ Assert.assertTrue(status.getDescription().contains("Node is null"));
fc.setNode(Node.fromString(Node.NodeIDType.OPENFLOW, "1"));
- Assert.assertTrue(fc.isValid(null, sb));
+ Assert.assertFalse(fc.validate().isSuccess());
+ List<String> actions = new ArrayList<String>();
+ fc.setActions(actions);
+ Assert.assertFalse(fc.validate().isSuccess());
+ actions.add("OUTPUT=2");
+ fc.setActions(actions);
+ Assert.assertTrue(fc.validate().isSuccess());
fc.setPriority("-1");
- Assert.assertFalse(fc.isValid(null, sb));
- Assert.assertTrue(sb.toString().contains(
- "is not in the range 0 - 65535"));
- sb.setLength(0);
+ status = fc.validate();
+ Assert.assertFalse(status.isSuccess());
+ Assert.assertTrue(status.getDescription().contains("is not in the range 0 - 65535"));
fc.setPriority("100000");
- Assert.assertFalse(fc.isValid(null, sb));
- Assert.assertTrue(sb.toString().contains(
- "is not in the range 0 - 65535"));
- sb.setLength(0);
+ status = fc.validate();
+ Assert.assertFalse(status.isSuccess());
+ Assert.assertTrue(status.getDescription().contains("is not in the range 0 - 65535"));
+
fc.setPriority("2000");
- Assert.assertTrue(fc.isValid(null, sb));
+ Assert.assertTrue(fc.validate().isSuccess());
fc.setCookie("100");
- fc.setIngressPort("-1");
- Assert.assertFalse(fc.isValid(null, sb));
- Assert.assertTrue(sb.toString().contains("is not valid for the Switch"));
+ Assert.assertTrue(fc.validate().isSuccess());
+
fc.setIngressPort("100");
- Assert.assertTrue(fc.isValid(null, sb));
+ Assert.assertTrue(fc.validate().isSuccess());
fc.setVlanId(("-1"));
- Assert.assertFalse(fc.isValid(null, sb));
- Assert.assertTrue(sb.toString()
- .contains("is not in the range 0 - 4095"));
- sb.setLength(0);
+ status = fc.validate();
+ Assert.assertFalse(status.isSuccess());
+ Assert.assertTrue(status.getDescription().contains("is not in the range 0 - 4095"));
+
fc.setVlanId("5000");
- Assert.assertFalse(fc.isValid(null, sb));
- Assert.assertTrue(sb.toString()
- .contains("is not in the range 0 - 4095"));
+ status = fc.validate();
+ Assert.assertFalse(status.isSuccess());
+ Assert.assertTrue(status.getDescription().contains("is not in the range 0 - 4095"));
+
fc.setVlanId("100");
- Assert.assertTrue(fc.isValid(null, sb));
+ Assert.assertTrue(fc.validate().isSuccess());
+
fc.setVlanPriority("-1");
- Assert.assertFalse(fc.isValid(null, sb));
- Assert.assertTrue(sb.toString().contains("is not in the range 0 - 7"));
- sb.setLength(0);
+ status = fc.validate();
+ Assert.assertFalse(status.isSuccess());
+ Assert.assertTrue(status.getDescription().contains("is not in the range 0 - 7"));
+
fc.setVlanPriority("9");
- Assert.assertFalse(fc.isValid(null, sb));
- Assert.assertTrue(sb.toString().contains("is not in the range 0 - 7"));
+ status = fc.validate();
+ Assert.assertFalse(status.isSuccess());
+ Assert.assertTrue(status.getDescription().contains("is not in the range 0 - 7"));
+
fc.setVlanPriority("5");
- Assert.assertTrue(fc.isValid(null, sb));
+ Assert.assertTrue(fc.validate().isSuccess());
fc.setEtherType("-1");
- Assert.assertFalse(fc.isValid(null, sb));
- Assert.assertTrue(sb.toString().contains("Ethernet type"));
- sb.setLength(0);
+ status = fc.validate();
+ Assert.assertFalse(status.isSuccess());
+ Assert.assertTrue(status.getDescription().contains("Ethernet type"));
+
fc.setEtherType("0xfffff");
- Assert.assertFalse(fc.isValid(null, sb));
- Assert.assertTrue(sb.toString().contains("Ethernet type"));
+ status = fc.validate();
+ Assert.assertFalse(status.isSuccess());
+ Assert.assertTrue(status.getDescription().contains("Ethernet type"));
+
fc.setEtherType("0x800");
- Assert.assertTrue(fc.isValid(null, sb));
+ Assert.assertTrue(fc.validate().isSuccess());
fc.setTosBits("-1");
- Assert.assertFalse(fc.isValid(null, sb));
- Assert.assertTrue(sb.toString().contains("IP ToS bits"));
+ status = fc.validate();
+ Assert.assertFalse(status.isSuccess());
+ Assert.assertTrue(status.getDescription().contains("IP ToS bits"));
+
fc.setTosBits("65");
- sb.setLength(0);
- Assert.assertFalse(fc.isValid(null, sb));
- Assert.assertTrue(sb.toString().contains("IP ToS bits"));
+ status = fc.validate();
+ Assert.assertFalse(status.isSuccess());
+ Assert.assertTrue(status.getDescription().contains("IP ToS bits"));
+
fc.setTosBits("60");
- Assert.assertTrue(fc.isValid(null, sb));
+ Assert.assertTrue(fc.validate().isSuccess());
fc.setSrcPort("-1");
- Assert.assertFalse(fc.isValid(null, sb));
- Assert.assertTrue(sb.toString().contains("Transport source port"));
- sb.setLength(0);
+ status = fc.validate();
+ Assert.assertFalse(status.isSuccess());
+ Assert.assertTrue(status.getDescription().contains("Transport source port"));
+
fc.setSrcPort("0xfffff");
- Assert.assertFalse(fc.isValid(null, sb));
- Assert.assertTrue(sb.toString().contains("Transport source port"));
+ status = fc.validate();
+ Assert.assertFalse(status.isSuccess());
+ Assert.assertTrue(status.getDescription().contains("Transport source port"));
+
+ fc.setSrcPort("0");
+ Assert.assertTrue(fc.validate().isSuccess());
+
fc.setSrcPort("0x00ff");
- Assert.assertTrue(fc.isValid(null, sb));
+ Assert.assertTrue(fc.validate().isSuccess());
+
+ fc.setSrcPort("0xffff");
+ Assert.assertTrue(fc.validate().isSuccess());
fc.setDstPort("-1");
- Assert.assertFalse(fc.isValid(null, sb));
- Assert.assertTrue(sb.toString().contains("Transport destination port"));
- sb.setLength(0);
+ status = fc.validate();
+ Assert.assertFalse(status.isSuccess());
+ Assert.assertTrue(status.getDescription().contains("Transport destination port"));
+
fc.setDstPort("0xfffff");
- Assert.assertFalse(fc.isValid(null, sb));
- Assert.assertTrue(sb.toString().contains("Transport destination port"));
+ status = fc.validate();
+ Assert.assertFalse(status.isSuccess());
+ Assert.assertTrue(status.getDescription().contains("Transport destination port"));
+
+ fc.setDstPort("0");
+ Assert.assertTrue(fc.validate().isSuccess());
+
fc.setDstPort("0x00ff");
- Assert.assertTrue(fc.isValid(null, sb));
+ Assert.assertTrue(fc.validate().isSuccess());
+
+ fc.setDstPort("0xffff");
+ Assert.assertTrue(fc.validate().isSuccess());
fc.setSrcMac("abc");
- Assert.assertFalse(fc.isValid(null, sb));
- Assert.assertTrue(sb.toString().contains("Ethernet source address"));
- sb.setLength(0);
+ status = fc.validate();
+ Assert.assertFalse(status.isSuccess());
+ Assert.assertTrue(status.getDescription().contains("Ethernet source address"));
+
fc.setSrcMac("00:A0:C9:14:C8:29");
- Assert.assertTrue(fc.isValid(null, sb));
+ Assert.assertTrue(fc.validate().isSuccess());
fc.setDstMac("abc");
- Assert.assertFalse(fc.isValid(null, sb));
- Assert.assertTrue(sb.toString()
- .contains("Ethernet destination address"));
+ status = fc.validate();
+ Assert.assertFalse(status.isSuccess());
+ Assert.assertTrue(status.getDescription().contains("Ethernet destination address"));
+
fc.setDstMac("00:A0:C9:22:AB:11");
- Assert.assertTrue(fc.isValid(null, sb));
+ Assert.assertTrue(fc.validate().isSuccess());
fc.setSrcIp("-1");
- Assert.assertFalse(fc.isValid(null, sb));
- Assert.assertTrue(sb.toString().contains("IP source address"));
+ status = fc.validate();
+ Assert.assertFalse(status.isSuccess());
+ Assert.assertTrue(status.getDescription().contains("IP source address"));
+
fc.setSrcIp("2001:420:281:1004:407a:57f4:4d15:c355");
- Assert.assertFalse(fc.isValid(null, sb));
- Assert.assertTrue(sb.toString().contains(
- "Type mismatch between Ethernet & Src IP"));
+ status = fc.validate();
+ Assert.assertFalse(status.isSuccess());
+ Assert.assertTrue(status.getDescription().contains("Type mismatch between Ethernet & Src IP"));
fc.setEtherType("0x86dd");
- Assert.assertTrue(fc.isValid(null, sb));
- sb.setLength(0);
+ Assert.assertTrue(fc.validate().isSuccess());
fc.setSrcIp("1.1.1.1");
- Assert.assertFalse(fc.isValid(null, sb));
- Assert.assertTrue(sb.toString().contains(
- "Type mismatch between Ethernet & Src IP"));
+ status = fc.validate();
+ Assert.assertFalse(status.isSuccess());
+ Assert.assertTrue(status.getDescription().contains("Type mismatch between Ethernet & Src IP"));
+
fc.setEtherType("0x800");
- Assert.assertTrue(fc.isValid(null, sb));
+ Assert.assertTrue(fc.validate().isSuccess());
fc.setDstIp("-1");
- Assert.assertFalse(fc.isValid(null, sb));
- Assert.assertTrue(sb.toString().contains("IP destination address"));
+ status = fc.validate();
+ Assert.assertFalse(status.isSuccess());
+ Assert.assertTrue(status.getDescription().contains("IP destination address"));
+
fc.setDstIp("2001:420:281:1004:407a:57f4:4d15:c355");
- Assert.assertFalse(fc.isValid(null, sb));
- Assert.assertTrue(sb.toString().contains(
- "Type mismatch between Ethernet & Dst IP"));
+ status = fc.validate();
+ Assert.assertFalse(status.isSuccess());
+ Assert.assertTrue(status.getDescription().contains("Type mismatch between Ethernet & Dst IP"));
fc.setEtherType("0x86dd");
fc.setSrcIp("2001:420:281:1004:407a:57f4:4d15:c355");
- Assert.assertTrue(fc.isValid(null, sb));
- sb.setLength(0);
+ Assert.assertTrue(fc.validate().isSuccess());
fc.setDstIp("2.2.2.2");
- Assert.assertFalse(fc.isValid(null, sb));
- Assert.assertTrue(sb.toString().contains(
- "Type mismatch between Ethernet & Dst IP"));
+ status = fc.validate();
+ Assert.assertFalse(status.isSuccess());
+ Assert.assertTrue(status.getDescription().contains("Type mismatch between Ethernet & Dst IP"));
+
fc.setEtherType("0x800");
fc.setSrcIp("1.1.1.1");
- Assert.assertTrue(fc.isValid(null, sb));
+ Assert.assertTrue(fc.validate().isSuccess());
fc.setEtherType(null);
fc.setSrcIp("2001:420:281:1004:407a:57f4:4d15:c355");
- Assert.assertFalse(fc.isValid(null, sb));
- Assert.assertTrue(sb.toString().contains("IP Src Dest Type mismatch"));
+ status = fc.validate();
+ Assert.assertFalse(status.isSuccess());
+ Assert.assertTrue(status.getDescription().contains("IP Src Dest Type mismatch"));
+
fc.setSrcIp("1.1.1.1");
fc.setIdleTimeout("-1");
- Assert.assertFalse(fc.isValid(null, sb));
- Assert.assertTrue(sb.toString().contains("Idle Timeout value"));
- sb.setLength(0);
+ status = fc.validate();
+ Assert.assertFalse(status.isSuccess());
+ Assert.assertTrue(status.getDescription().contains("Idle Timeout value"));
+
fc.setIdleTimeout("0xfffff");
- Assert.assertFalse(fc.isValid(null, sb));
- Assert.assertTrue(sb.toString().contains("Idle Timeout value"));
+ status = fc.validate();
+ Assert.assertFalse(status.isSuccess());
+ Assert.assertTrue(status.getDescription().contains("Idle Timeout value"));
+
fc.setIdleTimeout("10");
- Assert.assertTrue(fc.isValid(null, sb));
+ Assert.assertTrue(fc.validate().isSuccess());
fc.setHardTimeout("-1");
- Assert.assertFalse(fc.isValid(null, sb));
- Assert.assertTrue(sb.toString().contains("Hard Timeout value"));
+ status = fc.validate();
+ Assert.assertFalse(status.isSuccess());
+ Assert.assertTrue(status.getDescription().contains("Hard Timeout value"));
+
fc.setHardTimeout("0xfffff");
- Assert.assertFalse(fc.isValid(null, sb));
- Assert.assertTrue(sb.toString().contains("Hard Timeout value"));
+ status = fc.validate();
+ Assert.assertFalse(status.isSuccess());
+ Assert.assertTrue(status.getDescription().contains("Hard Timeout value"));
+
fc.setHardTimeout("10");
- Assert.assertTrue(fc.isValid(null, sb));
+ Assert.assertTrue(fc.validate().isSuccess());
}
ArrayList<String> actions;
actions = createSampleActionList();
// actions.add(ActionType.CONTROLLER.toString());
- FlowConfig flowConfig = new FlowConfig("true", "Config1",
- Node.fromString(Node.NodeIDType.OPENFLOW, "1"), "100", "0",
- "60", "2", "100", "0", "0x0800", "00:A0:C9:14:C8:29",
- "00:A0:C9:22:AB:11", IPProtocols.TCP.toString(), "0",
- "1.2.3.4", "2.2.2.2", "8080", "100", "300", "1000", actions);
+ FlowConfig flowConfig = new FlowConfig("true", "Config1", Node.fromString(Node.NodeIDType.OPENFLOW, "1"),
+ "100", "0", "60", "2", "100", "0", "0x0800", "00:A0:C9:14:C8:29", "00:A0:C9:22:AB:11",
+ IPProtocols.TCP.toString(), "0", "1.2.3.4", "2.2.2.2", "8080", "100", "300", "1000", actions);
return flowConfig;
}
}
private Flow getSampleFlowV6(Node node) throws UnknownHostException {
- NodeConnector port = NodeConnectorCreator.createOFNodeConnector(
- (short) 24, node);
- NodeConnector oport = NodeConnectorCreator.createOFNodeConnector(
- (short) 30, node);
- byte srcMac[] = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78,
- (byte) 0x9a, (byte) 0xbc };
- byte dstMac[] = { (byte) 0x1a, (byte) 0x2b, (byte) 0x3c, (byte) 0x4d,
- (byte) 0x5e, (byte) 0x6f };
- byte newMac[] = { (byte) 0x11, (byte) 0xaa, (byte) 0xbb, (byte) 0x34,
- (byte) 0x9a, (byte) 0xee };
- InetAddress srcIP = InetAddress
- .getByName("2001:420:281:1004:407a:57f4:4d15:c355");
- InetAddress dstIP = InetAddress
- .getByName("2001:420:281:1004:e123:e688:d655:a1b0");
- InetAddress ipMask = InetAddress
- .getByName("ffff:ffff:ffff:ffff:0:0:0:0");
- InetAddress ipMask2 = InetAddress
- .getByName("ffff:ffff:ffff:ffff:ffff:ffff:ffff:0");
+ NodeConnector port = NodeConnectorCreator.createOFNodeConnector((short) 24, node);
+ NodeConnector oport = NodeConnectorCreator.createOFNodeConnector((short) 30, node);
+ byte srcMac[] = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9a, (byte) 0xbc };
+ byte dstMac[] = { (byte) 0x1a, (byte) 0x2b, (byte) 0x3c, (byte) 0x4d, (byte) 0x5e, (byte) 0x6f };
+ byte newMac[] = { (byte) 0x11, (byte) 0xaa, (byte) 0xbb, (byte) 0x34, (byte) 0x9a, (byte) 0xee };
+ InetAddress srcIP = InetAddress.getByName("2001:420:281:1004:407a:57f4:4d15:c355");
+ InetAddress dstIP = InetAddress.getByName("2001:420:281:1004:e123:e688:d655:a1b0");
+ InetAddress ipMask = InetAddress.getByName("ffff:ffff:ffff:ffff:0:0:0:0");
+ InetAddress ipMask2 = InetAddress.getByName("ffff:ffff:ffff:ffff:ffff:ffff:ffff:0");
InetAddress newIP = InetAddress.getByName("2056:650::a1b0");
short ethertype = EtherTypes.IPv6.shortValue();
short vlan = (short) 27;
actions.add(new PopVlan());
actions.add(new Flood());
- actions.add(new Controller());
-
Flow flow = new Flow(match, actions);
flow.setPriority((short) 300);
flow.setHardTimeout((short) 240);