Search in sources :

Example 1 with SiteId

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);
    }
}
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 SiteId

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);
    }
}
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 SiteId

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();
}
Also used : MapRegisterCacheKeyBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.map.register.cache.key.container.MapRegisterCacheKeyBuilder)

Example 4 with SiteId

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()));
}
Also used : SiteId(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.SiteId) MappingRecordBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder) MappingData(org.opendaylight.lispflowmapping.lisp.type.MappingData)

Example 5 with SiteId

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;
    }
}
Also used : SiteId(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.SiteId) ArrayList(java.util.ArrayList)

Aggregations

SiteId (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.SiteId)11 MappingRecordBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder)8 ArrayList (java.util.ArrayList)4 XtrId (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.XtrId)4 MappingRecordItemBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItemBuilder)4 MappingData (org.opendaylight.lispflowmapping.lisp.type.MappingData)3 MappingRecordItem (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItem)3 MapRegisterBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapregisternotification.MapRegisterBuilder)3 LispSerializationException (org.opendaylight.lispflowmapping.lisp.serializer.exception.LispSerializationException)2 MappingRecord (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord)2 EidUri (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.EidUri)2 MappingBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.MappingBuilder)2 XtrIdMappingBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.mapping.XtrIdMappingBuilder)2 ByteBuffer (java.nio.ByteBuffer)1 Test (org.junit.Test)1 Eid (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid)1 LocatorRecord (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecord)1 MapRegisterCacheKeyBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.map.register.cache.key.container.MapRegisterCacheKeyBuilder)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.mapregistermessage.MapRegisterBuilder)1