Search in sources :

Example 1 with LispSerializationException

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);
    }
}
Also used : SiteId(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.SiteId) 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) MappingRecordBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder) ArrayList(java.util.ArrayList) LispSerializationException(org.opendaylight.lispflowmapping.lisp.serializer.exception.LispSerializationException) MapNotifyBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapnotifymessage.MapNotifyBuilder) XtrId(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.XtrId)

Example 2 with LispSerializationException

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);
    }
}
Also used : SiteId(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.SiteId) 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) MappingRecordBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder) ArrayList(java.util.ArrayList) MapRegisterBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapregisternotification.MapRegisterBuilder) LispSerializationException(org.opendaylight.lispflowmapping.lisp.serializer.exception.LispSerializationException) XtrId(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.XtrId)

Example 3 with LispSerializationException

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);
    }
}
Also used : LispAddressSerializerContext(org.opendaylight.lispflowmapping.lisp.serializer.address.LispAddressSerializerContext) MapRequestBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequestnotification.MapRequestBuilder) EidItemBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.list.EidItemBuilder) EidItem(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.list.EidItem) LispSerializationException(org.opendaylight.lispflowmapping.lisp.serializer.exception.LispSerializationException) ItrRloc(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRloc) ItrRlocBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRlocBuilder) SourceEidBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.SourceEidBuilder)

Example 4 with LispSerializationException

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

Example 5 with LispSerializationException

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);
}
Also used : InstanceIdType(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.InstanceIdType) 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