2 * Copyright (c) 2014 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
8 package org.opendaylight.netconf.sal.connect.netconf.sal;
10 import com.google.common.base.Preconditions;
11 import com.google.common.collect.ClassToInstanceMap;
12 import com.google.common.collect.ImmutableClassToInstanceMap;
13 import org.opendaylight.mdsal.dom.api.DOMDataBrokerExtension;
14 import org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction;
15 import org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction;
16 import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
17 import org.opendaylight.mdsal.dom.api.DOMRpcService;
18 import org.opendaylight.mdsal.dom.api.DOMTransactionChain;
19 import org.opendaylight.mdsal.dom.api.DOMTransactionChainListener;
20 import org.opendaylight.mdsal.dom.spi.PingPongMergingDOMDataBroker;
21 import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences;
22 import org.opendaylight.netconf.sal.connect.netconf.sal.tx.ReadOnlyTx;
23 import org.opendaylight.netconf.sal.connect.netconf.sal.tx.ReadWriteTx;
24 import org.opendaylight.netconf.sal.connect.netconf.sal.tx.TxChain;
25 import org.opendaylight.netconf.sal.connect.netconf.sal.tx.WriteCandidateRunningTx;
26 import org.opendaylight.netconf.sal.connect.netconf.sal.tx.WriteCandidateTx;
27 import org.opendaylight.netconf.sal.connect.netconf.sal.tx.WriteRunningTx;
28 import org.opendaylight.netconf.sal.connect.netconf.util.NetconfBaseOps;
29 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
30 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
32 public final class NetconfDeviceDataBroker implements PingPongMergingDOMDataBroker {
34 private final RemoteDeviceId id;
35 private final NetconfBaseOps netconfOps;
36 private final boolean rollbackSupport;
37 private final boolean candidateSupported;
38 private final boolean runningWritable;
40 private boolean isLockAllowed = true;
42 public NetconfDeviceDataBroker(final RemoteDeviceId id, final SchemaContext schemaContext,
43 final DOMRpcService rpc, final NetconfSessionPreferences netconfSessionPreferences) {
45 this.netconfOps = new NetconfBaseOps(rpc, schemaContext);
46 // get specific attributes from netconf preferences and get rid of it
47 // no need to keep the entire preferences object, its quite big with all the capability QNames
48 candidateSupported = netconfSessionPreferences.isCandidateSupported();
49 runningWritable = netconfSessionPreferences.isRunningWritable();
50 rollbackSupport = netconfSessionPreferences.isRollbackSupported();
51 Preconditions.checkArgument(candidateSupported || runningWritable,
52 "Device %s has advertised neither :writable-running nor :candidate capability."
53 + "At least one of these should be advertised. Failed to establish a session.", id.getName());
57 public DOMDataTreeReadTransaction newReadOnlyTransaction() {
58 return new ReadOnlyTx(netconfOps, id);
62 public DOMDataTreeReadWriteTransaction newReadWriteTransaction() {
63 return new ReadWriteTx(newReadOnlyTransaction(), newWriteOnlyTransaction());
67 public DOMDataTreeWriteTransaction newWriteOnlyTransaction() {
68 if (candidateSupported) {
69 if (runningWritable) {
70 return new WriteCandidateRunningTx(id, netconfOps, rollbackSupport, isLockAllowed);
72 return new WriteCandidateTx(id, netconfOps, rollbackSupport, isLockAllowed);
75 return new WriteRunningTx(id, netconfOps, rollbackSupport, isLockAllowed);
80 public DOMTransactionChain createTransactionChain(final DOMTransactionChainListener listener) {
81 return new TxChain(this, listener);
85 public ClassToInstanceMap<DOMDataBrokerExtension> getExtensions() {
86 return ImmutableClassToInstanceMap.of();
89 void setLockAllowed(boolean isLockAllowedOrig) {
90 this.isLockAllowed = isLockAllowedOrig;