2 * Copyright (c) 2018 Pantheon Technologies s.r.o. 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 https://www.eclipse.org/legal/epl-v10.html
8 package io.lighty.controllers.tpce.module;
10 import io.lighty.core.controller.api.AbstractLightyModule;
11 import io.lighty.core.controller.api.LightyServices;
12 import java.util.ArrayList;
13 import java.util.List;
14 import org.opendaylight.transportpce.common.crossconnect.CrossConnect;
15 import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl;
16 import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl121;
17 import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl221;
18 import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl710;
19 import org.opendaylight.transportpce.common.device.DeviceTransactionManagerImpl;
20 import org.opendaylight.transportpce.common.mapping.MappingUtils;
21 import org.opendaylight.transportpce.common.mapping.MappingUtilsImpl;
22 import org.opendaylight.transportpce.common.mapping.PortMapping;
23 import org.opendaylight.transportpce.common.mapping.PortMappingImpl;
24 import org.opendaylight.transportpce.common.mapping.PortMappingVersion121;
25 import org.opendaylight.transportpce.common.mapping.PortMappingVersion221;
26 import org.opendaylight.transportpce.common.mapping.PortMappingVersion710;
27 import org.opendaylight.transportpce.common.network.NetworkTransactionImpl;
28 import org.opendaylight.transportpce.common.network.NetworkTransactionService;
29 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
30 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl;
31 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl121;
32 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl221;
33 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl710;
34 import org.opendaylight.transportpce.nbinotifications.impl.NbiNotificationsProvider;
35 import org.opendaylight.transportpce.networkmodel.NetConfTopologyListener;
36 import org.opendaylight.transportpce.networkmodel.NetworkModelProvider;
37 import org.opendaylight.transportpce.networkmodel.NetworkUtilsImpl;
38 import org.opendaylight.transportpce.networkmodel.listeners.PortMappingListener;
39 import org.opendaylight.transportpce.networkmodel.service.FrequenciesServiceImpl;
40 import org.opendaylight.transportpce.networkmodel.service.NetworkModelService;
41 import org.opendaylight.transportpce.networkmodel.service.NetworkModelServiceImpl;
42 import org.opendaylight.transportpce.olm.OlmPowerServiceRpcImpl;
43 import org.opendaylight.transportpce.olm.power.PowerMgmtImpl;
44 import org.opendaylight.transportpce.olm.service.OlmPowerServiceImpl;
45 import org.opendaylight.transportpce.pce.gnpy.consumer.GnpyConsumerImpl;
46 import org.opendaylight.transportpce.pce.impl.PceServiceRPCImpl;
47 import org.opendaylight.transportpce.pce.service.PathComputationService;
48 import org.opendaylight.transportpce.pce.service.PathComputationServiceImpl;
49 import org.opendaylight.transportpce.renderer.openroadminterface.OpenRoadmInterfaceFactory;
50 // Adding OTN interface
51 import org.opendaylight.transportpce.renderer.provisiondevice.DeviceRendererService;
52 import org.opendaylight.transportpce.renderer.provisiondevice.DeviceRendererServiceImpl;
53 import org.opendaylight.transportpce.renderer.provisiondevice.OtnDeviceRendererService;
55 import org.opendaylight.transportpce.renderer.provisiondevice.OtnDeviceRendererServiceImpl;
56 import org.opendaylight.transportpce.renderer.provisiondevice.RendererServiceOperations;
57 import org.opendaylight.transportpce.renderer.provisiondevice.RendererServiceOperationsImpl;
58 import org.opendaylight.transportpce.renderer.provisiondevice.notification.NotificationSender;
59 import org.opendaylight.transportpce.renderer.rpcs.DeviceRendererRPCImpl;
60 import org.opendaylight.transportpce.renderer.rpcs.TransportPCEServicePathRPCImpl;
61 import org.opendaylight.transportpce.servicehandler.catalog.CatalogDataStoreOperationsImpl;
62 import org.opendaylight.transportpce.servicehandler.impl.ServiceHandlerProvider;
63 import org.opendaylight.transportpce.servicehandler.impl.ServicehandlerImpl;
64 import org.opendaylight.transportpce.servicehandler.listeners.NetworkModelNotificationHandler;
65 import org.opendaylight.transportpce.servicehandler.listeners.PceNotificationHandler;
66 import org.opendaylight.transportpce.servicehandler.listeners.RendererNotificationHandler;
67 import org.opendaylight.transportpce.servicehandler.listeners.ServiceListener;
68 import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperations;
69 import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperationsImpl;
70 import org.opendaylight.transportpce.tapi.impl.TapiProvider;
71 import org.opendaylight.transportpce.tapi.listeners.TapiNetworkModelNotificationHandler;
72 import org.opendaylight.transportpce.tapi.topology.TapiNetworkModelService;
73 import org.opendaylight.transportpce.tapi.topology.TapiNetworkModelServiceImpl;
74 import org.opendaylight.transportpce.tapi.topology.TapiNetworkUtilsImpl;
75 import org.opendaylight.transportpce.tapi.utils.TapiLink;
76 import org.opendaylight.transportpce.tapi.utils.TapiLinkImpl;
77 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.TransportpceOlmService;
78 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.OrgOpenroadmServiceService;
79 import org.opendaylight.yangtools.concepts.Registration;
80 import org.slf4j.Logger;
81 import org.slf4j.LoggerFactory;
84 public class TransportPCEImpl extends AbstractLightyModule implements TransportPCE {
85 private static final Logger LOG = LoggerFactory.getLogger(TransportPCEImpl.class);
86 private static final long MAX_TIME_FOR_TRANSACTION = 1500;
88 // cannot use interface for DeviceTransactionManagerImpl
89 // because implementation has additional public methods ...
90 private final DeviceTransactionManagerImpl deviceTransactionManager;
91 private final NetworkTransactionService networkTransaction;
92 // network model beans
93 private final NetworkModelProvider networkModelProvider;
94 // service-handler beans
95 private final ServiceHandlerProvider servicehandlerProvider;
97 private TapiProvider tapiProvider;
98 // nbi-notifications beans
99 private NbiNotificationsProvider nbiNotificationsProvider;
100 private List<Registration> rpcRegistrations = new ArrayList<>();
102 public TransportPCEImpl(
103 LightyServices lightyServices, boolean activateNbiNotification, boolean activateTapi,
104 String olmtimer1, String olmtimer2) {
105 LOG.info("Initializing transaction providers ...");
106 deviceTransactionManager =
107 new DeviceTransactionManagerImpl(lightyServices.getBindingMountPointService(), MAX_TIME_FOR_TRANSACTION);
108 var lgServBDB = lightyServices.getBindingDataBroker();
109 networkTransaction = new NetworkTransactionImpl(lgServBDB);
111 LOG.info("Creating network-model beans ...");
112 PortMapping portMapping = initPortMapping(lightyServices);
113 var lgServBNPS = lightyServices.getBindingNotificationPublishService();
114 NetworkModelService networkModelService = new NetworkModelServiceImpl(
116 deviceTransactionManager, networkTransaction, portMapping,
118 new NetConfTopologyListener(
119 networkModelService, lgServBDB, deviceTransactionManager, portMapping);
120 new PortMappingListener(networkModelService);
121 var lgServRPS = lightyServices.getRpcProviderService();
122 var lgServNS = lightyServices.getNotificationService();
123 new NetworkUtilsImpl(lgServBDB, lgServRPS);
124 networkModelProvider = new NetworkModelProvider(
127 networkModelService, deviceTransactionManager, portMapping,
129 new FrequenciesServiceImpl(lgServBDB));
131 LOG.info("Creating PCE beans ...");
132 // TODO: pass those parameters through command line
133 PathComputationService pathComputationService = new PathComputationServiceImpl(
136 new GnpyConsumerImpl(
137 "http://127.0.0.1:8008", "gnpy", "gnpy", lightyServices.getAdapterContext().currentSerializer()),
139 rpcRegistrations.add(
140 new PceServiceRPCImpl(lgServRPS, pathComputationService)
141 .getRegisteredRpc());
142 LOG.info("Creating OLM beans ...");
143 MappingUtils mappingUtils = new MappingUtilsImpl(lgServBDB);
144 CrossConnect crossConnect = initCrossConnect(mappingUtils);
145 OpenRoadmInterfaces openRoadmInterfaces = initOpenRoadmInterfaces(mappingUtils, portMapping);
146 OlmPowerServiceRpcImpl olmPowerServiceRpc = new OlmPowerServiceRpcImpl(
147 new OlmPowerServiceImpl(
150 openRoadmInterfaces, crossConnect, deviceTransactionManager,
151 portMapping, Long.valueOf(olmtimer1).longValue(), Long.valueOf(olmtimer2).longValue()),
152 deviceTransactionManager, portMapping, mappingUtils, openRoadmInterfaces),
154 rpcRegistrations.add(olmPowerServiceRpc.getRegisteredRpc());
155 LOG.info("Creating renderer beans ...");
156 initOpenRoadmFactory(mappingUtils, openRoadmInterfaces, portMapping);
157 DeviceRendererService deviceRendererService = new DeviceRendererServiceImpl(
159 deviceTransactionManager, openRoadmInterfaces, crossConnect,
160 mappingUtils, portMapping);
161 OtnDeviceRendererService otnDeviceRendererService = new OtnDeviceRendererServiceImpl(
162 crossConnect, openRoadmInterfaces, deviceTransactionManager, mappingUtils, portMapping);
163 initRenderer(lightyServices, olmPowerServiceRpc, deviceRendererService, otnDeviceRendererService, portMapping);
165 LOG.info("Creating service-handler beans ...");
166 RendererServiceOperations rendererServiceOperations = new RendererServiceOperationsImpl(
167 deviceRendererService, otnDeviceRendererService, olmPowerServiceRpc,
169 new NotificationSender(lgServBNPS),
172 ServiceDataStoreOperations serviceDataStoreOperations =
173 new ServiceDataStoreOperationsImpl(lgServBDB);
174 RendererNotificationHandler rendererNotificationHandler =
175 new RendererNotificationHandler(pathComputationService, lgServBNPS, networkModelService);
176 PceNotificationHandler pceListenerImpl = new PceNotificationHandler(
177 rendererServiceOperations, pathComputationService,
178 lgServBNPS, serviceDataStoreOperations);
179 NetworkModelNotificationHandler networkModelNotificationHandler = new NetworkModelNotificationHandler(
180 lgServBNPS, serviceDataStoreOperations);
181 ServicehandlerImpl servicehandler = new ServicehandlerImpl(lgServRPS,
182 pathComputationService, rendererServiceOperations,
183 lgServBNPS, pceListenerImpl,
184 rendererNotificationHandler, networkModelNotificationHandler, serviceDataStoreOperations,
185 new CatalogDataStoreOperationsImpl(networkTransaction));
186 rpcRegistrations.add(servicehandler.getRegisteredRpc());
187 servicehandlerProvider = new ServiceHandlerProvider(
189 lgServNS, serviceDataStoreOperations, pceListenerImpl,
190 rendererNotificationHandler, networkModelNotificationHandler,
192 servicehandler, serviceDataStoreOperations, lgServBNPS));
194 LOG.info("Creating tapi beans ...");
195 TapiLink tapiLink = new TapiLinkImpl(networkTransaction);
196 new TapiNetworkUtilsImpl(lgServRPS, networkTransaction, tapiLink);
197 tapiProvider = initTapi(
198 lightyServices, servicehandler, networkTransaction, serviceDataStoreOperations,
199 new TapiNetworkModelNotificationHandler(
200 networkTransaction, lgServBNPS),
202 new TapiNetworkModelServiceImpl(
203 networkTransaction, deviceTransactionManager, tapiLink,
205 rpcRegistrations.addAll(tapiProvider.getRegisteredRpcs());
207 if (activateNbiNotification) {
208 LOG.info("Creating nbi-notifications beans ...");
209 nbiNotificationsProvider = new NbiNotificationsProvider(
211 lightyServices.getAdapterContext().currentSerializer(),
212 networkTransaction, null);
217 protected boolean initProcedure() {
218 if (tapiProvider != null) {
219 LOG.info("Initializing tapi provider ...");
221 if (nbiNotificationsProvider != null) {
222 LOG.info("Initializing nbi-notifications provider ...");
224 LOG.info("Init done.");
229 protected boolean stopProcedure() {
230 if (nbiNotificationsProvider != null) {
231 nbiNotificationsProvider.close();
232 LOG.info("Shutting down nbi-notifications provider ...");
234 if (tapiProvider != null) {
235 tapiProvider.close();
236 LOG.info("Shutting down service-handler provider ...");
238 servicehandlerProvider.close();
239 LOG.info("Shutting down network-model provider ...");
240 networkModelProvider.close();
241 LOG.info("Shutting down transaction providers ...");
242 deviceTransactionManager.preDestroy();
243 LOG.info("Closing registered RPCs...");
244 for (Registration reg : rpcRegistrations) {
247 LOG.info("Shutdown done.");
251 private TapiProvider initTapi(
252 LightyServices lightyServices, OrgOpenroadmServiceService servicehandler,
253 NetworkTransactionService networkTransactionService, ServiceDataStoreOperations serviceDataStoreOperations,
254 TapiNetworkModelNotificationHandler tapiNetworkModelNotificationHandler, TapiLink tapiLink,
255 TapiNetworkModelService tapiNetworkModelService) {
256 return new TapiProvider(
257 lightyServices.getBindingDataBroker(), lightyServices.getRpcProviderService(),
258 lightyServices.getNotificationService(), lightyServices.getBindingNotificationPublishService(),
259 networkTransactionService, servicehandler, serviceDataStoreOperations,
260 tapiNetworkModelNotificationHandler, tapiNetworkModelService);
263 private void initRenderer(
264 LightyServices lightyServices, TransportpceOlmService olmPowerServiceRpc,
265 DeviceRendererService deviceRendererService, OtnDeviceRendererService otnDeviceRendererService,
266 PortMapping portMapping) {
267 rpcRegistrations.add(
268 new DeviceRendererRPCImpl(
269 lightyServices.getRpcProviderService(),
270 deviceRendererService,
271 otnDeviceRendererService)
272 .getRegisteredRpc());
273 rpcRegistrations.add(
274 new TransportPCEServicePathRPCImpl(
275 new RendererServiceOperationsImpl(
276 deviceRendererService,
277 otnDeviceRendererService,
279 lightyServices.getBindingDataBroker(),
280 new NotificationSender(
281 lightyServices.getBindingNotificationPublishService()
285 lightyServices.getRpcProviderService())
286 .getRegisteredRpc());
289 private OpenRoadmInterfaceFactory initOpenRoadmFactory(
290 MappingUtils mappingUtils, OpenRoadmInterfaces openRoadmInterfaces, PortMapping portMapping) {
291 return new OpenRoadmInterfaceFactory(mappingUtils, portMapping, openRoadmInterfaces);
294 private PortMapping initPortMapping(LightyServices lightyServices) {
295 PortMappingVersion710 portMappingVersion710 =
296 new PortMappingVersion710(lightyServices.getBindingDataBroker(), deviceTransactionManager);
297 PortMappingVersion221 portMappingVersion221 =
298 new PortMappingVersion221(lightyServices.getBindingDataBroker(), deviceTransactionManager);
299 PortMappingVersion121 portMappingVersion121 =
300 new PortMappingVersion121(lightyServices.getBindingDataBroker(), deviceTransactionManager);
301 return new PortMappingImpl(
302 lightyServices.getBindingDataBroker(), portMappingVersion710, portMappingVersion221, portMappingVersion121);
305 private OpenRoadmInterfaces initOpenRoadmInterfaces(MappingUtils mappingUtils, PortMapping portMapping) {
306 OpenRoadmInterfacesImpl121 openRoadmInterfacesImpl121 =
307 new OpenRoadmInterfacesImpl121(deviceTransactionManager);
308 OpenRoadmInterfacesImpl221 openRoadmInterfacesImpl221 =
309 new OpenRoadmInterfacesImpl221(deviceTransactionManager, portMapping);
310 OpenRoadmInterfacesImpl710 openRoadmInterfacesImpl710 =
311 new OpenRoadmInterfacesImpl710(deviceTransactionManager, portMapping);
312 return new OpenRoadmInterfacesImpl(
313 deviceTransactionManager, mappingUtils,
314 openRoadmInterfacesImpl121, openRoadmInterfacesImpl221, openRoadmInterfacesImpl710);
318 private CrossConnect initCrossConnect(MappingUtils mappingUtils) {
319 CrossConnectImpl121 crossConnectImpl121 = new CrossConnectImpl121(deviceTransactionManager);
320 CrossConnectImpl221 crossConnectImpl221 = new CrossConnectImpl221(deviceTransactionManager);
321 CrossConnectImpl710 crossConnectImpl710 = new CrossConnectImpl710(deviceTransactionManager);
322 return new CrossConnectImpl(
323 deviceTransactionManager, mappingUtils,
324 crossConnectImpl121, crossConnectImpl221, crossConnectImpl710);