Search in sources :

Example 11 with MapNotifyBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapnotifymessage.MapNotifyBuilder 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 12 with MapNotifyBuilder

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

Example 13 with MapNotifyBuilder

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

the class MapServerTest method handleMapRegisterTest_verifyTransportAddresses.

@Test
public void handleMapRegisterTest_verifyTransportAddresses() throws NoSuchFieldException, IllegalAccessException {
    setConfigIniMappingMergeField(true);
    // input
    Mockito.when(mapService.getAuthenticationKey(IPV4_EID_1)).thenReturn(MAPPING_AUTHKEY);
    Mockito.when(mapService.getMapping(MappingOrigin.Southbound, IPV4_EID_1)).thenReturn(OLD_MAPPING_DATA_1).thenReturn(OLD_MAPPING_DATA_2).thenReturn(getDefaultMappingData(getDefaultMappingRecordBuilder().build()));
    Mockito.when(mapService.getData(MappingOrigin.Southbound, IPV4_EID_1, SubKeys.SUBSCRIBERS)).thenReturn(subscriberSetMock_1);
    Mockito.when(mapService.getData(MappingOrigin.Southbound, IPV4_EID_1, SubKeys.SRC_RLOCS)).thenReturn(DEFAULT_IP_ADDRESS_SET);
    // result
    final List<TransportAddress> transportAddressList = getTransportAddressList();
    final MapNotifyBuilder mapNotifyBuilder = getDefaultMapNotifyBuilder(mapRegister);
    mapNotifyBuilder.setMappingRecordItem(new ArrayList<>());
    mapNotifyBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(getDefaultMappingRecordBuilder().build()).build());
    mapServer.handleMapRegister(mapRegister);
    Mockito.verify(notifyHandler).handleMapNotify(mapNotifyBuilder.build(), transportAddressList);
}
Also used : MappingRecordItemBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItemBuilder) TransportAddress(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.transport.address.TransportAddress) MapNotifyBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapnotifymessage.MapNotifyBuilder) Test(org.junit.Test)

Aggregations

MapNotifyBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapnotifymessage.MapNotifyBuilder)13 MappingRecordItemBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItemBuilder)9 Test (org.junit.Test)8 MappingRecordItem (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItem)8 MappingRecordBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder)7 ByteBuffer (java.nio.ByteBuffer)4 ArrayList (java.util.ArrayList)3 MappingData (org.opendaylight.lispflowmapping.lisp.type.MappingData)2 MapNotify (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapNotify)2 LocatorRecord (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecord)2 TransportAddress (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.transport.address.TransportAddress)2 SendMapNotifyInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.sb.rev150904.SendMapNotifyInputBuilder)2 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Before (org.junit.Before)1 DataBroker (org.opendaylight.controller.md.sal.binding.api.DataBroker)1 LispSerializationException (org.opendaylight.lispflowmapping.lisp.serializer.exception.LispSerializationException)1 ConcurrentLispSouthboundStats (org.opendaylight.lispflowmapping.southbound.ConcurrentLispSouthboundStats)1 LispSouthboundPlugin (org.opendaylight.lispflowmapping.southbound.LispSouthboundPlugin)1 MapRegisterCache (org.opendaylight.lispflowmapping.southbound.lisp.cache.MapRegisterCache)1