blob: d591d6d47bf8712c2e61025c090ba96bced2677b [file] [log] [blame]
gaurav36785932016-03-10 17:24:04 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
gaurav36785932016-03-10 17:24:04 +05303 *
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 */
Jonathan Hartf4bd0482017-01-27 15:11:18 -080016
17package org.onosproject.routing.fibinstaller;
gaurav36785932016-03-10 17:24:04 +053018
Jonathan Hartf04b7d92016-03-29 09:39:11 -070019import com.google.common.collect.Sets;
gaurav36785932016-03-10 17:24:04 +053020import org.easymock.EasyMock;
21import org.junit.Before;
22import org.junit.Test;
23import org.onlab.packet.Ethernet;
gaurav36785932016-03-10 17:24:04 +053024import org.onlab.packet.Ip4Prefix;
25import org.onlab.packet.IpAddress;
26import org.onlab.packet.IpPrefix;
27import org.onlab.packet.MacAddress;
28import org.onlab.packet.VlanId;
29import org.onosproject.TestApplicationId;
gaurava2e61a52016-05-05 03:39:31 +053030import org.onosproject.app.ApplicationService;
Jonathan Hartf04b7d92016-03-29 09:39:11 -070031import org.onosproject.cfg.ComponentConfigService;
gaurav36785932016-03-10 17:24:04 +053032import org.onosproject.core.ApplicationId;
33import org.onosproject.core.CoreService;
Ray Milkeyfacf2862017-08-03 11:58:29 -070034import org.onosproject.net.intf.Interface;
35import org.onosproject.net.intf.InterfaceListener;
36import org.onosproject.net.intf.InterfaceService;
37import org.onosproject.net.intf.InterfaceServiceAdapter;
Ray Milkey69ec8712017-08-08 13:00:43 -070038import org.onosproject.routeservice.ResolvedRoute;
39import org.onosproject.routeservice.Route;
40import org.onosproject.routeservice.RouteEvent;
41import org.onosproject.routeservice.RouteListener;
42import org.onosproject.routeservice.RouteServiceAdapter;
gaurav36785932016-03-10 17:24:04 +053043import org.onosproject.net.ConnectPoint;
44import org.onosproject.net.DeviceId;
45import org.onosproject.net.PortNumber;
Jonathan Hart25bd6682016-06-03 10:45:47 -070046import org.onosproject.net.config.NetworkConfigListener;
Charles Chand55e84d2016-03-30 17:54:24 -070047import org.onosproject.net.config.NetworkConfigRegistry;
gaurav36785932016-03-10 17:24:04 +053048import org.onosproject.net.config.NetworkConfigService;
49import org.onosproject.net.device.DeviceListener;
50import org.onosproject.net.device.DeviceService;
51import org.onosproject.net.device.DeviceServiceAdapter;
52import org.onosproject.net.flow.DefaultTrafficSelector;
53import org.onosproject.net.flow.DefaultTrafficTreatment;
54import org.onosproject.net.flow.TrafficSelector;
55import org.onosproject.net.flow.TrafficTreatment;
56import org.onosproject.net.flowobjective.DefaultForwardingObjective;
57import org.onosproject.net.flowobjective.DefaultNextObjective;
58import org.onosproject.net.flowobjective.FlowObjectiveService;
59import org.onosproject.net.flowobjective.ForwardingObjective;
60import org.onosproject.net.flowobjective.NextObjective;
61import org.onosproject.net.host.InterfaceIpAddress;
gaurav36785932016-03-10 17:24:04 +053062import org.onosproject.routing.RoutingService;
gaurav36785932016-03-10 17:24:04 +053063import org.onosproject.routing.config.RouterConfig;
Jonathan Hart249b4cf2017-02-03 18:02:58 -080064import org.onosproject.routing.config.RoutersConfig;
Jonathan Hartf04b7d92016-03-29 09:39:11 -070065import org.osgi.service.component.ComponentContext;
66
67import java.util.ArrayList;
68import java.util.Collections;
Jonathan Hartf04b7d92016-03-29 09:39:11 -070069import java.util.List;
70import java.util.Set;
71
72import static org.easymock.EasyMock.anyObject;
Jonathan Harta2eb9ff2016-04-13 21:27:06 -070073import static org.easymock.EasyMock.anyString;
Jonathan Hartf04b7d92016-03-29 09:39:11 -070074import static org.easymock.EasyMock.createMock;
Jonathan Harta2eb9ff2016-04-13 21:27:06 -070075import static org.easymock.EasyMock.createNiceMock;
76import static org.easymock.EasyMock.eq;
Jonathan Hartf04b7d92016-03-29 09:39:11 -070077import static org.easymock.EasyMock.expect;
Jonathan Harta2eb9ff2016-04-13 21:27:06 -070078import static org.easymock.EasyMock.expectLastCall;
Jonathan Hartf04b7d92016-03-29 09:39:11 -070079import static org.easymock.EasyMock.replay;
80import static org.easymock.EasyMock.reset;
81import static org.easymock.EasyMock.verify;
gaurav36785932016-03-10 17:24:04 +053082
83/**
84 * Unit tests for SingleSwitchFibInstaller.
85 */
Jonathan Harte7327042017-02-02 13:11:25 -080086public class FibInstallerTest {
gaurav36785932016-03-10 17:24:04 +053087
Jonathan Harta2eb9ff2016-04-13 21:27:06 -070088 private static final DeviceId DEVICE_ID = DeviceId.deviceId("of:0000000000000001");
89
gaurav36785932016-03-10 17:24:04 +053090 private static final ConnectPoint SW1_ETH1 = new ConnectPoint(
Jonathan Harta2eb9ff2016-04-13 21:27:06 -070091 DEVICE_ID, PortNumber.portNumber(1));
gaurav36785932016-03-10 17:24:04 +053092
Jonathan Harta2eb9ff2016-04-13 21:27:06 -070093 private static final ConnectPoint SW1_ETH2 = new ConnectPoint(
94 DEVICE_ID, PortNumber.portNumber(2));
gaurav36785932016-03-10 17:24:04 +053095
Jonathan Harta2eb9ff2016-04-13 21:27:06 -070096 private static final int NEXT_ID = 11;
gaurav36785932016-03-10 17:24:04 +053097
Jonathan Harta2eb9ff2016-04-13 21:27:06 -070098 private static final VlanId VLAN1 = VlanId.vlanId((short) 1);
99 private static final MacAddress MAC1 = MacAddress.valueOf("00:00:00:00:00:01");
100 private static final MacAddress MAC2 = MacAddress.valueOf("00:00:00:00:00:02");
gaurav36785932016-03-10 17:24:04 +0530101
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700102 private static final IpPrefix PREFIX1 = Ip4Prefix.valueOf("1.1.1.0/24");
103 private static final IpAddress NEXT_HOP1 = IpAddress.valueOf("192.168.10.1");
104 private static final IpAddress NEXT_HOP2 = IpAddress.valueOf("192.168.20.1");
105 private static final InterfaceIpAddress INTF1 =
106 InterfaceIpAddress.valueOf("192.168.10.2/24");
107 private static final InterfaceIpAddress INTF2 =
108 InterfaceIpAddress.valueOf("192.168.20.2/24");
109
gaurav36785932016-03-10 17:24:04 +0530110 private final Set<Interface> interfaces = Sets.newHashSet();
111 private InterfaceService interfaceService;
112 private NetworkConfigService networkConfigService;
Charles Chand55e84d2016-03-30 17:54:24 -0700113 private NetworkConfigRegistry networkConfigRegistry;
gaurav36785932016-03-10 17:24:04 +0530114 private FlowObjectiveService flowObjectiveService;
gaurava2e61a52016-05-05 03:39:31 +0530115 private ApplicationService applicationService;
gaurav36785932016-03-10 17:24:04 +0530116 private DeviceService deviceService;
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700117 private static final ApplicationId APPID = TestApplicationId.create("foo");
118
119 private RouteListener routeListener;
gaurav36785932016-03-10 17:24:04 +0530120 private DeviceListener deviceListener;
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700121
gaurav36785932016-03-10 17:24:04 +0530122 private RouterConfig routerConfig;
Jonathan Harte7327042017-02-02 13:11:25 -0800123 private FibInstaller sSfibInstaller;
gaurav164cf6d2016-03-25 21:43:04 +0530124 private InterfaceListener interfaceListener;
gaurav36785932016-03-10 17:24:04 +0530125
126 @Before
127 public void setUp() throws Exception {
Jonathan Harte7327042017-02-02 13:11:25 -0800128 sSfibInstaller = new FibInstaller();
gaurav36785932016-03-10 17:24:04 +0530129
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700130 sSfibInstaller.componentConfigService = createNiceMock(ComponentConfigService.class);
gaurav36785932016-03-10 17:24:04 +0530131
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700132 ComponentContext mockContext = createNiceMock(ComponentContext.class);
gaurav36785932016-03-10 17:24:04 +0530133
gaurav36785932016-03-10 17:24:04 +0530134 routerConfig = new TestRouterConfig();
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700135 interfaceService = createMock(InterfaceService.class);
136
gaurav36785932016-03-10 17:24:04 +0530137 networkConfigService = createMock(NetworkConfigService.class);
Jonathan Hart25bd6682016-06-03 10:45:47 -0700138 networkConfigService.addListener(anyObject(NetworkConfigListener.class));
139 expectLastCall().anyTimes();
Charles Chand55e84d2016-03-30 17:54:24 -0700140 networkConfigRegistry = createMock(NetworkConfigRegistry.class);
gaurav36785932016-03-10 17:24:04 +0530141 flowObjectiveService = createMock(FlowObjectiveService.class);
gaurava2e61a52016-05-05 03:39:31 +0530142 applicationService = createNiceMock(ApplicationService.class);
143 replay(applicationService);
gaurav36785932016-03-10 17:24:04 +0530144 deviceService = new TestDeviceService();
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700145 CoreService coreService = createNiceMock(CoreService.class);
Charles Chand55e84d2016-03-30 17:54:24 -0700146 expect(coreService.registerApplication(anyString())).andReturn(APPID).anyTimes();
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700147 replay(coreService);
gaurav36785932016-03-10 17:24:04 +0530148
149 sSfibInstaller.networkConfigService = networkConfigService;
Charles Chand55e84d2016-03-30 17:54:24 -0700150 sSfibInstaller.networkConfigRegistry = networkConfigRegistry;
gaurav36785932016-03-10 17:24:04 +0530151 sSfibInstaller.interfaceService = interfaceService;
152 sSfibInstaller.flowObjectiveService = flowObjectiveService;
gaurava2e61a52016-05-05 03:39:31 +0530153 sSfibInstaller.applicationService = applicationService;
gaurav36785932016-03-10 17:24:04 +0530154 sSfibInstaller.coreService = coreService;
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700155 sSfibInstaller.routeService = new TestRouteService();
gaurav36785932016-03-10 17:24:04 +0530156 sSfibInstaller.deviceService = deviceService;
157
158 setUpNetworkConfigService();
159 setUpInterfaceService();
160 sSfibInstaller.activate(mockContext);
161 }
162
163 /**
164 * Sets up InterfaceService.
165 */
166 private void setUpInterfaceService() {
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700167 interfaceService.addListener(anyObject(InterfaceListener.class));
168 expectLastCall().andDelegateTo(new TestInterfaceService());
169
170 // Interface with no VLAN
171 Interface sw1Eth1 = new Interface("intf1", SW1_ETH1,
172 Collections.singletonList(INTF1), MAC1, VlanId.NONE);
173 expect(interfaceService.getMatchingInterface(NEXT_HOP1)).andReturn(sw1Eth1);
gaurav36785932016-03-10 17:24:04 +0530174 interfaces.add(sw1Eth1);
175
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700176 // Interface with a VLAN
177 Interface sw2Eth1 = new Interface("intf2", SW1_ETH2,
178 Collections.singletonList(INTF2), MAC2, VLAN1);
179 expect(interfaceService.getMatchingInterface(NEXT_HOP2)).andReturn(sw2Eth1);
gaurav36785932016-03-10 17:24:04 +0530180 interfaces.add(sw2Eth1);
181
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700182 expect(interfaceService.getInterfaces()).andReturn(interfaces);
gaurav36785932016-03-10 17:24:04 +0530183
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700184 replay(interfaceService);
gaurav36785932016-03-10 17:24:04 +0530185 }
186
187 /*
188 * Sets up NetworkConfigService.
Jonathan Hartf04b7d92016-03-29 09:39:11 -0700189 */
gaurav36785932016-03-10 17:24:04 +0530190 private void setUpNetworkConfigService() {
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700191 expect(networkConfigService.getConfig(
192 anyObject(ApplicationId.class), eq(RoutingService.ROUTER_CONFIG_CLASS))).
gaurav36785932016-03-10 17:24:04 +0530193 andReturn(routerConfig);
Jonathan Hart249b4cf2017-02-03 18:02:58 -0800194 expect(networkConfigService.getConfig(anyObject(ApplicationId.class), eq(RoutersConfig.class)))
195 .andReturn(null);
gaurav36785932016-03-10 17:24:04 +0530196 replay(networkConfigService);
197 }
198
199 /**
200 * Sets up FlowObjectiveService.
201 */
202 private void setUpFlowObjectiveService() {
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700203 expect(flowObjectiveService.allocateNextId()).andReturn(NEXT_ID);
gaurav36785932016-03-10 17:24:04 +0530204 replay(flowObjectiveService);
205 }
206
207 /**
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700208 * Creates a next objective with the given parameters.
gaurav36785932016-03-10 17:24:04 +0530209 *
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700210 * @param srcMac source MAC address
211 * @param dstMac destination MAC address
212 * @param port port number
213 * @param vlan vlan ID
214 * @param add whether to create an add objective or remove objective
215 * @return new next objective
gaurav36785932016-03-10 17:24:04 +0530216 */
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700217 private NextObjective createNextObjective(MacAddress srcMac,
218 MacAddress dstMac,
219 PortNumber port,
220 VlanId vlan,
221 boolean add) {
gaurav36785932016-03-10 17:24:04 +0530222 TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder()
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700223 .setEthSrc(srcMac)
224 .setEthDst(dstMac);
gaurav36785932016-03-10 17:24:04 +0530225 TrafficSelector.Builder metabuilder = null;
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700226 if (!vlan.equals(VlanId.NONE)) {
gaurav36785932016-03-10 17:24:04 +0530227 treatment.pushVlan()
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700228 .setVlanId(vlan)
229 .setVlanPcp((byte) 0);
gaurav36785932016-03-10 17:24:04 +0530230 } else {
231 metabuilder = DefaultTrafficSelector.builder();
Jonathan Harte7327042017-02-02 13:11:25 -0800232 metabuilder.matchVlanId(VlanId.vlanId(FibInstaller.ASSIGNED_VLAN));
gaurav36785932016-03-10 17:24:04 +0530233 }
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700234
235 treatment.setOutput(port);
gaurav36785932016-03-10 17:24:04 +0530236 NextObjective.Builder nextBuilder = DefaultNextObjective.builder()
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700237 .withId(NEXT_ID)
gaurav36785932016-03-10 17:24:04 +0530238 .addTreatment(treatment.build())
239 .withType(NextObjective.Type.SIMPLE)
240 .fromApp(APPID);
241 if (metabuilder != null) {
242 nextBuilder.withMeta(metabuilder.build());
243 }
244
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700245 return add ? nextBuilder.add() : nextBuilder.remove();
246 }
gaurav36785932016-03-10 17:24:04 +0530247
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700248 /**
249 * Creates a new forwarding objective with the given parameters.
250 *
251 * @param prefix IP prefix
252 * @param add whether to create an add objective or a remove objective
253 * @return new forwarding objective
254 */
255 private ForwardingObjective createForwardingObjective(IpPrefix prefix,
256 boolean add) {
gaurav36785932016-03-10 17:24:04 +0530257 TrafficSelector selector = DefaultTrafficSelector.builder()
258 .matchEthType(Ethernet.TYPE_IPV4)
259 .matchIPDst(prefix)
260 .build();
261
262 int priority = prefix.prefixLength() * 5 + 100;
263 ForwardingObjective.Builder fwdBuilder = DefaultForwardingObjective.builder()
264 .fromApp(APPID)
265 .makePermanent()
266 .withSelector(selector)
267 .withPriority(priority)
268 .withFlag(ForwardingObjective.Flag.SPECIFIC);
269
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700270 if (add) {
271 fwdBuilder.nextStep(NEXT_ID);
272 } else {
273 fwdBuilder.withTreatment(DefaultTrafficTreatment.builder().build());
274 }
275
276 return add ? fwdBuilder.add() : fwdBuilder.remove();
277 }
278
279 /**
280 * Tests adding a route.
281 *
282 * We verify that the flowObjectiveService records the correct state and that the
283 * correct flow is submitted to the flowObjectiveService.
284 */
285 @Test
286 public void testRouteAdd() {
Jonathan Hartf2e7a342017-03-20 15:43:21 -0700287 ResolvedRoute resolvedRoute = createRoute(PREFIX1, NEXT_HOP1, MAC1, SW1_ETH1);
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700288
289 // Create the next objective
290 NextObjective nextObjective = createNextObjective(MAC1, MAC1, SW1_ETH1.port(), VlanId.NONE, true);
291 flowObjectiveService.next(DEVICE_ID, nextObjective);
292
293 // Create the flow objective
294 ForwardingObjective fwd = createForwardingObjective(PREFIX1, true);
295 flowObjectiveService.forward(DEVICE_ID, fwd);
gaurav36785932016-03-10 17:24:04 +0530296 EasyMock.expectLastCall().once();
297 setUpFlowObjectiveService();
298
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700299 // Send in the add event
300 RouteEvent routeEvent = new RouteEvent(RouteEvent.Type.ROUTE_ADDED, resolvedRoute);
301 routeListener.event(routeEvent);
gaurav36785932016-03-10 17:24:04 +0530302 verify(flowObjectiveService);
303 }
304
305 /**
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700306 * Tests adding a route with to a next hop in a VLAN.
gaurav36785932016-03-10 17:24:04 +0530307 *
308 * We verify that the flowObjectiveService records the correct state and that the
309 * correct flowObjectiveService is submitted to the flowObjectiveService.
310 */
311 @Test
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700312 public void testRouteAddWithVlan() {
Jonathan Hartf2e7a342017-03-20 15:43:21 -0700313 ResolvedRoute route = createRoute(PREFIX1, NEXT_HOP2, MAC2, SW1_ETH2);
gaurav36785932016-03-10 17:24:04 +0530314
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700315 // Create the next objective
316 NextObjective nextObjective = createNextObjective(MAC2, MAC2, SW1_ETH2.port(), VLAN1, true);
317 flowObjectiveService.next(DEVICE_ID, nextObjective);
gaurav36785932016-03-10 17:24:04 +0530318
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700319 // Create the flow objective
320 ForwardingObjective fwd = createForwardingObjective(PREFIX1, true);
321 flowObjectiveService.forward(DEVICE_ID, fwd);
gaurav36785932016-03-10 17:24:04 +0530322 EasyMock.expectLastCall().once();
323 setUpFlowObjectiveService();
324
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700325 // Send in the add event
326 routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_ADDED, route));
gaurav36785932016-03-10 17:24:04 +0530327
328 verify(flowObjectiveService);
329 }
330
331 /**
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700332 * Tests updating a route.
gaurav36785932016-03-10 17:24:04 +0530333 *
334 * We verify that the flowObjectiveService records the correct state and that the
335 * correct flow is submitted to the flowObjectiveService.
336 */
337 @Test
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700338 public void testRouteUpdate() {
gaurav36785932016-03-10 17:24:04 +0530339 // Firstly add a route
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700340 testRouteAdd();
gaurav36785932016-03-10 17:24:04 +0530341 reset(flowObjectiveService);
gaurav36785932016-03-10 17:24:04 +0530342
Jonathan Hartf2e7a342017-03-20 15:43:21 -0700343 ResolvedRoute oldRoute = createRoute(PREFIX1, NEXT_HOP1, MAC1, SW1_ETH1);
344 ResolvedRoute route = createRoute(PREFIX1, NEXT_HOP2, MAC2, SW1_ETH2);
gaurav36785932016-03-10 17:24:04 +0530345
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700346 // Create the next objective
347 NextObjective nextObjective = createNextObjective(MAC2, MAC2, SW1_ETH2.port(), VLAN1, true);
348 flowObjectiveService.next(DEVICE_ID, nextObjective);
gaurav36785932016-03-10 17:24:04 +0530349
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700350 // Create the flow objective
351 ForwardingObjective fwd = createForwardingObjective(PREFIX1, true);
352 flowObjectiveService.forward(DEVICE_ID, fwd);
gaurav36785932016-03-10 17:24:04 +0530353 EasyMock.expectLastCall().once();
354 setUpFlowObjectiveService();
355
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700356 // Send in the update event
Charles Chane4d13102016-11-08 15:38:44 -0800357 routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_UPDATED, route, oldRoute));
gaurav36785932016-03-10 17:24:04 +0530358
359 verify(flowObjectiveService);
360 }
361
Jonathan Hartf04b7d92016-03-29 09:39:11 -0700362 /**
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700363 * Tests deleting a route.
gaurav36785932016-03-10 17:24:04 +0530364 *
365 * We verify that the flowObjectiveService records the correct state and that the
366 * correct flow is withdrawn from the flowObjectiveService.
367 */
gaurav36785932016-03-10 17:24:04 +0530368 @Test
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700369 public void testRouteDelete() {
gaurav36785932016-03-10 17:24:04 +0530370 // Firstly add a route
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700371 testRouteAdd();
gaurav36785932016-03-10 17:24:04 +0530372
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700373 // Construct the existing route
Jonathan Hartf2e7a342017-03-20 15:43:21 -0700374 ResolvedRoute route = createRoute(PREFIX1, NEXT_HOP1, MAC1, SW1_ETH1);
gaurav36785932016-03-10 17:24:04 +0530375
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700376 // Create the flow objective
gaurav36785932016-03-10 17:24:04 +0530377 reset(flowObjectiveService);
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700378 ForwardingObjective fwd = createForwardingObjective(PREFIX1, false);
379 flowObjectiveService.forward(DEVICE_ID, fwd);
gaurav36785932016-03-10 17:24:04 +0530380 replay(flowObjectiveService);
381
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700382 // Send in the delete event
383 routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_REMOVED, route));
gaurav36785932016-03-10 17:24:04 +0530384
385 verify(flowObjectiveService);
386 }
387
Jonathan Hartf2e7a342017-03-20 15:43:21 -0700388 private static ResolvedRoute createRoute(IpPrefix prefix, IpAddress nextHop,
389 MacAddress nextHopMac, ConnectPoint location) {
390 return new ResolvedRoute(
391 new Route(Route.Source.UNDEFINED, prefix, nextHop), nextHopMac, location);
392 }
393
gaurav164cf6d2016-03-25 21:43:04 +0530394 private class TestInterfaceService extends InterfaceServiceAdapter {
gaurav164cf6d2016-03-25 21:43:04 +0530395 @Override
396 public void addListener(InterfaceListener listener) {
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700397 interfaceListener = listener;
gaurav164cf6d2016-03-25 21:43:04 +0530398 }
399 }
400
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700401 private class TestRouteService extends RouteServiceAdapter {
gaurav36785932016-03-10 17:24:04 +0530402 @Override
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700403 public void addListener(RouteListener listener) {
Jonathan Harte7327042017-02-02 13:11:25 -0800404 FibInstallerTest.this.routeListener = listener;
gaurav36785932016-03-10 17:24:04 +0530405 }
406 }
407
408 private class TestRouterConfig extends RouterConfig {
409
410 @Override
411 public List<String> getInterfaces() {
412 ArrayList<String> interfaces = new ArrayList<>();
413 interfaces.add("of:0000000000000001/1");
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700414 interfaces.add("of:0000000000000001/2");
gaurav36785932016-03-10 17:24:04 +0530415 return interfaces;
416 }
417
418 @Override
419 public ConnectPoint getControlPlaneConnectPoint() {
420 return SW1_ETH1;
421 }
422
423 @Override
424 public boolean getOspfEnabled() {
425 return true;
426 }
427 }
428
429 private class TestDeviceService extends DeviceServiceAdapter {
430
431 @Override
432 public boolean isAvailable(DeviceId deviceId) {
433 return true;
434 }
435
436 @Override
437 public void addListener(DeviceListener listener) {
Jonathan Harte7327042017-02-02 13:11:25 -0800438 FibInstallerTest.this.deviceListener = listener;
gaurav36785932016-03-10 17:24:04 +0530439 }
440 }
441}