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.mdsal.binding.api.DataBroker;
15 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
16 import org.opendaylight.mdsal.binding.api.NotificationService;
17 import org.opendaylight.mdsal.binding.api.RpcProviderService;
18 import org.opendaylight.transportpce.common.crossconnect.CrossConnect;
19 import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl;
20 import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl121;
21 import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl221;
22 import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl710;
23 import org.opendaylight.transportpce.common.device.DeviceTransactionManagerImpl;
24 import org.opendaylight.transportpce.common.mapping.MappingUtils;
25 import org.opendaylight.transportpce.common.mapping.MappingUtilsImpl;
26 import org.opendaylight.transportpce.common.mapping.PortMapping;
27 import org.opendaylight.transportpce.common.mapping.PortMappingImpl;
28 import org.opendaylight.transportpce.common.mapping.PortMappingVersion121;
29 import org.opendaylight.transportpce.common.mapping.PortMappingVersion221;
30 import org.opendaylight.transportpce.common.mapping.PortMappingVersion710;
31 import org.opendaylight.transportpce.common.network.NetworkTransactionImpl;
32 import org.opendaylight.transportpce.common.network.NetworkTransactionService;
33 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
34 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl;
35 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl121;
36 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl221;
37 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl710;
38 import org.opendaylight.transportpce.nbinotifications.impl.NbiNotificationsProvider;
39 import org.opendaylight.transportpce.networkmodel.NetConfTopologyListener;
40 import org.opendaylight.transportpce.networkmodel.NetworkModelProvider;
41 import org.opendaylight.transportpce.networkmodel.NetworkUtilsImpl;
42 import org.opendaylight.transportpce.networkmodel.listeners.PortMappingListener;
43 import org.opendaylight.transportpce.networkmodel.service.FrequenciesServiceImpl;
44 import org.opendaylight.transportpce.networkmodel.service.NetworkModelService;
45 import org.opendaylight.transportpce.networkmodel.service.NetworkModelServiceImpl;
46 import org.opendaylight.transportpce.olm.OlmPowerServiceRpcImpl;
47 import org.opendaylight.transportpce.olm.power.PowerMgmtImpl;
48 import org.opendaylight.transportpce.olm.service.OlmPowerServiceImpl;
49 import org.opendaylight.transportpce.pce.gnpy.consumer.GnpyConsumerImpl;
50 import org.opendaylight.transportpce.pce.impl.PceServiceRPCImpl;
51 import org.opendaylight.transportpce.pce.service.PathComputationService;
52 import org.opendaylight.transportpce.pce.service.PathComputationServiceImpl;
53 import org.opendaylight.transportpce.renderer.openroadminterface.OpenRoadmInterfaceFactory;
54 // Adding OTN interface
55 import org.opendaylight.transportpce.renderer.provisiondevice.DeviceRendererService;
56 import org.opendaylight.transportpce.renderer.provisiondevice.DeviceRendererServiceImpl;
57 import org.opendaylight.transportpce.renderer.provisiondevice.OtnDeviceRendererService;
59 import org.opendaylight.transportpce.renderer.provisiondevice.OtnDeviceRendererServiceImpl;
60 import org.opendaylight.transportpce.renderer.provisiondevice.RendererServiceOperations;
61 import org.opendaylight.transportpce.renderer.provisiondevice.RendererServiceOperationsImpl;
62 import org.opendaylight.transportpce.renderer.provisiondevice.notification.NotificationSender;
63 import org.opendaylight.transportpce.renderer.rpcs.DeviceRendererRPCImpl;
64 import org.opendaylight.transportpce.renderer.rpcs.RendererRPCImpl;
65 import org.opendaylight.transportpce.servicehandler.catalog.CatalogDataStoreOperationsImpl;
66 import org.opendaylight.transportpce.servicehandler.impl.ServiceHandlerProvider;
67 import org.opendaylight.transportpce.servicehandler.impl.ServicehandlerImpl;
68 import org.opendaylight.transportpce.servicehandler.listeners.NetworkModelNotificationHandler;
69 import org.opendaylight.transportpce.servicehandler.listeners.PceNotificationHandler;
70 import org.opendaylight.transportpce.servicehandler.listeners.RendererNotificationHandler;
71 import org.opendaylight.transportpce.servicehandler.listeners.ServiceListener;
72 import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperations;
73 import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperationsImpl;
74 import org.opendaylight.transportpce.tapi.impl.TapiProvider;
75 import org.opendaylight.transportpce.tapi.listeners.TapiNetworkModelNotificationHandler;
76 import org.opendaylight.transportpce.tapi.topology.TapiNetworkModelServiceImpl;
77 import org.opendaylight.transportpce.tapi.topology.TapiNetworkUtilsImpl;
78 import org.opendaylight.transportpce.tapi.utils.TapiLink;
79 import org.opendaylight.transportpce.tapi.utils.TapiLinkImpl;
80 import org.opendaylight.yangtools.concepts.Registration;
81 import org.slf4j.Logger;
82 import org.slf4j.LoggerFactory;
85 public class TransportPCEImpl extends AbstractLightyModule implements TransportPCE {
86 private static final Logger LOG = LoggerFactory.getLogger(TransportPCEImpl.class);
87 private static final long MAX_TIME_FOR_TRANSACTION = 1500;
89 // cannot use interface for DeviceTransactionManagerImpl
90 // because implementation has additional public methods ...
91 private final DeviceTransactionManagerImpl deviceTransactionManager;
92 private final NetworkTransactionService networkTransaction;
93 // network model beans
94 private final NetworkModelProvider networkModelProvider;
95 // service-handler beans
96 private final ServiceHandlerProvider servicehandlerProvider;
98 private TapiProvider tapiProvider;
99 // nbi-notifications beans
100 private NbiNotificationsProvider nbiNotificationsProvider;
101 private List<Registration> rpcRegistrations = new ArrayList<>();
103 public TransportPCEImpl(
104 LightyServices lightyServices, boolean activateNbiNotification, boolean activateTapi,
105 String olmtimer1, String olmtimer2) {
106 LOG.info("Initializing transaction providers ...");
107 deviceTransactionManager =
108 new DeviceTransactionManagerImpl(lightyServices.getBindingMountPointService(), MAX_TIME_FOR_TRANSACTION);
109 DataBroker dataBroker = lightyServices.getBindingDataBroker();
110 networkTransaction = new NetworkTransactionImpl(dataBroker);
112 LOG.info("Creating network-model beans ...");
113 PortMapping portMapping = initPortMapping(dataBroker);
114 NotificationPublishService notificationPublishService = lightyServices.getBindingNotificationPublishService();
115 NetworkModelService networkModelService = new NetworkModelServiceImpl(dataBroker, deviceTransactionManager,
116 networkTransaction, portMapping, notificationPublishService);
117 new NetConfTopologyListener(networkModelService, dataBroker, deviceTransactionManager, portMapping);
118 new PortMappingListener(networkModelService);
120 RpcProviderService rpcProviderService = lightyServices.getRpcProviderService();
121 NotificationService notificationService = lightyServices.getNotificationService();
122 new NetworkUtilsImpl(dataBroker, rpcProviderService);
123 networkModelProvider = new NetworkModelProvider(networkTransaction, dataBroker, networkModelService,
124 deviceTransactionManager, portMapping, notificationService, new FrequenciesServiceImpl(dataBroker));
126 LOG.info("Creating PCE beans ...");
127 // TODO: pass those parameters through command line
128 PathComputationService pathComputationService = new PathComputationServiceImpl(
130 notificationPublishService,
131 new GnpyConsumerImpl(
132 "http://127.0.0.1:8008", "gnpy", "gnpy", lightyServices.getAdapterContext().currentSerializer()),
134 rpcRegistrations.add(new PceServiceRPCImpl(rpcProviderService, pathComputationService).getRegisteredRpc());
136 LOG.info("Creating OLM beans ...");
137 MappingUtils mappingUtils = new MappingUtilsImpl(dataBroker);
138 CrossConnect crossConnect = initCrossConnect(mappingUtils);
139 OpenRoadmInterfaces openRoadmInterfaces = initOpenRoadmInterfaces(mappingUtils, portMapping);
140 OlmPowerServiceRpcImpl olmPowerServiceRpc = new OlmPowerServiceRpcImpl(
141 new OlmPowerServiceImpl(
146 deviceTransactionManager,
148 Long.valueOf(olmtimer1).longValue(),
149 Long.valueOf(olmtimer2).longValue()),
150 deviceTransactionManager,
153 openRoadmInterfaces),
155 rpcRegistrations.add(olmPowerServiceRpc.getRegisteredRpc());
157 LOG.info("Creating renderer beans ...");
158 new OpenRoadmInterfaceFactory(mappingUtils, portMapping, openRoadmInterfaces);
159 DeviceRendererService deviceRendererService = new DeviceRendererServiceImpl(
161 deviceTransactionManager,
166 OtnDeviceRendererService otnDeviceRendererService = new OtnDeviceRendererServiceImpl(
169 deviceTransactionManager,
172 //FIXME: need mdsal.binding;api.RpcService from LightyServices
173 RpcService rpcService = lightyServices.getRpcService();
174 RendererServiceOperations rendererServiceOperations = new RendererServiceOperationsImpl(
175 deviceRendererService, otnDeviceRendererService, dataBroker,
176 new NotificationSender(notificationPublishService),
179 rpcRegistrations.add(new DeviceRendererRPCImpl(
180 lightyServices.getRpcProviderService(),
181 deviceRendererService,
182 otnDeviceRendererService)
183 .getRegisteredRpc());
184 rpcRegistrations.add(new RendererRPCImpl(
185 rendererServiceOperations,
186 lightyServices.getRpcProviderService())
187 .getRegisteredRpc());
189 LOG.info("Creating service-handler beans ...");
190 ServiceDataStoreOperations serviceDataStoreOperations = new ServiceDataStoreOperationsImpl(dataBroker);
191 RendererNotificationHandler rendererListener =
192 new RendererNotificationHandler(pathComputationService, notificationPublishService, networkModelService);
193 PceNotificationHandler pceListenerImpl = new PceNotificationHandler(
194 rendererServiceOperations, pathComputationService,
195 notificationPublishService, serviceDataStoreOperations);
196 NetworkModelNotificationHandler networkListener = new NetworkModelNotificationHandler(
197 notificationPublishService, serviceDataStoreOperations);
198 ServicehandlerImpl servicehandler = new ServicehandlerImpl(
200 serviceDataStoreOperations,
204 new CatalogDataStoreOperationsImpl(networkTransaction),
205 pathComputationService,
206 rendererServiceOperations,
207 notificationPublishService);
208 rpcRegistrations.add(servicehandler.getRegisteredRpc());
209 servicehandlerProvider = new ServiceHandlerProvider(
212 serviceDataStoreOperations,
216 new ServiceListener(rpcService, serviceDataStoreOperations, notificationPublishService));
219 LOG.info("Creating tapi beans ...");
220 TapiLink tapiLink = new TapiLinkImpl(networkTransaction);
221 new TapiNetworkUtilsImpl(rpcProviderService, networkTransaction, tapiLink);
222 tapiProvider = new TapiProvider(
227 notificationPublishService,
229 serviceDataStoreOperations,
230 new TapiNetworkModelNotificationHandler(networkTransaction, notificationPublishService),
231 new TapiNetworkModelServiceImpl(
233 deviceTransactionManager,
235 notificationPublishService));
236 rpcRegistrations.addAll(tapiProvider.getRegisteredRpcs());
238 if (activateNbiNotification) {
239 LOG.info("Creating nbi-notifications beans ...");
240 nbiNotificationsProvider = new NbiNotificationsProvider(
243 lightyServices.getAdapterContext().currentSerializer(),
244 networkTransaction, null);
249 protected boolean initProcedure() {
250 if (tapiProvider != null) {
251 LOG.info("Initializing tapi provider ...");
253 if (nbiNotificationsProvider != null) {
254 LOG.info("Initializing nbi-notifications provider ...");
256 LOG.info("Init done.");
261 protected boolean stopProcedure() {
262 if (nbiNotificationsProvider != null) {
263 nbiNotificationsProvider.close();
264 LOG.info("Shutting down nbi-notifications provider ...");
266 if (tapiProvider != null) {
267 tapiProvider.close();
268 LOG.info("Shutting down service-handler provider ...");
270 servicehandlerProvider.close();
271 LOG.info("Shutting down network-model provider ...");
272 networkModelProvider.close();
273 LOG.info("Shutting down transaction providers ...");
274 deviceTransactionManager.preDestroy();
275 LOG.info("Closing registered RPCs...");
276 for (Registration reg : rpcRegistrations) {
279 LOG.info("Shutdown done.");
283 private PortMapping initPortMapping(DataBroker dataBroker) {
284 PortMappingVersion710 portMappingVersion710 = new PortMappingVersion710(dataBroker, deviceTransactionManager);
285 PortMappingVersion221 portMappingVersion221 = new PortMappingVersion221(dataBroker, deviceTransactionManager);
286 PortMappingVersion121 portMappingVersion121 = new PortMappingVersion121(dataBroker, deviceTransactionManager);
287 return new PortMappingImpl(dataBroker, portMappingVersion710, portMappingVersion221, portMappingVersion121);
290 private OpenRoadmInterfaces initOpenRoadmInterfaces(MappingUtils mappingUtils, PortMapping portMapping) {
291 OpenRoadmInterfacesImpl121 openRoadmInterfacesImpl121 =
292 new OpenRoadmInterfacesImpl121(deviceTransactionManager);
293 OpenRoadmInterfacesImpl221 openRoadmInterfacesImpl221 =
294 new OpenRoadmInterfacesImpl221(deviceTransactionManager, portMapping);
295 OpenRoadmInterfacesImpl710 openRoadmInterfacesImpl710 =
296 new OpenRoadmInterfacesImpl710(deviceTransactionManager, portMapping);
297 return new OpenRoadmInterfacesImpl(deviceTransactionManager, mappingUtils, openRoadmInterfacesImpl121,
298 openRoadmInterfacesImpl221, openRoadmInterfacesImpl710);
301 private CrossConnect initCrossConnect(MappingUtils mappingUtils) {
302 CrossConnectImpl121 crossConnectImpl121 = new CrossConnectImpl121(deviceTransactionManager);
303 CrossConnectImpl221 crossConnectImpl221 = new CrossConnectImpl221(deviceTransactionManager);
304 CrossConnectImpl710 crossConnectImpl710 = new CrossConnectImpl710(deviceTransactionManager);
305 return new CrossConnectImpl(deviceTransactionManager, mappingUtils, crossConnectImpl121,
306 crossConnectImpl221, crossConnectImpl710);