pier | 6a2052b | 2019-06-28 22:17:31 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019-present Open Networking Foundation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package org.onosproject.segmentrouting; |
| 18 | |
| 19 | import com.fasterxml.jackson.databind.JsonNode; |
| 20 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 21 | import com.fasterxml.jackson.databind.node.ArrayNode; |
| 22 | import com.google.common.collect.ImmutableSet; |
| 23 | import org.junit.Before; |
| 24 | import org.junit.Test; |
| 25 | import org.onlab.packet.Ethernet; |
| 26 | import org.onlab.packet.ICMP; |
| 27 | import org.onlab.packet.ICMP6; |
| 28 | import org.onlab.packet.IPv4; |
| 29 | import org.onlab.packet.IPv6; |
| 30 | import org.onlab.packet.MPLS; |
| 31 | import org.onosproject.TestApplicationId; |
| 32 | import org.onosproject.core.ApplicationId; |
| 33 | import org.onosproject.net.config.ConfigApplyDelegate; |
| 34 | import org.onosproject.net.config.basics.InterfaceConfig; |
| 35 | import org.onosproject.net.device.DeviceService; |
| 36 | import org.onosproject.segmentrouting.config.DeviceConfiguration; |
| 37 | import org.onosproject.segmentrouting.config.SegmentRoutingAppConfig; |
| 38 | import org.onosproject.segmentrouting.config.SegmentRoutingDeviceConfig; |
| 39 | |
| 40 | import java.util.Collections; |
| 41 | |
| 42 | import static org.easymock.EasyMock.*; |
| 43 | import static org.hamcrest.core.Is.is; |
| 44 | import static org.junit.Assert.*; |
| 45 | import static org.onlab.packet.ICMP.*; |
| 46 | import static org.onlab.packet.ICMP6.ECHO_REPLY; |
| 47 | import static org.onosproject.segmentrouting.TestUtils.*; |
| 48 | |
| 49 | /** |
| 50 | * Tests for IcmpHandler. |
| 51 | */ |
| 52 | public class IcmpHandlerTest { |
| 53 | |
| 54 | private IcmpHandler icmpHandler; |
| 55 | private MockPacketService packetService; |
| 56 | private SegmentRoutingManager segmentRoutingManager; |
| 57 | private ApplicationId testApplicationId = TestApplicationId.create("test"); |
| 58 | |
| 59 | @Before |
| 60 | public void setUp() { |
| 61 | |
| 62 | // Init |
| 63 | ObjectMapper mapper = new ObjectMapper(); |
| 64 | ConfigApplyDelegate delegate = config -> { }; |
| 65 | |
| 66 | // Setup configuration for app |
| 67 | SegmentRoutingAppConfig appConfig = new SegmentRoutingAppConfig(); |
| 68 | JsonNode appTree = mapper.createObjectNode(); |
| 69 | appConfig.init(testApplicationId, "icmp-handler-test", appTree, mapper, delegate); |
| 70 | appConfig.setSuppressSubnet(Collections.emptySet()); |
| 71 | |
| 72 | // Setup configuration for the devices |
| 73 | SegmentRoutingDeviceConfig remoteLeafConfig = new SegmentRoutingDeviceConfig(); |
| 74 | JsonNode remoteLeafTree = mapper.createObjectNode(); |
| 75 | remoteLeafConfig.init(REMOTE_LEAF, "icmp-handler-test", remoteLeafTree, mapper, delegate); |
| 76 | remoteLeafConfig.setNodeSidIPv4(REMOTE_LEAF_SID4) |
| 77 | .setNodeSidIPv6(REMOTE_LEAF_SID6) |
| 78 | .setRouterIpv4(REMOTE_LEAF_LB4) |
| 79 | .setRouterIpv6(REMOTE_LEAF_LB6) |
| 80 | .setIsEdgeRouter(true) |
| 81 | .setRouterMac(REMOTE_MAC.toString()); |
| 82 | SegmentRoutingDeviceConfig localLeafConfig = new SegmentRoutingDeviceConfig(); |
| 83 | JsonNode localLeafTree = mapper.createObjectNode(); |
| 84 | localLeafConfig.init(LOCAL_LEAF, "icmp-handler-test", localLeafTree, mapper, delegate); |
| 85 | localLeafConfig.setNodeSidIPv4(LOCAL_LEAF_SID4) |
| 86 | .setRouterIpv4(LOCAL_LEAF_LB4) |
| 87 | .setNodeSidIPv6(LOCAL_LEAF_SID6) |
| 88 | .setRouterIpv6(LOCAL_LEAF_LB6) |
| 89 | .setIsEdgeRouter(true) |
| 90 | .setRouterMac(LOCAL_MAC.toString()); |
| 91 | SegmentRoutingDeviceConfig localLeaf1Config = new SegmentRoutingDeviceConfig(); |
| 92 | JsonNode localLeaf1Tree = mapper.createObjectNode(); |
| 93 | localLeaf1Config.init(LOCAL_LEAF1, "icmp-handler-test", localLeaf1Tree, mapper, delegate); |
| 94 | localLeaf1Config.setNodeSidIPv4(LOCAL_LEAF1_SID4) |
| 95 | .setRouterIpv4(LOCAL_LEAF1_LB4) |
| 96 | .setNodeSidIPv6(LOCAL_LEAF1_SID6) |
| 97 | .setRouterIpv6(LOCAL_LEAF1_LB6) |
| 98 | .setIsEdgeRouter(true) |
| 99 | .setRouterMac(LOCAL_MAC1.toString()) |
| 100 | .setPairDeviceId(LOCAL_LEAF2) |
| 101 | .setPairLocalPort(P3); |
| 102 | SegmentRoutingDeviceConfig localLeaf2Config = new SegmentRoutingDeviceConfig(); |
| 103 | JsonNode localLeaf2Tree = mapper.createObjectNode(); |
| 104 | localLeaf2Config.init(LOCAL_LEAF2, "icmp-handler-test", localLeaf2Tree, mapper, delegate); |
| 105 | localLeaf2Config.setNodeSidIPv4(LOCAL_LEAF2_SID4) |
| 106 | .setRouterIpv4(LOCAL_LEAF2_LB4) |
| 107 | .setNodeSidIPv6(LOCAL_LEAF2_SID6) |
| 108 | .setRouterIpv6(LOCAL_LEAF2_LB6) |
| 109 | .setIsEdgeRouter(true) |
| 110 | .setRouterMac(LOCAL_MAC2.toString()) |
| 111 | .setPairDeviceId(LOCAL_LEAF1) |
| 112 | .setPairLocalPort(P3); |
| 113 | |
| 114 | // Setup configuration for ports |
| 115 | InterfaceConfig remoteLeafPorts1Config = new InterfaceConfig(); |
| 116 | ArrayNode remoteLeafPorts1Tree = mapper.createArrayNode(); |
| 117 | remoteLeafPorts1Config.init(CP12, "icmp-handler-test", remoteLeafPorts1Tree, mapper, delegate); |
| 118 | remoteLeafPorts1Config.addInterface(INTF1); |
| 119 | InterfaceConfig remoteLeafPorts2Config = new InterfaceConfig(); |
| 120 | ArrayNode remoteLeafPorts2Tree = mapper.createArrayNode(); |
| 121 | remoteLeafPorts2Config.init(CP13, "icmp-handler-test", remoteLeafPorts2Tree, mapper, delegate); |
| 122 | remoteLeafPorts2Config.addInterface(INTF2); |
| 123 | InterfaceConfig localLeafPortsConfig = new InterfaceConfig(); |
| 124 | ArrayNode localLeafPortsTree = mapper.createArrayNode(); |
| 125 | localLeafPortsConfig.init(CP1011, "icmp-handler-test", localLeafPortsTree, mapper, delegate); |
| 126 | localLeafPortsConfig.addInterface(INTF111); |
| 127 | InterfaceConfig localLeaf1PortsConfig = new InterfaceConfig(); |
| 128 | ArrayNode localLeaf1PortsTree = mapper.createArrayNode(); |
| 129 | localLeaf1PortsConfig.init(CP2011, "icmp-handler-test", localLeaf1PortsTree, mapper, delegate); |
| 130 | localLeaf1PortsConfig.addInterface(INTF211); |
| 131 | InterfaceConfig localLeaf2Ports1Config = new InterfaceConfig(); |
| 132 | ArrayNode localLeaf2Ports1Tree = mapper.createArrayNode(); |
| 133 | localLeaf2Ports1Config.init(CP2021, "icmp-handler-test", localLeaf2Ports1Tree, mapper, delegate); |
| 134 | localLeaf2Ports1Config.addInterface(INTF212); |
| 135 | InterfaceConfig localLeaf2Ports2Config = new InterfaceConfig(); |
| 136 | ArrayNode localLeaf2Ports2Tree = mapper.createArrayNode(); |
| 137 | localLeaf2Ports2Config.init(CP2024, "icmp-handler-test", localLeaf2Ports2Tree, mapper, delegate); |
| 138 | localLeaf2Ports2Config.addInterface(INTF213); |
| 139 | |
| 140 | // Apply config |
| 141 | MockNetworkConfigRegistry mockNetworkConfigRegistry = new MockNetworkConfigRegistry(); |
| 142 | mockNetworkConfigRegistry.applyConfig(remoteLeafConfig); |
| 143 | mockNetworkConfigRegistry.applyConfig(remoteLeafPorts1Config); |
| 144 | mockNetworkConfigRegistry.applyConfig(remoteLeafPorts2Config); |
| 145 | mockNetworkConfigRegistry.applyConfig(localLeafConfig); |
| 146 | mockNetworkConfigRegistry.applyConfig(localLeafPortsConfig); |
| 147 | mockNetworkConfigRegistry.applyConfig(localLeaf1Config); |
| 148 | mockNetworkConfigRegistry.applyConfig(localLeaf1PortsConfig); |
| 149 | mockNetworkConfigRegistry.applyConfig(localLeaf2Config); |
| 150 | mockNetworkConfigRegistry.applyConfig(localLeaf2Ports1Config); |
| 151 | mockNetworkConfigRegistry.applyConfig(localLeaf2Ports2Config); |
| 152 | |
| 153 | segmentRoutingManager = new SegmentRoutingManager(); |
| 154 | segmentRoutingManager.appId = testApplicationId; |
| 155 | packetService = new MockPacketService(); |
| 156 | segmentRoutingManager.packetService = packetService; |
| 157 | segmentRoutingManager.cfgService = mockNetworkConfigRegistry; |
| 158 | segmentRoutingManager.neighbourResolutionService = new MockNeighbourResolutionService(); |
| 159 | segmentRoutingManager.interfaceService = new MockInterfaceService(ImmutableSet.of( |
| 160 | INTF1, INTF2, INTF111, INTF211, INTF212, INTF213)); |
| 161 | segmentRoutingManager.deviceConfiguration = new DeviceConfiguration(segmentRoutingManager); |
| 162 | segmentRoutingManager.ipHandler = new IpHandler(segmentRoutingManager); |
| 163 | segmentRoutingManager.deviceService = createMock(DeviceService.class); |
| 164 | segmentRoutingManager.routeService = new MockRouteService(ROUTE_STORE); |
| 165 | segmentRoutingManager.hostService = new MockHostService(Collections.emptySet()); |
| 166 | icmpHandler = new IcmpHandler(segmentRoutingManager); |
| 167 | } |
| 168 | |
| 169 | // Ping to our gateway |
| 170 | @Test |
| 171 | public void testPing4MyGateway() { |
| 172 | // Expected behavior |
| 173 | expect(segmentRoutingManager.deviceService.isAvailable(REMOTE_LEAF)) |
| 174 | .andReturn(true) |
| 175 | .times(1); |
| 176 | replay(segmentRoutingManager.deviceService); |
| 177 | |
| 178 | // Process |
| 179 | icmpHandler.processIcmp(ETH_REQ_IPV4_MY, CP12); |
| 180 | |
| 181 | // Verify packet-out |
| 182 | Ethernet ethernet = packetService.getEthernetPacket(ETH_REQ_IPV4_MY.getSourceMAC()); |
| 183 | assertNotNull(ethernet); |
| 184 | assertThat(ethernet.getSourceMAC(), is(ETH_REQ_IPV4_MY.getDestinationMAC())); |
| 185 | assertThat(ethernet.getDestinationMAC(), is(ETH_REQ_IPV4_MY.getSourceMAC())); |
| 186 | assertTrue(ethernet.getPayload() instanceof IPv4); |
| 187 | IPv4 ip = (IPv4) ethernet.getPayload(); |
| 188 | assertThat(ip.getSourceAddress(), is(DST_IPV4.toInt())); |
| 189 | assertThat(ip.getDestinationAddress(), is(SRC_IPV4_MY.toInt())); |
| 190 | assertTrue(ip.getPayload() instanceof ICMP); |
| 191 | ICMP icmp = (ICMP) ip.getPayload(); |
| 192 | assertThat(icmp.getIcmpType(), is(TYPE_ECHO_REPLY)); |
| 193 | assertThat(icmp.getIcmpCode(), is(CODE_ECHO_REPLY)); |
| 194 | // Verify behavior |
| 195 | verify(segmentRoutingManager.deviceService); |
| 196 | } |
| 197 | |
| 198 | // Ping6 to our gateway |
| 199 | @Test |
| 200 | public void testPing6MyGateway() { |
| 201 | // Expected behavior |
| 202 | expect(segmentRoutingManager.deviceService.isAvailable(REMOTE_LEAF)) |
| 203 | .andReturn(true) |
| 204 | .times(1); |
| 205 | replay(segmentRoutingManager.deviceService); |
| 206 | |
| 207 | // Process |
| 208 | icmpHandler.processIcmpv6(ETH_REQ_IPV6_MY, CP12); |
| 209 | |
| 210 | // Verify packet-out |
| 211 | Ethernet ethernet = packetService.getEthernetPacket(ETH_REQ_IPV6_MY.getSourceMAC()); |
| 212 | assertNotNull(ethernet); |
| 213 | assertThat(ethernet.getSourceMAC(), is(ETH_REQ_IPV6_MY.getDestinationMAC())); |
| 214 | assertThat(ethernet.getDestinationMAC(), is(ETH_REQ_IPV6_MY.getSourceMAC())); |
| 215 | assertTrue(ethernet.getPayload() instanceof IPv6); |
| 216 | IPv6 ip = (IPv6) ethernet.getPayload(); |
| 217 | assertThat(ip.getSourceAddress(), is(DST_IPV6.toOctets())); |
| 218 | assertThat(ip.getDestinationAddress(), is(SRC_IPV6_MY.toOctets())); |
| 219 | assertTrue(ip.getPayload() instanceof ICMP6); |
| 220 | ICMP6 icmp = (ICMP6) ip.getPayload(); |
| 221 | assertThat(icmp.getIcmpType(), is(ECHO_REPLY)); |
| 222 | // Verify behavior |
| 223 | verify(segmentRoutingManager.deviceService); |
| 224 | } |
| 225 | |
| 226 | // Ping to a gateway attached to our leaf |
| 227 | @Test |
| 228 | public void testPing4LocalGateway() { |
| 229 | // Expected behavior |
| 230 | expect(segmentRoutingManager.deviceService.isAvailable(REMOTE_LEAF)) |
| 231 | .andReturn(true) |
| 232 | .times(1); |
| 233 | replay(segmentRoutingManager.deviceService); |
| 234 | |
| 235 | // Process |
| 236 | icmpHandler.processIcmp(ETH_REQ_IPV4_LOCAL, CP12); |
| 237 | |
| 238 | // Verify packet-out |
| 239 | Ethernet ethernet = packetService.getEthernetPacket(ETH_REQ_IPV4_LOCAL.getSourceMAC()); |
| 240 | assertNotNull(ethernet); |
| 241 | assertThat(ethernet.getSourceMAC(), is(ETH_REQ_IPV4_LOCAL.getDestinationMAC())); |
| 242 | assertThat(ethernet.getDestinationMAC(), is(ETH_REQ_IPV4_LOCAL.getSourceMAC())); |
| 243 | assertTrue(ethernet.getPayload() instanceof IPv4); |
| 244 | IPv4 ip = (IPv4) ethernet.getPayload(); |
| 245 | assertThat(ip.getSourceAddress(), is(DST_IPV4_LOCAL.toInt())); |
| 246 | assertThat(ip.getDestinationAddress(), is(SRC_IPV4_MY.toInt())); |
| 247 | assertTrue(ip.getPayload() instanceof ICMP); |
| 248 | ICMP icmp = (ICMP) ip.getPayload(); |
| 249 | assertThat(icmp.getIcmpType(), is(TYPE_ECHO_REPLY)); |
| 250 | assertThat(icmp.getIcmpCode(), is(CODE_ECHO_REPLY)); |
| 251 | // Verify behavior |
| 252 | verify(segmentRoutingManager.deviceService); |
| 253 | } |
| 254 | |
| 255 | // Ping6 to a gateway attached to our leaf |
| 256 | @Test |
| 257 | public void testPing6LocalGateway() { |
| 258 | // Expected behavior |
| 259 | expect(segmentRoutingManager.deviceService.isAvailable(REMOTE_LEAF)) |
| 260 | .andReturn(true) |
| 261 | .times(1); |
| 262 | replay(segmentRoutingManager.deviceService); |
| 263 | |
| 264 | // Process |
| 265 | icmpHandler.processIcmpv6(ETH_REQ_IPV6_LOCAL, CP12); |
| 266 | |
| 267 | // Verify packet-out |
| 268 | Ethernet ethernet = packetService.getEthernetPacket(ETH_REQ_IPV6_LOCAL.getSourceMAC()); |
| 269 | assertNotNull(ethernet); |
| 270 | assertThat(ethernet.getSourceMAC(), is(ETH_REQ_IPV6_LOCAL.getDestinationMAC())); |
| 271 | assertThat(ethernet.getDestinationMAC(), is(ETH_REQ_IPV6_LOCAL.getSourceMAC())); |
| 272 | assertTrue(ethernet.getPayload() instanceof IPv6); |
| 273 | IPv6 ip = (IPv6) ethernet.getPayload(); |
| 274 | assertThat(ip.getSourceAddress(), is(DST_IPV6_LOCAL.toOctets())); |
| 275 | assertThat(ip.getDestinationAddress(), is(SRC_IPV6_MY.toOctets())); |
| 276 | assertTrue(ip.getPayload() instanceof ICMP6); |
| 277 | ICMP6 icmp = (ICMP6) ip.getPayload(); |
| 278 | assertThat(icmp.getIcmpType(), is(ECHO_REPLY)); |
| 279 | // Verify behavior |
| 280 | verify(segmentRoutingManager.deviceService); |
| 281 | } |
| 282 | |
| 283 | // Ping to a gateway attached only to the pair leaf (routing through spine) |
| 284 | @Test |
| 285 | public void testPing4RemoteGatewaySamePair() { |
| 286 | // Expected behavior |
| 287 | expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF1)) |
| 288 | .andReturn(true) |
| 289 | .times(1); |
| 290 | expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF2)) |
| 291 | .andReturn(true) |
| 292 | .times(1); |
| 293 | replay(segmentRoutingManager.deviceService); |
| 294 | |
| 295 | // Process |
| 296 | icmpHandler.processIcmp(ETH_REQ_IPV4_SAME, CP2025); |
| 297 | |
| 298 | // Verify packet-out |
| 299 | Ethernet ethernet = packetService.getEthernetPacket(ETH_REQ_IPV4_SAME.getSourceMAC()); |
| 300 | assertNotNull(ethernet); |
| 301 | assertThat(ethernet.getSourceMAC(), is(ETH_REQ_IPV4_SAME.getDestinationMAC())); |
| 302 | assertThat(ethernet.getDestinationMAC(), is(ETH_REQ_IPV4_SAME.getSourceMAC())); |
| 303 | assertTrue(ethernet.getPayload() instanceof MPLS); |
| 304 | MPLS mpls = (MPLS) ethernet.getPayload(); |
| 305 | assertThat(mpls.getLabel(), is(LOCAL_LEAF1_SID4)); |
| 306 | assertTrue(mpls.getPayload() instanceof IPv4); |
| 307 | IPv4 ip = (IPv4) mpls.getPayload(); |
| 308 | assertThat(ip.getSourceAddress(), is(DST_IPV4_SAME.toInt())); |
| 309 | assertThat(ip.getDestinationAddress(), is(SRC_IPV41.toInt())); |
| 310 | assertTrue(ip.getPayload() instanceof ICMP); |
| 311 | ICMP icmp = (ICMP) ip.getPayload(); |
| 312 | assertThat(icmp.getIcmpType(), is(TYPE_ECHO_REPLY)); |
| 313 | assertThat(icmp.getIcmpCode(), is(CODE_ECHO_REPLY)); |
| 314 | // Verify behavior |
| 315 | verify(segmentRoutingManager.deviceService); |
| 316 | } |
| 317 | |
| 318 | // Ping6 to a gateway attached only to the pair leaf (routing through spine) |
| 319 | @Test |
| 320 | public void testPing6RemoteGatewaySamePair() { |
| 321 | // Expected behavior |
| 322 | expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF1)) |
| 323 | .andReturn(true) |
| 324 | .times(1); |
| 325 | expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF2)) |
| 326 | .andReturn(true) |
| 327 | .times(1); |
| 328 | replay(segmentRoutingManager.deviceService); |
| 329 | |
| 330 | // Process |
| 331 | icmpHandler.processIcmpv6(ETH_REQ_IPV6_SAME, CP2025); |
| 332 | |
| 333 | // Verify packet-out |
| 334 | Ethernet ethernet = packetService.getEthernetPacket(ETH_REQ_IPV6_SAME.getSourceMAC()); |
| 335 | assertNotNull(ethernet); |
| 336 | assertThat(ethernet.getSourceMAC(), is(ETH_REQ_IPV6_SAME.getDestinationMAC())); |
| 337 | assertThat(ethernet.getDestinationMAC(), is(ETH_REQ_IPV6_SAME.getSourceMAC())); |
| 338 | assertTrue(ethernet.getPayload() instanceof MPLS); |
| 339 | MPLS mpls = (MPLS) ethernet.getPayload(); |
| 340 | assertThat(mpls.getLabel(), is(LOCAL_LEAF1_SID6)); |
| 341 | assertTrue(mpls.getPayload() instanceof IPv6); |
| 342 | IPv6 ip = (IPv6) mpls.getPayload(); |
| 343 | assertThat(ip.getSourceAddress(), is(DST_IPV6_SAME.toOctets())); |
| 344 | assertThat(ip.getDestinationAddress(), is(SRC_IPV61.toOctets())); |
| 345 | assertTrue(ip.getPayload() instanceof ICMP6); |
| 346 | ICMP6 icmp = (ICMP6) ip.getPayload(); |
| 347 | assertThat(icmp.getIcmpType(), is(ECHO_REPLY)); |
| 348 | // Verify behavior |
| 349 | verify(segmentRoutingManager.deviceService); |
| 350 | } |
| 351 | |
| 352 | // Ping to a gateway but destination leaf is down |
| 353 | @Test |
| 354 | public void testPing4RemoteGatewayLeafDown() { |
| 355 | // Expected behavior |
| 356 | expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF)) |
| 357 | .andReturn(false) |
| 358 | .times(1); |
| 359 | replay(segmentRoutingManager.deviceService); |
| 360 | |
| 361 | // Process |
| 362 | icmpHandler.processIcmp(ETH_REQ_IPV4, CP11); |
| 363 | |
| 364 | // Verify packet-out |
| 365 | Ethernet ethernet = packetService.getEthernetPacket(ETH_REQ_IPV4.getSourceMAC()); |
| 366 | assertNull(ethernet); |
| 367 | |
| 368 | // Verify behavior |
| 369 | verify(segmentRoutingManager.deviceService); |
| 370 | } |
| 371 | |
| 372 | // Ping6 to a gateway but destination leaf is down |
| 373 | @Test |
| 374 | public void testPing6RemoteGatewayLeafDown() { |
| 375 | // Expected behavior |
| 376 | expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF)) |
| 377 | .andReturn(false) |
| 378 | .times(1); |
| 379 | replay(segmentRoutingManager.deviceService); |
| 380 | |
| 381 | // Process |
| 382 | icmpHandler.processIcmpv6(ETH_REQ_IPV6, CP11); |
| 383 | |
| 384 | // Verify packet-out |
| 385 | Ethernet ethernet = packetService.getEthernetPacket(ETH_REQ_IPV6.getSourceMAC()); |
| 386 | assertNull(ethernet); |
| 387 | |
| 388 | // Verify behavior |
| 389 | verify(segmentRoutingManager.deviceService); |
| 390 | } |
| 391 | |
| 392 | // Ping to a gateway but one of the destination leaf is down |
| 393 | @Test |
| 394 | public void testPing4RemoteGatewayLeaf1Down() { |
| 395 | // Expected behavior |
| 396 | expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF1)) |
| 397 | .andReturn(false) |
| 398 | .times(1); |
| 399 | expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF2)) |
| 400 | .andReturn(true) |
| 401 | .times(1); |
| 402 | replay(segmentRoutingManager.deviceService); |
| 403 | |
| 404 | // Process |
| 405 | icmpHandler.processIcmp(ETH_REQ_IPV41, CP11); |
| 406 | |
| 407 | // Verify packet-out |
| 408 | Ethernet ethernet = packetService.getEthernetPacket(ETH_REQ_IPV41.getSourceMAC()); |
| 409 | assertNotNull(ethernet); |
| 410 | assertThat(ethernet.getSourceMAC(), is(ETH_REQ_IPV41.getDestinationMAC())); |
| 411 | assertThat(ethernet.getDestinationMAC(), is(ETH_REQ_IPV41.getSourceMAC())); |
| 412 | assertThat(ethernet.getEtherType(), is(Ethernet.MPLS_UNICAST)); |
| 413 | assertTrue(ethernet.getPayload() instanceof MPLS); |
| 414 | MPLS mpls = (MPLS) ethernet.getPayload(); |
| 415 | assertThat(mpls.getLabel(), is(LOCAL_LEAF2_SID4)); |
| 416 | assertTrue(mpls.getPayload() instanceof IPv4); |
| 417 | IPv4 ip = (IPv4) mpls.getPayload(); |
| 418 | assertThat(ip.getSourceAddress(), is(DST_IPV4.toInt())); |
| 419 | assertThat(ip.getDestinationAddress(), is(SRC_IPV41.toInt())); |
| 420 | assertTrue(ip.getPayload() instanceof ICMP); |
| 421 | ICMP icmp = (ICMP) ip.getPayload(); |
| 422 | assertThat(icmp.getIcmpType(), is(TYPE_ECHO_REPLY)); |
| 423 | assertThat(icmp.getIcmpCode(), is(CODE_ECHO_REPLY)); |
| 424 | // Verify behavior |
| 425 | verify(segmentRoutingManager.deviceService); |
| 426 | } |
| 427 | |
| 428 | // Ping6 to a gateway but one of the destination leaf is down |
| 429 | @Test |
| 430 | public void testPing6RemoteGatewayLeaf2Down() { |
| 431 | // Expected behavior |
| 432 | expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF1)) |
| 433 | .andReturn(true) |
| 434 | .times(1); |
| 435 | expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF2)) |
| 436 | .andReturn(false) |
| 437 | .times(1); |
| 438 | replay(segmentRoutingManager.deviceService); |
| 439 | |
| 440 | // Process |
| 441 | icmpHandler.processIcmpv6(ETH_REQ_IPV61, CP11); |
| 442 | |
| 443 | // Verify packet-out |
| 444 | Ethernet ethernet = packetService.getEthernetPacket(ETH_REQ_IPV61.getSourceMAC()); |
| 445 | assertNotNull(ethernet); |
| 446 | assertThat(ethernet.getSourceMAC(), is(ETH_REQ_IPV61.getDestinationMAC())); |
| 447 | assertThat(ethernet.getDestinationMAC(), is(ETH_REQ_IPV61.getSourceMAC())); |
| 448 | assertThat(ethernet.getEtherType(), is(Ethernet.MPLS_UNICAST)); |
| 449 | assertTrue(ethernet.getPayload() instanceof MPLS); |
| 450 | MPLS mpls = (MPLS) ethernet.getPayload(); |
| 451 | assertThat(mpls.getLabel(), is(LOCAL_LEAF1_SID6)); |
| 452 | assertTrue(mpls.getPayload() instanceof IPv6); |
| 453 | IPv6 ip = (IPv6) mpls.getPayload(); |
| 454 | assertThat(ip.getSourceAddress(), is(DST_IPV6.toOctets())); |
| 455 | assertThat(ip.getDestinationAddress(), is(SRC_IPV61.toOctets())); |
| 456 | assertTrue(ip.getPayload() instanceof ICMP6); |
| 457 | ICMP6 icmp = (ICMP6) ip.getPayload(); |
| 458 | assertThat(icmp.getIcmpType(), is(ECHO_REPLY)); |
| 459 | // Verify behavior |
| 460 | verify(segmentRoutingManager.deviceService); |
| 461 | } |
| 462 | |
| 463 | // Ping6 to a link local address |
| 464 | @Test |
| 465 | public void testPing6LinkLocalAddress() { |
| 466 | // Process |
| 467 | icmpHandler.processIcmpv6(ETH_REQ_IPV6_LL, CP12); |
| 468 | |
| 469 | // Verify packet-out |
| 470 | Ethernet ethernet = packetService.getEthernetPacket(ETH_REQ_IPV6_LL.getSourceMAC()); |
| 471 | assertNotNull(ethernet); |
| 472 | assertThat(ethernet.getSourceMAC(), is(ETH_REQ_IPV6_LL.getDestinationMAC())); |
| 473 | assertThat(ethernet.getDestinationMAC(), is(ETH_REQ_IPV6_LL.getSourceMAC())); |
| 474 | assertTrue(ethernet.getPayload() instanceof IPv6); |
| 475 | IPv6 ip = (IPv6) ethernet.getPayload(); |
| 476 | assertThat(ip.getSourceAddress(), is(DST_IPV6_LL.toOctets())); |
| 477 | assertThat(ip.getDestinationAddress(), is(SRC_IPV6_LL.toOctets())); |
| 478 | assertTrue(ip.getPayload() instanceof ICMP6); |
| 479 | ICMP6 icmp = (ICMP6) ip.getPayload(); |
| 480 | assertThat(icmp.getIcmpType(), is(ECHO_REPLY)); |
| 481 | } |
| 482 | |
| 483 | // Ping to the looback of our leaf |
| 484 | @Test |
| 485 | public void testPing4Loopback() { |
| 486 | // Expected behavior |
| 487 | expect(segmentRoutingManager.deviceService.isAvailable(REMOTE_LEAF)) |
| 488 | .andReturn(true) |
| 489 | .times(1); |
| 490 | replay(segmentRoutingManager.deviceService); |
| 491 | |
| 492 | // Process |
| 493 | icmpHandler.processIcmp(ETH_REQ_IPV4_LOOPBACK, CP12); |
| 494 | |
| 495 | // Verify packet-out |
| 496 | Ethernet ethernet = packetService.getEthernetPacket(ETH_REQ_IPV4_LOOPBACK.getSourceMAC()); |
| 497 | assertNotNull(ethernet); |
| 498 | assertThat(ethernet.getSourceMAC(), is(ETH_REQ_IPV4_LOOPBACK.getDestinationMAC())); |
| 499 | assertThat(ethernet.getDestinationMAC(), is(ETH_REQ_IPV4_LOOPBACK.getSourceMAC())); |
| 500 | assertTrue(ethernet.getPayload() instanceof IPv4); |
| 501 | IPv4 ip = (IPv4) ethernet.getPayload(); |
| 502 | assertThat(ip.getSourceAddress(), is(DST_IPV4_LOOPBACK.toInt())); |
| 503 | assertThat(ip.getDestinationAddress(), is(SRC_IPV4_MY.toInt())); |
| 504 | assertTrue(ip.getPayload() instanceof ICMP); |
| 505 | ICMP icmp = (ICMP) ip.getPayload(); |
| 506 | assertThat(icmp.getIcmpType(), is(TYPE_ECHO_REPLY)); |
| 507 | assertThat(icmp.getIcmpCode(), is(CODE_ECHO_REPLY)); |
| 508 | // Verify behavior |
| 509 | verify(segmentRoutingManager.deviceService); |
| 510 | } |
| 511 | |
| 512 | // Ping6 to the looback of our leaf |
| 513 | @Test |
| 514 | public void testPing6Loopback() { |
| 515 | // Expected behavior |
| 516 | expect(segmentRoutingManager.deviceService.isAvailable(REMOTE_LEAF)) |
| 517 | .andReturn(true) |
| 518 | .times(1); |
| 519 | replay(segmentRoutingManager.deviceService); |
| 520 | |
| 521 | // Process |
| 522 | icmpHandler.processIcmpv6(ETH_REQ_IPV6_LOOPBACK, CP12); |
| 523 | |
| 524 | // Verify packet-out |
| 525 | Ethernet ethernet = packetService.getEthernetPacket(ETH_REQ_IPV6_LOOPBACK.getSourceMAC()); |
| 526 | assertNotNull(ethernet); |
| 527 | assertThat(ethernet.getSourceMAC(), is(ETH_REQ_IPV6_LOOPBACK.getDestinationMAC())); |
| 528 | assertThat(ethernet.getDestinationMAC(), is(ETH_REQ_IPV6_LOOPBACK.getSourceMAC())); |
| 529 | assertTrue(ethernet.getPayload() instanceof IPv6); |
| 530 | IPv6 ip = (IPv6) ethernet.getPayload(); |
| 531 | assertThat(ip.getSourceAddress(), is(DST_IPV6_LOOPBACK.toOctets())); |
| 532 | assertThat(ip.getDestinationAddress(), is(SRC_IPV6_MY.toOctets())); |
| 533 | assertTrue(ip.getPayload() instanceof ICMP6); |
| 534 | ICMP6 icmp = (ICMP6) ip.getPayload(); |
| 535 | assertThat(icmp.getIcmpType(), is(ECHO_REPLY)); |
| 536 | // Verify behavior |
| 537 | verify(segmentRoutingManager.deviceService); |
| 538 | } |
| 539 | |
| 540 | // Ping to the looback of our leaf (pair) |
| 541 | @Test |
| 542 | public void testPing4LoopbackPair() { |
| 543 | // Expected behavior |
| 544 | expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF1)) |
| 545 | .andReturn(true) |
| 546 | .times(1); |
| 547 | expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF2)) |
| 548 | .andReturn(true) |
| 549 | .times(1); |
| 550 | replay(segmentRoutingManager.deviceService); |
| 551 | |
| 552 | // Process |
| 553 | icmpHandler.processIcmp(ETH_REQ_IPV4_LOOPBACK_PAIR, CP2011); |
| 554 | |
| 555 | // Verify packet-out |
| 556 | Ethernet ethernet = packetService.getEthernetPacket(ETH_REQ_IPV4_LOOPBACK_PAIR.getSourceMAC()); |
| 557 | assertNotNull(ethernet); |
| 558 | assertThat(ethernet.getSourceMAC(), is(ETH_REQ_IPV4_LOOPBACK_PAIR.getDestinationMAC())); |
| 559 | assertThat(ethernet.getDestinationMAC(), is(ETH_REQ_IPV4_LOOPBACK_PAIR.getSourceMAC())); |
| 560 | assertTrue(ethernet.getPayload() instanceof IPv4); |
| 561 | IPv4 ip = (IPv4) ethernet.getPayload(); |
| 562 | assertThat(ip.getSourceAddress(), is(DST_IPV4_LOOPBACK_PAIR.toInt())); |
| 563 | assertThat(ip.getDestinationAddress(), is(SRC_IPV41.toInt())); |
| 564 | assertTrue(ip.getPayload() instanceof ICMP); |
| 565 | ICMP icmp = (ICMP) ip.getPayload(); |
| 566 | assertThat(icmp.getIcmpType(), is(TYPE_ECHO_REPLY)); |
| 567 | assertThat(icmp.getIcmpCode(), is(CODE_ECHO_REPLY)); |
| 568 | // Verify behavior |
| 569 | verify(segmentRoutingManager.deviceService); |
| 570 | } |
| 571 | |
| 572 | // Ping6 to the looback of our leaf (pair) |
| 573 | @Test |
| 574 | public void testPing6LoopbackPair() { |
| 575 | // Expected behavior |
| 576 | expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF1)) |
| 577 | .andReturn(true) |
| 578 | .times(1); |
| 579 | expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF2)) |
| 580 | .andReturn(true) |
| 581 | .times(1); |
| 582 | replay(segmentRoutingManager.deviceService); |
| 583 | |
| 584 | // Process |
| 585 | icmpHandler.processIcmpv6(ETH_REQ_IPV6_LOOPBACK_PAIR, CP2021); |
| 586 | |
| 587 | // Verify packet-out |
| 588 | Ethernet ethernet = packetService.getEthernetPacket(ETH_REQ_IPV6_LOOPBACK_PAIR.getSourceMAC()); |
| 589 | assertNotNull(ethernet); |
| 590 | assertThat(ethernet.getSourceMAC(), is(ETH_REQ_IPV6_LOOPBACK_PAIR.getDestinationMAC())); |
| 591 | assertThat(ethernet.getDestinationMAC(), is(ETH_REQ_IPV6_LOOPBACK_PAIR.getSourceMAC())); |
| 592 | assertTrue(ethernet.getPayload() instanceof IPv6); |
| 593 | IPv6 ip = (IPv6) ethernet.getPayload(); |
| 594 | assertThat(ip.getSourceAddress(), is(DST_IPV6_LOOPBACK_PAIR.toOctets())); |
| 595 | assertThat(ip.getDestinationAddress(), is(SRC_IPV61.toOctets())); |
| 596 | assertTrue(ip.getPayload() instanceof ICMP6); |
| 597 | ICMP6 icmp = (ICMP6) ip.getPayload(); |
| 598 | assertThat(icmp.getIcmpType(), is(ECHO_REPLY)); |
| 599 | // Verify behavior |
| 600 | verify(segmentRoutingManager.deviceService); |
| 601 | } |
| 602 | |
| 603 | // Ping to the loopback of the leaf but hashing of the bond interfaces sends to wrong leaf |
| 604 | @Test |
| 605 | public void testPing4LoopbackPairDifferentLeaf() { |
| 606 | // Expected behavior |
| 607 | expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF1)) |
| 608 | .andReturn(true) |
| 609 | .times(1); |
| 610 | expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF2)) |
| 611 | .andReturn(true) |
| 612 | .times(1); |
| 613 | replay(segmentRoutingManager.deviceService); |
| 614 | |
| 615 | // Process |
| 616 | icmpHandler.processIcmp(ETH_REQ_IPV4_LOOPBACK_PAIR, CP2021); |
| 617 | |
| 618 | // Verify packet-out |
| 619 | Ethernet ethernet = packetService.getEthernetPacket(ETH_REQ_IPV4_LOOPBACK_PAIR.getSourceMAC()); |
| 620 | assertNotNull(ethernet); |
| 621 | assertThat(ethernet.getSourceMAC(), is(ETH_REQ_IPV4_LOOPBACK_PAIR.getDestinationMAC())); |
| 622 | assertThat(ethernet.getDestinationMAC(), is(ETH_REQ_IPV4_LOOPBACK_PAIR.getSourceMAC())); |
| 623 | assertTrue(ethernet.getPayload() instanceof IPv4); |
| 624 | IPv4 ip = (IPv4) ethernet.getPayload(); |
| 625 | assertThat(ip.getSourceAddress(), is(DST_IPV4_LOOPBACK_PAIR.toInt())); |
| 626 | assertThat(ip.getDestinationAddress(), is(SRC_IPV41.toInt())); |
| 627 | assertTrue(ip.getPayload() instanceof ICMP); |
| 628 | ICMP icmp = (ICMP) ip.getPayload(); |
| 629 | assertThat(icmp.getIcmpType(), is(TYPE_ECHO_REPLY)); |
| 630 | assertThat(icmp.getIcmpCode(), is(CODE_ECHO_REPLY)); |
| 631 | // Verify behavior |
| 632 | verify(segmentRoutingManager.deviceService); |
| 633 | } |
| 634 | |
| 635 | // Ping6 to the loopback of the leaf but hashing of the bond interfaces sends to wrong leaf |
| 636 | @Test |
| 637 | public void testPing6LoopbackPairDifferentLeaf() { |
| 638 | // Expected behavior |
| 639 | expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF1)) |
| 640 | .andReturn(true) |
| 641 | .times(1); |
| 642 | expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF2)) |
| 643 | .andReturn(true) |
| 644 | .times(1); |
| 645 | replay(segmentRoutingManager.deviceService); |
| 646 | |
| 647 | // Process |
| 648 | icmpHandler.processIcmpv6(ETH_REQ_IPV6_LOOPBACK_PAIR, CP2011); |
| 649 | |
| 650 | // Verify packet-out |
| 651 | Ethernet ethernet = packetService.getEthernetPacket(ETH_REQ_IPV6_LOOPBACK_PAIR.getSourceMAC()); |
| 652 | assertNotNull(ethernet); |
| 653 | assertThat(ethernet.getSourceMAC(), is(ETH_REQ_IPV6_LOOPBACK_PAIR.getDestinationMAC())); |
| 654 | assertThat(ethernet.getDestinationMAC(), is(ETH_REQ_IPV6_LOOPBACK_PAIR.getSourceMAC())); |
| 655 | assertTrue(ethernet.getPayload() instanceof IPv6); |
| 656 | IPv6 ip = (IPv6) ethernet.getPayload(); |
| 657 | assertThat(ip.getSourceAddress(), is(DST_IPV6_LOOPBACK_PAIR.toOctets())); |
| 658 | assertThat(ip.getDestinationAddress(), is(SRC_IPV61.toOctets())); |
| 659 | assertTrue(ip.getPayload() instanceof ICMP6); |
| 660 | ICMP6 icmp = (ICMP6) ip.getPayload(); |
| 661 | assertThat(icmp.getIcmpType(), is(ECHO_REPLY)); |
| 662 | // Verify behavior |
| 663 | verify(segmentRoutingManager.deviceService); |
| 664 | } |
| 665 | |
| 666 | // Ping loopback of a destination that is down but |
| 667 | // hashing of the bond interfaces sends to other leaf |
| 668 | @Test |
| 669 | public void testPing4LoopbackPairDifferentLeafDown() { |
| 670 | // Expected behavior |
| 671 | expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF1)) |
| 672 | .andReturn(false) |
| 673 | .times(1); |
| 674 | expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF2)) |
| 675 | .andReturn(true) |
| 676 | .times(1); |
| 677 | replay(segmentRoutingManager.deviceService); |
| 678 | |
| 679 | // Process |
| 680 | icmpHandler.processIcmp(ETH_REQ_IPV4_LOOPBACK_PAIR, CP2021); |
| 681 | |
| 682 | // Verify packet-out |
| 683 | Ethernet ethernet = packetService.getEthernetPacket(ETH_REQ_IPV4_LOOPBACK_PAIR.getSourceMAC()); |
| 684 | assertNotNull(ethernet); |
| 685 | assertThat(ethernet.getSourceMAC(), is(ETH_REQ_IPV4_LOOPBACK_PAIR.getDestinationMAC())); |
| 686 | assertThat(ethernet.getDestinationMAC(), is(ETH_REQ_IPV4_LOOPBACK_PAIR.getSourceMAC())); |
| 687 | assertTrue(ethernet.getPayload() instanceof IPv4); |
| 688 | IPv4 ip = (IPv4) ethernet.getPayload(); |
| 689 | assertThat(ip.getSourceAddress(), is(DST_IPV4_LOOPBACK_PAIR.toInt())); |
| 690 | assertThat(ip.getDestinationAddress(), is(SRC_IPV41.toInt())); |
| 691 | assertTrue(ip.getPayload() instanceof ICMP); |
| 692 | ICMP icmp = (ICMP) ip.getPayload(); |
| 693 | assertThat(icmp.getIcmpType(), is(TYPE_ECHO_REPLY)); |
| 694 | assertThat(icmp.getIcmpCode(), is(CODE_ECHO_REPLY)); |
| 695 | // Verify behavior |
| 696 | verify(segmentRoutingManager.deviceService); |
| 697 | } |
| 698 | |
| 699 | // Ping6 loopback of a destination that is down but |
| 700 | // hashing of the bond interfaces sends to other leaf |
| 701 | @Test |
| 702 | public void testPing6LoopbackPairDifferentLeafDown() { |
| 703 | // Expected behavior |
| 704 | expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF1)) |
| 705 | .andReturn(true) |
| 706 | .times(1); |
| 707 | expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF2)) |
| 708 | .andReturn(false) |
| 709 | .times(1); |
| 710 | replay(segmentRoutingManager.deviceService); |
| 711 | |
| 712 | // Process |
| 713 | icmpHandler.processIcmpv6(ETH_REQ_IPV6_LOOPBACK_PAIR, CP2011); |
| 714 | |
| 715 | // Verify packet-out |
| 716 | Ethernet ethernet = packetService.getEthernetPacket(ETH_REQ_IPV6_LOOPBACK_PAIR.getSourceMAC()); |
| 717 | assertNotNull(ethernet); |
| 718 | assertThat(ethernet.getSourceMAC(), is(ETH_REQ_IPV6_LOOPBACK_PAIR.getDestinationMAC())); |
| 719 | assertThat(ethernet.getDestinationMAC(), is(ETH_REQ_IPV6_LOOPBACK_PAIR.getSourceMAC())); |
| 720 | assertTrue(ethernet.getPayload() instanceof IPv6); |
| 721 | IPv6 ip = (IPv6) ethernet.getPayload(); |
| 722 | assertThat(ip.getSourceAddress(), is(DST_IPV6_LOOPBACK_PAIR.toOctets())); |
| 723 | assertThat(ip.getDestinationAddress(), is(SRC_IPV61.toOctets())); |
| 724 | assertTrue(ip.getPayload() instanceof ICMP6); |
| 725 | ICMP6 icmp = (ICMP6) ip.getPayload(); |
| 726 | assertThat(icmp.getIcmpType(), is(ECHO_REPLY)); |
| 727 | // Verify behavior |
| 728 | verify(segmentRoutingManager.deviceService); |
| 729 | } |
| 730 | |
| 731 | // Ping to a dh gateway |
| 732 | @Test |
| 733 | public void testPing4GatewayPair() { |
| 734 | // Expected behavior |
| 735 | expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF1)) |
| 736 | .andReturn(true) |
| 737 | .times(1); |
| 738 | expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF2)) |
| 739 | .andReturn(true) |
| 740 | .times(1); |
| 741 | replay(segmentRoutingManager.deviceService); |
| 742 | |
| 743 | // Process |
| 744 | icmpHandler.processIcmp(ETH_REQ_IPV4_GATEWAY_PAIR, CP2011); |
| 745 | |
| 746 | // Verify packet-out |
| 747 | Ethernet ethernet = packetService.getEthernetPacket(ETH_REQ_IPV4_GATEWAY_PAIR.getSourceMAC()); |
| 748 | assertNotNull(ethernet); |
| 749 | assertThat(ethernet.getSourceMAC(), is(ETH_REQ_IPV4_GATEWAY_PAIR.getDestinationMAC())); |
| 750 | assertThat(ethernet.getDestinationMAC(), is(ETH_REQ_IPV4_GATEWAY_PAIR.getSourceMAC())); |
| 751 | assertTrue(ethernet.getPayload() instanceof IPv4); |
| 752 | IPv4 ip = (IPv4) ethernet.getPayload(); |
| 753 | assertThat(ip.getSourceAddress(), is(DST_IPV4_GATEWAY_PAIR.toInt())); |
| 754 | assertThat(ip.getDestinationAddress(), is(SRC_IPV41.toInt())); |
| 755 | assertTrue(ip.getPayload() instanceof ICMP); |
| 756 | ICMP icmp = (ICMP) ip.getPayload(); |
| 757 | assertThat(icmp.getIcmpType(), is(TYPE_ECHO_REPLY)); |
| 758 | assertThat(icmp.getIcmpCode(), is(CODE_ECHO_REPLY)); |
| 759 | // Verify behavior |
| 760 | verify(segmentRoutingManager.deviceService); |
| 761 | } |
| 762 | |
| 763 | // Ping6 to a dh gateway |
| 764 | @Test |
| 765 | public void testPing6GatewayPair() { |
| 766 | // Expected behavior |
| 767 | expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF1)) |
| 768 | .andReturn(true) |
| 769 | .times(1); |
| 770 | expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF2)) |
| 771 | .andReturn(true) |
| 772 | .times(1); |
| 773 | replay(segmentRoutingManager.deviceService); |
| 774 | |
| 775 | // Process |
| 776 | icmpHandler.processIcmpv6(ETH_REQ_IPV6_GATEWAY_PAIR, CP2021); |
| 777 | |
| 778 | // Verify packet-out |
| 779 | Ethernet ethernet = packetService.getEthernetPacket(ETH_REQ_IPV6_GATEWAY_PAIR.getSourceMAC()); |
| 780 | assertNotNull(ethernet); |
| 781 | assertThat(ethernet.getSourceMAC(), is(ETH_REQ_IPV6_GATEWAY_PAIR.getDestinationMAC())); |
| 782 | assertThat(ethernet.getDestinationMAC(), is(ETH_REQ_IPV6_GATEWAY_PAIR.getSourceMAC())); |
| 783 | assertTrue(ethernet.getPayload() instanceof IPv6); |
| 784 | IPv6 ip = (IPv6) ethernet.getPayload(); |
| 785 | assertThat(ip.getSourceAddress(), is(DST_IPV6_GATEWAY_PAIR.toOctets())); |
| 786 | assertThat(ip.getDestinationAddress(), is(SRC_IPV61.toOctets())); |
| 787 | assertTrue(ip.getPayload() instanceof ICMP6); |
| 788 | ICMP6 icmp = (ICMP6) ip.getPayload(); |
| 789 | assertThat(icmp.getIcmpType(), is(ECHO_REPLY)); |
| 790 | // Verify behavior |
| 791 | verify(segmentRoutingManager.deviceService); |
| 792 | } |
| 793 | |
| 794 | } |