TAPI topology creation for 100GE Transponder
[transportpce.git] / tapi / src / main / java / org / opendaylight / transportpce / tapi / utils / MappingUtils.java
1 /*
2  * Copyright © 2018 Orange, 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.Map.Entry;
13 import java.util.Set;
14
15 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.create.input.ServiceAEnd;
16 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.create.input.ServiceZEnd;
17 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.Uuid;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.tapi.rev180928.EndPointType;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.tapi.rev180928.service._interface.points.ServiceEndPoint;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23 public final class MappingUtils {
24
25     private static final Logger LOG = LoggerFactory.getLogger(MappingUtils.class);
26
27     private static Map<Uuid, GenericServiceEndpoint> map = new HashMap<Uuid, GenericServiceEndpoint>();
28
29     private MappingUtils() {
30     }
31
32     private static GenericServiceEndpoint createMapEntry(ServiceEndPoint sep) {
33         if (sep.getEndPoint().getServiceEndPointType().equals(EndPointType.Aend)) {
34             ServiceAEnd sepG = TapiUtils.buildServiceAEnd(sep.getEndPoint().getNodeId().getValue(), sep.getEndPoint()
35                 .getClli(), sep.getEndPoint().getTxDirection().getPort().getPortDeviceName(), sep.getEndPoint()
36                     .getTxDirection().getPort().getPortName(),
37                 sep.getEndPoint().getRxDirection().getPort().getPortDeviceName(), sep.getEndPoint().getRxDirection()
38                     .getPort().getPortName());
39             return new GenericServiceEndpoint(sepG, ServiceEndpointType.SERVICEAEND);
40         } else {
41             ServiceZEnd sepG = TapiUtils.buildServiceZEnd(sep.getEndPoint().getNodeId().getValue(), sep.getEndPoint()
42                 .getClli(), sep.getEndPoint().getTxDirection().getPort().getPortDeviceName(), sep.getEndPoint()
43                     .getTxDirection().getPort().getPortName(),
44                 sep.getEndPoint().getRxDirection().getPort().getPortDeviceName(), sep.getEndPoint().getRxDirection()
45                     .getPort().getPortName());
46             return new GenericServiceEndpoint(sepG, ServiceEndpointType.SERVICEZEND);
47         }
48     }
49
50     public static void addMapSEP(ServiceEndPoint sep) {
51         Uuid uuid = sep.getUuid();
52         if (!map.containsKey(uuid)) {
53             LOG.info("adding new entry {} into static map", uuid);
54             map.put(uuid, MappingUtils.createMapEntry(sep));
55         } else {
56             LOG.error("service-end-point entry already exist. Please DELETE it before PUT it...");
57         }
58     }
59
60     public static void deleteMapEntry(Uuid uuid) {
61         if (map.containsKey(uuid)) {
62             LOG.info("map size = {}", Integer.toString(map.size()));
63             map.remove(uuid);
64             LOG.info("map size = {}", Integer.toString(map.size()));
65         } else {
66             LOG.info("No existing entry with uuid {}", uuid);
67         }
68     }
69
70     public static void afficheMap() {
71         if (!map.isEmpty()) {
72             Set<Entry<Uuid, GenericServiceEndpoint>> entries = map.entrySet();
73             LOG.info("Displaying the static map...");
74             for (Entry<Uuid, GenericServiceEndpoint> entry : entries) {
75                 LOG.info("uuid = {} \t service end point = {}", entry.getKey().toString(), entry.getValue().getValue()
76                     .toString());
77             }
78         } else {
79             LOG.info("Static map is empty - Nothing to display");
80         }
81
82     }
83
84     public static void deleteMap() {
85         if (!map.isEmpty()) {
86             map.clear();
87         } else {
88             LOG.info("Static map is already empty - Nothing to delete");
89         }
90     }
91
92     public static Map<Uuid, GenericServiceEndpoint> getMap() {
93         return map;
94     }
95
96 }