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