harjak | 47ff0db | 2019-10-08 10:30:47 +0200 | [diff] [blame] | 1 | /* |
Sudeep Desai | f0911a7 | 2019-12-09 18:31:37 +0530 | [diff] [blame] | 2 | * Copyright 2019-present Open Networking Foundation |
harjak | 47ff0db | 2019-10-08 10:30:47 +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 | |
| 19 | package org.onosproject.drivers.odtn; |
| 20 | |
| 21 | import com.google.common.collect.Range; |
Sudeep Desai | f0911a7 | 2019-12-09 18:31:37 +0530 | [diff] [blame] | 22 | import org.onosproject.drivers.odtn.openconfig.TerminalDevicePowerConfig; |
harjak | 47ff0db | 2019-10-08 10:30:47 +0200 | [diff] [blame] | 23 | import org.onosproject.net.PortNumber; |
| 24 | import org.onosproject.net.behaviour.PowerConfig; |
harjak | 47ff0db | 2019-10-08 10:30:47 +0200 | [diff] [blame] | 25 | import org.slf4j.Logger; |
| 26 | |
harjak | 47ff0db | 2019-10-08 10:30:47 +0200 | [diff] [blame] | 27 | import java.util.Optional; |
harjak | 47ff0db | 2019-10-08 10:30:47 +0200 | [diff] [blame] | 28 | |
harjak | 47ff0db | 2019-10-08 10:30:47 +0200 | [diff] [blame] | 29 | import static org.slf4j.LoggerFactory.getLogger; |
| 30 | |
| 31 | /** |
| 32 | * Driver Implementation of the PowerConfig for OpenConfig terminal devices. |
| 33 | */ |
| 34 | public class AdvaTerminalDevicePowerConfig<T> |
Sudeep Desai | f0911a7 | 2019-12-09 18:31:37 +0530 | [diff] [blame] | 35 | extends TerminalDevicePowerConfig<T> implements PowerConfig<T> { |
harjak | 47ff0db | 2019-10-08 10:30:47 +0200 | [diff] [blame] | 36 | |
| 37 | private static final Logger log = getLogger(AdvaTerminalDevicePowerConfig.class); |
| 38 | |
Sudeep Desai | f0911a7 | 2019-12-09 18:31:37 +0530 | [diff] [blame] | 39 | /** |
| 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 | } |
harjak | 47ff0db | 2019-10-08 10:30:47 +0200 | [diff] [blame] | 58 | |
| 59 | /** |
Sudeep Desai | f0911a7 | 2019-12-09 18:31:37 +0530 | [diff] [blame] | 60 | * Construct a rpc target power message. |
harjak | 47ff0db | 2019-10-08 10:30:47 +0200 | [diff] [blame] | 61 | * |
Sudeep Desai | f0911a7 | 2019-12-09 18:31:37 +0530 | [diff] [blame] | 62 | * @param name for optical channel name |
| 63 | * @param power to build rpc for target output power configuration |
| 64 | * @return RPC payload |
harjak | 47ff0db | 2019-10-08 10:30:47 +0200 | [diff] [blame] | 65 | */ |
| 66 | @Override |
Sudeep Desai | f0911a7 | 2019-12-09 18:31:37 +0530 | [diff] [blame] | 67 | 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>") |
harjak | 47ff0db | 2019-10-08 10:30:47 +0200 | [diff] [blame] | 76 | .append("</config>") |
harjak | 47ff0db | 2019-10-08 10:30:47 +0200 | [diff] [blame] | 77 | .append("<optical-channel xmlns=\"http://openconfig.net/yang/terminal-device\">") |
Sudeep Desai | f0911a7 | 2019-12-09 18:31:37 +0530 | [diff] [blame] | 78 | .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>"); |
harjak | 47ff0db | 2019-10-08 10:30:47 +0200 | [diff] [blame] | 88 | } |
Sudeep Desai | f0911a7 | 2019-12-09 18:31:37 +0530 | [diff] [blame] | 89 | return rpc; |
harjak | 47ff0db | 2019-10-08 10:30:47 +0200 | [diff] [blame] | 90 | } |
| 91 | } |