changed license year
[lispflowmapping.git] / mappingservice / api / src / main / java / org / opendaylight / lispflowmapping / type / lisp / address / LispAddressGeneric.java
1 /*
2  * Copyright (c) 2014 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.lispflowmapping.type.lisp.address;
10
11 import java.util.ArrayList;
12 import java.util.List;
13
14 import javax.xml.bind.annotation.XmlAccessType;
15 import javax.xml.bind.annotation.XmlAccessorType;
16 import javax.xml.bind.annotation.XmlElement;
17 import javax.xml.bind.annotation.XmlRootElement;
18
19 import org.opendaylight.lispflowmapping.type.AddressFamilyNumberEnum;
20
21 @XmlRootElement(name="LispAddressGeneric")
22 @XmlAccessorType(XmlAccessType.NONE)
23 public class LispAddressGeneric{
24
25         @XmlElement
26         int afi;
27         
28         @XmlElement
29         String ipAddress;
30         
31         @XmlElement
32         byte[] mac;
33         
34         @XmlElement
35         int instanceId;
36         
37         @XmlElement
38         int asNum;
39         
40         @XmlElement
41         int lcafType;
42         
43         @XmlElement
44     byte protocol;
45         
46         @XmlElement
47     int ipTos;
48         
49         @XmlElement
50     short localPort;
51         
52         @XmlElement
53     short remotePort;
54         
55         @XmlElement
56     LispAddressGeneric address;
57         
58         @XmlElement
59     LispAddressGeneric srcAddress;
60         
61         @XmlElement
62     LispAddressGeneric dstAddress;
63         
64         @XmlElement
65     byte srcMaskLength;
66         
67         @XmlElement
68     byte dstMaskLength;
69         
70         @XmlElement
71     boolean lookup;
72         
73         @XmlElement
74     boolean RLOCProbe;
75         
76         @XmlElement
77     boolean strict;
78         
79         @XmlElement
80         List<LispAddressGeneric> hops;
81         
82         @XmlElement
83         List<LispAddressGeneric> addresses;
84         
85         @XmlElement
86         String distinguishedName;
87         
88         
89         public LispAddressGeneric(){}
90         
91         
92         public LispAddressGeneric(int afi) {
93                 this.afi = afi;
94         }
95         
96         public LispAddressGeneric(int afi, String address) {
97                 this.afi = afi;
98                 
99                 AddressFamilyNumberEnum afiEnum = AddressFamilyNumberEnum.valueOf((short) afi);
100                 
101                 switch (afiEnum) {
102                 case AS:
103                         asNum = Integer.valueOf(address);
104                         break;
105                 case IP:
106                 case IP6:
107                         ipAddress = address;
108                         break;                  
109                 default:
110                         throw new IllegalArgumentException("AFI " + afi + 
111                                         " not supported by this constructor: LispAddressGeneric(int afi, String address)");
112                 }
113         }
114         
115         public LispAddressGeneric(int afi, LispAddressGeneric address) {
116                 this.afi = afi;
117                 this.address = address;
118         }
119         
120         
121
122         
123         public LispAddressGeneric(LispAddress lispAddress) {
124                 
125                 afi = lispAddress.getAfi().getIanaCode();
126                 
127                 switch (lispAddress.getAfi()){
128                 case IP:
129                         LispIpv4Address ipv4Address = (LispIpv4Address) lispAddress;
130                         ipAddress = ipv4Address.getAddress().getHostAddress();
131                         break;
132                 case AS:
133                         LispASAddress asAddress = (LispASAddress) lispAddress;
134                         asNum = asAddress.getAS();
135                         break;
136                 case IP6:
137                         LispIpv6Address ipv6Address = (LispIpv6Address) lispAddress;
138                         ipAddress = ipv6Address.getAddress().getHostAddress();
139                         break;
140                 case MAC:
141                         LispMACAddress macAddress = (LispMACAddress) lispAddress;
142                         mac = macAddress.getMAC();
143                         break;
144                 case DISTINGUISHED_NAME:
145                         LispDistinguishedNameAddress distinguishedNameAddress = (LispDistinguishedNameAddress) lispAddress;
146                         distinguishedName = distinguishedNameAddress.getDistinguishedName();
147                         break;
148                 case LCAF:
149                         LispLCAFAddress lcafAddress = (LispLCAFAddress) lispAddress;
150                         lcafType = lcafAddress.getType().getLispCode();
151                         
152                         switch (lcafAddress.getType()){
153                         case APPLICATION_DATA:
154                                 applicationDataGeneric(lcafAddress);
155                                 break;
156                         case LIST:
157                                 listGeneric(lcafAddress);
158                                 break;
159                         case SEGMENT:
160                                 segmentGeneric(lcafAddress);
161                                 break;
162                         case SOURCE_DEST:
163                                 srcDstGeneric(lcafAddress);
164                                 break;
165                         case TRAFFIC_ENGINEERING:
166                                 trafficEngineeringGeneric(lcafAddress);
167                                 break;
168                         default:
169                                 throw new IllegalArgumentException("LCAF type " + lcafAddress.getType() + 
170                                                 " not supported by this constructor: LispAddressGeneric(LispAddress lispAddress)");
171                         }
172                         break;
173                 default:
174                         throw new IllegalArgumentException("AFI " + afi + 
175                                         " not supported by this constructor: LispAddressGeneric(LispAddress lispAddress)");
176                 }
177         }
178         
179         private void applicationDataGeneric(LispLCAFAddress lcafAddress){
180                 LispApplicationDataLCAFAddress appDataAddress = (LispApplicationDataLCAFAddress) lcafAddress; 
181             protocol = appDataAddress.getProtocol();
182             ipTos = appDataAddress.getIPTos();
183             localPort = appDataAddress.getLocalPort();
184             remotePort = appDataAddress.getLocalPort();
185             address = new LispAddressGeneric(appDataAddress.getAddress());
186         }
187         
188         private void listGeneric(LispLCAFAddress lcafAddress){
189                 LispListLCAFAddress listAddress = (LispListLCAFAddress) lcafAddress;
190                 addresses = new ArrayList<LispAddressGeneric>();
191                 for(int i=0;i<listAddress.getAddresses().size();i++){
192                         addresses.add(new LispAddressGeneric(listAddress.getAddresses().get(i)));
193                 }
194         }
195         
196         private void segmentGeneric(LispLCAFAddress lcafAddress){
197                 LispSegmentLCAFAddress segmentAddress = (LispSegmentLCAFAddress) lcafAddress;
198                 instanceId = segmentAddress.getInstanceId();
199                 address = new LispAddressGeneric(segmentAddress);
200         }
201         
202         private void srcDstGeneric(LispLCAFAddress lcafAddress){
203                 LispSourceDestLCAFAddress srcDstAddress = (LispSourceDestLCAFAddress) lcafAddress;
204             srcAddress = new LispAddressGeneric(srcDstAddress.getSrcAddress());
205             dstAddress = new LispAddressGeneric(srcDstAddress.getDstAddress());
206             srcMaskLength = srcDstAddress.getSrcMaskLength();
207             dstMaskLength = srcDstAddress.getDstMaskLength();
208         }
209         
210         private void trafficEngineeringGeneric(LispLCAFAddress lcafAddress){
211                 LispTrafficEngineeringLCAFAddress teAddress = (LispTrafficEngineeringLCAFAddress) lcafAddress;
212                 
213                 hops = new ArrayList<LispAddressGeneric>();
214                 for(int i=0;i<teAddress.getHops().size();i++){
215                         LispAddressGeneric hop = new LispAddressGeneric(AddressFamilyNumberEnum.UNKNOWN.getIanaCode());
216                         hop.setLookup(teAddress.getHops().get(i).isLookup());
217                         hop.setRLOCProbe(teAddress.getHops().get(i).isRLOCProbe());
218                         hop.setStrict(teAddress.getHops().get(i).isStrict());
219                         hop.setAddress(new LispAddressGeneric(teAddress.getHops().get(i).getHop()));
220                         hops.add(hop);
221                 }
222         }
223
224         
225         
226         
227         
228         public String getIpAddress() {
229                 return ipAddress;
230         }
231
232         public void setIpAddress(String ipAddress) {
233                 this.ipAddress = ipAddress;
234         }
235
236         public int getAfi() {
237                 return afi;
238         }
239
240         public void setAfi(int afi) {
241                 this.afi = afi;
242         }
243         
244     public int getInstanceId() {
245                 return instanceId;
246         }
247
248         public void setInstanceId(int iid) {
249                 this.instanceId = iid;
250         }
251
252         public byte[] getMac() {
253                 return mac;
254         }
255
256         public void setMac(byte[] mac) {
257                 this.mac = mac;
258         }
259
260         public int getAsNum() {
261                 return asNum;
262         }
263
264         public void setAsNum(int asNum) {
265                 this.asNum = asNum;
266         }
267
268         public int getLcafType() {
269                 return lcafType;
270         }
271
272         public void setLcafType(int lcafType) {
273                 this.lcafType = lcafType;
274         }
275
276         public byte getProtocol() {
277                 return protocol;
278         }
279
280         public void setProtocol(byte protocol) {
281                 this.protocol = protocol;
282         }
283
284         public short getLocalPort() {
285                 return localPort;
286         }
287
288         public void setLocalPort(short localPort) {
289                 this.localPort = localPort;
290         }
291
292         public short getRemotePort() {
293                 return remotePort;
294         }
295
296         public void setRemotePort(short remotePort) {
297                 this.remotePort = remotePort;
298         }
299
300         public LispAddressGeneric getSrcAddress() {
301                 return srcAddress;
302         }
303
304         public void setSrcAddress(LispAddressGeneric srcAddress) {
305                 this.srcAddress = srcAddress;
306         }
307
308         public LispAddressGeneric getDstAddress() {
309                 return dstAddress;
310         }
311
312         public void setDstAddress(LispAddressGeneric dstAddress) {
313                 this.dstAddress = dstAddress;
314         }
315
316         public byte getSrcMaskLength() {
317                 return srcMaskLength;
318         }
319
320         public void setSrcMaskLength(byte srcMaskLength) {
321                 this.srcMaskLength = srcMaskLength;
322         }
323
324         public byte getDstMaskLength() {
325                 return dstMaskLength;
326         }
327
328         public void setDstMaskLength(byte dstMaskLength) {
329                 this.dstMaskLength = dstMaskLength;
330         }
331
332         public boolean isLookup() {
333                 return lookup;
334         }
335
336         public void setLookup(boolean lookup) {
337                 this.lookup = lookup;
338         }
339
340         public boolean isRLOCProbe() {
341                 return RLOCProbe;
342         }
343
344         public void setRLOCProbe(boolean rLOCProbe) {
345                 RLOCProbe = rLOCProbe;
346         }
347
348         public boolean isStrict() {
349                 return strict;
350         }
351
352         public void setStrict(boolean strict) {
353                 this.strict = strict;
354         }
355
356         public List<LispAddressGeneric> getHops() {
357                 return hops;
358         }
359
360         public void setHops(List<LispAddressGeneric> hops) {
361                 this.hops = hops;
362         }
363         
364         public LispAddressGeneric getAddress() {
365                 return address;
366         }
367
368         public void setAddress(LispAddressGeneric address) {
369                 this.address = address;
370         }
371
372         public List<LispAddressGeneric> getAddresses() {
373                 return addresses;
374         }
375
376         public void setAddresses(List<LispAddressGeneric> addresses) {
377                 this.addresses = addresses;
378         }
379
380
381         public int getIpTos() {
382                 return ipTos;
383         }
384
385
386         public void setIpTos(int ipTos) {
387                 this.ipTos = ipTos;
388         }
389
390
391         public String getDistinguishedName() {
392                 return distinguishedName;
393         }
394
395
396         public void setDistinguishedName(String distinguishedName) {
397                 this.distinguishedName = distinguishedName;
398         }
399
400     
401 }