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