use of org.onosproject.net.packet.DefaultOutboundPacket in project fabric-tna by stratum.
the class FabricInterpreterTest method testMapOutboundPacketWithoutForwarding.
@Test
public void testMapOutboundPacketWithoutForwarding() throws PiPipelineInterpreter.PiInterpreterException, ImmutableByteSequence.ByteSequenceTrimException {
PortNumber outputPort = PortNumber.portNumber(1);
TrafficTreatment outputTreatment = DefaultTrafficTreatment.builder().setOutput(outputPort).build();
ByteBuffer data = ByteBuffer.allocate(64);
OutboundPacket outPkt = new DefaultOutboundPacket(DEVICE_ID, outputTreatment, data);
Collection<PiPacketOperation> result = interpreter.mapOutboundPacket(outPkt);
assertEquals(result.size(), 1);
ImmutableList.Builder<PiPacketMetadata> builder = ImmutableList.builder();
builder.add(PiPacketMetadata.builder().withId(P4InfoConstants.PAD0).withValue(ImmutableByteSequence.copyFrom(0).fit(P4InfoConstants.PAD0_BITWIDTH)).build());
builder.add(PiPacketMetadata.builder().withId(P4InfoConstants.EGRESS_PORT).withValue(ImmutableByteSequence.copyFrom(outputPort.toLong()).fit(P4InfoConstants.EGRESS_PORT_BITWIDTH)).build());
builder.add(PiPacketMetadata.builder().withId(P4InfoConstants.PAD1).withValue(ImmutableByteSequence.copyFrom(0).fit(P4InfoConstants.PAD1_BITWIDTH)).build());
builder.add(PiPacketMetadata.builder().withId(P4InfoConstants.QUEUE_ID).withValue(ImmutableByteSequence.copyFrom(SYSTEM_QUEUE_ID).fit(P4InfoConstants.QUEUE_ID_BITWIDTH)).build());
builder.add(PiPacketMetadata.builder().withId(P4InfoConstants.PAD2).withValue(ImmutableByteSequence.copyFrom(0).fit(P4InfoConstants.PAD2_BITWIDTH)).build());
builder.add(PiPacketMetadata.builder().withId(P4InfoConstants.CPU_LOOPBACK_MODE).withValue(ImmutableByteSequence.copyFrom(0).fit(P4InfoConstants.CPU_LOOPBACK_MODE_BITWIDTH)).build());
builder.add(PiPacketMetadata.builder().withId(P4InfoConstants.DO_FORWARDING).withValue(ImmutableByteSequence.copyFrom(0).fit(P4InfoConstants.DO_FORWARDING_BITWIDTH)).build());
builder.add(PiPacketMetadata.builder().withId(P4InfoConstants.PAD3).withValue(ImmutableByteSequence.copyFrom(0).fit(P4InfoConstants.PAD3_BITWIDTH)).build());
builder.add(PiPacketMetadata.builder().withId(P4InfoConstants.PAD4).withValue(ImmutableByteSequence.copyFrom(0).fit(P4InfoConstants.PAD4_BITWIDTH)).build());
builder.add(PiPacketMetadata.builder().withId(P4InfoConstants.ETHER_TYPE).withValue(ImmutableByteSequence.copyFrom(0xBF01).fit(P4InfoConstants.ETHER_TYPE_BITWIDTH)).build());
PiPacketOperation expectedPktOp = PiPacketOperation.builder().withType(PiPacketOperationType.PACKET_OUT).withData(ImmutableByteSequence.copyFrom(data)).withMetadatas(builder.build()).build();
assertEquals(expectedPktOp, result.iterator().next());
}
use of org.onosproject.net.packet.DefaultOutboundPacket in project onos by opennetworkinglab.
the class FabricInterpreterTest method testMapOutboundPacketWithForwarding.
@Test
public void testMapOutboundPacketWithForwarding() throws Exception {
PortNumber outputPort = PortNumber.TABLE;
TrafficTreatment outputTreatment = DefaultTrafficTreatment.builder().setOutput(outputPort).build();
ByteBuffer data = ByteBuffer.allocate(64);
OutboundPacket outPkt = new DefaultOutboundPacket(DEVICE_ID, outputTreatment, data);
Collection<PiPacketOperation> result = interpreter.mapOutboundPacket(outPkt);
assertEquals(result.size(), 1);
ImmutableList.Builder<PiPacketMetadata> builder = ImmutableList.builder();
builder.add(PiPacketMetadata.builder().withId(FabricConstants.DO_FORWARDING).withValue(ImmutableByteSequence.copyFrom(1).fit(1)).build());
PiPacketOperation expectedPktOp = PiPacketOperation.builder().withType(PiPacketOperationType.PACKET_OUT).withData(ImmutableByteSequence.copyFrom(data)).withMetadatas(builder.build()).build();
assertEquals(expectedPktOp, result.iterator().next());
}
use of org.onosproject.net.packet.DefaultOutboundPacket in project onos by opennetworkinglab.
the class FabricInterpreterTest method testMapOutboundPacketWithoutForwarding.
@Test
public void testMapOutboundPacketWithoutForwarding() throws Exception {
PortNumber outputPort = PortNumber.portNumber(1);
TrafficTreatment outputTreatment = DefaultTrafficTreatment.builder().setOutput(outputPort).build();
ByteBuffer data = ByteBuffer.allocate(64);
OutboundPacket outPkt = new DefaultOutboundPacket(DEVICE_ID, outputTreatment, data);
Collection<PiPacketOperation> result = interpreter.mapOutboundPacket(outPkt);
assertEquals(result.size(), 1);
ImmutableList.Builder<PiPacketMetadata> builder = ImmutableList.builder();
builder.add(PiPacketMetadata.builder().withId(FabricConstants.EGRESS_PORT).withValue(ImmutableByteSequence.copyFrom(outputPort.toLong()).fit(PORT_BITWIDTH)).build());
PiPacketOperation expectedPktOp = PiPacketOperation.builder().withType(PiPacketOperationType.PACKET_OUT).withData(ImmutableByteSequence.copyFrom(data)).withMetadatas(builder.build()).build();
assertEquals(expectedPktOp, result.iterator().next());
}
use of org.onosproject.net.packet.DefaultOutboundPacket 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.DefaultOutboundPacket 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