Controller MAC to be synced in cluster
[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.ArrayList;
12 import java.util.HashSet;
13 import java.util.Set;
14
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;
28
29 public class SwitchManagerTest {
30
31     @Test
32     public void testSwitchManagerAddRemoveSubnet() {
33         SwitchManager switchmgr = new SwitchManager();
34         switchmgr.startUp();
35
36         ArrayList<String> portList = new ArrayList<String>();
37         portList.add("1/1");
38         portList.add("1/2");
39         portList.add("1/3");
40
41         SubnetConfig subnet = new SubnetConfig("subnet", "10.0.0.254/16",
42                 portList);
43         // System.out.println("*" + switchmgr.addSubnet(subnet) + "*");
44         Status addResult = (switchmgr.addSubnet(subnet));
45         Assert.assertTrue(addResult.isSuccess());
46
47         Status removeResult = (switchmgr.removeSubnet(subnet.getName()));
48         Assert.assertTrue(removeResult.isSuccess());
49
50         SubnetConfig subnetConfigResult = switchmgr.getSubnetConfig(subnet
51                 .getName());
52         Assert.assertTrue(subnetConfigResult == null);
53
54     }
55
56     @Test
57     public void testSwitchManagerNodeConnectors() {
58         SwitchManager switchmgr = new SwitchManager();
59         switchmgr.startUp();
60
61         State state;
62         Bandwidth bw;
63         Latency l;
64
65         NodeConnector[] headnc = new NodeConnector[5];
66         NodeConnector[] tailnc = new NodeConnector[5];
67
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);
72         props.add(state);
73         props.add(bw);
74         props.add(l);
75
76         for (short i = 1; i < 6; i = (short) (i + 1)) {
77
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,
84                     props);
85             switchmgr.updateNode(tailnc[i - 1].getNode(), UpdateType.ADDED,
86                     props);
87
88             switchmgr.updateNodeConnector(headnc[i - 1], UpdateType.ADDED,
89                     props);
90             switchmgr.updateNodeConnector(tailnc[i - 1], UpdateType.ADDED,
91                     props);
92         }
93
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);
101         }
102
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());
107             }
108
109             if (nodes.contains(tailnc[i].getNode()) == true) {
110                 nodes.remove(tailnc[i].getNode());
111             }
112
113         }
114         Assert.assertTrue(nodes.isEmpty());
115     }
116
117 }