use of org.opendaylight.lispflowmapping.lisp.serializer.exception.LispSerializationException in project lispflowmapping by opendaylight.
the class MapReplySerializer method deserialize.
public MapReply deserialize(ByteBuffer replyBuffer) {
final byte typeAndFlags = replyBuffer.get();
final int type = typeAndFlags >> 4;
if (MessageType.forValue(type) != MessageType.MapReply) {
throw new LispSerializationException("Expected Map-Reply packet (type 2), but was type " + type);
}
MapReplyBuilder builder = new MapReplyBuilder();
builder.setProbe(ByteUtil.extractBit(typeAndFlags, Flags.PROBE));
builder.setEchoNonceEnabled(ByteUtil.extractBit(typeAndFlags, Flags.ECHO_NONCE_ENABLED));
builder.setSecurityEnabled(ByteUtil.extractBit(typeAndFlags, Flags.SECURITY_ENABLED));
replyBuffer.getShort();
int recordCount = ByteUtil.getUnsignedByte(replyBuffer);
builder.setNonce(replyBuffer.getLong());
builder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
for (int i = 0; i < recordCount; i++) {
builder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(MappingRecordSerializer.getInstance().deserialize(replyBuffer)).build());
}
return builder.build();
}
use of org.opendaylight.lispflowmapping.lisp.serializer.exception.LispSerializationException in project lispflowmapping by opendaylight.
the class LispAddressSerializer method deserializeEid.
@SuppressWarnings("checkstyle:IllegalCatch")
public Eid deserializeEid(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.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.deserializeEidData(buffer, ctx);
} catch (RuntimeException e) {
throw new LispSerializationException("Problem deserializing AFI " + afi + " in EID context", e);
}
}
use of org.opendaylight.lispflowmapping.lisp.serializer.exception.LispSerializationException in project lispflowmapping by opendaylight.
the class SimpleAddressSerializer method deserialize.
@SuppressWarnings("checkstyle:IllegalCatch")
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);
}
}
Aggregations