blob: fabc94bad4fc2dfcc3c810099b3abf3ce587e2d3 [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 Hart249b4cf2017-02-03 18:02:58 -080063import org.onosproject.routing.config.RoutersConfig;
Jonathan Hartf04b7d92016-03-29 09:39:11 -070064import org.osgi.service.component.ComponentContext;
65
66import java.util.ArrayList;
67import java.util.Collections;
Jonathan Hartf04b7d92016-03-29 09:39:11 -070068import java.util.List;
69import java.util.Set;
70
71import static org.easymock.EasyMock.anyObject;
Jonathan Harta2eb9ff2016-04-13 21:27:06 -070072import static org.easymock.EasyMock.anyString;
Jonathan Hartf04b7d92016-03-29 09:39:11 -070073import static org.easymock.EasyMock.createMock;
Jonathan Harta2eb9ff2016-04-13 21:27:06 -070074import static org.easymock.EasyMock.createNiceMock;
75import static org.easymock.EasyMock.eq;
Jonathan Hartf04b7d92016-03-29 09:39:11 -070076import static org.easymock.EasyMock.expect;
Jonathan Harta2eb9ff2016-04-13 21:27:06 -070077import static org.easymock.EasyMock.expectLastCall;
Jonathan Hartf04b7d92016-03-29 09:39:11 -070078import static org.easymock.EasyMock.replay;
79import static org.easymock.EasyMock.reset;
80import static org.easymock.EasyMock.verify;
gaurav36785932016-03-10 17:24:04 +053081
82/**
83 * Unit tests for SingleSwitchFibInstaller.
84 */
Jonathan Harte7327042017-02-02 13:11:25 -080085public class FibInstallerTest {
gaurav36785932016-03-10 17:24:04 +053086
Jonathan Harta2eb9ff2016-04-13 21:27:06 -070087 private static final DeviceId DEVICE_ID = DeviceId.deviceId("of:0000000000000001");
88
gaurav36785932016-03-10 17:24:04 +053089 private static final ConnectPoint SW1_ETH1 = new ConnectPoint(
Jonathan Harta2eb9ff2016-04-13 21:27:06 -070090 DEVICE_ID, PortNumber.portNumber(1));
gaurav36785932016-03-10 17:24:04 +053091
Jonathan Harta2eb9ff2016-04-13 21:27:06 -070092 private static final ConnectPoint SW1_ETH2 = new ConnectPoint(
93 DEVICE_ID, PortNumber.portNumber(2));
gaurav36785932016-03-10 17:24:04 +053094
Jonathan Harta2eb9ff2016-04-13 21:27:06 -070095 private static final int NEXT_ID = 11;
gaurav36785932016-03-10 17:24:04 +053096
Jonathan Harta2eb9ff2016-04-13 21:27:06 -070097 private static final VlanId VLAN1 = VlanId.vlanId((short) 1);
98 private static final MacAddress MAC1 = MacAddress.valueOf("00:00:00:00:00:01");
99 private static final MacAddress MAC2 = MacAddress.valueOf("00:00:00:00:00:02");
gaurav36785932016-03-10 17:24:04 +0530100
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700101 private static final IpPrefix PREFIX1 = Ip4Prefix.valueOf("1.1.1.0/24");
102 private static final IpAddress NEXT_HOP1 = IpAddress.valueOf("192.168.10.1");
103 private static final IpAddress NEXT_HOP2 = IpAddress.valueOf("192.168.20.1");
104 private static final InterfaceIpAddress INTF1 =
105 InterfaceIpAddress.valueOf("192.168.10.2/24");
106 private static final InterfaceIpAddress INTF2 =
107 InterfaceIpAddress.valueOf("192.168.20.2/24");
108
gaurav36785932016-03-10 17:24:04 +0530109 private final Set<Interface> interfaces = Sets.newHashSet();
110 private InterfaceService interfaceService;
111 private NetworkConfigService networkConfigService;
Charles Chand55e84d2016-03-30 17:54:24 -0700112 private NetworkConfigRegistry networkConfigRegistry;
gaurav36785932016-03-10 17:24:04 +0530113 private FlowObjectiveService flowObjectiveService;
gaurava2e61a52016-05-05 03:39:31 +0530114 private ApplicationService applicationService;
gaurav36785932016-03-10 17:24:04 +0530115 private DeviceService deviceService;
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700116 private static final ApplicationId APPID = TestApplicationId.create("foo");
117
118 private RouteListener routeListener;
gaurav36785932016-03-10 17:24:04 +0530119 private DeviceListener deviceListener;
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700120
gaurav36785932016-03-10 17:24:04 +0530121 private RouterConfig routerConfig;
Jonathan Harte7327042017-02-02 13:11:25 -0800122 private FibInstaller sSfibInstaller;
gaurav164cf6d2016-03-25 21:43:04 +0530123 private InterfaceListener interfaceListener;
gaurav36785932016-03-10 17:24:04 +0530124
125 @Before
126 public void setUp() throws Exception {
Jonathan Harte7327042017-02-02 13:11:25 -0800127 sSfibInstaller = new FibInstaller();
gaurav36785932016-03-10 17:24:04 +0530128
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700129 sSfibInstaller.componentConfigService = createNiceMock(ComponentConfigService.class);
gaurav36785932016-03-10 17:24:04 +0530130
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700131 ComponentContext mockContext = createNiceMock(ComponentContext.class);
gaurav36785932016-03-10 17:24:04 +0530132
gaurav36785932016-03-10 17:24:04 +0530133 routerConfig = new TestRouterConfig();
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700134 interfaceService = createMock(InterfaceService.class);
135
gaurav36785932016-03-10 17:24:04 +0530136 networkConfigService = createMock(NetworkConfigService.class);
Jonathan Hart25bd6682016-06-03 10:45:47 -0700137 networkConfigService.addListener(anyObject(NetworkConfigListener.class));
138 expectLastCall().anyTimes();
Charles Chand55e84d2016-03-30 17:54:24 -0700139 networkConfigRegistry = createMock(NetworkConfigRegistry.class);
gaurav36785932016-03-10 17:24:04 +0530140 flowObjectiveService = createMock(FlowObjectiveService.class);
gaurava2e61a52016-05-05 03:39:31 +0530141 applicationService = createNiceMock(ApplicationService.class);
142 replay(applicationService);
gaurav36785932016-03-10 17:24:04 +0530143 deviceService = new TestDeviceService();
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700144 CoreService coreService = createNiceMock(CoreService.class);
Charles Chand55e84d2016-03-30 17:54:24 -0700145 expect(coreService.registerApplication(anyString())).andReturn(APPID).anyTimes();
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700146 replay(coreService);
gaurav36785932016-03-10 17:24:04 +0530147
148 sSfibInstaller.networkConfigService = networkConfigService;
Charles Chand55e84d2016-03-30 17:54:24 -0700149 sSfibInstaller.networkConfigRegistry = networkConfigRegistry;
gaurav36785932016-03-10 17:24:04 +0530150 sSfibInstaller.interfaceService = interfaceService;
151 sSfibInstaller.flowObjectiveService = flowObjectiveService;
gaurava2e61a52016-05-05 03:39:31 +0530152 sSfibInstaller.applicationService = applicationService;
gaurav36785932016-03-10 17:24:04 +0530153 sSfibInstaller.coreService = coreService;
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700154 sSfibInstaller.routeService = new TestRouteService();
gaurav36785932016-03-10 17:24:04 +0530155 sSfibInstaller.deviceService = deviceService;
156
157 setUpNetworkConfigService();
158 setUpInterfaceService();
159 sSfibInstaller.activate(mockContext);
160 }
161
162 /**
163 * Sets up InterfaceService.
164 */
165 private void setUpInterfaceService() {
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700166 interfaceService.addListener(anyObject(InterfaceListener.class));
167 expectLastCall().andDelegateTo(new TestInterfaceService());
168
169 // Interface with no VLAN
170 Interface sw1Eth1 = new Interface("intf1", SW1_ETH1,
171 Collections.singletonList(INTF1), MAC1, VlanId.NONE);
172 expect(interfaceService.getMatchingInterface(NEXT_HOP1)).andReturn(sw1Eth1);
gaurav36785932016-03-10 17:24:04 +0530173 interfaces.add(sw1Eth1);
174
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700175 // Interface with a VLAN
176 Interface sw2Eth1 = new Interface("intf2", SW1_ETH2,
177 Collections.singletonList(INTF2), MAC2, VLAN1);
178 expect(interfaceService.getMatchingInterface(NEXT_HOP2)).andReturn(sw2Eth1);
gaurav36785932016-03-10 17:24:04 +0530179 interfaces.add(sw2Eth1);
180
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700181 expect(interfaceService.getInterfaces()).andReturn(interfaces);
gaurav36785932016-03-10 17:24:04 +0530182
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700183 replay(interfaceService);
gaurav36785932016-03-10 17:24:04 +0530184 }
185
186 /*
187 * Sets up NetworkConfigService.
Jonathan Hartf04b7d92016-03-29 09:39:11 -0700188 */
gaurav36785932016-03-10 17:24:04 +0530189 private void setUpNetworkConfigService() {
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700190 expect(networkConfigService.getConfig(
191 anyObject(ApplicationId.class), eq(RoutingService.ROUTER_CONFIG_CLASS))).
gaurav36785932016-03-10 17:24:04 +0530192 andReturn(routerConfig);
Jonathan Hart249b4cf2017-02-03 18:02:58 -0800193 expect(networkConfigService.getConfig(anyObject(ApplicationId.class), eq(RoutersConfig.class)))
194 .andReturn(null);
gaurav36785932016-03-10 17:24:04 +0530195 replay(networkConfigService);
196 }
197
198 /**
199 * Sets up FlowObjectiveService.
200 */
201 private void setUpFlowObjectiveService() {
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700202 expect(flowObjectiveService.allocateNextId()).andReturn(NEXT_ID);
gaurav36785932016-03-10 17:24:04 +0530203 replay(flowObjectiveService);
204 }
205
206 /**
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700207 * Creates a next objective with the given parameters.
gaurav36785932016-03-10 17:24:04 +0530208 *
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700209 * @param srcMac source MAC address
210 * @param dstMac destination MAC address
211 * @param port port number
212 * @param vlan vlan ID
213 * @param add whether to create an add objective or remove objective
214 * @return new next objective
gaurav36785932016-03-10 17:24:04 +0530215 */
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700216 private NextObjective createNextObjective(MacAddress srcMac,
217 MacAddress dstMac,
218 PortNumber port,
219 VlanId vlan,
220 boolean add) {
gaurav36785932016-03-10 17:24:04 +0530221 TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder()
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700222 .setEthSrc(srcMac)
223 .setEthDst(dstMac);
gaurav36785932016-03-10 17:24:04 +0530224 TrafficSelector.Builder metabuilder = null;
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700225 if (!vlan.equals(VlanId.NONE)) {
gaurav36785932016-03-10 17:24:04 +0530226 treatment.pushVlan()
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700227 .setVlanId(vlan)
228 .setVlanPcp((byte) 0);
gaurav36785932016-03-10 17:24:04 +0530229 } else {
230 metabuilder = DefaultTrafficSelector.builder();
Jonathan Harte7327042017-02-02 13:11:25 -0800231 metabuilder.matchVlanId(VlanId.vlanId(FibInstaller.ASSIGNED_VLAN));
gaurav36785932016-03-10 17:24:04 +0530232 }
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700233
234 treatment.setOutput(port);
gaurav36785932016-03-10 17:24:04 +0530235 NextObjective.Builder nextBuilder = DefaultNextObjective.builder()
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700236 .withId(NEXT_ID)
gaurav36785932016-03-10 17:24:04 +0530237 .addTreatment(treatment.build())
238 .withType(NextObjective.Type.SIMPLE)
239 .fromApp(APPID);
240 if (metabuilder != null) {
241 nextBuilder.withMeta(metabuilder.build());
242 }
243
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700244 return add ? nextBuilder.add() : nextBuilder.remove();
245 }
gaurav36785932016-03-10 17:24:04 +0530246
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700247 /**
248 * Creates a new forwarding objective with the given parameters.
249 *
250 * @param prefix IP prefix
251 * @param add whether to create an add objective or a remove objective
252 * @return new forwarding objective
253 */
254 private ForwardingObjective createForwardingObjective(IpPrefix prefix,
255 boolean add) {
gaurav36785932016-03-10 17:24:04 +0530256 TrafficSelector selector = DefaultTrafficSelector.builder()
257 .matchEthType(Ethernet.TYPE_IPV4)
258 .matchIPDst(prefix)
259 .build();
260
261 int priority = prefix.prefixLength() * 5 + 100;
262 ForwardingObjective.Builder fwdBuilder = DefaultForwardingObjective.builder()
263 .fromApp(APPID)
264 .makePermanent()
265 .withSelector(selector)
266 .withPriority(priority)
267 .withFlag(ForwardingObjective.Flag.SPECIFIC);
268
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700269 if (add) {
270 fwdBuilder.nextStep(NEXT_ID);
271 } else {
272 fwdBuilder.withTreatment(DefaultTrafficTreatment.builder().build());
273 }
274
275 return add ? fwdBuilder.add() : fwdBuilder.remove();
276 }
277
278 /**
279 * Tests adding a route.
280 *
281 * We verify that the flowObjectiveService records the correct state and that the
282 * correct flow is submitted to the flowObjectiveService.
283 */
284 @Test
285 public void testRouteAdd() {
Charles Chan8fe9f4c2016-10-24 16:46:25 -0700286 ResolvedRoute resolvedRoute = new ResolvedRoute(PREFIX1, NEXT_HOP1, MAC1, SW1_ETH1);
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700287
288 // Create the next objective
289 NextObjective nextObjective = createNextObjective(MAC1, MAC1, SW1_ETH1.port(), VlanId.NONE, true);
290 flowObjectiveService.next(DEVICE_ID, nextObjective);
291
292 // Create the flow objective
293 ForwardingObjective fwd = createForwardingObjective(PREFIX1, true);
294 flowObjectiveService.forward(DEVICE_ID, fwd);
gaurav36785932016-03-10 17:24:04 +0530295 EasyMock.expectLastCall().once();
296 setUpFlowObjectiveService();
297
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700298 // Send in the add event
299 RouteEvent routeEvent = new RouteEvent(RouteEvent.Type.ROUTE_ADDED, resolvedRoute);
300 routeListener.event(routeEvent);
gaurav36785932016-03-10 17:24:04 +0530301 verify(flowObjectiveService);
302 }
303
304 /**
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700305 * Tests adding a route with to a next hop in a VLAN.
gaurav36785932016-03-10 17:24:04 +0530306 *
307 * We verify that the flowObjectiveService records the correct state and that the
308 * correct flowObjectiveService is submitted to the flowObjectiveService.
309 */
310 @Test
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700311 public void testRouteAddWithVlan() {
Charles Chan8fe9f4c2016-10-24 16:46:25 -0700312 ResolvedRoute route = new ResolvedRoute(PREFIX1, NEXT_HOP2, MAC2, SW1_ETH2);
gaurav36785932016-03-10 17:24:04 +0530313
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700314 // Create the next objective
315 NextObjective nextObjective = createNextObjective(MAC2, MAC2, SW1_ETH2.port(), VLAN1, true);
316 flowObjectiveService.next(DEVICE_ID, nextObjective);
gaurav36785932016-03-10 17:24:04 +0530317
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700318 // Create the flow objective
319 ForwardingObjective fwd = createForwardingObjective(PREFIX1, true);
320 flowObjectiveService.forward(DEVICE_ID, fwd);
gaurav36785932016-03-10 17:24:04 +0530321 EasyMock.expectLastCall().once();
322 setUpFlowObjectiveService();
323
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700324 // Send in the add event
325 routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_ADDED, route));
gaurav36785932016-03-10 17:24:04 +0530326
327 verify(flowObjectiveService);
328 }
329
330 /**
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700331 * Tests updating a route.
gaurav36785932016-03-10 17:24:04 +0530332 *
333 * We verify that the flowObjectiveService records the correct state and that the
334 * correct flow is submitted to the flowObjectiveService.
335 */
336 @Test
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700337 public void testRouteUpdate() {
gaurav36785932016-03-10 17:24:04 +0530338 // Firstly add a route
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700339 testRouteAdd();
gaurav36785932016-03-10 17:24:04 +0530340 reset(flowObjectiveService);
gaurav36785932016-03-10 17:24:04 +0530341
Charles Chane4d13102016-11-08 15:38:44 -0800342 ResolvedRoute oldRoute = new ResolvedRoute(PREFIX1, NEXT_HOP1, MAC1, SW1_ETH1);
Charles Chan8fe9f4c2016-10-24 16:46:25 -0700343 ResolvedRoute route = new ResolvedRoute(PREFIX1, NEXT_HOP2, MAC2, SW1_ETH2);
gaurav36785932016-03-10 17:24:04 +0530344
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700345 // Create the next objective
346 NextObjective nextObjective = createNextObjective(MAC2, MAC2, SW1_ETH2.port(), VLAN1, true);
347 flowObjectiveService.next(DEVICE_ID, nextObjective);
gaurav36785932016-03-10 17:24:04 +0530348
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700349 // Create the flow objective
350 ForwardingObjective fwd = createForwardingObjective(PREFIX1, true);
351 flowObjectiveService.forward(DEVICE_ID, fwd);
gaurav36785932016-03-10 17:24:04 +0530352 EasyMock.expectLastCall().once();
353 setUpFlowObjectiveService();
354
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700355 // Send in the update event
Charles Chane4d13102016-11-08 15:38:44 -0800356 routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_UPDATED, route, oldRoute));
gaurav36785932016-03-10 17:24:04 +0530357
358 verify(flowObjectiveService);
359 }
360
Jonathan Hartf04b7d92016-03-29 09:39:11 -0700361 /**
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700362 * Tests deleting a route.
gaurav36785932016-03-10 17:24:04 +0530363 *
364 * We verify that the flowObjectiveService records the correct state and that the
365 * correct flow is withdrawn from the flowObjectiveService.
366 */
gaurav36785932016-03-10 17:24:04 +0530367 @Test
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700368 public void testRouteDelete() {
gaurav36785932016-03-10 17:24:04 +0530369 // Firstly add a route
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700370 testRouteAdd();
gaurav36785932016-03-10 17:24:04 +0530371
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700372 // Construct the existing route
Charles Chane4d13102016-11-08 15:38:44 -0800373 ResolvedRoute route = new ResolvedRoute(PREFIX1, NEXT_HOP1, MAC1, SW1_ETH1);
gaurav36785932016-03-10 17:24:04 +0530374
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700375 // Create the flow objective
gaurav36785932016-03-10 17:24:04 +0530376 reset(flowObjectiveService);
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700377 ForwardingObjective fwd = createForwardingObjective(PREFIX1, false);
378 flowObjectiveService.forward(DEVICE_ID, fwd);
gaurav36785932016-03-10 17:24:04 +0530379 replay(flowObjectiveService);
380
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700381 // Send in the delete event
382 routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_REMOVED, route));
gaurav36785932016-03-10 17:24:04 +0530383
384 verify(flowObjectiveService);
385 }
386
gaurav164cf6d2016-03-25 21:43:04 +0530387 private class TestInterfaceService extends InterfaceServiceAdapter {
gaurav164cf6d2016-03-25 21:43:04 +0530388 @Override
389 public void addListener(InterfaceListener listener) {
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700390 interfaceListener = listener;
gaurav164cf6d2016-03-25 21:43:04 +0530391 }
392 }
393
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700394 private class TestRouteService extends RouteServiceAdapter {
gaurav36785932016-03-10 17:24:04 +0530395 @Override
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700396 public void addListener(RouteListener listener) {
Jonathan Harte7327042017-02-02 13:11:25 -0800397 FibInstallerTest.this.routeListener = listener;
gaurav36785932016-03-10 17:24:04 +0530398 }
399 }
400
401 private class TestRouterConfig extends RouterConfig {
402
403 @Override
404 public List<String> getInterfaces() {
405 ArrayList<String> interfaces = new ArrayList<>();
406 interfaces.add("of:0000000000000001/1");
Jonathan Harta2eb9ff2016-04-13 21:27:06 -0700407 interfaces.add("of:0000000000000001/2");
gaurav36785932016-03-10 17:24:04 +0530408 return interfaces;
409 }
410
411 @Override
412 public ConnectPoint getControlPlaneConnectPoint() {
413 return SW1_ETH1;
414 }
415
416 @Override
417 public boolean getOspfEnabled() {
418 return true;
419 }
420 }
421
422 private class TestDeviceService extends DeviceServiceAdapter {
423
424 @Override
425 public boolean isAvailable(DeviceId deviceId) {
426 return true;
427 }
428
429 @Override
430 public void addListener(DeviceListener listener) {
Jonathan Harte7327042017-02-02 13:11:25 -0800431 FibInstallerTest.this.deviceListener = listener;
gaurav36785932016-03-10 17:24:04 +0530432 }
433 }
434}