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.openroadm.service.rev190531.OrgOpenroadmServiceService;
31 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.TapiConnectivityService;
32 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.TapiTopologyService;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.tapi.rev180928.ServiceInterfacePoints;
34 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
35 import org.opendaylight.yangtools.concepts.ListenerRegistration;
36 import org.opendaylight.yangtools.concepts.ObjectRegistration;
37 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
42 * Class to register TAPI interface Service and Notification.
44 * @author Gilles Thouenon (gilles.thouenon@orange.com) on behalf of Orange
47 public class TapiProvider {
49 private static final Logger LOG = LoggerFactory.getLogger(TapiProvider.class);
51 private static final InstanceIdentifier<Nodes> MAPPING_II = InstanceIdentifier.create(Network.class)
52 .child(org.opendaylight.yang.gen.v1.http
53 .org.opendaylight.transportpce.portmapping.rev210315.network.Nodes.class);
54 private final DataBroker dataBroker;
55 private final RpcProviderService rpcProviderService;
56 private ObjectRegistration<TapiConnectivityService> rpcRegistration;
57 private ListenerRegistration<TapiNetconfTopologyListener> dataTreeChangeListenerRegistration;
58 private ListenerRegistration<TapiPortMappingListener> mappingListenerListenerRegistration;
59 private final OrgOpenroadmServiceService serviceHandler;
60 private final ServiceDataStoreOperations serviceDataStoreOperations;
61 private final TapiListener tapiListener;
62 private final TapiNetconfTopologyListener topologyListener;
63 private TapiPortMappingListener tapiPortMappingListener;
64 private final NetworkTransactionService networkTransactionService;
66 public TapiProvider(DataBroker dataBroker, RpcProviderService rpcProviderService,
67 OrgOpenroadmServiceService serviceHandler, ServiceDataStoreOperations serviceDataStoreOperations,
68 TapiListener tapiListener, NetworkTransactionService networkTransactionService,
69 TapiNetconfTopologyListener topologyListener, TapiPortMappingListener tapiPortMappingListener) {
70 this.dataBroker = dataBroker;
71 this.rpcProviderService = rpcProviderService;
72 this.serviceHandler = serviceHandler;
73 this.serviceDataStoreOperations = serviceDataStoreOperations;
74 this.tapiListener = tapiListener;
75 this.networkTransactionService = networkTransactionService;
76 this.topologyListener = topologyListener;
77 this.tapiPortMappingListener = tapiPortMappingListener;
81 * Method called when the blueprint container is created.
84 LOG.info("TapiProvider Session Initiated");
85 TapiContext tapiContext = new TapiContext(this.networkTransactionService);
86 LOG.info("Empty TAPI context created: {}", tapiContext.getTapiContext());
88 TopologyUtils topologyUtils = new TopologyUtils(this.networkTransactionService, this.dataBroker);
89 ConnectivityUtils connectivityUtils = new ConnectivityUtils(this.serviceDataStoreOperations, new HashMap<>(),
91 TapiInitialORMapping tapiInitialORMapping = new TapiInitialORMapping(topologyUtils, connectivityUtils,
92 tapiContext, this.serviceDataStoreOperations);
93 tapiInitialORMapping.performTopoInitialMapping();
94 tapiInitialORMapping.performServInitialMapping();
96 TapiConnectivityImpl tapi = new TapiConnectivityImpl(this.serviceHandler);
97 TapiTopologyImpl topo = new TapiTopologyImpl(this.dataBroker, tapiContext, topologyUtils);
98 rpcRegistration = rpcProviderService.registerRpcImplementation(TapiConnectivityService.class, tapi);
99 rpcProviderService.registerRpcImplementation(TapiTopologyService.class, topo);
100 dataTreeChangeListenerRegistration =
101 dataBroker.registerDataTreeChangeListener(DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL,
102 InstanceIdentifiers.NETCONF_TOPOLOGY_II.child(Node.class)), topologyListener);
103 mappingListenerListenerRegistration =
104 dataBroker.registerDataTreeChangeListener(DataTreeIdentifier.create(LogicalDatastoreType.CONFIGURATION,
105 MAPPING_II), tapiPortMappingListener);
107 InstanceIdentifier<ServiceInterfacePoints> sipIID = InstanceIdentifier.create(ServiceInterfacePoints.class);
108 dataBroker.registerDataTreeChangeListener(DataTreeIdentifier.create(
109 LogicalDatastoreType.CONFIGURATION, sipIID), tapiListener);
113 * Method called when the blueprint container is destroyed.
115 public void close() {
116 LOG.info("TapiProvider Session Closed");
117 if (dataTreeChangeListenerRegistration != null) {
118 dataTreeChangeListenerRegistration.close();
120 if (mappingListenerListenerRegistration != null) {
121 mappingListenerListenerRegistration.close();
123 rpcRegistration.close();