Search in sources :

Example 6 with MappingRecordItem

use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItem in project lispflowmapping by opendaylight.

the class MapReplySerializationTest method serialize__EidRecordDefaultAction.

@Test
public void serialize__EidRecordDefaultAction() throws Exception {
    MapReplyBuilder mrBuilder = new MapReplyBuilder();
    mrBuilder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
    MappingRecordBuilder recordBuilder = new MappingRecordBuilder();
    recordBuilder.setEid(LispAddressUtil.asIpv4PrefixEid("0.0.0.1/32"));
    mrBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(recordBuilder.build()).build());
    ByteBuffer packet = MapReplySerializer.getInstance().serialize(mrBuilder.build());
    packet.position(18);
    // MapReplyAction.NoAction
    assertHexEquals((byte) 0x00, packet.get());
}
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) MappingRecordBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder) MapReplyBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapreplymessage.MapReplyBuilder) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 7 with MappingRecordItem

use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItem in project lispflowmapping by opendaylight.

the class MapReplySerializationTest method serialize__EidRecordFields.

@Test
public void serialize__EidRecordFields() throws Exception {
    MapReplyBuilder mrBuilder = new MapReplyBuilder();
    mrBuilder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
    MappingRecordBuilder eidToLocator1 = new MappingRecordBuilder();
    eidToLocator1.setEid(LispAddressUtil.asIpv4PrefixEid("0.0.0.1/32"));
    eidToLocator1.setRecordTtl(7);
    eidToLocator1.setAction(Action.SendMapRequest);
    eidToLocator1.setAuthoritative(true);
    eidToLocator1.setMapVersion((short) 3072);
    mrBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(eidToLocator1.build()).build());
    MappingRecordBuilder eidToLocator2 = new MappingRecordBuilder();
    eidToLocator2.setEid(LispAddressUtil.asIpv4PrefixEid("0.0.0.7/32"));
    eidToLocator2.setRecordTtl(1000000);
    eidToLocator2.setAction(Action.Drop);
    eidToLocator2.setAuthoritative(false);
    eidToLocator2.setMapVersion((short) 29);
    mrBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(eidToLocator2.build()).build());
    ByteBuffer packet = MapReplySerializer.getInstance().serialize(mrBuilder.build());
    // First record
    packet.position(12);
    assertEquals(7, packet.getInt());
    // skip Locator Count & Mask-len
    packet.position(packet.position() + 2);
    assertHexEquals((byte) 0x50, packet.get());
    // skip Reserved byte
    packet.position(packet.position() + 1);
    assertEquals((short) 3072, packet.getShort());
    // Second record
    packet.position(packet.position() + 6);
    assertEquals(1000000, packet.getInt());
    // skip Locator Count & Mask-len
    packet.position(packet.position() + 2);
    assertHexEquals((byte) 0x60, packet.get());
    // skip Reserved byte
    packet.position(packet.position() + 1);
    assertEquals((short) 29, packet.getShort());
}
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) MappingRecordBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder) MapReplyBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapreplymessage.MapReplyBuilder) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 8 with MappingRecordItem

use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItem 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 9 with MappingRecordItem

use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItem 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 10 with MappingRecordItem

use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItem in project lispflowmapping by opendaylight.

the class MapRegisterSerializer method serialize.

public ByteBuffer serialize(MapRegister mapRegister) {
    int size = Length.HEADER_SIZE;
    if (mapRegister.getAuthenticationData() != null) {
        size += mapRegister.getAuthenticationData().length;
    }
    if (mapRegister.isXtrSiteIdPresent() != null && mapRegister.isXtrSiteIdPresent()) {
        size += Length.XTRID_SIZE + Length.SITEID_SIZE;
    }
    for (MappingRecordItem eidToLocatorRecord : mapRegister.getMappingRecordItem()) {
        size += MappingRecordSerializer.getInstance().getSerializationSize(eidToLocatorRecord.getMappingRecord());
    }
    ByteBuffer registerBuffer = ByteBuffer.allocate(size);
    registerBuffer.put((byte) ((byte) (MessageType.MapRegister.getIntValue() << 4) | ByteUtil.boolToBit(BooleanUtils.isTrue(mapRegister.isProxyMapReply()), Flags.PROXY) | ByteUtil.boolToBit(BooleanUtils.isTrue(mapRegister.isXtrSiteIdPresent()), Flags.XTRSITEID)));
    registerBuffer.position(registerBuffer.position() + Length.RES);
    registerBuffer.put((byte) (ByteUtil.boolToBit(BooleanUtils.isTrue(mapRegister.isMergeEnabled()), Flags.MERGE_ENABLED) | ByteUtil.boolToBit(BooleanUtils.isTrue(mapRegister.isWantMapNotify()), Flags.WANT_MAP_NOTIFY)));
    registerBuffer.put((byte) mapRegister.getMappingRecordItem().size());
    registerBuffer.putLong(NumberUtil.asLong(mapRegister.getNonce()));
    registerBuffer.putShort(NumberUtil.asShort(mapRegister.getKeyId()));
    if (mapRegister.getAuthenticationData() != null) {
        registerBuffer.putShort((short) mapRegister.getAuthenticationData().length);
        registerBuffer.put(mapRegister.getAuthenticationData());
    } else {
        registerBuffer.putShort((short) 0);
    }
    for (MappingRecordItem eidToLocatorRecord : mapRegister.getMappingRecordItem()) {
        MappingRecordSerializer.getInstance().serialize(registerBuffer, eidToLocatorRecord.getMappingRecord());
    }
    if (mapRegister.isXtrSiteIdPresent() != null && mapRegister.isXtrSiteIdPresent()) {
        registerBuffer.put(mapRegister.getXtrId().getValue());
        registerBuffer.put(mapRegister.getSiteId().getValue());
    }
    registerBuffer.clear();
    return registerBuffer;
}
Also used : MappingRecordItem(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItem) ByteBuffer(java.nio.ByteBuffer)

Aggregations

MappingRecordItem (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItem)33 MappingRecordItemBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItemBuilder)23 MappingRecordBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder)20 Test (org.junit.Test)19 ByteBuffer (java.nio.ByteBuffer)17 LocatorRecord (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecord)8 MapNotifyBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapnotifymessage.MapNotifyBuilder)8 MapReplyBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapreplymessage.MapReplyBuilder)8 MapRegisterBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapregisternotification.MapRegisterBuilder)7 ArrayList (java.util.ArrayList)4 MapNotify (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapNotify)4 Eid (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid)4 MappingRecord (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord)4 LispSerializationException (org.opendaylight.lispflowmapping.lisp.serializer.exception.LispSerializationException)3 MapRegister (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapRegister)3 SiteId (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.SiteId)3 XtrId (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.XtrId)3 GotMapNotify (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.GotMapNotify)2 LocatorRecordBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecordBuilder)2 MappingAuthkey (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.authkey.container.MappingAuthkey)2