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);
}
}
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);
}
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);
}
Aggregations