Yuta HIGUCHI | 8810aa4 | 2017-08-02 15:05:37 -0700 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.d.config.sync.impl.netconf; |
| 17 | |
| 18 | import org.apache.felix.scr.annotations.Activate; |
| 19 | import org.apache.felix.scr.annotations.Component; |
| 20 | import org.apache.felix.scr.annotations.Deactivate; |
| 21 | import org.apache.felix.scr.annotations.Reference; |
| 22 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 23 | import org.onosproject.d.config.sync.DeviceConfigSynchronizationProviderRegistry; |
| 24 | import org.onosproject.d.config.sync.DeviceConfigSynchronizationProviderService; |
| 25 | import org.onosproject.net.device.DeviceService; |
| 26 | import org.onosproject.net.provider.ProviderId; |
| 27 | import org.onosproject.netconf.NetconfController; |
| 28 | import org.onosproject.yang.model.SchemaContextProvider; |
| 29 | import org.onosproject.yang.runtime.YangRuntimeService; |
| 30 | import org.slf4j.Logger; |
| 31 | import org.slf4j.LoggerFactory; |
| 32 | |
| 33 | import com.google.common.annotations.Beta; |
| 34 | |
| 35 | /** |
| 36 | * Main component of Dynamic config synchronizer for NETCONF. |
Yuta HIGUCHI | ab35080 | 2018-05-07 14:56:32 -0700 | [diff] [blame] | 37 | * |
Yuta HIGUCHI | 8810aa4 | 2017-08-02 15:05:37 -0700 | [diff] [blame] | 38 | * <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) |
| 44 | public 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 | |
| 54 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 55 | protected DeviceConfigSynchronizationProviderRegistry registry; |
| 56 | |
| 57 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 58 | protected NetconfController netconfController; |
| 59 | |
| 60 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 61 | protected YangRuntimeService yangRuntimeService; |
| 62 | |
| 63 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 64 | protected SchemaContextProvider schemaContextProvider; |
| 65 | |
| 66 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 67 | 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 | } |