5465d6cc34f040b941fc0d8b00340e3dca3ff453
[transportpce.git] / tapi / src / main / java / org / opendaylight / transportpce / tapi / utils / TapiInitialORMapping.java
1 /*
2  * Copyright © 2021 Nokia, Inc. 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.tapi.utils;
9
10 import java.util.HashMap;
11 import java.util.Map;
12 import java.util.Optional;
13 import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperations;
14 import org.opendaylight.transportpce.tapi.connectivity.ConnectivityUtils;
15 import org.opendaylight.transportpce.tapi.topology.TapiTopologyException;
16 import org.opendaylight.transportpce.tapi.topology.TopologyUtils;
17 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.Service;
18 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceList;
19 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.tapi.context.ServiceInterfacePoint;
20 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.tapi.context.ServiceInterfacePointKey;
21 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.connectivity.context.ConnectivityService;
22 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.connectivity.context.ConnectivityServiceKey;
23 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.context.Topology;
24 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.context.TopologyKey;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27
28 public class TapiInitialORMapping {
29
30     private static final Logger LOG = LoggerFactory.getLogger(TapiInitialORMapping.class);
31     private final TapiContext tapiContext;
32     private final TopologyUtils topologyUtils;
33     private final ConnectivityUtils connectivityUtils;
34     private final ServiceDataStoreOperations serviceDataStoreOperations;
35
36     public TapiInitialORMapping(TopologyUtils topologyUtils, ConnectivityUtils connectivityUtils,
37                                 TapiContext tapiContext, ServiceDataStoreOperations serviceDataStoreOperations) {
38         this.topologyUtils = topologyUtils;
39         this.tapiContext = tapiContext;
40         this.connectivityUtils = connectivityUtils;
41         this.serviceDataStoreOperations = serviceDataStoreOperations;
42     }
43
44     public void performTopoInitialMapping() {
45         // creation of both topologies but with the fully roadm infrastructure.
46         try {
47             LOG.info("Performing initial mapping between OR and TAPI models.");
48             Topology t0FullMultiLayer = this.topologyUtils.createFullOtnTopology();
49             Map<TopologyKey, Topology> topologyMap = new HashMap<>();
50             topologyMap.put(t0FullMultiLayer.key(), t0FullMultiLayer);
51             this.tapiContext.updateTopologyContext(topologyMap);
52             Map<ServiceInterfacePointKey, ServiceInterfacePoint> sipMap = this.topologyUtils.getSipMap();
53             this.tapiContext.updateSIPContext(sipMap);
54             this.connectivityUtils.setSipMap(sipMap);
55         } catch (TapiTopologyException e) {
56             LOG.error("error building TAPI topology", e);
57         }
58     }
59
60     public void performServInitialMapping() {
61         Optional<ServiceList> optOrServices = this.serviceDataStoreOperations.getServices();
62         if (!optOrServices.isPresent()) {
63             LOG.error("Couldnt obtain OR services from datastore");
64             return;
65         }
66         ServiceList orServices = optOrServices.get();
67         if (orServices.getServices() == null) {
68             LOG.info("No services in datastore. No mapping needed");
69             return;
70         }
71         Map<ConnectivityServiceKey, ConnectivityService> connServMap = new HashMap<>();
72         for (Service service:orServices.getServices().values()) {
73             // map services
74             // connections needed to be created --> looking at path description
75             ConnectivityService connServ = this.connectivityUtils.mapORServiceToTapiConnectivity(service);
76             connServMap.put(connServ.key(), connServ);
77         }
78         // Put in datastore connectivity services and connections
79         this.tapiContext.updateConnectivityContext(connServMap, this.connectivityUtils.getConnectionFullMap());
80     }
81 }