Merge "Bug 1029: Remove dead code: samples/clustersession"
[controller.git] / opendaylight / adsal / northbound / hosttracker / src / main / java / org / opendaylight / controller / hosttracker / northbound / HostConfig.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.controller.hosttracker.northbound;
10
11 import java.io.Serializable;
12
13 import javax.xml.bind.annotation.XmlAccessType;
14 import javax.xml.bind.annotation.XmlAccessorType;
15 import javax.xml.bind.annotation.XmlElement;
16 import javax.xml.bind.annotation.XmlRootElement;
17
18 import org.opendaylight.controller.hosttracker.hostAware.HostNodeConnector;
19 import org.opendaylight.controller.sal.core.Node;
20 import org.opendaylight.controller.sal.core.NodeConnector;
21 import org.opendaylight.controller.sal.packet.address.DataLinkAddress;
22 import org.opendaylight.controller.sal.packet.address.EthernetAddress;
23
24 /**
25  * Configuration Java Object which represents a Host configuration information
26  * for HostTracker.
27  */
28 @XmlRootElement
29 @XmlAccessorType(XmlAccessType.NONE)
30 public class HostConfig implements Serializable {
31     private static final long serialVersionUID = 1L;
32
33     @XmlElement
34     public String dataLayerAddress;
35     @XmlElement
36     private String nodeType;
37     @XmlElement
38     private String nodeId;
39     @XmlElement
40     private String nodeConnectorType;
41     @XmlElement
42     private String nodeConnectorId;
43     @XmlElement
44     private String vlan;
45     @XmlElement
46     private boolean staticHost;
47     @XmlElement
48     private String networkAddress;
49
50     public HostConfig() {
51
52     }
53
54     protected String getDataLayerAddress() {
55         return this.dataLayerAddress;
56     }
57
58     protected String getNodeType() {
59         return this.nodeType;
60     }
61
62     protected String getNodeId() {
63         return this.nodeId;
64     }
65
66     protected String getNodeConnectorType() {
67         return this.nodeConnectorType;
68     }
69
70     protected String getNodeConnectorId() {
71         return this.nodeConnectorId;
72     }
73
74     protected String getVlan() {
75         return this.vlan;
76     }
77
78     protected boolean isStaticHost() {
79         return staticHost;
80     }
81
82     protected String getNetworkAddress() {
83         return networkAddress;
84     }
85
86     public static HostConfig convert(HostNodeConnector hnc) {
87         if(hnc == null) {
88             return null;
89         }
90         HostConfig hc = new HostConfig();
91         DataLinkAddress dl = hnc.getDataLayerAddress();
92         if(dl instanceof EthernetAddress) {
93             EthernetAddress et = (EthernetAddress) dl;
94             hc.dataLayerAddress = et.getMacAddress();
95         } else {
96             hc.dataLayerAddress = dl.getName();
97         }
98         NodeConnector nc = hnc.getnodeConnector();
99         if(nc != null) {
100             hc.nodeConnectorType = nc.getType();
101             hc.nodeConnectorId = nc.getNodeConnectorIDString();
102             Node n = hnc.getnodeconnectorNode();
103             if(n != null) {
104                 hc.nodeType = n.getType();
105                 hc.nodeId = n.getNodeIDString();
106             }
107         }
108         hc.vlan = String.valueOf(hnc.getVlan());
109         hc.staticHost = hnc.isStaticHost();
110         hc.networkAddress = hnc.getNetworkAddressAsString();
111         return hc;
112     }
113 }