Search in sources :

Example 11 with RestSBController

use of org.onosproject.protocol.rest.RestSBController in project onos by opennetworkinglab.

the class DellRestPortDiscovery method getPorts.

@Deprecated
public List<PortDescription> getPorts() {
    List<PortDescription> ports = Lists.newArrayList();
    DriverHandler handler = handler();
    RestSBController controller = checkNotNull(handler.get(RestSBController.class));
    DeviceId deviceId = handler.data().deviceId();
    String remotePortName = "";
    // read configuration from REST API
    HierarchicalConfiguration config = XmlConfigParser.loadXml(controller.get(deviceId, INTERFACES_REQUEST, MediaType.valueOf("*/*")));
    // get the interfaces part
    List<HierarchicalConfiguration> portsConfig = parseDellPorts(config);
    portsConfig.stream().forEach(sub -> {
        String portName = sub.getString(NAME);
        DefaultAnnotations.Builder annotations = DefaultAnnotations.builder().set(AnnotationKeys.PORT_NAME, portName);
        // TODO: obtain proper port speed and type
        long portSpeed = 10_000;
        Port.Type portType = Port.Type.COPPER;
        PortNumber portNumber = PortNumber.fromString(remotePortName.replaceAll(TENGINTERFACENAME, ""));
        ports.add(DefaultPortDescription.builder().withPortNumber(portNumber).isEnabled(true).type(portType).portSpeed(portSpeed).annotations(annotations.build()).build());
    });
    return ImmutableList.copyOf(ports);
}
Also used : DefaultAnnotations(org.onosproject.net.DefaultAnnotations) DeviceId(org.onosproject.net.DeviceId) Port(org.onosproject.net.Port) DefaultPortDescription(org.onosproject.net.device.DefaultPortDescription) PortDescription(org.onosproject.net.device.PortDescription) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration) RestSBController(org.onosproject.protocol.rest.RestSBController) DriverHandler(org.onosproject.net.driver.DriverHandler) PortNumber(org.onosproject.net.PortNumber)

Example 12 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)

Example 13 with RestSBController

use of org.onosproject.protocol.rest.RestSBController in project onos by opennetworkinglab.

the class AristaUtils method getWithChecking.

public static boolean getWithChecking(DriverHandler handler, List<String> commands) {
    RestSBController controller = checkNotNull(handler.get(RestSBController.class));
    DeviceId deviceId = checkNotNull(handler.data()).deviceId();
    String response = generate(commands);
    log.debug("request :{}", response);
    try {
        ObjectMapper om = new ObjectMapper();
        JsonNode json = om.readTree(response);
        JsonNode errNode = json.findPath(ERROR);
        if (errNode.isMissingNode()) {
            return true;
        }
        log.error("Error get with checking {}", errNode.asText(""));
        for (String str : commands) {
            log.error("Command Failed due to Cmd : {}", str);
        }
        return false;
    } catch (IOException e) {
        log.error("IO exception occured because of ", e);
        return false;
    }
}
Also used : RestSBController(org.onosproject.protocol.rest.RestSBController) DeviceId(org.onosproject.net.DeviceId) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 14 with RestSBController

use of org.onosproject.protocol.rest.RestSBController in project onos by opennetworkinglab.

the class CiscoNxosDeviceDescription method discoverPortDetails.

@Override
public List<PortDescription> discoverPortDetails() {
    DriverHandler handler = handler();
    RestSBController controller = checkNotNull(handler.get(RestSBController.class));
    DeviceId deviceId = handler.data().deviceId();
    ArrayList<String> cmd = new ArrayList<>();
    cmd.add(SHOW_INTERFACES_CMD);
    String req = NxApiRequest.generate(cmd, NxApiRequest.CommandType.CLI);
    String response = NxApiRequest.post(controller, deviceId, req);
    // parse interface information from response
    List<PortDescription> ports = Lists.newArrayList();
    try {
        ObjectMapper om = new ObjectMapper();
        JsonNode json = om.readTree(response);
        JsonNode interfaces = json.findValue(ROW_INTERFACE);
        if (interfaces != null) {
            interfaces.forEach(itf -> {
                String ifName = itf.get(INTERFACE).asText();
                if (ifName.startsWith(ETH)) {
                    String ifNum = ifName.substring(ETHERNET.length()).replace(SLASH, ZERO);
                    boolean state = itf.get(STATE).asText().equals(UP);
                    // in Mbps
                    long portSpeed = itf.get(ETH_BW).asLong() / ONE_THOUSAND;
                    DefaultAnnotations.Builder annotations = DefaultAnnotations.builder().set(AnnotationKeys.PORT_NAME, ifName);
                    PortDescription desc = DefaultPortDescription.builder().withPortNumber(PortNumber.portNumber(ifNum)).isEnabled(state).type(Port.Type.FIBER).portSpeed(portSpeed).annotations(annotations.build()).build();
                    ports.add(desc);
                }
            });
        }
    } catch (IOException e) {
        log.error("Failed to to retrieve Interfaces {}", e);
    }
    return ports;
}
Also used : DefaultAnnotations(org.onosproject.net.DefaultAnnotations) DeviceId(org.onosproject.net.DeviceId) ArrayList(java.util.ArrayList) PortDescription(org.onosproject.net.device.PortDescription) DefaultPortDescription(org.onosproject.net.device.DefaultPortDescription) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) RestSBController(org.onosproject.protocol.rest.RestSBController) DriverHandler(org.onosproject.net.driver.DriverHandler) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 15 with RestSBController

use of org.onosproject.protocol.rest.RestSBController in project onos by opennetworkinglab.

the class CiscoNxosPortStatistics method discoverPortStatistics.

@Override
public Collection<PortStatistics> discoverPortStatistics() {
    DriverHandler handler = handler();
    RestSBController controller = checkNotNull(handler.get(RestSBController.class));
    DeviceId deviceId = handler.data().deviceId();
    DeviceService deviceService = this.handler().get(DeviceService.class);
    List<Port> ports = deviceService.getPorts(deviceId);
    Collection<PortStatistics> portStatistics = Lists.newArrayList();
    ports.stream().filter(Port::isEnabled).forEach(port -> portStatistics.add(discoverSpecifiedPortStatistics(port, controller, deviceId)));
    return ImmutableList.copyOf(portStatistics);
}
Also used : RestSBController(org.onosproject.protocol.rest.RestSBController) DeviceId(org.onosproject.net.DeviceId) Port(org.onosproject.net.Port) DriverHandler(org.onosproject.net.driver.DriverHandler) DeviceService(org.onosproject.net.device.DeviceService) PortStatistics(org.onosproject.net.device.PortStatistics) DefaultPortStatistics(org.onosproject.net.device.DefaultPortStatistics)

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