use of org.onosproject.protocol.rest.RestSBController in project onos by opennetworkinglab.
the class CiscoNxosDeviceDescription method discoverDeviceDetails.
@Override
public DeviceDescription discoverDeviceDetails() {
DriverHandler handler = handler();
RestSBController controller = checkNotNull(handler.get(RestSBController.class));
DeviceId deviceId = handler.data().deviceId();
ArrayList<String> cmd = new ArrayList<>();
cmd.add(SHOW_VERSION_CMD);
String req = NxApiRequest.generate(cmd, NxApiRequest.CommandType.CLI);
String response = NxApiRequest.post(controller, deviceId, req);
String mrf = UNKNOWN;
String hwVer = UNKNOWN;
String swVer = UNKNOWN;
String serialNum = UNKNOWN;
try {
ObjectMapper om = new ObjectMapper();
JsonNode json = om.readTree(response);
JsonNode body = json.findValue("body");
if (body != null) {
mrf = body.get(MANUFACTURER).asText();
hwVer = body.get(CHASSIS_ID).asText();
swVer = body.get(KICKSTART_VER).asText();
}
} catch (IOException e) {
log.error("Failed to to retrieve Device Information {}", e);
}
DeviceService deviceService = checkNotNull(handler().get(DeviceService.class));
Device device = deviceService.getDevice(deviceId);
return new DefaultDeviceDescription(device.id().uri(), Device.Type.SWITCH, mrf, hwVer, swVer, serialNum, new ChassisId(), (SparseAnnotations) device.annotations());
}
use of org.onosproject.protocol.rest.RestSBController in project onos by opennetworkinglab.
the class DellRestOpenFlowControllerConfig method setControllers.
// Example test with ONOS CLI:
// device-setcontrollers rest:10.251.217.143:8008 tcp:1.2.3.4:2222
// TODO: assumes that of-instance 1 was in "no shutdown" state,
// check previous state
@Override
public void setControllers(List<ControllerInfo> controllers) {
// Dell supports max 2 controllers per of-instance
if (controllers.size() > MAX_CONTROLLERS) {
log.warn("Cannot set more than 2 controllers.");
}
DriverHandler handler = handler();
RestSBController controller = checkNotNull(handler.get(RestSBController.class));
DeviceId deviceId = handler.data().deviceId();
String controllerCommands = getControllerCommands(controllers).stream().reduce(String::concat).orElse("");
InputStream payload = new StringBufferInputStream(String.format(SET_CONTROLLERS_XML, controllerCommands));
String resp = controller.post(deviceId, CLI_REQUEST, payload, MediaType.valueOf("*/*"), String.class);
log.info("{}", resp);
}
use of org.onosproject.protocol.rest.RestSBController in project onos by opennetworkinglab.
the class TapiFlowRuleProgrammable method removeFlowRules.
@Override
public Collection<FlowRule> removeFlowRules(Collection<FlowRule> rules) {
DeviceId deviceId = handler().data().deviceId();
RestSBController controller = checkNotNull(handler().get(RestSBController.class));
ImmutableList.Builder<FlowRule> removed = ImmutableList.builder();
rules.forEach(flowRule -> {
DeviceConnection conn = getConnectionCache().get(deviceId, flowRule.id());
if (conn == null || conn.getId() == null) {
log.warn("Can't find associate device connection for flow {} and device {}", flowRule.id(), deviceId);
return;
}
CompletableFuture<Integer> flowRemoval = CompletableFuture.supplyAsync(() -> controller.delete(deviceId, CONN_REQ_REMOVE_DATA_API + conn.getId(), null, MediaType.APPLICATION_JSON_TYPE));
flowRemoval.thenApply(result -> {
if (result == HttpStatus.SC_NO_CONTENT) {
getConnectionCache().remove(deviceId, flowRule);
removed.add(flowRule);
} else {
log.error("Can't remove flow {}, result {}", flowRule, result);
}
return result;
});
});
// TODO workaround for blocking call on ADVA OLS shoudl return removed
return rules;
}
use of org.onosproject.protocol.rest.RestSBController 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.protocol.rest.RestSBController in project onos by opennetworkinglab.
the class AristaUtils method retrieveCommandResult.
public static Optional<JsonNode> retrieveCommandResult(DriverHandler handler, List<String> cmds) {
RestSBController controller = checkNotNull(handler.get(RestSBController.class));
DeviceId deviceId = checkNotNull(handler.data()).deviceId();
String request = generate(cmds);
log.debug("request :{}", request);
String response = controller.post(deviceId, API_ENDPOINT, new ByteArrayInputStream(request.getBytes()), MediaType.APPLICATION_JSON_TYPE, String.class);
log.debug("response :{}", response);
try {
ObjectMapper mapper = new ObjectMapper();
ObjectNode node = (ObjectNode) mapper.readTree(response);
if (node.has(ERROR)) {
log.error("Error {}", node.get(ERROR));
return Optional.empty();
} else {
return Optional.ofNullable(node.get(RESULT));
}
} catch (IOException e) {
log.warn("IO exception occurred because of ", e);
}
return Optional.empty();
}
Aggregations