use of org.onosproject.net.Port 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.Port in project onos by opennetworkinglab.
the class OplinkPowerConfigUtil method getPortPower.
/**
* Find specified port power from port description.
*
* @param portNum the port number
* @param annotation annotation in port description
* @return power value in 0.01 dBm
*/
private Long getPortPower(PortNumber portNum, String annotation) {
// Check if switch is connected, otherwise do not return value in store, which is obsolete.
if (getOpenFlowDevice() == null) {
// Warning already exists in method getOpenFlowDevice()
return null;
}
final DriverHandler handler = behaviour.handler();
DeviceService deviceService = handler.get(DeviceService.class);
Port port = deviceService.getPort(handler.data().deviceId(), portNum);
if (port == null) {
log.warn("Unexpected port: {}", portNum);
return null;
}
String power = port.annotations().value(annotation);
if (power == null) {
// Do not need warning here for port polling.
log.debug("Cannot get {} from port {}.", annotation, portNum);
return null;
}
return Long.valueOf(power);
}
use of org.onosproject.net.Port in project onos by opennetworkinglab.
the class TapiDeviceLambdaQuery method queryLambdas.
@Override
public Set<OchSignal> queryLambdas(PortNumber port) {
RestSBController controller = checkNotNull(handler().get(RestSBController.class));
DeviceService deviceService = checkNotNull(handler().get(DeviceService.class));
DeviceId deviceId = did();
Device dev = deviceService.getDevice(deviceId);
if (dev == null) {
log.error("Device {} does not exist", deviceId);
return ImmutableSet.of();
}
Port p = deviceService.getPort(dev.id(), port);
if (p == null) {
log.error("Port {} does not exist", port);
return ImmutableSet.of();
}
String uuid = p.annotations().value(UUID);
try {
InputStream inputStream = controller.get(deviceId, SIP_REQUEST_DATA_API + uuid, MediaType.APPLICATION_JSON_TYPE);
log.debug("Service interface point UUID: {}", uuid);
JsonNode sipAttributes = new ObjectMapper().readTree(inputStream);
JsonNode mcPool = sipAttributes.get(MEDIA_CHANNEL_SERVICE_INTERFACE_POINT_SPEC).get(MC_POOL);
// This creates a hashset of OChSignals representing the spectrum availability at the target port.
return TapiDeviceHelper.getOchSignal(mcPool);
} catch (IOException e) {
log.error("Exception discoverPortDetails() {}", did(), e);
return ImmutableSet.of();
}
}
use of org.onosproject.net.Port in project onos by opennetworkinglab.
the class DefaultTributarySlotQuery method queryTributarySlots.
@Override
public Set<TributarySlot> queryTributarySlots(PortNumber port) {
// currently return all slots by default.
DeviceService deviceService = opticalView(this.handler().get(DeviceService.class));
Port p = deviceService.getPort(this.data().deviceId(), port);
if (p == null) {
return Collections.emptySet();
}
switch(p.type()) {
case OCH:
return queryOchTributarySlots(p);
case OTU:
return queryOtuTributarySlots(p);
default:
return Collections.emptySet();
}
}
use of org.onosproject.net.Port in project onos by opennetworkinglab.
the class OFOpticalSwitch13LambdaQuery method queryLambdas.
@Override
public Set<OchSignal> queryLambdas(PortNumber port) {
DeviceService deviceService = opticalView(this.handler().get(DeviceService.class));
Port p = deviceService.getPort(this.data().deviceId(), port);
// Only OMS ports expose lambda resources
if (p == null || !p.type().equals(Port.Type.OMS)) {
return Collections.emptySet();
}
short lambdaCount = ((OmsPort) p).totalChannels();
// OMS ports expose 'lambdaCount' fixed grid lambdas of 50GHz width, starting from min-frequency 191.7 THz.
return IntStream.rangeClosed(1, lambdaCount).mapToObj(x -> OchSignal.newDwdmSlot(ChannelSpacing.CHL_50GHZ, x)).collect(GuavaCollectors.toImmutableSet());
}
Aggregations