use of org.onosproject.net.device.PortDescription in project onos by opennetworkinglab.
the class OplinkHandshakerUtil method buildPortPowerDescriptions.
/**
* Creates port descriptions with current power.
*
* @param portPowers current power
* @return port descriptions
*/
public List<PortDescription> buildPortPowerDescriptions(List<OFOplinkPortPower> portPowers) {
DeviceService deviceService = driver.handler().get(DeviceService.class);
List<Port> ports = deviceService.getPorts(driver.data().deviceId());
HashMap<Long, OFOplinkPortPower> powerMap = new HashMap<>(portPowers.size());
// Get each port power value
portPowers.forEach(power -> powerMap.put((long) power.getPort(), power));
final List<PortDescription> portDescs = new ArrayList<>();
for (Port port : ports) {
DefaultAnnotations.Builder builder = DefaultAnnotations.builder();
builder.putAll(port.annotations());
OFOplinkPortPower power = powerMap.get(port.number().toLong());
if (power != null) {
// power value is actually signed-short value, down casting to recover sign bit.
builder.set(OpticalAnnotations.CURRENT_POWER, Short.toString((short) power.getPowerValue()));
}
portDescs.add(DefaultPortDescription.builder().withPortNumber(port.number()).isEnabled(port.isEnabled()).type(port.type()).portSpeed(port.portSpeed()).annotations(builder.build()).build());
}
return portDescs;
}
use of org.onosproject.net.device.PortDescription in project onos by opennetworkinglab.
the class OplinkSwitchHandshaker method buildPortDescriptions.
private List<PortDescription> buildPortDescriptions(List<OFCalientPortStatsEntry> entries) {
DeviceService deviceService = this.handler().get(DeviceService.class);
List<Port> ports = deviceService.getPorts(this.data().deviceId());
HashMap<Long, OFCalientPortStatsEntry> statsMap = new HashMap<>(entries.size());
entries.forEach(entry -> statsMap.put((long) entry.getPortNo().getPortNumber(), entry));
final List<PortDescription> portDescs = new ArrayList<>();
for (Port port : ports) {
DefaultAnnotations.Builder builder = DefaultAnnotations.builder();
builder.putAll(port.annotations());
// set fingerprint for the virtual port (port 0)
if (port.number().toLong() == PROTECTION_VIRTUAL_PORT) {
builder.set(ProtectionConfigBehaviour.FINGERPRINT, PROTECTION_FINGERPRINT);
}
OFCalientPortStatsEntry entry = statsMap.get(port.number().toLong());
if (entry == null) {
continue;
}
builder.set(CURRENT_POWER, entry.getInportPower());
builder.set(OUTPUT_POWER, entry.getOutportPower());
// We just use this code for a short term, and will modify in the future.
if (entry.getInOperStatus().isEmpty()) {
builder.set(INPUT_PORT_STATUS, STATUS_IN_SERVICE);
} else {
builder.set(INPUT_PORT_STATUS, STATUS_OUT_SERVICE);
}
if (entry.getOutOperStatus().isEmpty()) {
builder.set(OUTPUT_PORT_STATUS, STATUS_IN_SERVICE);
} else {
builder.set(OUTPUT_PORT_STATUS, STATUS_OUT_SERVICE);
}
portDescs.add(DefaultPortDescription.builder().withPortNumber(port.number()).isEnabled(port.isEnabled()).type(port.type()).portSpeed(port.portSpeed()).annotations(builder.build()).build());
}
return portDescs;
}
use of org.onosproject.net.device.PortDescription in project onos by opennetworkinglab.
the class GnmiTerminalDeviceDiscovery method discoverPortDetails.
@Override
public List<PortDescription> discoverPortDetails() {
if (!setupBehaviour("discoverPortDetails()")) {
return Collections.emptyList();
}
// Get all components
Gnmi.Path path = GnmiPathBuilder.newBuilder().addElem("components").addElem("component").withKeyValue("name", "*").build();
Gnmi.GetRequest req = Gnmi.GetRequest.newBuilder().addPath(path).setEncoding(Gnmi.Encoding.PROTO).build();
Gnmi.GetResponse resp;
try {
resp = client.get(req).get();
} catch (ExecutionException | InterruptedException e) {
log.warn("unable to get components via gNMI: {}", e.getMessage());
return Collections.emptyList();
}
Multimap<String, Gnmi.Update> componentUpdates = HashMultimap.create();
resp.getNotificationList().stream().map(Gnmi.Notification::getUpdateList).flatMap(List::stream).forEach(u -> {
// Get component name
// /components/component[name=?]
Gnmi.Path p = u.getPath();
if (p.getElemCount() < 2) {
// Invalid path
return;
}
String name = p.getElem(1).getKeyOrDefault("name", null);
// name -> a set of gNMI updates
if (name != null) {
componentUpdates.put(name, u);
}
});
Stream<PortDescription> normalPorts = super.discoverPortDetails().stream();
Stream<PortDescription> opticalPorts = componentUpdates.keySet().stream().map(name -> convertComponentToOdtnPortDesc(name, componentUpdates.get(name))).filter(Objects::nonNull);
return Streams.concat(normalPorts, opticalPorts).collect(Collectors.toList());
}
use of org.onosproject.net.device.PortDescription in project onos by opennetworkinglab.
the class OpenRoadmDeviceDescription method discoverPortDetails.
/**
* Returns a list of PortDescriptions for the device.
*
* @return a list of descriptions.
*/
/*
* Assumptions: ROADM degree ports are Oms carrying 80 lambdas (should be
* configurable)
* ROADM SRG (client) ports are OCh carrying ODU4 (should be
* configurable)
*/
@Override
public List<PortDescription> discoverPortDetails() {
NetconfSession session = getNetconfSession(did());
if (session == null) {
log.error("discoverPortDetails null session for {}", did());
return ImmutableList.of();
}
if (!getDevice().annotations().keys().contains("openroadm-node-id")) {
log.error("Unable to run PortDiscovery: missing openroadm-node-id annotation." + " Probable failure during DeviceDiscovery. Aborting!");
return ImmutableList.of();
}
List<HierarchicalConfiguration> externalLinks = getExternalLinks(session);
List<PortDescription> list = new ArrayList<PortDescription>();
discoverDegreePorts(session, list, externalLinks);
discoverSrgPorts(session, list, externalLinks);
return list;
}
use of org.onosproject.net.device.PortDescription in project onos by opennetworkinglab.
the class OvsdbBridgeConfig method getPorts.
@Override
public Collection<PortDescription> getPorts() {
OvsdbClientService client = getOvsdbClientService(handler());
if (client == null) {
return Collections.emptyList();
}
Set<OvsdbPort> ports = client.getPorts();
return ports.stream().map(x -> DefaultPortDescription.builder().withPortNumber(PortNumber.portNumber(x.portNumber().value())).isEnabled(true).annotations(DefaultAnnotations.builder().set("portName", x.portName().value()).build()).build()).collect(Collectors.toSet());
}
Aggregations