2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.switchmanager.internal;
11 import java.util.ArrayList;
12 import java.util.HashSet;
15 import org.junit.Assert;
16 import org.junit.Test;
17 import org.opendaylight.controller.sal.core.Bandwidth;
18 import org.opendaylight.controller.sal.core.Latency;
19 import org.opendaylight.controller.sal.core.Node;
20 import org.opendaylight.controller.sal.core.NodeConnector;
21 import org.opendaylight.controller.sal.core.Property;
22 import org.opendaylight.controller.sal.core.State;
23 import org.opendaylight.controller.sal.core.UpdateType;
24 import org.opendaylight.controller.sal.utils.NodeConnectorCreator;
25 import org.opendaylight.controller.sal.utils.NodeCreator;
26 import org.opendaylight.controller.sal.utils.Status;
27 import org.opendaylight.controller.switchmanager.SubnetConfig;
29 public class SwitchManagerTest {
32 public void testSwitchManagerAddRemoveSubnet() {
33 SwitchManager switchmgr = new SwitchManager();
36 ArrayList<String> portList = new ArrayList<String>();
41 SubnetConfig subnet = new SubnetConfig("subnet", "10.0.0.254/16",
43 // System.out.println("*" + switchmgr.addSubnet(subnet) + "*");
44 Status addResult = (switchmgr.addSubnet(subnet));
45 Assert.assertTrue(addResult.isSuccess());
47 Status removeResult = (switchmgr.removeSubnet(subnet.getName()));
48 Assert.assertTrue(removeResult.isSuccess());
50 SubnetConfig subnetConfigResult = switchmgr.getSubnetConfig(subnet
52 Assert.assertTrue(subnetConfigResult == null);
57 public void testSwitchManagerNodeConnectors() {
58 SwitchManager switchmgr = new SwitchManager();
65 NodeConnector[] headnc = new NodeConnector[5];
66 NodeConnector[] tailnc = new NodeConnector[5];
68 Set<Property> props = new HashSet<Property>();
69 state = new State(State.EDGE_UP);
70 bw = new Bandwidth(Bandwidth.BW100Gbps);
71 l = new Latency(Latency.LATENCY100ns);
76 for (short i = 1; i < 6; i = (short) (i + 1)) {
78 headnc[i - 1] = NodeConnectorCreator.createOFNodeConnector(i,
79 NodeCreator.createOFNode((long) i));
80 tailnc[i - 1] = NodeConnectorCreator
81 .createOFNodeConnector((short) (i + 10),
82 NodeCreator.createOFNode((long) (i + 10)));
83 switchmgr.updateNode(headnc[i - 1].getNode(), UpdateType.ADDED,
85 switchmgr.updateNode(tailnc[i - 1].getNode(), UpdateType.ADDED,
88 switchmgr.updateNodeConnector(headnc[i - 1], UpdateType.ADDED,
90 switchmgr.updateNodeConnector(tailnc[i - 1], UpdateType.ADDED,
94 for (int i = 0; i < 5; i++) {
95 Property bwProp = switchmgr.getNodeConnectorProp(headnc[i],
96 Bandwidth.BandwidthPropName);
97 Assert.assertTrue(bwProp.equals(bw));
98 Property latencyProp = switchmgr.getNodeConnectorProp(tailnc[i],
99 Latency.LatencyPropName);
100 Assert.assertEquals(latencyProp, l);
103 Set<Node> nodes = switchmgr.getNodes();
104 for (int i = 0; i < 5; i++) {
105 if (nodes.contains(headnc[i].getNode()) == true) {
106 nodes.remove(headnc[i].getNode());
109 if (nodes.contains(tailnc[i].getNode()) == true) {
110 nodes.remove(tailnc[i].getNode());
114 Assert.assertTrue(nodes.isEmpty());