gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onosproject.routing.impl; |
| 17 | |
Jonathan Hart | f04b7d9 | 2016-03-29 09:39:11 -0700 | [diff] [blame] | 18 | import com.google.common.collect.Sets; |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 19 | import org.easymock.EasyMock; |
| 20 | import org.junit.Before; |
| 21 | import org.junit.Test; |
| 22 | import org.onlab.packet.Ethernet; |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 23 | import org.onlab.packet.Ip4Prefix; |
| 24 | import org.onlab.packet.IpAddress; |
| 25 | import org.onlab.packet.IpPrefix; |
| 26 | import org.onlab.packet.MacAddress; |
| 27 | import org.onlab.packet.VlanId; |
| 28 | import org.onosproject.TestApplicationId; |
Jonathan Hart | f04b7d9 | 2016-03-29 09:39:11 -0700 | [diff] [blame] | 29 | import org.onosproject.cfg.ComponentConfigService; |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 30 | import org.onosproject.core.ApplicationId; |
| 31 | import org.onosproject.core.CoreService; |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 32 | import org.onosproject.incubator.net.intf.Interface; |
gaurav | 164cf6d | 2016-03-25 21:43:04 +0530 | [diff] [blame] | 33 | import org.onosproject.incubator.net.intf.InterfaceListener; |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 34 | import org.onosproject.incubator.net.intf.InterfaceService; |
gaurav | 164cf6d | 2016-03-25 21:43:04 +0530 | [diff] [blame] | 35 | import org.onosproject.incubator.net.intf.InterfaceServiceAdapter; |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame^] | 36 | import org.onosproject.incubator.net.routing.ResolvedRoute; |
| 37 | import org.onosproject.incubator.net.routing.RouteEvent; |
| 38 | import org.onosproject.incubator.net.routing.RouteListener; |
| 39 | import org.onosproject.incubator.net.routing.RouteServiceAdapter; |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 40 | import org.onosproject.net.ConnectPoint; |
| 41 | import org.onosproject.net.DeviceId; |
| 42 | import org.onosproject.net.PortNumber; |
| 43 | import org.onosproject.net.config.NetworkConfigService; |
| 44 | import org.onosproject.net.device.DeviceListener; |
| 45 | import org.onosproject.net.device.DeviceService; |
| 46 | import org.onosproject.net.device.DeviceServiceAdapter; |
| 47 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 48 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 49 | import org.onosproject.net.flow.TrafficSelector; |
| 50 | import org.onosproject.net.flow.TrafficTreatment; |
| 51 | import org.onosproject.net.flowobjective.DefaultForwardingObjective; |
| 52 | import org.onosproject.net.flowobjective.DefaultNextObjective; |
| 53 | import org.onosproject.net.flowobjective.FlowObjectiveService; |
| 54 | import org.onosproject.net.flowobjective.ForwardingObjective; |
| 55 | import org.onosproject.net.flowobjective.NextObjective; |
| 56 | import org.onosproject.net.host.InterfaceIpAddress; |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 57 | import org.onosproject.routing.RoutingService; |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 58 | import org.onosproject.routing.config.RouterConfig; |
Jonathan Hart | f04b7d9 | 2016-03-29 09:39:11 -0700 | [diff] [blame] | 59 | import org.osgi.service.component.ComponentContext; |
| 60 | |
| 61 | import java.util.ArrayList; |
| 62 | import java.util.Collections; |
Jonathan Hart | f04b7d9 | 2016-03-29 09:39:11 -0700 | [diff] [blame] | 63 | import java.util.List; |
| 64 | import java.util.Set; |
| 65 | |
| 66 | import static org.easymock.EasyMock.anyObject; |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame^] | 67 | import static org.easymock.EasyMock.anyString; |
Jonathan Hart | f04b7d9 | 2016-03-29 09:39:11 -0700 | [diff] [blame] | 68 | import static org.easymock.EasyMock.createMock; |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame^] | 69 | import static org.easymock.EasyMock.createNiceMock; |
| 70 | import static org.easymock.EasyMock.eq; |
Jonathan Hart | f04b7d9 | 2016-03-29 09:39:11 -0700 | [diff] [blame] | 71 | import static org.easymock.EasyMock.expect; |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame^] | 72 | import static org.easymock.EasyMock.expectLastCall; |
Jonathan Hart | f04b7d9 | 2016-03-29 09:39:11 -0700 | [diff] [blame] | 73 | import static org.easymock.EasyMock.replay; |
| 74 | import static org.easymock.EasyMock.reset; |
| 75 | import static org.easymock.EasyMock.verify; |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 76 | |
| 77 | /** |
| 78 | * Unit tests for SingleSwitchFibInstaller. |
| 79 | */ |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame^] | 80 | public class SingleSwitchFibInstallerTest { |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 81 | |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame^] | 82 | private static final DeviceId DEVICE_ID = DeviceId.deviceId("of:0000000000000001"); |
| 83 | |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 84 | private static final ConnectPoint SW1_ETH1 = new ConnectPoint( |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame^] | 85 | DEVICE_ID, PortNumber.portNumber(1)); |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 86 | |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame^] | 87 | private static final ConnectPoint SW1_ETH2 = new ConnectPoint( |
| 88 | DEVICE_ID, PortNumber.portNumber(2)); |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 89 | |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame^] | 90 | private static final int NEXT_ID = 11; |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 91 | |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame^] | 92 | private static final VlanId VLAN1 = VlanId.vlanId((short) 1); |
| 93 | private static final MacAddress MAC1 = MacAddress.valueOf("00:00:00:00:00:01"); |
| 94 | private static final MacAddress MAC2 = MacAddress.valueOf("00:00:00:00:00:02"); |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 95 | |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame^] | 96 | private static final IpPrefix PREFIX1 = Ip4Prefix.valueOf("1.1.1.0/24"); |
| 97 | private static final IpAddress NEXT_HOP1 = IpAddress.valueOf("192.168.10.1"); |
| 98 | private static final IpAddress NEXT_HOP2 = IpAddress.valueOf("192.168.20.1"); |
| 99 | private static final InterfaceIpAddress INTF1 = |
| 100 | InterfaceIpAddress.valueOf("192.168.10.2/24"); |
| 101 | private static final InterfaceIpAddress INTF2 = |
| 102 | InterfaceIpAddress.valueOf("192.168.20.2/24"); |
| 103 | |
| 104 | |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 105 | private final Set<Interface> interfaces = Sets.newHashSet(); |
| 106 | private InterfaceService interfaceService; |
| 107 | private NetworkConfigService networkConfigService; |
| 108 | private FlowObjectiveService flowObjectiveService; |
| 109 | private DeviceService deviceService; |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame^] | 110 | private static final ApplicationId APPID = TestApplicationId.create("foo"); |
| 111 | |
| 112 | private RouteListener routeListener; |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 113 | private DeviceListener deviceListener; |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame^] | 114 | |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 115 | private RouterConfig routerConfig; |
gaurav | 164cf6d | 2016-03-25 21:43:04 +0530 | [diff] [blame] | 116 | private SingleSwitchFibInstaller sSfibInstaller; |
| 117 | private InterfaceListener interfaceListener; |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 118 | |
| 119 | @Before |
| 120 | public void setUp() throws Exception { |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 121 | sSfibInstaller = new SingleSwitchFibInstaller(); |
| 122 | |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame^] | 123 | sSfibInstaller.componentConfigService = createNiceMock(ComponentConfigService.class); |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 124 | |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame^] | 125 | ComponentContext mockContext = createNiceMock(ComponentContext.class); |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 126 | |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 127 | routerConfig = new TestRouterConfig(); |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame^] | 128 | interfaceService = createMock(InterfaceService.class); |
| 129 | |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 130 | networkConfigService = createMock(NetworkConfigService.class); |
| 131 | flowObjectiveService = createMock(FlowObjectiveService.class); |
| 132 | deviceService = new TestDeviceService(); |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame^] | 133 | CoreService coreService = createNiceMock(CoreService.class); |
| 134 | expect(coreService.registerApplication(anyString())).andReturn(APPID); |
| 135 | replay(coreService); |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 136 | |
| 137 | sSfibInstaller.networkConfigService = networkConfigService; |
| 138 | sSfibInstaller.interfaceService = interfaceService; |
| 139 | sSfibInstaller.flowObjectiveService = flowObjectiveService; |
| 140 | sSfibInstaller.coreService = coreService; |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame^] | 141 | sSfibInstaller.routeService = new TestRouteService(); |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 142 | sSfibInstaller.deviceService = deviceService; |
| 143 | |
| 144 | setUpNetworkConfigService(); |
| 145 | setUpInterfaceService(); |
| 146 | sSfibInstaller.activate(mockContext); |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * Sets up InterfaceService. |
| 151 | */ |
| 152 | private void setUpInterfaceService() { |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame^] | 153 | interfaceService.addListener(anyObject(InterfaceListener.class)); |
| 154 | expectLastCall().andDelegateTo(new TestInterfaceService()); |
| 155 | |
| 156 | // Interface with no VLAN |
| 157 | Interface sw1Eth1 = new Interface("intf1", SW1_ETH1, |
| 158 | Collections.singletonList(INTF1), MAC1, VlanId.NONE); |
| 159 | expect(interfaceService.getMatchingInterface(NEXT_HOP1)).andReturn(sw1Eth1); |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 160 | interfaces.add(sw1Eth1); |
| 161 | |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame^] | 162 | // Interface with a VLAN |
| 163 | Interface sw2Eth1 = new Interface("intf2", SW1_ETH2, |
| 164 | Collections.singletonList(INTF2), MAC2, VLAN1); |
| 165 | expect(interfaceService.getMatchingInterface(NEXT_HOP2)).andReturn(sw2Eth1); |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 166 | interfaces.add(sw2Eth1); |
| 167 | |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame^] | 168 | expect(interfaceService.getInterfaces()).andReturn(interfaces); |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 169 | |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame^] | 170 | replay(interfaceService); |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | /* |
| 174 | * Sets up NetworkConfigService. |
Jonathan Hart | f04b7d9 | 2016-03-29 09:39:11 -0700 | [diff] [blame] | 175 | */ |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 176 | private void setUpNetworkConfigService() { |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame^] | 177 | expect(networkConfigService.getConfig( |
| 178 | anyObject(ApplicationId.class), eq(RoutingService.ROUTER_CONFIG_CLASS))). |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 179 | andReturn(routerConfig); |
| 180 | replay(networkConfigService); |
| 181 | } |
| 182 | |
| 183 | /** |
| 184 | * Sets up FlowObjectiveService. |
| 185 | */ |
| 186 | private void setUpFlowObjectiveService() { |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame^] | 187 | expect(flowObjectiveService.allocateNextId()).andReturn(NEXT_ID); |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 188 | replay(flowObjectiveService); |
| 189 | } |
| 190 | |
| 191 | /** |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame^] | 192 | * Creates a next objective with the given parameters. |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 193 | * |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame^] | 194 | * @param srcMac source MAC address |
| 195 | * @param dstMac destination MAC address |
| 196 | * @param port port number |
| 197 | * @param vlan vlan ID |
| 198 | * @param add whether to create an add objective or remove objective |
| 199 | * @return new next objective |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 200 | */ |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame^] | 201 | private NextObjective createNextObjective(MacAddress srcMac, |
| 202 | MacAddress dstMac, |
| 203 | PortNumber port, |
| 204 | VlanId vlan, |
| 205 | boolean add) { |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 206 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder() |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame^] | 207 | .setEthSrc(srcMac) |
| 208 | .setEthDst(dstMac); |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 209 | TrafficSelector.Builder metabuilder = null; |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame^] | 210 | if (!vlan.equals(VlanId.NONE)) { |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 211 | treatment.pushVlan() |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame^] | 212 | .setVlanId(vlan) |
| 213 | .setVlanPcp((byte) 0); |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 214 | } else { |
| 215 | metabuilder = DefaultTrafficSelector.builder(); |
| 216 | metabuilder.matchVlanId(VlanId.vlanId(SingleSwitchFibInstaller.ASSIGNED_VLAN)); |
| 217 | } |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame^] | 218 | |
| 219 | treatment.setOutput(port); |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 220 | NextObjective.Builder nextBuilder = DefaultNextObjective.builder() |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame^] | 221 | .withId(NEXT_ID) |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 222 | .addTreatment(treatment.build()) |
| 223 | .withType(NextObjective.Type.SIMPLE) |
| 224 | .fromApp(APPID); |
| 225 | if (metabuilder != null) { |
| 226 | nextBuilder.withMeta(metabuilder.build()); |
| 227 | } |
| 228 | |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame^] | 229 | return add ? nextBuilder.add() : nextBuilder.remove(); |
| 230 | } |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 231 | |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame^] | 232 | /** |
| 233 | * Creates a new forwarding objective with the given parameters. |
| 234 | * |
| 235 | * @param prefix IP prefix |
| 236 | * @param add whether to create an add objective or a remove objective |
| 237 | * @return new forwarding objective |
| 238 | */ |
| 239 | private ForwardingObjective createForwardingObjective(IpPrefix prefix, |
| 240 | boolean add) { |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 241 | TrafficSelector selector = DefaultTrafficSelector.builder() |
| 242 | .matchEthType(Ethernet.TYPE_IPV4) |
| 243 | .matchIPDst(prefix) |
| 244 | .build(); |
| 245 | |
| 246 | int priority = prefix.prefixLength() * 5 + 100; |
| 247 | ForwardingObjective.Builder fwdBuilder = DefaultForwardingObjective.builder() |
| 248 | .fromApp(APPID) |
| 249 | .makePermanent() |
| 250 | .withSelector(selector) |
| 251 | .withPriority(priority) |
| 252 | .withFlag(ForwardingObjective.Flag.SPECIFIC); |
| 253 | |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame^] | 254 | if (add) { |
| 255 | fwdBuilder.nextStep(NEXT_ID); |
| 256 | } else { |
| 257 | fwdBuilder.withTreatment(DefaultTrafficTreatment.builder().build()); |
| 258 | } |
| 259 | |
| 260 | return add ? fwdBuilder.add() : fwdBuilder.remove(); |
| 261 | } |
| 262 | |
| 263 | /** |
| 264 | * Tests adding a route. |
| 265 | * |
| 266 | * We verify that the flowObjectiveService records the correct state and that the |
| 267 | * correct flow is submitted to the flowObjectiveService. |
| 268 | */ |
| 269 | @Test |
| 270 | public void testRouteAdd() { |
| 271 | ResolvedRoute resolvedRoute = new ResolvedRoute(PREFIX1, NEXT_HOP1, MAC1); |
| 272 | |
| 273 | // Create the next objective |
| 274 | NextObjective nextObjective = createNextObjective(MAC1, MAC1, SW1_ETH1.port(), VlanId.NONE, true); |
| 275 | flowObjectiveService.next(DEVICE_ID, nextObjective); |
| 276 | |
| 277 | // Create the flow objective |
| 278 | ForwardingObjective fwd = createForwardingObjective(PREFIX1, true); |
| 279 | flowObjectiveService.forward(DEVICE_ID, fwd); |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 280 | EasyMock.expectLastCall().once(); |
| 281 | setUpFlowObjectiveService(); |
| 282 | |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame^] | 283 | // Send in the add event |
| 284 | RouteEvent routeEvent = new RouteEvent(RouteEvent.Type.ROUTE_ADDED, resolvedRoute); |
| 285 | routeListener.event(routeEvent); |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 286 | verify(flowObjectiveService); |
| 287 | } |
| 288 | |
| 289 | /** |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame^] | 290 | * Tests adding a route with to a next hop in a VLAN. |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 291 | * |
| 292 | * We verify that the flowObjectiveService records the correct state and that the |
| 293 | * correct flowObjectiveService is submitted to the flowObjectiveService. |
| 294 | */ |
| 295 | @Test |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame^] | 296 | public void testRouteAddWithVlan() { |
| 297 | ResolvedRoute route = new ResolvedRoute(PREFIX1, NEXT_HOP2, MAC2); |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 298 | |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame^] | 299 | // Create the next objective |
| 300 | NextObjective nextObjective = createNextObjective(MAC2, MAC2, SW1_ETH2.port(), VLAN1, true); |
| 301 | flowObjectiveService.next(DEVICE_ID, nextObjective); |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 302 | |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame^] | 303 | // Create the flow objective |
| 304 | ForwardingObjective fwd = createForwardingObjective(PREFIX1, true); |
| 305 | flowObjectiveService.forward(DEVICE_ID, fwd); |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 306 | EasyMock.expectLastCall().once(); |
| 307 | setUpFlowObjectiveService(); |
| 308 | |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame^] | 309 | // Send in the add event |
| 310 | routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_ADDED, route)); |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 311 | |
| 312 | verify(flowObjectiveService); |
| 313 | } |
| 314 | |
| 315 | /** |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame^] | 316 | * Tests updating a route. |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 317 | * |
| 318 | * We verify that the flowObjectiveService records the correct state and that the |
| 319 | * correct flow is submitted to the flowObjectiveService. |
| 320 | */ |
| 321 | @Test |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame^] | 322 | public void testRouteUpdate() { |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 323 | // Firstly add a route |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame^] | 324 | testRouteAdd(); |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 325 | reset(flowObjectiveService); |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 326 | |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame^] | 327 | ResolvedRoute route = new ResolvedRoute(PREFIX1, NEXT_HOP2, MAC2); |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 328 | |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame^] | 329 | // Create the next objective |
| 330 | NextObjective nextObjective = createNextObjective(MAC2, MAC2, SW1_ETH2.port(), VLAN1, true); |
| 331 | flowObjectiveService.next(DEVICE_ID, nextObjective); |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 332 | |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame^] | 333 | // Create the flow objective |
| 334 | ForwardingObjective fwd = createForwardingObjective(PREFIX1, true); |
| 335 | flowObjectiveService.forward(DEVICE_ID, fwd); |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 336 | EasyMock.expectLastCall().once(); |
| 337 | setUpFlowObjectiveService(); |
| 338 | |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame^] | 339 | // Send in the update event |
| 340 | routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_UPDATED, route)); |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 341 | |
| 342 | verify(flowObjectiveService); |
| 343 | } |
| 344 | |
Jonathan Hart | f04b7d9 | 2016-03-29 09:39:11 -0700 | [diff] [blame] | 345 | /** |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame^] | 346 | * Tests deleting a route. |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 347 | * |
| 348 | * We verify that the flowObjectiveService records the correct state and that the |
| 349 | * correct flow is withdrawn from the flowObjectiveService. |
| 350 | */ |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 351 | @Test |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame^] | 352 | public void testRouteDelete() { |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 353 | // Firstly add a route |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame^] | 354 | testRouteAdd(); |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 355 | |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame^] | 356 | // Construct the existing route |
| 357 | ResolvedRoute route = new ResolvedRoute(PREFIX1, null, null); |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 358 | |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame^] | 359 | // Create the flow objective |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 360 | reset(flowObjectiveService); |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame^] | 361 | ForwardingObjective fwd = createForwardingObjective(PREFIX1, false); |
| 362 | flowObjectiveService.forward(DEVICE_ID, fwd); |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 363 | replay(flowObjectiveService); |
| 364 | |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame^] | 365 | // Send in the delete event |
| 366 | routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_REMOVED, route)); |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 367 | |
| 368 | verify(flowObjectiveService); |
| 369 | } |
| 370 | |
gaurav | 164cf6d | 2016-03-25 21:43:04 +0530 | [diff] [blame] | 371 | private class TestInterfaceService extends InterfaceServiceAdapter { |
gaurav | 164cf6d | 2016-03-25 21:43:04 +0530 | [diff] [blame] | 372 | @Override |
| 373 | public void addListener(InterfaceListener listener) { |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame^] | 374 | interfaceListener = listener; |
gaurav | 164cf6d | 2016-03-25 21:43:04 +0530 | [diff] [blame] | 375 | } |
| 376 | } |
| 377 | |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame^] | 378 | private class TestRouteService extends RouteServiceAdapter { |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 379 | @Override |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame^] | 380 | public void addListener(RouteListener listener) { |
| 381 | SingleSwitchFibInstallerTest.this.routeListener = listener; |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 382 | } |
| 383 | } |
| 384 | |
| 385 | private class TestRouterConfig extends RouterConfig { |
| 386 | |
| 387 | @Override |
| 388 | public List<String> getInterfaces() { |
| 389 | ArrayList<String> interfaces = new ArrayList<>(); |
| 390 | interfaces.add("of:0000000000000001/1"); |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame^] | 391 | interfaces.add("of:0000000000000001/2"); |
gaurav | 3678593 | 2016-03-10 17:24:04 +0530 | [diff] [blame] | 392 | return interfaces; |
| 393 | } |
| 394 | |
| 395 | @Override |
| 396 | public ConnectPoint getControlPlaneConnectPoint() { |
| 397 | return SW1_ETH1; |
| 398 | } |
| 399 | |
| 400 | @Override |
| 401 | public boolean getOspfEnabled() { |
| 402 | return true; |
| 403 | } |
| 404 | } |
| 405 | |
| 406 | private class TestDeviceService extends DeviceServiceAdapter { |
| 407 | |
| 408 | @Override |
| 409 | public boolean isAvailable(DeviceId deviceId) { |
| 410 | return true; |
| 411 | } |
| 412 | |
| 413 | @Override |
| 414 | public void addListener(DeviceListener listener) { |
| 415 | SingleSwitchFibInstallerTest.this.deviceListener = listener; |
| 416 | } |
| 417 | } |
| 418 | } |