2 * Copyright (c) 2014 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
8 package org.opendaylight.controller.switchmanager;
10 import java.util.ArrayList;
11 import java.util.List;
12 import org.junit.Assert;
13 import org.junit.Test;
14 import org.opendaylight.controller.sal.core.ConstructionException;
15 import org.opendaylight.controller.sal.core.Node;
16 import org.opendaylight.controller.sal.core.NodeConnector;
17 import org.opendaylight.controller.sal.utils.Status;
19 public class SubnetConfigTest {
22 public void configuration() throws ConstructionException {
23 // Create the node connector string list
24 Node node1 = new Node(Node.NodeIDType.OPENFLOW, 1L);
25 Node node2 = new Node(Node.NodeIDType.OPENFLOW, 2L);
26 Node node3 = new Node(Node.NodeIDType.OPENFLOW, 3L);
27 NodeConnector nc1 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW, (short)1, node1);
28 NodeConnector nc2 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW, (short)2, node2);
29 NodeConnector nc3 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW, (short)3, node3);
30 List<String> portList = new ArrayList<String>();
31 portList.add(nc1.toString());
32 portList.add(nc2.toString());
33 portList.add(nc3.toString());
35 // Full subnet creation
36 SubnetConfig config = new SubnetConfig("eng", "11.1.1.254/16", portList);
37 Status status = config.validate();
38 Assert.assertTrue(status.isSuccess());
40 // No port set specified
41 config = new SubnetConfig("eng", "11.1.1.254/16", null);
42 status = config.validate();
43 Assert.assertTrue(status.isSuccess());
46 config = new SubnetConfig("eng", "11.1.1.254/16", new ArrayList<String>(0));
47 status = config.validate();
48 Assert.assertTrue(status.isSuccess());
51 config = new SubnetConfig("eng", "1.2.3.254/1", null);
52 status = config.validate();
53 Assert.assertFalse(status.isSuccess());
55 // Port set with invalid port notation
56 List<String> badPortList = new ArrayList<String>();
57 badPortList.add("1/1");
58 config = new SubnetConfig("eng", "1.2.3.254/1", badPortList);
59 status = config.validate();
60 Assert.assertFalse(status.isSuccess());