Search in sources :

Example 11 with PacketContext

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

the class LldpLinkProviderTest method knownPktCtx.

@Test
public void knownPktCtx() {
    deviceListener.event(deviceEvent(DeviceEvent.Type.DEVICE_ADDED, DID1));
    deviceListener.event(deviceEvent(DeviceEvent.Type.DEVICE_ADDED, DID2));
    PacketContext pktCtx = new TestPacketContext(deviceService.getDevice(DID2));
    testProcessor.process(pktCtx);
    assertTrue("Link not detected", detectedLink(DID1, DID2));
}
Also used : PacketContext(org.onosproject.net.packet.PacketContext) Test(org.junit.Test)

Example 12 with PacketContext

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

the class NetworkConfigLinksProviderTest method testConfiguredLink.

/**
 * Tests discovery of an expected link.
 */
@Test
public void testConfiguredLink() {
    LinkKey key = LinkKey.linkKey(src, dst);
    configListener.event(new NetworkConfigEvent(NetworkConfigEvent.Type.CONFIG_ADDED, key, BasicLinkConfig.class));
    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());
    LinkDescription linkDescription = providerService.discoveredLinkDescriptions().get(key);
    assertThat(linkDescription, notNullValue());
    assertThat(linkDescription.isExpected(), is(true));
}
Also used : LinkKey(org.onosproject.net.LinkKey) NetworkConfigEvent(org.onosproject.net.config.NetworkConfigEvent) LinkDescription(org.onosproject.net.link.LinkDescription) DeviceId(org.onosproject.net.DeviceId) PacketContext(org.onosproject.net.packet.PacketContext) BasicLinkConfig(org.onosproject.net.config.basics.BasicLinkConfig) Test(org.junit.Test)

Example 13 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 14 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)

Example 15 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)

Aggregations

PacketContext (org.onosproject.net.packet.PacketContext)27 ByteBuffer (java.nio.ByteBuffer)14 Ethernet (org.onlab.packet.Ethernet)12 DeviceId (org.onosproject.net.DeviceId)11 InboundPacket (org.onosproject.net.packet.InboundPacket)11 Test (org.junit.Test)10 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 PacketService (org.onosproject.net.packet.PacketService)8 Executors.newSingleThreadExecutor (java.util.concurrent.Executors.newSingleThreadExecutor)7 Tools.groupedThreads (org.onlab.util.Tools.groupedThreads)7