Search in sources :

Example 16 with RestSBController

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

the class LinkDiscoveryCiscoImpl method retrieveResponse.

private String retrieveResponse(String command) {
    DriverHandler handler = handler();
    RestSBController controller = checkNotNull(handler.get(RestSBController.class));
    DeviceId deviceId = handler.data().deviceId();
    String req = NxApiRequest.generate(Lists.newArrayList(command), NxApiRequest.CommandType.CLI);
    log.debug("request :" + req);
    InputStream stream = new ByteArrayInputStream(req.getBytes(StandardCharsets.UTF_8));
    return controller.post(deviceId, "/ins", stream, MediaType.valueOf("application/json-rpc"), String.class);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) RestSBController(org.onosproject.protocol.rest.RestSBController) DeviceId(org.onosproject.net.DeviceId) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DriverHandler(org.onosproject.net.driver.DriverHandler)

Example 17 with RestSBController

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

the class NxApiRequest method postClis.

/**
 * Sends NX-API request message to the device.
 * @param handler device's driver handler
 * @param cmds NX-API list of command strings
 * @return the response string
 */
public static String postClis(DriverHandler handler, List<String> cmds) {
    RestSBController controller = checkNotNull(handler.get(RestSBController.class));
    DeviceId deviceId = handler.data().deviceId();
    String request = generate(cmds, CommandType.CLI);
    InputStream stream = new ByteArrayInputStream(request.getBytes(StandardCharsets.UTF_8));
    return controller.post(deviceId, API_URI, stream, MediaType.valueOf(APP_JSON_RPC), String.class);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) RestSBController(org.onosproject.protocol.rest.RestSBController) DeviceId(org.onosproject.net.DeviceId) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream)

Example 18 with RestSBController

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

the class NxApiRequest method post.

/**
 * Sends NX-API request message to the device.
 * @param handler device's driver handler
 * @param command NX-API command string
 * @param type response message format
 * @return the response string
 */
public static String post(DriverHandler handler, String command, CommandType type) {
    RestSBController controller = checkNotNull(handler.get(RestSBController.class));
    DeviceId deviceId = handler.data().deviceId();
    String request = generate(command, type);
    return post(controller, deviceId, request);
}
Also used : RestSBController(org.onosproject.protocol.rest.RestSBController) DeviceId(org.onosproject.net.DeviceId)

Example 19 with RestSBController

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

the class CienaWaveserverDeviceDescription method getPorts.

private List<PortDescription> getPorts() {
    /*
         * Relationship between ptp-index and port number shown in Ciena Wave Server
         * CLI:
         *      ptp-index = 4 * port_number (without decimal) + decimal
         *      e.g
         *          if port_number is 5 then ptp-index = 5 * 4 + 0 = 20
         *          if port_number is 5.1 then ptp-index = 5 * 4 + 1 = 21
         *
         * Relationship between channelId and in/out port:
         *      in_port = channelId * 2
         *      out_port = channelId * 2 -1
         */
    List<PortDescription> ports = Lists.newArrayList();
    RestSBController controller = checkNotNull(handler().get(RestSBController.class));
    DeviceId deviceId = handler().data().deviceId();
    HierarchicalConfiguration config = XmlConfigParser.loadXml(controller.get(deviceId, PORT_REQUEST, MediaType.APPLICATION_XML_TYPE));
    List<HierarchicalConfiguration> portsConfig = parseWaveServerCienaPorts(config);
    portsConfig.forEach(sub -> {
        String portId = sub.getString(PORT_ID);
        DefaultAnnotations.Builder annotations = DefaultAnnotations.builder();
        if (CienaRestDevice.getLinesidePortId().contains(portId)) {
            annotations.set(AnnotationKeys.CHANNEL_ID, sub.getString(CHANNEL_ID));
            // TX/OUT and RX/IN ports
            annotations.set(AnnotationKeys.PORT_OUT, sub.getString(PORT_OUT));
            annotations.set(AnnotationKeys.PORT_IN, sub.getString(PORT_IN));
            ports.add(parseWaveServerCienaOchPorts(Long.valueOf(portId), sub, annotations.build()));
        } else if (!portId.equals("5") && !portId.equals("49")) {
            DefaultAnnotations.builder().set(AnnotationKeys.PORT_NAME, portId);
            // FIXME change when all optical types have two way information methods, see jira tickets
            ports.add(oduCltPortDescription(PortNumber.portNumber(sub.getLong(PORT_ID)), sub.getString(ADMIN_STATE).equals(ENABLED), CltSignalType.CLT_100GBE, annotations.build()));
        }
    });
    return ImmutableList.copyOf(ports);
}
Also used : DefaultAnnotations(org.onosproject.net.DefaultAnnotations) RestSBController(org.onosproject.protocol.rest.RestSBController) DeviceId(org.onosproject.net.DeviceId) OchPortHelper.ochPortDescription(org.onosproject.net.optical.device.OchPortHelper.ochPortDescription) PortDescription(org.onosproject.net.device.PortDescription) OduCltPortHelper.oduCltPortDescription(org.onosproject.net.optical.device.OduCltPortHelper.oduCltPortDescription) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration)

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