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.yang.gen.v1.http.org.openroadm.service.rev190531.service.create.input.ServiceAEnd;
15 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.create.input.ServiceZEnd;
16 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.Uuid;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.tapi.rev180928.EndPointType;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.tapi.rev180928.service._interface.points.ServiceEndPoint;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
22 public final class MappingUtils {
24 private static final Logger LOG = LoggerFactory.getLogger(MappingUtils.class);
26 private static Map<Uuid, GenericServiceEndpoint> map = new HashMap<Uuid, GenericServiceEndpoint>();
28 private MappingUtils() {
31 private static GenericServiceEndpoint createMapEntry(ServiceEndPoint sep) {
32 if (sep.getEndPoint().getServiceEndPointType().equals(EndPointType.Aend)) {
33 ServiceAEnd sepG = TapiUtils.buildServiceAEnd(sep.getEndPoint().getNodeId().getValue(), sep.getEndPoint()
34 .getClli(), sep.getEndPoint().getTxDirection().getPort().getPortDeviceName(), sep.getEndPoint()
35 .getTxDirection().getPort().getPortName(),
36 sep.getEndPoint().getRxDirection().getPort().getPortDeviceName(), sep.getEndPoint().getRxDirection()
37 .getPort().getPortName());
38 return new GenericServiceEndpoint(sepG, ServiceEndpointType.SERVICEAEND);
40 ServiceZEnd sepG = TapiUtils.buildServiceZEnd(sep.getEndPoint().getNodeId().getValue(), sep.getEndPoint()
41 .getClli(), sep.getEndPoint().getTxDirection().getPort().getPortDeviceName(), sep.getEndPoint()
42 .getTxDirection().getPort().getPortName(),
43 sep.getEndPoint().getRxDirection().getPort().getPortDeviceName(), sep.getEndPoint().getRxDirection()
44 .getPort().getPortName());
45 return new GenericServiceEndpoint(sepG, ServiceEndpointType.SERVICEZEND);
49 public static void addMapSEP(ServiceEndPoint sep) {
50 Uuid uuid = sep.getUuid();
51 if (!map.containsKey(uuid)) {
52 LOG.info("adding new entry {} into static map", uuid);
53 map.put(uuid, MappingUtils.createMapEntry(sep));
55 LOG.error("service-end-point entry already exist. Please DELETE it before PUT it...");
59 public static void deleteMapEntry(Uuid uuid) {
60 if (map.containsKey(uuid)) {
61 LOG.info("map size = {}", Integer.toString(map.size()));
63 LOG.info("map size = {}", Integer.toString(map.size()));
65 LOG.info("No existing entry with uuid {}", uuid);
69 public static void afficheMap() {
71 Set<Entry<Uuid, GenericServiceEndpoint>> entries = map.entrySet();
72 LOG.info("Displaying the static map...");
73 for (Entry<Uuid, GenericServiceEndpoint> entry : entries) {
74 LOG.info("uuid = {} \t service end point = {}", entry.getKey().toString(), entry.getValue().getValue()
78 LOG.info("Static map is empty - Nothing to display");
83 public static void deleteMap() {
87 LOG.info("Static map is already empty - Nothing to delete");
91 public static Map<Uuid, GenericServiceEndpoint> getMap() {