blob: ab7b8e547df8a7624abd2a8412d31fb4a2224cc0 [file] [log] [blame]
MaoLu937cf422017-03-03 23:31:46 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
MaoLu937cf422017-03-03 23:31:46 -08003 *
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
17package org.onosproject.driver.optical.power;
18
19import java.util.Optional;
20
21import com.google.common.collect.Range;
22import org.onosproject.net.driver.AbstractHandlerBehaviour;
23import org.onosproject.net.PortNumber;
24import org.onosproject.net.behaviour.PowerConfig;
25
26/**
27 * Port Power implementation for Oplink protection switch device.
Andrea Campanelladadf6402019-08-07 15:24:11 +020028 * <p>
MaoLu937cf422017-03-03 23:31:46 -080029 * Intruduction:
Andrea Campanelladadf6402019-08-07 15:24:11 +020030 * _____
31 * _____________________ | | 0 VIRTUAL
32 * | | | 1 |
33 * CLIENT | |---|-----|--- PRIMARY
MaoLu937cf422017-03-03 23:31:46 -080034 * -----------| OPS | | | NETWORK
Andrea Campanelladadf6402019-08-07 15:24:11 +020035 * 3 | |---|-----|--- SECONDARY
36 * |_____________________| | 2 |
37 * |_____|
MaoLu937cf422017-03-03 23:31:46 -080038 * 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.
MaoLu937cf422017-03-03 23:31:46 -080041 */
42
43public class OplinkSwitchPowerConfig extends AbstractHandlerBehaviour
Andrea Campanelladadf6402019-08-07 15:24:11 +020044 implements PowerConfig<Object> {
MaoLu937cf422017-03-03 23:31:46 -080045
46 // oplink power config utility
47 private OplinkPowerConfigUtil oplinkUtil = new OplinkPowerConfigUtil(this);
48
49 @Override
Andrea Campanelladadf6402019-08-07 15:24:11 +020050 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());
MaoLu937cf422017-03-03 23:31:46 -080056 }
57
58 @Override
Andrea Campanelladadf6402019-08-07 15:24:11 +020059 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());
MaoLu937cf422017-03-03 23:31:46 -080065 }
66
67 @Override
Andrea Campanelladadf6402019-08-07 15:24:11 +020068 public void setTargetPower(PortNumber port, Object component, double power) {
69 oplinkUtil.setTargetPower(port, component, (long) power);
MaoLu937cf422017-03-03 23:31:46 -080070 }
71
72 @Override
Andrea Campanelladadf6402019-08-07 15:24:11 +020073 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()));
MaoLu937cf422017-03-03 23:31:46 -080079 }
80
81 @Override
Andrea Campanelladadf6402019-08-07 15:24:11 +020082 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()));
MaoLu937cf422017-03-03 23:31:46 -080088 }
89}