3 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
5 * This program and the accompanying materials are made available under the
6 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7 * and is available at http://www.eclipse.org/legal/epl-v10.html
10 package org.opendaylight.controller.switchmanager.internal;
12 import java.util.ArrayList;
13 import java.util.HashSet;
16 import org.junit.Assert;
17 import org.junit.Test;
18 import org.opendaylight.controller.sal.core.Bandwidth;
19 import org.opendaylight.controller.sal.core.Latency;
20 import org.opendaylight.controller.sal.core.Node;
21 import org.opendaylight.controller.sal.core.NodeConnector;
22 import org.opendaylight.controller.sal.core.Property;
23 import org.opendaylight.controller.sal.core.State;
24 import org.opendaylight.controller.sal.core.UpdateType;
25 import org.opendaylight.controller.sal.utils.NodeConnectorCreator;
26 import org.opendaylight.controller.sal.utils.NodeCreator;
27 import org.opendaylight.controller.sal.utils.Status;
28 import org.opendaylight.controller.switchmanager.SubnetConfig;
30 public class SwitchManagerImplTest {
33 public void testSwitchManagerAddRemoveSubnet() {
34 SwitchManagerImpl switchmgr = new SwitchManagerImpl();
35 switchmgr.nonClusterObjectCreate();
37 ArrayList<String>portList = new ArrayList<String>();
43 SubnetConfig subnet = new SubnetConfig("subnet", "10.0.0.254/16", portList);
44 //System.out.println("*" + switchmgr.addSubnet(subnet) + "*");
45 Status addResult = (switchmgr.addSubnet(subnet));
46 Assert.assertTrue(addResult.isSuccess());
48 Status removeResult = (switchmgr.removeSubnet(subnet.getName()));
49 Assert.assertTrue(removeResult.isSuccess());
51 SubnetConfig subnetConfigResult = switchmgr.getSubnetConfig(subnet.getName());
52 Assert.assertTrue(subnetConfigResult == null);
57 public void testSwitchManagerNodeConnectors() {
58 SwitchManagerImpl switchmgr = new SwitchManagerImpl();
59 switchmgr.nonClusterObjectCreate();
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, NodeCreator.createOFNode((long)i));
79 tailnc[i - 1] = NodeConnectorCreator.createOFNodeConnector((short)(i+10), NodeCreator.createOFNode((long)(i+10)));
80 switchmgr.updateNode(headnc[i - 1].getNode(), UpdateType.ADDED, props);
81 switchmgr.updateNode(tailnc[i - 1].getNode(), UpdateType.ADDED, props);
83 switchmgr.updateNodeConnector(headnc[i - 1], UpdateType.ADDED, props);
84 switchmgr.updateNodeConnector(tailnc[i - 1], UpdateType.ADDED, props);
87 for (int i = 0; i < 5; i++) {
88 Property bwProp = switchmgr.getNodeConnectorProp(headnc[i], Bandwidth.BandwidthPropName);
89 Assert.assertTrue(bwProp.equals(bw));
90 Property latencyProp = switchmgr.getNodeConnectorProp(tailnc[i], Latency.LatencyPropName);
91 Assert.assertEquals(latencyProp, l);
93 byte[] headNodeMac = switchmgr.getNodeMAC(headnc[i].getNode());
94 Assert.assertTrue(headNodeMac[headNodeMac.length - 1] == (byte)(i + 1));
97 Set<Node> nodes = switchmgr.getNodes();
98 for (int i = 0; i < 5; i++) {
99 if (nodes.contains(headnc[i].getNode()) == true)
100 nodes.remove(headnc[i].getNode());
102 if (nodes.contains(tailnc[i].getNode()) == true)
103 nodes.remove(tailnc[i].getNode());
106 Assert.assertTrue(nodes.isEmpty());