use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.SiteId 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.SiteId 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.SiteId 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.SiteId in project lispflowmapping by opendaylight.
the class MultiSiteScenario method storeNorthMappingSrcDst.
void storeNorthMappingSrcDst(final Site srcSite, final Site... dstSite) {
final MappingRecordBuilder mrb = prepareMappingRecord(EidType.EID_SRC_DST, srcSite, dstSite);
mapService.addMapping(MappingOrigin.Northbound, mrb.getEid(), new SiteId(DEFAULT_SITE_ID), new MappingData(mrb.build()));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.SiteId in project lispflowmapping by opendaylight.
the class LispNotificationHelper method getSiteId.
public static List<SiteId> getSiteId(MapRegister mapRegister) {
if (mapRegister.isXtrSiteIdPresent()) {
List<SiteId> siteIds = new ArrayList<SiteId>();
SiteId siteId = new SiteId(mapRegister.getSiteId());
siteIds.add(siteId);
return siteIds;
} else {
return null;
}
}
Aggregations