Search in sources :

Example 6 with MapRegister

use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapregistermessage.MapRegister in project lispflowmapping by opendaylight.

the class MapRegisterSerializationTest method deserialize__serialize.

@Test
public void deserialize__serialize() throws Exception {
    ByteBuffer bb = hexToByteBuffer("32 00 01 01 63 99 " + "83 64 23 06 a8 be 00 01 00 14 b8 c2 a2 e1 dc 4a " + "08 0c f6 01 b0 9d 70 5a d4 88 95 f8 73 dd 00 00 " + "05 a0 01 20 10 00 00 00 40 03 00 00 02 20 00 0a " + "00 00 00 01 00 01 c3 a8 c8 01 0a 32 ff 00 00 04 " + "00 01 ac 10 01 02 15 1a 39 80 e3 35 e6 c4 49 a6 " + "90 87 20 65 9a b7 00 00 00 00 00 00 00 00 ");
    MapRegister mr = MapRegisterSerializer.getInstance().deserialize(bb, null);
    assertTrue(mr.isXtrSiteIdPresent());
    ArrayAssert.assertEquals(bb.array(), MapRegisterSerializer.getInstance().serialize(mr).array());
}
Also used : MapRegister(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapRegister) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 7 with MapRegister

use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapregistermessage.MapRegister in project lispflowmapping by opendaylight.

the class MapRegisterSerializationTest method deserialize__IllegalAction.

@Test
public void deserialize__IllegalAction() throws Exception {
    MapRegister mr = MapRegisterSerializer.getInstance().deserialize(hexToByteBuffer("38 00 01 01 FF BB " + // 
    "00 00 00 00 00 00 00 01 00 14 ec 47 1e 53 25 91 " + // 
    "2f 68 10 75 13 dd 2c e8 6e 3c ac 94 ed e4 00 00 " + // 
    "00 0a 01 20 F0 00 00 00 00 01 99 10 fe 01 01 64 " + // 
    "ff 00 00 05 00 01 c0 a8 88 0a"), null);
    assertEquals(1, mr.getMappingRecordItem().size());
    assertEquals(Action.NoAction, mr.getMappingRecordItem().get(0).getMappingRecord().getAction());
}
Also used : MapRegister(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapRegister) Test(org.junit.Test)

Example 8 with MapRegister

use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapregistermessage.MapRegister in project lispflowmapping by opendaylight.

the class LispAuthenticationTest method validate__NoAuthentication.

@Test
public void validate__NoAuthentication() throws Exception {
    // LISP(Type = 3 Map-Register, P=1, M=1
    // Record Counter: 1
    // Nonce: (something)
    // Key ID: 0x0000
    // AuthDataLength: 0:
    // EID prefix: 153.16.254.1/32 (EID=0x9910FE01), TTL: 10, Authoritative,
    // No-Action
    // Local RLOC: 192.168.136.10 (RLOC=0xC0A8880A), Reachable,
    // Priority/Weight: 1/100, Multicast Priority/Weight: 255/0
    // 
    final ByteBuffer byteBuffer = hexToByteBuffer("38 00 01 01 FF BB " + "00 00 00 00 00 00 00 00 00 00 " + "00 00 " + "00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " + "ff 00 00 05 00 01 c0 a8 88 0a");
    MapRegister mapRegister = MapRegisterSerializer.getInstance().deserialize(byteBuffer, null);
    assertTrue(validate(mapRegister, byteBuffer, EID, 0, PASSWORD));
    assertTrue(validate(mapRegister, byteBuffer, EID, 0, WRONG_PASSWORD));
}
Also used : MapRegister(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapRegister) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 9 with MapRegister

use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapregistermessage.MapRegister 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 MapRegister

use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapregistermessage.MapRegister 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

MapRegister (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapRegister)22 Test (org.junit.Test)19 MappingRecordItem (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItem)8 GotMapNotify (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.GotMapNotify)7 MapNotify (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapNotify)7 Eid (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid)7 ByteBuffer (java.nio.ByteBuffer)6 MappingRecordItemBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItemBuilder)6 ArrayList (java.util.ArrayList)5 MapRequest (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapRequest)5 MapNotifyBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapnotifymessage.MapNotifyBuilder)5 GotMapReply (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.GotMapReply)4 MapReply (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapReply)4 LocatorRecord (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecord)4 MappingRecordBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder)4 MappingAuthkey (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.authkey.container.MappingAuthkey)3 MappingRecord (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord)3 MapRegisterBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapregisternotification.MapRegisterBuilder)3 TransportAddress (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.transport.address.TransportAddress)3 MappingData (org.opendaylight.lispflowmapping.lisp.type.MappingData)2