blob: 37c50d317194ce87aa4c38623dba46bc0980d144 [file] [log] [blame]
alshabibab984662014-12-04 18:56:18 -08001/*
Ray Milkey34c95902015-04-15 09:47:53 -07002 * Copyright 2014-2015 Open Networking Laboratory
alshabibab984662014-12-04 18:56:18 -08003 *
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 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.sdnip;
Pingpingf5d90932014-10-27 10:50:04 -070017
Jonathan Hart552e31f2015-02-06 11:11:59 -080018import com.google.common.collect.Sets;
Jonathan Hart9a426f82015-09-03 15:43:13 +020019import com.google.common.util.concurrent.MoreExecutors;
Pingpingf5d90932014-10-27 10:50:04 -070020import org.junit.Before;
21import org.junit.Test;
22import org.onlab.junit.TestUtils;
23import org.onlab.junit.TestUtils.TestUtilsException;
Jonathan Hart6cd2f352015-01-13 17:44:45 -080024import org.onlab.packet.Ethernet;
25import org.onlab.packet.Ip4Address;
26import org.onlab.packet.Ip4Prefix;
27import org.onlab.packet.IpAddress;
28import org.onlab.packet.IpPrefix;
29import org.onlab.packet.MacAddress;
30import org.onlab.packet.VlanId;
Jonathan Hart9a426f82015-09-03 15:43:13 +020031import org.onosproject.TestApplicationId;
Jonathan Hart365335e2015-12-10 11:09:53 -080032import org.onosproject.cluster.LeadershipServiceAdapter;
Brian O'Connorabafb502014-12-02 22:26:20 -080033import org.onosproject.core.ApplicationId;
Jonathan Hart365335e2015-12-10 11:09:53 -080034import org.onosproject.core.CoreServiceAdapter;
Jonathan Hart4cb39882015-08-12 23:50:55 -040035import org.onosproject.incubator.net.intf.Interface;
Brian O'Connorabafb502014-12-02 22:26:20 -080036import org.onosproject.net.ConnectPoint;
Brian O'Connorabafb502014-12-02 22:26:20 -080037import org.onosproject.net.DeviceId;
Brian O'Connorabafb502014-12-02 22:26:20 -080038import org.onosproject.net.PortNumber;
39import org.onosproject.net.flow.DefaultTrafficSelector;
40import org.onosproject.net.flow.DefaultTrafficTreatment;
41import org.onosproject.net.flow.TrafficSelector;
42import org.onosproject.net.flow.TrafficTreatment;
Brian O'Connorabafb502014-12-02 22:26:20 -080043import org.onosproject.net.host.InterfaceIpAddress;
44import org.onosproject.net.intent.AbstractIntentTest;
45import org.onosproject.net.intent.Intent;
Brian O'Connorabafb502014-12-02 22:26:20 -080046import org.onosproject.net.intent.IntentService;
47import org.onosproject.net.intent.IntentState;
Jonathan Hart365335e2015-12-10 11:09:53 -080048import org.onosproject.net.intent.IntentUtils;
Jonathan Hart9a426f82015-09-03 15:43:13 +020049import org.onosproject.net.intent.Key;
Brian O'Connorabafb502014-12-02 22:26:20 -080050import org.onosproject.net.intent.MultiPointToSinglePointIntent;
Jonathan Hart2da1e602015-02-18 19:09:24 -080051import org.onosproject.routing.RouteEntry;
Pingpingf5d90932014-10-27 10:50:04 -070052
Jonathan Hart41349e92015-02-09 14:14:02 -080053import java.util.Collections;
Jonathan Hart552e31f2015-02-06 11:11:59 -080054import java.util.HashSet;
55import java.util.Set;
Jonathan Hart365335e2015-12-10 11:09:53 -080056import java.util.concurrent.ExecutorService;
Jonathan Hart552e31f2015-02-06 11:11:59 -080057
Jonathan Hart4cb39882015-08-12 23:50:55 -040058import static org.easymock.EasyMock.createMock;
59import static org.easymock.EasyMock.expect;
60import static org.easymock.EasyMock.replay;
61import static org.easymock.EasyMock.reset;
62import static org.easymock.EasyMock.verify;
Jonathan Hart552e31f2015-02-06 11:11:59 -080063import static org.hamcrest.Matchers.is;
Jonathan Hartcb726fc2015-02-13 16:26:22 -080064import static org.junit.Assert.assertFalse;
65import static org.junit.Assert.assertThat;
Pingpingf5d90932014-10-27 10:50:04 -070066
67/**
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -080068 * This class tests the intent synchronization function in the
69 * IntentSynchronizer class.
Pingpingf5d90932014-10-27 10:50:04 -070070 */
Brian O'Connor520c0522014-11-23 23:50:47 -080071public class IntentSyncTest extends AbstractIntentTest {
Pingpingf5d90932014-10-27 10:50:04 -070072
Pingpingf5d90932014-10-27 10:50:04 -070073 private IntentService intentService;
Pingpingf5d90932014-10-27 10:50:04 -070074
75 private static final ConnectPoint SW1_ETH1 = new ConnectPoint(
76 DeviceId.deviceId("of:0000000000000001"),
77 PortNumber.portNumber(1));
78
79 private static final ConnectPoint SW2_ETH1 = new ConnectPoint(
80 DeviceId.deviceId("of:0000000000000002"),
81 PortNumber.portNumber(1));
82
83 private static final ConnectPoint SW3_ETH1 = new ConnectPoint(
84 DeviceId.deviceId("of:0000000000000003"),
85 PortNumber.portNumber(1));
86
Jonathan Hart41349e92015-02-09 14:14:02 -080087 private static final ConnectPoint SW4_ETH1 = new ConnectPoint(
88 DeviceId.deviceId("of:0000000000000004"),
89 PortNumber.portNumber(1));
90
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -080091 private IntentSynchronizer intentSynchronizer;
Jonathan Hart4cb39882015-08-12 23:50:55 -040092 private final Set<Interface> interfaces = Sets.newHashSet();
Pingpingf5d90932014-10-27 10:50:04 -070093
Jonathan Hart365335e2015-12-10 11:09:53 -080094 private static final ApplicationId APPID =
95 TestApplicationId.create("intent-sync-test");
Pingpingf5d90932014-10-27 10:50:04 -070096
97 @Before
98 public void setUp() throws Exception {
Brian O'Connor520c0522014-11-23 23:50:47 -080099 super.setUp();
Jonathan Hart41349e92015-02-09 14:14:02 -0800100
Jonathan Hart90a02c22015-02-13 11:52:07 -0800101 setUpInterfaceService();
Jonathan Hart90a02c22015-02-13 11:52:07 -0800102
Pingpingf5d90932014-10-27 10:50:04 -0700103 intentService = createMock(IntentService.class);
104
Jonathan Hart365335e2015-12-10 11:09:53 -0800105 intentSynchronizer = new TestIntentSynchronizer();
106
107 intentSynchronizer.coreService = new TestCoreService();
108 intentSynchronizer.leadershipService = new TestLeadershipService();
109 intentSynchronizer.intentService = intentService;
110
111 intentSynchronizer.activate();
Pingpingf5d90932014-10-27 10:50:04 -0700112 }
113
114 /**
115 * Sets up InterfaceService.
116 */
117 private void setUpInterfaceService() {
Pingpingf5d90932014-10-27 10:50:04 -0700118 Set<InterfaceIpAddress> interfaceIpAddresses1 = Sets.newHashSet();
119 interfaceIpAddresses1.add(new InterfaceIpAddress(
120 IpAddress.valueOf("192.168.10.101"),
121 IpPrefix.valueOf("192.168.10.0/24")));
122 Interface sw1Eth1 = new Interface(SW1_ETH1,
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800123 interfaceIpAddresses1, MacAddress.valueOf("00:00:00:00:00:01"),
124 VlanId.NONE);
Pingpingf5d90932014-10-27 10:50:04 -0700125 interfaces.add(sw1Eth1);
126
127 Set<InterfaceIpAddress> interfaceIpAddresses2 = Sets.newHashSet();
Jonathan Hart41349e92015-02-09 14:14:02 -0800128 interfaceIpAddresses2.add(
129 new InterfaceIpAddress(IpAddress.valueOf("192.168.20.101"),
130 IpPrefix.valueOf("192.168.20.0/24")));
Pingpingf5d90932014-10-27 10:50:04 -0700131 Interface sw2Eth1 = new Interface(SW2_ETH1,
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800132 interfaceIpAddresses2, MacAddress.valueOf("00:00:00:00:00:02"),
133 VlanId.NONE);
Pingpingf5d90932014-10-27 10:50:04 -0700134 interfaces.add(sw2Eth1);
135
136 Set<InterfaceIpAddress> interfaceIpAddresses3 = Sets.newHashSet();
Jonathan Hart41349e92015-02-09 14:14:02 -0800137 interfaceIpAddresses3.add(
138 new InterfaceIpAddress(IpAddress.valueOf("192.168.30.101"),
139 IpPrefix.valueOf("192.168.30.0/24")));
Pingpingf5d90932014-10-27 10:50:04 -0700140 Interface sw3Eth1 = new Interface(SW3_ETH1,
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800141 interfaceIpAddresses3, MacAddress.valueOf("00:00:00:00:00:03"),
142 VlanId.NONE);
Pingpingf5d90932014-10-27 10:50:04 -0700143 interfaces.add(sw3Eth1);
144
Jonathan Hart41349e92015-02-09 14:14:02 -0800145 InterfaceIpAddress interfaceIpAddress4 =
146 new InterfaceIpAddress(IpAddress.valueOf("192.168.40.101"),
147 IpPrefix.valueOf("192.168.40.0/24"));
148 Interface sw4Eth1 = new Interface(SW4_ETH1,
149 Sets.newHashSet(interfaceIpAddress4),
150 MacAddress.valueOf("00:00:00:00:00:04"),
151 VlanId.vlanId((short) 1));
152
Jonathan Hart41349e92015-02-09 14:14:02 -0800153 interfaces.add(sw4Eth1);
Pingpingf5d90932014-10-27 10:50:04 -0700154 }
155
156 /**
Jonathan Hart9a426f82015-09-03 15:43:13 +0200157 * Tests the synchronization behavior of intent synchronizer. We set up
158 * a discrepancy between the intent service state and the intent
159 * synchronizer's state and ensure that this is reconciled correctly.
Pingpingf5d90932014-10-27 10:50:04 -0700160 *
161 * @throws TestUtilsException
162 */
163 @Test
164 public void testIntentSync() throws TestUtilsException {
165
166 //
167 // Construct routes and intents.
168 // This test simulates the following cases during the master change
169 // time interval:
170 // 1. RouteEntry1 did not change and the intent also did not change.
171 // 2. RouteEntry2 was deleted, but the intent was not deleted.
172 // 3. RouteEntry3 was newly added, and the intent was also submitted.
173 // 4. RouteEntry4 was updated to RouteEntry4Update, and the intent was
174 // also updated to a new one.
175 // 5. RouteEntry5 did not change, but its intent id changed.
176 // 6. RouteEntry6 was newly added, but the intent was not submitted.
177 //
178 RouteEntry routeEntry1 = new RouteEntry(
Pavlin Radoslavov6b570732014-11-06 13:16:45 -0800179 Ip4Prefix.valueOf("1.1.1.0/24"),
180 Ip4Address.valueOf("192.168.10.1"));
Pingpingf5d90932014-10-27 10:50:04 -0700181
182 RouteEntry routeEntry2 = new RouteEntry(
Pavlin Radoslavov6b570732014-11-06 13:16:45 -0800183 Ip4Prefix.valueOf("2.2.2.0/24"),
184 Ip4Address.valueOf("192.168.20.1"));
Pingpingf5d90932014-10-27 10:50:04 -0700185
186 RouteEntry routeEntry3 = new RouteEntry(
Pavlin Radoslavov6b570732014-11-06 13:16:45 -0800187 Ip4Prefix.valueOf("3.3.3.0/24"),
188 Ip4Address.valueOf("192.168.30.1"));
Pingpingf5d90932014-10-27 10:50:04 -0700189
190 RouteEntry routeEntry4 = new RouteEntry(
Pavlin Radoslavov6b570732014-11-06 13:16:45 -0800191 Ip4Prefix.valueOf("4.4.4.0/24"),
192 Ip4Address.valueOf("192.168.30.1"));
Pingpingf5d90932014-10-27 10:50:04 -0700193
194 RouteEntry routeEntry4Update = new RouteEntry(
Pavlin Radoslavov6b570732014-11-06 13:16:45 -0800195 Ip4Prefix.valueOf("4.4.4.0/24"),
196 Ip4Address.valueOf("192.168.20.1"));
Pingpingf5d90932014-10-27 10:50:04 -0700197
198 RouteEntry routeEntry5 = new RouteEntry(
Pavlin Radoslavov6b570732014-11-06 13:16:45 -0800199 Ip4Prefix.valueOf("5.5.5.0/24"),
200 Ip4Address.valueOf("192.168.10.1"));
Pingpingf5d90932014-10-27 10:50:04 -0700201
202 RouteEntry routeEntry6 = new RouteEntry(
Pavlin Radoslavov6b570732014-11-06 13:16:45 -0800203 Ip4Prefix.valueOf("6.6.6.0/24"),
204 Ip4Address.valueOf("192.168.10.1"));
Pingpingf5d90932014-10-27 10:50:04 -0700205
Jonathan Hartec2df012014-10-23 16:40:24 -0700206 RouteEntry routeEntry7 = new RouteEntry(
Pavlin Radoslavov6b570732014-11-06 13:16:45 -0800207 Ip4Prefix.valueOf("7.7.7.0/24"),
208 Ip4Address.valueOf("192.168.10.1"));
Jonathan Hartec2df012014-10-23 16:40:24 -0700209
Pingpingf5d90932014-10-27 10:50:04 -0700210 MultiPointToSinglePointIntent intent1 = intentBuilder(
211 routeEntry1.prefix(), "00:00:00:00:00:01", SW1_ETH1);
212 MultiPointToSinglePointIntent intent2 = intentBuilder(
213 routeEntry2.prefix(), "00:00:00:00:00:02", SW2_ETH1);
214 MultiPointToSinglePointIntent intent3 = intentBuilder(
215 routeEntry3.prefix(), "00:00:00:00:00:03", SW3_ETH1);
216 MultiPointToSinglePointIntent intent4 = intentBuilder(
217 routeEntry4.prefix(), "00:00:00:00:00:03", SW3_ETH1);
218 MultiPointToSinglePointIntent intent4Update = intentBuilder(
219 routeEntry4Update.prefix(), "00:00:00:00:00:02", SW2_ETH1);
220 MultiPointToSinglePointIntent intent5 = intentBuilder(
221 routeEntry5.prefix(), "00:00:00:00:00:01", SW1_ETH1);
Jonathan Hartec2df012014-10-23 16:40:24 -0700222 MultiPointToSinglePointIntent intent7 = intentBuilder(
223 routeEntry7.prefix(), "00:00:00:00:00:01", SW1_ETH1);
Pingpingf5d90932014-10-27 10:50:04 -0700224
225 // Compose a intent, which is equal to intent5 but the id is different.
226 MultiPointToSinglePointIntent intent5New =
227 staticIntentBuilder(intent5, routeEntry5, "00:00:00:00:00:01");
Ray Milkey4fd3ceb2015-12-10 14:43:08 -0800228 assertThat(IntentUtils.intentsAreEqual(intent5, intent5New), is(true));
Jonathan Hartec2df012014-10-23 16:40:24 -0700229 assertFalse(intent5.equals(intent5New));
Pingpingf5d90932014-10-27 10:50:04 -0700230
231 MultiPointToSinglePointIntent intent6 = intentBuilder(
232 routeEntry6.prefix(), "00:00:00:00:00:01", SW1_ETH1);
233
Pingpingf5d90932014-10-27 10:50:04 -0700234 // Set up expectation
Jonathan Hart90a02c22015-02-13 11:52:07 -0800235 Set<Intent> intents = new HashSet<>();
Pingpingf5d90932014-10-27 10:50:04 -0700236 intents.add(intent1);
Ray Milkeyf9af43c2015-02-09 16:45:48 -0800237 expect(intentService.getIntentState(intent1.key()))
Jonathan Hartec2df012014-10-23 16:40:24 -0700238 .andReturn(IntentState.INSTALLED).anyTimes();
Pingpingf5d90932014-10-27 10:50:04 -0700239 intents.add(intent2);
Ray Milkeyf9af43c2015-02-09 16:45:48 -0800240 expect(intentService.getIntentState(intent2.key()))
Jonathan Hartec2df012014-10-23 16:40:24 -0700241 .andReturn(IntentState.INSTALLED).anyTimes();
Pingpingf5d90932014-10-27 10:50:04 -0700242 intents.add(intent4);
Ray Milkeyf9af43c2015-02-09 16:45:48 -0800243 expect(intentService.getIntentState(intent4.key()))
Jonathan Hartec2df012014-10-23 16:40:24 -0700244 .andReturn(IntentState.INSTALLED).anyTimes();
Pingpingf5d90932014-10-27 10:50:04 -0700245 intents.add(intent5);
Ray Milkeyf9af43c2015-02-09 16:45:48 -0800246 expect(intentService.getIntentState(intent5.key()))
Jonathan Hartec2df012014-10-23 16:40:24 -0700247 .andReturn(IntentState.INSTALLED).anyTimes();
248 intents.add(intent7);
Ray Milkeyf9af43c2015-02-09 16:45:48 -0800249 expect(intentService.getIntentState(intent7.key()))
Jonathan Hartec2df012014-10-23 16:40:24 -0700250 .andReturn(IntentState.WITHDRAWING).anyTimes();
Pingpingf5d90932014-10-27 10:50:04 -0700251 expect(intentService.getIntents()).andReturn(intents).anyTimes();
252
Jonathan Hart9a426f82015-09-03 15:43:13 +0200253 // These are the operations that should be done to the intentService
254 // during synchronization
Brian O'Connor03406a42015-02-03 17:28:57 -0800255 intentService.withdraw(intent2);
Brian O'Connor03406a42015-02-03 17:28:57 -0800256 intentService.submit(intent3);
257 intentService.submit(intent4Update);
258 intentService.submit(intent6);
259 intentService.submit(intent7);
Pingpingf5d90932014-10-27 10:50:04 -0700260 replay(intentService);
261
262 // Start the test
Pingpingf5d90932014-10-27 10:50:04 -0700263
Jonathan Hart9a426f82015-09-03 15:43:13 +0200264 // Simulate some input from the clients. The intent synchronizer has not
265 // gained the global leadership yet, but it will remember this input for
266 // when it does.
267 intentSynchronizer.submit(intent1);
268 intentSynchronizer.submit(intent2);
269 intentSynchronizer.withdraw(intent2);
270 intentSynchronizer.submit(intent3);
271 intentSynchronizer.submit(intent4);
272 intentSynchronizer.submit(intent4Update);
273 intentSynchronizer.submit(intent5);
274 intentSynchronizer.submit(intent6);
275 intentSynchronizer.submit(intent7);
276
277 // Give the leadership to the intent synchronizer. It will now attempt
278 // to synchronize the intents in the store with the intents it has
279 // recorded based on the earlier user input.
Jonathan Hart365335e2015-12-10 11:09:53 -0800280 intentSynchronizer.modifyPrimary(true);
Jonathan Hart9a426f82015-09-03 15:43:13 +0200281
282 verify(intentService);
283 }
284
285 /**
286 * Tests the behavior of the submit API, both when the synchronizer has
287 * leadership and when it does not.
288 */
289 @Test
290 public void testSubmit() {
291 IpPrefix prefix = Ip4Prefix.valueOf("1.1.1.0/24");
292 Intent intent = intentBuilder(prefix, "00:00:00:00:00:01", SW1_ETH1);
293
294 // Set up expectations
295 intentService.submit(intent);
296 expect(intentService.getIntents()).andReturn(Collections.emptyList())
297 .anyTimes();
298 replay(intentService);
299
300 // Give the intent synchronizer leadership so it will submit intents
301 // to the intent service
Jonathan Hart365335e2015-12-10 11:09:53 -0800302 intentSynchronizer.modifyPrimary(true);
Jonathan Hart9a426f82015-09-03 15:43:13 +0200303
304 // Test the submit
305 intentSynchronizer.submit(intent);
306
307 verify(intentService);
308
309 // Now we'll remove leadership from the intent synchronizer and verify
310 // that it does not submit any intents to the intent service when we
311 // call the submit API
312 reset(intentService);
313 replay(intentService);
314
Jonathan Hart365335e2015-12-10 11:09:53 -0800315 intentSynchronizer.modifyPrimary(false);
Jonathan Hart9a426f82015-09-03 15:43:13 +0200316
317 intentSynchronizer.submit(intent);
318
319 verify(intentService);
320 }
321
322 /**
323 * Tests the behavior of the withdraw API, both when the synchronizer has
324 * leadership and when it does not.
325 */
326 @Test
327 public void testWithdraw() {
328 IpPrefix prefix = Ip4Prefix.valueOf("1.1.1.0/24");
329 Intent intent = intentBuilder(prefix, "00:00:00:00:00:01", SW1_ETH1);
330
331 // Submit an intent first so we can withdraw it later
332 intentService.submit(intent);
333 intentService.withdraw(intent);
334 expect(intentService.getIntents()).andReturn(Collections.emptyList())
335 .anyTimes();
336 replay(intentService);
337
338 // Give the intent synchronizer leadership so it will submit intents
339 // to the intent service
Jonathan Hart365335e2015-12-10 11:09:53 -0800340 intentSynchronizer.modifyPrimary(true);
Jonathan Hart9a426f82015-09-03 15:43:13 +0200341
342 // Test the submit then withdraw
343 intentSynchronizer.submit(intent);
344 intentSynchronizer.withdraw(intent);
345
346 verify(intentService);
347
348 // Now we'll remove leadership from the intent synchronizer and verify
349 // that it does not withdraw any intents to the intent service when we
350 // call the withdraw API
351 reset(intentService);
352 replay(intentService);
353
Jonathan Hart365335e2015-12-10 11:09:53 -0800354 intentSynchronizer.modifyPrimary(false);
Jonathan Hart9a426f82015-09-03 15:43:13 +0200355
356 intentSynchronizer.submit(intent);
357 intentSynchronizer.withdraw(intent);
Pingpingf5d90932014-10-27 10:50:04 -0700358
359 verify(intentService);
360 }
361
362 /**
363 * MultiPointToSinglePointIntent builder.
364 *
365 * @param ipPrefix the ipPrefix to match
366 * @param nextHopMacAddress to which the destination MAC address in packet
367 * should be rewritten
368 * @param egressPoint to which packets should be sent
369 * @return the constructed MultiPointToSinglePointIntent
370 */
Pavlin Radoslavov3a0a52e2015-01-06 17:41:37 -0800371 private MultiPointToSinglePointIntent intentBuilder(IpPrefix ipPrefix,
Pingpingf5d90932014-10-27 10:50:04 -0700372 String nextHopMacAddress, ConnectPoint egressPoint) {
373
374 TrafficSelector.Builder selectorBuilder =
375 DefaultTrafficSelector.builder();
Pavlin Radoslavov87dd9302015-03-10 13:53:24 -0700376 if (ipPrefix.isIp4()) {
Jonathan Hart9a426f82015-09-03 15:43:13 +0200377 selectorBuilder.matchEthType(Ethernet.TYPE_IPV4);
Pavlin Radoslavova8537092015-02-23 10:15:20 -0800378 selectorBuilder.matchIPDst(ipPrefix);
Pavlin Radoslavov3a0a52e2015-01-06 17:41:37 -0800379 } else {
Jonathan Hart9a426f82015-09-03 15:43:13 +0200380 selectorBuilder.matchEthType(Ethernet.TYPE_IPV6);
Pavlin Radoslavova8537092015-02-23 10:15:20 -0800381 selectorBuilder.matchIPv6Dst(ipPrefix);
Pavlin Radoslavov3a0a52e2015-01-06 17:41:37 -0800382 }
Pingpingf5d90932014-10-27 10:50:04 -0700383
384 TrafficTreatment.Builder treatmentBuilder =
385 DefaultTrafficTreatment.builder();
386 treatmentBuilder.setEthDst(MacAddress.valueOf(nextHopMacAddress));
387
Jonathan Hart90a02c22015-02-13 11:52:07 -0800388 Set<ConnectPoint> ingressPoints = new HashSet<>();
Jonathan Hart4cb39882015-08-12 23:50:55 -0400389 for (Interface intf : interfaces) {
390 if (!intf.connectPoint().equals(egressPoint)) {
Pingpingf5d90932014-10-27 10:50:04 -0700391 ConnectPoint srcPort = intf.connectPoint();
392 ingressPoints.add(srcPort);
393 }
394 }
395 MultiPointToSinglePointIntent intent =
Ray Milkeyebc5d222015-03-18 15:45:36 -0700396 MultiPointToSinglePointIntent.builder()
397 .appId(APPID)
Jonathan Hart9a426f82015-09-03 15:43:13 +0200398 .key(Key.of(ipPrefix.toString(), APPID))
Ray Milkeyebc5d222015-03-18 15:45:36 -0700399 .selector(selectorBuilder.build())
400 .treatment(treatmentBuilder.build())
401 .ingressPoints(ingressPoints)
402 .egressPoint(egressPoint)
Jonathan Hart9a426f82015-09-03 15:43:13 +0200403 .constraints(SdnIpFib.CONSTRAINTS)
Ray Milkeyebc5d222015-03-18 15:45:36 -0700404 .build();
Pingpingf5d90932014-10-27 10:50:04 -0700405 return intent;
406 }
407
408 /**
409 * A static MultiPointToSinglePointIntent builder, the returned intent is
410 * equal to the input intent except that the id is different.
411 *
Pingpingf5d90932014-10-27 10:50:04 -0700412 * @param intent the intent to be used for building a new intent
413 * @param routeEntry the relative routeEntry of the intent
414 * @return the newly constructed MultiPointToSinglePointIntent
415 * @throws TestUtilsException
416 */
Jonathan Hart9a426f82015-09-03 15:43:13 +0200417 private MultiPointToSinglePointIntent staticIntentBuilder(
Pingpingf5d90932014-10-27 10:50:04 -0700418 MultiPointToSinglePointIntent intent, RouteEntry routeEntry,
419 String nextHopMacAddress) throws TestUtilsException {
420
421 // Use a different egress ConnectPoint with that in intent
422 // to generate a different id
423 MultiPointToSinglePointIntent intentNew = intentBuilder(
424 routeEntry.prefix(), nextHopMacAddress, SW2_ETH1);
425 TestUtils.setField(intentNew, "egressPoint", intent.egressPoint());
426 TestUtils.setField(intentNew,
427 "ingressPoints", intent.ingressPoints());
428 return intentNew;
429 }
Jonathan Hart365335e2015-12-10 11:09:53 -0800430
431 private class TestIntentSynchronizer extends IntentSynchronizer {
432 @Override
433 protected ExecutorService createExecutor() {
434 return MoreExecutors.newDirectExecutorService();
435 }
436 }
437
438 private class TestCoreService extends CoreServiceAdapter {
439 @Override
440 public ApplicationId registerApplication(String name) {
441 return APPID;
442 }
443 }
444
445 private class TestLeadershipService extends LeadershipServiceAdapter {
446
447 }
Pingpingf5d90932014-10-27 10:50:04 -0700448}