Andreas Papazois | b85190b | 2016-02-05 09:44:31 -0800 | [diff] [blame] | 1 | /* |
Andreas Papazois | e6aebaa | 2016-05-26 15:25:51 +0300 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Andreas Papazois | b85190b | 2016-02-05 09:44:31 -0800 | [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 | |
| 17 | package org.onosproject.sdxl3; |
| 18 | |
| 19 | import com.google.common.collect.Sets; |
| 20 | import org.junit.Before; |
| 21 | import org.junit.Test; |
| 22 | import org.onlab.packet.Ethernet; |
| 23 | import org.onlab.packet.Ip4Address; |
| 24 | import org.onlab.packet.Ip4Prefix; |
| 25 | import org.onlab.packet.IpAddress; |
| 26 | import org.onlab.packet.IpPrefix; |
| 27 | import org.onlab.packet.MacAddress; |
| 28 | import org.onlab.packet.VlanId; |
| 29 | import org.onosproject.TestApplicationId; |
| 30 | import org.onosproject.core.ApplicationId; |
| 31 | import org.onosproject.core.CoreServiceAdapter; |
| 32 | import org.onosproject.incubator.net.intf.Interface; |
Andreas Papazois | eb51893 | 2016-06-21 13:46:20 +0300 | [diff] [blame^] | 33 | import org.onosproject.incubator.net.intf.InterfaceListener; |
Andreas Papazois | b85190b | 2016-02-05 09:44:31 -0800 | [diff] [blame] | 34 | import org.onosproject.incubator.net.intf.InterfaceService; |
Andreas Papazois | eb51893 | 2016-06-21 13:46:20 +0300 | [diff] [blame^] | 35 | import org.onosproject.incubator.net.intf.InterfaceServiceAdapter; |
| 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; |
Andreas Papazois | b85190b | 2016-02-05 09:44:31 -0800 | [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.flow.DefaultTrafficSelector; |
| 44 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 45 | import org.onosproject.net.flow.TrafficSelector; |
| 46 | import org.onosproject.net.flow.TrafficTreatment; |
| 47 | import org.onosproject.net.host.InterfaceIpAddress; |
| 48 | import org.onosproject.net.intent.AbstractIntentTest; |
| 49 | import org.onosproject.net.intent.Key; |
| 50 | import org.onosproject.net.intent.MultiPointToSinglePointIntent; |
Andreas Papazois | b85190b | 2016-02-05 09:44:31 -0800 | [diff] [blame] | 51 | import org.onosproject.routing.IntentSynchronizationService; |
Andreas Papazois | b85190b | 2016-02-05 09:44:31 -0800 | [diff] [blame] | 52 | |
Yuta HIGUCHI | 9d64cb2 | 2016-06-17 20:37:59 -0700 | [diff] [blame] | 53 | import java.util.ArrayList; |
Andreas Papazois | b85190b | 2016-02-05 09:44:31 -0800 | [diff] [blame] | 54 | import java.util.Collections; |
Andreas Papazois | b85190b | 2016-02-05 09:44:31 -0800 | [diff] [blame] | 55 | import java.util.HashSet; |
Yuta HIGUCHI | 9d64cb2 | 2016-06-17 20:37:59 -0700 | [diff] [blame] | 56 | import java.util.List; |
Andreas Papazois | b85190b | 2016-02-05 09:44:31 -0800 | [diff] [blame] | 57 | import java.util.Set; |
| 58 | |
Andreas Papazois | eb51893 | 2016-06-21 13:46:20 +0300 | [diff] [blame^] | 59 | import static org.easymock.EasyMock.anyObject; |
Andreas Papazois | b85190b | 2016-02-05 09:44:31 -0800 | [diff] [blame] | 60 | import static org.easymock.EasyMock.createMock; |
| 61 | import static org.easymock.EasyMock.expect; |
Andreas Papazois | eb51893 | 2016-06-21 13:46:20 +0300 | [diff] [blame^] | 62 | import static org.easymock.EasyMock.expectLastCall; |
Andreas Papazois | b85190b | 2016-02-05 09:44:31 -0800 | [diff] [blame] | 63 | import static org.easymock.EasyMock.replay; |
| 64 | import static org.easymock.EasyMock.reset; |
| 65 | import static org.easymock.EasyMock.verify; |
| 66 | import static org.onosproject.routing.TestIntentServiceHelper.eqExceptId; |
| 67 | |
| 68 | /** |
| 69 | * Unit tests for SdxL3Fib. |
| 70 | */ |
| 71 | public class SdxL3FibTest extends AbstractIntentTest { |
| 72 | |
Andreas Papazois | b85190b | 2016-02-05 09:44:31 -0800 | [diff] [blame] | 73 | private InterfaceService interfaceService; |
| 74 | private SdxL3PeerService peerService; |
| 75 | |
| 76 | private static final String DEVICE1_ID = "of:0000000000000001"; |
| 77 | private static final String DEVICE2_ID = "of:0000000000000002"; |
| 78 | private static final String DEVICE3_ID = "of:0000000000000003"; |
| 79 | private static final String DEVICE4_ID = "of:0000000000000004"; |
| 80 | |
| 81 | private static final String PEER1_IP = "192.168.10.1"; |
| 82 | private static final String PEER2_IP = "192.168.10.2"; |
| 83 | private static final String PEER3_IP = "192.168.10.3"; |
| 84 | private static final String PEER4_IP = "192.168.20.4"; |
| 85 | |
| 86 | private static final String SPEAKER1_IP = "192.168.10.101"; |
| 87 | private static final String SPEAKER2_IP = "192.168.20.101"; |
| 88 | |
| 89 | private static final String MAC1 = "00:00:00:00:00:01"; |
| 90 | private static final String MAC2 = "00:00:00:00:00:02"; |
| 91 | |
| 92 | private Interface interface1; |
| 93 | private Interface interface2; |
| 94 | private Interface interface3; |
| 95 | private Interface interface4; |
| 96 | |
| 97 | private static final ConnectPoint CONN_POINT1 = new ConnectPoint( |
| 98 | DeviceId.deviceId(DEVICE1_ID), |
| 99 | PortNumber.portNumber(1)); |
| 100 | |
| 101 | private static final ConnectPoint CONN_POINT2 = new ConnectPoint( |
| 102 | DeviceId.deviceId(DEVICE2_ID), |
| 103 | PortNumber.portNumber(1)); |
| 104 | |
| 105 | private static final ConnectPoint CONN_POINT3 = new ConnectPoint( |
| 106 | DeviceId.deviceId(DEVICE3_ID), |
| 107 | PortNumber.portNumber(1)); |
| 108 | |
| 109 | private static final ConnectPoint CONN_POINT4 = new ConnectPoint( |
| 110 | DeviceId.deviceId(DEVICE4_ID), |
| 111 | PortNumber.portNumber(1)); |
| 112 | |
| 113 | private SdxL3Fib sdxL3Fib; |
| 114 | private IntentSynchronizationService intentSynchronizer; |
| 115 | private final Set<Interface> interfaces = Sets.newHashSet(); |
| 116 | |
| 117 | private static final ApplicationId APPID = TestApplicationId.create("sdxl3"); |
| 118 | |
Andreas Papazois | eb51893 | 2016-06-21 13:46:20 +0300 | [diff] [blame^] | 119 | private RouteListener routeListener; |
| 120 | private InterfaceListener interfaceListener; |
Andreas Papazois | b85190b | 2016-02-05 09:44:31 -0800 | [diff] [blame] | 121 | |
Yuta HIGUCHI | 9d64cb2 | 2016-06-17 20:37:59 -0700 | [diff] [blame] | 122 | @Override |
Andreas Papazois | b85190b | 2016-02-05 09:44:31 -0800 | [diff] [blame] | 123 | @Before |
| 124 | public void setUp() throws Exception { |
| 125 | super.setUp(); |
| 126 | |
Andreas Papazois | b85190b | 2016-02-05 09:44:31 -0800 | [diff] [blame] | 127 | interfaceService = createMock(InterfaceService.class); |
Andreas Papazois | eb51893 | 2016-06-21 13:46:20 +0300 | [diff] [blame^] | 128 | interfaceService.addListener(anyObject(InterfaceListener.class)); |
| 129 | expectLastCall().andDelegateTo(new InterfaceServiceDelegate()); |
| 130 | |
Andreas Papazois | b85190b | 2016-02-05 09:44:31 -0800 | [diff] [blame] | 131 | peerService = createMock(SdxL3PeerService.class); |
| 132 | |
| 133 | // These will set expectations on routingConfig and interfaceService |
| 134 | setUpInterfaceService(); |
| 135 | setUpBgpPeers(); |
| 136 | |
Andreas Papazois | b85190b | 2016-02-05 09:44:31 -0800 | [diff] [blame] | 137 | replay(interfaceService); |
| 138 | replay(peerService); |
| 139 | |
| 140 | intentSynchronizer = createMock(IntentSynchronizationService.class); |
| 141 | |
| 142 | sdxL3Fib = new SdxL3Fib(); |
Andreas Papazois | eb51893 | 2016-06-21 13:46:20 +0300 | [diff] [blame^] | 143 | sdxL3Fib.routeService = new TestRouteService(); |
Andreas Papazois | b85190b | 2016-02-05 09:44:31 -0800 | [diff] [blame] | 144 | sdxL3Fib.coreService = new TestCoreService(); |
| 145 | sdxL3Fib.interfaceService = interfaceService; |
| 146 | sdxL3Fib.intentSynchronizer = intentSynchronizer; |
| 147 | sdxL3Fib.peerService = peerService; |
| 148 | |
| 149 | sdxL3Fib.activate(); |
| 150 | } |
| 151 | |
| 152 | /** |
| 153 | * Sets up InterfaceService. |
| 154 | */ |
| 155 | private void setUpInterfaceService() { |
Yuta HIGUCHI | 9d64cb2 | 2016-06-17 20:37:59 -0700 | [diff] [blame] | 156 | List<InterfaceIpAddress> interfaceIpAddresses1 = new ArrayList<>(); |
Andreas Papazois | b85190b | 2016-02-05 09:44:31 -0800 | [diff] [blame] | 157 | interfaceIpAddresses1.add(new InterfaceIpAddress( |
| 158 | IpAddress.valueOf(SPEAKER1_IP), |
| 159 | IpPrefix.valueOf("192.168.10.0/24"))); |
Yuta HIGUCHI | 9d64cb2 | 2016-06-17 20:37:59 -0700 | [diff] [blame] | 160 | interface1 = new Interface("test1", |
| 161 | CONN_POINT1, |
Andreas Papazois | b85190b | 2016-02-05 09:44:31 -0800 | [diff] [blame] | 162 | interfaceIpAddresses1, MacAddress.valueOf(MAC1), |
| 163 | VlanId.NONE); |
| 164 | interfaces.add(interface1); |
| 165 | |
Yuta HIGUCHI | 9d64cb2 | 2016-06-17 20:37:59 -0700 | [diff] [blame] | 166 | List<InterfaceIpAddress> interfaceIpAddresses2 = new ArrayList<>(); |
Andreas Papazois | b85190b | 2016-02-05 09:44:31 -0800 | [diff] [blame] | 167 | interfaceIpAddresses2.add( |
| 168 | new InterfaceIpAddress(IpAddress.valueOf(SPEAKER1_IP), |
| 169 | IpPrefix.valueOf("192.168.10.0/24"))); |
Yuta HIGUCHI | 9d64cb2 | 2016-06-17 20:37:59 -0700 | [diff] [blame] | 170 | interface2 = new Interface("test2", |
| 171 | CONN_POINT2, |
Andreas Papazois | b85190b | 2016-02-05 09:44:31 -0800 | [diff] [blame] | 172 | interfaceIpAddresses2, MacAddress.valueOf(MAC1), |
| 173 | VlanId.NONE); |
| 174 | interfaces.add(interface2); |
| 175 | |
Yuta HIGUCHI | 9d64cb2 | 2016-06-17 20:37:59 -0700 | [diff] [blame] | 176 | List<InterfaceIpAddress> interfaceIpAddresses3 = new ArrayList<>(); |
Andreas Papazois | b85190b | 2016-02-05 09:44:31 -0800 | [diff] [blame] | 177 | interfaceIpAddresses3.add( |
| 178 | new InterfaceIpAddress(IpAddress.valueOf(SPEAKER1_IP), |
| 179 | IpPrefix.valueOf("192.168.10.0/24"))); |
Yuta HIGUCHI | 9d64cb2 | 2016-06-17 20:37:59 -0700 | [diff] [blame] | 180 | interface3 = new Interface("test3", |
| 181 | CONN_POINT3, |
Andreas Papazois | b85190b | 2016-02-05 09:44:31 -0800 | [diff] [blame] | 182 | interfaceIpAddresses3, MacAddress.valueOf(MAC1), |
| 183 | VlanId.vlanId((short) 1)); |
| 184 | interfaces.add(interface3); |
| 185 | |
Yuta HIGUCHI | 9d64cb2 | 2016-06-17 20:37:59 -0700 | [diff] [blame] | 186 | List<InterfaceIpAddress> interfaceIpAddresses4 = new ArrayList<>(); |
Andreas Papazois | b85190b | 2016-02-05 09:44:31 -0800 | [diff] [blame] | 187 | interfaceIpAddresses4.add( |
| 188 | new InterfaceIpAddress(IpAddress.valueOf(SPEAKER2_IP), |
| 189 | IpPrefix.valueOf("192.168.20.0/24"))); |
Yuta HIGUCHI | 9d64cb2 | 2016-06-17 20:37:59 -0700 | [diff] [blame] | 190 | interface4 = new Interface("test4", |
| 191 | CONN_POINT4, |
Andreas Papazois | b85190b | 2016-02-05 09:44:31 -0800 | [diff] [blame] | 192 | interfaceIpAddresses4, MacAddress.valueOf(MAC2), |
Andreas Papazois | eb51893 | 2016-06-21 13:46:20 +0300 | [diff] [blame^] | 193 | VlanId.vlanId((short) 2)); |
Andreas Papazois | b85190b | 2016-02-05 09:44:31 -0800 | [diff] [blame] | 194 | interfaces.add(interface4); |
| 195 | |
| 196 | expect(interfaceService.getInterfacesByPort(CONN_POINT1)).andReturn( |
| 197 | Collections.singleton(interface1)).anyTimes(); |
| 198 | expect(interfaceService.getMatchingInterface(Ip4Address.valueOf(PEER1_IP))) |
| 199 | .andReturn(interface1).anyTimes(); |
| 200 | expect(interfaceService.getInterfacesByPort(CONN_POINT2)).andReturn( |
| 201 | Collections.singleton(interface2)).anyTimes(); |
| 202 | expect(interfaceService.getMatchingInterface(Ip4Address.valueOf(PEER4_IP))) |
| 203 | .andReturn(interface1).anyTimes(); |
| 204 | expect(interfaceService.getInterfacesByPort(CONN_POINT4)).andReturn( |
| 205 | Collections.singleton(interface4)).anyTimes(); |
| 206 | |
| 207 | expect(interfaceService.getInterfaces()).andReturn(interfaces).anyTimes(); |
| 208 | } |
| 209 | |
| 210 | /** |
| 211 | * Sets up BGP peers in external networks. |
| 212 | */ |
| 213 | private void setUpBgpPeers() { |
Andreas Papazois | b85190b | 2016-02-05 09:44:31 -0800 | [diff] [blame] | 214 | expect(peerService.getInterfaceForPeer(IpAddress.valueOf(PEER1_IP))) |
| 215 | .andReturn(interface1).anyTimes(); |
| 216 | |
Andreas Papazois | b85190b | 2016-02-05 09:44:31 -0800 | [diff] [blame] | 217 | expect(peerService.getInterfaceForPeer(IpAddress.valueOf(PEER2_IP))) |
| 218 | .andReturn(interface2).anyTimes(); |
| 219 | |
Andreas Papazois | b85190b | 2016-02-05 09:44:31 -0800 | [diff] [blame] | 220 | expect(peerService.getInterfaceForPeer(IpAddress.valueOf(PEER3_IP))) |
| 221 | .andReturn(interface3).anyTimes(); |
| 222 | |
Andreas Papazois | b85190b | 2016-02-05 09:44:31 -0800 | [diff] [blame] | 223 | expect(peerService.getInterfaceForPeer(IpAddress.valueOf(PEER4_IP))) |
| 224 | .andReturn(null).anyTimes(); |
Andreas Papazois | b85190b | 2016-02-05 09:44:31 -0800 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | /** |
Andreas Papazois | eb51893 | 2016-06-21 13:46:20 +0300 | [diff] [blame^] | 228 | * Tests adding a route to the IntentSynchronizer. Peers within the same |
Andreas Papazois | b85190b | 2016-02-05 09:44:31 -0800 | [diff] [blame] | 229 | * subnet exist. |
| 230 | * |
| 231 | * We verify that the synchronizer records the correct state and that the |
| 232 | * correct intent is submitted to the IntentService. |
| 233 | */ |
| 234 | @Test |
Andreas Papazois | eb51893 | 2016-06-21 13:46:20 +0300 | [diff] [blame^] | 235 | public void testRouteAdd() { |
Andreas Papazois | b85190b | 2016-02-05 09:44:31 -0800 | [diff] [blame] | 236 | IpPrefix prefix = Ip4Prefix.valueOf("1.1.1.0/24"); |
Andreas Papazois | eb51893 | 2016-06-21 13:46:20 +0300 | [diff] [blame^] | 237 | ResolvedRoute route = new ResolvedRoute(prefix, |
| 238 | Ip4Address.valueOf(PEER1_IP), |
| 239 | MacAddress.valueOf(MAC1)); |
Andreas Papazois | b85190b | 2016-02-05 09:44:31 -0800 | [diff] [blame] | 240 | |
| 241 | // Construct a MultiPointToSinglePointIntent intent |
| 242 | TrafficSelector.Builder selectorBuilder = |
| 243 | DefaultTrafficSelector.builder(); |
Andreas Papazois | eb51893 | 2016-06-21 13:46:20 +0300 | [diff] [blame^] | 244 | selectorBuilder.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(prefix).matchVlanId(VlanId.ANY); |
Andreas Papazois | b85190b | 2016-02-05 09:44:31 -0800 | [diff] [blame] | 245 | |
| 246 | TrafficTreatment.Builder treatmentBuilder = |
| 247 | DefaultTrafficTreatment.builder(); |
Andreas Papazois | eb51893 | 2016-06-21 13:46:20 +0300 | [diff] [blame^] | 248 | treatmentBuilder.setEthDst(MacAddress.valueOf(MAC1)).popVlan(); |
Andreas Papazois | b85190b | 2016-02-05 09:44:31 -0800 | [diff] [blame] | 249 | |
| 250 | Set<ConnectPoint> ingressPoints = new HashSet<>(); |
| 251 | ingressPoints.add(CONN_POINT2); |
| 252 | ingressPoints.add(CONN_POINT3); |
| 253 | ingressPoints.add(CONN_POINT4); |
| 254 | |
| 255 | MultiPointToSinglePointIntent intent = |
| 256 | MultiPointToSinglePointIntent.builder() |
| 257 | .appId(APPID) |
| 258 | .key(Key.of(prefix.toString(), APPID)) |
| 259 | .selector(selectorBuilder.build()) |
| 260 | .treatment(treatmentBuilder.build()) |
| 261 | .ingressPoints(ingressPoints) |
| 262 | .egressPoint(CONN_POINT1) |
| 263 | .constraints(SdxL3Fib.CONSTRAINTS) |
| 264 | .build(); |
| 265 | |
| 266 | // Setup the expected intents |
| 267 | intentSynchronizer.submit(eqExceptId(intent)); |
| 268 | replay(intentSynchronizer); |
| 269 | |
Andreas Papazois | eb51893 | 2016-06-21 13:46:20 +0300 | [diff] [blame^] | 270 | // Send in the added event |
| 271 | routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_ADDED, route)); |
Andreas Papazois | b85190b | 2016-02-05 09:44:31 -0800 | [diff] [blame] | 272 | |
| 273 | verify(intentSynchronizer); |
| 274 | } |
| 275 | |
| 276 | /** |
Andreas Papazois | eb51893 | 2016-06-21 13:46:20 +0300 | [diff] [blame^] | 277 | * Tests adding a route entry with a next hop in a VLAN. |
Andreas Papazois | b85190b | 2016-02-05 09:44:31 -0800 | [diff] [blame] | 278 | * |
| 279 | * We verify that the synchronizer records the correct state and that the |
| 280 | * correct intent is submitted to the IntentService. |
| 281 | */ |
| 282 | @Test |
Andreas Papazois | eb51893 | 2016-06-21 13:46:20 +0300 | [diff] [blame^] | 283 | public void testRouteAddWithVlan() { |
Andreas Papazois | b85190b | 2016-02-05 09:44:31 -0800 | [diff] [blame] | 284 | IpPrefix prefix = Ip4Prefix.valueOf("1.1.1.0/24"); |
Andreas Papazois | eb51893 | 2016-06-21 13:46:20 +0300 | [diff] [blame^] | 285 | ResolvedRoute route = new ResolvedRoute(prefix, |
| 286 | Ip4Address.valueOf(PEER3_IP), |
| 287 | MacAddress.valueOf(MAC1)); |
Andreas Papazois | b85190b | 2016-02-05 09:44:31 -0800 | [diff] [blame] | 288 | |
| 289 | // Construct a MultiPointToSinglePointIntent intent |
| 290 | TrafficSelector.Builder selectorBuilder = |
| 291 | DefaultTrafficSelector.builder(); |
| 292 | selectorBuilder.matchEthType(Ethernet.TYPE_IPV4) |
Andreas Papazois | eb51893 | 2016-06-21 13:46:20 +0300 | [diff] [blame^] | 293 | .matchIPDst(prefix) |
Andreas Papazois | b85190b | 2016-02-05 09:44:31 -0800 | [diff] [blame] | 294 | .matchVlanId(VlanId.ANY); |
| 295 | |
| 296 | TrafficTreatment.Builder treatmentBuilder = |
| 297 | DefaultTrafficTreatment.builder(); |
| 298 | treatmentBuilder.setEthDst(MacAddress.valueOf(MAC1)) |
| 299 | .setVlanId(VlanId.vlanId((short) 1)); |
| 300 | |
| 301 | Set<ConnectPoint> ingressPoints = new HashSet<>(); |
| 302 | ingressPoints.add(CONN_POINT1); |
| 303 | ingressPoints.add(CONN_POINT2); |
| 304 | ingressPoints.add(CONN_POINT4); |
| 305 | |
| 306 | MultiPointToSinglePointIntent intent = |
| 307 | MultiPointToSinglePointIntent.builder() |
| 308 | .appId(APPID) |
| 309 | .key(Key.of(prefix.toString(), APPID)) |
| 310 | .selector(selectorBuilder.build()) |
| 311 | .treatment(treatmentBuilder.build()) |
| 312 | .ingressPoints(ingressPoints) |
| 313 | .egressPoint(CONN_POINT3) |
| 314 | .constraints(SdxL3Fib.CONSTRAINTS) |
| 315 | .build(); |
| 316 | |
| 317 | // Setup the expected intents |
| 318 | intentSynchronizer.submit(eqExceptId(intent)); |
| 319 | |
| 320 | replay(intentSynchronizer); |
| 321 | |
Andreas Papazois | eb51893 | 2016-06-21 13:46:20 +0300 | [diff] [blame^] | 322 | // Send in the added event |
| 323 | routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_ADDED, route)); |
Andreas Papazois | b85190b | 2016-02-05 09:44:31 -0800 | [diff] [blame] | 324 | |
| 325 | verify(intentSynchronizer); |
| 326 | } |
| 327 | |
| 328 | /** |
Andreas Papazois | eb51893 | 2016-06-21 13:46:20 +0300 | [diff] [blame^] | 329 | * Tests updating a route entry. |
Andreas Papazois | b85190b | 2016-02-05 09:44:31 -0800 | [diff] [blame] | 330 | * |
| 331 | * We verify that the synchronizer records the correct state and that the |
| 332 | * correct intent is submitted to the IntentService. |
| 333 | */ |
| 334 | @Test |
Andreas Papazois | eb51893 | 2016-06-21 13:46:20 +0300 | [diff] [blame^] | 335 | public void testRouteUpdate() { |
Andreas Papazois | b85190b | 2016-02-05 09:44:31 -0800 | [diff] [blame] | 336 | // Firstly add a route |
Andreas Papazois | eb51893 | 2016-06-21 13:46:20 +0300 | [diff] [blame^] | 337 | testRouteAdd(); |
Andreas Papazois | b85190b | 2016-02-05 09:44:31 -0800 | [diff] [blame] | 338 | |
| 339 | IpPrefix prefix = Ip4Prefix.valueOf("1.1.1.0/24"); |
| 340 | |
| 341 | // Start to construct a new route entry and new intent |
Andreas Papazois | eb51893 | 2016-06-21 13:46:20 +0300 | [diff] [blame^] | 342 | ResolvedRoute route = new ResolvedRoute(prefix, |
| 343 | Ip4Address.valueOf(PEER2_IP), |
| 344 | MacAddress.valueOf(MAC1)); |
Andreas Papazois | b85190b | 2016-02-05 09:44:31 -0800 | [diff] [blame] | 345 | |
| 346 | // Construct a new MultiPointToSinglePointIntent intent |
| 347 | TrafficSelector.Builder selectorBuilderNew = |
| 348 | DefaultTrafficSelector.builder(); |
Andreas Papazois | eb51893 | 2016-06-21 13:46:20 +0300 | [diff] [blame^] | 349 | selectorBuilderNew.matchEthType(Ethernet.TYPE_IPV4) |
| 350 | .matchIPDst(prefix) |
| 351 | .matchVlanId(VlanId.ANY); |
Andreas Papazois | b85190b | 2016-02-05 09:44:31 -0800 | [diff] [blame] | 352 | |
| 353 | TrafficTreatment.Builder treatmentBuilderNew = |
| 354 | DefaultTrafficTreatment.builder(); |
Andreas Papazois | eb51893 | 2016-06-21 13:46:20 +0300 | [diff] [blame^] | 355 | treatmentBuilderNew.setEthDst(MacAddress.valueOf(MAC1)).popVlan(); |
Andreas Papazois | b85190b | 2016-02-05 09:44:31 -0800 | [diff] [blame] | 356 | |
| 357 | Set<ConnectPoint> ingressPointsNew = new HashSet<>(); |
| 358 | ingressPointsNew.add(CONN_POINT1); |
| 359 | ingressPointsNew.add(CONN_POINT3); |
| 360 | ingressPointsNew.add(CONN_POINT4); |
| 361 | |
| 362 | MultiPointToSinglePointIntent intentNew = |
| 363 | MultiPointToSinglePointIntent.builder() |
| 364 | .appId(APPID) |
| 365 | .key(Key.of(prefix.toString(), APPID)) |
| 366 | .selector(selectorBuilderNew.build()) |
| 367 | .treatment(treatmentBuilderNew.build()) |
| 368 | .ingressPoints(ingressPointsNew) |
| 369 | .egressPoint(CONN_POINT2) |
| 370 | .constraints(SdxL3Fib.CONSTRAINTS) |
| 371 | .build(); |
| 372 | |
| 373 | // Set up test expectation |
| 374 | reset(intentSynchronizer); |
| 375 | |
| 376 | // Setup the expected intents |
| 377 | intentSynchronizer.submit(eqExceptId(intentNew)); |
| 378 | replay(intentSynchronizer); |
| 379 | |
Andreas Papazois | eb51893 | 2016-06-21 13:46:20 +0300 | [diff] [blame^] | 380 | // Send in the update event |
| 381 | routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_UPDATED, route)); |
Andreas Papazois | b85190b | 2016-02-05 09:44:31 -0800 | [diff] [blame] | 382 | |
| 383 | verify(intentSynchronizer); |
| 384 | } |
| 385 | |
| 386 | /** |
Andreas Papazois | eb51893 | 2016-06-21 13:46:20 +0300 | [diff] [blame^] | 387 | * Tests deleting a route entry. |
Andreas Papazois | b85190b | 2016-02-05 09:44:31 -0800 | [diff] [blame] | 388 | * |
| 389 | * We verify that the synchronizer records the correct state and that the |
| 390 | * correct intent is withdrawn from the IntentService. |
| 391 | */ |
| 392 | @Test |
Andreas Papazois | eb51893 | 2016-06-21 13:46:20 +0300 | [diff] [blame^] | 393 | public void testRouteDelete() { |
Andreas Papazois | b85190b | 2016-02-05 09:44:31 -0800 | [diff] [blame] | 394 | // Firstly add a route |
Andreas Papazois | eb51893 | 2016-06-21 13:46:20 +0300 | [diff] [blame^] | 395 | testRouteAdd(); |
Andreas Papazois | b85190b | 2016-02-05 09:44:31 -0800 | [diff] [blame] | 396 | |
| 397 | IpPrefix prefix = Ip4Prefix.valueOf("1.1.1.0/24"); |
| 398 | |
| 399 | // Construct the existing route entry |
Andreas Papazois | eb51893 | 2016-06-21 13:46:20 +0300 | [diff] [blame^] | 400 | ResolvedRoute route = new ResolvedRoute(prefix, null, null); |
Andreas Papazois | b85190b | 2016-02-05 09:44:31 -0800 | [diff] [blame] | 401 | |
| 402 | // Construct the existing MultiPointToSinglePoint intent |
| 403 | TrafficSelector.Builder selectorBuilder = |
| 404 | DefaultTrafficSelector.builder(); |
Andreas Papazois | eb51893 | 2016-06-21 13:46:20 +0300 | [diff] [blame^] | 405 | selectorBuilder.matchEthType(Ethernet.TYPE_IPV4) |
| 406 | .matchIPDst(prefix) |
| 407 | .matchVlanId(VlanId.ANY); |
Andreas Papazois | b85190b | 2016-02-05 09:44:31 -0800 | [diff] [blame] | 408 | |
| 409 | TrafficTreatment.Builder treatmentBuilder = |
| 410 | DefaultTrafficTreatment.builder(); |
Andreas Papazois | eb51893 | 2016-06-21 13:46:20 +0300 | [diff] [blame^] | 411 | treatmentBuilder.setEthDst(MacAddress.valueOf(MAC1)).popVlan(); |
Andreas Papazois | b85190b | 2016-02-05 09:44:31 -0800 | [diff] [blame] | 412 | |
| 413 | Set<ConnectPoint> ingressPoints = new HashSet<>(); |
| 414 | ingressPoints.add(CONN_POINT2); |
| 415 | ingressPoints.add(CONN_POINT3); |
| 416 | ingressPoints.add(CONN_POINT4); |
| 417 | |
| 418 | MultiPointToSinglePointIntent addedIntent = |
| 419 | MultiPointToSinglePointIntent.builder() |
| 420 | .appId(APPID) |
| 421 | .key(Key.of(prefix.toString(), APPID)) |
| 422 | .selector(selectorBuilder.build()) |
| 423 | .treatment(treatmentBuilder.build()) |
| 424 | .ingressPoints(ingressPoints) |
| 425 | .egressPoint(CONN_POINT1) |
| 426 | .constraints(SdxL3Fib.CONSTRAINTS) |
| 427 | .build(); |
| 428 | |
| 429 | // Set up expectation |
| 430 | reset(intentSynchronizer); |
| 431 | // Setup the expected intents |
| 432 | intentSynchronizer.withdraw(eqExceptId(addedIntent)); |
| 433 | replay(intentSynchronizer); |
| 434 | |
Andreas Papazois | eb51893 | 2016-06-21 13:46:20 +0300 | [diff] [blame^] | 435 | // Send in the removed event |
| 436 | routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_REMOVED, route)); |
Andreas Papazois | b85190b | 2016-02-05 09:44:31 -0800 | [diff] [blame] | 437 | |
| 438 | verify(intentSynchronizer); |
| 439 | } |
| 440 | |
| 441 | private class TestCoreService extends CoreServiceAdapter { |
| 442 | @Override |
| 443 | public ApplicationId getAppId(String name) { |
| 444 | return APPID; |
| 445 | } |
| 446 | } |
| 447 | |
Andreas Papazois | eb51893 | 2016-06-21 13:46:20 +0300 | [diff] [blame^] | 448 | private class TestRouteService extends RouteServiceAdapter { |
Andreas Papazois | b85190b | 2016-02-05 09:44:31 -0800 | [diff] [blame] | 449 | @Override |
Andreas Papazois | eb51893 | 2016-06-21 13:46:20 +0300 | [diff] [blame^] | 450 | public void addListener(RouteListener routeListener) { |
| 451 | SdxL3FibTest.this.routeListener = routeListener; |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | private class InterfaceServiceDelegate extends InterfaceServiceAdapter { |
| 456 | @Override |
| 457 | public void addListener(InterfaceListener listener) { |
| 458 | SdxL3FibTest.this.interfaceListener = listener; |
Andreas Papazois | b85190b | 2016-02-05 09:44:31 -0800 | [diff] [blame] | 459 | } |
| 460 | } |
| 461 | } |