use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.XtrId in project lispflowmapping by opendaylight.
the class MapNotifySerializer method deserialize.
@SuppressWarnings("checkstyle:IllegalCatch")
public MapNotify deserialize(ByteBuffer notifyBuffer) {
try {
final byte typeAndFlags = notifyBuffer.get();
final int type = typeAndFlags >> 4;
if (MessageType.forValue(type) != MessageType.MapNotify) {
throw new LispSerializationException("Expected Map-Notify packet (type 4), but was type " + type);
}
MapNotifyBuilder builder = new MapNotifyBuilder();
builder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
boolean xtrSiteIdPresent = ByteUtil.extractBit(typeAndFlags, Flags.XTRSITEID);
builder.setXtrSiteIdPresent(xtrSiteIdPresent);
notifyBuffer.position(notifyBuffer.position() + Length.RES);
builder.setMergeEnabled(ByteUtil.extractBit(notifyBuffer.get(), Flags.MERGE_ENABLED));
byte recordCount = (byte) ByteUtil.getUnsignedByte(notifyBuffer);
builder.setNonce(notifyBuffer.getLong());
builder.setKeyId(notifyBuffer.getShort());
short authenticationLength = notifyBuffer.getShort();
byte[] authenticationData = new byte[authenticationLength];
notifyBuffer.get(authenticationData);
builder.setAuthenticationData(authenticationData);
if (xtrSiteIdPresent) {
List<MappingRecordBuilder> mrbs = new ArrayList<MappingRecordBuilder>();
for (int i = 0; i < recordCount; i++) {
mrbs.add(MappingRecordSerializer.getInstance().deserializeToBuilder(notifyBuffer));
}
byte[] xtrIdBuf = new byte[MapRegisterSerializer.Length.XTRID_SIZE];
notifyBuffer.get(xtrIdBuf);
XtrId xtrId = new XtrId(xtrIdBuf);
byte[] siteIdBuf = new byte[MapRegisterSerializer.Length.SITEID_SIZE];
notifyBuffer.get(siteIdBuf);
SiteId siteId = new SiteId(siteIdBuf);
builder.setXtrId(xtrId);
builder.setSiteId(siteId);
for (MappingRecordBuilder mrb : mrbs) {
mrb.setXtrId(xtrId);
mrb.setSiteId(siteId);
builder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(mrb.build()).build());
}
} else {
for (int i = 0; i < recordCount; i++) {
builder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(MappingRecordSerializer.getInstance().deserialize(notifyBuffer)).build());
}
}
notifyBuffer.limit(notifyBuffer.position());
return builder.build();
} catch (RuntimeException re) {
throw new LispSerializationException("Couldn't deserialize Map-Notify (len=" + notifyBuffer.capacity() + ")", re);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.XtrId in project lispflowmapping by opendaylight.
the class MapRegisterSerializer method deserialize.
@SuppressWarnings("checkstyle:IllegalCatch")
public MapRegister deserialize(ByteBuffer registerBuffer, InetAddress sourceRloc) {
try {
final byte typeAndFlags = registerBuffer.get();
final int type = typeAndFlags >> 4;
if (MessageType.forValue(type) != MessageType.MapRegister) {
throw new LispSerializationException("Expected Map-Register packet (type 3), but was type " + type);
}
MapRegisterBuilder builder = new MapRegisterBuilder();
builder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
boolean xtrSiteIdPresent = ByteUtil.extractBit(typeAndFlags, Flags.XTRSITEID);
builder.setProxyMapReply(ByteUtil.extractBit(typeAndFlags, Flags.PROXY));
builder.setXtrSiteIdPresent(xtrSiteIdPresent);
registerBuffer.position(registerBuffer.position() + Length.RES);
byte mergeAndMapReply = registerBuffer.get();
builder.setWantMapNotify(ByteUtil.extractBit(mergeAndMapReply, Flags.WANT_MAP_NOTIFY));
builder.setMergeEnabled(ByteUtil.extractBit(mergeAndMapReply, Flags.MERGE_ENABLED));
byte recordCount = (byte) ByteUtil.getUnsignedByte(registerBuffer);
builder.setNonce(registerBuffer.getLong());
builder.setKeyId(registerBuffer.getShort());
short authenticationLength = registerBuffer.getShort();
byte[] authenticationData = new byte[authenticationLength];
registerBuffer.get(authenticationData);
builder.setAuthenticationData(authenticationData);
if (xtrSiteIdPresent) {
List<MappingRecordBuilder> mrbs = new ArrayList<MappingRecordBuilder>();
for (int i = 0; i < recordCount; i++) {
mrbs.add(MappingRecordSerializer.getInstance().deserializeToBuilder(registerBuffer));
}
byte[] xtrIdBuf = new byte[Length.XTRID_SIZE];
registerBuffer.get(xtrIdBuf);
XtrId xtrId = new XtrId(xtrIdBuf);
byte[] siteIdBuf = new byte[Length.SITEID_SIZE];
registerBuffer.get(siteIdBuf);
SiteId siteId = new SiteId(siteIdBuf);
builder.setXtrId(xtrId);
builder.setSiteId(siteId);
for (MappingRecordBuilder mrb : mrbs) {
mrb.setXtrId(xtrId);
mrb.setSiteId(siteId);
mrb.setSourceRloc(LispAddressUtil.addressBinaryFromInet(sourceRloc));
builder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(mrb.build()).build());
}
} else {
for (int i = 0; i < recordCount; i++) {
builder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(MappingRecordSerializer.getInstance().deserialize(registerBuffer)).build());
}
}
registerBuffer.limit(registerBuffer.position());
byte[] mapRegisterBytes = new byte[registerBuffer.position()];
registerBuffer.position(0);
registerBuffer.get(mapRegisterBytes);
return builder.build();
} catch (RuntimeException re) {
throw new LispSerializationException("Couldn't deserialize Map-Register (len=" + registerBuffer.capacity() + ")", re);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.XtrId in project lispflowmapping by opendaylight.
the class MapRegisterPartialDeserializer method createKeyFromBytes.
private static MapRegisterCacheKey createKeyFromBytes(final ByteBuffer buffer, int authDataLength) {
byte typeAndFlags = buffer.get();
buffer.position(0);
boolean xtrSiteIdPresent = ByteUtil.extractBit(typeAndFlags, XTR_SITE_ID);
if (!xtrSiteIdPresent) {
return null;
}
final MapRegisterCacheKeyBuilder mapRegisterCacheKeyBuilder = new MapRegisterCacheKeyBuilder();
final byte[] eidPrefix = extractEidPrefix(buffer, authDataLength);
if (eidPrefix == null) {
return null;
}
mapRegisterCacheKeyBuilder.setEidPrefix(eidPrefix);
if (xtrSiteIdPresent) {
buffer.position(0);
final int bufferLength = buffer.remaining();
buffer.position(bufferLength - MapRegisterSerializer.Length.XTRID_SIZE - MapRegisterSerializer.Length.SITEID_SIZE);
byte[] xtrId = new byte[MapRegisterSerializer.Length.XTRID_SIZE];
buffer.get(xtrId);
mapRegisterCacheKeyBuilder.setXtrId(xtrId);
byte[] siteId = new byte[MapRegisterSerializer.Length.SITEID_SIZE];
buffer.get(siteId);
mapRegisterCacheKeyBuilder.setSiteId(siteId);
}
return mapRegisterCacheKeyBuilder.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.XtrId in project lispflowmapping by opendaylight.
the class MappingMergeUtil method mergeMappings.
public static MappingRecord mergeMappings(MappingRecord currentMergedMapping, MappingRecord newMapping, XtrId xtrId, Date regdate) {
if (currentMergedMapping == null) {
return newMapping;
}
MappingRecordBuilder mrb = new MappingRecordBuilder(currentMergedMapping);
mergeCommonMappingRecordFields(mrb, newMapping);
mergeLocatorRecords(mrb, newMapping);
if (xtrId != null) {
mrb.setXtrId(xtrId);
mrb.setTimestamp(regdate.getTime());
}
return mrb.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.XtrId in project lispflowmapping by opendaylight.
the class MappingMergeUtil method mergeXtrIdMappings.
public static MappingData mergeXtrIdMappings(List<Object> mappingDataList, List<MappingData> expiredMappingDataList, Set<IpAddressBinary> sourceRlocs) {
MappingRecordBuilder mrb = null;
XtrId xtrId = null;
Long timestamp = Long.MAX_VALUE;
for (int i = 0; i < mappingDataList.size(); i++) {
MappingData mappingData = (MappingData) mappingDataList.get(i);
MappingRecord record = mappingData.getRecord();
// Skip expired mappings and add them to a list to be returned to the caller
if (timestampIsExpired(mappingData.getTimestamp())) {
expiredMappingDataList.add(mappingData);
continue;
}
if (mrb == null) {
mrb = new MappingRecordBuilder(record);
}
// Save the oldest valid timestamp
if (mappingData.getTimestamp().getTime() < timestamp) {
timestamp = mappingData.getTimestamp().getTime();
xtrId = mappingData.getXtrId();
}
// Merge record fields and locators
mergeCommonMappingRecordFields(mrb, record);
mergeLocatorRecords(mrb, record);
// Save source locator for use in Map-Notify
sourceRlocs.add(record.getSourceRloc());
}
if (mrb == null) {
LOG.warn("All mappings expired when merging! Unexpected!");
return null;
}
mrb.setXtrId(xtrId);
return new MappingData(mrb.build(), new Date(timestamp));
}
Aggregations