SMR parent prefix
[lispflowmapping.git] / mappingservice / implementation / src / main / java / org / opendaylight / lispflowmapping / implementation / MappingService.java
index 237b8ff318d3daacdd6d2bb82f48bbe5faa077f3..a60c8a0107166d1ce4e79293bc98e3d2979d3611 100644 (file)
@@ -7,60 +7,66 @@
  */
 package org.opendaylight.lispflowmapping.implementation;
 
-import java.util.Arrays;
+import com.google.common.base.Preconditions;
+import com.google.common.util.concurrent.Futures;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.concurrent.Future;
-
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
-import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
-import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RpcRegistration;
-import org.opendaylight.lispflowmapping.implementation.config.ConfigIni;
+import org.opendaylight.lispflowmapping.config.ConfigIni;
+import org.opendaylight.lispflowmapping.dsbackend.DataStoreBackEnd;
 import org.opendaylight.lispflowmapping.implementation.mdsal.AuthenticationKeyDataListener;
-import org.opendaylight.lispflowmapping.implementation.mdsal.DataStoreBackEnd;
 import org.opendaylight.lispflowmapping.implementation.mdsal.MappingDataListener;
 import org.opendaylight.lispflowmapping.implementation.util.DSBEInputUtil;
 import org.opendaylight.lispflowmapping.implementation.util.RPCInputConvertorUtil;
 import org.opendaylight.lispflowmapping.interfaces.dao.ILispDAO;
 import org.opendaylight.lispflowmapping.interfaces.mappingservice.IMappingService;
-import org.opendaylight.lispflowmapping.lisp.util.MaskUtil;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.eidtolocatorrecords.EidToLocatorRecord;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.lispaddress.LispAddressContainer;
+import org.opendaylight.lispflowmapping.lisp.type.MappingData;
+import org.opendaylight.lispflowmapping.lisp.util.LispAddressUtil;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.SiteId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.XtrId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecord;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecordBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.authkey.container.MappingAuthkey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord;
+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.mappingservice.rev150906.AddKeyInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.AddKeyInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.AddKeysInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.AddMappingInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.AddMappingInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.AddMappingsInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.GetAllKeysOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.GetAllMappingsOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.GetKeyInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.GetKeyInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.GetKeyOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.GetKeyOutputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.GetKeysInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.GetKeysOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.GetMappingInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.GetMappingInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.GetMappingOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.GetMappingOutputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.GetMappingWithXtrIdInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.GetMappingWithXtrIdOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.GetMappingWithXtrIdOutputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.GetMappingsInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.GetMappingsOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.MappingOrigin;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.MappingserviceService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.OdlMappingserviceService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.RemoveKeyInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.RemoveKeyInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.RemoveKeysInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.RemoveMappingInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.RemoveMappingInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.SiteId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.RemoveMappingsInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.UpdateKeyInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.UpdateKeyInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.UpdateKeysInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.UpdateMappingInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.UpdateMappingInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.update.key.input.EidBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.UpdateMappingsInput;
 import org.opendaylight.yangtools.yang.common.RpcError;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.common.base.Preconditions;
-import com.google.common.util.concurrent.Futures;
-
 /**
  * Dispatcher of API calls that implements the RPC and Java APIs in mappingservice.yang and IMappingService
  * respectively. It also coordinates and acts as container for all objects in charge of
@@ -72,72 +78,61 @@ import com.google.common.util.concurrent.Futures;
  * @author Florin Coras
  *
  */
-public class MappingService implements MappingserviceService, IMappingService, BindingAwareProvider, AutoCloseable {
+public class MappingService implements OdlMappingserviceService, IMappingService, AutoCloseable {
     protected static final Logger LOG = LoggerFactory.getLogger(MappingService.class);
     private static final String NOT_FOUND_TAG = "data-missing";
     private static final String DATA_EXISTS_TAG = "data-exists";
 
     private MappingSystem mappingSystem;
     private DataStoreBackEnd dsbe;
-    private RpcRegistration<MappingserviceService> mappingServiceRpc;
     private AuthenticationKeyDataListener keyListener;
     private MappingDataListener mappingListener;
-    private ILispDAO dao;
+    private final ILispDAO dao;
 
-    private DataBroker dataBroker;
-    private RpcProviderRegistry rpcRegistry;
-    private BindingAwareBroker bindingAwareBroker;
-    private NotificationPublishService notificationPublishService;
+    private final DataBroker dataBroker;
+    private final NotificationPublishService notificationPublishService;
 
-    private static final ConfigIni configIni = new ConfigIni();
-    private boolean overwritePolicy = configIni.mappingOverwriteIsSet();
-    private boolean notificationPolicy = configIni.smrIsSet();
+    private boolean mappingMergePolicy = ConfigIni.getInstance().mappingMergeIsSet();
+    private boolean notificationPolicy = ConfigIni.getInstance().smrIsSet();
     private boolean iterateMask = true;
+    private boolean isMaster = false;
 
-    public MappingService() {
-        LOG.debug("MappingService created!");
-    }
-
-    public void setDataBroker(DataBroker dataBroker) {
-        this.dataBroker = dataBroker;
-    }
-
-    public void setRpcProviderRegistry(RpcProviderRegistry rpc) {
-        this.rpcRegistry = rpc;
-    }
-
-    public void setBindingAwareBroker(BindingAwareBroker broker) {
-        this.bindingAwareBroker = broker;
-    }
+    public MappingService(final DataBroker broker,
+            final NotificationPublishService notificationPublishService,
+            final ILispDAO lispDAO) {
+        this.dataBroker = broker;
+        this.notificationPublishService = notificationPublishService;
+        this.dao = lispDAO;
 
-    public void setNotificationPublishService(NotificationPublishService nps) {
-        this.notificationPublishService = nps;
+        LOG.debug("MappingService created!");
     }
 
-    public void setDaoService(ILispDAO dao) {
-        this.dao = dao;
-    }
 
     @Override
-    public void setMappingOverwrite(boolean overwrite) {
-        this.overwritePolicy = overwrite;
+    public void setMappingMerge(boolean mergeMapping) {
+        this.mappingMergePolicy = mergeMapping;
         if (mappingSystem != null) {
-            mappingSystem.setOverwritePolicy(overwrite);
+            mappingSystem.setMappingMerge(mergeMapping);
+            ConfigIni.getInstance().setMappingMerge(mappingMergePolicy);
         }
     }
 
-    public void initialize() {
-        bindingAwareBroker.registerProvider(this);
+    @Override
+    public void setLookupPolicy(IMappingService.LookupPolicy policy) {
+        ConfigIni.getInstance().setLookupPolicy(policy);
+    }
 
-        mappingServiceRpc = rpcRegistry.addRpcImplementation(MappingserviceService.class, this);
+    public void initialize() {
+        LOG.info("Mapping Service initializing...");
         dsbe = new DataStoreBackEnd(dataBroker);
 
-        mappingSystem = new MappingSystem(dao, iterateMask, notificationPolicy, overwritePolicy);
+        mappingSystem = new MappingSystem(dao, iterateMask, notificationPolicy, mappingMergePolicy);
         mappingSystem.setDataStoreBackEnd(dsbe);
         mappingSystem.initialize();
 
         keyListener = new AuthenticationKeyDataListener(dataBroker, mappingSystem);
         mappingListener = new MappingDataListener(dataBroker, mappingSystem, notificationPublishService);
+        LOG.info("Mapping Service loaded.");
     }
 
     @Override
@@ -147,11 +142,7 @@ public class MappingService implements MappingserviceService, IMappingService, B
 
         RpcResultBuilder<Void> rpcResultBuilder;
 
-        // XXX: to remove once RPC API has been updated to remove explicit mask
-        input = new AddKeyInputBuilder(input).setLispAddressContainer(
-                MaskUtil.fixMask(input.getLispAddressContainer(), input.getMaskLength())).build();
-
-        String key = mappingSystem.getAuthenticationKey(input.getLispAddressContainer());
+        MappingAuthkey key = mappingSystem.getAuthenticationKey(convertToBinaryIfNecessary(input.getEid()));
 
         if (key != null) {
             String message = "Key already exists! Please use update-key if you want to change it.";
@@ -171,10 +162,6 @@ public class MappingService implements MappingserviceService, IMappingService, B
         Preconditions.checkNotNull(input, "add-mapping RPC input must be not null!");
         LOG.trace("RPC received to add the following mapping: " + input.toString());
 
-        // XXX: to remove once RPC API has been updated to remove explicit mask
-        input = new AddMappingInputBuilder(input).setLispAddressContainer(
-                MaskUtil.fixMask(input.getLispAddressContainer(), input.getMaskLength())).build();
-
         dsbe.addMapping(RPCInputConvertorUtil.toMapping(input));
 
         RpcResultBuilder<Void> rpcResultBuilder;
@@ -184,25 +171,42 @@ public class MappingService implements MappingserviceService, IMappingService, B
         return Futures.immediateFuture(rpcResultBuilder.build());
     }
 
+    @Override
+    public void addMapping(MappingOrigin origin, Eid key, SiteId siteId, MappingData mappingData) {
+        // SB registrations are first written to the MappingSystem and only afterwards are persisted to the datastore
+        if (origin.equals(MappingOrigin.Southbound)) {
+            // Store data first in MapCache and only afterwards persist to datastore. This should be used only for SB
+            // registrations
+            mappingSystem.addMapping(origin, key, mappingData);
+            dsbe.addMapping(DSBEInputUtil.toMapping(origin, key, siteId, mappingData));
+            if (mappingData.getXtrId() != null) {
+                dsbe.addXtrIdMapping(DSBEInputUtil.toXtrIdMapping(mappingData));
+            }
+        } else {
+            dsbe.addMapping(DSBEInputUtil.toMapping(origin, key, siteId, mappingData));
+        }
+    }
+
+    @Override
+    public void refreshMappingRegistration(Eid key, XtrId xtrId, Long timestamp) {
+        mappingSystem.refreshMappingRegistration(key, xtrId, timestamp);
+    }
+
     @Override
     public Future<RpcResult<GetKeyOutput>> getKey(GetKeyInput input) {
         Preconditions.checkNotNull(input, "get-key RPC input must be not null!");
         LOG.trace("RPC received to get the following key: " + input.toString());
 
-        // XXX: to remove once RPC API has been updated to remove explicit mask
-        input = new GetKeyInputBuilder(input).setLispAddressContainer(
-                MaskUtil.fixMask(input.getLispAddressContainer(), input.getMaskLength())).build();
-
         RpcResultBuilder<GetKeyOutput> rpcResultBuilder;
 
-        String key = mappingSystem.getAuthenticationKey(input.getLispAddressContainer());
+        MappingAuthkey key = mappingSystem.getAuthenticationKey(convertToBinaryIfNecessary(input.getEid()));
 
         if (key == null) {
             String message = "Key was not found in the mapping database";
             rpcResultBuilder = RpcResultBuilder.<GetKeyOutput>failed()
                     .withError(RpcError.ErrorType.APPLICATION, NOT_FOUND_TAG, message);
         } else {
-            rpcResultBuilder = RpcResultBuilder.success(new GetKeyOutputBuilder().setAuthkey(key));
+            rpcResultBuilder = RpcResultBuilder.success(new GetKeyOutputBuilder().setMappingAuthkey(key));
         }
 
         return Futures.immediateFuture(rpcResultBuilder.build());
@@ -213,21 +217,55 @@ public class MappingService implements MappingserviceService, IMappingService, B
         Preconditions.checkNotNull(input, "get-mapping RPC input must be not null!");
         LOG.trace("RPC received to get the following mapping: " + input.toString());
 
-        // XXX: to remove once RPC API has been updated to remove explicit mask
-        input = new GetMappingInputBuilder(input).setLispAddressContainer(
-                MaskUtil.fixMask(input.getLispAddressContainer(), input.getMaskLength())).build();
-
         RpcResultBuilder<GetMappingOutput> rpcResultBuilder;
 
-        EidToLocatorRecord reply = (EidToLocatorRecord) mappingSystem.getMapping(input.getLispAddressContainer());
+        MappingData reply = mappingSystem.getMapping(convertToBinaryIfNecessary(input.getEid()));
 
         if (reply == null) {
             String message = "No mapping was found in the mapping database";
             rpcResultBuilder = RpcResultBuilder.<GetMappingOutput>failed()
                     .withError(RpcError.ErrorType.APPLICATION, NOT_FOUND_TAG, message);
         } else {
-            rpcResultBuilder = RpcResultBuilder.success(new GetMappingOutputBuilder().setEidToLocatorRecord(Arrays
-                    .asList(reply)));
+            final MappingRecord convertedReply = convertFromBinaryIfNecessary(reply.getRecord());
+            rpcResultBuilder = RpcResultBuilder.success(new GetMappingOutputBuilder().setMappingRecord(convertedReply));
+        }
+
+        return Futures.immediateFuture(rpcResultBuilder.build());
+    }
+
+    @Override
+    public MappingData getMapping(MappingOrigin origin, Eid key) {
+        return mappingSystem.getMapping(origin, key);
+    }
+
+    @Override
+    public MappingData getMapping(Eid key) {
+        return mappingSystem.getMapping(key);
+    }
+
+    @Override
+    public MappingData getMapping(Eid srcKey, Eid dstKey) {
+        return mappingSystem.getMapping(srcKey, dstKey);
+    }
+
+    @Override
+    public Future<RpcResult<GetMappingWithXtrIdOutput>> getMappingWithXtrId(GetMappingWithXtrIdInput input) {
+        Preconditions.checkNotNull(input, "get-mapping RPC input must be not null!");
+        LOG.trace("RPC received to get the following mapping: " + input.toString());
+
+        RpcResultBuilder<GetMappingWithXtrIdOutput> rpcResultBuilder;
+
+        MappingData reply = mappingSystem.getMapping(null, convertToBinaryIfNecessary(input.getEid()),
+                input.getXtrId());
+
+        if (reply == null) {
+            String message = "No mapping was found in the mapping database";
+            rpcResultBuilder = RpcResultBuilder.<GetMappingWithXtrIdOutput>failed()
+                    .withError(RpcError.ErrorType.APPLICATION, NOT_FOUND_TAG, message);
+        } else {
+            final MappingRecord convertedReply = convertFromBinaryIfNecessary(reply.getRecord());
+            rpcResultBuilder = RpcResultBuilder.success(new GetMappingWithXtrIdOutputBuilder()
+                    .setMappingRecord(convertedReply));
         }
 
         return Futures.immediateFuture(rpcResultBuilder.build());
@@ -238,10 +276,6 @@ public class MappingService implements MappingserviceService, IMappingService, B
         Preconditions.checkNotNull(input, "remove-key RPC input must be not null!");
         LOG.trace("RPC received to remove the following key: " + input.toString());
 
-        // XXX: to remove once RPC API has been updated to remove explicit mask
-        input = new RemoveKeyInputBuilder(input).setLispAddressContainer(
-                MaskUtil.fixMask(input.getLispAddressContainer(), input.getMaskLength())).build();
-
         RpcResultBuilder<Void> rpcResultBuilder;
 
         dsbe.removeAuthenticationKey(RPCInputConvertorUtil.toAuthenticationKey(input));
@@ -256,10 +290,6 @@ public class MappingService implements MappingserviceService, IMappingService, B
         Preconditions.checkNotNull(input, "remove-mapping RPC input must be not null!");
         LOG.trace("RPC received to remove the following mapping: " + input.toString());
 
-        // XXX: to remove once RPC API has been updated to remove explicit mask
-        input = new RemoveMappingInputBuilder(input).setLispAddressContainer(
-                MaskUtil.fixMask(input.getLispAddressContainer(), input.getMaskLength())).build();
-
         RpcResultBuilder<Void> rpcResultBuilder;
 
         dsbe.removeMapping(RPCInputConvertorUtil.toMapping(input));
@@ -269,20 +299,19 @@ public class MappingService implements MappingserviceService, IMappingService, B
         return Futures.immediateFuture(rpcResultBuilder.build());
     }
 
+    @Override
+    public void removeMapping(MappingOrigin origin, Eid key) {
+        dsbe.removeMapping(DSBEInputUtil.toMapping(origin, key));
+    }
+
     @Override
     public Future<RpcResult<Void>> updateKey(UpdateKeyInput input) {
         Preconditions.checkNotNull(input, "update-key RPC input must be not null!");
         LOG.trace("RPC received to update the following key: " + input.toString());
 
-        // XXX: to remove once RPC API has been updated to remove explicit mask
-        input = new UpdateKeyInputBuilder(input).setEid(
-                new EidBuilder(input.getEid()).setLispAddressContainer(
-                        MaskUtil.fixMask(input.getEid().getLispAddressContainer(), input.getEid()
-                                .getMaskLength())).build()).build();
-
         RpcResultBuilder<Void> rpcResultBuilder;
 
-        String key = mappingSystem.getAuthenticationKey(input.getEid().getLispAddressContainer());
+        MappingAuthkey key = mappingSystem.getAuthenticationKey(convertToBinaryIfNecessary(input.getEid()));
 
         if (key == null) {
             String message = "Key doesn't exist! Please use add-key if you want to create a new authentication key.";
@@ -302,10 +331,6 @@ public class MappingService implements MappingserviceService, IMappingService, B
         LOG.trace("RPC received to update the following mapping: " + input.toString());
         Preconditions.checkNotNull(input, "update-mapping RPC input must be not null!");
 
-        // XXX: to remove once RPC API has been updated to remove explicit mask
-        input = new UpdateMappingInputBuilder(input).setLispAddressContainer(
-                MaskUtil.fixMask(input.getLispAddressContainer(), input.getMaskLength())).build();
-
         RpcResultBuilder<Void> rpcResultBuilder;
 
         dsbe.updateMapping(RPCInputConvertorUtil.toMapping(input));
@@ -316,82 +341,214 @@ public class MappingService implements MappingserviceService, IMappingService, B
     }
 
     @Override
-    public void addMapping(MappingOrigin origin, LispAddressContainer key, SiteId siteId, Object data) {
-        dsbe.addMapping(DSBEInputUtil.toMapping(origin, key, siteId, (EidToLocatorRecord) data));
-        mappingSystem.updateMappingRegistration(origin, key);
+    public Future<RpcResult<Void>> removeKeys(RemoveKeysInput input) {
+        // TODO Auto-generated method stub
+        return null;
     }
 
     @Override
-    public Object getMapping(MappingOrigin origin, LispAddressContainer key) {
-        return mappingSystem.getMapping(origin, key);
+    public Future<RpcResult<Void>> removeMappings(RemoveMappingsInput input) {
+        // TODO Auto-generated method stub
+        return null;
     }
 
     @Override
-    public Object getMapping(LispAddressContainer key) {
-        return mappingSystem.getMapping(key);
+    public Future<RpcResult<GetKeysOutput>> getKeys(GetKeysInput input) {
+        // TODO Auto-generated method stub
+        return null;
     }
 
     @Override
-    public Object getMapping(LispAddressContainer srcKey, LispAddressContainer dstKey) {
-        return mappingSystem.getMapping(srcKey, dstKey);
+    public Future<RpcResult<Void>> addMappings(AddMappingsInput input) {
+        // TODO Auto-generated method stub
+        return null;
     }
 
     @Override
-    public void removeMapping(MappingOrigin origin, LispAddressContainer key) {
-        dsbe.removeMapping(DSBEInputUtil.toMapping(origin, key));
+    public Future<RpcResult<Void>> updateKeys(UpdateKeysInput input) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public Future<RpcResult<Void>> removeAllMappings() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public Future<RpcResult<Void>> removeAllKeys() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public Future<RpcResult<GetAllKeysOutput>> getAllKeys() {
+        // TODO Auto-generated method stub
+        return null;
     }
 
     @Override
-    public void addAuthenticationKey(LispAddressContainer key, String authKey) {
+    public Future<RpcResult<Void>> updateMappings(UpdateMappingsInput input) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public Future<RpcResult<Void>> addKeys(AddKeysInput input) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public Future<RpcResult<GetAllMappingsOutput>> getAllMappings() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public Future<RpcResult<GetMappingsOutput>> getMappings(
+            GetMappingsInput input) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public Future<RpcResult<Void>> removeAllOperationalContent() {
+        RpcResultBuilder<Void> rpcResultBuilder;
+
+        /*
+         * Since master nodes ignore datastore changes for southbound originated mappings, they need to be removed
+         * explicitly.
+         */
+        if (isMaster) {
+            mappingSystem.cleanSBMappings();
+        }
+        dsbe.removeAllOperationalDatastoreContent();
+
+        rpcResultBuilder = RpcResultBuilder.success();
+
+        return Futures.immediateFuture(rpcResultBuilder.build());
+    }
+
+    @Override
+    public Eid getWidestNegativePrefix(Eid key) {
+        return mappingSystem.getWidestNegativePrefix(key);
+    }
+
+    @Override
+    public void addAuthenticationKey(Eid key, MappingAuthkey authKey) {
         dsbe.addAuthenticationKey(DSBEInputUtil.toAuthenticationKey(key, authKey));
     }
 
     @Override
-    public String getAuthenticationKey(LispAddressContainer key) {
+    public MappingAuthkey getAuthenticationKey(Eid key) {
         return mappingSystem.getAuthenticationKey(key);
     }
 
     @Override
-    public void removeAuthenticationKey(LispAddressContainer key) {
+    public void removeAuthenticationKey(Eid key) {
         dsbe.removeAuthenticationKey(DSBEInputUtil.toAuthenticationKey(key, null));
     }
 
     @Override
-    public void addData(MappingOrigin origin, LispAddressContainer key, String subKey, Object data) {
+    public void addData(MappingOrigin origin, Eid key, String subKey, Object data) {
         mappingSystem.addData(origin, key, subKey, data);
     }
 
     @Override
-    public Object getData(MappingOrigin origin, LispAddressContainer key, String subKey) {
+    public Object getData(MappingOrigin origin, Eid key, String subKey) {
         return mappingSystem.getData(origin, key, subKey);
     }
 
     @Override
-    public void removeData(MappingOrigin origin, LispAddressContainer key, String subKey) {
+    public void removeData(MappingOrigin origin, Eid key, String subKey) {
         mappingSystem.removeData(origin, key, subKey);
     }
 
+    @Override
+    public Eid getParentPrefix(Eid key) {
+        return mappingSystem.getParentPrefix(key);
+    }
+
     @Override
     public String printMappings() {
         return mappingSystem.printMappings();
     }
 
     @Override
-    public void onSessionInitiated(ProviderContext session) {
-        LOG.info("Mapping Service provider session initializing!");
+    public String printKeys() {
+        return mappingSystem.printKeys();
     }
 
     @Override
     public void close() throws Exception {
         LOG.info("Mapping Service is being destroyed!");
-        mappingServiceRpc.close();
         keyListener.closeDataChangeListener();
         mappingListener.closeDataChangeListener();
+        mappingSystem.destroy();
     }
 
     @Override
     public void cleanCachedMappings() {
         mappingSystem.cleanCaches();
-        dsbe.removeAllMappings();
+        dsbe.removeAllDatastoreContent();
+    }
+
+    private static Eid convertToBinaryIfNecessary(Eid eid) {
+        if (LispAddressUtil.addressNeedsConversionToBinary(eid.getAddress())) {
+            return LispAddressUtil.convertToBinary(eid);
+        }
+        return eid;
+    }
+
+    private static MappingRecord convertFromBinaryIfNecessary(MappingRecord originalRecord) {
+        List<LocatorRecord> originalLocators = originalRecord.getLocatorRecord();
+
+        List<LocatorRecord> convertedLocators = null;
+        if (originalLocators != null) {
+            // If convertedLocators is non-null, while originalLocators is also non-null, conversion has been made
+            convertedLocators = convertFromBinaryIfNecessary(originalLocators);
+        }
+
+        if (LispAddressUtil.addressNeedsConversionFromBinary(originalRecord.getEid().getAddress())
+                || (originalLocators != null && convertedLocators != null)) {
+            MappingRecordBuilder mrb = new MappingRecordBuilder(originalRecord);
+            mrb.setEid(LispAddressUtil.convertFromBinary(originalRecord.getEid()));
+            if (convertedLocators != null) {
+                mrb.setLocatorRecord(convertedLocators);
+            }
+            return mrb.build();
+        }
+        return originalRecord;
+    }
+
+    private static List<LocatorRecord> convertFromBinaryIfNecessary(List<LocatorRecord> originalLocators) {
+        List<LocatorRecord> convertedLocators = null;
+        for (LocatorRecord record : originalLocators) {
+            if (LispAddressUtil.addressNeedsConversionFromBinary(record.getRloc().getAddress())) {
+                LocatorRecordBuilder lrb = new LocatorRecordBuilder(record);
+                lrb.setRloc(LispAddressUtil.convertFromBinary(record.getRloc()));
+                if (convertedLocators == null) {
+                    convertedLocators = new ArrayList<LocatorRecord>();
+                }
+                convertedLocators.add(lrb.build());
+            }
+        }
+        if (convertedLocators != null) {
+            return convertedLocators;
+        }
+        return originalLocators;
+    }
+
+    @Override
+    public void setIsMaster(boolean isMaster) {
+        this.isMaster = isMaster;
+        mappingSystem.setIsMaster(isMaster);
+    }
+
+    @Override
+    public boolean isMaster() {
+        return isMaster;
     }
 }