Separate authentication key in-memory storage 15/49715/5
authorLorand Jakab <lojakab@cisco.com>
Wed, 21 Dec 2016 15:50:09 +0000 (17:50 +0200)
committerLorand Jakab <lojakab@cisco.com>
Tue, 17 Jan 2017 18:46:49 +0000 (20:46 +0200)
Authentication key operations (add/get/remove) are part of the IMapCache
interface, so all map-caches implement them, even though we only really
use them in SimpleMapCache. This makes map-caches less "general", in the
sense that they need to be aware of the AuthenticationKey type, and we
have unused code.

This patch creates a new IAuthKeyDb interface and the AuthKeyDb class
implementing it, which contains only the authentication key operations.
The MappingSystem and the LispSouthBoundPlugin are switched to the new
implementation.

This is a prerequisite for a full solution to bug 7272, by making it
possible to remove all sub-keys when removing a mapping, leaving the
RadixTrie in a consistent state. It also makes a proper implementation
for the newly introduced remove-all-operational-content RPC, since
deleting all operational content should delete all southbound mappings,
but not authentication keys, which are now in the same in-memory
structures.

Checked system tests, all passing.

Change-Id: I9536dbccb06d486e205f8a15e9e8ac3fa1c53fcc
Signed-off-by: Lorand Jakab <lojakab@cisco.com>
26 files changed:
mappingservice/api/src/main/java/org/opendaylight/lispflowmapping/interfaces/mapcache/IAuthKeyDb.java [new file with mode: 0644]
mappingservice/api/src/main/java/org/opendaylight/lispflowmapping/interfaces/mapcache/IMapCache.java
mappingservice/api/src/main/java/org/opendaylight/lispflowmapping/interfaces/mapcache/IMappingSystem.java
mappingservice/api/src/main/java/org/opendaylight/lispflowmapping/interfaces/mappingservice/IMappingService.java
mappingservice/api/src/main/java/org/opendaylight/lispflowmapping/interfaces/mappingservice/IMappingServiceShell.java
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/MappingService.java
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/MappingServiceShell.java
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/MappingSystem.java
mappingservice/implementation/src/test/java/org/opendaylight/lispflowmapping/implementation/MappingSystemTest.java
mappingservice/mapcache/src/main/java/org/opendaylight/lispflowmapping/mapcache/AuthKeyDb.java [new file with mode: 0644]
mappingservice/mapcache/src/main/java/org/opendaylight/lispflowmapping/mapcache/FlatMapCache.java
mappingservice/mapcache/src/main/java/org/opendaylight/lispflowmapping/mapcache/MultiTableMapCache.java
mappingservice/mapcache/src/main/java/org/opendaylight/lispflowmapping/mapcache/SimpleMapCache.java
mappingservice/mapcache/src/test/java/org/opendaylight/lispflowmapping/mapcache/AuthKeyDbTest.java [new file with mode: 0644]
mappingservice/mapcache/src/test/java/org/opendaylight/lispflowmapping/mapcache/FlatMapCacheTest.java
mappingservice/mapcache/src/test/java/org/opendaylight/lispflowmapping/mapcache/MultiTableMapCacheTest.java
mappingservice/mapcache/src/test/java/org/opendaylight/lispflowmapping/mapcache/SimpleMapCacheTest.java
mappingservice/shell/src/main/java/org/opendaylight/lispflowmapping/shell/LispAddKey.java
mappingservice/shell/src/main/java/org/opendaylight/lispflowmapping/shell/LispKeys.java [new file with mode: 0644]
mappingservice/shell/src/main/java/org/opendaylight/lispflowmapping/shell/LispMappings.java
mappingservice/shell/src/main/resources/OSGI-INF/blueprint/blueprint.xml
mappingservice/southbound/src/main/java/org/opendaylight/lispflowmapping/southbound/LispSouthboundPlugin.java
mappingservice/southbound/src/main/java/org/opendaylight/lispflowmapping/southbound/lisp/AuthenticationKeyDataListener.java
mappingservice/southbound/src/main/java/org/opendaylight/lispflowmapping/southbound/lisp/LispSouthboundHandler.java
mappingservice/southbound/src/test/java/org/opendaylight/lispflowmapping/southbound/lisp/AuthenticationKeyDataListenerTest.java
mappingservice/southbound/src/test/java/org/opendaylight/lispflowmapping/southbound/lisp/LispSouthboundServiceTest.java

diff --git a/mappingservice/api/src/main/java/org/opendaylight/lispflowmapping/interfaces/mapcache/IAuthKeyDb.java b/mappingservice/api/src/main/java/org/opendaylight/lispflowmapping/interfaces/mapcache/IAuthKeyDb.java
new file mode 100644 (file)
index 0000000..b25070a
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.lispflowmapping.interfaces.mapcache;
+
+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.mapping.authkey.container.MappingAuthkey;
+
+/**
+ * Authentication key database interface.
+ *
+ * @author Lorand Jakab
+ *
+ */
+
+public interface IAuthKeyDb {
+    /**
+     * Add authentication key.
+     *
+     * @param key
+     *            The key for which the authentication key is added
+     * @param authKey
+     *            The authentication key
+     */
+    void addAuthenticationKey(Eid key, MappingAuthkey authKey);
+
+    /**
+     * Retrieve authentication key.
+     *
+     * @param key
+     *            The key for which the authentication key is being looked up.
+     * @return The authentication key.
+     */
+    MappingAuthkey getAuthenticationKey(Eid key);
+
+    /**
+     * Remove authentication key.
+     *
+     * @param key
+     *            Key for which the authentication key should be removed.
+     */
+    void removeAuthenticationKey(Eid key);
+
+    /**
+     * Print authentication keys in database. Used for testing, debugging and the karaf shell.
+     *
+     * @return a String consisting of all the authentication keys in the database
+     */
+    String printKeys();
+}
index 016218e0fca1ee75487417b11ad55516e32fd753..91cee91d0a7a3cce3f686262a81795e27a147234 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Cisco Systems, Inc.  All rights reserved.
+ * Copyright (c) 2015, 2016 Cisco Systems, Inc.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -9,7 +9,6 @@
 package org.opendaylight.lispflowmapping.interfaces.mapcache;
 
 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.mapping.authkey.container.MappingAuthkey;
 
 /**
  * Map-cache interface.
@@ -57,33 +56,6 @@ public interface IMapCache {
      */
     void removeMapping(Eid key);
 
-    /**
-     * Add authentication key.
-     *
-     * @param key
-     *            The key for which the authentication key is added
-     * @param authKey
-     *            The authentication key
-     */
-    void addAuthenticationKey(Eid key, MappingAuthkey authKey);
-
-    /**
-     * Retrieve authentication key.
-     *
-     * @param key
-     *            The key for which the authentication key is being looked up.
-     * @return The authentication key.
-     */
-    MappingAuthkey getAuthenticationKey(Eid key);
-
-    /**
-     * Remove authentication key.
-     *
-     * @param key
-     *            Key for which the authentication key should be removed.
-     */
-    void removeAuthenticationKey(Eid key);
-
     /**
      * Add data for key.
      *
index cb04452e42153a96c3a7db3a4e1d0b687b052e03..caf877203993c510d668f29760fe7dc29a899b7e 100644 (file)
@@ -202,6 +202,13 @@ public interface IMappingSystem {
      */
     String printMappings();
 
+    /**
+     * Print all authentication keys. Used for testing, debugging and the karaf shell.
+     *
+     * @return String consisting of all mappings
+     */
+    String printKeys();
+
     /**
      * Set cluster master status.
      *
index 23634b36ee1324e57343656499185916c7c68cba..9b96bd0c0a58db3377bf48e880d39b44a91b40f0 100644 (file)
@@ -195,6 +195,13 @@ public interface IMappingService {
      */
     String printMappings();
 
+    /**
+     * Print all authentication keys. Used for testing, debugging and the karaf shell.
+     *
+     * @return String consisting of all mappings
+     */
+    String printKeys();
+
     /**
      * Cleans all cached mappings.Used for testing.
      */
index c863dcbd56986e6cb966cb2cc73f08a118b61f3f..474b3b8e78b64d72292c1ed4c9a395d534010249 100644 (file)
@@ -22,6 +22,13 @@ public interface IMappingServiceShell {
      */
     String printMappings();
 
+    /**
+     * Print the full authentication key database.
+     *
+     * @return the text to be printed on the Karaf console.
+     */
+    String printKeys();
+
     /**
      * Add the default key "password" for the IPv4 prefix 0.0.0.0/0.
      */
index 28194ff1933dcf3704be1fb4d043b009191f3a01..fa55a6b0d7474596988513dfac53c9114bd0edcf 100644 (file)
@@ -464,6 +464,11 @@ public class MappingService implements OdlMappingserviceService, IMappingService
         return mappingSystem.printMappings();
     }
 
+    @Override
+    public String printKeys() {
+        return mappingSystem.printKeys();
+    }
+
     @Override
     public void close() throws Exception {
         LOG.info("Mapping Service is being destroyed!");
index 51d38291caceb7a203a25653a64a5c42c6cc0b73..a214f26bc89205a28c774bb8940f15293710af75 100644 (file)
@@ -37,6 +37,11 @@ public class MappingServiceShell implements IMappingServiceShell {
         return mappingService.printMappings();
     }
 
+    @Override
+    public String printKeys() {
+        return mappingService.printKeys();
+    }
+
     @Override
     public void addDefaultKeyIPv4() {
         Eid eid = LispAddressUtil.toEid(new Ipv4Prefix("0.0.0.0/0"), null);
index 08f924be716cc05257bf3d57fca6de724203b836..584a1edbba5ec372350b7b3112b7aeb127e24b8a 100644 (file)
@@ -20,6 +20,7 @@ import org.opendaylight.lispflowmapping.dsbackend.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.IAuthKeyDb;
 import org.opendaylight.lispflowmapping.interfaces.mapcache.ILispMapCache;
 import org.opendaylight.lispflowmapping.interfaces.mapcache.IMapCache;
 import org.opendaylight.lispflowmapping.interfaces.mapcache.IMappingSystem;
@@ -27,6 +28,7 @@ import org.opendaylight.lispflowmapping.interfaces.mappingservice.IMappingServic
 import org.opendaylight.lispflowmapping.lisp.type.MappingData;
 import org.opendaylight.lispflowmapping.lisp.util.LispAddressStringifier;
 import org.opendaylight.lispflowmapping.lisp.util.LispAddressUtil;
+import org.opendaylight.lispflowmapping.mapcache.AuthKeyDb;
 import org.opendaylight.lispflowmapping.mapcache.MultiTableMapCache;
 import org.opendaylight.lispflowmapping.mapcache.SimpleMapCache;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SimpleAddress;
@@ -59,11 +61,13 @@ import org.slf4j.LoggerFactory;
  */
 public class MappingSystem implements IMappingSystem {
     private static final Logger LOG = LoggerFactory.getLogger(MappingSystem.class);
+    private static final String AUTH_KEY_TABLE = "authentication";
     private boolean notificationService;
     private boolean mappingMerge;
     private ILispDAO dao;
     private ILispMapCache smc;
     private IMapCache pmc;
+    private IAuthKeyDb akdb;
     private final EnumMap<MappingOrigin, IMapCache> tableMap = new EnumMap<>(MappingOrigin.class);
     private DataStoreBackEnd dsbe;
     private boolean isMaster = false;
@@ -102,8 +106,9 @@ public class MappingSystem implements IMappingSystem {
          * but that option is no longer supported in the code, since it was never tested and may lead to unexpected
          * results.
          */
-        smc = new SimpleMapCache(dao.putTable(MappingOrigin.Southbound.toString()));
         pmc = new MultiTableMapCache(dao.putTable(MappingOrigin.Northbound.toString()));
+        smc = new SimpleMapCache(dao.putTable(MappingOrigin.Southbound.toString()));
+        akdb = new AuthKeyDb(dao.putTable(AUTH_KEY_TABLE));
         tableMap.put(MappingOrigin.Northbound, pmc);
         tableMap.put(MappingOrigin.Southbound, smc);
     }
@@ -339,7 +344,7 @@ public class MappingSystem implements IMappingSystem {
     public void addAuthenticationKey(Eid key, MappingAuthkey authKey) {
         LOG.debug("Adding authentication key '{}' with key-ID {} for {}", authKey.getKeyString(), authKey.getKeyType(),
                 LispAddressStringifier.getString(key));
-        smc.addAuthenticationKey(key, authKey);
+        akdb.addAuthenticationKey(key, authKey);
     }
 
     @Override
@@ -347,7 +352,7 @@ public class MappingSystem implements IMappingSystem {
         if (LOG.isDebugEnabled()) {
             LOG.debug("Retrieving authentication key for {}", LispAddressStringifier.getString(key));
         }
-        return smc.getAuthenticationKey(key);
+        return akdb.getAuthenticationKey(key);
     }
 
     @Override
@@ -355,7 +360,7 @@ public class MappingSystem implements IMappingSystem {
         if (LOG.isDebugEnabled()) {
             LOG.debug("Removing authentication key for {}", LispAddressStringifier.getString(key));
         }
-        smc.removeAuthenticationKey(key);
+        akdb.removeAuthenticationKey(key);
     }
 
     @Override
@@ -435,6 +440,11 @@ public class MappingSystem implements IMappingSystem {
         return sb.toString();
     }
 
+    @Override
+    public String printKeys() {
+        return akdb.printKeys();
+    }
+
     public void cleanCaches() {
         dao.removeAll();
         buildMapCaches();
index da4533fe7934c8a2359231e69005016c5122e79a..3b8205af184bdf0261e0944689eb58f3d9b3e54d 100644 (file)
@@ -34,6 +34,7 @@ import org.opendaylight.lispflowmapping.implementation.util.MappingMergeUtil;
 import org.opendaylight.lispflowmapping.inmemorydb.HashMapDb;
 import org.opendaylight.lispflowmapping.interfaces.dao.ILispDAO;
 import org.opendaylight.lispflowmapping.interfaces.dao.SubKeys;
+import org.opendaylight.lispflowmapping.interfaces.mapcache.IAuthKeyDb;
 import org.opendaylight.lispflowmapping.interfaces.mapcache.ILispMapCache;
 import org.opendaylight.lispflowmapping.interfaces.mapcache.IMapCache;
 import org.opendaylight.lispflowmapping.interfaces.mappingservice.IMappingService;
@@ -84,6 +85,7 @@ public class MappingSystemTest {
     private static ILispDAO daoMock = Mockito.mock(ILispDAO.class);
     @Mock private static ILispMapCache smcMock;
     @Mock private static IMapCache pmcMock;
+    @Mock private static IAuthKeyDb akdbMock;
     @Mock private static DataStoreBackEnd dsbeMock;
     @Mock private static EnumMap<MappingOrigin, IMapCache> tableMapMock;
     @InjectMocks private static MappingSystem mappingSystem = new MappingSystem(daoMock, false, true, true);
@@ -479,8 +481,8 @@ public class MappingSystemTest {
         assertEquals(captor.getValue().getRecord(), mapping_1.getMappingRecord());
         Mockito.verify(pmcMock).addMapping(Mockito.eq(EID_IPV4_2), captor.capture());
         assertEquals(captor.getValue().getRecord(), mapping_2.getMappingRecord());
-        Mockito.verify(smcMock).addAuthenticationKey(EID_IPV4_1, mappingAuthkey_1);
-        Mockito.verify(smcMock).addAuthenticationKey(EID_IPV4_2, mappingAuthkey_2);
+        Mockito.verify(akdbMock).addAuthenticationKey(EID_IPV4_1, mappingAuthkey_1);
+        Mockito.verify(akdbMock).addAuthenticationKey(EID_IPV4_2, mappingAuthkey_2);
     }
 
     /**
@@ -489,7 +491,7 @@ public class MappingSystemTest {
     @Test
     public void addAuthenticationKeyTest() {
         mappingSystem.addAuthenticationKey(EID_IPV4_1, MAPPING_AUTHKEY_BUILDER.build());
-        Mockito.verify(smcMock).addAuthenticationKey(EID_IPV4_1, MAPPING_AUTHKEY_BUILDER.build());
+        Mockito.verify(akdbMock).addAuthenticationKey(EID_IPV4_1, MAPPING_AUTHKEY_BUILDER.build());
     }
 
     /**
@@ -497,7 +499,7 @@ public class MappingSystemTest {
      */
     @Test
     public void getAuthenticationKeyTest() {
-        Mockito.when(smcMock.getAuthenticationKey(EID_IPV4_1)).thenReturn(MAPPING_AUTHKEY_BUILDER.build());
+        Mockito.when(akdbMock.getAuthenticationKey(EID_IPV4_1)).thenReturn(MAPPING_AUTHKEY_BUILDER.build());
         assertEquals(MAPPING_AUTHKEY_BUILDER.build(), mappingSystem.getAuthenticationKey(EID_IPV4_1));
     }
 
@@ -507,7 +509,7 @@ public class MappingSystemTest {
     @Test
     public void removeAuthenticationKeyTest() {
         mappingSystem.removeAuthenticationKey(EID_IPV4_1);
-        Mockito.verify(smcMock).removeAuthenticationKey(EID_IPV4_1);
+        Mockito.verify(akdbMock).removeAuthenticationKey(EID_IPV4_1);
     }
 
     /**
diff --git a/mappingservice/mapcache/src/main/java/org/opendaylight/lispflowmapping/mapcache/AuthKeyDb.java b/mappingservice/mapcache/src/main/java/org/opendaylight/lispflowmapping/mapcache/AuthKeyDb.java
new file mode 100644 (file)
index 0000000..f66366e
--- /dev/null
@@ -0,0 +1,155 @@
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.lispflowmapping.mapcache;
+
+import org.opendaylight.lispflowmapping.interfaces.dao.ILispDAO;
+import org.opendaylight.lispflowmapping.interfaces.dao.IRowVisitor;
+import org.opendaylight.lispflowmapping.interfaces.dao.MappingEntry;
+import org.opendaylight.lispflowmapping.interfaces.dao.SubKeys;
+import org.opendaylight.lispflowmapping.interfaces.mapcache.IAuthKeyDb;
+import org.opendaylight.lispflowmapping.lisp.util.MaskUtil;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.SourceDestKey;
+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.mapping.authkey.container.MappingAuthkey;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Simple in-memory database for authentication keys, that works with 'simple' addresses (see lisp-proto.yang). It can
+ * do longest prefix matching for IP addresses.
+ *
+ * @author Lorand Jakab
+ *
+ */
+public class AuthKeyDb implements IAuthKeyDb {
+    private static final Logger LOG = LoggerFactory.getLogger(AuthKeyDb.class);
+    private ILispDAO dao;
+
+    public AuthKeyDb(ILispDAO dao) {
+        this.dao = dao;
+    }
+
+    private ILispDAO getVniTable(Eid eid) {
+        long vni = 0;
+        if (eid.getVirtualNetworkId() == null) {
+            vni = 0;
+        } else {
+            vni = eid.getVirtualNetworkId().getValue();
+        }
+        return (ILispDAO) dao.getSpecific(vni, SubKeys.VNI);
+    }
+
+    private ILispDAO getOrInstantiateVniTable(Eid eid) {
+        long vni = 0;
+        if (eid.getVirtualNetworkId() == null) {
+            vni = 0;
+        } else {
+            vni = eid.getVirtualNetworkId().getValue();
+        }
+        ILispDAO table = (ILispDAO) dao.getSpecific(vni, SubKeys.VNI);
+        if (table == null) {
+            table = dao.putNestedTable(vni, SubKeys.VNI);
+        }
+        return table;
+    }
+
+    @Override
+    public void addAuthenticationKey(Eid eid, MappingAuthkey authKey) {
+        Eid key = MaskUtil.normalize(eid);
+        ILispDAO table = getOrInstantiateVniTable(key);
+        table.put(key, new MappingEntry<>(SubKeys.AUTH_KEY, authKey));
+    }
+
+    private MappingAuthkey getAuthKeyLpm(Eid prefix, ILispDAO db) {
+        short maskLength = MaskUtil.getMaskForAddress(prefix.getAddress());
+        while (maskLength >= 0) {
+            Eid key = MaskUtil.normalize(prefix, maskLength);
+            Object password = db.getSpecific(key, SubKeys.AUTH_KEY);
+            if (password != null && password instanceof MappingAuthkey) {
+                return (MappingAuthkey) password;
+            }
+            maskLength -= 1;
+        }
+        return null;
+    }
+
+    /*
+     * Retrieves authentication key from the database. As opposed to the mapping cache, Source/Dest keys are treated as
+     * exact match keys here, and a two level longest prefix match is NOT performed.
+     */
+    @Override
+    public MappingAuthkey getAuthenticationKey(Eid eid) {
+        ILispDAO table = getVniTable(eid);
+        if (table == null) {
+            return null;
+        }
+        if (MaskUtil.isMaskable(eid.getAddress()) && !(eid.getAddress() instanceof SourceDestKey)) {
+            return getAuthKeyLpm(eid, table);
+        } else {
+            Eid key = MaskUtil.normalize(eid);
+            Object password = table.getSpecific(key, SubKeys.AUTH_KEY);
+            if (password != null && password instanceof MappingAuthkey) {
+                return (MappingAuthkey) password;
+            } else {
+                LOG.warn("Failed to find password!");
+                return null;
+            }
+        }
+    }
+
+    @Override
+    public void removeAuthenticationKey(Eid eid) {
+        Eid key = MaskUtil.normalize(eid);
+        ILispDAO table = getVniTable(key);
+        if (table == null) {
+            return;
+        }
+        table.removeSpecific(key, SubKeys.AUTH_KEY);
+    }
+
+    @Override
+    public String printKeys() {
+        final StringBuffer sb = new StringBuffer();
+        sb.append("Keys\tValues\n");
+
+        final IRowVisitor innerVisitor = (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("\n" + key + "\t");
+                }
+                sb.append(valueKey + "=" + value + "\t");
+                lastKey = key;
+            }
+        });
+
+        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("\n" + key + "\t");
+                }
+                if (valueKey.equals(SubKeys.VNI)) {
+                    sb.append(valueKey + "= { ");
+                    ((ILispDAO)value).getAll(innerVisitor);
+                    sb.append("}\t");
+                } else {
+                    sb.append(valueKey + "=" + value + "\t");
+                }
+                lastKey = key;
+            }
+        });
+        sb.append("\n");
+        return sb.toString();
+    }
+}
index 80e2f34f119bf355997198fb89cd39f6c4dc62e9..2764766984cbaf0beabe500b634c2161cd7c765d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
+ * Copyright (c) 2015, 2016 Cisco Systems, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -15,7 +15,6 @@ import org.opendaylight.lispflowmapping.interfaces.dao.SubKeys;
 import org.opendaylight.lispflowmapping.interfaces.mapcache.IMapCache;
 import org.opendaylight.lispflowmapping.lisp.util.MaskUtil;
 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.mapping.authkey.container.MappingAuthkey;
 
 /**
  * Flat key implementation of a map-cache. As the name suggests, no longest prefix matching is done for IP addresses
@@ -58,29 +57,6 @@ public class FlatMapCache implements IMapCache {
         dao.removeSpecific(key, SubKeys.RECORD);
     }
 
-    @Override
-    public void addAuthenticationKey(Eid eid, MappingAuthkey authKey) {
-        Eid key = MaskUtil.normalize(eid);
-        dao.put(key, new MappingEntry<>(SubKeys.AUTH_KEY, authKey));
-    }
-
-    @Override
-    public MappingAuthkey getAuthenticationKey(Eid eid) {
-        Eid key = MaskUtil.normalize(eid);
-        Object data = dao.getSpecific(key, SubKeys.AUTH_KEY);
-        if (data instanceof MappingAuthkey) {
-            return (MappingAuthkey) data;
-        } else {
-            return null;
-        }
-    }
-
-    @Override
-    public void removeAuthenticationKey(Eid eid) {
-        Eid key = MaskUtil.normalize(eid);
-        dao.removeSpecific(key, SubKeys.AUTH_KEY);
-    }
-
     @Override
     public void addData(Eid eid, String subKey, Object value) {
         Eid key = MaskUtil.normalize(eid);
index 38ded1bfed6ed1eafec4a56b447f6c3c2450ce3b..960927fb1674711bd1ca8ff5ad1e2b442a5dc74c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Contextream, Inc. and others.  All rights reserved.
+ * Copyright (c) 2014, 2016 Contextream, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -18,9 +18,6 @@ import org.opendaylight.lispflowmapping.lisp.util.MaskUtil;
 import org.opendaylight.lispflowmapping.lisp.util.SourceDestKeyHelper;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.SourceDestKey;
 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.mapping.authkey.container.MappingAuthkey;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 /**
  * Multi table map-cache that works with 'simple' and SourceDest LCAF addresses (see lisp-proto.yang). It can do longest
@@ -30,8 +27,6 @@ import org.slf4j.LoggerFactory;
  * @author Florin Coras
  */
 public class MultiTableMapCache implements IMapCache {
-    private static final Logger LOG = LoggerFactory.getLogger(MultiTableMapCache.class);
-
     private ILispDAO dao;
 
     public MultiTableMapCache(ILispDAO dao) {
@@ -157,77 +152,6 @@ public class MultiTableMapCache implements IMapCache {
         }
     }
 
-    public void addAuthenticationKey(Eid eid, MappingAuthkey authKey) {
-        Eid key = MaskUtil.normalize(eid);
-        ILispDAO table = getOrInstantiateVniTable(key);
-
-        if (key.getAddress() instanceof SourceDestKey) {
-            ILispDAO srcDstDao = getOrInstantiateSDInnerDao(key, table);
-            srcDstDao.put(SourceDestKeyHelper.getSrcBinary(key), new MappingEntry<>(SubKeys.AUTH_KEY, authKey));
-        } else {
-            table.put(key, new MappingEntry<>(SubKeys.AUTH_KEY, authKey));
-        }
-    }
-
-    private MappingAuthkey getAuthKeyLpm(Eid prefix, ILispDAO db) {
-        short maskLength = MaskUtil.getMaskForAddress(prefix.getAddress());
-        while (maskLength >= 0) {
-            Eid key = MaskUtil.normalize(prefix, maskLength);
-            Object password = db.getSpecific(key, SubKeys.AUTH_KEY);
-            if (password != null && password instanceof MappingAuthkey) {
-                return (MappingAuthkey) password;
-            }
-            maskLength -= 1;
-        }
-        return null;
-    }
-
-    public MappingAuthkey getAuthenticationKey(Eid eid) {
-        ILispDAO table = getVniTable(eid);
-        if (table == null) {
-            return null;
-        }
-
-        if (MaskUtil.isMaskable(eid.getAddress())) {
-            if (eid.getAddress() instanceof SourceDestKey) {
-                // NOTE: this is an exact match, not a longest prefix match
-                ILispDAO srcDstDao = getSDInnerDao(eid, table);
-                if (srcDstDao != null) {
-                    return getAuthKeyLpm(SourceDestKeyHelper.getSrcBinary(eid), srcDstDao);
-                }
-                return null;
-            } else {
-                return getAuthKeyLpm(eid, table);
-            }
-        } else {
-            Eid key = MaskUtil.normalize(eid);
-            Object password = table.getSpecific(key, SubKeys.AUTH_KEY);
-            if (password != null && password instanceof MappingAuthkey) {
-                return (MappingAuthkey) password;
-            } else {
-                LOG.warn("Failed to find password!");
-                return null;
-            }
-        }
-    }
-
-    public void removeAuthenticationKey(Eid eid) {
-        Eid key = MaskUtil.normalize(eid);
-        ILispDAO table = getVniTable(key);
-        if (table == null) {
-            return;
-        }
-
-        if (key.getAddress() instanceof SourceDestKey) {
-            ILispDAO srcDstDao = getSDInnerDao(key, table);
-            if (srcDstDao != null) {
-                srcDstDao.removeSpecific(key, SubKeys.AUTH_KEY);
-            }
-        } else {
-            table.removeSpecific(key, SubKeys.AUTH_KEY);
-        }
-    }
-
     // SrcDst LCAFs are stored in a 2-tier DAO with dst having priority over src.
     // This method returns the DAO associated to a dst or creates it if it doesn't exist.
     private ILispDAO getOrInstantiateSDInnerDao(Eid address, ILispDAO mappingsDb) {
index a2e88fcf4245c044651c351854e654b65c16a2c9..1de9ddcf0e2796d92364b4c35d1cab06a3ce8b86 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
+ * Copyright (c) 2015, 2016 Cisco Systems, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -19,13 +19,9 @@ import org.opendaylight.lispflowmapping.interfaces.dao.MappingEntry;
 import org.opendaylight.lispflowmapping.interfaces.dao.SubKeys;
 import org.opendaylight.lispflowmapping.interfaces.mapcache.ILispMapCache;
 import org.opendaylight.lispflowmapping.lisp.util.MaskUtil;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.SourceDestKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.inet.binary.types.rev160303.IpAddressBinary;
 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.mapping.authkey.container.MappingAuthkey;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 /**
  * Simple map-cache that works with 'simple' addresses (see lisp-proto.yang). It can do longest prefix matching for IP
@@ -36,7 +32,6 @@ import org.slf4j.LoggerFactory;
  *
  */
 public class SimpleMapCache implements ILispMapCache {
-    private static final Logger LOG = LoggerFactory.getLogger(SimpleMapCache.class);
     private ILispDAO dao;
 
     public SimpleMapCache(ILispDAO dao) {
@@ -222,56 +217,6 @@ public class SimpleMapCache implements ILispMapCache {
         }
     }
 
-    @Override
-    public void addAuthenticationKey(Eid eid, MappingAuthkey authKey) {
-        Eid key = MaskUtil.normalize(eid);
-        ILispDAO table = getOrInstantiateVniTable(key);
-        table.put(key, new MappingEntry<>(SubKeys.AUTH_KEY, authKey));
-    }
-
-    private MappingAuthkey getAuthKeyLpm(Eid prefix, ILispDAO db) {
-        short maskLength = MaskUtil.getMaskForAddress(prefix.getAddress());
-        while (maskLength >= 0) {
-            Eid key = MaskUtil.normalize(prefix, maskLength);
-            Object password = db.getSpecific(key, SubKeys.AUTH_KEY);
-            if (password != null && password instanceof MappingAuthkey) {
-                return (MappingAuthkey) password;
-            }
-            maskLength -= 1;
-        }
-        return null;
-    }
-
-    @Override
-    public MappingAuthkey getAuthenticationKey(Eid eid) {
-        ILispDAO table = getVniTable(eid);
-        if (table == null) {
-            return null;
-        }
-        if (MaskUtil.isMaskable(eid.getAddress()) && !(eid.getAddress() instanceof SourceDestKey)) {
-            return getAuthKeyLpm(eid, table);
-        } else {
-            Eid key = MaskUtil.normalize(eid);
-            Object password = table.getSpecific(key, SubKeys.AUTH_KEY);
-            if (password != null && password instanceof MappingAuthkey) {
-                return (MappingAuthkey) password;
-            } else {
-                LOG.warn("Failed to find password!");
-                return null;
-            }
-        }
-    }
-
-    @Override
-    public void removeAuthenticationKey(Eid eid) {
-        Eid key = MaskUtil.normalize(eid);
-        ILispDAO table = getVniTable(key);
-        if (table == null) {
-            return;
-        }
-        table.removeSpecific(key, SubKeys.AUTH_KEY);
-    }
-
     @Override
     public void addData(Eid eid, String subKey, Object data) {
         Eid key = MaskUtil.normalize(eid);
diff --git a/mappingservice/mapcache/src/test/java/org/opendaylight/lispflowmapping/mapcache/AuthKeyDbTest.java b/mappingservice/mapcache/src/test/java/org/opendaylight/lispflowmapping/mapcache/AuthKeyDbTest.java
new file mode 100644 (file)
index 0000000..673cd8c
--- /dev/null
@@ -0,0 +1,131 @@
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.lispflowmapping.mapcache;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.opendaylight.lispflowmapping.interfaces.dao.ILispDAO;
+import org.opendaylight.lispflowmapping.interfaces.dao.MappingEntry;
+import org.opendaylight.lispflowmapping.interfaces.dao.SubKeys;
+import org.opendaylight.lispflowmapping.lisp.util.LispAddressUtil;
+import org.opendaylight.lispflowmapping.lisp.util.MaskUtil;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.InstanceIdType;
+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.mapping.authkey.container.MappingAuthkey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.authkey.container.MappingAuthkeyBuilder;
+
+public class AuthKeyDbTest {
+
+    private static ILispDAO tableMock;
+    private static ILispDAO daoMock;
+    private static AuthKeyDb authKeyDb;
+
+    private static final String IPV4_STRING_1 =      "1.2.3.0";
+    private static final String IPV4_PREFIX_STRING = "/24";
+    private static final short MASK = 24;
+    private static final long VNI_0 = 0L;
+    private static final long VNI_100 = 100L;
+
+    private static final Eid EID_IPV4_PREFIX_1_VNI = LispAddressUtil
+            .asIpv4PrefixEid(IPV4_STRING_1 + IPV4_PREFIX_STRING, new InstanceIdType(VNI_100));
+    private static final Eid EID_IPV4 = LispAddressUtil.asIpv4Eid(IPV4_STRING_1);
+    private static final Eid NORMALIZED_EID_IPV4 = MaskUtil.normalize(EID_IPV4);
+    private static final MappingAuthkey MAPPING_AUTHKEY = new MappingAuthkeyBuilder()
+            .setKeyString("pass")
+            .setKeyType(1).build();
+
+    @Before
+    public void init() {
+        daoMock = Mockito.mock(ILispDAO.class, "dao");
+        tableMock = Mockito.mock(ILispDAO.class);
+        authKeyDb = new AuthKeyDb(daoMock);
+    }
+
+    /**
+     * Tests {@link AuthKeyDb#addAuthenticationKey} method.
+     */
+    @Test
+    public void addAuthenticationKeyTest() {
+        Mockito.when(daoMock.getSpecific(VNI_0, SubKeys.VNI)).thenReturn(tableMock);
+
+        authKeyDb.addAuthenticationKey(EID_IPV4, MAPPING_AUTHKEY);
+        Mockito.verify(tableMock)
+                .put(MaskUtil.normalize(EID_IPV4), new MappingEntry<>(SubKeys.AUTH_KEY, MAPPING_AUTHKEY));
+    }
+
+    /**
+     * Tests {@link AuthKeyDb#getAuthenticationKey} method with maskable address.
+     */
+    @Test
+    public void getAuthenticationKeyTest_withMaskableAddress() {
+        Mockito.when(daoMock.getSpecific(VNI_100, SubKeys.VNI)).thenReturn(tableMock);
+        Mockito.when(tableMock.getSpecific(MaskUtil.normalize(EID_IPV4_PREFIX_1_VNI, MASK), SubKeys.AUTH_KEY))
+                .thenReturn(MAPPING_AUTHKEY);
+
+        assertEquals(MAPPING_AUTHKEY, authKeyDb.getAuthenticationKey(EID_IPV4_PREFIX_1_VNI));
+    }
+
+    /**
+     * Tests {@link AuthKeyDb#getAuthenticationKey} method with non maskable address.
+     */
+    @Test
+    public void addAuthenticationKeyTest_withNonMaskableAddress() {
+        Mockito.when(daoMock.getSpecific(VNI_0, SubKeys.VNI)).thenReturn(tableMock);
+        Mockito.when(tableMock.getSpecific(NORMALIZED_EID_IPV4, SubKeys.AUTH_KEY)).thenReturn(MAPPING_AUTHKEY);
+
+        assertEquals(MAPPING_AUTHKEY, authKeyDb.getAuthenticationKey(EID_IPV4));
+        Mockito.verify(tableMock).getSpecific(NORMALIZED_EID_IPV4, SubKeys.AUTH_KEY);
+    }
+
+    /**
+     * Tests {@link AuthKeyDb#getAuthenticationKey} method with no MappingAuthkey.
+     */
+    @Test
+    public void addAuthenticationKeyTest_withNoMappingAuthkey() {
+        Mockito.when(daoMock.getSpecific(VNI_0, SubKeys.VNI)).thenReturn(tableMock);
+        Mockito.when(tableMock.getSpecific(NORMALIZED_EID_IPV4, SubKeys.AUTH_KEY)).thenReturn(null);
+
+        assertNull(authKeyDb.getAuthenticationKey(EID_IPV4));
+    }
+
+    /**
+     * Tests {@link AuthKeyDb#getAuthenticationKey} method with no VNI_100 table.
+     */
+    @Test
+    public void addAuthenticationKeyTest_withNullVniTable() {
+        Mockito.when(daoMock.getSpecific(VNI_0, SubKeys.VNI)).thenReturn(null);
+
+        assertNull(authKeyDb.getAuthenticationKey(EID_IPV4));
+    }
+
+    /**
+     * Tests {@link AuthKeyDb#removeAuthenticationKey} method.
+     */
+    @Test
+    public void removeAuthenticationKeyTest() {
+        Mockito.when(daoMock.getSpecific(VNI_0, SubKeys.VNI)).thenReturn(tableMock);
+
+        authKeyDb.removeAuthenticationKey(EID_IPV4);
+        Mockito.verify(tableMock).removeSpecific(NORMALIZED_EID_IPV4, SubKeys.AUTH_KEY);
+    }
+
+    /**
+     * Tests {@link AuthKeyDb#removeAuthenticationKey} method with no VNI_100 table.
+     */
+    @Test
+    public void removeAuthenticationKeyTest_withNoVniTable() {
+        Mockito.when(daoMock.getSpecific(VNI_0, SubKeys.VNI)).thenReturn(null);
+
+        authKeyDb.removeAuthenticationKey(EID_IPV4);
+        Mockito.verify(tableMock, Mockito.never()).removeSpecific(Mockito.any(Eid.class), Mockito.anyString());
+    }
+}
index faa02a38caa02b07239e318c22726407f6ad534f..0b30097fce088c89d5683b5866f5902bdf3abd4a 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.lispflowmapping.mapcache;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.anyString;
 import static org.mockito.Mockito.atMost;
@@ -27,8 +26,6 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Builder;
 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.eid.container.EidBuilder;
-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.authkey.container.MappingAuthkeyBuilder;
 
 public class FlatMapCacheTest {
 
@@ -39,8 +36,6 @@ public class FlatMapCacheTest {
 
     private static final Eid EID_TEST = new EidBuilder().setAddress(new Ipv4Builder()
             .setIpv4(new Ipv4Address("127.0.0.1")).build()).build();
-    private static final MappingAuthkey MAPPING_AUTHKEY = new MappingAuthkeyBuilder().setKeyString("auth_string_test")
-            .build();
     private static final Eid NORMALIZED_EID = MaskUtil.normalize(EID_TEST);
 
     @Before
@@ -77,42 +72,6 @@ public class FlatMapCacheTest {
         verify(daoMock).removeSpecific(NORMALIZED_EID, SubKeys.RECORD);
     }
 
-    /**
-     * Tests {@link FlatMapCache#addAuthenticationKey}.
-     */
-    @Test
-    public void addAuthenticationKeyTest() {
-        flatMapCache.addAuthenticationKey(EID_TEST, MAPPING_AUTHKEY);
-        verify(daoMock, atMost(1)).put(NORMALIZED_EID, new MappingEntry<>(SubKeys.AUTH_KEY, MAPPING_AUTHKEY));
-    }
-
-    /**
-     * Tests {@link FlatMapCache#getAuthenticationKey}.
-     */
-    @Test
-    public void getAuthenticationKeyTest() {
-        when(daoMock.getSpecific(NORMALIZED_EID, SubKeys.AUTH_KEY)).thenReturn(MAPPING_AUTHKEY);
-        assertEquals(MAPPING_AUTHKEY, flatMapCache.getAuthenticationKey(EID_TEST));
-    }
-
-    /**
-     * Tests {@link FlatMapCache#getAuthenticationKey} with other than MappingAuthkey object.
-     */
-    @Test
-    public void getAuthenticationKeyTest_withNull() {
-        when(daoMock.getSpecific(NORMALIZED_EID, SubKeys.AUTH_KEY)).thenReturn(new Object());
-        assertNull(flatMapCache.getAuthenticationKey(EID_TEST));
-    }
-
-    /**
-     * Tests {@link FlatMapCache#removeAuthenticationKey}.
-     */
-    @Test
-    public void removeAuthenticationKeyTest() {
-        flatMapCache.removeAuthenticationKey(EID_TEST);
-        verify(daoMock).removeSpecific(NORMALIZED_EID, SubKeys.AUTH_KEY);
-    }
-
     /**
      * Tests {@link FlatMapCache#addData}.
      */
index eb13f1a4613e5b06b095b585ebda5f4c3256d2c9..bdc4200597dbed5040d2e5ef91b675e9802fbc8b 100644 (file)
@@ -32,13 +32,9 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.addres
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SimpleAddress;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Builder;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4PrefixBuilder;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.MacBuilder;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.SourceDestKeyBuilder;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
 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.eid.container.EidBuilder;
-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.authkey.container.MappingAuthkeyBuilder;
 
 public class MultiTableMapCacheTest {
 
@@ -67,13 +63,9 @@ public class MultiTableMapCacheTest {
             .setAddress(new Ipv4PrefixBuilder().setIpv4Prefix(IPV_4_PREFIX_DST).build()).build();
     private static final Eid NORMALIZED_SRCDST_EID = MaskUtil.normalize(EID_SOURCE_DEST_KEY_TYPE);
     private static final Eid NORMALIZED_PREFIX_SRC_EID = MaskUtil.normalize(EID_IPV4_PREFIX_SRC);
-    private static final Eid EID_MAC = new EidBuilder().setVirtualNetworkId(new InstanceIdType(VNI))
-            .setAddress(new MacBuilder().setMac(new MacAddress("aa:bb:cc:dd:ee:ff")).build()).build();
     private static final Eid NORMALIZED_EID = MaskUtil.normalize(EID_TEST);
     private static final Object DUMMY_OBJECT = "dummy_object";
     private static final Object DUMMY_OBJECT_2 = "mapping_lpm_eid";
-    private static final MappingAuthkey MAPPING_AUTHKEY = new MappingAuthkeyBuilder()
-            .setKeyString("mapping_authkey_test").build();
 
     @Before
     public void init() {
@@ -214,139 +206,6 @@ public class MultiTableMapCacheTest {
         verifyZeroInteractions(dbMock);
     }
 
-    /**
-     * Tests {@link MultiTableMapCache#addAuthenticationKey}.
-     */
-    @Test
-    public void addAuthenticationKeyTest() {
-        when(daoMock.getSpecific(VNI, SubKeys.VNI)).thenReturn(tableDaoMock);
-        when(tableDaoMock.putNestedTable(SourceDestKeyHelper.getDstBinary(NORMALIZED_SRCDST_EID), SubKeys.LCAF_SRCDST))
-                .thenReturn(srcDstDaoMock);
-
-        multiTableMapCache.addAuthenticationKey(EID_SOURCE_DEST_KEY_TYPE, MAPPING_AUTHKEY);
-        verify(srcDstDaoMock).put(SourceDestKeyHelper.getSrcBinary(NORMALIZED_SRCDST_EID),
-                new MappingEntry<>(SubKeys.AUTH_KEY, MAPPING_AUTHKEY));
-
-        multiTableMapCache.addAuthenticationKey(EID_TEST, MAPPING_AUTHKEY);
-        verify(tableDaoMock).put(NORMALIZED_EID, new MappingEntry<>(SubKeys.AUTH_KEY, MAPPING_AUTHKEY));
-    }
-
-    /**
-     * Tests {@link MultiTableMapCache#getAuthenticationKey} with Ipv4Prefix address.
-     */
-    @Test
-    public void getAuthenticationKeyTest_withIpv4Prefix() {
-        final short maskLength = MaskUtil.getMaskForAddress(EID_IPV4_PREFIX_SRC.getAddress());
-        final Eid key = MaskUtil.normalize(EID_IPV4_PREFIX_SRC, maskLength);
-
-        when(daoMock.getSpecific(0L, SubKeys.VNI)).thenReturn(tableDaoMock);
-        when(tableDaoMock.getSpecific(key, SubKeys.AUTH_KEY)).thenReturn(MAPPING_AUTHKEY);
-
-        assertEquals(MAPPING_AUTHKEY, multiTableMapCache.getAuthenticationKey(EID_IPV4_PREFIX_SRC));
-    }
-
-    /**
-     * Tests {@link MultiTableMapCache#getAuthenticationKey} with SourceDestKey address.
-     */
-    @Test
-    public void getAuthenticationKeyTest_withSourceDestKey() {
-        final Eid eidSrc = SourceDestKeyHelper.getSrcBinary(EID_SOURCE_DEST_KEY_TYPE);
-        final Eid eidDst = SourceDestKeyHelper.getDstBinary(EID_SOURCE_DEST_KEY_TYPE);
-        final short maskLength = MaskUtil.getMaskForAddress(eidSrc.getAddress());
-        final Eid key = MaskUtil.normalize(eidSrc, maskLength);
-
-        when(daoMock.getSpecific(VNI, SubKeys.VNI)).thenReturn(tableDaoMock);
-        when(tableDaoMock.getSpecific(eidDst, SubKeys.LCAF_SRCDST))
-                .thenReturn(srcDstDaoMock);
-        when(srcDstDaoMock.getSpecific(key, SubKeys.AUTH_KEY)).thenReturn(MAPPING_AUTHKEY);
-
-        assertEquals(MAPPING_AUTHKEY, multiTableMapCache.getAuthenticationKey(EID_SOURCE_DEST_KEY_TYPE));
-    }
-
-    /**
-     * Tests {@link MultiTableMapCache#getAuthenticationKey} with SourceDestKey address, srcDstDao == null.
-     */
-    @Test
-    public void getAuthenticationKeyTest_withSourceDestKey_nullDao() {
-        final Eid eidDst = SourceDestKeyHelper.getDstBinary(EID_SOURCE_DEST_KEY_TYPE);
-
-        when(daoMock.getSpecific(VNI, SubKeys.VNI)).thenReturn(tableDaoMock);
-        when(tableDaoMock.getSpecific(eidDst, SubKeys.LCAF_SRCDST))
-                .thenReturn(null);
-
-        assertNull(multiTableMapCache.getAuthenticationKey(EID_SOURCE_DEST_KEY_TYPE));
-    }
-
-    /**
-     * Tests {@link MultiTableMapCache#getAuthenticationKey} with Mac address.
-     */
-    @Test
-    public void getAuthenticationKeyTest_withMac() {
-        final Eid key = MaskUtil.normalize(EID_MAC);
-
-        when(daoMock.getSpecific(VNI, SubKeys.VNI)).thenReturn(tableDaoMock);
-        when(tableDaoMock.getSpecific(key, SubKeys.AUTH_KEY)).thenReturn(MAPPING_AUTHKEY);
-
-        assertEquals(MAPPING_AUTHKEY, multiTableMapCache.getAuthenticationKey(EID_MAC));
-    }
-
-    /**
-     * Tests {@link MultiTableMapCache#getAuthenticationKey} with Mac address, failed authentication.
-     */
-    @Test
-    public void getAuthenticationKeyTest_withMac_failedAuthentication() {
-        final Eid key = MaskUtil.normalize(EID_MAC);
-
-        when(daoMock.getSpecific(VNI, SubKeys.VNI)).thenReturn(tableDaoMock);
-        when(tableDaoMock.getSpecific(key, SubKeys.AUTH_KEY)).thenReturn(null);
-
-        assertNull(multiTableMapCache.getAuthenticationKey(EID_MAC));
-    }
-
-    /**
-     * Tests {@link MultiTableMapCache#getAuthenticationKey} with Mac address, table == null.
-     */
-    @Test
-    public void getAuthenticationKeyTest_withMac_nullTable() {
-        when(daoMock.getSpecific(VNI, SubKeys.VNI)).thenReturn(null);
-        assertNull(multiTableMapCache.getAuthenticationKey(EID_MAC));
-    }
-
-    /**
-     * Tests {@link MultiTableMapCache#removeAuthenticationKey} with SourceDestKey address type.
-     */
-    @Test
-    public void removeAuthenticationKeyTest_withSourceDestKey() {
-        when(daoMock.getSpecific(VNI, SubKeys.VNI)).thenReturn(tableDaoMock);
-        when(tableDaoMock.getSpecific(SourceDestKeyHelper.getDstBinary(NORMALIZED_SRCDST_EID), SubKeys.LCAF_SRCDST))
-                .thenReturn(srcDstDaoMock);
-
-        multiTableMapCache.removeAuthenticationKey(EID_SOURCE_DEST_KEY_TYPE);
-        verify(srcDstDaoMock).removeSpecific(NORMALIZED_SRCDST_EID, SubKeys.AUTH_KEY);
-    }
-
-    /**
-     * Tests {@link MultiTableMapCache#removeAuthenticationKey} with Ipv4 address type.
-     */
-    @Test
-    public void removeAuthenticationKeyTest_withIpv4() {
-        when(daoMock.getSpecific(VNI, SubKeys.VNI)).thenReturn(tableDaoMock);
-
-        multiTableMapCache.removeAuthenticationKey(EID_TEST);
-        verify(tableDaoMock).removeSpecific(NORMALIZED_EID, SubKeys.AUTH_KEY);
-    }
-
-    /**
-     * Tests {@link MultiTableMapCache#removeAuthenticationKey} with table == null.
-     */
-    @Test
-    public void removeAuthenticationKeyTest_withNullTable() {
-        when(daoMock.getSpecific(VNI, SubKeys.VNI)).thenReturn(null);
-
-        multiTableMapCache.removeAuthenticationKey(EID_TEST);
-        verifyZeroInteractions(tableDaoMock);
-    }
-
     /**
      * Tests {@link MultiTableMapCache#addData} with SourceDestKey address type.
      */
index b57b70d77b46bce1aa0f58e9f9e56babc1481427..1a2418a7bdca3eee5a2f666ebb17830c5727811a 100644 (file)
@@ -28,8 +28,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.inet.binary.types.rev16
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.inet.binary.types.rev160303.Ipv4AddressBinary;
 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.mapping.authkey.container.MappingAuthkey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.authkey.container.MappingAuthkeyBuilder;
 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;
 
@@ -63,9 +61,6 @@ public class SimpleMapCacheTest {
     private static final Eid NORMALIZED_EID_IPV4_PREFIX_DST = MaskUtil.normalize(EID_IPV4_PREFIX_DST, (short) 24);
 
     private static final IpAddressBinary IP_ADDRESS = new IpAddressBinary(new Ipv4AddressBinary(IPV4_RLOC_BINARY));
-    private static final MappingAuthkey MAPPING_AUTHKEY = new MappingAuthkeyBuilder()
-            .setKeyString("pass")
-            .setKeyType(1).build();
 
     @Before
     public void init() {
@@ -130,85 +125,6 @@ public class SimpleMapCacheTest {
         Mockito.verifyNoMoreInteractions(tableMock);
     }
 
-    /**
-     * Tests {@link SimpleMapCache#addAuthenticationKey} method.
-     */
-    @Test
-    public void addAuthenticationKeyTest() {
-        Mockito.when(daoMock.getSpecific(VNI_0, SubKeys.VNI)).thenReturn(tableMock);
-
-        simpleMapCache.addAuthenticationKey(EID_IPV4, MAPPING_AUTHKEY);
-        Mockito.verify(tableMock)
-                .put(MaskUtil.normalize(EID_IPV4), new MappingEntry<>(SubKeys.AUTH_KEY, MAPPING_AUTHKEY));
-    }
-
-    /**
-     * Tests {@link SimpleMapCache#getAuthenticationKey} method with maskable address.
-     */
-    @Test
-    public void getAuthenticationKeyTest_withMaskableAddress() {
-        Mockito.when(daoMock.getSpecific(VNI_100, SubKeys.VNI)).thenReturn(tableMock);
-        Mockito.when(tableMock.getSpecific(MaskUtil.normalize(EID_IPV4_PREFIX_1_VNI, MASK), SubKeys.AUTH_KEY))
-                .thenReturn(MAPPING_AUTHKEY);
-
-        assertEquals(MAPPING_AUTHKEY, simpleMapCache.getAuthenticationKey(EID_IPV4_PREFIX_1_VNI));
-    }
-
-    /**
-     * Tests {@link SimpleMapCache#getAuthenticationKey} method with non maskable address.
-     */
-    @Test
-    public void addAuthenticationKeyTest_withNonMaskableAddress() {
-        Mockito.when(daoMock.getSpecific(VNI_0, SubKeys.VNI)).thenReturn(tableMock);
-        Mockito.when(tableMock.getSpecific(NORMALIZED_EID_IPV4, SubKeys.AUTH_KEY)).thenReturn(MAPPING_AUTHKEY);
-
-        assertEquals(MAPPING_AUTHKEY, simpleMapCache.getAuthenticationKey(EID_IPV4));
-        Mockito.verify(tableMock).getSpecific(NORMALIZED_EID_IPV4, SubKeys.AUTH_KEY);
-    }
-
-    /**
-     * Tests {@link SimpleMapCache#getAuthenticationKey} method with no MappingAuthkey.
-     */
-    @Test
-    public void addAuthenticationKeyTest_withNoMappingAuthkey() {
-        Mockito.when(daoMock.getSpecific(VNI_0, SubKeys.VNI)).thenReturn(tableMock);
-        Mockito.when(tableMock.getSpecific(NORMALIZED_EID_IPV4, SubKeys.AUTH_KEY)).thenReturn(null);
-
-        assertNull(simpleMapCache.getAuthenticationKey(EID_IPV4));
-    }
-
-    /**
-     * Tests {@link SimpleMapCache#getAuthenticationKey} method with no VNI_100 table.
-     */
-    @Test
-    public void addAuthenticationKeyTest_withNullVniTable() {
-        Mockito.when(daoMock.getSpecific(VNI_0, SubKeys.VNI)).thenReturn(null);
-
-        assertNull(simpleMapCache.getAuthenticationKey(EID_IPV4));
-    }
-
-    /**
-     * Tests {@link SimpleMapCache#removeAuthenticationKey} method.
-     */
-    @Test
-    public void removeAuthenticationKeyTest() {
-        Mockito.when(daoMock.getSpecific(VNI_0, SubKeys.VNI)).thenReturn(tableMock);
-
-        simpleMapCache.removeAuthenticationKey(EID_IPV4);
-        Mockito.verify(tableMock).removeSpecific(NORMALIZED_EID_IPV4, SubKeys.AUTH_KEY);
-    }
-
-    /**
-     * Tests {@link SimpleMapCache#removeAuthenticationKey} method with no VNI_100 table.
-     */
-    @Test
-    public void removeAuthenticationKeyTest_withNoVniTable() {
-        Mockito.when(daoMock.getSpecific(VNI_0, SubKeys.VNI)).thenReturn(null);
-
-        simpleMapCache.removeAuthenticationKey(EID_IPV4);
-        Mockito.verify(tableMock, Mockito.never()).removeSpecific(Mockito.any(Eid.class), Mockito.anyString());
-    }
-
     /**
      * Tests {@link SimpleMapCache#getAllXtrIdMappings} method with maskable address.
      */
index 77167967ba665d6aa100bd064cb9bfba5e1b1593..f28db4ea5f7b2d02211259392697e0e08a4f1bfc 100644 (file)
@@ -13,7 +13,7 @@ import org.apache.karaf.shell.console.OsgiCommandSupport;
 import org.opendaylight.lispflowmapping.interfaces.mappingservice.IMappingServiceShell;
 
 /**
- * This class implements the "lisp:addkey" Karaf shell command.
+ * This class implements the "mappingservice:addkey" Karaf shell command.
  *
  * @author Lorand Jakab
  *
diff --git a/mappingservice/shell/src/main/java/org/opendaylight/lispflowmapping/shell/LispKeys.java b/mappingservice/shell/src/main/java/org/opendaylight/lispflowmapping/shell/LispKeys.java
new file mode 100644 (file)
index 0000000..34436e8
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.lispflowmapping.shell;
+
+import org.apache.karaf.shell.commands.Command;
+import org.apache.karaf.shell.console.OsgiCommandSupport;
+import org.opendaylight.lispflowmapping.interfaces.mappingservice.IMappingServiceShell;
+
+/**
+ * This class implements the "mappingservice:keys" Karaf shell command.
+ *
+ * @author Lorand Jakab
+ *
+ */
+@Command(scope = "mappingservice", name = "keys", description = "Print LISP authentication keys")
+public class LispKeys  extends OsgiCommandSupport {
+    private IMappingServiceShell mappingServiceShell;
+
+    /*
+     * TODO  Eventually it would be best to merge the addkey command into this one, using optional arguments.
+     */
+
+    @Override
+    @SuppressWarnings("checkstyle:RegexpSinglelineJava")
+    protected Object doExecute() throws Exception {
+        System.out.print(mappingServiceShell.printKeys());
+        return null;
+    }
+
+    public void setMappingServiceShell(IMappingServiceShell mappingServiceShell) {
+        this.mappingServiceShell = mappingServiceShell;
+    }
+}
index c9d6e71f7cc55b33a083bc36f84ad8c2cb84a2ce..ecb36a2531a8683cafe4e5eb277537b53dc6223f 100644 (file)
@@ -13,12 +13,12 @@ import org.apache.karaf.shell.console.OsgiCommandSupport;
 import org.opendaylight.lispflowmapping.interfaces.mappingservice.IMappingServiceShell;
 
 /**
- * This class implements the "lisp:mappings" Karaf shell command.
+ * This class implements the "mappingservice:mappings" Karaf shell command.
  *
  * @author Lorand Jakab
  *
  */
-@Command(scope = "mappingservice", name = "mappings", description = "Print LISP mapping database")
+@Command(scope = "mappingservice", name = "mappings", description = "Print mapping database")
 public class LispMappings  extends OsgiCommandSupport {
     private IMappingServiceShell mappingServiceShell;
 
index 6008115c7523c9c69731e54af856653a6ecf99ed..1717040413041c4225f1b1d0d65480e4502a39ba 100644 (file)
@@ -6,6 +6,11 @@
         <property name="mappingServiceShell" ref="mappingServiceShellRef"/>
       </action>
     </command>
+    <command>
+      <action class="org.opendaylight.lispflowmapping.shell.LispKeys">
+        <property name="mappingServiceShell" ref="mappingServiceShellRef"/>
+      </action>
+    </command>
     <command>
       <action class="org.opendaylight.lispflowmapping.shell.LispAddKey">
         <property name="mappingServiceShell" ref="mappingServiceShellRef"/>
index dde1c45463434bc09a9e28b5491fcc5e3165a985..58286e68c6bb0d02b73c42986e5e0252e7107abf 100644 (file)
@@ -40,7 +40,7 @@ import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService
 import org.opendaylight.lispflowmapping.dsbackend.DataStoreBackEnd;
 import org.opendaylight.lispflowmapping.inmemorydb.HashMapDb;
 import org.opendaylight.lispflowmapping.lisp.type.LispMessage;
-import org.opendaylight.lispflowmapping.mapcache.SimpleMapCache;
+import org.opendaylight.lispflowmapping.mapcache.AuthKeyDb;
 import org.opendaylight.lispflowmapping.southbound.lisp.AuthenticationKeyDataListener;
 import org.opendaylight.lispflowmapping.southbound.lisp.LispSouthboundHandler;
 import org.opendaylight.lispflowmapping.southbound.lisp.LispXtrSouthboundHandler;
@@ -62,7 +62,7 @@ public class LispSouthboundPlugin implements IConfigLispSouthboundPlugin, AutoCl
             LISPFLOWMAPPING_ENTITY_NAME);
 
     private volatile String bindingAddress;
-    private SimpleMapCache smc;
+    private AuthKeyDb akdb;
     private MapRegisterCache mapRegisterCache = new MapRegisterCache();
     private boolean mapRegisterCacheEnabled;
     private long mapRegisterCacheTimeout;
@@ -106,14 +106,14 @@ public class LispSouthboundPlugin implements IConfigLispSouthboundPlugin, AutoCl
     public void init() {
         LOG.info("LISP (RFC6830) Southbound Plugin is initializing...");
         synchronized (startLock) {
-            this.smc = new SimpleMapCache(new HashMapDb());
-            this.authenticationKeyDataListener = new AuthenticationKeyDataListener(dataBroker, smc);
+            this.akdb = new AuthKeyDb(new HashMapDb());
+            this.authenticationKeyDataListener = new AuthenticationKeyDataListener(dataBroker, akdb);
             this.dsbe = new DataStoreBackEnd(dataBroker);
 
             lispSouthboundHandler = new LispSouthboundHandler(this);
             lispSouthboundHandler.setDataBroker(dataBroker);
             lispSouthboundHandler.setNotificationProvider(notificationPublishService);
-            lispSouthboundHandler.setSimpleMapCache(smc);
+            lispSouthboundHandler.setAuthKeyDb(akdb);
             lispSouthboundHandler.setMapRegisterCache(mapRegisterCache);
             lispSouthboundHandler.setMapRegisterCacheTimeout(mapRegisterCacheTimeout);
             lispSouthboundHandler.setAuthenticationKeyDataListener(authenticationKeyDataListener);
index 2856d4023afaaeef8e7963e6b7b5327d4d764134..79bb3ab89e8f3c2c11dc726ac315436c63af5f9b 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.lispflowmapping.southbound.lisp;
 
 import java.util.Collection;
-
 import org.opendaylight.controller.md.sal.binding.api.ClusteredDataTreeChangeListener;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
@@ -17,7 +16,7 @@ import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.lispflowmapping.lisp.util.LispAddressUtil;
-import org.opendaylight.lispflowmapping.mapcache.SimpleMapCache;
+import org.opendaylight.lispflowmapping.mapcache.AuthKeyDb;
 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.MappingDatabase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.AuthenticationKey;
@@ -35,7 +34,7 @@ import org.slf4j.LoggerFactory;
 public class AuthenticationKeyDataListener implements ClusteredDataTreeChangeListener<AuthenticationKey> {
     private static final Logger LOG = LoggerFactory.getLogger(AuthenticationKeyDataListener.class);
 
-    private final SimpleMapCache smc;
+    private final AuthKeyDb akdb;
     private final DataBroker broker;
     private final InstanceIdentifier<AuthenticationKey> path;
     private ListenerRegistration<ClusteredDataTreeChangeListener<AuthenticationKey>> registration;
@@ -43,9 +42,9 @@ public class AuthenticationKeyDataListener implements ClusteredDataTreeChangeLis
     private long authKeyRefreshingDate;
 
 
-    public AuthenticationKeyDataListener(final DataBroker broker, final SimpleMapCache smc) {
+    public AuthenticationKeyDataListener(final DataBroker broker, final AuthKeyDb akdb) {
         this.broker = broker;
-        this.smc = smc;
+        this.akdb = akdb;
         this.path = InstanceIdentifier.create(MappingDatabase.class).child(VirtualNetworkIdentifier.class)
                 .child(AuthenticationKey.class);
         LOG.trace("Registering AuthenticationKey listener.");
@@ -86,7 +85,7 @@ public class AuthenticationKeyDataListener implements ClusteredDataTreeChangeLis
 
                 final AuthenticationKey convertedAuthKey = convertToBinaryIfNecessary(authKey);
 
-                smc.removeAuthenticationKey(convertedAuthKey.getEid());
+                akdb.removeAuthenticationKey(convertedAuthKey.getEid());
             } else if (ModificationType.WRITE == mod.getModificationType() || ModificationType.SUBTREE_MODIFIED == mod
                     .getModificationType()) {
                 if (ModificationType.WRITE == mod.getModificationType()) {
@@ -102,7 +101,7 @@ public class AuthenticationKeyDataListener implements ClusteredDataTreeChangeLis
 
                 final AuthenticationKey convertedAuthKey = convertToBinaryIfNecessary(authKey);
 
-                smc.addAuthenticationKey(convertedAuthKey.getEid(), convertedAuthKey.getMappingAuthkey());
+                akdb.addAuthenticationKey(convertedAuthKey.getEid(), convertedAuthKey.getMappingAuthkey());
             } else {
                 LOG.warn("Ignoring unhandled modification type {}", mod.getModificationType());
             }
index 3c42818a49154778d19519672790fe379d6012d7..3a3493a9361609c9663925dc7adc2516af0bfcc7 100644 (file)
@@ -34,7 +34,7 @@ import org.opendaylight.lispflowmapping.lisp.type.LispMessage;
 import org.opendaylight.lispflowmapping.lisp.util.ByteUtil;
 import org.opendaylight.lispflowmapping.lisp.util.LispAddressStringifier;
 import org.opendaylight.lispflowmapping.lisp.util.MapRequestUtil;
-import org.opendaylight.lispflowmapping.mapcache.SimpleMapCache;
+import org.opendaylight.lispflowmapping.mapcache.AuthKeyDb;
 import org.opendaylight.lispflowmapping.southbound.ConcurrentLispSouthboundStats;
 import org.opendaylight.lispflowmapping.southbound.LispSouthboundPlugin;
 import org.opendaylight.lispflowmapping.southbound.lisp.cache.MapRegisterCache;
@@ -86,7 +86,7 @@ public class LispSouthboundHandler extends SimpleChannelInboundHandler<DatagramP
     private boolean authenticationEnabled = true;
     private final LispSouthboundPlugin lispSbPlugin;
     private ConcurrentLispSouthboundStats lispSbStats = null;
-    private SimpleMapCache smc;
+    private AuthKeyDb akdb;
     private AuthenticationKeyDataListener authenticationKeyDataListener;
     private DataStoreBackEnd dsbe;
     private boolean isReadFromChannelEnabled = true;
@@ -323,9 +323,9 @@ public class LispSouthboundHandler extends SimpleChannelInboundHandler<DatagramP
         for (int i = 0; i < eidLispAddresses.size(); i++) {
             final Eid eid = eidLispAddresses.get(i).getEid();
             if (i == 0) {
-                firstAuthKey = smc.getAuthenticationKey(eid);
+                firstAuthKey = akdb.getAuthenticationKey(eid);
             } else {
-                final MappingAuthkey authKey = smc.getAuthenticationKey(eid);
+                final MappingAuthkey authKey = akdb.getAuthenticationKey(eid);
                 if (!Objects.equals(firstAuthKey, authKey)) {
                     return null;
                 }
@@ -393,7 +393,7 @@ public class LispSouthboundHandler extends SimpleChannelInboundHandler<DatagramP
      * <p>Methods pass through all records from map register message. For the EID of the first record it gets
      * authentication key and does validation of authentication data again this authentication key. If it pass
      * it just checks for remaining records (and its EID) whether they have the same authenticatin key stored in
-     * simple map cache (smc).
+     * the authentication key database (akdb).
      *
      * @return Returns authentication key if all of EIDs have the same authentication key or null otherwise
      */
@@ -402,7 +402,7 @@ public class LispSouthboundHandler extends SimpleChannelInboundHandler<DatagramP
             return null;
         }
 
-        if (smc == null) {
+        if (akdb == null) {
             LOG.debug("Simple map cache wasn't instantieted and set.");
             return null;
         }
@@ -413,13 +413,13 @@ public class LispSouthboundHandler extends SimpleChannelInboundHandler<DatagramP
             final MappingRecordItem recordItem = mappingRecords.get(i);
             final MappingRecord mappingRecord = recordItem.getMappingRecord();
             if (i == 0) {
-                firstAuthKey = smc.getAuthenticationKey(mappingRecord.getEid());
+                firstAuthKey = akdb.getAuthenticationKey(mappingRecord.getEid());
                 if (!LispAuthenticationUtil.validate(mapRegister, byteBuffer, mappingRecord.getEid(), firstAuthKey)) {
                     return null;
                 }
             } else {
                 final Eid eid = mappingRecord.getEid();
-                final MappingAuthkey authKey = smc.getAuthenticationKey(eid);
+                final MappingAuthkey authKey = akdb.getAuthenticationKey(eid);
                 if (!firstAuthKey.equals(authKey)) {
                     LOG.debug("Map register packet contained several eids. Authentication keys for first one and for "
                             + "{} are different.",LispAddressStringifier.getString(eid));
@@ -516,8 +516,8 @@ public class LispSouthboundHandler extends SimpleChannelInboundHandler<DatagramP
     public void close() throws Exception {
     }
 
-    public void setSimpleMapCache(final SimpleMapCache smc) {
-        this.smc = smc;
+    public void setAuthKeyDb(final AuthKeyDb smc) {
+        this.akdb = smc;
     }
 
     public void setDataBroker(final DataBroker dataBroker) {
@@ -557,7 +557,7 @@ public class LispSouthboundHandler extends SimpleChannelInboundHandler<DatagramP
             LOG.debug("Adding authentication key '{}' with key-ID {} for {}", mappingAuthkey.getKeyString(),
                     mappingAuthkey.getKeyType(),
                     LispAddressStringifier.getString(key));
-            smc.addAuthenticationKey(key, mappingAuthkey);
+            akdb.addAuthenticationKey(key, mappingAuthkey);
         }
     }
 
index 87e36f370851bbb1e9e89231ca55681acfde0e6c..36a27f7b6ba53ccbae354bb4c9a8806b6b90a682 100644 (file)
@@ -21,7 +21,7 @@ import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.lispflowmapping.lisp.util.LispAddressUtil;
-import org.opendaylight.lispflowmapping.mapcache.SimpleMapCache;
+import org.opendaylight.lispflowmapping.mapcache.AuthKeyDb;
 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.mapping.authkey.container.MappingAuthkey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.authkey.container.MappingAuthkeyBuilder;
@@ -33,7 +33,7 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 @RunWith(MockitoJUnitRunner.class)
 public class AuthenticationKeyDataListenerTest {
 
-    @Mock(name = "smc") private static SimpleMapCache smcMock;
+    @Mock(name = "akdb") private static AuthKeyDb akdbMock;
     @Mock(name = "broker") private static DataBroker brokerMock;
     @Mock(name = "registration") private static ListenerRegistration<AuthenticationKeyDataListener>
             registrationMock;
@@ -92,7 +92,7 @@ public class AuthenticationKeyDataListenerTest {
 
         Mockito.when(brokerMock.registerDataTreeChangeListener(Mockito.any(DataTreeIdentifier.class),
                 Mockito.any(AuthenticationKeyDataListener.class))).thenReturn(registrationMock);
-        authenticationKeyDataListener = new AuthenticationKeyDataListener(brokerMock, smcMock);
+        authenticationKeyDataListener = new AuthenticationKeyDataListener(brokerMock, akdbMock);
     }
 
     /**
@@ -104,7 +104,7 @@ public class AuthenticationKeyDataListenerTest {
         Mockito.when(mod_del.getDataBefore()).thenReturn(AUTHENTICATION_KEY_1);
 
         authenticationKeyDataListener.onDataTreeChanged(Lists.newArrayList(change_del));
-        Mockito.verify(smcMock).removeAuthenticationKey(IPV4_BINARY_EID_1);
+        Mockito.verify(akdbMock).removeAuthenticationKey(IPV4_BINARY_EID_1);
     }
 
     /**
@@ -116,7 +116,7 @@ public class AuthenticationKeyDataListenerTest {
         Mockito.when(mod_del.getDataBefore()).thenReturn(AUTHENTICATION_KEY_PREFIX);
 
         authenticationKeyDataListener.onDataTreeChanged(Lists.newArrayList(change_del));
-        Mockito.verify(smcMock).removeAuthenticationKey(IPV4_PREFIX_BINARY_EID);
+        Mockito.verify(akdbMock).removeAuthenticationKey(IPV4_PREFIX_BINARY_EID);
     }
 
     /**
@@ -128,7 +128,7 @@ public class AuthenticationKeyDataListenerTest {
         Mockito.when(mod_subtreeModified.getDataAfter()).thenReturn(AUTHENTICATION_KEY_2);
 
         authenticationKeyDataListener.onDataTreeChanged(Lists.newArrayList(change_subtreeModified));
-        Mockito.verify(smcMock).addAuthenticationKey(IPV4_BINARY_EID_2, MAPPING_AUTHKEY);
+        Mockito.verify(akdbMock).addAuthenticationKey(IPV4_BINARY_EID_2, MAPPING_AUTHKEY);
     }
 
     /**
@@ -140,7 +140,7 @@ public class AuthenticationKeyDataListenerTest {
         Mockito.when(mod_write.getDataAfter()).thenReturn(AUTHENTICATION_KEY_3);
 
         authenticationKeyDataListener.onDataTreeChanged(Lists.newArrayList(change_write));
-        Mockito.verify(smcMock).addAuthenticationKey(IPV4_BINARY_EID_3, MAPPING_AUTHKEY);
+        Mockito.verify(akdbMock).addAuthenticationKey(IPV4_BINARY_EID_3, MAPPING_AUTHKEY);
     }
 
     /**
@@ -155,7 +155,7 @@ public class AuthenticationKeyDataListenerTest {
         Mockito.when(mod_nullModType.getModificationType()).thenReturn(null);
 
         authenticationKeyDataListener.onDataTreeChanged(Lists.newArrayList(change_nullModType));
-        Mockito.verifyZeroInteractions(smcMock);
+        Mockito.verifyZeroInteractions(akdbMock);
     }
 
     /**
index fa11429ed1c25c2076ea1c852b86b53d6f90ac0a..ae963150d27f3f24bf0aa8467bacaf7613956d32 100644 (file)
@@ -50,7 +50,7 @@ import org.opendaylight.lispflowmapping.lisp.util.ByteUtil;
 import org.opendaylight.lispflowmapping.lisp.util.LispAddressUtil;
 import org.opendaylight.lispflowmapping.lisp.util.MapNotifyBuilderHelper;
 import org.opendaylight.lispflowmapping.lisp.util.MaskUtil;
-import org.opendaylight.lispflowmapping.mapcache.SimpleMapCache;
+import org.opendaylight.lispflowmapping.mapcache.AuthKeyDb;
 import org.opendaylight.lispflowmapping.southbound.ConcurrentLispSouthboundStats;
 import org.opendaylight.lispflowmapping.southbound.LispSouthboundPlugin;
 import org.opendaylight.lispflowmapping.southbound.lisp.cache.MapRegisterCache;
@@ -102,7 +102,7 @@ public class LispSouthboundServiceTest extends BaseTestCase {
     private ConcurrentLispSouthboundStats lispSouthboundStats;
     private static final long CACHE_RECORD_TIMEOUT = 90000;
 
-    private static SimpleMapCache smc;
+    private static AuthKeyDb akdb;
 
     private interface MapReplyIpv4SingleLocatorPos {
         int RECORD_COUNT = 3;
@@ -125,23 +125,23 @@ public class LispSouthboundServiceTest extends BaseTestCase {
 
     @BeforeClass
     public static void initTests() {
-        smc = Mockito.mock(SimpleMapCache.class);
-        Mockito.when(smc.getAuthenticationKey(Matchers.eq(LispAddressUtil.asIpv4PrefixBinaryEid("10.10.10.10/8"))))
+        akdb = Mockito.mock(AuthKeyDb.class);
+        Mockito.when(akdb.getAuthenticationKey(Matchers.eq(LispAddressUtil.asIpv4PrefixBinaryEid("10.10.10.10/8"))))
                 .thenReturn(new MappingAuthkeyBuilder().setKeyType(1).setKeyString("password").build());
-        Mockito.when(smc.getAuthenticationKey(Matchers.eq(LispAddressUtil.asIpv6PrefixBinaryEid(
+        Mockito.when(akdb.getAuthenticationKey(Matchers.eq(LispAddressUtil.asIpv6PrefixBinaryEid(
                 "2610:d0:ffff:192:0:0:0:1/128"))))
                 .thenReturn(new MappingAuthkeyBuilder().setKeyType(1).setKeyString("password").build());
-        Mockito.when(smc.getAuthenticationKey(Matchers.eq(LispAddressUtil.asIpv4PrefixBinaryEid("153.16.254.1/32"))))
+        Mockito.when(akdb.getAuthenticationKey(Matchers.eq(LispAddressUtil.asIpv4PrefixBinaryEid("153.16.254.1/32"))))
                 .thenReturn(new MappingAuthkeyBuilder().setKeyType(1).setKeyString("password").build());
-        Mockito.when(smc.getAuthenticationKey(Matchers.eq(LispAddressUtil.asIpv4PrefixBinaryEid("125.124.123.122/8", new
-                InstanceIdType(21L)))))
+        Mockito.when(akdb.getAuthenticationKey(Matchers.eq(LispAddressUtil.asIpv4PrefixBinaryEid("125.124.123.122/8",
+                new InstanceIdType(21L)))))
                 .thenReturn(new MappingAuthkeyBuilder().setKeyType(1).setKeyString("password").build());
-        Mockito.when(smc.getAuthenticationKey(Matchers.eq(LispAddressUtil.asMacEid("0a:0b:0c:0d:0e:0f"))))
+        Mockito.when(akdb.getAuthenticationKey(Matchers.eq(LispAddressUtil.asMacEid("0a:0b:0c:0d:0e:0f"))))
                 .thenReturn(new MappingAuthkeyBuilder().setKeyType(1).setKeyString("password").build());
-        Mockito.when(smc.getAuthenticationKey(Matchers.eq(LispAddressUtil.asIpv6PrefixBinaryEid(
+        Mockito.when(akdb.getAuthenticationKey(Matchers.eq(LispAddressUtil.asIpv6PrefixBinaryEid(
                 "f0f:f0f:f0f:f0f:f0f:f0f:f0f:f0f/8"))))
                 .thenReturn(new MappingAuthkeyBuilder().setKeyType(1).setKeyString("password").build());
-        Mockito.when(smc.getAuthenticationKey(Matchers.eq(LispAddressUtil.asIpv4PrefixBinaryEid("172.1.1.2/32"))))
+        Mockito.when(akdb.getAuthenticationKey(Matchers.eq(LispAddressUtil.asIpv4PrefixBinaryEid("172.1.1.2/32"))))
                 .thenReturn(new MappingAuthkeyBuilder().setKeyType(1).setKeyString("password").build());
     }
 
@@ -158,7 +158,7 @@ public class LispSouthboundServiceTest extends BaseTestCase {
         mapRegisterCache = new MapRegisterCache();
         testedLispService.setMapRegisterCache(mapRegisterCache);
         testedLispService.setDataBroker(Mockito.mock(DataBroker.class));
-        testedLispService.setSimpleMapCache(smc);
+        testedLispService.setAuthKeyDb(akdb);
         testedLispService.setAuthenticationKeyDataListener(Mockito.mock(AuthenticationKeyDataListener.class));
         testedLispService.setDataStoreBackEnd(Mockito.mock(DataStoreBackEnd.class));
         nps = context.mock(NotificationPublishService.class);