Search in sources :

Example 11 with OutputInstruction

use of org.onosproject.net.flow.instructions.Instructions.OutputInstruction in project onos by opennetworkinglab.

the class TrafficMonitor method getEgressFlows.

// Counts all entries that egress on the link source port.
private int getEgressFlows(Link link, List<FlowEntry> entries) {
    int count = 0;
    PortNumber out = link.src().port();
    for (FlowEntry entry : entries) {
        TrafficTreatment treatment = entry.treatment();
        for (Instruction instruction : treatment.allInstructions()) {
            if (instruction.type() == Instruction.Type.OUTPUT && ((OutputInstruction) instruction).port().equals(out)) {
                count++;
            }
        }
    }
    return count;
}
Also used : OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) PortNumber(org.onosproject.net.PortNumber) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) Instruction(org.onosproject.net.flow.instructions.Instruction) FlowEntry(org.onosproject.net.flow.FlowEntry)

Example 12 with OutputInstruction

use of org.onosproject.net.flow.instructions.Instructions.OutputInstruction in project onos by opennetworkinglab.

the class ProtectedIntentMonitor method populateLinks.

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/**
 * Populate Links along the primary/backup path.
 *
 * @param links   link collection to populate [output]
 * @param head    head-end of primary/backup path
 * @param tail    tail-end of primary/backup path
 * @param transit Intents if any
 */
private void populateLinks(Set<Link> links, ConnectPoint head, ConnectPoint tail, List<FlowRuleIntent> transit) {
    // find first hop link
    Link first = transit.stream().flatMap(fri -> fri.flowRules().stream()).map(fr -> Optional.ofNullable(fr.selector().getCriterion(Criterion.Type.IN_PORT)).filter(PortCriterion.class::isInstance).map(PortCriterion.class::cast).map(PortCriterion::port).map(pn -> new ConnectPoint(fr.deviceId(), pn)).orElse(null)).filter(Objects::nonNull).map(dst -> services.link().getLink(head, dst)).filter(Objects::nonNull).findFirst().orElse(services.link().getLink(head, tail));
    // add first link
    if (first != null) {
        links.add(first);
    }
    // add links in the middle if any
    transit.forEach(fri -> links.addAll(linkResources(fri)));
    // add last hop if any
    Lists.reverse(transit).stream().flatMap(fri -> ImmutableList.copyOf(fri.flowRules()).reverse().stream()).map(fr -> fr.treatment().allInstructions().stream().filter(OutputInstruction.class::isInstance).findFirst().map(OutputInstruction.class::cast).map(OutputInstruction::port).map(pn -> new ConnectPoint(fr.deviceId(), pn)).orElse(null)).filter(Objects::nonNull).map(src -> services.link().getLink(src, tail)).filter(Objects::nonNull).findFirst().ifPresent(links::add);
}
Also used : DeviceHighlight(org.onosproject.ui.topo.DeviceHighlight) TrafficLinkMap(org.onosproject.ui.impl.topo.util.TrafficLinkMap) LoggerFactory(org.slf4j.LoggerFactory) ElementId(org.onosproject.net.ElementId) Highlights(org.onosproject.ui.topo.Highlights) Timer(java.util.Timer) MarkerResource.marker(org.onosproject.net.MarkerResource.marker) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) Link(org.onosproject.net.Link) ConnectPoint(org.onosproject.net.ConnectPoint) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) HostHighlight(org.onosproject.ui.topo.HostHighlight) NodeHighlight(org.onosproject.ui.topo.NodeHighlight) IntentService(org.onosproject.net.intent.IntentService) Map(java.util.Map) Intent(org.onosproject.net.intent.Intent) ServicesBundle(org.onosproject.ui.impl.topo.util.ServicesBundle) LinkedList(java.util.LinkedList) TimerTask(java.util.TimerTask) HostId(org.onosproject.net.HostId) StatsType(org.onosproject.ui.impl.topo.util.TrafficLink.StatsType) Criterion(org.onosproject.net.flow.criteria.Criterion) LinkedHashSet(java.util.LinkedHashSet) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) ImmutableSet(com.google.common.collect.ImmutableSet) Logger(org.slf4j.Logger) IDLE(org.onosproject.ui.impl.ProtectedIntentMonitor.ProtectedMode.IDLE) TrafficLink(org.onosproject.ui.impl.topo.util.TrafficLink) Flavor(org.onosproject.ui.topo.LinkHighlight.Flavor) Collection(java.util.Collection) Mod(org.onosproject.ui.topo.Mod) Set(java.util.Set) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Objects(java.util.Objects) List(java.util.List) LinkService(org.onosproject.net.link.LinkService) Optional(java.util.Optional) SELECTED_INTENT(org.onosproject.ui.impl.ProtectedIntentMonitor.ProtectedMode.SELECTED_INTENT) DeviceId(org.onosproject.net.DeviceId) AbstractTopoMonitor(org.onosproject.ui.topo.AbstractTopoMonitor) OpticalConnectivityIntent(org.onosproject.net.intent.OpticalConnectivityIntent) Collections(java.util.Collections) ProtectionEndpointIntent(org.onosproject.net.intent.ProtectionEndpointIntent) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) Objects(java.util.Objects) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) ConnectPoint(org.onosproject.net.ConnectPoint) Link(org.onosproject.net.Link) TrafficLink(org.onosproject.ui.impl.topo.util.TrafficLink)

Example 13 with OutputInstruction

use of org.onosproject.net.flow.instructions.Instructions.OutputInstruction in project onos by opennetworkinglab.

the class PolatisInternalConnectivity method filterUsedPorts.

private Set<PortNumber> filterUsedPorts(Set<PortNumber> ports, Collection<FlowEntry> flowEntries) {
    if (ports.isEmpty() || flowEntries.isEmpty()) {
        return ports;
    }
    for (FlowEntry flowEntry : flowEntries) {
        PortNumber inputPort = ((PortCriterion) flowEntry.selector().getCriterion(Criterion.Type.IN_PORT)).port();
        ports.remove(inputPort);
        PortNumber outputPort = ((OutputInstruction) flowEntry.treatment().allInstructions().get(0)).port();
        ports.remove(outputPort);
        log.debug("Cross-connection {}-{} removed from output port list", inputPort, outputPort);
    }
    log.debug("Ports after filtering out used ones: " + ports);
    return ports;
}
Also used : OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) PortNumber(org.onosproject.net.PortNumber) FlowEntry(org.onosproject.net.flow.FlowEntry)

Example 14 with OutputInstruction

use of org.onosproject.net.flow.instructions.Instructions.OutputInstruction in project onos by opennetworkinglab.

the class OpenFlowCorePacketContext method sendPacket.

private void sendPacket(Ethernet eth) {
    List<Instruction> ins = treatmentBuilder().build().allInstructions();
    OFPort p = null;
    // TODO: support arbitrary list of treatments must be supported in ofPacketContext
    for (Instruction i : ins) {
        if (i.type() == Type.OUTPUT) {
            p = buildPort(((OutputInstruction) i).port());
            // for now...
            break;
        }
    }
    if (eth == null) {
        ofPktCtx.build(p);
    } else {
        ofPktCtx.build(eth, p);
    }
    ofPktCtx.send();
}
Also used : OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) OFPort(org.projectfloodlight.openflow.types.OFPort) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) Instruction(org.onosproject.net.flow.instructions.Instruction)

Example 15 with OutputInstruction

use of org.onosproject.net.flow.instructions.Instructions.OutputInstruction in project onos by opennetworkinglab.

the class OpenFlowPacketProvider method emit.

@Override
public void emit(OutboundPacket packet) {
    DeviceId devId = packet.sendThrough();
    String scheme = devId.toString().split(":")[0];
    if (!scheme.equals(this.id().scheme())) {
        throw new IllegalArgumentException("Don't know how to handle Device with scheme " + scheme);
    }
    Dpid dpid = Dpid.dpid(devId.uri());
    OpenFlowSwitch sw = controller.getSwitch(dpid);
    if (sw == null) {
        log.warn("Device {} isn't available?", devId);
        return;
    }
    OFPort inPort;
    if (packet.inPort() != null) {
        inPort = portDesc(packet.inPort()).getPortNo();
    } else {
        inPort = OFPort.CONTROLLER;
    }
    // Ethernet eth = new Ethernet();
    // eth.deserialize(packet.data().array(), 0, packet.data().array().length);
    OFPortDesc p = null;
    for (Instruction inst : packet.treatment().allInstructions()) {
        if (inst.type().equals(Instruction.Type.OUTPUT)) {
            p = portDesc(((OutputInstruction) inst).port());
            OFPacketOut po = packetOut(sw, packet.data().array(), p.getPortNo(), inPort);
            sw.sendMsg(po);
        }
    }
}
Also used : OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) OFPortDesc(org.projectfloodlight.openflow.protocol.OFPortDesc) DeviceId(org.onosproject.net.DeviceId) Dpid(org.onosproject.openflow.controller.Dpid) OpenFlowSwitch(org.onosproject.openflow.controller.OpenFlowSwitch) OFPort(org.projectfloodlight.openflow.types.OFPort) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) Instruction(org.onosproject.net.flow.instructions.Instruction) OFPacketOut(org.projectfloodlight.openflow.protocol.OFPacketOut)

Aggregations

OutputInstruction (org.onosproject.net.flow.instructions.Instructions.OutputInstruction)34 Instruction (org.onosproject.net.flow.instructions.Instruction)21 PortNumber (org.onosproject.net.PortNumber)17 DeviceId (org.onosproject.net.DeviceId)15 ConnectPoint (org.onosproject.net.ConnectPoint)11 Port (org.onosproject.net.Port)10 L2ModificationInstruction (org.onosproject.net.flow.instructions.L2ModificationInstruction)9 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)7 Criterion (org.onosproject.net.flow.criteria.Criterion)7 Group (org.onosproject.net.group.Group)7 Collection (java.util.Collection)6 DeviceService (org.onosproject.net.device.DeviceService)6 FlowEntry (org.onosproject.net.flow.FlowEntry)6 ImmutableList (com.google.common.collect.ImmutableList)5 HashSet (java.util.HashSet)5 Ethernet (org.onlab.packet.Ethernet)5 AbstractHandlerBehaviour (org.onosproject.net.driver.AbstractHandlerBehaviour)5 IPCriterion (org.onosproject.net.flow.criteria.IPCriterion)5 ModEtherInstruction (org.onosproject.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction)5 ModVlanIdInstruction (org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanIdInstruction)5