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(); |
Andrea Campanella | 0994384 | 2020-03-27 12:53:46 +0100 | [diff] [blame] | 142 | |
pier | 6a2052b | 2019-06-28 22:17:31 +0200 | [diff] [blame] | 143 | mockNetworkConfigRegistry.applyConfig(remoteLeafConfig); |
| 144 | mockNetworkConfigRegistry.applyConfig(remoteLeafPorts1Config); |
| 145 | mockNetworkConfigRegistry.applyConfig(remoteLeafPorts2Config); |
| 146 | mockNetworkConfigRegistry.applyConfig(localLeafConfig); |
| 147 | mockNetworkConfigRegistry.applyConfig(localLeafPortsConfig); |
| 148 | mockNetworkConfigRegistry.applyConfig(localLeaf1Config); |
| 149 | mockNetworkConfigRegistry.applyConfig(localLeaf1PortsConfig); |
| 150 | mockNetworkConfigRegistry.applyConfig(localLeaf2Config); |
| 151 | mockNetworkConfigRegistry.applyConfig(localLeaf2Ports1Config); |
| 152 | mockNetworkConfigRegistry.applyConfig(localLeaf2Ports2Config); |
| 153 | |
| 154 | segmentRoutingManager = new SegmentRoutingManager(); |
| 155 | segmentRoutingManager.appId = testApplicationId; |
| 156 | packetService = new MockPacketService(); |
| 157 | segmentRoutingManager.packetService = packetService; |
| 158 | segmentRoutingManager.cfgService = mockNetworkConfigRegistry; |
| 159 | segmentRoutingManager.neighbourResolutionService = new MockNeighbourResolutionService(); |
| 160 | segmentRoutingManager.interfaceService = new MockInterfaceService(ImmutableSet.of( |
| 161 | INTF1, INTF2, INTF111, INTF211, INTF212, INTF213)); |
| 162 | segmentRoutingManager.deviceConfiguration = new DeviceConfiguration(segmentRoutingManager); |
| 163 | segmentRoutingManager.ipHandler = new IpHandler(segmentRoutingManager); |
| 164 | segmentRoutingManager.deviceService = createMock(DeviceService.class); |
| 165 | segmentRoutingManager.routeService = new MockRouteService(ROUTE_STORE); |
| 166 | segmentRoutingManager.hostService = new MockHostService(Collections.emptySet()); |
| 167 | icmpHandler = new IcmpHandler(segmentRoutingManager); |
| 168 | } |
| 169 | |
| 170 | // Ping to our gateway |
| 171 | @Test |
| 172 | public void testPing4MyGateway() { |
| 173 | // Expected behavior |
| 174 | expect(segmentRoutingManager.deviceService.isAvailable(REMOTE_LEAF)) |
| 175 | .andReturn(true) |
| 176 | .times(1); |
| 177 | replay(segmentRoutingManager.deviceService); |
| 178 | |
| 179 | // Process |
| 180 | icmpHandler.processIcmp(ETH_REQ_IPV4_MY, CP12); |
| 181 | |
| 182 | // Verify packet-out |
| 183 | Ethernet ethernet = packetService.getEthernetPacket(ETH_REQ_IPV4_MY.getSourceMAC()); |
| 184 | assertNotNull(ethernet); |
| 185 | assertThat(ethernet.getSourceMAC(), is(ETH_REQ_IPV4_MY.getDestinationMAC())); |
| 186 | assertThat(ethernet.getDestinationMAC(), is(ETH_REQ_IPV4_MY.getSourceMAC())); |
| 187 | assertTrue(ethernet.getPayload() instanceof IPv4); |
| 188 | IPv4 ip = (IPv4) ethernet.getPayload(); |
| 189 | assertThat(ip.getSourceAddress(), is(DST_IPV4.toInt())); |
| 190 | assertThat(ip.getDestinationAddress(), is(SRC_IPV4_MY.toInt())); |
| 191 | assertTrue(ip.getPayload() instanceof ICMP); |
| 192 | ICMP icmp = (ICMP) ip.getPayload(); |
| 193 | assertThat(icmp.getIcmpType(), is(TYPE_ECHO_REPLY)); |
| 194 | assertThat(icmp.getIcmpCode(), is(CODE_ECHO_REPLY)); |
| 195 | // Verify behavior |
| 196 | verify(segmentRoutingManager.deviceService); |
| 197 | } |
| 198 | |
| 199 | // Ping6 to our gateway |
| 200 | @Test |
| 201 | public void testPing6MyGateway() { |
| 202 | // Expected behavior |
| 203 | expect(segmentRoutingManager.deviceService.isAvailable(REMOTE_LEAF)) |
| 204 | .andReturn(true) |
| 205 | .times(1); |
| 206 | replay(segmentRoutingManager.deviceService); |
| 207 | |
| 208 | // Process |
| 209 | icmpHandler.processIcmpv6(ETH_REQ_IPV6_MY, CP12); |
| 210 | |
| 211 | // Verify packet-out |
| 212 | Ethernet ethernet = packetService.getEthernetPacket(ETH_REQ_IPV6_MY.getSourceMAC()); |
| 213 | assertNotNull(ethernet); |
| 214 | assertThat(ethernet.getSourceMAC(), is(ETH_REQ_IPV6_MY.getDestinationMAC())); |
| 215 | assertThat(ethernet.getDestinationMAC(), is(ETH_REQ_IPV6_MY.getSourceMAC())); |
| 216 | assertTrue(ethernet.getPayload() instanceof IPv6); |
| 217 | IPv6 ip = (IPv6) ethernet.getPayload(); |
| 218 | assertThat(ip.getSourceAddress(), is(DST_IPV6.toOctets())); |
| 219 | assertThat(ip.getDestinationAddress(), is(SRC_IPV6_MY.toOctets())); |
| 220 | assertTrue(ip.getPayload() instanceof ICMP6); |
| 221 | ICMP6 icmp = (ICMP6) ip.getPayload(); |
| 222 | assertThat(icmp.getIcmpType(), is(ECHO_REPLY)); |
| 223 | // Verify behavior |
| 224 | verify(segmentRoutingManager.deviceService); |
| 225 | } |
| 226 | |
| 227 | // Ping to a gateway attached to our leaf |
| 228 | @Test |
| 229 | public void testPing4LocalGateway() { |
| 230 | // Expected behavior |
| 231 | expect(segmentRoutingManager.deviceService.isAvailable(REMOTE_LEAF)) |
| 232 | .andReturn(true) |
| 233 | .times(1); |
| 234 | replay(segmentRoutingManager.deviceService); |
| 235 | |
| 236 | // Process |
| 237 | icmpHandler.processIcmp(ETH_REQ_IPV4_LOCAL, CP12); |
| 238 | |
| 239 | // Verify packet-out |
| 240 | Ethernet ethernet = packetService.getEthernetPacket(ETH_REQ_IPV4_LOCAL.getSourceMAC()); |
| 241 | assertNotNull(ethernet); |
| 242 | assertThat(ethernet.getSourceMAC(), is(ETH_REQ_IPV4_LOCAL.getDestinationMAC())); |
| 243 | assertThat(ethernet.getDestinationMAC(), is(ETH_REQ_IPV4_LOCAL.getSourceMAC())); |
| 244 | assertTrue(ethernet.getPayload() instanceof IPv4); |
| 245 | IPv4 ip = (IPv4) ethernet.getPayload(); |
| 246 | assertThat(ip.getSourceAddress(), is(DST_IPV4_LOCAL.toInt())); |
| 247 | assertThat(ip.getDestinationAddress(), is(SRC_IPV4_MY.toInt())); |
| 248 | assertTrue(ip.getPayload() instanceof ICMP); |
| 249 | ICMP icmp = (ICMP) ip.getPayload(); |
| 250 | assertThat(icmp.getIcmpType(), is(TYPE_ECHO_REPLY)); |
| 251 | assertThat(icmp.getIcmpCode(), is(CODE_ECHO_REPLY)); |
| 252 | // Verify behavior |
| 253 | verify(segmentRoutingManager.deviceService); |
| 254 | } |
| 255 | |
| 256 | // Ping6 to a gateway attached to our leaf |
| 257 | @Test |
| 258 | public void testPing6LocalGateway() { |
| 259 | // Expected behavior |
| 260 | expect(segmentRoutingManager.deviceService.isAvailable(REMOTE_LEAF)) |
| 261 | .andReturn(true) |
| 262 | .times(1); |
| 263 | replay(segmentRoutingManager.deviceService); |
| 264 | |
| 265 | // Process |
| 266 | icmpHandler.processIcmpv6(ETH_REQ_IPV6_LOCAL, CP12); |
| 267 | |
| 268 | // Verify packet-out |
| 269 | Ethernet ethernet = packetService.getEthernetPacket(ETH_REQ_IPV6_LOCAL.getSourceMAC()); |
| 270 | assertNotNull(ethernet); |
| 271 | assertThat(ethernet.getSourceMAC(), is(ETH_REQ_IPV6_LOCAL.getDestinationMAC())); |
| 272 | assertThat(ethernet.getDestinationMAC(), is(ETH_REQ_IPV6_LOCAL.getSourceMAC())); |
| 273 | assertTrue(ethernet.getPayload() instanceof IPv6); |
| 274 | IPv6 ip = (IPv6) ethernet.getPayload(); |
| 275 | assertThat(ip.getSourceAddress(), is(DST_IPV6_LOCAL.toOctets())); |
| 276 | assertThat(ip.getDestinationAddress(), is(SRC_IPV6_MY.toOctets())); |
| 277 | assertTrue(ip.getPayload() instanceof ICMP6); |
| 278 | ICMP6 icmp = (ICMP6) ip.getPayload(); |
| 279 | assertThat(icmp.getIcmpType(), is(ECHO_REPLY)); |
| 280 | // Verify behavior |
| 281 | verify(segmentRoutingManager.deviceService); |
| 282 | } |
| 283 | |
| 284 | // Ping to a gateway attached only to the pair leaf (routing through spine) |
| 285 | @Test |
| 286 | public void testPing4RemoteGatewaySamePair() { |
| 287 | // Expected behavior |
| 288 | expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF1)) |
| 289 | .andReturn(true) |
| 290 | .times(1); |
| 291 | expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF2)) |
| 292 | .andReturn(true) |
| 293 | .times(1); |
| 294 | replay(segmentRoutingManager.deviceService); |
| 295 | |
| 296 | // Process |
| 297 | icmpHandler.processIcmp(ETH_REQ_IPV4_SAME, CP2025); |
| 298 | |
| 299 | // Verify packet-out |
| 300 | Ethernet ethernet = packetService.getEthernetPacket(ETH_REQ_IPV4_SAME.getSourceMAC()); |
| 301 | assertNotNull(ethernet); |
| 302 | assertThat(ethernet.getSourceMAC(), is(ETH_REQ_IPV4_SAME.getDestinationMAC())); |
| 303 | assertThat(ethernet.getDestinationMAC(), is(ETH_REQ_IPV4_SAME.getSourceMAC())); |
| 304 | assertTrue(ethernet.getPayload() instanceof MPLS); |
| 305 | MPLS mpls = (MPLS) ethernet.getPayload(); |
| 306 | assertThat(mpls.getLabel(), is(LOCAL_LEAF1_SID4)); |
| 307 | assertTrue(mpls.getPayload() instanceof IPv4); |
| 308 | IPv4 ip = (IPv4) mpls.getPayload(); |
| 309 | assertThat(ip.getSourceAddress(), is(DST_IPV4_SAME.toInt())); |
| 310 | assertThat(ip.getDestinationAddress(), is(SRC_IPV41.toInt())); |
| 311 | assertTrue(ip.getPayload() instanceof ICMP); |
| 312 | ICMP icmp = (ICMP) ip.getPayload(); |
| 313 | assertThat(icmp.getIcmpType(), is(TYPE_ECHO_REPLY)); |
| 314 | assertThat(icmp.getIcmpCode(), is(CODE_ECHO_REPLY)); |
| 315 | // Verify behavior |
| 316 | verify(segmentRoutingManager.deviceService); |
| 317 | } |
| 318 | |
| 319 | // Ping6 to a gateway attached only to the pair leaf (routing through spine) |
| 320 | @Test |
| 321 | public void testPing6RemoteGatewaySamePair() { |
| 322 | // Expected behavior |
| 323 | expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF1)) |
| 324 | .andReturn(true) |
| 325 | .times(1); |
| 326 | expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF2)) |
| 327 | .andReturn(true) |
| 328 | .times(1); |
| 329 | replay(segmentRoutingManager.deviceService); |
| 330 | |
| 331 | // Process |
| 332 | icmpHandler.processIcmpv6(ETH_REQ_IPV6_SAME, CP2025); |
| 333 | |
| 334 | // Verify packet-out |
| 335 | Ethernet ethernet = packetService.getEthernetPacket(ETH_REQ_IPV6_SAME.getSourceMAC()); |
| 336 | assertNotNull(ethernet); |
| 337 | assertThat(ethernet.getSourceMAC(), is(ETH_REQ_IPV6_SAME.getDestinationMAC())); |
| 338 | assertThat(ethernet.getDestinationMAC(), is(ETH_REQ_IPV6_SAME.getSourceMAC())); |
| 339 | assertTrue(ethernet.getPayload() instanceof MPLS); |
| 340 | MPLS mpls = (MPLS) ethernet.getPayload(); |
| 341 | assertThat(mpls.getLabel(), is(LOCAL_LEAF1_SID6)); |
| 342 | assertTrue(mpls.getPayload() instanceof IPv6); |
| 343 | IPv6 ip = (IPv6) mpls.getPayload(); |
| 344 | assertThat(ip.getSourceAddress(), is(DST_IPV6_SAME.toOctets())); |
| 345 | assertThat(ip.getDestinationAddress(), is(SRC_IPV61.toOctets())); |
| 346 | assertTrue(ip.getPayload() instanceof ICMP6); |
| 347 | ICMP6 icmp = (ICMP6) ip.getPayload(); |
| 348 | assertThat(icmp.getIcmpType(), is(ECHO_REPLY)); |
| 349 | // Verify behavior |
| 350 | verify(segmentRoutingManager.deviceService); |
| 351 | } |
| 352 | |
| 353 | // Ping to a gateway but destination leaf is down |
| 354 | @Test |
| 355 | public void testPing4RemoteGatewayLeafDown() { |
| 356 | // Expected behavior |
| 357 | expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF)) |
| 358 | .andReturn(false) |
| 359 | .times(1); |
| 360 | replay(segmentRoutingManager.deviceService); |
| 361 | |
| 362 | // Process |
| 363 | icmpHandler.processIcmp(ETH_REQ_IPV4, CP11); |
| 364 | |
| 365 | // Verify packet-out |
| 366 | Ethernet ethernet = packetService.getEthernetPacket(ETH_REQ_IPV4.getSourceMAC()); |
| 367 | assertNull(ethernet); |
| 368 | |
| 369 | // Verify behavior |
| 370 | verify(segmentRoutingManager.deviceService); |
| 371 | } |
| 372 | |
| 373 | // Ping6 to a gateway but destination leaf is down |
| 374 | @Test |
| 375 | public void testPing6RemoteGatewayLeafDown() { |
| 376 | // Expected behavior |
| 377 | expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF)) |
| 378 | .andReturn(false) |
| 379 | .times(1); |
| 380 | replay(segmentRoutingManager.deviceService); |
| 381 | |
| 382 | // Process |
| 383 | icmpHandler.processIcmpv6(ETH_REQ_IPV6, CP11); |
| 384 | |
| 385 | // Verify packet-out |
| 386 | Ethernet ethernet = packetService.getEthernetPacket(ETH_REQ_IPV6.getSourceMAC()); |
| 387 | assertNull(ethernet); |
| 388 | |
| 389 | // Verify behavior |
| 390 | verify(segmentRoutingManager.deviceService); |
| 391 | } |
| 392 | |
| 393 | // Ping to a gateway but one of the destination leaf is down |
| 394 | @Test |
| 395 | public void testPing4RemoteGatewayLeaf1Down() { |
| 396 | // Expected behavior |
| 397 | expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF1)) |
| 398 | .andReturn(false) |
| 399 | .times(1); |
| 400 | expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF2)) |
| 401 | .andReturn(true) |
| 402 | .times(1); |
| 403 | replay(segmentRoutingManager.deviceService); |
| 404 | |
| 405 | // Process |
| 406 | icmpHandler.processIcmp(ETH_REQ_IPV41, CP11); |
| 407 | |
| 408 | // Verify packet-out |
| 409 | Ethernet ethernet = packetService.getEthernetPacket(ETH_REQ_IPV41.getSourceMAC()); |
| 410 | assertNotNull(ethernet); |
| 411 | assertThat(ethernet.getSourceMAC(), is(ETH_REQ_IPV41.getDestinationMAC())); |
| 412 | assertThat(ethernet.getDestinationMAC(), is(ETH_REQ_IPV41.getSourceMAC())); |
| 413 | assertThat(ethernet.getEtherType(), is(Ethernet.MPLS_UNICAST)); |
| 414 | assertTrue(ethernet.getPayload() instanceof MPLS); |
| 415 | MPLS mpls = (MPLS) ethernet.getPayload(); |
| 416 | assertThat(mpls.getLabel(), is(LOCAL_LEAF2_SID4)); |
| 417 | assertTrue(mpls.getPayload() instanceof IPv4); |
| 418 | IPv4 ip = (IPv4) mpls.getPayload(); |
| 419 | assertThat(ip.getSourceAddress(), is(DST_IPV4.toInt())); |
| 420 | assertThat(ip.getDestinationAddress(), is(SRC_IPV41.toInt())); |
| 421 | assertTrue(ip.getPayload() instanceof ICMP); |
| 422 | ICMP icmp = (ICMP) ip.getPayload(); |
| 423 | assertThat(icmp.getIcmpType(), is(TYPE_ECHO_REPLY)); |
| 424 | assertThat(icmp.getIcmpCode(), is(CODE_ECHO_REPLY)); |
| 425 | // Verify behavior |
| 426 | verify(segmentRoutingManager.deviceService); |
| 427 | } |
| 428 | |
| 429 | // Ping6 to a gateway but one of the destination leaf is down |
| 430 | @Test |
| 431 | public void testPing6RemoteGatewayLeaf2Down() { |
| 432 | // Expected behavior |
| 433 | expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF1)) |
| 434 | .andReturn(true) |
| 435 | .times(1); |
| 436 | expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF2)) |
| 437 | .andReturn(false) |
| 438 | .times(1); |
| 439 | replay(segmentRoutingManager.deviceService); |
| 440 | |
| 441 | // Process |
| 442 | icmpHandler.processIcmpv6(ETH_REQ_IPV61, CP11); |
| 443 | |
| 444 | // Verify packet-out |
| 445 | Ethernet ethernet = packetService.getEthernetPacket(ETH_REQ_IPV61.getSourceMAC()); |
| 446 | assertNotNull(ethernet); |
| 447 | assertThat(ethernet.getSourceMAC(), is(ETH_REQ_IPV61.getDestinationMAC())); |
| 448 | assertThat(ethernet.getDestinationMAC(), is(ETH_REQ_IPV61.getSourceMAC())); |
| 449 | assertThat(ethernet.getEtherType(), is(Ethernet.MPLS_UNICAST)); |
| 450 | assertTrue(ethernet.getPayload() instanceof MPLS); |
| 451 | MPLS mpls = (MPLS) ethernet.getPayload(); |
| 452 | assertThat(mpls.getLabel(), is(LOCAL_LEAF1_SID6)); |
| 453 | assertTrue(mpls.getPayload() instanceof IPv6); |
| 454 | IPv6 ip = (IPv6) mpls.getPayload(); |
| 455 | assertThat(ip.getSourceAddress(), is(DST_IPV6.toOctets())); |
| 456 | assertThat(ip.getDestinationAddress(), is(SRC_IPV61.toOctets())); |
| 457 | assertTrue(ip.getPayload() instanceof ICMP6); |
| 458 | ICMP6 icmp = (ICMP6) ip.getPayload(); |
| 459 | assertThat(icmp.getIcmpType(), is(ECHO_REPLY)); |
| 460 | // Verify behavior |
| 461 | verify(segmentRoutingManager.deviceService); |
| 462 | } |
| 463 | |
| 464 | // Ping6 to a link local address |
| 465 | @Test |
| 466 | public void testPing6LinkLocalAddress() { |
| 467 | // Process |
| 468 | icmpHandler.processIcmpv6(ETH_REQ_IPV6_LL, CP12); |
| 469 | |
| 470 | // Verify packet-out |
| 471 | Ethernet ethernet = packetService.getEthernetPacket(ETH_REQ_IPV6_LL.getSourceMAC()); |
| 472 | assertNotNull(ethernet); |
| 473 | assertThat(ethernet.getSourceMAC(), is(ETH_REQ_IPV6_LL.getDestinationMAC())); |
| 474 | assertThat(ethernet.getDestinationMAC(), is(ETH_REQ_IPV6_LL.getSourceMAC())); |
| 475 | assertTrue(ethernet.getPayload() instanceof IPv6); |
| 476 | IPv6 ip = (IPv6) ethernet.getPayload(); |
| 477 | assertThat(ip.getSourceAddress(), is(DST_IPV6_LL.toOctets())); |
| 478 | assertThat(ip.getDestinationAddress(), is(SRC_IPV6_LL.toOctets())); |
| 479 | assertTrue(ip.getPayload() instanceof ICMP6); |
| 480 | ICMP6 icmp = (ICMP6) ip.getPayload(); |
| 481 | assertThat(icmp.getIcmpType(), is(ECHO_REPLY)); |
| 482 | } |
| 483 | |
| 484 | // Ping to the looback of our leaf |
| 485 | @Test |
| 486 | public void testPing4Loopback() { |
| 487 | // Expected behavior |
| 488 | expect(segmentRoutingManager.deviceService.isAvailable(REMOTE_LEAF)) |
| 489 | .andReturn(true) |
| 490 | .times(1); |
| 491 | replay(segmentRoutingManager.deviceService); |
| 492 | |
| 493 | // Process |
| 494 | icmpHandler.processIcmp(ETH_REQ_IPV4_LOOPBACK, CP12); |
| 495 | |
| 496 | // Verify packet-out |
| 497 | Ethernet ethernet = packetService.getEthernetPacket(ETH_REQ_IPV4_LOOPBACK.getSourceMAC()); |
| 498 | assertNotNull(ethernet); |
| 499 | assertThat(ethernet.getSourceMAC(), is(ETH_REQ_IPV4_LOOPBACK.getDestinationMAC())); |
| 500 | assertThat(ethernet.getDestinationMAC(), is(ETH_REQ_IPV4_LOOPBACK.getSourceMAC())); |
| 501 | assertTrue(ethernet.getPayload() instanceof IPv4); |
| 502 | IPv4 ip = (IPv4) ethernet.getPayload(); |
| 503 | assertThat(ip.getSourceAddress(), is(DST_IPV4_LOOPBACK.toInt())); |
| 504 | assertThat(ip.getDestinationAddress(), is(SRC_IPV4_MY.toInt())); |
| 505 | assertTrue(ip.getPayload() instanceof ICMP); |
| 506 | ICMP icmp = (ICMP) ip.getPayload(); |
| 507 | assertThat(icmp.getIcmpType(), is(TYPE_ECHO_REPLY)); |
| 508 | assertThat(icmp.getIcmpCode(), is(CODE_ECHO_REPLY)); |
| 509 | // Verify behavior |
| 510 | verify(segmentRoutingManager.deviceService); |
| 511 | } |
| 512 | |
| 513 | // Ping6 to the looback of our leaf |
| 514 | @Test |
| 515 | public void testPing6Loopback() { |
| 516 | // Expected behavior |
| 517 | expect(segmentRoutingManager.deviceService.isAvailable(REMOTE_LEAF)) |
| 518 | .andReturn(true) |
| 519 | .times(1); |
| 520 | replay(segmentRoutingManager.deviceService); |
| 521 | |
| 522 | // Process |
| 523 | icmpHandler.processIcmpv6(ETH_REQ_IPV6_LOOPBACK, CP12); |
| 524 | |
| 525 | // Verify packet-out |
| 526 | Ethernet ethernet = packetService.getEthernetPacket(ETH_REQ_IPV6_LOOPBACK.getSourceMAC()); |
| 527 | assertNotNull(ethernet); |
| 528 | assertThat(ethernet.getSourceMAC(), is(ETH_REQ_IPV6_LOOPBACK.getDestinationMAC())); |
| 529 | assertThat(ethernet.getDestinationMAC(), is(ETH_REQ_IPV6_LOOPBACK.getSourceMAC())); |
| 530 | assertTrue(ethernet.getPayload() instanceof IPv6); |
| 531 | IPv6 ip = (IPv6) ethernet.getPayload(); |
| 532 | assertThat(ip.getSourceAddress(), is(DST_IPV6_LOOPBACK.toOctets())); |
| 533 | assertThat(ip.getDestinationAddress(), is(SRC_IPV6_MY.toOctets())); |
| 534 | assertTrue(ip.getPayload() instanceof ICMP6); |
| 535 | ICMP6 icmp = (ICMP6) ip.getPayload(); |
| 536 | assertThat(icmp.getIcmpType(), is(ECHO_REPLY)); |
| 537 | // Verify behavior |
| 538 | verify(segmentRoutingManager.deviceService); |
| 539 | } |
| 540 | |
| 541 | // Ping to the looback of our leaf (pair) |
| 542 | @Test |
| 543 | public void testPing4LoopbackPair() { |
| 544 | // Expected behavior |
| 545 | expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF1)) |
| 546 | .andReturn(true) |
| 547 | .times(1); |
| 548 | expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF2)) |
| 549 | .andReturn(true) |
| 550 | .times(1); |
| 551 | replay(segmentRoutingManager.deviceService); |
| 552 | |
| 553 | // Process |
| 554 | icmpHandler.processIcmp(ETH_REQ_IPV4_LOOPBACK_PAIR, CP2011); |
| 555 | |
| 556 | // Verify packet-out |
| 557 | Ethernet ethernet = packetService.getEthernetPacket(ETH_REQ_IPV4_LOOPBACK_PAIR.getSourceMAC()); |
| 558 | assertNotNull(ethernet); |
| 559 | assertThat(ethernet.getSourceMAC(), is(ETH_REQ_IPV4_LOOPBACK_PAIR.getDestinationMAC())); |
| 560 | assertThat(ethernet.getDestinationMAC(), is(ETH_REQ_IPV4_LOOPBACK_PAIR.getSourceMAC())); |
| 561 | assertTrue(ethernet.getPayload() instanceof IPv4); |
| 562 | IPv4 ip = (IPv4) ethernet.getPayload(); |
| 563 | assertThat(ip.getSourceAddress(), is(DST_IPV4_LOOPBACK_PAIR.toInt())); |
| 564 | assertThat(ip.getDestinationAddress(), is(SRC_IPV41.toInt())); |
| 565 | assertTrue(ip.getPayload() instanceof ICMP); |
| 566 | ICMP icmp = (ICMP) ip.getPayload(); |
| 567 | assertThat(icmp.getIcmpType(), is(TYPE_ECHO_REPLY)); |
| 568 | assertThat(icmp.getIcmpCode(), is(CODE_ECHO_REPLY)); |
| 569 | // Verify behavior |
| 570 | verify(segmentRoutingManager.deviceService); |
| 571 | } |
| 572 | |
| 573 | // Ping6 to the looback of our leaf (pair) |
| 574 | @Test |
| 575 | public void testPing6LoopbackPair() { |
| 576 | // Expected behavior |
| 577 | expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF1)) |
| 578 | .andReturn(true) |
| 579 | .times(1); |
| 580 | expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF2)) |
| 581 | .andReturn(true) |
| 582 | .times(1); |
| 583 | replay(segmentRoutingManager.deviceService); |
| 584 | |
| 585 | // Process |
| 586 | icmpHandler.processIcmpv6(ETH_REQ_IPV6_LOOPBACK_PAIR, CP2021); |
| 587 | |
| 588 | // Verify packet-out |
| 589 | Ethernet ethernet = packetService.getEthernetPacket(ETH_REQ_IPV6_LOOPBACK_PAIR.getSourceMAC()); |
| 590 | assertNotNull(ethernet); |
| 591 | assertThat(ethernet.getSourceMAC(), is(ETH_REQ_IPV6_LOOPBACK_PAIR.getDestinationMAC())); |
| 592 | assertThat(ethernet.getDestinationMAC(), is(ETH_REQ_IPV6_LOOPBACK_PAIR.getSourceMAC())); |
| 593 | assertTrue(ethernet.getPayload() instanceof IPv6); |
| 594 | IPv6 ip = (IPv6) ethernet.getPayload(); |
| 595 | assertThat(ip.getSourceAddress(), is(DST_IPV6_LOOPBACK_PAIR.toOctets())); |
| 596 | assertThat(ip.getDestinationAddress(), is(SRC_IPV61.toOctets())); |
| 597 | assertTrue(ip.getPayload() instanceof ICMP6); |
| 598 | ICMP6 icmp = (ICMP6) ip.getPayload(); |
| 599 | assertThat(icmp.getIcmpType(), is(ECHO_REPLY)); |
| 600 | // Verify behavior |
| 601 | verify(segmentRoutingManager.deviceService); |
| 602 | } |
| 603 | |
| 604 | // Ping to the loopback of the leaf but hashing of the bond interfaces sends to wrong leaf |
| 605 | @Test |
| 606 | public void testPing4LoopbackPairDifferentLeaf() { |
| 607 | // Expected behavior |
| 608 | expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF1)) |
| 609 | .andReturn(true) |
| 610 | .times(1); |
| 611 | expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF2)) |
| 612 | .andReturn(true) |
| 613 | .times(1); |
| 614 | replay(segmentRoutingManager.deviceService); |
| 615 | |
| 616 | // Process |
| 617 | icmpHandler.processIcmp(ETH_REQ_IPV4_LOOPBACK_PAIR, CP2021); |
| 618 | |
| 619 | // Verify packet-out |
| 620 | Ethernet ethernet = packetService.getEthernetPacket(ETH_REQ_IPV4_LOOPBACK_PAIR.getSourceMAC()); |
| 621 | assertNotNull(ethernet); |
| 622 | assertThat(ethernet.getSourceMAC(), is(ETH_REQ_IPV4_LOOPBACK_PAIR.getDestinationMAC())); |
| 623 | assertThat(ethernet.getDestinationMAC(), is(ETH_REQ_IPV4_LOOPBACK_PAIR.getSourceMAC())); |
| 624 | assertTrue(ethernet.getPayload() instanceof IPv4); |
| 625 | IPv4 ip = (IPv4) ethernet.getPayload(); |
| 626 | assertThat(ip.getSourceAddress(), is(DST_IPV4_LOOPBACK_PAIR.toInt())); |
| 627 | assertThat(ip.getDestinationAddress(), is(SRC_IPV41.toInt())); |
| 628 | assertTrue(ip.getPayload() instanceof ICMP); |
| 629 | ICMP icmp = (ICMP) ip.getPayload(); |
| 630 | assertThat(icmp.getIcmpType(), is(TYPE_ECHO_REPLY)); |
| 631 | assertThat(icmp.getIcmpCode(), is(CODE_ECHO_REPLY)); |
| 632 | // Verify behavior |
| 633 | verify(segmentRoutingManager.deviceService); |
| 634 | } |
| 635 | |
| 636 | // Ping6 to the loopback of the leaf but hashing of the bond interfaces sends to wrong leaf |
| 637 | @Test |
| 638 | public void testPing6LoopbackPairDifferentLeaf() { |
| 639 | // Expected behavior |
| 640 | expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF1)) |
| 641 | .andReturn(true) |
| 642 | .times(1); |
| 643 | expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF2)) |
| 644 | .andReturn(true) |
| 645 | .times(1); |
| 646 | replay(segmentRoutingManager.deviceService); |
| 647 | |
| 648 | // Process |
| 649 | icmpHandler.processIcmpv6(ETH_REQ_IPV6_LOOPBACK_PAIR, CP2011); |
| 650 | |
| 651 | // Verify packet-out |
| 652 | Ethernet ethernet = packetService.getEthernetPacket(ETH_REQ_IPV6_LOOPBACK_PAIR.getSourceMAC()); |
| 653 | assertNotNull(ethernet); |
| 654 | assertThat(ethernet.getSourceMAC(), is(ETH_REQ_IPV6_LOOPBACK_PAIR.getDestinationMAC())); |
| 655 | assertThat(ethernet.getDestinationMAC(), is(ETH_REQ_IPV6_LOOPBACK_PAIR.getSourceMAC())); |
| 656 | assertTrue(ethernet.getPayload() instanceof IPv6); |
| 657 | IPv6 ip = (IPv6) ethernet.getPayload(); |
| 658 | assertThat(ip.getSourceAddress(), is(DST_IPV6_LOOPBACK_PAIR.toOctets())); |
| 659 | assertThat(ip.getDestinationAddress(), is(SRC_IPV61.toOctets())); |
| 660 | assertTrue(ip.getPayload() instanceof ICMP6); |
| 661 | ICMP6 icmp = (ICMP6) ip.getPayload(); |
| 662 | assertThat(icmp.getIcmpType(), is(ECHO_REPLY)); |
| 663 | // Verify behavior |
| 664 | verify(segmentRoutingManager.deviceService); |
| 665 | } |
| 666 | |
| 667 | // Ping loopback of a destination that is down but |
| 668 | // hashing of the bond interfaces sends to other leaf |
| 669 | @Test |
| 670 | public void testPing4LoopbackPairDifferentLeafDown() { |
| 671 | // Expected behavior |
| 672 | expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF1)) |
| 673 | .andReturn(false) |
| 674 | .times(1); |
| 675 | expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF2)) |
| 676 | .andReturn(true) |
| 677 | .times(1); |
| 678 | replay(segmentRoutingManager.deviceService); |
| 679 | |
| 680 | // Process |
| 681 | icmpHandler.processIcmp(ETH_REQ_IPV4_LOOPBACK_PAIR, CP2021); |
| 682 | |
| 683 | // Verify packet-out |
| 684 | Ethernet ethernet = packetService.getEthernetPacket(ETH_REQ_IPV4_LOOPBACK_PAIR.getSourceMAC()); |
| 685 | assertNotNull(ethernet); |
| 686 | assertThat(ethernet.getSourceMAC(), is(ETH_REQ_IPV4_LOOPBACK_PAIR.getDestinationMAC())); |
| 687 | assertThat(ethernet.getDestinationMAC(), is(ETH_REQ_IPV4_LOOPBACK_PAIR.getSourceMAC())); |
| 688 | assertTrue(ethernet.getPayload() instanceof IPv4); |
| 689 | IPv4 ip = (IPv4) ethernet.getPayload(); |
| 690 | assertThat(ip.getSourceAddress(), is(DST_IPV4_LOOPBACK_PAIR.toInt())); |
| 691 | assertThat(ip.getDestinationAddress(), is(SRC_IPV41.toInt())); |
| 692 | assertTrue(ip.getPayload() instanceof ICMP); |
| 693 | ICMP icmp = (ICMP) ip.getPayload(); |
| 694 | assertThat(icmp.getIcmpType(), is(TYPE_ECHO_REPLY)); |
| 695 | assertThat(icmp.getIcmpCode(), is(CODE_ECHO_REPLY)); |
| 696 | // Verify behavior |
| 697 | verify(segmentRoutingManager.deviceService); |
| 698 | } |
| 699 | |
| 700 | // Ping6 loopback of a destination that is down but |
| 701 | // hashing of the bond interfaces sends to other leaf |
| 702 | @Test |
| 703 | public void testPing6LoopbackPairDifferentLeafDown() { |
| 704 | // Expected behavior |
| 705 | expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF1)) |
| 706 | .andReturn(true) |
| 707 | .times(1); |
| 708 | expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF2)) |
| 709 | .andReturn(false) |
| 710 | .times(1); |
| 711 | replay(segmentRoutingManager.deviceService); |
| 712 | |
| 713 | // Process |
| 714 | icmpHandler.processIcmpv6(ETH_REQ_IPV6_LOOPBACK_PAIR, CP2011); |
| 715 | |
| 716 | // Verify packet-out |
| 717 | Ethernet ethernet = packetService.getEthernetPacket(ETH_REQ_IPV6_LOOPBACK_PAIR.getSourceMAC()); |
| 718 | assertNotNull(ethernet); |
| 719 | assertThat(ethernet.getSourceMAC(), is(ETH_REQ_IPV6_LOOPBACK_PAIR.getDestinationMAC())); |
| 720 | assertThat(ethernet.getDestinationMAC(), is(ETH_REQ_IPV6_LOOPBACK_PAIR.getSourceMAC())); |
| 721 | assertTrue(ethernet.getPayload() instanceof IPv6); |
| 722 | IPv6 ip = (IPv6) ethernet.getPayload(); |
| 723 | assertThat(ip.getSourceAddress(), is(DST_IPV6_LOOPBACK_PAIR.toOctets())); |
| 724 | assertThat(ip.getDestinationAddress(), is(SRC_IPV61.toOctets())); |
| 725 | assertTrue(ip.getPayload() instanceof ICMP6); |
| 726 | ICMP6 icmp = (ICMP6) ip.getPayload(); |
| 727 | assertThat(icmp.getIcmpType(), is(ECHO_REPLY)); |
| 728 | // Verify behavior |
| 729 | verify(segmentRoutingManager.deviceService); |
| 730 | } |
| 731 | |
| 732 | // Ping to a dh gateway |
| 733 | @Test |
| 734 | public void testPing4GatewayPair() { |
| 735 | // Expected behavior |
| 736 | expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF1)) |
| 737 | .andReturn(true) |
| 738 | .times(1); |
| 739 | expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF2)) |
| 740 | .andReturn(true) |
| 741 | .times(1); |
| 742 | replay(segmentRoutingManager.deviceService); |
| 743 | |
| 744 | // Process |
| 745 | icmpHandler.processIcmp(ETH_REQ_IPV4_GATEWAY_PAIR, CP2011); |
| 746 | |
| 747 | // Verify packet-out |
| 748 | Ethernet ethernet = packetService.getEthernetPacket(ETH_REQ_IPV4_GATEWAY_PAIR.getSourceMAC()); |
| 749 | assertNotNull(ethernet); |
| 750 | assertThat(ethernet.getSourceMAC(), is(ETH_REQ_IPV4_GATEWAY_PAIR.getDestinationMAC())); |
| 751 | assertThat(ethernet.getDestinationMAC(), is(ETH_REQ_IPV4_GATEWAY_PAIR.getSourceMAC())); |
| 752 | assertTrue(ethernet.getPayload() instanceof IPv4); |
| 753 | IPv4 ip = (IPv4) ethernet.getPayload(); |
| 754 | assertThat(ip.getSourceAddress(), is(DST_IPV4_GATEWAY_PAIR.toInt())); |
| 755 | assertThat(ip.getDestinationAddress(), is(SRC_IPV41.toInt())); |
| 756 | assertTrue(ip.getPayload() instanceof ICMP); |
| 757 | ICMP icmp = (ICMP) ip.getPayload(); |
| 758 | assertThat(icmp.getIcmpType(), is(TYPE_ECHO_REPLY)); |
| 759 | assertThat(icmp.getIcmpCode(), is(CODE_ECHO_REPLY)); |
| 760 | // Verify behavior |
| 761 | verify(segmentRoutingManager.deviceService); |
| 762 | } |
| 763 | |
| 764 | // Ping6 to a dh gateway |
| 765 | @Test |
| 766 | public void testPing6GatewayPair() { |
| 767 | // Expected behavior |
| 768 | expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF1)) |
| 769 | .andReturn(true) |
| 770 | .times(1); |
| 771 | expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF2)) |
| 772 | .andReturn(true) |
| 773 | .times(1); |
| 774 | replay(segmentRoutingManager.deviceService); |
| 775 | |
| 776 | // Process |
| 777 | icmpHandler.processIcmpv6(ETH_REQ_IPV6_GATEWAY_PAIR, CP2021); |
| 778 | |
| 779 | // Verify packet-out |
| 780 | Ethernet ethernet = packetService.getEthernetPacket(ETH_REQ_IPV6_GATEWAY_PAIR.getSourceMAC()); |
| 781 | assertNotNull(ethernet); |
| 782 | assertThat(ethernet.getSourceMAC(), is(ETH_REQ_IPV6_GATEWAY_PAIR.getDestinationMAC())); |
| 783 | assertThat(ethernet.getDestinationMAC(), is(ETH_REQ_IPV6_GATEWAY_PAIR.getSourceMAC())); |
| 784 | assertTrue(ethernet.getPayload() instanceof IPv6); |
| 785 | IPv6 ip = (IPv6) ethernet.getPayload(); |
| 786 | assertThat(ip.getSourceAddress(), is(DST_IPV6_GATEWAY_PAIR.toOctets())); |
| 787 | assertThat(ip.getDestinationAddress(), is(SRC_IPV61.toOctets())); |
| 788 | assertTrue(ip.getPayload() instanceof ICMP6); |
| 789 | ICMP6 icmp = (ICMP6) ip.getPayload(); |
| 790 | assertThat(icmp.getIcmpType(), is(ECHO_REPLY)); |
| 791 | // Verify behavior |
| 792 | verify(segmentRoutingManager.deviceService); |
| 793 | } |
| 794 | |
| 795 | } |