Search in sources :

Example 6 with ICMP

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

the class IcmpHandler method processIcmp.

// ////////////////////////////////////
// ICMP Echo/Reply Protocol     //
// ////////////////////////////////////
/**
 * Process incoming ICMP packet.
 * If it is an ICMP request to router, then sends an ICMP response.
 * Otherwise ignore the packet.
 *
 * @param eth inbound ICMP packet
 * @param inPort the input port
 */
public void processIcmp(Ethernet eth, ConnectPoint inPort) {
    DeviceId deviceId = inPort.deviceId();
    IPv4 ipv4Packet = (IPv4) eth.getPayload();
    ICMP icmp = (ICMP) ipv4Packet.getPayload();
    Ip4Address destinationAddress = Ip4Address.valueOf(ipv4Packet.getDestinationAddress());
    Set<IpAddress> gatewayIpAddresses = config.getPortIPs(deviceId);
    IpAddress routerIp;
    // Only proceed with echo request
    if (icmp.getIcmpType() != ICMP.TYPE_ECHO_REQUEST) {
        return;
    }
    try {
        routerIp = config.getRouterIpv4(deviceId);
    } catch (DeviceConfigNotFoundException e) {
        log.warn(e.getMessage() + " Aborting processPacketIn.");
        return;
    }
    // Get pair ip - if it exists
    IpAddress pairRouterIp;
    try {
        DeviceId pairDeviceId = config.getPairDeviceId(deviceId);
        pairRouterIp = pairDeviceId != null ? config.getRouterIpv4(pairDeviceId) : null;
    } catch (DeviceConfigNotFoundException e) {
        pairRouterIp = null;
    }
    // ICMP to the router IP or gateway IP
    if (destinationAddress.equals(routerIp.getIp4Address()) || (pairRouterIp != null && destinationAddress.equals(pairRouterIp.getIp4Address())) || gatewayIpAddresses.contains(destinationAddress)) {
        sendIcmpResponse(eth, inPort);
    } else {
        log.trace("Ignore ICMP that targets for {}", destinationAddress);
    }
}
Also used : DeviceId(org.onosproject.net.DeviceId) IPv4(org.onlab.packet.IPv4) Ip4Address(org.onlab.packet.Ip4Address) IpAddress(org.onlab.packet.IpAddress) DeviceConfigNotFoundException(org.onosproject.segmentrouting.config.DeviceConfigNotFoundException) ICMP(org.onlab.packet.ICMP)

Example 7 with ICMP

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

the class IcmpHandlerTest method testPing4Loopback.

// Ping to the looback of our leaf
@Test
public void testPing4Loopback() {
    // Expected behavior
    expect(segmentRoutingManager.deviceService.isAvailable(REMOTE_LEAF)).andReturn(true).times(1);
    replay(segmentRoutingManager.deviceService);
    // Process
    icmpHandler.processIcmp(ETH_REQ_IPV4_LOOPBACK, CP12);
    // Verify packet-out
    Ethernet ethernet = packetService.getEthernetPacket(ETH_REQ_IPV4_LOOPBACK.getSourceMAC());
    assertNotNull(ethernet);
    assertThat(ethernet.getSourceMAC(), is(ETH_REQ_IPV4_LOOPBACK.getDestinationMAC()));
    assertThat(ethernet.getDestinationMAC(), is(ETH_REQ_IPV4_LOOPBACK.getSourceMAC()));
    assertTrue(ethernet.getPayload() instanceof IPv4);
    IPv4 ip = (IPv4) ethernet.getPayload();
    assertThat(ip.getSourceAddress(), is(DST_IPV4_LOOPBACK.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 8 with ICMP

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

the class IcmpHandlerTest method setUp.

@Before
public void setUp() {
    // Init
    ObjectMapper mapper = new ObjectMapper();
    ConfigApplyDelegate delegate = config -> {
    };
    // Setup configuration for app
    SegmentRoutingAppConfig appConfig = new SegmentRoutingAppConfig();
    JsonNode appTree = mapper.createObjectNode();
    appConfig.init(testApplicationId, "icmp-handler-test", appTree, mapper, delegate);
    appConfig.setSuppressSubnet(Collections.emptySet());
    // Setup configuration for the devices
    SegmentRoutingDeviceConfig remoteLeafConfig = new SegmentRoutingDeviceConfig();
    JsonNode remoteLeafTree = mapper.createObjectNode();
    remoteLeafConfig.init(REMOTE_LEAF, "icmp-handler-test", remoteLeafTree, mapper, delegate);
    remoteLeafConfig.setNodeSidIPv4(REMOTE_LEAF_SID4).setNodeSidIPv6(REMOTE_LEAF_SID6).setRouterIpv4(REMOTE_LEAF_LB4).setRouterIpv6(REMOTE_LEAF_LB6).setIsEdgeRouter(true).setRouterMac(REMOTE_MAC.toString());
    SegmentRoutingDeviceConfig localLeafConfig = new SegmentRoutingDeviceConfig();
    JsonNode localLeafTree = mapper.createObjectNode();
    localLeafConfig.init(LOCAL_LEAF, "icmp-handler-test", localLeafTree, mapper, delegate);
    localLeafConfig.setNodeSidIPv4(LOCAL_LEAF_SID4).setRouterIpv4(LOCAL_LEAF_LB4).setNodeSidIPv6(LOCAL_LEAF_SID6).setRouterIpv6(LOCAL_LEAF_LB6).setIsEdgeRouter(true).setRouterMac(LOCAL_MAC.toString());
    SegmentRoutingDeviceConfig localLeaf1Config = new SegmentRoutingDeviceConfig();
    JsonNode localLeaf1Tree = mapper.createObjectNode();
    localLeaf1Config.init(LOCAL_LEAF1, "icmp-handler-test", localLeaf1Tree, mapper, delegate);
    localLeaf1Config.setNodeSidIPv4(LOCAL_LEAF1_SID4).setRouterIpv4(LOCAL_LEAF1_LB4).setNodeSidIPv6(LOCAL_LEAF1_SID6).setRouterIpv6(LOCAL_LEAF1_LB6).setIsEdgeRouter(true).setRouterMac(LOCAL_MAC1.toString()).setPairDeviceId(LOCAL_LEAF2).setPairLocalPort(P3);
    SegmentRoutingDeviceConfig localLeaf2Config = new SegmentRoutingDeviceConfig();
    JsonNode localLeaf2Tree = mapper.createObjectNode();
    localLeaf2Config.init(LOCAL_LEAF2, "icmp-handler-test", localLeaf2Tree, mapper, delegate);
    localLeaf2Config.setNodeSidIPv4(LOCAL_LEAF2_SID4).setRouterIpv4(LOCAL_LEAF2_LB4).setNodeSidIPv6(LOCAL_LEAF2_SID6).setRouterIpv6(LOCAL_LEAF2_LB6).setIsEdgeRouter(true).setRouterMac(LOCAL_MAC2.toString()).setPairDeviceId(LOCAL_LEAF1).setPairLocalPort(P3);
    // Setup configuration for ports
    InterfaceConfig remoteLeafPorts1Config = new InterfaceConfig();
    ArrayNode remoteLeafPorts1Tree = mapper.createArrayNode();
    remoteLeafPorts1Config.init(CP12, "icmp-handler-test", remoteLeafPorts1Tree, mapper, delegate);
    remoteLeafPorts1Config.addInterface(INTF1);
    InterfaceConfig remoteLeafPorts2Config = new InterfaceConfig();
    ArrayNode remoteLeafPorts2Tree = mapper.createArrayNode();
    remoteLeafPorts2Config.init(CP13, "icmp-handler-test", remoteLeafPorts2Tree, mapper, delegate);
    remoteLeafPorts2Config.addInterface(INTF2);
    InterfaceConfig localLeafPortsConfig = new InterfaceConfig();
    ArrayNode localLeafPortsTree = mapper.createArrayNode();
    localLeafPortsConfig.init(CP1011, "icmp-handler-test", localLeafPortsTree, mapper, delegate);
    localLeafPortsConfig.addInterface(INTF111);
    InterfaceConfig localLeaf1PortsConfig = new InterfaceConfig();
    ArrayNode localLeaf1PortsTree = mapper.createArrayNode();
    localLeaf1PortsConfig.init(CP2011, "icmp-handler-test", localLeaf1PortsTree, mapper, delegate);
    localLeaf1PortsConfig.addInterface(INTF211);
    InterfaceConfig localLeaf2Ports1Config = new InterfaceConfig();
    ArrayNode localLeaf2Ports1Tree = mapper.createArrayNode();
    localLeaf2Ports1Config.init(CP2021, "icmp-handler-test", localLeaf2Ports1Tree, mapper, delegate);
    localLeaf2Ports1Config.addInterface(INTF212);
    InterfaceConfig localLeaf2Ports2Config = new InterfaceConfig();
    ArrayNode localLeaf2Ports2Tree = mapper.createArrayNode();
    localLeaf2Ports2Config.init(CP2024, "icmp-handler-test", localLeaf2Ports2Tree, mapper, delegate);
    localLeaf2Ports2Config.addInterface(INTF213);
    // Apply config
    MockNetworkConfigRegistry mockNetworkConfigRegistry = new MockNetworkConfigRegistry();
    mockNetworkConfigRegistry.applyConfig(remoteLeafConfig);
    mockNetworkConfigRegistry.applyConfig(remoteLeafPorts1Config);
    mockNetworkConfigRegistry.applyConfig(remoteLeafPorts2Config);
    mockNetworkConfigRegistry.applyConfig(localLeafConfig);
    mockNetworkConfigRegistry.applyConfig(localLeafPortsConfig);
    mockNetworkConfigRegistry.applyConfig(localLeaf1Config);
    mockNetworkConfigRegistry.applyConfig(localLeaf1PortsConfig);
    mockNetworkConfigRegistry.applyConfig(localLeaf2Config);
    mockNetworkConfigRegistry.applyConfig(localLeaf2Ports1Config);
    mockNetworkConfigRegistry.applyConfig(localLeaf2Ports2Config);
    segmentRoutingManager = new SegmentRoutingManager();
    segmentRoutingManager.appId = testApplicationId;
    packetService = new MockPacketService();
    segmentRoutingManager.packetService = packetService;
    segmentRoutingManager.cfgService = mockNetworkConfigRegistry;
    segmentRoutingManager.neighbourResolutionService = new MockNeighbourResolutionService();
    segmentRoutingManager.interfaceService = new MockInterfaceService(ImmutableSet.of(INTF1, INTF2, INTF111, INTF211, INTF212, INTF213));
    segmentRoutingManager.deviceConfiguration = new DeviceConfiguration(segmentRoutingManager);
    segmentRoutingManager.ipHandler = new IpHandler(segmentRoutingManager);
    segmentRoutingManager.deviceService = createMock(DeviceService.class);
    segmentRoutingManager.routeService = new MockRouteService(ROUTE_STORE);
    segmentRoutingManager.hostService = new MockHostService(Collections.emptySet());
    icmpHandler = new IcmpHandler(segmentRoutingManager);
}
Also used : ICMP6(org.onlab.packet.ICMP6) TestApplicationId(org.onosproject.TestApplicationId) InterfaceConfig(org.onosproject.net.config.basics.InterfaceConfig) DeviceService(org.onosproject.net.device.DeviceService) SegmentRoutingDeviceConfig(org.onosproject.segmentrouting.config.SegmentRoutingDeviceConfig) Ethernet(org.onlab.packet.Ethernet) SegmentRoutingAppConfig(org.onosproject.segmentrouting.config.SegmentRoutingAppConfig) ApplicationId(org.onosproject.core.ApplicationId) Is.is(org.hamcrest.core.Is.is) JsonNode(com.fasterxml.jackson.databind.JsonNode) Before(org.junit.Before) ImmutableSet(com.google.common.collect.ImmutableSet) ConfigApplyDelegate(org.onosproject.net.config.ConfigApplyDelegate) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) ICMP(org.onlab.packet.ICMP) EasyMock(org.easymock.EasyMock) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) IPv6(org.onlab.packet.IPv6) IPv4(org.onlab.packet.IPv4) ECHO_REPLY(org.onlab.packet.ICMP6.ECHO_REPLY) MPLS(org.onlab.packet.MPLS) Assert(org.junit.Assert) TestUtils(org.onosproject.segmentrouting.TestUtils) Collections(java.util.Collections) SegmentRoutingDeviceConfig(org.onosproject.segmentrouting.config.SegmentRoutingDeviceConfig) SegmentRoutingAppConfig(org.onosproject.segmentrouting.config.SegmentRoutingAppConfig) DeviceService(org.onosproject.net.device.DeviceService) JsonNode(com.fasterxml.jackson.databind.JsonNode) ConfigApplyDelegate(org.onosproject.net.config.ConfigApplyDelegate) InterfaceConfig(org.onosproject.net.config.basics.InterfaceConfig) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Before(org.junit.Before)

Example 9 with ICMP

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

the class IcmpHandlerTest method testPing4LoopbackPairDifferentLeafDown.

// Ping loopback of a destination that is down but
// hashing of the bond interfaces sends to other leaf
@Test
public void testPing4LoopbackPairDifferentLeafDown() {
    // 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_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 10 with ICMP

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

the class IcmpHandlerTest method testPing4GatewayPair.

// Ping to a dh gateway
@Test
public void testPing4GatewayPair() {
    // 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_GATEWAY_PAIR, CP2011);
    // Verify packet-out
    Ethernet ethernet = packetService.getEthernetPacket(ETH_REQ_IPV4_GATEWAY_PAIR.getSourceMAC());
    assertNotNull(ethernet);
    assertThat(ethernet.getSourceMAC(), is(ETH_REQ_IPV4_GATEWAY_PAIR.getDestinationMAC()));
    assertThat(ethernet.getDestinationMAC(), is(ETH_REQ_IPV4_GATEWAY_PAIR.getSourceMAC()));
    assertTrue(ethernet.getPayload() instanceof IPv4);
    IPv4 ip = (IPv4) ethernet.getPayload();
    assertThat(ip.getSourceAddress(), is(DST_IPV4_GATEWAY_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)

Aggregations

ICMP (org.onlab.packet.ICMP)23 IPv4 (org.onlab.packet.IPv4)20 Ethernet (org.onlab.packet.Ethernet)19 Test (org.junit.Test)10 ICMP6 (org.onlab.packet.ICMP6)5 ICMPEcho (org.onlab.packet.ICMPEcho)5 IPv6 (org.onlab.packet.IPv6)5 IpAddress (org.onlab.packet.IpAddress)5 MPLS (org.onlab.packet.MPLS)5 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)5 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)5 ByteBuffer (java.nio.ByteBuffer)4 ConnectPoint (org.onosproject.net.ConnectPoint)4 DeviceId (org.onosproject.net.DeviceId)4 Objects (java.util.Objects)3 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3 Ip4Address (org.onlab.packet.Ip4Address)3 MacAddress (org.onlab.packet.MacAddress)3 VlanId (org.onlab.packet.VlanId)3