use of org.onosproject.net.packet.DefaultOutboundPacket 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.net.packet.DefaultOutboundPacket in project onos by opennetworkinglab.
the class DefaultVirtualPacketProvider method devirtualize.
/**
* Translate the requested virtual outbound packet into
* a set of physical OutboundPacket.
* See {@link org.onosproject.net.packet.OutboundPacket}
*
* @param packet an OutboundPacket to be translated
* @return a set of de-virtualized (physical) OutboundPacket
*/
private Set<OutboundPacket> devirtualize(NetworkId networkId, OutboundPacket packet) {
Set<OutboundPacket> outboundPackets = new HashSet<>();
Set<VirtualPort> vPorts = vnaService.getVirtualPorts(networkId, packet.sendThrough());
TrafficTreatment.Builder commonTreatmentBuilder = DefaultTrafficTreatment.builder();
packet.treatment().allInstructions().stream().filter(i -> i.type() != Instruction.Type.OUTPUT).forEach(i -> commonTreatmentBuilder.add(i));
TrafficTreatment commonTreatment = commonTreatmentBuilder.build();
PortNumber vOutPortNum = packet.treatment().allInstructions().stream().filter(i -> i.type() == Instruction.Type.OUTPUT).map(i -> ((Instructions.OutputInstruction) i).port()).findFirst().get();
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, packet.sendThrough());
return outboundPackets;
}
ConnectPoint egressPoint = optionalCpOut.get();
TrafficTreatment treatment = DefaultTrafficTreatment.builder(commonTreatment).setOutput(egressPoint.port()).build();
OutboundPacket outboundPacket = new DefaultOutboundPacket(egressPoint.deviceId(), treatment, packet.data());
outboundPackets.add(outboundPacket);
} else {
if (vOutPortNum == PortNumber.FLOOD) {
for (VirtualPort outPort : vPorts) {
ConnectPoint cpOut = outPort.realizedBy();
if (cpOut != null) {
TrafficTreatment treatment = DefaultTrafficTreatment.builder(commonTreatment).setOutput(cpOut.port()).build();
OutboundPacket outboundPacket = new DefaultOutboundPacket(cpOut.deviceId(), treatment, packet.data());
outboundPackets.add(outboundPacket);
} else {
log.warn("Port {} is not realized yet, in Network {}, Device {}", outPort.number(), networkId, packet.sendThrough());
}
}
}
}
return outboundPackets;
}
use of org.onosproject.net.packet.DefaultOutboundPacket in project onos by opennetworkinglab.
the class CastorArpManager method createArp.
@Override
public void createArp(Peer peer) {
Ethernet packet = null;
packet = buildArpRequest(peer);
ByteBuffer buf = ByteBuffer.wrap(packet.serialize());
ConnectPoint connectPoint = ConnectPoint.deviceConnectPoint(peer.getPort());
TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder();
builder.setOutput(connectPoint.port());
packetService.emit(new DefaultOutboundPacket(connectPoint.deviceId(), builder.build(), buf));
}
use of org.onosproject.net.packet.DefaultOutboundPacket in project onos by opennetworkinglab.
the class CastorArpManager method forward.
/**
* Forwards the ARP packet to the specified connect point via packet out.
*
* @param context The packet context
*/
private void forward(MessageContext context) {
TrafficTreatment.Builder builder = null;
Ethernet eth = context.packet();
ByteBuffer buf = ByteBuffer.wrap(eth.serialize());
IpAddress target = context.target();
String value = getMatchingConnectPoint(target);
if (value != null) {
ConnectPoint connectPoint = ConnectPoint.deviceConnectPoint(value);
builder = DefaultTrafficTreatment.builder();
builder.setOutput(connectPoint.port());
packetService.emit(new DefaultOutboundPacket(connectPoint.deviceId(), builder.build(), buf));
}
}
use of org.onosproject.net.packet.DefaultOutboundPacket in project onos by opennetworkinglab.
the class DefaultNeighbourMessageActions method sendTo.
/**
* Outputs a packet out a specific port.
*
* @param packet packet to send
* @param outPort port to send it out
*/
private void sendTo(ByteBuffer packet, ConnectPoint outPort) {
if (!edgeService.isEdgePoint(outPort)) {
// misconfiguration).
return;
}
TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder();
builder.setOutput(outPort.port());
packetService.emit(new DefaultOutboundPacket(outPort.deviceId(), builder.build(), packet));
}
Aggregations