Search in sources :

Example 66 with FlowEntry

use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.

the class ECFlowRuleStoreTest method testPurgeFlow.

/**
 * Tests purge flow for a device.
 */
@Test
public void testPurgeFlow() {
    FlowEntry flowEntry = new DefaultFlowEntry(flowRule);
    flowStoreImpl.addOrUpdateFlowRule(flowEntry);
    FlowEntry flowEntry1 = new DefaultFlowEntry(flowRule1);
    flowStoreImpl.addOrUpdateFlowRule(flowEntry1);
    assertFlowsOnDevice(deviceId, 2);
    flowStoreImpl.purgeFlowRule(deviceId);
    assertFlowsOnDevice(deviceId, 0);
}
Also used : DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) FlowEntry(org.onosproject.net.flow.FlowEntry) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) Test(org.junit.Test)

Example 67 with FlowEntry

use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.

the class DistributedStatisticStore method removeFromStatistics.

@Override
public synchronized void removeFromStatistics(FlowRule rule) {
    ConnectPoint cp = buildConnectPoint(rule);
    if (cp == null) {
        return;
    }
    InternalStatisticRepresentation rep = representations.get(cp);
    if (rep != null && rep.remove(rule)) {
        updatePublishedStats(cp, Collections.emptySet());
    }
    Set<FlowEntry> values = current.get(cp);
    if (values != null) {
        values.remove(rule);
    }
    values = previous.get(cp);
    if (values != null) {
        values.remove(rule);
    }
}
Also used : ConnectPoint(org.onosproject.net.ConnectPoint) FlowEntry(org.onosproject.net.flow.FlowEntry)

Example 68 with FlowEntry

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;
}
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 69 with FlowEntry

use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.

the class LumentumSdnRoadmFlowRuleProgrammable method getFlowEntries.

@Override
public Collection<FlowEntry> getFlowEntries() {
    try {
        snmp = new LumentumSnmpDevice(handler().data().deviceId());
    } catch (IOException e) {
        log.error("Failed to connect to device: ", e);
        return Collections.emptyList();
    }
    // Line in is last but one port, line out is last
    DeviceService deviceService = this.handler().get(DeviceService.class);
    List<Port> ports = deviceService.getPorts(data().deviceId());
    if (ports.size() < 2) {
        return Collections.emptyList();
    }
    PortNumber lineIn = ports.get(ports.size() - 2).number();
    PortNumber lineOut = ports.get(ports.size() - 1).number();
    Collection<FlowEntry> entries = Lists.newLinkedList();
    // Add rules
    OID addOid = new OID(CTRL_CHANNEL_STATE + "1");
    entries.addAll(fetchRules(addOid, true, lineOut).stream().map(fr -> new DefaultFlowEntry(fr, FlowEntry.FlowEntryState.ADDED, 0, 0, 0)).collect(Collectors.toList()));
    // Drop rules
    OID dropOid = new OID(CTRL_CHANNEL_STATE + "2");
    entries.addAll(fetchRules(dropOid, false, lineIn).stream().map(fr -> new DefaultFlowEntry(fr, FlowEntry.FlowEntryState.ADDED, 0, 0, 0)).collect(Collectors.toList()));
    return entries;
}
Also used : DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) Port(org.onosproject.net.Port) DeviceService(org.onosproject.net.device.DeviceService) IOException(java.io.IOException) OID(org.snmp4j.smi.OID) PortNumber(org.onosproject.net.PortNumber) FlowEntry(org.onosproject.net.flow.FlowEntry) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry)

Example 70 with FlowEntry

use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.

the class FlowEntryBuilder method createFlowEntryForFlowMod.

private FlowEntry createFlowEntryForFlowMod(FlowEntryState... state) {
    FlowEntryState flowState = state.length > 0 ? state[0] : FlowEntryState.FAILED;
    FlowRule.Builder builder = DefaultFlowRule.builder().forDevice(deviceId).withSelector(buildSelector()).withTreatment(buildTreatment()).withPriority(flowMod.getPriority()).withIdleTimeout(flowMod.getIdleTimeout()).withCookie(flowMod.getCookie().getValue());
    if (flowMod.getVersion() != OFVersion.OF_10) {
        builder.forTable(flowMod.getTableId().getValue());
    }
    if (afsc != null) {
        FlowEntry.FlowLiveType liveType = FlowEntry.FlowLiveType.IMMEDIATE;
        return new DefaultFlowEntry(builder.build(), flowState, 0, liveType, 0, 0);
    } else {
        return new DefaultFlowEntry(builder.build(), flowState, 0, 0, 0);
    }
}
Also used : DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) FlowEntryState(org.onosproject.net.flow.FlowEntry.FlowEntryState) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) FlowEntry(org.onosproject.net.flow.FlowEntry) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry)

Aggregations

FlowEntry (org.onosproject.net.flow.FlowEntry)123 DefaultFlowEntry (org.onosproject.net.flow.DefaultFlowEntry)61 FlowRule (org.onosproject.net.flow.FlowRule)51 Test (org.junit.Test)31 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)31 FlowRuleService (org.onosproject.net.flow.FlowRuleService)27 ArrayList (java.util.ArrayList)24 StoredFlowEntry (org.onosproject.net.flow.StoredFlowEntry)23 DeviceId (org.onosproject.net.DeviceId)20 Device (org.onosproject.net.Device)19 PortNumber (org.onosproject.net.PortNumber)17 TrafficSelector (org.onosproject.net.flow.TrafficSelector)16 Instruction (org.onosproject.net.flow.instructions.Instruction)16 DeviceService (org.onosproject.net.device.DeviceService)15 List (java.util.List)14 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)13 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)13 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)12 HashSet (java.util.HashSet)12 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)11