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.utils;
10 import java.util.HashMap;
12 import java.util.Map.Entry;
14 import org.opendaylight.transportpce.tapi.connectivity.ConnectivityUtils;
15 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.service.create.input.ServiceAEnd;
16 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.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;
23 public final class MappingUtils {
25 private static final Logger LOG = LoggerFactory.getLogger(MappingUtils.class);
27 private static Map<Uuid, GenericServiceEndpoint> map = new HashMap<>();
29 private MappingUtils() {
32 private static GenericServiceEndpoint createMapEntry(ServiceEndPoint sep) {
33 if (sep.getEndPoint().getServiceEndPointType().equals(EndPointType.Aend)) {
34 ServiceAEnd sepG = ConnectivityUtils.buildServiceAEnd(sep.getEndPoint().getNodeId().getValue(),
35 sep.getEndPoint().getClli(),
36 sep.getEndPoint().getTxDirection().values().stream().findFirst().get().getPort()
38 sep.getEndPoint().getTxDirection().values().stream().findFirst().get().getPort().getPortName(),
39 sep.getEndPoint().getRxDirection().values().stream().findFirst().get().getPort()
41 sep.getEndPoint().getRxDirection().values().stream().findFirst().get().getPort().getPortName());
42 return new GenericServiceEndpoint(sepG, ServiceEndpointType.SERVICEAEND);
44 ServiceZEnd sepG = ConnectivityUtils.buildServiceZEnd(sep.getEndPoint().getNodeId().getValue(),
45 sep.getEndPoint().getClli(),
46 sep.getEndPoint().getTxDirection().values().stream().findFirst().get().getPort()
48 sep.getEndPoint().getTxDirection().values().stream().findFirst().get().getPort().getPortName(),
49 sep.getEndPoint().getRxDirection().values().stream().findFirst().get().getPort()
51 sep.getEndPoint().getRxDirection().values().stream().findFirst().get().getPort().getPortName());
52 return new GenericServiceEndpoint(sepG, ServiceEndpointType.SERVICEZEND);
56 public static void addMapSEP(ServiceEndPoint sep) {
57 Uuid uuid = sep.getUuid();
58 if (!map.containsKey(uuid)) {
59 LOG.info("adding new entry {} into static map", uuid);
60 map.put(uuid, MappingUtils.createMapEntry(sep));
62 LOG.error("service-end-point entry already exist. Please DELETE it before PUT it...");
66 public static void deleteMapEntry(Uuid uuid) {
67 if (map.containsKey(uuid)) {
68 LOG.info("map size = {}", Integer.toString(map.size()));
70 LOG.info("map size = {}", Integer.toString(map.size()));
72 LOG.info("No existing entry with uuid {}", uuid);
76 public static void afficheMap() {
78 Set<Entry<Uuid, GenericServiceEndpoint>> entries = map.entrySet();
79 LOG.info("Displaying the static map...");
80 for (Entry<Uuid, GenericServiceEndpoint> entry : entries) {
81 LOG.info("uuid = {} \t service end point = {}", entry.getKey(), entry.getValue().getValue());
84 LOG.info("Static map is empty - Nothing to display");
89 public static void deleteMap() {
93 LOG.info("Static map is already empty - Nothing to delete");
97 public static Map<Uuid, GenericServiceEndpoint> getMap() {