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