Search in sources :

Example 91 with DriverHandler

use of org.onosproject.net.driver.DriverHandler 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 92 with DriverHandler

use of org.onosproject.net.driver.DriverHandler 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)

Example 93 with DriverHandler

use of org.onosproject.net.driver.DriverHandler 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 94 with DriverHandler

use of org.onosproject.net.driver.DriverHandler in project onos by opennetworkinglab.

the class OplinkPowerConfigUtil method findFlow.

/**
 * Find matching flow on device.
 *
 * @param portNum the port number
 * @param och channel signal
 * @return flow entry
 */
private FlowEntry findFlow(PortNumber portNum, OchSignal och) {
    final DriverHandler handler = behaviour.handler();
    FlowRuleService service = handler.get(FlowRuleService.class);
    Iterable<FlowEntry> flowEntries = service.getFlowEntries(handler.data().deviceId());
    // Return first matching flow
    for (FlowEntry entry : flowEntries) {
        TrafficSelector selector = entry.selector();
        OchSignalCriterion entrySigid = (OchSignalCriterion) selector.getCriterion(Criterion.Type.OCH_SIGID);
        // Check channel
        if (entrySigid != null && och.equals(entrySigid.lambda())) {
            // Check input port
            PortCriterion entryPort = (PortCriterion) selector.getCriterion(Criterion.Type.IN_PORT);
            if (entryPort != null && portNum.equals(entryPort.port())) {
                return entry;
            }
            // Check output port
            TrafficTreatment treatment = entry.treatment();
            for (Instruction instruction : treatment.allInstructions()) {
                if (instruction.type() == Instruction.Type.OUTPUT && ((Instructions.OutputInstruction) instruction).port().equals(portNum)) {
                    return entry;
                }
            }
        }
    }
    log.warn("No matching flow found");
    return null;
}
Also used : OchSignalCriterion(org.onosproject.net.flow.criteria.OchSignalCriterion) DriverHandler(org.onosproject.net.driver.DriverHandler) TrafficSelector(org.onosproject.net.flow.TrafficSelector) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) FlowRuleService(org.onosproject.net.flow.FlowRuleService) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Instruction(org.onosproject.net.flow.instructions.Instruction) FlowEntry(org.onosproject.net.flow.FlowEntry)

Example 95 with DriverHandler

use of org.onosproject.net.driver.DriverHandler in project onos by opennetworkinglab.

the class OvsdbBridgeConfig method getLocalPorts.

@Override
public List<PortNumber> getLocalPorts(Iterable<String> ifaceIds) {
    List<PortNumber> ports = new ArrayList<>();
    DriverHandler handler = handler();
    OvsdbClientService client = getOvsdbClientService(handler);
    if (client == null) {
        return Collections.emptyList();
    }
    Set<OvsdbPort> ovsdbSet = client.getLocalPorts(ifaceIds);
    ovsdbSet.forEach(o -> {
        PortNumber port = PortNumber.portNumber(o.portNumber().value(), o.portName().value());
        ports.add(port);
    });
    return ports;
}
Also used : OvsdbClientService(org.onosproject.ovsdb.controller.OvsdbClientService) ArrayList(java.util.ArrayList) DriverHandler(org.onosproject.net.driver.DriverHandler) PortNumber(org.onosproject.net.PortNumber) OvsdbPort(org.onosproject.ovsdb.controller.OvsdbPort)

Aggregations

DriverHandler (org.onosproject.net.driver.DriverHandler)104 DeviceId (org.onosproject.net.DeviceId)46 DriverService (org.onosproject.net.driver.DriverService)22 NetconfController (org.onosproject.netconf.NetconfController)22 NetconfException (org.onosproject.netconf.NetconfException)22 MastershipService (org.onosproject.mastership.MastershipService)20 ArrayList (java.util.ArrayList)12 DefaultDriverHandler (org.onosproject.net.driver.DefaultDriverHandler)12 ItemNotFoundException (org.onlab.util.ItemNotFoundException)9 DeviceService (org.onosproject.net.device.DeviceService)9 OvsdbClientService (org.onosproject.ovsdb.controller.OvsdbClientService)9 DefaultDriverData (org.onosproject.net.driver.DefaultDriverData)8 Driver (org.onosproject.net.driver.Driver)8 Test (org.junit.Test)7 ControllerInfo (org.onosproject.net.behaviour.ControllerInfo)6 RestSBController (org.onosproject.protocol.rest.RestSBController)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 PolicerConfigurable (org.onosproject.net.behaviour.trafficcontrol.PolicerConfigurable)5 PolicerId (org.onosproject.net.behaviour.trafficcontrol.PolicerId)5