Search in sources :

Example 1 with RestSBController

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());
}
Also used : ChassisId(org.onlab.packet.ChassisId) DeviceId(org.onosproject.net.DeviceId) Device(org.onosproject.net.Device) ArrayList(java.util.ArrayList) DeviceService(org.onosproject.net.device.DeviceService) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) RestSBController(org.onosproject.protocol.rest.RestSBController) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) DriverHandler(org.onosproject.net.driver.DriverHandler) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with RestSBController

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);
}
Also used : StringBufferInputStream(java.io.StringBufferInputStream) RestSBController(org.onosproject.protocol.rest.RestSBController) DeviceId(org.onosproject.net.DeviceId) StringBufferInputStream(java.io.StringBufferInputStream) InputStream(java.io.InputStream) DriverHandler(org.onosproject.net.driver.DriverHandler)

Example 3 with RestSBController

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;
}
Also used : DeviceId(org.onosproject.net.DeviceId) RestSBController(org.onosproject.protocol.rest.RestSBController) ImmutableList(com.google.common.collect.ImmutableList) DeviceConnection(org.onosproject.drivers.odtn.impl.DeviceConnection) FlowRule(org.onosproject.net.flow.FlowRule)

Example 4 with RestSBController

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();
    }
}
Also used : RestSBController(org.onosproject.protocol.rest.RestSBController) DeviceId(org.onosproject.net.DeviceId) Device(org.onosproject.net.Device) InputStream(java.io.InputStream) Port(org.onosproject.net.Port) DeviceService(org.onosproject.net.device.DeviceService) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 5 with RestSBController

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();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ByteArrayInputStream(java.io.ByteArrayInputStream) RestSBController(org.onosproject.protocol.rest.RestSBController) DeviceId(org.onosproject.net.DeviceId) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

RestSBController (org.onosproject.protocol.rest.RestSBController)19 DeviceId (org.onosproject.net.DeviceId)17 InputStream (java.io.InputStream)8 DriverHandler (org.onosproject.net.driver.DriverHandler)8 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)7 IOException (java.io.IOException)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)6 ByteArrayInputStream (java.io.ByteArrayInputStream)4 PortDescription (org.onosproject.net.device.PortDescription)4 StringBufferInputStream (java.io.StringBufferInputStream)3 DefaultAnnotations (org.onosproject.net.DefaultAnnotations)3 Port (org.onosproject.net.Port)3 DeviceService (org.onosproject.net.device.DeviceService)3 ImmutableList (com.google.common.collect.ImmutableList)2 ArrayList (java.util.ArrayList)2 HierarchicalConfiguration (org.apache.commons.configuration.HierarchicalConfiguration)2 Device (org.onosproject.net.Device)2 DefaultPortDescription (org.onosproject.net.device.DefaultPortDescription)2 FlowRule (org.onosproject.net.flow.FlowRule)2 OchPortHelper.ochPortDescription (org.onosproject.net.optical.device.OchPortHelper.ochPortDescription)2