<mdsal.model.version>0.8.0-SNAPSHOT</mdsal.model.version>
<neutron.version>0.6.0-SNAPSHOT</neutron.version>
<restconf.version>1.3.0-SNAPSHOT</restconf.version>
- <!-- Temporary -->
- <skipTests>true</skipTests>
</properties>
<dependencyManagement>
<repository>mvn:org.opendaylight.netconf/features-restconf/{{VERSION}}/xml/features</repository>
<!-- Needed for odl-config-api -->
<repository>mvn:org.opendaylight.controller/features-config/{{VERSION}}/xml/features</repository>
+ <!--
<repository>mvn:org.opendaylight.neutron/features-neutron/{{VERSION}}/xml/features</repository>
<repository>mvn:org.opendaylight.dlux/features-dlux/{{VERSION}}/xml/features</repository>
+ -->
<!--
<feature name="odl-lispflowmapping-msmr" description="OpenDaylight :: LISP Flow Mapping :: Map-Server/Map-Resolver" version='${project.version}'>
</configfile>
</feature>
+ <feature name="odl-lispflowmapping-mappingservice-shell" description="OpenDaylight :: LISP Flow Mapping :: Mappingservice Shell" version='${project.version}'>
+ <feature version="${project.version}">odl-lispflowmapping-mappingservice</feature>
+ <bundle>mvn:org.opendaylight.lispflowmapping/mappingservice.shell/{{VERSION}}</bundle>
+ </feature>
+
<feature name="odl-lispflowmapping-inmemorydb" description="OpenDaylight :: LISP Flow Mapping :: In Memory DB" version='${project.version}'>
<feature version="${mdsal.version}">odl-mdsal-broker</feature>
<feature version='${project.version}'>odl-lispflowmapping-models</feature>
<feature name="odl-lispflowmapping-models" description="OpenDaylight :: LISP Flow Mapping :: Models" version='${project.version}'>
<feature version='${config.version}'>odl-config-api</feature>
<feature version='${mdsal.model.version}'>odl-mdsal-models</feature>
- <!-- Temporary: add APIDOCS so we don't have to load manually while testing IETF LISP address models -->
- <feature version='${mdsal.version}'>odl-mdsal-apidocs</feature>
<bundle>mvn:org.apache.commons/commons-lang3/{{VERSION}}</bundle>
<bundle>mvn:org.opendaylight.lispflowmapping/mappingservice.lisp-proto/{{VERSION}}</bundle>
<bundle>mvn:org.opendaylight.lispflowmapping/mappingservice.api/{{VERSION}}</bundle>
</feature>
-
- <feature name="odl-lispflowmapping-mappingservice-shell" description="OpenDaylight :: LISP Flow Mapping :: Mappingservice Shell" version='${project.version}'>
- <feature version="${project.version}">odl-lispflowmapping-mappingservice</feature>
- <bundle>mvn:org.opendaylight.lispflowmapping/mappingservice.shell/{{VERSION}}</bundle>
- </feature>
</features>
* The address of the ETR
*/
void handleNonProxyMapRequest(MapRequest mapRequest, TransportAddress transportAddress);
-}
\ No newline at end of file
+}
<groupId>org.opendaylight.mdsal.model</groupId>
<artifactId>ietf-yang-types</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.mdsal.model</groupId>
+ <artifactId>iana-afn-safi</artifactId>
+ </dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
</dependencies>
- <!-- Temporarily disable compiling non-generated code, like serializers, which won't build for now -->
<build>
<pluginManagement>
<plugins>
</plugin>
</plugins>
</pluginManagement>
-
- <plugins>
- <plugin>
- <artifactId>maven-compiler-plugin</artifactId>
- <executions>
- <execution>
- <id>default-compile</id>
- <phase>compile</phase>
- <goals>
- <goal>compile</goal>
- </goals>
- <configuration>
- <excludes>
- <exclude>org/opendaylight/lispflowmapping/**</exclude>
- </excludes>
- </configuration>
- </execution>
- <execution>
- <id>default-testCompile</id>
- <phase>test-compile</phase>
- <goals>
- <goal>testCompile</goal>
- </goals>
- <configuration>
- <skip>true</skip>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
</build>
</project>
import java.nio.ByteBuffer;
import org.opendaylight.lispflowmapping.lisp.serializer.address.LispAddressSerializer;
+import org.opendaylight.lispflowmapping.lisp.serializer.address.LispAddressSerializerContext;
import org.opendaylight.lispflowmapping.lisp.util.ByteUtil;
-import org.opendaylight.lispflowmapping.lisp.util.LispAFIConvertor;
-import org.opendaylight.lispflowmapping.lisp.util.MaskUtil;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.LispAFIAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eidrecords.EidRecord;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eidrecords.EidRecordBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
public class EidRecordSerializer {
return INSTANCE;
}
- public EidRecord deserialize(ByteBuffer requestBuffer) {
+ public Eid deserialize(ByteBuffer requestBuffer) {
/* byte reserved = */requestBuffer.get();
short maskLength = (short) (ByteUtil.getUnsignedByte(requestBuffer));
- LispAFIAddress prefix = LispAddressSerializer.getInstance().deserialize(requestBuffer);
- prefix = MaskUtil.fixMask(prefix, maskLength);
- return new EidRecordBuilder().setLispAddressContainer(LispAFIConvertor.toContainer(prefix)).setMask(maskLength)
- .build();
+ LispAddressSerializerContext ctx = new LispAddressSerializerContext(maskLength);
+ return LispAddressSerializer.getInstance().deserializeEid(requestBuffer, ctx);
}
}
import org.apache.commons.lang3.BooleanUtils;
import org.opendaylight.lispflowmapping.lisp.serializer.address.LispAddressSerializer;
import org.opendaylight.lispflowmapping.lisp.util.ByteUtil;
-import org.opendaylight.lispflowmapping.lisp.util.LispAFIConvertor;
import org.opendaylight.lispflowmapping.lisp.util.LispAddressStringifier;
import org.opendaylight.lispflowmapping.lisp.util.NumberUtil;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.LispAFIAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.LispAddressContainer;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecord;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecordBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.Rloc;
public class LocatorRecordSerializer {
builder.setLocalLocator(ByteUtil.extractBit(flags, Flags.LOCAL_LOCATOR));
builder.setRlocProbed(ByteUtil.extractBit(flags, Flags.RLOC_PROBED));
builder.setRouted(ByteUtil.extractBit(flags, Flags.ROUTED));
- LispAFIAddress afiAddress = LispAddressSerializer.getInstance().deserialize(buffer);
- LispAddressContainer locator = LispAFIConvertor.toContainer(afiAddress);
- builder.setLispAddressContainer(locator);
- builder.setName(LispAddressStringifier.getString(locator));
+ Rloc rloc = LispAddressSerializer.getInstance().deserializeRloc(buffer);
+ builder.setRloc(rloc);
+ builder.setLocatorId(LispAddressStringifier.getString(rloc));
return builder.build();
}
replyBuffer.put((byte) (ByteUtil.boolToBit(BooleanUtils.isTrue(record.isLocalLocator()), Flags.LOCAL_LOCATOR) | //
ByteUtil.boolToBit(BooleanUtils.isTrue(record.isRlocProbed()), Flags.RLOC_PROBED) | //
ByteUtil.boolToBit(BooleanUtils.isTrue(record.isRouted()), Flags.ROUTED)));
- LispAddressSerializer.getInstance().serialize(replyBuffer, LispAFIConvertor.toAFI(record.getLispAddressContainer()));
+ LispAddressSerializer.getInstance().serialize(replyBuffer, record.getRloc());
}
public int getSerializationSize(LocatorRecord record) {
return Length.HEADER_SIZE
- + LispAddressSerializer.getInstance().getAddressSize(LispAFIConvertor.toAFI(record.getLispAddressContainer()));
+ + LispAddressSerializer.getInstance().getAddressSize(record.getRloc());
}
private interface Flags {
import org.opendaylight.lispflowmapping.lisp.util.ByteUtil;
import org.opendaylight.lispflowmapping.lisp.util.NumberUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapNotify;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eidtolocatorrecords.EidToLocatorRecord;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eidtolocatorrecords.EidToLocatorRecordBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapnotifymessage.MapNotifyBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItem;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItemBuilder;
/**
* This class deals with serializing map notify from the java object to udp.
size += org.opendaylight.lispflowmapping.lisp.serializer.MapRegisterSerializer.Length.XTRID_SIZE +
org.opendaylight.lispflowmapping.lisp.serializer.MapRegisterSerializer.Length.SITEID_SIZE;
}
- for (EidToLocatorRecord eidToLocatorRecord : mapNotify.getEidToLocatorRecord()) {
- size += EidToLocatorRecordSerializer.getInstance().getSerializationSize(eidToLocatorRecord);
+ for (MappingRecordItem mappingRecord : mapNotify.getMappingRecordItem()) {
+ size += MappingRecordSerializer.getInstance().getSerializationSize(mappingRecord.getMappingRecord());
}
ByteBuffer replyBuffer = ByteBuffer.allocate(size);
replyBuffer.put((byte) (LispMessageEnum.MapNotify.getValue() << 4));
replyBuffer.position(replyBuffer.position() + Length.RES);
- if (mapNotify.getEidToLocatorRecord() != null) {
- replyBuffer.put((byte) mapNotify.getEidToLocatorRecord().size());
+ if (mapNotify.getMappingRecordItem() != null) {
+ replyBuffer.put((byte) mapNotify.getMappingRecordItem().size());
} else {
replyBuffer.put((byte) 0);
}
replyBuffer.putShort((short) 0);
}
- if (mapNotify.getEidToLocatorRecord() != null) {
- for (EidToLocatorRecord eidToLocatorRecord : mapNotify.getEidToLocatorRecord()) {
- EidToLocatorRecordSerializer.getInstance().serialize(replyBuffer, eidToLocatorRecord);
+ if (mapNotify.getMappingRecordItem() != null) {
+ for (MappingRecordItem mappingRecord : mapNotify.getMappingRecordItem()) {
+ MappingRecordSerializer.getInstance().serialize(replyBuffer, mappingRecord.getMappingRecord());
}
}
notifyBuffer.get(authenticationData);
builder.setAuthenticationData(authenticationData);
- builder.setEidToLocatorRecord(new ArrayList<EidToLocatorRecord>());
+ builder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
for (int i = 0; i < recordCount; i++) {
- builder.getEidToLocatorRecord().add(
- new EidToLocatorRecordBuilder(EidToLocatorRecordSerializer.getInstance().deserialize(notifyBuffer)).build());
+ builder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(
+ (MappingRecordSerializer.getInstance().deserialize(notifyBuffer))).build());
}
if (xtrSiteIdPresent) {
- byte[] xtrId = new byte[org.opendaylight.lispflowmapping.lisp.serializer.MapRegisterSerializer.Length.XTRID_SIZE];
+ byte[] xtrId = new byte[MapRegisterSerializer.Length.XTRID_SIZE];
notifyBuffer.get(xtrId);
- byte[] siteId = new byte[org.opendaylight.lispflowmapping.lisp.serializer.MapRegisterSerializer.Length.SITEID_SIZE];
+ byte[] siteId = new byte[MapRegisterSerializer.Length.SITEID_SIZE];
notifyBuffer.get(siteId);
builder.setXtrId(xtrId);
builder.setSiteId(siteId);
import org.opendaylight.lispflowmapping.lisp.util.ByteUtil;
import org.opendaylight.lispflowmapping.lisp.util.NumberUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapRegister;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eidtolocatorrecords.EidToLocatorRecord;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eidtolocatorrecords.EidToLocatorRecordBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItem;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItemBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapregisternotification.MapRegisterBuilder;
/**
if (mapRegister.isXtrSiteIdPresent() != null && mapRegister.isXtrSiteIdPresent()) {
size += Length.XTRID_SIZE + Length.SITEID_SIZE;
}
- for (EidToLocatorRecord eidToLocatorRecord : mapRegister.getEidToLocatorRecord()) {
- size += EidToLocatorRecordSerializer.getInstance().getSerializationSize(eidToLocatorRecord);
+ for (MappingRecordItem eidToLocatorRecord : mapRegister.getMappingRecordItem()) {
+ size += MappingRecordSerializer.getInstance().getSerializationSize(eidToLocatorRecord.getMappingRecord());
}
ByteBuffer registerBuffer = ByteBuffer.allocate(size);
ByteUtil.boolToBit(BooleanUtils.isTrue(mapRegister.isXtrSiteIdPresent()), Flags.XTRSITEID)));
registerBuffer.position(registerBuffer.position() + Length.RES);
registerBuffer.put(ByteUtil.boolToBit(BooleanUtils.isTrue(mapRegister.isWantMapNotify()), Flags.WANT_MAP_REPLY));
- registerBuffer.put((byte) mapRegister.getEidToLocatorRecord().size());
+ registerBuffer.put((byte) mapRegister.getMappingRecordItem().size());
registerBuffer.putLong(NumberUtil.asLong(mapRegister.getNonce()));
registerBuffer.putShort(NumberUtil.asShort(mapRegister.getKeyId()));
} else {
registerBuffer.putShort((short) 0);
}
- for (EidToLocatorRecord eidToLocatorRecord : mapRegister.getEidToLocatorRecord()) {
- EidToLocatorRecordSerializer.getInstance().serialize(registerBuffer, eidToLocatorRecord);
+ for (MappingRecordItem eidToLocatorRecord : mapRegister.getMappingRecordItem()) {
+ MappingRecordSerializer.getInstance().serialize(registerBuffer, eidToLocatorRecord.getMappingRecord());
}
if (mapRegister.isXtrSiteIdPresent() != null && mapRegister.isXtrSiteIdPresent()) {
public MapRegister deserialize(ByteBuffer registerBuffer) {
try {
MapRegisterBuilder builder = new MapRegisterBuilder();
- builder.setEidToLocatorRecord(new ArrayList<EidToLocatorRecord>());
+ builder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
byte typeAndFlags = registerBuffer.get();
boolean xtrSiteIdPresent = ByteUtil.extractBit(typeAndFlags, Flags.XTRSITEID);
builder.setAuthenticationData(authenticationData);
for (int i = 0; i < recordCount; i++) {
- builder.getEidToLocatorRecord().add(
- new EidToLocatorRecordBuilder(EidToLocatorRecordSerializer.getInstance().deserialize(registerBuffer)).build());
+ builder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(
+ MappingRecordSerializer.getInstance().deserialize(registerBuffer)).build());
}
if (xtrSiteIdPresent) {
import org.opendaylight.lispflowmapping.lisp.util.ByteUtil;
import org.opendaylight.lispflowmapping.lisp.util.NumberUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapReply;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eidtolocatorrecords.EidToLocatorRecord;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eidtolocatorrecords.EidToLocatorRecordBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItem;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItemBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapreplymessage.MapReplyBuilder;
/**
public ByteBuffer serialize(MapReply mapReply) {
int size = Length.HEADER_SIZE;
- for (EidToLocatorRecord eidToLocatorRecord : mapReply.getEidToLocatorRecord()) {
- size += EidToLocatorRecordSerializer.getInstance().getSerializationSize(eidToLocatorRecord);
+ for (MappingRecordItem eidToLocatorRecord : mapReply.getMappingRecordItem()) {
+ size += MappingRecordSerializer.getInstance().getSerializationSize(eidToLocatorRecord.getMappingRecord());
}
ByteBuffer replyBuffer = ByteBuffer.allocate(size);
(BooleanUtils.isTrue(mapReply.isEchoNonceEnabled()) ? Flags.ECHO_NONCE_ENABLED : 0x00)));
replyBuffer.position(replyBuffer.position() + Length.RES);
- if (mapReply.getEidToLocatorRecord() != null) {
- replyBuffer.put((byte) mapReply.getEidToLocatorRecord().size());
+ if (mapReply.getMappingRecordItem() != null) {
+ replyBuffer.put((byte) mapReply.getMappingRecordItem().size());
} else {
replyBuffer.put((byte) 0);
}
replyBuffer.putLong(NumberUtil.asLong(mapReply.getNonce()));
- if (mapReply.getEidToLocatorRecord() != null) {
- for (EidToLocatorRecord eidToLocatorRecord : mapReply.getEidToLocatorRecord()) {
- EidToLocatorRecordSerializer.getInstance().serialize(replyBuffer, eidToLocatorRecord);
+ if (mapReply.getMappingRecordItem() != null) {
+ for (MappingRecordItem eidToLocatorRecord : mapReply.getMappingRecordItem()) {
+ MappingRecordSerializer.getInstance().serialize(replyBuffer, eidToLocatorRecord.getMappingRecord());
}
}
return replyBuffer;
replyBuffer.getShort();
int recordCount = ByteUtil.getUnsignedByte(replyBuffer);
builder.setNonce(replyBuffer.getLong());
- builder.setEidToLocatorRecord(new ArrayList<EidToLocatorRecord>());
+ builder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
for (int i = 0; i < recordCount; i++) {
- builder.getEidToLocatorRecord().add(
- new EidToLocatorRecordBuilder(EidToLocatorRecordSerializer.getInstance().deserialize(replyBuffer)).build());
+ builder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(
+ MappingRecordSerializer.getInstance().deserialize(replyBuffer)).build());
}
return builder.build();
import org.apache.commons.lang3.BooleanUtils;
import org.opendaylight.lispflowmapping.lisp.serializer.address.LispAddressSerializer;
+import org.opendaylight.lispflowmapping.lisp.serializer.address.LispAddressSerializerContext;
import org.opendaylight.lispflowmapping.lisp.serializer.exception.LispSerializationException;
import org.opendaylight.lispflowmapping.lisp.type.LispMessageEnum;
import org.opendaylight.lispflowmapping.lisp.util.ByteUtil;
-import org.opendaylight.lispflowmapping.lisp.util.LispAFIConvertor;
+import org.opendaylight.lispflowmapping.lisp.util.MaskUtil;
import org.opendaylight.lispflowmapping.lisp.util.NumberUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapRequest;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eidrecords.EidRecord;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eidtolocatorrecords.EidToLocatorRecordBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.list.EidItem;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.list.EidItemBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRloc;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRlocBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.SourceEidBuilder;
public ByteBuffer serialize(MapRequest mapRequest) {
int size = Length.HEADER_SIZE;
- if (mapRequest.getSourceEid() != null && mapRequest.getSourceEid().getLispAddressContainer() != null) {
- size += LispAddressSerializer.getInstance().getAddressSize(
- LispAFIConvertor.toAFI(mapRequest.getSourceEid().getLispAddressContainer()));
+ if (mapRequest.getSourceEid() != null && mapRequest.getSourceEid().getEid() != null) {
+ size += LispAddressSerializer.getInstance().getAddressSize(mapRequest.getSourceEid().getEid());
} else {
size += 2;
}
if (mapRequest.getItrRloc() != null) {
for (ItrRloc address : mapRequest.getItrRloc()) {
- size += LispAddressSerializer.getInstance().getAddressSize(LispAFIConvertor.toAFI(address.getLispAddressContainer()));
+ size += LispAddressSerializer.getInstance().getAddressSize(address.getRloc());
}
}
- if (mapRequest.getEidRecord() != null) {
- for (EidRecord record : mapRequest.getEidRecord()) {
- size += 2 + LispAddressSerializer.getInstance().getAddressSize(LispAFIConvertor.toAFI(record.getLispAddressContainer()));
+ if (mapRequest.getEidItem() != null) {
+ for (EidItem record : mapRequest.getEidItem()) {
+ size += 2 + LispAddressSerializer.getInstance().getAddressSize(record.getEid());
}
}
ByteBuffer requestBuffer = ByteBuffer.allocate(size);
requestBuffer.put((byte) 0);
}
- if (mapRequest.getEidRecord() != null) {
- requestBuffer.put((byte) mapRequest.getEidRecord().size());
+ if (mapRequest.getEidItem() != null) {
+ requestBuffer.put((byte) mapRequest.getEidItem().size());
} else {
requestBuffer.put((byte) 0);
}
requestBuffer.putLong(NumberUtil.asLong(mapRequest.getNonce()));
- if (mapRequest.getSourceEid() != null && mapRequest.getSourceEid().getLispAddressContainer() != null) {
- LispAddressSerializer.getInstance().serialize(requestBuffer,
- LispAFIConvertor.toAFI(mapRequest.getSourceEid().getLispAddressContainer()));
+ if (mapRequest.getSourceEid() != null && mapRequest.getSourceEid().getEid() != null) {
+ LispAddressSerializer.getInstance().serialize(requestBuffer, mapRequest.getSourceEid().getEid());
} else {
requestBuffer.putShort((short) 0);
}
if (mapRequest.getItrRloc() != null) {
for (ItrRloc address : mapRequest.getItrRloc()) {
- LispAddressSerializer.getInstance().serialize(requestBuffer, LispAFIConvertor.toAFI(address.getLispAddressContainer()));
+ LispAddressSerializer.getInstance().serialize(requestBuffer, address.getRloc());
}
}
- if (mapRequest.getEidRecord() != null) {
- for (EidRecord record : mapRequest.getEidRecord()) {
+ if (mapRequest.getEidItem() != null) {
+ for (EidItem record : mapRequest.getEidItem()) {
requestBuffer.put((byte) 0);
- requestBuffer.put((byte) record.getMask().byteValue());
- LispAddressSerializer.getInstance().serialize(requestBuffer, LispAFIConvertor.toAFI(record.getLispAddressContainer()));
+ requestBuffer.put((byte) MaskUtil.getMaskForAddress(record.getEid().getAddress()));
+ LispAddressSerializer.getInstance().serialize(requestBuffer, record.getEid());
}
}
if (mapRequest.getMapReply() != null) {
- ByteBuffer replyBuffer = ByteBuffer.allocate(EidToLocatorRecordSerializer.getInstance().getSerializationSize(mapRequest.getMapReply()));
- EidToLocatorRecordSerializer.getInstance().serialize(replyBuffer, mapRequest.getMapReply());
+ ByteBuffer replyBuffer = ByteBuffer.allocate(MappingRecordSerializer.getInstance()
+ .getSerializationSize(mapRequest.getMapReply().getMappingRecord()));
+ MappingRecordSerializer.getInstance().serialize(replyBuffer, mapRequest.getMapReply().getMappingRecord());
ByteBuffer combinedBuffer = ByteBuffer.allocate(requestBuffer.capacity() + replyBuffer.capacity());
combinedBuffer.put(requestBuffer.array());
combinedBuffer.put(replyBuffer.array());
int itrCount = ByteUtil.getUnsignedByte(requestBuffer) + 1;
int recordCount = ByteUtil.getUnsignedByte(requestBuffer);
builder.setNonce(requestBuffer.getLong());
- builder.setSourceEid(new SourceEidBuilder().setLispAddressContainer(
- LispAFIConvertor.toContainer(LispAddressSerializer.getInstance().deserialize(requestBuffer)))
- .build());
+ LispAddressSerializerContext ctx = new LispAddressSerializerContext(
+ LispAddressSerializerContext.MASK_LEN_MISSING);
+ builder.setSourceEid(new SourceEidBuilder().setEid(
+ LispAddressSerializer.getInstance().deserializeEid(requestBuffer, ctx)).build());
if (builder.getItrRloc() == null) {
builder.setItrRloc(new ArrayList<ItrRloc>());
}
for (int i = 0; i < itrCount; i++) {
- builder.getItrRloc().add(
- new ItrRlocBuilder().setLispAddressContainer(
- LispAFIConvertor.toContainer(LispAddressSerializer.getInstance().deserialize(requestBuffer)))
- .build());
+ builder.getItrRloc().add(new ItrRlocBuilder().setRloc(
+ LispAddressSerializer.getInstance().deserializeRloc(requestBuffer)).build());
}
- if (builder.getEidRecord() == null) {
- builder.setEidRecord(new ArrayList<EidRecord>());
+ if (builder.getEidItem() == null) {
+ builder.setEidItem(new ArrayList<EidItem>());
}
for (int i = 0; i < recordCount; i++) {
- builder.getEidRecord().add(EidRecordSerializer.getInstance().deserialize(requestBuffer));
+ builder.getEidItem().add(new EidItemBuilder().setEid(
+ EidRecordSerializer.getInstance().deserialize(requestBuffer)).build());
}
if (builder.isMapDataPresent() && requestBuffer.hasRemaining()) {
try {
- builder.setMapReply(new org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.MapReplyBuilder(
- new EidToLocatorRecordBuilder(EidToLocatorRecordSerializer.getInstance().deserialize(requestBuffer)).build()).build());
+ builder.setMapReply(new org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.MapReplyBuilder().setMappingRecord(
+ MappingRecordSerializer.getInstance().deserialize(requestBuffer)).build()).build();
} catch (RuntimeException re) {
LOG.warn("couldn't deserialize map reply encapsulated in map request. {}", re.getMessage());
}
import org.apache.commons.lang3.BooleanUtils;
import org.opendaylight.lispflowmapping.lisp.serializer.address.LispAddressSerializer;
+import org.opendaylight.lispflowmapping.lisp.serializer.address.LispAddressSerializerContext;
import org.opendaylight.lispflowmapping.lisp.util.ByteUtil;
-import org.opendaylight.lispflowmapping.lisp.util.LispAFIConvertor;
import org.opendaylight.lispflowmapping.lisp.util.MaskUtil;
import org.opendaylight.lispflowmapping.lisp.util.NumberUtil;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.EidToLocatorRecord;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.EidToLocatorRecord.Action;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.LispAFIAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eidtolocatorrecords.EidToLocatorRecordBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.LispAddressContainer;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecord;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord.Action;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder;
-public class EidToLocatorRecordSerializer {
+public class MappingRecordSerializer {
- private static final EidToLocatorRecordSerializer INSTANCE = new EidToLocatorRecordSerializer();
+ private static final MappingRecordSerializer INSTANCE = new MappingRecordSerializer();
// Private constructor prevents instantiation from other classes
- private EidToLocatorRecordSerializer() {
+ private MappingRecordSerializer() {
}
- public static EidToLocatorRecordSerializer getInstance() {
+ public static MappingRecordSerializer getInstance() {
return INSTANCE;
}
- public EidToLocatorRecord deserialize(ByteBuffer buffer) {
- EidToLocatorRecordBuilder builder = new EidToLocatorRecordBuilder();
+ public MappingRecord deserialize(ByteBuffer buffer) {
+ MappingRecordBuilder builder = new MappingRecordBuilder();
builder.setRecordTtl(buffer.getInt());
byte locatorCount = (byte) ByteUtil.getUnsignedByte(buffer);
builder.setMaskLength((short) ByteUtil.getUnsignedByte(buffer));
buffer.position(buffer.position() + Length.RESERVED);
builder.setMapVersion(buffer.getShort());
- LispAFIAddress afiAddress = LispAddressSerializer.getInstance().deserialize(buffer);
- afiAddress = MaskUtil.fixMask(afiAddress, builder.getMaskLength());
- LispAddressContainer container = LispAFIConvertor.toContainer(afiAddress);
- builder.setLispAddressContainer(container);
+ LispAddressSerializerContext ctx = new LispAddressSerializerContext(builder.getMaskLength());
+ builder.setEid(LispAddressSerializer.getInstance().deserializeEid(buffer, ctx));
builder.setLocatorRecord(new ArrayList<LocatorRecord>());
for (int i = 0; i < locatorCount; i++) {
return builder.build();
}
- public void serialize(ByteBuffer replyBuffer, EidToLocatorRecord record) {
+ public void serialize(ByteBuffer replyBuffer, MappingRecord record) {
replyBuffer.putInt(NumberUtil.asInt(record.getRecordTtl()));
if (record.getLocatorRecord() != null) {
replyBuffer.put((byte) record.getLocatorRecord().size());
} else {
replyBuffer.put((byte) 0);
}
- replyBuffer.put((byte) NumberUtil.asShort(record.getMaskLength()));
+ if (record.getEid() != null && MaskUtil.getMaskForAddress(record.getEid().getAddress()) != -1) {
+ replyBuffer.put((byte) NumberUtil.asShort(MaskUtil.getMaskForAddress(record.getEid().getAddress())));
+ } else {
+ replyBuffer.put((byte) 0);
+ }
Action act = Action.NoAction;
if (record.getAction() != null) {
act = record.getAction();
ByteUtil.boolToBit(BooleanUtils.isTrue(record.isAuthoritative()), Flags.AUTHORITATIVE)));
replyBuffer.position(replyBuffer.position() + Length.RESERVED);
replyBuffer.putShort(NumberUtil.asShort(record.getMapVersion()));
- if (record.getLispAddressContainer() != null && record.getLispAddressContainer().getAddress() != null) {
- LispAddressSerializer.getInstance().serialize(replyBuffer, LispAFIConvertor.toAFI(record.getLispAddressContainer()));
+ if (record.getEid() != null && record.getEid().getAddress() != null) {
+ LispAddressSerializer.getInstance().serialize(replyBuffer, record.getEid());
}
if (record.getLocatorRecord() != null) {
}
}
- public int getSerializationSize(EidToLocatorRecord record) {
+ public int getSerializationSize(MappingRecord record) {
int size = Length.HEADER_SIZE;
- if (record.getLispAddressContainer() != null) {
- size += LispAddressSerializer.getInstance().getAddressSize((LispAFIConvertor.toAFI(record.getLispAddressContainer())));
+ if (record.getEid() != null) {
+ size += LispAddressSerializer.getInstance().getAddressSize(record.getEid());
}
if (record.getLocatorRecord() != null) {
for (LocatorRecord locatorRecord : record.getLocatorRecord()) {
--- /dev/null
+/*
+ * Copyright (c) 2014 Contextream, 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.lisp.serializer.address;
+
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.opendaylight.lispflowmapping.lisp.type.LispCanonicalAddressFormatEnum;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana.afn.safi.rev130704.AddressFamily;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.AfiListLcaf;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.LispAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SimpleAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.afi.list.AfiList;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.afi.list.AfiListBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.EidBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.Rloc;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.RlocBuilder;
+
+public class AfiListSerializer extends LcafSerializer {
+
+ private static final AfiListSerializer INSTANCE = new AfiListSerializer();
+
+ // Private constructor prevents instantiation from other classes
+ private AfiListSerializer() {
+ }
+
+ public static AfiListSerializer getInstance() {
+ return INSTANCE;
+ }
+
+ @Override
+ protected byte getLcafType() {
+ return LispCanonicalAddressFormatEnum.LIST.getLispCode();
+ }
+
+ @Override
+ protected short getLcafLength(LispAddress lispAddress) {
+ short totalSize = 0;
+ AfiList afiList = (((org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.AfiList)
+ lispAddress.getAddress()).getAfiList());
+ for (SimpleAddress address : afiList.getAddressList()) {
+ totalSize += SimpleAddressSerializer.getInstance().getAddressSize(address);
+ }
+ return totalSize;
+ }
+
+ @Override
+ protected short getAfi() {
+ return (short) AddressFamily.LispCanonicalAddressFormat.getIntValue();
+ }
+
+ @Override
+ protected void serializeData(ByteBuffer buffer, LispAddress lispAddress) {
+ AfiList afiList = (((org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.AfiList)
+ lispAddress.getAddress()).getAfiList());
+ for (SimpleAddress address : afiList.getAddressList()) {
+ SimpleAddressSerializer.getInstance().serialize(buffer, address);
+ }
+ }
+
+ @Override
+ public Eid deserializeLcafEidData(ByteBuffer buffer, byte res2, short length, LispAddressSerializerContext ctx) {
+ EidBuilder eb = new EidBuilder();
+ eb.setAddressType(AfiListLcaf.class);
+ eb.setVirtualNetworkId(getVni(ctx));
+ eb.setAddress(deserializeData(buffer, length, ctx));
+ return eb.build();
+ }
+
+ @Override
+ public Rloc deserializeLcafRlocData(ByteBuffer buffer, byte res2, short length, LispAddressSerializerContext ctx) {
+ RlocBuilder rb = new RlocBuilder();
+ rb.setAddressType(AfiListLcaf.class);
+ rb.setVirtualNetworkId(getVni(ctx));
+ rb.setAddress(deserializeData(buffer, length, ctx));
+ return rb.build();
+ }
+
+ private Address deserializeData(ByteBuffer buffer, short length, LispAddressSerializerContext ctx) {
+ List<SimpleAddress> addresses = new ArrayList<SimpleAddress>();
+ while (length > 0) {
+ SimpleAddress address = SimpleAddressSerializer.getInstance().deserialize(buffer, ctx);
+ length -= SimpleAddressSerializer.getInstance().getAddressSize(address);
+ addresses.add(address);
+ }
+ return new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.AfiListBuilder()
+ .setAfiList(new AfiListBuilder().setAddressList(addresses).build()).build();
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2014 Contextream, 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.lisp.serializer.address;
+
+import java.nio.ByteBuffer;
+
+import org.opendaylight.lispflowmapping.lisp.type.LispCanonicalAddressFormatEnum;
+import org.opendaylight.lispflowmapping.lisp.util.ByteUtil;
+import org.opendaylight.lispflowmapping.lisp.util.NumberUtil;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana.afn.safi.rev130704.AddressFamily;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.ApplicationDataLcaf;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.LispAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SimpleAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.application.data.ApplicationData;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.application.data.ApplicationDataBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.EidBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.Rloc;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.RlocBuilder;
+
+public class ApplicationDataSerializer extends LcafSerializer {
+
+ private static final ApplicationDataSerializer INSTANCE = new ApplicationDataSerializer();
+
+ // Private constructor prevents instantiation from other classes
+ private ApplicationDataSerializer() {
+ }
+
+ public static ApplicationDataSerializer getInstance() {
+ return INSTANCE;
+ }
+
+ @Override
+ protected byte getLcafType() {
+ return LispCanonicalAddressFormatEnum.APPLICATION_DATA.getLispCode();
+ }
+
+ @Override
+ protected short getLcafLength(LispAddress lispAddress) {
+ ApplicationData appData = ((org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.ApplicationData)
+ lispAddress.getAddress()).getApplicationData();
+ return (short) (Length.ALL_FIELDS + SimpleAddressSerializer.getInstance().getAddressSize(appData.getAddress()));
+ }
+
+ @Override
+ protected short getAfi() {
+ return (short) AddressFamily.LispCanonicalAddressFormat.getIntValue();
+ }
+
+ @Override
+ protected void serializeData(ByteBuffer buffer, LispAddress lispAddress) {
+ ApplicationData appData = ((org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.ApplicationData)
+ lispAddress.getAddress()).getApplicationData();
+ buffer.put(ByteUtil.partialIntToByteArray(NumberUtil.asInt(appData.getIpTos()), Length.TOC));
+ buffer.put((byte) NumberUtil.asShort(appData.getProtocol()));
+ if (appData.getLocalPortLow() != null) {
+ buffer.putShort(NumberUtil.asShort(appData.getLocalPortLow().getValue().shortValue()));
+ } else {
+ buffer.putShort((short) 0);
+ }
+ if (appData.getLocalPortHigh() != null) {
+ buffer.putShort(NumberUtil.asShort(appData.getLocalPortHigh().getValue().shortValue()));
+ } else {
+ buffer.putShort((short) 0);
+ }
+ if (appData.getRemotePortLow() != null) {
+ buffer.putShort(NumberUtil.asShort(appData.getRemotePortLow().getValue().shortValue()));
+ } else {
+ buffer.putShort((short) 0);
+ }
+ if (appData.getRemotePortHigh() != null) {
+ buffer.putShort(NumberUtil.asShort(appData.getRemotePortHigh().getValue().shortValue()));
+ } else {
+ buffer.putShort((short) 0);
+ }
+ SimpleAddressSerializer.getInstance().serialize(buffer, appData.getAddress());
+ }
+
+ @Override
+ protected Eid deserializeLcafEidData(ByteBuffer buffer, byte res2, short length, LispAddressSerializerContext ctx) {
+ EidBuilder eb = new EidBuilder();
+ eb.setAddressType(ApplicationDataLcaf.class);
+ eb.setVirtualNetworkId(getVni(ctx));
+ eb.setAddress(deserializeData(buffer, ctx));
+ return eb.build();
+ }
+
+ @Override
+ protected Rloc deserializeLcafRlocData(ByteBuffer buffer, byte res2, short length, LispAddressSerializerContext ctx) {
+ RlocBuilder eb = new RlocBuilder();
+ eb.setAddressType(ApplicationDataLcaf.class);
+ eb.setVirtualNetworkId(null);
+ eb.setAddress(deserializeData(buffer, ctx));
+ return eb.build();
+ }
+
+ private Address deserializeData(ByteBuffer buffer, LispAddressSerializerContext ctx) {
+ ApplicationDataBuilder builder = new ApplicationDataBuilder();
+ byte[] rawIPTos = new byte[3];
+ buffer.get(rawIPTos);
+ builder.setIpTos(ByteUtil.getPartialInt(rawIPTos));
+ builder.setProtocol((short) ByteUtil.getUnsignedByte(buffer));
+ builder.setLocalPortLow(new PortNumber(ByteUtil.asUnsignedShort(buffer.getShort())));
+ builder.setLocalPortHigh(new PortNumber(ByteUtil.asUnsignedShort(buffer.getShort())));
+ builder.setRemotePortLow(new PortNumber(ByteUtil.asUnsignedShort(buffer.getShort())));
+ builder.setRemotePortHigh(new PortNumber(ByteUtil.asUnsignedShort(buffer.getShort())));
+ SimpleAddress address = SimpleAddressSerializer.getInstance().deserialize(buffer, ctx);
+ builder.setAddress(address);
+ return new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.ApplicationDataBuilder()
+ .setApplicationData(builder.build()).build();
+ }
+
+ private interface Length {
+ int LOCAL_PORT_LOW = 2;
+ int LOCAL_PORT_HIGH = 2;
+ int REMOTE_PORT_LOW = 2;
+ int REMOTE_PORT_HIGH = 2;
+ int TOC = 3;
+ int PROTOCOL = 1;
+ int ALL_FIELDS = LOCAL_PORT_LOW + LOCAL_PORT_HIGH + REMOTE_PORT_LOW + REMOTE_PORT_HIGH + TOC + PROTOCOL;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2014 Contextream, 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.lisp.serializer.address;
+
+import java.nio.ByteBuffer;
+
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana.afn.safi.rev130704.AddressFamily;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.DistinguishedNameAfi;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.DistinguishedNameType;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.LispAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SimpleAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.DistinguishedName;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.DistinguishedNameBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.EidBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.Rloc;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.RlocBuilder;
+
+public class DistinguishedNameSerializer extends LispAddressSerializer {
+
+ private static final DistinguishedNameSerializer INSTANCE = new DistinguishedNameSerializer();
+
+ // Private constructor prevents instantiation from other classes
+ private DistinguishedNameSerializer() {
+ }
+
+ public static DistinguishedNameSerializer getInstance() {
+ return INSTANCE;
+ }
+
+ @Override
+ public int getAddressSize(LispAddress lispAddress) {
+ return ((DistinguishedName) lispAddress.getAddress()).getDistinguishedName().getValue().length() + 1;
+
+ }
+
+ @Override
+ public int getAddressSize(SimpleAddress simpleAddress) {
+ return simpleAddress.getDistinguishedNameType().getValue().length() + 1;
+
+ }
+
+ @Override
+ protected short getAfi() {
+ return (short) AddressFamily.DistinguishedName.getIntValue();
+ }
+
+ @Override
+ protected void serializeData(ByteBuffer buffer, LispAddress lispAddress) {
+ DistinguishedName distinguishedNameAddress = (DistinguishedName) lispAddress.getAddress();
+ buffer.put(distinguishedNameAddress.getDistinguishedName().getValue().getBytes());
+ buffer.put((byte) 0);
+ }
+
+ @Override
+ protected void serializeData(ByteBuffer buffer, SimpleAddress simpleAddress) {
+ buffer.put(simpleAddress.getDistinguishedNameType().getValue().getBytes());
+ buffer.put((byte) 0);
+ }
+
+ @Override
+ protected Eid deserializeEidData(ByteBuffer buffer, LispAddressSerializerContext ctx) {
+ EidBuilder eb = new EidBuilder();
+ eb.setAddressType(DistinguishedNameAfi.class);
+ eb.setVirtualNetworkId(getVni(ctx));
+ eb.setAddress(new DistinguishedNameBuilder().setDistinguishedName(deserializeData(buffer)).build());
+ return eb.build();
+ }
+
+ @Override
+ protected Rloc deserializeRlocData(ByteBuffer buffer) {
+ RlocBuilder rb = new RlocBuilder();
+ rb.setAddressType(DistinguishedNameAfi.class);
+ rb.setVirtualNetworkId(null);
+ rb.setAddress(new DistinguishedNameBuilder().setDistinguishedName(deserializeData(buffer)).build());
+ return rb.build();
+ }
+
+
+ @Override
+ protected SimpleAddress deserializeSimpleAddressData(ByteBuffer buffer, LispAddressSerializerContext ctx) {
+ return new SimpleAddress(deserializeData(buffer));
+ }
+
+ private DistinguishedNameType deserializeData(ByteBuffer buffer) {
+ StringBuilder sb = new StringBuilder();
+ byte b = buffer.get();
+ while (b != 0) {
+ sb.append((char) b);
+ b = buffer.get();
+ }
+ return new DistinguishedNameType(sb.toString());
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2014 Contextream, 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.lisp.serializer.address;
+
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.lang3.BooleanUtils;
+import org.opendaylight.lispflowmapping.lisp.type.LispCanonicalAddressFormatEnum;
+import org.opendaylight.lispflowmapping.lisp.util.ByteUtil;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana.afn.safi.rev130704.AddressFamily;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.ExplicitLocatorPathLcaf;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.LispAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SimpleAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.ExplicitLocatorPath;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.explicit.locator.path.ExplicitLocatorPathBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.explicit.locator.path.explicit.locator.path.Hop;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.explicit.locator.path.explicit.locator.path.Hop.LrsBits;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.explicit.locator.path.explicit.locator.path.HopBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.EidBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.Rloc;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.RlocBuilder;
+
+public class ExplicitLocatorPathSerializer extends LcafSerializer {
+
+ private static final ExplicitLocatorPathSerializer INSTANCE = new ExplicitLocatorPathSerializer();
+
+ // Private constructor prevents instantiation from other classes
+ private ExplicitLocatorPathSerializer() {
+ }
+
+ public static ExplicitLocatorPathSerializer getInstance() {
+ return INSTANCE;
+ }
+
+ @Override
+ protected byte getLcafType() {
+ return LispCanonicalAddressFormatEnum.TRAFFIC_ENGINEERING.getLispCode();
+ }
+
+ @Override
+ protected short getLcafLength(LispAddress lispAddress) {
+ short totalSize = 0;
+ ExplicitLocatorPath elp = (ExplicitLocatorPath) lispAddress.getAddress();
+ if (elp.getExplicitLocatorPath() != null) {
+ for (Hop hop : elp.getExplicitLocatorPath().getHop()) {
+ totalSize += SimpleAddressSerializer.getInstance().getAddressSize(hop.getAddress()) + 2;
+ }
+ }
+ return totalSize;
+ }
+
+ @Override
+ protected short getAfi() {
+ return (short) AddressFamily.LispCanonicalAddressFormat.getIntValue();
+ }
+
+ @Override
+ protected void serializeData(ByteBuffer buffer, LispAddress lispAddress) {
+ ExplicitLocatorPath elp = (ExplicitLocatorPath) lispAddress.getAddress();
+ if (elp.getExplicitLocatorPath() != null) {
+ for (Hop hop : elp.getExplicitLocatorPath().getHop()) {
+ buffer.put((byte) 0);
+ if (hop.getLrsBits() != null) {
+ buffer.put((byte) (ByteUtil.boolToBit(BooleanUtils.isTrue(hop.getLrsBits().isLookup()), Flags.LOOKUP) | //
+ ByteUtil.boolToBit(BooleanUtils.isTrue(hop.getLrsBits().isRlocProbe()), Flags.RLOC_PROBE) | //
+ ByteUtil.boolToBit(BooleanUtils.isTrue(hop.getLrsBits().isStrict()), Flags.STRICT)));
+ } else {
+ buffer.put((byte) 0);
+ }
+ SimpleAddressSerializer.getInstance().serialize(buffer, hop.getAddress());
+ }
+ }
+ }
+
+ @Override
+ protected Eid deserializeLcafEidData(ByteBuffer buffer, byte res2, short length, LispAddressSerializerContext ctx) {
+ EidBuilder eb = new EidBuilder();
+ eb.setAddressType(ExplicitLocatorPathLcaf.class);
+ eb.setVirtualNetworkId(getVni(ctx));
+ eb.setAddress(deserializeData(buffer, length, ctx));
+ return eb.build();
+ }
+
+ @Override
+ protected Rloc deserializeLcafRlocData(ByteBuffer buffer, byte res2, short length, LispAddressSerializerContext ctx) {
+ RlocBuilder rb = new RlocBuilder();
+ rb.setAddressType(ExplicitLocatorPathLcaf.class);
+ rb.setVirtualNetworkId(null);
+ rb.setAddress(deserializeData(buffer, length, ctx));
+ return rb.build();
+ }
+
+ private Address deserializeData(ByteBuffer buffer, short length, LispAddressSerializerContext ctx) {
+ List<Hop> hops = new ArrayList<Hop>();
+ while (length > 0) {
+ byte flags = (byte) buffer.getShort();
+ boolean lookup = ByteUtil.extractBit(flags, Flags.LOOKUP);
+ boolean rlocProbe = ByteUtil.extractBit(flags, Flags.RLOC_PROBE);
+ boolean strict = ByteUtil.extractBit(flags, Flags.STRICT);
+ SimpleAddress address = SimpleAddressSerializer.getInstance().deserialize(buffer, ctx);
+ HopBuilder builder = new HopBuilder();
+ builder.setLrsBits(new LrsBits(lookup, rlocProbe, strict));
+ builder.setAddress(address);
+ builder.setHopId("Hop " + (hops.size()+1));
+ length -= SimpleAddressSerializer.getInstance().getAddressSize(address) + 2;
+ hops.add(builder.build());
+ }
+ return new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.ExplicitLocatorPathBuilder()
+ .setExplicitLocatorPath(new ExplicitLocatorPathBuilder().setHop(hops).build()).build();
+ }
+
+ private interface Flags {
+ int LOOKUP = 0x04;
+ int RLOC_PROBE = 0x02;
+ int STRICT = 0x01;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2014 Contextream, 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.lisp.serializer.address;
+
+import java.nio.ByteBuffer;
+
+import org.opendaylight.lispflowmapping.lisp.serializer.exception.LispSerializationException;
+import org.opendaylight.lispflowmapping.lisp.type.LispCanonicalAddressFormatEnum;
+import org.opendaylight.lispflowmapping.lisp.util.ByteUtil;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana.afn.safi.rev130704.AddressFamily;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.InstanceIdType;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.LispAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.InstanceId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
+
+public class InstanceIdSerializer extends LcafSerializer {
+
+ private static final int MAX_INSTANCE_ID = 16777216;
+ private static final InstanceIdSerializer INSTANCE = new InstanceIdSerializer();
+
+ // Private constructor prevents instantiation from other classes
+ private InstanceIdSerializer() {
+ }
+
+ public static InstanceIdSerializer getInstance() {
+ return INSTANCE;
+ }
+
+ @Override
+ protected byte getLcafType() {
+ return LispCanonicalAddressFormatEnum.SEGMENT.getLispCode();
+ }
+
+ @Override
+ protected short getLcafLength(LispAddress lispAddress) {
+ return (short) (Length.INSTANCE + LispAddressSerializer.getInstance().getAddressSize(lispAddress));
+ }
+
+ protected int getInstanceIdSize() {
+ return Length.INSTANCE;
+ }
+
+ @Override
+ protected short getAfi() {
+ return (short) AddressFamily.LispCanonicalAddressFormat.getIntValue();
+ }
+
+ @Override
+ protected void serializeData(ByteBuffer buffer, LispAddress lispAddress) {
+ InstanceId iid = (InstanceId) lispAddress.getAddress();
+ // The IID mask-len field is in the LCAF header on the res2 position
+ buffer.put(buffer.position() - 3, iid.getInstanceId().getMaskLength().byteValue());
+
+ buffer.putInt(iid.getInstanceId().getIid().getValue().intValue());
+ LispAddressSerializer.getInstance().serialize(buffer, lispAddress);
+ }
+
+ protected void serializeNonLcafAddress(ByteBuffer buffer, LispAddress lispAddress) {
+ buffer.putInt(lispAddress.getVirtualNetworkId().getValue().intValue());
+ }
+
+ @Override
+ protected Eid deserializeLcafEidData(ByteBuffer buffer, byte res2, short length, LispAddressSerializerContext ctx) {
+ long instanceId = (int) ByteUtil.asUnsignedInteger(buffer.getInt());
+
+ if (instanceId > MAX_INSTANCE_ID) {
+ throw new LispSerializationException("Instance ID is longer than 24 bits: " + instanceId);
+ }
+ ctx.setVni(new InstanceIdType(instanceId));
+ return LispAddressSerializer.getInstance().deserializeEid(buffer, ctx);
+ }
+
+ private interface Length {
+ int INSTANCE = 4;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. 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.lisp.serializer.address;
+
+import java.net.Inet4Address;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.nio.ByteBuffer;
+
+import org.opendaylight.lispflowmapping.lisp.serializer.address.Ipv4Serializer.Length;
+import org.opendaylight.lispflowmapping.lisp.serializer.exception.LispSerializationException;
+import org.opendaylight.lispflowmapping.lisp.util.MaskUtil;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana.afn.safi.rev130704.AddressFamily;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv4PrefixAfi;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.LispAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SimpleAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Prefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4PrefixBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.EidBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.Rloc;
+
+/**
+ * @author Lorand Jakab
+ *
+ */
+public class Ipv4PrefixSerializer extends LispAddressSerializer {
+
+ private static final Ipv4PrefixSerializer INSTANCE = new Ipv4PrefixSerializer();
+
+ // Private constructor prevents instantiation from other classes
+ private Ipv4PrefixSerializer() {
+ }
+
+ public static Ipv4PrefixSerializer getInstance() {
+ return INSTANCE;
+ }
+
+ @Override
+ public int getAddressSize(LispAddress lispAddress) {
+ return Length.IPV4; // XXX does this need to worry about the mask too?
+ }
+
+ @Override
+ public int getAddressSize(SimpleAddress simpleAddress) {
+ return Length.IPV4; // XXX does this need to worry about the mask too?
+ }
+
+ @Override
+ protected short getAfi() {
+ return (short) AddressFamily.IpV4.getIntValue();
+ }
+
+ @Override
+ protected void serializeData(ByteBuffer buffer, LispAddress lispAddress) {
+ Ipv4Prefix address = (Ipv4Prefix) lispAddress.getAddress();
+ try {
+ buffer.put(Inet4Address.getByName(MaskUtil.getAddressStringForIpv4Prefix(address)).getAddress());
+ } catch (UnknownHostException e) {
+ }
+ }
+
+ @Override
+ protected void serializeData(ByteBuffer buffer, SimpleAddress address) {
+ try {
+ buffer.put(Inet4Address.getByName(MaskUtil.getAddressStringForIpPrefix(address.getIpPrefix())).getAddress());
+ } catch (UnknownHostException e) {
+ }
+ }
+
+ @Override
+ protected Eid deserializeEidData(ByteBuffer buffer, LispAddressSerializerContext ctx) {
+ EidBuilder eb = new EidBuilder();
+ eb.setAddressType(Ipv4PrefixAfi.class);
+ eb.setVirtualNetworkId(getVni(ctx));
+ eb.setAddress(new Ipv4PrefixBuilder().setIpv4Prefix(deserializeData(buffer, ctx)).build());
+ return eb.build();
+ }
+
+ @Override
+ protected Rloc deserializeRlocData(ByteBuffer buffer) {
+ throw new LispSerializationException("RLOCs should not be deserialized into prefixes!");
+ }
+
+ @Override
+ protected SimpleAddress deserializeSimpleAddressData(ByteBuffer buffer, LispAddressSerializerContext ctx) {
+ return new SimpleAddress(new IpPrefix(deserializeData(buffer, ctx)));
+ }
+
+ private org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix
+ deserializeData(ByteBuffer buffer, LispAddressSerializerContext ctx) {
+ byte[] ipBuffer = new byte[4];
+ InetAddress address = null;
+ buffer.get(ipBuffer);
+ try {
+ address = InetAddress.getByAddress(ipBuffer);
+ } catch (UnknownHostException e) {
+ }
+ return new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix(
+ address.getHostAddress() + "/" + ctx.getMaskLen());
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. 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.lisp.serializer.address;
+
+import java.net.Inet4Address;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.nio.ByteBuffer;
+
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana.afn.safi.rev130704.AddressFamily;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv4Afi;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.LispAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SimpleAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.EidBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.Rloc;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.RlocBuilder;
+
+/**
+ * @author Lorand Jakab
+ *
+ */
+public class Ipv4Serializer extends LispAddressSerializer {
+
+ private static final Ipv4Serializer INSTANCE = new Ipv4Serializer();
+
+ // Private constructor prevents instantiation from other classes
+ private Ipv4Serializer() {
+ }
+
+ public static Ipv4Serializer getInstance() {
+ return INSTANCE;
+ }
+
+ @Override
+ public int getAddressSize(LispAddress lispAddress) {
+ return Length.IPV4;
+ }
+
+ @Override
+ public int getAddressSize(SimpleAddress simpleAddress) {
+ return Length.IPV4;
+ }
+
+ @Override
+ protected short getAfi() {
+ return (short) AddressFamily.IpV4.getIntValue();
+ }
+
+ @Override
+ protected void serializeData(ByteBuffer buffer, LispAddress lispAddress) {
+ Ipv4 address = (Ipv4) lispAddress.getAddress();
+ try {
+ buffer.put(Inet4Address.getByName(address.getIpv4().getValue()).getAddress());
+ } catch (UnknownHostException e) {
+ }
+ }
+
+ @Override
+ protected void serializeData(ByteBuffer buffer, SimpleAddress address) {
+ try {
+ buffer.put(Inet4Address.getByName(address.getIpAddress().getIpv4Address().getValue()).getAddress());
+ } catch (UnknownHostException e) {
+ }
+ }
+
+ @Override
+ protected Eid deserializeEidData(ByteBuffer buffer, LispAddressSerializerContext ctx) {
+ EidBuilder eb = new EidBuilder();
+ eb.setAddressType(Ipv4Afi.class);
+ eb.setVirtualNetworkId(getVni(ctx));
+ eb.setAddress(new Ipv4Builder().setIpv4(deserializeData(buffer)).build());
+ return eb.build();
+ }
+
+ @Override
+ protected Rloc deserializeRlocData(ByteBuffer buffer) {
+ RlocBuilder rb = new RlocBuilder();
+ rb.setAddressType(Ipv4Afi.class);
+ rb.setVirtualNetworkId(null);
+ rb.setAddress(new Ipv4Builder().setIpv4(deserializeData(buffer)).build());
+ return rb.build();
+ }
+
+ @Override
+ protected SimpleAddress deserializeSimpleAddressData(ByteBuffer buffer, LispAddressSerializerContext ctx) {
+ return new SimpleAddress(new IpAddress(deserializeData(buffer)));
+ }
+
+ private Ipv4Address deserializeData(ByteBuffer buffer) {
+ byte[] ipBuffer = new byte[4];
+ InetAddress address = null;
+ buffer.get(ipBuffer);
+ try {
+ address = InetAddress.getByAddress(ipBuffer);
+ } catch (UnknownHostException e) {
+ }
+ return new Ipv4Address(address.getHostAddress());
+ }
+
+ protected interface Length {
+ int IPV4 = 4;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. 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.lisp.serializer.address;
+
+import java.net.Inet6Address;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.nio.ByteBuffer;
+
+import org.opendaylight.lispflowmapping.lisp.serializer.address.Ipv6Serializer.Length;
+import org.opendaylight.lispflowmapping.lisp.serializer.exception.LispSerializationException;
+import org.opendaylight.lispflowmapping.lisp.util.MaskUtil;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana.afn.safi.rev130704.AddressFamily;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv6PrefixAfi;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.LispAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SimpleAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6Prefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6PrefixBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.EidBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.Rloc;
+
+/**
+ * @author Lorand Jakab
+ *
+ */
+public class Ipv6PrefixSerializer extends LispAddressSerializer {
+
+ private static final Ipv6PrefixSerializer INSTANCE = new Ipv6PrefixSerializer();
+
+ // Private constructor prevents instantiation from other classes
+ private Ipv6PrefixSerializer() {
+ }
+
+ public static Ipv6PrefixSerializer getInstance() {
+ return INSTANCE;
+ }
+
+ @Override
+ public int getAddressSize(LispAddress lispAddress) {
+ return Length.IPV6; // XXX does this need to worry about the mask too?
+ }
+
+ @Override
+ public int getAddressSize(SimpleAddress simpleAddress) {
+ return Length.IPV6; // XXX does this need to worry about the mask too?
+ }
+
+ @Override
+ protected short getAfi() {
+ return (short) AddressFamily.IpV6.getIntValue();
+ }
+
+ @Override
+ protected void serializeData(ByteBuffer buffer, LispAddress lispAddress) {
+ Ipv6Prefix address = (Ipv6Prefix) lispAddress.getAddress();
+ try {
+ buffer.put(Inet6Address.getByName(MaskUtil.getAddressStringForIpv6Prefix(address)).getAddress());
+ } catch (UnknownHostException e) {
+ }
+ }
+
+ @Override
+ protected void serializeData(ByteBuffer buffer, IpPrefix prefix) {
+ try {
+ buffer.put(Inet6Address.getByName(prefix.getIpv6Prefix().getValue()).getAddress());
+ } catch (UnknownHostException e) {
+ }
+ }
+
+ @Override
+ protected Eid deserializeEidData(ByteBuffer buffer, LispAddressSerializerContext ctx) {
+ EidBuilder eb = new EidBuilder();
+ eb.setAddressType(Ipv6PrefixAfi.class);
+ eb.setVirtualNetworkId(getVni(ctx));
+ eb.setAddress(new Ipv6PrefixBuilder().setIpv6Prefix(deserializeData(buffer, ctx)).build());
+ return eb.build();
+ }
+
+ @Override
+ protected Rloc deserializeRlocData(ByteBuffer buffer) {
+ throw new LispSerializationException("RLOCs should not be deserialized into prefixes!");
+ }
+
+ @Override
+ protected SimpleAddress deserializeSimpleAddressData(ByteBuffer buffer, LispAddressSerializerContext ctx) {
+ return new SimpleAddress(new IpPrefix(deserializeData(buffer, ctx)));
+ }
+
+ private org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix
+ deserializeData(ByteBuffer buffer, LispAddressSerializerContext ctx) {
+ byte[] ipBuffer = new byte[16];
+ InetAddress address = null;
+ buffer.get(ipBuffer);
+ try {
+ address = InetAddress.getByAddress(ipBuffer);
+ } catch (UnknownHostException e) {
+ }
+ return new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix(
+ address.getHostAddress() + "/" + ctx.getMaskLen());
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. 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.lisp.serializer.address;
+
+import java.net.Inet6Address;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.nio.ByteBuffer;
+
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana.afn.safi.rev130704.AddressFamily;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv6Afi;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.LispAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SimpleAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.EidBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.Rloc;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.RlocBuilder;
+
+/**
+ * @author Lorand Jakab
+ *
+ */
+public class Ipv6Serializer extends LispAddressSerializer {
+
+ private static final Ipv6Serializer INSTANCE = new Ipv6Serializer();
+
+ // Private constructor prevents instantiation from other classes
+ private Ipv6Serializer() {
+ }
+
+ public static Ipv6Serializer getInstance() {
+ return INSTANCE;
+ }
+
+ @Override
+ public int getAddressSize(LispAddress lispAddress) {
+ return Length.IPV6;
+ }
+
+ @Override
+ public int getAddressSize(SimpleAddress simpleAddress) {
+ return Length.IPV6;
+ }
+
+ @Override
+ protected short getAfi() {
+ return (short) AddressFamily.IpV6.getIntValue();
+ }
+
+ @Override
+ protected void serializeData(ByteBuffer buffer, LispAddress lispAddress) {
+ Ipv6 address = (Ipv6) lispAddress.getAddress();
+ try {
+ buffer.put(Inet6Address.getByName(address.getIpv6().getValue()).getAddress());
+ } catch (UnknownHostException e) {
+ }
+ }
+
+ @Override
+ protected void serializeData(ByteBuffer buffer, SimpleAddress address) {
+ try {
+ buffer.put(Inet6Address.getByName(address.getIpAddress().getIpv6Address().getValue()).getAddress());
+ } catch (UnknownHostException e) {
+ }
+ }
+
+ @Override
+ protected Eid deserializeEidData(ByteBuffer buffer, LispAddressSerializerContext ctx) {
+ EidBuilder eb = new EidBuilder();
+ eb.setAddressType(Ipv6Afi.class);
+ eb.setVirtualNetworkId(getVni(ctx));
+ eb.setAddress(new Ipv6Builder().setIpv6(deserializeData(buffer)).build());
+ return eb.build();
+ }
+
+ @Override
+ protected Rloc deserializeRlocData(ByteBuffer buffer) {
+ RlocBuilder rb = new RlocBuilder();
+ rb.setAddressType(Ipv6Afi.class);
+ rb.setVirtualNetworkId(null);
+ rb.setAddress(new Ipv6Builder().setIpv6(deserializeData(buffer)).build());
+ return rb.build();
+ }
+
+ @Override
+ protected SimpleAddress deserializeSimpleAddressData(ByteBuffer buffer, LispAddressSerializerContext ctx) {
+ return new SimpleAddress(new IpAddress(deserializeData(buffer)));
+ }
+
+ private Ipv6Address deserializeData(ByteBuffer buffer) {
+ byte[] ipBuffer = new byte[16];
+ InetAddress address = null;
+ buffer.get(ipBuffer);
+ try {
+ address = InetAddress.getByAddress(ipBuffer);
+ } catch (UnknownHostException e) {
+ }
+ return new Ipv6Address(address.getHostAddress());
+ }
+
+ protected interface Length {
+ int IPV6 = 16;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2014 Contextream, 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.lisp.serializer.address;
+
+import java.nio.ByteBuffer;
+
+import org.opendaylight.lispflowmapping.lisp.type.LispCanonicalAddressFormatEnum;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana.afn.safi.rev130704.AddressFamily;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.KeyValueAddressLcaf;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.LispAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SimpleAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.KeyValueAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.key.value.address.KeyValueAddressBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.EidBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.Rloc;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.RlocBuilder;
+
+public class KeyValueAddressSerializer extends LcafSerializer {
+
+ private static final KeyValueAddressSerializer INSTANCE = new KeyValueAddressSerializer();
+
+ // Private constructor prevents instantiation from other classes
+ private KeyValueAddressSerializer() {
+ }
+
+ public static KeyValueAddressSerializer getInstance() {
+ return INSTANCE;
+ }
+
+ @Override
+ protected byte getLcafType() {
+ return LispCanonicalAddressFormatEnum.KEY_VALUE.getLispCode();
+ }
+
+ @Override
+ protected short getLcafLength(LispAddress lispAddress) {
+ KeyValueAddress kva = (KeyValueAddress) lispAddress.getAddress();
+ return (short) (SimpleAddressSerializer.getInstance().getAddressSize(kva.getKeyValueAddress().getKey())
+ + SimpleAddressSerializer.getInstance().getAddressSize(kva.getKeyValueAddress().getValue()));
+ }
+
+ @Override
+ protected short getAfi() {
+ return (short) AddressFamily.LispCanonicalAddressFormat.getIntValue();
+ }
+
+ @Override
+ protected void serializeData(ByteBuffer buffer, LispAddress lispAddress) {
+ KeyValueAddress kva = (KeyValueAddress) lispAddress.getAddress();
+ SimpleAddressSerializer.getInstance().serialize(buffer, kva.getKeyValueAddress().getKey());
+ SimpleAddressSerializer.getInstance().serialize(buffer, kva.getKeyValueAddress().getValue());
+ }
+
+ @Override
+ protected Eid deserializeLcafEidData(ByteBuffer buffer, byte res2, short length, LispAddressSerializerContext ctx) {
+ EidBuilder eb = new EidBuilder();
+ eb.setAddressType(KeyValueAddressLcaf.class);
+ eb.setVirtualNetworkId(getVni(ctx));
+ eb.setAddress(deserializeData(buffer, ctx));
+ return eb.build();
+ }
+
+ @Override
+ protected Rloc deserializeLcafRlocData(ByteBuffer buffer, byte res2, short length, LispAddressSerializerContext ctx) {
+ RlocBuilder rb = new RlocBuilder();
+ rb.setAddressType(KeyValueAddressLcaf.class);
+ rb.setVirtualNetworkId(null);
+ rb.setAddress(deserializeData(buffer, ctx));
+ return rb.build();
+ }
+
+ private Address deserializeData(ByteBuffer buffer, LispAddressSerializerContext ctx) {
+ SimpleAddress keyAddress = SimpleAddressSerializer.getInstance().deserialize(buffer, ctx);
+ SimpleAddress valueAddress = SimpleAddressSerializer.getInstance().deserialize(buffer, ctx);
+ KeyValueAddressBuilder kvab = new KeyValueAddressBuilder();
+ kvab.setKey(keyAddress);
+ kvab.setValue(valueAddress);
+ return new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.KeyValueAddressBuilder()
+ .setKeyValueAddress(kvab.build()).build();
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2014 Contextream, 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.lisp.serializer.address;
+
+import java.nio.ByteBuffer;
+
+import org.opendaylight.lispflowmapping.lisp.serializer.address.factory.LispAddressSerializerFactory;
+import org.opendaylight.lispflowmapping.lisp.serializer.exception.LispSerializationException;
+import org.opendaylight.lispflowmapping.lisp.util.AddressTypeMap;
+import org.opendaylight.lispflowmapping.lisp.util.ByteUtil;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana.afn.safi.rev130704.AddressFamily;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.InstanceIdLcaf;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.LispAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.LispAddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.Rloc;
+
+public class LcafSerializer extends LispAddressSerializer {
+
+ private static final LcafSerializer INSTANCE = new LcafSerializer();
+
+ // Private constructor prevents instantiation from other classes
+ protected LcafSerializer() {
+ }
+
+ public static LcafSerializer getInstance() {
+ return INSTANCE;
+ }
+
+ @Override
+ public int getAddressSize(LispAddress lispAddress) {
+ return Length.LCAF_HEADER
+ + LispAddressSerializerFactory.getSerializer(lispAddress.getAddressType()).getLcafLength(lispAddress);
+ }
+
+ protected int getLcafHeaderSize() {
+ return Length.LCAF_HEADER;
+ }
+
+ protected short getLcafLength(LispAddress lispAddress) {
+ throw new RuntimeException("Not implemented");
+ }
+
+ @Override
+ protected short getAfi() {
+ return (short) AddressFamily.LispCanonicalAddressFormat.getIntValue();
+ }
+
+ @Override
+ protected void serializeData(ByteBuffer buffer, LispAddress lispAddress) {
+ LispAddressSerializer lcafSerializer = LispAddressSerializerFactory.getSerializer(lispAddress.getAddressType());
+ serializeLCAFAddressHeader(buffer, lispAddress, lcafSerializer);
+ buffer.putShort(lcafSerializer.getLcafLength(lispAddress));
+ lcafSerializer.serializeData(buffer, lispAddress);
+ }
+
+ protected void serializeLCAFAddressHeaderForInstanceId(ByteBuffer buffer, LispAddress lispAddress) {
+ LispAddressSerializer lcafSerializer = InstanceIdSerializer.getInstance();
+ serializeLCAFAddressHeader(buffer, lispAddress, lcafSerializer);
+ buffer.putShort((short) (lcafSerializer.getLcafLength(lispAddress) -
+ LispAddressSerializer.getInstance().getInstanceIdExtraSize()));
+ }
+
+ private void serializeLCAFAddressHeader(ByteBuffer buffer, LispAddress lispAddress,
+ LispAddressSerializer serializer) {
+ buffer.putShort((short) 0); // RES + Flags.
+ buffer.put(serializer.getLcafType());
+ buffer.put((byte) 0);
+ }
+
+ @Override
+ protected Eid deserializeEidData(ByteBuffer buffer, LispAddressSerializerContext ctx) {
+ buffer.position(buffer.position() + Length.RES + Length.FLAGS);
+ byte lcafType = (byte) ByteUtil.getUnsignedByte(buffer);
+ Class <? extends LispAddressFamily> addressType = AddressTypeMap.getLcafType(lcafType);
+ // TODO move these to ctx to shorten the list of arguments
+ byte res2 = buffer.get();
+ short length = buffer.getShort();
+
+ LispAddressSerializer serializer = LispAddressSerializerFactory.getSerializer(addressType);
+ if (serializer == null) {
+ throw new LispSerializationException("Unknown LCAF type: " + lcafType);
+ }
+ // Reset the mask context here, since the general mask length field in mapping records doesn't apply to LCAF
+ // address types; except for Instance ID, since we don't store it as an LCAF
+ if (ctx != null && addressType != InstanceIdLcaf.class) {
+ ctx.setMaskLen(LispAddressSerializerContext.MASK_LEN_MISSING);
+ }
+ return serializer.deserializeLcafEidData(buffer, res2, length, ctx);
+ }
+
+ @Override
+ protected Rloc deserializeRlocData(ByteBuffer buffer) {
+ buffer.position(buffer.position() + Length.RES + Length.FLAGS);
+ byte lcafType = (byte) ByteUtil.getUnsignedByte(buffer);
+ Class <? extends LispAddressFamily> addressType = AddressTypeMap.getLcafType(lcafType);
+ byte res2 = buffer.get();
+ short length = buffer.getShort();
+
+ LispAddressSerializer serializer = LispAddressSerializerFactory.getSerializer(addressType);
+ if (serializer == null) {
+ throw new LispSerializationException("Unknown LCAF type: " + lcafType);
+ }
+ return serializer.deserializeLcafRlocData(buffer, res2, length, null);
+ }
+
+ private interface Length {
+ int RES = 1;
+ int FLAGS = 1;
+
+ int LCAF_HEADER = 6;
+ }
+}
import java.nio.ByteBuffer;
-import org.opendaylight.lispflowmapping.lisp.serializer.address.factory.LispAFIAddressSerializerFactory;
+import org.opendaylight.lispflowmapping.lisp.serializer.address.factory.LispAddressSerializerFactory;
import org.opendaylight.lispflowmapping.lisp.serializer.exception.LispSerializationException;
-import org.opendaylight.lispflowmapping.lisp.type.AddressFamilyNumberEnum;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.LispAFIAddress;
+import org.opendaylight.lispflowmapping.lisp.util.AddressTypeMap;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana.afn.safi.rev130704.AddressFamily;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.InstanceIdType;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Lcaf;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.LispAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.LispAddressFamily;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SimpleAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.Rloc;
public class LispAddressSerializer {
private static final LispAddressSerializer INSTANCE = new LispAddressSerializer();
+ public static final InstanceIdType DEFAULT_VNI = new InstanceIdType(0L);
// Private constructor prevents instantiation from other classes
protected LispAddressSerializer() {
return INSTANCE;
}
- protected void serializeData(ByteBuffer buffer, LispAFIAddress lispAddress) {
- throw new RuntimeException("UnImplemented");
+ protected void serializeData(ByteBuffer buffer, LispAddress lispAddress) {
+ throw new RuntimeException("Unimplemented");
}
- protected LispAFIAddress deserializeData(ByteBuffer buffer) {
- throw new RuntimeException("UnImplemented");
+ protected void serializeData(ByteBuffer buffer, SimpleAddress lispAddress) {
+ throw new RuntimeException("Unimplemented");
}
- public void serialize(ByteBuffer buffer, LispAFIAddress lispAddress) {
- LispAddressSerializer serializer = LispAFIAddressSerializerFactory.getSerializer(AddressFamilyNumberEnum.valueOf(lispAddress.getAfi()));
+ protected void serializeData(ByteBuffer buffer, IpPrefix lispAddress) {
+ throw new RuntimeException("Unimplemented");
+ }
+
+ protected Eid deserializeEidData(ByteBuffer buffer, LispAddressSerializerContext ctx) {
+ throw new RuntimeException("Unimplemented");
+ }
+
+ protected SimpleAddress deserializeSimpleAddressData(ByteBuffer buffer, LispAddressSerializerContext ctx) {
+ throw new RuntimeException("Unimplemented");
+ }
+
+ protected Eid deserializeLcafEidData(ByteBuffer buffer, byte res2, short length,
+ LispAddressSerializerContext ctx) {
+ throw new RuntimeException("Unimplemented");
+ }
+
+ protected Rloc deserializeRlocData(ByteBuffer buffer) {
+ throw new RuntimeException("Unimplemented");
+ }
+
+ protected Rloc deserializeLcafRlocData(ByteBuffer buffer, byte res2, short length,
+ LispAddressSerializerContext ctx) {
+ throw new RuntimeException("Unimplemented");
+ }
+
+ protected short getAfi() {
+ throw new RuntimeException("Unimplemented");
+ }
+
+ protected byte getLcafType() {
+ throw new RuntimeException("Unimplemented");
+ }
+
+ protected short getLcafLength(LispAddress lispAddress) {
+ throw new RuntimeException("Unimplemented");
+ }
+
+ protected int getAddressSize(SimpleAddress address) {
+ throw new RuntimeException("Unimplemented");
+ }
+
+ protected InstanceIdType getVni(LispAddressSerializerContext ctx) {
+ if (ctx != null) {
+ return ctx.getVni();
+ }
+ return null;
+ }
+
+ public void serialize(ByteBuffer buffer, LispAddress lispAddress) {
+ if (lispAddress.getVirtualNetworkId() != null) {
+ serializeInstanceIdExtra(buffer, lispAddress);
+ }
+ LispAddressSerializer serializer = LispAddressSerializerFactory.getSerializer(lispAddress.getAddressType());
if (serializer == null) {
- throw new LispSerializationException("Unknown AFI type=" + lispAddress.getAfi());
+ throw new LispSerializationException("Unknown address type: "
+ + lispAddress.getAddressType().getSimpleName());
}
- serializeAFIAddressHeader(buffer, lispAddress);
+ short afi = serializer.getAfi();
+ if (afi == (short) AddressFamily.LispCanonicalAddressFormat.getIntValue()) {
+ serializer = LispAddressSerializerFactory.getSerializer(Lcaf.class);
+ }
+ buffer.putShort(afi);
serializer.serializeData(buffer, lispAddress);
}
- protected static void serializeAFIAddressHeader(ByteBuffer buffer, LispAFIAddress lispAddress) {
- buffer.putShort(lispAddress.getAfi());
+ private void serializeInstanceIdExtra(ByteBuffer buffer, LispAddress lispAddress) {
+ buffer.putShort((short) AddressFamily.LispCanonicalAddressFormat.getIntValue());
+ LcafSerializer.getInstance().serializeLCAFAddressHeaderForInstanceId(buffer, lispAddress);
+ InstanceIdSerializer.getInstance().serializeNonLcafAddress(buffer, lispAddress);
}
- public int getAddressSize(LispAFIAddress lispAddress) {
- AddressFamilyNumberEnum afiType = AddressFamilyNumberEnum.valueOf(lispAddress.getAfi());
- LispAddressSerializer serializer = LispAFIAddressSerializerFactory.getSerializer(afiType);
+ public int getAddressSize(LispAddress lispAddress) {
+ int size = Length.AFI;
+ if (lispAddress.getVirtualNetworkId() != null) {
+ size += getInstanceIdExtraSize();
+ }
+ LispAddressSerializer serializer = LispAddressSerializerFactory.getSerializer(lispAddress.getAddressType());
if (serializer == null) {
- throw new LispSerializationException("Unknown AFI type=" + afiType);
+ throw new LispSerializationException("Unknown address type: "
+ + lispAddress.getAddressType().getSimpleName());
}
- return Length.AFI + serializer.getAddressSize(lispAddress);
+ return size + serializer.getAddressSize(lispAddress);
}
- public LispAFIAddress deserialize(ByteBuffer buffer) {
+ int getInstanceIdExtraSize() {
+ return LcafSerializer.getInstance().getLcafHeaderSize() +
+ InstanceIdSerializer.getInstance().getInstanceIdSize() +
+ Length.AFI;
+ }
+
+ public Eid deserializeEid(ByteBuffer buffer, LispAddressSerializerContext ctx) {
short afi = buffer.getShort();
- AddressFamilyNumberEnum afiType = AddressFamilyNumberEnum.valueOf(afi);
- LispAddressSerializer serializer = LispAFIAddressSerializerFactory.getSerializer(afiType);
+ // AddressTypeMap indexes IPv4 and IPv6 prefixes (vs simple addresses) with the negative AFI values -1 and -2
+ if ((afi == 1 || afi == 2) && ctx.getMaskLen() != LispAddressSerializerContext.MASK_LEN_MISSING) {
+ afi *= -1;
+ }
+ Class <? extends LispAddressFamily> addressType = AddressTypeMap.getAddressType(afi);
+ LispAddressSerializer serializer = LispAddressSerializerFactory.getSerializer(addressType);
if (serializer == null) {
- throw new LispSerializationException("Unknown AFI type=" + afiType);
+ throw new LispSerializationException("Unknown AFI: " + afi);
}
try {
- return serializer.deserializeData(buffer);
+ return serializer.deserializeEidData(buffer, ctx);
} catch (RuntimeException e) {
- throw new LispSerializationException("Problem deserializing AFI=" + afiType, e);
+ throw new LispSerializationException("Problem deserializing AFI " + afi + " in EID context", e);
+ }
+ }
+
+ public Rloc deserializeRloc(ByteBuffer buffer) {
+ short afi = buffer.getShort();
+ Class <? extends LispAddressFamily> addressType = AddressTypeMap.getAddressType(afi);
+ LispAddressSerializer serializer = LispAddressSerializerFactory.getSerializer(addressType);
+ if (serializer == null) {
+ throw new LispSerializationException("Unknown AFI: " + afi);
+ }
+ try {
+ return serializer.deserializeRlocData(buffer);
+ } catch (RuntimeException e) {
+ throw new LispSerializationException("Problem deserializing AFI " + afi + " in RLOC context", e);
}
}
private interface Length {
int AFI = 2;
}
-
}
--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. 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.lisp.serializer.address;
+
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.InstanceIdType;
+
+/**
+ * @author Lorand Jakab
+ *
+ */
+public class LispAddressSerializerContext {
+ public static final short MASK_LEN_MISSING = -1;
+ private InstanceIdType vni;
+ private short maskLen;
+
+ public LispAddressSerializerContext(InstanceIdType vni) {
+ this(vni, MASK_LEN_MISSING);
+ }
+
+ public LispAddressSerializerContext(short maskLen) {
+ this(null, maskLen);
+ }
+
+ public LispAddressSerializerContext(InstanceIdType vni, short maskLength) {
+ this.vni = vni;
+ this.maskLen = maskLength;
+ }
+
+ InstanceIdType getVni() {
+ return vni;
+ }
+
+ void setVni(InstanceIdType vni) {
+ this.vni = vni;
+ }
+
+ short getMaskLen() {
+ return maskLen;
+ }
+
+ void setMaskLen(short maskLen) {
+ this.maskLen = maskLen;
+ }
+}
+++ /dev/null
-/*
- * Copyright (c) 2014 Contextream, 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.lisp.serializer.address;
-
-import java.nio.ByteBuffer;
-
-import org.opendaylight.lispflowmapping.lisp.type.AddressFamilyNumberEnum;
-import org.opendaylight.lispflowmapping.lisp.type.LispCanonicalAddressFormatEnum;
-import org.opendaylight.lispflowmapping.lisp.util.ByteUtil;
-import org.opendaylight.lispflowmapping.lisp.util.LispAFIConvertor;
-import org.opendaylight.lispflowmapping.lisp.util.NumberUtil;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.LcafApplicationDataAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.LispAFIAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lcafapplicationdataaddress.AddressBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.lcafapplicationdata.LcafApplicationDataAddrBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.PrimitiveAddress;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
-
-public class LispApplicationDataLCAFAddressSerializer extends LispLCAFAddressSerializer {
-
- private static final LispApplicationDataLCAFAddressSerializer INSTANCE = new LispApplicationDataLCAFAddressSerializer();
-
- // Private constructor prevents instantiation from other classes
- private LispApplicationDataLCAFAddressSerializer() {
- }
-
- public static LispApplicationDataLCAFAddressSerializer getInstance() {
- return INSTANCE;
- }
-
- @Override
- protected short getLcafLength(LispAFIAddress lispAddress) {
- return (short) (Length.ALL_FIELDS + LispAddressSerializer.getInstance().getAddressSize(
- LispAFIConvertor.toAFIfromPrimitive(((LcafApplicationDataAddress) lispAddress).getAddress().getPrimitiveAddress())));
- }
-
- @Override
- protected void serializeData(ByteBuffer buffer, LispAFIAddress lispAddress) {
- LcafApplicationDataAddress applicationDataAddress = ((LcafApplicationDataAddress) lispAddress);
- buffer.put(ByteUtil.partialIntToByteArray(NumberUtil.asInt(applicationDataAddress.getIpTos()), Length.TOC));
- buffer.put((byte) NumberUtil.asShort(applicationDataAddress.getProtocol()));
- if (applicationDataAddress.getLocalPortLow() != null) {
- buffer.putShort(NumberUtil.asShort(applicationDataAddress.getLocalPortLow().getValue().shortValue()));
- } else {
- buffer.putShort((short) 0);
- }
- if (applicationDataAddress.getLocalPortHigh() != null) {
- buffer.putShort(NumberUtil.asShort(applicationDataAddress.getLocalPortHigh().getValue().shortValue()));
- } else {
- buffer.putShort((short) 0);
- }
- if (applicationDataAddress.getRemotePortLow() != null) {
- buffer.putShort(NumberUtil.asShort(applicationDataAddress.getRemotePortLow().getValue().shortValue()));
- } else {
- buffer.putShort((short) 0);
- }
- if (applicationDataAddress.getRemotePortHigh() != null) {
- buffer.putShort(NumberUtil.asShort(applicationDataAddress.getRemotePortHigh().getValue().shortValue()));
- } else {
- buffer.putShort((short) 0);
- }
- LispAddressSerializer.getInstance().serialize(buffer,
- LispAFIConvertor.toAFIfromPrimitive(((LcafApplicationDataAddress) lispAddress).getAddress().getPrimitiveAddress()));
- }
-
- @Override
- protected LcafApplicationDataAddress deserializeData(ByteBuffer buffer, byte res2, short length) {
-
- LcafApplicationDataAddrBuilder builder = new LcafApplicationDataAddrBuilder();
- byte[] rawIPTos = new byte[3];
- buffer.get(rawIPTos);
- builder.setIpTos(ByteUtil.getPartialInt(rawIPTos));
- builder.setProtocol((short) ByteUtil.getUnsignedByte(buffer));
- builder.setLocalPortLow(new PortNumber(ByteUtil.asUnsignedShort(buffer.getShort())));
- builder.setLocalPortHigh(new PortNumber(ByteUtil.asUnsignedShort(buffer.getShort())));
- builder.setRemotePortLow(new PortNumber(ByteUtil.asUnsignedShort(buffer.getShort())));
- builder.setRemotePortHigh(new PortNumber(ByteUtil.asUnsignedShort(buffer.getShort())));
- LispAFIAddress address = LispAddressSerializer.getInstance().deserialize(buffer);
- builder.setAfi(AddressFamilyNumberEnum.LCAF.getIanaCode()).setLcafType((short) LispCanonicalAddressFormatEnum.APPLICATION_DATA.getLispCode())
- .setAddress(new AddressBuilder().setPrimitiveAddress((PrimitiveAddress) LispAFIConvertor.toPrimitive(address)).build());
-
- return builder.build();
- }
-
- private interface Length {
- int LOCAL_PORT_LOW = 2;
- int LOCAL_PORT_HIGH = 2;
- int REMOTE_PORT_LOW = 2;
- int REMOTE_PORT_HIGH = 2;
- int TOC = 3;
- int PROTOCOL = 1;
- int ALL_FIELDS = LOCAL_PORT_LOW + LOCAL_PORT_HIGH + REMOTE_PORT_LOW + REMOTE_PORT_HIGH + TOC + PROTOCOL;
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 Contextream, 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.lisp.serializer.address;
-
-import java.nio.ByteBuffer;
-
-import org.opendaylight.lispflowmapping.lisp.type.AddressFamilyNumberEnum;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.LispAFIAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.LispDistinguishedNameAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.distinguishedname.DistinguishedNameBuilder;
-
-public class LispDistinguishedNameAddressSerializer extends LispAddressSerializer {
-
- private static final LispDistinguishedNameAddressSerializer INSTANCE = new LispDistinguishedNameAddressSerializer();
-
- // Private constructor prevents instantiation from other classes
- private LispDistinguishedNameAddressSerializer() {
- }
-
- public static LispDistinguishedNameAddressSerializer getInstance() {
- return INSTANCE;
- }
-
- @Override
- public int getAddressSize(LispAFIAddress lispAddress) {
- return ((LispDistinguishedNameAddress) lispAddress).getDistinguishedName().length() + 1;
-
- }
-
- @Override
- protected LispDistinguishedNameAddress deserializeData(ByteBuffer buffer) {
- StringBuilder sb = new StringBuilder();
- byte b = buffer.get();
- while (b != 0) {
- sb.append((char) b);
- b = buffer.get();
- }
- return new DistinguishedNameBuilder().setAfi(AddressFamilyNumberEnum.DISTINGUISHED_NAME.getIanaCode()).setDistinguishedName((sb.toString()))
- .build();
- }
-
- @Override
- protected void serializeData(ByteBuffer buffer, LispAFIAddress lispAddress) {
- LispDistinguishedNameAddress distinguishedNameAddress = (LispDistinguishedNameAddress) lispAddress;
- buffer.put(distinguishedNameAddress.getDistinguishedName().getBytes());
- buffer.put((byte) 0);
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 Contextream, 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.lisp.serializer.address;
-
-import java.net.Inet4Address;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-import java.nio.ByteBuffer;
-
-import org.opendaylight.lispflowmapping.lisp.type.AddressFamilyNumberEnum;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.LispAFIAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.LispIpv4Address;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.ipv4.Ipv4AddressBuilder;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
-
-public class LispIpv4AddressSerializer extends LispAddressSerializer {
-
- private static final LispIpv4AddressSerializer INSTANCE = new LispIpv4AddressSerializer();
-
- // Private constructor prevents instantiation from other classes
- private LispIpv4AddressSerializer() {
- }
-
- public static LispIpv4AddressSerializer getInstance() {
- return INSTANCE;
- }
-
- @Override
- public int getAddressSize(LispAFIAddress lispAddress) {
- return Length.IPV4;
- }
-
- @Override
- protected void serializeData(ByteBuffer buffer, LispAFIAddress lispAddress) {
- LispIpv4Address lispIpvAddress = (LispIpv4Address) lispAddress;
- try {
- buffer.put(Inet4Address.getByName(lispIpvAddress.getIpv4Address().getValue()).getAddress());
- } catch (UnknownHostException e) {
- }
- }
-
- @Override
- protected LispIpv4Address deserializeData(ByteBuffer buffer) {
- byte[] ipBuffer = new byte[4];
- InetAddress address = null;
- buffer.get(ipBuffer);
- try {
- address = InetAddress.getByAddress(ipBuffer);
- } catch (UnknownHostException e) {
- }
- return new Ipv4AddressBuilder().setIpv4Address(new Ipv4Address(address.getHostAddress())).setAfi(AddressFamilyNumberEnum.IP.getIanaCode()).build();
- }
-
- private interface Length {
- int IPV4 = 4;
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 Contextream, 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.lisp.serializer.address;
-
-import java.net.Inet6Address;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-import java.nio.ByteBuffer;
-
-import org.opendaylight.lispflowmapping.lisp.type.AddressFamilyNumberEnum;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.LispAFIAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.LispIpv6Address;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.ipv6.Ipv6AddressBuilder;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
-
-public class LispIpv6AddressSerializer extends LispAddressSerializer {
-
- private static final LispIpv6AddressSerializer INSTANCE = new LispIpv6AddressSerializer();
-
- // Private constructor prevents instantiation from other classes
- private LispIpv6AddressSerializer() {
- }
-
- public static LispIpv6AddressSerializer getInstance() {
- return INSTANCE;
- }
-
- @Override
- public int getAddressSize(LispAFIAddress lispAddress) {
- return Length.IPV6;
- }
-
- @Override
- protected void serializeData(ByteBuffer buffer, LispAFIAddress lispAddress) {
- LispIpv6Address lispIpvAddress = (LispIpv6Address) lispAddress;
- try {
- buffer.put(Inet6Address.getByName(lispIpvAddress.getIpv6Address().getValue()).getAddress());
- } catch (UnknownHostException e) {
- }
- }
-
- @Override
- protected LispIpv6Address deserializeData(ByteBuffer buffer) {
- byte[] ipBuffer = new byte[16];
- InetAddress address = null;
- buffer.get(ipBuffer);
- try {
- address = InetAddress.getByAddress(ipBuffer);
- } catch (UnknownHostException e) {
- }
- return new Ipv6AddressBuilder().setIpv6Address(new Ipv6Address(address.getHostAddress())).setAfi((short) AddressFamilyNumberEnum.IP6.getIanaCode())
- .build();
- }
-
- private interface Length {
- int IPV6 = 16;
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 Contextream, 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.lisp.serializer.address;
-
-import java.nio.ByteBuffer;
-
-import org.opendaylight.lispflowmapping.lisp.type.AddressFamilyNumberEnum;
-import org.opendaylight.lispflowmapping.lisp.type.LispCanonicalAddressFormatEnum;
-import org.opendaylight.lispflowmapping.lisp.util.LispAFIConvertor;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.LcafKeyValueAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.LispAFIAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lcafkeyvalueaddress.KeyBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lcafkeyvalueaddress.ValueBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.lcafkeyvalue.LcafKeyValueAddressAddrBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.PrimitiveAddress;
-
-public class LispKeyValueLCAFSerializer extends LispLCAFAddressSerializer {
-
- private static final LispKeyValueLCAFSerializer INSTANCE = new LispKeyValueLCAFSerializer();
-
- // Private constructor prevents instantiation from other classes
- private LispKeyValueLCAFSerializer() {
- }
-
- public static LispKeyValueLCAFSerializer getInstance() {
- return INSTANCE;
- }
-
- @Override
- protected short getLcafLength(LispAFIAddress lispAddress) {
- return (short) (LispAddressSerializer.getInstance().getAddressSize(
- LispAFIConvertor.toAFIfromPrimitive(((LcafKeyValueAddress) lispAddress).getKey().getPrimitiveAddress())) + LispAddressSerializer.getInstance()
- .getAddressSize(LispAFIConvertor.toAFIfromPrimitive(((LcafKeyValueAddress) lispAddress).getValue().getPrimitiveAddress())));
- }
-
- @Override
- protected void serializeData(ByteBuffer buffer, LispAFIAddress lispAddress) {
- LcafKeyValueAddress lispKeyValueLCAFAddress = ((LcafKeyValueAddress) lispAddress);
- LispAddressSerializer.getInstance().serialize(buffer, LispAFIConvertor.toAFIfromPrimitive(lispKeyValueLCAFAddress.getKey().getPrimitiveAddress()));
- LispAddressSerializer.getInstance().serialize(buffer, LispAFIConvertor.toAFIfromPrimitive(lispKeyValueLCAFAddress.getValue().getPrimitiveAddress()));
- }
-
- @Override
- protected LcafKeyValueAddress deserializeData(ByteBuffer buffer, byte res2, short length) {
- LispAFIAddress keyAddress = LispAddressSerializer.getInstance().deserialize(buffer);
- LispAFIAddress valueAddress = LispAddressSerializer.getInstance().deserialize(buffer);
- LcafKeyValueAddressAddrBuilder builder = new LcafKeyValueAddressAddrBuilder();
- builder.setKey(new KeyBuilder().setPrimitiveAddress((PrimitiveAddress) LispAFIConvertor.toPrimitive(keyAddress)).build());
- builder.setValue(new ValueBuilder().setPrimitiveAddress((PrimitiveAddress) LispAFIConvertor.toPrimitive(valueAddress)).build());
- builder.setAfi(AddressFamilyNumberEnum.LCAF.getIanaCode());
- builder.setLcafType((short) LispCanonicalAddressFormatEnum.KEY_VALUE.getLispCode());
-
- return builder.build();
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 Contextream, 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.lisp.serializer.address;
-
-import java.nio.ByteBuffer;
-
-import org.opendaylight.lispflowmapping.lisp.serializer.address.factory.LispLCAFAddressSerializerFactory;
-import org.opendaylight.lispflowmapping.lisp.serializer.exception.LispSerializationException;
-import org.opendaylight.lispflowmapping.lisp.type.LispCanonicalAddressFormatEnum;
-import org.opendaylight.lispflowmapping.lisp.util.ByteUtil;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.LispAFIAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.LispLcafAddress;
-
-public class LispLCAFAddressSerializer extends LispAddressSerializer {
-
- private static final LispLCAFAddressSerializer INSTANCE = new LispLCAFAddressSerializer();
-
- // Private constructor prevents instantiation from other classes
- protected LispLCAFAddressSerializer() {
- }
-
- public static LispLCAFAddressSerializer getInstance() {
- return INSTANCE;
- }
-
- @Override
- protected LispLcafAddress deserializeData(ByteBuffer buffer) {
- buffer.position(buffer.position() + Length.RES + Length.FLAGS);
- byte lispCode = (byte) ByteUtil.getUnsignedByte(buffer);
- LispCanonicalAddressFormatEnum lcafType = LispCanonicalAddressFormatEnum.valueOf(lispCode);
- byte res2 = buffer.get();
- short length = buffer.getShort();
-
- LispLCAFAddressSerializer serializer = LispLCAFAddressSerializerFactory.getLCAFSerializer(lcafType);
- if (serializer == null) {
- throw new LispSerializationException("Unknown LispLCAFAddress type=" + lispCode);
- }
- return serializer.deserializeData(buffer, res2, length);
- }
-
- protected LispLcafAddress deserializeData(ByteBuffer buffer, byte res2, short length) {
- throw new RuntimeException("Not implemented");
- }
-
- @Override
- public int getAddressSize(LispAFIAddress lispAddress) {
- return Length.LCAF_HEADER
- + LispLCAFAddressSerializerFactory.getLCAFSerializer(
- LispCanonicalAddressFormatEnum.valueOf(((LispLcafAddress) lispAddress).getLcafType())).getLcafLength(lispAddress);
- }
-
- protected short getLcafLength(LispAFIAddress lispAddress) {
- throw new RuntimeException("Not implemented");
- }
-
- @Override
- protected void serializeData(ByteBuffer buffer, LispAFIAddress lispAddress) {
- serializeLCAFAddressHeader(buffer, lispAddress);
-
- LispLCAFAddressSerializer lcafSerializer = LispLCAFAddressSerializerFactory.getLCAFSerializer(LispCanonicalAddressFormatEnum
- .valueOf(((LispLcafAddress) lispAddress).getLcafType()));
- lcafSerializer.serializeData(buffer, lispAddress);
- }
-
- private void serializeLCAFAddressHeader(ByteBuffer buffer, LispAFIAddress lispAddress) {
- LispLcafAddress lispLcafAddress = (LispLcafAddress) lispAddress;
- buffer.putShort((short) 0); // RES + Flags.
- buffer.put(lispLcafAddress.getLcafType().byteValue());
- buffer.put((byte) 0);
- LispLCAFAddressSerializer lcafSerializer = LispLCAFAddressSerializerFactory.getLCAFSerializer(LispCanonicalAddressFormatEnum
- .valueOf(lispLcafAddress.getLcafType()));
- buffer.putShort(lcafSerializer.getLcafLength(lispAddress));
- }
-
- private interface Length {
- int RES = 1;
- int FLAGS = 1;
-
- int LCAF_HEADER = 6;
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 Contextream, 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.lisp.serializer.address;
-
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.opendaylight.lispflowmapping.lisp.type.AddressFamilyNumberEnum;
-import org.opendaylight.lispflowmapping.lisp.type.LispCanonicalAddressFormatEnum;
-import org.opendaylight.lispflowmapping.lisp.util.LispAFIConvertor;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.LcafListAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.LispAFIAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lcaflistaddress.Addresses;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lcaflistaddress.AddressesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.lcaflist.LcafListAddrBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.PrimitiveAddress;
-
-public class LispListLCAFAddressSerializer extends LispLCAFAddressSerializer {
-
- private static final LispListLCAFAddressSerializer INSTANCE = new LispListLCAFAddressSerializer();
-
- // Private constructor prevents instantiation from other classes
- private LispListLCAFAddressSerializer() {
- }
-
- public static LispListLCAFAddressSerializer getInstance() {
- return INSTANCE;
- }
-
- @Override
- protected short getLcafLength(LispAFIAddress lispAddress) {
- short totalSize = 0;
- for (Addresses address : ((LcafListAddress) lispAddress).getAddresses()) {
- totalSize += LispAddressSerializer.getInstance().getAddressSize(LispAFIConvertor.toAFIfromPrimitive(address.getPrimitiveAddress()));
- }
- return totalSize;
- }
-
- @Override
- protected void serializeData(ByteBuffer buffer, LispAFIAddress lispAddress) {
- for (Addresses address : ((LcafListAddress) lispAddress).getAddresses()) {
- LispAddressSerializer.getInstance().serialize(buffer, LispAFIConvertor.toAFIfromPrimitive(address.getPrimitiveAddress()));
- }
- }
-
- @Override
- public LcafListAddress deserializeData(ByteBuffer buffer, byte res2, short length) {
- List<Addresses> addresses = new ArrayList<Addresses>();
- while (length > 0) {
- PrimitiveAddress address = LispAFIConvertor.toPrimitive(LispAddressSerializer.getInstance().deserialize(buffer));
- length -= LispAddressSerializer.getInstance().getAddressSize(LispAFIConvertor.toAFIfromPrimitive(address));
- addresses.add(new AddressesBuilder().setName("Address " + (addresses.size()+1))
- .setPrimitiveAddress((PrimitiveAddress) address).build());
- }
- return new LcafListAddrBuilder().setAddresses(addresses).setAfi(AddressFamilyNumberEnum.LCAF.getIanaCode())
- .setLcafType((short) LispCanonicalAddressFormatEnum.LIST.getLispCode()).build();
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 Contextream, 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.lisp.serializer.address;
-
-import java.nio.ByteBuffer;
-
-import javax.xml.bind.DatatypeConverter;
-
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.LispAFIAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.LispMacAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.mac.MacAddressBuilder;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
-
-public class LispMACAddressSerializer extends LispAddressSerializer {
-
- private static final LispMACAddressSerializer INSTANCE = new LispMACAddressSerializer();
-
- // Private constructor prevents instantiation from other classes
- private LispMACAddressSerializer() {
- }
-
- public static LispMACAddressSerializer getInstance() {
- return INSTANCE;
- }
-
- @Override
- public int getAddressSize(LispAFIAddress lispAddress) {
- return Length.MAC;
- }
-
- @Override
- protected LispMacAddress deserializeData(ByteBuffer buffer) {
- byte[] macBuffer = new byte[6];
- buffer.get(macBuffer);
- StringBuilder sb = new StringBuilder(17);
- for (byte b : macBuffer) {
- if (sb.length() > 0)
- sb.append(':');
- sb.append(String.format("%02x", b));
- }
- return new MacAddressBuilder().setMacAddress(new MacAddress(sb.toString())).setAfi((short) 16389).build();
- }
-
- @Override
- protected void serializeData(ByteBuffer buffer, LispAFIAddress lispAddress) {
- LispMacAddress lispMACAddress = (LispMacAddress) lispAddress;
- String macString = lispMACAddress.getMacAddress().getValue();
- macString = macString.replaceAll(":", "");
- buffer.put(DatatypeConverter.parseHexBinary(macString));
- }
-
- private interface Length {
- int MAC = 6;
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 Contextream, 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.lisp.serializer.address;
-
-import java.nio.ByteBuffer;
-
-import org.opendaylight.lispflowmapping.lisp.type.AddressFamilyNumberEnum;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.LispAFIAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.LispNoAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.no.NoAddressBuilder;
-
-public class LispNoAddressSerializer extends LispAddressSerializer {
-
- private static final LispNoAddressSerializer INSTANCE = new LispNoAddressSerializer();
-
- // Private constructor prevents instantiation from other classes
- private LispNoAddressSerializer() {
- }
-
- public static LispNoAddressSerializer getInstance() {
- return INSTANCE;
- }
-
- @Override
- public int getAddressSize(LispAFIAddress lispAddress) {
- return Length.NO;
- }
-
- @Override
- protected void serializeData(ByteBuffer buffer, LispAFIAddress lispAddress) {
- }
-
- @Override
- protected LispNoAddress deserializeData(ByteBuffer buffer) {
- return new NoAddressBuilder().setAfi(AddressFamilyNumberEnum.NO_ADDRESS.getIanaCode()).build();
- }
-
- private interface Length {
- int NO = 0;
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 Contextream, 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.lisp.serializer.address;
-
-import java.nio.ByteBuffer;
-
-import org.opendaylight.lispflowmapping.lisp.serializer.exception.LispSerializationException;
-import org.opendaylight.lispflowmapping.lisp.type.AddressFamilyNumberEnum;
-import org.opendaylight.lispflowmapping.lisp.type.LispCanonicalAddressFormatEnum;
-import org.opendaylight.lispflowmapping.lisp.util.ByteUtil;
-import org.opendaylight.lispflowmapping.lisp.util.LispAFIConvertor;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.LcafSegmentAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.LispAFIAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lcafsegmentaddress.AddressBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.lcafsegment.LcafSegmentAddrBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.PrimitiveAddress;
-
-public class LispSegmentLCAFAddressSerializer extends LispLCAFAddressSerializer {
-
- private static final int MAX_INSTANCE_ID = 16777216;
- private static final LispSegmentLCAFAddressSerializer INSTANCE = new LispSegmentLCAFAddressSerializer();
-
- // Private constructor prevents instantiation from other classes
- private LispSegmentLCAFAddressSerializer() {
- }
-
- public static LispSegmentLCAFAddressSerializer getInstance() {
- return INSTANCE;
- }
-
- @Override
- protected short getLcafLength(LispAFIAddress lispAddress) {
- return (short) (Length.INSTANCE + LispAddressSerializer.getInstance().getAddressSize(
- LispAFIConvertor.toAFIfromPrimitive(((LcafSegmentAddress) lispAddress).getAddress().getPrimitiveAddress())));
- }
-
- @Override
- protected void serializeData(ByteBuffer buffer, LispAFIAddress lispAddress) {
- // The IID mask-len field is in the LCAF header on the res2 position
- buffer.put(buffer.position() - 3, ((LcafSegmentAddress) lispAddress).getIidMaskLength().byteValue());
-
- buffer.putInt(((LcafSegmentAddress) lispAddress).getInstanceId().intValue());
- LispAddressSerializer.getInstance().serialize(buffer, LispAFIConvertor.toAFIfromPrimitive(((LcafSegmentAddress) lispAddress).getAddress().getPrimitiveAddress()));
- }
-
- @Override
- protected LcafSegmentAddress deserializeData(ByteBuffer buffer, byte res2, short length) {
- long instanceId = (int) ByteUtil.asUnsignedInteger(buffer.getInt());
-
- if (instanceId > MAX_INSTANCE_ID) {
- throw new LispSerializationException("Instance ID is longer than 24 bits. got " + instanceId);
- }
- LispAFIAddress address = LispAddressSerializer.getInstance().deserialize(buffer);
- LcafSegmentAddrBuilder builder = new LcafSegmentAddrBuilder();
- builder.setInstanceId(instanceId);
- builder.setIidMaskLength((short) res2);
- builder.setAfi(AddressFamilyNumberEnum.LCAF.getIanaCode()).setLcafType((short) LispCanonicalAddressFormatEnum.SEGMENT.getLispCode())
- .setAddress(new AddressBuilder().setPrimitiveAddress((PrimitiveAddress) LispAFIConvertor.toPrimitive(address)).build());
-
- return builder.build();
- }
-
- private interface Length {
- int INSTANCE = 4;
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 Contextream, 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.lisp.serializer.address;
-
-import java.nio.ByteBuffer;
-
-import org.opendaylight.lispflowmapping.lisp.type.AddressFamilyNumberEnum;
-import org.opendaylight.lispflowmapping.lisp.type.LispCanonicalAddressFormatEnum;
-import org.opendaylight.lispflowmapping.lisp.util.ByteUtil;
-import org.opendaylight.lispflowmapping.lisp.util.LispAFIConvertor;
-import org.opendaylight.lispflowmapping.lisp.util.MaskUtil;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.LcafSourceDestAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.LispAFIAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lcafsourcedestaddress.DstAddressBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lcafsourcedestaddress.SrcAddressBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.lcafsourcedest.LcafSourceDestAddrBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.PrimitiveAddress;
-
-public class LispSourceDestLCAFAddressSerializer extends LispLCAFAddressSerializer {
-
- private static final LispSourceDestLCAFAddressSerializer INSTANCE = new LispSourceDestLCAFAddressSerializer();
-
- // Private constructor prevents instantiation from other classes
- private LispSourceDestLCAFAddressSerializer() {
- }
-
- public static LispSourceDestLCAFAddressSerializer getInstance() {
- return INSTANCE;
- }
-
- @Override
- protected short getLcafLength(LispAFIAddress lispAddress) {
- return (short) (Length.ALL_FIELDS
- + LispAddressSerializer.getInstance().getAddressSize(
- LispAFIConvertor.toAFIfromPrimitive(((LcafSourceDestAddress) lispAddress).getSrcAddress().getPrimitiveAddress())) + LispAddressSerializer
- .getInstance().getAddressSize(LispAFIConvertor.toAFIfromPrimitive(((LcafSourceDestAddress) lispAddress).getDstAddress().getPrimitiveAddress())));
- }
-
- @Override
- protected void serializeData(ByteBuffer buffer, LispAFIAddress lispAddress) {
- LcafSourceDestAddress lispSourceDestLCAFAddress = ((LcafSourceDestAddress) lispAddress);
- buffer.putShort((short) 0);
- buffer.put(lispSourceDestLCAFAddress.getSrcMaskLength().byteValue());
- buffer.put(lispSourceDestLCAFAddress.getDstMaskLength().byteValue());
- LispAddressSerializer.getInstance().serialize(buffer, LispAFIConvertor.toAFIfromPrimitive(lispSourceDestLCAFAddress.getSrcAddress().getPrimitiveAddress()));
- LispAddressSerializer.getInstance().serialize(buffer, LispAFIConvertor.toAFIfromPrimitive(lispSourceDestLCAFAddress.getDstAddress().getPrimitiveAddress()));
- }
-
- @Override
- protected LcafSourceDestAddress deserializeData(ByteBuffer buffer, byte res2, short length) {
- short res = buffer.getShort();
- short srcMaskLength = (short) ByteUtil.getUnsignedByte(buffer);
- short dstMaskLength = (short) ByteUtil.getUnsignedByte(buffer);
- LispAFIAddress srcAddress = LispAddressSerializer.getInstance().deserialize(buffer);
- srcAddress = MaskUtil.fixMask(srcAddress, srcMaskLength);
- LispAFIAddress dstAddress = LispAddressSerializer.getInstance().deserialize(buffer);
- dstAddress = MaskUtil.fixMask(dstAddress, dstMaskLength);
- LcafSourceDestAddrBuilder builder = new LcafSourceDestAddrBuilder();
- builder.setDstMaskLength((short) dstMaskLength).setSrcMaskLength((short) srcMaskLength);
- builder.setSrcAddress(new SrcAddressBuilder().setPrimitiveAddress((PrimitiveAddress) LispAFIConvertor.toPrimitive(srcAddress)).build());
- builder.setDstAddress(new DstAddressBuilder().setPrimitiveAddress((PrimitiveAddress) LispAFIConvertor.toPrimitive(dstAddress)).build());
- builder.setAfi(AddressFamilyNumberEnum.LCAF.getIanaCode());
- builder.setLcafType((short) LispCanonicalAddressFormatEnum.SOURCE_DEST.getLispCode());
-
- return builder.build();
- }
-
- private interface Length {
- int SOURCE_MASK_LENGTH = 1;
- int DEST_MASK_LENGTH = 1;
- int RESERVED = 2;
- int ALL_FIELDS = SOURCE_MASK_LENGTH + DEST_MASK_LENGTH + RESERVED;
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 Contextream, 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.lisp.serializer.address;
-
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.commons.lang3.BooleanUtils;
-import org.opendaylight.lispflowmapping.lisp.type.AddressFamilyNumberEnum;
-import org.opendaylight.lispflowmapping.lisp.type.LispCanonicalAddressFormatEnum;
-import org.opendaylight.lispflowmapping.lisp.util.ByteUtil;
-import org.opendaylight.lispflowmapping.lisp.util.LispAFIConvertor;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.LcafTrafficEngineeringAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.LispAFIAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lcaftrafficengineeringaddress.Hops;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lcaftrafficengineeringaddress.HopsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.lcaftrafficengineering.LcafTrafficEngineeringAddrBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.PrimitiveAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.reencaphop.HopBuilder;
-
-public class LispTrafficEngineeringLCAFAddressSerializer extends LispLCAFAddressSerializer {
-
- private static final LispTrafficEngineeringLCAFAddressSerializer INSTANCE = new LispTrafficEngineeringLCAFAddressSerializer();
-
- // Private constructor prevents instantiation from other classes
- private LispTrafficEngineeringLCAFAddressSerializer() {
- }
-
- public static LispTrafficEngineeringLCAFAddressSerializer getInstance() {
- return INSTANCE;
- }
-
- @Override
- protected short getLcafLength(LispAFIAddress lispAddress) {
- short totalSize = 0;
- if (((LcafTrafficEngineeringAddress) lispAddress).getHops() != null) {
- for (Hops hop : ((LcafTrafficEngineeringAddress) lispAddress).getHops()) {
- totalSize += LispAddressSerializer.getInstance().getAddressSize(LispAFIConvertor.toAFIfromPrimitive(hop.getHop().getPrimitiveAddress())) + 2;
- }
- }
- return totalSize;
- }
-
- @Override
- protected void serializeData(ByteBuffer buffer, LispAFIAddress lispAddress) {
- if (((LcafTrafficEngineeringAddress) lispAddress).getHops() != null) {
- for (Hops hop : ((LcafTrafficEngineeringAddress) lispAddress).getHops()) {
- buffer.put((byte) 0);
- buffer.put((byte) (ByteUtil.boolToBit(BooleanUtils.isTrue(hop.isLookup()), Flags.LOOKUP) | //
- ByteUtil.boolToBit(BooleanUtils.isTrue(hop.isRLOCProbe()), Flags.RLOC_PROBE) | //
- ByteUtil.boolToBit(BooleanUtils.isTrue(hop.isStrict()), Flags.STRICT)));
- LispAddressSerializer.getInstance().serialize(buffer, LispAFIConvertor.toAFIfromPrimitive(hop.getHop().getPrimitiveAddress()));
- }
- }
- }
-
- @Override
- protected LcafTrafficEngineeringAddress deserializeData(ByteBuffer buffer, byte res2, short length) {
- List<Hops> hops = new ArrayList<Hops>();
- while (length > 0) {
- byte flags = (byte) buffer.getShort();
- boolean lookup = ByteUtil.extractBit(flags, Flags.LOOKUP);
- boolean RLOCProbe = ByteUtil.extractBit(flags, Flags.RLOC_PROBE);
- boolean strict = ByteUtil.extractBit(flags, Flags.STRICT);
- PrimitiveAddress address = LispAFIConvertor.toPrimitive(LispAddressSerializer.getInstance().deserialize(buffer));
- HopsBuilder builder = new HopsBuilder();
- builder.setLookup(lookup);
- builder.setRLOCProbe(RLOCProbe);
- builder.setStrict(strict);
- builder.setHop(new HopBuilder().setPrimitiveAddress(address).build());
- builder.setName("Hop " + (hops.size()+1));
- length -= LispAddressSerializer.getInstance().getAddressSize(LispAFIConvertor.toAFIfromPrimitive(address)) + 2;
- hops.add(builder.build());
- }
- return new LcafTrafficEngineeringAddrBuilder().setAfi(AddressFamilyNumberEnum.LCAF.getIanaCode())
- .setLcafType((short) LispCanonicalAddressFormatEnum.TRAFFIC_ENGINEERING.getLispCode()).setHops(hops).build();
- }
-
- private interface Flags {
- int LOOKUP = 0x04;
- int RLOC_PROBE = 0x02;
- int STRICT = 0x01;
- }
-
-}
--- /dev/null
+/*
+ * Copyright (c) 2014 Contextream, 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.lisp.serializer.address;
+
+import java.nio.ByteBuffer;
+
+import javax.xml.bind.DatatypeConverter;
+
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana.afn.safi.rev130704.AddressFamily;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.LispAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.MacAfi;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SimpleAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Mac;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.MacBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.EidBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.Rloc;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.RlocBuilder;
+
+public class MacSerializer extends LispAddressSerializer {
+
+ private static final MacSerializer INSTANCE = new MacSerializer();
+
+ // Private constructor prevents instantiation from other classes
+ private MacSerializer() {
+ }
+
+ public static MacSerializer getInstance() {
+ return INSTANCE;
+ }
+
+ @Override
+ public int getAddressSize(LispAddress lispAddress) {
+ return Length.MAC;
+ }
+
+ @Override
+ public int getAddressSize(SimpleAddress simpleAddress) {
+ return Length.MAC;
+ }
+
+ @Override
+ protected short getAfi() {
+ return (short) AddressFamily._48BitMac.getIntValue();
+ }
+
+ @Override
+ protected void serializeData(ByteBuffer buffer, LispAddress lispAddress) {
+ Mac mac = (Mac) lispAddress.getAddress();
+ String macString = mac.getMac().getValue();
+ macString = macString.replaceAll(":", "");
+ buffer.put(DatatypeConverter.parseHexBinary(macString));
+ }
+
+ @Override
+ protected void serializeData(ByteBuffer buffer, SimpleAddress simpleAddress) {
+ String macString = simpleAddress.getMacAddress().getValue();
+ macString = macString.replaceAll(":", "");
+ buffer.put(DatatypeConverter.parseHexBinary(macString));
+ }
+
+ @Override
+ protected Eid deserializeEidData(ByteBuffer buffer, LispAddressSerializerContext ctx) {
+ EidBuilder eb = new EidBuilder();
+ eb.setAddressType(MacAfi.class);
+ eb.setVirtualNetworkId(getVni(ctx));
+ eb.setAddress(new MacBuilder().setMac(deserializeData(buffer)).build());
+ return eb.build();
+ }
+
+ @Override
+ protected Rloc deserializeRlocData(ByteBuffer buffer) {
+ RlocBuilder rb = new RlocBuilder();
+ rb.setAddressType(MacAfi.class);
+ rb.setVirtualNetworkId(null);
+ rb.setAddress(new MacBuilder().setMac(deserializeData(buffer)).build());
+ return rb.build();
+ }
+
+ @Override
+ protected SimpleAddress deserializeSimpleAddressData(ByteBuffer buffer, LispAddressSerializerContext ctx) {
+ return new SimpleAddress(deserializeData(buffer));
+ }
+
+ private MacAddress deserializeData(ByteBuffer buffer) {
+ byte[] macBuffer = new byte[6];
+ buffer.get(macBuffer);
+ StringBuilder sb = new StringBuilder(17);
+ for (byte b : macBuffer) {
+ if (sb.length() > 0)
+ sb.append(':');
+ sb.append(String.format("%02x", b));
+ }
+ return new MacAddress(sb.toString());
+ }
+
+ private interface Length {
+ int MAC = 6;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2014 Contextream, 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.lisp.serializer.address;
+
+import java.nio.ByteBuffer;
+
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.LispAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.NoAddressAfi;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.NoAddressBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.EidBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.Rloc;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.RlocBuilder;
+
+public class NoAddressSerializer extends LispAddressSerializer {
+
+ private static final NoAddressSerializer INSTANCE = new NoAddressSerializer();
+
+ // Private constructor prevents instantiation from other classes
+ private NoAddressSerializer() {
+ }
+
+ public static NoAddressSerializer getInstance() {
+ return INSTANCE;
+ }
+
+ @Override
+ public int getAddressSize(LispAddress lispAddress) {
+ return Length.NO;
+ }
+
+ @Override
+ protected short getAfi() {
+ return (short) 0;
+ }
+
+ @Override
+ protected void serializeData(ByteBuffer buffer, LispAddress lispAddress) {
+ }
+
+ @Override
+ protected Eid deserializeEidData(ByteBuffer buffer, LispAddressSerializerContext ctx) {
+ EidBuilder eb = new EidBuilder();
+ eb.setAddressType(NoAddressAfi.class);
+ eb.setVirtualNetworkId(getVni(ctx));
+ eb.setAddress(new NoAddressBuilder().setNoAddress(true).build());
+ return eb.build();
+ }
+
+ @Override
+ protected Rloc deserializeRlocData(ByteBuffer buffer) {
+ RlocBuilder rb = new RlocBuilder();
+ rb.setAddressType(NoAddressAfi.class);
+ rb.setVirtualNetworkId(null);
+ rb.setAddress(new NoAddressBuilder().setNoAddress(true).build());
+ return rb.build();
+ }
+
+ private interface Length {
+ int NO = 0;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. 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.lisp.serializer.address;
+
+import java.nio.ByteBuffer;
+
+import org.opendaylight.lispflowmapping.lisp.serializer.address.factory.LispAddressSerializerFactory;
+import org.opendaylight.lispflowmapping.lisp.serializer.exception.LispSerializationException;
+import org.opendaylight.lispflowmapping.lisp.util.AddressTypeMap;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.LispAddressFamily;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SimpleAddress;
+
+/**
+ * @author Lorand Jakab
+ *
+ */
+public class SimpleAddressSerializer {
+
+ private static final SimpleAddressSerializer INSTANCE = new SimpleAddressSerializer();
+
+ // Private constructor prevents instantiation from other classes
+ protected SimpleAddressSerializer() {
+ }
+
+ public static SimpleAddressSerializer getInstance() {
+ return INSTANCE;
+ }
+
+ public int getAddressSize(SimpleAddress address) {
+ LispAddressSerializer serializer = LispAddressSerializerFactory.getSerializer(
+ AddressTypeMap.getSimpleAddressInnerType(address));
+ return Length.AFI + serializer.getAddressSize(address);
+ }
+
+ public void serialize(ByteBuffer buffer, SimpleAddress address) {
+ LispAddressSerializer serializer = LispAddressSerializerFactory.getSerializer(
+ AddressTypeMap.getSimpleAddressInnerType(address));
+ buffer.putShort(serializer.getAfi());
+ serializer.serializeData(buffer, address);
+ }
+
+ public SimpleAddress deserialize(ByteBuffer buffer, LispAddressSerializerContext ctx) {
+ short afi = buffer.getShort();
+ // AddressTypeMap indexes IPv4 and IPv6 prefixes (vs simple addresses) with the negative AFI values -1 and -2
+ if ((afi == 1 || afi == 2) && ctx != null &&
+ ctx.getMaskLen() != LispAddressSerializerContext.MASK_LEN_MISSING) {
+ afi *= -1;
+ }
+ Class <? extends LispAddressFamily> addressType = AddressTypeMap.getAddressType(afi);
+ LispAddressSerializer serializer = LispAddressSerializerFactory.getSerializer(addressType);
+ if (serializer == null) {
+ throw new LispSerializationException("Unknown AFI: " + afi);
+ }
+ try {
+ return serializer.deserializeSimpleAddressData(buffer, ctx);
+ } catch (RuntimeException e) {
+ throw new LispSerializationException("Problem deserializing AFI " + afi + " in SimpleAddress context", e);
+ }
+ }
+
+ private interface Length {
+ int AFI = 2;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2014 Contextream, 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.lisp.serializer.address;
+
+import java.nio.ByteBuffer;
+
+import org.opendaylight.lispflowmapping.lisp.type.LispCanonicalAddressFormatEnum;
+import org.opendaylight.lispflowmapping.lisp.util.ByteUtil;
+import org.opendaylight.lispflowmapping.lisp.util.MaskUtil;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana.afn.safi.rev130704.AddressFamily;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.LispAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SimpleAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SourceDestKeyLcaf;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.SourceDestKey;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.source.dest.key.SourceDestKeyBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.EidBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.Rloc;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.RlocBuilder;
+
+public class SourceDestKeySerializer extends LcafSerializer {
+
+ private static final SourceDestKeySerializer INSTANCE = new SourceDestKeySerializer();
+
+ // Private constructor prevents instantiation from other classes
+ private SourceDestKeySerializer() {
+ }
+
+ public static SourceDestKeySerializer getInstance() {
+ return INSTANCE;
+ }
+
+ @Override
+ protected byte getLcafType() {
+ return LispCanonicalAddressFormatEnum.SOURCE_DEST.getLispCode();
+ }
+
+ @Override
+ protected short getLcafLength(LispAddress lispAddress) {
+ SourceDestKey sdk = (SourceDestKey) lispAddress.getAddress();
+ return (short) (Length.ALL_FIELDS
+ + SimpleAddressSerializer.getInstance().getAddressSize(new SimpleAddress(sdk.getSourceDestKey().getSource()))
+ + SimpleAddressSerializer.getInstance().getAddressSize(new SimpleAddress(sdk.getSourceDestKey().getDest())));
+ }
+
+ @Override
+ protected short getAfi() {
+ return (short) AddressFamily.LispCanonicalAddressFormat.getIntValue();
+ }
+
+ @Override
+ protected void serializeData(ByteBuffer buffer, LispAddress lispAddress) {
+ SourceDestKey sdk = (SourceDestKey) lispAddress.getAddress();
+ buffer.putShort((short) 0);
+ buffer.put((byte) MaskUtil.getMaskForIpPrefix(sdk.getSourceDestKey().getSource()));
+ buffer.put((byte) MaskUtil.getMaskForIpPrefix(sdk.getSourceDestKey().getDest()));
+ SimpleAddressSerializer.getInstance().serialize(buffer, new SimpleAddress(sdk.getSourceDestKey().getSource()));
+ SimpleAddressSerializer.getInstance().serialize(buffer, new SimpleAddress(sdk.getSourceDestKey().getDest()));
+ }
+
+ @Override
+ protected Eid deserializeLcafEidData(ByteBuffer buffer, byte res2, short length, LispAddressSerializerContext ctx) {
+ EidBuilder eb = new EidBuilder();
+ eb.setAddressType(SourceDestKeyLcaf.class);
+ eb.setVirtualNetworkId(getVni(ctx));
+ eb.setAddress(deserializeData(buffer, ctx));
+ return eb.build();
+ }
+
+ @Override
+ protected Rloc deserializeLcafRlocData(ByteBuffer buffer, byte res2, short length, LispAddressSerializerContext ctx) {
+ RlocBuilder rb = new RlocBuilder();
+ rb.setAddressType(SourceDestKeyLcaf.class);
+ rb.setVirtualNetworkId(null);
+ rb.setAddress(deserializeData(buffer, ctx));
+ return rb.build();
+ }
+
+ private Address deserializeData(ByteBuffer buffer, LispAddressSerializerContext ctx) {
+ buffer.getShort(); // reserved bytes
+ short srcMaskLength = (short) ByteUtil.getUnsignedByte(buffer);
+ short dstMaskLength = (short) ByteUtil.getUnsignedByte(buffer);
+ ctx.setMaskLen(srcMaskLength);
+ SimpleAddress srcAddress = SimpleAddressSerializer.getInstance().deserialize(buffer, ctx);
+ ctx.setMaskLen(dstMaskLength);
+ SimpleAddress dstAddress = SimpleAddressSerializer.getInstance().deserialize(buffer, ctx);
+ SourceDestKeyBuilder sdb = new SourceDestKeyBuilder();
+ sdb.setSource(srcAddress.getIpPrefix());
+ sdb.setDest(dstAddress.getIpPrefix());
+ return new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.SourceDestKeyBuilder()
+ .setSourceDestKey(sdb.build()).build();
+ }
+
+ private interface Length {
+ int SOURCE_MASK_LENGTH = 1;
+ int DEST_MASK_LENGTH = 1;
+ int RESERVED = 2;
+ int ALL_FIELDS = SOURCE_MASK_LENGTH + DEST_MASK_LENGTH + RESERVED;
+ }
+}
+++ /dev/null
-/*
- * Copyright (c) 2014 Contextream, 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.lisp.serializer.address.factory;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.opendaylight.lispflowmapping.lisp.serializer.address.LispAddressSerializer;
-import org.opendaylight.lispflowmapping.lisp.serializer.address.LispDistinguishedNameAddressSerializer;
-import org.opendaylight.lispflowmapping.lisp.serializer.address.LispIpv4AddressSerializer;
-import org.opendaylight.lispflowmapping.lisp.serializer.address.LispIpv6AddressSerializer;
-import org.opendaylight.lispflowmapping.lisp.serializer.address.LispLCAFAddressSerializer;
-import org.opendaylight.lispflowmapping.lisp.serializer.address.LispMACAddressSerializer;
-import org.opendaylight.lispflowmapping.lisp.serializer.address.LispNoAddressSerializer;
-import org.opendaylight.lispflowmapping.lisp.type.AddressFamilyNumberEnum;
-
-public class LispAFIAddressSerializerFactory {
-
- private static Map<AddressFamilyNumberEnum, LispAddressSerializer> afiToSearializerMap;
-
- private static void initializeMap() {
- afiToSearializerMap = new HashMap<AddressFamilyNumberEnum, LispAddressSerializer>();
- afiToSearializerMap.put(AddressFamilyNumberEnum.IP, LispIpv4AddressSerializer.getInstance());
- afiToSearializerMap.put(AddressFamilyNumberEnum.NO_ADDRESS, LispNoAddressSerializer.getInstance());
- afiToSearializerMap.put(AddressFamilyNumberEnum.IP6, LispIpv6AddressSerializer.getInstance());
- afiToSearializerMap.put(AddressFamilyNumberEnum.DISTINGUISHED_NAME, LispDistinguishedNameAddressSerializer.getInstance());
- afiToSearializerMap.put(AddressFamilyNumberEnum.LCAF, LispLCAFAddressSerializer.getInstance());
- afiToSearializerMap.put(AddressFamilyNumberEnum.MAC, LispMACAddressSerializer.getInstance());
-
- }
-
- public static LispAddressSerializer getSerializer(AddressFamilyNumberEnum afi) {
- if (afiToSearializerMap == null) {
- initializeMap();
- }
- return afiToSearializerMap.get(afi);
- }
-
-}
--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. 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.lisp.serializer.address.factory;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.opendaylight.lispflowmapping.lisp.serializer.address.AfiListSerializer;
+import org.opendaylight.lispflowmapping.lisp.serializer.address.ApplicationDataSerializer;
+import org.opendaylight.lispflowmapping.lisp.serializer.address.DistinguishedNameSerializer;
+import org.opendaylight.lispflowmapping.lisp.serializer.address.ExplicitLocatorPathSerializer;
+import org.opendaylight.lispflowmapping.lisp.serializer.address.InstanceIdSerializer;
+import org.opendaylight.lispflowmapping.lisp.serializer.address.Ipv4PrefixSerializer;
+import org.opendaylight.lispflowmapping.lisp.serializer.address.Ipv6PrefixSerializer;
+import org.opendaylight.lispflowmapping.lisp.serializer.address.Ipv6Serializer;
+import org.opendaylight.lispflowmapping.lisp.serializer.address.KeyValueAddressSerializer;
+import org.opendaylight.lispflowmapping.lisp.serializer.address.LcafSerializer;
+import org.opendaylight.lispflowmapping.lisp.serializer.address.LispAddressSerializer;
+import org.opendaylight.lispflowmapping.lisp.serializer.address.Ipv4Serializer;
+import org.opendaylight.lispflowmapping.lisp.serializer.address.MacSerializer;
+import org.opendaylight.lispflowmapping.lisp.serializer.address.NoAddressSerializer;
+import org.opendaylight.lispflowmapping.lisp.serializer.address.SourceDestKeySerializer;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.AfiListLcaf;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.ApplicationDataLcaf;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.DistinguishedNameAfi;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.ExplicitLocatorPathLcaf;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.InstanceIdLcaf;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv4Afi;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv4PrefixAfi;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv6Afi;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv6PrefixAfi;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.KeyValueAddressLcaf;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Lcaf;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.LispAddressFamily;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.MacAfi;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.NoAddressAfi;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SourceDestKeyLcaf;
+
+/**
+ * Factory for LispAddress (de)serializers
+ *
+ * @author Lorand Jakab
+ *
+ */
+public class LispAddressSerializerFactory {
+ private static Map<Class<? extends LispAddressFamily>, LispAddressSerializer> addressTypeToSerializerMap;
+
+ private static void initializeMap() {
+ addressTypeToSerializerMap = new HashMap<Class<? extends LispAddressFamily>, LispAddressSerializer>();
+ addressTypeToSerializerMap.put(NoAddressAfi.class, NoAddressSerializer.getInstance());
+ addressTypeToSerializerMap.put(Ipv4Afi.class, Ipv4Serializer.getInstance());
+ addressTypeToSerializerMap.put(Ipv4PrefixAfi.class, Ipv4PrefixSerializer.getInstance());
+ addressTypeToSerializerMap.put(Ipv6Afi.class, Ipv6Serializer.getInstance());
+ addressTypeToSerializerMap.put(Ipv6PrefixAfi.class, Ipv6PrefixSerializer.getInstance());
+ addressTypeToSerializerMap.put(MacAfi.class, MacSerializer.getInstance());
+ addressTypeToSerializerMap.put(DistinguishedNameAfi.class, DistinguishedNameSerializer.getInstance());
+ addressTypeToSerializerMap.put(Lcaf.class, LcafSerializer.getInstance());
+ addressTypeToSerializerMap.put(AfiListLcaf.class, AfiListSerializer.getInstance());
+ addressTypeToSerializerMap.put(InstanceIdLcaf.class, InstanceIdSerializer.getInstance());
+ addressTypeToSerializerMap.put(ApplicationDataLcaf.class, ApplicationDataSerializer.getInstance());
+ addressTypeToSerializerMap.put(ExplicitLocatorPathLcaf.class, ExplicitLocatorPathSerializer.getInstance());
+ addressTypeToSerializerMap.put(SourceDestKeyLcaf.class, SourceDestKeySerializer.getInstance());
+ addressTypeToSerializerMap.put(KeyValueAddressLcaf.class, KeyValueAddressSerializer.getInstance());
+ }
+
+ public static LispAddressSerializer getSerializer(Class<? extends LispAddressFamily> clazz) {
+ if (addressTypeToSerializerMap == null) {
+ initializeMap();
+ }
+ return addressTypeToSerializerMap.get(clazz);
+ }
+}
+++ /dev/null
-/*
- * Copyright (c) 2014 Contextream, 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.lisp.serializer.address.factory;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.opendaylight.lispflowmapping.lisp.serializer.address.LispApplicationDataLCAFAddressSerializer;
-import org.opendaylight.lispflowmapping.lisp.serializer.address.LispKeyValueLCAFSerializer;
-import org.opendaylight.lispflowmapping.lisp.serializer.address.LispLCAFAddressSerializer;
-import org.opendaylight.lispflowmapping.lisp.serializer.address.LispListLCAFAddressSerializer;
-import org.opendaylight.lispflowmapping.lisp.serializer.address.LispSegmentLCAFAddressSerializer;
-import org.opendaylight.lispflowmapping.lisp.serializer.address.LispSourceDestLCAFAddressSerializer;
-import org.opendaylight.lispflowmapping.lisp.serializer.address.LispTrafficEngineeringLCAFAddressSerializer;
-import org.opendaylight.lispflowmapping.lisp.type.LispCanonicalAddressFormatEnum;
-
-public class LispLCAFAddressSerializerFactory {
-
- private static Map<LispCanonicalAddressFormatEnum, LispLCAFAddressSerializer> lcafToSearializerMap;
-
- private static void initializeMap() {
-
- lcafToSearializerMap = new HashMap<LispCanonicalAddressFormatEnum, LispLCAFAddressSerializer>();
- lcafToSearializerMap.put(LispCanonicalAddressFormatEnum.LIST, LispListLCAFAddressSerializer.getInstance());
- lcafToSearializerMap.put(LispCanonicalAddressFormatEnum.SEGMENT, LispSegmentLCAFAddressSerializer.getInstance());
- lcafToSearializerMap.put(LispCanonicalAddressFormatEnum.APPLICATION_DATA, LispApplicationDataLCAFAddressSerializer.getInstance());
- lcafToSearializerMap.put(LispCanonicalAddressFormatEnum.TRAFFIC_ENGINEERING, LispTrafficEngineeringLCAFAddressSerializer.getInstance());
- lcafToSearializerMap.put(LispCanonicalAddressFormatEnum.SOURCE_DEST, LispSourceDestLCAFAddressSerializer.getInstance());
- lcafToSearializerMap.put(LispCanonicalAddressFormatEnum.KEY_VALUE, LispKeyValueLCAFSerializer.getInstance());
- }
-
- public static LispLCAFAddressSerializer getLCAFSerializer(LispCanonicalAddressFormatEnum lcaf) {
- if (lcafToSearializerMap == null) {
- initializeMap();
- }
- return lcafToSearializerMap.get(lcaf);
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 Contextream, 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.lisp.type;
-
-/**
- * The AFI enum:
- * http://www.iana.org/assignments/address-family-numbers/address-family
- * -numbers.xhtml
- */
-public enum AddressFamilyNumberEnum {
- NO_ADDRESS(0), //
- IP(1), //
- IP6(2), //
- DISTINGUISHED_NAME(17), //
- AS(18), //
- LCAF(16387), //
- MAC(16389), //
- UNKNOWN(-1);
-
- private short ianaCode;
-
- private AddressFamilyNumberEnum(int ianaCode) {
- this.ianaCode = (short) ianaCode;
- }
-
- public short getIanaCode() {
- return ianaCode;
- }
-
- public static AddressFamilyNumberEnum valueOf(short ianaCode) {
- for (AddressFamilyNumberEnum val : values()) {
- if (val.getIanaCode() == ianaCode) {
- return val;
- }
- }
- return UNKNOWN;
- }
-}
--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. 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.lisp.util;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.opendaylight.lispflowmapping.lisp.type.LispCanonicalAddressFormatEnum;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana.afn.safi.rev130704.AddressFamily;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.AfiListLcaf;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.ApplicationDataLcaf;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.AsNumberAfi;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.DistinguishedNameAfi;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.ExplicitLocatorPathLcaf;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.InstanceIdLcaf;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv4Afi;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv4PrefixAfi;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv6Afi;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv6PrefixAfi;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.KeyValueAddressLcaf;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Lcaf;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.LispAddressFamily;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.MacAfi;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.NoAddressAfi;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SimpleAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SourceDestKeyLcaf;
+
+/**
+ * This class contains static HashMaps of AFIs and LCAF types to LispAddressFamily identities
+ *
+ * @author Lorand Jakab
+ *
+ */
+public final class AddressTypeMap {
+ private static Map<Short, Class<? extends LispAddressFamily>> afiToAddressTypeMap;
+ private static Map<Short, Class<? extends LispAddressFamily>> lcafToAddressTypeMap;
+
+ private static void initializeAfiMap() {
+ afiToAddressTypeMap = new HashMap<Short, Class<? extends LispAddressFamily>>();
+ afiToAddressTypeMap.put((short) 0, NoAddressAfi.class);
+ afiToAddressTypeMap.put((short) AddressFamily.IpV4.getIntValue(), Ipv4Afi.class);
+ afiToAddressTypeMap.put((short) (AddressFamily.IpV4.getIntValue() * -1), Ipv4PrefixAfi.class);
+ afiToAddressTypeMap.put((short) AddressFamily.IpV6.getIntValue(), Ipv6Afi.class);
+ afiToAddressTypeMap.put((short) (AddressFamily.IpV6.getIntValue() * -1), Ipv6PrefixAfi.class);
+ afiToAddressTypeMap.put((short) AddressFamily.DistinguishedName.getIntValue(), DistinguishedNameAfi.class);
+ afiToAddressTypeMap.put((short) AddressFamily.AsNumber.getIntValue(), AsNumberAfi.class);
+ afiToAddressTypeMap.put((short) AddressFamily.LispCanonicalAddressFormat.getIntValue(), Lcaf.class);
+ afiToAddressTypeMap.put((short) AddressFamily._48BitMac.getIntValue(), MacAfi.class);
+ }
+
+ private static void initializeLcafMap() {
+ lcafToAddressTypeMap = new HashMap<Short, Class<? extends LispAddressFamily>>();
+ lcafToAddressTypeMap.put((short) LispCanonicalAddressFormatEnum.LIST.getLispCode(), AfiListLcaf.class);
+ lcafToAddressTypeMap.put((short) LispCanonicalAddressFormatEnum.SEGMENT.getLispCode(), InstanceIdLcaf.class);
+ lcafToAddressTypeMap.put((short) LispCanonicalAddressFormatEnum.APPLICATION_DATA.getLispCode(),
+ ApplicationDataLcaf.class);
+ lcafToAddressTypeMap.put((short) LispCanonicalAddressFormatEnum.TRAFFIC_ENGINEERING.getLispCode(),
+ ExplicitLocatorPathLcaf.class);
+ lcafToAddressTypeMap.put((short) LispCanonicalAddressFormatEnum.SOURCE_DEST.getLispCode(),
+ SourceDestKeyLcaf.class);
+ lcafToAddressTypeMap.put((short) LispCanonicalAddressFormatEnum.KEY_VALUE.getLispCode(),
+ KeyValueAddressLcaf.class);
+ // TODO
+ }
+
+ public static Class<? extends LispAddressFamily> getAddressType(short afi) {
+ if (afiToAddressTypeMap == null) {
+ initializeAfiMap();
+ }
+ return afiToAddressTypeMap.get(afi);
+ }
+
+ public static Class<? extends LispAddressFamily> getLcafType(short lcafType) {
+ if (lcafToAddressTypeMap == null) {
+ initializeLcafMap();
+ }
+ return lcafToAddressTypeMap.get(lcafType);
+ }
+
+ public static Class <? extends LispAddressFamily> getSimpleAddressInnerType(SimpleAddress address) {
+ if (address == null) {
+ return null;
+ } else if (address.getIpAddress() != null) {
+ if (address.getIpAddress().getIpv4Address() != null) {
+ return Ipv4Afi.class;
+ } else if (address.getIpAddress().getIpv6Address() != null) {
+ return Ipv6Afi.class;
+ }
+ } else if (address.getIpPrefix() != null) {
+ if (address.getIpPrefix().getIpv4Prefix() != null) {
+ return Ipv4PrefixAfi.class;
+ } else if (address.getIpPrefix().getIpv6Prefix() != null) {
+ return Ipv6PrefixAfi.class;
+ }
+ } else if (address.getMacAddress() != null) {
+ return MacAfi.class;
+ } else if (address.getAsNumber() != null) {
+ return AsNumberAfi.class;
+ } else if (address.getDistinguishedNameType() != null) {
+ return DistinguishedNameAfi.class;
+ }
+ return null;
+ }
+}
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. 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.lisp.util;
-
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.LcafSourceDestAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.LispAFIAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lcafsourcedestaddress.DstAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lcafsourcedestaddress.SrcAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.LispAddressContainer;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.LcafSourceDest;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * @author Florin Coras
- *
- */
-
-public class LcafSourceDestHelper {
- private final static Logger LOG = LoggerFactory.getLogger(LcafSourceDestHelper.class);
- public static LispAFIAddress getSrcAfi(LispAddressContainer addr) {
- if (!isSrcDst(addr)) {
- return LispAFIConvertor.toAFI(addr);
- }
- return LispAFIConvertor.toAFIfromPrimitive(((LcafSourceDest) addr.getAddress()).getLcafSourceDestAddr()
- .getSrcAddress().getPrimitiveAddress());
- }
-
- public static LispAFIAddress getSrcAfi(LispAFIAddress addr) {
- if (!isSrcDst(addr)) {
- return addr;
- }
- return LispAFIConvertor.toAFIfromPrimitive(((LcafSourceDestAddress) addr)
- .getSrcAddress().getPrimitiveAddress());
- }
-
- public static LispAFIAddress getDstAfi(LispAddressContainer addr) {
- if (!isSrcDst(addr)) {
- return LispAFIConvertor.toAFI(addr);
- }
- return LispAFIConvertor.toAFIfromPrimitive(((LcafSourceDest) addr.getAddress()).getLcafSourceDestAddr()
- .getDstAddress().getPrimitiveAddress());
- }
-
- public static LispAFIAddress getDstAfi(LispAFIAddress addr) {
- if (!isSrcDst(addr)) {
- return addr;
- }
- return LispAFIConvertor.toAFIfromPrimitive(((LcafSourceDestAddress) addr)
- .getDstAddress().getPrimitiveAddress());
- }
-
- public static LispAddressContainer getSrc(LispAddressContainer addr) {
- if (!isSrcDst(addr)) {
- return addr;
- }
- return LispAFIConvertor.toContainer(LispAFIConvertor.toAFIfromPrimitive(((LcafSourceDest) addr
- .getAddress()).getLcafSourceDestAddr().getSrcAddress().getPrimitiveAddress())); }
-
- public static LispAddressContainer getDst(LispAddressContainer addr) {
- if (!isSrcDst(addr)) {
- return addr;
- }
- return LispAFIConvertor.toContainer(LispAFIConvertor.toAFIfromPrimitive(((LcafSourceDest) addr
- .getAddress()).getLcafSourceDestAddr().getDstAddress().getPrimitiveAddress()));
- }
-
- public static short getSrcMask(LispAddressContainer addr) {
- if (!isSrcDst(addr)) {
- return 0;
- }
- return ((LcafSourceDest) addr.getAddress()).getLcafSourceDestAddr().getSrcMaskLength();
- }
-
- public static short getDstMask(LispAddressContainer addr) {
- if (!isSrcDst(addr)) {
- return 0;
- }
- return ((LcafSourceDest) addr.getAddress()).getLcafSourceDestAddr().getDstMaskLength();
- }
-
- public static short getSrcMask(LispAFIAddress addr) {
- if (!isSrcDst(addr)) {
- return 0;
- }
- return ((LcafSourceDestAddress) addr).getSrcMaskLength();
- }
-
- public static short getDstMask(LispAFIAddress addr) {
- if (!isSrcDst(addr)) {
- return 0;
- }
- return ((LcafSourceDestAddress) addr).getDstMaskLength();
- }
-
- public static DstAddress getDstAddress(LispAFIAddress addr) {
- if (!isSrcDst(addr)) {
- return null;
- }
- return ((LcafSourceDestAddress)addr).getDstAddress();
- }
-
- public static SrcAddress getSrcAddress(LispAFIAddress addr) {
- if (!isSrcDst(addr)) {
- return null;
- }
- return ((LcafSourceDestAddress)addr).getSrcAddress();
- }
-
- public static DstAddress getDstAddress(LispAddressContainer addr) {
- if (!isSrcDst(addr)) {
- return null;
- }
- return ((LcafSourceDest)addr.getAddress()).getLcafSourceDestAddr().getDstAddress();
- }
-
- public static SrcAddress getSrcAddress(LispAddressContainer addr) {
- if (!isSrcDst(addr)) {
- return null;
- }
- return ((LcafSourceDest)addr.getAddress()).getLcafSourceDestAddr().getSrcAddress();
- }
-
-
- private static boolean isSrcDst(LispAFIAddress addr) {
- if (!(addr instanceof LcafSourceDestAddress)) {
- LOG.warn("Address {} is not a valid SourceDest LCAF", addr);
- return false;
- }
- return true;
- }
-
- private static boolean isSrcDst(LispAddressContainer addr) {
- if (!(addr.getAddress() instanceof LcafSourceDest)) {
- LOG.warn("Address {} is not a valid SourceDest LCAF", addr);
- return false;
- }
- return true;
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 Contextream, 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.lisp.util;
-
-import java.net.Inet4Address;
-import java.net.Inet6Address;
-import java.net.InetAddress;
-
-import org.opendaylight.lispflowmapping.lisp.type.AddressFamilyNumberEnum;
-import org.opendaylight.lispflowmapping.lisp.type.LispCanonicalAddressFormatEnum;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.LispAFIAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lcafkeyvalueaddress.KeyBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lcafkeyvalueaddress.ValueBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.LispAddressContainer;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.LispAddressContainerBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.Address;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.ipv6.Ipv6AddressBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.lcafkeyvalue.LcafKeyValueAddressAddr;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.lcafkeyvalue.LcafKeyValueAddressAddrBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.PrimitiveAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.primitiveaddress.DistinguishedNameBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.primitiveaddress.Ipv4Builder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.primitiveaddress.MacBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.primitiveaddress.distinguishedname.DistinguishedNameAddressBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.primitiveaddress.mac.MacAddressBuilder;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
-
-public class LispAFIConvertor {
-
- public static LispAddressContainer toContainer(LispAFIAddress address) {
- Address addr = null;
-
- if (address instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.ipv4.Ipv4Address) {
- addr = new org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.Ipv4Builder()
- .setIpv4Address(
- (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.ipv4.Ipv4Address) address)
- .build();
- } else if (address instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.ipv6.Ipv6Address) {
- addr = new org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.Ipv6Builder()
- .setIpv6Address(
- (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.ipv6.Ipv6Address) address)
- .build();
- } else if (address instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.lcaftrafficengineering.LcafTrafficEngineeringAddr) {
- addr = new org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.LcafTrafficEngineeringBuilder()
- .setLcafTrafficEngineeringAddr(
- (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.lcaftrafficengineering.LcafTrafficEngineeringAddr) address)
- .build();
- } else if (address instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.as.AS) {
- addr = new org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.ASBuilder()
- .setAS((org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.as.AS) address)
- .build();
- } else if (address instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.distinguishedname.DistinguishedName) {
- addr = new org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.DistinguishedNameBuilder()
- .setDistinguishedName(
- (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.distinguishedname.DistinguishedName) address)
- .build();
- } else if (address instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.lcafapplicationdata.LcafApplicationDataAddr) {
- addr = new org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.LcafApplicationDataBuilder()
- .setLcafApplicationDataAddr(
- (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.lcafapplicationdata.LcafApplicationDataAddr) address)
- .build();
- } else if (address instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.lcafkeyvalue.LcafKeyValueAddressAddr) {
- addr = new org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.LcafKeyValueBuilder()
- .setLcafKeyValueAddressAddr(
- (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.lcafkeyvalue.LcafKeyValueAddressAddr) address)
- .build();
- } else if (address instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.lcaflist.LcafListAddr) {
- addr = new org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.LcafListBuilder()
- .setLcafListAddr(
- (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.lcaflist.LcafListAddr) address)
- .build();
- } else if (address instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.lcafsegment.LcafSegmentAddr) {
- addr = new org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.LcafSegmentBuilder()
- .setLcafSegmentAddr(
- (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.lcafsegment.LcafSegmentAddr) address)
- .build();
- } else if (address instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.lcafsourcedest.LcafSourceDestAddr) {
- addr = new org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.LcafSourceDestBuilder()
- .setLcafSourceDestAddr(
- (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.lcafsourcedest.LcafSourceDestAddr) address)
- .build();
- } else if (address instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.mac.MacAddress) {
- addr = new org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.MacBuilder()
- .setMacAddress(
- (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.mac.MacAddress) address)
- .build();
- } else if (address instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.no.NoAddress) {
- addr = new org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.NoBuilder()
- .setNoAddress(
- (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.no.NoAddress) address)
- .build();
- }
- return new LispAddressContainerBuilder().setAddress(addr).build();
- }
-
- public static LispAddressContainer toContainer(InetAddress address) {
- if (address instanceof Inet4Address) {
- return toContainer(asIPAfiAddress(address.getHostAddress()));
- }
-
- if (address instanceof Inet6Address) {
- return toContainer(asIPv6AfiAddress(address.getHostAddress()));
- }
-
- return null;
- }
-
- public static LispAFIAddress toAFI(LispAddressContainer container) {
- Address address = container.getAddress();
- LispAFIAddress addr = null;
-
- if (address instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.Ipv4) {
- return ((org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.Ipv4) address)
- .getIpv4Address();
- } else if (address instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.Ipv6) {
- return ((org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.Ipv6) address)
- .getIpv6Address();
- } else if (address instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.LcafTrafficEngineering) {
- return ((org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.LcafTrafficEngineering) address)
- .getLcafTrafficEngineeringAddr();
- } else if (address instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.AS) {
- return ((org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.AS) address)
- .getAS();
- } else if (address instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.DistinguishedName) {
- return ((org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.DistinguishedName) address)
- .getDistinguishedName();
- } else if (address instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.LcafApplicationData) {
- return ((org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.LcafApplicationData) address)
- .getLcafApplicationDataAddr();
- } else if (address instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.LcafKeyValue) {
- return ((org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.LcafKeyValue) address)
- .getLcafKeyValueAddressAddr();
- } else if (address instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.LcafList) {
- return ((org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.LcafList) address)
- .getLcafListAddr();
- } else if (address instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.LcafSegment) {
- return ((org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.LcafSegment) address)
- .getLcafSegmentAddr();
- } else if (address instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.LcafSourceDest) {
- return ((org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.LcafSourceDest) address)
- .getLcafSourceDestAddr();
- } else if (address instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.Mac) {
- return ((org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.Mac) address)
- .getMacAddress();
- } else if (address instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.No) {
- return ((org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.No) address)
- .getNoAddress();
- }
-
- return addr;
- }
-
- public static PrimitiveAddress toPrimitive(LispAFIAddress address) {
- if (address instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.ipv4.Ipv4Address) {
- return new Ipv4Builder()
- .setIpv4Address(
- new org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.primitiveaddress.ipv4.Ipv4AddressBuilder(
- (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.LispIpv4Address) address)
- .build()).build();
- }
- if (address instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.ipv6.Ipv6Address) {
- return new org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.primitiveaddress.Ipv6Builder()
- .setIpv6Address(
- new org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.primitiveaddress.ipv6.Ipv6AddressBuilder(
- (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.LispIpv6Address) address)
- .build()).build();
- }
- if (address instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.mac.MacAddress) {
- return new MacBuilder()
- .setMacAddress(
- new MacAddressBuilder()
- .setMacAddress(
- ((org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.mac.MacAddress) address)
- .getMacAddress())
- .setAfi(address.getAfi()).build()).build();
- }
- if (address instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.distinguishedname.DistinguishedName) {
- return new DistinguishedNameBuilder()
- .setDistinguishedNameAddress(
- new DistinguishedNameAddressBuilder()
- .setDistinguishedName(
- ((org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.distinguishedname.DistinguishedName) address)
- .getDistinguishedName())
- .setAfi(address.getAfi()).build()).build();
- }
- return null;
- }
-
- public static LispAFIAddress toAFIfromPrimitive(PrimitiveAddress primitive) {
-
- if (primitive instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.primitiveaddress.Ipv4) {
- return new org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.ipv4.Ipv4AddressBuilder(((org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.lispsimpleaddress.primitiveaddress.Ipv4) primitive)
- .getIpv4Address()).build();
- }
- if (primitive instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.primitiveaddress.Ipv6) {
- return new org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.ipv6.Ipv6AddressBuilder(((org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.lispsimpleaddress.primitiveaddress.Ipv6) primitive)
- .getIpv6Address()).build();
- }
- if (primitive instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.primitiveaddress.Mac) {
- return new org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.mac.MacAddressBuilder()
- .setAfi(((org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.primitiveaddress.Mac) primitive)
- .getMacAddress().getAfi())
- .setMacAddress(
- ((org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.primitiveaddress.Mac) primitive)
- .getMacAddress().getMacAddress()).build();
- }
- if (primitive instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.primitiveaddress.DistinguishedName) {
- return new org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.distinguishedname.DistinguishedNameBuilder()
- .setAfi(((org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.primitiveaddress.DistinguishedName) primitive)
- .getDistinguishedNameAddress().getAfi())
- .setDistinguishedName(
- ((org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.primitiveaddress.DistinguishedName) primitive)
- .getDistinguishedNameAddress()
- .getDistinguishedName()).build();
- }
- if (primitive instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.primitiveaddress.AS) {
- return new org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.as.ASBuilder()
- .setAfi(((org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.primitiveaddress.AS) primitive)
- .getASAddress().getAfi())
- .setAS(((org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.primitiveaddress.AS) primitive)
- .getASAddress().getAS()).build();
- }
- return null;
- }
-
- public static LispAddressContainer getIPContainer(String ip) {
- return toContainer(asIPAfiAddress(ip));
- }
-
- public static org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.distinguishedname.DistinguishedName asDistinguishedNameAddress(
- String distName) {
- return new org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.distinguishedname.DistinguishedNameBuilder()
- .setAfi(AddressFamilyNumberEnum.DISTINGUISHED_NAME.getIanaCode())
- .setDistinguishedName(distName).build();
- }
-
- public static org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.ipv4.Ipv4Address asIPAfiAddress(
- String ip) {
- return new org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.ipv4.Ipv4AddressBuilder()
- .setIpv4Address(new Ipv4Address(ip))
- .setAfi((short) AddressFamilyNumberEnum.IP.getIanaCode())
- .build();
- }
-
- public static org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.ipv6.Ipv6Address asIPv6AfiAddress(
- String ip) {
- return new Ipv6AddressBuilder().setIpv6Address(new Ipv6Address(ip))
- .setAfi((short) AddressFamilyNumberEnum.IP6.getIanaCode())
- .build();
- }
-
- public static LispAddressContainer asIPv4Address(String ip) {
- return new LispAddressContainerBuilder().setAddress(new org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.Ipv4Builder()
- .setIpv4Address(new org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.ipv4.Ipv4AddressBuilder()
- .setIpv4Address(new Ipv4Address(ip)).setAfi((short) AddressFamilyNumberEnum.IP.getIanaCode()).setMask((short)32).build()).build()).build();
- }
-
- public static LispAFIAddress asIPv4AfiPrefix(String ip, int mask) {
- return new org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.ipv4.Ipv4AddressBuilder()
- .setIpv4Address(new Ipv4Address(MaskUtil.normalizeIPString(ip, mask))).setAfi((short) AddressFamilyNumberEnum.IP.getIanaCode()).setMask((short)mask).build();
- }
-
- public static LispAddressContainer asIPv4Prefix(String ip, int mask) {
- return new LispAddressContainerBuilder().setAddress(new org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.Ipv4Builder()
- .setIpv4Address(new org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.ipv4.Ipv4AddressBuilder()
- .setIpv4Address(new Ipv4Address(MaskUtil.normalizeIPString(ip, mask))).setAfi((short) AddressFamilyNumberEnum.IP.getIanaCode()).setMask((short)mask).build()).build()).build();
- }
-
- public static LispAddressContainer asIPv6Address(String ip) {
- return new LispAddressContainerBuilder().setAddress(new org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.Ipv6Builder()
- .setIpv6Address(new org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.ipv6.Ipv6AddressBuilder()
- .setIpv6Address(new Ipv6Address(ip)).setAfi((short) AddressFamilyNumberEnum.IP6.getIanaCode()).setMask((short)128).build()).build()).build();
- }
-
- public static LispAFIAddress asIPv6AfiPrefix(String ip, int mask) {
- return new org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.ipv6.Ipv6AddressBuilder()
- .setIpv6Address(new Ipv6Address(MaskUtil.normalizeIPString(ip, mask))).setAfi((short) AddressFamilyNumberEnum.IP6.getIanaCode()).setMask((short)mask).build();
- }
-
- public static LispAddressContainer asIPv6Prefix(String ip, int mask) {
- return new LispAddressContainerBuilder().setAddress(new org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.Ipv6Builder()
- .setIpv6Address(new org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.ipv6.Ipv6AddressBuilder()
- .setIpv6Address(new Ipv6Address(MaskUtil.normalizeIPString(ip, mask))).setAfi((short) AddressFamilyNumberEnum.IP6.getIanaCode()).setMask((short)mask).build()).build()).build();
- }
-
- public static LcafKeyValueAddressAddr asKeyValue(String key,
- PrimitiveAddress value) {
- return new LcafKeyValueAddressAddrBuilder()
- .setAfi(AddressFamilyNumberEnum.LCAF.getIanaCode())
- .setLcafType(
- (short) LispCanonicalAddressFormatEnum.KEY_VALUE
- .getLispCode())
- .setKey(new KeyBuilder()
- .setPrimitiveAddress(
- new DistinguishedNameBuilder()
- .setDistinguishedNameAddress(
- new DistinguishedNameAddressBuilder()
- .setAfi(AddressFamilyNumberEnum.DISTINGUISHED_NAME
- .getIanaCode())
- .setDistinguishedName(
- key).build())
- .build()).build())
- .setValue(new ValueBuilder().setPrimitiveAddress(value).build())
- .build();
- }
-
- public static org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.primitiveaddress.Ipv4 asPrimitiveIPAfiAddress(
- String ip) {
- return new org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.primitiveaddress.Ipv4Builder()
- .setIpv4Address(
- new org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.primitiveaddress.ipv4.Ipv4AddressBuilder()
- .setIpv4Address(new Ipv4Address(ip))
- .setAfi((short) AddressFamilyNumberEnum.IP
- .getIanaCode()).build()).build();
- }
-
- public static org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.primitiveaddress.Ipv4 asPrimitiveIPv4AfiPrefix(
- String ip, int mask) {
- return new org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.primitiveaddress.Ipv4Builder()
- .setIpv4Address(
- new org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.primitiveaddress.ipv4.Ipv4AddressBuilder()
- .setIpv4Address(new Ipv4Address(ip))
- .setAfi((short) AddressFamilyNumberEnum.IP.getIanaCode()).setMask((short) mask).build())
- .build();
- }
-
- public static org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.primitiveaddress.Ipv6 asPrimitiveIPv6AfiPrefix(
- String ip, int mask) {
- return new org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.primitiveaddress.Ipv6Builder()
- .setIpv6Address(
- new org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.primitiveaddress.ipv6.Ipv6AddressBuilder()
- .setIpv6Address(new Ipv6Address(ip))
- .setAfi((short) AddressFamilyNumberEnum.IP6.getIanaCode()).setMask((short) mask).build())
- .build();
- }
-
- public static org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.mac.MacAddress asMacAfiAddress(
- String mac) {
- return new org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.mac.MacAddressBuilder()
- .setMacAddress(new MacAddress(mac))
- .setAfi((short) AddressFamilyNumberEnum.MAC.getIanaCode())
- .build();
- }
-
- public static org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.primitiveaddress.Mac asPrimitiveMacAfiAddress(
- String mac) {
- return new org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.primitiveaddress.MacBuilder()
- .setMacAddress(
- new org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.primitiveaddress.mac.MacAddressBuilder()
- .setMacAddress(new MacAddress(mac))
- .setAfi((short) AddressFamilyNumberEnum.MAC
- .getIanaCode()).build()).build();
- }
-}
import java.util.List;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lcaflistaddress.Addresses;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lcaftrafficengineeringaddress.Hops;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.LispAddressContainer;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.Address;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.AS;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.DistinguishedName;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.Ipv4;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.Ipv6;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.LcafApplicationData;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.LcafKeyValue;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.LcafList;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.LcafSegment;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.LcafSourceDest;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.LcafTrafficEngineering;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.Mac;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.No;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.lcafapplicationdata.LcafApplicationDataAddr;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.lcafkeyvalue.LcafKeyValueAddressAddr;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.lcafsourcedest.LcafSourceDestAddr;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.PrimitiveAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.LispAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SimpleAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.AfiList;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.ApplicationData;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.AsNumber;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.DistinguishedName;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.ExplicitLocatorPath;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.InstanceId;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Prefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6Prefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.KeyValueAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Mac;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.NoAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.SourceDestKey;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.explicit.locator.path.explicit.locator.path.Hop;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.explicit.locator.path.explicit.locator.path.Hop.LrsBits;
import com.google.common.base.Preconditions;
URL;
}
- public static String getString(LispAddressContainer container) {
- return getAddrString(Destination.USER, container);
+ public static String getString(LispAddress lispAddress) {
+ return getAddrString(Destination.USER, lispAddress);
}
- public static String getURIString(LispAddressContainer container) {
- return getString(Destination.URI, container);
+ public static String getURIString(LispAddress lispAddress) {
+ return getAddrString(Destination.URI, lispAddress);
}
- public static String getURLString(LispAddressContainer container) {
- return getString(Destination.URL, container);
+ public static String getURLString(LispAddress lispAddress) {
+ return getAddrString(Destination.URL, lispAddress);
}
- private static String getAddrString(Destination dst, LispAddressContainer container) {
- Preconditions.checkNotNull(container, "address should not be null");
- Address addr = container.getAddress();
+ private static String getAddrString(Destination dst, LispAddress lispAddress) {
+ Preconditions.checkNotNull(lispAddress, "lispAddress should not be null");
+ Address addr = lispAddress.getAddress();
String prefix = null;
String address = null;
if (addr instanceof Ipv4) {
prefix = "ipv4" + PREFIX_SEPARATOR;
address = getStringFromIpv4(dst, (Ipv4) addr);
+ } else if (addr instanceof Ipv4Prefix) {
+ prefix = "ipv4" + PREFIX_SEPARATOR;
+ address = getStringFromIpv4Prefix(dst, (Ipv4Prefix) addr);
} else if (addr instanceof Ipv6) {
prefix = "ipv6" + PREFIX_SEPARATOR;
address = getStringFromIpv6(dst, (Ipv6) addr);
+ } else if (addr instanceof Ipv6Prefix) {
+ prefix = "ipv6" + PREFIX_SEPARATOR;
+ address = getStringFromIpv6Prefix(dst, (Ipv6Prefix) addr);
} else if (addr instanceof Mac) {
prefix = "mac" + PREFIX_SEPARATOR;
address = getStringFromMac(dst, (Mac) addr);
- } else if (addr instanceof LcafSegment) {
- PrimitiveAddress pa = ((LcafSegment) addr).getLcafSegmentAddr().getAddress().getPrimitiveAddress();
+ } else if (addr instanceof InstanceId) {
+ SimpleAddress pa = ((InstanceId)addr).getInstanceId().getAddress();
// Instance ID is a separate parent hierarchy, so we use the simple address prefix
- prefix = LispPrimitiveAddressStringifier.getURLPrefix(pa) + PREFIX_SEPARATOR;
- address = getStringFromLcafSegment(dst, (LcafSegment) addr);
- } else if (addr instanceof No) {
+ prefix = LispSimpleAddressStringifier.getURLPrefix(pa) + PREFIX_SEPARATOR;
+ address = getStringFromInstanceId(dst, (InstanceId) addr);
+ } else if (addr instanceof NoAddress) {
prefix = "no" + PREFIX_SEPARATOR;
- address = getStringFromNo(dst, (No) addr);
+ address = getStringFromNoAddress(dst, (NoAddress) addr);
} else if (addr instanceof DistinguishedName) {
prefix = "dn" + PREFIX_SEPARATOR;
address = getStringFromDistinguishedName(dst, (DistinguishedName) addr);
- } else if (addr instanceof AS) {
+ } else if (addr instanceof AsNumber) {
prefix = "as" + PREFIX_SEPARATOR;
- address = getStringFromAS(dst, (AS) addr);
- } else if (addr instanceof LcafList) {
+ address = getStringFromAsNumber(dst, (AsNumber) addr);
+ } else if (addr instanceof AfiList) {
prefix = "list" + PREFIX_SEPARATOR;
- address = getStringFromLcafList(dst, (LcafList) addr);
- } else if (addr instanceof LcafApplicationData) {
+ address = getStringFromAfiList(dst, (AfiList) addr);
+ } else if (addr instanceof ApplicationData) {
prefix = "appdata" + PREFIX_SEPARATOR;
- address = getStringFromLcafApplicationData(dst, (LcafApplicationData) addr);
- } else if (addr instanceof LcafTrafficEngineering) {
+ address = getStringFromApplicationData(dst, (ApplicationData) addr);
+ } else if (addr instanceof ExplicitLocatorPath) {
prefix = "elp" + PREFIX_SEPARATOR;
- address = getStringFromLcafTrafficEngineering(dst, (LcafTrafficEngineering) addr);
- } else if (addr instanceof LcafSourceDest) {
+ address = getStringFromExplicitLocatorPath(dst, (ExplicitLocatorPath) addr);
+ } else if (addr instanceof SourceDestKey) {
prefix = "srcdst" + PREFIX_SEPARATOR;
- address = getStringFromLcafSourceDest(dst, (LcafSourceDest) addr);
- } else if (addr instanceof LcafKeyValue) {
+ address = getStringFromSourceDestKey(dst, (SourceDestKey) addr);
+ } else if (addr instanceof KeyValueAddress) {
prefix = "kv" + PREFIX_SEPARATOR;
- address = getStringFromLcafKeyValue(dst, (LcafKeyValue) addr);
+ address = getStringFromKeyValueAddress(dst, (KeyValueAddress) addr);
}
if (dst == Destination.USER) {
}
- private static String getString(Destination dst, LispAddressContainer container) {
- if (MaskUtil.isMaskable(container)) {
- return (getAddrString(dst, container) + getMaskSeparator(dst) + MaskUtil.getMaskForAddress(container));
- } else {
- return getAddrString(dst, container);
- }
- }
-
- private static String getMaskSeparator(Destination dst) {
+ private static String getPrefixString(Destination dst, String prefix) {
if (dst == Destination.URL) {
- return "%2f";
+ return prefix.replace("/", "%2f");
} else {
- return "/";
+ return prefix;
}
}
- protected static String getStringFromNo(Destination dst, No addr) {
+ protected static String getStringFromNoAddress(Destination dst, NoAddress addr) {
// AFI = 0
if (dst == Destination.USER) {
return "No Address Present";
protected static String getStringFromIpv4(Destination dst, Ipv4 addr) {
// AFI = 1; IPv4
- return addr.getIpv4Address().getIpv4Address().getValue();
+ return addr.getIpv4().getValue();
+ }
+
+ protected static String getStringFromIpv4Prefix(Destination dst, Ipv4Prefix addr) {
+ // AFI = 1; IPv4
+ String prefix = addr.getIpv4Prefix().getValue();
+ return getPrefixString(dst, prefix);
}
protected static String getStringFromIpv6(Destination dst, Ipv6 addr) {
// AFI = 2; IPv6
- return addr.getIpv6Address().getIpv6Address().getValue();
+ return addr.getIpv6().getValue();
+ }
+
+ protected static String getStringFromIpv6Prefix(Destination dst, Ipv6Prefix addr) {
+ // AFI = 2; IPv6
+ return addr.getIpv6Prefix().getValue();
}
protected static String getStringFromDistinguishedName(Destination dst, DistinguishedName addr) {
// AFI = 17; Distinguished Name
- return addr.getDistinguishedName().getDistinguishedName();
+ return addr.getDistinguishedName().getValue();
}
- protected static String getStringFromAS(Destination dst, AS addr) {
+ protected static String getStringFromAsNumber(Destination dst, AsNumber addr) {
// AFI = 18; Autonomous System Number
- return "AS" + addr.getAS().getAS();
+ return "AS" + addr.getAsNumber().getValue();
}
- protected static String getStringFromLcafList(Destination dst, LcafList addr) {
+ protected static String getStringFromAfiList(Destination dst, AfiList addr) {
// AFI 16387, LCAF Type 1; Address List
// Example rendering:
// {192.0.2.1,192.0.2.2,2001:db8::1}
- List<Addresses> addresses = addr.getLcafListAddr().getAddresses();
+ List<SimpleAddress> addresses = addr.getAfiList().getAddressList();
StringBuilder sb = new StringBuilder("{");
boolean needComma = false;
- for (Addresses a : addresses) {
+ for (SimpleAddress a : addresses) {
if (needComma) {
sb.append(",");
}
- sb.append(LispPrimitiveAddressStringifier.getString(dst, a.getPrimitiveAddress()));
+ sb.append(a.getValue());
needComma = true;
}
sb.append("}");
return sb.toString();
}
- protected static String getStringFromLcafSegment(Destination dst, LcafSegment addr) {
+ protected static String getStringFromInstanceId(Destination dst, InstanceId addr) {
// AFI = 16387, LCAF Type 2; Instance ID
// Example rendering:
// [223] 192.0.2.0/24
- PrimitiveAddress pa = addr.getLcafSegmentAddr().getAddress().getPrimitiveAddress();
+ SimpleAddress pa = addr.getInstanceId().getAddress();
if (dst == Destination.USER) {
- return "[" + addr.getLcafSegmentAddr().getInstanceId() + "] "
- + LispPrimitiveAddressStringifier.getString(dst, pa);
+ return "[" + addr.getInstanceId().getIid().getValue() + "] "
+ + LispSimpleAddressStringifier.getString(dst, pa);
} else {
- return LispPrimitiveAddressStringifier.getString(dst, pa);
+ return LispSimpleAddressStringifier.getString(dst, pa);
}
}
- protected static String getStringFromLcafApplicationData(Destination dst, LcafApplicationData addr) {
+ protected static String getStringFromApplicationData(Destination dst, ApplicationData addr) {
// AFI = 16387, LCAF Type 4; Application Data
// Example rendering:
// 192.0.2.1!128!17!80-81!6667-7000
- LcafApplicationDataAddr a = addr.getLcafApplicationDataAddr();
- return LispPrimitiveAddressStringifier.getString(dst, a.getAddress().getPrimitiveAddress())
- + "!" + a.getIpTos() + "!" + a.getProtocol()
- + "!" + a.getLocalPortLow() + "-" + a.getLocalPortHigh()
- + "!" + a.getRemotePortLow() + "-" + a.getRemotePortHigh();
-
+ return LispSimpleAddressStringifier.getString(dst, addr.getApplicationData().getAddress())
+ + "!" + addr.getApplicationData().getIpTos()
+ + "!" + addr.getApplicationData().getProtocol()
+ + "!" + addr.getApplicationData().getLocalPortLow()
+ + "-" + addr.getApplicationData().getLocalPortHigh()
+ + "!" + addr.getApplicationData().getRemotePortLow()
+ + "-" + addr.getApplicationData().getRemotePortHigh();
}
- protected static String getStringFromLcafTrafficEngineering(Destination dst, LcafTrafficEngineering addr) {
+
+ protected static String getStringFromExplicitLocatorPath(Destination dst, ExplicitLocatorPath addr) {
// AFI = 16387, LCAF Type 10, Explicit Locator Path
// Example rendering:
// {192.0.2.1->192.0.2.2|lps->192.0.2.3}
- List<Hops> hops = addr.getLcafTrafficEngineeringAddr().getHops();
+ List<Hop> hops = addr.getExplicitLocatorPath().getHop();
StringBuilder sb = new StringBuilder();
sb.append("{");
boolean needArrow = false;
- for (Hops hop : hops) {
+ for (Hop hop : hops) {
if (needArrow) {
sb.append("->");
}
- sb.append(LispPrimitiveAddressStringifier.getString(dst, hop.getHop().getPrimitiveAddress()));
- if (hop.isLookup() || hop.isRLOCProbe() || hop.isStrict()) {
+ sb.append(LispSimpleAddressStringifier.getString(dst, hop.getAddress()));
+ LrsBits lrs = hop.getLrsBits();
+ if (lrs.isLookup() || lrs.isRlocProbe() || lrs.isStrict()) {
sb.append("|");
}
- if (hop.isLookup()) {
+ if (lrs.isLookup()) {
sb.append("l");
}
- if (hop.isRLOCProbe()) {
+ if (lrs.isRlocProbe()) {
sb.append("p");
}
- if (hop.isStrict()) {
+ if (lrs.isStrict()) {
sb.append("s");
}
needArrow = true;
return sb.toString();
}
- protected static String getStringFromLcafSourceDest(Destination dst, LcafSourceDest addr) {
+ protected static String getStringFromSourceDestKey(Destination dst, SourceDestKey addr) {
// AFI = 16387, LCAF Type 12, Source/Destination Key
// Example rendering:
// 192.0.2.1/32|192.0.2.2/32
- LcafSourceDestAddr a = ((LcafSourceDest) addr).getLcafSourceDestAddr();
- return LispPrimitiveAddressStringifier.getString(dst, a.getSrcAddress().getPrimitiveAddress())
- + getMaskSeparator(dst) + a.getSrcMaskLength() + "|"
- + LispPrimitiveAddressStringifier.getString(dst, a.getDstAddress().getPrimitiveAddress())
- + getMaskSeparator(dst) + a.getDstMaskLength();
+ return getPrefixString(dst, (new String(addr.getSourceDestKey().getSource().getValue()))
+ + "|" + getPrefixString(dst, new String(addr.getSourceDestKey().getDest().getValue())));
}
- protected static String getStringFromLcafKeyValue(Destination dst, LcafKeyValue addr) {
+ protected static String getStringFromKeyValueAddress(Destination dst, KeyValueAddress addr) {
// AFI = 16387, LCAF Type 15, Key/Value Address Pair
// Example rendering:
// 192.0.2.1=>192.0.2.2
- LcafKeyValueAddressAddr a = addr.getLcafKeyValueAddressAddr();
- return LispPrimitiveAddressStringifier.getString(dst, a.getKey().getPrimitiveAddress()) + "=>"
- + LispPrimitiveAddressStringifier.getString(dst, a.getValue().getPrimitiveAddress());
+ return getPrefixString(dst, new String(addr.getKeyValueAddress().getKey().getValue())
+ + "=>" + getPrefixString(dst, new String(addr.getKeyValueAddress().getValue().getValue())));
}
protected static String getStringFromMac(Destination dst, Mac addr) {
// AFI = 16389; MAC
- return addr.getMacAddress().getMacAddress().getValue();
+ return addr.getMac().getValue();
}
}
--- /dev/null
+/*
+ * Copyright (c) 2014 Contextream, 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.lisp.util;
+
+import java.net.Inet4Address;
+import java.net.Inet6Address;
+import java.net.InetAddress;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
+
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.AsNumberAfi;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.DistinguishedNameAfi;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.DistinguishedNameType;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.InstanceIdType;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv4Afi;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv4PrefixAfi;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv6Afi;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv6PrefixAfi;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.KeyValueAddressLcaf;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.LispAddressFamily;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.MacAfi;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SimpleAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SourceDestKeyLcaf;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Builder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4PrefixBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6Builder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6PrefixBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.KeyValueAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.MacBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.EidBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.Rloc;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.RlocBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.key.value.address.KeyValueAddressBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.source.dest.key.SourceDestKey;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.source.dest.key.SourceDestKeyBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
+
+public class LispAddressUtil {
+ private static Pattern IP4_PATTERN = null;
+ private static Pattern IP6_PATTERN = null;
+ private static final String ip4Pattern = "(([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.){3}([01]?\\d\\d?|2[0-4]\\d|25[0-5])";
+ private static final String ip6Pattern = "([0-9a-f]{1,4}:){7}([0-9a-f]){1,4}";
+ static {
+ try {
+ IP4_PATTERN = Pattern.compile(ip4Pattern, Pattern.CASE_INSENSITIVE);
+ IP6_PATTERN = Pattern.compile(ip6Pattern, Pattern.CASE_INSENSITIVE);
+ } catch (PatternSyntaxException e) {
+ }
+ }
+
+ public static Class<? extends LispAddressFamily> addressTypeFromSimpleAddress(SimpleAddress address) {
+ if (address.getIpAddress() != null) {
+ return addressTypeFromIpAddress(address.getIpAddress());
+ } else if (address.getIpPrefix() != null) {
+ return addressTypeFromIpPrefix(address.getIpPrefix());
+ } else if (address.getMacAddress() != null) {
+ return MacAfi.class;
+ } else if (address.getDistinguishedNameType() != null) {
+ return DistinguishedNameAfi.class;
+ } else if (address.getAsNumber() != null) {
+ return AsNumberAfi.class;
+ }
+ return null;
+ }
+
+ public static Address addressFromSimpleAddress(SimpleAddress address) {
+ if (address.getIpAddress() != null) {
+ return addressFromIpAddress(address.getIpAddress());
+ } else if (address.getIpPrefix() != null) {
+ return addressFromIpPrefix(address.getIpPrefix());
+ }
+ // TODO the rest of the types
+ return null;
+ }
+
+ public static Class<? extends LispAddressFamily> addressTypeFromInet(InetAddress address) {
+ if (address instanceof Inet4Address) {
+ return Ipv4Afi.class;
+ } else if (address instanceof Inet6Address) {
+ return Ipv6Afi.class;
+ }
+ return null;
+ }
+
+ public static Address addressFromInet(InetAddress address) {
+ if (address instanceof Inet4Address) {
+ return (Address) new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Builder()
+ .setIpv4(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address(address.getHostAddress())).build();
+ } else if (address instanceof Inet6Address) {
+ return (Address) new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6Builder()
+ .setIpv6(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address(address.getHostAddress())).build();
+ }
+ return null;
+ }
+
+ public static Class<? extends LispAddressFamily> addressTypeFromIpAddress(IpAddress address) {
+ if (address == null) {
+ return null;
+ } else if (address.getIpv4Address() != null) {
+ return Ipv4Afi.class;
+ } else if (address.getIpv6Address() != null) {
+ return Ipv6Afi.class;
+ }
+ return null;
+ }
+
+ public static Address addressFromIpAddress(IpAddress address) {
+ if (address == null) {
+ return null;
+ } else if (address.getIpv4Address() != null) {
+ return (Address) new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Builder().setIpv4(address.getIpv4Address()).build();
+ } else if (address.getIpv6Address() != null) {
+ return (Address) new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6Builder().setIpv6(address.getIpv6Address()).build();
+ }
+ return null;
+ }
+
+ public static Class<? extends LispAddressFamily> addressTypeFromIpPrefix(IpPrefix address) {
+ if (address == null) {
+ return null;
+ } else if (address.getIpv4Prefix() != null) {
+ return Ipv4PrefixAfi.class;
+ } else if (address.getIpv6Prefix() != null) {
+ return Ipv6PrefixAfi.class;
+ }
+ return null;
+ }
+
+ public static Address addressFromIpPrefix(IpPrefix address) {
+ if (address == null) {
+ return null;
+ } else if (address.getIpv4Prefix() != null) {
+ return (Address) new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4PrefixBuilder().setIpv4Prefix(address.getIpv4Prefix()).build();
+ } else if (address.getIpv6Prefix() != null) {
+ return (Address) new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6PrefixBuilder().setIpv6Prefix(address.getIpv6Prefix()).build();
+ }
+ return null;
+ }
+
+ public static Rloc toRloc(SimpleAddress address) {
+ RlocBuilder builder = new RlocBuilder();
+ builder.setAddressType(addressTypeFromSimpleAddress(address));
+ builder.setVirtualNetworkId(null);
+ builder.setAddress(addressFromSimpleAddress(address));
+ return builder.build();
+ }
+
+ public static Rloc toRloc(InetAddress address) {
+ RlocBuilder builder = new RlocBuilder();
+ builder.setAddressType(addressTypeFromInet(address));
+ builder.setVirtualNetworkId(null);
+ builder.setAddress(addressFromInet(address));
+ return builder.build();
+ }
+
+ public static Rloc toRloc(Ipv4Address address) {
+ RlocBuilder builder = new RlocBuilder();
+ builder.setAddressType(Ipv4Afi.class);
+ builder.setVirtualNetworkId(null);
+ builder.setAddress((Address) new Ipv4Builder().setIpv4(address).build());
+ return builder.build();
+ }
+
+ public static Rloc toRloc(Ipv6Address address) {
+ RlocBuilder builder = new RlocBuilder();
+ builder.setAddressType(Ipv6Afi.class);
+ builder.setVirtualNetworkId(null);
+ builder.setAddress((Address) new Ipv6Builder().setIpv6(address).build());
+ return builder.build();
+ }
+
+ public static Rloc asIpv4Rloc(String address) {
+ return toRloc(new Ipv4Address(address));
+ }
+
+ public static Rloc asIpv6Rloc(String address) {
+ return toRloc(new Ipv6Address(address));
+ }
+
+ public static Eid toEid(Ipv4Prefix prefix, InstanceIdType vni) {
+ EidBuilder builder = new EidBuilder();
+ builder.setAddressType(Ipv4PrefixAfi.class);
+ builder.setVirtualNetworkId(vni);
+ builder.setAddress((Address) new Ipv4PrefixBuilder().setIpv4Prefix(prefix).build());
+ return builder.build();
+ }
+
+ public static Eid toEid(Ipv4Address prefix, InstanceIdType vni) {
+ EidBuilder builder = new EidBuilder();
+ builder.setAddressType(Ipv4Afi.class);
+ builder.setVirtualNetworkId(vni);
+ builder.setAddress((Address) new Ipv4Builder().setIpv4(prefix).build());
+ return builder.build();
+ }
+
+ public static Eid toEid(Eid eid, IpPrefix prefix) {
+ EidBuilder builder = new EidBuilder();
+ builder.setAddressType(eid.getAddressType());
+ builder.setVirtualNetworkId(eid.getVirtualNetworkId());
+ // XXX Not sure if the below actually works as expected... also, what happens to AFI?
+ builder.setAddress(addressFromIpPrefix(prefix));
+ return builder.build();
+ }
+
+ public static Eid toEid(IpPrefix prefix, int vni) {
+ EidBuilder builder = new EidBuilder();
+ builder.setAddress(addressFromIpPrefix(prefix));
+ builder.setAddressType(addressTypeFromIpPrefix(prefix));
+ builder.setVirtualNetworkId(new InstanceIdType(Long.valueOf(vni)));
+ return builder.build();
+ }
+
+ public static Eid asIpv4PrefixEid(String prefix) {
+ return toEid(new Ipv4Prefix(prefix), null);
+ }
+
+ public static Eid asIpv4Eid(String address) {
+ return toEid(new Ipv4Address(address), null);
+ }
+
+ public static Eid toEid(Ipv6Prefix prefix, InstanceIdType vni) {
+ EidBuilder builder = new EidBuilder();
+ builder.setAddressType(Ipv6PrefixAfi.class);
+ builder.setVirtualNetworkId(vni);
+ builder.setAddress((Address) new Ipv6PrefixBuilder().setIpv6Prefix(prefix).build());
+ return builder.build();
+ }
+
+ public static Eid toEid(Ipv6Address prefix, InstanceIdType vni) {
+ EidBuilder builder = new EidBuilder();
+ builder.setAddressType(Ipv6Afi.class);
+ builder.setVirtualNetworkId(vni);
+ builder.setAddress((Address) new Ipv6Builder().setIpv6(prefix).build());
+ return builder.build();
+ }
+
+ public static Eid asIpv6Eid(String address, long vni) {
+ return toEid(new Ipv6Address(address), new InstanceIdType(vni));
+ }
+
+ public static Eid asIpv6PrefixEid(String prefix) {
+ return toEid(new Ipv6Prefix(prefix), null);
+ }
+
+ public static Eid asIpv6Eid(String address) {
+ return toEid(new Ipv6Address(address), null);
+ }
+
+ public static Eid asIpv4Eid(String address, long vni) {
+ return toEid(new Ipv4Address(address), new InstanceIdType(vni));
+ }
+
+ public static int ipVersionFromString(String ip) {
+ if (IP4_PATTERN.matcher(ip).matches()) {
+ return 4;
+ } else if (IP6_PATTERN.matcher(ip).matches()) {
+ return 6;
+ } else {
+ return 0;
+ }
+ }
+
+ public static IpPrefix asIpPrefix(String addr, int mask) {
+ int version = ipVersionFromString(addr);
+ if (version == 4 && (mask >= 0 && mask <= 32)) {
+ return new IpPrefix(new Ipv4Prefix(addr + "/" + mask));
+ } else if (version == 6 && (mask >=0 && mask <= 128)) {
+ return new IpPrefix(new Ipv6Prefix(addr + "/" + mask));
+ } else {
+ return null;
+ }
+ }
+
+ public static Eid asIpv4PrefixEid(Eid eid, Inet4Address address, short mask) {
+ EidBuilder builder = new EidBuilder();
+ builder.setAddressType(eid.getAddressType());
+ builder.setVirtualNetworkId(eid.getVirtualNetworkId());
+ builder.setAddress(new Ipv4PrefixBuilder().setIpv4Prefix(new Ipv4Prefix(getStringPrefix(address, mask))).build());
+ return builder.build();
+ }
+
+ public static Eid asIpv6PrefixEid(Eid eid, Inet6Address address, short mask) {
+ EidBuilder builder = new EidBuilder();
+ builder.setAddressType(eid.getAddressType());
+ builder.setVirtualNetworkId(eid.getVirtualNetworkId());
+ builder.setAddress(new Ipv6PrefixBuilder().setIpv6Prefix(new Ipv6Prefix(getStringPrefix(address, mask))).build());
+ return builder.build();
+ }
+
+ public static Eid toEid(MacAddress mac, InstanceIdType vni) {
+ EidBuilder builder = new EidBuilder();
+ builder.setAddressType(MacAfi.class);
+ builder.setVirtualNetworkId(vni);
+ builder.setAddress((Address) new MacBuilder().setMac(mac).build());
+ return builder.build();
+ }
+
+ public static Eid asMacEid(String address, long vni) {
+ return toEid(new MacAddress(address), new InstanceIdType(vni));
+ }
+
+ public static Eid asMacEid(String address) {
+ return toEid(new MacAddress(address), null);
+ }
+
+ public static Rloc asKeyValueAddress(String key, SimpleAddress value) {
+ KeyValueAddressBuilder kvab = new KeyValueAddressBuilder();
+ kvab.setKey(new SimpleAddress(new DistinguishedNameType(key)));
+ kvab.setValue(value);
+ KeyValueAddress address = new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.KeyValueAddressBuilder()
+ .setKeyValueAddress(kvab.build()).build();
+ RlocBuilder builder = new RlocBuilder();
+ builder.setAddressType(KeyValueAddressLcaf.class);
+ builder.setVirtualNetworkId(null);
+ builder.setAddress((Address) address);
+ return builder.build();
+ }
+
+ private static String getStringPrefix(InetAddress address, short mask) {
+ StringBuilder sb = new StringBuilder();
+ sb.append(address.getHostAddress());
+ sb.append("/");
+ sb.append(mask);
+ return sb.toString();
+ }
+
+ public static SourceDestKey asSrcDst(String src, String dst, int smask, int dmask) {
+ SourceDestKeyBuilder builder = new SourceDestKeyBuilder();
+ builder.setSource(asIpPrefix(src, smask));
+ builder.setDest(asIpPrefix(dst, dmask));
+ return builder.build();
+ }
+
+ public static Eid asSrcDstEid(String src, String dst, int smask, int dmask, int vni) {
+ EidBuilder builder = new EidBuilder();
+ builder.setAddressType(SourceDestKeyLcaf.class);
+ builder.setVirtualNetworkId(new InstanceIdType(Long.valueOf(vni)));
+ builder.setAddress(
+ new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.SourceDestKeyBuilder()
+ .setSourceDestKey(asSrcDst(src, dst, smask, dmask)).build());
+
+ return builder.build();
+ }
+
+ public static Eid asSrcDstEid(SourceDestKey sd, int vni) {
+ EidBuilder builder = new EidBuilder();
+ builder.setAddressType(SourceDestKeyLcaf.class);
+ builder.setVirtualNetworkId(new InstanceIdType(Long.valueOf(vni)));
+ builder.setAddress(
+ new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.SourceDestKeyBuilder()
+ .setSourceDestKey(sd).build());
+ return builder.build();
+ }
+}
package org.opendaylight.lispflowmapping.lisp.util;
import org.opendaylight.lispflowmapping.lisp.util.LispAddressStringifier.Destination;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.PrimitiveAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.primitiveaddress.AS;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.primitiveaddress.DistinguishedName;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.primitiveaddress.Ipv4;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.primitiveaddress.Ipv6;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.primitiveaddress.Mac;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.primitiveaddress.No;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SimpleAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.AsNumber;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.DistinguishedName;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Mac;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.NoAddress;
import com.google.common.base.Preconditions;
* @author Lorand Jakab
*
*/
-public class LispPrimitiveAddressStringifier {
+public class LispSimpleAddressStringifier {
- public static String getString(PrimitiveAddress addr) {
+ public static String getString(SimpleAddress addr) {
return getString(Destination.USER, addr);
}
- public static String getString(Destination dst, PrimitiveAddress addr) {
+ public static String getString(Destination dst, SimpleAddress addr) {
Preconditions.checkNotNull(addr, "address should not be null");
if (addr instanceof Ipv4) {
- return ((Ipv4) addr).getIpv4Address().getIpv4Address().getValue();
+ return ((Ipv4) addr).getIpv4().getValue();
} else if (addr instanceof Ipv6) {
- return ((Ipv6) addr).getIpv6Address().getIpv6Address().getValue();
+ return ((Ipv6) addr).getIpv6().getValue();
} else if (addr instanceof Mac) {
- return ((Mac) addr).getMacAddress().getMacAddress().getValue();
+ return ((Mac) addr).getMac().getValue();
} else if (addr instanceof DistinguishedName) {
- return ((DistinguishedName) addr).getDistinguishedNameAddress().getDistinguishedName();
- } else if (addr instanceof AS) {
- return "AS" + ((AS) addr).getASAddress().getAS();
- } else if (addr instanceof No) {
+ return ((DistinguishedName) addr).getDistinguishedName().getValue();
+ } else if (addr instanceof AsNumber) {
+ return "AS" + ((AsNumber) addr).getAsNumber().getValue();
+ } else if (addr instanceof NoAddress) {
if (dst == Destination.USER) {
return "No Address Present";
} else {
return null;
}
- protected static String getURLPrefix(PrimitiveAddress addr) {
+ protected static String getURLPrefix(SimpleAddress addr) {
Preconditions.checkNotNull(addr, "address should not be null");
if (addr instanceof Ipv4) {
return "mac";
} else if (addr instanceof DistinguishedName) {
return "dn";
- } else if (addr instanceof AS) {
+ } else if (addr instanceof AsNumber) {
return "as";
- } else if (addr instanceof No) {
+ } else if (addr instanceof NoAddress) {
return "no";
}
import java.util.Arrays;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapRegister;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eidtolocatorrecords.EidToLocatorRecord;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapnotifymessage.MapNotifyBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItem;
public class MapNotifyBuilderHelper {
public static void setFromMapRegister(MapNotifyBuilder builder, MapRegister mapRegister) {
- if (builder.getEidToLocatorRecord() == null) {
- builder.setEidToLocatorRecord(new ArrayList<EidToLocatorRecord>());
+ if (builder.getMappingRecordItem() == null) {
+ builder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
}
builder.setNonce(mapRegister.getNonce());
builder.setKeyId(mapRegister.getKeyId());
}
builder.setAuthenticationData(authenticationData);
- for (EidToLocatorRecord eidToLocator : mapRegister.getEidToLocatorRecord()) {
- builder.getEidToLocatorRecord().add(eidToLocator);
+ for (MappingRecordItem eidToLocator : mapRegister.getMappingRecordItem()) {
+ builder.getMappingRecordItem().add(eidToLocator);
}
}
}
import java.util.ArrayList;
import java.util.Random;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapRequest;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.LispAddressContainer;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.Address;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.Ipv4;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.Ipv6;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRloc;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRlocBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.SourceEidBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequestnotification.MapRequestBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.Rloc;
public class MapRequestUtil {
public static InetAddress selectItrRloc(MapRequest request) {
}
InetAddress selectedItrRloc = null;
for (ItrRloc itr : request.getItrRloc()) {
- Address addr = itr.getLispAddressContainer().getAddress();
+ Address addr = itr.getRloc().getAddress();
if (addr instanceof Ipv4) {
try {
- selectedItrRloc = InetAddress.getByName(((Ipv4) addr).getIpv4Address().getIpv4Address().getValue());
+ selectedItrRloc = InetAddress.getByName(((Ipv4) addr).getIpv4().getValue());
} catch (UnknownHostException e) {
}
break;
}
if (addr instanceof Ipv6) {
try {
- selectedItrRloc = InetAddress.getByName((((Ipv6) addr).getIpv6Address().getIpv6Address().getValue()));
+ selectedItrRloc = InetAddress.getByName(((Ipv6) addr).getIpv6().getValue());
} catch (UnknownHostException e) {
}
break;
return selectedItrRloc;
}
- public static MapRequestBuilder prepareSMR(LispAddressContainer srcEid, LispAddressContainer itrRloc) {
+ public static MapRequestBuilder prepareSMR(Eid srcEid, Rloc itrRloc) {
MapRequestBuilder builder = new MapRequestBuilder();
builder.setAuthoritative(false);
builder.setMapDataPresent(false);
builder.setSmr(true);
builder.setSmrInvoked(false);
- builder.setSourceEid(new SourceEidBuilder().setLispAddressContainer(srcEid).build());
+ builder.setSourceEid(new SourceEidBuilder().setEid(srcEid).build());
builder.setItrRloc(new ArrayList<ItrRloc>());
- builder.getItrRloc().add(new ItrRlocBuilder().setLispAddressContainer(itrRloc).build());
+ builder.getItrRloc().add(new ItrRlocBuilder().setRloc(itrRloc).build());
builder.setMapReply(null);
builder.setNonce(new Random().nextLong());
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
package org.opendaylight.lispflowmapping.lisp.util;
-
+/*
import java.util.ArrayList;
import java.util.List;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.LispAddressContainer;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapregisternotification.MapRegisterBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequestnotification.MapRequestBuilder;
-
+*/
/**
* Utilities to prepare MapRegister and MapRequest object for interaction with
* the IFlowMapping API.
*
*/
public class MapServerMapResolverUtil {
-
+/*
public static MapRegister getMapRegister(EidToLocatorRecord mapping) {
MapRegisterBuilder mrb = new MapRegisterBuilder();
mrb.setEidToLocatorRecord(getEidToLocatorRecord(mapping));
return mrb.build();
}
- public static MapRequest getMapRequest(LispAddressContainer address, short mask) {
+ public static MapRequest getMapRequest(LispAddress address) {
MapRequestBuilder mrb = new MapRequestBuilder();
mrb.setPitr(false);
- mrb.setEidRecord(getEidRecord(address, mask));
+ mrb.setEidRecord(getEidRecord(address));
return mrb.build();
}
etlrb.setMapVersion(mapping.getMapVersion());
etlrb.setAction(mapping.getAction());
etlrb.setAuthoritative(mapping.isAuthoritative());
- etlrb.setLispAddressContainer(mapping.getLispAddressContainer());
+ etlrb.setEid(mapping.getEid());
etlrb.setLocatorRecord(mapping.getLocatorRecord());
List<org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eidtolocatorrecords.EidToLocatorRecord> mappings =
return mappings;
}
- public static List<EidRecord> getEidRecord(LispAddressContainer address, short mask) {
+ public static List<EidRecord> getEidRecord(LispAddress address) {
EidRecordBuilder erb = new EidRecordBuilder();
- erb.setLispAddressContainer(address);
- erb.setMask(mask);
+ erb.setEid(address);
+ erb.setAddress(address.getAddress());
+ erb.setAfi(address.getAfi());
+ erb.setVirtualNetworkId(address.getVirtualNetworkId());
List<EidRecord> records = new ArrayList<EidRecord>();
records.add(erb.build());
return records;
}
+ */
}
import java.nio.ByteBuffer;
import org.apache.commons.lang3.exception.ExceptionUtils;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.LcafSegmentAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.LcafSourceDestAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.LispAFIAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.LispIpv4Address;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.LispIpv6Address;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lcafsegmentaddress.AddressBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lcafsegmentaddress.Address;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lcafsourcedestaddress.DstAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lcafsourcedestaddress.DstAddressBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lcafsourcedestaddress.SrcAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lcafsourcedestaddress.SrcAddressBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.LispAddressContainer;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.LispAddressContainerBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.Ipv4;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.Ipv4Builder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.Ipv6;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.Ipv6Builder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.LcafSegment;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.LcafSegmentBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.LcafSourceDest;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.LcafSourceDestBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.ipv4.Ipv4Address;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.ipv4.Ipv4AddressBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.ipv6.Ipv6Address;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.ipv6.Ipv6AddressBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.lcafsegment.LcafSegmentAddr;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.lcafsegment.LcafSegmentAddrBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.lcafsourcedest.LcafSourceDestAddr;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.lcafsourcedest.LcafSourceDestAddrBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SimpleAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.InstanceId;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Prefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6Prefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.SourceDestKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class MaskUtil {
private static final Logger LOG = LoggerFactory.getLogger(MaskUtil.class);
- public static boolean isMaskable(LispAFIAddress address) {
- if (address instanceof Ipv4Address || address instanceof Ipv6Address || address instanceof LcafSegmentAddr) {
+ private static final short IPV4_MAX_MASK = 32;
+ private static final short IPV6_MAX_MASK = 128;
+
+ public static boolean isMaskable(Address address) {
+ if (address instanceof Ipv4Prefix || address instanceof Ipv6Prefix || address instanceof SourceDestKey) {
return true;
+ } else if (address instanceof InstanceId) {
+ return isMaskable(((InstanceId)address).getInstanceId().getAddress());
}
return false;
}
- public static boolean isMaskable(LispAddressContainer address) {
- if (address.getAddress() instanceof Ipv4 || address.getAddress() instanceof Ipv6) {
+ public static boolean isMaskable(SimpleAddress address) {
+ if (address.getIpPrefix() != null) {
return true;
- } else if (address.getAddress() instanceof LcafSegment) {
- return isMaskable(LispAFIConvertor.toAFIfromPrimitive(((LcafSegment) address.getAddress())
- .getLcafSegmentAddr().getAddress().getPrimitiveAddress()));
- } else if (address.getAddress() instanceof LcafSourceDestAddress) {
- LcafSourceDestAddr sd = ((LcafSourceDest) address.getAddress()).getLcafSourceDestAddr();
- return isMaskable(LispAFIConvertor.toAFIfromPrimitive(sd.getSrcAddress().getPrimitiveAddress()))
- && isMaskable(LispAFIConvertor.toAFIfromPrimitive(sd.getDstAddress().getPrimitiveAddress()));
}
return false;
}
- public static LispAFIAddress normalize(LispAFIAddress address, short mask) {
+ public static Eid normalize(Eid eid, short mask) {
+ Address address = eid.getAddress();
try {
- if (address instanceof Ipv4Address) {
- return LispAFIConvertor.asIPAfiAddress(normalizeIP(
- Inet4Address.getByName(((Ipv4Address) address).getIpv4Address().getValue()),
- mask).getHostAddress());
- } else if (address instanceof Ipv6Address) {
- return LispAFIConvertor.asIPv6AfiAddress(normalizeIP(
- Inet6Address.getByName(((Ipv6Address) address).getIpv6Address().getValue()),
- mask).getHostAddress());
- } else if (address instanceof LcafSegmentAddr) {
- LcafSegmentAddr segAddr = (LcafSegmentAddr) address;
- LispAFIAddress afiAddr = LispAFIConvertor
- .toAFIfromPrimitive(segAddr.getAddress().getPrimitiveAddress());
- Address normalizedAddr = new AddressBuilder().setPrimitiveAddress(
- LispAFIConvertor.toPrimitive(normalize(afiAddr, mask))).build();
- return new LcafSegmentAddrBuilder(segAddr).setAddress(normalizedAddr).build();
+ if (address instanceof Ipv4Prefix) {
+ String[] v4prefix = String.valueOf(((Ipv4Prefix)address).getIpv4Prefix().getValue()).split("/");
+ InetAddress normalized = normalizeIP(Inet4Address.getByName(v4prefix[0]), mask);
+ return LispAddressUtil.asIpv4PrefixEid(eid, (Inet4Address)normalized, mask);
+ } else if (address instanceof Ipv6Prefix) {
+ String[] v6prefix = String.valueOf(((Ipv6Prefix)address).getIpv6Prefix().getValue()).split("/");
+ InetAddress normalized = normalizeIP(Inet6Address.getByName(v6prefix[0]), mask);
+ return LispAddressUtil.asIpv6PrefixEid(eid, (Inet6Address)normalized, mask);
+ } else if (address instanceof InstanceId) {
+ // TODO - not absolutely necessary, but should be implemented
+ return eid;
}
} catch (UnknownHostException e) {
- LOG.trace("Failed to normalize " + address + ": " + ExceptionUtils.getStackTrace(e));
- }
- return address;
- }
-
- public static LispAFIAddress normalize(LispAFIAddress address) {
- if (address instanceof Ipv4Address) {
- return normalize(address, ((Ipv4Address) address).getMask());
- } else if (address instanceof Ipv6Address) {
- return normalize(address, ((Ipv6Address) address).getMask());
- } else if (address instanceof LcafSegmentAddr) {
- LcafSegmentAddr segAddr = (LcafSegmentAddr) address;
- LispAFIAddress afiAddr = LispAFIConvertor.toAFIfromPrimitive(segAddr.getAddress().getPrimitiveAddress());
- short mask = getMaskForAfiAddress(afiAddr);
- if (mask == 0) {
- return address;
- }
- Address normalizedAddr = new AddressBuilder().setPrimitiveAddress(
- LispAFIConvertor.toPrimitive(normalize(afiAddr, mask))).build();
- return new LcafSegmentAddrBuilder(segAddr).setAddress(normalizedAddr).build();
+ LOG.trace("Failed to normalize eid {} with mask {}: {}", eid, mask, ExceptionUtils.getStackTrace(e));
}
- return address;
+ return eid;
}
- public static LispAddressContainer normalize(LispAddressContainer address, short mask) {
+ public static Eid normalize(Eid eid) {
+ Address address = eid.getAddress();
try {
- if (address.getAddress() instanceof Ipv4) {
- return LispAFIConvertor.asIPv4Prefix(normalizeIP(
- Inet4Address.getByName(((Ipv4) address.getAddress()).getIpv4Address().getIpv4Address().getValue()),
- mask).getHostAddress(), mask);
- } else if (address.getAddress() instanceof Ipv6) {
- return LispAFIConvertor.asIPv6Prefix(normalizeIP(
- Inet6Address.getByName(((Ipv6) address.getAddress()).getIpv6Address().getIpv6Address().getValue()),
- mask).getHostAddress(), mask);
- } else if (address.getAddress() instanceof LcafSegment) {
- LcafSegmentAddress segAddr = ((LcafSegment) address.getAddress()).getLcafSegmentAddr();
- LispAFIAddress afiAddr = LispAFIConvertor
- .toAFIfromPrimitive(segAddr.getAddress().getPrimitiveAddress());
- Address normalizedAddr = new AddressBuilder().setPrimitiveAddress(
- LispAFIConvertor.toPrimitive(normalize(afiAddr, mask))).build();
- return new LispAddressContainerBuilder().setAddress(
- new LcafSegmentBuilder().setLcafSegmentAddr(
- new LcafSegmentAddrBuilder(segAddr).setAddress(normalizedAddr).build()).build())
- .build();
+ if (address instanceof Ipv4Prefix) {
+ String[] v4prefix = String.valueOf(((Ipv4Prefix)address).getIpv4Prefix().getValue()).split("/");
+ short mask = Short.parseShort(v4prefix[1]);
+ InetAddress normalized = normalizeIP(Inet4Address.getByName(v4prefix[0]), mask);
+ return LispAddressUtil.asIpv4PrefixEid(eid, (Inet4Address)normalized, mask);
+ } else if (address instanceof Ipv6Prefix) {
+ String[] v6prefix = String.valueOf(((Ipv6Prefix)address).getIpv6Prefix().getValue()).split("/");
+ short mask = Short.parseShort(v6prefix[1]);
+ InetAddress normalized = normalizeIP(Inet6Address.getByName(v6prefix[0]), mask);
+ return LispAddressUtil.asIpv6PrefixEid(eid, (Inet6Address)normalized, mask);
+ } else if (address instanceof InstanceId) {
+ // TODO - not absolutely necessary, but should be implemented
+ return eid;
}
} catch (UnknownHostException e) {
- LOG.trace("Failed to normalize " + address + ": " + ExceptionUtils.getStackTrace(e));
- }
- return address;
- }
-
- public static LispAddressContainer normalize(LispAddressContainer address) {
- if (address.getAddress() instanceof Ipv4) {
- return normalize(address, ((Ipv4)address.getAddress()).getIpv4Address().getMask());
- } else if (address.getAddress() instanceof Ipv6) {
- return normalize(address, ((Ipv6)address.getAddress()).getIpv6Address().getMask());
- } else if (address.getAddress() instanceof LcafSegment) {
- LcafSegmentAddress segAddr = ((LcafSegment) address.getAddress()).getLcafSegmentAddr();
- LispAFIAddress afiAddr = LispAFIConvertor
- .toAFIfromPrimitive(segAddr.getAddress().getPrimitiveAddress());
- short mask = getMaskForAfiAddress(afiAddr);
- if (mask == 0) {
- return address;
- }
- Address normalizedAddr = new AddressBuilder().setPrimitiveAddress(
- LispAFIConvertor.toPrimitive(normalize(afiAddr, mask))).build();
- return new LispAddressContainerBuilder().setAddress(
- new LcafSegmentBuilder().setLcafSegmentAddr(
- new LcafSegmentAddrBuilder(segAddr).setAddress(normalizedAddr).build()).build())
- .build();
+ LOG.trace("Failed to normalize eid {}: {}", eid, ExceptionUtils.getStackTrace(e));
}
- return address;
+ return eid;
}
private static InetAddress normalizeIP(InetAddress address, int mask) throws UnknownHostException {
return InetAddress.getByAddress(byteRepresentation.array());
}
- public static String normalizeIPString(String addr, int mask) {
- short afi = getIpAfiForString(addr);
- try {
- if (afi == 1) {
- return normalizeIP(Inet4Address.getByName(addr), mask).getHostAddress();
- } else if (afi == 2) {
- return normalizeIP(Inet6Address.getByName(addr), mask).getHostAddress();
- } else {
- LOG.debug("The string {} is not a valid IP address!", addr);
- return null;
- }
- } catch (Exception e){
- LOG.trace("Failed to normalize " + addr + ": " + ExceptionUtils.getStackTrace(e));
- }
- return null;
- }
-
- public static int getMaxMask(LispAFIAddress address) {
- if (address instanceof Ipv4Address) {
- return 32;
- }
- if (address instanceof Ipv6Address) {
- return 128;
- }
- return -1;
- }
-
- public static byte getMaxMaskForAfi(int afi) {
- if (afi == 1) {
- return (byte) 32;
- } else if (afi == 2) {
- return (byte) 128;
+ public static int getMaxMask(Address address) {
+ if (address instanceof Ipv4 || address instanceof Ipv4Prefix) {
+ return IPV4_MAX_MASK;
+ } else if (address instanceof Ipv6 || address instanceof Ipv6Prefix) {
+ return IPV6_MAX_MASK;
} else {
- return (byte) -1;
- }
- }
-
- private static short getMaskForAfiAddress(LispAFIAddress addr) {
- if (addr instanceof Ipv4Address) {
- Short res = ((Ipv4Address) addr).getMask();
- return (res != null) ? res.shortValue() : 32;
- } else if (addr instanceof Ipv6Address) {
- Short res = ((Ipv6Address) addr).getMask();
- return (res != null) ? res.shortValue() : 128;
- } else {
- return 0;
- }
- }
-
- public static short getMaskForAddress(LispAddressContainer addr) {
- if (addr.getAddress() instanceof Ipv4) {
- Short res = ((Ipv4)addr.getAddress()).getIpv4Address().getMask();
- return (res != null) ? res.shortValue() : 32;
- } else if (addr.getAddress() instanceof Ipv6) {
- Short res = ((Ipv6)addr.getAddress()).getIpv6Address().getMask();
- return (res != null) ? res.shortValue() : 128;
- } else if (addr.getAddress() instanceof LcafSegment) {
- return getMaskForAfiAddress(LispAFIConvertor.toAFIfromPrimitive((((LcafSegment) addr.getAddress())
- .getLcafSegmentAddr()).getAddress().getPrimitiveAddress()));
+ return -1;
}
- return 0;
}
- private static short getIpAfiForString(String addr) {
- if(addr.matches("([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])") == true){
- return 1;
+ public static short getMaskForAddress(SimpleAddress address) {
+ if (address.getIpPrefix() == null) {
+ return -1;
}
- else if(addr.matches("([0-9a-f]+)\\:([0-9a-f]+)\\:([0-9a-f]+)\\:([0-9a-f]+)\\:([0-9a-f]+)\\:([0-9a-f]+)\\:([0-9a-f]+)\\:([0-9a-f]+)") == true){
- return 2;
- }
- return -1;
+ return getMaskForIpPrefix(address.getIpPrefix());
}
- public static LispAddressContainer setMask(LispAddressContainer addr, int mask) {
- if (addr.getAddress() instanceof Ipv4) {
- return new LispAddressContainerBuilder().setAddress(
- new Ipv4Builder().setIpv4Address(
- new Ipv4AddressBuilder(((Ipv4) addr.getAddress()).getIpv4Address()).setMask((short) mask)
- .build()).build()).build();
-
- } else if (addr.getAddress() instanceof Ipv6) {
- return new LispAddressContainerBuilder().setAddress(
- new Ipv6Builder().setIpv6Address(
- new Ipv6AddressBuilder(((Ipv6) addr.getAddress()).getIpv6Address()).setMask((short) mask)
- .build()).build()).build();
- } else if (addr.getAddress() instanceof LcafSegment) {
- setMask(LispAFIConvertor.toAFIfromPrimitive(((LcafSegment) addr.getAddress()).getLcafSegmentAddr()
- .getAddress().getPrimitiveAddress()), mask);
- }
- return addr;
+ public static short getMaskForIpPrefix(IpPrefix prefix) {
+ return Short.parseShort(String.valueOf(prefix.getValue()).split("/")[1]);
}
- public static LispAFIAddress setMask(LispAFIAddress addr, int mask) {
- if (addr instanceof LispIpv4Address) {
- return new Ipv4AddressBuilder().setIpv4Address(((LispIpv4Address) addr).getIpv4Address())
- .setAfi(addr.getAfi()).setMask((short)mask).build();
- } else if (addr instanceof LispIpv6Address) {
- return new Ipv6AddressBuilder().setIpv6Address(((LispIpv6Address) addr).getIpv6Address())
- .setAfi(addr.getAfi()).setMask((short)mask).build();
- } else if (addr instanceof LcafSegmentAddress) {
- LispAFIAddress afiAddr = LispAFIConvertor.toAFIfromPrimitive(((LcafSegmentAddress) addr).getAddress()
- .getPrimitiveAddress());
- afiAddr = setMask(afiAddr, mask);
- return new LcafSegmentAddrBuilder((LcafSegmentAddress) addr).setAddress(
- new AddressBuilder().setPrimitiveAddress(LispAFIConvertor.toPrimitive(afiAddr)).build()).build();
- }
- return addr;
+ public static String getAddressStringForIpPrefix(IpPrefix prefix) {
+ return String.valueOf(prefix.getValue()).split("/")[0];
}
- public static LispAFIAddress setMaskSourceDest(LispAFIAddress addr, int srcMask, int dstMask) {
- DstAddress dst = LcafSourceDestHelper.getDstAddress(addr);
- LispAFIAddress dstAfi = LispAFIConvertor.toAFIfromPrimitive(dst.getPrimitiveAddress());
- DstAddress newDst = new DstAddressBuilder(dst).setPrimitiveAddress(LispAFIConvertor.toPrimitive(setMask(dstAfi, dstMask))).build();
- SrcAddress src = LcafSourceDestHelper.getSrcAddress(addr);
- LispAFIAddress srcAfi = LispAFIConvertor.toAFIfromPrimitive(src.getPrimitiveAddress());
- SrcAddress newSrc = new SrcAddressBuilder(src).setPrimitiveAddress(LispAFIConvertor.toPrimitive(setMask(srcAfi, srcMask))).build();
- return new LcafSourceDestAddrBuilder((LcafSourceDestAddress)addr).setDstAddress(newDst).setSrcAddress(newSrc).build();
+ public static String getAddressStringForIpv4Prefix(Ipv4Prefix prefix) {
+ return String.valueOf(prefix.getIpv4Prefix().getValue()).split("/")[0];
}
- public static LispAddressContainer setMaskSourceDest(LispAddressContainer addr, int srcMask, int dstMask) {
- return new LispAddressContainerBuilder().setAddress(
- new LcafSourceDestBuilder((LcafSourceDest) addr.getAddress()).setLcafSourceDestAddr(
- (LcafSourceDestAddr) setMaskSourceDest(
- ((LcafSourceDest) addr.getAddress()).getLcafSourceDestAddr(), srcMask, dstMask))
- .build()).build();
+ public static String getAddressStringForIpv6Prefix(Ipv6Prefix prefix) {
+ return String.valueOf(prefix.getIpv6Prefix().getValue()).split("/")[0];
}
- /**
- * RFC6830 defines masks and EIDs as separate fields of larger, encompassing blocks of LISP messages. However within
- * LispFlowMapping masks are internal fields of EIDs. The fixMask methods should be used in deserializers and RPC
- * handlers to ensure that masks for EIDs reflect accordingly the mask field values carried in LISP messages or RPC
- * input objects respectively.
- */
- public static LispAFIAddress fixMask(LispAFIAddress addr, short mask) {
- if (addr instanceof LispIpv4Address || addr instanceof LispIpv6Address || addr instanceof LcafSegmentAddress) {
- return MaskUtil.setMask(addr, mask);
- } else if (addr instanceof LcafSourceDestAddress) {
- return MaskUtil.setMaskSourceDest(addr, LcafSourceDestHelper.getSrcMask(addr),
- LcafSourceDestHelper.getDstMask(addr));
+ public static short getMaskForAddress(Address address) {
+ if (address instanceof Ipv4) {
+ return IPV4_MAX_MASK;
+ } else if (address instanceof Ipv6) {
+ return IPV6_MAX_MASK;
+ } else if (address instanceof Ipv4Prefix) {
+ String[] prefix = String.valueOf(((Ipv4Prefix)address).getIpv4Prefix().getValue()).split("/"); // TODO use something more efficient
+ return Short.parseShort(prefix[1]);
+ } else if (address instanceof Ipv6Prefix) {
+ String[] prefix = String.valueOf(((Ipv6Prefix)address).getIpv6Prefix().getValue()).split("/"); // TODO use something more efficient
+ return Short.parseShort(prefix[1]);
+ } else if (address instanceof InstanceId) {
+ return getMaskForAddress(((InstanceId)address).getInstanceId().getAddress());
}
- return addr;
- }
-
- public static LispAddressContainer fixMask(LispAddressContainer addr, short mask) {
- if (addr.getAddress() instanceof Ipv4 || addr.getAddress() instanceof Ipv6
- || addr.getAddress() instanceof LcafSegment) {
- return MaskUtil.setMask(addr, mask);
- } else if (addr.getAddress() instanceof LcafSourceDest) {
- return MaskUtil.setMaskSourceDest(addr, LcafSourceDestHelper.getSrcMask(addr),
- LcafSourceDestHelper.getDstMask(addr));
- }
- return addr;
+ return -1;
}
}
--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. 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.lisp.util;
+
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.SourceDestKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @author Lorand Jakab
+ *
+ */
+
+public class SourceDestKeyHelper {
+ private final static Logger LOG = LoggerFactory.getLogger(SourceDestKeyHelper.class);
+ public static Eid getSrc(Eid eid) {
+ Address addr = eid.getAddress();
+ if (addr instanceof SourceDestKey) {
+ return LispAddressUtil.toEid(eid, ((SourceDestKey)addr).getSourceDestKey().getSource());
+ } else {
+ return eid;
+ }
+ }
+
+ public static Eid getDst(Eid eid) {
+ Address addr = eid.getAddress();
+ if (addr instanceof SourceDestKey) {
+ return LispAddressUtil.toEid(eid, ((SourceDestKey)addr).getSourceDestKey().getDest());
+ } else {
+ return eid;
+ }
+ }
+
+ public static short getSrcMask(Eid eid) {
+ Address addr = eid.getAddress();
+ if (!isSrcDst(addr)) {
+ return 0;
+ }
+ return MaskUtil.getMaskForIpPrefix(((SourceDestKey)addr).getSourceDestKey().getSource());
+ }
+
+ public static short getDstMask(Eid eid) {
+ Address addr = eid.getAddress();
+ if (!isSrcDst(addr)) {
+ return 0;
+ }
+ return MaskUtil.getMaskForIpPrefix(((SourceDestKey)addr).getSourceDestKey().getDest());
+ }
+
+ private static boolean isSrcDst(Address addr) {
+ if (!(addr instanceof SourceDestKey)) {
+ LOG.warn("Address {} is not a valid SourceDest LCAF", addr);
+ return false;
+ }
+ return true;
+ }
+}
package org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddressBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefixBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
+
/**
* The purpose of generated class in src/main/java for Union types is to create new instances of unions from a string representation.
*/
public class SimpleAddressBuilder {
- public static SimpleAddress getDefaultInstance(java.lang.String defaultValue) {
- throw new java.lang.UnsupportedOperationException("Not yet implemented");
+ public static SimpleAddress getDefaultInstance(String defaultValue) {
+ SimpleAddress address = tryIpAddress(defaultValue);
+ if (address != null) {
+ return address;
+ }
+
+ address = tryIpPrefix(defaultValue);
+ if (address != null) {
+ return address;
+ }
+
+ address = tryMacAddress(defaultValue);
+ if (address != null) {
+ return address;
+ }
+
+ // XXX need support for MAC addresses and AS numbers
+ address = new SimpleAddress(new DistinguishedNameType(defaultValue));
+
+ return address;
}
+ private static SimpleAddress tryIpAddress(String defaultValue) {
+ try {
+ SimpleAddress address = new SimpleAddress(IpAddressBuilder.getDefaultInstance(defaultValue));
+ return address;
+ } catch (IllegalArgumentException e) {
+ return null;
+ }
+ }
+
+ private static SimpleAddress tryIpPrefix(String defaultValue) {
+ try {
+ SimpleAddress address = new SimpleAddress(IpPrefixBuilder.getDefaultInstance(defaultValue));
+ return address;
+ } catch (IllegalArgumentException e) {
+ return null;
+ }
+ }
+
+ private static SimpleAddress tryMacAddress(String defaultValue) {
+ try {
+ SimpleAddress address = new SimpleAddress(new MacAddress(defaultValue));
+ return address;
+ } catch (IllegalArgumentException e) {
+ return null;
+ }
+ }
}
import org.junit.Test;
import org.opendaylight.lispflowmapping.lisp.serializer.MapNotifySerializer;
import org.opendaylight.lispflowmapping.lisp.serializer.exception.LispSerializationException;
-import org.opendaylight.lispflowmapping.lisp.type.AddressFamilyNumberEnum;
-import org.opendaylight.lispflowmapping.lisp.util.LispAFIConvertor;
+import org.opendaylight.lispflowmapping.lisp.util.LispAddressUtil;
import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.EidToLocatorRecord.Action;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.NoAddressAfi;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.NoAddressBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapNotify;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eidtolocatorrecords.EidToLocatorRecord;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eidtolocatorrecords.EidToLocatorRecordBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.no.NoAddressBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.EidBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecord;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapnotifymessage.MapNotifyBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord.Action;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItem;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItemBuilder;
public class MapNotifySerializationTest extends BaseTestCase {
@Test
public void serialize__Fields() throws Exception {
MapNotifyBuilder mnBuilder = new MapNotifyBuilder();
- mnBuilder.setEidToLocatorRecord(new ArrayList<EidToLocatorRecord>());
- mnBuilder.getEidToLocatorRecord().add(
- new EidToLocatorRecordBuilder().setLispAddressContainer(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("0.0.0.1")))
+ mnBuilder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
+ mnBuilder.getMappingRecordItem().add(
+ new MappingRecordItemBuilder().setMappingRecord(
+ new MappingRecordBuilder().setEid(LispAddressUtil.asIpv4PrefixEid("0.0.0.1/32")).build())
.build());
- mnBuilder.getEidToLocatorRecord().add(
- new EidToLocatorRecordBuilder().setLispAddressContainer(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("0.0.0.73")))
+ mnBuilder.getMappingRecordItem().add(
+ new MappingRecordItemBuilder().setMappingRecord(
+ new MappingRecordBuilder().setEid(LispAddressUtil.asIpv4PrefixEid("0.0.0.73/32")).build())
.build());
mnBuilder.setNonce(6161616161L);
}
@Test
- public void serialize__deserizlise() throws Exception {
+ public void serialize__deserialize() throws Exception {
MapNotifyBuilder mnBuilder = new MapNotifyBuilder();
- mnBuilder.setEidToLocatorRecord(new ArrayList<EidToLocatorRecord>());
- mnBuilder.getEidToLocatorRecord().add(
- new EidToLocatorRecordBuilder().setLispAddressContainer(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("0.0.0.1")))
+ mnBuilder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
+ mnBuilder.getMappingRecordItem().add(
+ new MappingRecordItemBuilder().setMappingRecord(
+ new MappingRecordBuilder().setEid(LispAddressUtil.asIpv4PrefixEid("0.0.0.1/32")).build())
.build());
- mnBuilder.getEidToLocatorRecord().add(
- new EidToLocatorRecordBuilder().setLispAddressContainer(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("0.0.0.73")))
+ mnBuilder.getMappingRecordItem().add(
+ new MappingRecordItemBuilder().setMappingRecord(
+ new MappingRecordBuilder().setEid(LispAddressUtil.asIpv4PrefixEid("0.0.0.73/32")).build())
.build());
mnBuilder.setNonce(6161616161L);
assertTrue(mn.isXtrSiteIdPresent());
- assertEquals(1, mn.getEidToLocatorRecord().size());
+ assertEquals(1, mn.getMappingRecordItem().size());
assertEquals(0xFFBB000000000000L, mn.getNonce().longValue());
assertEquals(0x0000, mn.getKeyId().shortValue());
byte[] expectedAuthenticationData = {};
@Test
public void serialize__NoAuthenticationData() throws Exception {
MapNotifyBuilder mnBuilder = new MapNotifyBuilder();
- mnBuilder.setEidToLocatorRecord(new ArrayList<EidToLocatorRecord>());
- mnBuilder.getEidToLocatorRecord().add(
- new EidToLocatorRecordBuilder().setRecordTtl(55)
- .setLispAddressContainer(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("0.0.0.1"))).build());
+ mnBuilder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
+ mnBuilder.getMappingRecordItem().add(
+ new MappingRecordItemBuilder().setMappingRecord(
+ new MappingRecordBuilder().setEid(LispAddressUtil.asIpv4PrefixEid("0.0.0.1/32"))
+ .setRecordTtl(55).build()).build());
ByteBuffer bb = MapNotifySerializer.getInstance().serialize(mnBuilder.build());
bb.position(bb.position() + 14); // jump to AuthenticationDataLength
@Test
public void serialize__NoPrefixInEidToLocator() throws Exception {
MapNotifyBuilder mnBuilder = new MapNotifyBuilder();
- mnBuilder.setEidToLocatorRecord(new ArrayList<EidToLocatorRecord>());
- mnBuilder.getEidToLocatorRecord().add(new EidToLocatorRecordBuilder().build());
- mnBuilder.getEidToLocatorRecord().add(new EidToLocatorRecordBuilder().setLispAddressContainer(null).build());
- mnBuilder.getEidToLocatorRecord().add(
- new EidToLocatorRecordBuilder().setLispAddressContainer(
- LispAFIConvertor.toContainer(new NoAddressBuilder().setAfi(AddressFamilyNumberEnum.NO_ADDRESS.getIanaCode()).build())).build());
+ mnBuilder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
+ mnBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(
+ new MappingRecordBuilder().build()).build());
+ mnBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord
+ (new MappingRecordBuilder().setEid(null).build()).build());
+ mnBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(
+ new MappingRecordBuilder().setEid(new EidBuilder().setAddressType(NoAddressAfi.class).setAddress(
+ (Address) new NoAddressBuilder().setNoAddress(true).build()).build()).build()).build());
ByteBuffer bb = MapNotifySerializer.getInstance().serialize(mnBuilder.build());
bb.position(bb.position() + 16); // jump to first record prefix AFI
+ "ff 00 00 05 00 01 c0 a8 88 0d " // contd
));
- assertEquals(4, mn.getEidToLocatorRecord().size());
- assertEquals(LispAFIConvertor.asIPv4Address("153.16.254.1"), mn.getEidToLocatorRecord().get(0)
- .getLispAddressContainer());
- assertEquals(LispAFIConvertor.asIPv4Address("151.16.254.1"), mn.getEidToLocatorRecord().get(2)
- .getLispAddressContainer());
- assertEquals(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("192.168.136.11")), mn.getEidToLocatorRecord().get(1)
- .getLocatorRecord().get(0).getLispAddressContainer());
- assertEquals(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("192.168.136.13")), mn.getEidToLocatorRecord().get(3)
- .getLocatorRecord().get(0).getLispAddressContainer());
+ assertEquals(4, mn.getMappingRecordItem().size());
+ assertEquals(LispAddressUtil.asIpv4PrefixEid("153.16.254.1/32"), mn.getMappingRecordItem().get(0)
+ .getMappingRecord().getEid());
+ assertEquals(LispAddressUtil.asIpv4PrefixEid("151.16.254.1/32"), mn.getMappingRecordItem().get(2)
+ .getMappingRecord().getEid());
+ assertEquals(LispAddressUtil.asIpv4Rloc("192.168.136.11"), mn.getMappingRecordItem().get(1)
+ .getMappingRecord().getLocatorRecord().get(0).getRloc());
+ assertEquals(LispAddressUtil.asIpv4Rloc("192.168.136.13"), mn.getMappingRecordItem().get(3)
+ .getMappingRecord().getLocatorRecord().get(0).getRloc());
}
@Test
+ "00 01 c0 a8 88 0a " // Locator
));
- assertEquals(1, mn.getEidToLocatorRecord().size());
- EidToLocatorRecord eidToLocator = mn.getEidToLocatorRecord().get(0);
- assertEquals(3, eidToLocator.getLocatorRecord().size());
- LocatorRecord loc0 = eidToLocator.getLocatorRecord().get(0);
- LocatorRecord loc1 = eidToLocator.getLocatorRecord().get(1);
- LocatorRecord loc2 = eidToLocator.getLocatorRecord().get(2);
+ assertEquals(1, mn.getMappingRecordItem().size());
+ MappingRecordItem eidToLocator = mn.getMappingRecordItem().get(0);
+ assertEquals(3, eidToLocator.getMappingRecord().getLocatorRecord().size());
+ LocatorRecord loc0 = eidToLocator.getMappingRecord().getLocatorRecord().get(0);
+ LocatorRecord loc1 = eidToLocator.getMappingRecord().getLocatorRecord().get(1);
+ LocatorRecord loc2 = eidToLocator.getMappingRecord().getLocatorRecord().get(2);
assertEquals((byte) 0x01, loc0.getPriority().byteValue());
assertEquals((byte) 0x67, loc1.getPriority().byteValue());
assertEquals((byte) 0x60, loc2.getPriority().byteValue());
assertFalse(loc1.isRouted());
assertTrue(loc2.isRouted());
- assertEquals(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("192.168.136.10")), loc0.getLispAddressContainer());
- assertEquals(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("204.170.170.17")), loc1.getLispAddressContainer());
+ assertEquals(LispAddressUtil.asIpv4Rloc("192.168.136.10"), loc0.getRloc());
+ assertEquals(LispAddressUtil.asIpv4Rloc("204.170.170.17"), loc1.getRloc());
}
@Test
+ "ff 00 00 05 00 01 c0 a8 88 0d " // contd
));
- assertEquals(4, mn.getEidToLocatorRecord().size());
+ assertEquals(4, mn.getMappingRecordItem().size());
- EidToLocatorRecord record0 = mn.getEidToLocatorRecord().get(0);
- EidToLocatorRecord record1 = mn.getEidToLocatorRecord().get(1);
- EidToLocatorRecord record2 = mn.getEidToLocatorRecord().get(2);
- EidToLocatorRecord record3 = mn.getEidToLocatorRecord().get(3);
+ MappingRecord record0 = mn.getMappingRecordItem().get(0).getMappingRecord();
+ MappingRecord record1 = mn.getMappingRecordItem().get(1).getMappingRecord();
+ MappingRecord record2 = mn.getMappingRecordItem().get(2).getMappingRecord();
+ MappingRecord record3 = mn.getMappingRecordItem().get(3).getMappingRecord();
assertEquals(10, record0.getRecordTtl().intValue());
assertEquals(13, record3.getRecordTtl().intValue());
+ "00 0a 01 20 F0 00 00 00 00 01 99 10 fe 01 01 64 " //
+ "ff 00 00 05 00 01 c0 a8 88 0a"));
- assertEquals(1, mn.getEidToLocatorRecord().size());
- assertEquals(Action.NoAction, mn.getEidToLocatorRecord().get(0).getAction());
+ assertEquals(1, mn.getMappingRecordItem().size());
+ assertEquals(Action.NoAction, mn.getMappingRecordItem().get(0).getMappingRecord().getAction());
}
@Test(expected = LispSerializationException.class)
assertFalse(mn.isXtrSiteIdPresent());
- assertEquals(1, mn.getEidToLocatorRecord().size());
+ assertEquals(1, mn.getMappingRecordItem().size());
assertEquals(0xFFBB000000000000L, mn.getNonce().longValue());
assertEquals(0x0001, mn.getKeyId().shortValue());
byte[] expectedAuthenticationData = { (byte) 0x2c, (byte) 0x61, (byte) 0xb9, (byte) 0xc9, (byte) 0x9a, (byte) 0x20, (byte) 0xba, (byte) 0xd8, //
assertFalse(mn.isXtrSiteIdPresent());
- assertEquals(1, mn.getEidToLocatorRecord().size());
+ assertEquals(1, mn.getMappingRecordItem().size());
assertEquals(0xFFBB000000000000L, mn.getNonce().longValue());
assertEquals(0x0002, mn.getKeyId().shortValue());
byte[] expectedAuthenticationData = { (byte) 0x70, (byte) 0x30, (byte) 0xd4, (byte) 0xc6, (byte) 0x10, (byte) 0x44, (byte) 0x0d, (byte) 0x83,
import org.opendaylight.lispflowmapping.lisp.serializer.MapRegisterSerializer;
import org.opendaylight.lispflowmapping.lisp.serializer.MapRegisterSerializer.Length;
import org.opendaylight.lispflowmapping.lisp.serializer.exception.LispSerializationException;
-import org.opendaylight.lispflowmapping.lisp.type.AddressFamilyNumberEnum;
-import org.opendaylight.lispflowmapping.lisp.util.LispAFIConvertor;
+import org.opendaylight.lispflowmapping.lisp.util.LispAddressUtil;
import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.EidToLocatorRecord.Action;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.NoAddressAfi;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.NoAddressBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapRegister;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eidtolocatorrecords.EidToLocatorRecord;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eidtolocatorrecords.EidToLocatorRecordBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.no.NoAddressBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.EidBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecord;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord.Action;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItem;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItemBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapregisternotification.MapRegisterBuilder;
public class MapRegisterSerializationTest extends BaseTestCase {
@Test
public void serialize__Fields() throws Exception {
MapRegisterBuilder mrBuilder = new MapRegisterBuilder();
- mrBuilder.setEidToLocatorRecord(new ArrayList<EidToLocatorRecord>());
- EidToLocatorRecordBuilder etlrBuilder = new EidToLocatorRecordBuilder();
- etlrBuilder.setLocatorRecord(new ArrayList<LocatorRecord>());
- etlrBuilder.setLispAddressContainer(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("0.0.0.1")));
+ mrBuilder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
+ MappingRecordBuilder recordBuilder = new MappingRecordBuilder();
+ recordBuilder.setLocatorRecord(new ArrayList<LocatorRecord>());
+ recordBuilder.setEid(LispAddressUtil.asIpv4PrefixEid("0.0.0.1/32"));
- mrBuilder.getEidToLocatorRecord().add(etlrBuilder.build());
- etlrBuilder.setLispAddressContainer(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("0.0.0.73")));
- mrBuilder.getEidToLocatorRecord().add(etlrBuilder.build());
+ mrBuilder.getMappingRecordItem().add(
+ new MappingRecordItemBuilder().setMappingRecord(recordBuilder.build()).build());
+ recordBuilder.setEid(LispAddressUtil.asIpv4PrefixEid("0.0.0.73/32"));
+ mrBuilder.getMappingRecordItem().add(
+ new MappingRecordItemBuilder().setMappingRecord(recordBuilder.build()).build());
mrBuilder.setNonce(6161616161L);
mrBuilder.setKeyId((short) 0x0001);
bb.get(actualAuthenticationData);
ArrayAssert.assertEquals(authenticationData, actualAuthenticationData);
- bb.position(bb.position() + 12); /* EID in first record */
+ bb.position(bb.position() + 12); // EID in first record
assertEquals(0x1, bb.getInt());
- bb.position(bb.position() + 12); /* EID in second record */
+ bb.position(bb.position() + 12); // EID in second record
assertEquals(73, bb.getInt());
byte[] actualXtrId = new byte[Length.XTRID_SIZE];
@Test
public void serialize__deserialize() throws Exception {
MapRegisterBuilder mrBuilder = new MapRegisterBuilder();
- mrBuilder.setEidToLocatorRecord(new ArrayList<EidToLocatorRecord>());
- EidToLocatorRecordBuilder etlrBuilder = new EidToLocatorRecordBuilder();
- etlrBuilder.setLocatorRecord(new ArrayList<LocatorRecord>());
- etlrBuilder.setLispAddressContainer(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("0.0.0.1")));
-
- etlrBuilder.setLispAddressContainer(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("0.0.0.73")));
- mrBuilder.getEidToLocatorRecord().add(etlrBuilder.build());
-
- etlrBuilder.setAction(Action.NoAction);
- etlrBuilder.setMapVersion((short) 0);
- etlrBuilder.setMaskLength((short) 0);
- etlrBuilder.setRecordTtl(0);
+ mrBuilder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
+ MappingRecordBuilder recordBuilder = new MappingRecordBuilder();
+ recordBuilder.setLocatorRecord(new ArrayList<LocatorRecord>());
+ recordBuilder.setEid(LispAddressUtil.asIpv4PrefixEid("0.0.0.1/32"));
+
+ mrBuilder.getMappingRecordItem().add(
+ new MappingRecordItemBuilder().setMappingRecord(recordBuilder.build()).build());
+ recordBuilder.setEid(LispAddressUtil.asIpv4PrefixEid("0.0.0.73/32"));
+ mrBuilder.getMappingRecordItem().add(
+ new MappingRecordItemBuilder().setMappingRecord(recordBuilder.build()).build());
+
+ recordBuilder.setAction(Action.NoAction);
+ recordBuilder.setMapVersion((short) 0);
+ recordBuilder.setMaskLength((short) 0);
+ recordBuilder.setRecordTtl(0);
mrBuilder.setNonce(6161616161L);
mrBuilder.setKeyId((short) 0x0001);
mrBuilder.setWantMapNotify(true);
@Test
public void serialize__NoAuthenticationData() throws Exception {
MapRegisterBuilder mrBuilder = new MapRegisterBuilder();
- mrBuilder.setEidToLocatorRecord(new ArrayList<EidToLocatorRecord>());
- mrBuilder.getEidToLocatorRecord().add(
- new EidToLocatorRecordBuilder().setRecordTtl(55)
- .setLispAddressContainer(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("0.0.0.1"))).build());
+ mrBuilder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
+ mrBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(
+ new MappingRecordBuilder().setRecordTtl(55)
+ .setEid(LispAddressUtil.asIpv4PrefixEid("0.0.0.1/32")).build()).build());
// mrBuilder.addEidToLocator(new EidToLocatorRecord().setPrefix(new
// LispIpv4Address(1)).setRecordTtl(55));
@Test
public void serialize__NoPrefixInEidToLocator() throws Exception {
MapRegisterBuilder mrBuilder = new MapRegisterBuilder();
- mrBuilder.setEidToLocatorRecord(new ArrayList<EidToLocatorRecord>());
- mrBuilder.getEidToLocatorRecord().add(new EidToLocatorRecordBuilder().build());
- mrBuilder.getEidToLocatorRecord().add(new EidToLocatorRecordBuilder().setLispAddressContainer(null).build());
- mrBuilder.getEidToLocatorRecord().add(
- new EidToLocatorRecordBuilder().setLispAddressContainer(
- LispAFIConvertor.toContainer(new NoAddressBuilder().setAfi(AddressFamilyNumberEnum.NO_ADDRESS.getIanaCode()).build())).build());
+ mrBuilder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
+ mrBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(
+ new MappingRecordBuilder().build()).build());
+ mrBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(
+ new MappingRecordBuilder().setEid(null).build()).build());
+ mrBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(
+ new MappingRecordBuilder().setEid(new EidBuilder().setAddressType(NoAddressAfi.class).setAddress(
+ (Address) new NoAddressBuilder().setNoAddress(true).build()).build()).build()).build());
ByteBuffer bb = MapRegisterSerializer.getInstance().serialize(mrBuilder.build());
bb.position(bb.position() + 16); // jump to first record prefix AFI
assertTrue(mr.isProxyMapReply());
assertTrue(mr.isWantMapNotify());
- assertEquals(1, mr.getEidToLocatorRecord().size());
+ assertEquals(1, mr.getMappingRecordItem().size());
assertEquals(0xFFBB000000000000L, mr.getNonce().longValue());
assertEquals(0x0000, mr.getKeyId().shortValue());
byte[] expectedAuthenticationData = {};
ByteBuffer bb = hexToByteBuffer("32 00 01 01 63 99 "
+ "83 64 23 06 a8 be 00 01 00 14 b8 c2 a2 e1 dc 4a "
+ "08 0c f6 01 b0 9d 70 5a d4 88 95 f8 73 dd 00 00 "
- + "05 a0 01 20 10 00 00 00 40 03 00 00 02 20 00 0a "
+ + "05 a0 01 20 10 00 00 00 40 03 00 00 02 00 00 0a "
+ "00 00 00 01 00 01 c3 a8 c8 01 0a 32 ff 00 00 04 "
+ "00 01 ac 10 01 02 15 1a 39 80 e3 35 e6 c4 49 a6 "
+ "90 87 20 65 9a b7 00 00 00 00 00 00 00 00 ");
+ "ff 00 00 05 00 01 c0 a8 88 0d " // contd
));
- assertEquals(4, mr.getEidToLocatorRecord().size());
- assertEquals(LispAFIConvertor.asIPv4Address("153.16.254.1"), mr.getEidToLocatorRecord().get(0)
- .getLispAddressContainer());
- assertEquals(LispAFIConvertor.asIPv4Address("151.16.254.1"), mr.getEidToLocatorRecord().get(2)
- .getLispAddressContainer());
- assertEquals(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("192.168.136.11")), mr.getEidToLocatorRecord().get(1)
- .getLocatorRecord().get(0).getLispAddressContainer());
- assertEquals(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("192.168.136.13")), mr.getEidToLocatorRecord().get(3)
- .getLocatorRecord().get(0).getLispAddressContainer());
+ assertEquals(4, mr.getMappingRecordItem().size());
+ assertEquals(LispAddressUtil.asIpv4PrefixEid("153.16.254.1/32"), mr.getMappingRecordItem().get(0)
+ .getMappingRecord().getEid());
+ assertEquals(LispAddressUtil.asIpv4PrefixEid("151.16.254.1/32"), mr.getMappingRecordItem().get(2)
+ .getMappingRecord().getEid());
+ assertEquals(LispAddressUtil.asIpv4Rloc("192.168.136.11"), mr.getMappingRecordItem().get(1)
+ .getMappingRecord().getLocatorRecord().get(0).getRloc());
+ assertEquals(LispAddressUtil.asIpv4Rloc("192.168.136.13"), mr.getMappingRecordItem().get(3)
+ .getMappingRecord().getLocatorRecord().get(0).getRloc());
}
@Test
+ "00 01 c0 a8 88 0a " // Locator
));
- assertEquals(1, mr.getEidToLocatorRecord().size());
- EidToLocatorRecord eidToLocator = mr.getEidToLocatorRecord().get(0);
- assertEquals(3, eidToLocator.getLocatorRecord().size());
- LocatorRecord loc0 = eidToLocator.getLocatorRecord().get(0);
- LocatorRecord loc1 = eidToLocator.getLocatorRecord().get(1);
- LocatorRecord loc2 = eidToLocator.getLocatorRecord().get(2);
+ assertEquals(1, mr.getMappingRecordItem().size());
+ MappingRecordItem eidToLocator = mr.getMappingRecordItem().get(0);
+ assertEquals(3, eidToLocator.getMappingRecord().getLocatorRecord().size());
+ LocatorRecord loc0 = eidToLocator.getMappingRecord().getLocatorRecord().get(0);
+ LocatorRecord loc1 = eidToLocator.getMappingRecord().getLocatorRecord().get(1);
+ LocatorRecord loc2 = eidToLocator.getMappingRecord().getLocatorRecord().get(2);
assertEquals((byte) 0x01, loc0.getPriority().byteValue());
assertEquals((byte) 0x67, loc1.getPriority().byteValue());
assertEquals((byte) 0x60, loc2.getPriority().byteValue());
assertFalse(loc1.isRouted());
assertTrue(loc2.isRouted());
- assertEquals(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("192.168.136.10")), loc0.getLispAddressContainer());
- assertEquals(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("204.170.170.17")), loc1.getLispAddressContainer());
+ assertEquals(LispAddressUtil.asIpv4Rloc("192.168.136.10"), loc0.getRloc());
+ assertEquals(LispAddressUtil.asIpv4Rloc("204.170.170.17"), loc1.getRloc());
}
@Test
+ "ff 00 00 05 00 01 c0 a8 88 0d " // contd
));
- assertEquals(4, mr.getEidToLocatorRecord().size());
+ assertEquals(4, mr.getMappingRecordItem().size());
- EidToLocatorRecord record0 = mr.getEidToLocatorRecord().get(0);
- EidToLocatorRecord record1 = mr.getEidToLocatorRecord().get(1);
- EidToLocatorRecord record2 = mr.getEidToLocatorRecord().get(2);
- EidToLocatorRecord record3 = mr.getEidToLocatorRecord().get(3);
+ MappingRecord record0 = mr.getMappingRecordItem().get(0).getMappingRecord();
+ MappingRecord record1 = mr.getMappingRecordItem().get(1).getMappingRecord();
+ MappingRecord record2 = mr.getMappingRecordItem().get(2).getMappingRecord();
+ MappingRecord record3 = mr.getMappingRecordItem().get(3).getMappingRecord();
assertEquals(10, record0.getRecordTtl().intValue());
assertEquals(13, record3.getRecordTtl().intValue());
+ "00 0a 01 20 F0 00 00 00 00 01 99 10 fe 01 01 64 " //
+ "ff 00 00 05 00 01 c0 a8 88 0a"));
- assertEquals(1, mr.getEidToLocatorRecord().size());
- assertEquals(Action.NoAction, mr.getEidToLocatorRecord().get(0).getAction());
+ assertEquals(1, mr.getMappingRecordItem().size());
+ assertEquals(Action.NoAction, mr.getMappingRecordItem().get(0).getMappingRecord().getAction());
}
@Test(expected = LispSerializationException.class)
assertTrue(mr.isProxyMapReply());
assertTrue(mr.isWantMapNotify());
- assertEquals(1, mr.getEidToLocatorRecord().size());
+ assertEquals(1, mr.getMappingRecordItem().size());
assertEquals(0xFFBB000000000000L, mr.getNonce().longValue());
assertEquals(0x0001, mr.getKeyId().shortValue());
byte[] expectedAuthenticationData = { (byte) 0x2c, (byte) 0x61, (byte) 0xb9, (byte) 0xc9, (byte) 0x9a, (byte) 0x20, (byte) 0xba, (byte) 0xd8, //
assertTrue(mr.isProxyMapReply());
assertTrue(mr.isWantMapNotify());
- assertEquals(1, mr.getEidToLocatorRecord().size());
+ assertEquals(1, mr.getMappingRecordItem().size());
assertEquals(0xFFBB000000000000L, mr.getNonce().longValue());
assertEquals(0x0002, mr.getKeyId().shortValue());
byte[] expectedAuthenticationData = { (byte) 0x70, (byte) 0x30, (byte) 0xd4, (byte) 0xc6, (byte) 0x10, (byte) 0x44, (byte) 0x0d, (byte) 0x83,
(byte) 0x11, (byte) 0x23, (byte) 0xb9, (byte) 0x38 };
ArrayAssert.assertEquals(expectedAuthenticationData, mr.getAuthenticationData());
}
-
}
import org.junit.Ignore;
import org.junit.Test;
import org.opendaylight.lispflowmapping.lisp.serializer.MapReplySerializer;
-import org.opendaylight.lispflowmapping.lisp.util.LispAFIConvertor;
+import org.opendaylight.lispflowmapping.lisp.util.LispAddressUtil;
import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.EidToLocatorRecord.Action;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Prefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapReply;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eidtolocatorrecords.EidToLocatorRecord;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eidtolocatorrecords.EidToLocatorRecordBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecord;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecordBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord.Action;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItem;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItemBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapreplymessage.MapReplyBuilder;
public class MapReplySerializationTest extends BaseTestCase {
@Test
public void serialize__SomeFlags() throws Exception {
MapReplyBuilder mr = new MapReplyBuilder();
- mr.setEidToLocatorRecord(new ArrayList<EidToLocatorRecord>());
- mr.getEidToLocatorRecord().add(
- new EidToLocatorRecordBuilder().setLispAddressContainer(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("0.0.0.1")))
- .build());
+ mr.setMappingRecordItem(new ArrayList<MappingRecordItem>());
+ MappingRecordBuilder recordBuilder = new MappingRecordBuilder();
+ recordBuilder.setEid(LispAddressUtil.asIpv4PrefixEid("0.0.0.1/32"));
+ mr.getMappingRecordItem().add(
+ new MappingRecordItemBuilder().setMappingRecord(recordBuilder.build()).build());
mr.setProbe(true);
mr.setEchoNonceEnabled(false);
+ "00 02 00 01 00 02 00 03 " //
+ "00 04 00 05 00 06 00 07 00 08 00 00 00 00 00 10 30 00 00 02 00 01 04 03 00 00"));
assertEquals(2, mr.getNonce().longValue());
- assertEquals(LispAFIConvertor.asIPv4Address(("1.2.3.4")), mr.getEidToLocatorRecord().get(0)
- .getLispAddressContainer());
- assertEquals(LispAFIConvertor.asIPv4Prefix(("4.3.2.1"), 16), mr.getEidToLocatorRecord().get(1)
- .getLispAddressContainer());
- assertEquals(false, mr.getEidToLocatorRecord().get(0).isAuthoritative());
- assertEquals(true, mr.getEidToLocatorRecord().get(1).isAuthoritative());
- assertEquals(Action.NoAction, mr.getEidToLocatorRecord().get(0).getAction());
- assertEquals(Action.NativelyForward, mr.getEidToLocatorRecord().get(1).getAction());
- assertEquals(0, mr.getEidToLocatorRecord().get(0).getMapVersion().shortValue());
- assertEquals(2, mr.getEidToLocatorRecord().get(1).getMapVersion().shortValue());
- assertEquals(32, mr.getEidToLocatorRecord().get(0).getMaskLength().shortValue());
- assertEquals(16, mr.getEidToLocatorRecord().get(1).getMaskLength().shortValue());
- assertEquals(2, mr.getEidToLocatorRecord().get(0).getRecordTtl().byteValue());
- assertEquals(0, mr.getEidToLocatorRecord().get(1).getRecordTtl().byteValue());
- assertEquals(LispAFIConvertor.toContainer(LispAFIConvertor.asIPv6AfiAddress(("1:2:3:4:5:6:7:8"))), mr.getEidToLocatorRecord().get(0)
- .getLocatorRecord().get(1).getLispAddressContainer());
- assertEquals(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress(("10.10.10.10"))), mr.getEidToLocatorRecord().get(0)
- .getLocatorRecord().get(0).getLispAddressContainer());
- assertEquals(1, mr.getEidToLocatorRecord().get(0).getLocatorRecord().get(0).getPriority().byteValue());
- assertEquals(2, mr.getEidToLocatorRecord().get(0).getLocatorRecord().get(0).getWeight().byteValue());
- assertEquals(3, mr.getEidToLocatorRecord().get(0).getLocatorRecord().get(0).getMulticastPriority().byteValue());
- assertEquals(4, mr.getEidToLocatorRecord().get(0).getLocatorRecord().get(0).getMulticastWeight().byteValue());
- assertEquals(4, mr.getEidToLocatorRecord().get(0).getLocatorRecord().get(1).getPriority().byteValue());
- assertEquals(3, mr.getEidToLocatorRecord().get(0).getLocatorRecord().get(1).getWeight().byteValue());
- assertEquals(2, mr.getEidToLocatorRecord().get(0).getLocatorRecord().get(1).getMulticastPriority().byteValue());
- assertEquals(1, mr.getEidToLocatorRecord().get(0).getLocatorRecord().get(1).getMulticastWeight().byteValue());
- assertEquals(true, mr.getEidToLocatorRecord().get(0).getLocatorRecord().get(0).isLocalLocator());
- assertEquals(true, mr.getEidToLocatorRecord().get(0).getLocatorRecord().get(0).isRlocProbed());
- assertEquals(false, mr.getEidToLocatorRecord().get(0).getLocatorRecord().get(0).isRouted());
- assertEquals(false, mr.getEidToLocatorRecord().get(0).getLocatorRecord().get(1).isLocalLocator());
- assertEquals(false, mr.getEidToLocatorRecord().get(0).getLocatorRecord().get(1).isRlocProbed());
- assertEquals(true, mr.getEidToLocatorRecord().get(0).getLocatorRecord().get(1).isRouted());
+ assertEquals("1.2.3.4/32", ((Ipv4Prefix) mr.getMappingRecordItem().get(0)
+ .getMappingRecord().getEid().getAddress()).getIpv4Prefix().getValue());
+ // XXX Why here normalized and other cases not normalized?
+ assertEquals("4.3.0.0/16", ((Ipv4Prefix) mr.getMappingRecordItem().get(1)
+ .getMappingRecord().getEid().getAddress()).getIpv4Prefix().getValue());
+ assertEquals(false, mr.getMappingRecordItem().get(0).getMappingRecord().isAuthoritative());
+ assertEquals(true, mr.getMappingRecordItem().get(1).getMappingRecord().isAuthoritative());
+ assertEquals(Action.NoAction, mr.getMappingRecordItem().get(0).getMappingRecord().getAction());
+ assertEquals(Action.NativelyForward, mr.getMappingRecordItem().get(1).getMappingRecord().getAction());
+ assertEquals(0, mr.getMappingRecordItem().get(0).getMappingRecord().getMapVersion().shortValue());
+ assertEquals(2, mr.getMappingRecordItem().get(1).getMappingRecord().getMapVersion().shortValue());
+ assertEquals(32, mr.getMappingRecordItem().get(0).getMappingRecord().getMaskLength().shortValue());
+ assertEquals(16, mr.getMappingRecordItem().get(1).getMappingRecord().getMaskLength().shortValue());
+ assertEquals(2, mr.getMappingRecordItem().get(0).getMappingRecord().getRecordTtl().byteValue());
+ assertEquals(0, mr.getMappingRecordItem().get(1).getMappingRecord().getRecordTtl().byteValue());
+ assertEquals("1:2:3:4:5:6:7:8", ((Ipv6) mr.getMappingRecordItem().get(0).getMappingRecord()
+ .getLocatorRecord().get(1).getRloc().getAddress()).getIpv6().getValue());
+ assertEquals("10.10.10.10", ((Ipv4) mr.getMappingRecordItem().get(0).getMappingRecord()
+ .getLocatorRecord().get(0).getRloc().getAddress()).getIpv4().getValue());
+ assertEquals(1, mr.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().get(0).getPriority().byteValue());
+ assertEquals(2, mr.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().get(0).getWeight().byteValue());
+ assertEquals(3, mr.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().get(0).getMulticastPriority().byteValue());
+ assertEquals(4, mr.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().get(0).getMulticastWeight().byteValue());
+ assertEquals(4, mr.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().get(1).getPriority().byteValue());
+ assertEquals(3, mr.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().get(1).getWeight().byteValue());
+ assertEquals(2, mr.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().get(1).getMulticastPriority().byteValue());
+ assertEquals(1, mr.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().get(1).getMulticastWeight().byteValue());
+ assertEquals(true, mr.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().get(0).isLocalLocator());
+ assertEquals(true, mr.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().get(0).isRlocProbed());
+ assertEquals(false, mr.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().get(0).isRouted());
+ assertEquals(false, mr.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().get(1).isLocalLocator());
+ assertEquals(false, mr.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().get(1).isRlocProbed());
+ assertEquals(true, mr.getMappingRecordItem().get(0).getMappingRecord().getLocatorRecord().get(1).isRouted());
}
@Test
public void serialize__MultipleRecordsWithoutRLOCs() throws Exception {
MapReplyBuilder mrBuilder = new MapReplyBuilder();
- mrBuilder.setEidToLocatorRecord(new ArrayList<EidToLocatorRecord>());
- mrBuilder.getEidToLocatorRecord().add(
- new EidToLocatorRecordBuilder().setLispAddressContainer(
- LispAFIConvertor.toContainer(LispAFIConvertor.asIPv6AfiAddress(("0:0:0:0:0:0:0:8")))).build());
- mrBuilder.getEidToLocatorRecord().add(
- new EidToLocatorRecordBuilder().setLispAddressContainer(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("8.2.4.5")))
- .build());
+ mrBuilder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
+ MappingRecordBuilder recordBuilder = new MappingRecordBuilder();
+ recordBuilder.setEid(LispAddressUtil.asIpv6PrefixEid("0:0:0:0:0:0:0:8/128"));
+ mrBuilder.getMappingRecordItem().add(
+ new MappingRecordItemBuilder().setMappingRecord(recordBuilder.build()).build());
+
+ recordBuilder.setEid(LispAddressUtil.asIpv4PrefixEid("8.2.4.5/32"));
+ mrBuilder.getMappingRecordItem().add(
+ new MappingRecordItemBuilder().setMappingRecord(recordBuilder.build()).build());
ByteBuffer packet = MapReplySerializer.getInstance().serialize(mrBuilder.build());
assertEquals(2, packet.get(3));
- packet.position(24); /* EID in first record */
+ packet.position(24); // EID in first record
byte[] expected = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08 };
byte[] actual = new byte[16];
packet.get(actual);
ArrayAssert.assertEquals(expected, actual);
- packet.position(packet.position() + 12); /* EID in second record */
+ packet.position(packet.position() + 12); // EID in second record
assertEquals(0x08020405, packet.getInt());
}
MapReply mr = MapReplySerializer.getInstance().deserialize(hexToByteBuffer("20 00 00 02 00 00 "
//
+ "00 00 00 00 00 00 00 00 00 01 00 20 00 00 00 00 00 01 01 02 03 04 00 00 00 00 00 10 30 00 00 02 00 01 04 03 00 00"));
- assertEquals(LispAFIConvertor.asIPv4Address(("1.2.3.4")), mr.getEidToLocatorRecord().get(0)
- .getLispAddressContainer());
- assertEquals(LispAFIConvertor.asIPv4Prefix("4.3.2.1", 16), mr.getEidToLocatorRecord().get(1)
- .getLispAddressContainer());
- assertEquals(false, mr.getEidToLocatorRecord().get(0).isAuthoritative());
- assertEquals(true, mr.getEidToLocatorRecord().get(1).isAuthoritative());
- assertEquals(Action.NoAction, mr.getEidToLocatorRecord().get(0).getAction());
- assertEquals(Action.NativelyForward, mr.getEidToLocatorRecord().get(1).getAction());
- assertEquals(0, mr.getEidToLocatorRecord().get(0).getMapVersion().shortValue());
- assertEquals(2, mr.getEidToLocatorRecord().get(1).getMapVersion().shortValue());
- assertEquals(32, mr.getEidToLocatorRecord().get(0).getMaskLength().shortValue());
- assertEquals(16, mr.getEidToLocatorRecord().get(1).getMaskLength().shortValue());
- assertEquals(1, mr.getEidToLocatorRecord().get(0).getRecordTtl().byteValue());
- assertEquals(0, mr.getEidToLocatorRecord().get(1).getRecordTtl().byteValue());
+ assertEquals("1.2.3.4/32", ((Ipv4Prefix) mr.getMappingRecordItem().get(0)
+ .getMappingRecord().getEid().getAddress()).getIpv4Prefix().getValue());
+ // XXX Why here normalized and other cases not normalized?
+ assertEquals("4.3.0.0/16", ((Ipv4Prefix) mr.getMappingRecordItem().get(1)
+ .getMappingRecord().getEid().getAddress()).getIpv4Prefix().getValue());
+ assertEquals(false, mr.getMappingRecordItem().get(0).getMappingRecord().isAuthoritative());
+ assertEquals(true, mr.getMappingRecordItem().get(1).getMappingRecord().isAuthoritative());
+ assertEquals(Action.NoAction, mr.getMappingRecordItem().get(0).getMappingRecord().getAction());
+ assertEquals(Action.NativelyForward, mr.getMappingRecordItem().get(1).getMappingRecord().getAction());
+ assertEquals(0, mr.getMappingRecordItem().get(0).getMappingRecord().getMapVersion().shortValue());
+ assertEquals(2, mr.getMappingRecordItem().get(1).getMappingRecord().getMapVersion().shortValue());
+ assertEquals(32, mr.getMappingRecordItem().get(0).getMappingRecord().getMaskLength().shortValue());
+ assertEquals(16, mr.getMappingRecordItem().get(1).getMappingRecord().getMaskLength().shortValue());
+ assertEquals(1, mr.getMappingRecordItem().get(0).getMappingRecord().getRecordTtl().byteValue());
+ assertEquals(0, mr.getMappingRecordItem().get(1).getMappingRecord().getRecordTtl().byteValue());
}
@Test
public void serialize__EidRecordDefaultAction() throws Exception {
MapReplyBuilder mrBuilder = new MapReplyBuilder();
- mrBuilder.setEidToLocatorRecord(new ArrayList<EidToLocatorRecord>());
- mrBuilder.getEidToLocatorRecord().add(
- new EidToLocatorRecordBuilder().setLispAddressContainer(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress(("0.0.0.1"))))
- .build());
+ mrBuilder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
+ MappingRecordBuilder recordBuilder = new MappingRecordBuilder();
+ recordBuilder.setEid(LispAddressUtil.asIpv4PrefixEid("0.0.0.1/32"));
+ mrBuilder.getMappingRecordItem().add(
+ new MappingRecordItemBuilder().setMappingRecord(recordBuilder.build()).build());
ByteBuffer packet = MapReplySerializer.getInstance().serialize(mrBuilder.build());
@Test
public void serialize__EidRecordNullActionShouldTranslateToDefault() throws Exception {
MapReplyBuilder mrBuilder = new MapReplyBuilder();
- mrBuilder.setEidToLocatorRecord(new ArrayList<EidToLocatorRecord>());
- mrBuilder.getEidToLocatorRecord().add(
- new EidToLocatorRecordBuilder().setAction(null)
- .setLispAddressContainer(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress(("0.0.0.1")))).build());
+ mrBuilder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
+ MappingRecordBuilder recordBuilder = new MappingRecordBuilder();
+ recordBuilder.setEid(LispAddressUtil.asIpv4PrefixEid("0.0.0.1/32"));
+ recordBuilder.setAction(null);
+ mrBuilder.getMappingRecordItem().add(
+ new MappingRecordItemBuilder().setMappingRecord(recordBuilder.build()).build());
ByteBuffer packet = MapReplySerializer.getInstance().serialize(mrBuilder.build());
@Test
public void serialize__EidRecordFields() throws Exception {
MapReplyBuilder mrBuilder = new MapReplyBuilder();
- mrBuilder.setEidToLocatorRecord(new ArrayList<EidToLocatorRecord>());
+ mrBuilder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
- EidToLocatorRecordBuilder eidToLocator1 = new EidToLocatorRecordBuilder();
- eidToLocator1.setLispAddressContainer(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("0.0.0.1")));
+ MappingRecordBuilder eidToLocator1 = new MappingRecordBuilder();
+ eidToLocator1.setEid(LispAddressUtil.asIpv4PrefixEid("0.0.0.1/32"));
eidToLocator1.setRecordTtl(7);
eidToLocator1.setAction(Action.SendMapRequest);
eidToLocator1.setAuthoritative(true);
eidToLocator1.setMapVersion((short) 3072);
- mrBuilder.getEidToLocatorRecord().add(eidToLocator1.build());
+ mrBuilder.getMappingRecordItem().add(
+ new MappingRecordItemBuilder().setMappingRecord(eidToLocator1.build()).build());
- EidToLocatorRecordBuilder eidToLocator2 = new EidToLocatorRecordBuilder();
- eidToLocator2.setLispAddressContainer(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("0.0.0.7")));
+ MappingRecordBuilder eidToLocator2 = new MappingRecordBuilder();
+ eidToLocator2.setEid(LispAddressUtil.asIpv4PrefixEid("0.0.0.7/32"));
eidToLocator2.setRecordTtl(1000000);
eidToLocator2.setAction(Action.Drop);
eidToLocator2.setAuthoritative(false);
eidToLocator2.setMapVersion((short) 29);
- mrBuilder.getEidToLocatorRecord().add(eidToLocator2.build());
+ mrBuilder.getMappingRecordItem().add(
+ new MappingRecordItemBuilder().setMappingRecord(eidToLocator2.build()).build());
ByteBuffer packet = MapReplySerializer.getInstance().serialize(mrBuilder.build());
- packet.position(12); /* First record */
+ packet.position(12); // First record
assertEquals(7, packet.getInt());
- packet.position(packet.position() + 2); /*
- * skip Locator Count & Mask-len
- */
+ packet.position(packet.position() + 2); // skip Locator Count & Mask-len
+
assertHexEquals((byte) 0x50, packet.get());
- packet.position(packet.position() + 1); /* skip Reserved byte */
+ packet.position(packet.position() + 1); // skip Reserved byte
assertEquals((short) 3072, packet.getShort());
- packet.position(packet.position() + 6); /* Second record */
+ packet.position(packet.position() + 6); // Second record
assertEquals(1000000, packet.getInt());
- packet.position(packet.position() + 2); /*
- * skip Locator Count & Mask-len
- */
+ packet.position(packet.position() + 2); // skip Locator Count & Mask-len
+
assertHexEquals((byte) 0x60, packet.get());
- packet.position(packet.position() + 1); /* skip Reserved byte */
+ packet.position(packet.position() + 1); // skip Reserved byte
assertEquals((short) 29, packet.getShort());
}
@Test
public void serialize__LocatorRecordFields() throws Exception {
MapReplyBuilder mrBuilder = new MapReplyBuilder();
- mrBuilder.setEidToLocatorRecord(new ArrayList<EidToLocatorRecord>());
+ mrBuilder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
- EidToLocatorRecordBuilder eidToLocatorBuilder = new EidToLocatorRecordBuilder();
- eidToLocatorBuilder.setLispAddressContainer(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("0.0.0.1")));
+ MappingRecordBuilder eidToLocatorBuilder = new MappingRecordBuilder();
+ eidToLocatorBuilder.setEid(LispAddressUtil.asIpv4PrefixEid("0.0.0.1/32"));
eidToLocatorBuilder.setLocatorRecord(new ArrayList<LocatorRecord>());
LocatorRecordBuilder locatorBuilder1 = new LocatorRecordBuilder();
locatorBuilder1.setWeight((short) 0xF6);
locatorBuilder1.setMulticastPriority((short) 0xA3);
locatorBuilder1.setMulticastWeight((short) 0x06);
- locatorBuilder1.setLispAddressContainer(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("0.0.0.1")));
+ locatorBuilder1.setRloc(LispAddressUtil.asIpv4Rloc("0.0.0.1"));
locatorBuilder1.setLocalLocator(true);
locatorBuilder1.setRlocProbed(true);
locatorBuilder1.setRouted(true);
locatorBuilder2.setWeight((short) 0x06);
locatorBuilder2.setMulticastPriority((short) 0x03);
locatorBuilder2.setMulticastWeight((short) 0xF1);
- locatorBuilder2.setLispAddressContainer(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("0.0.0.2")));
+ locatorBuilder2.setRloc(LispAddressUtil.asIpv4Rloc("0.0.0.2"));
locatorBuilder2.setLocalLocator(false);
locatorBuilder2.setRlocProbed(false);
locatorBuilder2.setRouted(false);
eidToLocatorBuilder.getLocatorRecord().add(locatorBuilder2.build());
- mrBuilder.getEidToLocatorRecord().add(eidToLocatorBuilder.build());
+ mrBuilder.getMappingRecordItem().add(
+ new MappingRecordItemBuilder().setMappingRecord(eidToLocatorBuilder.build()).build());
ByteBuffer packet = MapReplySerializer.getInstance().serialize(mrBuilder.build());
- packet.position(12 + 16); /* First locator record */
+ packet.position(12 + 16); // First locator record
assertHexEquals((byte) 0xF3, packet.get());
assertHexEquals((byte) 0xF6, packet.get());
assertHexEquals((byte) 0xA3, packet.get());
packet.position(packet.position() + 1);
assertHexEquals((byte) 0x07, packet.get());
- packet.position(packet.position() + 6); /* Second locator record */
+ packet.position(packet.position() + 6); // Second locator record
assertHexEquals((byte) 0x03, packet.get());
assertHexEquals((byte) 0x06, packet.get());
assertHexEquals((byte) 0x03, packet.get());
import org.junit.Test;
import org.opendaylight.lispflowmapping.lisp.serializer.MapRequestSerializer;
-import org.opendaylight.lispflowmapping.lisp.type.AddressFamilyNumberEnum;
-import org.opendaylight.lispflowmapping.lisp.util.LispAFIConvertor;
+import org.opendaylight.lispflowmapping.lisp.util.LispAddressUtil;
import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.EidToLocatorRecord.Action;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.NoAddressAfi;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Prefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6Prefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.NoAddressBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapRequest;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eidrecords.EidRecord;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eidrecords.EidRecordBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.LispAddressContainerBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.Ipv4;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.NoBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.no.NoAddressBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.EidBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.list.EidItem;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.list.EidItemBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecord;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecordBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord.Action;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRloc;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRlocBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.MapReply;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.MapReplyBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.SourceEidBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequestnotification.MapRequestBuilder;
@Test
public void prefix__NoPrefix() throws Exception {
MapRequestBuilder mrBuilder = new MapRequestBuilder();
- mrBuilder.setEidRecord(new ArrayList<EidRecord>());
- mrBuilder.getEidRecord().add(
- new EidRecordBuilder().setLispAddressContainer(
- new LispAddressContainerBuilder().setAddress(
- new NoBuilder().setNoAddress(
- new NoAddressBuilder().setAfi((short) 0)
- .build()).build()).build()).build());
+ mrBuilder.setEidItem(new ArrayList<EidItem>());
+ mrBuilder.getEidItem().add(new EidItemBuilder().setEid(
+ new EidBuilder().setAddressType(NoAddressAfi.class).setAddress(
+ (Address) new NoAddressBuilder().setNoAddress(true).build()).build()).build());
- assertEquals(AddressFamilyNumberEnum.NO_ADDRESS.getIanaCode(),
- LispAFIConvertor.toAFI(mrBuilder.getEidRecord().get(0).getLispAddressContainer()).getAfi().shortValue());
+ assertEquals(NoAddressAfi.class, mrBuilder.getEidItem().get(0).getEid().getAddressType());
}
@Test
+ "38 66 00 20 00 01 01 02 03 04 00 00 00 0a 01 20 " //
+ "10 00 00 00 00 01 01 01 01 01 01 64 ff 00 00 05 " //
+ "00 01 c0 a8 38 66"));
- assertEquals("1.1.1.1", ((Ipv4) mr.getSourceEid().getLispAddressContainer().getAddress()).getIpv4Address().getIpv4Address().getValue());
- assertEquals("1.2.3.4", ((Ipv4) mr.getEidRecord().get(0).getLispAddressContainer().getAddress()).getIpv4Address().getIpv4Address().getValue());
+ assertEquals("1.1.1.1", ((Ipv4) mr.getSourceEid().getEid().getAddress()).getIpv4().getValue());
+ assertEquals("1.2.3.4/32",
+ ((Ipv4Prefix) mr.getEidItem().get(0).getEid().getAddress()).getIpv4Prefix().getValue());
}
}
@Test
- public void deserialize__SingleEidRecord() throws Exception {
+ public void deserialize__SingleEidItem() throws Exception {
MapRequest mr = MapRequestSerializer.getInstance().deserialize(hexToByteBuffer("16 80 00 "
//
+ "01 " // single record
+ "3d 8d 2a cd 39 c8 d6 08 00 00 00 01 c0 a8 88 0a " //
+ "00 20 00 01 01 02 03 04"));
- assertEquals(1, mr.getEidRecord().size());
- EidRecord eid = mr.getEidRecord().get(0);
- assertEquals(0x20, eid.getMask().byteValue());
- assertEquals(LispAFIConvertor.asIPv4Address("1.2.3.4"), eid.getLispAddressContainer());
+ assertEquals(1, mr.getEidItem().size());
+ Eid eid = mr.getEidItem().get(0).getEid();
+ assertEquals("1.2.3.4/32", ((Ipv4Prefix) eid.getAddress()).getIpv4Prefix().getValue());
}
@Test
));
- assertEquals(1, mr.getEidRecord().size());
- EidRecord eid = mr.getEidRecord().get(0);
- assertEquals(0x20, eid.getMask().byteValue());
- assertEquals(LispAFIConvertor.asIPv4Prefix("1.2.3.4", 0x20), eid.getLispAddressContainer());
- MapReply mapReply = mr.getMapReply();
- assertEquals(LispAFIConvertor.asIPv4Address(("1.2.3.4")), mapReply.getLispAddressContainer());
- assertEquals(false, mapReply.isAuthoritative());
- assertEquals(Action.NoAction, mapReply.getAction());
- assertEquals(0, mapReply.getMapVersion().shortValue());
- assertEquals(32, mapReply.getMaskLength().shortValue());
- assertEquals(2, mapReply.getRecordTtl().byteValue());
- assertEquals(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress(("10.10.10.10"))), mapReply.getLocatorRecord().get(0)
- .getLispAddressContainer());
- assertEquals(1, mapReply.getLocatorRecord().get(0).getPriority().byteValue());
- assertEquals(2, mapReply.getLocatorRecord().get(0).getWeight().byteValue());
- assertEquals(3, mapReply.getLocatorRecord().get(0).getMulticastPriority().byteValue());
- assertEquals(4, mapReply.getLocatorRecord().get(0).getMulticastWeight().byteValue());
- assertEquals(true, mapReply.getLocatorRecord().get(0).isLocalLocator());
- assertEquals(true, mapReply.getLocatorRecord().get(0).isRlocProbed());
- assertEquals(false, mapReply.getLocatorRecord().get(0).isRouted());
+ assertEquals(1, mr.getEidItem().size());
+ Eid eid = mr.getEidItem().get(0).getEid();
+ assertEquals("1.2.3.4/32", ((Ipv4Prefix) eid.getAddress()).getIpv4Prefix().getValue());
+ MappingRecord record = mr.getMapReply().getMappingRecord();
+ assertEquals("1.2.3.4/32", ((Ipv4Prefix) record.getEid().getAddress()).getIpv4Prefix().getValue());
+ assertEquals(false, record.isAuthoritative());
+ assertEquals(Action.NoAction, record.getAction());
+ assertEquals(0, record.getMapVersion().shortValue());
+ assertEquals(32, record.getMaskLength().shortValue());
+ assertEquals(2, record.getRecordTtl().byteValue());
+ assertEquals("10.10.10.10",
+ ((Ipv4) record.getLocatorRecord().get(0).getRloc().getAddress()).getIpv4().getValue());
+ assertEquals(1, record.getLocatorRecord().get(0).getPriority().byteValue());
+ assertEquals(2, record.getLocatorRecord().get(0).getWeight().byteValue());
+ assertEquals(3, record.getLocatorRecord().get(0).getMulticastPriority().byteValue());
+ assertEquals(4, record.getLocatorRecord().get(0).getMulticastWeight().byteValue());
+ assertEquals(true, record.getLocatorRecord().get(0).isLocalLocator());
+ assertEquals(true, record.getLocatorRecord().get(0).isRlocProbed());
+ assertEquals(false, record.getLocatorRecord().get(0).isRouted());
}
@Test
- public void serialize__SingleEidRecord() throws Exception {
+ public void serialize__SingleEidItem() throws Exception {
MapRequestBuilder mrBuilder = new MapRequestBuilder();
- mrBuilder.setEidRecord(new ArrayList<EidRecord>());
- mrBuilder.getEidRecord().add(
- new EidRecordBuilder().setMask((short) 32)
- .setLispAddressContainer(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("1.2.3.4"))).build());
+ mrBuilder.setEidItem(new ArrayList<EidItem>());
+ mrBuilder.getEidItem().add(new EidItemBuilder().setEid(LispAddressUtil.asIpv4PrefixEid("1.2.3.4/32")).build());
ByteBuffer expected = hexToByteBuffer("10 00 00 01 00 00 " //
+ "00 00 00 00 00 00 00 00 00 20 00 01 01 02 03 04");
assertArrayEquals(expected.array(), MapRequestSerializer.getInstance().serialize(mrBuilder.build()).array());
}
@Test
- public void deserialize__MultipleEidRecord() throws Exception {
+ public void deserialize__MultipleEidItem() throws Exception {
MapRequest mr = MapRequestSerializer.getInstance().deserialize(hexToByteBuffer("16 80 00 "
//
+ "02 " // 2 records
+ "00 20 00 01 01 02 03 04 " //
+ "00 80 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 05"));
- assertEquals(2, mr.getEidRecord().size());
+ assertEquals(2, mr.getEidItem().size());
- EidRecord eid = mr.getEidRecord().get(0);
- assertEquals(0x0020, eid.getMask().shortValue());
- assertEquals(LispAFIConvertor.asIPv4Address("1.2.3.4"), eid.getLispAddressContainer());
+ Eid eid = mr.getEidItem().get(0).getEid();
+ assertEquals("1.2.3.4/32", ((Ipv4Prefix) eid.getAddress()).getIpv4Prefix().getValue());
- eid = mr.getEidRecord().get(1);
- assertEquals(0x0080, eid.getMask().shortValue());
- assertEquals(LispAFIConvertor.asIPv6Address("0:0:0:0:0:0:0:5"), eid.getLispAddressContainer());
+ eid = mr.getEidItem().get(1).getEid();
+ assertEquals("0:0:0:0:0:0:0:5/128", ((Ipv6Prefix) eid.getAddress()).getIpv6Prefix().getValue());
}
@Test
- public void serialize__MultipleEidRecord() throws Exception {
+ public void serialize__MultipleEidItem() throws Exception {
MapRequestBuilder mrBuilder = new MapRequestBuilder();
- mrBuilder.setEidRecord(new ArrayList<EidRecord>());
- mrBuilder.getEidRecord().add(
- new EidRecordBuilder().setMask((short) 32)
- .setLispAddressContainer(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("1.2.3.4"))).build());
- mrBuilder.getEidRecord().add(
- new EidRecordBuilder().setMask((short) 0)
- .setLispAddressContainer(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("4.3.2.1"))).build());
+ mrBuilder.setEidItem(new ArrayList<EidItem>());
+ mrBuilder.getEidItem().add(new EidItemBuilder().setEid(LispAddressUtil.asIpv4PrefixEid("1.2.3.4/32")).build());
+ mrBuilder.getEidItem().add(new EidItemBuilder().setEid(LispAddressUtil.asIpv4PrefixEid("4.3.2.1/0")).build());
ByteBuffer expected = hexToByteBuffer("10 00 00 02 00 00 " //
+ "00 00 00 00 00 00 00 00 00 20 00 01 01 02 03 04 00 00 00 01 04 03 02 01");
assertArrayEquals(expected.array(), MapRequestSerializer.getInstance().serialize(mrBuilder.build()).array());
+ "00 20 00 01 01 02 03 04"));
assertEquals(1, mr.getItrRloc().size());
- assertEquals(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("192.168.136.10")), mr.getItrRloc().get(0)
- .getLispAddressContainer());
+ assertEquals("192.168.136.10", ((Ipv4) mr.getItrRloc().get(0).getRloc().getAddress()).getIpv4().getValue());
}
@Test
public void serialize__SingleItrRloc() throws Exception {
MapRequestBuilder mrBuilder = new MapRequestBuilder();
mrBuilder.setItrRloc(new ArrayList<ItrRloc>());
- mrBuilder.getItrRloc().add(
- new ItrRlocBuilder().setLispAddressContainer(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("1.2.3.4"))).build());
+ mrBuilder.getItrRloc().add(new ItrRlocBuilder().setRloc(LispAddressUtil.asIpv4Rloc("1.2.3.4")).build());
ByteBuffer expected = hexToByteBuffer("10 00 00 00 00 00 " //
+ "00 00 00 00 00 00 00 00 00 01 01 02 03 04");
assertArrayEquals(expected.array(), MapRequestSerializer.getInstance().serialize(mrBuilder.build()).array());
public void serialize__MultipleItrRloc() throws Exception {
MapRequestBuilder mrBuilder = new MapRequestBuilder();
mrBuilder.setItrRloc(new ArrayList<ItrRloc>());
- mrBuilder.getItrRloc().add(
- new ItrRlocBuilder().setLispAddressContainer(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("1.2.3.4"))).build());
- mrBuilder.getItrRloc().add(
- new ItrRlocBuilder().setLispAddressContainer(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("4.3.2.1"))).build());
+ mrBuilder.getItrRloc().add(new ItrRlocBuilder().setRloc(LispAddressUtil.asIpv4Rloc("1.2.3.4")).build());
+ mrBuilder.getItrRloc().add(new ItrRlocBuilder().setRloc(LispAddressUtil.asIpv4Rloc("4.3.2.1")).build());
ByteBuffer expected = hexToByteBuffer("10 00 01 00 00 00 " //
+ "00 00 00 00 00 00 00 00 00 01 01 02 03 04 00 01 04 03 02 01");
assertArrayEquals(expected.array(), MapRequestSerializer.getInstance().serialize(mrBuilder.build()).array());
+ "00 20 00 01 01 02 03 04"));
assertEquals(3, mr.getItrRloc().size());
- assertEquals(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("192.168.136.10")), mr.getItrRloc().get(0)
- .getLispAddressContainer());
- assertEquals(LispAFIConvertor.toContainer(LispAFIConvertor.asIPv6AfiAddress("0:0:0:0:0:0:0:1")), mr.getItrRloc().get(1)
- .getLispAddressContainer());
- assertEquals(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("17.34.52.86")), mr.getItrRloc().get(2).getLispAddressContainer());
+ assertEquals("192.168.136.10", ((Ipv4) mr.getItrRloc().get(0).getRloc().getAddress()).getIpv4().getValue());
+ assertEquals("0:0:0:0:0:0:0:1", ((Ipv6) mr.getItrRloc().get(1).getRloc().getAddress()).getIpv6().getValue());
+ assertEquals("17.34.52.86", ((Ipv4) mr.getItrRloc().get(2).getRloc().getAddress()).getIpv4().getValue());
}
@Test
mrBuilder.setProbe(true);
mrBuilder.setPitr(true);
mrBuilder.setNonce((long) 13);
- mrBuilder.setSourceEid(new SourceEidBuilder().setLispAddressContainer(
- LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("10.0.0.1"))).build());
+ mrBuilder.setSourceEid(new SourceEidBuilder().setEid(LispAddressUtil.asIpv4Eid(("10.0.0.1"))).build());
mrBuilder.setItrRloc(new ArrayList<ItrRloc>());
- mrBuilder.getItrRloc().add(
- new ItrRlocBuilder().setLispAddressContainer(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("1.2.3.4"))).build());
- mrBuilder.getItrRloc().add(
- new ItrRlocBuilder().setLispAddressContainer(LispAFIConvertor.toContainer(LispAFIConvertor.asIPv6AfiAddress("1:2:3:4:5:6:7:8")))
- .build());
- mrBuilder.setEidRecord(new ArrayList<EidRecord>());
- mrBuilder.getEidRecord().add(
- new EidRecordBuilder().setMask((short) 32)
- .setLispAddressContainer(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("1.2.3.4"))).build());
+ mrBuilder.getItrRloc().add(new ItrRlocBuilder().setRloc(LispAddressUtil.asIpv4Rloc("1.2.3.4")).build());
+ mrBuilder.getItrRloc().add(new ItrRlocBuilder().setRloc(LispAddressUtil.asIpv6Rloc("1:2:3:4:5:6:7:8")).build());
+ mrBuilder.setEidItem(new ArrayList<EidItem>());
+ mrBuilder.getEidItem().add(new EidItemBuilder().setEid(LispAddressUtil.asIpv4PrefixEid("1.2.3.4/32")).build());
ByteBuffer expected = hexToByteBuffer("12 80 01 01 00 00 " //
+ "00 00 00 00 00 0D 00 01 0a 00 00 01 00 01 01 02 03 04 00 02 00 01 00 02 00 03 00 04 00 05 00 06 00 07 00 08 00 20 00 01 01 02 03 04");
assertArrayEquals(expected.array(), MapRequestSerializer.getInstance().serialize(mrBuilder.build()).array());
mapRequestBuilder.setMapDataPresent(true);
mapRequestBuilder.setPitr(true);
mapRequestBuilder.setNonce((long) 13);
- mapRequestBuilder.setSourceEid(new SourceEidBuilder().setLispAddressContainer(
- LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("10.0.0.1"))).build());
+ mapRequestBuilder.setSourceEid(new SourceEidBuilder().setEid(LispAddressUtil.asIpv4Eid(("10.0.0.1"))).build());
mapRequestBuilder.setItrRloc(new ArrayList<ItrRloc>());
- mapRequestBuilder.getItrRloc().add(
- new ItrRlocBuilder().setLispAddressContainer(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("1.2.3.4"))).build());
- mapRequestBuilder.getItrRloc().add(
- new ItrRlocBuilder().setLispAddressContainer(LispAFIConvertor.toContainer(LispAFIConvertor.asIPv6AfiAddress("1:2:3:4:5:6:7:8")))
- .build());
- mapRequestBuilder.setEidRecord(new ArrayList<EidRecord>());
- mapRequestBuilder.getEidRecord().add(
- new EidRecordBuilder().setMask((short) 32)
- .setLispAddressContainer(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("1.2.3.4"))).build());
+ mapRequestBuilder.getItrRloc().add(new ItrRlocBuilder().setRloc(LispAddressUtil.asIpv4Rloc("1.2.3.4")).build());
+ mapRequestBuilder.getItrRloc().add(new ItrRlocBuilder().setRloc(LispAddressUtil.asIpv6Rloc("1:2:3:4:5:6:7:8")).build());
+ mapRequestBuilder.setEidItem(new ArrayList<EidItem>());
+ mapRequestBuilder.getEidItem().add(new EidItemBuilder().setEid(LispAddressUtil.asIpv4PrefixEid("1.2.3.4/32")).build());
MapReplyBuilder mapreplyBuilder = new MapReplyBuilder();
+ MappingRecordBuilder recordBuilder = new MappingRecordBuilder();
- mapreplyBuilder.setLispAddressContainer(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("0.0.0.1")));
- mapreplyBuilder.setLocatorRecord(new ArrayList<LocatorRecord>());
+ recordBuilder.setEid(LispAddressUtil.asIpv4PrefixEid("0.0.0.1/0"));
+ recordBuilder.setLocatorRecord(new ArrayList<LocatorRecord>());
LocatorRecordBuilder locatorBuilder = new LocatorRecordBuilder();
- locatorBuilder.setLispAddressContainer(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("0.0.0.2")));
- mapreplyBuilder.getLocatorRecord().add(locatorBuilder.build());
+ locatorBuilder.setRloc(LispAddressUtil.asIpv4Rloc("0.0.0.2"));
+ recordBuilder.getLocatorRecord().add(locatorBuilder.build());
+ mapreplyBuilder.setMappingRecord(recordBuilder.build());
mapRequestBuilder.setMapReply(mapreplyBuilder.build());
ByteBuffer expected = hexToByteBuffer("16 80 01 01 00 00 " //
+ "00 00 00 00 01 00 00 00 00 00 00 01 00 00 00 01 00 00 00 00 00 00 00 01 00 00 00 02");
assertArrayEquals(expected.array(), MapRequestSerializer.getInstance().serialize(mapRequestBuilder.build()).array());
}
-
}
--- /dev/null
+/*
+ * Copyright (c) 2014 Contextream, 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.serializer.address;
+
+import static org.junit.Assert.assertEquals;
+
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.List;
+
+import junitx.framework.ArrayAssert;
+import junitx.framework.Assert;
+
+import org.junit.Test;
+import org.opendaylight.lispflowmapping.lisp.serializer.address.LispAddressSerializer;
+import org.opendaylight.lispflowmapping.lisp.serializer.exception.LispSerializationException;
+import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.AfiListLcaf;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SimpleAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SimpleAddressBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.AfiList;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.afi.list.AfiListBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.Rloc;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.RlocBuilder;
+
+public class AfiListSerializerTest extends BaseTestCase {
+
+ @Test
+ public void deserialize__Simple() throws Exception {
+ Rloc address = LispAddressSerializer.getInstance().deserializeRloc(hexToByteBuffer("40 03 00 00 " + //
+ "01 00 00 18 " + //
+ "00 01 AA BB CC DD " + // IPv4
+ "00 02 11 22 33 44 11 22 33 44 11 22 33 44 11 22 33 44")); // IPv6
+
+ assertEquals(AfiListLcaf.class, address.getAddressType());
+ AfiList afiList = (AfiList) address.getAddress();
+
+ List<SimpleAddress> addressList = afiList.getAfiList().getAddressList();
+ assertEquals(2, addressList.size());
+
+ assertEquals("170.187.204.221", String.valueOf(addressList.get(0).getValue()));
+ assertEquals("1122:3344:1122:3344:1122:3344:1122:3344", String.valueOf(addressList.get(1).getValue()));
+ }
+
+ @Test
+ public void deserialize__NoAddresses() throws Exception {
+ Rloc address = LispAddressSerializer.getInstance().deserializeRloc(hexToByteBuffer("40 03 00 00 " + //
+ "01 00 00 00 "));
+
+ assertEquals(AfiListLcaf.class, address.getAddressType());
+ AfiList afiList = (AfiList) address.getAddress();
+
+ List<SimpleAddress> addressList = afiList.getAfiList().getAddressList();
+ assertEquals(0, addressList.size());
+ }
+
+ @Test(expected = LispSerializationException.class)
+ public void deserialize__ShorterBuffer() throws Exception {
+ LispAddressSerializer.getInstance().deserializeRloc(hexToByteBuffer("40 03 00 00 " + //
+ "01 00 00 18 " + //
+ "00 01 AA BB CC DD " + // IPv4
+ "00 02 11 22 33 44 11 22 33 44 11 22 33 44"));
+ }
+
+ @Test(expected = LispSerializationException.class)
+ public void deserialize__ShorterBuffer2() throws Exception {
+ LispAddressSerializer.getInstance().deserializeRloc(hexToByteBuffer("40 03 00 00 " + //
+ "01 00 00 18 "));
+ }
+
+ @Test
+ public void serialize__Simple() throws Exception {
+ AfiListBuilder listBuilder = new AfiListBuilder();
+ List<SimpleAddress> addressList = new ArrayList<SimpleAddress>();
+ addressList.add(SimpleAddressBuilder.getDefaultInstance("170.187.204.221"));
+ addressList.add(SimpleAddressBuilder.getDefaultInstance("1122:3344:1122:3344:1122:3344:1122:3344"));
+ listBuilder.setAddressList(addressList);
+
+ RlocBuilder rb = new RlocBuilder();
+ rb.setAddressType(AfiListLcaf.class);
+ rb.setVirtualNetworkId(null);
+ rb.setAddress((Address)
+ new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.AfiListBuilder()
+ .setAfiList(listBuilder.build()).build());
+
+ ByteBuffer buf = ByteBuffer.allocate(LispAddressSerializer.getInstance().getAddressSize(rb.build()));
+ LispAddressSerializer.getInstance().serialize(buf, rb.build());
+ ByteBuffer expectedBuf = hexToByteBuffer("40 03 00 00 " + //
+ "01 00 00 18 " + //
+ "00 01 AA BB CC DD " + // IPv4
+ "00 02 11 22 33 44 11 22 33 44 11 22 33 44 11 22 33 44");
+ ArrayAssert.assertEquals(expectedBuf.array(), buf.array());
+ }
+
+ @Test
+ public void serialize__NoAddresses() throws Exception {
+ AfiListBuilder listBuilder = new AfiListBuilder();
+ List<SimpleAddress> addressList = new ArrayList<SimpleAddress>();
+ listBuilder.setAddressList(addressList);
+
+ RlocBuilder rb = new RlocBuilder();
+ rb.setAddressType(AfiListLcaf.class);
+ rb.setVirtualNetworkId(null);
+ rb.setAddress((Address)
+ new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.AfiListBuilder()
+ .setAfiList(listBuilder.build()).build());
+
+ ByteBuffer buf = ByteBuffer.allocate(LispAddressSerializer.getInstance().getAddressSize(rb.build()));
+ LispAddressSerializer.getInstance().serialize(buf, rb.build());
+ ByteBuffer expectedBuf = hexToByteBuffer("40 03 00 00 " + //
+ "01 00 00 00");
+ ArrayAssert.assertEquals(expectedBuf.array(), buf.array());
+ }
+
+ @Test
+ public void equals__Simple() throws Exception {
+ SimpleAddress ip1 = SimpleAddressBuilder.getDefaultInstance("0:0:0:0:0:0:0:1");
+ SimpleAddress ip2 = SimpleAddressBuilder.getDefaultInstance("0:0:0:0:0:0:0:2");
+
+ AfiListBuilder listBuilder = new AfiListBuilder().setAddressList(new ArrayList<SimpleAddress>());
+
+ listBuilder.getAddressList().add(ip1);
+ org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.afi.list.AfiList address1 = listBuilder.build();
+ listBuilder.setAddressList(new ArrayList<SimpleAddress>());
+ listBuilder.getAddressList().add(ip1);
+ org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.afi.list.AfiList address2 = listBuilder.build();
+ listBuilder.setAddressList(new ArrayList<SimpleAddress>());
+ listBuilder.getAddressList().add(ip2);
+ org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.afi.list.AfiList address3 = listBuilder.build();
+
+ assertEquals(address1, address2);
+ Assert.assertNotEquals(address2, address3);
+ Assert.assertNotEquals(address1, address3);
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2014 Contextream, 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.serializer.address;
+
+import static org.junit.Assert.assertEquals;
+
+import java.nio.ByteBuffer;
+
+import junitx.framework.ArrayAssert;
+
+import org.junit.Test;
+import org.opendaylight.lispflowmapping.lisp.serializer.address.LispAddressSerializer;
+import org.opendaylight.lispflowmapping.lisp.serializer.exception.LispSerializationException;
+import org.opendaylight.lispflowmapping.lisp.util.ByteUtil;
+import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.ApplicationDataLcaf;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SimpleAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.ApplicationData;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.application.data.ApplicationDataBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.EidBuilder;
+
+public class ApplicationDataSerializerTest extends BaseTestCase {
+
+ @Test
+ public void deserialize__Simple() throws Exception {
+ Eid address = LispAddressSerializer.getInstance().deserializeEid(hexToByteBuffer("40 03 00 00 " + //
+ "04 20 00 0E " + //
+ "AA BB CC DD " + // IPTOS & protocol
+ "A6 A1 A6 A2 " + // local port range
+ "FF DD FF DE " + // remote port range
+ "00 01 11 22 33 44"), null); // AFI=1, IP=0x11223344
+
+ assertEquals(ApplicationDataLcaf.class, address.getAddressType());
+ ApplicationData appAddress = (ApplicationData) address.getAddress();
+
+ assertEquals("17.34.51.68", String.valueOf(appAddress.getApplicationData().getAddress().getValue()));
+ assertEquals(ByteUtil.getPartialInt(new byte[] { (byte) 0xAA, (byte) 0xBB, (byte) 0xCC }),
+ appAddress.getApplicationData().getIpTos().intValue());
+ assertEquals((byte) 0xDD, appAddress.getApplicationData().getProtocol().byteValue());
+ assertEquals((short) 0xA6A1, appAddress.getApplicationData().getLocalPortLow().getValue().shortValue());
+ assertEquals((short) 0xA6A2, appAddress.getApplicationData().getLocalPortHigh().getValue().shortValue());
+ assertEquals((short) 0xFFDD, appAddress.getApplicationData().getRemotePortLow().getValue().shortValue());
+ assertEquals((short) 0xFFDE, appAddress.getApplicationData().getRemotePortHigh().getValue().shortValue());
+ }
+
+ @Test(expected = LispSerializationException.class)
+ public void deserialize__ShorterBuffer() throws Exception {
+ LispAddressSerializer.getInstance().deserializeEid(hexToByteBuffer("40 03 00 00 " + //
+ "04 20 00 0A " + //
+ "AA BB "), null);
+ }
+
+ @Test(expected = LispSerializationException.class)
+ public void deserialize__UnknownLCAFType() throws Exception {
+ LispAddressSerializer.getInstance().deserializeEid(hexToByteBuffer("40 03 00 00 " + //
+ "AA 20 00 12 " + // Type AA is unknown
+ "AA BB CC DD " + // IPTOS & protocol
+ "A6 A1 A6 A2 " + // local port range
+ "FF DD FF DE " + // remote port range
+ "00 01 11 22 33 44"), null); // AFI=1, IP=0x11223344
+ }
+
+ @Test
+ public void deserialize__Ipv6() throws Exception {
+ Eid appAddress = LispAddressSerializer.getInstance().deserializeEid(
+ hexToByteBuffer("40 03 00 00 " + //
+ "04 20 00 1E " + //
+ "AA BB CC DD " + // IPTOS & protocol
+ "A6 A1 A6 A2 " + // local port range
+ "FF DD FF DE " + // remote port range
+ "00 02 11 22 33 44 55 66 77 88 99 AA BB CC AA BB CC DD"), null); // AFI=2,
+ // IPv6
+
+ assertEquals("1122:3344:5566:7788:99aa:bbcc:aabb:ccdd", String.valueOf(
+ ((ApplicationData) appAddress.getAddress()).getApplicationData().getAddress().getValue()));
+ }
+
+ @Test
+ public void serialize__Simple() throws Exception {
+ ApplicationDataBuilder addressBuilder = new ApplicationDataBuilder();
+ addressBuilder.setIpTos(ByteUtil.getPartialInt(new byte[] { (byte) 0xAA, (byte) 0xBB, (byte) 0xCC }));
+ addressBuilder.setProtocol((short) 0xDD);
+ addressBuilder.setLocalPortLow(new PortNumber(0xA6A1));
+ addressBuilder.setLocalPortHigh(new PortNumber(0xA6A2));
+ addressBuilder.setRemotePortLow(new PortNumber(0xFFDD));
+ addressBuilder.setRemotePortHigh(new PortNumber(0xFFDE));
+ addressBuilder.setAddress(new SimpleAddress(new IpAddress(new Ipv4Address("17.34.51.68"))));
+
+ EidBuilder eb = new EidBuilder();
+ eb.setAddressType(ApplicationDataLcaf.class);
+ eb.setVirtualNetworkId(null);
+ eb.setAddress((Address)
+ new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.ApplicationDataBuilder()
+ .setApplicationData(addressBuilder.build()).build());
+
+ ByteBuffer buf = ByteBuffer.allocate(LispAddressSerializer.getInstance().getAddressSize(eb.build()));
+ LispAddressSerializer.getInstance().serialize(buf, eb.build());
+ ByteBuffer expectedBuf = hexToByteBuffer("40 03 00 00 " + //
+ "04 00 00 12 " + //
+ "AA BB CC DD " + // IPTOS & protocol
+ "A6 A1 A6 A2 " + // local port range
+ "FF DD FF DE " + // remote port range
+ "00 01 11 22 33 44"); // AFI=1, IP=0x11223344
+ ArrayAssert.assertEquals(expectedBuf.array(), buf.array());
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2014 Contextream, 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.serializer.address;
+
+import static org.junit.Assert.assertEquals;
+
+import java.nio.ByteBuffer;
+
+import junitx.framework.ArrayAssert;
+
+import org.junit.Test;
+import org.opendaylight.lispflowmapping.lisp.serializer.address.LispAddressSerializer;
+import org.opendaylight.lispflowmapping.lisp.serializer.exception.LispSerializationException;
+import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.AfiListLcaf;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.DistinguishedNameAfi;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.DistinguishedNameType;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.AfiList;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.DistinguishedName;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.DistinguishedNameBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.EidBuilder;
+
+public class DistinguishedNameSerializerTest extends BaseTestCase {
+
+ @Test
+ public void deserialize__EmptyString() throws Exception {
+ Eid address = LispAddressSerializer.getInstance().deserializeEid(hexToByteBuffer("00 11 00"), null);
+
+ assertEquals(DistinguishedNameAfi.class, address.getAddressType());
+ DistinguishedName distinguishedName = (DistinguishedName) address.getAddress();
+
+ assertEquals("", distinguishedName.getDistinguishedName().getValue());
+
+ }
+
+ @Test
+ public void deserialize__DavidString() throws Exception {
+ Eid address = LispAddressSerializer.getInstance().deserializeEid(hexToByteBuffer("00 11 64 61 76 69 64 00"),
+ null);
+
+ assertEquals(DistinguishedNameAfi.class, address.getAddressType());
+ DistinguishedName distinguishedName = (DistinguishedName) address.getAddress();
+
+ assertEquals("david", distinguishedName.getDistinguishedName().getValue());
+
+ }
+
+ @Test
+ public void deserialize__inList() throws Exception {
+ Eid address = LispAddressSerializer.getInstance().deserializeEid(hexToByteBuffer("40 03 00 00 " + //
+ "01 00 00 8 " + //
+ "00 11 64 61 76 69 64 00"), null);
+
+ assertEquals(AfiListLcaf.class, address.getAddressType());
+ assertEquals("david", ((AfiList) address.getAddress()).getAfiList().getAddressList().get(0)
+ .getDistinguishedNameType().getValue());
+
+ }
+
+ @Test(expected = LispSerializationException.class)
+ public void deserialize__ShorterBuffer() throws Exception {
+ LispAddressSerializer.getInstance().deserializeEid(hexToByteBuffer("40 03 00 00 " + //
+ "01 00 00 10 " + //
+ "00 11 64 61 76 69 64 00"), null);
+ }
+
+ @Test(expected = LispSerializationException.class)
+ public void deserialize__ShorterBuffer2() throws Exception {
+ LispAddressSerializer.getInstance().deserializeEid(hexToByteBuffer("40 03 00 00 " + //
+ "01 00 00 18 "), null);
+ }
+
+ @Test
+ public void deserialize__ReadUntilZero() throws Exception {
+ Eid address = LispAddressSerializer.getInstance().deserializeEid(hexToByteBuffer("00 11 64 61 76 00 69 64"),
+ null);
+
+ DistinguishedName distinguishedName = (DistinguishedName) address.getAddress();
+
+ assertEquals("dav", distinguishedName.getDistinguishedName().getValue());
+ }
+
+ @Test
+ public void serialize__Simple() throws Exception {
+ EidBuilder eb = new EidBuilder();
+ eb.setAddressType(DistinguishedNameAfi.class);
+ eb.setVirtualNetworkId(null);
+ eb.setAddress(new DistinguishedNameBuilder().setDistinguishedName(new DistinguishedNameType("david")).build());
+
+ ByteBuffer buf = ByteBuffer.allocate(LispAddressSerializer.getInstance().getAddressSize(eb.build()));
+ LispAddressSerializer.getInstance().serialize(buf, eb.build());
+ ByteBuffer expectedBuf = hexToByteBuffer("00 11 64 61 76 69 64 00");
+ ArrayAssert.assertEquals(expectedBuf.array(), buf.array());
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2014 Contextream, 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.serializer.address;
+
+import static org.junit.Assert.assertEquals;
+
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.List;
+
+import junitx.framework.ArrayAssert;
+
+import org.junit.Test;
+import org.opendaylight.lispflowmapping.lisp.serializer.address.LispAddressSerializer;
+import org.opendaylight.lispflowmapping.lisp.serializer.exception.LispSerializationException;
+import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.ExplicitLocatorPathLcaf;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SimpleAddressBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.ExplicitLocatorPath;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.explicit.locator.path.ExplicitLocatorPathBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.explicit.locator.path.explicit.locator.path.Hop;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.explicit.locator.path.explicit.locator.path.HopBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.Rloc;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.RlocBuilder;
+
+public class ExplicitLocatorPathSerializerTest extends BaseTestCase {
+
+ @Test
+ public void deserialize__Simple() throws Exception {
+ Rloc address = LispAddressSerializer.getInstance().deserializeRloc(hexToByteBuffer("40 03 00 00 " + //
+ "0A 00 00 10 " + //
+ "00 00 00 01 AA BB CC DD " + // IPv4
+ "00 00 00 01 11 22 33 44")); // IPv4
+
+ assertEquals(ExplicitLocatorPathLcaf.class, address.getAddressType());
+ ExplicitLocatorPath elp = (ExplicitLocatorPath) address.getAddress();
+
+ List<Hop> hops = elp.getExplicitLocatorPath().getHop();
+ assertEquals(2, hops.size());
+
+ assertEquals("170.187.204.221", String.valueOf(hops.get(0).getAddress().getValue()));
+ assertEquals("17.34.51.68", String.valueOf(hops.get(1).getAddress().getValue()));
+ }
+
+ @Test
+ public void deserialize__Bits() throws Exception {
+ Rloc address = LispAddressSerializer.getInstance().deserializeRloc(hexToByteBuffer("40 03 00 00 " + //
+ "0A 00 00 10 " + //
+ "00 05 00 01 AA BB CC DD " + // IPv4
+ "00 02 00 01 11 22 33 44")); // IPv4
+
+ assertEquals(ExplicitLocatorPathLcaf.class, address.getAddressType());
+ ExplicitLocatorPath elp = (ExplicitLocatorPath) address.getAddress();
+
+ List<Hop> hops = elp.getExplicitLocatorPath().getHop();
+ assertEquals(2, hops.size());
+
+ assertEquals("170.187.204.221", String.valueOf(hops.get(0).getAddress().getValue()));
+ assertEquals(true, hops.get(0).getLrsBits().isLookup().booleanValue());
+ assertEquals(false, hops.get(0).getLrsBits().isRlocProbe().booleanValue());
+ assertEquals(true, hops.get(0).getLrsBits().isStrict().booleanValue());
+ assertEquals("17.34.51.68", String.valueOf(hops.get(1).getAddress().getValue()));
+ assertEquals(false, hops.get(1).getLrsBits().isLookup().booleanValue());
+ assertEquals(true, hops.get(1).getLrsBits().isRlocProbe().booleanValue());
+ assertEquals(false, hops.get(1).getLrsBits().isStrict().booleanValue());
+ }
+
+ @Test
+ public void deserialize__NoAddresses() throws Exception {
+ Rloc address = LispAddressSerializer.getInstance().deserializeRloc(hexToByteBuffer("40 03 00 00 " + //
+ "0A 00 00 00 "));
+
+ assertEquals(ExplicitLocatorPathLcaf.class, address.getAddressType());
+ ExplicitLocatorPath elp = (ExplicitLocatorPath) address.getAddress();
+
+ List<Hop> hops = elp.getExplicitLocatorPath().getHop();
+ assertEquals(0, hops.size());
+ }
+
+ @Test(expected = LispSerializationException.class)
+ public void deserialize__ShorterBuffer() throws Exception {
+ LispAddressSerializer.getInstance().deserializeRloc(hexToByteBuffer("40 03 00 00 " + //
+ "0A 00 00 18 " + //
+ "00 01 AA BB CC DD " + // IPv4
+ "00 02 11 22 33 44 11 22 33 44 11 22 33 44"));
+ }
+
+ @Test(expected = LispSerializationException.class)
+ public void deserialize__ShorterBuffer2() throws Exception {
+ LispAddressSerializer.getInstance().deserializeRloc(hexToByteBuffer("40 03 00 00 " + //
+ "0A 00 00 18 "));
+ }
+
+ @Test
+ public void serialize__Simple() throws Exception {
+ List<Hop> hops = new ArrayList<Hop>();
+ hops.add(new HopBuilder().setAddress(SimpleAddressBuilder.getDefaultInstance("170.187.204.221")).build());
+ hops.add(new HopBuilder().setAddress(SimpleAddressBuilder.getDefaultInstance("17.34.51.68")).build());
+
+ ExplicitLocatorPathBuilder elpb = new ExplicitLocatorPathBuilder();
+ elpb.setHop(hops);
+
+ RlocBuilder rb = new RlocBuilder();
+ rb.setAddressType(ExplicitLocatorPathLcaf.class);
+ rb.setVirtualNetworkId(null);
+ rb.setAddress((Address)
+ new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.ExplicitLocatorPathBuilder()
+ .setExplicitLocatorPath(elpb.build()).build());
+
+ ByteBuffer buf = ByteBuffer.allocate(LispAddressSerializer.getInstance().getAddressSize(rb.build()));
+ LispAddressSerializer.getInstance().serialize(buf, rb.build());
+ ByteBuffer expectedBuf = hexToByteBuffer("40 03 00 00 " + //
+ "0A 00 00 10 " + //
+ "00 00 00 01 AA BB CC DD " + // IPv4
+ "00 00 00 01 11 22 33 44"); // IPv4
+ ArrayAssert.assertEquals(expectedBuf.array(), buf.array());
+ }
+
+ @Test
+ public void serialize__NoAddresses() throws Exception {
+ RlocBuilder rb = new RlocBuilder();
+ rb.setAddressType(ExplicitLocatorPathLcaf.class);
+ rb.setVirtualNetworkId(null);
+ rb.setAddress((Address)
+ new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.ExplicitLocatorPathBuilder().build());
+
+ ByteBuffer buf = ByteBuffer.allocate(LispAddressSerializer.getInstance().getAddressSize(rb.build()));
+ LispAddressSerializer.getInstance().serialize(buf, rb.build());
+ ByteBuffer expectedBuf = hexToByteBuffer("40 03 00 00 " + //
+ "0A 00 00 00");
+ ArrayAssert.assertEquals(expectedBuf.array(), buf.array());
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2014 Contextream, 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.serializer.address;
+
+import static org.junit.Assert.assertEquals;
+
+import java.nio.ByteBuffer;
+
+import junitx.framework.ArrayAssert;
+
+import org.junit.Test;
+import org.opendaylight.lispflowmapping.lisp.serializer.address.LispAddressSerializer;
+import org.opendaylight.lispflowmapping.lisp.serializer.address.LispAddressSerializerContext;
+import org.opendaylight.lispflowmapping.lisp.serializer.exception.LispSerializationException;
+import org.opendaylight.lispflowmapping.lisp.util.LispAddressUtil;
+import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv4Afi;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
+
+public class InstanceIdSerializerTest extends BaseTestCase {
+
+ @Test
+ public void deserialize__Simple() throws Exception {
+ Eid address = LispAddressSerializer.getInstance().deserializeEid(hexToByteBuffer("40 03 00 00 " + //
+ "02 20 00 0A " + //
+ "00 BB CC DD " + // instance ID
+ "00 01 11 22 33 44"), // AFI=1, IP=0x11223344
+ new LispAddressSerializerContext(null));
+
+ assertEquals(Ipv4Afi.class, address.getAddressType());
+ Ipv4 ipv4 = (Ipv4) address.getAddress();
+
+ assertEquals("17.34.51.68", ipv4.getIpv4().getValue());
+ assertEquals(0x00BBCCDD, address.getVirtualNetworkId().getValue().longValue());
+ }
+
+ @Test(expected = LispSerializationException.class)
+ public void deserialize__ShorterBuffer() throws Exception {
+ LispAddressSerializer.getInstance().deserializeEid(hexToByteBuffer("40 03 00 00 " + //
+ "02 20 00 0A " + //
+ "AA BB "),
+ new LispAddressSerializerContext(null));
+ }
+
+ @Test(expected = LispSerializationException.class)
+ public void deserialize__UnknownLCAFType() throws Exception {
+ LispAddressSerializer.getInstance().deserializeEid(hexToByteBuffer("40 03 00 00 " + //
+ "AA 20 00 0A " + // Type AA is unknown
+ "00 BB CC DD " + // instance ID
+ "00 01 11 22 33 44"), // AFI=1, IP=0x11223344
+ new LispAddressSerializerContext(null));
+ }
+
+ @Test(expected = LispSerializationException.class)
+ public void deserialize__LongInstanceID() throws Exception {
+ LispAddressSerializer.getInstance().deserializeEid(hexToByteBuffer("40 03 00 00 " + //
+ "02 20 00 0A " + // Type AA is unknown
+ "AA BB CC DD " + // instance ID
+ "00 01 11 22 33 44"), // AFI=1, IP=0x11223344
+ new LispAddressSerializerContext(null));
+ }
+
+ @Test
+ public void deserialize__Ipv6() throws Exception {
+ Eid address = LispAddressSerializer.getInstance().deserializeEid(hexToByteBuffer("40 03 00 00 " + //
+ "02 20 00 0A " + //
+ "00 BB CC DD " + // instance ID
+ "00 02 11 22 33 44 55 66 77 88 99 AA BB CC AA BB CC DD"), // AFI=2,
+ new LispAddressSerializerContext(null));
+ // IPv6
+
+ assertEquals("1122:3344:5566:7788:99aa:bbcc:aabb:ccdd", ((Ipv6) address.getAddress()).getIpv6().getValue());
+
+ }
+
+ @Test
+ public void serialize__Simple() throws Exception {
+ Eid eid = LispAddressUtil.asIpv4Eid("17.34.51.68", (long) 0x00020304);
+
+ ByteBuffer buf = ByteBuffer.allocate(LispAddressSerializer.getInstance().getAddressSize(eid));
+ LispAddressSerializer.getInstance().serialize(buf, eid);
+ ByteBuffer expectedBuf = hexToByteBuffer("40 03 00 00 " + //
+ "02 00 00 0A " + //
+ "00 02 03 04 " + // instance ID
+ "00 01 11 22 33 44");
+ ArrayAssert.assertEquals(expectedBuf.array(), buf.array());
+ }
+}
import org.junit.Test;
import org.opendaylight.lispflowmapping.lisp.serializer.address.LispAddressSerializer;
-import org.opendaylight.lispflowmapping.lisp.type.AddressFamilyNumberEnum;
-import org.opendaylight.lispflowmapping.lisp.util.LispAFIConvertor;
+import org.opendaylight.lispflowmapping.lisp.util.LispAddressUtil;
import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.ipv6.Ipv6Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv6Afi;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.Rloc;
-public class LispIpv6AddressTest extends BaseTestCase {
+public class Ipv6SerializerTest extends BaseTestCase {
@Test
public void constructor__Name() throws Exception {
- Ipv6Address ip = (Ipv6Address) LispAFIConvertor.asIPv6AfiAddress("0:0:0:0:0:0:0:0");
+ Rloc rloc = LispAddressUtil.asIpv6Rloc("0:0:0:0:0:0:0:0");
- assertEquals(AddressFamilyNumberEnum.IP6.getIanaCode(), ip.getAfi().shortValue());
- assertEquals(18, LispAddressSerializer.getInstance().getAddressSize(ip));
- assertEquals("0:0:0:0:0:0:0:0", ip.getIpv6Address().getValue());
+ assertEquals(Ipv6Afi.class, rloc.getAddressType());
+ assertEquals(18, LispAddressSerializer.getInstance().getAddressSize(rloc));
+ assertEquals("0:0:0:0:0:0:0:0", ((Ipv6) rloc.getAddress()).getIpv6().getValue());
}
@Test
public void constructor__Buffer() throws Exception {
- Ipv6Address ip = (Ipv6Address) LispAFIConvertor.asIPv6AfiAddress("0:0:0:0:0:0:0:1");
+ Rloc rloc = LispAddressUtil.asIpv6Rloc("0:0:0:0:0:0:0:1");
- assertEquals(AddressFamilyNumberEnum.IP6.getIanaCode(), ip.getAfi().shortValue());
- assertEquals(18, LispAddressSerializer.getInstance().getAddressSize(ip));
- assertEquals("0:0:0:0:0:0:0:1", ip.getIpv6Address().getValue());
+ assertEquals(Ipv6Afi.class, rloc.getAddressType());
+ assertEquals(18, LispAddressSerializer.getInstance().getAddressSize(rloc));
+ assertEquals("0:0:0:0:0:0:0:1", ((Ipv6) rloc.getAddress()).getIpv6().getValue());
}
}
--- /dev/null
+/*
+ * Copyright (c) 2014 Contextream, 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.serializer.address;
+
+import static org.junit.Assert.assertEquals;
+
+import java.nio.ByteBuffer;
+
+import junitx.framework.ArrayAssert;
+
+import org.junit.Test;
+import org.opendaylight.lispflowmapping.lisp.serializer.address.LispAddressSerializer;
+import org.opendaylight.lispflowmapping.lisp.serializer.exception.LispSerializationException;
+import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.KeyValueAddressLcaf;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SimpleAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.KeyValueAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.key.value.address.KeyValueAddressBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.EidBuilder;
+
+public class KeyValueAddressSerializerTest extends BaseTestCase {
+
+ @Test
+ public void deserialize__Simple() throws Exception {
+ Eid address = LispAddressSerializer.getInstance().deserializeEid(hexToByteBuffer("40 03 00 00 " + //
+ "0F 20 00 0C " + //
+ "00 01 11 22 33 44 " + // AFI=1, IP=0x11223344
+ "00 01 22 33 44 55"), null); // AFI=1, IP=0x22334455
+
+ assertEquals(KeyValueAddressLcaf.class, address.getAddressType());
+ KeyValueAddress srcDestAddress = (KeyValueAddress) address.getAddress();
+
+ assertEquals("17.34.51.68", String.valueOf(srcDestAddress.getKeyValueAddress().getKey().getValue()));
+ assertEquals("34.51.68.85", String.valueOf(srcDestAddress.getKeyValueAddress().getValue().getValue()));
+ }
+
+ @Test(expected = LispSerializationException.class)
+ public void deserialize__ShorterBuffer() throws Exception {
+ LispAddressSerializer.getInstance().deserializeEid(hexToByteBuffer("40 03 00 00 " + //
+ "02 20 00 0A " + //
+ "AA BB "), null);
+ }
+
+ @Test(expected = LispSerializationException.class)
+ public void deserialize__UnknownLCAFType() throws Exception {
+ LispAddressSerializer.getInstance().deserializeEid(hexToByteBuffer("40 03 00 00 " + //
+ "AA 20 00 0A " + // Type AA is unknown
+ "00 01 11 22 33 44 " + // AFI=1, IP=0x11223344
+ "00 01 22 33 44 55"), null); // AFI=1, IP=0x22334455
+ }
+
+ @Test
+ public void deserialize__Ipv6() throws Exception {
+ Eid srcAddress = LispAddressSerializer.getInstance().deserializeEid(hexToByteBuffer("40 03 00 00 " + //
+ "0F 20 00 24 " + //
+ "00 02 11 22 33 44 55 66 77 88 99 AA BB CC AA BB CC DD " + // AFI=2,
+ "00 02 44 33 22 11 88 77 66 55 99 AA BB CC AA BB CC DD"), null); // AFI=2,
+ // IPv6
+
+ assertEquals("1122:3344:5566:7788:99aa:bbcc:aabb:ccdd", String.valueOf(
+ ((KeyValueAddress) srcAddress.getAddress()).getKeyValueAddress().getKey().getValue()));
+ assertEquals("4433:2211:8877:6655:99aa:bbcc:aabb:ccdd", String.valueOf(
+ ((KeyValueAddress) srcAddress.getAddress()).getKeyValueAddress().getValue().getValue()));
+ }
+
+ @Test
+ public void serialize__Simple() throws Exception {
+ KeyValueAddressBuilder addressBuilder = new KeyValueAddressBuilder();
+ addressBuilder.setKey(new SimpleAddress(new IpAddress(new Ipv4Address("17.34.51.68"))));
+ addressBuilder.setValue(new SimpleAddress(new IpAddress(new Ipv4Address("34.51.68.85"))));
+
+ EidBuilder eb = new EidBuilder();
+ eb.setAddressType(KeyValueAddressLcaf.class);
+ eb.setVirtualNetworkId(null);
+ eb.setAddress((Address)
+ new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.KeyValueAddressBuilder()
+ .setKeyValueAddress(addressBuilder.build()).build());
+
+ ByteBuffer buf = ByteBuffer.allocate(LispAddressSerializer.getInstance().getAddressSize(eb.build()));
+ LispAddressSerializer.getInstance().serialize(buf, eb.build());
+
+ ByteBuffer expectedBuf = hexToByteBuffer("40 03 00 00 " + //
+ "0F 00 00 0C " + //
+ "00 01 11 22 33 44 " + // AFI=1, IP=0x11223344
+ "00 01 22 33 44 55"); // AFI=1, IP=0x22334455
+ ArrayAssert.assertEquals(expectedBuf.array(), buf.array());
+ }
+}
+++ /dev/null
-/*
- * Copyright (c) 2014 Contextream, 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.serializer.address;
-
-import static org.junit.Assert.assertEquals;
-
-import java.nio.ByteBuffer;
-
-import junitx.framework.ArrayAssert;
-
-import org.junit.Test;
-import org.opendaylight.lispflowmapping.lisp.serializer.address.LispAddressSerializer;
-import org.opendaylight.lispflowmapping.lisp.serializer.exception.LispSerializationException;
-import org.opendaylight.lispflowmapping.lisp.type.AddressFamilyNumberEnum;
-import org.opendaylight.lispflowmapping.lisp.type.LispCanonicalAddressFormatEnum;
-import org.opendaylight.lispflowmapping.lisp.util.ByteUtil;
-import org.opendaylight.lispflowmapping.lisp.util.LispAFIConvertor;
-import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.LcafApplicationDataAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.LispAFIAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lcafapplicationdataaddress.AddressBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.lcafapplicationdata.LcafApplicationDataAddrBuilder;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
-
-public class LispApplicationDataLCAFAddressTest extends BaseTestCase {
-
- @Test
- public void deserialize__Simple() throws Exception {
- LispAFIAddress address = LispAddressSerializer.getInstance().deserialize(hexToByteBuffer("40 03 00 00 " + //
- "04 20 00 0E " + //
- "AA BB CC DD " + // IPTOS & protocol
- "A6 A1 A6 A2 " + // local port range
- "FF DD FF DE " + // remote port range
- "00 01 11 22 33 44")); // AFI=1, IP=0x11223344
-
- assertEquals(AddressFamilyNumberEnum.LCAF.getIanaCode(), address.getAfi().shortValue());
- LcafApplicationDataAddress appAddress = (LcafApplicationDataAddress) address;
-
- assertEquals(LispAFIConvertor.asPrimitiveIPAfiAddress("17.34.51.68"), appAddress.getAddress().getPrimitiveAddress());
- assertEquals(ByteUtil.getPartialInt(new byte[] { (byte) 0xAA, (byte) 0xBB, (byte) 0xCC }), appAddress.getIpTos().intValue());
- assertEquals((byte) 0xDD, appAddress.getProtocol().byteValue());
- assertEquals((short) 0xA6A1, appAddress.getLocalPortLow().getValue().shortValue());
- assertEquals((short) 0xA6A2, appAddress.getLocalPortHigh().getValue().shortValue());
- assertEquals((short) 0xFFDD, appAddress.getRemotePortLow().getValue().shortValue());
- assertEquals((short) 0xFFDE, appAddress.getRemotePortHigh().getValue().shortValue());
- assertEquals(LispCanonicalAddressFormatEnum.APPLICATION_DATA.getLispCode(), appAddress.getLcafType().byteValue());
- }
-
- @Test(expected = LispSerializationException.class)
- public void deserialize__ShorterBuffer() throws Exception {
- LispAddressSerializer.getInstance().deserialize(hexToByteBuffer("40 03 00 00 " + //
- "04 20 00 0A " + //
- "AA BB "));
- }
-
- @Test(expected = LispSerializationException.class)
- public void deserialize__UnknownLCAFType() throws Exception {
- LispAddressSerializer.getInstance().deserialize(hexToByteBuffer("40 03 00 00 " + //
- "AA 20 00 12 " + // Type AA is unknown
- "AA BB CC DD " + // IPTOS & protocol
- "A6 A1 A6 A2 " + // local port range
- "FF DD FF DE " + // remote port range
- "00 01 11 22 33 44")); // AFI=1, IP=0x11223344
- }
-
- @Test
- public void deserialize__Ipv6() throws Exception {
- LcafApplicationDataAddress appAddress = (LcafApplicationDataAddress) LispAddressSerializer.getInstance().deserialize(
- hexToByteBuffer("40 03 00 00 " + //
- "04 20 00 1E " + //
- "AA BB CC DD " + // IPTOS & protocol
- "A6 A1 A6 A2 " + // local port range
- "FF DD FF DE " + // remote port range
- "00 02 11 22 33 44 55 66 77 88 99 AA BB CC AA BB CC DD")); // AFI=2,
- // IPv6
-
- assertEquals(LispAFIConvertor.toPrimitive(LispAFIConvertor.asIPv6AfiAddress("1122:3344:5566:7788:99aa:bbcc:aabb:ccdd")), appAddress
- .getAddress().getPrimitiveAddress());
-
- }
-
- @Test
- public void serialize__Simple() throws Exception {
- LcafApplicationDataAddrBuilder addressBuilder = new LcafApplicationDataAddrBuilder();
- addressBuilder.setIpTos(ByteUtil.getPartialInt(new byte[] { (byte) 0xAA, (byte) 0xBB, (byte) 0xCC }));
- addressBuilder.setAfi(AddressFamilyNumberEnum.LCAF.getIanaCode()).setLcafType(
- (short) LispCanonicalAddressFormatEnum.APPLICATION_DATA.getLispCode());
- addressBuilder.setProtocol((short) 0xDD);
- addressBuilder.setLocalPortLow(new PortNumber(0xA6A1));
- addressBuilder.setLocalPortHigh(new PortNumber(0xA6A2));
- addressBuilder.setRemotePortLow(new PortNumber(0xFFDD));
- addressBuilder.setRemotePortHigh(new PortNumber(0xFFDE));
- addressBuilder.setAddress(new AddressBuilder().setPrimitiveAddress(LispAFIConvertor.asPrimitiveIPAfiAddress("17.34.51.68")).build());
- ByteBuffer buf = ByteBuffer.allocate(LispAddressSerializer.getInstance().getAddressSize(addressBuilder.build()));
- LispAddressSerializer.getInstance().serialize(buf, addressBuilder.build());
- ByteBuffer expectedBuf = hexToByteBuffer("40 03 00 00 " + //
- "04 00 00 12 " + //
- "AA BB CC DD " + // IPTOS & protocol
- "A6 A1 A6 A2 " + // local port range
- "FF DD FF DE " + // remote port range
- "00 01 11 22 33 44"); // AFI=1, IP=0x11223344
- ArrayAssert.assertEquals(expectedBuf.array(), buf.array());
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 Contextream, 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.serializer.address;
-
-import static org.junit.Assert.assertEquals;
-
-import java.nio.ByteBuffer;
-
-import junitx.framework.ArrayAssert;
-
-import org.junit.Test;
-import org.opendaylight.lispflowmapping.lisp.serializer.address.LispAddressSerializer;
-import org.opendaylight.lispflowmapping.lisp.serializer.exception.LispSerializationException;
-import org.opendaylight.lispflowmapping.lisp.type.AddressFamilyNumberEnum;
-import org.opendaylight.lispflowmapping.lisp.type.LispCanonicalAddressFormatEnum;
-import org.opendaylight.lispflowmapping.lisp.util.LispAFIConvertor;
-import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.LcafListAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.LispAFIAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.LispDistinguishedNameAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.distinguishedname.DistinguishedNameBuilder;
-
-public class LispDistinguishedNameAddressSerializerTest extends BaseTestCase {
-
- @Test
- public void deserialize__EmptyString() throws Exception {
- LispAFIAddress address = LispAddressSerializer.getInstance().deserialize(hexToByteBuffer("00 11 00"));
-
- assertEquals(AddressFamilyNumberEnum.DISTINGUISHED_NAME.getIanaCode(), address.getAfi().shortValue());
- LispDistinguishedNameAddress distinguishedNameAddress = (LispDistinguishedNameAddress) address;
-
- assertEquals("", distinguishedNameAddress.getDistinguishedName());
-
- }
-
- @Test
- public void deserialize__DavidString() throws Exception {
- LispAFIAddress address = LispAddressSerializer.getInstance().deserialize(hexToByteBuffer("00 11 64 61 76 69 64 00"));
-
- assertEquals(AddressFamilyNumberEnum.DISTINGUISHED_NAME.getIanaCode(), address.getAfi().shortValue());
- LispDistinguishedNameAddress distinguishedNameAddress = (LispDistinguishedNameAddress) address;
-
- assertEquals("david", distinguishedNameAddress.getDistinguishedName());
-
- }
-
- @Test
- public void deserialize__inList() throws Exception {
- LispAFIAddress address = LispAddressSerializer.getInstance().deserialize(hexToByteBuffer("40 03 00 00 " + //
- "01 00 00 8 " + //
- "00 11 64 61 76 69 64 00"));
-
- assertEquals(AddressFamilyNumberEnum.LCAF.getIanaCode(), address.getAfi().shortValue());
- LcafListAddress lispLCAFAddress = (LcafListAddress) address;
-
- assertEquals(LispCanonicalAddressFormatEnum.LIST.getLispCode(), lispLCAFAddress.getLcafType().byteValue());
-
- LispDistinguishedNameAddress distinguishedNameAddress = (LispDistinguishedNameAddress) LispAFIConvertor.toAFIfromPrimitive(lispLCAFAddress.getAddresses().get(0)
- .getPrimitiveAddress());
-
- assertEquals("david", distinguishedNameAddress.getDistinguishedName());
-
- }
-
- @Test(expected = LispSerializationException.class)
- public void deserialize__ShorterBuffer() throws Exception {
- LispAddressSerializer.getInstance().deserialize(hexToByteBuffer("40 03 00 00 " + //
- "01 00 00 10 " + //
- "00 11 64 61 76 69 64 00"));
- }
-
- @Test(expected = LispSerializationException.class)
- public void deserialize__ShorterBuffer2() throws Exception {
- LispAddressSerializer.getInstance().deserialize(hexToByteBuffer("40 03 00 00 " + //
- "01 00 00 18 "));
- }
-
- @Test
- public void deserialize__ReadUntilZero() throws Exception {
- LispDistinguishedNameAddress address = (LispDistinguishedNameAddress) LispAddressSerializer.getInstance().deserialize(
- hexToByteBuffer("00 11 64 61 76 00 69 64"));
- assertEquals("dav", address.getDistinguishedName());
- }
-
- @Test
- public void serialize__Simple() throws Exception {
- DistinguishedNameBuilder distinguishedName = new DistinguishedNameBuilder().setDistinguishedName("david").setAfi(
- AddressFamilyNumberEnum.DISTINGUISHED_NAME.getIanaCode());
-
- ByteBuffer buf = ByteBuffer.allocate(LispAddressSerializer.getInstance().getAddressSize(distinguishedName.build()));
- LispAddressSerializer.getInstance().serialize(buf, distinguishedName.build());
- ByteBuffer expectedBuf = hexToByteBuffer("00 11 64 61 76 69 64 00");
- ArrayAssert.assertEquals(expectedBuf.array(), buf.array());
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 Contextream, 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.serializer.address;
-
-import static org.junit.Assert.assertEquals;
-
-import java.nio.ByteBuffer;
-
-import junitx.framework.ArrayAssert;
-
-import org.junit.Test;
-import org.opendaylight.lispflowmapping.lisp.serializer.address.LispAddressSerializer;
-import org.opendaylight.lispflowmapping.lisp.serializer.exception.LispSerializationException;
-import org.opendaylight.lispflowmapping.lisp.type.AddressFamilyNumberEnum;
-import org.opendaylight.lispflowmapping.lisp.type.LispCanonicalAddressFormatEnum;
-import org.opendaylight.lispflowmapping.lisp.util.LispAFIConvertor;
-import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.LcafKeyValueAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.LispAFIAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lcafkeyvalueaddress.KeyBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lcafkeyvalueaddress.ValueBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.lcafkeyvalue.LcafKeyValueAddressAddrBuilder;
-
-public class LispKeyValueLCAFAddressTest extends BaseTestCase {
-
- @Test
- public void deserialize__Simple() throws Exception {
- LispAFIAddress address = LispAddressSerializer.getInstance().deserialize(hexToByteBuffer("40 03 00 00 " + //
- "0F 20 00 0C " + //
- "00 01 11 22 33 44 " + // AFI=1, IP=0x11223344
- "00 01 22 33 44 55")); // AFI=1, IP=0x22334455
-
- assertEquals(AddressFamilyNumberEnum.LCAF.getIanaCode(), address.getAfi().shortValue());
- LcafKeyValueAddress srcDestAddress = (LcafKeyValueAddress) address;
-
- assertEquals(LispAFIConvertor.asPrimitiveIPAfiAddress("17.34.51.68"), srcDestAddress.getKey().getPrimitiveAddress());
- assertEquals(LispAFIConvertor.asPrimitiveIPAfiAddress("34.51.68.85"), srcDestAddress.getValue().getPrimitiveAddress());
- assertEquals(LispCanonicalAddressFormatEnum.KEY_VALUE.getLispCode(), srcDestAddress.getLcafType().byteValue());
- }
-
- @Test(expected = LispSerializationException.class)
- public void deserialize__ShorterBuffer() throws Exception {
- LispAddressSerializer.getInstance().deserialize(hexToByteBuffer("40 03 00 00 " + //
- "02 20 00 0A " + //
- "AA BB "));
- }
-
- @Test(expected = LispSerializationException.class)
- public void deserialize__UnknownLCAFType() throws Exception {
- LispAddressSerializer.getInstance().deserialize(hexToByteBuffer("40 03 00 00 " + //
- "AA 20 00 0A " + // Type AA is unknown
- "00 01 11 22 33 44 " + // AFI=1, IP=0x11223344
- "00 01 22 33 44 55")); // AFI=1, IP=0x22334455
- }
-
- @Test
- public void deserialize__Ipv6() throws Exception {
- LcafKeyValueAddress srcAddress = (LcafKeyValueAddress) LispAddressSerializer.getInstance().deserialize(hexToByteBuffer("40 03 00 00 " + //
- "0F 20 00 24 " + //
- "00 02 11 22 33 44 55 66 77 88 99 AA BB CC AA BB CC DD " + // AFI=2,
- "00 02 44 33 22 11 88 77 66 55 99 AA BB CC AA BB CC DD")); // AFI=2,
- // IPv6
-
- assertEquals(LispAFIConvertor.toPrimitive(LispAFIConvertor.asIPv6AfiAddress("1122:3344:5566:7788:99aa:bbcc:aabb:ccdd")), srcAddress.getKey()
- .getPrimitiveAddress());
- assertEquals(LispAFIConvertor.toPrimitive(LispAFIConvertor.asIPv6AfiAddress("4433:2211:8877:6655:99aa:bbcc:aabb:ccdd")), srcAddress
- .getValue().getPrimitiveAddress());
- }
-
- @Test
- public void serialize__Simple() throws Exception {
- LcafKeyValueAddressAddrBuilder addressBuilder = new LcafKeyValueAddressAddrBuilder();
- addressBuilder.setAfi(AddressFamilyNumberEnum.LCAF.getIanaCode()).setLcafType((short) LispCanonicalAddressFormatEnum.KEY_VALUE.getLispCode());
- addressBuilder.setKey(new KeyBuilder().setPrimitiveAddress(LispAFIConvertor.asPrimitiveIPAfiAddress("17.34.51.68")).build());
- addressBuilder.setValue(new ValueBuilder().setPrimitiveAddress(LispAFIConvertor.asPrimitiveIPAfiAddress("34.51.68.85")).build());
- ByteBuffer buf = ByteBuffer.allocate(LispAddressSerializer.getInstance().getAddressSize(addressBuilder.build()));
- LispAddressSerializer.getInstance().serialize(buf, addressBuilder.build());
- ByteBuffer expectedBuf = hexToByteBuffer("40 03 00 00 " + //
- "0F 00 00 0C " + //
- "00 01 11 22 33 44 " + // AFI=1, IP=0x11223344
- "00 01 22 33 44 55"); // AFI=1, IP=0x22334455
- ArrayAssert.assertEquals(expectedBuf.array(), buf.array());
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 Contextream, 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.serializer.address;
-
-import static org.junit.Assert.assertEquals;
-
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.List;
-
-import junitx.framework.ArrayAssert;
-import junitx.framework.Assert;
-
-import org.junit.Test;
-import org.opendaylight.lispflowmapping.lisp.serializer.address.LispAddressSerializer;
-import org.opendaylight.lispflowmapping.lisp.serializer.exception.LispSerializationException;
-import org.opendaylight.lispflowmapping.lisp.type.AddressFamilyNumberEnum;
-import org.opendaylight.lispflowmapping.lisp.type.LispCanonicalAddressFormatEnum;
-import org.opendaylight.lispflowmapping.lisp.util.LispAFIConvertor;
-import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.LcafListAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.LispAFIAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lcaflistaddress.Addresses;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lcaflistaddress.AddressesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.lcaflist.LcafListAddr;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.lcaflist.LcafListAddrBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.primitiveaddress.Ipv6;
-
-public class LispListLCAFAddressTest extends BaseTestCase {
-
- @Test
- public void deserialize__Simple() throws Exception {
- LispAFIAddress address = LispAddressSerializer.getInstance().deserialize(hexToByteBuffer("40 03 00 00 " + //
- "01 00 00 18 " + //
- "00 01 AA BB CC DD " + // IPv4
- "00 02 11 22 33 44 11 22 33 44 11 22 33 44 11 22 33 44")); // IPv6
-
- assertEquals(AddressFamilyNumberEnum.LCAF.getIanaCode(), address.getAfi().shortValue());
- LcafListAddress lcafList = (LcafListAddress) address;
-
- assertEquals(LispCanonicalAddressFormatEnum.LIST.getLispCode(), lcafList.getLcafType().byteValue());
-
- List<Addresses> addressList = lcafList.getAddresses();
- assertEquals(2, addressList.size());
-
- assertEquals(LispAFIConvertor.toPrimitive(LispAFIConvertor.asIPAfiAddress("170.187.204.221")), addressList.get(0).getPrimitiveAddress());
- assertEquals(LispAFIConvertor.toPrimitive(LispAFIConvertor.asIPv6AfiAddress("1122:3344:1122:3344:1122:3344:1122:3344")), addressList.get(1)
- .getPrimitiveAddress());
- }
-
- @Test
- public void deserialize__NoAddresses() throws Exception {
- LispAFIAddress address = LispAddressSerializer.getInstance().deserialize(hexToByteBuffer("40 03 00 00 " + //
- "01 00 00 00 "));
-
- assertEquals(AddressFamilyNumberEnum.LCAF.getIanaCode(), address.getAfi().shortValue());
- LcafListAddress lcafList = (LcafListAddress) address;
-
- assertEquals(LispCanonicalAddressFormatEnum.LIST.getLispCode(), lcafList.getLcafType().byteValue());
-
- List<Addresses> addressList = lcafList.getAddresses();
- assertEquals(0, addressList.size());
- }
-
- @Test(expected = LispSerializationException.class)
- public void deserialize__ShorterBuffer() throws Exception {
- LispAddressSerializer.getInstance().deserialize(hexToByteBuffer("40 03 00 00 " + //
- "01 00 00 18 " + //
- "00 01 AA BB CC DD " + // IPv4
- "00 02 11 22 33 44 11 22 33 44 11 22 33 44"));
- }
-
- @Test(expected = LispSerializationException.class)
- public void deserialize__ShorterBuffer2() throws Exception {
- LispAddressSerializer.getInstance().deserialize(hexToByteBuffer("40 03 00 00 " + //
- "01 00 00 18 "));
- }
-
- @Test
- public void serialize__Simple() throws Exception {
- LcafListAddrBuilder listBuilder = new LcafListAddrBuilder();
- listBuilder.setAfi(AddressFamilyNumberEnum.LCAF.getIanaCode());
- listBuilder.setLcafType((short) LispCanonicalAddressFormatEnum.LIST.getLispCode());
- List<Addresses> addressList = new ArrayList<Addresses>();
- addressList.add(new AddressesBuilder().setPrimitiveAddress(LispAFIConvertor.toPrimitive(LispAFIConvertor.asIPAfiAddress("170.187.204.221")))
- .build());
- addressList.add(new AddressesBuilder().setPrimitiveAddress(
- LispAFIConvertor.toPrimitive(LispAFIConvertor.asIPv6AfiAddress("1122:3344:1122:3344:1122:3344:1122:3344"))).build());
- listBuilder.setAddresses(addressList);
- ByteBuffer buf = ByteBuffer.allocate(LispAddressSerializer.getInstance().getAddressSize(listBuilder.build()));
- LispAddressSerializer.getInstance().serialize(buf, listBuilder.build());
- ByteBuffer expectedBuf = hexToByteBuffer("40 03 00 00 " + //
- "01 00 00 18 " + //
- "00 01 AA BB CC DD " + // IPv4
- "00 02 11 22 33 44 11 22 33 44 11 22 33 44 11 22 33 44");
- ArrayAssert.assertEquals(expectedBuf.array(), buf.array());
- }
-
- @Test
- public void serialize__NoAddresses() throws Exception {
- LcafListAddrBuilder listBuilder = new LcafListAddrBuilder();
- listBuilder.setAfi(AddressFamilyNumberEnum.LCAF.getIanaCode());
- listBuilder.setLcafType((short) LispCanonicalAddressFormatEnum.LIST.getLispCode());
- List<Addresses> addressList = new ArrayList<Addresses>();
- listBuilder.setAddresses(addressList);
- ByteBuffer buf = ByteBuffer.allocate(LispAddressSerializer.getInstance().getAddressSize(listBuilder.build()));
- LispAddressSerializer.getInstance().serialize(buf, listBuilder.build());
- ByteBuffer expectedBuf = hexToByteBuffer("40 03 00 00 " + //
- "01 00 00 00");
- ArrayAssert.assertEquals(expectedBuf.array(), buf.array());
- }
-
- @Test
- public void equals__Simple() throws Exception {
- Ipv6 ip1 = (Ipv6) LispAFIConvertor.toPrimitive(LispAFIConvertor.asIPv6AfiAddress("0:0:0:0:0:0:0:1"));
- Ipv6 ip2 = (Ipv6) LispAFIConvertor.toPrimitive(LispAFIConvertor.asIPv6AfiAddress("0:0:0:0:0:0:0:2"));
- LcafListAddrBuilder listBuilder = new LcafListAddrBuilder().setAfi(AddressFamilyNumberEnum.LCAF.getIanaCode())
- .setLcafType((short) LispCanonicalAddressFormatEnum.LIST.getLispCode()).setAddresses(new ArrayList<Addresses>());
- listBuilder.getAddresses().add(new AddressesBuilder().setPrimitiveAddress(ip1).build());
- LcafListAddr address1 = listBuilder.build();
- listBuilder.setAddresses(new ArrayList<Addresses>());
- listBuilder.getAddresses().add(new AddressesBuilder().setPrimitiveAddress(ip1).build());
- LcafListAddr address2 = listBuilder.build();
- listBuilder.setAddresses(new ArrayList<Addresses>());
- listBuilder.getAddresses().add(new AddressesBuilder().setPrimitiveAddress(ip2).build());
- LcafListAddr address3 = listBuilder.build();
-
- assertEquals(address1, address2);
- Assert.assertNotEquals(address2, address3);
- Assert.assertNotEquals(address1, address3);
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 Contextream, 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.serializer.address;
-
-import static org.junit.Assert.assertEquals;
-
-import java.nio.ByteBuffer;
-
-import junitx.framework.ArrayAssert;
-
-import org.junit.Test;
-import org.opendaylight.lispflowmapping.lisp.serializer.address.LispAddressSerializer;
-import org.opendaylight.lispflowmapping.lisp.serializer.exception.LispSerializationException;
-import org.opendaylight.lispflowmapping.lisp.type.AddressFamilyNumberEnum;
-import org.opendaylight.lispflowmapping.lisp.type.LispCanonicalAddressFormatEnum;
-import org.opendaylight.lispflowmapping.lisp.util.LispAFIConvertor;
-import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.LcafSegmentAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.LispAFIAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lcafsegmentaddress.AddressBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.lcafsegment.LcafSegmentAddrBuilder;
-
-public class LispSegmentLCAFAddressTest extends BaseTestCase {
-
- @Test
- public void deserialize__Simple() throws Exception {
- LispAFIAddress address = LispAddressSerializer.getInstance().deserialize(hexToByteBuffer("40 03 00 00 " + //
- "02 20 00 0A " + //
- "00 BB CC DD " + // instance ID
- "00 01 11 22 33 44")); // AFI=1, IP=0x11223344
-
- assertEquals(AddressFamilyNumberEnum.LCAF.getIanaCode(), address.getAfi().shortValue());
- LcafSegmentAddress segAddress = (LcafSegmentAddress) address;
-
- assertEquals(LispAFIConvertor.asPrimitiveIPAfiAddress("17.34.51.68"), segAddress.getAddress().getPrimitiveAddress());
- assertEquals(0x00BBCCDD, segAddress.getInstanceId().intValue());
- assertEquals(LispCanonicalAddressFormatEnum.SEGMENT.getLispCode(), segAddress.getLcafType().byteValue());
- }
-
- @Test(expected = LispSerializationException.class)
- public void deserialize__ShorterBuffer() throws Exception {
- LispAddressSerializer.getInstance().deserialize(hexToByteBuffer("40 03 00 00 " + //
- "02 20 00 0A " + //
- "AA BB "));
- }
-
- @Test(expected = LispSerializationException.class)
- public void deserialize__UnknownLCAFType() throws Exception {
- LispAddressSerializer.getInstance().deserialize(hexToByteBuffer("40 03 00 00 " + //
- "AA 20 00 0A " + // Type AA is unknown
- "00 BB CC DD " + // instance ID
- "00 01 11 22 33 44")); // AFI=1, IP=0x11223344
- }
-
- @Test(expected = LispSerializationException.class)
- public void deserialize__LongInstanceID() throws Exception {
- LispAddressSerializer.getInstance().deserialize(hexToByteBuffer("40 03 00 00 " + //
- "02 20 00 0A " + // Type AA is unknown
- "AA BB CC DD " + // instance ID
- "00 01 11 22 33 44")); // AFI=1, IP=0x11223344
- }
-
- @Test
- public void deserialize__Ipv6() throws Exception {
- LcafSegmentAddress segAddress = (LcafSegmentAddress) LispAddressSerializer.getInstance().deserialize(hexToByteBuffer("40 03 00 00 " + //
- "02 20 00 0A " + //
- "00 BB CC DD " + // instance ID
- "00 02 11 22 33 44 55 66 77 88 99 AA BB CC AA BB CC DD")); // AFI=2,
- // IPv6
-
- assertEquals(LispAFIConvertor.toPrimitive(LispAFIConvertor.asIPv6AfiAddress("1122:3344:5566:7788:99aa:bbcc:aabb:ccdd")), segAddress
- .getAddress().getPrimitiveAddress());
-
- }
-
- @Test
- public void serialize__Simple() throws Exception {
- LcafSegmentAddrBuilder addressBuilder = new LcafSegmentAddrBuilder();
- addressBuilder.setInstanceId((long) 0x00020304);
- addressBuilder.setIidMaskLength((short) 0);
- addressBuilder.setAfi(AddressFamilyNumberEnum.LCAF.getIanaCode()).setLcafType((short) LispCanonicalAddressFormatEnum.SEGMENT.getLispCode());
- addressBuilder.setAddress(new AddressBuilder().setPrimitiveAddress(LispAFIConvertor.asPrimitiveIPAfiAddress("17.34.51.68")).build());
- ByteBuffer buf = ByteBuffer.allocate(LispAddressSerializer.getInstance().getAddressSize(addressBuilder.build()));
- LispAddressSerializer.getInstance().serialize(buf, addressBuilder.build());
- ByteBuffer expectedBuf = hexToByteBuffer("40 03 00 00 " + //
- "02 00 00 0A " + //
- "00 02 03 04 " + // instance ID
- "00 01 11 22 33 44");
- ArrayAssert.assertEquals(expectedBuf.array(), buf.array());
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 Contextream, 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.serializer.address;
-
-import static org.junit.Assert.assertEquals;
-
-import java.nio.ByteBuffer;
-
-import junitx.framework.ArrayAssert;
-
-import org.junit.Test;
-import org.opendaylight.lispflowmapping.lisp.serializer.address.LispAddressSerializer;
-import org.opendaylight.lispflowmapping.lisp.serializer.exception.LispSerializationException;
-import org.opendaylight.lispflowmapping.lisp.type.AddressFamilyNumberEnum;
-import org.opendaylight.lispflowmapping.lisp.type.LispCanonicalAddressFormatEnum;
-import org.opendaylight.lispflowmapping.lisp.util.LispAFIConvertor;
-import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.LcafSourceDestAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.LispAFIAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lcafsourcedestaddress.DstAddressBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lcafsourcedestaddress.SrcAddressBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.lcafsourcedest.LcafSourceDestAddrBuilder;
-
-public class LispSourceDestLCAFAddressTest extends BaseTestCase {
-
- @Test
- public void deserialize__Simple() throws Exception {
- LispAFIAddress address = LispAddressSerializer.getInstance().deserialize(hexToByteBuffer("40 03 00 00 " + //
- "0C 20 00 10 " + //
- "00 00 10 18 " + // reserved + masks
- "00 01 11 22 33 44 " + // AFI=1, IP=0x11223344
- "00 01 22 33 44 55")); // AFI=1, IP=0x22334455
-
- assertEquals(AddressFamilyNumberEnum.LCAF.getIanaCode(), address.getAfi().shortValue());
- LcafSourceDestAddress srcDestAddress = (LcafSourceDestAddress) address;
-
- assertEquals((byte) 0x10, srcDestAddress.getSrcMaskLength().byteValue());
- assertEquals((byte) 0x18, srcDestAddress.getDstMaskLength().byteValue());
-
- assertEquals(LispAFIConvertor.asPrimitiveIPv4AfiPrefix("17.34.51.68", 16), srcDestAddress.getSrcAddress().getPrimitiveAddress());
- assertEquals(LispAFIConvertor.asPrimitiveIPv4AfiPrefix("34.51.68.85", 24), srcDestAddress.getDstAddress().getPrimitiveAddress());
- assertEquals(LispCanonicalAddressFormatEnum.SOURCE_DEST.getLispCode(), srcDestAddress.getLcafType().byteValue());
- }
-
- @Test(expected = LispSerializationException.class)
- public void deserialize__ShorterBuffer() throws Exception {
- LispAddressSerializer.getInstance().deserialize(hexToByteBuffer("40 03 00 00 " + //
- "02 20 00 0A " + //
- "AA BB "));
- }
-
- @Test(expected = LispSerializationException.class)
- public void deserialize__UnknownLCAFType() throws Exception {
- LispAddressSerializer.getInstance().deserialize(hexToByteBuffer("40 03 00 00 " + //
- "AA 20 00 0A " + // Type AA is unknown
- "00 00 CC DD " + // reserved + masks
- "00 01 11 22 33 44 " + // AFI=1, IP=0x11223344
- "00 01 22 33 44 55")); // AFI=1, IP=0x22334455
- }
-
- @Test
- public void deserialize__Ipv6() throws Exception {
- LcafSourceDestAddress srcAddress = (LcafSourceDestAddress) LispAddressSerializer.getInstance().deserialize(hexToByteBuffer("40 03 00 00 " + //
- "0C 20 00 28 " + //
- "00 00 78 78 " + // reserved + masks
- "00 02 11 22 33 44 55 66 77 88 99 AA BB CC AA BB CC 00 " + // AFI=2,
- "00 02 44 33 22 11 88 77 66 55 99 AA BB CC AA BB CC 00")); // AFI=2,
- // IPv6
-
- assertEquals(LispAFIConvertor.toPrimitive(LispAFIConvertor.asIPv6AfiPrefix("1122:3344:5566:7788:99aa:bbcc:aabb:ccdd", 0x78)), srcAddress
- .getSrcAddress().getPrimitiveAddress());
- assertEquals(LispAFIConvertor.toPrimitive(LispAFIConvertor.asIPv6AfiPrefix("4433:2211:8877:6655:99aa:bbcc:aabb:ccdd", 0x78)), srcAddress
- .getDstAddress().getPrimitiveAddress());
- }
-
- @Test
- public void serialize__Simple() throws Exception {
- LcafSourceDestAddrBuilder addressBuilder = new LcafSourceDestAddrBuilder();
- addressBuilder.setAfi(AddressFamilyNumberEnum.LCAF.getIanaCode()).setLcafType(
- (short) LispCanonicalAddressFormatEnum.SOURCE_DEST.getLispCode());
- addressBuilder.setSrcMaskLength((short) 0xCC);
- addressBuilder.setDstMaskLength((short) 0xDD);
- addressBuilder.setSrcAddress(new SrcAddressBuilder().setPrimitiveAddress(LispAFIConvertor.asPrimitiveIPAfiAddress("17.34.51.68")).build());
- addressBuilder.setDstAddress(new DstAddressBuilder().setPrimitiveAddress(LispAFIConvertor.asPrimitiveIPAfiAddress("34.51.68.85")).build());
- ByteBuffer buf = ByteBuffer.allocate(LispAddressSerializer.getInstance().getAddressSize(addressBuilder.build()));
- LispAddressSerializer.getInstance().serialize(buf, addressBuilder.build());
- ByteBuffer expectedBuf = hexToByteBuffer("40 03 00 00 " + //
- "0C 00 00 10 " + //
- "00 00 CC DD " + // reserved + masks
- "00 01 11 22 33 44 " + // AFI=1, IP=0x11223344
- "00 01 22 33 44 55"); // AFI=1, IP=0x22334455
- ArrayAssert.assertEquals(expectedBuf.array(), buf.array());
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 Contextream, 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.serializer.address;
-
-import static org.junit.Assert.assertEquals;
-
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.List;
-
-import junitx.framework.ArrayAssert;
-
-import org.junit.Test;
-import org.opendaylight.lispflowmapping.lisp.serializer.address.LispAddressSerializer;
-import org.opendaylight.lispflowmapping.lisp.serializer.exception.LispSerializationException;
-import org.opendaylight.lispflowmapping.lisp.type.AddressFamilyNumberEnum;
-import org.opendaylight.lispflowmapping.lisp.type.LispCanonicalAddressFormatEnum;
-import org.opendaylight.lispflowmapping.lisp.util.LispAFIConvertor;
-import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.LcafTrafficEngineeringAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.LispAFIAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lcaftrafficengineeringaddress.Hops;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lcaftrafficengineeringaddress.HopsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.lcaftrafficengineering.LcafTrafficEngineeringAddrBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.reencaphop.HopBuilder;
-
-public class LispTrafficEngineeringLCAFAddressTest extends BaseTestCase {
-
- @Test
- public void deserialize__Simple() throws Exception {
- LispAFIAddress address = LispAddressSerializer.getInstance().deserialize(hexToByteBuffer("40 03 00 00 " + //
- "0A 00 00 10 " + //
- "00 00 00 01 AA BB CC DD " + // IPv4
- "00 00 00 01 11 22 33 44")); // IPv4
-
- assertEquals(AddressFamilyNumberEnum.LCAF.getIanaCode(), address.getAfi().shortValue());
- LcafTrafficEngineeringAddress trafficEngineering = (LcafTrafficEngineeringAddress) address;
-
- assertEquals(LispCanonicalAddressFormatEnum.TRAFFIC_ENGINEERING.getLispCode(), trafficEngineering.getLcafType().byteValue());
-
- List<Hops> hops = trafficEngineering.getHops();
- assertEquals(2, hops.size());
-
- assertEquals(LispAFIConvertor.asPrimitiveIPAfiAddress("170.187.204.221"), hops.get(0).getHop().getPrimitiveAddress());
- assertEquals(LispAFIConvertor.asPrimitiveIPAfiAddress("17.34.51.68"), hops.get(1).getHop().getPrimitiveAddress());
- }
-
- @Test
- public void deserialize__Bits() throws Exception {
- LispAFIAddress address = LispAddressSerializer.getInstance().deserialize(hexToByteBuffer("40 03 00 00 " + //
- "0A 00 00 10 " + //
- "00 05 00 01 AA BB CC DD " + // IPv4
- "00 02 00 01 11 22 33 44")); // IPv4
-
- assertEquals(AddressFamilyNumberEnum.LCAF.getIanaCode(), address.getAfi().shortValue());
- LcafTrafficEngineeringAddress trafficEngineering = (LcafTrafficEngineeringAddress) address;
-
- assertEquals(LispCanonicalAddressFormatEnum.TRAFFIC_ENGINEERING.getLispCode(), trafficEngineering.getLcafType().byteValue());
-
- List<Hops> hops = trafficEngineering.getHops();
- assertEquals(2, hops.size());
-
- assertEquals(LispAFIConvertor.asPrimitiveIPAfiAddress("170.187.204.221"), hops.get(0).getHop().getPrimitiveAddress());
- assertEquals(true, hops.get(0).isLookup().booleanValue());
- assertEquals(false, hops.get(0).isRLOCProbe().booleanValue());
- assertEquals(true, hops.get(0).isStrict().booleanValue());
- assertEquals(LispAFIConvertor.asPrimitiveIPAfiAddress("17.34.51.68"), hops.get(1).getHop().getPrimitiveAddress());
- assertEquals(false, hops.get(1).isLookup().booleanValue());
- assertEquals(true, hops.get(1).isRLOCProbe().booleanValue());
- assertEquals(false, hops.get(1).isStrict().booleanValue());
- }
-
- @Test
- public void deserialize__NoAddresses() throws Exception {
- LispAFIAddress address = LispAddressSerializer.getInstance().deserialize(hexToByteBuffer("40 03 00 00 " + //
- "0A 00 00 00 "));
-
- assertEquals(AddressFamilyNumberEnum.LCAF.getIanaCode(), address.getAfi().shortValue());
- LcafTrafficEngineeringAddress trafficEngineering = (LcafTrafficEngineeringAddress) address;
-
- assertEquals(LispCanonicalAddressFormatEnum.TRAFFIC_ENGINEERING.getLispCode(), trafficEngineering.getLcafType().byteValue());
-
- List<Hops> hops = trafficEngineering.getHops();
- assertEquals(0, hops.size());
- }
-
- @Test(expected = LispSerializationException.class)
- public void deserialize__ShorterBuffer() throws Exception {
- LispAddressSerializer.getInstance().deserialize(hexToByteBuffer("40 03 00 00 " + //
- "0A 00 00 18 " + //
- "00 01 AA BB CC DD " + // IPv4
- "00 02 11 22 33 44 11 22 33 44 11 22 33 44"));
- }
-
- @Test(expected = LispSerializationException.class)
- public void deserialize__ShorterBuffer2() throws Exception {
- LispAddressSerializer.getInstance().deserialize(hexToByteBuffer("40 03 00 00 " + //
- "0A 00 00 18 "));
- }
-
- @Test
- public void serialize__Simple() throws Exception {
- List<Hops> hops = new ArrayList<Hops>();
- hops.add(new HopsBuilder().setHop(new HopBuilder().setPrimitiveAddress(LispAFIConvertor.asPrimitiveIPAfiAddress("170.187.204.221")).build())
- .build());
- hops.add(new HopsBuilder().setHop(new HopBuilder().setPrimitiveAddress(LispAFIConvertor.asPrimitiveIPAfiAddress("17.34.51.68")).build())
- .build());
- LcafTrafficEngineeringAddrBuilder trafficBuilder = new LcafTrafficEngineeringAddrBuilder();
- trafficBuilder.setAfi(AddressFamilyNumberEnum.LCAF.getIanaCode()).setLcafType(
- (short) LispCanonicalAddressFormatEnum.TRAFFIC_ENGINEERING.getLispCode());
- trafficBuilder.setHops(hops);
-
- ByteBuffer buf = ByteBuffer.allocate(LispAddressSerializer.getInstance().getAddressSize(trafficBuilder.build()));
- LispAddressSerializer.getInstance().serialize(buf, trafficBuilder.build());
- ByteBuffer expectedBuf = hexToByteBuffer("40 03 00 00 " + //
- "0A 00 00 10 " + //
- "00 00 00 01 AA BB CC DD " + // IPv4
- "00 00 00 01 11 22 33 44"); // IPv4
- ArrayAssert.assertEquals(expectedBuf.array(), buf.array());
- }
-
- @Test
- public void serialize__NoAddresses() throws Exception {
- LcafTrafficEngineeringAddrBuilder addressBuilder = new LcafTrafficEngineeringAddrBuilder();
- addressBuilder.setAfi(AddressFamilyNumberEnum.LCAF.getIanaCode()).setLcafType(
- (short) LispCanonicalAddressFormatEnum.TRAFFIC_ENGINEERING.getLispCode());
-
- ByteBuffer buf = ByteBuffer.allocate(LispAddressSerializer.getInstance().getAddressSize(addressBuilder.build()));
- LispAddressSerializer.getInstance().serialize(buf, addressBuilder.build());
- ByteBuffer expectedBuf = hexToByteBuffer("40 03 00 00 " + //
- "0A 00 00 00");
- ArrayAssert.assertEquals(expectedBuf.array(), buf.array());
- }
-}
--- /dev/null
+/*
+ * Copyright (c) 2014 Contextream, 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.serializer.address;
+
+import static org.junit.Assert.assertEquals;
+
+import java.nio.ByteBuffer;
+
+import junitx.framework.ArrayAssert;
+
+import org.junit.Test;
+import org.opendaylight.lispflowmapping.lisp.serializer.address.LispAddressSerializer;
+import org.opendaylight.lispflowmapping.lisp.serializer.address.LispAddressSerializerContext;
+import org.opendaylight.lispflowmapping.lisp.serializer.exception.LispSerializationException;
+import org.opendaylight.lispflowmapping.lisp.util.MaskUtil;
+import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SourceDestKeyLcaf;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.SourceDestKey;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.source.dest.key.SourceDestKeyBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.EidBuilder;
+
+public class SourceDestKeySerializerTest extends BaseTestCase {
+
+ @Test
+ public void deserialize__Simple() throws Exception {
+ Eid address = LispAddressSerializer.getInstance().deserializeEid(hexToByteBuffer("40 03 00 00 " + //
+ "0C 20 00 10 " + //
+ "00 00 10 18 " + // reserved + masks
+ "00 01 11 22 33 44 " + // AFI=1, IP=0x11223344
+ "00 01 22 33 44 55"), // AFI=1, IP=0x22334455
+ new LispAddressSerializerContext(null));
+
+ assertEquals(SourceDestKeyLcaf.class, address.getAddressType());
+ SourceDestKey srcDestAddress = (SourceDestKey) address.getAddress();
+
+ assertEquals((byte) 0x10, MaskUtil.getMaskForIpPrefix(srcDestAddress.getSourceDestKey().getSource()));
+ assertEquals((byte) 0x18, MaskUtil.getMaskForIpPrefix(srcDestAddress.getSourceDestKey().getDest()));
+
+ assertEquals("17.34.51.68/16", String.valueOf(srcDestAddress.getSourceDestKey().getSource().getValue()));
+ assertEquals("34.51.68.85/24", String.valueOf(srcDestAddress.getSourceDestKey().getDest().getValue()));
+ }
+
+ @Test(expected = LispSerializationException.class)
+ public void deserialize__ShorterBuffer() throws Exception {
+ LispAddressSerializer.getInstance().deserializeEid(hexToByteBuffer("40 03 00 00 " + //
+ "02 20 00 0A " + //
+ "AA BB "), new LispAddressSerializerContext(null));
+ }
+
+ @Test(expected = LispSerializationException.class)
+ public void deserialize__UnknownLCAFType() throws Exception {
+ LispAddressSerializer.getInstance().deserializeEid(hexToByteBuffer("40 03 00 00 " + //
+ "AA 20 00 0A " + // Type AA is unknown
+ "00 00 CC DD " + // reserved + masks
+ "00 01 11 22 33 44 " + // AFI=1, IP=0x11223344
+ "00 01 22 33 44 55"), // AFI=1, IP=0x22334455
+ new LispAddressSerializerContext(null));
+ }
+
+ @Test
+ public void deserialize__Ipv6() throws Exception {
+ Eid srcAddress = LispAddressSerializer.getInstance().deserializeEid(hexToByteBuffer("40 03 00 00 " + //
+ "0C 20 00 28 " + //
+ "00 00 78 78 " + // reserved + masks
+ "00 02 11 22 33 44 55 66 77 88 99 AA BB CC AA BB CC DD " + // AFI=2,
+ "00 02 44 33 22 11 88 77 66 55 99 AA BB CC AA BB CC DD"), // AFI=2,
+ new LispAddressSerializerContext(null));
+ // IPv6
+
+ assertEquals("1122:3344:5566:7788:99aa:bbcc:aabb:ccdd/120", String.valueOf(
+ ((SourceDestKey) srcAddress.getAddress()).getSourceDestKey().getSource().getValue()));
+ assertEquals("4433:2211:8877:6655:99aa:bbcc:aabb:ccdd/120", String.valueOf(
+ ((SourceDestKey) srcAddress.getAddress()).getSourceDestKey().getDest().getValue()));
+ }
+
+ @Test
+ public void serialize__Simple() throws Exception {
+ SourceDestKeyBuilder addressBuilder = new SourceDestKeyBuilder();
+ addressBuilder.setSource(new IpPrefix(new Ipv4Prefix("17.34.51.68/8")));
+ addressBuilder.setDest(new IpPrefix(new Ipv4Prefix("34.51.68.85/16")));
+
+ EidBuilder eb = new EidBuilder();
+ eb.setAddressType(SourceDestKeyLcaf.class);
+ eb.setVirtualNetworkId(null);
+ eb.setAddress((Address)
+ new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.SourceDestKeyBuilder()
+ .setSourceDestKey(addressBuilder.build()).build());
+
+ ByteBuffer buf = ByteBuffer.allocate(LispAddressSerializer.getInstance().getAddressSize(eb.build()));
+ LispAddressSerializer.getInstance().serialize(buf, eb.build());
+
+ ByteBuffer expectedBuf = hexToByteBuffer("40 03 00 00 " + //
+ "0C 00 00 10 " + //
+ "00 00 08 10 " + // reserved + masks
+ "00 01 11 22 33 44 " + // AFI=1, IP=0x11223344
+ "00 01 22 33 44 55"); // AFI=1, IP=0x22334455
+ ArrayAssert.assertEquals(expectedBuf.array(), buf.array());
+ }
+}