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;
}
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);
}
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;
}
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();
}
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);
}
}
}
Aggregations