Search in sources :

Example 21 with OutboundPacket

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());
}
Also used : PiPacketMetadata(org.onosproject.net.pi.runtime.PiPacketMetadata) ImmutableList(com.google.common.collect.ImmutableList) PiPacketOperation(org.onosproject.net.pi.runtime.PiPacketOperation) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) PortNumber(org.onosproject.net.PortNumber) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ByteBuffer(java.nio.ByteBuffer) OutboundPacket(org.onosproject.net.packet.OutboundPacket) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) Test(org.junit.Test)

Example 22 with OutboundPacket

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());
}
Also used : OFActionOutput(org.projectfloodlight.openflow.protocol.action.OFActionOutput) OFMessage(org.projectfloodlight.openflow.protocol.OFMessage) Ethernet(org.onlab.packet.Ethernet) OFAction(org.projectfloodlight.openflow.protocol.action.OFAction) MacAddress(org.projectfloodlight.openflow.types.MacAddress) OutboundPacket(org.onosproject.net.packet.OutboundPacket) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) OFPacketOut(org.projectfloodlight.openflow.protocol.OFPacketOut) ARP(org.onlab.packet.ARP) Test(org.junit.Test)

Example 23 with OutboundPacket

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());
}
Also used : OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) IPv6(org.onlab.packet.IPv6) DeviceId(org.onosproject.net.DeviceId) Device(org.onosproject.net.Device) Port(org.onosproject.net.Port) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) Instruction(org.onosproject.net.flow.instructions.Instruction) ConnectPoint(org.onosproject.net.ConnectPoint) OutboundPacket(org.onosproject.net.packet.OutboundPacket) InterfaceService(org.onosproject.net.intf.InterfaceService) Ethernet(org.onlab.packet.Ethernet) NeighborSolicitation(org.onlab.packet.ndp.NeighborSolicitation) PortNumber(org.onosproject.net.PortNumber) Interface(org.onosproject.net.intf.Interface) Test(org.junit.Test)

Example 24 with OutboundPacket

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());
}
Also used : PiPacketMetadata(org.onosproject.net.pi.runtime.PiPacketMetadata) ImmutableList(com.google.common.collect.ImmutableList) PiPacketOperation(org.onosproject.net.pi.runtime.PiPacketOperation) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) PortNumber(org.onosproject.net.PortNumber) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ByteBuffer(java.nio.ByteBuffer) OutboundPacket(org.onosproject.net.packet.OutboundPacket) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) Test(org.junit.Test)

Example 25 with OutboundPacket

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());
}
Also used : PiPacketMetadata(org.onosproject.net.pi.runtime.PiPacketMetadata) ImmutableList(com.google.common.collect.ImmutableList) PiPacketOperation(org.onosproject.net.pi.runtime.PiPacketOperation) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) PortNumber(org.onosproject.net.PortNumber) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ByteBuffer(java.nio.ByteBuffer) OutboundPacket(org.onosproject.net.packet.OutboundPacket) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) Test(org.junit.Test)

Aggregations

OutboundPacket (org.onosproject.net.packet.OutboundPacket)46 DefaultOutboundPacket (org.onosproject.net.packet.DefaultOutboundPacket)35 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)29 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)25 Ethernet (org.onlab.packet.Ethernet)20 Test (org.junit.Test)17 ConnectPoint (org.onosproject.net.ConnectPoint)16 PortNumber (org.onosproject.net.PortNumber)15 DeviceId (org.onosproject.net.DeviceId)12 ByteBuffer (java.nio.ByteBuffer)11 Port (org.onosproject.net.Port)9 InboundPacket (org.onosproject.net.packet.InboundPacket)9 PiPacketOperation (org.onosproject.net.pi.runtime.PiPacketOperation)9 ImmutableList (com.google.common.collect.ImmutableList)8 Instruction (org.onosproject.net.flow.instructions.Instruction)8 DefaultInboundPacket (org.onosproject.net.packet.DefaultInboundPacket)8 PiPacketMetadata (org.onosproject.net.pi.runtime.PiPacketMetadata)8 Optional (java.util.Optional)7 Device (org.onosproject.net.Device)7 Interface (org.onosproject.net.intf.Interface)6