2 * Copyright © 2018 Orange, 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
8 package org.opendaylight.transportpce.tapi.impl;
10 import java.util.ArrayList;
11 import java.util.HashMap;
12 import java.util.List;
13 import org.opendaylight.mdsal.binding.api.DataBroker;
14 import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
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.mdsal.common.api.LogicalDatastoreType;
19 import org.opendaylight.transportpce.common.InstanceIdentifiers;
20 import org.opendaylight.transportpce.common.NetworkUtils;
21 import org.opendaylight.transportpce.common.network.NetworkTransactionService;
22 import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperations;
23 import org.opendaylight.transportpce.tapi.connectivity.ConnectivityUtils;
24 import org.opendaylight.transportpce.tapi.connectivity.TapiConnectivityImpl;
25 import org.opendaylight.transportpce.tapi.listeners.TapiPceListenerImpl;
26 import org.opendaylight.transportpce.tapi.listeners.TapiRendererListenerImpl;
27 import org.opendaylight.transportpce.tapi.listeners.TapiServiceHandlerListenerImpl;
28 import org.opendaylight.transportpce.tapi.topology.TapiNetconfTopologyListener;
29 import org.opendaylight.transportpce.tapi.topology.TapiNetworkModelService;
30 import org.opendaylight.transportpce.tapi.topology.TapiOrLinkListener;
31 import org.opendaylight.transportpce.tapi.topology.TapiPortMappingListener;
32 import org.opendaylight.transportpce.tapi.topology.TapiTopologyImpl;
33 import org.opendaylight.transportpce.tapi.topology.TopologyUtils;
34 import org.opendaylight.transportpce.tapi.utils.TapiContext;
35 import org.opendaylight.transportpce.tapi.utils.TapiInitialORMapping;
36 import org.opendaylight.transportpce.tapi.utils.TapiLink;
37 import org.opendaylight.transportpce.tapi.utils.TapiLinkImpl;
38 import org.opendaylight.transportpce.tapi.utils.TapiListener;
39 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.TransportpcePceListener;
40 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220922.Network;
41 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220922.network.Nodes;
42 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.TransportpceRendererListener;
43 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev201125.TransportpceServicehandlerListener;
44 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.tapinetworkutils.rev210408.TransportpceTapinetworkutilsService;
45 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.OrgOpenroadmServiceService;
46 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NetworkId;
47 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.Networks;
48 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.NetworkKey;
49 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Network1;
50 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.Link;
51 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.TapiCommonService;
52 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.TapiConnectivityService;
53 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.TapiNotificationListener;
54 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.TapiTopologyService;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.tapi.rev180928.ServiceInterfacePoints;
56 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
57 import org.opendaylight.yangtools.concepts.ListenerRegistration;
58 import org.opendaylight.yangtools.concepts.ObjectRegistration;
59 import org.opendaylight.yangtools.concepts.Registration;
60 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
61 import org.osgi.service.component.annotations.Activate;
62 import org.osgi.service.component.annotations.Component;
63 import org.osgi.service.component.annotations.Deactivate;
64 import org.osgi.service.component.annotations.Reference;
65 import org.slf4j.Logger;
66 import org.slf4j.LoggerFactory;
69 * Class to register TAPI interface Service and Notification.
71 * @author Gilles Thouenon (gilles.thouenon@orange.com) on behalf of Orange
75 public class TapiProvider {
77 private static final Logger LOG = LoggerFactory.getLogger(TapiProvider.class);
79 private static final InstanceIdentifier<Nodes> MAPPING_II = InstanceIdentifier.create(Network.class)
80 .child(org.opendaylight.yang.gen.v1.http
81 .org.opendaylight.transportpce.portmapping.rev220922.network.Nodes.class);
82 private static final InstanceIdentifier<Link> LINK_II = InstanceIdentifier.create(Networks.class).child(
83 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.Network.class,
84 new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID))).augmentation(Network1.class)
86 private final DataBroker dataBroker;
87 private final RpcProviderService rpcProviderService;
88 private final NotificationService notificationService;
89 private final NetworkTransactionService networkTransactionService;
90 private final OrgOpenroadmServiceService serviceHandler;
91 private final ServiceDataStoreOperations serviceDataStoreOperations;
92 private final TransportpceTapinetworkutilsService tapiNetworkUtils;
93 private TapiNotificationListener tapiNetworkModelListenerImpl;
94 private ObjectRegistration<TapiConnectivityService> rpcRegistration;
95 private ObjectRegistration<TransportpceTapinetworkutilsService> tapiNetworkutilsServiceRpcRegistration;
96 private List<Registration> listeners;
97 private ListenerRegistration<TransportpcePceListener> pcelistenerRegistration;
98 private ListenerRegistration<TransportpceRendererListener> rendererlistenerRegistration;
99 private ListenerRegistration<TransportpceServicehandlerListener> servicehandlerlistenerRegistration;
100 private ListenerRegistration<TapiNotificationListener> tapinetworkmodellistenerRegistration;
103 public TapiProvider(@Reference DataBroker dataBroker,
104 @Reference RpcProviderService rpcProviderService,
105 @Reference NotificationService notificationService,
106 @Reference NotificationPublishService notificationPublishService,
107 @Reference NetworkTransactionService networkTransactionService,
108 @Reference OrgOpenroadmServiceService serviceHandler,
109 @Reference ServiceDataStoreOperations serviceDataStoreOperations,
110 @Reference TransportpceTapinetworkutilsService tapiNetworkUtils,
111 @Reference TapiNotificationListener tapiNetworkModelListenerImpl,
112 @Reference TapiNetworkModelService tapiNetworkModelServiceImpl) {
113 this.dataBroker = dataBroker;
114 this.rpcProviderService = rpcProviderService;
115 this.notificationService = notificationService;
116 this.networkTransactionService = networkTransactionService;
117 this.serviceHandler = serviceHandler;
118 this.serviceDataStoreOperations = serviceDataStoreOperations;
119 this.tapiNetworkUtils = tapiNetworkUtils;
120 this.tapiNetworkModelListenerImpl = tapiNetworkModelListenerImpl;
122 LOG.info("TapiProvider Session Initiated");
123 TapiContext tapiContext = new TapiContext(this.networkTransactionService);
124 LOG.info("Empty TAPI context created: {}", tapiContext.getTapiContext());
125 TapiLink tapiLink = new TapiLinkImpl(this.networkTransactionService);
126 TopologyUtils topologyUtils = new TopologyUtils(this.networkTransactionService, this.dataBroker, tapiLink);
127 ConnectivityUtils connectivityUtils = new ConnectivityUtils(this.serviceDataStoreOperations, new HashMap<>(),
128 tapiContext, this.networkTransactionService);
129 TapiInitialORMapping tapiInitialORMapping = new TapiInitialORMapping(topologyUtils, connectivityUtils,
130 tapiContext, this.serviceDataStoreOperations);
131 tapiInitialORMapping.performTopoInitialMapping();
132 tapiInitialORMapping.performServInitialMapping();
133 TapiPceListenerImpl pceListenerImpl = new TapiPceListenerImpl(dataBroker);
134 TapiRendererListenerImpl rendererListenerImpl = new TapiRendererListenerImpl(dataBroker,
135 notificationPublishService);
137 TapiConnectivityImpl tapi = new TapiConnectivityImpl(this.serviceHandler, tapiContext, connectivityUtils,
138 pceListenerImpl, rendererListenerImpl);
139 TapiTopologyImpl topo = new TapiTopologyImpl(this.dataBroker, tapiContext, topologyUtils, tapiLink);
141 rpcRegistration = rpcProviderService.registerRpcImplementation(TapiConnectivityService.class, tapi);
142 rpcProviderService.registerRpcImplementation(TapiTopologyService.class, topo);
143 rpcProviderService.registerRpcImplementation(TapiCommonService.class, topo);
145 this.listeners = new ArrayList<>();
146 TapiNetconfTopologyListener topologyListener = new TapiNetconfTopologyListener(tapiNetworkModelServiceImpl);
147 TapiOrLinkListener orLinkListener = new TapiOrLinkListener(tapiLink, networkTransactionService);
148 TapiPortMappingListener tapiPortMappingListener = new TapiPortMappingListener(tapiNetworkModelServiceImpl);
149 listeners.add(dataBroker.registerDataTreeChangeListener(
150 DataTreeIdentifier.create(LogicalDatastoreType.CONFIGURATION, LINK_II), orLinkListener));
151 listeners.add(dataBroker.registerDataTreeChangeListener(
152 DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL, InstanceIdentifiers.NETCONF_TOPOLOGY_II
155 listeners.add(dataBroker.registerDataTreeChangeListener(
156 DataTreeIdentifier.create(LogicalDatastoreType.CONFIGURATION, MAPPING_II), tapiPortMappingListener));
157 tapiNetworkutilsServiceRpcRegistration =
158 rpcProviderService.registerRpcImplementation(TransportpceTapinetworkutilsService.class,
159 this.tapiNetworkUtils);
160 TapiListener tapiListener = new TapiListener();
161 listeners.add(dataBroker.registerDataTreeChangeListener(
162 DataTreeIdentifier.create(
163 LogicalDatastoreType.CONFIGURATION,
164 InstanceIdentifier.create(ServiceInterfacePoints.class)),
166 // Notification Listener
167 pcelistenerRegistration = notificationService.registerNotificationListener(pceListenerImpl);
168 rendererlistenerRegistration = notificationService.registerNotificationListener(rendererListenerImpl);
169 TapiServiceHandlerListenerImpl serviceHandlerListenerImpl = new TapiServiceHandlerListenerImpl(dataBroker);
170 servicehandlerlistenerRegistration = notificationService
171 .registerNotificationListener(serviceHandlerListenerImpl);
172 tapinetworkmodellistenerRegistration = notificationService
173 .registerNotificationListener(tapiNetworkModelListenerImpl);
177 * Method called when the blueprint container is destroyed.
180 public void close() {
181 listeners.forEach(lis -> lis.close());
183 if (tapiNetworkutilsServiceRpcRegistration != null) {
184 tapiNetworkutilsServiceRpcRegistration.close();
186 pcelistenerRegistration.close();
187 rendererlistenerRegistration.close();
188 servicehandlerlistenerRegistration.close();
189 rpcRegistration.close();
190 tapinetworkmodellistenerRegistration.close();
191 LOG.info("TapiProvider Session Closed");