use of org.onosproject.net.packet.OutboundPacket in project onos by opennetworkinglab.
the class HostMonitor method sendProbe.
public void sendProbe(ConnectPoint connectPoint, IpAddress targetIp, IpAddress sourceIp, MacAddress sourceMac, VlanId vlan) {
log.debug("Sending probe for target:{} out of intf:{} vlan:{}", targetIp, connectPoint, vlan);
Ethernet probePacket;
if (targetIp.isIp4()) {
// IPv4: Use ARP
probePacket = buildArpRequest(targetIp, sourceIp, sourceMac, vlan);
} else {
// IPv6: Use Neighbor Discovery. According to the NDP protocol,
// we should use the solicitation node address as IPv6 destination
// and the multicast mac address as Ethernet destination.
byte[] destIp = IPv6.getSolicitNodeAddress(targetIp.toOctets());
probePacket = NeighborSolicitation.buildNdpSolicit(targetIp.getIp6Address(), sourceIp.getIp6Address(), Ip6Address.valueOf(destIp), sourceMac, MacAddress.valueOf(IPv6.getMCastMacAddress(destIp)), vlan);
}
if (probePacket == null) {
log.warn("Not able to build the probe packet");
return;
}
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(connectPoint.port()).build();
OutboundPacket outboundPacket = new DefaultOutboundPacket(connectPoint.deviceId(), treatment, ByteBuffer.wrap(probePacket.serialize()));
packetService.emit(outboundPacket);
}
use of org.onosproject.net.packet.OutboundPacket 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;
}
use of org.onosproject.net.packet.OutboundPacket in project onos by opennetworkinglab.
the class NeighbourResolutionManagerTest method context.
/**
* Creates a packet context for the given packet coming in the given port.
*
* @param packet packet to wrap in a packet context
* @param inPort input port of the packet
* @return packet context
*/
private static PacketContext context(Ethernet packet, ConnectPoint inPort) {
InboundPacket inboundPacket = new DefaultInboundPacket(inPort, packet, null);
OutboundPacket outboundPacket = new DefaultOutboundPacket(null, null, null);
return new PacketContextAdapter(0, inboundPacket, outboundPacket, false);
}
use of org.onosproject.net.packet.OutboundPacket in project onos by opennetworkinglab.
the class PacketManagerTest method packetProviderfallbackBasics.
/**
* Tests the correct usage of fallback driver provider for packets.
*/
@Test
public void packetProviderfallbackBasics() {
OutboundPacket packet = new DefaultOutboundPacket(FOO_DID, DefaultTrafficTreatment.emptyTreatment(), ByteBuffer.allocate(5));
mgr.emit(packet);
assertEquals("Packet not emitted correctly", packet, emittedPacket);
}
use of org.onosproject.net.packet.OutboundPacket in project onos by opennetworkinglab.
the class DefaultVirtualPacketProviderTest method devirtualizePacket.
/**
* Test the virtual outbound packet is delivered to a proper (physical)
* device.
*/
@Test
public void devirtualizePacket() {
TrafficTreatment tr = DefaultTrafficTreatment.builder().setOutput(VPORT_NUM1).build();
ByteBuffer data = ByteBuffer.wrap("abc".getBytes());
OutboundPacket vOutPacket = new DefaultOutboundPacket(VDID, tr, data);
virtualProvider.emit(VNET_ID, vOutPacket);
assertEquals("The count should be 1", 1, testPacketService.getRequestedPacketCount());
OutboundPacket pOutPacket = testPacketService.getRequestedPacket(0);
assertEquals("The packet should be requested on DEV1", DID1, pOutPacket.sendThrough());
PortNumber outPort = pOutPacket.treatment().allInstructions().stream().filter(i -> i.type() == Instruction.Type.OUTPUT).map(i -> (Instructions.OutputInstruction) i).map(i -> i.port()).findFirst().get();
assertEquals("The packet should be out at PORT1 of DEV1", PORT_NUM1, outPort);
}
Aggregations