use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.
the class FlowRuleManager method removeFlowRulesById.
@Override
public void removeFlowRulesById(ApplicationId id) {
checkPermission(FLOWRULE_WRITE);
Set<FlowRule> flowEntries = Sets.newHashSet();
for (Device d : deviceService.getDevices()) {
for (FlowEntry flowEntry : store.getFlowEntries(d.id())) {
if (flowEntry.appId() == id.id()) {
flowEntries.add(flowEntry);
}
}
}
removeFlowRules(Iterables.toArray(flowEntries, FlowRule.class));
}
use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.
the class FlowRuleJuniperImpl method getFlowEntries.
@Override
public Collection<FlowEntry> getFlowEntries() {
DeviceId devId = checkNotNull(this.data().deviceId());
NetconfSession session = lookupNetconfSession(devId);
if (session == null) {
return Collections.emptyList();
}
// Installed static routes
String reply;
try {
reply = session.get(routingTableBuilder());
} catch (NetconfException e) {
throw new IllegalStateException(new NetconfException("Failed to retrieve configuration.", e));
}
Collection<StaticRoute> devicesStaticRoutes = JuniperUtils.parseRoutingTable(loadXmlString(reply));
// Expected FlowEntries installed
FlowRuleService flowRuleService = this.handler().get(FlowRuleService.class);
Iterable<FlowEntry> flowEntries = flowRuleService.getFlowEntries(devId);
Collection<FlowEntry> installedRules = new HashSet<>();
flowEntries.forEach(flowEntry -> {
Optional<IPCriterion> ipCriterion = getIpCriterion(flowEntry);
if (!ipCriterion.isPresent()) {
return;
}
Optional<OutputInstruction> output = getOutput(flowEntry);
if (!output.isPresent()) {
return;
}
// convert FlowRule into static route
getStaticRoute(devId, ipCriterion.get(), output.get(), flowEntry.priority()).ifPresent(staticRoute -> {
if (staticRoute.isLocalRoute()) {
// if the FlowRule is in PENDING_REMOVE or REMOVED, it is not reported.
if (flowEntry.state() == PENDING_REMOVE || flowEntry.state() == REMOVED) {
devicesStaticRoutes.remove(staticRoute);
} else {
// FlowRule is reported installed
installedRules.add(flowEntry);
devicesStaticRoutes.remove(staticRoute);
}
} else {
// if the route is found in the device, the FlowRule is reported installed.
if (devicesStaticRoutes.contains(staticRoute)) {
installedRules.add(flowEntry);
devicesStaticRoutes.remove(staticRoute);
}
}
});
});
if (!devicesStaticRoutes.isEmpty()) {
log.info("Found static routes on device {} not installed by ONOS: {}", devId, devicesStaticRoutes);
// FIXME: enable configuration to purge already installed flows.
// It cannot be allowed by default because it may remove needed management routes
// log.warn("Removing from device {} the FlowEntries not expected {}", deviceId, devicesStaticRoutes);
// devicesStaticRoutes.forEach(staticRoute -> editRoute(session, REMOVE, staticRoute));
}
return installedRules;
}
use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.
the class OplinkPowerConfigUtil method getChannelAttenuation.
/**
* Gets specified channel attenuation.
*
* @param portNum the port number
* @param och channel signal
* @return atteuation in 0.01 dB
*/
private Long getChannelAttenuation(PortNumber portNum, OchSignal och) {
FlowEntry flowEntry = findFlow(portNum, och);
if (flowEntry == null) {
return null;
}
List<Instruction> instructions = flowEntry.treatment().allInstructions();
for (Instruction ins : instructions) {
if (ins.type() != Instruction.Type.EXTENSION) {
continue;
}
ExtensionTreatment ext = ((Instructions.ExtensionInstructionWrapper) ins).extensionInstruction();
if (ext.type() == ExtensionTreatmentType.ExtensionTreatmentTypes.OPLINK_ATTENUATION.type()) {
return (long) ((OplinkAttenuation) ext).getAttenuation();
}
}
return null;
}
use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.
the class OplinkPowerConfigUtil method findFlow.
/**
* Find matching flow on device.
*
* @param portNum the port number
* @param och channel signal
* @return flow entry
*/
private FlowEntry findFlow(PortNumber portNum, OchSignal och) {
final DriverHandler handler = behaviour.handler();
FlowRuleService service = handler.get(FlowRuleService.class);
Iterable<FlowEntry> flowEntries = service.getFlowEntries(handler.data().deviceId());
// Return first matching flow
for (FlowEntry entry : flowEntries) {
TrafficSelector selector = entry.selector();
OchSignalCriterion entrySigid = (OchSignalCriterion) selector.getCriterion(Criterion.Type.OCH_SIGID);
// Check channel
if (entrySigid != null && och.equals(entrySigid.lambda())) {
// Check input port
PortCriterion entryPort = (PortCriterion) selector.getCriterion(Criterion.Type.IN_PORT);
if (entryPort != null && portNum.equals(entryPort.port())) {
return entry;
}
// Check output port
TrafficTreatment treatment = entry.treatment();
for (Instruction instruction : treatment.allInstructions()) {
if (instruction.type() == Instruction.Type.OUTPUT && ((Instructions.OutputInstruction) instruction).port().equals(portNum)) {
return entry;
}
}
}
}
log.warn("No matching flow found");
return null;
}
use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.
the class OplinkOpticalUtility method toFlowRule.
/**
* Finds the FlowRule from flow rule store by the given ports and channel.
* Returns an extra flow to remove the flow by ONOS if not found.
* @param behaviour the parent driver handler
* @param inPort the input port
* @param outPort the output port
* @param channel the specified channel
* @return the flow rule
*/
public static FlowRule toFlowRule(HandlerBehaviour behaviour, PortNumber inPort, PortNumber outPort, Integer channel) {
FlowRuleService service = behaviour.handler().get(FlowRuleService.class);
Iterable<FlowEntry> entries = service.getFlowEntries(behaviour.data().deviceId());
// Try to Find the flow from flow rule store.
for (FlowEntry entry : entries) {
Set<Criterion> criterions = entry.selector().criteria();
// input port
PortNumber ip = criterions.stream().filter(c -> c instanceof PortCriterion).map(c -> ((PortCriterion) c).port()).findAny().orElse(null);
// channel
Integer ch = criterions.stream().filter(c -> c instanceof OchSignalCriterion).map(c -> ((OchSignalCriterion) c).lambda().spacingMultiplier()).findAny().orElse(null);
// output port
PortNumber op = entry.treatment().immediate().stream().filter(c -> c instanceof Instructions.OutputInstruction).map(c -> ((Instructions.OutputInstruction) c).port()).findAny().orElse(null);
if (inPort.equals(ip) && channel.equals(ch) && outPort.equals(op)) {
// Find the flow.
return entry;
}
}
// Cannot find the flow from store. So report an extra flow to remove the flow by ONOS.
TrafficSelector selector = DefaultTrafficSelector.builder().matchInPort(inPort).add(Criteria.matchOchSignalType(OchSignalType.FIXED_GRID)).add(Criteria.matchLambda(Lambda.ochSignal(GRID_TYPE, CHANNEL_SPACING, channel, SLOT_GRANULARITY))).build();
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(outPort).build();
return DefaultFlowRule.builder().forDevice(behaviour.data().deviceId()).withSelector(selector).withTreatment(treatment).withPriority(DEFAULT_PRIORITY).makePermanent().fromApp(behaviour.handler().get(CoreService.class).getAppId(DEFAULT_APP)).build();
}
Aggregations