* 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 java.util.Date;
import java.util.Map;
-
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.IMapCache;
+import org.opendaylight.lispflowmapping.lisp.util.LispAddressUtil;
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.mappingservice.rev150906.mapping.authkey.container.MappingAuthkey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.authkey.container.MappingAuthkey;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
* another for source, queried and populated in this exact order.
*
* @author Florin Coras
- *
*/
public class MultiTableMapCache implements IMapCache {
private static final Logger LOG = LoggerFactory.getLogger(MultiTableMapCache.class);
+
private ILispDAO dao;
public MultiTableMapCache(ILispDAO dao) {
}
}
- // Method returns the DAO entry (hash) corresponding to either the longest prefix match of eid, if eid is maskable,
- // or the exact match otherwise. eid must be a 'simple' address
- private Map<String, ?> getDaoEntryBest(Eid eid, ILispDAO dao) {
- Eid key;
- if (MaskUtil.isMaskable(eid.getAddress())) {
- short mask = MaskUtil.getMaskForAddress(eid.getAddress());
- while (mask > 0) {
- key = MaskUtil.normalize(eid, mask);
- mask--;
- Map<String, ?> entry = dao.get(key);
- if (entry != null) {
- return entry;
- }
- }
- return null;
- } else {
- key = MaskUtil.normalize(eid);
- Map<String, ?> entry = dao.get(key);
- return entry;
- }
- }
-
- private Object getMappingExactSD(Eid srcEid, Eid dstEid, ILispDAO dao) {
- Map<String, ?> daoEntry = dao.get(dstEid);
- if (daoEntry != null) {
- // try SrcDst eid lookup
- ILispDAO srcDstDao = (ILispDAO) daoEntry.get(SubKeys.LCAF_SRCDST);
- if (srcEid != null && srcDstDao != null) {
- return srcDstDao.getSpecific(srcEid, SubKeys.RECORD);
- }
- // if lookup fails, return whatever is found for dst eid
- return daoEntry.get(SubKeys.RECORD);
- }
- return null;
- }
-
// Returns the mapping corresponding to the longest prefix match for eid.
// eid must be a simple (maskable or not) address
- private Object getMappingLpmEid(Eid eid, ILispDAO dao) {
+ private Object getMappingLpmEid(Eid eid, ILispDAO mappingsDb) {
if (eid == null) {
return null;
}
- Eid key = MaskUtil.normalize(eid);
- Map<String, ?> daoEntry = getDaoEntryBest(key, dao);
+ Map<String, ?> daoEntry = mappingsDb.getBest(MaskUtil.normalize(eid));
if (daoEntry != null) {
return daoEntry.get(SubKeys.RECORD);
} else {
// Returns a mapping corresponding to either the longest prefix match for both dstEid and srcEid,
// if a SourceDest mapping exists, or to dstEid
- private Object getMappingLpmSD(Eid srcEid, Eid dstEid, ILispDAO dao) {
- Map<String, ?> daoEntry = getDaoEntryBest(dstEid, dao);
+ private Object getMappingLpmSD(Eid srcEid, Eid dstEid, ILispDAO mappingsDb) {
+ Map<String, ?> daoEntry = mappingsDb.getBest(MaskUtil.normalize(dstEid));
if (daoEntry != null) {
// try SrcDst eid lookup
ILispDAO srcDstDao = (ILispDAO) daoEntry.get(SubKeys.LCAF_SRCDST);
- if (srcDstDao != null) {
- Object mapping = getMappingLpmEid(srcEid, srcDstDao);
- if (mapping!= null) {
+ if (srcEid != null && srcDstDao != null) {
+ // make sure that srcEid is a prefix, not an IP and binary
+ Object mapping = getMappingLpmEid(LispAddressUtil.asIpPrefixBinaryEid(srcEid), srcDstDao);
+ if (mapping != null) {
return mapping;
}
}
return getMappingLpmSD(srcEid, dstEid, table);
}
+ @Override
+ public Eid getWidestNegativeMapping(Eid key) {
+ ILispDAO table = getVniTable(key);
+ if (table == null) {
+ return null;
+ }
+ return table.getWidestNegativePrefix(key);
+ }
+
public void removeMapping(Eid eid, boolean overwrite) {
Eid key = MaskUtil.normalize(eid);
ILispDAO table = getVniTable(key);
if (db != null) {
db.removeSpecific(SourceDestKeyHelper.getSrcBinary(key),
SubKeys.RECORD);
+ db.removeSpecific(SourceDestKeyHelper.getSrcBinary(key),
+ SubKeys.REGDATE);
}
} else {
table.removeSpecific(key, SubKeys.RECORD);
+ table.removeSpecific(key, SubKeys.REGDATE);
}
}
// 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 dao) {
+ private ILispDAO getOrInstantiateSDInnerDao(Eid address, ILispDAO mappingsDb) {
Eid dstKey = SourceDestKeyHelper.getDstBinary(address);
- ILispDAO srcDstDao = (ILispDAO) dao.getSpecific(dstKey, SubKeys.LCAF_SRCDST);
+ ILispDAO srcDstDao = (ILispDAO) mappingsDb.getSpecific(dstKey, SubKeys.LCAF_SRCDST);
if (srcDstDao == null) {
// inserts nested table for source
- srcDstDao = dao.putNestedTable(dstKey, SubKeys.LCAF_SRCDST);
+ srcDstDao = mappingsDb.putNestedTable(dstKey, SubKeys.LCAF_SRCDST);
}
return srcDstDao;
}
// SrcDst LCAFs are stored in a 2-tier DAO with dst having priority over src.
// This method returns the DAO associated to dst or null if it doesn't exist.
- private ILispDAO getSDInnerDao(Eid address, ILispDAO dao) {
- return (ILispDAO) dao.getSpecific(SourceDestKeyHelper.getDstBinary(address), SubKeys.LCAF_SRCDST);
+ private ILispDAO getSDInnerDao(Eid address, ILispDAO mappingsDb) {
+ return (ILispDAO) mappingsDb.getSpecific(SourceDestKeyHelper.getDstBinary(address), SubKeys.LCAF_SRCDST);
}
public String printMappings() {
if (key.getAddress() instanceof SourceDestKey) {
ILispDAO srcDstDao = getOrInstantiateSDInnerDao(key, table);
- srcDstDao.put(SourceDestKeyHelper.getSrcBinary(key), new MappingEntry<Object>(subKey, data));
+ srcDstDao.put(SourceDestKeyHelper.getSrcBinary(key), new MappingEntry<>(subKey, data));
} else {
- table.put(key, new MappingEntry<Object>(subKey, data));
+ table.put(key, new MappingEntry<>(subKey, data));
}
}