blob: f5b4eda6760d5a1b463995802891e26f8c3f2958 [file] [log] [blame]
Andrea Campanellaa9cdaf62019-09-08 10:30:16 -07001/*
Sudeep Desaibffe1532020-01-21 16:43:46 +05302 * Copyright 2020-present Open Networking Foundation
Andrea Campanellaa9cdaf62019-09-08 10:30:16 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * This work was partially supported by EC H2020 project METRO-HAUL (761727).
17 */
18package org.onosproject.drivers.odtn;
19
20import org.apache.commons.configuration.HierarchicalConfiguration;
21import org.apache.commons.configuration.XMLConfiguration;
Andrea Campanellaa9cdaf62019-09-08 10:30:16 -070022import org.onosproject.net.ModulationScheme;
23import org.onosproject.net.PortNumber;
Andrea Campanellaa9cdaf62019-09-08 10:30:16 -070024import org.onosproject.netconf.DatastoreId;
Andrea Campanellaa9cdaf62019-09-08 10:30:16 -070025import org.slf4j.Logger;
26import org.slf4j.LoggerFactory;
27
28import java.util.Optional;
Andrea Campanellaa9cdaf62019-09-08 10:30:16 -070029import java.util.regex.Matcher;
30import java.util.regex.Pattern;
31
Andrea Campanellaa9cdaf62019-09-08 10:30:16 -070032/*
33 * Driver Implementation of the ModulationConfig for OcNos standard open config based terminal devices.
34 */
Sudeep Desaibffe1532020-01-21 16:43:46 +053035public class GrooveModulationOpenConfig<T> extends TerminalDeviceModulationConfig<T> {
Andrea Campanellaa9cdaf62019-09-08 10:30:16 -070036
Sudeep Desaibffe1532020-01-21 16:43:46 +053037 public static Logger log = LoggerFactory.getLogger(GrooveModulationOpenConfig.class);
Andrea Campanellaa9cdaf62019-09-08 10:30:16 -070038
39 /**
Sudeep Desaibffe1532020-01-21 16:43:46 +053040 * Construct a rpc target power message.
Andrea Campanellaa9cdaf62019-09-08 10:30:16 -070041 *
Sudeep Desaibffe1532020-01-21 16:43:46 +053042 * @return RPC payload
Andrea Campanellaa9cdaf62019-09-08 10:30:16 -070043 */
Sudeep Desaibffe1532020-01-21 16:43:46 +053044 @Override
45 public DatastoreId getDataStoreId() {
46 return DatastoreId.RUNNING;
47 }
48 /**
49 * Construct a rpc target power message.
50 *
51 * @param name for optical channel name
52 * @return RPC payload
53 */
54 @Override
55 public StringBuilder createModulationFilterRequestRpc(String name) {
56 StringBuilder rpc = new StringBuilder();
57 rpc.append("<name>").append(name).append("</name>");
58 return rpc;
59 }
Andrea Campanellaa9cdaf62019-09-08 10:30:16 -070060
Sudeep Desaibffe1532020-01-21 16:43:46 +053061 @Override
62 public ModulationScheme modulationSchemeType(String operationalMode) {
63 /*Used for Internal Testing */
64 //String modulationScheme="DP16QAM";
65 ModulationScheme modulation;
66 if (operationalMode.equalsIgnoreCase("62") ||
67 operationalMode.equalsIgnoreCase("68")) {
68 modulation = ModulationScheme.DP_16QAM;
69 } else {
70 modulation = ModulationScheme.DP_QPSK;
71 }
72 return modulation;
73 }
Andrea Campanellaa9cdaf62019-09-08 10:30:16 -070074
Sudeep Desaibffe1532020-01-21 16:43:46 +053075 @Override
76 public String modulationEditConfigRequestRpc(TerminalDeviceModulationConfig modulationConfig, PortNumber portNumber,
77 Object component, long bitRate, String modulation) {
78 if (component != null) {
79 // This is an edit-config operation.
80 String portMode = modulation.equals("DP_QPSK") ? "QPSK_100G" : "16QAM_200G";
81 String portName = state.ocName(modulationConfig, portNumber);
82 Pattern portPattern = Pattern.compile(".*-[1]-[1-9][0-4]?-L[1-2]$"); // e.g. TRANSCEIVER-1-1-L1
83 Matcher lineMatch = portPattern.matcher(portName);
84 lineMatch.find();
85 final String[] split = lineMatch.group(0).split("-");
86
87 return "<ne xmlns=\"http://coriant.com/yang/os/ne\">" +
88 " <shelf>" +
89 " <shelf-id>" + split[1] + "</shelf-id>" +
90 " <slot>" +
91 " <slot-id>" + split[2] + "</slot-id>" +
92 " <card>" +
93 " <port>" +
94 " <port-id>" + split[3].replace("L", "") + "</port-id>" +
95 " <port-mode>" + portMode + "</port-mode>" +
96 " </port>" +
97 " </card>" +
98 " </slot>" +
99 " </shelf>" +
100 " </ne>";
101 } else {
102 log.error("Cannot process the component {}.", component.getClass());
Andrea Campanellaa9cdaf62019-09-08 10:30:16 -0700103 return null;
104 }
Andrea Campanellaa9cdaf62019-09-08 10:30:16 -0700105 }
106
Andrea Campanellaa9cdaf62019-09-08 10:30:16 -0700107 @Override
Sudeep Desaibffe1532020-01-21 16:43:46 +0530108 public void setModulationSchemeProcessor(PortNumber port, Object component, long bitRate) {
109 ModulationScheme modulation = null;
110 if (bitRate <= BitRate.GBPS_100.value) {
111 modulation = ModulationScheme.DP_QPSK;
112 } else {
113 modulation = ModulationScheme.DP_16QAM;
114
115 }
116 // TODO: Groove doesn't support to change the modulation format via OpenConfig directly
117 // without recommissioning the Optical Channel
118 // Workaround: use Groove native model via port-mode change
119 // String editConfig = modulationEditConfig(groove, port, component, bitRate, modulation.name());
120 String editConfig = state.modulationEditConfig(state.terminalDevice, port, component,
121 bitRate, modulation.name());
122
123 //setting the modulation by calling rpc
124 state.setModulationRpc(port, component, editConfig);
Andrea Campanellaa9cdaf62019-09-08 10:30:16 -0700125 }
126
127 /**
Sudeep Desaibffe1532020-01-21 16:43:46 +0530128 * Get the Modulation Scheme on the component.
Andrea Campanellaa9cdaf62019-09-08 10:30:16 -0700129 *
Sudeep Desaibffe1532020-01-21 16:43:46 +0530130 * @param conf HierarchicalConfiguration for path ../optical-channel/config
131 * @return Optional<ModulationScheme>
Andrea Campanellaa9cdaf62019-09-08 10:30:16 -0700132 **/
Sudeep Desaibffe1532020-01-21 16:43:46 +0530133 public Optional<ModulationScheme> getModulation(XMLConfiguration conf) {
134 HierarchicalConfiguration config =
135 conf.configurationAt("data/components/component/optical-channel/config");
Andrea Campanellaa9cdaf62019-09-08 10:30:16 -0700136
Sudeep Desaibffe1532020-01-21 16:43:46 +0530137 String operationalMode = String.valueOf(config.getString("operational-mode"));
138 /*Used for Internal Testing */
139 //String modulationScheme="DP16QAM";
140 ModulationScheme modulation;
141 if (operationalMode.equalsIgnoreCase("62") ||
142 operationalMode.equalsIgnoreCase("68")) {
143 modulation = ModulationScheme.DP_16QAM;
144 } else {
145 modulation = ModulationScheme.DP_QPSK;
Andrea Campanellaa9cdaf62019-09-08 10:30:16 -0700146 }
Sudeep Desaibffe1532020-01-21 16:43:46 +0530147 return Optional.of(modulation);
Andrea Campanellaa9cdaf62019-09-08 10:30:16 -0700148 }
149}
Sudeep Desaibffe1532020-01-21 16:43:46 +0530150