OpenDaylight Controller functional modules.
[controller.git] / opendaylight / switchmanager / src / test / java / org / opendaylight / controller / switchmanager / SubnetTest.java
1
2 /*
3  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
4  *
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
8  */
9
10 package org.opendaylight.controller.switchmanager;
11
12 import java.net.InetAddress;
13 import java.util.HashSet;
14 import java.util.Set;
15
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;
22
23
24 public class SubnetTest {
25         
26         @Test
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");
31                 
32                 Assert.assertTrue(subnet.isFlatLayer2() == true);
33                 
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);
39                 
40                 ncSet.add(nc0);
41                 ncSet.add(nc1);
42                 ncSet.add(nc2);
43                 
44                 subnet.addNodeConnectors(ncSet);
45                 
46                 Set<NodeConnector> resultncSet = subnet.getNodeConnectors();
47                 Assert.assertEquals(resultncSet, ncSet);
48                 
49                 subnet.setNetworkAddress(subnetAddr);
50                 Assert.assertTrue(subnet.getNetworkAddress().equals(subnetAddr));
51                 
52                 subnet.setSubnetMaskLength((short) 16);
53                 Assert.assertTrue(subnet.getSubnetMaskLength() == 16);
54                 
55                 subnet.setVlan((short)100);
56                 Assert.assertTrue(subnet.getVlan() == 100);
57                 
58                 Assert.assertTrue(subnet.isFlatLayer2() == false);
59
60         }
61
62 }