blob: e17d7799cb53144bd76f7669fe802a5e40b7eef2 [file] [log] [blame]
gaurav36785932016-03-10 17:24:04 +05301/*
Jonathan Hartf4bd0482017-01-27 15:11:18 -08002 * Copyright 2017-present Open Networking Laboratory
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;
gaurav36785932016-03-10 17:24:04 +053034import org.onosproject.incubator.net.intf.Interface;
gaurav164cf6d2016-03-25 21:43:04 +053035import org.onosproject.incubator.net.intf.InterfaceListener;
gaurav36785932016-03-10 17:24:04 +053036import org.onosproject.incubator.net.intf.InterfaceService;
gaurav164cf6d2016-03-25 21:43:04 +053037import org.onosproject.incubator.net.intf.InterfaceServiceAdapter;
Jonathan Harta2eb9ff2016-04-13 21:27:06 -070038import org.onosproject.incubator.net.routing.ResolvedRoute;
39import org.onosproject.incubator.net.routing.RouteEvent;
40import org.onosproject.incubator.net.routing.RouteListener;
41import org.onosproject.incubator.net.routing.RouteServiceAdapter;
gaurav36785932016-03-10 17:24:04 +053042import org.onosproject.net.ConnectPoint;
43import org.onosproject.net.DeviceId;
44import org.onosproject.net.PortNumber;
Jonathan Hart25bd6682016-06-03 10:45:47 -070045import org.onosproject.net.config.NetworkConfigListener;
Charles Chand55e84d2016-03-30 17:54:24 -070046import org.onosproject.net.config.NetworkConfigRegistry;
gaurav36785932016-03-10 17:24:04 +053047import org.onosproject.net.config.NetworkConfigService;
48import org.onosproject.net.device.DeviceListener;
49import org.onosproject.net.device.DeviceService;
50import org.onosproject.net.device.DeviceServiceAdapter;
51import org.onosproject.net.flow.DefaultTrafficSelector;
52import org.onosproject.net.flow.DefaultTrafficTreatment;
53import org.onosproject.net.flow.TrafficSelector;
54import org.onosproject.net.flow.TrafficTreatment;
55import org.onosproject.net.flowobjective.DefaultForwardingObjective;
56import org.onosproject.net.flowobjective.DefaultNextObjective;
57import org.onosproject.net.flowobjective.FlowObjectiveService;
58import org.onosproject.net.flowobjective.ForwardingObjective;
59import org.onosproject.net.flowobjective.NextObjective;
60import org.onosproject.net.host.InterfaceIpAddress;
gaurav36785932016-03-10 17:24:04 +053061import org.onosproject.routing.RoutingService;
gaurav36785932016-03-10 17:24:04 +053062import org.onosproject.routing.config.RouterConfig;
Jonathan Hartf04b7d92016-03-29 09:39:11 -070063import org.osgi.service.component.ComponentContext;
64
65import java.util.ArrayList;
66import java.util.Collections;
Jonathan Hartf04b7d92016-03-29 09:39:11 -070067import java.util.List;
68import java.util.Set;
69
70import static org.easymock.EasyMock.anyObject;
Jonathan Harta2eb9ff2016-04-13 21:27:06 -070071import static org.easymock.EasyMock.anyString;
Jonathan Hartf04b7d92016-03-29 09:39:11 -070072import static org.easymock.EasyMock.createMock;
Jonathan Harta2eb9ff2016-04-13 21:27:06 -070073import static org.easymock.EasyMock.createNiceMock;
74import static org.easymock.EasyMock.eq;
Jonathan Hartf04b7d92016-03-29 09:39:11 -070075import static org.easymock.EasyMock.expect;
Jonathan Harta2eb9ff2016-04-13 21:27:06 -070076import static org.easymock.EasyMock.expectLastCall;
Jonathan Hartf04b7d92016-03-29 09:39:11 -070077import static org.easymock.EasyMock.replay;
78import static org.easymock.EasyMock.reset;
79import static org.easymock.EasyMock.verify;
gaurav36785932016-03-10 17:24:04 +053080
81/**
82 * Unit tests for SingleSwitchFibInstaller.
83 */
Jonathan Harte7327042017-02-02 13:11:25 -080084public class FibInstallerTest {
gaurav36785932016-03-10 17:24:04 +053085
Jonathan Harta2eb9ff2016-04-13 21:27:06 -070086 private static final DeviceId DEVICE_ID = DeviceId.deviceId("of:0000000000000001");
87
gaurav36785932016-03-10 17:24:04 +053088 private static final ConnectPoint SW1_ETH1 = new ConnectPoint(
Jonathan Harta2eb9ff2016-04-13 21:27:06 -070089 DEVICE_ID, PortNumber.portNumber(1));
gaurav36785932016-03-10 17:24:04 +053090
Jonathan Harta2eb9ff2016-04-13 21:27:06 -070091 private static final ConnectPoint SW1_ETH2 = new ConnectPoint(
92 DEVICE_ID, PortNumber.portNumber(2));
gaurav36785932016-03-10 17:24:04 +053093
Jonathan Harta2eb9ff2016-04-13 21:27:06 -070094 private static final int NEXT_ID = 11;
gaurav36785932016-03-10 17:24:04 +053095
Jonathan Harta2eb9ff2016-04-13 21:27:06 -070096 private static final VlanId VLAN1 = VlanId.vlanId((short) 1);
97 private static final MacAddress MAC1 = MacAddress.valueOf("00:00:00:00:00:01");
98 private static final MacAddress MAC2 = MacAddress.valueOf("00:00:00:00:00:02");
gaurav36785932016-03-10 17:24:04 +053099
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700100 private static final IpPrefix PREFIX1 = Ip4Prefix.valueOf("1.1.1.0/24");
101 private static final IpAddress NEXT_HOP1 = IpAddress.valueOf("192.168.10.1");
102 private static final IpAddress NEXT_HOP2 = IpAddress.valueOf("192.168.20.1");
103 private static final InterfaceIpAddress INTF1 =
104 InterfaceIpAddress.valueOf("192.168.10.2/24");
105 private static final InterfaceIpAddress INTF2 =
106 InterfaceIpAddress.valueOf("192.168.20.2/24");
107
gaurav36785932016-03-10 17:24:04 +0530108 private final Set<Interface> interfaces = Sets.newHashSet();
109 private InterfaceService interfaceService;
110 private NetworkConfigService networkConfigService;
Charles Chand55e84d2016-03-30 17:54:24 -0700111 private NetworkConfigRegistry networkConfigRegistry;
gaurav36785932016-03-10 17:24:04 +0530112 private FlowObjectiveService flowObjectiveService;
gaurava2e61a52016-05-05 03:39:31 +0530113 private ApplicationService applicationService;
gaurav36785932016-03-10 17:24:04 +0530114 private DeviceService deviceService;
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700115 private static final ApplicationId APPID = TestApplicationId.create("foo");
116
117 private RouteListener routeListener;
gaurav36785932016-03-10 17:24:04 +0530118 private DeviceListener deviceListener;
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700119
gaurav36785932016-03-10 17:24:04 +0530120 private RouterConfig routerConfig;
Jonathan Harte7327042017-02-02 13:11:25 -0800121 private FibInstaller sSfibInstaller;
gaurav164cf6d2016-03-25 21:43:04 +0530122 private InterfaceListener interfaceListener;
gaurav36785932016-03-10 17:24:04 +0530123
124 @Before
125 public void setUp() throws Exception {
Jonathan Harte7327042017-02-02 13:11:25 -0800126 sSfibInstaller = new FibInstaller();
gaurav36785932016-03-10 17:24:04 +0530127
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700128 sSfibInstaller.componentConfigService = createNiceMock(ComponentConfigService.class);
gaurav36785932016-03-10 17:24:04 +0530129
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700130 ComponentContext mockContext = createNiceMock(ComponentContext.class);
gaurav36785932016-03-10 17:24:04 +0530131
gaurav36785932016-03-10 17:24:04 +0530132 routerConfig = new TestRouterConfig();
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700133 interfaceService = createMock(InterfaceService.class);
134
gaurav36785932016-03-10 17:24:04 +0530135 networkConfigService = createMock(NetworkConfigService.class);
Jonathan Hart25bd6682016-06-03 10:45:47 -0700136 networkConfigService.addListener(anyObject(NetworkConfigListener.class));
137 expectLastCall().anyTimes();
Charles Chand55e84d2016-03-30 17:54:24 -0700138 networkConfigRegistry = createMock(NetworkConfigRegistry.class);
gaurav36785932016-03-10 17:24:04 +0530139 flowObjectiveService = createMock(FlowObjectiveService.class);
gaurava2e61a52016-05-05 03:39:31 +0530140 applicationService = createNiceMock(ApplicationService.class);
141 replay(applicationService);
gaurav36785932016-03-10 17:24:04 +0530142 deviceService = new TestDeviceService();
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700143 CoreService coreService = createNiceMock(CoreService.class);
Charles Chand55e84d2016-03-30 17:54:24 -0700144 expect(coreService.registerApplication(anyString())).andReturn(APPID).anyTimes();
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700145 replay(coreService);
gaurav36785932016-03-10 17:24:04 +0530146
147 sSfibInstaller.networkConfigService = networkConfigService;
Charles Chand55e84d2016-03-30 17:54:24 -0700148 sSfibInstaller.networkConfigRegistry = networkConfigRegistry;
gaurav36785932016-03-10 17:24:04 +0530149 sSfibInstaller.interfaceService = interfaceService;
150 sSfibInstaller.flowObjectiveService = flowObjectiveService;
gaurava2e61a52016-05-05 03:39:31 +0530151 sSfibInstaller.applicationService = applicationService;
gaurav36785932016-03-10 17:24:04 +0530152 sSfibInstaller.coreService = coreService;
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700153 sSfibInstaller.routeService = new TestRouteService();
gaurav36785932016-03-10 17:24:04 +0530154 sSfibInstaller.deviceService = deviceService;
155
156 setUpNetworkConfigService();
157 setUpInterfaceService();
158 sSfibInstaller.activate(mockContext);
159 }
160
161 /**
162 * Sets up InterfaceService.
163 */
164 private void setUpInterfaceService() {
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700165 interfaceService.addListener(anyObject(InterfaceListener.class));
166 expectLastCall().andDelegateTo(new TestInterfaceService());
167
168 // Interface with no VLAN
169 Interface sw1Eth1 = new Interface("intf1", SW1_ETH1,
170 Collections.singletonList(INTF1), MAC1, VlanId.NONE);
171 expect(interfaceService.getMatchingInterface(NEXT_HOP1)).andReturn(sw1Eth1);
gaurav36785932016-03-10 17:24:04 +0530172 interfaces.add(sw1Eth1);
173
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700174 // Interface with a VLAN
175 Interface sw2Eth1 = new Interface("intf2", SW1_ETH2,
176 Collections.singletonList(INTF2), MAC2, VLAN1);
177 expect(interfaceService.getMatchingInterface(NEXT_HOP2)).andReturn(sw2Eth1);
gaurav36785932016-03-10 17:24:04 +0530178 interfaces.add(sw2Eth1);
179
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700180 expect(interfaceService.getInterfaces()).andReturn(interfaces);
gaurav36785932016-03-10 17:24:04 +0530181
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700182 replay(interfaceService);
gaurav36785932016-03-10 17:24:04 +0530183 }
184
185 /*
186 * Sets up NetworkConfigService.
Jonathan Hartf04b7d92016-03-29 09:39:11 -0700187 */
gaurav36785932016-03-10 17:24:04 +0530188 private void setUpNetworkConfigService() {
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700189 expect(networkConfigService.getConfig(
190 anyObject(ApplicationId.class), eq(RoutingService.ROUTER_CONFIG_CLASS))).
gaurav36785932016-03-10 17:24:04 +0530191 andReturn(routerConfig);
192 replay(networkConfigService);
193 }
194
195 /**
196 * Sets up FlowObjectiveService.
197 */
198 private void setUpFlowObjectiveService() {
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700199 expect(flowObjectiveService.allocateNextId()).andReturn(NEXT_ID);
gaurav36785932016-03-10 17:24:04 +0530200 replay(flowObjectiveService);
201 }
202
203 /**
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700204 * Creates a next objective with the given parameters.
gaurav36785932016-03-10 17:24:04 +0530205 *
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700206 * @param srcMac source MAC address
207 * @param dstMac destination MAC address
208 * @param port port number
209 * @param vlan vlan ID
210 * @param add whether to create an add objective or remove objective
211 * @return new next objective
gaurav36785932016-03-10 17:24:04 +0530212 */
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700213 private NextObjective createNextObjective(MacAddress srcMac,
214 MacAddress dstMac,
215 PortNumber port,
216 VlanId vlan,
217 boolean add) {
gaurav36785932016-03-10 17:24:04 +0530218 TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder()
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700219 .setEthSrc(srcMac)
220 .setEthDst(dstMac);
gaurav36785932016-03-10 17:24:04 +0530221 TrafficSelector.Builder metabuilder = null;
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700222 if (!vlan.equals(VlanId.NONE)) {
gaurav36785932016-03-10 17:24:04 +0530223 treatment.pushVlan()
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700224 .setVlanId(vlan)
225 .setVlanPcp((byte) 0);
gaurav36785932016-03-10 17:24:04 +0530226 } else {
227 metabuilder = DefaultTrafficSelector.builder();
Jonathan Harte7327042017-02-02 13:11:25 -0800228 metabuilder.matchVlanId(VlanId.vlanId(FibInstaller.ASSIGNED_VLAN));
gaurav36785932016-03-10 17:24:04 +0530229 }
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700230
231 treatment.setOutput(port);
gaurav36785932016-03-10 17:24:04 +0530232 NextObjective.Builder nextBuilder = DefaultNextObjective.builder()
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700233 .withId(NEXT_ID)
gaurav36785932016-03-10 17:24:04 +0530234 .addTreatment(treatment.build())
235 .withType(NextObjective.Type.SIMPLE)
236 .fromApp(APPID);
237 if (metabuilder != null) {
238 nextBuilder.withMeta(metabuilder.build());
239 }
240
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700241 return add ? nextBuilder.add() : nextBuilder.remove();
242 }
gaurav36785932016-03-10 17:24:04 +0530243
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700244 /**
245 * Creates a new forwarding objective with the given parameters.
246 *
247 * @param prefix IP prefix
248 * @param add whether to create an add objective or a remove objective
249 * @return new forwarding objective
250 */
251 private ForwardingObjective createForwardingObjective(IpPrefix prefix,
252 boolean add) {
gaurav36785932016-03-10 17:24:04 +0530253 TrafficSelector selector = DefaultTrafficSelector.builder()
254 .matchEthType(Ethernet.TYPE_IPV4)
255 .matchIPDst(prefix)
256 .build();
257
258 int priority = prefix.prefixLength() * 5 + 100;
259 ForwardingObjective.Builder fwdBuilder = DefaultForwardingObjective.builder()
260 .fromApp(APPID)
261 .makePermanent()
262 .withSelector(selector)
263 .withPriority(priority)
264 .withFlag(ForwardingObjective.Flag.SPECIFIC);
265
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700266 if (add) {
267 fwdBuilder.nextStep(NEXT_ID);
268 } else {
269 fwdBuilder.withTreatment(DefaultTrafficTreatment.builder().build());
270 }
271
272 return add ? fwdBuilder.add() : fwdBuilder.remove();
273 }
274
275 /**
276 * Tests adding a route.
277 *
278 * We verify that the flowObjectiveService records the correct state and that the
279 * correct flow is submitted to the flowObjectiveService.
280 */
281 @Test
282 public void testRouteAdd() {
Charles Chan8fe9f4c2016-10-24 16:46:25 -0700283 ResolvedRoute resolvedRoute = new ResolvedRoute(PREFIX1, NEXT_HOP1, MAC1, SW1_ETH1);
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700284
285 // Create the next objective
286 NextObjective nextObjective = createNextObjective(MAC1, MAC1, SW1_ETH1.port(), VlanId.NONE, true);
287 flowObjectiveService.next(DEVICE_ID, nextObjective);
288
289 // Create the flow objective
290 ForwardingObjective fwd = createForwardingObjective(PREFIX1, true);
291 flowObjectiveService.forward(DEVICE_ID, fwd);
gaurav36785932016-03-10 17:24:04 +0530292 EasyMock.expectLastCall().once();
293 setUpFlowObjectiveService();
294
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700295 // Send in the add event
296 RouteEvent routeEvent = new RouteEvent(RouteEvent.Type.ROUTE_ADDED, resolvedRoute);
297 routeListener.event(routeEvent);
gaurav36785932016-03-10 17:24:04 +0530298 verify(flowObjectiveService);
299 }
300
301 /**
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700302 * Tests adding a route with to a next hop in a VLAN.
gaurav36785932016-03-10 17:24:04 +0530303 *
304 * We verify that the flowObjectiveService records the correct state and that the
305 * correct flowObjectiveService is submitted to the flowObjectiveService.
306 */
307 @Test
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700308 public void testRouteAddWithVlan() {
Charles Chan8fe9f4c2016-10-24 16:46:25 -0700309 ResolvedRoute route = new ResolvedRoute(PREFIX1, NEXT_HOP2, MAC2, SW1_ETH2);
gaurav36785932016-03-10 17:24:04 +0530310
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700311 // Create the next objective
312 NextObjective nextObjective = createNextObjective(MAC2, MAC2, SW1_ETH2.port(), VLAN1, true);
313 flowObjectiveService.next(DEVICE_ID, nextObjective);
gaurav36785932016-03-10 17:24:04 +0530314
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700315 // Create the flow objective
316 ForwardingObjective fwd = createForwardingObjective(PREFIX1, true);
317 flowObjectiveService.forward(DEVICE_ID, fwd);
gaurav36785932016-03-10 17:24:04 +0530318 EasyMock.expectLastCall().once();
319 setUpFlowObjectiveService();
320
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700321 // Send in the add event
322 routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_ADDED, route));
gaurav36785932016-03-10 17:24:04 +0530323
324 verify(flowObjectiveService);
325 }
326
327 /**
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700328 * Tests updating a route.
gaurav36785932016-03-10 17:24:04 +0530329 *
330 * We verify that the flowObjectiveService records the correct state and that the
331 * correct flow is submitted to the flowObjectiveService.
332 */
333 @Test
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700334 public void testRouteUpdate() {
gaurav36785932016-03-10 17:24:04 +0530335 // Firstly add a route
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700336 testRouteAdd();
gaurav36785932016-03-10 17:24:04 +0530337 reset(flowObjectiveService);
gaurav36785932016-03-10 17:24:04 +0530338
Charles Chane4d13102016-11-08 15:38:44 -0800339 ResolvedRoute oldRoute = new ResolvedRoute(PREFIX1, NEXT_HOP1, MAC1, SW1_ETH1);
Charles Chan8fe9f4c2016-10-24 16:46:25 -0700340 ResolvedRoute route = new ResolvedRoute(PREFIX1, NEXT_HOP2, MAC2, SW1_ETH2);
gaurav36785932016-03-10 17:24:04 +0530341
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700342 // Create the next objective
343 NextObjective nextObjective = createNextObjective(MAC2, MAC2, SW1_ETH2.port(), VLAN1, true);
344 flowObjectiveService.next(DEVICE_ID, nextObjective);
gaurav36785932016-03-10 17:24:04 +0530345
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700346 // Create the flow objective
347 ForwardingObjective fwd = createForwardingObjective(PREFIX1, true);
348 flowObjectiveService.forward(DEVICE_ID, fwd);
gaurav36785932016-03-10 17:24:04 +0530349 EasyMock.expectLastCall().once();
350 setUpFlowObjectiveService();
351
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700352 // Send in the update event
Charles Chane4d13102016-11-08 15:38:44 -0800353 routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_UPDATED, route, oldRoute));
gaurav36785932016-03-10 17:24:04 +0530354
355 verify(flowObjectiveService);
356 }
357
Jonathan Hartf04b7d92016-03-29 09:39:11 -0700358 /**
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700359 * Tests deleting a route.
gaurav36785932016-03-10 17:24:04 +0530360 *
361 * We verify that the flowObjectiveService records the correct state and that the
362 * correct flow is withdrawn from the flowObjectiveService.
363 */
gaurav36785932016-03-10 17:24:04 +0530364 @Test
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700365 public void testRouteDelete() {
gaurav36785932016-03-10 17:24:04 +0530366 // Firstly add a route
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700367 testRouteAdd();
gaurav36785932016-03-10 17:24:04 +0530368
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700369 // Construct the existing route
Charles Chane4d13102016-11-08 15:38:44 -0800370 ResolvedRoute route = new ResolvedRoute(PREFIX1, NEXT_HOP1, MAC1, SW1_ETH1);
gaurav36785932016-03-10 17:24:04 +0530371
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700372 // Create the flow objective
gaurav36785932016-03-10 17:24:04 +0530373 reset(flowObjectiveService);
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700374 ForwardingObjective fwd = createForwardingObjective(PREFIX1, false);
375 flowObjectiveService.forward(DEVICE_ID, fwd);
gaurav36785932016-03-10 17:24:04 +0530376 replay(flowObjectiveService);
377
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700378 // Send in the delete event
379 routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_REMOVED, route));
gaurav36785932016-03-10 17:24:04 +0530380
381 verify(flowObjectiveService);
382 }
383
gaurav164cf6d2016-03-25 21:43:04 +0530384 private class TestInterfaceService extends InterfaceServiceAdapter {
gaurav164cf6d2016-03-25 21:43:04 +0530385 @Override
386 public void addListener(InterfaceListener listener) {
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700387 interfaceListener = listener;
gaurav164cf6d2016-03-25 21:43:04 +0530388 }
389 }
390
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700391 private class TestRouteService extends RouteServiceAdapter {
gaurav36785932016-03-10 17:24:04 +0530392 @Override
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700393 public void addListener(RouteListener listener) {
Jonathan Harte7327042017-02-02 13:11:25 -0800394 FibInstallerTest.this.routeListener = listener;
gaurav36785932016-03-10 17:24:04 +0530395 }
396 }
397
398 private class TestRouterConfig extends RouterConfig {
399
400 @Override
401 public List<String> getInterfaces() {
402 ArrayList<String> interfaces = new ArrayList<>();
403 interfaces.add("of:0000000000000001/1");
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700404 interfaces.add("of:0000000000000001/2");
gaurav36785932016-03-10 17:24:04 +0530405 return interfaces;
406 }
407
408 @Override
409 public ConnectPoint getControlPlaneConnectPoint() {
410 return SW1_ETH1;
411 }
412
413 @Override
414 public boolean getOspfEnabled() {
415 return true;
416 }
417 }
418
419 private class TestDeviceService extends DeviceServiceAdapter {
420
421 @Override
422 public boolean isAvailable(DeviceId deviceId) {
423 return true;
424 }
425
426 @Override
427 public void addListener(DeviceListener listener) {
Jonathan Harte7327042017-02-02 13:11:25 -0800428 FibInstallerTest.this.deviceListener = listener;
gaurav36785932016-03-10 17:24:04 +0530429 }
430 }
431}