Search in sources :

Example 6 with FlowRuleService

use of org.onosproject.net.flow.FlowRuleService in project onos by opennetworkinglab.

the class TableStatisticsCommand method doExecute.

@Override
protected void doExecute() {
    FlowRuleService flowService = get(FlowRuleService.class);
    DeviceService deviceService = get(DeviceService.class);
    SortedMap<Device, List<TableStatisticsEntry>> deviceTableStats = getSortedTableStats(deviceService, flowService);
    if (outputJson()) {
        print("%s", json(deviceTableStats.keySet(), deviceTableStats));
    } else {
        deviceTableStats.forEach((device, tableStats) -> printTableStats(device, tableStats));
    }
}
Also used : Device(org.onosproject.net.Device) DeviceService(org.onosproject.net.device.DeviceService) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) FlowRuleService(org.onosproject.net.flow.FlowRuleService)

Example 7 with FlowRuleService

use of org.onosproject.net.flow.FlowRuleService 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)

Example 8 with FlowRuleService

use of org.onosproject.net.flow.FlowRuleService 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 9 with FlowRuleService

use of org.onosproject.net.flow.FlowRuleService in project onos by opennetworkinglab.

the class FlowsWebResource method getPendingFlows.

/**
 * Gets all pending flow entries. Returns array of all pending flow rules in the system.
 *
 * @return 200 OK with a collection of flows
 * @onos.rsModel FlowEntries
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("pending")
public Response getPendingFlows() {
    ObjectNode root = mapper().createObjectNode();
    ArrayNode flowsNode = root.putArray(FLOWS);
    FlowRuleService service = get(FlowRuleService.class);
    Iterable<Device> devices = get(DeviceService.class).getDevices();
    for (Device device : devices) {
        Iterable<FlowEntry> flowEntries = service.getFlowEntries(device.id());
        if (flowEntries != null) {
            for (FlowEntry entry : flowEntries) {
                if ((entry.state() == FlowEntry.FlowEntryState.PENDING_ADD) || (entry.state() == FlowEntry.FlowEntryState.PENDING_REMOVE)) {
                    flowsNode.add(codec(FlowEntry.class).encode(entry, this));
                }
            }
        }
    }
    return ok(root).build();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Device(org.onosproject.net.Device) DeviceService(org.onosproject.net.device.DeviceService) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) FlowRuleService(org.onosproject.net.flow.FlowRuleService) FlowEntry(org.onosproject.net.flow.FlowEntry) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 10 with FlowRuleService

use of org.onosproject.net.flow.FlowRuleService in project onos by opennetworkinglab.

the class FlowsWebResource method removeFlowByAppId.

/**
 * Removes flow rules by application ID.
 * Removes a collection of flow rules generated by the given application.
 *
 * @param appId application identifier
 * @return 204 NO CONTENT
 */
@DELETE
@Produces(MediaType.APPLICATION_JSON)
@Path("application/{appId}")
public Response removeFlowByAppId(@PathParam("appId") String appId) {
    FlowRuleService service = get(FlowRuleService.class);
    ApplicationService appService = get(ApplicationService.class);
    ApplicationId idInstant = nullIsNotFound(appService.getId(appId), APP_ID_NOT_FOUND);
    service.removeFlowRulesById(idInstant);
    return Response.noContent().build();
}
Also used : FlowRuleService(org.onosproject.net.flow.FlowRuleService) ApplicationId(org.onosproject.core.ApplicationId) ApplicationService(org.onosproject.app.ApplicationService) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces)

Aggregations

FlowRuleService (org.onosproject.net.flow.FlowRuleService)51 FlowEntry (org.onosproject.net.flow.FlowEntry)23 CoreService (org.onosproject.core.CoreService)18 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)16 DeviceService (org.onosproject.net.device.DeviceService)16 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)14 Produces (javax.ws.rs.Produces)14 ApplicationId (org.onosproject.core.ApplicationId)13 Device (org.onosproject.net.Device)13 Path (javax.ws.rs.Path)12 FlowRule (org.onosproject.net.flow.FlowRule)12 GET (javax.ws.rs.GET)11 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)11 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)10 List (java.util.List)9 TrafficSelector (org.onosproject.net.flow.TrafficSelector)9 DeviceId (org.onosproject.net.DeviceId)8 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)7 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)7 IOException (java.io.IOException)6