2 * Copyright (c) 2015 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.implementation.mapcache;
11 import java.util.Date;
13 import org.opendaylight.lispflowmapping.interfaces.dao.ILispDAO;
14 import org.opendaylight.lispflowmapping.interfaces.dao.IRowVisitor;
15 import org.opendaylight.lispflowmapping.interfaces.dao.MappingEntry;
16 import org.opendaylight.lispflowmapping.interfaces.dao.SubKeys;
17 import org.opendaylight.lispflowmapping.interfaces.mapcache.IMapCache;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.LispAddressContainer;
21 * Flat key implementation of a map-cache. As the name suggests, no longest prefix matching is done for IP addresses
22 * or their derivatives.
24 * @author Florin Coras
28 public class FlatMapCache implements IMapCache {
31 public FlatMapCache(ILispDAO dao) {
36 public void addMapping(LispAddressContainer key, Object data, boolean shouldOverwrite) {
37 dao.put(key, new MappingEntry<>(SubKeys.REGDATE, new Date(System.currentTimeMillis())));
38 dao.put(key, new MappingEntry<>(SubKeys.RECORD, data));
42 public Object getMapping(LispAddressContainer srcKey, LispAddressContainer dstKey) {
46 return dao.getSpecific(dstKey, SubKeys.RECORD);
50 public void removeMapping(LispAddressContainer key, boolean overwrite) {
51 dao.removeSpecific(key, SubKeys.RECORD);
55 public void addAuthenticationKey(LispAddressContainer key, String authKey) {
56 dao.put(key, new MappingEntry<>(SubKeys.AUTH_KEY, authKey));
60 public String getAuthenticationKey(LispAddressContainer key) {
61 Object data = dao.getSpecific(key, SubKeys.AUTH_KEY);
62 if (data instanceof String) {
70 public void removeAuthenticationKey(LispAddressContainer key) {
71 dao.removeSpecific(key, SubKeys.AUTH_KEY);
75 public void updateMappingRegistration(LispAddressContainer key) {
76 if (dao.get(key) != null) {
77 dao.put(key, new MappingEntry<>(SubKeys.REGDATE, new Date(System.currentTimeMillis())));
82 public void addData(LispAddressContainer key, String subKey, Object data) {
83 dao.put(key, new MappingEntry<>(subKey, data));
87 public Object getData(LispAddressContainer key, String subKey) {
88 return dao.getSpecific(key, subKey);
92 public void removeData(LispAddressContainer key, String subKey) {
93 dao.removeSpecific(key, subKey);
97 public String printMappings() {
98 final StringBuffer sb = new StringBuffer();
99 sb.append("Keys\tValues\n");
100 dao.getAll(new IRowVisitor() {
103 public void visitRow(Object keyId, String valueKey, Object value) {
104 String key = keyId.getClass().getSimpleName() + "#" + keyId;
105 if (!lastKey.equals(key)) {
106 sb.append("\n" + key + "\t");
108 sb.append(valueKey + "=" + value + "\t");
113 return sb.toString();