--- /dev/null
+/*
+ * 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();
+}
/*
- * 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,
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.
*/
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.
*
*/
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.
*
*/
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.
*/
*/
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.
*/
return mappingSystem.printMappings();
}
+ @Override
+ public String printKeys() {
+ return mappingSystem.printKeys();
+ }
+
@Override
public void close() throws Exception {
LOG.info("Mapping Service is being destroyed!");
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);
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;
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;
*/
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;
* 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);
}
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
if (LOG.isDebugEnabled()) {
LOG.debug("Retrieving authentication key for {}", LispAddressStringifier.getString(key));
}
- return smc.getAuthenticationKey(key);
+ return akdb.getAuthenticationKey(key);
}
@Override
if (LOG.isDebugEnabled()) {
LOG.debug("Removing authentication key for {}", LispAddressStringifier.getString(key));
}
- smc.removeAuthenticationKey(key);
+ akdb.removeAuthenticationKey(key);
}
@Override
return sb.toString();
}
+ @Override
+ public String printKeys() {
+ return akdb.printKeys();
+ }
+
public void cleanCaches() {
dao.removeAll();
buildMapCaches();
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;
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);
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);
}
/**
@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());
}
/**
*/
@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));
}
@Test
public void removeAuthenticationKeyTest() {
mappingSystem.removeAuthenticationKey(EID_IPV4_1);
- Mockito.verify(smcMock).removeAuthenticationKey(EID_IPV4_1);
+ Mockito.verify(akdbMock).removeAuthenticationKey(EID_IPV4_1);
}
/**
--- /dev/null
+/*
+ * 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();
+ }
+}
/*
- * 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,
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
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);
/*
- * 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,
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
* @author Florin Coras
*/
public class MultiTableMapCache implements IMapCache {
- private static final Logger LOG = LoggerFactory.getLogger(MultiTableMapCache.class);
-
private ILispDAO dao;
public MultiTableMapCache(ILispDAO dao) {
}
}
- 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) {
/*
- * 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,
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
*
*/
public class SimpleMapCache implements ILispMapCache {
- private static final Logger LOG = LoggerFactory.getLogger(SimpleMapCache.class);
private ILispDAO dao;
public SimpleMapCache(ILispDAO dao) {
}
}
- @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);
--- /dev/null
+/*
+ * 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());
+ }
+}
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;
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 {
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
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}.
*/
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 {
.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() {
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.
*/
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;
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() {
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.
*/
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
*
--- /dev/null
+/*
+ * 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;
+ }
+}
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;
<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"/>
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;
LISPFLOWMAPPING_ENTITY_NAME);
private volatile String bindingAddress;
- private SimpleMapCache smc;
+ private AuthKeyDb akdb;
private MapRegisterCache mapRegisterCache = new MapRegisterCache();
private boolean mapRegisterCacheEnabled;
private long mapRegisterCacheTimeout;
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);
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;
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;
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;
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.");
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()) {
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());
}
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;
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;
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;
}
* <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
*/
return null;
}
- if (smc == null) {
+ if (akdb == null) {
LOG.debug("Simple map cache wasn't instantieted and set.");
return null;
}
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));
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) {
LOG.debug("Adding authentication key '{}' with key-ID {} for {}", mappingAuthkey.getKeyString(),
mappingAuthkey.getKeyType(),
LispAddressStringifier.getString(key));
- smc.addAuthenticationKey(key, mappingAuthkey);
+ akdb.addAuthenticationKey(key, mappingAuthkey);
}
}
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;
@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;
Mockito.when(brokerMock.registerDataTreeChangeListener(Mockito.any(DataTreeIdentifier.class),
Mockito.any(AuthenticationKeyDataListener.class))).thenReturn(registrationMock);
- authenticationKeyDataListener = new AuthenticationKeyDataListener(brokerMock, smcMock);
+ authenticationKeyDataListener = new AuthenticationKeyDataListener(brokerMock, akdbMock);
}
/**
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);
}
/**
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);
}
/**
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);
}
/**
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);
}
/**
Mockito.when(mod_nullModType.getModificationType()).thenReturn(null);
authenticationKeyDataListener.onDataTreeChanged(Lists.newArrayList(change_nullModType));
- Mockito.verifyZeroInteractions(smcMock);
+ Mockito.verifyZeroInteractions(akdbMock);
}
/**
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;
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;
@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());
}
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);