import java.util.AbstractMap.SimpleImmutableEntry;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
this.dao = dao;
}
- private ILispDAO getVniTable(Eid eid) {
- long vni = 0;
+ private long getVni(Eid eid) {
if (eid.getVirtualNetworkId() == null) {
- vni = 0;
+ return 0;
} else {
- vni = eid.getVirtualNetworkId().getValue();
+ return eid.getVirtualNetworkId().getValue();
}
- return (ILispDAO) dao.getSpecific(vni, SubKeys.VNI);
+ }
+
+ private ILispDAO getVniTable(Eid eid) {
+ return (ILispDAO) dao.getSpecific(getVni(eid), SubKeys.VNI);
+ }
+
+ private void removeVniTable(Eid eid) {
+ dao.removeSpecific(getVni(eid), SubKeys.VNI);
}
private ILispDAO getOrInstantiateVniTable(Eid eid) {
- long vni = 0;
- if (eid.getVirtualNetworkId() == null) {
- vni = 0;
- } else {
- vni = eid.getVirtualNetworkId().getValue();
- }
+ long vni = getVni(eid);
ILispDAO table = (ILispDAO) dao.getSpecific(vni, SubKeys.VNI);
if (table == null) {
table = dao.putNestedTable(vni, SubKeys.VNI);
return table;
}
- private ILispDAO getOrInstantiateXtrIdTable(Eid eid, ILispDAO dao) {
- ILispDAO table = (ILispDAO) dao.getSpecific(eid, SubKeys.XTRID_RECORDS);
+ private ILispDAO getOrInstantiateXtrIdTable(Eid eid, ILispDAO lispDAO) {
+ ILispDAO table = (ILispDAO) lispDAO.getSpecific(eid, SubKeys.XTRID_RECORDS);
if (table == null) {
- table = dao.putNestedTable(eid, SubKeys.XTRID_RECORDS);
+ table = lispDAO.putNestedTable(eid, SubKeys.XTRID_RECORDS);
}
return table;
}
// 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, XtrId xtrId, ILispDAO dao) {
- SimpleImmutableEntry<Eid, Map<String, ?>> daoEntry = dao.getBestPair(MaskUtil.normalize(eid));
+ private Object getMappingLpmEid(Eid eid, XtrId xtrId, ILispDAO lispDAO) {
+ SimpleImmutableEntry<Eid, Map<String, ?>> daoEntry = lispDAO.getBestPair(MaskUtil.normalize(eid));
if (daoEntry != null) {
if (xtrId != null) {
ILispDAO xtrIdTable = (ILispDAO) daoEntry.getValue().get(SubKeys.XTRID_RECORDS);
}
// Returns the list of mappings stored in an xTR-ID DAO
- private List<Object> getXtrIdMappingList(ILispDAO dao) {
- if (dao != null) {
+ private List<Object> getXtrIdMappingList(ILispDAO lispDAO) {
+ if (lispDAO != null) {
final List<Object> records = new ArrayList<>();
- dao.getAll(new IRowVisitor() {
+ lispDAO.getAll(new IRowVisitor() {
public void visitRow(Object keyId, String valueKey, Object value) {
if (valueKey.equals(SubKeys.RECORD)) {
records.add(value);
return null;
}
+ // Returns null for positive mappings, and 0/0 for empty cache.
+ @Override
public Eid getWidestNegativeMapping(Eid eid) {
ILispDAO table = getVniTable(eid);
if (table == null) {
- return null;
+ return MaskUtil.normalize(eid, (short) 0);
}
return table.getWidestNegativePrefix(MaskUtil.normalize(eid));
}
+ @Override
+ public Eid getCoveringLessSpecific(Eid eid) {
+ ILispDAO table = getVniTable(eid);
+ if (table == null) {
+ return null;
+ }
+ return table.getCoveringLessSpecific(MaskUtil.normalize(eid));
+ }
+
@Override
public Eid getParentPrefix(Eid eid) {
ILispDAO table = getVniTable(eid);
}
@Override
- public void removeMapping(Eid eid) {
+ public Set<Eid> getSubtree(Eid eid) {
ILispDAO table = getVniTable(eid);
if (table == null) {
- return;
+ return Collections.emptySet();
}
-
- Eid key = MaskUtil.normalize(eid);
- table.remove(key);
+ return table.getSubtree(eid);
}
@Override
- public void removeMapping(Eid eid, XtrId xtrId) {
+ public void removeMapping(Eid eid) {
ILispDAO table = getVniTable(eid);
if (table == null) {
return;
}
+
Eid key = MaskUtil.normalize(eid);
- ILispDAO xtrIdTable = (ILispDAO) table.getSpecific(key, SubKeys.XTRID_RECORDS);
- if (xtrIdTable == null) {
- return;
+ table.remove(key);
+ if (table.isEmpty()) {
+ removeVniTable(eid);
}
- xtrIdTable.removeSpecific(xtrId, SubKeys.RECORD);
+ }
+
+ @Override
+ public void removeMapping(Eid eid, XtrId xtrId) {
+ List<XtrId> xtrIds = Arrays.asList(xtrId);
+ removeXtrIdMappings(eid, xtrIds);
}
@Override
for (XtrId xtrId : xtrIds) {
xtrIdTable.removeSpecific(xtrId, SubKeys.RECORD);
}
+ if (xtrIdTable.isEmpty()) {
+ table.removeSpecific(key, SubKeys.XTRID_RECORDS);
+ if (table.isEmpty()) {
+ removeVniTable(eid);
+ }
+ }
}
@Override
@Override
public Object getData(Eid eid, String subKey) {
- ILispDAO table = getOrInstantiateVniTable(eid);
+ ILispDAO table = getVniTable(eid);
if (table == null) {
return null;
}
@Override
public void removeData(Eid eid, String subKey) {
- ILispDAO table = getOrInstantiateVniTable(eid);
+ ILispDAO table = getVniTable(eid);
if (table == null) {
return;
}
Eid key = MaskUtil.normalize(eid);
table.removeSpecific(key, subKey);
+ if (table.isEmpty()) {
+ removeVniTable(eid);
+ }
}
@Override