import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.MappingOrigin;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.SiteId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.mapping.authkey.container.MappingAuthkey;
/**
*/
void addMapping(MappingOrigin origin, Eid key, Object data);
+ /**
+ * Add mapping and persist to datastore
+ *
+ * @param origin
+ * Table where mapping should be added
+ * @param siteId
+ * SiteID of SB device doing the registration
+ * @param key
+ * Key of the mapping
+ * @param data
+ * Value to be stored
+ */
+ void addMapping(MappingOrigin origin, SiteId siteId, Eid key, Object data);
+
/**
* Retrieves mapping for the provided src and dst key.
*
@Override
public void addMapping(MappingOrigin origin, Eid key, SiteId siteId, Object data) {
- dsbe.addMapping(DSBEInputUtil.toMapping(origin, key, siteId, (MappingRecord) data));
- mappingSystem.updateMappingRegistration(origin, key);
+ // SB registrations are first written to the MappingSystem and only afterwards are persisted to the datastore
+ if (origin.equals(MappingOrigin.Southbound)) {
+ mappingSystem.addMapping(origin, siteId, key, data);
+ } else {
+ dsbe.addMapping(DSBEInputUtil.toMapping(origin, key, siteId, (MappingRecord) data));
+ }
}
@Override
import org.opendaylight.lispflowmapping.implementation.mapcache.MultiTableMapCache;
import org.opendaylight.lispflowmapping.implementation.mapcache.SimpleMapCache;
import org.opendaylight.lispflowmapping.implementation.mdsal.DataStoreBackEnd;
+import org.opendaylight.lispflowmapping.implementation.util.DSBEInputUtil;
import org.opendaylight.lispflowmapping.implementation.util.MappingMergeUtil;
import org.opendaylight.lispflowmapping.interfaces.dao.ILispDAO;
import org.opendaylight.lispflowmapping.interfaces.mapcache.IMapCache;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.Rloc;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.MappingOrigin;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.SiteId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.AuthenticationKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.Mapping;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.mapping.authkey.container.MappingAuthkey;
tableMap.put(MappingOrigin.Southbound, smc);
}
+ public void addMapping(MappingOrigin origin, SiteId siteId, Eid key, Object data) {
+ // Store data first in MapCache and only afterwards persist to datastore. This should be used only for SB
+ // registrations
+ addMapping(origin, key, data);
+ dsbe.addMapping(DSBEInputUtil.toMapping(origin, key, siteId, (MappingRecord) data));
+ }
+
public void addMapping(MappingOrigin origin, Eid key, Object value) {
tableMap.get(origin).addMapping(key, value, origin == MappingOrigin.Southbound ? overwrite : true);
}
@SuppressWarnings("unchecked")
public void handleMapRegister(MapRegister mapRegister) {
- boolean failed = false;
- boolean updated = false;
+ boolean authFailed = false;
String password = null;
Set<SubscriberRLOC> subscribers = null;
MappingRecord oldMapping;
}
if (!LispAuthenticationUtil.validate(mapRegister, password)) {
LOG.warn("Authentication failed");
- failed = true;
+ authFailed = true;
break;
}
}
oldMapping = (MappingRecord) mapService.getMapping(MappingOrigin.Southbound, mapping.getEid());
+ mapService.addMapping(MappingOrigin.Southbound, mapping.getEid(), getSiteId(mapRegister), mapping);
- if (subscriptionService && mappingChanged(oldMapping, mapping)) {
- if (LOG.isDebugEnabled()){
- LOG.debug("Mapping update occured for {} SMRs will be sent for its subscribers.",
- LispAddressStringifier.getString(mapping.getEid()));
+ if (subscriptionService) {
+ MappingRecord newMapping = ConfigIni.getInstance().mappingMergeIsSet()
+ ? (MappingRecord) mapService.getMapping(MappingOrigin.Southbound, mapping.getEid()) : mapping;
+ if (mappingChanged(oldMapping, newMapping)) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Mapping update occured for {} SMRs will be sent for its subscribers.",
+ LispAddressStringifier.getString(mapping.getEid()));
+ }
+ subscribers = getSubscribers(mapping.getEid());
+ sendSmrs(mapping, subscribers);
}
- subscribers = getSubscribers(mapping.getEid());
- updated = true;
- }
- // Must update the record before sending SMRs
- mapService.addMapping(MappingOrigin.Southbound, mapping.getEid(), getSiteId(mapRegister), mapping);
- if (updated) {
- updated = false;
- sendSmrs(mapping, subscribers);
}
}
- if (!failed && BooleanUtils.isTrue(mapRegister.isWantMapNotify())) {
+ if (!authFailed && BooleanUtils.isTrue(mapRegister.isWantMapNotify())) {
LOG.trace("MapRegister wants MapNotify");
MapNotifyBuilder builder = new MapNotifyBuilder();
List<TransportAddress> rlocs = null;
private void sendSmrs(MappingRecord record, Set<SubscriberRLOC> subscribers) {
Eid eid = record.getEid();
- handleSmr(record, subscribers, notifyHandler);
+ handleSmr(eid, subscribers, notifyHandler);
// For SrcDst LCAF also send SMRs to Dst prefix
if (eid.getAddress() instanceof SourceDestKey) {
Eid dstAddr = SourceDestKeyHelper.getDst(eid);
Set<SubscriberRLOC> dstSubs = getSubscribers(dstAddr);
- MappingRecord newRecord = new MappingRecordBuilder().setAction(record.getAction())
- .setAuthoritative(record.isAuthoritative()).setLocatorRecord(record.getLocatorRecord())
- .setMapVersion(record.getMapVersion()).setRecordTtl(record.getRecordTtl())
- .setEid(dstAddr).build();
- handleSmr(newRecord, dstSubs, notifyHandler);
+ MappingRecord newRecord = new MappingRecordBuilder(record).setEid(dstAddr).build();
+ handleSmr(newRecord.getEid(), dstSubs, notifyHandler);
}
}
- private void handleSmr(MappingRecord record, Set<SubscriberRLOC> subscribers, IMapNotifyHandler callback) {
+ private void handleSmr(Eid eid, Set<SubscriberRLOC> subscribers, IMapNotifyHandler callback) {
if (subscribers == null) {
return;
}
- MapRequestBuilder mrb = MapRequestUtil.prepareSMR(record.getEid(), LispAddressUtil.toRloc(getLocalAddress()));
+ MapRequestBuilder mrb = MapRequestUtil.prepareSMR(eid, LispAddressUtil.toRloc(getLocalAddress()));
LOG.trace("Built SMR packet: " + mrb.build().toString());
for (SubscriberRLOC subscriber : subscribers) {
if (subscriber.timedOut()) {
}
}
}
- addSubscribers(record.getEid(), subscribers);
+ addSubscribers(eid, subscribers);
}
@SuppressWarnings("unchecked")
*/
public class DataStoreBackEnd implements TransactionChainListener {
protected static final Logger LOG = LoggerFactory.getLogger(DataStoreBackEnd.class);
-
- private DataBroker broker;
private BindingTransactionChain txChain;
public DataStoreBackEnd(DataBroker broker) {
- this.broker = broker;
this.txChain = broker.createTransactionChain(this);
}
if (entry.getValue() instanceof Mapping) {
Mapping mapping = (Mapping)entry.getValue();
+ // Only treat mapping changes caused by Northbound, since Southbound changes are already handled
+ // before being persisted. XXX separate NB and SB to avoid ignoring SB notifications
+ if (mapping.getOrigin() == MappingOrigin.Southbound) {
+ continue;
+ }
+
LOG.trace("Received created data");
LOG.trace("Key: {}", entry.getKey());
LOG.trace("Value: {}", mapping);
mapSystem.addMapping(mapping.getOrigin(), mapping.getMappingRecord().getEid(),
mapping.getMappingRecord());
- if (mapping.getOrigin() == MappingOrigin.Northbound) {
- // Only publish notifications for mapping changes caused by Northbound, since Southbound has a
- // dedicated code path for detecting mapping updates. The notifications are used for sending SMR.
- try {
- notificationPublishService.putNotification(MSNotificationInputUtil.toMappingChanged(mapping,
- MappingChange.Created));
- } catch (InterruptedException e) {
- LOG.warn("Notification publication interrupted!");
- }
+ try {
+ // The notifications are used for sending SMR.
+ notificationPublishService.putNotification(MSNotificationInputUtil.toMappingChanged(mapping,
+ MappingChange.Created));
+ } catch (InterruptedException e) {
+ LOG.warn("Notification publication interrupted!");
}
}
}
if (entry.getValue() instanceof Mapping) {
Mapping mapping = (Mapping)entry.getValue();
+ // Only treat mapping changes caused by Northbound, since Southbound changes are already handled
+ // before being persisted.
+ if (mapping.getOrigin() == MappingOrigin.Southbound) {
+ continue;
+ }
+
LOG.trace("Received changed data");
LOG.trace("Key: {}", entry.getKey());
LOG.trace("Value: {}", entry.getValue());
mapSystem.addMapping(mapping.getOrigin(), mapping.getMappingRecord().getEid(),
mapping.getMappingRecord());
- if (mapping.getOrigin() == MappingOrigin.Northbound) {
- // Only publish notifications for mapping changes caused by Northbound, since Southbound has a
- // dedicated code path for detecting mapping updates. The notifications are used for sending SMR.
- try {
- notificationPublishService.putNotification(MSNotificationInputUtil.toMappingChanged(mapping,
- MappingChange.Updated));
- } catch (InterruptedException e) {
- LOG.warn("Notification publication interrupted!");
- }
+ // The notifications are used for sending SMR.
+ try {
+ notificationPublishService.putNotification(MSNotificationInputUtil.toMappingChanged(mapping,
+ MappingChange.Updated));
+ } catch (InterruptedException e) {
+ LOG.warn("Notification publication interrupted!");
}
}
}
if (dataObject instanceof Mapping) {
Mapping mapping = (Mapping)dataObject;
+ // Only treat mapping changes caused by Northbound, since Southbound changes are already handled
+ // before being persisted.
+ if (mapping.getOrigin() == MappingOrigin.Southbound) {
+ continue;
+ }
+
LOG.trace("Received deleted data");
LOG.trace("Key: {}", entry);
LOG.trace("Value: {}", dataObject);