Andrea Campanella | a9cdaf6 | 2019-09-08 10:30:16 -0700 | [diff] [blame] | 1 | /* |
Sudeep Desai | bffe153 | 2020-01-21 16:43:46 +0530 | [diff] [blame] | 2 | * Copyright 2020-present Open Networking Foundation |
Andrea Campanella | a9cdaf6 | 2019-09-08 10:30:16 -0700 | [diff] [blame] | 3 | * |
| 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 | */ |
| 18 | package org.onosproject.drivers.odtn; |
| 19 | |
| 20 | import org.apache.commons.configuration.HierarchicalConfiguration; |
| 21 | import org.apache.commons.configuration.XMLConfiguration; |
Andrea Campanella | a9cdaf6 | 2019-09-08 10:30:16 -0700 | [diff] [blame] | 22 | import org.onosproject.net.ModulationScheme; |
| 23 | import org.onosproject.net.PortNumber; |
Andrea Campanella | a9cdaf6 | 2019-09-08 10:30:16 -0700 | [diff] [blame] | 24 | import org.onosproject.netconf.DatastoreId; |
Andrea Campanella | a9cdaf6 | 2019-09-08 10:30:16 -0700 | [diff] [blame] | 25 | import org.slf4j.Logger; |
| 26 | import org.slf4j.LoggerFactory; |
| 27 | |
| 28 | import java.util.Optional; |
Andrea Campanella | a9cdaf6 | 2019-09-08 10:30:16 -0700 | [diff] [blame] | 29 | import java.util.regex.Matcher; |
| 30 | import java.util.regex.Pattern; |
| 31 | |
Andrea Campanella | a9cdaf6 | 2019-09-08 10:30:16 -0700 | [diff] [blame] | 32 | /* |
| 33 | * Driver Implementation of the ModulationConfig for OcNos standard open config based terminal devices. |
| 34 | */ |
Sudeep Desai | bffe153 | 2020-01-21 16:43:46 +0530 | [diff] [blame] | 35 | public class GrooveModulationOpenConfig<T> extends TerminalDeviceModulationConfig<T> { |
Andrea Campanella | a9cdaf6 | 2019-09-08 10:30:16 -0700 | [diff] [blame] | 36 | |
Sudeep Desai | bffe153 | 2020-01-21 16:43:46 +0530 | [diff] [blame] | 37 | public static Logger log = LoggerFactory.getLogger(GrooveModulationOpenConfig.class); |
Andrea Campanella | a9cdaf6 | 2019-09-08 10:30:16 -0700 | [diff] [blame] | 38 | |
| 39 | /** |
Sudeep Desai | bffe153 | 2020-01-21 16:43:46 +0530 | [diff] [blame] | 40 | * Construct a rpc target power message. |
Andrea Campanella | a9cdaf6 | 2019-09-08 10:30:16 -0700 | [diff] [blame] | 41 | * |
Sudeep Desai | bffe153 | 2020-01-21 16:43:46 +0530 | [diff] [blame] | 42 | * @return RPC payload |
Andrea Campanella | a9cdaf6 | 2019-09-08 10:30:16 -0700 | [diff] [blame] | 43 | */ |
Sudeep Desai | bffe153 | 2020-01-21 16:43:46 +0530 | [diff] [blame] | 44 | @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 Campanella | a9cdaf6 | 2019-09-08 10:30:16 -0700 | [diff] [blame] | 60 | |
Sudeep Desai | bffe153 | 2020-01-21 16:43:46 +0530 | [diff] [blame] | 61 | @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 Campanella | a9cdaf6 | 2019-09-08 10:30:16 -0700 | [diff] [blame] | 74 | |
Sudeep Desai | bffe153 | 2020-01-21 16:43:46 +0530 | [diff] [blame] | 75 | @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 Campanella | a9cdaf6 | 2019-09-08 10:30:16 -0700 | [diff] [blame] | 103 | return null; |
| 104 | } |
Andrea Campanella | a9cdaf6 | 2019-09-08 10:30:16 -0700 | [diff] [blame] | 105 | } |
| 106 | |
Andrea Campanella | a9cdaf6 | 2019-09-08 10:30:16 -0700 | [diff] [blame] | 107 | @Override |
Sudeep Desai | bffe153 | 2020-01-21 16:43:46 +0530 | [diff] [blame] | 108 | 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 Campanella | a9cdaf6 | 2019-09-08 10:30:16 -0700 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | /** |
Sudeep Desai | bffe153 | 2020-01-21 16:43:46 +0530 | [diff] [blame] | 128 | * Get the Modulation Scheme on the component. |
Andrea Campanella | a9cdaf6 | 2019-09-08 10:30:16 -0700 | [diff] [blame] | 129 | * |
Sudeep Desai | bffe153 | 2020-01-21 16:43:46 +0530 | [diff] [blame] | 130 | * @param conf HierarchicalConfiguration for path ../optical-channel/config |
| 131 | * @return Optional<ModulationScheme> |
Andrea Campanella | a9cdaf6 | 2019-09-08 10:30:16 -0700 | [diff] [blame] | 132 | **/ |
Sudeep Desai | bffe153 | 2020-01-21 16:43:46 +0530 | [diff] [blame] | 133 | public Optional<ModulationScheme> getModulation(XMLConfiguration conf) { |
| 134 | HierarchicalConfiguration config = |
| 135 | conf.configurationAt("data/components/component/optical-channel/config"); |
Andrea Campanella | a9cdaf6 | 2019-09-08 10:30:16 -0700 | [diff] [blame] | 136 | |
Sudeep Desai | bffe153 | 2020-01-21 16:43:46 +0530 | [diff] [blame] | 137 | 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 Campanella | a9cdaf6 | 2019-09-08 10:30:16 -0700 | [diff] [blame] | 146 | } |
Sudeep Desai | bffe153 | 2020-01-21 16:43:46 +0530 | [diff] [blame] | 147 | return Optional.of(modulation); |
Andrea Campanella | a9cdaf6 | 2019-09-08 10:30:16 -0700 | [diff] [blame] | 148 | } |
| 149 | } |
Sudeep Desai | bffe153 | 2020-01-21 16:43:46 +0530 | [diff] [blame] | 150 | |