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();
}
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);
}
}
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();
}
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();
}
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();
}
Aggregations