Upgrade ietf-{inet,yang}-types to 2013-07-15
[vpnservice.git] / neutronvpn / neutronvpn-api / src / main / java / org / opendaylight / vpnservice / neutronvpn / api / l2gw / L2GatewayDevice.java
1 /*
2  * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. 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.vpnservice.neutronvpn.api.l2gw;
10
11 import java.util.ArrayList;
12 import java.util.Collections;
13 import java.util.List;
14 import java.util.concurrent.atomic.AtomicBoolean;
15
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
17 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LocalUcastMacs;
19
20 /**
21  * The Class L2GatewayDevice.
22  */
23 public class L2GatewayDevice {
24
25     /** The device name. */
26     String deviceName;
27
28     /** The hwvtep node id. */
29     String hwvtepNodeId;
30
31     /** The tunnel ips. */
32     List<IpAddress> tunnelIps = new ArrayList<IpAddress>();
33
34     /** The l2 gateway ids. */
35     List<Uuid> l2GatewayIds = new ArrayList<Uuid>();
36
37     /** The ucast local macs. */
38     List<LocalUcastMacs> ucastLocalMacs = Collections.synchronizedList(new ArrayList<LocalUcastMacs>());
39
40     /** the status of this device connectin */
41     AtomicBoolean connected = new AtomicBoolean(true);
42
43     /**
44      * VTEP device name mentioned with L2 Gateway.
45      *
46      * @return the device name
47      */
48     public String getDeviceName() {
49         return deviceName;
50     }
51
52     /**
53      * Sets the device name.
54      *
55      * @param deviceName
56      *            the new device name
57      */
58     public void setDeviceName(String deviceName) {
59         this.deviceName = deviceName;
60     }
61
62     /**
63      * VTEP Node id for the device mentioned with L2 Gateway.
64      *
65      * @return the hwvtep node id
66      */
67     public String getHwvtepNodeId() {
68         return hwvtepNodeId;
69     }
70
71     /**
72      * Sets the hwvtep node id.
73      *
74      * @param nodeId
75      *            the new hwvtep node id
76      */
77     public void setHwvtepNodeId(String nodeId) {
78         this.hwvtepNodeId = nodeId;
79     }
80
81     /**
82      * Tunnel IP created with in the device mentioned with L2 Gateway.
83      *
84      * @return the tunnel ips
85      */
86     public List<IpAddress> getTunnelIps() {
87         return tunnelIps;
88     }
89
90     /**
91      * Gets the tunnel ip.
92      *
93      * @return the tunnel ip
94      */
95     public IpAddress getTunnelIp() {
96         if (tunnelIps.size() > 0) {
97             return tunnelIps.get(0);
98         }
99         return null;
100     }
101
102     /**
103      * Adds the tunnel ip.
104      *
105      * @param tunnelIp
106      *            the tunnel ip
107      */
108     public void addTunnelIp(IpAddress tunnelIp) {
109         tunnelIps.add(tunnelIp);
110     }
111
112     /**
113      * UUID representing L2Gateway.
114      *
115      * @return the l2 gateway ids
116      */
117     public List<Uuid> getL2GatewayIds() {
118         return l2GatewayIds;
119     }
120
121     /**
122      * Adds the l2 gateway id.
123      *
124      * @param l2GatewayId
125      *            the l2 gateway id
126      */
127     public void addL2GatewayId(Uuid l2GatewayId) {
128         l2GatewayIds.add(l2GatewayId);
129     }
130
131     /**
132      * Removes the l2 gateway id.
133      *
134      * @param l2GatewayId
135      *            the l2 gateway id
136      */
137     public void removeL2GatewayId(Uuid l2GatewayId) {
138         l2GatewayIds.remove(l2GatewayId);
139     }
140
141     /**
142      * Clear hwvtep node data.
143      */
144     public void clearHwvtepNodeData() {
145         tunnelIps.clear();
146         hwvtepNodeId = null;
147     }
148
149     /**
150      * Sets the tunnel ips.
151      *
152      * @param tunnelIps
153      *            the new tunnel ips
154      */
155     public void setTunnelIps(List<IpAddress> tunnelIps) {
156         this.tunnelIps = tunnelIps;
157     }
158
159     /**
160      * Gets the ucast local macs.
161      *
162      * @return the ucast local macs
163      */
164     public List<LocalUcastMacs> getUcastLocalMacs() {
165         return new ArrayList<>(ucastLocalMacs);
166     }
167
168     /**
169      * Adds the ucast local mac.
170      *
171      * @param localUcastMacs
172      *            the local ucast macs
173      */
174     public void addUcastLocalMac(LocalUcastMacs localUcastMacs) {
175         ucastLocalMacs.add(localUcastMacs);
176     }
177
178     /**
179      * Removes the ucast local mac.
180      *
181      * @param localUcastMacs
182      *            the local ucast macs
183      */
184     public void removeUcastLocalMac(LocalUcastMacs localUcastMacs) {
185         ucastLocalMacs.remove(localUcastMacs);
186     }
187
188     public boolean isConnected() {
189         return connected.get();
190     }
191
192     public void setConnected(boolean connected) {
193         this.connected.set(connected);
194     }
195
196     /*
197      * (non-Javadoc)
198      *
199      * @see java.lang.Object#hashCode()
200      */
201     @Override
202     public int hashCode() {
203         final int prime = 31;
204         int result = 1;
205         result = prime * result + ((deviceName == null) ? 0 : deviceName.hashCode());
206         result = prime * result + ((hwvtepNodeId == null) ? 0 : hwvtepNodeId.hashCode());
207         result = prime * result + ((l2GatewayIds == null) ? 0 : l2GatewayIds.hashCode());
208         result = prime * result + ((tunnelIps == null) ? 0 : tunnelIps.hashCode());
209         result = prime * result + ((ucastLocalMacs == null) ? 0 : ucastLocalMacs.hashCode());
210         return result;
211     }
212
213     /*
214      * (non-Javadoc)
215      *
216      * @see java.lang.Object#equals(java.lang.Object)
217      */
218     @Override
219     public boolean equals(Object obj) {
220         if (this == obj) {
221             return true;
222         }
223         if (obj == null) {
224             return false;
225         }
226         if (getClass() != obj.getClass()) {
227             return false;
228         }
229         L2GatewayDevice other = (L2GatewayDevice) obj;
230         if (deviceName == null) {
231             if (other.deviceName != null) {
232                 return false;
233             }
234         } else if (!deviceName.equals(other.deviceName)) {
235             return false;
236         }
237         if (hwvtepNodeId == null) {
238             if (other.hwvtepNodeId != null) {
239                 return false;
240             }
241         } else if (!hwvtepNodeId.equals(other.hwvtepNodeId)) {
242             return false;
243         }
244         if (l2GatewayIds == null) {
245             if (other.l2GatewayIds != null) {
246                 return false;
247             }
248         } else if (!l2GatewayIds.equals(other.l2GatewayIds)) {
249             return false;
250         }
251         if (tunnelIps == null) {
252             if (other.tunnelIps != null) {
253                 return false;
254             }
255         } else if (!tunnelIps.equals(other.tunnelIps)) {
256             return false;
257         }
258         if (ucastLocalMacs == null) {
259             if (other.ucastLocalMacs != null) {
260                 return false;
261             }
262         } else if (!ucastLocalMacs.equals(other.ucastLocalMacs)) {
263             return false;
264         }
265         return true;
266     }
267
268     /*
269      * (non-Javadoc)
270      *
271      * @see java.lang.Object#toString()
272      */
273     @Override
274     public String toString() {
275         StringBuilder builder = new StringBuilder();
276         builder.append("L2GatewayDevice [deviceName=").append(deviceName).append(", hwvtepNodeId=").append(hwvtepNodeId)
277                 .append(", tunnelIps=").append(tunnelIps).append(", l2GatewayIds=").append(l2GatewayIds)
278                 .append(", ucastLocalMacs=").append(ucastLocalMacs).append("]");
279         return builder.toString();
280     }
281
282 }