2 * Copyright (c) 2015 Cisco Systems, Inc. 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
8 package org.opendaylight.lispflowmapping.implementation.mdsal;
10 import java.util.concurrent.ExecutionException;
12 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
13 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
14 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
15 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
16 import org.opendaylight.lispflowmapping.implementation.util.InstanceIdentifierUtil;
17 import org.opendaylight.lispflowmapping.implementation.util.LispAFIConvertor;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mapping.database.rev150314.db.instance.AuthenticationKey;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mapping.database.rev150314.db.instance.Mapping;
20 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
24 import com.google.common.util.concurrent.CheckedFuture;
27 * Stores data coming from the mapping database RPCs into the config datastore.
29 * @author Lorand Jakab
32 public class DataStoreBackEnd {
33 protected static final Logger LOG = LoggerFactory.getLogger(DataStoreBackEnd.class);
35 private DataBroker broker;
37 public DataStoreBackEnd(DataBroker broker) {
41 public void addAuthenticationKey(AuthenticationKey authenticationKey) {
42 LOG.debug("MD-SAL: Adding authentication key '{}' for {}/{}", authenticationKey.getAuthkey(),
43 LispAFIConvertor.toString(authenticationKey.getLispAddressContainer()),
44 authenticationKey.getMaskLength());
46 InstanceIdentifier<AuthenticationKey> path = InstanceIdentifierUtil
47 .createAuthenticationKeyIid(authenticationKey.getLispAddressContainer());
48 WriteTransaction transaction = broker.newWriteOnlyTransaction();
49 transaction.put(LogicalDatastoreType.CONFIGURATION, path, authenticationKey, true);
50 CheckedFuture<Void, TransactionCommitFailedException> future = transaction.submit();
51 checkTransaction(future, "Adding authentication key to config datastrore failed");
54 public void addMapping(Mapping mapping) {
55 LOG.debug("MD-SAL: Adding mapping for {}/{}",
56 LispAFIConvertor.toString(mapping.getLispAddressContainer()), mapping.getMaskLength());
58 InstanceIdentifier<Mapping> path = InstanceIdentifierUtil
59 .createMappingIid(mapping.getLispAddressContainer());
60 WriteTransaction transaction = broker.newWriteOnlyTransaction();
61 transaction.put(LogicalDatastoreType.CONFIGURATION, path, mapping, true);
62 CheckedFuture<Void, TransactionCommitFailedException> future = transaction.submit();
63 checkTransaction(future, "Adding mapping to config datastrore failed");
66 public void removeAuthenticationKey(AuthenticationKey authenticationKey) {
67 LOG.debug("MD-SAL: Removing authentication key for {}/{}",
68 LispAFIConvertor.toString(authenticationKey.getLispAddressContainer()),
69 authenticationKey.getMaskLength());
71 InstanceIdentifier<AuthenticationKey> path = InstanceIdentifierUtil
72 .createAuthenticationKeyIid(authenticationKey.getLispAddressContainer());
73 WriteTransaction transaction = broker.newWriteOnlyTransaction();
74 transaction.delete(LogicalDatastoreType.CONFIGURATION, path);
75 CheckedFuture<Void, TransactionCommitFailedException> future = transaction.submit();
76 checkTransaction(future, "Deleting authentication key from config datastrore failed");
79 public void removeMapping(Mapping mapping) {
80 LOG.debug("MD-SAL: Removing mapping for {}/{}",
81 LispAFIConvertor.toString(mapping.getLispAddressContainer()), mapping.getMaskLength());
83 InstanceIdentifier<Mapping> path = InstanceIdentifierUtil
84 .createMappingIid(mapping.getLispAddressContainer());
85 WriteTransaction transaction = broker.newWriteOnlyTransaction();
86 transaction.delete(LogicalDatastoreType.CONFIGURATION, path);
87 CheckedFuture<Void, TransactionCommitFailedException> future = transaction.submit();
88 checkTransaction(future, "Deleting mapping from config datastrore failed");
91 public void updateAuthenticationKey(AuthenticationKey authenticationKey) {
92 LOG.debug("MD-SAL: Updating authentication key for {}/{} with '{}'",
93 LispAFIConvertor.toString(authenticationKey.getLispAddressContainer()),
94 authenticationKey.getMaskLength(), authenticationKey.getAuthkey());
96 InstanceIdentifier<AuthenticationKey> path = InstanceIdentifierUtil
97 .createAuthenticationKeyIid(authenticationKey.getLispAddressContainer());
98 WriteTransaction transaction = broker.newWriteOnlyTransaction();
99 transaction.put(LogicalDatastoreType.CONFIGURATION, path, authenticationKey, true);
100 CheckedFuture<Void, TransactionCommitFailedException> future = transaction.submit();
101 checkTransaction(future, "Updating authentication key in config datastrore failed");
104 public void updateMapping(Mapping mapping) {
105 LOG.debug("MD-SAL: Updating mapping for {}/{}",
106 LispAFIConvertor.toString(mapping.getLispAddressContainer()), mapping.getMaskLength());
108 InstanceIdentifier<Mapping> path = InstanceIdentifierUtil
109 .createMappingIid(mapping.getLispAddressContainer());
110 WriteTransaction transaction = broker.newWriteOnlyTransaction();
111 transaction.put(LogicalDatastoreType.CONFIGURATION, path, mapping, true);
112 CheckedFuture<Void, TransactionCommitFailedException> future = transaction.submit();
113 checkTransaction(future, "Updating mapping in config datastrore failed");
116 void checkTransaction(CheckedFuture<Void, TransactionCommitFailedException> future, String errMsg) {
119 } catch (InterruptedException | ExecutionException e) {
120 LOG.warn(errMsg + e);