use of org.opendaylight.lispflowmapping.interfaces.dao.Subscriber in project lispflowmapping by opendaylight.
the class MapServer method handleSmr.
private void handleSmr(Eid eid, Set<Subscriber> subscribers) {
sendSmrs(eid, subscribers);
// For SrcDst LCAF also send SMRs to Dst prefix
if (eid.getAddress() instanceof SourceDestKey) {
Eid dstAddr = SourceDestKeyHelper.getDstBinary(eid);
Set<Subscriber> dstSubs = mapService.getSubscribers(dstAddr);
sendSmrs(dstAddr, dstSubs);
}
}
use of org.opendaylight.lispflowmapping.interfaces.dao.Subscriber in project lispflowmapping by opendaylight.
the class MappingServiceIntegrationTest method testRepeatedSmr.
private void testRepeatedSmr() throws SocketTimeoutException, UnknownHostException {
cleanUP();
long timeout = ConfigIni.getInstance().getSmrTimeout();
ConfigIni.getInstance().setSmrRetryCount(5);
final InstanceIdType iid = new InstanceIdType(1L);
final Eid eid1 = LispAddressUtil.asIpv4Eid("1.1.1.1", 1L);
final Eid subscriberEid = LispAddressUtil.asIpv4Eid("2.2.2.2", 1L);
final int expectedSmrs1 = 2;
final int expectedSmrs2 = 3;
/* set auth */
final Eid eid = LispAddressUtil.asIpv4PrefixBinaryEid("0.0.0.0/0", iid);
mapService.addAuthenticationKey(eid, NULL_AUTH_KEY);
/* add subscribers */
final String subscriberSrcRloc1 = "127.0.0.3";
final String subscriberSrcRloc2 = "127.0.0.4";
final Set<Subscriber> subscriberSet1 = Sets.newHashSet(newSubscriber(subscriberEid, subscriberSrcRloc1), newSubscriber(subscriberEid, subscriberSrcRloc2));
mapService.addData(MappingOrigin.Southbound, eid1, SubKeys.SUBSCRIBERS, subscriberSet1);
final SocketReader reader1 = startSocketReader(subscriberSrcRloc1, 15000);
final SocketReader reader2 = startSocketReader(subscriberSrcRloc2, 15000);
sleepForSeconds(1);
/* add mapping */
final MappingRecord mapping1 = new MappingRecordBuilder().setEid(eid1).setTimestamp(System.currentTimeMillis()).setRecordTtl(1440).build();
mapService.addMapping(MappingOrigin.Northbound, eid1, null, new MappingData(mapping1));
sleepForMilliseconds((timeout * expectedSmrs1) - (timeout / 2));
final List<MapRequest> requests1 = processSmrPackets(reader1, subscriberSrcRloc1, expectedSmrs1);
final MapReply mapReply1 = lms.handleMapRequest(new MapRequestBuilder(requests1.get(0)).setSourceEid(new SourceEidBuilder().setEid(subscriberEid).build()).setItrRloc(Lists.newArrayList(new ItrRlocBuilder().setRloc(LispAddressUtil.asIpv4Rloc(subscriberSrcRloc1)).build())).setEidItem(Lists.newArrayList(new EidItemBuilder().setEid(eid1).build())).setSmrInvoked(true).setSmr(false).build());
// sleep to get 1 extra smr request
sleepForMilliseconds(timeout * 1);
final List<MapRequest> requests2 = processSmrPackets(reader2, subscriberSrcRloc2, expectedSmrs2);
final MapReply mapReply2 = lms.handleMapRequest(new MapRequestBuilder(requests2.get(0)).setSourceEid(new SourceEidBuilder().setEid(subscriberEid).build()).setItrRloc(Lists.newArrayList(new ItrRlocBuilder().setRloc(LispAddressUtil.asIpv4Rloc(subscriberSrcRloc2)).build())).setEidItem(Lists.newArrayList(new EidItemBuilder().setEid(eid1).build())).setSmrInvoked(true).setSmr(false).build());
sleepForSeconds(3);
assertEquals(expectedSmrs1, requests1.size());
assertEquals(expectedSmrs2, requests2.size());
assertEquals((long) mapReply1.getNonce(), (long) requests1.get(0).getNonce());
assertEquals((long) mapReply2.getNonce(), (long) requests2.get(0).getNonce());
assertNextBufferEmpty(reader1);
assertNextBufferEmpty(reader2);
reader1.stopReading();
reader2.stopReading();
}
use of org.opendaylight.lispflowmapping.interfaces.dao.Subscriber in project lispflowmapping by opendaylight.
the class LispMapCacheStringifier method prettyPrintMTMCMappings.
@SuppressWarnings("unchecked")
public static String prettyPrintMTMCMappings(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;
case SubKeys.LCAF_SRCDST:
((ILispDAO) value).getAll(this);
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 LispMapCacheStringifier method prettyPrintSubscriberSet.
/**
* Given a Set of Subscriber objects, and the level of indentation, create a nicely formatted String to be added
* to a map-cache print-out in a tabular form.
*
* @param subscribers the Set of Subscriber objects to be printed
* @param indentation indentation level
* @return the formatted String
*/
public static String prettyPrintSubscriberSet(Set<Subscriber> subscribers, int indentation) {
final String indent = new String(new char[indentation]).replace("\0", " ");
StringBuilder sb = new StringBuilder(indent);
sb.append(" -----------------------------------------------------------------\n");
sb.append(indent);
if (subscribers == null) {
return sb.append(" No subscribers").toString();
}
sb.append("-> Subscriber RLOC Subscriber EID\n ");
sb.append(indent);
boolean first = true;
for (Subscriber subscriber : subscribers) {
if (first) {
first = false;
} else {
sb.append("\n ");
sb.append(indent);
}
String srcRloc = LispAddressStringifier.getString(subscriber.getSrcRloc());
int padLen = Constants.INET6_ADDRSTRLEN + 2 - srcRloc.length();
sb.append(srcRloc);
sb.append(new String(new char[padLen]).replace("\0", " "));
sb.append(LispAddressStringifier.getString(subscriber.getSrcEid()));
}
return sb.toString();
}
use of org.opendaylight.lispflowmapping.interfaces.dao.Subscriber in project lispflowmapping by opendaylight.
the class MappingSystem method notifyChange.
public void notifyChange(Eid eid, MappingRecord mapping, MappingChange mappingChange) {
Set<Subscriber> subscribers = getSubscribers(eid);
Set<Subscriber> dstSubscribers = null;
// For SrcDst LCAF also send SMRs to Dst prefix
if (eid.getAddress() instanceof SourceDestKey) {
Eid dstAddr = SourceDestKeyHelper.getDstBinary(eid);
dstSubscribers = getSubscribers(dstAddr);
notifyChildren(dstAddr, mapping, mappingChange);
}
// No reason to send a notification when no subscribers exist
if (subscribers != null || dstSubscribers != null) {
publishNotification(mapping, eid, subscribers, dstSubscribers, mappingChange);
}
notifyChildren(eid, mapping, mappingChange);
}
Aggregations