blob: d107da7a02b73f1ccf21af0c8434a8903483a710 [file] [log] [blame]
Yuta HIGUCHI8810aa42017-08-02 15:05:37 -07001/*
2 * Copyright 2017-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.d.config.sync.impl.netconf;
17
Ray Milkeyd84f89b2018-08-17 14:54:17 -070018import org.osgi.service.component.annotations.Activate;
19import org.osgi.service.component.annotations.Component;
20import org.osgi.service.component.annotations.Deactivate;
21import org.osgi.service.component.annotations.Reference;
22import org.osgi.service.component.annotations.ReferenceCardinality;
Yuta HIGUCHI8810aa42017-08-02 15:05:37 -070023import org.onosproject.d.config.sync.DeviceConfigSynchronizationProviderRegistry;
24import org.onosproject.d.config.sync.DeviceConfigSynchronizationProviderService;
25import org.onosproject.net.device.DeviceService;
26import org.onosproject.net.provider.ProviderId;
27import org.onosproject.netconf.NetconfController;
28import org.onosproject.yang.model.SchemaContextProvider;
29import org.onosproject.yang.runtime.YangRuntimeService;
30import org.slf4j.Logger;
31import org.slf4j.LoggerFactory;
32
33import com.google.common.annotations.Beta;
34
35/**
36 * Main component of Dynamic config synchronizer for NETCONF.
Yuta HIGUCHIab350802018-05-07 14:56:32 -070037 *
Yuta HIGUCHI8810aa42017-08-02 15:05:37 -070038 * <ul>
39 * <li> bootstrap Active and Passive synchronization modules
40 * <li> start background anti-entropy mechanism for offline device configuration
41 * </ul>
42 */
43@Component(immediate = true)
44public class NetconfDeviceConfigSynchronizerComponent {
45
46 private final Logger log = LoggerFactory.getLogger(getClass());
47
48 /**
49 * NETCONF dynamic config synchronizer provider ID.
50 */
51 public static final ProviderId PID =
52 new ProviderId("netconf", "org.onosproject.d.config.sync.netconf");
53
Ray Milkeyd84f89b2018-08-17 14:54:17 -070054 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Yuta HIGUCHI8810aa42017-08-02 15:05:37 -070055 protected DeviceConfigSynchronizationProviderRegistry registry;
56
Ray Milkeyd84f89b2018-08-17 14:54:17 -070057 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Yuta HIGUCHI8810aa42017-08-02 15:05:37 -070058 protected NetconfController netconfController;
59
Ray Milkeyd84f89b2018-08-17 14:54:17 -070060 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Yuta HIGUCHI8810aa42017-08-02 15:05:37 -070061 protected YangRuntimeService yangRuntimeService;
62
Ray Milkeyd84f89b2018-08-17 14:54:17 -070063 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Yuta HIGUCHI8810aa42017-08-02 15:05:37 -070064 protected SchemaContextProvider schemaContextProvider;
65
Ray Milkeyd84f89b2018-08-17 14:54:17 -070066 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Yuta HIGUCHI8810aa42017-08-02 15:05:37 -070067 protected DeviceService deviceService;
68
69 private NetconfDeviceConfigSynchronizerProvider provider;
70
71 private DeviceConfigSynchronizationProviderService providerService;
72
73
74 @Activate
75 protected void activate() {
76 provider = new NetconfDeviceConfigSynchronizerProvider(PID, new InnerNetconfContext());
77 providerService = registry.register(provider);
78
79 // TODO (Phase 2 or later)
80 // listen to NETCONF events (new Device appeared, etc.)
81 // for PASSIVE "state" synchronization upward
82
83 // TODO listen to DeviceEvents (Offline pre-configuration scenario)
84
85 // TODO background anti-entropy mechanism
86
87 log.info("Started");
88 }
89
90 @Deactivate
91 protected void deactivate() {
92 registry.unregister(provider);
93 log.info("Stopped");
94 }
95
96 /**
97 * Context object to provide reference to OSGi services, etc.
98 */
99 @Beta
100 public static interface NetconfContext {
101
102 /**
103 * Returns DeviceConfigSynchronizationProviderService interface.
104 *
105 * @return DeviceConfigSynchronizationProviderService
106 */
107 DeviceConfigSynchronizationProviderService providerService();
108
109 SchemaContextProvider schemaContextProvider();
110
111 YangRuntimeService yangRuntime();
112
113 NetconfController netconfController();
114
115 }
116
117 class InnerNetconfContext implements NetconfContext {
118
119 @Override
120 public NetconfController netconfController() {
121 return netconfController;
122 }
123
124 @Override
125 public YangRuntimeService yangRuntime() {
126 return yangRuntimeService;
127 }
128
129 @Override
130 public SchemaContextProvider schemaContextProvider() {
131 return schemaContextProvider;
132 }
133
134 @Override
135 public DeviceConfigSynchronizationProviderService providerService() {
136 return providerService;
137 }
138 }
139}