Merge changes I74e9bee3,Ia1ad6f9c,Ic47363f6,I2bba2b18,I507097db, ...
[transportpce.git] / common / src / main / java / org / opendaylight / transportpce / common / service / ServiceTypes.java
1 /*
2  * Copyright © 2021 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
9 package org.opendaylight.transportpce.common.service;
10
11 import java.util.Map;
12 import org.opendaylight.transportpce.common.StringConstants;
13 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.mapping.Mapping;
14 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.types.rev191129.PortQual;
15 import org.opendaylight.yangtools.yang.common.Uint32;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18
19 public final class ServiceTypes {
20     private static final Logger LOG = LoggerFactory.getLogger(ServiceTypes.class);
21
22     private ServiceTypes() {
23     }
24
25     public static String getServiceType(String serviceFormat, Uint32 serviceRate, Mapping mapping) {
26
27         switch (serviceFormat) {
28             case "OC":
29                 if (Uint32.valueOf(100).equals(serviceRate)) {
30                     return StringConstants.SERVICE_TYPE_100GE_T;
31                 }
32                 LOG.warn("Invalid service-rate {}", serviceRate);
33                 return null;
34
35             case "Ethernet":
36                 if (Uint32.valueOf(400).equals(serviceRate)) {
37                     return StringConstants.SERVICE_TYPE_400GE;
38                 }
39                 if (Uint32.valueOf(100).equals(serviceRate)
40                         && (mapping == null || !PortQual.SwitchClient.getName().equals(mapping.getPortQual()))) {
41                     return StringConstants.SERVICE_TYPE_100GE_T;
42                 }
43                 return getOtnServiceType(serviceFormat, serviceRate);
44
45             //case "ODU":
46             //case "OTU":
47             default:
48                 return getOtnServiceType(serviceFormat, serviceRate);
49         }
50     }
51
52     public static String getOtnServiceType(String serviceFormat, Uint32 serviceRate) {
53         Map<String, Map<Uint32, String>> otnMap = Map.of(
54             "Ethernet", Map.of(
55                     Uint32.valueOf(1), StringConstants.SERVICE_TYPE_1GE,
56                     Uint32.valueOf(10), StringConstants.SERVICE_TYPE_10GE,
57                     Uint32.valueOf(100), StringConstants.SERVICE_TYPE_100GE_M),
58             "OTU", Map.of(
59                     Uint32.valueOf(100), StringConstants.SERVICE_TYPE_OTU4,
60                     Uint32.valueOf(400), StringConstants.SERVICE_TYPE_OTUC4),
61             "ODU", Map.of(
62                     Uint32.valueOf(100), StringConstants.SERVICE_TYPE_ODU4,
63                     Uint32.valueOf(400), StringConstants.SERVICE_TYPE_ODUC4));
64
65         if (!otnMap.containsKey(serviceFormat)) {
66             LOG.warn("Invalid service-format {}", serviceFormat);
67             return null;
68         }
69
70         if (!otnMap.get(serviceFormat).containsKey(serviceRate)) {
71             LOG.warn("Invalid service-rate {}", serviceRate);
72             return null;
73         }
74
75         return otnMap.get(serviceFormat).get(serviceRate);
76
77     }
78 }