blob: d7c9fcb4c8043fe105764aeb3c6a0b2a05ef9a06 [file] [log] [blame]
Andrea Campanella99ab7102019-07-26 14:43:14 +02001/*
Sudeep Desai5013f492020-01-08 16:01:47 +05302 * 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
Andrea Campanella99ab7102019-07-26 14:43:14 +020020import org.onosproject.net.PortNumber;
Andrea Campanella99ab7102019-07-26 14:43:14 +020021import org.slf4j.Logger;
22import org.slf4j.LoggerFactory;
23
Andrea Campanella99ab7102019-07-26 14:43:14 +020024/*
25 * Driver Implementation of the ModulationConfig for OcNos based terminal devices.
26 */
Sudeep Desai5013f492020-01-08 16:01:47 +053027public class CassiniModulationOcNos<T> extends TerminalDeviceModulationConfig<T> {
Andrea Campanella99ab7102019-07-26 14:43:14 +020028
29
Sudeep Desai5013f492020-01-08 16:01:47 +053030 private static Logger log = LoggerFactory.getLogger(CassiniModulationOcNos.class);
Andrea Campanella99ab7102019-07-26 14:43:14 +020031
32
Andrea Campanella99ab7102019-07-26 14:43:14 +020033
34 /**
Sudeep Desai5013f492020-01-08 16:01:47 +053035 * Construct a rpc target power message.
Andrea Campanella99ab7102019-07-26 14:43:14 +020036 *
Sudeep Desai5013f492020-01-08 16:01:47 +053037 * @param name for optical channel name
38 * @return RPC payload
Andrea Campanella99ab7102019-07-26 14:43:14 +020039 */
Sudeep Desai5013f492020-01-08 16:01:47 +053040 @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 Campanella99ab7102019-07-26 14:43:14 +020046
Sudeep Desaibffe1532020-01-21 16:43:46 +053047 /**
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 Desai5013f492020-01-08 16:01:47 +053064 @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 Desaibffe1532020-01-21 16:43:46 +053070 editConfig = state.modulationEditConfig(state.terminalDevice, port, component, bitRate, modulation);
Sudeep Desai5013f492020-01-08 16:01:47 +053071 //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 Desaibffe1532020-01-21 16:43:46 +053075 editConfig = state.modulationEditConfig(state.terminalDevice, port, component, bitRate, modulation);
Sudeep Desai5013f492020-01-08 16:01:47 +053076 //setting the modulation by calling rpc
77 state.setModulationRpc(port, component, editConfig);
78 }
Andrea Campanella99ab7102019-07-26 14:43:14 +020079
Sudeep Desai5013f492020-01-08 16:01:47 +053080 }
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 Campanella99ab7102019-07-26 14:43:14 +0200106 return null;
107 }
Andrea Campanella99ab7102019-07-26 14:43:14 +0200108 }
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 Desai5013f492020-01-08 16:01:47 +0530119 state = ComponentType.DIRECTION;
Andrea Campanella99ab7102019-07-26 14:43:14 +0200120 break;
121 case "org.onosproject.net.OchSignal":
Sudeep Desai5013f492020-01-08 16:01:47 +0530122 state = ComponentType.OCHSIGNAL;
Andrea Campanella99ab7102019-07-26 14:43:14 +0200123 break;
124 default:
125 log.error("Cannot parse the component type {}.", clsName);
126 log.info("The component content is {}.", component.toString());
127 }
128
Sudeep Desaibffe1532020-01-21 16:43:46 +0530129 state.terminalDevice = this;
Andrea Campanella99ab7102019-07-26 14:43:14 +0200130 log.info("Setting the state with clsName :{} ", clsName);
131 }
132
Andrea Campanella99ab7102019-07-26 14:43:14 +0200133
134}