Search in sources :

Example 16 with FlowEntry

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

the class DefaultOFSwitch method processStatsRequest.

@Override
public void processStatsRequest(Channel channel, OFMessage msg) {
    if (msg.getType() != OFType.STATS_REQUEST) {
        log.warn("Ignoring message of type {}.", msg.getType());
        return;
    }
    OFStatsRequest ofStatsRequest = (OFStatsRequest) msg;
    OFStatsReply ofStatsReply = null;
    switch(ofStatsRequest.getStatsType()) {
        case PORT_DESC:
            List<OFPortDesc> portDescs = new ArrayList<>();
            Set<Port> ports = ofSwitchService.ports(networkId, deviceId);
            ports.forEach(port -> {
                OFPortDesc ofPortDesc = portDesc(port);
                portDescs.add(ofPortDesc);
            });
            ofStatsReply = FACTORY.buildPortDescStatsReply().setXid(msg.getXid()).setEntries(portDescs).build();
            break;
        case PORT:
            OFPortStatsRequest portStatsRequest = (OFPortStatsRequest) msg;
            OFPort ofPort = portStatsRequest.getPortNo();
            List<OFPortStatsEntry> portStatsEntries = new ArrayList<>();
            List<PortStatistics> portStatistics = ofSwitchService.getPortStatistics(networkId, deviceId);
            if (ofPort.equals(OFPort.ANY)) {
                portStatistics.forEach(portStatistic -> {
                    OFPortStatsEntry ofPortStatsEntry = portStatsEntry(portStatistic);
                    portStatsEntries.add(ofPortStatsEntry);
                });
            }
            ofStatsReply = FACTORY.buildPortStatsReply().setEntries(portStatsEntries).setXid(msg.getXid()).build();
            break;
        case METER_FEATURES:
            OFMeterFeatures ofMeterFeatures = FACTORY.buildMeterFeatures().build();
            ofStatsReply = FACTORY.buildMeterFeaturesStatsReply().setXid(msg.getXid()).setFeatures(ofMeterFeatures).build();
            break;
        case FLOW:
            List<OFFlowStatsEntry> flowStatsEntries = new ArrayList<>();
            List<FlowEntry> flowStats = ofSwitchService.getFlowEntries(networkId, deviceId);
            flowStats.forEach(flowEntry -> {
                OFFlowStatsEntry ofFlowStatsEntry = ofFlowStatsEntry(flowEntry);
                flowStatsEntries.add(ofFlowStatsEntry);
            });
            ofStatsReply = FACTORY.buildFlowStatsReply().setEntries(flowStatsEntries).setXid(msg.getXid()).build();
            break;
        case TABLE:
            List<OFTableStatsEntry> ofTableStatsEntries = new ArrayList<>();
            List<TableStatisticsEntry> tableStats = ofSwitchService.getFlowTableStatistics(networkId, deviceId);
            tableStats.forEach(tableStatisticsEntry -> {
                OFTableStatsEntry ofFlowStatsEntry = ofFlowTableStatsEntry(tableStatisticsEntry);
                ofTableStatsEntries.add(ofFlowStatsEntry);
            });
            ofStatsReply = FACTORY.buildTableStatsReply().setEntries(ofTableStatsEntries).setXid(msg.getXid()).build();
            break;
        case GROUP:
            List<Group> groupStats = ofSwitchService.getGroups(networkId, deviceId);
            List<OFGroupStatsEntry> ofGroupStatsEntries = new ArrayList<>();
            groupStats.forEach(group -> {
                OFGroupStatsEntry entry = ofGroupStatsEntry(group);
                ofGroupStatsEntries.add(entry);
            });
            ofStatsReply = FACTORY.buildGroupStatsReply().setEntries(ofGroupStatsEntries).setXid(msg.getXid()).build();
            break;
        case GROUP_DESC:
            List<OFGroupDescStatsEntry> ofGroupDescStatsEntries = new ArrayList<>();
            List<Group> groupStats2 = ofSwitchService.getGroups(networkId, deviceId);
            groupStats2.forEach(group -> {
                OFGroupDescStatsEntry entry = ofGroupDescStatsEntry(group);
                ofGroupDescStatsEntries.add(entry);
            });
            ofStatsReply = FACTORY.buildGroupDescStatsReply().setEntries(ofGroupDescStatsEntries).setXid(msg.getXid()).build();
            break;
        case DESC:
            ofStatsReply = FACTORY.buildDescStatsReply().setXid(msg.getXid()).build();
            break;
        default:
            log.debug("Functionality not yet supported for type {} statsType{} msg {}", msg.getType(), ofStatsRequest.getStatsType(), msg);
            break;
    }
    if (ofStatsReply != null) {
        log.trace("request {}; reply {}", msg, ofStatsReply);
        channel.writeAndFlush(Collections.singletonList(ofStatsReply));
    }
}
Also used : OFStatsReply(org.projectfloodlight.openflow.protocol.OFStatsReply) OFGroup(org.projectfloodlight.openflow.types.OFGroup) Group(org.onosproject.net.group.Group) OFGroupDescStatsEntry(org.projectfloodlight.openflow.protocol.OFGroupDescStatsEntry) Port(org.onosproject.net.Port) OFPort(org.projectfloodlight.openflow.types.OFPort) ArrayList(java.util.ArrayList) OFPortStatsRequest(org.projectfloodlight.openflow.protocol.OFPortStatsRequest) FlowEntry(org.onosproject.net.flow.FlowEntry) OFFlowStatsEntry(org.projectfloodlight.openflow.protocol.OFFlowStatsEntry) OFStatsRequest(org.projectfloodlight.openflow.protocol.OFStatsRequest) PortStatistics(org.onosproject.net.device.PortStatistics) TableStatisticsEntry(org.onosproject.net.flow.TableStatisticsEntry) OFPortDesc(org.projectfloodlight.openflow.protocol.OFPortDesc) OFGroupStatsEntry(org.projectfloodlight.openflow.protocol.OFGroupStatsEntry) OFTableStatsEntry(org.projectfloodlight.openflow.protocol.OFTableStatsEntry) OFPort(org.projectfloodlight.openflow.types.OFPort) OFPortStatsEntry(org.projectfloodlight.openflow.protocol.OFPortStatsEntry) OFMeterFeatures(org.projectfloodlight.openflow.protocol.OFMeterFeatures)

Example 17 with FlowEntry

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

the class DefaultOFSwitch method processFlowMod.

private void processFlowMod(OFFlowMod flowMod) {
    // convert OFFlowMod to FLowRule object
    OFAgentVirtualFlowEntryBuilder flowEntryBuilder = new OFAgentVirtualFlowEntryBuilder(deviceId, flowMod, driverService);
    FlowEntry flowEntry = flowEntryBuilder.build();
    flowRuleService.applyFlowRules(flowEntry);
}
Also used : FlowEntry(org.onosproject.net.flow.FlowEntry)

Example 18 with FlowEntry

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

the class ECFlowRuleStore method removeFlowRuleInternal.

private FlowRuleEvent removeFlowRuleInternal(FlowEntry rule) {
    // This is where one could mark a rule as removed and still keep it in the store.
    final FlowEntry removed = flowTable.remove(rule);
    log.debug("Removed flow rule: {}", removed);
    // rule may be partial rule that is missing treatment, we should use rule from store instead
    return removed != null ? new FlowRuleEvent(RULE_REMOVED, removed) : null;
}
Also used : FlowRuleEvent(org.onosproject.net.flow.FlowRuleEvent) FlowEntry(org.onosproject.net.flow.FlowEntry) StoredFlowEntry(org.onosproject.net.flow.StoredFlowEntry) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry)

Example 19 with FlowEntry

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

the class FlowBucket method update.

/**
 * Updates the given flow rule in the bucket.
 *
 * @param rule  the rule to update
 * @param term  the term in which the change occurred
 * @param clock the logical clock
 */
public void update(FlowEntry rule, long term, LogicalClock clock) {
    Map<StoredFlowEntry, StoredFlowEntry> flowEntries = flowBucket.get(rule.id());
    if (flowEntries == null) {
        flowEntries = flowBucket.computeIfAbsent(rule.id(), id -> Maps.newConcurrentMap());
    }
    flowEntries.computeIfPresent((StoredFlowEntry) rule, (k, stored) -> {
        if (rule instanceof DefaultFlowEntry) {
            DefaultFlowEntry updated = (DefaultFlowEntry) rule;
            if (stored instanceof DefaultFlowEntry) {
                DefaultFlowEntry storedEntry = (DefaultFlowEntry) stored;
                if (updated.created() >= storedEntry.created()) {
                    recordUpdate(term, clock.getTimestamp());
                    return updated;
                } else {
                    LOGGER.debug("Trying to update more recent flow entry {} (stored: {})", updated, stored);
                    return stored;
                }
            }
        }
        return stored;
    });
}
Also used : DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) FlowEntry(org.onosproject.net.flow.FlowEntry) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) FlowId(org.onosproject.net.flow.FlowId) Map(java.util.Map) FlowRule(org.onosproject.net.flow.FlowRule) ApplicationId(org.onosproject.core.ApplicationId) StoredFlowEntry(org.onosproject.net.flow.StoredFlowEntry) LogicalTimestamp(org.onosproject.store.LogicalTimestamp) StoredFlowEntry(org.onosproject.net.flow.StoredFlowEntry) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry)

Example 20 with FlowEntry

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

the class OpenRoadmFlowRuleProgrammable method getFlowEntries.

/**
 * Get the flow entries that are present on the device, called by
 * FlowRuleDriverProvider. <p> The flow entries must match exactly the
 * FlowRule entries in the ONOS store. If they are not an exact match the
 * device will be requested to remove those flows.
 *
 * @return A collection of Flow Entries
 */
@Override
public Collection<FlowEntry> getFlowEntries() {
    List<HierarchicalConfiguration> conf = getDeviceConnections();
    List<FlowEntry> entries = new ArrayList<>();
    for (HierarchicalConfiguration c : conf) {
        openRoadmLog("Existing connection {}", c);
        FlowRule r = buildFlowrule(c);
        if (r != null) {
            FlowEntry e = new DefaultFlowEntry(r, FlowEntry.FlowEntryState.ADDED, 0, 0, 0);
            openRoadmLog("RULE RETRIEVED {}", r);
            entries.add(e);
        }
    }
    return entries;
}
Also used : DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) ArrayList(java.util.ArrayList) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration) 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