Andrea Campanella | 99ab710 | 2019-07-26 14:43:14 +0200 | [diff] [blame] | 1 | /* |
Sudeep Desai | 5013f49 | 2020-01-08 16:01:47 +0530 | [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 | |
Andrea Campanella | 99ab710 | 2019-07-26 14:43:14 +0200 | [diff] [blame] | 20 | import org.onosproject.net.PortNumber; |
Andrea Campanella | 99ab710 | 2019-07-26 14:43:14 +0200 | [diff] [blame] | 21 | import org.slf4j.Logger; |
| 22 | import org.slf4j.LoggerFactory; |
| 23 | |
Andrea Campanella | 99ab710 | 2019-07-26 14:43:14 +0200 | [diff] [blame] | 24 | /* |
| 25 | * Driver Implementation of the ModulationConfig for OcNos based terminal devices. |
| 26 | */ |
Sudeep Desai | 5013f49 | 2020-01-08 16:01:47 +0530 | [diff] [blame] | 27 | public class CassiniModulationOcNos<T> extends TerminalDeviceModulationConfig<T> { |
Andrea Campanella | 99ab710 | 2019-07-26 14:43:14 +0200 | [diff] [blame] | 28 | |
| 29 | |
Sudeep Desai | 5013f49 | 2020-01-08 16:01:47 +0530 | [diff] [blame] | 30 | private static Logger log = LoggerFactory.getLogger(CassiniModulationOcNos.class); |
Andrea Campanella | 99ab710 | 2019-07-26 14:43:14 +0200 | [diff] [blame] | 31 | |
| 32 | |
Andrea Campanella | 99ab710 | 2019-07-26 14:43:14 +0200 | [diff] [blame] | 33 | |
| 34 | /** |
Sudeep Desai | 5013f49 | 2020-01-08 16:01:47 +0530 | [diff] [blame] | 35 | * Construct a rpc target power message. |
Andrea Campanella | 99ab710 | 2019-07-26 14:43:14 +0200 | [diff] [blame] | 36 | * |
Sudeep Desai | 5013f49 | 2020-01-08 16:01:47 +0530 | [diff] [blame] | 37 | * @param name for optical channel name |
| 38 | * @return RPC payload |
Andrea Campanella | 99ab710 | 2019-07-26 14:43:14 +0200 | [diff] [blame] | 39 | */ |
Sudeep Desai | 5013f49 | 2020-01-08 16:01:47 +0530 | [diff] [blame] | 40 | @Override |
| 41 | public StringBuilder createModulationFilterRequestRpc(String name) { |
| 42 | StringBuilder rpc = new StringBuilder(); |
| 43 | rpc.append("<name>").append(name).append("</name>"); |
| 44 | return rpc; |
| 45 | } |
Andrea Campanella | 99ab710 | 2019-07-26 14:43:14 +0200 | [diff] [blame] | 46 | |
Sudeep Desai | bffe153 | 2020-01-21 16:43:46 +0530 | [diff] [blame^] | 47 | /** |
| 48 | * Construct a rpc target power message. |
| 49 | * |
| 50 | * @param filter to build rpc |
| 51 | * @return RPC payload |
| 52 | */ |
| 53 | @Override |
| 54 | public StringBuilder getModulationSchemeRequestRpc(String filter) { |
| 55 | StringBuilder rpc = new StringBuilder(); |
| 56 | rpc.append("<get>") |
| 57 | .append("<filter>") |
| 58 | .append(filter) |
| 59 | .append("</filter>") |
| 60 | .append("</get>"); |
| 61 | return rpc; |
| 62 | } |
| 63 | |
Sudeep Desai | 5013f49 | 2020-01-08 16:01:47 +0530 | [diff] [blame] | 64 | @Override |
| 65 | public void setModulationSchemeProcessor(PortNumber port, Object component, long bitRate) { |
| 66 | String modulation = null; |
| 67 | String editConfig = null; |
| 68 | if (bitRate <= TerminalDeviceModulationConfig.BitRate.GBPS_100.value) { |
| 69 | modulation = "dp_qpsk"; |
Sudeep Desai | bffe153 | 2020-01-21 16:43:46 +0530 | [diff] [blame^] | 70 | editConfig = state.modulationEditConfig(state.terminalDevice, port, component, bitRate, modulation); |
Sudeep Desai | 5013f49 | 2020-01-08 16:01:47 +0530 | [diff] [blame] | 71 | //setting the modulation by calling rpc |
| 72 | state.setModulationRpc(port, component, editConfig); |
| 73 | } else { // check if bitrate is greater than 100 Gig |
| 74 | modulation = "dp_16qam"; |
Sudeep Desai | bffe153 | 2020-01-21 16:43:46 +0530 | [diff] [blame^] | 75 | editConfig = state.modulationEditConfig(state.terminalDevice, port, component, bitRate, modulation); |
Sudeep Desai | 5013f49 | 2020-01-08 16:01:47 +0530 | [diff] [blame] | 76 | //setting the modulation by calling rpc |
| 77 | state.setModulationRpc(port, component, editConfig); |
| 78 | } |
Andrea Campanella | 99ab710 | 2019-07-26 14:43:14 +0200 | [diff] [blame] | 79 | |
Sudeep Desai | 5013f49 | 2020-01-08 16:01:47 +0530 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | @Override |
| 83 | public String modulationEditConfigRequestRpc(TerminalDeviceModulationConfig modulationConfig, PortNumber portNumber, |
| 84 | Object component, long bitRate, String modulation) { |
| 85 | if (component != null) { |
| 86 | String portName = state.ocName(modulationConfig, portNumber); //oc1/1 |
| 87 | String slotName = portName.split("/")[0]; //get oc1 |
| 88 | String slotIndex = slotName.substring(slotName.length() - 1); //then just 1 |
| 89 | String netIndex = portName.split("/")[1]; //get 1 after the / |
| 90 | StringBuilder sb = new StringBuilder("<cmmOpticalControllerTable " + |
| 91 | "xmlns=\"http://www.ipinfusion.com/CMLSchema/zebos\">"); |
| 92 | sb.append("<slotIndex>").append(slotIndex).append("</slotIndex>"); |
| 93 | if (modulation != null) { |
| 94 | // This is an edit-config operation. |
| 95 | sb.append("<cmmOpticalChannelInterfaceTable>") |
| 96 | .append("<netIndex>").append(netIndex).append("<netIndex>") |
| 97 | .append("<modulationFormat>") |
| 98 | .append(modulation) |
| 99 | .append("</modulationFormat>") |
| 100 | .append("</cmmOpticalNetworkInterfaceTable>"); |
| 101 | } |
| 102 | sb.append("</cmmOpticalControllerTable>"); |
| 103 | return sb.toString(); |
| 104 | } else { |
| 105 | log.error("Cannot process the component {}.", component.getClass()); |
Andrea Campanella | 99ab710 | 2019-07-26 14:43:14 +0200 | [diff] [blame] | 106 | return null; |
| 107 | } |
Andrea Campanella | 99ab710 | 2019-07-26 14:43:14 +0200 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | /* |
| 111 | * |
| 112 | * Set the ComponentType to invoke proper methods for different template T. |
| 113 | * @param component the component. |
| 114 | */ |
| 115 | void checkState(Object component) { |
| 116 | String clsName = component.getClass().getName(); |
| 117 | switch (clsName) { |
| 118 | case "org.onosproject.net.Direction": |
Sudeep Desai | 5013f49 | 2020-01-08 16:01:47 +0530 | [diff] [blame] | 119 | state = ComponentType.DIRECTION; |
Andrea Campanella | 99ab710 | 2019-07-26 14:43:14 +0200 | [diff] [blame] | 120 | break; |
| 121 | case "org.onosproject.net.OchSignal": |
Sudeep Desai | 5013f49 | 2020-01-08 16:01:47 +0530 | [diff] [blame] | 122 | state = ComponentType.OCHSIGNAL; |
Andrea Campanella | 99ab710 | 2019-07-26 14:43:14 +0200 | [diff] [blame] | 123 | break; |
| 124 | default: |
| 125 | log.error("Cannot parse the component type {}.", clsName); |
| 126 | log.info("The component content is {}.", component.toString()); |
| 127 | } |
| 128 | |
Sudeep Desai | bffe153 | 2020-01-21 16:43:46 +0530 | [diff] [blame^] | 129 | state.terminalDevice = this; |
Andrea Campanella | 99ab710 | 2019-07-26 14:43:14 +0200 | [diff] [blame] | 130 | log.info("Setting the state with clsName :{} ", clsName); |
| 131 | } |
| 132 | |
Andrea Campanella | 99ab710 | 2019-07-26 14:43:14 +0200 | [diff] [blame] | 133 | |
| 134 | } |