use of org.onosproject.net.driver.DriverHandler in project onos by opennetworkinglab.
the class OvsdbControllerConfig method getControllers.
@Override
public List<ControllerInfo> getControllers() {
DriverHandler handler = handler();
OvsdbClientService clientService = getOvsdbClientService(handler);
Set<ControllerInfo> controllers = clientService.getControllers(handler().data().deviceId());
return new ArrayList<>(controllers);
}
use of org.onosproject.net.driver.DriverHandler in project onos by opennetworkinglab.
the class OvsdbControllerConfig method setControllers.
@Override
public void setControllers(List<ControllerInfo> controllers) {
DriverHandler handler = handler();
OvsdbClientService clientService = getOvsdbClientService(handler);
if (!clientService.getControllers(handler().data().deviceId()).equals(ImmutableSet.copyOf(controllers))) {
clientService.setControllersWithDeviceId(handler().data().deviceId(), controllers);
}
}
use of org.onosproject.net.driver.DriverHandler in project onos by opennetworkinglab.
the class OvsdbControllerConfig method getOvsdbClientService.
// Used for getting OvsdbClientService.
private OvsdbClientService getOvsdbClientService(DriverHandler handler) {
OvsdbController ovsController = handler.get(OvsdbController.class);
DeviceService deviceService = handler.get(DeviceService.class);
DeviceId ofDeviceId = handler.data().deviceId();
String[] mgmtAddress = deviceService.getDevice(ofDeviceId).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, ofDeviceId))).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;
}
use of org.onosproject.net.driver.DriverHandler 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.driver.DriverHandler in project onos by opennetworkinglab.
the class OvsdbMirroringConfig method addMirroring.
/**
* Adds a mirroring with a given description.
*
* @param bridge the bridge name
* @param mirroringDescription mirroring description
* @return true if succeeds, or false
*/
@Override
public boolean addMirroring(BridgeName bridge, MirroringDescription mirroringDescription) {
DriverHandler handler = handler();
OvsdbClientService ovsdbClient = getOvsdbClientService(handler);
OvsdbMirror mirror = OvsdbMirror.builder(mirroringDescription).build();
return ovsdbClient.createMirror(bridge.name(), mirror);
}
Aggregations