2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.lispflowmapping.type.lisp.address;
11 import java.util.ArrayList;
12 import java.util.List;
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;
19 import org.opendaylight.lispflowmapping.type.AddressFamilyNumberEnum;
21 @XmlRootElement(name="LispAddressGeneric")
22 @XmlAccessorType(XmlAccessType.NONE)
23 public class LispAddressGeneric{
56 LispAddressGeneric address;
59 LispAddressGeneric srcAddress;
62 LispAddressGeneric dstAddress;
80 List<LispAddressGeneric> hops;
83 List<LispAddressGeneric> addresses;
86 String distinguishedName;
89 public LispAddressGeneric(){}
92 public LispAddressGeneric(int afi) {
96 public LispAddressGeneric(int afi, String address) {
99 AddressFamilyNumberEnum afiEnum = AddressFamilyNumberEnum.valueOf((short) afi);
103 asNum = Integer.valueOf(address);
110 throw new IllegalArgumentException("AFI " + afi +
111 " not supported by this constructor: LispAddressGeneric(int afi, String address)");
115 public LispAddressGeneric(int afi, LispAddressGeneric address) {
117 this.address = address;
123 public LispAddressGeneric(LispAddress lispAddress) {
125 afi = lispAddress.getAfi().getIanaCode();
127 switch (lispAddress.getAfi()){
129 LispIpv4Address ipv4Address = (LispIpv4Address) lispAddress;
130 ipAddress = ipv4Address.getAddress().getHostAddress();
133 LispASAddress asAddress = (LispASAddress) lispAddress;
134 asNum = asAddress.getAS();
137 LispIpv6Address ipv6Address = (LispIpv6Address) lispAddress;
138 ipAddress = ipv6Address.getAddress().getHostAddress();
141 LispMACAddress macAddress = (LispMACAddress) lispAddress;
142 mac = macAddress.getMAC();
144 case DISTINGUISHED_NAME:
145 LispDistinguishedNameAddress distinguishedNameAddress = (LispDistinguishedNameAddress) lispAddress;
146 distinguishedName = distinguishedNameAddress.getDistinguishedName();
149 LispLCAFAddress lcafAddress = (LispLCAFAddress) lispAddress;
150 lcafType = lcafAddress.getType().getLispCode();
152 switch (lcafAddress.getType()){
153 case APPLICATION_DATA:
154 applicationDataGeneric(lcafAddress);
157 listGeneric(lcafAddress);
160 segmentGeneric(lcafAddress);
163 srcDstGeneric(lcafAddress);
165 case TRAFFIC_ENGINEERING:
166 trafficEngineeringGeneric(lcafAddress);
169 throw new IllegalArgumentException("LCAF type " + lcafAddress.getType() +
170 " not supported by this constructor: LispAddressGeneric(LispAddress lispAddress)");
174 throw new IllegalArgumentException("AFI " + afi +
175 " not supported by this constructor: LispAddressGeneric(LispAddress lispAddress)");
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());
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)));
196 private void segmentGeneric(LispLCAFAddress lcafAddress){
197 LispSegmentLCAFAddress segmentAddress = (LispSegmentLCAFAddress) lcafAddress;
198 instanceId = segmentAddress.getInstanceId();
199 address = new LispAddressGeneric(segmentAddress);
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();
210 private void trafficEngineeringGeneric(LispLCAFAddress lcafAddress){
211 LispTrafficEngineeringLCAFAddress teAddress = (LispTrafficEngineeringLCAFAddress) lcafAddress;
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()));
228 public String getIpAddress() {
232 public void setIpAddress(String ipAddress) {
233 this.ipAddress = ipAddress;
236 public int getAfi() {
240 public void setAfi(int afi) {
244 public int getInstanceId() {
248 public void setInstanceId(int iid) {
249 this.instanceId = iid;
252 public byte[] getMac() {
256 public void setMac(byte[] mac) {
260 public int getAsNum() {
264 public void setAsNum(int asNum) {
268 public int getLcafType() {
272 public void setLcafType(int lcafType) {
273 this.lcafType = lcafType;
276 public byte getProtocol() {
280 public void setProtocol(byte protocol) {
281 this.protocol = protocol;
284 public short getLocalPort() {
288 public void setLocalPort(short localPort) {
289 this.localPort = localPort;
292 public short getRemotePort() {
296 public void setRemotePort(short remotePort) {
297 this.remotePort = remotePort;
300 public LispAddressGeneric getSrcAddress() {
304 public void setSrcAddress(LispAddressGeneric srcAddress) {
305 this.srcAddress = srcAddress;
308 public LispAddressGeneric getDstAddress() {
312 public void setDstAddress(LispAddressGeneric dstAddress) {
313 this.dstAddress = dstAddress;
316 public byte getSrcMaskLength() {
317 return srcMaskLength;
320 public void setSrcMaskLength(byte srcMaskLength) {
321 this.srcMaskLength = srcMaskLength;
324 public byte getDstMaskLength() {
325 return dstMaskLength;
328 public void setDstMaskLength(byte dstMaskLength) {
329 this.dstMaskLength = dstMaskLength;
332 public boolean isLookup() {
336 public void setLookup(boolean lookup) {
337 this.lookup = lookup;
340 public boolean isRLOCProbe() {
344 public void setRLOCProbe(boolean rLOCProbe) {
345 RLOCProbe = rLOCProbe;
348 public boolean isStrict() {
352 public void setStrict(boolean strict) {
353 this.strict = strict;
356 public List<LispAddressGeneric> getHops() {
360 public void setHops(List<LispAddressGeneric> hops) {
364 public LispAddressGeneric getAddress() {
368 public void setAddress(LispAddressGeneric address) {
369 this.address = address;
372 public List<LispAddressGeneric> getAddresses() {
376 public void setAddresses(List<LispAddressGeneric> addresses) {
377 this.addresses = addresses;
381 public int getIpTos() {
386 public void setIpTos(int ipTos) {
391 public String getDistinguishedName() {
392 return distinguishedName;
396 public void setDistinguishedName(String distinguishedName) {
397 this.distinguishedName = distinguishedName;