blob: 17eaf92a9fd41417dfbdfef57250e6e5afd10268 [file] [log] [blame]
harjak47ff0db2019-10-08 10:30:47 +02001/*
Sudeep Desaif0911a72019-12-09 18:31:37 +05302 * Copyright 2019-present Open Networking Foundation
harjak47ff0db2019-10-08 10:30:47 +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 */
18
19package org.onosproject.drivers.odtn;
20
21import com.google.common.collect.Range;
Sudeep Desaif0911a72019-12-09 18:31:37 +053022import org.onosproject.drivers.odtn.openconfig.TerminalDevicePowerConfig;
harjak47ff0db2019-10-08 10:30:47 +020023import org.onosproject.net.PortNumber;
24import org.onosproject.net.behaviour.PowerConfig;
harjak47ff0db2019-10-08 10:30:47 +020025import org.slf4j.Logger;
26
harjak47ff0db2019-10-08 10:30:47 +020027import java.util.Optional;
harjak47ff0db2019-10-08 10:30:47 +020028
harjak47ff0db2019-10-08 10:30:47 +020029import static org.slf4j.LoggerFactory.getLogger;
30
31/**
32 * Driver Implementation of the PowerConfig for OpenConfig terminal devices.
33 */
34public class AdvaTerminalDevicePowerConfig<T>
Sudeep Desaif0911a72019-12-09 18:31:37 +053035 extends TerminalDevicePowerConfig<T> implements PowerConfig<T> {
harjak47ff0db2019-10-08 10:30:47 +020036
37 private static final Logger log = getLogger(AdvaTerminalDevicePowerConfig.class);
38
Sudeep Desaif0911a72019-12-09 18:31:37 +053039 /**
40 * Getting target value of output power.
41 * @param port port
42 * @param component the component
43 * @return target output power range
44 */
45 @Override
46 public Optional<Range<Double>> getTargetPowerRange(PortNumber port, Object component) {
47 double targetMin = -30;
48 double targetMax = 1;
49 return Optional.of(Range.open(targetMin, targetMax));
50 }
51
52 @Override
53 public Optional<Range<Double>> getInputPowerRange(PortNumber port, Object component) {
54 double targetMin = -30;
55 double targetMax = 1;
56 return Optional.of(Range.open(targetMin, targetMax));
57 }
harjak47ff0db2019-10-08 10:30:47 +020058
59 /**
Sudeep Desaif0911a72019-12-09 18:31:37 +053060 * Construct a rpc target power message.
harjak47ff0db2019-10-08 10:30:47 +020061 *
Sudeep Desaif0911a72019-12-09 18:31:37 +053062 * @param name for optical channel name
63 * @param power to build rpc for target output power configuration
64 * @return RPC payload
harjak47ff0db2019-10-08 10:30:47 +020065 */
66 @Override
Sudeep Desaif0911a72019-12-09 18:31:37 +053067 public StringBuilder parsePortRequestRpc(Double power, String name) {
68 StringBuilder rpc = new StringBuilder();
69 rpc.append("<component>");
70 if (power != null) {
71 // This is an edit-config operation.
72 rpc.append("<config>")
73 .append("<name>")
74 .append(name)
75 .append("</name>")
harjak47ff0db2019-10-08 10:30:47 +020076 .append("</config>")
harjak47ff0db2019-10-08 10:30:47 +020077 .append("<optical-channel xmlns=\"http://openconfig.net/yang/terminal-device\">")
Sudeep Desaif0911a72019-12-09 18:31:37 +053078 .append("<config>")
79 .append("<target-output-power>")
80 .append(power)
81 .append("</target-output-power>")
82 .append("</config>")
83 .append("</optical-channel>");
84 } else {
85 rpc.append("<name>")
86 .append(name)
87 .append("</name>");
harjak47ff0db2019-10-08 10:30:47 +020088 }
Sudeep Desaif0911a72019-12-09 18:31:37 +053089 return rpc;
harjak47ff0db2019-10-08 10:30:47 +020090 }
91}