Andrea Campanella | 99ab710 | 2019-07-26 14:43:14 +0200 | [diff] [blame] | 1 | /* |
Andrea Campanella | 3a36145 | 2019-08-02 10:17:53 +0200 | [diff] [blame] | 2 | * Copyright 2019-present Open Networking Foundation |
Andrea Campanella | 99ab710 | 2019-07-26 14:43:14 +0200 | [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 | |
Sudeep Desai | 5013f49 | 2020-01-08 16:01:47 +0530 | [diff] [blame] | 20 | |
Andrea Campanella | 99ab710 | 2019-07-26 14:43:14 +0200 | [diff] [blame] | 21 | import org.onosproject.net.ModulationScheme; |
| 22 | import org.onosproject.net.PortNumber; |
Andrea Campanella | 3a36145 | 2019-08-02 10:17:53 +0200 | [diff] [blame] | 23 | import org.onosproject.netconf.DatastoreId; |
Andrea Campanella | 99ab710 | 2019-07-26 14:43:14 +0200 | [diff] [blame] | 24 | import org.slf4j.Logger; |
| 25 | import org.slf4j.LoggerFactory; |
Andrea Campanella | 99ab710 | 2019-07-26 14:43:14 +0200 | [diff] [blame] | 26 | /* |
| 27 | * Driver Implementation of the ModulationConfig for OcNos standard open config based terminal devices. |
| 28 | */ |
Sudeep Desai | 5013f49 | 2020-01-08 16:01:47 +0530 | [diff] [blame] | 29 | public class CassiniModulationOpenConfig<T> extends TerminalDeviceModulationConfig<T> { |
Andrea Campanella | 99ab710 | 2019-07-26 14:43:14 +0200 | [diff] [blame] | 30 | |
Sudeep Desai | 5013f49 | 2020-01-08 16:01:47 +0530 | [diff] [blame] | 31 | public static Logger log = LoggerFactory.getLogger(CassiniModulationOpenConfig.class); |
Andrea Campanella | 99ab710 | 2019-07-26 14:43:14 +0200 | [diff] [blame] | 32 | |
Sudeep Desai | 5013f49 | 2020-01-08 16:01:47 +0530 | [diff] [blame] | 33 | /** |
| 34 | * Construct a rpc target power message. |
| 35 | * |
Sudeep Desai | 5013f49 | 2020-01-08 16:01:47 +0530 | [diff] [blame] | 36 | * @return RPC payload |
Andrea Campanella | 99ab710 | 2019-07-26 14:43:14 +0200 | [diff] [blame] | 37 | */ |
Sudeep Desai | 5013f49 | 2020-01-08 16:01:47 +0530 | [diff] [blame] | 38 | @Override |
| 39 | public DatastoreId getDataStoreId() { |
| 40 | return DatastoreId.CANDIDATE; |
| 41 | } |
Andrea Campanella | 99ab710 | 2019-07-26 14:43:14 +0200 | [diff] [blame] | 42 | |
Sudeep Desai | 5013f49 | 2020-01-08 16:01:47 +0530 | [diff] [blame] | 43 | /** |
| 44 | * Construct a rpc target power message. |
| 45 | * |
| 46 | * @param name for optical channel name |
| 47 | * @return RPC payload |
| 48 | */ |
| 49 | @Override |
| 50 | public StringBuilder createModulationFilterRequestRpc(String name) { |
| 51 | StringBuilder rpc = new StringBuilder(); |
| 52 | rpc.append("<name>").append(name).append("</name>"); |
| 53 | return rpc; |
Andrea Campanella | 99ab710 | 2019-07-26 14:43:14 +0200 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | /* |
| 57 | * |
Sudeep Desai | 5013f49 | 2020-01-08 16:01:47 +0530 | [diff] [blame] | 58 | * Parse filtering string from port and component. |
| 59 | * @param portNumber Port Number |
| 60 | * @param component port component (optical-channel) |
| 61 | * @param bitRate bitRate in bps |
| 62 | * @return filtering string in xml format |
| 63 | |
Andrea Campanella | 99ab710 | 2019-07-26 14:43:14 +0200 | [diff] [blame] | 64 | */ |
Sudeep Desai | 5013f49 | 2020-01-08 16:01:47 +0530 | [diff] [blame] | 65 | @Override |
| 66 | public String modulationEditConfigRequestRpc(TerminalDeviceModulationConfig modulationConfig, PortNumber portNumber, |
| 67 | Object component, long bitRate, String modulation) { |
| 68 | if (component != null) { |
| 69 | // This is an edit-config operation. |
| 70 | String portName = state.ocName(modulationConfig, portNumber); //oc1/0 |
| 71 | StringBuilder sb = new StringBuilder("<components xmlns=\"http://openconfig.net/yang/platform\">"); |
| 72 | sb.append("<component>"); |
| 73 | sb.append("<name>").append(portName).append("</name>"); |
| 74 | sb.append("<config>"); |
| 75 | sb.append("<name>").append(portName).append("</name>"); |
| 76 | sb.append("</config>"); |
| 77 | sb.append("<optical-channel xmlns=\"http://openconfig.net/yang/terminal-device\">") |
| 78 | .append("<config>") |
| 79 | .append("<modulation-format>") |
| 80 | .append(modulation) |
| 81 | .append("</modulation-format>") |
| 82 | .append("</config>") |
| 83 | .append("</optical-channel>"); |
| 84 | sb.append("</component>"); |
| 85 | sb.append("</components>"); |
| 86 | return sb.toString(); |
| 87 | } else { |
| 88 | log.error("Cannot process the component {}.", component.getClass()); |
| 89 | return null; |
Andrea Campanella | 99ab710 | 2019-07-26 14:43:14 +0200 | [diff] [blame] | 90 | } |
Andrea Campanella | 99ab710 | 2019-07-26 14:43:14 +0200 | [diff] [blame] | 91 | } |
| 92 | |
Andrea Campanella | 99ab710 | 2019-07-26 14:43:14 +0200 | [diff] [blame] | 93 | @Override |
Sudeep Desai | 5013f49 | 2020-01-08 16:01:47 +0530 | [diff] [blame] | 94 | public void setModulationSchemeProcessor(PortNumber port, Object component, long bitRate) { |
| 95 | String modulation = null; |
| 96 | String editConfig = null; |
| 97 | if (bitRate <= BitRate.GBPS_100.value) { |
| 98 | modulation = "dp_qpsk"; |
Sudeep Desai | bffe153 | 2020-01-21 16:43:46 +0530 | [diff] [blame] | 99 | editConfig = state.modulationEditConfig(state.terminalDevice, port, component, bitRate, modulation); |
Sudeep Desai | 5013f49 | 2020-01-08 16:01:47 +0530 | [diff] [blame] | 100 | //setting the modulation by calling rpc |
| 101 | state.setModulationRpc(port, component, editConfig); |
| 102 | } else { // check if bitrate is greater than 100 Gig |
| 103 | modulation = "dp_16qam"; |
Sudeep Desai | bffe153 | 2020-01-21 16:43:46 +0530 | [diff] [blame] | 104 | editConfig = state.modulationEditConfig(state.terminalDevice, port, component, bitRate, modulation); |
Sudeep Desai | 5013f49 | 2020-01-08 16:01:47 +0530 | [diff] [blame] | 105 | //setting the modulation by calling rpc |
| 106 | state.setModulationRpc(port, component, editConfig); |
| 107 | } |
| 108 | |
Andrea Campanella | 99ab710 | 2019-07-26 14:43:14 +0200 | [diff] [blame] | 109 | } |
| 110 | |
Andrea Campanella | 99ab710 | 2019-07-26 14:43:14 +0200 | [diff] [blame] | 111 | @Override |
Sudeep Desai | 5013f49 | 2020-01-08 16:01:47 +0530 | [diff] [blame] | 112 | public ModulationScheme modulationSchemeType(String modulationScheme) { |
| 113 | /*Used for Internal Testing */ |
| 114 | //String modulationScheme="DP16QAM"; |
| 115 | ModulationScheme modulation; |
| 116 | if (modulationScheme.equalsIgnoreCase("dp-16-qam")) { |
| 117 | modulation = ModulationScheme.DP_16QAM; |
| 118 | } else if (modulationScheme.equalsIgnoreCase("dp-8-qam")) { |
| 119 | modulation = ModulationScheme.DP_8QAM; |
| 120 | } else { |
| 121 | modulation = ModulationScheme.DP_QPSK; |
| 122 | } |
| 123 | return modulation; |
Andrea Campanella | 99ab710 | 2019-07-26 14:43:14 +0200 | [diff] [blame] | 124 | } |
| 125 | |
Andrea Campanella | 99ab710 | 2019-07-26 14:43:14 +0200 | [diff] [blame] | 126 | /* |
| 127 | * |
| 128 | * Set the ComponentType to invoke proper methods for different template T. |
| 129 | * @param component the component. |
| 130 | */ |
| 131 | void checkState(Object component) { |
| 132 | String clsName = component.getClass().getName(); |
| 133 | switch (clsName) { |
| 134 | case "org.onosproject.net.Direction": |
Sudeep Desai | 5013f49 | 2020-01-08 16:01:47 +0530 | [diff] [blame] | 135 | state = ComponentType.DIRECTION; |
Andrea Campanella | 99ab710 | 2019-07-26 14:43:14 +0200 | [diff] [blame] | 136 | break; |
| 137 | case "org.onosproject.net.OchSignal": |
Sudeep Desai | 5013f49 | 2020-01-08 16:01:47 +0530 | [diff] [blame] | 138 | state = ComponentType.OCHSIGNAL; |
Andrea Campanella | 99ab710 | 2019-07-26 14:43:14 +0200 | [diff] [blame] | 139 | break; |
| 140 | default: |
| 141 | log.error("Cannot parse the component type {}.", clsName); |
| 142 | log.info("The component content is {}.", component.toString()); |
| 143 | } |
| 144 | |
Sudeep Desai | bffe153 | 2020-01-21 16:43:46 +0530 | [diff] [blame] | 145 | state.terminalDevice = this; |
Andrea Campanella | 99ab710 | 2019-07-26 14:43:14 +0200 | [diff] [blame] | 146 | } |
Andrea Campanella | 99ab710 | 2019-07-26 14:43:14 +0200 | [diff] [blame] | 147 | } |