mirror of
https://github.com/opennetworkinglab/onos.git
synced 2026-05-05 04:06:49 +02:00
Support power config ports retrieval
Change-Id: If0535eb713ca76bffdf43891d28e6357402246ac
This commit is contained in:
parent
4e3780ef25
commit
8cd61fb0a8
@ -20,6 +20,8 @@ import com.google.common.collect.Range;
|
||||
import org.onosproject.net.PortNumber;
|
||||
import org.onosproject.net.driver.HandlerBehaviour;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
@ -87,4 +89,15 @@ public interface PowerConfig<T> extends HandlerBehaviour {
|
||||
default Optional<Range<Long>> getInputPowerRange(PortNumber port, T component) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ports, which support {@code PowerConfig} operations for the specified
|
||||
* {@code component}.
|
||||
*
|
||||
* @param component the port component
|
||||
* @return a set of power config ports
|
||||
*/
|
||||
default List<PortNumber> getPorts(T component) {
|
||||
return new ArrayList<PortNumber>();
|
||||
}
|
||||
}
|
||||
|
||||
@ -54,6 +54,7 @@ public final class PolatisNetconfUtility {
|
||||
public static final String KEY_DATA_PORTCONFIG = String.format("%s.%s.%s", KEY_DATA, KEY_PORTCONFIG, KEY_PORT);
|
||||
public static final String KEY_OPM = "opm-power";
|
||||
public static final String KEY_OPM_XMLNS = String.format("%s %s", KEY_OPM, KEY_XMLNS);
|
||||
public static final String KEY_DATA_OPM = String.format("%s.%s.%s", KEY_DATA, KEY_OPM, KEY_PORT);
|
||||
public static final String KEY_POWER = "power";
|
||||
public static final String KEY_DATA_OPM_PORT = String.format("%s.%s.%s", KEY_DATA, KEY_OPM, KEY_PORT);
|
||||
public static final String OPTICAL_CAPABILITY_PREFIX
|
||||
|
||||
@ -25,6 +25,8 @@ import org.onosproject.net.behaviour.PowerConfig;
|
||||
import org.onosproject.net.driver.AbstractHandlerBehaviour;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.onosproject.drivers.polatis.netconf.PolatisOpticalUtility.POWER_MULTIPLIER;
|
||||
@ -70,12 +72,41 @@ public class PolatisPowerConfig<T> extends AbstractHandlerBehaviour
|
||||
return Optional.ofNullable(getRxPowerRange(port, component));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PortNumber> getPorts(T component) {
|
||||
if (component instanceof OchSignal) {
|
||||
log.warn("Channel component is not applicable.");
|
||||
return new ArrayList<PortNumber>();
|
||||
}
|
||||
log.debug("Get port config ports...");
|
||||
return acquirePorts();
|
||||
}
|
||||
|
||||
private List<PortNumber> acquirePorts() {
|
||||
String filter = getPortPowerFilter(null);
|
||||
String reply = netconfGet(handler(), filter);
|
||||
List<HierarchicalConfiguration> subtrees = configsAt(reply, KEY_DATA_OPM);
|
||||
List<PortNumber> ports = new ArrayList<PortNumber>();
|
||||
for (HierarchicalConfiguration portConfig : subtrees) {
|
||||
ports.add(PortNumber.portNumber(portConfig.getLong(KEY_PORTID)));
|
||||
}
|
||||
return ports;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the filter string for the OPM power NETCONF request.
|
||||
*
|
||||
* @param port the port, null to return all the opm ports
|
||||
* @return filter string
|
||||
*/
|
||||
private String getPortPowerFilter(PortNumber port) {
|
||||
return new StringBuilder(xmlOpen(KEY_OPM_XMLNS))
|
||||
StringBuilder filter = new StringBuilder(xmlOpen(KEY_OPM_XMLNS))
|
||||
.append(xmlOpen(KEY_PORT))
|
||||
.append(xmlOpen(KEY_PORTID))
|
||||
.append(port.toLong())
|
||||
.append(xmlClose(KEY_PORTID))
|
||||
.append(xmlOpen(KEY_PORTID));
|
||||
if (port != null) {
|
||||
filter.append(port.toLong());
|
||||
}
|
||||
return filter.append(xmlClose(KEY_PORTID))
|
||||
.append(xmlClose(KEY_PORT))
|
||||
.append(xmlClose(KEY_OPM))
|
||||
.toString();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user