Search in sources :

Example 6 with ICMP6

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

the class NeighborSolicitationTest method testBuildNdpSolicit.

/**
 * Tests regular non-DAD neighbor solicitation.
 */
@Test
public void testBuildNdpSolicit() throws Exception {
    final Ethernet ethPacket = NeighborSolicitation.buildNdpSolicit(TARGET_IP, SRC_IP, DST_IP, SRC_MAC, DST_MAC, VLAN_ID);
    assertTrue(ethPacket.getDestinationMAC().equals(DST_MAC));
    assertTrue(ethPacket.getSourceMAC().equals(SRC_MAC));
    assertTrue(ethPacket.getEtherType() == Ethernet.TYPE_IPV6);
    assertTrue(ethPacket.getVlanID() == VLAN_ID.id());
    final IPv6 ipPacket = (IPv6) ethPacket.getPayload();
    assertArrayEquals(ipPacket.getSourceAddress(), SRC_IP.toOctets());
    assertArrayEquals(ipPacket.getDestinationAddress(), DST_IP.toOctets());
    final ICMP6 icmp6Packet = (ICMP6) ipPacket.getPayload();
    final NeighborSolicitation nsPacket = (NeighborSolicitation) icmp6Packet.getPayload();
    assertArrayEquals(nsPacket.getTargetAddress(), TARGET_IP.toOctets());
    assertEquals("Non-DAD NS should have 1 option", 1, nsPacket.getOptions().size());
    assertEquals("The option should be SRC_LL_ADDR type", TYPE_SOURCE_LL_ADDRESS, nsPacket.getOptions().stream().findFirst().get().type());
}
Also used : IPv6(org.onlab.packet.IPv6) Ethernet(org.onlab.packet.Ethernet) ICMP6(org.onlab.packet.ICMP6) Test(org.junit.Test)

Example 7 with ICMP6

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

the class NeighborSolicitationTest method testBuildNdpSolicitDad.

/**
 * Tests DAD neighbor solicitation.
 * Source IP should be all-zero.
 */
@Test
public void testBuildNdpSolicitDad() throws Exception {
    Ethernet ethPacket = NeighborSolicitation.buildNdpSolicit(TARGET_IP, Ip6Address.ZERO, DST_IP, SRC_MAC, DST_MAC, VLAN_ID);
    IPv6 ipPacket = (IPv6) ethPacket.getPayload();
    ICMP6 icmp6Packet = (ICMP6) ipPacket.getPayload();
    NeighborSolicitation nsPacket = (NeighborSolicitation) icmp6Packet.getPayload();
    assertEquals("DAD NS should have no option", 0, nsPacket.getOptions().size());
}
Also used : IPv6(org.onlab.packet.IPv6) Ethernet(org.onlab.packet.Ethernet) ICMP6(org.onlab.packet.ICMP6) Test(org.junit.Test)

Example 8 with ICMP6

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

the class NeighborAdvertisementTest method testBuildNdpAdv.

/**
 * Test Neighbor Advertisement reply build.
 */
@Test
public void testBuildNdpAdv() {
    Ethernet eth = new Ethernet();
    eth.setSourceMACAddress(MAC_ADDRESS);
    eth.setDestinationMACAddress(MAC_ADDRESS2);
    IPv6 ipv6 = new IPv6();
    ipv6.setSourceAddress(IPV6_SOURCE_ADDRESS);
    ipv6.setDestinationAddress(IPV6_DESTINATION_ADDRESS);
    ipv6.setNextHeader(IPv6.PROTOCOL_ICMP6);
    eth.setEtherType(Ethernet.TYPE_IPV6);
    eth.setPayload(ipv6);
    ICMP6 icmp6 = new ICMP6();
    icmp6.setIcmpType(ICMP6.NEIGHBOR_SOLICITATION);
    icmp6.setIcmpCode(NeighborAdvertisement.RESERVED_CODE);
    ipv6.setPayload(icmp6);
    final Ethernet ethResponse = NeighborAdvertisement.buildNdpAdv(IP_6_ADDRESS, MAC_ADDRESS2, eth);
    assertTrue(ethResponse.getDestinationMAC().equals(MAC_ADDRESS));
    assertTrue(ethResponse.getSourceMAC().equals(MAC_ADDRESS2));
    assertTrue(ethResponse.getEtherType() == Ethernet.TYPE_IPV6);
    final IPv6 responseIpv6 = (IPv6) ethResponse.getPayload();
    assertArrayEquals(responseIpv6.getSourceAddress(), ipv6.getDestinationAddress());
    assertArrayEquals(responseIpv6.getDestinationAddress(), ipv6.getSourceAddress());
    assertTrue(responseIpv6.getNextHeader() == IPv6.PROTOCOL_ICMP6);
    final ICMP6 responseIcmp6 = (ICMP6) responseIpv6.getPayload();
    assertTrue(responseIcmp6.getIcmpType() == ICMP6.NEIGHBOR_ADVERTISEMENT);
    assertTrue(responseIcmp6.getIcmpCode() == NeighborAdvertisement.RESERVED_CODE);
    final NeighborAdvertisement responseNadv = (NeighborAdvertisement) responseIcmp6.getPayload();
    assertArrayEquals(responseNadv.getTargetAddress(), IPV6_DESTINATION_ADDRESS);
    assertTrue(responseNadv.getSolicitedFlag() == NeighborAdvertisement.NDP_SOLICITED_FLAG);
    assertTrue(responseNadv.getOverrideFlag() == NeighborAdvertisement.NDP_OVERRIDE_FLAG);
    assertThat(responseNadv.getOptions(), hasItem(hasOption(NeighborDiscoveryOptions.TYPE_TARGET_LL_ADDRESS, MAC_ADDRESS2.toBytes())));
}
Also used : IPv6(org.onlab.packet.IPv6) Ethernet(org.onlab.packet.Ethernet) ICMP6(org.onlab.packet.ICMP6) Test(org.junit.Test)

Example 9 with ICMP6

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

the class NeighborSolicitation method buildNdpSolicit.

/**
 * Builds a NDP solicitation using the supplied parameters.
 *
 * @param targetIp the target ip
 * @param sourceIp the source ip
 * @param destinationIp the destination ip
 * @param sourceMac the source mac address
 * @param destinationMac the destination mac address
 * @param vlan the vlan id
 * @return the ethernet packet containing the ndp solicitation
 */
public static Ethernet buildNdpSolicit(Ip6Address targetIp, Ip6Address sourceIp, Ip6Address destinationIp, MacAddress sourceMac, MacAddress destinationMac, VlanId vlan) {
    checkNotNull(targetIp, "Target IP address cannot be null");
    checkNotNull(sourceIp, "Source IP address cannot be null");
    checkNotNull(destinationIp, "Destination IP address cannot be null");
    checkNotNull(sourceMac, "Source MAC address cannot be null");
    checkNotNull(destinationMac, "Destination MAC address cannot be null");
    checkNotNull(vlan, "Vlan cannot be null");
    // Here we craft the Ethernet packet.
    Ethernet ethernet = new Ethernet();
    ethernet.setEtherType(Ethernet.TYPE_IPV6).setDestinationMACAddress(destinationMac).setSourceMACAddress(sourceMac);
    ethernet.setVlanID(vlan.id());
    // IPv6 packet is created.
    IPv6 ipv6 = new IPv6();
    ipv6.setSourceAddress(sourceIp.toOctets());
    ipv6.setDestinationAddress(destinationIp.toOctets());
    ipv6.setHopLimit(NDP_HOP_LIMIT);
    // Create the ICMPv6 packet.
    ICMP6 icmp6 = new ICMP6();
    icmp6.setIcmpType(ICMP6.NEIGHBOR_SOLICITATION);
    icmp6.setIcmpCode(RESERVED_CODE);
    // Create the Neighbor Solicitation packet.
    NeighborSolicitation ns = new NeighborSolicitation();
    ns.setTargetAddress(targetIp.toOctets());
    // DAD packets should not contain SRC_LL_ADDR option
    if (!Arrays.equals(sourceIp.toOctets(), Ip6Address.ZERO.toOctets())) {
        ns.addOption(NeighborDiscoveryOptions.TYPE_SOURCE_LL_ADDRESS, sourceMac.toBytes());
    }
    // Set the payloads
    icmp6.setPayload(ns);
    ipv6.setPayload(icmp6);
    ethernet.setPayload(ipv6);
    return ethernet;
}
Also used : IPv6(org.onlab.packet.IPv6) Ethernet(org.onlab.packet.Ethernet) ICMP6(org.onlab.packet.ICMP6)

Aggregations

ICMP6 (org.onlab.packet.ICMP6)9 IPv6 (org.onlab.packet.IPv6)9 Ethernet (org.onlab.packet.Ethernet)8 Test (org.junit.Test)3 ICMP (org.onlab.packet.ICMP)2 IPv4 (org.onlab.packet.IPv4)2 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)2 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)2 Ip4Prefix (org.onlab.packet.Ip4Prefix)1 Ip6Prefix (org.onlab.packet.Ip6Prefix)1 IpAddress (org.onlab.packet.IpAddress)1 MacAddress (org.onlab.packet.MacAddress)1 TCP (org.onlab.packet.TCP)1 UDP (org.onlab.packet.UDP)1 NeighborAdvertisement (org.onlab.packet.ndp.NeighborAdvertisement)1 NeighborSolicitation (org.onlab.packet.ndp.NeighborSolicitation)1 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)1 TrafficSelector (org.onosproject.net.flow.TrafficSelector)1 DefaultForwardingObjective (org.onosproject.net.flowobjective.DefaultForwardingObjective)1 ForwardingObjective (org.onosproject.net.flowobjective.ForwardingObjective)1