blob: 9960481a2edc9a6052b153a8ba6704bdcc96a8a4 [file] [log] [blame]
alshabibab984662014-12-04 18:56:18 -08001/*
2 * Copyright 2014 Open Networking Laboratory
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 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.sdnip;
Pingpingf5d90932014-10-27 10:50:04 -070017
18import static org.easymock.EasyMock.anyObject;
19import static org.easymock.EasyMock.createMock;
20import static org.easymock.EasyMock.expect;
21import static org.easymock.EasyMock.expectLastCall;
22import static org.easymock.EasyMock.replay;
23import static org.easymock.EasyMock.reset;
24import static org.easymock.EasyMock.verify;
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -080025import static org.hamcrest.Matchers.is;
Pingpingf5d90932014-10-27 10:50:04 -070026import static org.junit.Assert.assertEquals;
Jonathan Hartec2df012014-10-23 16:40:24 -070027import static org.junit.Assert.assertFalse;
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -080028import static org.junit.Assert.assertThat;
Pingpingf5d90932014-10-27 10:50:04 -070029import static org.junit.Assert.assertTrue;
30
31import java.util.HashSet;
32import java.util.Set;
33import java.util.concurrent.ConcurrentHashMap;
34
35import org.junit.Before;
36import org.junit.Test;
37import org.onlab.junit.TestUtils;
38import org.onlab.junit.TestUtils.TestUtilsException;
Jonathan Hart6cd2f352015-01-13 17:44:45 -080039import org.onlab.packet.Ethernet;
40import org.onlab.packet.Ip4Address;
41import org.onlab.packet.Ip4Prefix;
42import org.onlab.packet.IpAddress;
43import org.onlab.packet.IpPrefix;
44import org.onlab.packet.MacAddress;
45import org.onlab.packet.VlanId;
Brian O'Connorabafb502014-12-02 22:26:20 -080046import org.onosproject.core.ApplicationId;
47import org.onosproject.net.ConnectPoint;
48import org.onosproject.net.DefaultHost;
49import org.onosproject.net.DeviceId;
50import org.onosproject.net.Host;
51import org.onosproject.net.HostId;
52import org.onosproject.net.HostLocation;
53import org.onosproject.net.PortNumber;
54import org.onosproject.net.flow.DefaultTrafficSelector;
55import org.onosproject.net.flow.DefaultTrafficTreatment;
56import org.onosproject.net.flow.TrafficSelector;
57import org.onosproject.net.flow.TrafficTreatment;
58import org.onosproject.net.host.HostListener;
59import org.onosproject.net.host.HostService;
60import org.onosproject.net.host.InterfaceIpAddress;
61import org.onosproject.net.intent.AbstractIntentTest;
62import org.onosproject.net.intent.Intent;
63import org.onosproject.net.intent.IntentOperations;
64import org.onosproject.net.intent.IntentService;
65import org.onosproject.net.intent.IntentState;
66import org.onosproject.net.intent.MultiPointToSinglePointIntent;
67import org.onosproject.net.provider.ProviderId;
68import org.onosproject.sdnip.config.Interface;
Pingpingf5d90932014-10-27 10:50:04 -070069
70import com.google.common.collect.Sets;
71import com.googlecode.concurrenttrees.radix.node.concrete.DefaultByteArrayNodeFactory;
72import com.googlecode.concurrenttrees.radixinverted.ConcurrentInvertedRadixTree;
73import com.googlecode.concurrenttrees.radixinverted.InvertedRadixTree;
74
75/**
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -080076 * This class tests the intent synchronization function in the
77 * IntentSynchronizer class.
Pingpingf5d90932014-10-27 10:50:04 -070078 */
Brian O'Connor520c0522014-11-23 23:50:47 -080079public class IntentSyncTest extends AbstractIntentTest {
Pingpingf5d90932014-10-27 10:50:04 -070080
81 private InterfaceService interfaceService;
82 private IntentService intentService;
83 private HostService hostService;
84
85 private static final ConnectPoint SW1_ETH1 = new ConnectPoint(
86 DeviceId.deviceId("of:0000000000000001"),
87 PortNumber.portNumber(1));
88
89 private static final ConnectPoint SW2_ETH1 = new ConnectPoint(
90 DeviceId.deviceId("of:0000000000000002"),
91 PortNumber.portNumber(1));
92
93 private static final ConnectPoint SW3_ETH1 = new ConnectPoint(
94 DeviceId.deviceId("of:0000000000000003"),
95 PortNumber.portNumber(1));
96
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -080097 private IntentSynchronizer intentSynchronizer;
Pingpingf5d90932014-10-27 10:50:04 -070098 private Router router;
99
100 private static final ApplicationId APPID = new ApplicationId() {
101 @Override
102 public short id() {
103 return 1;
104 }
105
106 @Override
107 public String name() {
108 return "SDNIP";
109 }
110 };
111
112 @Before
113 public void setUp() throws Exception {
Brian O'Connor520c0522014-11-23 23:50:47 -0800114 super.setUp();
Pingpingf5d90932014-10-27 10:50:04 -0700115 setUpInterfaceService();
116 setUpHostService();
117 intentService = createMock(IntentService.class);
118
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800119 intentSynchronizer = new IntentSynchronizer(APPID, intentService);
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800120 router = new Router(APPID, intentSynchronizer, null, interfaceService,
121 hostService);
Pingpingf5d90932014-10-27 10:50:04 -0700122 }
123
124 /**
125 * Sets up InterfaceService.
126 */
127 private void setUpInterfaceService() {
128
129 interfaceService = createMock(InterfaceService.class);
130
131 Set<Interface> interfaces = Sets.newHashSet();
132
133 Set<InterfaceIpAddress> interfaceIpAddresses1 = Sets.newHashSet();
134 interfaceIpAddresses1.add(new InterfaceIpAddress(
135 IpAddress.valueOf("192.168.10.101"),
136 IpPrefix.valueOf("192.168.10.0/24")));
137 Interface sw1Eth1 = new Interface(SW1_ETH1,
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800138 interfaceIpAddresses1, MacAddress.valueOf("00:00:00:00:00:01"),
139 VlanId.NONE);
Pingpingf5d90932014-10-27 10:50:04 -0700140 interfaces.add(sw1Eth1);
141
142 Set<InterfaceIpAddress> interfaceIpAddresses2 = Sets.newHashSet();
143 interfaceIpAddresses2.add(new InterfaceIpAddress(
144 IpAddress.valueOf("192.168.20.101"),
145 IpPrefix.valueOf("192.168.20.0/24")));
146 Interface sw2Eth1 = new Interface(SW2_ETH1,
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800147 interfaceIpAddresses2, MacAddress.valueOf("00:00:00:00:00:02"),
148 VlanId.NONE);
Pingpingf5d90932014-10-27 10:50:04 -0700149 interfaces.add(sw2Eth1);
150
151 Set<InterfaceIpAddress> interfaceIpAddresses3 = Sets.newHashSet();
152 interfaceIpAddresses3.add(new InterfaceIpAddress(
153 IpAddress.valueOf("192.168.30.101"),
154 IpPrefix.valueOf("192.168.30.0/24")));
155 Interface sw3Eth1 = new Interface(SW3_ETH1,
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800156 interfaceIpAddresses3, MacAddress.valueOf("00:00:00:00:00:03"),
157 VlanId.NONE);
Pingpingf5d90932014-10-27 10:50:04 -0700158 interfaces.add(sw3Eth1);
159
160 expect(interfaceService.getInterface(SW1_ETH1)).andReturn(
161 sw1Eth1).anyTimes();
162 expect(interfaceService.getInterface(SW2_ETH1)).andReturn(
163 sw2Eth1).anyTimes();
164 expect(interfaceService.getInterface(SW3_ETH1)).andReturn(
165 sw3Eth1).anyTimes();
166 expect(interfaceService.getInterfaces()).andReturn(
167 interfaces).anyTimes();
168 replay(interfaceService);
169 }
170
171 /**
172 * Sets up the host service with details of hosts.
173 */
174 private void setUpHostService() {
175 hostService = createMock(HostService.class);
176
177 hostService.addListener(anyObject(HostListener.class));
178 expectLastCall().anyTimes();
179
180 IpAddress host1Address = IpAddress.valueOf("192.168.10.1");
181 Host host1 = new DefaultHost(ProviderId.NONE, HostId.NONE,
182 MacAddress.valueOf("00:00:00:00:00:01"), VlanId.NONE,
183 new HostLocation(SW1_ETH1, 1),
184 Sets.newHashSet(host1Address));
185
186 expect(hostService.getHostsByIp(host1Address))
187 .andReturn(Sets.newHashSet(host1)).anyTimes();
188 hostService.startMonitoringIp(host1Address);
189 expectLastCall().anyTimes();
190
191
192 IpAddress host2Address = IpAddress.valueOf("192.168.20.1");
193 Host host2 = new DefaultHost(ProviderId.NONE, HostId.NONE,
194 MacAddress.valueOf("00:00:00:00:00:02"), VlanId.NONE,
195 new HostLocation(SW2_ETH1, 1),
196 Sets.newHashSet(host2Address));
197
198 expect(hostService.getHostsByIp(host2Address))
199 .andReturn(Sets.newHashSet(host2)).anyTimes();
200 hostService.startMonitoringIp(host2Address);
201 expectLastCall().anyTimes();
202
203
204 IpAddress host3Address = IpAddress.valueOf("192.168.30.1");
205 Host host3 = new DefaultHost(ProviderId.NONE, HostId.NONE,
206 MacAddress.valueOf("00:00:00:00:00:03"), VlanId.NONE,
207 new HostLocation(SW3_ETH1, 1),
208 Sets.newHashSet(host3Address));
209
210 expect(hostService.getHostsByIp(host3Address))
211 .andReturn(Sets.newHashSet(host3)).anyTimes();
212 hostService.startMonitoringIp(host3Address);
213 expectLastCall().anyTimes();
214
215
216 replay(hostService);
217 }
218
219 /**
220 * This method tests the behavior of intent Synchronizer.
221 *
222 * @throws TestUtilsException
223 */
224 @Test
225 public void testIntentSync() throws TestUtilsException {
226
227 //
228 // Construct routes and intents.
229 // This test simulates the following cases during the master change
230 // time interval:
231 // 1. RouteEntry1 did not change and the intent also did not change.
232 // 2. RouteEntry2 was deleted, but the intent was not deleted.
233 // 3. RouteEntry3 was newly added, and the intent was also submitted.
234 // 4. RouteEntry4 was updated to RouteEntry4Update, and the intent was
235 // also updated to a new one.
236 // 5. RouteEntry5 did not change, but its intent id changed.
237 // 6. RouteEntry6 was newly added, but the intent was not submitted.
238 //
239 RouteEntry routeEntry1 = new RouteEntry(
Pavlin Radoslavov6b570732014-11-06 13:16:45 -0800240 Ip4Prefix.valueOf("1.1.1.0/24"),
241 Ip4Address.valueOf("192.168.10.1"));
Pingpingf5d90932014-10-27 10:50:04 -0700242
243 RouteEntry routeEntry2 = new RouteEntry(
Pavlin Radoslavov6b570732014-11-06 13:16:45 -0800244 Ip4Prefix.valueOf("2.2.2.0/24"),
245 Ip4Address.valueOf("192.168.20.1"));
Pingpingf5d90932014-10-27 10:50:04 -0700246
247 RouteEntry routeEntry3 = new RouteEntry(
Pavlin Radoslavov6b570732014-11-06 13:16:45 -0800248 Ip4Prefix.valueOf("3.3.3.0/24"),
249 Ip4Address.valueOf("192.168.30.1"));
Pingpingf5d90932014-10-27 10:50:04 -0700250
251 RouteEntry routeEntry4 = new RouteEntry(
Pavlin Radoslavov6b570732014-11-06 13:16:45 -0800252 Ip4Prefix.valueOf("4.4.4.0/24"),
253 Ip4Address.valueOf("192.168.30.1"));
Pingpingf5d90932014-10-27 10:50:04 -0700254
255 RouteEntry routeEntry4Update = new RouteEntry(
Pavlin Radoslavov6b570732014-11-06 13:16:45 -0800256 Ip4Prefix.valueOf("4.4.4.0/24"),
257 Ip4Address.valueOf("192.168.20.1"));
Pingpingf5d90932014-10-27 10:50:04 -0700258
259 RouteEntry routeEntry5 = new RouteEntry(
Pavlin Radoslavov6b570732014-11-06 13:16:45 -0800260 Ip4Prefix.valueOf("5.5.5.0/24"),
261 Ip4Address.valueOf("192.168.10.1"));
Pingpingf5d90932014-10-27 10:50:04 -0700262
263 RouteEntry routeEntry6 = new RouteEntry(
Pavlin Radoslavov6b570732014-11-06 13:16:45 -0800264 Ip4Prefix.valueOf("6.6.6.0/24"),
265 Ip4Address.valueOf("192.168.10.1"));
Pingpingf5d90932014-10-27 10:50:04 -0700266
Jonathan Hartec2df012014-10-23 16:40:24 -0700267 RouteEntry routeEntry7 = new RouteEntry(
Pavlin Radoslavov6b570732014-11-06 13:16:45 -0800268 Ip4Prefix.valueOf("7.7.7.0/24"),
269 Ip4Address.valueOf("192.168.10.1"));
Jonathan Hartec2df012014-10-23 16:40:24 -0700270
Pingpingf5d90932014-10-27 10:50:04 -0700271 MultiPointToSinglePointIntent intent1 = intentBuilder(
272 routeEntry1.prefix(), "00:00:00:00:00:01", SW1_ETH1);
273 MultiPointToSinglePointIntent intent2 = intentBuilder(
274 routeEntry2.prefix(), "00:00:00:00:00:02", SW2_ETH1);
275 MultiPointToSinglePointIntent intent3 = intentBuilder(
276 routeEntry3.prefix(), "00:00:00:00:00:03", SW3_ETH1);
277 MultiPointToSinglePointIntent intent4 = intentBuilder(
278 routeEntry4.prefix(), "00:00:00:00:00:03", SW3_ETH1);
279 MultiPointToSinglePointIntent intent4Update = intentBuilder(
280 routeEntry4Update.prefix(), "00:00:00:00:00:02", SW2_ETH1);
281 MultiPointToSinglePointIntent intent5 = intentBuilder(
282 routeEntry5.prefix(), "00:00:00:00:00:01", SW1_ETH1);
Jonathan Hartec2df012014-10-23 16:40:24 -0700283 MultiPointToSinglePointIntent intent7 = intentBuilder(
284 routeEntry7.prefix(), "00:00:00:00:00:01", SW1_ETH1);
Pingpingf5d90932014-10-27 10:50:04 -0700285
286 // Compose a intent, which is equal to intent5 but the id is different.
287 MultiPointToSinglePointIntent intent5New =
288 staticIntentBuilder(intent5, routeEntry5, "00:00:00:00:00:01");
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800289 assertThat(IntentSynchronizer.IntentKey.equalIntents(
290 intent5, intent5New),
291 is(true));
Jonathan Hartec2df012014-10-23 16:40:24 -0700292 assertFalse(intent5.equals(intent5New));
Pingpingf5d90932014-10-27 10:50:04 -0700293
294 MultiPointToSinglePointIntent intent6 = intentBuilder(
295 routeEntry6.prefix(), "00:00:00:00:00:01", SW1_ETH1);
296
Pavlin Radoslavov64c1ed12014-12-10 18:10:55 -0800297 // Set up the ribTable field in Router class and routeIntents fields
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800298 // in IntentSynchronizer class
Pavlin Radoslavov64c1ed12014-12-10 18:10:55 -0800299 InvertedRadixTree<RouteEntry> ribTable =
Pingpingf5d90932014-10-27 10:50:04 -0700300 new ConcurrentInvertedRadixTree<>(
301 new DefaultByteArrayNodeFactory());
Pavlin Radoslavov64c1ed12014-12-10 18:10:55 -0800302 ribTable.put(RouteEntry.createBinaryString(routeEntry1.prefix()),
303 routeEntry1);
304 ribTable.put(RouteEntry.createBinaryString(routeEntry3.prefix()),
305 routeEntry3);
306 ribTable.put(RouteEntry.createBinaryString(routeEntry4Update.prefix()),
307 routeEntry4Update);
308 ribTable.put(RouteEntry.createBinaryString(routeEntry5.prefix()),
309 routeEntry5);
310 ribTable.put(RouteEntry.createBinaryString(routeEntry6.prefix()),
311 routeEntry6);
312 ribTable.put(RouteEntry.createBinaryString(routeEntry7.prefix()),
313 routeEntry7);
Pavlin Radoslavov3a0a52e2015-01-06 17:41:37 -0800314 TestUtils.setField(router, "ribTable4", ribTable);
Pingpingf5d90932014-10-27 10:50:04 -0700315
Pavlin Radoslavov3a0a52e2015-01-06 17:41:37 -0800316 ConcurrentHashMap<IpPrefix, MultiPointToSinglePointIntent>
317 routeIntents = new ConcurrentHashMap<>();
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800318 routeIntents.put(routeEntry1.prefix(), intent1);
319 routeIntents.put(routeEntry3.prefix(), intent3);
320 routeIntents.put(routeEntry4Update.prefix(), intent4Update);
321 routeIntents.put(routeEntry5.prefix(), intent5New);
322 routeIntents.put(routeEntry6.prefix(), intent6);
323 routeIntents.put(routeEntry7.prefix(), intent7);
324 TestUtils.setField(intentSynchronizer, "routeIntents", routeIntents);
Pingpingf5d90932014-10-27 10:50:04 -0700325
326 // Set up expectation
327 reset(intentService);
328 Set<Intent> intents = new HashSet<Intent>();
329 intents.add(intent1);
Jonathan Hartec2df012014-10-23 16:40:24 -0700330 expect(intentService.getIntentState(intent1.id()))
331 .andReturn(IntentState.INSTALLED).anyTimes();
Pingpingf5d90932014-10-27 10:50:04 -0700332 intents.add(intent2);
Jonathan Hartec2df012014-10-23 16:40:24 -0700333 expect(intentService.getIntentState(intent2.id()))
334 .andReturn(IntentState.INSTALLED).anyTimes();
Pingpingf5d90932014-10-27 10:50:04 -0700335 intents.add(intent4);
Jonathan Hartec2df012014-10-23 16:40:24 -0700336 expect(intentService.getIntentState(intent4.id()))
337 .andReturn(IntentState.INSTALLED).anyTimes();
Pingpingf5d90932014-10-27 10:50:04 -0700338 intents.add(intent5);
Jonathan Hartec2df012014-10-23 16:40:24 -0700339 expect(intentService.getIntentState(intent5.id()))
340 .andReturn(IntentState.INSTALLED).anyTimes();
341 intents.add(intent7);
342 expect(intentService.getIntentState(intent7.id()))
343 .andReturn(IntentState.WITHDRAWING).anyTimes();
Pingpingf5d90932014-10-27 10:50:04 -0700344 expect(intentService.getIntents()).andReturn(intents).anyTimes();
345
Pavlin Radoslavov248c2ae2014-12-02 09:51:25 -0800346 IntentOperations.Builder builder = IntentOperations.builder(APPID);
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800347 builder.addWithdrawOperation(intent2.id());
348 builder.addWithdrawOperation(intent4.id());
Pavlin Radoslavovdde22ae2014-11-24 11:47:17 -0800349 intentService.execute(TestIntentServiceHelper.eqExceptId(
350 builder.build()));
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800351
Pavlin Radoslavov248c2ae2014-12-02 09:51:25 -0800352 builder = IntentOperations.builder(APPID);
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800353 builder.addSubmitOperation(intent3);
354 builder.addSubmitOperation(intent4Update);
355 builder.addSubmitOperation(intent6);
356 builder.addSubmitOperation(intent7);
Pavlin Radoslavovdde22ae2014-11-24 11:47:17 -0800357 intentService.execute(TestIntentServiceHelper.eqExceptId(
358 builder.build()));
Pingpingf5d90932014-10-27 10:50:04 -0700359 replay(intentService);
360
361 // Start the test
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800362 intentSynchronizer.leaderChanged(true);
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800363 /*
364 TestUtils.callMethod(intentSynchronizer, "synchronizeIntents",
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800365 new Class<?>[] {});
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800366 */
367 intentSynchronizer.synchronizeIntents();
Pingpingf5d90932014-10-27 10:50:04 -0700368
369 // Verify
Pavlin Radoslavov3a0a52e2015-01-06 17:41:37 -0800370 assertEquals(router.getRoutes4().size(), 6);
371 assertTrue(router.getRoutes4().contains(routeEntry1));
372 assertTrue(router.getRoutes4().contains(routeEntry3));
373 assertTrue(router.getRoutes4().contains(routeEntry4Update));
374 assertTrue(router.getRoutes4().contains(routeEntry5));
375 assertTrue(router.getRoutes4().contains(routeEntry6));
Pingpingf5d90932014-10-27 10:50:04 -0700376
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800377 assertEquals(intentSynchronizer.getRouteIntents().size(), 6);
378 assertTrue(intentSynchronizer.getRouteIntents().contains(intent1));
379 assertTrue(intentSynchronizer.getRouteIntents().contains(intent3));
380 assertTrue(intentSynchronizer.getRouteIntents().contains(intent4Update));
381 assertTrue(intentSynchronizer.getRouteIntents().contains(intent5));
382 assertTrue(intentSynchronizer.getRouteIntents().contains(intent6));
Pingpingf5d90932014-10-27 10:50:04 -0700383
384 verify(intentService);
385 }
386
387 /**
388 * MultiPointToSinglePointIntent builder.
389 *
390 * @param ipPrefix the ipPrefix to match
391 * @param nextHopMacAddress to which the destination MAC address in packet
392 * should be rewritten
393 * @param egressPoint to which packets should be sent
394 * @return the constructed MultiPointToSinglePointIntent
395 */
Pavlin Radoslavov3a0a52e2015-01-06 17:41:37 -0800396 private MultiPointToSinglePointIntent intentBuilder(IpPrefix ipPrefix,
Pingpingf5d90932014-10-27 10:50:04 -0700397 String nextHopMacAddress, ConnectPoint egressPoint) {
398
399 TrafficSelector.Builder selectorBuilder =
400 DefaultTrafficSelector.builder();
Pavlin Radoslavov3a0a52e2015-01-06 17:41:37 -0800401 if (ipPrefix.version() == Ip4Address.VERSION) {
402 selectorBuilder.matchEthType(Ethernet.TYPE_IPV4); // IPv4
403 } else {
404 selectorBuilder.matchEthType(Ethernet.TYPE_IPV6); // IPv6
405 }
406 selectorBuilder.matchIPDst(ipPrefix);
Pingpingf5d90932014-10-27 10:50:04 -0700407
408 TrafficTreatment.Builder treatmentBuilder =
409 DefaultTrafficTreatment.builder();
410 treatmentBuilder.setEthDst(MacAddress.valueOf(nextHopMacAddress));
411
412 Set<ConnectPoint> ingressPoints = new HashSet<ConnectPoint>();
413 for (Interface intf : interfaceService.getInterfaces()) {
414 if (!intf.equals(interfaceService.getInterface(egressPoint))) {
415 ConnectPoint srcPort = intf.connectPoint();
416 ingressPoints.add(srcPort);
417 }
418 }
419 MultiPointToSinglePointIntent intent =
420 new MultiPointToSinglePointIntent(APPID,
421 selectorBuilder.build(), treatmentBuilder.build(),
422 ingressPoints, egressPoint);
423 return intent;
424 }
425
426 /**
427 * A static MultiPointToSinglePointIntent builder, the returned intent is
428 * equal to the input intent except that the id is different.
429 *
430 *
431 * @param intent the intent to be used for building a new intent
432 * @param routeEntry the relative routeEntry of the intent
433 * @return the newly constructed MultiPointToSinglePointIntent
434 * @throws TestUtilsException
435 */
436 private MultiPointToSinglePointIntent staticIntentBuilder(
437 MultiPointToSinglePointIntent intent, RouteEntry routeEntry,
438 String nextHopMacAddress) throws TestUtilsException {
439
440 // Use a different egress ConnectPoint with that in intent
441 // to generate a different id
442 MultiPointToSinglePointIntent intentNew = intentBuilder(
443 routeEntry.prefix(), nextHopMacAddress, SW2_ETH1);
444 TestUtils.setField(intentNew, "egressPoint", intent.egressPoint());
445 TestUtils.setField(intentNew,
446 "ingressPoints", intent.ingressPoints());
447 return intentNew;
448 }
Pingpingf5d90932014-10-27 10:50:04 -0700449}