X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fswitchmanager%2Fimplementation%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fswitchmanager%2Finternal%2FSwitchManagerTest.java;h=97747e9a220922d6c07be06d36a4b3b4938c4cac;hb=51e9be2b3aac6ea33bf21e5a3a978325d24e9e0e;hp=a233ad4b3ebc556558bed7cc92274d6f465b41c6;hpb=93e4ab834487a4d86a5b6ab27adb542cc9f86233;p=controller.git diff --git a/opendaylight/switchmanager/implementation/src/test/java/org/opendaylight/controller/switchmanager/internal/SwitchManagerTest.java b/opendaylight/switchmanager/implementation/src/test/java/org/opendaylight/controller/switchmanager/internal/SwitchManagerTest.java index a233ad4b3e..97747e9a22 100644 --- a/opendaylight/switchmanager/implementation/src/test/java/org/opendaylight/controller/switchmanager/internal/SwitchManagerTest.java +++ b/opendaylight/switchmanager/implementation/src/test/java/org/opendaylight/controller/switchmanager/internal/SwitchManagerTest.java @@ -10,11 +10,13 @@ package org.opendaylight.controller.switchmanager.internal; import java.util.ArrayList; import java.util.HashSet; +import java.util.List; import java.util.Set; import org.junit.Assert; import org.junit.Test; import org.opendaylight.controller.sal.core.Bandwidth; +import org.opendaylight.controller.sal.core.ConstructionException; import org.opendaylight.controller.sal.core.Latency; import org.opendaylight.controller.sal.core.Node; import org.opendaylight.controller.sal.core.NodeConnector; @@ -29,28 +31,75 @@ import org.opendaylight.controller.switchmanager.SubnetConfig; public class SwitchManagerTest { @Test - public void testSwitchManagerAddRemoveSubnet() { + public void testSwitchManagerAddRemoveSubnet() throws ConstructionException { SwitchManager switchmgr = new SwitchManager(); switchmgr.startUp(); - ArrayList portList = new ArrayList(); - portList.add("1/1"); - portList.add("1/2"); - portList.add("1/3"); + // Create the node connector string list + Node node1 = new Node(Node.NodeIDType.OPENFLOW, 1L); + Node node2 = new Node(Node.NodeIDType.OPENFLOW, 2L); + NodeConnector nc1 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW, (short)1, node1); + NodeConnector nc2 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW, (short)2, node2); + NodeConnector nc3 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW, (short)3, node1); + List portList = new ArrayList(); + portList.add(nc1.toString()); + portList.add(nc2.toString()); + portList.add(nc3.toString()); - SubnetConfig subnet = new SubnetConfig("subnet", "10.0.0.254/16", - portList); - // System.out.println("*" + switchmgr.addSubnet(subnet) + "*"); + + SubnetConfig subnet = new SubnetConfig("subnet", "10.0.0.254/16", portList); Status addResult = (switchmgr.addSubnet(subnet)); Assert.assertTrue(addResult.isSuccess()); Status removeResult = (switchmgr.removeSubnet(subnet.getName())); Assert.assertTrue(removeResult.isSuccess()); - SubnetConfig subnetConfigResult = switchmgr.getSubnetConfig(subnet - .getName()); - Assert.assertTrue(subnetConfigResult == null); + SubnetConfig subnetConfigResult = switchmgr.getSubnetConfig(subnet.getName()); + Assert.assertNull(subnetConfigResult); + + subnet = new SubnetConfig("hr", "0.0.0.0", portList); + Status status = switchmgr.addSubnet(subnet); + Assert.assertFalse(status.isSuccess()); + + subnet = new SubnetConfig("hr", "12.12.12.254/16", null); + status = switchmgr.addSubnet(subnet); + Assert.assertTrue(status.isSuccess()); + + } + + @Test + public void testSwitchManagerAddRemovePortsToSubnet() { + SwitchManager switchmgr = new SwitchManager(); + switchmgr.startUp(); + + List portList = new ArrayList(); + portList.add("OF|1@OF|1"); + portList.add("OF|2@OF|00:00:00:00:00:00:00:02"); + portList.add("OF|3@OF|00:00:00:00:00:00:00:01"); + + SubnetConfig subnet = new SubnetConfig("eng", "11.1.1.254/16", portList); + Status status = (switchmgr.addSubnet(subnet)); + Assert.assertTrue(status.isSuccess()); + + + // Empty port set + List badPortSet = new ArrayList(); + status = switchmgr.addPortsToSubnet("eng", badPortSet); + Assert.assertFalse(status.isSuccess()); + + // Non existant subnet + status = switchmgr.removePortsFromSubnet("hr", badPortSet); + Assert.assertFalse(status.isSuccess()); + + // Port set containing non conventional but parsable port + badPortSet.add("1/1"); + status = switchmgr.addPortsToSubnet("eng", badPortSet); + Assert.assertTrue(status.isSuccess()); + // Port set containing non parsable port + badPortSet.add("OF1/1"); + status = switchmgr.addPortsToSubnet("eng", badPortSet); + Assert.assertTrue(status.isSuccess()); } @Test