BUG-2218: Keep existing link augmentations during discovery process
[controller.git] / opendaylight / hosttracker / api / src / test / java / org / opendaylight / controller / hosttracker / hostAware / HostNodeConnectorTest.java
1 /*\r
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
3  *\r
4  * This program and the accompanying materials are made available under the\r
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
6  * and is available at http://www.eclipse.org/legal/epl-v10.html\r
7  */\r
8 \r
9 package org.opendaylight.controller.hosttracker.hostAware;\r
10 \r
11 import java.net.InetAddress;\r
12 import java.net.UnknownHostException;\r
13 \r
14 import org.junit.Assert;\r
15 import org.junit.Test;\r
16 import org.opendaylight.controller.sal.core.ConstructionException;\r
17 import org.opendaylight.controller.sal.core.Node;\r
18 import org.opendaylight.controller.sal.core.NodeConnector;\r
19 import org.opendaylight.controller.sal.packet.address.EthernetAddress;\r
20 import org.opendaylight.controller.sal.utils.NodeConnectorCreator;\r
21 import org.opendaylight.controller.sal.utils.NodeCreator;\r
22 \r
23 public class HostNodeConnectorTest {\r
24 \r
25     @Test\r
26     public void testHostNodeConnector() throws UnknownHostException {\r
27         HostNodeConnector hostnodeconnector_1, hostnodeconnector_2, hostnodeconnector_3;\r
28         InetAddress hostIP_1 = InetAddress.getByName("192.168.0.8");\r
29         InetAddress hostIP_2 = InetAddress\r
30                 .getByName("2001:420:281:1004:e123:e688:d655:a1b0");\r
31         InetAddress hostIP_3 = InetAddress.getByName("192.168.0.28");\r
32         byte[] hostMAC_2 = new byte[] { (byte) 0x11, (byte) 0x22, (byte) 0x33,\r
33                 (byte) 0x22, (byte) 0x22, (byte) 0x22 };\r
34         byte[] hostMAC_3 = new byte[] { (byte) 0x11, (byte) 0x22, (byte) 0x33,\r
35                 (byte) 0x33, (byte) 0x33, (byte) 0x33 };\r
36 \r
37         Node node = NodeCreator.createOFNode(1L);\r
38         NodeConnector nc1 = NodeConnectorCreator.createOFNodeConnector(\r
39                 (short) 2, node);\r
40         NodeConnector nc2 = NodeConnectorCreator.createOFNodeConnector(\r
41                 (short) 1, node);\r
42 \r
43         try {\r
44             hostnodeconnector_1 = new HostNodeConnector(hostIP_1);\r
45             Assert.assertTrue(hostnodeconnector_1.equalsByIP(hostIP_1));\r
46             Assert.assertTrue(hostnodeconnector_1.isV4Host());\r
47             Assert.assertTrue(hostnodeconnector_1.equalsByIP(hostIP_1));\r
48         } catch (ConstructionException e) {\r
49             Assert.assertTrue(false);\r
50         }\r
51 \r
52         try {\r
53             hostnodeconnector_2 = new HostNodeConnector(hostMAC_2, hostIP_2,\r
54                     nc1, (short) 2);\r
55             Assert.assertTrue(hostnodeconnector_2.isV6Host());\r
56             Assert.assertTrue(hostnodeconnector_2.getnodeConnector()\r
57                     .equals(nc1));\r
58             Assert.assertTrue(hostnodeconnector_2.getnodeconnectorNode()\r
59                     .equals(node));\r
60             Assert.assertTrue(node.equals(hostnodeconnector_2\r
61                     .getnodeconnectorNode()));\r
62         } catch (ConstructionException e) {\r
63             Assert.assertTrue(false);\r
64         }\r
65 \r
66         try {\r
67             hostnodeconnector_3 = new HostNodeConnector(new EthernetAddress(\r
68                     hostMAC_3), hostIP_3, nc2, (short) 3);\r
69             byte[] hostMAC_3_rb = hostnodeconnector_3\r
70                     .getDataLayerAddressBytes();\r
71             HostNodeConnector hostnodeconnector_3rb = new HostNodeConnector(\r
72                     new EthernetAddress(hostMAC_3_rb), hostIP_3, nc2, (short) 3);\r
73             Assert.assertTrue(hostnodeconnector_3.equals(hostnodeconnector_3rb));\r
74 \r
75             Assert.assertTrue(hostnodeconnector_3.getVlan() == (short) 3);\r
76 \r
77             hostnodeconnector_3.setStaticHost(true);\r
78             Assert.assertTrue(hostnodeconnector_3.isStaticHost());\r
79 \r
80             Assert.assertTrue(hostnodeconnector_3.isRewriteEnabled());\r
81 \r
82             hostnodeconnector_3.initArpSendCountDown().setArpSendCountDown(\r
83                     (short) 10);\r
84             Assert.assertTrue(hostnodeconnector_3.getArpSendCountDown() == (short) 10);\r
85 \r
86         } catch (ConstructionException e) {\r
87             Assert.assertTrue(false);\r
88         }\r
89 \r
90     }\r
91 \r
92 }\r