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.openroadm.service.rev230526.OrgOpenroadmServiceService;
45 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NetworkId;
46 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.Networks;
47 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.NetworkKey;
48 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Network1;
49 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.Link;
50 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.TapiCommonService;
51 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.TapiConnectivityService;
52 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.TapiNotificationListener;
53 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.TapiTopologyService;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.tapi.rev180928.ServiceInterfacePoints;
55 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
56 import org.opendaylight.yangtools.concepts.ListenerRegistration;
57 import org.opendaylight.yangtools.concepts.ObjectRegistration;
58 import org.opendaylight.yangtools.concepts.Registration;
59 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
60 import org.osgi.service.component.annotations.Activate;
61 import org.osgi.service.component.annotations.Component;
62 import org.osgi.service.component.annotations.Deactivate;
63 import org.osgi.service.component.annotations.Reference;
64 import org.slf4j.Logger;
65 import org.slf4j.LoggerFactory;
68 * Class to register TAPI interface Service and Notification.
70 * @author Gilles Thouenon (gilles.thouenon@orange.com) on behalf of Orange
74 public class TapiProvider {
76 private static final Logger LOG = LoggerFactory.getLogger(TapiProvider.class);
78 private static final InstanceIdentifier<Nodes> MAPPING_II = InstanceIdentifier.create(Network.class)
79 .child(org.opendaylight.yang.gen.v1.http
80 .org.opendaylight.transportpce.portmapping.rev220922.network.Nodes.class);
81 private static final InstanceIdentifier<Link> LINK_II = InstanceIdentifier.create(Networks.class).child(
82 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.Network.class,
83 new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID))).augmentation(Network1.class)
85 private final DataBroker dataBroker;
86 private final NetworkTransactionService networkTransactionService;
87 private final OrgOpenroadmServiceService serviceHandler;
88 private final ServiceDataStoreOperations serviceDataStoreOperations;
89 private ObjectRegistration<TapiConnectivityService> rpcRegistration;
90 private List<Registration> listeners;
91 private ListenerRegistration<TransportpcePceListener> pcelistenerRegistration;
92 private ListenerRegistration<TransportpceRendererListener> rendererlistenerRegistration;
93 private ListenerRegistration<TransportpceServicehandlerListener> servicehandlerlistenerRegistration;
94 private ListenerRegistration<TapiNotificationListener> tapinetworkmodellistenerRegistration;
97 public TapiProvider(@Reference DataBroker dataBroker,
98 @Reference RpcProviderService rpcProviderService,
99 @Reference NotificationService notificationService,
100 @Reference NotificationPublishService notificationPublishService,
101 @Reference NetworkTransactionService networkTransactionService,
102 @Reference OrgOpenroadmServiceService serviceHandler,
103 @Reference ServiceDataStoreOperations serviceDataStoreOperations,
104 @Reference TapiNotificationListener tapiNetworkModelListenerImpl,
105 @Reference TapiNetworkModelService tapiNetworkModelServiceImpl) {
106 this.dataBroker = dataBroker;
107 this.networkTransactionService = networkTransactionService;
108 this.serviceHandler = serviceHandler;
109 this.serviceDataStoreOperations = serviceDataStoreOperations;
110 LOG.info("TapiProvider Session Initiated");
111 TapiContext tapiContext = new TapiContext(this.networkTransactionService);
112 LOG.info("Empty TAPI context created: {}", tapiContext.getTapiContext());
113 TapiLink tapiLink = new TapiLinkImpl(this.networkTransactionService);
114 TopologyUtils topologyUtils = new TopologyUtils(this.networkTransactionService, this.dataBroker, tapiLink);
115 ConnectivityUtils connectivityUtils = new ConnectivityUtils(this.serviceDataStoreOperations, new HashMap<>(),
116 tapiContext, this.networkTransactionService);
117 TapiInitialORMapping tapiInitialORMapping = new TapiInitialORMapping(topologyUtils, connectivityUtils,
118 tapiContext, this.serviceDataStoreOperations);
119 tapiInitialORMapping.performTopoInitialMapping();
120 tapiInitialORMapping.performServInitialMapping();
121 TapiPceListenerImpl pceListenerImpl = new TapiPceListenerImpl(dataBroker);
122 TapiRendererListenerImpl rendererListenerImpl = new TapiRendererListenerImpl(dataBroker,
123 notificationPublishService);
125 TapiConnectivityImpl tapi = new TapiConnectivityImpl(this.serviceHandler, tapiContext, connectivityUtils,
126 pceListenerImpl, rendererListenerImpl);
127 TapiTopologyImpl topo = new TapiTopologyImpl(this.dataBroker, tapiContext, topologyUtils, tapiLink);
129 rpcRegistration = rpcProviderService.registerRpcImplementation(TapiConnectivityService.class, tapi);
130 rpcProviderService.registerRpcImplementation(TapiTopologyService.class, topo);
131 rpcProviderService.registerRpcImplementation(TapiCommonService.class, topo);
133 this.listeners = new ArrayList<>();
134 TapiNetconfTopologyListener topologyListener = new TapiNetconfTopologyListener(tapiNetworkModelServiceImpl);
135 TapiOrLinkListener orLinkListener = new TapiOrLinkListener(tapiLink, networkTransactionService);
136 TapiPortMappingListener tapiPortMappingListener = new TapiPortMappingListener(tapiNetworkModelServiceImpl);
137 listeners.add(dataBroker.registerDataTreeChangeListener(
138 DataTreeIdentifier.create(LogicalDatastoreType.CONFIGURATION, LINK_II), orLinkListener));
139 listeners.add(dataBroker.registerDataTreeChangeListener(
140 DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL, InstanceIdentifiers.NETCONF_TOPOLOGY_II
143 listeners.add(dataBroker.registerDataTreeChangeListener(
144 DataTreeIdentifier.create(LogicalDatastoreType.CONFIGURATION, MAPPING_II), tapiPortMappingListener));
145 TapiListener tapiListener = new TapiListener();
146 listeners.add(dataBroker.registerDataTreeChangeListener(
147 DataTreeIdentifier.create(
148 LogicalDatastoreType.CONFIGURATION,
149 InstanceIdentifier.create(ServiceInterfacePoints.class)),
151 // Notification Listener
152 pcelistenerRegistration = notificationService.registerNotificationListener(pceListenerImpl);
153 rendererlistenerRegistration = notificationService.registerNotificationListener(rendererListenerImpl);
154 TapiServiceHandlerListenerImpl serviceHandlerListenerImpl = new TapiServiceHandlerListenerImpl(dataBroker);
155 servicehandlerlistenerRegistration = notificationService
156 .registerNotificationListener(serviceHandlerListenerImpl);
157 tapinetworkmodellistenerRegistration = notificationService
158 .registerNotificationListener(tapiNetworkModelListenerImpl);
162 * Method called when the blueprint container is destroyed.
165 public void close() {
166 listeners.forEach(lis -> lis.close());
168 pcelistenerRegistration.close();
169 rendererlistenerRegistration.close();
170 servicehandlerlistenerRegistration.close();
171 rpcRegistration.close();
172 tapinetworkmodellistenerRegistration.close();
173 LOG.info("TapiProvider Session Closed");