use of org.opendaylight.lispflowmapping.interfaces.dao.Subscriber in project lispflowmapping by opendaylight.
the class MappingSystem method removeMapping.
@Override
public void removeMapping(MappingOrigin origin, Eid key) {
Eid dstAddr = null;
Set<Subscriber> subscribers = null;
Set<Subscriber> dstSubscribers = null;
MappingData mapping = (MappingData) tableMap.get(origin).getMapping(null, key);
if (LOG.isDebugEnabled()) {
LOG.debug("Removing mapping for EID {} from {}", LispAddressStringifier.getString(key), origin);
}
if (LOG.isTraceEnabled() && mapping != null) {
LOG.trace(mapping.getString());
}
MappingRecord notificationMapping = null;
if (mapping != null) {
notificationMapping = mapping.getRecord();
subscribers = getSubscribers(key);
// For SrcDst LCAF also send SMRs to Dst prefix
if (key.getAddress() instanceof SourceDestKey) {
dstAddr = SourceDestKeyHelper.getDstBinary(key);
dstSubscribers = getSubscribers(dstAddr);
}
}
removeSubscribersConditionally(origin, key);
if (origin == MappingOrigin.Southbound) {
removeFromSbTimeoutService(key);
}
if (origin == MappingOrigin.Southbound && mapping != null && mapping.isPositive().or(false)) {
mergeNegativePrefixes(key);
} else {
// mergeNegativePrefixes() above removes the mapping, so addNegativeMapping() will work correctly
tableMap.get(origin).removeMapping(key);
}
if (notificationMapping != null) {
publishNotification(notificationMapping, key, subscribers, dstSubscribers, MappingChange.Removed);
notifyChildren(key, notificationMapping, MappingChange.Removed);
if (dstAddr != null) {
notifyChildren(dstAddr, notificationMapping, MappingChange.Removed);
}
}
}
use of org.opendaylight.lispflowmapping.interfaces.dao.Subscriber in project lispflowmapping by opendaylight.
the class MapServer method onMappingChanged.
@Override
public void onMappingChanged(MappingChanged notification) {
if (subscriptionService) {
Eid eid = notification.getEid();
if (eid == null) {
eid = notification.getMappingRecord().getEid();
}
LOG.trace("MappingChanged event for {} of type: `{}'", LispAddressStringifier.getString(eid), notification.getChangeType());
Set<Subscriber> subscribers = MSNotificationInputUtil.toSubscriberSet(notification.getSubscriberItem());
LoggingUtil.logSubscribers(LOG, eid, subscribers);
if (mapService.isMaster()) {
sendSmrs(eid, subscribers);
if (eid.getAddress() instanceof SourceDestKey) {
Set<Subscriber> dstSubscribers = MSNotificationInputUtil.toSubscriberSetFromDst(notification.getDstSubscriberItem());
LoggingUtil.logSubscribers(LOG, SourceDestKeyHelper.getDstBinary(eid), dstSubscribers);
sendSmrs(SourceDestKeyHelper.getDstBinary(eid), dstSubscribers);
}
}
}
}
use of org.opendaylight.lispflowmapping.interfaces.dao.Subscriber in project lispflowmapping by opendaylight.
the class MapResolverTest method isEqualIpVersionTest.
/**
* Tests {@link MapResolver#isEqualIpVersion} method.
*/
@Test
@Ignore
public void isEqualIpVersionTest() {
// input mapping
final LocatorRecordBuilder locatorRecordBuilder = getDefaultLocatorBuilder();
final MappingRecordBuilder mappingRecordBuilder = getDefaultMappingRecordBuilder();
mappingRecordBuilder.getLocatorRecord().add(locatorRecordBuilder.build());
final MappingData mappingData = getDefaultMappingData(mappingRecordBuilder.build());
Mockito.when(mapServiceMock.getMapping(mapRequestBuilder.getSourceEid().getEid(), IPV4_PREFIX_EID_1)).thenReturn(mappingData);
Mockito.when(mapServiceMock.getData(MappingOrigin.Southbound, IPV4_PREFIX_EID_1, SubKeys.SUBSCRIBERS)).thenReturn(subscriberSetMock);
Mockito.when(subscriberSetMock.contains(Mockito.any(Subscriber.class))).thenReturn(false);
// ----------------------
// with sourceRloc = null
List<ItrRloc> itrRlocList = Lists.newArrayList(newItrRloc(MacAfi.class, null), newItrRloc(Ipv4BinaryAfi.class, IPV4_ADDRESS));
ArgumentCaptor<Subscriber> captor = ArgumentCaptor.forClass(Subscriber.class);
mapResolver.handleMapRequest(mapRequestBuilder.setSourceRloc(null).setItrRloc(itrRlocList).build());
Mockito.verify(subscriberSetMock).add(captor.capture());
// Since mapRequest's sourceRloc is null, first ItrRloc from the itrRlocList must be used.
assertEquals(MacAfi.class, captor.getValue().getSrcRloc().getAddressType());
// ----------------------
// with sourceRloc address = itrRloc address
itrRlocList = Lists.newArrayList(newItrRloc(MacAfi.class, null), newItrRloc(Ipv4BinaryAfi.class, IPV4_ADDRESS));
MapRequest mapRequest = mapRequestBuilder.setSourceRloc(IPV4_ADDRESS_BINARY_1).setItrRloc(itrRlocList).build();
captor = ArgumentCaptor.forClass(Subscriber.class);
mapResolver.handleMapRequest(mapRequest);
Mockito.verify(subscriberSetMock, Mockito.times(2)).add(captor.capture());
assertEquals(IPV4_ADDRESS, captor.getValue().getSrcRloc().getAddress());
// ----------------------
// with sourceRloc address Afi = itrRloc address Afi (for Ipv4)
itrRlocList = Lists.newArrayList(newItrRloc(MacAfi.class, null), newItrRloc(Ipv6Afi.class, IPV6_ADDRESS), newItrRloc(Ipv4Afi.class, IPV4_ADDRESS));
mapRequest = mapRequestBuilder.setSourceRloc(IPV6_ADDRESS_BINARY).setItrRloc(itrRlocList).build();
captor = ArgumentCaptor.forClass(Subscriber.class);
mapResolver.handleMapRequest(mapRequest);
Mockito.verify(subscriberSetMock, Mockito.times(3)).add(captor.capture());
assertEquals(IPV6_ADDRESS, captor.getValue().getSrcRloc().getAddress());
// ----------------------
// with sourceRloc address Afi = itrRloc address Afi (for Ipv6)
itrRlocList = Lists.newArrayList(newItrRloc(MacAfi.class, null), newItrRloc(Ipv6Afi.class, IPV6_ADDRESS), newItrRloc(Ipv4Afi.class, IPV4_ADDRESS));
mapRequest = mapRequestBuilder.setSourceRloc(IPV4_ADDRESS_BINARY_2).setItrRloc(itrRlocList).build();
captor = ArgumentCaptor.forClass(Subscriber.class);
mapResolver.handleMapRequest(mapRequest);
Mockito.verify(subscriberSetMock, Mockito.times(4)).add(captor.capture());
assertEquals(IPV4_ADDRESS, captor.getValue().getSrcRloc().getAddress());
// ----------------------
// with no common ip address nor Afi
final Mac mac = new MacBuilder().setMac(new MacAddress("aa:bb:cc:dd:ee:ff")).build();
itrRlocList = Lists.newArrayList(newItrRloc(MacAfi.class, mac), newItrRloc(NoAddressAfi.class, Mockito.mock(NoAddress.class)));
mapRequest = mapRequestBuilder.setSourceRloc(IPV4_ADDRESS_BINARY_1).setItrRloc(itrRlocList).build();
captor = ArgumentCaptor.forClass(Subscriber.class);
mapResolver.handleMapRequest(mapRequest);
Mockito.verify(subscriberSetMock, Mockito.times(5)).add(captor.capture());
assertEquals(mac, captor.getValue().getSrcRloc().getAddress());
}
use of org.opendaylight.lispflowmapping.interfaces.dao.Subscriber in project lispflowmapping by opendaylight.
the class MapServerTest method handleMapRegisterTest_findNegativeSubscribers.
@Test
@Ignore
public void handleMapRegisterTest_findNegativeSubscribers() throws NoSuchFieldException, IllegalAccessException {
setConfigIniMappingMergeField(true);
mapRegister.getMappingRecordItem().clear();
mapRegister.getMappingRecordItem().add(getDefaultMappingRecordItemBuilder(IPV4_PREFIX_EID_1).build());
final MappingRecordBuilder mappingRecordBuilder_1 = getDefaultMappingRecordBuilder().setEid(IPV4_PREFIX_EID_2);
final MappingRecordBuilder mappingRecordBuilder_2 = getDefaultMappingRecordBuilder();
final Eid maskedEid1 = LispAddressUtil.asIpv4Eid("1.2.0.0");
final Subscriber subscriber1 = Mockito.mock(Subscriber.class);
Mockito.when(subscriber1.timedOut()).thenReturn(true);
Mockito.when(subscriber1.toString()).thenReturn("sub1");
final Set<Subscriber> set1 = Sets.newHashSet(subscriber1);
Mockito.when(mapService.getAuthenticationKey(IPV4_PREFIX_EID_1)).thenReturn(MAPPING_AUTHKEY);
Mockito.when(mapService.getData(MappingOrigin.Southbound, IPV4_PREFIX_EID_1, SubKeys.SRC_RLOCS)).thenReturn(DEFAULT_IP_ADDRESS_SET);
Mockito.when(mapService.getParentPrefix(IPV4_PREFIX_EID_1)).thenReturn(maskedEid1);
Mockito.when(mapService.getData(MappingOrigin.Southbound, IPV4_PREFIX_EID_1, SubKeys.SUBSCRIBERS)).thenReturn(null);
Mockito.when(mapService.getData(MappingOrigin.Southbound, maskedEid1, SubKeys.SUBSCRIBERS)).thenReturn(set1);
Mockito.when(mapService.getMapping(MappingOrigin.Southbound, IPV4_PREFIX_EID_1)).thenReturn(getDefaultMappingData(mappingRecordBuilder_1.build())).thenReturn(getDefaultMappingData(mappingRecordBuilder_2.build())).thenReturn(null);
mapServer.handleMapRegister(mapRegister);
Mockito.verify(subscriber1).timedOut();
}
Aggregations