MaoLu | 937cf42 | 2017-03-03 23:31:46 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
MaoLu | 937cf42 | 2017-03-03 23:31:46 -0800 | [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 | |
| 17 | package org.onosproject.driver.optical.power; |
| 18 | |
| 19 | import java.util.Optional; |
| 20 | |
| 21 | import com.google.common.collect.Range; |
| 22 | import org.onosproject.net.driver.AbstractHandlerBehaviour; |
| 23 | import org.onosproject.net.PortNumber; |
| 24 | import org.onosproject.net.behaviour.PowerConfig; |
| 25 | |
| 26 | /** |
| 27 | * Port Power implementation for Oplink protection switch device. |
Andrea Campanella | dadf640 | 2019-08-07 15:24:11 +0200 | [diff] [blame^] | 28 | * <p> |
MaoLu | 937cf42 | 2017-03-03 23:31:46 -0800 | [diff] [blame] | 29 | * Intruduction: |
Andrea Campanella | dadf640 | 2019-08-07 15:24:11 +0200 | [diff] [blame^] | 30 | * _____ |
| 31 | * _____________________ | | 0 VIRTUAL |
| 32 | * | | | 1 | |
| 33 | * CLIENT | |---|-----|--- PRIMARY |
MaoLu | 937cf42 | 2017-03-03 23:31:46 -0800 | [diff] [blame] | 34 | * -----------| OPS | | | NETWORK |
Andrea Campanella | dadf640 | 2019-08-07 15:24:11 +0200 | [diff] [blame^] | 35 | * 3 | |---|-----|--- SECONDARY |
| 36 | * |_____________________| | 2 | |
| 37 | * |_____| |
MaoLu | 937cf42 | 2017-03-03 23:31:46 -0800 | [diff] [blame] | 38 | * Uses flow to set switch path. |
| 39 | * network port = 0, client port = 3, AUTO mode. |
| 40 | * network port = 1 or 2, client port = 3, MANUAL mode. |
MaoLu | 937cf42 | 2017-03-03 23:31:46 -0800 | [diff] [blame] | 41 | */ |
| 42 | |
| 43 | public class OplinkSwitchPowerConfig extends AbstractHandlerBehaviour |
Andrea Campanella | dadf640 | 2019-08-07 15:24:11 +0200 | [diff] [blame^] | 44 | implements PowerConfig<Object> { |
MaoLu | 937cf42 | 2017-03-03 23:31:46 -0800 | [diff] [blame] | 45 | |
| 46 | // oplink power config utility |
| 47 | private OplinkPowerConfigUtil oplinkUtil = new OplinkPowerConfigUtil(this); |
| 48 | |
| 49 | @Override |
Andrea Campanella | dadf640 | 2019-08-07 15:24:11 +0200 | [diff] [blame^] | 50 | public Optional<Double> getTargetPower(PortNumber port, Object component) { |
| 51 | Long power = oplinkUtil.getTargetPower(port, component); |
| 52 | if (power == null) { |
| 53 | return Optional.empty(); |
| 54 | } |
| 55 | return Optional.of(power.doubleValue()); |
MaoLu | 937cf42 | 2017-03-03 23:31:46 -0800 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | @Override |
Andrea Campanella | dadf640 | 2019-08-07 15:24:11 +0200 | [diff] [blame^] | 59 | public Optional<Double> currentPower(PortNumber port, Object component) { |
| 60 | Long power = oplinkUtil.getCurrentPower(port, component); |
| 61 | if (power == null) { |
| 62 | return Optional.empty(); |
| 63 | } |
| 64 | return Optional.of(power.doubleValue()); |
MaoLu | 937cf42 | 2017-03-03 23:31:46 -0800 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | @Override |
Andrea Campanella | dadf640 | 2019-08-07 15:24:11 +0200 | [diff] [blame^] | 68 | public void setTargetPower(PortNumber port, Object component, double power) { |
| 69 | oplinkUtil.setTargetPower(port, component, (long) power); |
MaoLu | 937cf42 | 2017-03-03 23:31:46 -0800 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | @Override |
Andrea Campanella | dadf640 | 2019-08-07 15:24:11 +0200 | [diff] [blame^] | 73 | public Optional<Range<Double>> getTargetPowerRange(PortNumber port, Object component) { |
| 74 | Range<Long> power = oplinkUtil.getTargetPowerRange(port, component); |
| 75 | if (power == null) { |
| 76 | return Optional.empty(); |
| 77 | } |
| 78 | return Optional.of(Range.closed((double) power.lowerEndpoint(), (double) power.upperEndpoint())); |
MaoLu | 937cf42 | 2017-03-03 23:31:46 -0800 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | @Override |
Andrea Campanella | dadf640 | 2019-08-07 15:24:11 +0200 | [diff] [blame^] | 82 | public Optional<Range<Double>> getInputPowerRange(PortNumber port, Object component) { |
| 83 | Range<Long> power = oplinkUtil.getInputPowerRange(port, component); |
| 84 | if (power == null) { |
| 85 | return Optional.empty(); |
| 86 | } |
| 87 | return Optional.of(Range.closed((double) power.lowerEndpoint(), (double) power.upperEndpoint())); |
MaoLu | 937cf42 | 2017-03-03 23:31:46 -0800 | [diff] [blame] | 88 | } |
| 89 | } |