Search in sources :

Example 36 with FlowRuleService

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

the class FlowsWebResource method getFlowByDeviceIdAndFlowId.

/**
 * Gets flow rules. Returns the flow entry specified by the device id and
 * flow rule id.
 *
 * @param deviceId device identifier
 * @param flowId   flow rule identifier
 * @return 200 OK with a collection of flows of given device and flow
 * @onos.rsModel FlowEntries
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{deviceId}/{flowId}")
public Response getFlowByDeviceIdAndFlowId(@PathParam("deviceId") String deviceId, @PathParam("flowId") long flowId) {
    FlowRuleService service = get(FlowRuleService.class);
    ObjectNode root = mapper().createObjectNode();
    ArrayNode flowsNode = root.putArray(FLOWS);
    Iterable<FlowEntry> flowEntries = service.getFlowEntries(DeviceId.deviceId(deviceId));
    if (flowEntries == null || !flowEntries.iterator().hasNext()) {
        throw new ItemNotFoundException(DEVICE_NOT_FOUND);
    }
    for (FlowEntry entry : flowEntries) {
        if (entry.id().value() == flowId) {
            flowsNode.add(codec(FlowEntry.class).encode(entry, this));
        }
    }
    return ok(root).build();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) FlowRuleService(org.onosproject.net.flow.FlowRuleService) FlowEntry(org.onosproject.net.flow.FlowEntry) ItemNotFoundException(org.onlab.util.ItemNotFoundException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 37 with FlowRuleService

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

the class FlowsWebResource method createFlow.

/**
 * Creates new flow rule. Creates and installs a new flow rule for the
 * specified device. <br>
 * Flow rule criteria and instruction description:
 * https://wiki.onosproject.org/display/ONOS/Flow+Rules
 *
 * @param deviceId device identifier
 * @param appId    application identifier
 * @param stream   flow rule JSON
 * @return status of the request - CREATED if the JSON is correct,
 * BAD_REQUEST if the JSON is invalid
 * @onos.rsModel FlowsPost
 */
@POST
@Path("{deviceId}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response createFlow(@PathParam("deviceId") String deviceId, @QueryParam("appId") String appId, InputStream stream) {
    FlowRuleService service = get(FlowRuleService.class);
    try {
        ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
        JsonNode specifiedDeviceId = jsonTree.get("deviceId");
        if (specifiedDeviceId != null && !specifiedDeviceId.asText().equals(deviceId)) {
            throw new IllegalArgumentException("Invalid deviceId in flow creation request");
        }
        jsonTree.put("deviceId", deviceId);
        if (appId != null) {
            jsonTree.put("appId", appId);
        }
        FlowRule rule = codec(FlowRule.class).decode(jsonTree, this);
        service.applyFlowRules(rule);
        UriBuilder locationBuilder = uriInfo.getBaseUriBuilder().path("flows").path(deviceId).path(Long.toString(rule.id().value()));
        return Response.created(locationBuilder.build()).build();
    } catch (IOException ex) {
        throw new IllegalArgumentException(ex);
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) FlowRule(org.onosproject.net.flow.FlowRule) IOException(java.io.IOException) FlowRuleService(org.onosproject.net.flow.FlowRuleService) UriBuilder(javax.ws.rs.core.UriBuilder) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 38 with FlowRuleService

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

the class IntentsWebResource method getIntentFlowsById.

/**
 * Gets all related flow entries created by a particular intent.
 * Returns all flow entries of the specified intent.
 *
 * @param appId application identifier
 * @param key   intent key
 * @return 200 OK with intent data
 * @onos.rsModel Relatedflows
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("relatedflows/{appId}/{key}")
public Response getIntentFlowsById(@PathParam("appId") String appId, @PathParam("key") String key) {
    ApplicationId applicationId = get(CoreService.class).getAppId(appId);
    nullIsNotFound(applicationId, APP_ID_NOT_FOUND);
    IntentService intentService = get(IntentService.class);
    FlowRuleService flowService = get(FlowRuleService.class);
    Intent intent = intentService.getIntent(Key.of(key, applicationId));
    if (intent == null) {
        long numericalKey = Long.decode(key);
        intent = intentService.getIntent(Key.of(numericalKey, applicationId));
    }
    nullIsNotFound(intent, INTENT_NOT_FOUND);
    ObjectNode root = mapper().createObjectNode();
    root.put(APP_ID, appId);
    root.put(ID, key);
    IntentFilter intentFilter = new IntentFilter(intentService, flowService);
    List<Intent> installables = intentService.getInstallableIntents(intent.key());
    root.put(INTENT_TYPE, intent.getClass().getSimpleName());
    ArrayNode pathsNode = root.putArray(INTENT_PATHS);
    for (List<FlowEntry> flowEntries : intentFilter.readIntentFlows(installables)) {
        ArrayNode flowNode = pathsNode.addArray();
        for (FlowEntry entry : flowEntries) {
            flowNode.add(codec(FlowEntry.class).encode(entry, this));
        }
    }
    return ok(root).build();
}
Also used : IntentService(org.onosproject.net.intent.IntentService) IntentFilter(org.onosproject.net.intent.util.IntentFilter) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) CoreService(org.onosproject.core.CoreService) Intent(org.onosproject.net.intent.Intent) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ApplicationId(org.onosproject.core.ApplicationId) 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 39 with FlowRuleService

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

the class StatisticsWebResource method getActiveEntriesCountPerDevice.

/**
 * Gets sum of active entries in all tables for all devices.
 *
 * @onos.rsModel StatisticsFlowsActiveEntries
 * @return 200 OK with JSON encoded array of active entry count per device
 */
@GET
@Path("flows/activeentries")
@Produces(MediaType.APPLICATION_JSON)
public Response getActiveEntriesCountPerDevice() {
    final FlowRuleService service = get(FlowRuleService.class);
    final Iterable<Device> devices = get(DeviceService.class).getDevices();
    final ObjectNode root = mapper().createObjectNode();
    final ArrayNode rootArrayNode = root.putArray("statistics");
    for (final Device device : devices) {
        int activeEntries = service.getFlowRuleCount(device.id(), FlowEntry.FlowEntryState.ADDED);
        final ObjectNode entry = mapper().createObjectNode();
        entry.put("device", device.id().toString());
        entry.put("activeEntries", activeEntries);
        rootArrayNode.add(entry);
    }
    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) ConnectPoint(org.onosproject.net.ConnectPoint) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 40 with FlowRuleService

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

the class CzechLightFlowRuleProgrammable method asFlowRule.

private FlowRule asFlowRule(final Direction direction, final CzechLightRouting routing) {
    FlowRuleService service = handler().get(FlowRuleService.class);
    Iterable<FlowEntry> entries = service.getFlowEntries(data().deviceId());
    final var portIn = PortNumber.portNumber(direction == Direction.DROP ? CzechLightDiscovery.PORT_COMMON : routing.leafPort);
    final var portOut = PortNumber.portNumber(direction == Direction.ADD ? CzechLightDiscovery.PORT_COMMON : routing.leafPort);
    final var channelWidth = routing.channel.highMHz - routing.channel.lowMHz;
    final var channelCentralFreq = (int) (routing.channel.lowMHz + channelWidth / 2);
    for (FlowEntry entry : entries) {
        final var och = ochSignalFromFlow(entry);
        if (och.centralFrequency().asMHz() == channelCentralFreq && och.slotWidth().asMHz() == channelWidth && portIn.equals(inputPortFromFlow(entry)) && portOut.equals(outputPortFromFlow(entry))) {
            return entry;
        }
    }
    final var channelSlotWidth = (int) (channelWidth / ChannelSpacing.CHL_12P5GHZ.frequency().asMHz());
    final var channelMultiplier = (int) ((channelCentralFreq - Spectrum.CENTER_FREQUENCY.asMHz()) / ChannelSpacing.CHL_6P25GHZ.frequency().asMHz());
    TrafficSelector selector = DefaultTrafficSelector.builder().matchInPort(portIn).add(Criteria.matchOchSignalType(OchSignalType.FLEX_GRID)).add(Criteria.matchLambda(Lambda.ochSignal(GridType.FLEX, ChannelSpacing.CHL_6P25GHZ, channelMultiplier, channelSlotWidth))).build();
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(portOut).build();
    return DefaultFlowRule.builder().forDevice(data().deviceId()).withSelector(selector).withTreatment(treatment).withPriority(666).makePermanent().fromApp(handler().get(CoreService.class).getAppId(DEFAULT_APP)).build();
}
Also used : TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) CoreService(org.onosproject.core.CoreService) FlowRuleService(org.onosproject.net.flow.FlowRuleService) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) FlowEntry(org.onosproject.net.flow.FlowEntry) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry)

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