Refactor SupportedIfCapability usage
[transportpce.git] / networkmodel / src / main / java / org / opendaylight / transportpce / networkmodel / NetworkModelProvider.java
1 /*
2  * Copyright © 2016 Orange and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.transportpce.networkmodel;
9
10 import org.opendaylight.mdsal.binding.api.DataBroker;
11 import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
12 import org.opendaylight.mdsal.binding.api.NotificationService;
13 import org.opendaylight.mdsal.binding.api.RpcProviderService;
14 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
15 import org.opendaylight.transportpce.common.InstanceIdentifiers;
16 import org.opendaylight.transportpce.common.NetworkUtils;
17 import org.opendaylight.transportpce.common.network.NetworkTransactionService;
18 import org.opendaylight.transportpce.networkmodel.listeners.PortMappingListener;
19 import org.opendaylight.transportpce.networkmodel.listeners.ServiceHandlerListener;
20 import org.opendaylight.transportpce.networkmodel.service.FrequenciesService;
21 import org.opendaylight.transportpce.networkmodel.util.TpceNetwork;
22 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.networkutils.rev170818.TransportpceNetworkutilsService;
23 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.Network;
24 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.mapping.Mapping;
25 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev201125.TransportpceServicehandlerListener;
26 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
27 import org.opendaylight.yangtools.concepts.ListenerRegistration;
28 import org.opendaylight.yangtools.concepts.ObjectRegistration;
29 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32
33 public class NetworkModelProvider {
34
35     private static final Logger LOG = LoggerFactory.getLogger(NetworkModelProvider.class);
36     private static final InstanceIdentifier<Mapping> MAPPING_II = InstanceIdentifier.create(Network.class)
37         .child(org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.network
38                 .Nodes.class)
39         .child(Mapping.class);
40
41     private final DataBroker dataBroker;
42     private final RpcProviderService rpcProviderService;
43     private final TransportpceNetworkutilsService networkutilsService;
44     private final NetConfTopologyListener topologyListener;
45     private ListenerRegistration<NetConfTopologyListener> dataTreeChangeListenerRegistration;
46     private ListenerRegistration<PortMappingListener> mappingListenerRegistration;
47     private ObjectRegistration<TransportpceNetworkutilsService> networkutilsServiceRpcRegistration;
48     private TpceNetwork tpceNetwork;
49     private ListenerRegistration<TransportpceServicehandlerListener> serviceHandlerListenerRegistration;
50     private NotificationService notificationService;
51     private FrequenciesService frequenciesService;
52     private PortMappingListener portMappingListener;
53
54     public NetworkModelProvider(NetworkTransactionService networkTransactionService, final DataBroker dataBroker,
55         final RpcProviderService rpcProviderService, final TransportpceNetworkutilsService networkutilsService,
56         final NetConfTopologyListener topologyListener, NotificationService notificationService,
57         FrequenciesService frequenciesService, PortMappingListener portMappingListener) {
58         this.dataBroker = dataBroker;
59         this.rpcProviderService = rpcProviderService;
60         this.networkutilsService = networkutilsService;
61         this.topologyListener = topologyListener;
62         this.tpceNetwork = new TpceNetwork(networkTransactionService);
63         this.notificationService = notificationService;
64         this.frequenciesService = frequenciesService;
65         this.portMappingListener = portMappingListener;
66     }
67
68     /**
69      * Method called when the blueprint container is created.
70      */
71     public void init() {
72         LOG.info("NetworkModelProvider Session Initiated");
73         tpceNetwork.createLayer(NetworkUtils.CLLI_NETWORK_ID);
74         tpceNetwork.createLayer(NetworkUtils.UNDERLAY_NETWORK_ID);
75         tpceNetwork.createLayer(NetworkUtils.OVERLAY_NETWORK_ID);
76         tpceNetwork.createLayer(NetworkUtils.OTN_NETWORK_ID);
77         dataTreeChangeListenerRegistration = dataBroker.registerDataTreeChangeListener(
78                 DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL,
79                 InstanceIdentifiers.NETCONF_TOPOLOGY_II.child(Node.class)), topologyListener);
80         mappingListenerRegistration = dataBroker.registerDataTreeChangeListener(
81                 DataTreeIdentifier.create(LogicalDatastoreType.CONFIGURATION, MAPPING_II), portMappingListener);
82         networkutilsServiceRpcRegistration =
83             rpcProviderService.registerRpcImplementation(TransportpceNetworkutilsService.class, networkutilsService);
84         TransportpceServicehandlerListener serviceHandlerListner =
85                 new ServiceHandlerListener(frequenciesService);
86         serviceHandlerListenerRegistration = notificationService.registerNotificationListener(serviceHandlerListner);
87     }
88
89         /**
90          * Method called when the blueprint container is destroyed.
91          */
92     public void close() {
93         LOG.info("NetworkModelProvider Closed");
94         if (dataTreeChangeListenerRegistration != null) {
95             dataTreeChangeListenerRegistration.close();
96         }
97         if (mappingListenerRegistration != null) {
98             mappingListenerRegistration.close();
99         }
100         if (networkutilsServiceRpcRegistration != null) {
101             networkutilsServiceRpcRegistration.close();
102         }
103         serviceHandlerListenerRegistration.close();
104     }
105 }