d74c3d36308b157f4fa4021c504a01cc083b2627
[controller.git] / opendaylight / switchmanager / implementation / src / test / java / org / opendaylight / controller / switchmanager / internal / SwitchManagerTest.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.controller.switchmanager.internal;
10
11 import java.util.HashSet;
12 import java.util.Set;
13
14 import org.junit.Assert;
15 import org.junit.Test;
16 import org.opendaylight.controller.sal.core.Bandwidth;
17 import org.opendaylight.controller.sal.core.Latency;
18 import org.opendaylight.controller.sal.core.Node;
19 import org.opendaylight.controller.sal.core.NodeConnector;
20 import org.opendaylight.controller.sal.core.Property;
21 import org.opendaylight.controller.sal.core.State;
22 import org.opendaylight.controller.sal.core.UpdateType;
23 import org.opendaylight.controller.sal.utils.NodeConnectorCreator;
24 import org.opendaylight.controller.sal.utils.NodeCreator;
25 import org.opendaylight.controller.sal.utils.Status;
26 import org.opendaylight.controller.switchmanager.SubnetConfig;
27
28 public class SwitchManagerTest {
29
30     @Test
31     public void testSwitchManagerAddRemoveSubnet() {
32         SwitchManager switchmgr = new SwitchManager();
33         switchmgr.startUp();
34
35         Set<String> portList = new HashSet<String>();
36         portList.add("1/1");
37         portList.add("1/2");
38         portList.add("1/3");
39
40         SubnetConfig subnet = new SubnetConfig("subnet", "10.0.0.254/16",
41                 portList);
42         // System.out.println("*" + switchmgr.addSubnet(subnet) + "*");
43         Status addResult = (switchmgr.addSubnet(subnet));
44         Assert.assertTrue(addResult.isSuccess());
45
46         Status removeResult = (switchmgr.removeSubnet(subnet.getName()));
47         Assert.assertTrue(removeResult.isSuccess());
48
49         SubnetConfig subnetConfigResult = switchmgr.getSubnetConfig(subnet
50                 .getName());
51         Assert.assertTrue(subnetConfigResult == null);
52
53     }
54
55     @Test
56     public void testSwitchManagerNodeConnectors() {
57         SwitchManager switchmgr = new SwitchManager();
58         switchmgr.startUp();
59
60         State state;
61         Bandwidth bw;
62         Latency l;
63
64         NodeConnector[] headnc = new NodeConnector[5];
65         NodeConnector[] tailnc = new NodeConnector[5];
66
67         Set<Property> props = new HashSet<Property>();
68         state = new State(State.EDGE_UP);
69         bw = new Bandwidth(Bandwidth.BW100Gbps);
70         l = new Latency(Latency.LATENCY100ns);
71         props.add(state);
72         props.add(bw);
73         props.add(l);
74
75         for (short i = 1; i < 6; i = (short) (i + 1)) {
76
77             headnc[i - 1] = NodeConnectorCreator.createOFNodeConnector(i,
78                     NodeCreator.createOFNode((long) i));
79             tailnc[i - 1] = NodeConnectorCreator
80                     .createOFNodeConnector((short) (i + 10),
81                             NodeCreator.createOFNode((long) (i + 10)));
82             switchmgr.updateNode(headnc[i - 1].getNode(), UpdateType.ADDED,
83                     props);
84             switchmgr.updateNode(tailnc[i - 1].getNode(), UpdateType.ADDED,
85                     props);
86
87             switchmgr.updateNodeConnector(headnc[i - 1], UpdateType.ADDED,
88                     props);
89             switchmgr.updateNodeConnector(tailnc[i - 1], UpdateType.ADDED,
90                     props);
91         }
92
93         for (int i = 0; i < 5; i++) {
94             Property bwProp = switchmgr.getNodeConnectorProp(headnc[i],
95                     Bandwidth.BandwidthPropName);
96             Assert.assertTrue(bwProp.equals(bw));
97             Property latencyProp = switchmgr.getNodeConnectorProp(tailnc[i],
98                     Latency.LatencyPropName);
99             Assert.assertEquals(latencyProp, l);
100         }
101
102         Set<Node> nodes = switchmgr.getNodes();
103         for (int i = 0; i < 5; i++) {
104             if (nodes.contains(headnc[i].getNode()) == true) {
105                 nodes.remove(headnc[i].getNode());
106             }
107
108             if (nodes.contains(tailnc[i].getNode()) == true) {
109                 nodes.remove(tailnc[i].getNode());
110             }
111
112         }
113         Assert.assertTrue(nodes.isEmpty());
114     }
115
116 }