Search in sources :

Example 26 with DefaultFlowEntry

use of org.onosproject.net.flow.DefaultFlowEntry 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 27 with DefaultFlowEntry

use of org.onosproject.net.flow.DefaultFlowEntry 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)

Example 28 with DefaultFlowEntry

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

the class FlowBucket method remove.

/**
 * Removes the given flow rule from the bucket.
 *
 * @param rule  the rule to remove
 * @param term  the term in which the change occurred
 * @param clock the logical clock
 * @return the removed flow entry
 */
public FlowEntry remove(FlowEntry rule, long term, LogicalClock clock) {
    final AtomicReference<FlowEntry> removedRule = new AtomicReference<>();
    flowBucket.computeIfPresent(rule.id(), (flowId, flowEntries) -> {
        flowEntries.computeIfPresent((StoredFlowEntry) rule, (k, stored) -> {
            if (rule instanceof DefaultFlowEntry) {
                DefaultFlowEntry toRemove = (DefaultFlowEntry) rule;
                if (stored instanceof DefaultFlowEntry) {
                    DefaultFlowEntry storedEntry = (DefaultFlowEntry) stored;
                    if (toRemove.created() < storedEntry.created()) {
                        LOGGER.debug("Trying to remove more recent flow entry {} (stored: {})", toRemove, stored);
                        // the key is not updated, removedRule remains null
                        return stored;
                    }
                }
            }
            removedRule.set(stored);
            return null;
        });
        return flowEntries.isEmpty() ? null : flowEntries;
    });
    if (removedRule.get() != null) {
        recordUpdate(term, clock.getTimestamp());
        return removedRule.get();
    } else {
        return null;
    }
}
Also used : DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) AtomicReference(java.util.concurrent.atomic.AtomicReference) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) FlowEntry(org.onosproject.net.flow.FlowEntry) StoredFlowEntry(org.onosproject.net.flow.StoredFlowEntry)

Example 29 with DefaultFlowEntry

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

the class AbstractTerminalDeviceFlowRuleProgrammable method getFlowEntries.

/**
 * Get the flow entries that are present on the device.
 *
 * @return A collection of Flow Entries
 */
@Override
public Collection<FlowEntry> getFlowEntries() {
    DeviceConnectionCache cache = getConnectionCache();
    if (cache.get(did()) == null) {
        return ImmutableList.of();
    }
    List<FlowEntry> entries = new ArrayList<>();
    for (FlowRule r : cache.get(did())) {
        entries.add(new DefaultFlowEntry(r, FlowEntry.FlowEntryState.ADDED, 0, 0, 0));
    }
    return entries;
}
Also used : DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) ArrayList(java.util.ArrayList) DeviceConnectionCache(org.onosproject.drivers.odtn.impl.DeviceConnectionCache) FlowRule(org.onosproject.net.flow.FlowRule) FlowEntry(org.onosproject.net.flow.FlowEntry) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry)

Example 30 with DefaultFlowEntry

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

the class GnmiTerminalDeviceFlowRuleProgrammable method getFlowEntries.

@Override
public Collection<FlowEntry> getFlowEntries() {
    // TODO: currently, we store flow rules in a cluster store. Should check if rule/config exists via gNMI.
    if (!setupBehaviour("getFlowEntries")) {
        return Collections.emptyList();
    }
    DeviceConnectionCache cache = getConnectionCache();
    Set<FlowRule> cachedRules = cache.get(deviceId);
    if (cachedRules == null) {
        return ImmutableList.of();
    }
    return cachedRules.stream().filter(Objects::nonNull).map(r -> new DefaultFlowEntry(r, FlowEntry.FlowEntryState.ADDED, 0, 0, 0)).collect(Collectors.toList());
}
Also used : FlowRuleProgrammable(org.onosproject.net.flow.FlowRuleProgrammable) Gnmi(gnmi.Gnmi) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) LoggerFactory(org.slf4j.LoggerFactory) FlowEntry(org.onosproject.net.flow.FlowEntry) OC_NAME(org.onosproject.odtn.behaviour.OdtnDeviceDescriptionDiscovery.OC_NAME) ArrayList(java.util.ArrayList) Frequency(org.onlab.util.Frequency) ImmutableList(com.google.common.collect.ImmutableList) Port(org.onosproject.net.Port) GnmiClient(org.onosproject.gnmi.api.GnmiClient) AbstractGrpcHandlerBehaviour(org.onosproject.grpc.utils.AbstractGrpcHandlerBehaviour) GnmiPathBuilder(org.onosproject.gnmi.api.GnmiUtils.GnmiPathBuilder) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) Logger(org.slf4j.Logger) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) DeviceConnectionCache(org.onosproject.drivers.odtn.impl.DeviceConnectionCache) Objects(java.util.Objects) ExecutionException(java.util.concurrent.ExecutionException) List(java.util.List) FlowRuleParser(org.onosproject.drivers.odtn.impl.FlowRuleParser) FlowRule(org.onosproject.net.flow.FlowRule) GnmiController(org.onosproject.gnmi.api.GnmiController) Collections(java.util.Collections) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) Objects(java.util.Objects) DeviceConnectionCache(org.onosproject.drivers.odtn.impl.DeviceConnectionCache) FlowRule(org.onosproject.net.flow.FlowRule)

Aggregations

DefaultFlowEntry (org.onosproject.net.flow.DefaultFlowEntry)44 FlowEntry (org.onosproject.net.flow.FlowEntry)38 FlowRule (org.onosproject.net.flow.FlowRule)31 StoredFlowEntry (org.onosproject.net.flow.StoredFlowEntry)22 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)21 Test (org.junit.Test)20 ArrayList (java.util.ArrayList)8 DeviceId (org.onosproject.net.DeviceId)7 Collectors (java.util.stream.Collectors)6 Map (java.util.Map)4 HierarchicalConfiguration (org.apache.commons.configuration.HierarchicalConfiguration)4 DeviceConnectionCache (org.onosproject.drivers.odtn.impl.DeviceConnectionCache)4 PortNumber (org.onosproject.net.PortNumber)4 DeviceService (org.onosproject.net.device.DeviceService)4 FlowId (org.onosproject.net.flow.FlowId)4 Logger (org.slf4j.Logger)4 ImmutableList (com.google.common.collect.ImmutableList)3 IOException (java.io.IOException)3 Objects (java.util.Objects)3 Set (java.util.Set)3