Search in sources :

Example 41 with IPv4

use of org.onlab.packet.IPv4 in project trellis-control by opennetworkinglab.

the class IcmpHandlerTest method testPing4LoopbackPair.

// Ping to the looback of our leaf (pair)
@Test
public void testPing4LoopbackPair() {
    // Expected behavior
    expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF1)).andReturn(true).times(1);
    expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF2)).andReturn(true).times(1);
    replay(segmentRoutingManager.deviceService);
    // Process
    icmpHandler.processIcmp(ETH_REQ_IPV4_LOOPBACK_PAIR, CP2011);
    // Verify packet-out
    Ethernet ethernet = packetService.getEthernetPacket(ETH_REQ_IPV4_LOOPBACK_PAIR.getSourceMAC());
    assertNotNull(ethernet);
    assertThat(ethernet.getSourceMAC(), is(ETH_REQ_IPV4_LOOPBACK_PAIR.getDestinationMAC()));
    assertThat(ethernet.getDestinationMAC(), is(ETH_REQ_IPV4_LOOPBACK_PAIR.getSourceMAC()));
    assertTrue(ethernet.getPayload() instanceof IPv4);
    IPv4 ip = (IPv4) ethernet.getPayload();
    assertThat(ip.getSourceAddress(), is(DST_IPV4_LOOPBACK_PAIR.toInt()));
    assertThat(ip.getDestinationAddress(), is(SRC_IPV41.toInt()));
    assertTrue(ip.getPayload() instanceof ICMP);
    ICMP icmp = (ICMP) ip.getPayload();
    assertThat(icmp.getIcmpType(), is(TYPE_ECHO_REPLY));
    assertThat(icmp.getIcmpCode(), is(CODE_ECHO_REPLY));
    // Verify behavior
    verify(segmentRoutingManager.deviceService);
}
Also used : Ethernet(org.onlab.packet.Ethernet) IPv4(org.onlab.packet.IPv4) ICMP(org.onlab.packet.ICMP) Test(org.junit.Test)

Example 42 with IPv4

use of org.onlab.packet.IPv4 in project trellis-control by opennetworkinglab.

the class IcmpHandlerTest method testPing4LoopbackPairDifferentLeaf.

// Ping to the loopback of the leaf but hashing of the bond interfaces sends to wrong leaf
@Test
public void testPing4LoopbackPairDifferentLeaf() {
    // Expected behavior
    expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF1)).andReturn(true).times(1);
    expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF2)).andReturn(true).times(1);
    replay(segmentRoutingManager.deviceService);
    // Process
    icmpHandler.processIcmp(ETH_REQ_IPV4_LOOPBACK_PAIR, CP2021);
    // Verify packet-out
    Ethernet ethernet = packetService.getEthernetPacket(ETH_REQ_IPV4_LOOPBACK_PAIR.getSourceMAC());
    assertNotNull(ethernet);
    assertThat(ethernet.getSourceMAC(), is(ETH_REQ_IPV4_LOOPBACK_PAIR.getDestinationMAC()));
    assertThat(ethernet.getDestinationMAC(), is(ETH_REQ_IPV4_LOOPBACK_PAIR.getSourceMAC()));
    assertTrue(ethernet.getPayload() instanceof IPv4);
    IPv4 ip = (IPv4) ethernet.getPayload();
    assertThat(ip.getSourceAddress(), is(DST_IPV4_LOOPBACK_PAIR.toInt()));
    assertThat(ip.getDestinationAddress(), is(SRC_IPV41.toInt()));
    assertTrue(ip.getPayload() instanceof ICMP);
    ICMP icmp = (ICMP) ip.getPayload();
    assertThat(icmp.getIcmpType(), is(TYPE_ECHO_REPLY));
    assertThat(icmp.getIcmpCode(), is(CODE_ECHO_REPLY));
    // Verify behavior
    verify(segmentRoutingManager.deviceService);
}
Also used : Ethernet(org.onlab.packet.Ethernet) IPv4(org.onlab.packet.IPv4) ICMP(org.onlab.packet.ICMP) Test(org.junit.Test)

Example 43 with IPv4

use of org.onlab.packet.IPv4 in project trellis-control by opennetworkinglab.

the class IcmpHandlerTest method testPing4LocalGateway.

// Ping to a gateway attached to our leaf
@Test
public void testPing4LocalGateway() {
    // Expected behavior
    expect(segmentRoutingManager.deviceService.isAvailable(REMOTE_LEAF)).andReturn(true).times(1);
    replay(segmentRoutingManager.deviceService);
    // Process
    icmpHandler.processIcmp(ETH_REQ_IPV4_LOCAL, CP12);
    // Verify packet-out
    Ethernet ethernet = packetService.getEthernetPacket(ETH_REQ_IPV4_LOCAL.getSourceMAC());
    assertNotNull(ethernet);
    assertThat(ethernet.getSourceMAC(), is(ETH_REQ_IPV4_LOCAL.getDestinationMAC()));
    assertThat(ethernet.getDestinationMAC(), is(ETH_REQ_IPV4_LOCAL.getSourceMAC()));
    assertTrue(ethernet.getPayload() instanceof IPv4);
    IPv4 ip = (IPv4) ethernet.getPayload();
    assertThat(ip.getSourceAddress(), is(DST_IPV4_LOCAL.toInt()));
    assertThat(ip.getDestinationAddress(), is(SRC_IPV4_MY.toInt()));
    assertTrue(ip.getPayload() instanceof ICMP);
    ICMP icmp = (ICMP) ip.getPayload();
    assertThat(icmp.getIcmpType(), is(TYPE_ECHO_REPLY));
    assertThat(icmp.getIcmpCode(), is(CODE_ECHO_REPLY));
    // Verify behavior
    verify(segmentRoutingManager.deviceService);
}
Also used : Ethernet(org.onlab.packet.Ethernet) IPv4(org.onlab.packet.IPv4) ICMP(org.onlab.packet.ICMP) Test(org.junit.Test)

Example 44 with IPv4

use of org.onlab.packet.IPv4 in project trellis-control by opennetworkinglab.

the class IcmpHandlerTest method testPing4RemoteGatewayLeaf1Down.

// Ping to a gateway but one of the destination leaf is down
@Test
public void testPing4RemoteGatewayLeaf1Down() {
    // Expected behavior
    expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF1)).andReturn(false).times(1);
    expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF2)).andReturn(true).times(1);
    replay(segmentRoutingManager.deviceService);
    // Process
    icmpHandler.processIcmp(ETH_REQ_IPV41, CP11);
    // Verify packet-out
    Ethernet ethernet = packetService.getEthernetPacket(ETH_REQ_IPV41.getSourceMAC());
    assertNotNull(ethernet);
    assertThat(ethernet.getSourceMAC(), is(ETH_REQ_IPV41.getDestinationMAC()));
    assertThat(ethernet.getDestinationMAC(), is(ETH_REQ_IPV41.getSourceMAC()));
    assertThat(ethernet.getEtherType(), is(Ethernet.MPLS_UNICAST));
    assertTrue(ethernet.getPayload() instanceof MPLS);
    MPLS mpls = (MPLS) ethernet.getPayload();
    assertThat(mpls.getLabel(), is(LOCAL_LEAF2_SID4));
    assertTrue(mpls.getPayload() instanceof IPv4);
    IPv4 ip = (IPv4) mpls.getPayload();
    assertThat(ip.getSourceAddress(), is(DST_IPV4.toInt()));
    assertThat(ip.getDestinationAddress(), is(SRC_IPV41.toInt()));
    assertTrue(ip.getPayload() instanceof ICMP);
    ICMP icmp = (ICMP) ip.getPayload();
    assertThat(icmp.getIcmpType(), is(TYPE_ECHO_REPLY));
    assertThat(icmp.getIcmpCode(), is(CODE_ECHO_REPLY));
    // Verify behavior
    verify(segmentRoutingManager.deviceService);
}
Also used : Ethernet(org.onlab.packet.Ethernet) IPv4(org.onlab.packet.IPv4) MPLS(org.onlab.packet.MPLS) ICMP(org.onlab.packet.ICMP) Test(org.junit.Test)

Example 45 with IPv4

use of org.onlab.packet.IPv4 in project trellis-control by opennetworkinglab.

the class IcmpHandler method sendIcmpResponse.

/**
 * Sends an ICMP reply message.
 *
 * @param icmpRequest the original ICMP request
 * @param outport the output port where the ICMP reply should be sent to
 */
private void sendIcmpResponse(Ethernet icmpRequest, ConnectPoint outport) {
    Ethernet icmpReplyEth = ICMP.buildIcmpReply(icmpRequest);
    IPv4 icmpRequestIpv4 = (IPv4) icmpRequest.getPayload();
    IPv4 icmpReplyIpv4 = (IPv4) icmpReplyEth.getPayload();
    Ip4Address destIpAddress = Ip4Address.valueOf(icmpRequestIpv4.getSourceAddress());
    // Get the available connect points
    Set<ConnectPoint> destConnectPoints = config.getConnectPointsForASubnetHost(destIpAddress);
    // Select a router
    Ip4Address destRouterAddress = selectRouterIp4Address(destIpAddress, outport, destConnectPoints);
    // Lookup the route store for the nexthop instead.
    if (destRouterAddress == null) {
        Optional<DeviceId> deviceId = srManager.routeService.longestPrefixLookup(destIpAddress).map(srManager::nextHopLocations).flatMap(locations -> locations.stream().findFirst()).map(ConnectPoint::deviceId);
        if (deviceId.isPresent()) {
            try {
                destRouterAddress = config.getRouterIpv4(deviceId.get());
            } catch (DeviceConfigNotFoundException e) {
                log.warn("Device config for {} not found. Abort ICMP processing", deviceId);
                return;
            }
        }
    }
    int destSid = config.getIPv4SegmentId(destRouterAddress);
    if (destSid < 0) {
        log.warn("Failed to lookup SID of the switch that {} attaches to. " + "Unable to process ICMP request.", destIpAddress);
        return;
    }
    sendPacketOut(outport, icmpReplyEth, destSid, destIpAddress, icmpReplyIpv4.getTtl());
}
Also used : DeviceConfigNotFoundException(org.onosproject.segmentrouting.config.DeviceConfigNotFoundException) ICMP6(org.onlab.packet.ICMP6) Arrays(java.util.Arrays) Interface(org.onosproject.net.intf.Interface) LoggerFactory(org.slf4j.LoggerFactory) HostService(org.onosproject.net.host.HostService) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ByteBuffer(java.nio.ByteBuffer) NeighborSolicitation(org.onlab.packet.ndp.NeighborSolicitation) ConnectPoint(org.onosproject.net.ConnectPoint) Ethernet(org.onlab.packet.Ethernet) SegmentRoutingAppConfig(org.onosproject.segmentrouting.config.SegmentRoutingAppConfig) OutboundPacket(org.onosproject.net.packet.OutboundPacket) NeighbourMessageType(org.onosproject.net.neighbour.NeighbourMessageType) IpAddress(org.onlab.packet.IpAddress) NeighbourMessageContext(org.onosproject.net.neighbour.NeighbourMessageContext) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Ip6Address(org.onlab.packet.Ip6Address) Ip4Address(org.onlab.packet.Ip4Address) Logger(org.slf4j.Logger) VlanId(org.onlab.packet.VlanId) Set(java.util.Set) ICMP(org.onlab.packet.ICMP) Collectors(java.util.stream.Collectors) IPv6(org.onlab.packet.IPv6) Objects(java.util.Objects) IPv4(org.onlab.packet.IPv4) MPLS(org.onlab.packet.MPLS) Optional(java.util.Optional) MacAddress(org.onlab.packet.MacAddress) DeviceId(org.onosproject.net.DeviceId) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) DeviceId(org.onosproject.net.DeviceId) Ethernet(org.onlab.packet.Ethernet) IPv4(org.onlab.packet.IPv4) Ip4Address(org.onlab.packet.Ip4Address) ConnectPoint(org.onosproject.net.ConnectPoint) DeviceConfigNotFoundException(org.onosproject.segmentrouting.config.DeviceConfigNotFoundException) ConnectPoint(org.onosproject.net.ConnectPoint)

Aggregations

IPv4 (org.onlab.packet.IPv4)54 Ethernet (org.onlab.packet.Ethernet)43 UDP (org.onlab.packet.UDP)24 DHCP (org.onlab.packet.DHCP)18 ICMP (org.onlab.packet.ICMP)17 IpAddress (org.onlab.packet.IpAddress)15 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)14 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)13 Test (org.junit.Test)12 Ip4Address (org.onlab.packet.Ip4Address)10 MacAddress (org.onlab.packet.MacAddress)10 ConnectPoint (org.onosproject.net.ConnectPoint)10 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)10 TrafficSelector (org.onosproject.net.flow.TrafficSelector)10 ByteBuffer (java.nio.ByteBuffer)8 Optional (java.util.Optional)8 Interface (org.onosproject.net.intf.Interface)8 DefaultOutboundPacket (org.onosproject.net.packet.DefaultOutboundPacket)8 DhcpOption (org.onlab.packet.dhcp.DhcpOption)7 ApplicationId (org.onosproject.core.ApplicationId)7