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.HashMap;
11 import org.eclipse.jdt.annotation.NonNull;
12 import org.opendaylight.mdsal.binding.api.DataBroker;
13 import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
14 import org.opendaylight.mdsal.binding.api.RpcProviderService;
15 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
16 import org.opendaylight.transportpce.common.InstanceIdentifiers;
17 import org.opendaylight.transportpce.common.network.NetworkTransactionService;
18 import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperations;
19 import org.opendaylight.transportpce.tapi.connectivity.ConnectivityUtils;
20 import org.opendaylight.transportpce.tapi.connectivity.TapiConnectivityImpl;
21 import org.opendaylight.transportpce.tapi.topology.TapiNetconfTopologyListener;
22 import org.opendaylight.transportpce.tapi.topology.TapiPortMappingListener;
23 import org.opendaylight.transportpce.tapi.topology.TapiTopologyImpl;
24 import org.opendaylight.transportpce.tapi.topology.TopologyUtils;
25 import org.opendaylight.transportpce.tapi.utils.TapiContext;
26 import org.opendaylight.transportpce.tapi.utils.TapiInitialORMapping;
27 import org.opendaylight.transportpce.tapi.utils.TapiListener;
28 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210315.Network;
29 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210315.network.Nodes;
30 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.tapinetworkutils.rev210408.TransportpceTapinetworkutilsService;
31 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.OrgOpenroadmServiceService;
32 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.TapiConnectivityService;
33 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.TapiTopologyService;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.tapi.rev180928.ServiceInterfacePoints;
35 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
36 import org.opendaylight.yangtools.concepts.ListenerRegistration;
37 import org.opendaylight.yangtools.concepts.ObjectRegistration;
38 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
43 * Class to register TAPI interface Service and Notification.
45 * @author Gilles Thouenon (gilles.thouenon@orange.com) on behalf of Orange
48 public class TapiProvider {
50 private static final Logger LOG = LoggerFactory.getLogger(TapiProvider.class);
52 private static final InstanceIdentifier<Nodes> MAPPING_II = InstanceIdentifier.create(Network.class)
53 .child(org.opendaylight.yang.gen.v1.http
54 .org.opendaylight.transportpce.portmapping.rev210315.network.Nodes.class);
55 private final DataBroker dataBroker;
56 private final RpcProviderService rpcProviderService;
57 private ObjectRegistration<TapiConnectivityService> rpcRegistration;
58 private ObjectRegistration<TransportpceTapinetworkutilsService> tapiNetworkutilsServiceRpcRegistration;
59 private ListenerRegistration<TapiNetconfTopologyListener> dataTreeChangeListenerRegistration;
60 private ListenerRegistration<TapiPortMappingListener> mappingListenerListenerRegistration;
61 private final OrgOpenroadmServiceService serviceHandler;
62 private final ServiceDataStoreOperations serviceDataStoreOperations;
63 private final TapiListener tapiListener;
64 private final TapiNetconfTopologyListener topologyListener;
65 private TapiPortMappingListener tapiPortMappingListener;
66 private final NetworkTransactionService networkTransactionService;
67 private final TransportpceTapinetworkutilsService tapiNetworkUtils;
69 public TapiProvider(DataBroker dataBroker, RpcProviderService rpcProviderService,
70 OrgOpenroadmServiceService serviceHandler, ServiceDataStoreOperations serviceDataStoreOperations,
71 TapiListener tapiListener, NetworkTransactionService networkTransactionService,
72 TapiNetconfTopologyListener topologyListener, TapiPortMappingListener tapiPortMappingListener,
73 TransportpceTapinetworkutilsService tapiNetworkUtils) {
74 this.dataBroker = dataBroker;
75 this.rpcProviderService = rpcProviderService;
76 this.serviceHandler = serviceHandler;
77 this.serviceDataStoreOperations = serviceDataStoreOperations;
78 this.tapiListener = tapiListener;
79 this.networkTransactionService = networkTransactionService;
80 this.topologyListener = topologyListener;
81 this.tapiPortMappingListener = tapiPortMappingListener;
82 this.tapiNetworkUtils = tapiNetworkUtils;
86 * Method called when the blueprint container is created.
89 LOG.info("TapiProvider Session Initiated");
90 TapiContext tapiContext = new TapiContext(this.networkTransactionService);
91 LOG.info("Empty TAPI context created: {}", tapiContext.getTapiContext());
93 TopologyUtils topologyUtils = new TopologyUtils(this.networkTransactionService, this.dataBroker);
94 ConnectivityUtils connectivityUtils = new ConnectivityUtils(this.serviceDataStoreOperations, new HashMap<>(),
96 TapiInitialORMapping tapiInitialORMapping = new TapiInitialORMapping(topologyUtils, connectivityUtils,
97 tapiContext, this.serviceDataStoreOperations);
98 tapiInitialORMapping.performTopoInitialMapping();
99 tapiInitialORMapping.performServInitialMapping();
101 TapiConnectivityImpl tapi = new TapiConnectivityImpl(this.serviceHandler);
102 TapiTopologyImpl topo = new TapiTopologyImpl(this.dataBroker, tapiContext, topologyUtils);
103 rpcRegistration = rpcProviderService.registerRpcImplementation(TapiConnectivityService.class, tapi);
104 rpcProviderService.registerRpcImplementation(TapiTopologyService.class, topo);
105 dataTreeChangeListenerRegistration =
106 dataBroker.registerDataTreeChangeListener(DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL,
107 InstanceIdentifiers.NETCONF_TOPOLOGY_II.child(Node.class)), topologyListener);
108 mappingListenerListenerRegistration =
109 dataBroker.registerDataTreeChangeListener(DataTreeIdentifier.create(LogicalDatastoreType.CONFIGURATION,
110 MAPPING_II), tapiPortMappingListener);
111 tapiNetworkutilsServiceRpcRegistration =
112 rpcProviderService.registerRpcImplementation(TransportpceTapinetworkutilsService.class,
113 this.tapiNetworkUtils);
115 InstanceIdentifier<ServiceInterfacePoints> sipIID = InstanceIdentifier.create(ServiceInterfacePoints.class);
116 dataBroker.registerDataTreeChangeListener(DataTreeIdentifier.create(
117 LogicalDatastoreType.CONFIGURATION, sipIID), tapiListener);
121 * Method called when the blueprint container is destroyed.
123 public void close() {
124 LOG.info("TapiProvider Session Closed");
125 if (dataTreeChangeListenerRegistration != null) {
126 dataTreeChangeListenerRegistration.close();
128 if (mappingListenerListenerRegistration != null) {
129 mappingListenerListenerRegistration.close();
131 if (tapiNetworkutilsServiceRpcRegistration != null) {
132 tapiNetworkutilsServiceRpcRegistration.close();
134 rpcRegistration.close();