Search in sources :

Example 21 with PacketContext

use of org.onosproject.net.packet.PacketContext in project onos by opennetworkinglab.

the class OpenstackSwitchingArpHandlerTest method sendPacket.

/**
 * Sends an Ethernet packet to the process method of the Packet processor.
 *
 * @param ethernet Ethernet packet
 */
private void sendPacket(Ethernet ethernet) {
    final ByteBuffer byteBuffer = ByteBuffer.wrap(ethernet.serialize());
    InboundPacket inPacket = new DefaultInboundPacket(connectPoint("1", 1), ethernet, byteBuffer);
    PacketContext context = new TestPacketContext(127L, inPacket, null, false);
    packetProcessor.process(context);
}
Also used : DefaultInboundPacket(org.onosproject.net.packet.DefaultInboundPacket) DefaultInboundPacket(org.onosproject.net.packet.DefaultInboundPacket) InboundPacket(org.onosproject.net.packet.InboundPacket) DefaultPacketContext(org.onosproject.net.packet.DefaultPacketContext) PacketContext(org.onosproject.net.packet.PacketContext) ByteBuffer(java.nio.ByteBuffer)

Example 22 with PacketContext

use of org.onosproject.net.packet.PacketContext in project onos by opennetworkinglab.

the class DefaultVirtualPacketProviderTest method virtualizePacket.

/**
 * Test the physical packet context is delivered to a proper (physical)
 *  virtual network and device.
 */
@Test
public void virtualizePacket() {
    Ethernet eth = new Ethernet();
    eth.setSourceMACAddress(SRC_MAC_ADDR);
    eth.setDestinationMACAddress(DST_MAC_ADDR);
    eth.setVlanID((short) 1);
    eth.setPayload(null);
    InboundPacket pInPacket = new DefaultInboundPacket(CP22, eth, ByteBuffer.wrap(eth.serialize()));
    PacketContext pContext = new TestPacketContext(System.nanoTime(), pInPacket, null, false);
    testPacketService.sendTestPacketContext(pContext);
    PacketContext vContext = providerService.getRequestedPacketContext(0);
    InboundPacket vInPacket = vContext.inPacket();
    assertEquals("the packet should be received from VCP12", VCP12, vInPacket.receivedFrom());
    assertEquals("VLAN tag should be excludede", VlanId.UNTAGGED, vInPacket.parsed().getVlanID());
}
Also used : DefaultInboundPacket(org.onosproject.net.packet.DefaultInboundPacket) Ethernet(org.onlab.packet.Ethernet) InboundPacket(org.onosproject.net.packet.InboundPacket) DefaultInboundPacket(org.onosproject.net.packet.DefaultInboundPacket) DefaultPacketContext(org.onosproject.net.packet.DefaultPacketContext) PacketContext(org.onosproject.net.packet.PacketContext) Test(org.junit.Test)

Example 23 with PacketContext

use of org.onosproject.net.packet.PacketContext in project onos by opennetworkinglab.

the class Dhcp6IndirectPacketClassifier method match.

@Override
public boolean match(PacketContext packet) {
    Ethernet eth = packet.inPacket().parsed();
    if (eth.getEtherType() == Ethernet.TYPE_IPV6) {
        IPv6 ipv6Packet = (IPv6) eth.getPayload();
        if (ipv6Packet.getNextHeader() == IPv6.PROTOCOL_UDP) {
            UDP udpPacket = (UDP) ipv6Packet.getPayload();
            // Indirectly connected host
            if (udpPacket.getDestinationPort() == UDP.DHCP_V6_SERVER_PORT && udpPacket.getSourcePort() == UDP.DHCP_V6_SERVER_PORT && Arrays.equals(ipv6Packet.getDestinationAddress(), Ip6Address.valueOf("ff02::1:2").toOctets())) {
                DHCP6 relayMessage = (DHCP6) udpPacket.getPayload();
                DHCP6 dhcp6 = (DHCP6) relayMessage.getOptions().stream().filter(opt -> opt instanceof Dhcp6RelayOption).map(BasePacket::getPayload).map(pld -> (DHCP6) pld).findFirst().orElse(null);
                if (dhcp6.getMsgType() == DHCP6.MsgType.SOLICIT.value()) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : UDP(org.onlab.packet.UDP) IPv6(org.onlab.packet.IPv6) BasePacket(org.onlab.packet.BasePacket) Ethernet(org.onlab.packet.Ethernet) Ip6Address(org.onlab.packet.Ip6Address) DHCP6(org.onlab.packet.DHCP6) Arrays(java.util.Arrays) Logger(org.slf4j.Logger) PacketContext(org.onosproject.net.packet.PacketContext) PacketInClassifier(org.onosproject.net.packet.PacketInClassifier) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) UDP(org.onlab.packet.UDP) Dhcp6RelayOption(org.onlab.packet.dhcp.Dhcp6RelayOption) IPv6(org.onlab.packet.IPv6) Ethernet(org.onlab.packet.Ethernet) DHCP6(org.onlab.packet.DHCP6) BasePacket(org.onlab.packet.BasePacket) Dhcp6RelayOption(org.onlab.packet.dhcp.Dhcp6RelayOption)

Example 24 with PacketContext

use of org.onosproject.net.packet.PacketContext in project onos by opennetworkinglab.

the class NetworkConfigLinksProviderTest method testNotConfiguredLink.

/**
 * Tests discovery of a link that is not expected in the configuration.
 */
@Test
public void testNotConfiguredLink() {
    PacketContext pktCtx = new TestPacketContext(src, dst);
    testProcessor.process(pktCtx);
    assertThat(providerService.discoveredLinks().entrySet(), hasSize(1));
    DeviceId destination = providerService.discoveredLinks().get(dev1.id());
    assertThat(destination, notNullValue());
    LinkKey key = LinkKey.linkKey(src, dst);
    LinkDescription linkDescription = providerService.discoveredLinkDescriptions().get(key);
    assertThat(linkDescription, notNullValue());
    assertThat(linkDescription.isExpected(), is(false));
}
Also used : LinkKey(org.onosproject.net.LinkKey) LinkDescription(org.onosproject.net.link.LinkDescription) DeviceId(org.onosproject.net.DeviceId) PacketContext(org.onosproject.net.packet.PacketContext) Test(org.junit.Test)

Aggregations

PacketContext (org.onosproject.net.packet.PacketContext)24 ByteBuffer (java.nio.ByteBuffer)11 Ethernet (org.onlab.packet.Ethernet)11 DeviceId (org.onosproject.net.DeviceId)11 Logger (org.slf4j.Logger)10 Set (java.util.Set)9 IpAddress (org.onlab.packet.IpAddress)9 DefaultOutboundPacket (org.onosproject.net.packet.DefaultOutboundPacket)9 MacAddress (org.onlab.packet.MacAddress)8 ApplicationId (org.onosproject.core.ApplicationId)8 ConnectPoint (org.onosproject.net.ConnectPoint)8 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)8 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)8 TrafficSelector (org.onosproject.net.flow.TrafficSelector)8 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)8 InboundPacket (org.onosproject.net.packet.InboundPacket)8 PacketService (org.onosproject.net.packet.PacketService)8 Executors.newSingleThreadExecutor (java.util.concurrent.Executors.newSingleThreadExecutor)7 Tools.groupedThreads (org.onlab.util.Tools.groupedThreads)7 CoreService (org.onosproject.core.CoreService)7