2 * Copyright (c) 2013 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.controller.netconf.mdsal.connector;
11 import com.google.common.base.Preconditions;
12 import java.util.Collection;
13 import java.util.Collections;
14 import java.util.HashSet;
16 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
17 import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
18 import org.opendaylight.controller.netconf.api.Capability;
19 import org.opendaylight.controller.netconf.api.monitoring.CapabilityListener;
20 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory;
21 import org.opendaylight.controller.netconf.util.capability.BasicCapability;
22 import org.opendaylight.controller.netconf.util.capability.YangModuleCapability;
23 import org.opendaylight.controller.sal.core.api.Broker.ConsumerSession;
24 import org.opendaylight.controller.sal.core.api.Consumer;
25 import org.opendaylight.controller.sal.core.api.model.SchemaService;
26 import org.opendaylight.yangtools.yang.model.api.Module;
27 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
31 public class MdsalNetconfOperationServiceFactory implements NetconfOperationServiceFactory, Consumer, AutoCloseable {
33 private static final Logger LOG = LoggerFactory.getLogger(MdsalNetconfOperationServiceFactory.class);
35 private ConsumerSession session = null;
36 private DOMDataBroker dataBroker = null;
37 private DOMRpcService rpcService = null;
38 private final CurrentSchemaContext currentSchemaContext;
40 public MdsalNetconfOperationServiceFactory(final SchemaService schemaService) {
41 this.currentSchemaContext = new CurrentSchemaContext(Preconditions.checkNotNull(schemaService));
45 public MdsalNetconfOperationService createService(final String netconfSessionIdForReporting) {
46 Preconditions.checkState(dataBroker != null, "MD-SAL provider not yet initialized");
47 return new MdsalNetconfOperationService(currentSchemaContext, netconfSessionIdForReporting, dataBroker, rpcService);
51 public void close() throws Exception {
52 currentSchemaContext.close();
56 public Set<Capability> getCapabilities() {
57 return transformCapabilities(currentSchemaContext.getCurrentContext());
60 static Set<Capability> transformCapabilities(final SchemaContext currentContext1) {
61 final Set<Capability> capabilities = new HashSet<>();
62 // [RFC6241] 8.3. Candidate Configuration Capability
63 capabilities.add(new BasicCapability("urn:ietf:params:netconf:capability:candidate:1.0"));
65 final SchemaContext currentContext = currentContext1;
66 final Set<Module> modules = currentContext.getModules();
67 for (final Module module : modules) {
68 if(currentContext.getModuleSource(module).isPresent()) {
69 capabilities.add(new YangModuleCapability(module, currentContext.getModuleSource(module).get()));
71 LOG.warn("Missing source for module {}. This module will not be available from netconf server",
80 public AutoCloseable registerCapabilityListener(final CapabilityListener listener) {
81 return currentSchemaContext.registerCapabilityListener(listener);
85 public void onSessionInitiated(ConsumerSession session) {
86 this.session = Preconditions.checkNotNull(session);
87 this.dataBroker = this.session.getService(DOMDataBroker.class);
88 this.rpcService = this.session.getService(DOMRpcService.class);
92 public Collection<ConsumerFunctionality> getConsumerFunctionality() {
93 return Collections.emptySet();