Search in sources :

Example 6 with LispSerializationException

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();
}
Also used : MappingRecordItemBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItemBuilder) MappingRecordItem(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItem) MapReplyBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapreplymessage.MapReplyBuilder) LispSerializationException(org.opendaylight.lispflowmapping.lisp.serializer.exception.LispSerializationException)

Example 7 with LispSerializationException

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);
    }
}
Also used : LispSerializationException(org.opendaylight.lispflowmapping.lisp.serializer.exception.LispSerializationException)

Example 8 with LispSerializationException

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);
    }
}
Also used : LispSerializationException(org.opendaylight.lispflowmapping.lisp.serializer.exception.LispSerializationException)

Aggregations

LispSerializationException (org.opendaylight.lispflowmapping.lisp.serializer.exception.LispSerializationException)8 MappingRecordItem (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItem)3 MappingRecordItemBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItemBuilder)3 ArrayList (java.util.ArrayList)2 SiteId (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.SiteId)2 XtrId (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.XtrId)2 MappingRecordBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder)2 LispAddressSerializerContext (org.opendaylight.lispflowmapping.lisp.serializer.address.LispAddressSerializerContext)1 InstanceIdType (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.InstanceIdType)1 EidItem (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.list.EidItem)1 EidItemBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.list.EidItemBuilder)1 MapNotifyBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapnotifymessage.MapNotifyBuilder)1 MapRegisterBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapregisternotification.MapRegisterBuilder)1 MapReplyBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapreplymessage.MapReplyBuilder)1 ItrRloc (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRloc)1 ItrRlocBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRlocBuilder)1 SourceEidBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.SourceEidBuilder)1 MapRequestBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequestnotification.MapRequestBuilder)1