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;
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;
23 public final class MappingUtils {
25 private static final Logger LOG = LoggerFactory.getLogger(MappingUtils.class);
27 private static Map<Uuid, GenericServiceEndpoint> map = new HashMap<Uuid, GenericServiceEndpoint>();
29 private MappingUtils() {
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);
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);
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));
56 LOG.error("service-end-point entry already exist. Please DELETE it before PUT it...");
60 public static void deleteMapEntry(Uuid uuid) {
61 if (map.containsKey(uuid)) {
62 LOG.info("map size = {}", Integer.toString(map.size()));
64 LOG.info("map size = {}", Integer.toString(map.size()));
66 LOG.info("No existing entry with uuid {}", uuid);
70 public static void afficheMap() {
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()
79 LOG.info("Static map is empty - Nothing to display");
84 public static void deleteMap() {
88 LOG.info("Static map is already empty - Nothing to delete");
92 public static Map<Uuid, GenericServiceEndpoint> getMap() {