Search in sources :

Example 11 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 MapReplySerializer method serialize.

public ByteBuffer serialize(MapReply mapReply) {
    int size = Length.HEADER_SIZE;
    for (MappingRecordItem eidToLocatorRecord : mapReply.getMappingRecordItem()) {
        size += MappingRecordSerializer.getInstance().getSerializationSize(eidToLocatorRecord.getMappingRecord());
    }
    ByteBuffer replyBuffer = ByteBuffer.allocate(size);
    replyBuffer.put((byte) ((MessageType.MapReply.getIntValue() << 4) | (BooleanUtils.isTrue(mapReply.isProbe()) ? Flags.PROBE : 0x00) | (BooleanUtils.isTrue(mapReply.isEchoNonceEnabled()) ? Flags.ECHO_NONCE_ENABLED : 0x00)));
    replyBuffer.position(replyBuffer.position() + Length.RES);
    if (mapReply.getMappingRecordItem() != null) {
        replyBuffer.put((byte) mapReply.getMappingRecordItem().size());
    } else {
        replyBuffer.put((byte) 0);
    }
    replyBuffer.putLong(NumberUtil.asLong(mapReply.getNonce()));
    if (mapReply.getMappingRecordItem() != null) {
        for (MappingRecordItem eidToLocatorRecord : mapReply.getMappingRecordItem()) {
            MappingRecordSerializer.getInstance().serialize(replyBuffer, eidToLocatorRecord.getMappingRecord());
        }
    }
    return replyBuffer;
}
Also used : MappingRecordItem(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItem) ByteBuffer(java.nio.ByteBuffer)

Example 12 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 LispSouthboundHandler method tryToAuthenticateMessage.

/**
 * Checks whether authentication data is valid.
 *
 * <p>Methods pass through all records from map register message. For the EID of the first record it gets
 * authentication key and does validation of authentication data again this authentication key. If it pass
 * it just checks for remaining records (and its EID) whether they have the same authentication key stored in
 * the authentication key database.
 *
 * @return Returns authentication key if all of EIDs have the same authentication key or null otherwise
 */
private MappingAuthkey tryToAuthenticateMessage(final MapRegister mapRegister, final ByteBuffer byteBuffer) {
    if (lispSbPlugin.getAkdb() == null) {
        LOG.debug("Simple map cache wasn't instantieted and set.");
        return null;
    }
    MappingAuthkey firstAuthKey = null;
    final List<MappingRecordItem> mappingRecords = mapRegister.getMappingRecordItem();
    for (int i = 0; i < mappingRecords.size(); i++) {
        final MappingRecordItem recordItem = mappingRecords.get(i);
        final MappingRecord mappingRecord = recordItem.getMappingRecord();
        if (i == 0) {
            firstAuthKey = lispSbPlugin.getAkdb().getAuthenticationKey(mappingRecord.getEid());
            if (!LispAuthenticationUtil.validate(mapRegister, byteBuffer, mappingRecord.getEid(), firstAuthKey)) {
                return null;
            }
        } else {
            final Eid eid = mappingRecord.getEid();
            final MappingAuthkey authKey = lispSbPlugin.getAkdb().getAuthenticationKey(eid);
            if (!firstAuthKey.equals(authKey)) {
                LOG.debug("Map register packet contained several eids. Authentication keys for first one and for " + "{} are different.", LispAddressStringifier.getString(eid));
                return null;
            }
        }
    }
    return firstAuthKey;
}
Also used : Eid(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid) MappingRecordItem(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItem) MappingRecord(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord) MappingAuthkey(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.authkey.container.MappingAuthkey)

Example 13 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 LispSouthboundHandlerTest method lastMapNotifyPacket.

private DatagramPacket lastMapNotifyPacket() {
    if (mapNotifyBuilder.getMappingRecordItem() == null) {
        mapNotifyBuilder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
    }
    mapNotifyBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(mappingRecordBuilder.build()).build());
    mapNotifyBuilder.setNonce((long) 0);
    mapNotifyBuilder.setKeyId((short) 0);
    mapNotifyBuilder.setAuthenticationData(new byte[0]);
    ByteBuffer serialize = MapNotifySerializer.getInstance().serialize(mapNotifyBuilder.build());
    return new DatagramPacket(wrappedBuffer(serialize), new InetSocketAddress(0), new InetSocketAddress(0));
}
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) InetSocketAddress(java.net.InetSocketAddress) DatagramPacket(io.netty.channel.socket.DatagramPacket) ByteBuffer(java.nio.ByteBuffer)

Example 14 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 LispSouthboundHandlerTest method mapRegister__TwoRlocs.

@Test
public void mapRegister__TwoRlocs() throws Exception {
    // P Bit & M Bit set
    // EID prefix: 172.1.1.2/32, TTL: 10, Authoritative, No-Action
    // Local RLOC: 10.1.0.110, Reachable, Priority/Weight: 1/100, Multicast
    // Priority/Weight: 255/0
    // Local RLOC: 192.168.136.51, Reachable, Priority/Weight: 6/100,
    // Multicast Priority/Weight: 255/0
    mapRegisterPacket = extractWSUdpByteArray("0000   00 0c 29 7a ce 8d 00 0c 29 e4 ef 70 08 00 45 00 " + "0010   00 68 00 00 40 00 40 11 26 15 0a 01 00 6e 0a 01 " + "0020   00 01 10 f6 10 f6 00 54 03 3b 38 00 01 01 00 00 " + "0030   00 00 00 00 00 00 00 01 00 14 ae d8 7b d4 9c 59 " + "0040   e9 35 75 6e f1 29 27 a3 45 20 96 06 c2 e1 00 00 " + "0050   00 0a 02 20 10 00 00 00 00 01 ac 01 01 02 01 64 " + "0060   ff 00 00 05 00 01 0a 01 00 6e 06 64 ff 00 00 05 " + "0070   00 01 c0 a8 88 33");
    ArgumentCaptor<AddMapping> captor = ArgumentCaptor.forClass(AddMapping.class);
    handleMapRegisterPacket(mapRegisterPacket);
    Mockito.verify(mockLispSouthboundPlugin).sendNotificationIfPossible(captor.capture());
    List<MappingRecordItem> eidRecords = captor.getValue().getMapRegister().getMappingRecordItem();
    assertEquals(1, eidRecords.size());
    MappingRecord eidRecord = eidRecords.get(0).getMappingRecord();
    assertEquals(2, eidRecord.getLocatorRecord().size());
    assertEquals(LispAddressUtil.asIpv4Rloc("10.1.0.110"), eidRecord.getLocatorRecord().get(0).getRloc());
    assertEquals(LispAddressUtil.asIpv4Rloc("192.168.136.51"), eidRecord.getLocatorRecord().get(1).getRloc());
}
Also used : AddMapping(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.AddMapping) MappingRecordItem(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItem) MappingRecord(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord) Test(org.junit.Test)

Example 15 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 MappingServiceIntegrationTest method registerAddress.

/*
    // This registers an IP with a MapRegister, then adds a password via the
    // northbound REST API
    // and checks that the password works
    public void testPasswordExactMatch() throws Exception {
        cleanUP();
        String ipString = "10.0.0.1";
        LispIpv4Address address = LispAddressUtil.asIPAfiAddress(ipString);
        int mask = 32;
        String pass = "pass";

        URL url = createPutURL("key");

        String jsonAuthData = createAuthKeyJSON(pass, address, mask);

        LOG.trace("Sending this JSON to LISP server: \n" + jsonAuthData);
        LOG.trace("Address: " + address);

        byte[] expectedSha = new byte[] { (byte) 146, (byte) 234, (byte) 52, (byte) 247, (byte) 186, (byte) 232,
                (byte) 31, (byte) 249, (byte) 87,
                (byte) 73, (byte) 234, (byte) 54, (byte) 225, (byte) 160, (byte) 129, (byte) 251, (byte) 73, (byte) 53,
                (byte) 196, (byte) 62 };

        byte[] zeros = new byte[20];

        callURL("PUT", "application/json", "text/plain", jsonAuthData, url);

        // build a MapRegister
        MapRegisterBuilder mapRegister = new MapRegisterBuilder();
        mapRegister.setWantMapNotify(true);
        mapRegister.setNonce((long) 8);
        EidToLocatorRecordBuilder etlr = new EidToLocatorRecordBuilder();
        etlr.setLispAddressContainer(LispAddressUtil.toContainer(address));
        etlr.setMaskLength((short) mask);
        etlr.setRecordTtl(254);
        LocatorRecordBuilder record = new LocatorRecordBuilder();
        record.setLispAddressContainer(LispAddressUtil.toContainer(locatorEid));
        etlr.setLocatorRecord(new ArrayList<LocatorRecord>());
        etlr.getLocatorRecord().add(record.build());
        mapRegister.setMappingRecordItem(new ArrayList<MappingRecordItem>());
        mapRegister.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(etlr.build()).build());

        mapRegister.setKeyId((short) 1); // LispKeyIDEnum.SHA1.getKeyID()
        mapRegister.setAuthenticationData(zeros);

        sendMapRegister(mapRegister.build());
        assertNoPacketReceived(3000);

        mapRegister.setAuthenticationData(expectedSha);

        sendMapRegister(mapRegister.build());

        assertMapNotifyReceived();
    }

    public void testPasswordMaskMatch() throws Exception {
        cleanUP();
        LispIpv4Address addressInRange = LispAddressUtil.asIPAfiAddress("10.20.30.40");
        LispIpv4Address addressOutOfRange = LispAddressUtil.asIPAfiAddress("20.40.30.40");
        LispIpv4Address range = LispAddressUtil.asIPAfiAddress("10.20.30.0");

        int mask = 32;
        String pass = "pass";

        URL url = createPutURL("key");
        String jsonAuthData = createAuthKeyJSON(pass, range, 8);

        callURL("PUT", "application/json", "text/plain", jsonAuthData, url);
        // build a MapRegister
        MapRegisterBuilder mapRegister = new MapRegisterBuilder();

        mapRegister.setWantMapNotify(true);
        mapRegister.setNonce((long) 8);
        EidToLocatorRecordBuilder etlr = new EidToLocatorRecordBuilder();
        etlr.setLispAddressContainer(LispAddressUtil.toContainer(addressInRange));
        etlr.setMaskLength((short) mask);
        etlr.setRecordTtl(254);
        LocatorRecordBuilder record = new LocatorRecordBuilder();
        record.setLispAddressContainer(LispAddressUtil.toContainer(locatorEid));
        record.setLispAddressContainer(LispAddressUtil.toContainer(locatorEid));
        etlr.setLocatorRecord(new ArrayList<LocatorRecord>());
        etlr.getLocatorRecord().add(record.build());
        mapRegister.setMappingRecordItem(new ArrayList<MappingRecordItem>());
        mapRegister.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(etlr.build()).build());

        mapRegister.setKeyId((short) 1); // LispKeyIDEnum.SHA1.getKeyID()
        mapRegister
                .setAuthenticationData(new byte[] { -15, -52, 38, -94, 125, -111, -68, -79, 68, 6, 101, 45, -1, 47, -4,
                -67, -113, 104, -110, -71 });

        sendMapRegister(mapRegister.build());

        assertMapNotifyReceived();

        etlr.setLispAddressContainer(LispAddressUtil.toContainer(addressOutOfRange));
        mapRegister
                .setAuthenticationData(new byte[] { -54, 68, -58, -91, -23, 22, -88, -31, 113, 39, 115, 78, -68, -123,
                -71, -14, -99, 67, -23, -73 });

        sendMapRegister(mapRegister.build());
        assertNoPacketReceived(3000);
    }
*/
// takes an address, packs it in a MapRegister and sends it
private void registerAddress(Eid eid) throws SocketTimeoutException {
    mapService.addAuthenticationKey(eid, NULL_AUTH_KEY);
    sleepForSeconds(1);
    MapRegister mapRegister = MappingServiceIntegrationTestUtil.getDefaultMapRegisterBuilder(eid).build();
    sendMapRegister(mapRegister);
    MapNotify mapNotify = receiveMapNotify();
    assertEquals(8, mapNotify.getNonce().longValue());
}
Also used : GotMapNotify(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.GotMapNotify) MapNotify(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapNotify) MapRegister(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapRegister)

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