use of org.onosproject.net.packet.OutboundPacket 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.OutboundPacket in project onos by opennetworkinglab.
the class OpenFlowPacketProviderTest method emit.
@Test
public void emit() {
MacAddress mac1 = MacAddress.of("00:00:00:11:00:01");
MacAddress mac2 = MacAddress.of("00:00:00:22:00:02");
ARP arp = new ARP();
arp.setSenderProtocolAddress(ANY).setSenderHardwareAddress(mac1.getBytes()).setTargetHardwareAddress(mac2.getBytes()).setTargetProtocolAddress(ANY).setHardwareType((short) 0).setProtocolType((short) 0).setHardwareAddressLength((byte) 6).setProtocolAddressLength((byte) 4).setOpCode((byte) 0);
Ethernet eth = new Ethernet();
eth.setVlanID(VLANID).setEtherType(Ethernet.TYPE_ARP).setSourceMACAddress("00:00:00:11:00:01").setDestinationMACAddress("00:00:00:22:00:02").setPayload(arp);
// the should-be working setup.
OutboundPacket passPkt = outPacket(DID, TR, eth);
sw.setRole(RoleState.MASTER);
provider.emit(passPkt);
assertEquals("invalid switch", sw, controller.current);
assertEquals("message not sent", PLIST.size(), sw.sent.size());
sw.sent.clear();
// Send with different IN_PORT
OutboundPacket inPortPkt = outPacket(DID, TR_ALL, eth, IN_PORT);
sw.setRole(RoleState.MASTER);
provider.emit(inPortPkt);
assertEquals("invalid switch", sw, controller.current);
assertEquals("message not sent", PLIST_ALL.size(), sw.sent.size());
OFMessage ofMessage = sw.sent.get(0);
assertEquals("Wrong OF message type", OFType.PACKET_OUT, ofMessage.getType());
OFPacketOut packetOut = (OFPacketOut) ofMessage;
assertEquals("Wrong in port", OFPort.of(IN_PORT_PN), packetOut.getInPort());
assertEquals("Unexpected number of actions", 1, packetOut.getActions().size());
OFAction ofAction = packetOut.getActions().get(0);
assertEquals("Packet out action should be type output", OFActionType.OUTPUT, ofAction.getType());
OFActionOutput ofActionOutput = (OFActionOutput) ofAction;
assertEquals("Output should be ALL", OFPort.ALL, ofActionOutput.getPort());
sw.sent.clear();
// wrong Role
// sw.setRole(RoleState.SLAVE);
// provider.emit(passPkt);
// assertEquals("invalid switch", sw, controller.current);
// assertEquals("message sent incorrectly", 0, sw.sent.size());
// sw.setRole(RoleState.MASTER);
// missing switch
OutboundPacket swFailPkt = outPacket(DID_MISSING, TR, eth);
provider.emit(swFailPkt);
assertNull("invalid switch", controller.current);
assertEquals("message sent incorrectly", 0, sw.sent.size());
// to missing port
// OutboundPacket portFailPkt = outPacket(DID, TR_MISSING, eth);
// provider.emit(portFailPkt);
// assertEquals("extra message sent", 1, sw.sent.size());
}
use of org.onosproject.net.packet.OutboundPacket in project onos by opennetworkinglab.
the class HostMonitorTest method testMonitorIpv6HostDoesNotExistWithVlan.
@Test
public void testMonitorIpv6HostDoesNotExistWithVlan() throws Exception {
HostManager hostManager = createMock(HostManager.class);
DeviceId devId = DeviceId.deviceId("fake");
short vlan = 5;
Device device = createMock(Device.class);
expect(device.id()).andReturn(devId).anyTimes();
replay(device);
PortNumber portNum = PortNumber.portNumber(1L);
Port port = createMock(Port.class);
expect(port.number()).andReturn(portNum).anyTimes();
expect(port.isEnabled()).andReturn(true).anyTimes();
replay(port);
TestDeviceService deviceService = new TestDeviceService();
deviceService.addDevice(device, Collections.singleton(port));
ConnectPoint cp = new ConnectPoint(devId, portNum);
expect(hostManager.getHostsByIp(TARGET_IPV6_ADDR)).andReturn(Collections.emptySet()).anyTimes();
replay(hostManager);
InterfaceService interfaceService = createMock(InterfaceService.class);
expect(interfaceService.getMatchingInterfaces(TARGET_IPV6_ADDR)).andReturn(Collections.singleton(new Interface(Interface.NO_INTERFACE_NAME, cp, Collections.singletonList(IA2), sourceMac2, VlanId.vlanId(vlan)))).anyTimes();
replay(interfaceService);
TestPacketService packetService = new TestPacketService();
// Run the test
hostMonitor = new HostMonitor(packetService, hostManager, interfaceService, edgePortService, deviceService);
hostMonitor.addMonitoringFor(TARGET_IPV6_ADDR);
hostMonitor.run();
// Check that a packet was sent to our PacketService and that it has
// the properties we expect
assertEquals(2, packetService.packets.size());
OutboundPacket packet = packetService.packets.get(0);
// Check the output port is correct
assertEquals(1, packet.treatment().immediate().size());
Instruction instruction = packet.treatment().immediate().get(0);
assertTrue(instruction instanceof OutputInstruction);
OutputInstruction oi = (OutputInstruction) instruction;
assertEquals(portNum, oi.port());
// Check the output packet is correct (well the important bits anyway)
final byte[] pktData = new byte[packet.data().remaining()];
packet.data().get(pktData);
Ethernet eth = Ethernet.deserializer().deserialize(pktData, 0, pktData.length);
assertEquals(vlan, eth.getVlanID());
IPv6 ipv6 = (IPv6) eth.getPayload();
assertArrayEquals(SOURCE_IPV6_ADDR.toOctets(), ipv6.getSourceAddress());
NeighborSolicitation ns = (NeighborSolicitation) ipv6.getPayload().getPayload();
assertArrayEquals(sourceMac2.toBytes(), ns.getOptions().get(0).data());
assertArrayEquals(TARGET_IPV6_ADDR.toOctets(), ns.getTargetAddress());
}
use of org.onosproject.net.packet.OutboundPacket 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.OutboundPacket 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());
}
Aggregations