Search in sources :

Example 11 with DriverHandler

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

the class PortQueryVlansCommand method printVlans.

private void printVlans(Port port) {
    DeviceService deviceService = get(DeviceService.class);
    DriverService driverService = get(DriverService.class);
    DeviceId deviceId = (DeviceId) port.element().id();
    Device device = deviceService.getDevice(deviceId);
    if (!device.is(VlanQuery.class)) {
        // The relevant behavior is not supported by the device.
        print(NO_SUPPORT);
        return;
    }
    DriverHandler h = driverService.createHandler(deviceId);
    VlanQuery vlanQuery = h.behaviour(VlanQuery.class);
    try {
        Set<VlanId> vlanIds = vlanQuery.queryVlanIds(port.number());
        if (vlanIds.isEmpty()) {
            print(VLAN_NOT_AVAILABLE);
        } else {
            print(AVAIL_VLANS, getRanges(vlanIds).toString());
        }
    } catch (Exception e) {
        print(FAILURE + e.getMessage());
    }
}
Also used : DeviceId(org.onosproject.net.DeviceId) Device(org.onosproject.net.Device) DeviceService(org.onosproject.net.device.DeviceService) DriverHandler(org.onosproject.net.driver.DriverHandler) VlanQuery(org.onosproject.net.behaviour.VlanQuery) VlanId(org.onlab.packet.VlanId) DriverService(org.onosproject.net.driver.DriverService)

Example 12 with DriverHandler

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

the class OplinkPowerConfigUtil method addAttenuation.

/**
 * Replace flow with new flow containing Oplink attenuation extension instruction. Also resets metrics.
 *
 * @param flowEntry flow entry
 * @param power power value
 */
private void addAttenuation(FlowEntry flowEntry, long power) {
    FlowRule.Builder flowBuilder = new DefaultFlowRule.Builder().withCookie(flowEntry.id().value()).withPriority(flowEntry.priority()).forDevice(flowEntry.deviceId()).forTable(flowEntry.tableId());
    if (flowEntry.isPermanent()) {
        flowBuilder.makePermanent();
    } else {
        flowBuilder.makeTemporary(flowEntry.timeout());
    }
    flowBuilder.withSelector(flowEntry.selector());
    // Copy original instructions and add attenuation instruction
    TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
    flowEntry.treatment().allInstructions().forEach(ins -> treatmentBuilder.add(ins));
    final DriverHandler handler = behaviour.handler();
    treatmentBuilder.add(Instructions.extension(new OplinkAttenuation((int) power), handler.data().deviceId()));
    flowBuilder.withTreatment(treatmentBuilder.build());
    FlowRuleService service = handler.get(FlowRuleService.class);
    service.applyFlowRules(flowBuilder.build());
}
Also used : DriverHandler(org.onosproject.net.driver.DriverHandler) OplinkAttenuation(org.onosproject.driver.extensions.OplinkAttenuation) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) FlowRuleService(org.onosproject.net.flow.FlowRuleService)

Example 13 with DriverHandler

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

the class OplinkPowerConfigUtil method getOpenFlowDevice.

/**
 * Returns current switch known to this OF controller.
 *
 * @return current switch
 */
private OpenFlowSwitch getOpenFlowDevice() {
    final DriverHandler handler = behaviour.handler();
    final OpenFlowController controller = handler.get(OpenFlowController.class);
    final Dpid dpid = Dpid.dpid(handler.data().deviceId().uri());
    OpenFlowSwitch sw = controller.getSwitch(dpid);
    if (sw == null || !sw.isConnected()) {
        log.warn("OpenFlow handshaker driver not found or device is not connected, dpid = {}", dpid);
        return null;
    }
    return sw;
}
Also used : Dpid(org.onosproject.openflow.controller.Dpid) OpenFlowSwitch(org.onosproject.openflow.controller.OpenFlowSwitch) DriverHandler(org.onosproject.net.driver.DriverHandler) OpenFlowController(org.onosproject.openflow.controller.OpenFlowController)

Example 14 with DriverHandler

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

the class OplinkPowerConfigUtil method getPortPower.

/**
 * Find specified port power from port description.
 *
 * @param portNum the port number
 * @param annotation annotation in port description
 * @return power value in 0.01 dBm
 */
private Long getPortPower(PortNumber portNum, String annotation) {
    // Check if switch is connected, otherwise do not return value in store, which is obsolete.
    if (getOpenFlowDevice() == null) {
        // Warning already exists in method getOpenFlowDevice()
        return null;
    }
    final DriverHandler handler = behaviour.handler();
    DeviceService deviceService = handler.get(DeviceService.class);
    Port port = deviceService.getPort(handler.data().deviceId(), portNum);
    if (port == null) {
        log.warn("Unexpected port: {}", portNum);
        return null;
    }
    String power = port.annotations().value(annotation);
    if (power == null) {
        // Do not need warning here for port polling.
        log.debug("Cannot get {} from port {}.", annotation, portNum);
        return null;
    }
    return Long.valueOf(power);
}
Also used : Port(org.onosproject.net.Port) DriverHandler(org.onosproject.net.driver.DriverHandler) DeviceService(org.onosproject.net.device.DeviceService)

Example 15 with DriverHandler

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

the class OplinkPowerConfigUtil method setChannelAttenuation.

/**
 * Sets specified channle attenuation.
 *
 * @param portNum the port number
 * @param och channel signal
 * @param power attenuation in 0.01 dB
 */
private void setChannelAttenuation(PortNumber portNum, OchSignal och, long power) {
    FlowEntry flowEntry = findFlow(portNum, och);
    if (flowEntry == null) {
        log.warn("Target channel power not set");
        return;
    }
    final DriverHandler handler = behaviour.handler();
    for (Instruction ins : flowEntry.treatment().allInstructions()) {
        if (ins.type() != Instruction.Type.EXTENSION) {
            continue;
        }
        ExtensionTreatment ext = ((Instructions.ExtensionInstructionWrapper) ins).extensionInstruction();
        if (ext.type() == ExtensionTreatmentType.ExtensionTreatmentTypes.OPLINK_ATTENUATION.type()) {
            ((OplinkAttenuation) ext).setAttenuation((int) power);
            FlowRuleService service = handler.get(FlowRuleService.class);
            service.applyFlowRules(flowEntry);
            return;
        }
    }
    addAttenuation(flowEntry, power);
}
Also used : DriverHandler(org.onosproject.net.driver.DriverHandler) OplinkAttenuation(org.onosproject.driver.extensions.OplinkAttenuation) Instruction(org.onosproject.net.flow.instructions.Instruction) FlowRuleService(org.onosproject.net.flow.FlowRuleService) FlowEntry(org.onosproject.net.flow.FlowEntry) ExtensionTreatment(org.onosproject.net.flow.instructions.ExtensionTreatment)

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