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
9 package org.opendaylight.netconf.sal.connect.netconf.sal;
11 import com.google.common.base.Preconditions;
12 import java.util.Collections;
14 import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
15 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
16 import org.opendaylight.controller.md.sal.dom.api.DOMDataBrokerExtension;
17 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction;
18 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
19 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
20 import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
21 import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
22 import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences;
23 import org.opendaylight.netconf.sal.connect.netconf.sal.tx.ReadOnlyTx;
24 import org.opendaylight.netconf.sal.connect.netconf.sal.tx.ReadWriteTx;
25 import org.opendaylight.netconf.sal.connect.netconf.sal.tx.TxChain;
26 import org.opendaylight.netconf.sal.connect.netconf.sal.tx.WriteCandidateRunningTx;
27 import org.opendaylight.netconf.sal.connect.netconf.sal.tx.WriteCandidateTx;
28 import org.opendaylight.netconf.sal.connect.netconf.sal.tx.WriteRunningTx;
29 import org.opendaylight.netconf.sal.connect.netconf.util.NetconfBaseOps;
30 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
31 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
33 public final class NetconfDeviceDataBroker implements DOMDataBroker {
34 private final RemoteDeviceId id;
35 private final NetconfBaseOps netconfOps;
37 private final boolean rollbackSupport;
38 private final boolean candidateSupported;
39 private final boolean runningWritable;
41 public NetconfDeviceDataBroker(final RemoteDeviceId id, final SchemaContext schemaContext,
42 final DOMRpcService rpc, final NetconfSessionPreferences netconfSessionPreferences) {
44 this.netconfOps = new NetconfBaseOps(rpc, schemaContext);
45 // get specific attributes from netconf preferences and get rid of it
46 // no need to keep the entire preferences object, its quite big with all the capability QNames
47 candidateSupported = netconfSessionPreferences.isCandidateSupported();
48 runningWritable = netconfSessionPreferences.isRunningWritable();
49 rollbackSupport = netconfSessionPreferences.isRollbackSupported();
50 Preconditions.checkArgument(candidateSupported || runningWritable,
51 "Device %s has advertised neither :writable-running nor :candidate capability."
52 + "At least one of these should be advertised. Failed to establish a session.", id.getName());
56 public DOMDataReadOnlyTransaction newReadOnlyTransaction() {
57 return new ReadOnlyTx(netconfOps, id);
61 public DOMDataReadWriteTransaction newReadWriteTransaction() {
62 return new ReadWriteTx(newReadOnlyTransaction(), newWriteOnlyTransaction());
66 public DOMDataWriteTransaction newWriteOnlyTransaction() {
67 if (candidateSupported) {
68 if (runningWritable) {
69 return new WriteCandidateRunningTx(id, netconfOps, rollbackSupport);
71 return new WriteCandidateTx(id, netconfOps, rollbackSupport);
74 return new WriteRunningTx(id, netconfOps, rollbackSupport);
79 public DOMTransactionChain createTransactionChain(final TransactionChainListener listener) {
80 return new TxChain(this, listener);
84 public Map<Class<? extends DOMDataBrokerExtension>, DOMDataBrokerExtension> getSupportedExtensions() {
85 return Collections.emptyMap();