Search in sources :

Example 31 with MapRegister

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

the class LispAuthenticationTest method validate__SHA1.

@Test
public void validate__SHA1() throws Exception {
    // LISP(Type = 3 Map-Register, P=1, M=1
    // Record Counter: 1
    // Nonce: (something)
    // Key ID: 0x0001
    // AuthDataLength: 20 Data:
    // b2:dd:1a:25:c0:60:b1:46:e8:dc:6d:a6:ae:2e:92:92:a6:ca:b7:9d
    // 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 01 00 14 2c 61 b9 c9 9a 20 ba d8 f5 40 d3 55 6f 5f 6e 5a b2 0a bf b5 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, 1, PASSWORD));
    assertFalse(validate(mapRegister, byteBuffer, EID, 1, 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 32 with MapRegister

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

the class LispAuthenticationTest method validate_WrongAuthentication.

@Test
public void validate_WrongAuthentication() throws Exception {
    // LISP(Type = 3 Map-Register, P=1, M=1
    // Record Counter: 1
    // Nonce: (something)
    // Key ID: 0x0001
    // AuthDataLength: 20 Data:
    // e8:f5:0b:c5:c5:f2:b0:21:27:a8:21:41:04:f3:46:5a:5a:5b:5c:5d
    // 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 01 00 14 e8 f5 0b c5 c5 f2 " + "b0 21 27 a8 21 41 04 f3 46 5a 5a 5b 5c 5d 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);
    assertFalse(validate(mapRegister, byteBuffer, EID, 1, 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 33 with MapRegister

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

the class AuthenticationKeyDataListener method authKeysForEidsUnchanged.

/**
 * We maintain a HashMap with the update times of AuthenticationKey objects in the updatedEntries field. We keep
 * entries in the HashMap for the Map-Register cache timeout interval, and lazy remove them afterwards. As a result
 * the same EID will be considered updated during that interval, even on subsequent queries. This is necessary
 * because more than one xTR may register the same EID, and to avoid complexity we don't store origin information.
 * The performance trade-off is not significant, because during a typical cache timeout the same xTR will send only
 * a few registration packets (2 for the default value of 90s, when UDP Map-Registers are sent at 1 minute
 * intervals).
 *
 * @param eids List of EIDs to check
 * @param timeout MapRegister cache timeout value
 * @return false if any of the EIDs in the eids list was updated in the last timout period, true otherwise
 */
public synchronized boolean authKeysForEidsUnchanged(List<EidLispAddress> eids, long timeout) {
    boolean result = true;
    Long currentTime = System.currentTimeMillis();
    for (EidLispAddress eidLispAddress : eids) {
        Long updateTime = updatedEntries.get(eidLispAddress.getEid());
        if (updateTime != null) {
            result = false;
            if (currentTime - updateTime > timeout) {
                updatedEntries.remove(eidLispAddress.getEid());
            }
        }
    }
    return result;
}
Also used : EidLispAddress(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.map.register.cache.metadata.container.map.register.cache.metadata.EidLispAddress)

Example 34 with MapRegister

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

the class MapServer method handleMapRegister.

@SuppressWarnings("unchecked")
public void handleMapRegister(MapRegister mapRegister) {
    boolean mappingUpdated = false;
    boolean merge = ConfigIni.getInstance().mappingMergeIsSet() && mapRegister.isMergeEnabled();
    MappingRecord oldMapping;
    if (merge) {
        if (!mapRegister.isXtrSiteIdPresent() || mapRegister.getXtrId() == null) {
            LOG.error("Merge bit is set in Map-Register, but xTR-ID is not present. Will not merge.");
            merge = false;
        } else if (Arrays.equals(mapRegister.getXtrId().getValue(), ALL_ZEROES_XTR_ID)) {
            LOG.warn("Merge bit is set in Map-Register, but xTR-ID is all zeroes.");
        }
    }
    for (MappingRecordItem record : mapRegister.getMappingRecordItem()) {
        MappingRecord mapping = record.getMappingRecord();
        Eid eid = mapping.getEid();
        MappingData mappingData = new MappingData(mapping, System.currentTimeMillis());
        mappingData.setMergeEnabled(merge);
        mappingData.setXtrId(mapRegister.getXtrId());
        oldMapping = getMappingRecord(mapService.getMapping(MappingOrigin.Southbound, eid));
        mapService.addMapping(MappingOrigin.Southbound, eid, getSiteId(mapRegister), mappingData);
        if (merge) {
            MappingRecord newMapping = getMappingRecord(mapService.getMapping(MappingOrigin.Southbound, eid));
            if (MappingRecordUtil.mappingChanged(oldMapping, newMapping)) {
                // If there is a SB mapping change with merge on, Map-Notify will be sent to ALL xTRs, not jus the
                // one registering (merging is done in the MappingSystem code)
                mappingUpdated = true;
            }
        }
    }
    if (BooleanUtils.isTrue(mapRegister.isWantMapNotify())) {
        LOG.trace("MapRegister wants MapNotify");
        MapNotifyBuilder builder = new MapNotifyBuilder();
        List<TransportAddress> rlocs = null;
        if (merge) {
            Set<IpAddressBinary> notifyRlocs = new HashSet<IpAddressBinary>();
            List<MappingRecordItem> mergedMappings = new ArrayList<MappingRecordItem>();
            for (MappingRecordItem record : mapRegister.getMappingRecordItem()) {
                MappingRecord mapping = record.getMappingRecord();
                MappingRecord currentRecord = getMappingRecord(mapService.getMapping(MappingOrigin.Southbound, mapping.getEid()));
                mergedMappings.add(new MappingRecordItemBuilder().setMappingRecord(currentRecord).build());
                Set<IpAddressBinary> sourceRlocs = (Set<IpAddressBinary>) mapService.getData(MappingOrigin.Southbound, mapping.getEid(), SubKeys.SRC_RLOCS);
                if (sourceRlocs != null) {
                    notifyRlocs.addAll(sourceRlocs);
                }
            }
            MapNotifyBuilderHelper.setFromMapRegisterAndMappingRecordItems(builder, mapRegister, mergedMappings);
            // send map-notify to merge group only when mapping record is changed
            if (mappingUpdated) {
                rlocs = getTransportAddresses(notifyRlocs);
            }
        } else {
            MapNotifyBuilderHelper.setFromMapRegister(builder, mapRegister);
        }
        List<MappingRecordItem> mappings = builder.getMappingRecordItem();
        if (mappings != null && mappings.get(0) != null && mappings.get(0).getMappingRecord() != null && mappings.get(0).getMappingRecord().getEid() != null) {
            MappingAuthkey authkey = mapService.getAuthenticationKey(mappings.get(0).getMappingRecord().getEid());
            if (authkey != null) {
                builder.setAuthenticationData(LispAuthenticationUtil.createAuthenticationData(builder.build(), authkey.getKeyString()));
            }
        }
        notifyHandler.handleMapNotify(builder.build(), rlocs);
    }
}
Also used : Eid(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid) MappingRecordItemBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItemBuilder) Set(java.util.Set) HashSet(java.util.HashSet) MappingRecordItem(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItem) TransportAddress(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.transport.address.TransportAddress) ArrayList(java.util.ArrayList) IpAddressBinary(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.inet.binary.types.rev160303.IpAddressBinary) 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) MappingData(org.opendaylight.lispflowmapping.lisp.type.MappingData) MapNotifyBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapnotifymessage.MapNotifyBuilder) HashSet(java.util.HashSet)

Example 35 with MapRegister

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

the class MapServerTest method handleMapRegisterTest_MappingMergeTrue.

@Test
public void handleMapRegisterTest_MappingMergeTrue() throws NoSuchFieldException, IllegalAccessException {
    setConfigIniMappingMergeField(true);
    final MappingRecordItemBuilder mappingRecordItemBuilder = new MappingRecordItemBuilder().setMappingRecord(OLD_MAPPING_RECORD_1);
    final MapNotifyBuilder mapNotifyBuilder = getDefaultMapNotifyBuilder(mapRegister).setMappingRecordItem(new ArrayList<>());
    mapNotifyBuilder.getMappingRecordItem().add(mappingRecordItemBuilder.build());
    // no mapping changes
    Mockito.when(mapService.getMapping(MappingOrigin.Southbound, IPV4_EID_1)).thenReturn(OLD_MAPPING_DATA_1);
    mappingData.setMergeEnabled(true);
    mapServer.handleMapRegister(mapRegister);
    final ArgumentCaptor<MappingData> captor = ArgumentCaptor.forClass(MappingData.class);
    Mockito.verify(mapService).addMapping(Mockito.eq(MappingOrigin.Southbound), Mockito.eq(IPV4_EID_1), Mockito.eq(mapRegister.getSiteId()), captor.capture());
    assertEquals(captor.getValue().getRecord(), mappingData.getRecord());
    Mockito.verify(notifyHandler).handleMapNotify(mapNotifyBuilder.setAuthenticationData(null).build(), null);
}
Also used : MappingRecordItemBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItemBuilder) MappingData(org.opendaylight.lispflowmapping.lisp.type.MappingData) MapNotifyBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapnotifymessage.MapNotifyBuilder) Test(org.junit.Test)

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