use of org.onosproject.net.device.DeviceService in project onos by opennetworkinglab.
the class OvsdbMirroringConfig method getOvsdbClientService.
/**
* Helper method which is used for getting OvsdbClientService.
*/
private OvsdbClientService getOvsdbClientService(DriverHandler handler) {
OvsdbController ovsController = handler.get(OvsdbController.class);
DeviceService deviceService = handler.get(DeviceService.class);
DeviceId deviceId = handler.data().deviceId();
String[] splits = deviceId.toString().split(":");
if (splits == null || splits.length < 1) {
log.warn("Wrong deviceId format");
return null;
}
/**
* Each type of device has to be managed in a different way.
*/
switch(splits[0]) {
case "ovsdb":
OvsdbNodeId nodeId = changeDeviceIdToNodeId(deviceId);
return ovsController.getOvsdbClient(nodeId);
case "of":
String[] mgmtAddress = deviceService.getDevice(deviceId).annotations().value(AnnotationKeys.MANAGEMENT_ADDRESS).split(":");
String targetIp = mgmtAddress[0];
TpPort targetPort = null;
if (mgmtAddress.length > 1) {
targetPort = TpPort.tpPort(Integer.parseInt(mgmtAddress[1]));
}
List<OvsdbNodeId> nodeIds = ovsController.getNodeIds().stream().filter(nodeID -> nodeID.getIpAddress().equals(targetIp)).collect(Collectors.toList());
if (nodeIds.isEmpty()) {
// TODO decide what port?
ovsController.connect(IpAddress.valueOf(targetIp), targetPort == null ? TpPort.tpPort(OvsdbConstant.OVSDBPORT) : targetPort);
// FIXME... connect is async
delay(1000);
}
List<OvsdbClientService> clientServices = ovsController.getNodeIds().stream().filter(nodeID -> nodeID.getIpAddress().equals(targetIp)).map(ovsController::getOvsdbClient).filter(cs -> cs.getBridges().stream().anyMatch(b -> dpidMatches(b, deviceId))).collect(Collectors.toList());
checkState(!clientServices.isEmpty(), "No clientServices found");
// FIXME add connection to management address if null --> done ?
return !clientServices.isEmpty() ? clientServices.get(0) : null;
default:
log.warn("Unmanaged device type");
}
return null;
}
use of org.onosproject.net.device.DeviceService 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.device.DeviceService 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.device.DeviceService 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());
}
use of org.onosproject.net.device.DeviceService in project onos by opennetworkinglab.
the class OpenRoadmNetconfHandlerBehaviour method getDevice.
/**
* Get the device instance for which the methods apply.
*
* @return The device instance
*/
protected Device getDevice() {
DeviceService deviceService = checkNotNull(handler().get(DeviceService.class));
Device device = deviceService.getDevice(did());
return device;
}
Aggregations