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;
public class SwitchManagerTest {
@Test
- public void testSwitchManagerAddRemoveSubnet() {
+ public void testSwitchManagerAddRemoveSubnet() throws ConstructionException {
SwitchManager switchmgr = new SwitchManager();
switchmgr.startUp();
- ArrayList<String> portList = new ArrayList<String>();
- 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<String> portList = new ArrayList<String>();
+ 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<String> portList = new ArrayList<String>();
+ 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<String> badPortSet = new ArrayList<String>();
+ 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