use of org.onosproject.net.flow.FlowRuleService in project fabric-tna by stratum.
the class FabricIntProgrammable method setupBehaviour.
private boolean setupBehaviour() {
deviceId = this.data().deviceId();
flowRuleService = handler().get(FlowRuleService.class);
groupService = handler().get(GroupService.class);
cfgService = handler().get(NetworkConfigService.class);
hostService = handler().get(HostService.class);
final CoreService coreService = handler().get(CoreService.class);
appId = coreService.getAppId(Constants.APP_NAME);
if (appId == null) {
log.warn("Application ID is null. Cannot initialize behaviour.");
return false;
}
return true;
}
use of org.onosproject.net.flow.FlowRuleService 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.FlowRuleService in project onos by opennetworkinglab.
the class FabricPipelinerTest method setup.
@Before
public void setup() throws IOException {
FabricCapabilities capabilities = createMock(FabricCapabilities.class);
expect(capabilities.cpuPort()).andReturn(Optional.of(CPU_PORT)).anyTimes();
replay(capabilities);
// Services mock
flowRuleService = createMock(FlowRuleService.class);
pipeliner = new FabricPipeliner(capabilities);
pipeliner.flowRuleService = flowRuleService;
pipeliner.appId = APP_ID;
pipeliner.deviceId = DEVICE_ID;
}
use of org.onosproject.net.flow.FlowRuleService in project onos by opennetworkinglab.
the class WipeOutCommand method wipeOutFlows.
private void wipeOutFlows() {
print("Wiping Flows");
FlowRuleService flowRuleService = get(FlowRuleService.class);
DeviceAdminService deviceAdminService = get(DeviceAdminService.class);
for (Device device : deviceAdminService.getDevices()) {
flowRuleService.purgeFlowRules(device.id());
}
}
use of org.onosproject.net.flow.FlowRuleService in project onos by opennetworkinglab.
the class PolatisOpticalUtility 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
* @return the flow rule
*/
public static FlowRule toFlowRule(HandlerBehaviour behaviour, PortNumber inPort, PortNumber outPort) {
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);
// 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) && 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).build();
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(outPort).build();
return DefaultFlowRule.builder().forDevice(behaviour.data().deviceId()).withSelector(selector).withTreatment(treatment).makePermanent().withPriority(DEFAULT_PRIORITY).fromApp(behaviour.handler().get(CoreService.class).getAppId(DEFAULT_APP)).build();
}
Aggregations