Search in sources :

Example 11 with FlowEntry

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

the class OplinkOpticalPowerConfig method setChannelTargetPower.

private boolean setChannelTargetPower(PortNumber port, OchSignal channel, long power) {
    log.debug("Set port{} channel{} attenuation.", port, channel.channelSpacing());
    FlowRuleService service = handler().get(FlowRuleService.class);
    Iterable<FlowEntry> entries = service.getFlowEntries(data().deviceId());
    for (FlowEntry entry : entries) {
        OplinkCrossConnect crossConnect = OplinkOpticalUtility.fromFlowRule(this, entry);
        // The channel port might be input port or output port.
        if ((port.equals(crossConnect.getInPort()) || port.equals(crossConnect.getOutPort())) && channel.spacingMultiplier() == crossConnect.getChannel()) {
            log.debug("Flow is found, modify the flow with attenuation.");
            // Modify attenuation in treatment
            TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(crossConnect.getOutPort()).extension(new OplinkAttenuation((int) power), data().deviceId()).build();
            // Apply the new flow rule
            service.applyFlowRules(DefaultFlowRule.builder().forDevice(data().deviceId()).makePermanent().withSelector(entry.selector()).withTreatment(treatment).withPriority(entry.priority()).withCookie(entry.id().value()).build());
            return true;
        }
    }
    return false;
}
Also used : OplinkAttenuation(org.onosproject.driver.extensions.OplinkAttenuation) FlowRuleService(org.onosproject.net.flow.FlowRuleService) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) FlowEntry(org.onosproject.net.flow.FlowEntry)

Example 12 with FlowEntry

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

the class TapiFlowRuleProgrammable method getFlowEntries.

@Override
public Collection<FlowEntry> getFlowEntries() {
    DeviceId deviceId = did();
    // TODO this is a blocking call on ADVA OLS, right now using cache.
    // return getFlowsFromConnectivityServices(deviceId);
    List<FlowEntry> entries = new ArrayList<>();
    Set<FlowRule> rules = getConnectionCache().get(deviceId);
    if (rules != null) {
        rules.forEach(rule -> {
            entries.add(new DefaultFlowEntry(rule, FlowEntry.FlowEntryState.ADDED, 0, 0, 0));
        });
    }
    return entries;
}
Also used : DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) DeviceId(org.onosproject.net.DeviceId) ArrayList(java.util.ArrayList) FlowRule(org.onosproject.net.flow.FlowRule) FlowEntry(org.onosproject.net.flow.FlowEntry) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry)

Example 13 with FlowEntry

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

the class TapiFlowRuleProgrammable method getFlowsFromConnectivityServices.

// Currently uused because get is a blocking call on ADVA
private Collection<FlowEntry> getFlowsFromConnectivityServices(DeviceId deviceId) {
    Set<String> uuids = getUuids(deviceId, handler());
    if (uuids.isEmpty()) {
        return ImmutableList.of();
    }
    DeviceConnectionCache cache = getConnectionCache();
    if (cache.get(deviceId) == null) {
        return ImmutableList.of();
    }
    List<FlowEntry> entries = new ArrayList<>();
    uuids.forEach(uuid -> {
        FlowRule rule = cache.get(deviceId, uuid);
        if (rule != null) {
            entries.add(new DefaultFlowEntry(rule, FlowEntry.FlowEntryState.ADDED, 0, 0, 0));
        } else {
            log.info("Non existing rule for uuid {}", uuid);
        }
    });
    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 14 with FlowEntry

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

the class ReactiveForwarding method fixBlackhole.

private void fixBlackhole(ConnectPoint egress) {
    Set<FlowEntry> rules = getFlowRulesFrom(egress);
    Set<SrcDstPair> pairs = findSrcDstPairs(rules);
    Map<DeviceId, Set<Path>> srcPaths = new HashMap<>();
    for (SrcDstPair sd : pairs) {
        // get the edge deviceID for the src host
        Host srcHost = hostService.getHost(HostId.hostId(sd.src));
        Host dstHost = hostService.getHost(HostId.hostId(sd.dst));
        if (srcHost != null && dstHost != null) {
            DeviceId srcId = srcHost.location().deviceId();
            DeviceId dstId = dstHost.location().deviceId();
            log.trace("SRC ID is {}, DST ID is {}", srcId, dstId);
            cleanFlowRules(sd, egress.deviceId());
            Set<Path> shortestPaths = srcPaths.get(srcId);
            if (shortestPaths == null) {
                shortestPaths = topologyService.getPaths(topologyService.currentTopology(), egress.deviceId(), srcId);
                srcPaths.put(srcId, shortestPaths);
            }
            backTrackBadNodes(shortestPaths, dstId, sd);
        }
    }
}
Also used : Path(org.onosproject.net.Path) Set(java.util.Set) ImmutableSet(com.google.common.collect.ImmutableSet) HashMap(java.util.HashMap) DeviceId(org.onosproject.net.DeviceId) Host(org.onosproject.net.Host) FlowEntry(org.onosproject.net.flow.FlowEntry)

Example 15 with FlowEntry

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

the class FlowAnalyzer method analyze.

/**
 * Analyzes and prints out a report on the status of every flow entry inside
 * the network. The possible states are: Cleared (implying that the entry leads to
 * a host), Cycle (implying that it is part of cycle), and Black Hole (implying
 * that the entry does not lead to a single host).
 *
 * @return result string
 */
public String analyze() {
    graph = topologyService.getGraph(topologyService.currentTopology());
    for (TopologyVertex v : graph.getVertexes()) {
        DeviceId srcDevice = v.deviceId();
        Iterable<FlowEntry> flowTable = flowRuleService.getFlowEntries(srcDevice);
        for (FlowEntry flow : flowTable) {
            dfs(flow);
        }
    }
    // analyze the cycles to look for "critical flows" that can be removed
    // to break the cycle
    Set<FlowEntry> critpts = new HashSet<>();
    for (FlowEntry flow : label.keySet()) {
        if ("Cycle".equals(label.get(flow))) {
            Map<FlowEntry, String> labelSaved = label;
            label = new HashMap<FlowEntry, String>();
            ignoredFlows.add(flow);
            for (TopologyVertex v : graph.getVertexes()) {
                DeviceId srcDevice = v.deviceId();
                Iterable<FlowEntry> flowTable = flowRuleService.getFlowEntries(srcDevice);
                for (FlowEntry flow1 : flowTable) {
                    dfs(flow1);
                }
            }
            boolean replacable = true;
            for (FlowEntry flow2 : label.keySet()) {
                if ("Cleared".equals(labelSaved.get(flow2)) && !("Cleared".equals(label.get(flow2)))) {
                    replacable = false;
                }
            }
            if (replacable) {
                critpts.add(flow);
            }
            label = labelSaved;
        }
    }
    for (FlowEntry flow : critpts) {
        label.put(flow, "Cycle Critical Point");
    }
    String s = "\n";
    for (FlowEntry flow : label.keySet()) {
        s += ("Flow Rule: " + flowEntryRepresentation(flow) + "\n");
        s += ("Analysis: " + label.get(flow) + "!\n\n");
    }
    s += ("Analyzed " + label.keySet().size() + " flows.");
    // log.info(s);
    return s;
}
Also used : TopologyVertex(org.onosproject.net.topology.TopologyVertex) DeviceId(org.onosproject.net.DeviceId) FlowEntry(org.onosproject.net.flow.FlowEntry) HashSet(java.util.HashSet)

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