use of org.opendaylight.lispflowmapping.lisp.type.MappingData in project lispflowmapping by opendaylight.
the class MappingSystem method restoreDaoFromDatastore.
/**
* Restore all mappings and keys from mdsal datastore.
*/
private void restoreDaoFromDatastore() {
List<AuthenticationKey> authKeys = dsbe.getAllAuthenticationKeys();
List<Mapping> mappings = dsbe.getAllMappings(LogicalDatastoreType.CONFIGURATION);
/*
* XXX By default, the operational datastore is not persisted to disk, either at run-time, or on shutdown,
* so the following will have no effect (getLastUpdateTimestamp() will fail, since it's reading from
* the operational datastore, and even if it didn't getAllMappings() will fail anyway). According to rovarga it
* should be possible to turn on persistence for the operational datastore editing
* etc/opendaylight/karaf/05-clustering.xml, by setting <persistence>true</persistence>. At the time of writing
* the below code block that didn't seem to work though.
*/
Long lastUpdateTimestamp = dsbe.getLastUpdateTimestamp();
if (lastUpdateTimestamp != null && System.currentTimeMillis() - lastUpdateTimestamp > ConfigIni.getInstance().getRegistrationValiditySb()) {
LOG.warn("Restore threshold passed, not restoring operational datastore into DAO");
} else {
mappings.addAll(dsbe.getAllMappings(LogicalDatastoreType.OPERATIONAL));
}
dsbe.removeLastUpdateTimestamp();
LOG.info("Restoring {} mappings and {} keys from datastore into DAO", mappings.size(), authKeys.size());
for (Mapping mapping : mappings) {
addMapping(mapping.getOrigin(), mapping.getMappingRecord().getEid(), new MappingData(mapping.getMappingRecord()));
}
for (AuthenticationKey authKey : authKeys) {
addAuthenticationKey(authKey.getEid(), authKey.getMappingAuthkey());
}
}
use of org.opendaylight.lispflowmapping.lisp.type.MappingData in project lispflowmapping by opendaylight.
the class MappingSystem method addNegativeMapping.
@Override
public MappingData addNegativeMapping(Eid key) {
MappingRecord mapping = buildNegativeMapping(key);
MappingData mappingData = new MappingData(mapping);
LOG.debug("Adding negative mapping for EID {}", LispAddressStringifier.getString(mapping.getEid()));
LOG.trace(mappingData.getString());
smc.addMapping(mapping.getEid(), mappingData);
dsbe.addMapping(DSBEInputUtil.toMapping(MappingOrigin.Southbound, mapping.getEid(), null, mappingData));
return mappingData;
}
use of org.opendaylight.lispflowmapping.lisp.type.MappingData in project lispflowmapping by opendaylight.
the class MappingSystem method handleMergedMapping.
private MappingData handleMergedMapping(Eid key) {
LOG.trace("Merging mappings for EID {}", LispAddressStringifier.getString(key));
List<MappingData> expiredMappingDataList = new ArrayList<>();
Set<IpAddressBinary> sourceRlocs = new HashSet<>();
MappingData mergedMappingData = MappingMergeUtil.mergeXtrIdMappings(smc.getAllXtrIdMappings(key), expiredMappingDataList, sourceRlocs);
for (MappingData mappingData : expiredMappingDataList) {
removeSbXtrIdSpecificMapping(key, mappingData.getXtrId(), mappingData);
}
if (mergedMappingData != null) {
smc.addMapping(key, mergedMappingData, sourceRlocs);
dsbe.addMapping(DSBEInputUtil.toMapping(MappingOrigin.Southbound, key, mergedMappingData));
addOrRefreshMappingInTimeoutService(key, mergedMappingData);
} else {
removeSbMapping(key, mergedMappingData);
}
return mergedMappingData;
}
use of org.opendaylight.lispflowmapping.lisp.type.MappingData 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.lisp.type.MappingData in project lispflowmapping by opendaylight.
the class MappingSystem method updateServicePathMappingRecord.
private MappingData updateServicePathMappingRecord(MappingData mappingData, Eid eid) {
// keep properties of original record
MappingRecordBuilder recordBuilder = new MappingRecordBuilder(mappingData.getRecord());
recordBuilder.setLocatorRecord(new ArrayList<LocatorRecord>());
// there should only be one locator record
if (mappingData.getRecord().getLocatorRecord().size() != 1) {
LOG.warn("MappingRecord associated to ServicePath EID has more than one locator!");
return mappingData;
}
LocatorRecord locatorRecord = mappingData.getRecord().getLocatorRecord().get(0);
long serviceIndex = ((ServicePath) eid.getAddress()).getServicePath().getServiceIndex();
int index = LispAddressUtil.STARTING_SERVICE_INDEX - (int) serviceIndex;
Rloc rloc = locatorRecord.getRloc();
if (rloc.getAddress() instanceof Ipv4 || rloc.getAddress() instanceof Ipv6) {
if (index != 0) {
LOG.warn("Service Index should be 255 for simple IP RLOCs!");
}
return mappingData;
} else if (rloc.getAddress() instanceof ExplicitLocatorPath) {
ExplicitLocatorPath elp = (ExplicitLocatorPath) rloc.getAddress();
List<Hop> hops = elp.getExplicitLocatorPath().getHop();
if (index < 0 || index > hops.size()) {
LOG.warn("Service Index out of bounds!");
return mappingData;
}
SimpleAddress nextHop = hops.get(index).getAddress();
LocatorRecordBuilder lrb = new LocatorRecordBuilder(locatorRecord);
lrb.setRloc(LispAddressUtil.toRloc(nextHop));
recordBuilder.getLocatorRecord().add(lrb.build());
return new MappingData(recordBuilder.build());
} else {
LOG.warn("Nothing to do with ServicePath mapping record");
return mappingData;
}
}
Aggregations