use of org.opendaylight.lispflowmapping.lisp.serializer.exception.LispSerializationException 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.lispflowmapping.lisp.serializer.exception.LispSerializationException 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.lispflowmapping.lisp.serializer.exception.LispSerializationException in project lispflowmapping by opendaylight.
the class MapRequestSerializer method deserialize.
@SuppressWarnings("checkstyle:IllegalCatch")
public MapRequest deserialize(ByteBuffer requestBuffer, InetAddress sourceRloc) {
try {
final byte typeAndFlags = requestBuffer.get();
final int type = typeAndFlags >> 4;
if (MessageType.forValue(type) != MessageType.MapRequest) {
throw new LispSerializationException("Expected Map-Request packet (type 1), but was type " + type);
}
MapRequestBuilder builder = new MapRequestBuilder();
builder.setAuthoritative(ByteUtil.extractBit(typeAndFlags, Flags.AUTHORITATIVE));
builder.setMapDataPresent(ByteUtil.extractBit(typeAndFlags, Flags.MAP_DATA_PRESENT));
builder.setProbe(ByteUtil.extractBit(typeAndFlags, Flags.PROBE));
builder.setSmr(ByteUtil.extractBit(typeAndFlags, Flags.SMR));
final byte moreFlags = requestBuffer.get();
builder.setPitr(ByteUtil.extractBit(moreFlags, Flags.PITR));
builder.setSmrInvoked(ByteUtil.extractBit(moreFlags, Flags.SMR_INVOKED));
final int itrCount = ByteUtil.getUnsignedByte(requestBuffer) + 1;
final int recordCount = ByteUtil.getUnsignedByte(requestBuffer);
builder.setNonce(requestBuffer.getLong());
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().setRloc(LispAddressSerializer.getInstance().deserializeRloc(requestBuffer)).build());
}
if (builder.getEidItem() == null) {
builder.setEidItem(new ArrayList<EidItem>());
}
for (int i = 0; i < recordCount; i++) {
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().setMappingRecord(MappingRecordSerializer.getInstance().deserialize(requestBuffer)).build()).build();
} catch (RuntimeException re) {
LOG.warn("Couldn't deserialize Map-Reply encapsulated in Map-Request", re);
}
}
builder.setSourceRloc(LispAddressUtil.addressBinaryFromInet(sourceRloc));
return builder.build();
} catch (RuntimeException re) {
throw new LispSerializationException("Couldn't deserialize Map-Request (len=" + requestBuffer.capacity() + ")", re);
}
}
use of org.opendaylight.lispflowmapping.lisp.serializer.exception.LispSerializationException in project lispflowmapping by opendaylight.
the class LispAddressSerializer method deserializeRloc.
@SuppressWarnings("checkstyle:IllegalCatch")
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);
}
}
use of org.opendaylight.lispflowmapping.lisp.serializer.exception.LispSerializationException in project lispflowmapping by opendaylight.
the class InstanceIdSerializer method deserializeLcafEidData.
@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);
}
Aggregations