blob: 1e6efb53b736d3e8abb3f9c65b504f6b9ed67e69 [file] [log] [blame]
gaurav36785932016-03-10 17:24:04 +05301/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-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 */
16package org.onosproject.routing.impl;
17
Jonathan Hartf04b7d92016-03-29 09:39:11 -070018import com.google.common.collect.Sets;
gaurav36785932016-03-10 17:24:04 +053019import org.easymock.EasyMock;
20import org.junit.Before;
21import org.junit.Test;
22import org.onlab.packet.Ethernet;
gaurav36785932016-03-10 17:24:04 +053023import org.onlab.packet.Ip4Prefix;
24import org.onlab.packet.IpAddress;
25import org.onlab.packet.IpPrefix;
26import org.onlab.packet.MacAddress;
27import org.onlab.packet.VlanId;
28import org.onosproject.TestApplicationId;
gaurava2e61a52016-05-05 03:39:31 +053029import org.onosproject.app.ApplicationService;
Jonathan Hartf04b7d92016-03-29 09:39:11 -070030import org.onosproject.cfg.ComponentConfigService;
gaurav36785932016-03-10 17:24:04 +053031import org.onosproject.core.ApplicationId;
32import org.onosproject.core.CoreService;
gaurav36785932016-03-10 17:24:04 +053033import org.onosproject.incubator.net.intf.Interface;
gaurav164cf6d2016-03-25 21:43:04 +053034import org.onosproject.incubator.net.intf.InterfaceListener;
gaurav36785932016-03-10 17:24:04 +053035import org.onosproject.incubator.net.intf.InterfaceService;
gaurav164cf6d2016-03-25 21:43:04 +053036import org.onosproject.incubator.net.intf.InterfaceServiceAdapter;
Jonathan Harta2eb9ff2016-04-13 21:27:06 -070037import org.onosproject.incubator.net.routing.ResolvedRoute;
38import org.onosproject.incubator.net.routing.RouteEvent;
39import org.onosproject.incubator.net.routing.RouteListener;
40import org.onosproject.incubator.net.routing.RouteServiceAdapter;
gaurav36785932016-03-10 17:24:04 +053041import org.onosproject.net.ConnectPoint;
42import org.onosproject.net.DeviceId;
43import org.onosproject.net.PortNumber;
Jonathan Hart25bd6682016-06-03 10:45:47 -070044import org.onosproject.net.config.NetworkConfigListener;
Charles Chand55e84d2016-03-30 17:54:24 -070045import org.onosproject.net.config.NetworkConfigRegistry;
gaurav36785932016-03-10 17:24:04 +053046import org.onosproject.net.config.NetworkConfigService;
47import org.onosproject.net.device.DeviceListener;
48import org.onosproject.net.device.DeviceService;
49import org.onosproject.net.device.DeviceServiceAdapter;
50import org.onosproject.net.flow.DefaultTrafficSelector;
51import org.onosproject.net.flow.DefaultTrafficTreatment;
52import org.onosproject.net.flow.TrafficSelector;
53import org.onosproject.net.flow.TrafficTreatment;
54import org.onosproject.net.flowobjective.DefaultForwardingObjective;
55import org.onosproject.net.flowobjective.DefaultNextObjective;
56import org.onosproject.net.flowobjective.FlowObjectiveService;
57import org.onosproject.net.flowobjective.ForwardingObjective;
58import org.onosproject.net.flowobjective.NextObjective;
59import org.onosproject.net.host.InterfaceIpAddress;
gaurav36785932016-03-10 17:24:04 +053060import org.onosproject.routing.RoutingService;
gaurav36785932016-03-10 17:24:04 +053061import org.onosproject.routing.config.RouterConfig;
Jonathan Hartf04b7d92016-03-29 09:39:11 -070062import org.osgi.service.component.ComponentContext;
63
64import java.util.ArrayList;
65import java.util.Collections;
Jonathan Hartf04b7d92016-03-29 09:39:11 -070066import java.util.List;
67import java.util.Set;
68
69import static org.easymock.EasyMock.anyObject;
Jonathan Harta2eb9ff2016-04-13 21:27:06 -070070import static org.easymock.EasyMock.anyString;
Jonathan Hartf04b7d92016-03-29 09:39:11 -070071import static org.easymock.EasyMock.createMock;
Jonathan Harta2eb9ff2016-04-13 21:27:06 -070072import static org.easymock.EasyMock.createNiceMock;
73import static org.easymock.EasyMock.eq;
Jonathan Hartf04b7d92016-03-29 09:39:11 -070074import static org.easymock.EasyMock.expect;
Jonathan Harta2eb9ff2016-04-13 21:27:06 -070075import static org.easymock.EasyMock.expectLastCall;
Jonathan Hartf04b7d92016-03-29 09:39:11 -070076import static org.easymock.EasyMock.replay;
77import static org.easymock.EasyMock.reset;
78import static org.easymock.EasyMock.verify;
gaurav36785932016-03-10 17:24:04 +053079
80/**
81 * Unit tests for SingleSwitchFibInstaller.
82 */
Jonathan Harta2eb9ff2016-04-13 21:27:06 -070083public class SingleSwitchFibInstallerTest {
gaurav36785932016-03-10 17:24:04 +053084
Jonathan Harta2eb9ff2016-04-13 21:27:06 -070085 private static final DeviceId DEVICE_ID = DeviceId.deviceId("of:0000000000000001");
86
gaurav36785932016-03-10 17:24:04 +053087 private static final ConnectPoint SW1_ETH1 = new ConnectPoint(
Jonathan Harta2eb9ff2016-04-13 21:27:06 -070088 DEVICE_ID, PortNumber.portNumber(1));
gaurav36785932016-03-10 17:24:04 +053089
Jonathan Harta2eb9ff2016-04-13 21:27:06 -070090 private static final ConnectPoint SW1_ETH2 = new ConnectPoint(
91 DEVICE_ID, PortNumber.portNumber(2));
gaurav36785932016-03-10 17:24:04 +053092
Jonathan Harta2eb9ff2016-04-13 21:27:06 -070093 private static final int NEXT_ID = 11;
gaurav36785932016-03-10 17:24:04 +053094
Jonathan Harta2eb9ff2016-04-13 21:27:06 -070095 private static final VlanId VLAN1 = VlanId.vlanId((short) 1);
96 private static final MacAddress MAC1 = MacAddress.valueOf("00:00:00:00:00:01");
97 private static final MacAddress MAC2 = MacAddress.valueOf("00:00:00:00:00:02");
gaurav36785932016-03-10 17:24:04 +053098
Jonathan Harta2eb9ff2016-04-13 21:27:06 -070099 private static final IpPrefix PREFIX1 = Ip4Prefix.valueOf("1.1.1.0/24");
100 private static final IpAddress NEXT_HOP1 = IpAddress.valueOf("192.168.10.1");
101 private static final IpAddress NEXT_HOP2 = IpAddress.valueOf("192.168.20.1");
102 private static final InterfaceIpAddress INTF1 =
103 InterfaceIpAddress.valueOf("192.168.10.2/24");
104 private static final InterfaceIpAddress INTF2 =
105 InterfaceIpAddress.valueOf("192.168.20.2/24");
106
gaurav36785932016-03-10 17:24:04 +0530107 private final Set<Interface> interfaces = Sets.newHashSet();
108 private InterfaceService interfaceService;
109 private NetworkConfigService networkConfigService;
Charles Chand55e84d2016-03-30 17:54:24 -0700110 private NetworkConfigRegistry networkConfigRegistry;
gaurav36785932016-03-10 17:24:04 +0530111 private FlowObjectiveService flowObjectiveService;
gaurava2e61a52016-05-05 03:39:31 +0530112 private ApplicationService applicationService;
gaurav36785932016-03-10 17:24:04 +0530113 private DeviceService deviceService;
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700114 private static final ApplicationId APPID = TestApplicationId.create("foo");
115
116 private RouteListener routeListener;
gaurav36785932016-03-10 17:24:04 +0530117 private DeviceListener deviceListener;
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700118
gaurav36785932016-03-10 17:24:04 +0530119 private RouterConfig routerConfig;
gaurav164cf6d2016-03-25 21:43:04 +0530120 private SingleSwitchFibInstaller sSfibInstaller;
121 private InterfaceListener interfaceListener;
gaurav36785932016-03-10 17:24:04 +0530122
123 @Before
124 public void setUp() throws Exception {
gaurav36785932016-03-10 17:24:04 +0530125 sSfibInstaller = new SingleSwitchFibInstaller();
126
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700127 sSfibInstaller.componentConfigService = createNiceMock(ComponentConfigService.class);
gaurav36785932016-03-10 17:24:04 +0530128
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700129 ComponentContext mockContext = createNiceMock(ComponentContext.class);
gaurav36785932016-03-10 17:24:04 +0530130
gaurav36785932016-03-10 17:24:04 +0530131 routerConfig = new TestRouterConfig();
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700132 interfaceService = createMock(InterfaceService.class);
133
gaurav36785932016-03-10 17:24:04 +0530134 networkConfigService = createMock(NetworkConfigService.class);
Jonathan Hart25bd6682016-06-03 10:45:47 -0700135 networkConfigService.addListener(anyObject(NetworkConfigListener.class));
136 expectLastCall().anyTimes();
Charles Chand55e84d2016-03-30 17:54:24 -0700137 networkConfigRegistry = createMock(NetworkConfigRegistry.class);
gaurav36785932016-03-10 17:24:04 +0530138 flowObjectiveService = createMock(FlowObjectiveService.class);
gaurava2e61a52016-05-05 03:39:31 +0530139 applicationService = createNiceMock(ApplicationService.class);
140 replay(applicationService);
gaurav36785932016-03-10 17:24:04 +0530141 deviceService = new TestDeviceService();
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700142 CoreService coreService = createNiceMock(CoreService.class);
Charles Chand55e84d2016-03-30 17:54:24 -0700143 expect(coreService.registerApplication(anyString())).andReturn(APPID).anyTimes();
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700144 replay(coreService);
gaurav36785932016-03-10 17:24:04 +0530145
146 sSfibInstaller.networkConfigService = networkConfigService;
Charles Chand55e84d2016-03-30 17:54:24 -0700147 sSfibInstaller.networkConfigRegistry = networkConfigRegistry;
gaurav36785932016-03-10 17:24:04 +0530148 sSfibInstaller.interfaceService = interfaceService;
149 sSfibInstaller.flowObjectiveService = flowObjectiveService;
gaurava2e61a52016-05-05 03:39:31 +0530150 sSfibInstaller.applicationService = applicationService;
gaurav36785932016-03-10 17:24:04 +0530151 sSfibInstaller.coreService = coreService;
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700152 sSfibInstaller.routeService = new TestRouteService();
gaurav36785932016-03-10 17:24:04 +0530153 sSfibInstaller.deviceService = deviceService;
154
155 setUpNetworkConfigService();
156 setUpInterfaceService();
157 sSfibInstaller.activate(mockContext);
158 }
159
160 /**
161 * Sets up InterfaceService.
162 */
163 private void setUpInterfaceService() {
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700164 interfaceService.addListener(anyObject(InterfaceListener.class));
165 expectLastCall().andDelegateTo(new TestInterfaceService());
166
167 // Interface with no VLAN
168 Interface sw1Eth1 = new Interface("intf1", SW1_ETH1,
169 Collections.singletonList(INTF1), MAC1, VlanId.NONE);
170 expect(interfaceService.getMatchingInterface(NEXT_HOP1)).andReturn(sw1Eth1);
gaurav36785932016-03-10 17:24:04 +0530171 interfaces.add(sw1Eth1);
172
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700173 // Interface with a VLAN
174 Interface sw2Eth1 = new Interface("intf2", SW1_ETH2,
175 Collections.singletonList(INTF2), MAC2, VLAN1);
176 expect(interfaceService.getMatchingInterface(NEXT_HOP2)).andReturn(sw2Eth1);
gaurav36785932016-03-10 17:24:04 +0530177 interfaces.add(sw2Eth1);
178
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700179 expect(interfaceService.getInterfaces()).andReturn(interfaces);
gaurav36785932016-03-10 17:24:04 +0530180
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700181 replay(interfaceService);
gaurav36785932016-03-10 17:24:04 +0530182 }
183
184 /*
185 * Sets up NetworkConfigService.
Jonathan Hartf04b7d92016-03-29 09:39:11 -0700186 */
gaurav36785932016-03-10 17:24:04 +0530187 private void setUpNetworkConfigService() {
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700188 expect(networkConfigService.getConfig(
189 anyObject(ApplicationId.class), eq(RoutingService.ROUTER_CONFIG_CLASS))).
gaurav36785932016-03-10 17:24:04 +0530190 andReturn(routerConfig);
191 replay(networkConfigService);
192 }
193
194 /**
195 * Sets up FlowObjectiveService.
196 */
197 private void setUpFlowObjectiveService() {
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700198 expect(flowObjectiveService.allocateNextId()).andReturn(NEXT_ID);
gaurav36785932016-03-10 17:24:04 +0530199 replay(flowObjectiveService);
200 }
201
202 /**
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700203 * Creates a next objective with the given parameters.
gaurav36785932016-03-10 17:24:04 +0530204 *
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700205 * @param srcMac source MAC address
206 * @param dstMac destination MAC address
207 * @param port port number
208 * @param vlan vlan ID
209 * @param add whether to create an add objective or remove objective
210 * @return new next objective
gaurav36785932016-03-10 17:24:04 +0530211 */
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700212 private NextObjective createNextObjective(MacAddress srcMac,
213 MacAddress dstMac,
214 PortNumber port,
215 VlanId vlan,
216 boolean add) {
gaurav36785932016-03-10 17:24:04 +0530217 TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder()
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700218 .setEthSrc(srcMac)
219 .setEthDst(dstMac);
gaurav36785932016-03-10 17:24:04 +0530220 TrafficSelector.Builder metabuilder = null;
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700221 if (!vlan.equals(VlanId.NONE)) {
gaurav36785932016-03-10 17:24:04 +0530222 treatment.pushVlan()
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700223 .setVlanId(vlan)
224 .setVlanPcp((byte) 0);
gaurav36785932016-03-10 17:24:04 +0530225 } else {
226 metabuilder = DefaultTrafficSelector.builder();
227 metabuilder.matchVlanId(VlanId.vlanId(SingleSwitchFibInstaller.ASSIGNED_VLAN));
228 }
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700229
230 treatment.setOutput(port);
gaurav36785932016-03-10 17:24:04 +0530231 NextObjective.Builder nextBuilder = DefaultNextObjective.builder()
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700232 .withId(NEXT_ID)
gaurav36785932016-03-10 17:24:04 +0530233 .addTreatment(treatment.build())
234 .withType(NextObjective.Type.SIMPLE)
235 .fromApp(APPID);
236 if (metabuilder != null) {
237 nextBuilder.withMeta(metabuilder.build());
238 }
239
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700240 return add ? nextBuilder.add() : nextBuilder.remove();
241 }
gaurav36785932016-03-10 17:24:04 +0530242
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700243 /**
244 * Creates a new forwarding objective with the given parameters.
245 *
246 * @param prefix IP prefix
247 * @param add whether to create an add objective or a remove objective
248 * @return new forwarding objective
249 */
250 private ForwardingObjective createForwardingObjective(IpPrefix prefix,
251 boolean add) {
gaurav36785932016-03-10 17:24:04 +0530252 TrafficSelector selector = DefaultTrafficSelector.builder()
253 .matchEthType(Ethernet.TYPE_IPV4)
254 .matchIPDst(prefix)
255 .build();
256
257 int priority = prefix.prefixLength() * 5 + 100;
258 ForwardingObjective.Builder fwdBuilder = DefaultForwardingObjective.builder()
259 .fromApp(APPID)
260 .makePermanent()
261 .withSelector(selector)
262 .withPriority(priority)
263 .withFlag(ForwardingObjective.Flag.SPECIFIC);
264
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700265 if (add) {
266 fwdBuilder.nextStep(NEXT_ID);
267 } else {
268 fwdBuilder.withTreatment(DefaultTrafficTreatment.builder().build());
269 }
270
271 return add ? fwdBuilder.add() : fwdBuilder.remove();
272 }
273
274 /**
275 * Tests adding a route.
276 *
277 * We verify that the flowObjectiveService records the correct state and that the
278 * correct flow is submitted to the flowObjectiveService.
279 */
280 @Test
281 public void testRouteAdd() {
Charles Chan8fe9f4c2016-10-24 16:46:25 -0700282 ResolvedRoute resolvedRoute = new ResolvedRoute(PREFIX1, NEXT_HOP1, MAC1, SW1_ETH1);
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700283
284 // Create the next objective
285 NextObjective nextObjective = createNextObjective(MAC1, MAC1, SW1_ETH1.port(), VlanId.NONE, true);
286 flowObjectiveService.next(DEVICE_ID, nextObjective);
287
288 // Create the flow objective
289 ForwardingObjective fwd = createForwardingObjective(PREFIX1, true);
290 flowObjectiveService.forward(DEVICE_ID, fwd);
gaurav36785932016-03-10 17:24:04 +0530291 EasyMock.expectLastCall().once();
292 setUpFlowObjectiveService();
293
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700294 // Send in the add event
295 RouteEvent routeEvent = new RouteEvent(RouteEvent.Type.ROUTE_ADDED, resolvedRoute);
296 routeListener.event(routeEvent);
gaurav36785932016-03-10 17:24:04 +0530297 verify(flowObjectiveService);
298 }
299
300 /**
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700301 * Tests adding a route with to a next hop in a VLAN.
gaurav36785932016-03-10 17:24:04 +0530302 *
303 * We verify that the flowObjectiveService records the correct state and that the
304 * correct flowObjectiveService is submitted to the flowObjectiveService.
305 */
306 @Test
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700307 public void testRouteAddWithVlan() {
Charles Chan8fe9f4c2016-10-24 16:46:25 -0700308 ResolvedRoute route = new ResolvedRoute(PREFIX1, NEXT_HOP2, MAC2, SW1_ETH2);
gaurav36785932016-03-10 17:24:04 +0530309
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700310 // Create the next objective
311 NextObjective nextObjective = createNextObjective(MAC2, MAC2, SW1_ETH2.port(), VLAN1, true);
312 flowObjectiveService.next(DEVICE_ID, nextObjective);
gaurav36785932016-03-10 17:24:04 +0530313
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700314 // Create the flow objective
315 ForwardingObjective fwd = createForwardingObjective(PREFIX1, true);
316 flowObjectiveService.forward(DEVICE_ID, fwd);
gaurav36785932016-03-10 17:24:04 +0530317 EasyMock.expectLastCall().once();
318 setUpFlowObjectiveService();
319
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700320 // Send in the add event
321 routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_ADDED, route));
gaurav36785932016-03-10 17:24:04 +0530322
323 verify(flowObjectiveService);
324 }
325
326 /**
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700327 * Tests updating a route.
gaurav36785932016-03-10 17:24:04 +0530328 *
329 * We verify that the flowObjectiveService records the correct state and that the
330 * correct flow is submitted to the flowObjectiveService.
331 */
332 @Test
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700333 public void testRouteUpdate() {
gaurav36785932016-03-10 17:24:04 +0530334 // Firstly add a route
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700335 testRouteAdd();
gaurav36785932016-03-10 17:24:04 +0530336 reset(flowObjectiveService);
gaurav36785932016-03-10 17:24:04 +0530337
Charles Chane4d13102016-11-08 15:38:44 -0800338 ResolvedRoute oldRoute = new ResolvedRoute(PREFIX1, NEXT_HOP1, MAC1, SW1_ETH1);
Charles Chan8fe9f4c2016-10-24 16:46:25 -0700339 ResolvedRoute route = new ResolvedRoute(PREFIX1, NEXT_HOP2, MAC2, SW1_ETH2);
gaurav36785932016-03-10 17:24:04 +0530340
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700341 // Create the next objective
342 NextObjective nextObjective = createNextObjective(MAC2, MAC2, SW1_ETH2.port(), VLAN1, true);
343 flowObjectiveService.next(DEVICE_ID, nextObjective);
gaurav36785932016-03-10 17:24:04 +0530344
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700345 // Create the flow objective
346 ForwardingObjective fwd = createForwardingObjective(PREFIX1, true);
347 flowObjectiveService.forward(DEVICE_ID, fwd);
gaurav36785932016-03-10 17:24:04 +0530348 EasyMock.expectLastCall().once();
349 setUpFlowObjectiveService();
350
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700351 // Send in the update event
Charles Chane4d13102016-11-08 15:38:44 -0800352 routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_UPDATED, route, oldRoute));
gaurav36785932016-03-10 17:24:04 +0530353
354 verify(flowObjectiveService);
355 }
356
Jonathan Hartf04b7d92016-03-29 09:39:11 -0700357 /**
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700358 * Tests deleting a route.
gaurav36785932016-03-10 17:24:04 +0530359 *
360 * We verify that the flowObjectiveService records the correct state and that the
361 * correct flow is withdrawn from the flowObjectiveService.
362 */
gaurav36785932016-03-10 17:24:04 +0530363 @Test
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700364 public void testRouteDelete() {
gaurav36785932016-03-10 17:24:04 +0530365 // Firstly add a route
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700366 testRouteAdd();
gaurav36785932016-03-10 17:24:04 +0530367
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700368 // Construct the existing route
Charles Chane4d13102016-11-08 15:38:44 -0800369 ResolvedRoute route = new ResolvedRoute(PREFIX1, NEXT_HOP1, MAC1, SW1_ETH1);
gaurav36785932016-03-10 17:24:04 +0530370
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700371 // Create the flow objective
gaurav36785932016-03-10 17:24:04 +0530372 reset(flowObjectiveService);
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700373 ForwardingObjective fwd = createForwardingObjective(PREFIX1, false);
374 flowObjectiveService.forward(DEVICE_ID, fwd);
gaurav36785932016-03-10 17:24:04 +0530375 replay(flowObjectiveService);
376
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700377 // Send in the delete event
378 routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_REMOVED, route));
gaurav36785932016-03-10 17:24:04 +0530379
380 verify(flowObjectiveService);
381 }
382
gaurav164cf6d2016-03-25 21:43:04 +0530383 private class TestInterfaceService extends InterfaceServiceAdapter {
gaurav164cf6d2016-03-25 21:43:04 +0530384 @Override
385 public void addListener(InterfaceListener listener) {
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700386 interfaceListener = listener;
gaurav164cf6d2016-03-25 21:43:04 +0530387 }
388 }
389
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700390 private class TestRouteService extends RouteServiceAdapter {
gaurav36785932016-03-10 17:24:04 +0530391 @Override
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700392 public void addListener(RouteListener listener) {
393 SingleSwitchFibInstallerTest.this.routeListener = listener;
gaurav36785932016-03-10 17:24:04 +0530394 }
395 }
396
397 private class TestRouterConfig extends RouterConfig {
398
399 @Override
400 public List<String> getInterfaces() {
401 ArrayList<String> interfaces = new ArrayList<>();
402 interfaces.add("of:0000000000000001/1");
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700403 interfaces.add("of:0000000000000001/2");
gaurav36785932016-03-10 17:24:04 +0530404 return interfaces;
405 }
406
407 @Override
408 public ConnectPoint getControlPlaneConnectPoint() {
409 return SW1_ETH1;
410 }
411
412 @Override
413 public boolean getOspfEnabled() {
414 return true;
415 }
416 }
417
418 private class TestDeviceService extends DeviceServiceAdapter {
419
420 @Override
421 public boolean isAvailable(DeviceId deviceId) {
422 return true;
423 }
424
425 @Override
426 public void addListener(DeviceListener listener) {
427 SingleSwitchFibInstallerTest.this.deviceListener = listener;
428 }
429 }
430}