/* * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.lispflowmapping.type.lisp.address; import java.util.ArrayList; import java.util.List; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import org.opendaylight.lispflowmapping.type.AddressFamilyNumberEnum; import org.opendaylight.lispflowmapping.type.LispCanonicalAddressFormatEnum; @XmlRootElement(name="LispAddressGeneric") @XmlAccessorType(XmlAccessType.NONE) public class LispAddressGeneric{ @XmlElement int afi; @XmlElement String ipAddress; @XmlElement byte[] mac; @XmlElement int instanceId; @XmlElement int asNum; @XmlElement int lcafType; @XmlElement byte protocol; @XmlElement int ipTos; @XmlElement short localPort; @XmlElement short remotePort; @XmlElement LispAddressGeneric address; @XmlElement LispAddressGeneric srcAddress; @XmlElement LispAddressGeneric dstAddress; @XmlElement byte srcMaskLength; @XmlElement byte dstMaskLength; @XmlElement boolean lookup; @XmlElement boolean RLOCProbe; @XmlElement boolean strict; @XmlElement List hops; @XmlElement List addresses; public LispAddressGeneric(){} public LispAddressGeneric(int afi) { this.afi = afi; } public LispAddressGeneric(int afi, String address) { this.afi = afi; AddressFamilyNumberEnum afiEnum = AddressFamilyNumberEnum.valueOf((short) afi); switch (afiEnum) { case AS: asNum = Integer.valueOf(address); break; case IP: case IP6: ipAddress = address; break; default: throw new IllegalArgumentException("AFI " + afi + " not supported by this constructor: LispAddressGeneric(int afi, String address)"); } } public LispAddressGeneric(int afi, LispAddressGeneric address) { this.afi = afi; this.address = address; } public LispAddressGeneric(LispAddress lispAddress) { afi = lispAddress.getAfi().getIanaCode(); switch (lispAddress.getAfi()){ case IP: LispIpv4Address ipv4Address = (LispIpv4Address) lispAddress; ipAddress = ipv4Address.getAddress().getHostAddress(); break; case AS: LispASAddress asAddress = (LispASAddress) lispAddress; asNum = asAddress.getAS(); break; case IP6: LispIpv6Address ipv6Address = (LispIpv6Address) lispAddress; ipAddress = ipv6Address.getAddress().getHostAddress(); break; case MAC: LispMACAddress macAddress = (LispMACAddress) lispAddress; mac = macAddress.getMAC(); break; case LCAF: LispLCAFAddress lcafAddress = (LispLCAFAddress) lispAddress; lcafType = lcafAddress.getType().getLispCode(); switch (lcafAddress.getType()){ case APPLICATION_DATA: applicationDataGeneric(lcafAddress); break; case LIST: listGeneric(lcafAddress); break; case SEGMENT: segmentGeneric(lcafAddress); break; case SOURCE_DEST: srcDstGeneric(lcafAddress); break; case TRAFFIC_ENGINEERING: trafficEngineeringGeneric(lcafAddress); break; default: throw new IllegalArgumentException("LCAF type " + lcafAddress.getType() + " not supported by this constructor: LispAddressGeneric(LispAddress lispAddress)"); } break; default: throw new IllegalArgumentException("AFI " + afi + " not supported by this constructor: LispAddressGeneric(LispAddress lispAddress)"); } } private void applicationDataGeneric(LispLCAFAddress lcafAddress){ LispApplicationDataLCAFAddress appDataAddress = (LispApplicationDataLCAFAddress) lcafAddress; protocol = appDataAddress.getProtocol(); ipTos = appDataAddress.getIPTos(); localPort = appDataAddress.getLocalPort(); remotePort = appDataAddress.getLocalPort(); address = new LispAddressGeneric(appDataAddress.getAddress()); } private void listGeneric(LispLCAFAddress lcafAddress){ LispListLCAFAddress listAddress = (LispListLCAFAddress) lcafAddress; addresses = new ArrayList(); for(int i=0;i(); for(int i=0;i getHops() { return hops; } public void setHops(List hops) { this.hops = hops; } public LispAddressGeneric getAddress() { return address; } public void setAddress(LispAddressGeneric address) { this.address = address; } public List getAddresses() { return addresses; } public void setAddresses(List addresses) { this.addresses = addresses; } }