use of org.onosproject.net.packet.OutboundPacket in project onos by opennetworkinglab.
the class DhcpRelayManagerTest method testArpRequest.
@Test
public void testArpRequest() throws Exception {
packetService.processPacket(new TestArpRequestPacketContext(CLIENT_INTERFACE));
assertAfter(PKT_PROCESSING_MS, () -> assertNotNull(packetService.emittedPacket));
OutboundPacket outboundPacket = packetService.emittedPacket;
byte[] outPacketData = outboundPacket.data().array();
Ethernet eth = Ethernet.deserializer().deserialize(outPacketData, 0, outPacketData.length);
assertAfter(PKT_PROCESSING_MS, () -> assertEquals(eth.getEtherType(), Ethernet.TYPE_ARP));
ARP arp = (ARP) eth.getPayload();
assertAfter(PKT_PROCESSING_MS, () -> assertArrayEquals(arp.getSenderHardwareAddress(), CLIENT_INTERFACE.mac().toBytes()));
}
use of org.onosproject.net.packet.OutboundPacket in project onos by opennetworkinglab.
the class DhcpRelayManagerTest method testWithRelayAgentConfig.
@Test
public void testWithRelayAgentConfig() throws DeserializationException {
manager.v4Handler.setDefaultDhcpServerConfigs(ImmutableList.of(new MockDhcpServerConfig(RELAY_AGENT_IP)));
manager.v4Handler.setIndirectDhcpServerConfigs(ImmutableList.of(new MockDhcpServerConfig(RELAY_AGENT_IP)));
packetService.processPacket(new TestDhcpRequestPacketContext(CLIENT2_MAC, CLIENT2_VLAN, CLIENT2_CP, INTERFACE_IP.ipAddress().getIp4Address(), true));
assertAfter(PKT_PROCESSING_MS, () -> assertNotNull(packetService.emittedPacket));
OutboundPacket outPacket = packetService.emittedPacket;
byte[] outData = outPacket.data().array();
Ethernet eth = Ethernet.deserializer().deserialize(outData, 0, outData.length);
IPv4 ip = (IPv4) eth.getPayload();
UDP udp = (UDP) ip.getPayload();
DHCP dhcp = (DHCP) udp.getPayload();
assertAfter(PKT_PROCESSING_MS, () -> assertEquals(RELAY_AGENT_IP.toInt(), dhcp.getGatewayIPAddress()));
}
use of org.onosproject.net.packet.OutboundPacket in project aaa by opencord.
the class PortBasedRadiusCommunicator method sendFromRadiusServerPort.
/**
* Sends packet to the RADIUS server using one of the switch ports.
*
* @param packet Ethernet packet to be sent
*/
private void sendFromRadiusServerPort(Ethernet packet) {
if (radiusServerConnectPoint != null) {
log.trace("AAA Manager sending Ethernet packet = {}", packet);
TrafficTreatment t = DefaultTrafficTreatment.builder().setOutput(radiusServerConnectPoint.port()).build();
OutboundPacket o = new DefaultOutboundPacket(radiusServerConnectPoint.deviceId(), t, ByteBuffer.wrap(packet.serialize()));
packetService.emit(o);
} else {
log.error("Unable to send RADIUS packet, connectPoint is null");
}
}
use of org.onosproject.net.packet.OutboundPacket in project fabric-tna by stratum.
the class FabricInterpreterTest method testMapOutboundPacketWithForwarding.
@Test
public void testMapOutboundPacketWithForwarding() throws PiPipelineInterpreter.PiInterpreterException, ImmutableByteSequence.ByteSequenceTrimException {
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(P4InfoConstants.PAD0).withValue(ImmutableByteSequence.copyFrom(0).fit(P4InfoConstants.PAD0_BITWIDTH)).build());
builder.add(PiPacketMetadata.builder().withId(P4InfoConstants.EGRESS_PORT).withValue(ImmutableByteSequence.copyFrom(0).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(1).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.OutboundPacket in project fabric-tna by stratum.
the class FabricInterpreter method mapOutboundPacket.
@Override
public Collection<PiPacketOperation> mapOutboundPacket(OutboundPacket packet) throws PiInterpreterException {
TrafficTreatment treatment = packet.treatment();
// We support only OUTPUT instructions.
List<Instructions.OutputInstruction> outInstructions = treatment.allInstructions().stream().filter(i -> i.type().equals(OUTPUT)).map(i -> (Instructions.OutputInstruction) i).collect(toList());
if (treatment.allInstructions().size() != outInstructions.size()) {
// There are other instructions that are not of type OUTPUT.
throw new PiInterpreterException("Treatment not supported: " + treatment);
}
ImmutableList.Builder<PiPacketOperation> builder = ImmutableList.builder();
for (Instructions.OutputInstruction outInst : outInstructions) {
if (outInst.port().equals(TABLE)) {
// Logical port. Forward using the switch tables like a regular packet.
builder.add(createPiPacketOperation(packet.data(), 0, true));
} else if (outInst.port().equals(FLOOD)) {
// Logical port. Create a packet operation for each switch port.
final DeviceService deviceService = handler().get(DeviceService.class);
for (Port port : deviceService.getPorts(packet.sendThrough())) {
builder.add(createPiPacketOperation(packet.data(), port.number().toLong(), false));
}
} else if (outInst.port().isLogical()) {
throw new PiInterpreterException(format("Output on logical port '%s' not supported", outInst.port()));
} else {
// Send as-is to given port bypassing all switch tables.
builder.add(createPiPacketOperation(packet.data(), outInst.port().toLong(), false));
}
}
return builder.build();
}
Aggregations