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;
12 import java.net.InetAddress;
13 import java.util.HashSet;
16 import org.junit.Assert;
17 import org.junit.Test;
18 import org.opendaylight.controller.sal.utils.NodeCreator;
19 import org.opendaylight.controller.sal.core.Node;
20 import org.opendaylight.controller.sal.core.NodeConnector;
21 import org.opendaylight.controller.sal.utils.NodeConnectorCreator;
24 public class SubnetTest {
27 public void testSubnet() throws Exception {
28 InetAddress ipaddr = InetAddress.getByName("100.0.0.1");
29 Subnet subnet = new Subnet(ipaddr, (short)24, (short)5);
30 InetAddress subnetAddr = InetAddress.getByName("100.0.0.100");
32 Assert.assertTrue(subnet.isFlatLayer2() == true);
34 Set<NodeConnector> ncSet = new HashSet<NodeConnector>();
35 Node node = NodeCreator.createOFNode(((long)10));
36 NodeConnector nc0 = NodeConnectorCreator.createOFNodeConnector((short)20, node);
37 NodeConnector nc1 = NodeConnectorCreator.createOFNodeConnector((short)30, node);
38 NodeConnector nc2 = NodeConnectorCreator.createOFNodeConnector((short)40, node);
44 subnet.addNodeConnectors(ncSet);
46 Set<NodeConnector> resultncSet = subnet.getNodeConnectors();
47 Assert.assertEquals(resultncSet, ncSet);
49 subnet.setNetworkAddress(subnetAddr);
50 Assert.assertTrue(subnet.getNetworkAddress().equals(subnetAddr));
52 subnet.setSubnetMaskLength((short) 16);
53 Assert.assertTrue(subnet.getSubnetMaskLength() == 16);
55 subnet.setVlan((short)100);
56 Assert.assertTrue(subnet.getVlan() == 100);
58 Assert.assertTrue(subnet.isFlatLayer2() == false);