kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 1 | /* |
Jonathan Hart | f4bd048 | 2017-01-27 15:11:18 -0800 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Laboratory |
kishore | db79dc0 | 2016-03-07 16:24:55 +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 | */ |
Jonathan Hart | f4bd048 | 2017-01-27 15:11:18 -0800 | [diff] [blame] | 16 | |
| 17 | package org.onosproject.routing.cpr; |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 18 | |
Jonathan Hart | f04b7d9 | 2016-03-29 09:39:11 -0700 | [diff] [blame] | 19 | import com.google.common.collect.Sets; |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 20 | import org.easymock.EasyMock; |
| 21 | import org.junit.Before; |
Jonathan Hart | f8cd052 | 2016-10-25 07:09:55 -0700 | [diff] [blame] | 22 | import org.junit.Ignore; |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 23 | import org.junit.Test; |
Charles Chan | c6d227e | 2017-02-28 15:15:17 -0800 | [diff] [blame] | 24 | import org.onlab.osgi.ComponentContextAdapter; |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 25 | import org.onlab.packet.EthType; |
Pier Luigi | 2b1ad87 | 2017-01-31 09:35:42 -0800 | [diff] [blame] | 26 | import org.onlab.packet.Ip6Address; |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 27 | import org.onlab.packet.IpAddress; |
| 28 | import org.onlab.packet.IpPrefix; |
| 29 | import org.onlab.packet.MacAddress; |
| 30 | import org.onlab.packet.VlanId; |
kishore | 786b7e4 | 2016-05-19 16:25:57 +0530 | [diff] [blame] | 31 | import org.onosproject.app.ApplicationService; |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 32 | import org.onosproject.core.ApplicationId; |
| 33 | import org.onosproject.core.CoreService; |
| 34 | import org.onosproject.core.CoreServiceAdapter; |
| 35 | import org.onosproject.incubator.net.intf.Interface; |
kishore | 71a2753 | 2016-03-16 20:23:49 +0530 | [diff] [blame] | 36 | import org.onosproject.incubator.net.intf.InterfaceEvent; |
| 37 | import org.onosproject.incubator.net.intf.InterfaceListener; |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 38 | import org.onosproject.incubator.net.intf.InterfaceService; |
kishore | 71a2753 | 2016-03-16 20:23:49 +0530 | [diff] [blame] | 39 | import org.onosproject.incubator.net.intf.InterfaceServiceAdapter; |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 40 | import org.onosproject.mastership.MastershipService; |
| 41 | import org.onosproject.mastership.MastershipServiceAdapter; |
| 42 | import org.onosproject.net.ConnectPoint; |
| 43 | import org.onosproject.net.Device; |
| 44 | import org.onosproject.net.DeviceId; |
| 45 | import org.onosproject.net.NetTestTools; |
| 46 | import org.onosproject.net.PortNumber; |
| 47 | import org.onosproject.net.config.Config; |
| 48 | import org.onosproject.net.config.NetworkConfigEvent; |
| 49 | import org.onosproject.net.config.NetworkConfigEvent.Type; |
| 50 | import org.onosproject.net.config.NetworkConfigListener; |
| 51 | import org.onosproject.net.config.NetworkConfigService; |
| 52 | import org.onosproject.net.config.NetworkConfigServiceAdapter; |
| 53 | import org.onosproject.net.device.DeviceEvent; |
| 54 | import org.onosproject.net.device.DeviceListener; |
| 55 | import org.onosproject.net.device.DeviceService; |
| 56 | import org.onosproject.net.device.DeviceServiceAdapter; |
| 57 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 58 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 59 | import org.onosproject.net.flow.TrafficSelector; |
| 60 | import org.onosproject.net.flow.TrafficTreatment; |
| 61 | import org.onosproject.net.flowobjective.DefaultForwardingObjective; |
| 62 | import org.onosproject.net.flowobjective.DefaultNextObjective; |
| 63 | import org.onosproject.net.flowobjective.FlowObjectiveService; |
| 64 | import org.onosproject.net.flowobjective.ForwardingObjective; |
| 65 | import org.onosproject.net.flowobjective.NextObjective; |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 66 | import org.onosproject.net.host.HostService; |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 67 | import org.onosproject.net.host.InterfaceIpAddress; |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 68 | import org.onosproject.routing.RoutingService; |
| 69 | import org.onosproject.routing.config.RouterConfig; |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 70 | |
Jonathan Hart | f04b7d9 | 2016-03-29 09:39:11 -0700 | [diff] [blame] | 71 | import java.util.ArrayList; |
| 72 | import java.util.HashSet; |
| 73 | import java.util.List; |
| 74 | import java.util.Objects; |
| 75 | import java.util.Set; |
| 76 | |
| 77 | import static org.easymock.EasyMock.createMock; |
| 78 | import static org.easymock.EasyMock.createNiceMock; |
| 79 | import static org.easymock.EasyMock.expect; |
| 80 | import static org.easymock.EasyMock.expectLastCall; |
| 81 | import static org.easymock.EasyMock.replay; |
| 82 | import static org.easymock.EasyMock.verify; |
Vinayak Tejankar | 3a409c6 | 2017-01-12 02:20:53 +0530 | [diff] [blame] | 83 | import static org.onlab.packet.ICMP6.NEIGHBOR_ADVERTISEMENT; |
| 84 | import static org.onlab.packet.ICMP6.NEIGHBOR_SOLICITATION; |
Pier Luigi | 2b1ad87 | 2017-01-31 09:35:42 -0800 | [diff] [blame] | 85 | import static org.onlab.packet.IPv6.getLinkLocalAddress; |
| 86 | import static org.onlab.packet.IPv6.getSolicitNodeAddress; |
Jonathan Hart | f4bd048 | 2017-01-27 15:11:18 -0800 | [diff] [blame] | 87 | import static org.onosproject.routing.cpr.ControlPlaneRedirectManager.ACL_PRIORITY; |
| 88 | import static org.onosproject.routing.cpr.ControlPlaneRedirectManager.buildArpSelector; |
| 89 | import static org.onosproject.routing.cpr.ControlPlaneRedirectManager.buildIPDstSelector; |
| 90 | import static org.onosproject.routing.cpr.ControlPlaneRedirectManager.buildIPSrcSelector; |
| 91 | import static org.onosproject.routing.cpr.ControlPlaneRedirectManager.buildNdpSelector; |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 92 | |
| 93 | /** |
| 94 | * UnitTests for ControlPlaneRedirectManager. |
| 95 | */ |
Jonathan Hart | f8cd052 | 2016-10-25 07:09:55 -0700 | [diff] [blame] | 96 | @Ignore("Too many dependencies on internal implementation, too hard to maintain") |
Jonathan Hart | f04b7d9 | 2016-03-29 09:39:11 -0700 | [diff] [blame] | 97 | public class ControlPlaneRedirectManagerTest { |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 98 | |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 99 | private DeviceService deviceService; |
| 100 | private FlowObjectiveService flowObjectiveService; |
| 101 | private NetworkConfigService networkConfigService; |
| 102 | private final Set<Interface> interfaces = Sets.newHashSet(); |
| 103 | static Device dev3 = NetTestTools.device("0000000000000001"); |
| 104 | private static final int OSPF_IP_PROTO = 0x59; |
| 105 | private CoreService coreService = new TestCoreService(); |
| 106 | private InterfaceService interfaceService; |
kishore | 786b7e4 | 2016-05-19 16:25:57 +0530 | [diff] [blame] | 107 | private static final ApplicationId APPID = TestApplicationId.create("org.onosproject.vrouter"); |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 108 | |
Jonathan Hart | f04b7d9 | 2016-03-29 09:39:11 -0700 | [diff] [blame] | 109 | private static final DeviceId DEVICE_ID = DeviceId.deviceId("of:0000000000000001"); |
| 110 | |
| 111 | private ConnectPoint controlPlaneConnectPoint = new ConnectPoint(DEVICE_ID, |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 112 | PortNumber.portNumber(1)); |
| 113 | |
Jonathan Hart | f04b7d9 | 2016-03-29 09:39:11 -0700 | [diff] [blame] | 114 | private static final ConnectPoint SW1_ETH1 = new ConnectPoint(DEVICE_ID, |
| 115 | PortNumber.portNumber(1)); |
| 116 | |
| 117 | private static final ConnectPoint SW1_ETH2 = new ConnectPoint(DEVICE_ID, |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 118 | PortNumber.portNumber(2)); |
| 119 | |
Jonathan Hart | f04b7d9 | 2016-03-29 09:39:11 -0700 | [diff] [blame] | 120 | private static final ConnectPoint SW1_ETH3 = new ConnectPoint(DEVICE_ID, |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 121 | PortNumber.portNumber(3)); |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 122 | |
Jonathan Hart | f04b7d9 | 2016-03-29 09:39:11 -0700 | [diff] [blame] | 123 | private ControlPlaneRedirectManager controlPlaneRedirectManager = new ControlPlaneRedirectManager(); |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 124 | private RouterConfig routerConfig = new TestRouterConfig(); |
| 125 | private NetworkConfigListener networkConfigListener; |
| 126 | private DeviceListener deviceListener; |
| 127 | private MastershipService mastershipService = new InternalMastershipServiceTest(); |
kishore | 71a2753 | 2016-03-16 20:23:49 +0530 | [diff] [blame] | 128 | private InterfaceListener interfaceListener; |
kishore | 786b7e4 | 2016-05-19 16:25:57 +0530 | [diff] [blame] | 129 | private ApplicationService applicationService; |
Jonathan Hart | f04b7d9 | 2016-03-29 09:39:11 -0700 | [diff] [blame] | 130 | |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 131 | @Before |
kishore | 71a2753 | 2016-03-16 20:23:49 +0530 | [diff] [blame] | 132 | public void setUp() { |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 133 | networkConfigListener = createMock(NetworkConfigListener.class); |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 134 | deviceService = new TestDeviceService(); |
| 135 | deviceListener = createMock(DeviceListener.class); |
Jonathan Hart | f04b7d9 | 2016-03-29 09:39:11 -0700 | [diff] [blame] | 136 | |
kishore | 71a2753 | 2016-03-16 20:23:49 +0530 | [diff] [blame] | 137 | interfaceListener = createMock(InterfaceListener.class); |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 138 | deviceService.addListener(deviceListener); |
| 139 | setUpInterfaceService(); |
kishore | 71a2753 | 2016-03-16 20:23:49 +0530 | [diff] [blame] | 140 | interfaceService = new InternalInterfaceService(); |
| 141 | interfaceService.addListener(interfaceListener); |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 142 | networkConfigService = new TestNetworkConfigService(); |
| 143 | networkConfigService.addListener(networkConfigListener); |
| 144 | flowObjectiveService = createMock(FlowObjectiveService.class); |
kishore | 786b7e4 | 2016-05-19 16:25:57 +0530 | [diff] [blame] | 145 | applicationService = createNiceMock(ApplicationService.class); |
| 146 | replay(applicationService); |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 147 | setUpFlowObjectiveService(); |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 148 | controlPlaneRedirectManager.coreService = coreService; |
| 149 | controlPlaneRedirectManager.flowObjectiveService = flowObjectiveService; |
| 150 | controlPlaneRedirectManager.networkConfigService = networkConfigService; |
| 151 | controlPlaneRedirectManager.interfaceService = interfaceService; |
| 152 | controlPlaneRedirectManager.deviceService = deviceService; |
Jonathan Hart | f04b7d9 | 2016-03-29 09:39:11 -0700 | [diff] [blame] | 153 | controlPlaneRedirectManager.hostService = createNiceMock(HostService.class); |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 154 | controlPlaneRedirectManager.mastershipService = mastershipService; |
kishore | 786b7e4 | 2016-05-19 16:25:57 +0530 | [diff] [blame] | 155 | controlPlaneRedirectManager.applicationService = applicationService; |
Charles Chan | c6d227e | 2017-02-28 15:15:17 -0800 | [diff] [blame] | 156 | controlPlaneRedirectManager.activate(new ComponentContextAdapter()); |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 157 | verify(flowObjectiveService); |
| 158 | } |
kishore | 71a2753 | 2016-03-16 20:23:49 +0530 | [diff] [blame] | 159 | |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 160 | /** |
kishore | 71a2753 | 2016-03-16 20:23:49 +0530 | [diff] [blame] | 161 | * Tests adding new Device to a openflow router. |
| 162 | */ |
| 163 | @Test |
| 164 | public void testAddDevice() { |
Jonathan Hart | f04b7d9 | 2016-03-29 09:39:11 -0700 | [diff] [blame] | 165 | ConnectPoint sw1eth4 = new ConnectPoint(DEVICE_ID, PortNumber.portNumber(4)); |
Vinayak Tejankar | 3a409c6 | 2017-01-12 02:20:53 +0530 | [diff] [blame] | 166 | List<InterfaceIpAddress> interfaceIpAddresses = new ArrayList<>(); |
| 167 | interfaceIpAddresses.add( |
| 168 | new InterfaceIpAddress(IpAddress.valueOf("192.168.40.101"), IpPrefix.valueOf("192.168.40.0/24")) |
| 169 | ); |
| 170 | interfaceIpAddresses.add( |
| 171 | new InterfaceIpAddress(IpAddress.valueOf("2000::ff"), IpPrefix.valueOf("2000::ff/120")) |
| 172 | ); |
kishore | 71a2753 | 2016-03-16 20:23:49 +0530 | [diff] [blame] | 173 | |
Vinayak Tejankar | 3a409c6 | 2017-01-12 02:20:53 +0530 | [diff] [blame] | 174 | Interface sw1Eth4 = new Interface(sw1eth4.deviceId().toString(), sw1eth4, interfaceIpAddresses, |
kishore | 71a2753 | 2016-03-16 20:23:49 +0530 | [diff] [blame] | 175 | MacAddress.valueOf("00:00:00:00:00:04"), VlanId.NONE); |
| 176 | interfaces.add(sw1Eth4); |
| 177 | EasyMock.reset(flowObjectiveService); |
| 178 | setUpFlowObjectiveService(); |
| 179 | deviceListener.event(new DeviceEvent(DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED, dev3)); |
| 180 | verify(flowObjectiveService); |
| 181 | } |
| 182 | |
| 183 | /** |
| 184 | * Tests adding while updating the networkConfig. |
| 185 | */ |
| 186 | @Test |
| 187 | public void testUpdateNetworkConfig() { |
Jonathan Hart | f04b7d9 | 2016-03-29 09:39:11 -0700 | [diff] [blame] | 188 | ConnectPoint sw1eth4 = new ConnectPoint(DEVICE_ID, PortNumber.portNumber(4)); |
Vinayak Tejankar | 3a409c6 | 2017-01-12 02:20:53 +0530 | [diff] [blame] | 189 | List<InterfaceIpAddress> interfaceIpAddresses = new ArrayList<>(); |
| 190 | interfaceIpAddresses.add( |
| 191 | new InterfaceIpAddress(IpAddress.valueOf("192.168.40.101"), IpPrefix.valueOf("192.168.40.0/24")) |
| 192 | ); |
| 193 | interfaceIpAddresses.add( |
| 194 | new InterfaceIpAddress(IpAddress.valueOf("2000::ff"), IpPrefix.valueOf("2000::ff/120")) |
| 195 | ); |
kishore | 71a2753 | 2016-03-16 20:23:49 +0530 | [diff] [blame] | 196 | |
Vinayak Tejankar | 3a409c6 | 2017-01-12 02:20:53 +0530 | [diff] [blame] | 197 | Interface sw1Eth4 = new Interface(sw1eth4.deviceId().toString(), sw1eth4, interfaceIpAddresses, |
kishore | 71a2753 | 2016-03-16 20:23:49 +0530 | [diff] [blame] | 198 | MacAddress.valueOf("00:00:00:00:00:04"), VlanId.NONE); |
| 199 | interfaces.add(sw1Eth4); |
| 200 | EasyMock.reset(flowObjectiveService); |
| 201 | setUpFlowObjectiveService(); |
| 202 | networkConfigListener |
| 203 | .event(new NetworkConfigEvent(Type.CONFIG_UPDATED, dev3, RoutingService.ROUTER_CONFIG_CLASS)); |
| 204 | networkConfigService.addListener(networkConfigListener); |
| 205 | verify(flowObjectiveService); |
| 206 | } |
| 207 | |
| 208 | /** |
| 209 | * Tests adding while updating the networkConfig. |
| 210 | */ |
| 211 | @Test |
| 212 | public void testAddInterface() { |
Jonathan Hart | f04b7d9 | 2016-03-29 09:39:11 -0700 | [diff] [blame] | 213 | ConnectPoint sw1eth4 = new ConnectPoint(DEVICE_ID, PortNumber.portNumber(4)); |
Vinayak Tejankar | 3a409c6 | 2017-01-12 02:20:53 +0530 | [diff] [blame] | 214 | List<InterfaceIpAddress> interfaceIpAddresses = new ArrayList<>(); |
| 215 | interfaceIpAddresses.add( |
| 216 | new InterfaceIpAddress(IpAddress.valueOf("192.168.40.101"), IpPrefix.valueOf("192.168.40.0/24")) |
| 217 | ); |
| 218 | interfaceIpAddresses.add( |
| 219 | new InterfaceIpAddress(IpAddress.valueOf("2000::ff"), IpPrefix.valueOf("2000::ff/120")) |
| 220 | ); |
kishore | 71a2753 | 2016-03-16 20:23:49 +0530 | [diff] [blame] | 221 | |
Vinayak Tejankar | 3a409c6 | 2017-01-12 02:20:53 +0530 | [diff] [blame] | 222 | Interface sw1Eth4 = new Interface(sw1eth4.deviceId().toString(), sw1eth4, interfaceIpAddresses, |
kishore | 71a2753 | 2016-03-16 20:23:49 +0530 | [diff] [blame] | 223 | MacAddress.valueOf("00:00:00:00:00:04"), VlanId.NONE); |
| 224 | interfaces.add(sw1Eth4); |
| 225 | |
| 226 | EasyMock.reset(flowObjectiveService); |
| 227 | expect(flowObjectiveService.allocateNextId()).andReturn(1).anyTimes(); |
| 228 | |
| 229 | setUpInterfaceConfiguration(sw1Eth4, true); |
| 230 | replay(flowObjectiveService); |
Jonathan Hart | f04b7d9 | 2016-03-29 09:39:11 -0700 | [diff] [blame] | 231 | interfaceListener.event(new InterfaceEvent(InterfaceEvent.Type.INTERFACE_ADDED, sw1Eth4, 500L)); |
kishore | 71a2753 | 2016-03-16 20:23:49 +0530 | [diff] [blame] | 232 | verify(flowObjectiveService); |
| 233 | } |
| 234 | |
| 235 | @Test |
| 236 | public void testRemoveInterface() { |
Jonathan Hart | f04b7d9 | 2016-03-29 09:39:11 -0700 | [diff] [blame] | 237 | ConnectPoint sw1eth4 = new ConnectPoint(DEVICE_ID, PortNumber.portNumber(4)); |
Vinayak Tejankar | 3a409c6 | 2017-01-12 02:20:53 +0530 | [diff] [blame] | 238 | List<InterfaceIpAddress> interfaceIpAddresses = new ArrayList<>(); |
| 239 | interfaceIpAddresses.add( |
| 240 | new InterfaceIpAddress(IpAddress.valueOf("192.168.40.101"), IpPrefix.valueOf("192.168.40.0/24")) |
| 241 | ); |
| 242 | interfaceIpAddresses.add( |
| 243 | new InterfaceIpAddress(IpAddress.valueOf("2000::ff"), IpPrefix.valueOf("2000::ff/120")) |
| 244 | ); |
kishore | 71a2753 | 2016-03-16 20:23:49 +0530 | [diff] [blame] | 245 | |
Vinayak Tejankar | 3a409c6 | 2017-01-12 02:20:53 +0530 | [diff] [blame] | 246 | Interface sw1Eth4 = new Interface(sw1eth4.deviceId().toString(), sw1eth4, interfaceIpAddresses, |
kishore | 71a2753 | 2016-03-16 20:23:49 +0530 | [diff] [blame] | 247 | MacAddress.valueOf("00:00:00:00:00:04"), VlanId.NONE); |
| 248 | EasyMock.reset(flowObjectiveService); |
| 249 | expect(flowObjectiveService.allocateNextId()).andReturn(1).anyTimes(); |
| 250 | |
| 251 | setUpInterfaceConfiguration(sw1Eth4, false); |
| 252 | replay(flowObjectiveService); |
Jonathan Hart | f04b7d9 | 2016-03-29 09:39:11 -0700 | [diff] [blame] | 253 | interfaceListener.event(new InterfaceEvent(InterfaceEvent.Type.INTERFACE_REMOVED, sw1Eth4, 500L)); |
kishore | 71a2753 | 2016-03-16 20:23:49 +0530 | [diff] [blame] | 254 | verify(flowObjectiveService); |
| 255 | } |
| 256 | |
| 257 | /** |
| 258 | * Setup flow Configuration for all configured Interfaces. |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 259 | * |
| 260 | **/ |
| 261 | private void setUpFlowObjectiveService() { |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 262 | expect(flowObjectiveService.allocateNextId()).andReturn(1).anyTimes(); |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 263 | for (Interface intf : interfaceService.getInterfaces()) { |
kishore | 71a2753 | 2016-03-16 20:23:49 +0530 | [diff] [blame] | 264 | setUpInterfaceConfiguration(intf, true); |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 265 | } |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 266 | replay(flowObjectiveService); |
| 267 | } |
| 268 | |
| 269 | /** |
kishore | 71a2753 | 2016-03-16 20:23:49 +0530 | [diff] [blame] | 270 | * Setting up flowobjective expectations for basic forwarding and ospf. |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 271 | **/ |
kishore | 71a2753 | 2016-03-16 20:23:49 +0530 | [diff] [blame] | 272 | private void setUpInterfaceConfiguration(Interface intf, boolean install) { |
| 273 | DeviceId deviceId = controlPlaneConnectPoint.deviceId(); |
| 274 | PortNumber controlPlanePort = controlPlaneConnectPoint.port(); |
Ray Milkey | 048bf9a | 2017-05-12 14:31:50 -0700 | [diff] [blame^] | 275 | for (InterfaceIpAddress ip : intf.ipAddressesList()) { |
kishore | 71a2753 | 2016-03-16 20:23:49 +0530 | [diff] [blame] | 276 | int cpNextId, intfNextId; |
kishore | 71a2753 | 2016-03-16 20:23:49 +0530 | [diff] [blame] | 277 | cpNextId = modifyNextObjective(deviceId, controlPlanePort, |
Jonathan Hart | f4bd048 | 2017-01-27 15:11:18 -0800 | [diff] [blame] | 278 | VlanId.vlanId(ControlPlaneRedirectManager.ASSIGNED_VLAN), true, install); |
kishore | 71a2753 | 2016-03-16 20:23:49 +0530 | [diff] [blame] | 279 | intfNextId = modifyNextObjective(deviceId, intf.connectPoint().port(), |
Jonathan Hart | f4bd048 | 2017-01-27 15:11:18 -0800 | [diff] [blame] | 280 | VlanId.vlanId(ControlPlaneRedirectManager.ASSIGNED_VLAN), true, install); |
kishore | 71a2753 | 2016-03-16 20:23:49 +0530 | [diff] [blame] | 281 | |
Vinayak Tejankar | 3a409c6 | 2017-01-12 02:20:53 +0530 | [diff] [blame] | 282 | // IP to router |
Pier Luigi | 2b1ad87 | 2017-01-31 09:35:42 -0800 | [diff] [blame] | 283 | TrafficSelector toSelector = buildIPDstSelector(ip.ipAddress().toIpPrefix(), |
| 284 | intf.connectPoint().port(), |
| 285 | null, |
| 286 | intf.mac(), |
| 287 | intf.vlan()); |
Vinayak Tejankar | 3a409c6 | 2017-01-12 02:20:53 +0530 | [diff] [blame] | 288 | flowObjectiveService.forward(deviceId, buildForwardingObjective(toSelector, null, |
| 289 | cpNextId, install, ACL_PRIORITY)); |
kishore | 71a2753 | 2016-03-16 20:23:49 +0530 | [diff] [blame] | 290 | expectLastCall().once(); |
Vinayak Tejankar | 3a409c6 | 2017-01-12 02:20:53 +0530 | [diff] [blame] | 291 | // IP from router |
Pier Luigi | 2b1ad87 | 2017-01-31 09:35:42 -0800 | [diff] [blame] | 292 | TrafficSelector fromSelector = buildIPSrcSelector(ip.ipAddress().toIpPrefix(), |
| 293 | controlPlanePort, |
| 294 | intf.mac(), |
| 295 | null, |
| 296 | intf.vlan()); |
Vinayak Tejankar | 3a409c6 | 2017-01-12 02:20:53 +0530 | [diff] [blame] | 297 | flowObjectiveService.forward(deviceId, buildForwardingObjective(fromSelector, null, |
| 298 | intfNextId, install, ACL_PRIORITY)); |
kishore | 71a2753 | 2016-03-16 20:23:49 +0530 | [diff] [blame] | 299 | expectLastCall().once(); |
kishore | 71a2753 | 2016-03-16 20:23:49 +0530 | [diff] [blame] | 300 | TrafficTreatment puntTreatment = DefaultTrafficTreatment.builder().punt().build(); |
Vinayak Tejankar | 3a409c6 | 2017-01-12 02:20:53 +0530 | [diff] [blame] | 301 | if (ip.ipAddress().isIp4()) { |
| 302 | // ARP to router |
Pier Luigi | 2b1ad87 | 2017-01-31 09:35:42 -0800 | [diff] [blame] | 303 | toSelector = buildArpSelector(intf.connectPoint().port(), |
| 304 | intf.vlan(), |
| 305 | null, |
| 306 | null); |
Vinayak Tejankar | 3a409c6 | 2017-01-12 02:20:53 +0530 | [diff] [blame] | 307 | flowObjectiveService.forward(deviceId, buildForwardingObjective(toSelector, puntTreatment, |
| 308 | cpNextId, install, ACL_PRIORITY + 1)); |
| 309 | expectLastCall().once(); |
Vinayak Tejankar | 3a409c6 | 2017-01-12 02:20:53 +0530 | [diff] [blame] | 310 | // ARP from router |
Pier Luigi | 2b1ad87 | 2017-01-31 09:35:42 -0800 | [diff] [blame] | 311 | fromSelector = buildArpSelector(controlPlanePort, |
| 312 | intf.vlan(), |
| 313 | ip.ipAddress().getIp4Address(), |
| 314 | intf.mac()); |
Vinayak Tejankar | 3a409c6 | 2017-01-12 02:20:53 +0530 | [diff] [blame] | 315 | flowObjectiveService.forward(deviceId, |
| 316 | buildForwardingObjective(fromSelector, puntTreatment, |
| 317 | intfNextId, install, ACL_PRIORITY + 1)); |
| 318 | expectLastCall().once(); |
| 319 | } else { |
| 320 | // NDP solicitation to router |
Pier Luigi | 2b1ad87 | 2017-01-31 09:35:42 -0800 | [diff] [blame] | 321 | // Global unicast address |
| 322 | toSelector = buildNdpSelector(intf.connectPoint().port(), |
| 323 | intf.vlan(), |
Pier Luigi | 2b1ad87 | 2017-01-31 09:35:42 -0800 | [diff] [blame] | 324 | null, |
Pier Luigi | 9f765dc | 2017-02-03 13:35:23 -0800 | [diff] [blame] | 325 | ip.ipAddress().toIpPrefix(), |
Pier Luigi | 2b1ad87 | 2017-01-31 09:35:42 -0800 | [diff] [blame] | 326 | NEIGHBOR_SOLICITATION, |
| 327 | null); |
Vinayak Tejankar | 3a409c6 | 2017-01-12 02:20:53 +0530 | [diff] [blame] | 328 | flowObjectiveService.forward(deviceId, buildForwardingObjective(toSelector, puntTreatment, |
| 329 | cpNextId, install, ACL_PRIORITY + 1)); |
| 330 | expectLastCall().once(); |
Pier Luigi | 2b1ad87 | 2017-01-31 09:35:42 -0800 | [diff] [blame] | 331 | // NDP solicitation to router |
| 332 | // Link local address |
| 333 | toSelector = buildNdpSelector(intf.connectPoint().port(), |
| 334 | intf.vlan(), |
Pier Luigi | 9f765dc | 2017-02-03 13:35:23 -0800 | [diff] [blame] | 335 | null, |
Pier Luigi | 2b1ad87 | 2017-01-31 09:35:42 -0800 | [diff] [blame] | 336 | Ip6Address.valueOf( |
| 337 | getLinkLocalAddress(intf.mac().toBytes()) |
| 338 | ).toIpPrefix(), |
Pier Luigi | 2b1ad87 | 2017-01-31 09:35:42 -0800 | [diff] [blame] | 339 | NEIGHBOR_SOLICITATION, |
| 340 | null); |
| 341 | flowObjectiveService.forward(deviceId, |
| 342 | buildForwardingObjective(toSelector, puntTreatment, |
Pier Luigi | 9f765dc | 2017-02-03 13:35:23 -0800 | [diff] [blame] | 343 | cpNextId, install, ACL_PRIORITY + 1)); |
Pier Luigi | 2b1ad87 | 2017-01-31 09:35:42 -0800 | [diff] [blame] | 344 | expectLastCall().once(); |
| 345 | // NDP solicitation to router |
| 346 | // solicitated global unicast address |
| 347 | toSelector = buildNdpSelector(intf.connectPoint().port(), |
| 348 | intf.vlan(), |
Pier Luigi | 9f765dc | 2017-02-03 13:35:23 -0800 | [diff] [blame] | 349 | null, |
Pier Luigi | 2b1ad87 | 2017-01-31 09:35:42 -0800 | [diff] [blame] | 350 | Ip6Address.valueOf( |
| 351 | getSolicitNodeAddress(ip.ipAddress().toOctets()) |
| 352 | ).toIpPrefix(), |
Pier Luigi | 2b1ad87 | 2017-01-31 09:35:42 -0800 | [diff] [blame] | 353 | NEIGHBOR_SOLICITATION, |
| 354 | null); |
| 355 | flowObjectiveService.forward(deviceId, |
| 356 | buildForwardingObjective(toSelector, puntTreatment, |
Pier Luigi | 9f765dc | 2017-02-03 13:35:23 -0800 | [diff] [blame] | 357 | cpNextId, install, ACL_PRIORITY + 1)); |
| 358 | expectLastCall().once(); |
Pier Luigi | 2b1ad87 | 2017-01-31 09:35:42 -0800 | [diff] [blame] | 359 | // NDP solicitation to router |
| 360 | // solicitated link local address |
| 361 | toSelector = buildNdpSelector(intf.connectPoint().port(), |
| 362 | intf.vlan(), |
Pier Luigi | 9f765dc | 2017-02-03 13:35:23 -0800 | [diff] [blame] | 363 | null, |
Pier Luigi | 2b1ad87 | 2017-01-31 09:35:42 -0800 | [diff] [blame] | 364 | Ip6Address.valueOf( |
| 365 | getSolicitNodeAddress(getLinkLocalAddress(intf.mac().toBytes())) |
| 366 | ).toIpPrefix(), |
Pier Luigi | 2b1ad87 | 2017-01-31 09:35:42 -0800 | [diff] [blame] | 367 | NEIGHBOR_SOLICITATION, |
| 368 | null); |
| 369 | flowObjectiveService.forward(deviceId, |
| 370 | buildForwardingObjective(toSelector, puntTreatment, |
Pier Luigi | 9f765dc | 2017-02-03 13:35:23 -0800 | [diff] [blame] | 371 | cpNextId, install, ACL_PRIORITY + 1)); |
Pier Luigi | 2b1ad87 | 2017-01-31 09:35:42 -0800 | [diff] [blame] | 372 | expectLastCall().once(); |
Vinayak Tejankar | 3a409c6 | 2017-01-12 02:20:53 +0530 | [diff] [blame] | 373 | // NDP solicitation from router |
Pier Luigi | 2b1ad87 | 2017-01-31 09:35:42 -0800 | [diff] [blame] | 374 | // Global unicast address |
| 375 | fromSelector = buildNdpSelector(controlPlanePort, |
| 376 | intf.vlan(), |
Pier Luigi | 2b1ad87 | 2017-01-31 09:35:42 -0800 | [diff] [blame] | 377 | ip.ipAddress().toIpPrefix(), |
Pier Luigi | 9f765dc | 2017-02-03 13:35:23 -0800 | [diff] [blame] | 378 | null, |
Pier Luigi | 2b1ad87 | 2017-01-31 09:35:42 -0800 | [diff] [blame] | 379 | NEIGHBOR_SOLICITATION, |
| 380 | intf.mac()); |
Vinayak Tejankar | 3a409c6 | 2017-01-12 02:20:53 +0530 | [diff] [blame] | 381 | flowObjectiveService.forward(deviceId, |
| 382 | buildForwardingObjective(fromSelector, puntTreatment, |
| 383 | intfNextId, install, ACL_PRIORITY + 1)); |
Pier Luigi | 2b1ad87 | 2017-01-31 09:35:42 -0800 | [diff] [blame] | 384 | expectLastCall().once(); |
| 385 | // NDP solicitation from router |
| 386 | // Link local address |
| 387 | fromSelector = buildNdpSelector(controlPlanePort, |
| 388 | intf.vlan(), |
Pier Luigi | 2b1ad87 | 2017-01-31 09:35:42 -0800 | [diff] [blame] | 389 | Ip6Address.valueOf( |
| 390 | getLinkLocalAddress(intf.mac().toBytes()) |
| 391 | ).toIpPrefix(), |
Pier Luigi | 9f765dc | 2017-02-03 13:35:23 -0800 | [diff] [blame] | 392 | null, |
Pier Luigi | 2b1ad87 | 2017-01-31 09:35:42 -0800 | [diff] [blame] | 393 | NEIGHBOR_SOLICITATION, |
| 394 | intf.mac()); |
| 395 | flowObjectiveService.forward(deviceId, |
| 396 | buildForwardingObjective(fromSelector, puntTreatment, |
| 397 | intfNextId, install, ACL_PRIORITY + 1)); |
| 398 | expectLastCall().once(); |
Vinayak Tejankar | 3a409c6 | 2017-01-12 02:20:53 +0530 | [diff] [blame] | 399 | // NDP advertisement to router |
Pier Luigi | 2b1ad87 | 2017-01-31 09:35:42 -0800 | [diff] [blame] | 400 | // Global unicast address |
Vinayak Tejankar | 3a409c6 | 2017-01-12 02:20:53 +0530 | [diff] [blame] | 401 | toSelector = buildNdpSelector( |
| 402 | intf.connectPoint().port(), |
| 403 | intf.vlan(), |
Pier Luigi | 9f765dc | 2017-02-03 13:35:23 -0800 | [diff] [blame] | 404 | null, |
| 405 | ip.ipAddress().toIpPrefix(), |
| 406 | NEIGHBOR_ADVERTISEMENT, |
| 407 | null |
| 408 | ); |
| 409 | flowObjectiveService.forward(deviceId, buildForwardingObjective(toSelector, puntTreatment, |
| 410 | cpNextId, install, ACL_PRIORITY + 1)); |
| 411 | expectLastCall().once(); |
| 412 | // NDP advertisement to router |
| 413 | // Link local address |
| 414 | toSelector = buildNdpSelector( |
| 415 | intf.connectPoint().port(), |
| 416 | intf.vlan(), |
| 417 | null, |
| 418 | Ip6Address.valueOf(getLinkLocalAddress(intf.mac().toBytes())).toIpPrefix(), |
| 419 | NEIGHBOR_ADVERTISEMENT, |
| 420 | null |
| 421 | ); |
| 422 | flowObjectiveService.forward(deviceId, buildForwardingObjective(toSelector, puntTreatment, |
| 423 | cpNextId, install, ACL_PRIORITY + 1)); |
| 424 | expectLastCall().once(); |
| 425 | // NDP advertisement from the router |
| 426 | // Global unicast address |
| 427 | fromSelector = buildNdpSelector( |
| 428 | controlPlanePort, |
| 429 | intf.vlan(), |
Pier Luigi | 2b1ad87 | 2017-01-31 09:35:42 -0800 | [diff] [blame] | 430 | ip.ipAddress().toIpPrefix(), |
Vinayak Tejankar | 3a409c6 | 2017-01-12 02:20:53 +0530 | [diff] [blame] | 431 | null, |
| 432 | NEIGHBOR_ADVERTISEMENT, |
| 433 | null |
| 434 | ); |
Pier Luigi | 9f765dc | 2017-02-03 13:35:23 -0800 | [diff] [blame] | 435 | flowObjectiveService.forward(deviceId, buildForwardingObjective(fromSelector, puntTreatment, |
| 436 | intfNextId, install, ACL_PRIORITY + 1)); |
Vinayak Tejankar | 3a409c6 | 2017-01-12 02:20:53 +0530 | [diff] [blame] | 437 | expectLastCall().once(); |
Vinayak Tejankar | 3a409c6 | 2017-01-12 02:20:53 +0530 | [diff] [blame] | 438 | // NDP advertisement from router |
Pier Luigi | 2b1ad87 | 2017-01-31 09:35:42 -0800 | [diff] [blame] | 439 | // Link local address |
Vinayak Tejankar | 3a409c6 | 2017-01-12 02:20:53 +0530 | [diff] [blame] | 440 | fromSelector = buildNdpSelector( |
Pier Luigi | 9f765dc | 2017-02-03 13:35:23 -0800 | [diff] [blame] | 441 | controlPlanePort, |
Vinayak Tejankar | 3a409c6 | 2017-01-12 02:20:53 +0530 | [diff] [blame] | 442 | intf.vlan(), |
Pier Luigi | 2b1ad87 | 2017-01-31 09:35:42 -0800 | [diff] [blame] | 443 | Ip6Address.valueOf(getLinkLocalAddress(intf.mac().toBytes())).toIpPrefix(), |
| 444 | null, |
Vinayak Tejankar | 3a409c6 | 2017-01-12 02:20:53 +0530 | [diff] [blame] | 445 | NEIGHBOR_ADVERTISEMENT, |
Pier Luigi | 2b1ad87 | 2017-01-31 09:35:42 -0800 | [diff] [blame] | 446 | null |
Vinayak Tejankar | 3a409c6 | 2017-01-12 02:20:53 +0530 | [diff] [blame] | 447 | ); |
Vinayak Tejankar | 3a409c6 | 2017-01-12 02:20:53 +0530 | [diff] [blame] | 448 | flowObjectiveService.forward(deviceId, |
| 449 | buildForwardingObjective(fromSelector, puntTreatment, |
| 450 | intfNextId, install, ACL_PRIORITY + 1)); |
Pier Luigi | 2b1ad87 | 2017-01-31 09:35:42 -0800 | [diff] [blame] | 451 | expectLastCall().once(); |
Vinayak Tejankar | 3a409c6 | 2017-01-12 02:20:53 +0530 | [diff] [blame] | 452 | } |
kishore | 71a2753 | 2016-03-16 20:23:49 +0530 | [diff] [blame] | 453 | } |
| 454 | // setting expectations for ospf forwarding. |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 455 | TrafficSelector toSelector = DefaultTrafficSelector.builder().matchInPort(intf.connectPoint().port()) |
| 456 | .matchEthType(EthType.EtherType.IPV4.ethType().toShort()).matchVlanId(intf.vlan()) |
| 457 | .matchIPProtocol((byte) OSPF_IP_PROTO).build(); |
kishore | 71a2753 | 2016-03-16 20:23:49 +0530 | [diff] [blame] | 458 | modifyNextObjective(deviceId, controlPlanePort, VlanId.vlanId((short) 4094), true, install); |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 459 | flowObjectiveService.forward(controlPlaneConnectPoint.deviceId(), |
Vinayak Tejankar | 3a409c6 | 2017-01-12 02:20:53 +0530 | [diff] [blame] | 460 | buildForwardingObjective(toSelector, null, 1, install, 40001)); |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 461 | expectLastCall().once(); |
| 462 | } |
| 463 | |
| 464 | /** |
kishore | 71a2753 | 2016-03-16 20:23:49 +0530 | [diff] [blame] | 465 | * Setup expectations on flowObjectiveService.next for NextObjective. |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 466 | * |
| 467 | **/ |
kishore | 71a2753 | 2016-03-16 20:23:49 +0530 | [diff] [blame] | 468 | private int modifyNextObjective(DeviceId deviceId, PortNumber portNumber, VlanId vlanId, boolean popVlan, |
| 469 | boolean modifyFlag) { |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 470 | NextObjective.Builder nextObjBuilder = DefaultNextObjective.builder().withId(1) |
| 471 | .withType(NextObjective.Type.SIMPLE).fromApp(APPID); |
| 472 | |
| 473 | TrafficTreatment.Builder ttBuilder = DefaultTrafficTreatment.builder(); |
| 474 | if (popVlan) { |
| 475 | ttBuilder.popVlan(); |
| 476 | } |
| 477 | ttBuilder.setOutput(portNumber); |
| 478 | |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 479 | TrafficSelector.Builder metabuilder = DefaultTrafficSelector.builder(); |
| 480 | metabuilder.matchVlanId(vlanId); |
| 481 | |
| 482 | nextObjBuilder.withMeta(metabuilder.build()); |
| 483 | nextObjBuilder.addTreatment(ttBuilder.build()); |
kishore | 71a2753 | 2016-03-16 20:23:49 +0530 | [diff] [blame] | 484 | if (modifyFlag) { |
| 485 | flowObjectiveService.next(deviceId, nextObjBuilder.add()); |
| 486 | expectLastCall().once(); |
| 487 | } else { |
| 488 | flowObjectiveService.next(deviceId, nextObjBuilder.remove()); |
| 489 | expectLastCall().once(); |
| 490 | } |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 491 | return 1; |
| 492 | } |
| 493 | |
| 494 | /** |
kishore | 71a2753 | 2016-03-16 20:23:49 +0530 | [diff] [blame] | 495 | * Setup Interface expectation for all Testcases. |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 496 | **/ |
| 497 | private void setUpInterfaceService() { |
Sho SHIMIZU | 891162b | 2016-06-06 16:32:01 -0700 | [diff] [blame] | 498 | List<InterfaceIpAddress> interfaceIpAddresses1 = new ArrayList<>(); |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 499 | interfaceIpAddresses1 |
| 500 | .add(new InterfaceIpAddress(IpAddress.valueOf("192.168.10.101"), IpPrefix.valueOf("192.168.10.0/24"))); |
| 501 | Interface sw1Eth1 = new Interface(SW1_ETH1.deviceId().toString(), SW1_ETH1, interfaceIpAddresses1, |
| 502 | MacAddress.valueOf("00:00:00:00:00:01"), VlanId.NONE); |
| 503 | interfaces.add(sw1Eth1); |
| 504 | |
Sho SHIMIZU | 891162b | 2016-06-06 16:32:01 -0700 | [diff] [blame] | 505 | List<InterfaceIpAddress> interfaceIpAddresses2 = new ArrayList<>(); |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 506 | interfaceIpAddresses2 |
| 507 | .add(new InterfaceIpAddress(IpAddress.valueOf("192.168.20.101"), IpPrefix.valueOf("192.168.20.0/24"))); |
| 508 | Interface sw1Eth2 = new Interface(SW1_ETH1.deviceId().toString(), SW1_ETH2, interfaceIpAddresses2, |
| 509 | MacAddress.valueOf("00:00:00:00:00:02"), VlanId.NONE); |
| 510 | interfaces.add(sw1Eth2); |
| 511 | |
Sho SHIMIZU | 891162b | 2016-06-06 16:32:01 -0700 | [diff] [blame] | 512 | List<InterfaceIpAddress> interfaceIpAddresses3 = new ArrayList<>(); |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 513 | interfaceIpAddresses3 |
| 514 | .add(new InterfaceIpAddress(IpAddress.valueOf("192.168.30.101"), IpPrefix.valueOf("192.168.30.0/24"))); |
| 515 | Interface sw1Eth3 = new Interface(SW1_ETH1.deviceId().toString(), SW1_ETH3, interfaceIpAddresses3, |
| 516 | MacAddress.valueOf("00:00:00:00:00:03"), VlanId.NONE); |
| 517 | interfaces.add(sw1Eth3); |
| 518 | |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 519 | } |
| 520 | |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 521 | private ForwardingObjective buildForwardingObjective(TrafficSelector selector, TrafficTreatment treatment, |
Vinayak Tejankar | 3a409c6 | 2017-01-12 02:20:53 +0530 | [diff] [blame] | 522 | int nextId, boolean add, int priority) { |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 523 | DefaultForwardingObjective.Builder fobBuilder = DefaultForwardingObjective.builder(); |
| 524 | fobBuilder.withSelector(selector); |
| 525 | if (treatment != null) { |
| 526 | fobBuilder.withTreatment(treatment); |
| 527 | } |
| 528 | if (nextId != -1) { |
| 529 | fobBuilder.nextStep(nextId); |
| 530 | } |
Vinayak Tejankar | 3a409c6 | 2017-01-12 02:20:53 +0530 | [diff] [blame] | 531 | fobBuilder.fromApp(APPID).withPriority(priority).withFlag(ForwardingObjective.Flag.VERSATILE); |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 532 | |
| 533 | return add ? fobBuilder.add() : fobBuilder.remove(); |
| 534 | } |
| 535 | |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 536 | private class TestCoreService extends CoreServiceAdapter { |
kishore | 71a2753 | 2016-03-16 20:23:49 +0530 | [diff] [blame] | 537 | |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 538 | @Override |
| 539 | public ApplicationId getAppId(String name) { |
| 540 | return APPID; |
| 541 | } |
| 542 | |
| 543 | @Override |
| 544 | public ApplicationId registerApplication(String name) { |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 545 | return new TestApplicationId(name); |
| 546 | } |
| 547 | |
| 548 | } |
| 549 | |
| 550 | private class TestDeviceService extends DeviceServiceAdapter { |
| 551 | |
| 552 | @Override |
| 553 | public boolean isAvailable(DeviceId deviceId) { |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 554 | boolean flag = false; |
| 555 | if (deviceId.equals(controlPlaneConnectPoint.deviceId())) { |
| 556 | flag = true; |
| 557 | } |
| 558 | return flag; |
| 559 | } |
| 560 | |
| 561 | @Override |
| 562 | public void addListener(DeviceListener listener) { |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 563 | ControlPlaneRedirectManagerTest.this.deviceListener = listener; |
| 564 | } |
| 565 | |
| 566 | } |
| 567 | |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 568 | private class TestRouterConfig extends RouterConfig { |
| 569 | |
| 570 | @Override |
| 571 | public ConnectPoint getControlPlaneConnectPoint() { |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 572 | return controlPlaneConnectPoint; |
| 573 | } |
| 574 | |
| 575 | @Override |
| 576 | public boolean getOspfEnabled() { |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 577 | return true; |
| 578 | } |
| 579 | |
| 580 | @Override |
| 581 | public List<String> getInterfaces() { |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 582 | ArrayList<String> interfaces = new ArrayList<>(); |
| 583 | interfaces.add("of:0000000000000001"); |
| 584 | interfaces.add("of:0000000000000001/2"); |
| 585 | interfaces.add("of:0000000000000001/3"); |
| 586 | return interfaces; |
| 587 | } |
| 588 | |
| 589 | } |
| 590 | |
| 591 | private class TestNetworkConfigService extends NetworkConfigServiceAdapter { |
| 592 | |
| 593 | @Override |
| 594 | public void addListener(NetworkConfigListener listener) { |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 595 | ControlPlaneRedirectManagerTest.this.networkConfigListener = listener; |
| 596 | } |
| 597 | |
| 598 | @Override |
| 599 | public <S, C extends Config<S>> C getConfig(S subject, Class<C> configClass) { |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 600 | return (C) ControlPlaneRedirectManagerTest.this.routerConfig; |
| 601 | } |
| 602 | |
| 603 | } |
| 604 | |
| 605 | private static class TestApplicationId implements ApplicationId { |
| 606 | |
| 607 | private final String name; |
| 608 | private final short id; |
| 609 | |
| 610 | public TestApplicationId(String name) { |
| 611 | this.name = name; |
| 612 | this.id = (short) Objects.hash(name); |
| 613 | } |
| 614 | |
| 615 | public static ApplicationId create(String name) { |
| 616 | return new TestApplicationId(name); |
| 617 | } |
| 618 | |
| 619 | @Override |
| 620 | public short id() { |
| 621 | return id; |
| 622 | } |
| 623 | |
| 624 | @Override |
| 625 | public String name() { |
| 626 | return name; |
| 627 | } |
| 628 | |
| 629 | @Override |
| 630 | public int hashCode() { |
| 631 | final int prime = 31; |
| 632 | int result = 1; |
| 633 | result = prime * result + id; |
| 634 | result = prime * result + ((name == null) ? 0 : name.hashCode()); |
| 635 | return result; |
| 636 | } |
| 637 | |
| 638 | @Override |
| 639 | public boolean equals(Object obj) { |
| 640 | if (this == obj) { |
| 641 | return true; |
| 642 | } |
| 643 | if (obj == null) { |
| 644 | return false; |
| 645 | } |
| 646 | if (getClass() != obj.getClass()) { |
| 647 | return false; |
| 648 | } |
| 649 | TestApplicationId other = (TestApplicationId) obj; |
| 650 | if (id != other.id) { |
| 651 | return false; |
| 652 | } |
| 653 | if (name == null) { |
| 654 | if (other.name != null) { |
| 655 | return false; |
kishore | 71a2753 | 2016-03-16 20:23:49 +0530 | [diff] [blame] | 656 | } |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 657 | } else if (!name.equals(other.name)) { |
| 658 | return false; |
| 659 | } |
| 660 | return true; |
| 661 | } |
| 662 | } |
| 663 | |
| 664 | private class InternalMastershipServiceTest extends MastershipServiceAdapter { |
| 665 | |
| 666 | @Override |
| 667 | public boolean isLocalMaster(DeviceId deviceId) { |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 668 | boolean flag = deviceId.equals(controlPlaneConnectPoint.deviceId()); |
| 669 | return flag; |
| 670 | } |
| 671 | |
| 672 | } |
kishore | 71a2753 | 2016-03-16 20:23:49 +0530 | [diff] [blame] | 673 | |
| 674 | private class InternalInterfaceService extends InterfaceServiceAdapter { |
| 675 | |
| 676 | @Override |
| 677 | public void addListener(InterfaceListener listener) { |
| 678 | ControlPlaneRedirectManagerTest.this.interfaceListener = listener; |
| 679 | } |
| 680 | |
| 681 | @Override |
| 682 | public Set<Interface> getInterfaces() { |
| 683 | return interfaces; |
| 684 | } |
| 685 | |
| 686 | @Override |
| 687 | public Set<Interface> getInterfacesByPort(ConnectPoint port) { |
| 688 | Set<Interface> setIntf = new HashSet<Interface>(); |
| 689 | for (Interface intf : interfaces) { |
| 690 | if (intf.connectPoint().equals(port)) { |
| 691 | setIntf.add(intf); |
| 692 | } |
| 693 | } |
| 694 | return setIntf; |
| 695 | } |
| 696 | |
| 697 | @Override |
| 698 | public Interface getMatchingInterface(IpAddress ip) { |
| 699 | Interface intff = null; |
| 700 | for (Interface intf : interfaces) { |
Ray Milkey | 048bf9a | 2017-05-12 14:31:50 -0700 | [diff] [blame^] | 701 | for (InterfaceIpAddress address : intf.ipAddressesList()) { |
kishore | 71a2753 | 2016-03-16 20:23:49 +0530 | [diff] [blame] | 702 | if (address.ipAddress().equals(ip)) { |
| 703 | intff = intf; |
| 704 | break; |
| 705 | } |
| 706 | } |
| 707 | } |
| 708 | |
| 709 | return intff; |
| 710 | } |
| 711 | |
| 712 | } |
kishore | db79dc0 | 2016-03-07 16:24:55 +0530 | [diff] [blame] | 713 | } |