Search in sources :

Example 31 with Ethernet

use of org.onlab.packet.Ethernet in project onos by opennetworkinglab.

the class PipelineInterpreterImpl method mapInboundPacket.

@Override
public InboundPacket mapInboundPacket(PiPacketOperation packetIn, DeviceId deviceId) throws PiInterpreterException {
    // We assume that the packet is ethernet, which is fine since mytunnel.p4
    // can deparse only ethernet packets.
    Ethernet ethPkt;
    try {
        ethPkt = Ethernet.deserializer().deserialize(packetIn.data().asArray(), 0, packetIn.data().size());
    } catch (DeserializationException dex) {
        throw new PiInterpreterException(dex.getMessage());
    }
    // Returns the ingress port packet metadata.
    Optional<PiPacketMetadata> packetMetadata = packetIn.metadatas().stream().filter(metadata -> metadata.id().toString().equals(INGRESS_PORT)).findFirst();
    if (packetMetadata.isPresent()) {
        short s = packetMetadata.get().value().asReadOnlyBuffer().getShort();
        ConnectPoint receivedFrom = new ConnectPoint(deviceId, PortNumber.portNumber(s));
        return new DefaultInboundPacket(receivedFrom, ethPkt, packetIn.data().asReadOnlyBuffer());
    } else {
        throw new PiInterpreterException(format("Missing metadata '%s' in packet-in received from '%s': %s", INGRESS_PORT, deviceId, packetIn));
    }
}
Also used : PiTableId(org.onosproject.net.pi.model.PiTableId) PiPacketMetadata(org.onosproject.net.pi.runtime.PiPacketMetadata) PACKET_OUT(org.onosproject.net.pi.model.PiPacketOperationType.PACKET_OUT) PiActionParamId(org.onosproject.net.pi.model.PiActionParamId) ImmutableByteSequence(org.onlab.util.ImmutableByteSequence) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) ByteBuffer(java.nio.ByteBuffer) ConnectPoint(org.onosproject.net.ConnectPoint) AbstractHandlerBehaviour(org.onosproject.net.driver.AbstractHandlerBehaviour) Ethernet(org.onlab.packet.Ethernet) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) DeserializationException(org.onlab.packet.DeserializationException) OutboundPacket(org.onosproject.net.packet.OutboundPacket) ImmutableByteSequence.copyFrom(org.onlab.util.ImmutableByteSequence.copyFrom) Port(org.onosproject.net.Port) Map(java.util.Map) PiPacketOperation(org.onosproject.net.pi.runtime.PiPacketOperation) Criterion(org.onosproject.net.flow.criteria.Criterion) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) FLOOD(org.onosproject.net.PortNumber.FLOOD) PiPipelineInterpreter(org.onosproject.net.pi.model.PiPipelineInterpreter) ImmutableMap(com.google.common.collect.ImmutableMap) DefaultInboundPacket(org.onosproject.net.packet.DefaultInboundPacket) Instruction(org.onosproject.net.flow.instructions.Instruction) Collection(java.util.Collection) PiMatchFieldId(org.onosproject.net.pi.model.PiMatchFieldId) PiPacketMetadataId(org.onosproject.net.pi.model.PiPacketMetadataId) String.format(java.lang.String.format) CONTROLLER(org.onosproject.net.PortNumber.CONTROLLER) PiAction(org.onosproject.net.pi.runtime.PiAction) List(java.util.List) InboundPacket(org.onosproject.net.packet.InboundPacket) Optional(java.util.Optional) DeviceId(org.onosproject.net.DeviceId) OUTPUT(org.onosproject.net.flow.instructions.Instruction.Type.OUTPUT) PiActionId(org.onosproject.net.pi.model.PiActionId) DefaultInboundPacket(org.onosproject.net.packet.DefaultInboundPacket) PiPacketMetadata(org.onosproject.net.pi.runtime.PiPacketMetadata) Ethernet(org.onlab.packet.Ethernet) ConnectPoint(org.onosproject.net.ConnectPoint) DeserializationException(org.onlab.packet.DeserializationException)

Example 32 with Ethernet

use of org.onlab.packet.Ethernet in project onos by opennetworkinglab.

the class DefaultNeighbourMessageActionsTest method reply.

@Test
public void reply() throws Exception {
    Ethernet request = NeighbourTestUtils.createArpRequest(IP1);
    Ip4Address ip4Address = INTF1.ipAddressesList().get(0).ipAddress().getIp4Address();
    Ethernet response = ARP.buildArpReply(ip4Address, MAC2, request);
    packetService.emit(outbound(response, CP1));
    expectLastCall().once();
    replay(packetService);
    actions.reply(createContext(request, CP1, null), MAC2);
    verify(packetService);
}
Also used : Ethernet(org.onlab.packet.Ethernet) Ip4Address(org.onlab.packet.Ip4Address) Test(org.junit.Test)

Example 33 with Ethernet

use of org.onlab.packet.Ethernet in project onos by opennetworkinglab.

the class DefaultNeighbourMessageActionsTest method forwardToConnectPoint.

@Test
public void forwardToConnectPoint() {
    Ethernet request = NeighbourTestUtils.createArpRequest(IP1);
    packetService.emit(outbound(request, CP2));
    expectLastCall().once();
    replay(packetService);
    actions.forward(createContext(request, CP1, null), CP2);
    verify(packetService);
}
Also used : Ethernet(org.onlab.packet.Ethernet) Test(org.junit.Test)

Example 34 with Ethernet

use of org.onlab.packet.Ethernet in project onos by opennetworkinglab.

the class DefaultNeighbourMessageActionsTest method forwardToInterface.

@Test
public void forwardToInterface() {
    Ethernet request = NeighbourTestUtils.createArpRequest(IP1);
    Ethernet forwardedRequest = request.duplicate();
    forwardedRequest.setSourceMACAddress(INTF2.mac());
    forwardedRequest.setVlanID(INTF2.vlan().toShort());
    packetService.emit(outbound(forwardedRequest, CP2));
    expectLastCall().once();
    replay(packetService);
    actions.forward(createContext(request, CP1, null), INTF2);
    verify(packetService);
}
Also used : Ethernet(org.onlab.packet.Ethernet) Test(org.junit.Test)

Example 35 with Ethernet

use of org.onlab.packet.Ethernet in project onos by opennetworkinglab.

the class DefaultNeighbourMessageActionsTest method flood.

@Test
public void flood() {
    Ethernet request = NeighbourTestUtils.createArpRequest(IP1);
    // Expect the packet to be emitted out all ports apart from the in port
    Sets.difference(Sets.newLinkedHashSet(EDGE_PORTS), Collections.singleton(CP1)).forEach(cp -> {
        packetService.emit(outbound(request, cp));
        expectLastCall().once();
    });
    replay(packetService);
    actions.flood(createContext(request, CP1, null));
    verify(packetService);
}
Also used : Ethernet(org.onlab.packet.Ethernet) Test(org.junit.Test)

Aggregations

Ethernet (org.onlab.packet.Ethernet)187 Test (org.junit.Test)91 ConnectPoint (org.onosproject.net.ConnectPoint)46 IPv4 (org.onlab.packet.IPv4)42 IPv6 (org.onlab.packet.IPv6)41 UDP (org.onlab.packet.UDP)38 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)33 MacAddress (org.onlab.packet.MacAddress)30 DefaultOutboundPacket (org.onosproject.net.packet.DefaultOutboundPacket)30 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)29 IpAddress (org.onlab.packet.IpAddress)28 OutboundPacket (org.onosproject.net.packet.OutboundPacket)26 DeviceId (org.onosproject.net.DeviceId)25 ByteBuffer (java.nio.ByteBuffer)24 DHCP (org.onlab.packet.DHCP)24 DHCP6 (org.onlab.packet.DHCP6)24 Interface (org.onosproject.net.intf.Interface)22 DeserializationException (org.onlab.packet.DeserializationException)20 ICMP6 (org.onlab.packet.ICMP6)20 InboundPacket (org.onosproject.net.packet.InboundPacket)20