Search in sources :

Example 1 with FlowEntry

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

the class DefaultCheckLoop method findLoop.

/**
 * Enter of the loop checking algorithm.
 *
 * @return the set of loop results; empty, if there is no loop
 */
private Set<NetworkAnomaly> findLoop() {
    getNetworkSnapshot();
    loops = new HashSet<>();
    excludeDeviceId = new HashSet<>();
    for (Device device : accessDevices) {
        if (excludeDeviceId.contains(device.id())) {
            continue;
        }
        List<FlowEntry> availableFlowEntries = new ArrayList<>();
        flowEntryInfo.get(device.id()).forEach(flowEntry -> {
            if (flowEntry.state() == ADDED) {
                availableFlowEntries.add(flowEntry);
            }
        });
        List<FlowEntry> sortedFlowEntries = sortFlowTable(availableFlowEntries);
        for (FlowEntry flow : sortedFlowEntries) {
            TsLoopPacket pkt = matchBuilder(flow.selector().criteria(), null);
            pkt.pushPathFlow(flow);
            List<Instruction> inst = flow.treatment().immediate();
            for (Instruction instOne : inst) {
                // Attention !!!
                // if you would like to modify the code here,
                // please MAKE VERY SURE that you are clear with
                // the relationship of any invoked methods, and
                // the relationship of params which are passed in and out.
                processOneInstruction(instOne, device.id(), null, pkt, true, flow);
            }
        }
    }
    return loops;
}
Also used : Device(org.onosproject.net.Device) NetworkDiagnosticUtils.isDevice(org.onosproject.fnl.base.NetworkDiagnosticUtils.isDevice) ArrayList(java.util.ArrayList) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) Instruction(org.onosproject.net.flow.instructions.Instruction) FlowEntry(org.onosproject.net.flow.FlowEntry) TsLoopPacket(org.onosproject.fnl.base.TsLoopPacket)

Example 2 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 3 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 4 with FlowEntry

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

the class RoadmManager method channelAvailable.

@Override
public boolean channelAvailable(DeviceId deviceId, OchSignal ochSignal) {
    checkNotNull(deviceId);
    checkNotNull(ochSignal);
    for (FlowEntry entry : flowRuleService.getFlowEntries(deviceId)) {
        if (ChannelData.fromFlow(entry).ochSignal().equals(ochSignal)) {
            return false;
        }
    }
    return true;
}
Also used : FlowEntry(org.onosproject.net.flow.FlowEntry)

Example 5 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)119 DefaultFlowEntry (org.onosproject.net.flow.DefaultFlowEntry)58 FlowRule (org.onosproject.net.flow.FlowRule)48 Test (org.junit.Test)28 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)28 FlowRuleService (org.onosproject.net.flow.FlowRuleService)25 ArrayList (java.util.ArrayList)24 StoredFlowEntry (org.onosproject.net.flow.StoredFlowEntry)23 Device (org.onosproject.net.Device)19 DeviceId (org.onosproject.net.DeviceId)19 PortNumber (org.onosproject.net.PortNumber)16 Instruction (org.onosproject.net.flow.instructions.Instruction)16 DeviceService (org.onosproject.net.device.DeviceService)14 TrafficSelector (org.onosproject.net.flow.TrafficSelector)14 List (java.util.List)13 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)12 HashSet (java.util.HashSet)12 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)12 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)12 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)11