blob: f1263920be28d7588efe74f30e12601f0cbf6283 [file] [log] [blame]
Andrea Campanella99ab7102019-07-26 14:43:14 +02001/*
Andrea Campanella3a361452019-08-02 10:17:53 +02002 * Copyright 2019-present Open Networking Foundation
Andrea Campanella99ab7102019-07-26 14:43:14 +02003 *
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
Sudeep Desai5013f492020-01-08 16:01:47 +053020
Andrea Campanella99ab7102019-07-26 14:43:14 +020021import org.onosproject.net.ModulationScheme;
22import org.onosproject.net.PortNumber;
Andrea Campanella3a361452019-08-02 10:17:53 +020023import org.onosproject.netconf.DatastoreId;
Andrea Campanella99ab7102019-07-26 14:43:14 +020024import org.slf4j.Logger;
25import org.slf4j.LoggerFactory;
Andrea Campanella99ab7102019-07-26 14:43:14 +020026/*
27 * Driver Implementation of the ModulationConfig for OcNos standard open config based terminal devices.
28 */
Sudeep Desai5013f492020-01-08 16:01:47 +053029public class CassiniModulationOpenConfig<T> extends TerminalDeviceModulationConfig<T> {
Andrea Campanella99ab7102019-07-26 14:43:14 +020030
Sudeep Desai5013f492020-01-08 16:01:47 +053031 public static Logger log = LoggerFactory.getLogger(CassiniModulationOpenConfig.class);
Andrea Campanella99ab7102019-07-26 14:43:14 +020032
Sudeep Desai5013f492020-01-08 16:01:47 +053033 /**
34 * Construct a rpc target power message.
35 *
Sudeep Desai5013f492020-01-08 16:01:47 +053036 * @return RPC payload
Andrea Campanella99ab7102019-07-26 14:43:14 +020037 */
Sudeep Desai5013f492020-01-08 16:01:47 +053038 @Override
39 public DatastoreId getDataStoreId() {
40 return DatastoreId.CANDIDATE;
41 }
Andrea Campanella99ab7102019-07-26 14:43:14 +020042
Sudeep Desai5013f492020-01-08 16:01:47 +053043 /**
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 Campanella99ab7102019-07-26 14:43:14 +020054 }
55
56 /*
57 *
Sudeep Desai5013f492020-01-08 16:01:47 +053058 * 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 Campanella99ab7102019-07-26 14:43:14 +020064 */
Sudeep Desai5013f492020-01-08 16:01:47 +053065 @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 Campanella99ab7102019-07-26 14:43:14 +020090 }
Andrea Campanella99ab7102019-07-26 14:43:14 +020091 }
92
Andrea Campanella99ab7102019-07-26 14:43:14 +020093 @Override
Sudeep Desai5013f492020-01-08 16:01:47 +053094 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 Desaibffe1532020-01-21 16:43:46 +053099 editConfig = state.modulationEditConfig(state.terminalDevice, port, component, bitRate, modulation);
Sudeep Desai5013f492020-01-08 16:01:47 +0530100 //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 Desaibffe1532020-01-21 16:43:46 +0530104 editConfig = state.modulationEditConfig(state.terminalDevice, port, component, bitRate, modulation);
Sudeep Desai5013f492020-01-08 16:01:47 +0530105 //setting the modulation by calling rpc
106 state.setModulationRpc(port, component, editConfig);
107 }
108
Andrea Campanella99ab7102019-07-26 14:43:14 +0200109 }
110
Andrea Campanella99ab7102019-07-26 14:43:14 +0200111 @Override
Sudeep Desai5013f492020-01-08 16:01:47 +0530112 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 Campanella99ab7102019-07-26 14:43:14 +0200124 }
125
Andrea Campanella99ab7102019-07-26 14:43:14 +0200126 /*
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 Desai5013f492020-01-08 16:01:47 +0530135 state = ComponentType.DIRECTION;
Andrea Campanella99ab7102019-07-26 14:43:14 +0200136 break;
137 case "org.onosproject.net.OchSignal":
Sudeep Desai5013f492020-01-08 16:01:47 +0530138 state = ComponentType.OCHSIGNAL;
Andrea Campanella99ab7102019-07-26 14:43:14 +0200139 break;
140 default:
141 log.error("Cannot parse the component type {}.", clsName);
142 log.info("The component content is {}.", component.toString());
143 }
144
Sudeep Desaibffe1532020-01-21 16:43:46 +0530145 state.terminalDevice = this;
Andrea Campanella99ab7102019-07-26 14:43:14 +0200146 }
Andrea Campanella99ab7102019-07-26 14:43:14 +0200147}