use of org.onosproject.incubator.net.virtual.VirtualPacketContext in project onos by opennetworkinglab.
the class DefaultVirtualPacketProvider method virtualize.
/**
* Translate the requested physical PacketContext into a virtual PacketContext.
* See {@link org.onosproject.net.packet.PacketContext}
*
* @param context A physical PacketContext be translated
* @return A translated virtual PacketContext
*/
private VirtualPacketContext virtualize(PacketContext context) {
VirtualPort vPort = getMappedVirtualPort(context.inPacket().receivedFrom());
if (vPort != null) {
ConnectPoint cp = new ConnectPoint(vPort.element().id(), vPort.number());
Ethernet eth = context.inPacket().parsed();
eth.setVlanID(Ethernet.VLAN_UNTAGGED);
InboundPacket inPacket = new DefaultInboundPacket(cp, eth, ByteBuffer.wrap(eth.serialize()));
DefaultOutboundPacket outPkt = new DefaultOutboundPacket(cp.deviceId(), DefaultTrafficTreatment.builder().build(), ByteBuffer.wrap(eth.serialize()));
VirtualPacketContext vContext = new DefaultVirtualPacketContext(context.time(), inPacket, outPkt, false, vPort.networkId(), this);
return vContext;
} else {
return null;
}
}
use of org.onosproject.incubator.net.virtual.VirtualPacketContext in project onos by opennetworkinglab.
the class DefaultVirtualPacketProvider method devirtualizeContext.
/**
* Translate the requested virtual packet context into
* a set of physical outbound packets.
*
* @param context A handled virtual packet context
*/
private Set<OutboundPacket> devirtualizeContext(VirtualPacketContext context) {
Set<OutboundPacket> outboundPackets = new HashSet<>();
NetworkId networkId = context.networkId();
TrafficTreatment vTreatment = context.treatmentBuilder().build();
DeviceId sendThrough = context.outPacket().sendThrough();
Set<VirtualPort> vPorts = vnaService.getVirtualPorts(networkId, sendThrough);
PortNumber vOutPortNum = vTreatment.allInstructions().stream().filter(i -> i.type() == Instruction.Type.OUTPUT).map(i -> ((Instructions.OutputInstruction) i).port()).findFirst().get();
TrafficTreatment.Builder commonTreatmentBuilder = DefaultTrafficTreatment.builder();
vTreatment.allInstructions().stream().filter(i -> i.type() != Instruction.Type.OUTPUT).forEach(i -> commonTreatmentBuilder.add(i));
TrafficTreatment commonTreatment = commonTreatmentBuilder.build();
if (!vOutPortNum.isLogical()) {
Optional<ConnectPoint> optionalCpOut = vPorts.stream().filter(v -> v.number().equals(vOutPortNum)).map(v -> v.realizedBy()).findFirst();
if (!optionalCpOut.isPresent()) {
log.warn("Port {} is not realized yet, in Network {}, Device {}", vOutPortNum, networkId, sendThrough);
return outboundPackets;
}
ConnectPoint egressPoint = optionalCpOut.get();
TrafficTreatment treatment = DefaultTrafficTreatment.builder(commonTreatment).setOutput(egressPoint.port()).build();
OutboundPacket outboundPacket = new DefaultOutboundPacket(egressPoint.deviceId(), treatment, context.outPacket().data());
outboundPackets.add(outboundPacket);
} else {
if (vOutPortNum == PortNumber.FLOOD) {
Set<VirtualPort> outPorts = vPorts.stream().filter(vp -> !vp.number().isLogical()).filter(vp -> vp.number() != context.inPacket().receivedFrom().port()).collect(Collectors.toSet());
for (VirtualPort outPort : outPorts) {
ConnectPoint cpOut = outPort.realizedBy();
if (cpOut != null) {
TrafficTreatment treatment = DefaultTrafficTreatment.builder(commonTreatment).setOutput(cpOut.port()).build();
OutboundPacket outboundPacket = new DefaultOutboundPacket(cpOut.deviceId(), treatment, context.outPacket().data());
outboundPackets.add(outboundPacket);
} else {
log.warn("Port {} is not realized yet, in Network {}, Device {}", outPort.number(), networkId, sendThrough);
}
}
}
}
return outboundPackets;
}
Aggregations