2 * Copyright (c) 2015, 2016 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.lispflowmapping.mapcache;
11 import java.util.Collections;
13 import org.opendaylight.lispflowmapping.interfaces.dao.ILispDAO;
14 import org.opendaylight.lispflowmapping.interfaces.dao.MappingEntry;
15 import org.opendaylight.lispflowmapping.interfaces.dao.SubKeys;
16 import org.opendaylight.lispflowmapping.interfaces.mapcache.IMapCache;
17 import org.opendaylight.lispflowmapping.lisp.util.MaskUtil;
18 import org.opendaylight.lispflowmapping.mapcache.lisp.LispMapCacheStringifier;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
22 * Flat key implementation of a map-cache. As the name suggests, no longest prefix matching is done for IP addresses
23 * or their derivatives.
25 * @author Florin Coras
29 public class FlatMapCache implements IMapCache {
32 public FlatMapCache(ILispDAO dao) {
37 public void addMapping(Eid eid, Object value) {
38 Eid key = MaskUtil.normalize(eid);
39 dao.put(key, new MappingEntry<>(SubKeys.RECORD, value));
43 public Object getMapping(Eid srcKey, Eid dstKey) {
47 Eid key = MaskUtil.normalize(dstKey);
48 return dao.getSpecific(key, SubKeys.RECORD);
52 public Eid getWidestNegativeMapping(Eid key) {
57 public Set<Eid> getSubtree(Eid key) {
58 return Collections.emptySet();
62 public void removeMapping(Eid eid) {
63 Eid key = MaskUtil.normalize(eid);
64 dao.removeSpecific(key, SubKeys.RECORD);
68 public void addData(Eid eid, String subKey, Object value) {
69 Eid key = MaskUtil.normalize(eid);
70 dao.put(key, new MappingEntry<>(subKey, value));
74 public Object getData(Eid eid, String subKey) {
75 Eid key = MaskUtil.normalize(eid);
76 return dao.getSpecific(key, subKey);
80 public void removeData(Eid eid, String subKey) {
81 Eid key = MaskUtil.normalize(eid);
82 dao.removeSpecific(key, subKey);
86 public String printMappings() {
87 return LispMapCacheStringifier.printFMCMappings(dao);
91 public String prettyPrintMappings() {
92 return LispMapCacheStringifier.prettyPrintFMCMappings(dao);