use of org.opendaylight.lispflowmapping.interfaces.dao.Subscriber in project lispflowmapping by opendaylight.
the class LispMapCacheStringifier method prettyPrintSMCMappings.
@SuppressWarnings("unchecked")
public static String prettyPrintSMCMappings(ILispDAO dao) {
final StringBuilder sb = new StringBuilder();
final IRowVisitor mappingVisitor = (new IRowVisitor() {
public void visitRow(Object keyId, String valueKey, Object value) {
switch(valueKey) {
case SubKeys.RECORD:
MappingData md = (MappingData) value;
sb.append(Stringifier.getString(md.getRecord(), 2));
sb.append("\n");
break;
case SubKeys.SUBSCRIBERS:
Set<Subscriber> subscribers = (Set<Subscriber>) value;
sb.append(prettyPrintSubscriberSet(subscribers, 4));
sb.append("\n");
break;
default:
break;
}
}
});
dao.getAll(new IRowVisitor() {
String lastKey = "";
public void visitRow(Object keyId, String valueKey, Object value) {
String key = keyId.getClass().getSimpleName() + "#" + keyId;
if (!lastKey.equals(key)) {
sb.append("Instance ID " + keyId + "\n");
}
if (valueKey.equals(SubKeys.VNI)) {
((ILispDAO) value).getAll(mappingVisitor);
}
lastKey = key;
}
});
return sb.toString();
}
use of org.opendaylight.lispflowmapping.interfaces.dao.Subscriber in project lispflowmapping by opendaylight.
the class MappingServiceIntegrationTest method newSubscriber.
private static Subscriber newSubscriber(Eid srcEid, String srcRlocIp) {
final int timeout = 5;
final Rloc srcRloc = LispAddressUtil.asIpv4Rloc(srcRlocIp);
return new Subscriber(srcRloc, srcEid, timeout);
}
use of org.opendaylight.lispflowmapping.interfaces.dao.Subscriber in project lispflowmapping by opendaylight.
the class MapResolverTest method handleMapRequest__withSubscribersToRemove.
/**
* Tests {@link MapResolver#handleMapRequest} method.
*/
@Test
@Ignore
public void handleMapRequest__withSubscribersToRemove() {
// input mapping
final LocatorRecordBuilder locatorRecordBuilder = getDefaultLocatorBuilder();
final MappingRecordBuilder mappingRecordBuilder = getDefaultMappingRecordBuilder();
mappingRecordBuilder.getLocatorRecord().add(locatorRecordBuilder.build());
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);
Subscriber subscriberMock = new Subscriber(mapRequestBuilder.getItrRloc().get(0).getRloc(), mapRequestBuilder.getSourceEid().getEid(), Subscriber.DEFAULT_SUBSCRIBER_TIMEOUT);
subscriberMock.setSubscriberTtlByRecordTtl(mappingRecordBuilder.getRecordTtl());
Mockito.when(subscriberSetMock.contains(subscriberMock)).thenReturn(true);
// result
final MapReplyBuilder mapReplyBuilder = getDefaultMapReplyBuilder();
mapReplyBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(mappingRecordBuilder.build()).build());
// check if a subscriber is re-instantiating when there already is one in the subscriber set
mapResolver.handleMapRequest(mapRequestBuilder.build());
Mockito.verify(subscriberSetMock).remove(subscriberMock);
Mockito.verify(subscriberSetMock).add(subscriberMock);
Mockito.verify(lispMappingServiceMock).handleMapReply(mapReplyBuilder.build());
Mockito.verify(mapServiceMock).addData(MappingOrigin.Southbound, IPV4_PREFIX_EID_1, SubKeys.SUBSCRIBERS, subscriberSetMock);
// verify that itrRloc is subscribed to dst address
mappingRecordBuilder.setEid(SOURCE_DEST_KEY_EID);
mapRequestBuilder.getEidItem().add(new EidItemBuilder().setEid(IPV4_PREFIX_EID_2).build());
mappingData = getDefaultMappingData(mappingRecordBuilder.build());
Mockito.when(mapServiceMock.getMapping(mapRequestBuilder.getSourceEid().getEid(), IPV4_PREFIX_EID_2)).thenReturn(mappingData);
mapResolver.handleMapRequest(mapRequestBuilder.build());
Mockito.verify(mapServiceMock).getData(MappingOrigin.Southbound, SourceDestKeyHelper.getDstBinary(SOURCE_DEST_KEY_EID), SubKeys.SUBSCRIBERS);
}
use of org.opendaylight.lispflowmapping.interfaces.dao.Subscriber in project lispflowmapping by opendaylight.
the class MappingSystem method notifyChildren.
private void notifyChildren(Eid eid, MappingRecord mapping, MappingChange mappingChange) {
// Update/created only happens for NB mappings. We assume no overlapping prefix support for NB mappings - so
// this NB mapping should not have any children. Both for NB first and NB&SB cases all subscribers for SB
// prefixes that are equal or more specific to this NB prefix have to be notified of the potential change.
// Each subscriber is notified for the prefix that it is currently subscribed to, and MS should return to them
// a Map-Reply with the same prefix and update mapping in cases of EID_INTERSECTION_RLOC_NB_FIRST which is a
// new option we are creating TODO
Set<Eid> childPrefixes = getSubtree(MappingOrigin.Southbound, eid);
if (childPrefixes == null || childPrefixes.isEmpty()) {
return;
}
childPrefixes.remove(eid);
for (Eid prefix : childPrefixes) {
Set<Subscriber> subscribers = getSubscribers(prefix);
// No reason to send a notification when no subscribers exist
if (subscribers != null) {
publishNotification(mapping, prefix, subscribers, null, mappingChange);
}
}
}
use of org.opendaylight.lispflowmapping.interfaces.dao.Subscriber in project lispflowmapping by opendaylight.
the class MapResolver method updateSubscribers.
private void updateSubscribers(Rloc itrRloc, Eid reqEid, Eid mapEid, Eid srcEid, Integer recordTtl) {
Subscriber subscriber = new Subscriber(itrRloc, srcEid, Subscriber.recordTtlToSubscriberTime(recordTtl));
Eid subscribedEid = mapEid;
// mapping will be pushed to dst as well (see sendSMRs in MapServer)
if (mapEid.getAddressType().equals(SourceDestKeyLcaf.class) && !reqEid.getAddressType().equals(SourceDestKeyLcaf.class)) {
subscribedEid = SourceDestKeyHelper.getDstBinary(mapEid);
}
mapService.subscribe(subscriber, subscribedEid);
}
Aggregations