Search in sources :

Example 26 with FlowRuleService

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;
}
Also used : HostService(org.onosproject.net.host.HostService) NetworkConfigService(org.onosproject.net.config.NetworkConfigService) CoreService(org.onosproject.core.CoreService) FlowRuleService(org.onosproject.net.flow.FlowRuleService) GroupService(org.onosproject.net.group.GroupService)

Example 27 with FlowRuleService

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;
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) DeviceId(org.onosproject.net.DeviceId) XmlConfigParser.loadXmlString(org.onosproject.drivers.utilities.XmlConfigParser.loadXmlString) NetconfException(org.onosproject.netconf.NetconfException) FlowRuleService(org.onosproject.net.flow.FlowRuleService) FlowEntry(org.onosproject.net.flow.FlowEntry) HashSet(java.util.HashSet)

Example 28 with FlowRuleService

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;
}
Also used : FabricCapabilities(org.onosproject.pipelines.fabric.impl.behaviour.FabricCapabilities) FlowRuleService(org.onosproject.net.flow.FlowRuleService) Before(org.junit.Before)

Example 29 with FlowRuleService

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());
    }
}
Also used : Device(org.onosproject.net.Device) DeviceAdminService(org.onosproject.net.device.DeviceAdminService) FlowRuleService(org.onosproject.net.flow.FlowRuleService)

Example 30 with FlowRuleService

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();
}
Also used : TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Instructions(org.onosproject.net.flow.instructions.Instructions) PortFormat(org.onosproject.yang.gen.v1.opticalswitch.rev20180322.opticalswitch.PortFormat) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) CoreService(org.onosproject.core.CoreService) Instruction(org.onosproject.net.flow.instructions.Instruction) Range(com.google.common.collect.Range) PortNumber(org.onosproject.net.PortNumber) FlowEntry(org.onosproject.net.flow.FlowEntry) Pair(org.onosproject.yang.gen.v1.opticalswitch.rev20180322.opticalswitch.crossconnects.Pair) Set(java.util.Set) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) HandlerBehaviour(org.onosproject.net.driver.HandlerBehaviour) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) List(java.util.List) FlowRuleService(org.onosproject.net.flow.FlowRuleService) TrafficSelector(org.onosproject.net.flow.TrafficSelector) CrossConnects(org.onosproject.yang.gen.v1.opticalswitch.rev20180322.opticalswitch.CrossConnects) DefaultPair(org.onosproject.yang.gen.v1.opticalswitch.rev20180322.opticalswitch.crossconnects.DefaultPair) FlowRule(org.onosproject.net.flow.FlowRule) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) Criterion(org.onosproject.net.flow.criteria.Criterion) DefaultCrossConnects(org.onosproject.yang.gen.v1.opticalswitch.rev20180322.opticalswitch.DefaultCrossConnects) CoreService(org.onosproject.core.CoreService) Instructions(org.onosproject.net.flow.instructions.Instructions) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) FlowRuleService(org.onosproject.net.flow.FlowRuleService) PortNumber(org.onosproject.net.PortNumber) FlowEntry(org.onosproject.net.flow.FlowEntry)

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