Update portmapping YANG model
[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.ServiceHandlerListener;
19 import org.opendaylight.transportpce.networkmodel.service.FrequenciesService;
20 import org.opendaylight.transportpce.networkmodel.util.TpceNetwork;
21 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.networkutils.rev170818.TransportpceNetworkutilsService;
22 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210315.Network;
23 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210315.mapping.Mapping;
24 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev201125.TransportpceServicehandlerListener;
25 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
26 import org.opendaylight.yangtools.concepts.ListenerRegistration;
27 import org.opendaylight.yangtools.concepts.ObjectRegistration;
28 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31
32 public class NetworkModelProvider {
33
34     private static final Logger LOG = LoggerFactory.getLogger(NetworkModelProvider.class);
35     private static final InstanceIdentifier<Mapping> MAPPING_II = InstanceIdentifier.create(Network.class)
36         .child(org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210315.network
37                 .Nodes.class)
38         .child(Mapping.class);
39
40     private final DataBroker dataBroker;
41     private final RpcProviderService rpcProviderService;
42     private final TransportpceNetworkutilsService networkutilsService;
43     private final NetConfTopologyListener topologyListener;
44     private ListenerRegistration<NetConfTopologyListener> dataTreeChangeListenerRegistration;
45     private ObjectRegistration<TransportpceNetworkutilsService> networkutilsServiceRpcRegistration;
46     private TpceNetwork tpceNetwork;
47     private ListenerRegistration<TransportpceServicehandlerListener> serviceHandlerListenerRegistration;
48     private NotificationService notificationService;
49     private FrequenciesService frequenciesService;
50
51     public NetworkModelProvider(NetworkTransactionService networkTransactionService, final DataBroker dataBroker,
52         final RpcProviderService rpcProviderService, final TransportpceNetworkutilsService networkutilsService,
53         final NetConfTopologyListener topologyListener, NotificationService notificationService,
54         FrequenciesService frequenciesService) {
55         this.dataBroker = dataBroker;
56         this.rpcProviderService = rpcProviderService;
57         this.networkutilsService = networkutilsService;
58         this.topologyListener = topologyListener;
59         this.tpceNetwork = new TpceNetwork(networkTransactionService);
60         this.notificationService = notificationService;
61         this.frequenciesService = frequenciesService;
62     }
63
64     /**
65      * Method called when the blueprint container is created.
66      */
67     public void init() {
68         LOG.info("NetworkModelProvider Session Initiated");
69         tpceNetwork.createLayer(NetworkUtils.CLLI_NETWORK_ID);
70         tpceNetwork.createLayer(NetworkUtils.UNDERLAY_NETWORK_ID);
71         tpceNetwork.createLayer(NetworkUtils.OVERLAY_NETWORK_ID);
72         tpceNetwork.createLayer(NetworkUtils.OTN_NETWORK_ID);
73         dataTreeChangeListenerRegistration =
74             dataBroker.registerDataTreeChangeListener(DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL,
75                 InstanceIdentifiers.NETCONF_TOPOLOGY_II.child(Node.class)), topologyListener);
76         networkutilsServiceRpcRegistration =
77             rpcProviderService.registerRpcImplementation(TransportpceNetworkutilsService.class, networkutilsService);
78         TransportpceServicehandlerListener serviceHandlerListner =
79                 new ServiceHandlerListener(frequenciesService);
80         serviceHandlerListenerRegistration = notificationService.registerNotificationListener(serviceHandlerListner);
81     }
82
83         /**
84          * Method called when the blueprint container is destroyed.
85          */
86     public void close() {
87         LOG.info("NetworkModelProvider Closed");
88         if (dataTreeChangeListenerRegistration != null) {
89             dataTreeChangeListenerRegistration.close();
90         }
91         if (networkutilsServiceRpcRegistration != null) {
92             networkutilsServiceRpcRegistration.close();
93         }
94         serviceHandlerListenerRegistration.close();
95     }
96 }