Luca Prete | e4a5e1a | 2016-09-07 17:01:22 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015-present Open Networking Laboratory |
| 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.sdnip; |
| 18 | |
Luca Prete | 83bac34 | 2016-12-06 19:42:05 -0800 | [diff] [blame] | 19 | import com.fasterxml.jackson.databind.JsonNode; |
| 20 | import com.fasterxml.jackson.databind.ObjectMapper; |
Luca Prete | e4a5e1a | 2016-09-07 17:01:22 -0700 | [diff] [blame] | 21 | import com.google.common.collect.Lists; |
| 22 | import com.google.common.collect.Sets; |
| 23 | import org.junit.Before; |
| 24 | import org.junit.Test; |
| 25 | import org.onlab.packet.Ethernet; |
| 26 | import org.onlab.packet.Ip4Address; |
| 27 | import org.onlab.packet.Ip4Prefix; |
| 28 | import org.onlab.packet.IpAddress; |
| 29 | import org.onlab.packet.IpPrefix; |
| 30 | import org.onlab.packet.MacAddress; |
| 31 | import org.onlab.packet.VlanId; |
| 32 | import org.onosproject.TestApplicationId; |
| 33 | import org.onosproject.core.ApplicationId; |
| 34 | import org.onosproject.core.CoreServiceAdapter; |
| 35 | import org.onosproject.incubator.net.intf.Interface; |
| 36 | import org.onosproject.incubator.net.intf.InterfaceEvent; |
| 37 | import org.onosproject.incubator.net.intf.InterfaceListener; |
| 38 | import org.onosproject.incubator.net.intf.InterfaceService; |
| 39 | import org.onosproject.incubator.net.intf.InterfaceServiceAdapter; |
| 40 | import org.onosproject.incubator.net.routing.ResolvedRoute; |
| 41 | import org.onosproject.incubator.net.routing.RouteEvent; |
| 42 | import org.onosproject.incubator.net.routing.RouteListener; |
| 43 | import org.onosproject.incubator.net.routing.RouteServiceAdapter; |
| 44 | import org.onosproject.net.ConnectPoint; |
| 45 | import org.onosproject.net.DeviceId; |
| 46 | import org.onosproject.net.FilteredConnectPoint; |
| 47 | import org.onosproject.net.PortNumber; |
Luca Prete | 83bac34 | 2016-12-06 19:42:05 -0800 | [diff] [blame] | 48 | import org.onosproject.net.config.Config; |
| 49 | import org.onosproject.net.config.ConfigApplyDelegate; |
Luca Prete | 83bac34 | 2016-12-06 19:42:05 -0800 | [diff] [blame] | 50 | import org.onosproject.net.config.NetworkConfigServiceAdapter; |
Luca Prete | e4a5e1a | 2016-09-07 17:01:22 -0700 | [diff] [blame] | 51 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 52 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 53 | import org.onosproject.net.flow.TrafficSelector; |
| 54 | import org.onosproject.net.flow.TrafficTreatment; |
| 55 | import org.onosproject.net.host.InterfaceIpAddress; |
| 56 | import org.onosproject.net.intent.AbstractIntentTest; |
| 57 | import org.onosproject.net.intent.Key; |
| 58 | import org.onosproject.net.intent.MultiPointToSinglePointIntent; |
Jonathan Hart | 470ed4f | 2017-01-31 16:52:28 -0800 | [diff] [blame] | 59 | import org.onosproject.intentsync.IntentSynchronizationService; |
Luca Prete | 83bac34 | 2016-12-06 19:42:05 -0800 | [diff] [blame] | 60 | import org.onosproject.sdnip.config.SdnIpConfig; |
Luca Prete | e4a5e1a | 2016-09-07 17:01:22 -0700 | [diff] [blame] | 61 | |
| 62 | import java.util.Collections; |
| 63 | import java.util.List; |
| 64 | import java.util.Set; |
| 65 | |
Thomas Vachuska | d832fc5 | 2017-01-11 13:13:06 -0800 | [diff] [blame] | 66 | import static org.easymock.EasyMock.*; |
Luca Prete | e4a5e1a | 2016-09-07 17:01:22 -0700 | [diff] [blame] | 67 | import static org.onosproject.routing.TestIntentServiceHelper.eqExceptId; |
| 68 | |
| 69 | /** |
| 70 | * Unit tests for SdnIpFib. |
| 71 | */ |
| 72 | public class SdnIpFibTest extends AbstractIntentTest { |
| 73 | |
| 74 | private InterfaceService interfaceService; |
| 75 | |
| 76 | private static final ConnectPoint SW1_ETH1 = new ConnectPoint( |
| 77 | DeviceId.deviceId("of:0000000000000001"), |
| 78 | PortNumber.portNumber(1)); |
| 79 | |
| 80 | private static final ConnectPoint SW2_ETH1 = new ConnectPoint( |
| 81 | DeviceId.deviceId("of:0000000000000002"), |
| 82 | PortNumber.portNumber(1)); |
| 83 | |
| 84 | private static final ConnectPoint SW3_ETH1 = new ConnectPoint( |
| 85 | DeviceId.deviceId("of:0000000000000003"), |
| 86 | PortNumber.portNumber(1)); |
| 87 | |
| 88 | private static final ConnectPoint SW4_ETH1 = new ConnectPoint( |
| 89 | DeviceId.deviceId("of:0000000000000004"), |
| 90 | PortNumber.portNumber(1)); |
| 91 | |
| 92 | private static final MacAddress MAC1 = MacAddress.valueOf("00:00:00:00:00:01"); |
| 93 | private static final MacAddress MAC2 = MacAddress.valueOf("00:00:00:00:00:02"); |
| 94 | private static final MacAddress MAC3 = MacAddress.valueOf("00:00:00:00:00:03"); |
| 95 | private static final MacAddress MAC4 = MacAddress.valueOf("00:00:00:00:00:04"); |
| 96 | |
| 97 | private static final VlanId NO_VLAN = VlanId.NONE; |
| 98 | private static final VlanId VLAN10 = VlanId.vlanId(Short.valueOf("10")); |
| 99 | private static final VlanId VLAN20 = VlanId.vlanId(Short.valueOf("20")); |
| 100 | |
| 101 | private static final InterfaceIpAddress IIP1 = |
| 102 | InterfaceIpAddress.valueOf("192.168.10.101/24"); |
| 103 | private static final InterfaceIpAddress IIP2 = |
| 104 | InterfaceIpAddress.valueOf("192.168.20.101/24"); |
| 105 | private static final InterfaceIpAddress IIP3 = |
| 106 | InterfaceIpAddress.valueOf("192.168.30.101/24"); |
| 107 | private static final InterfaceIpAddress IIP4 = |
| 108 | InterfaceIpAddress.valueOf("192.168.40.101/24"); |
| 109 | |
| 110 | private static final IpAddress IP1 = Ip4Address.valueOf("192.168.10.1"); |
| 111 | private static final IpAddress IP2 = Ip4Address.valueOf("192.168.20.1"); |
| 112 | private static final IpAddress IP3 = Ip4Address.valueOf("192.168.30.1"); |
| 113 | |
| 114 | private static final IpPrefix PREFIX1 = Ip4Prefix.valueOf("1.1.1.0/24"); |
| 115 | private static final IpPrefix PREFIX2 = Ip4Prefix.valueOf("1.1.2.0/24"); |
| 116 | |
| 117 | private SdnIpFib sdnipFib; |
| 118 | private IntentSynchronizationService intentSynchronizer; |
| 119 | private final Set<Interface> interfaces = Sets.newHashSet(); |
| 120 | |
| 121 | private static final ApplicationId APPID = TestApplicationId.create("SDNIP"); |
| 122 | |
| 123 | private RouteListener routeListener; |
| 124 | private InterfaceListener interfaceListener; |
| 125 | |
| 126 | @Before |
| 127 | public void setUp() throws Exception { |
| 128 | super.setUp(); |
| 129 | |
| 130 | interfaceService = createMock(InterfaceService.class); |
| 131 | |
| 132 | interfaceService.addListener(anyObject(InterfaceListener.class)); |
| 133 | expectLastCall().andDelegateTo(new InterfaceServiceDelegate()); |
| 134 | |
| 135 | // These will set expectations on routingConfig and interfaceService |
| 136 | setUpInterfaceService(); |
| 137 | |
| 138 | replay(interfaceService); |
| 139 | |
| 140 | intentSynchronizer = createMock(IntentSynchronizationService.class); |
| 141 | |
| 142 | sdnipFib = new SdnIpFib(); |
| 143 | sdnipFib.routeService = new TestRouteService(); |
| 144 | sdnipFib.coreService = new TestCoreService(); |
Luca Prete | 83bac34 | 2016-12-06 19:42:05 -0800 | [diff] [blame] | 145 | sdnipFib.networkConfigService = new TestNetworkConfigService(); |
Luca Prete | e4a5e1a | 2016-09-07 17:01:22 -0700 | [diff] [blame] | 146 | sdnipFib.interfaceService = interfaceService; |
| 147 | sdnipFib.intentSynchronizer = intentSynchronizer; |
| 148 | |
| 149 | sdnipFib.activate(); |
| 150 | } |
| 151 | |
| 152 | /** |
| 153 | * Sets up the interface service. |
| 154 | */ |
| 155 | private void setUpInterfaceService() { |
| 156 | List<InterfaceIpAddress> iIps1 = Lists.newArrayList(); |
| 157 | iIps1.add(IIP1); |
| 158 | Interface sw1Eth1 = new Interface("sw1-eth1", SW1_ETH1, iIps1, MAC1, VLAN10); |
| 159 | interfaces.add(sw1Eth1); |
| 160 | |
| 161 | List<InterfaceIpAddress> iIps2 = Lists.newArrayList(); |
| 162 | iIps2.add(IIP2); |
| 163 | Interface sw2Eth1 = new Interface("sw2-eth1", SW2_ETH1, iIps2, MAC2, VLAN20); |
| 164 | interfaces.add(sw2Eth1); |
| 165 | |
| 166 | List<InterfaceIpAddress> iIps3 = Lists.newArrayList(); |
| 167 | iIps3.add(IIP3); |
| 168 | Interface sw3Eth1 = new Interface("sw3-eth1", SW3_ETH1, iIps3, MAC3, NO_VLAN); |
| 169 | interfaces.add(sw3Eth1); |
| 170 | |
| 171 | expect(interfaceService.getInterfacesByPort(SW1_ETH1)).andReturn( |
| 172 | Collections.singleton(sw1Eth1)).anyTimes(); |
| 173 | expect(interfaceService.getMatchingInterface(IP1)) |
| 174 | .andReturn(sw1Eth1).anyTimes(); |
| 175 | expect(interfaceService.getInterfacesByPort(SW2_ETH1)).andReturn( |
| 176 | Collections.singleton(sw2Eth1)).anyTimes(); |
| 177 | expect(interfaceService.getMatchingInterface(IP2)) |
| 178 | .andReturn(sw2Eth1).anyTimes(); |
| 179 | expect(interfaceService.getInterfacesByPort(SW3_ETH1)).andReturn( |
| 180 | Collections.singleton(sw3Eth1)).anyTimes(); |
| 181 | expect(interfaceService.getMatchingInterface(IP3)) |
| 182 | .andReturn(sw3Eth1).anyTimes(); |
| 183 | expect(interfaceService.getInterfaces()).andReturn(interfaces).anyTimes(); |
| 184 | } |
| 185 | |
| 186 | /** |
| 187 | * Tests adding a route. The egress interface has no VLAN configured. |
| 188 | * |
| 189 | * We verify that the synchronizer records the correct state and that the |
| 190 | * correct intent is submitted to the IntentService. |
| 191 | */ |
| 192 | @Test |
| 193 | public void testRouteAddToNoVlan() { |
| 194 | // Build the expected route |
Charles Chan | 8fe9f4c | 2016-10-24 16:46:25 -0700 | [diff] [blame] | 195 | ResolvedRoute route = new ResolvedRoute(PREFIX1, IP3, MAC3, SW3_ETH1); |
Luca Prete | e4a5e1a | 2016-09-07 17:01:22 -0700 | [diff] [blame] | 196 | |
| 197 | MultiPointToSinglePointIntent intent = |
| 198 | createIntentToThreeSrcOneTwo(PREFIX1); |
| 199 | |
| 200 | // Setup the expected intents |
| 201 | intentSynchronizer.submit(eqExceptId(intent)); |
| 202 | replay(intentSynchronizer); |
| 203 | |
| 204 | // Send in the added event |
| 205 | routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_ADDED, route)); |
| 206 | |
| 207 | verify(intentSynchronizer); |
| 208 | } |
| 209 | |
| 210 | /** |
| 211 | * Tests adding a route. The egress interface has a VLAN configured. |
| 212 | * |
| 213 | * We verify that the synchronizer records the correct state and that the |
| 214 | * correct intent is submitted to the IntentService. |
| 215 | */ |
| 216 | @Test |
| 217 | public void testRouteAddToVlan() { |
| 218 | // Build the expected route |
Charles Chan | 8fe9f4c | 2016-10-24 16:46:25 -0700 | [diff] [blame] | 219 | ResolvedRoute route = new ResolvedRoute(PREFIX2, IP1, MAC1, SW1_ETH1); |
Luca Prete | e4a5e1a | 2016-09-07 17:01:22 -0700 | [diff] [blame] | 220 | |
| 221 | MultiPointToSinglePointIntent intent = createIntentToOne(PREFIX2); |
| 222 | |
| 223 | // Setup the expected intents |
| 224 | intentSynchronizer.submit(eqExceptId(intent)); |
| 225 | replay(intentSynchronizer); |
| 226 | |
| 227 | // Send in the added event |
| 228 | routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_ADDED, route)); |
| 229 | |
| 230 | verify(intentSynchronizer); |
| 231 | } |
| 232 | |
| 233 | /** |
| 234 | * Tests updating a route. |
| 235 | * |
| 236 | * We first add a route from a next-hop with no vlan. We then announce the |
| 237 | * same route from another next-hop with a vlan. |
| 238 | * |
| 239 | * We verify that the synchronizer records the correct state and that the |
| 240 | * correct intent is submitted to the IntentService. |
| 241 | */ |
| 242 | @Test |
| 243 | public void testRouteUpdatesToVlan() { |
| 244 | // Add a route first to a destination with no VLAN |
| 245 | testRouteAddToNoVlan(); |
| 246 | |
| 247 | // Build the new route entries for prefix1 and prefix2 |
Charles Chan | e4d1310 | 2016-11-08 15:38:44 -0800 | [diff] [blame] | 248 | ResolvedRoute oldRoutePrefixOne = new ResolvedRoute(PREFIX1, IP3, MAC3, SW3_ETH1); |
Charles Chan | 8fe9f4c | 2016-10-24 16:46:25 -0700 | [diff] [blame] | 249 | ResolvedRoute routePrefixOne = new ResolvedRoute(PREFIX1, IP1, MAC1, SW1_ETH1); |
Luca Prete | e4a5e1a | 2016-09-07 17:01:22 -0700 | [diff] [blame] | 250 | |
| 251 | // Create the new expected intents |
| 252 | MultiPointToSinglePointIntent newPrefixOneIntent = createIntentToOne(PREFIX1); |
| 253 | |
| 254 | // Set up test expectation |
| 255 | reset(intentSynchronizer); |
| 256 | |
| 257 | // Setup the expected intents |
| 258 | intentSynchronizer.submit(eqExceptId(newPrefixOneIntent)); |
| 259 | replay(intentSynchronizer); |
| 260 | |
| 261 | // Send in the update events |
| 262 | routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_UPDATED, |
Charles Chan | e4d1310 | 2016-11-08 15:38:44 -0800 | [diff] [blame] | 263 | routePrefixOne, oldRoutePrefixOne)); |
Luca Prete | e4a5e1a | 2016-09-07 17:01:22 -0700 | [diff] [blame] | 264 | |
| 265 | verify(intentSynchronizer); |
| 266 | } |
| 267 | |
| 268 | /** |
| 269 | * Tests updating a route. |
| 270 | * |
| 271 | * We first add a route from a next-hop with a vlan. We then announce the |
| 272 | * same route from another next-hop with no vlan. |
| 273 | * |
| 274 | * We verify that the synchronizer records the correct state and that the |
| 275 | * correct intent is submitted to the IntentService. |
| 276 | */ |
| 277 | @Test |
| 278 | public void testRouteUpdatesToNoVlan() { |
| 279 | // Add a route first to a destination with no VLAN |
| 280 | testRouteAddToVlan(); |
| 281 | |
| 282 | // Build the new route entries for prefix1 and prefix2 |
Charles Chan | e4d1310 | 2016-11-08 15:38:44 -0800 | [diff] [blame] | 283 | ResolvedRoute oldRoutePrefix = new ResolvedRoute(PREFIX2, IP1, MAC1, SW1_ETH1); |
Charles Chan | 8fe9f4c | 2016-10-24 16:46:25 -0700 | [diff] [blame] | 284 | ResolvedRoute routePrefix = new ResolvedRoute(PREFIX2, IP3, MAC3, SW3_ETH1); |
Luca Prete | e4a5e1a | 2016-09-07 17:01:22 -0700 | [diff] [blame] | 285 | |
| 286 | // Create the new expected intents |
| 287 | MultiPointToSinglePointIntent newPrefixIntent = |
| 288 | createIntentToThreeSrcOneTwo(PREFIX2); |
| 289 | |
| 290 | // Set up test expectation |
| 291 | reset(intentSynchronizer); |
| 292 | |
| 293 | // Setup the expected intents |
| 294 | intentSynchronizer.submit(eqExceptId(newPrefixIntent)); |
| 295 | replay(intentSynchronizer); |
| 296 | |
| 297 | // Send in the update events |
| 298 | routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_UPDATED, |
Charles Chan | e4d1310 | 2016-11-08 15:38:44 -0800 | [diff] [blame] | 299 | routePrefix, oldRoutePrefix)); |
Luca Prete | e4a5e1a | 2016-09-07 17:01:22 -0700 | [diff] [blame] | 300 | |
| 301 | verify(intentSynchronizer); |
| 302 | } |
| 303 | |
| 304 | /** |
| 305 | * Tests deleting a route. |
| 306 | * |
| 307 | * We verify that the synchronizer records the correct state and that the |
| 308 | * correct intent is withdrawn from the IntentService. |
| 309 | */ |
| 310 | @Test |
| 311 | public void testRouteDelete() { |
| 312 | // Add a route first |
| 313 | testRouteAddToNoVlan(); |
| 314 | |
| 315 | // Construct the existing route entry |
Charles Chan | e4d1310 | 2016-11-08 15:38:44 -0800 | [diff] [blame] | 316 | ResolvedRoute route = new ResolvedRoute(PREFIX1, IP3, MAC3, SW3_ETH1); |
Luca Prete | e4a5e1a | 2016-09-07 17:01:22 -0700 | [diff] [blame] | 317 | |
| 318 | // Create existing intent |
| 319 | MultiPointToSinglePointIntent removedIntent = |
| 320 | createIntentToThreeSrcOneTwo(PREFIX1); |
| 321 | |
| 322 | // Set up expectation |
| 323 | reset(intentSynchronizer); |
| 324 | // Setup the expected intents |
| 325 | intentSynchronizer.withdraw(eqExceptId(removedIntent)); |
| 326 | replay(intentSynchronizer); |
| 327 | |
| 328 | // Send in the removed event |
| 329 | routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_REMOVED, route)); |
| 330 | |
| 331 | verify(intentSynchronizer); |
| 332 | } |
| 333 | |
| 334 | /** |
| 335 | * Tests adding a new interface. |
| 336 | * |
| 337 | * We verify that the synchronizer records the correct state and that the |
| 338 | * correct intent is withdrawn from the IntentService. |
| 339 | */ |
| 340 | @Test |
| 341 | public void testAddInterface() { |
| 342 | // Add a route first |
| 343 | testRouteAddToNoVlan(); |
| 344 | |
| 345 | // Create the new expected intent |
| 346 | MultiPointToSinglePointIntent addedIntent = |
| 347 | createIntentToThreeSrcOneTwoFour(PREFIX1); |
| 348 | |
| 349 | reset(intentSynchronizer); |
| 350 | |
| 351 | intentSynchronizer.submit(eqExceptId(addedIntent)); |
| 352 | expectLastCall().once(); |
| 353 | |
| 354 | replay(intentSynchronizer); |
| 355 | |
| 356 | // Create the new interface and add notify it |
| 357 | Interface intf = new Interface("sw4-eth1", SW4_ETH1, |
| 358 | Collections.singletonList(IIP4), |
| 359 | MAC4, NO_VLAN); |
| 360 | InterfaceEvent intfEvent = |
| 361 | new InterfaceEvent(InterfaceEvent.Type.INTERFACE_ADDED, intf); |
| 362 | |
| 363 | interfaceListener.event(intfEvent); |
| 364 | |
| 365 | verify(intentSynchronizer); |
| 366 | } |
| 367 | |
| 368 | /** |
| 369 | * Tests removing an existing interface. |
| 370 | * |
| 371 | * We first push an intent with destination sw3 and source sw1 and sw2. We |
| 372 | * then remove the ingress interface on sw1. |
| 373 | * |
| 374 | * We verify that the synchronizer records the correct state and that the |
| 375 | * correct intent is withdrawn from the IntentService. |
| 376 | */ |
| 377 | @Test |
| 378 | public void testRemoveIngressInterface() { |
| 379 | // Add a route first |
| 380 | testRouteAddToNoVlan(); |
| 381 | |
| 382 | // Create the new expected intent |
| 383 | MultiPointToSinglePointIntent remainingIntent = |
| 384 | createIntentToThreeSrcTwo(PREFIX1); |
| 385 | |
| 386 | reset(intentSynchronizer); |
| 387 | |
| 388 | intentSynchronizer.submit(eqExceptId(remainingIntent)); |
| 389 | expectLastCall().once(); |
| 390 | |
| 391 | replay(intentSynchronizer); |
| 392 | |
| 393 | // Define the existing ingress interface and remove it |
| 394 | Interface intf = new Interface("sw1-eth1", SW1_ETH1, |
| 395 | Collections.singletonList(IIP1), |
| 396 | MAC1, VLAN10); |
| 397 | InterfaceEvent intfEvent = |
| 398 | new InterfaceEvent(InterfaceEvent.Type.INTERFACE_REMOVED, intf); |
| 399 | interfaceListener.event(intfEvent); |
| 400 | |
| 401 | verify(intentSynchronizer); |
| 402 | } |
| 403 | |
| 404 | /** |
| 405 | * Tests removing an existing egress interface. |
| 406 | * |
| 407 | * We first push an intent with destination sw3 and source sw1 and sw2. We |
| 408 | * then remove the egress interface on sw3. |
| 409 | * |
| 410 | * We verify that the synchronizer records the correct state and that the |
| 411 | * correct intent is withdrawn from the IntentService. |
| 412 | */ |
| 413 | @Test |
| 414 | public void testRemoveEgressInterface() { |
| 415 | // Add a route first |
| 416 | testRouteAddToNoVlan(); |
| 417 | |
| 418 | // Create existing intent |
| 419 | MultiPointToSinglePointIntent removedIntent = |
| 420 | createIntentToThreeSrcOneTwo(PREFIX1); |
| 421 | |
| 422 | // Set up expectation |
| 423 | reset(intentSynchronizer); |
| 424 | // Setup the expected intents |
| 425 | intentSynchronizer.withdraw(eqExceptId(removedIntent)); |
| 426 | replay(intentSynchronizer); |
| 427 | |
| 428 | // Define the existing egress interface and remove it |
| 429 | Interface intf = new Interface("sw3-eth1", SW3_ETH1, |
| 430 | Collections.singletonList(IIP3), |
| 431 | MAC3, VlanId.NONE); |
| 432 | InterfaceEvent intfEvent = |
| 433 | new InterfaceEvent(InterfaceEvent.Type.INTERFACE_REMOVED, intf); |
| 434 | interfaceListener.event(intfEvent); |
| 435 | |
| 436 | verify(intentSynchronizer); |
| 437 | } |
| 438 | |
| 439 | /* |
| 440 | * Builds a MultiPointToSinglePointIntent with dest sw1 (VLAN Id) and src |
| 441 | * sw2, sw3. |
| 442 | */ |
| 443 | private MultiPointToSinglePointIntent createIntentToOne(IpPrefix ipPrefix) { |
| 444 | // Build the expected treatment |
| 445 | TrafficTreatment.Builder treatmentBuilder = |
| 446 | DefaultTrafficTreatment.builder(); |
| 447 | treatmentBuilder.setEthDst(MAC1); |
| 448 | |
| 449 | // Build the expected egress FilteredConnectPoint |
| 450 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 451 | selector.matchVlanId(VLAN10); |
| 452 | FilteredConnectPoint egressFilteredCP = |
| 453 | new FilteredConnectPoint(SW1_ETH1, selector.build()); |
| 454 | |
| 455 | // Build the expected selectors |
| 456 | Set<FilteredConnectPoint> ingressFilteredCPs = Sets.newHashSet(); |
| 457 | |
| 458 | // Build the expected ingress FilteredConnectPoint for sw2 |
| 459 | selector = DefaultTrafficSelector.builder(); |
| 460 | selector.matchVlanId(VLAN20); |
| 461 | selector.matchEthType(Ethernet.TYPE_IPV4); |
| 462 | selector.matchIPDst(ipPrefix); |
| 463 | FilteredConnectPoint ingressFilteredCP = |
| 464 | new FilteredConnectPoint(SW2_ETH1, selector.build()); |
| 465 | ingressFilteredCPs.add(ingressFilteredCP); |
| 466 | |
| 467 | // Build the expected ingress FilteredConnectPoint for sw3 |
| 468 | selector = DefaultTrafficSelector.builder(); |
| 469 | selector.matchEthType(Ethernet.TYPE_IPV4); |
| 470 | selector.matchIPDst(ipPrefix); |
| 471 | ingressFilteredCP = new FilteredConnectPoint(SW3_ETH1, selector.build()); |
| 472 | ingressFilteredCPs.add(ingressFilteredCP); |
| 473 | |
| 474 | // Build the expected intent |
| 475 | MultiPointToSinglePointIntent intent = |
| 476 | MultiPointToSinglePointIntent.builder() |
| 477 | .appId(APPID) |
| 478 | .key(Key.of(ipPrefix.toString(), APPID)) |
| 479 | .filteredIngressPoints(ingressFilteredCPs) |
| 480 | .filteredEgressPoint(egressFilteredCP) |
| 481 | .treatment(treatmentBuilder.build()) |
| 482 | .constraints(SdnIpFib.CONSTRAINTS) |
| 483 | .build(); |
| 484 | |
| 485 | return intent; |
| 486 | } |
| 487 | |
| 488 | /* |
| 489 | * Builds a MultiPointToSinglePointIntent with dest sw3 (no VLAN Id) and src |
| 490 | * sw1, sw2. |
| 491 | */ |
| 492 | private MultiPointToSinglePointIntent createIntentToThreeSrcOneTwo(IpPrefix ipPrefix) { |
| 493 | // Build the expected treatment |
| 494 | TrafficTreatment.Builder treatmentBuilder = |
| 495 | DefaultTrafficTreatment.builder(); |
| 496 | treatmentBuilder.setEthDst(MAC3); |
| 497 | |
| 498 | // Build the expected egress FilteredConnectPoint |
| 499 | FilteredConnectPoint egressFilteredCP = new FilteredConnectPoint(SW3_ETH1); |
| 500 | |
| 501 | // Build the expected selectors |
| 502 | Set<FilteredConnectPoint> ingressFilteredCPs = Sets.newHashSet(); |
| 503 | |
| 504 | // Build the expected ingress FilteredConnectPoint for sw1 |
| 505 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 506 | selector.matchVlanId(VLAN10); |
| 507 | selector.matchEthType(Ethernet.TYPE_IPV4); |
| 508 | selector.matchIPDst(ipPrefix); |
| 509 | FilteredConnectPoint ingressFilteredCP = |
| 510 | new FilteredConnectPoint(SW1_ETH1, selector.build()); |
| 511 | ingressFilteredCPs.add(ingressFilteredCP); |
| 512 | |
| 513 | // Build the expected ingress FilteredConnectPoint for sw2 |
| 514 | selector = DefaultTrafficSelector.builder(); |
| 515 | selector.matchVlanId(VLAN20); |
| 516 | selector.matchEthType(Ethernet.TYPE_IPV4); |
| 517 | selector.matchIPDst(ipPrefix); |
| 518 | ingressFilteredCP = new FilteredConnectPoint(SW2_ETH1, selector.build()); |
| 519 | ingressFilteredCPs.add(ingressFilteredCP); |
| 520 | |
| 521 | // Build the expected intent |
| 522 | MultiPointToSinglePointIntent intent = |
| 523 | MultiPointToSinglePointIntent.builder() |
| 524 | .appId(APPID) |
| 525 | .key(Key.of(ipPrefix.toString(), APPID)) |
| 526 | .filteredIngressPoints(ingressFilteredCPs) |
| 527 | .filteredEgressPoint(egressFilteredCP) |
| 528 | .treatment(treatmentBuilder.build()) |
| 529 | .constraints(SdnIpFib.CONSTRAINTS) |
| 530 | .build(); |
| 531 | |
| 532 | return intent; |
| 533 | } |
| 534 | |
| 535 | /* |
| 536 | * Builds a MultiPointToSinglePointIntent with dest sw3 (no VLAN Id) and src |
| 537 | * sw2. |
| 538 | */ |
| 539 | private MultiPointToSinglePointIntent createIntentToThreeSrcTwo(IpPrefix ipPrefix) { |
| 540 | // Build the expected treatment |
| 541 | TrafficTreatment.Builder treatmentBuilder = |
| 542 | DefaultTrafficTreatment.builder(); |
| 543 | treatmentBuilder.setEthDst(MAC3); |
| 544 | |
| 545 | // Build the expected egress FilteredConnectPoint |
| 546 | FilteredConnectPoint egressFilteredCP = new FilteredConnectPoint(SW3_ETH1); |
| 547 | |
| 548 | // Build the expected ingress FilteredConnectPoint for sw2 |
| 549 | Set<FilteredConnectPoint> ingressFilteredCPs = Sets.newHashSet(); |
| 550 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 551 | selector.matchVlanId(VLAN20); |
| 552 | selector.matchEthType(Ethernet.TYPE_IPV4); |
| 553 | selector.matchIPDst(ipPrefix); |
| 554 | FilteredConnectPoint ingressFilteredCP = |
| 555 | new FilteredConnectPoint(SW2_ETH1, selector.build()); |
| 556 | ingressFilteredCPs.add(ingressFilteredCP); |
| 557 | |
| 558 | // Build the expected intent |
| 559 | MultiPointToSinglePointIntent intent = |
| 560 | MultiPointToSinglePointIntent.builder() |
| 561 | .appId(APPID) |
| 562 | .key(Key.of(ipPrefix.toString(), APPID)) |
| 563 | .filteredIngressPoints(ingressFilteredCPs) |
| 564 | .filteredEgressPoint(egressFilteredCP) |
| 565 | .treatment(treatmentBuilder.build()) |
| 566 | .constraints(SdnIpFib.CONSTRAINTS) |
| 567 | .build(); |
| 568 | |
| 569 | return intent; |
| 570 | } |
| 571 | |
| 572 | /* |
| 573 | * Builds a MultiPointToSinglePointIntent with dest sw3 (no VLAN Id) and src |
| 574 | * sw1, sw2, sw4. |
| 575 | */ |
| 576 | private MultiPointToSinglePointIntent createIntentToThreeSrcOneTwoFour(IpPrefix ipPrefix) { |
| 577 | // Build the expected treatment |
| 578 | TrafficTreatment.Builder treatmentBuilder = |
| 579 | DefaultTrafficTreatment.builder(); |
| 580 | treatmentBuilder.setEthDst(MAC3); |
| 581 | |
| 582 | // Build the expected egress FilteredConnectPoint |
| 583 | FilteredConnectPoint egressFilteredCP = new FilteredConnectPoint(SW3_ETH1); |
| 584 | |
| 585 | // Build the expected selectors |
| 586 | Set<FilteredConnectPoint> ingressFilteredCPs = Sets.newHashSet(); |
| 587 | |
| 588 | // Build the expected ingress FilteredConnectPoint for sw1 |
| 589 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 590 | selector.matchVlanId(VLAN10); |
| 591 | selector.matchEthType(Ethernet.TYPE_IPV4); |
| 592 | selector.matchIPDst(ipPrefix); |
| 593 | FilteredConnectPoint ingressFilteredCP = |
| 594 | new FilteredConnectPoint(SW1_ETH1, selector.build()); |
| 595 | ingressFilteredCPs.add(ingressFilteredCP); |
| 596 | |
| 597 | // Build the expected ingress FilteredConnectPoint for sw2 |
| 598 | selector = DefaultTrafficSelector.builder(); |
| 599 | selector.matchVlanId(VLAN20); |
| 600 | selector.matchEthType(Ethernet.TYPE_IPV4); |
| 601 | selector.matchIPDst(ipPrefix); |
| 602 | ingressFilteredCP = new FilteredConnectPoint(SW2_ETH1, selector.build()); |
| 603 | ingressFilteredCPs.add(ingressFilteredCP); |
| 604 | |
| 605 | // Build the expected ingress FilteredConnectPoint for sw4 |
| 606 | selector = DefaultTrafficSelector.builder(); |
| 607 | selector.matchEthType(Ethernet.TYPE_IPV4); |
| 608 | selector.matchIPDst(ipPrefix); |
| 609 | ingressFilteredCP = new FilteredConnectPoint(SW4_ETH1, selector.build()); |
| 610 | ingressFilteredCPs.add(ingressFilteredCP); |
| 611 | |
| 612 | // Build the expected intent |
| 613 | MultiPointToSinglePointIntent intent = |
| 614 | MultiPointToSinglePointIntent.builder() |
| 615 | .appId(APPID) |
| 616 | .key(Key.of(ipPrefix.toString(), APPID)) |
| 617 | .filteredIngressPoints(ingressFilteredCPs) |
| 618 | .filteredEgressPoint(egressFilteredCP) |
| 619 | .treatment(treatmentBuilder.build()) |
| 620 | .constraints(SdnIpFib.CONSTRAINTS) |
| 621 | .build(); |
| 622 | |
| 623 | return intent; |
| 624 | } |
| 625 | |
| 626 | private class TestCoreService extends CoreServiceAdapter { |
| 627 | @Override |
| 628 | public ApplicationId getAppId(String name) { |
| 629 | return APPID; |
| 630 | } |
| 631 | } |
| 632 | |
| 633 | private class TestRouteService extends RouteServiceAdapter { |
| 634 | @Override |
| 635 | public void addListener(RouteListener routeListener) { |
| 636 | SdnIpFibTest.this.routeListener = routeListener; |
| 637 | } |
| 638 | } |
| 639 | |
Luca Prete | 83bac34 | 2016-12-06 19:42:05 -0800 | [diff] [blame] | 640 | private class TestNetworkConfigService extends NetworkConfigServiceAdapter { |
| 641 | /** |
| 642 | * Returns an empty BGP network configuration to be able to correctly |
| 643 | * return the encapsulation parameter when needed. |
| 644 | * |
| 645 | * @return an empty BGP network configuration object |
| 646 | */ |
| 647 | @Override |
| 648 | public <S, C extends Config<S>> C getConfig(S subject, Class<C> configClass) { |
| 649 | ApplicationId appId = |
| 650 | new TestApplicationId(SdnIp.SDN_IP_APP); |
| 651 | |
| 652 | ObjectMapper mapper = new ObjectMapper(); |
| 653 | ConfigApplyDelegate delegate = new MockCfgDelegate(); |
| 654 | JsonNode emptyTree = new ObjectMapper().createObjectNode(); |
| 655 | |
| 656 | SdnIpConfig sdnIpConfig = new SdnIpConfig(); |
| 657 | |
| 658 | sdnIpConfig.init(appId, "sdnip-test", emptyTree, mapper, delegate); |
| 659 | |
| 660 | return (C) sdnIpConfig; |
| 661 | } |
| 662 | } |
| 663 | |
Luca Prete | e4a5e1a | 2016-09-07 17:01:22 -0700 | [diff] [blame] | 664 | private class InterfaceServiceDelegate extends InterfaceServiceAdapter { |
| 665 | @Override |
| 666 | public void addListener(InterfaceListener listener) { |
| 667 | SdnIpFibTest.this.interfaceListener = listener; |
| 668 | } |
| 669 | } |
Luca Prete | 83bac34 | 2016-12-06 19:42:05 -0800 | [diff] [blame] | 670 | |
| 671 | private class MockCfgDelegate implements ConfigApplyDelegate { |
| 672 | @Override |
| 673 | public void onApply(@SuppressWarnings("rawtypes") Config config) { |
| 674 | config.apply(); |
| 675 | } |
| 676 | } |
Luca Prete | e4a5e1a | 2016-09-07 17:01:22 -0700 | [diff] [blame] | 677 | } |