blob: 7ec843b31e713872f6e1b4a0d6627bfd9ab29a74 [file] [log] [blame]
Thomas Vachuska781d18b2014-10-27 10:31:25 -07001/*
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07002 * Copyright 2014 Open Networking Laboratory
Thomas Vachuska781d18b2014-10-27 10:31:25 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * 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
Thomas Vachuska781d18b2014-10-27 10:31:25 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * 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.
Thomas Vachuska781d18b2014-10-27 10:31:25 -070015 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.sdnip;
Jonathan Hartce430a42014-10-16 20:44:29 -070017
Jonathan Hart552e31f2015-02-06 11:11:59 -080018import com.google.common.collect.Sets;
Jonathan Hartce430a42014-10-16 20:44:29 -070019import org.junit.Before;
20import org.junit.Ignore;
21import org.junit.Test;
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -080022import org.onlab.junit.TestUtils;
23import org.onlab.junit.TestUtils.TestUtilsException;
Jonathan Hart51372182014-12-03 21:32:34 -080024import org.onlab.packet.Ethernet;
25import org.onlab.packet.IPv4;
26import org.onlab.packet.IpAddress;
27import org.onlab.packet.IpPrefix;
28import org.onlab.packet.MacAddress;
Jonathan Hart6cd2f352015-01-13 17:44:45 -080029import org.onlab.packet.VlanId;
Brian O'Connorabafb502014-12-02 22:26:20 -080030import org.onosproject.core.ApplicationId;
31import org.onosproject.net.ConnectPoint;
32import org.onosproject.net.DeviceId;
33import org.onosproject.net.PortNumber;
34import org.onosproject.net.flow.DefaultTrafficSelector;
35import org.onosproject.net.flow.DefaultTrafficTreatment;
36import org.onosproject.net.flow.TrafficSelector;
37import org.onosproject.net.flow.TrafficTreatment;
38import org.onosproject.net.host.InterfaceIpAddress;
39import org.onosproject.net.intent.AbstractIntentTest;
40import org.onosproject.net.intent.Intent;
Brian O'Connorabafb502014-12-02 22:26:20 -080041import org.onosproject.net.intent.IntentService;
42import org.onosproject.net.intent.PointToPointIntent;
Jonathan Hart2da1e602015-02-18 19:09:24 -080043import org.onosproject.routing.config.BgpPeer;
44import org.onosproject.routing.config.BgpSpeaker;
45import org.onosproject.routing.config.Interface;
46import org.onosproject.routing.config.InterfaceAddress;
47import org.onosproject.routing.config.RoutingConfigurationService;
Jonathan Hartce430a42014-10-16 20:44:29 -070048
Jonathan Hart552e31f2015-02-06 11:11:59 -080049import java.util.ArrayList;
50import java.util.Collections;
51import java.util.HashMap;
52import java.util.LinkedList;
53import java.util.List;
54import java.util.Map;
55
56import static org.easymock.EasyMock.*;
Jonathan Hartcb726fc2015-02-13 16:26:22 -080057import static org.onosproject.sdnip.TestIntentServiceHelper.eqExceptId;
Jonathan Hartce430a42014-10-16 20:44:29 -070058
59/**
Jonathan Hart51372182014-12-03 21:32:34 -080060 * Unit tests for PeerConnectivityManager.
Jonathan Hartce430a42014-10-16 20:44:29 -070061 */
Brian O'Connor520c0522014-11-23 23:50:47 -080062public class PeerConnectivityManagerTest extends AbstractIntentTest {
Jonathan Hartce430a42014-10-16 20:44:29 -070063
Thomas Vachuskab97cf282014-10-20 23:31:12 -070064 private static final ApplicationId APPID = new ApplicationId() {
65 @Override
66 public short id() {
67 return 0;
68 }
69
70 @Override
71 public String name() {
72 return "foo";
73 }
74 };
75
Jonathan Hartce430a42014-10-16 20:44:29 -070076 private PeerConnectivityManager peerConnectivityManager;
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -080077 private IntentSynchronizer intentSynchronizer;
Jonathan Hart90a02c22015-02-13 11:52:07 -080078 private RoutingConfigurationService routingConfig;
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -080079 private IntentService intentService;
Jonathan Hartce430a42014-10-16 20:44:29 -070080
81 private Map<String, BgpSpeaker> bgpSpeakers;
82 private Map<String, Interface> interfaces;
83 private Map<IpAddress, BgpPeer> peers;
84
85 private Map<String, BgpSpeaker> configuredBgpSpeakers;
86 private Map<String, Interface> configuredInterfaces;
87 private Map<IpAddress, BgpPeer> configuredPeers;
88 private List<PointToPointIntent> intentList;
89
90 private final String dpid1 = "00:00:00:00:00:00:00:01";
91 private final String dpid2 = "00:00:00:00:00:00:00:02";
92
93 private final DeviceId deviceId1 =
94 DeviceId.deviceId(SdnIp.dpidToUri(dpid1));
95 private final DeviceId deviceId2 =
96 DeviceId.deviceId(SdnIp.dpidToUri(dpid2));
97
98 // Interfaces connected to BGP speakers
99 private final ConnectPoint s1Eth100 =
100 new ConnectPoint(deviceId1, PortNumber.portNumber(100));
101 private final ConnectPoint s2Eth100 =
102 new ConnectPoint(deviceId2, PortNumber.portNumber(100));
103
104 // Interfaces connected to BGP peers
105 private final ConnectPoint s1Eth1 =
106 new ConnectPoint(deviceId1, PortNumber.portNumber(1));
107 private final ConnectPoint s2Eth1 =
108 new ConnectPoint(deviceId2, PortNumber.portNumber(1));
109
Jonathan Hartce430a42014-10-16 20:44:29 -0700110 private final TrafficTreatment noTreatment =
Brian O'Connor6b528132015-03-10 16:39:52 -0700111 DefaultTrafficTreatment.emptyTreatment();
Jonathan Hartce430a42014-10-16 20:44:29 -0700112
113 @Before
114 public void setUp() throws Exception {
Brian O'Connor520c0522014-11-23 23:50:47 -0800115 super.setUp();
Jonathan Hart90a02c22015-02-13 11:52:07 -0800116 routingConfig = createMock(RoutingConfigurationService.class);
117
118 // These will set expectations on routingConfig
Jonathan Hartce430a42014-10-16 20:44:29 -0700119 bgpSpeakers = Collections.unmodifiableMap(setUpBgpSpeakers());
120 interfaces = Collections.unmodifiableMap(setUpInterfaces());
121 peers = Collections.unmodifiableMap(setUpPeers());
122
123 initPeerConnectivity();
124 intentList = setUpIntentList();
125 }
126
127 /**
128 * Sets up BGP speakers.
129 *
130 * @return configured BGP speakers as a map from speaker name to speaker
131 */
132 private Map<String, BgpSpeaker> setUpBgpSpeakers() {
133
134 configuredBgpSpeakers = new HashMap<>();
135
136 BgpSpeaker bgpSpeaker1 = new BgpSpeaker(
137 "bgpSpeaker1",
138 "00:00:00:00:00:00:00:01", 100,
139 "00:00:00:00:00:01");
Jonathan Hart90a02c22015-02-13 11:52:07 -0800140 List<InterfaceAddress> interfaceAddresses1 = new LinkedList<>();
Jonathan Hartce430a42014-10-16 20:44:29 -0700141 interfaceAddresses1.add(new InterfaceAddress(dpid1, 1, "192.168.10.101"));
142 interfaceAddresses1.add(new InterfaceAddress(dpid2, 1, "192.168.20.101"));
143 bgpSpeaker1.setInterfaceAddresses(interfaceAddresses1);
144 configuredBgpSpeakers.put(bgpSpeaker1.name(), bgpSpeaker1);
145
146 // BGP speaker2 is attached to the same switch port with speaker1
147 BgpSpeaker bgpSpeaker2 = new BgpSpeaker(
148 "bgpSpeaker2",
149 "00:00:00:00:00:00:00:01", 100,
150 "00:00:00:00:00:02");
Jonathan Hart90a02c22015-02-13 11:52:07 -0800151 List<InterfaceAddress> interfaceAddresses2 = new LinkedList<>();
Jonathan Hartce430a42014-10-16 20:44:29 -0700152 interfaceAddresses2.add(new InterfaceAddress(dpid1, 1, "192.168.10.102"));
153 interfaceAddresses2.add(new InterfaceAddress(dpid2, 1, "192.168.20.102"));
154 bgpSpeaker2.setInterfaceAddresses(interfaceAddresses2);
155 configuredBgpSpeakers.put(bgpSpeaker2.name(), bgpSpeaker2);
156
157 BgpSpeaker bgpSpeaker3 = new BgpSpeaker(
158 "bgpSpeaker3",
159 "00:00:00:00:00:00:00:02", 100,
160 "00:00:00:00:00:03");
Jonathan Hart90a02c22015-02-13 11:52:07 -0800161 List<InterfaceAddress> interfaceAddresses3 = new LinkedList<>();
Jonathan Hartce430a42014-10-16 20:44:29 -0700162 interfaceAddresses3.add(new InterfaceAddress(dpid1, 1, "192.168.10.103"));
163 interfaceAddresses3.add(new InterfaceAddress(dpid2, 1, "192.168.20.103"));
164 bgpSpeaker3.setInterfaceAddresses(interfaceAddresses3);
165 configuredBgpSpeakers.put(bgpSpeaker3.name(), bgpSpeaker3);
166
167 return configuredBgpSpeakers;
168 }
169
170 /**
171 * Sets up logical interfaces, which emulate the configured interfaces
172 * in SDN-IP application.
173 *
174 * @return configured interfaces as a MAP from Interface name to Interface
175 */
176 private Map<String, Interface> setUpInterfaces() {
177
178 configuredInterfaces = new HashMap<>();
179
180 String interfaceSw1Eth1 = "s1-eth1";
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -0700181 InterfaceIpAddress ia1 =
182 new InterfaceIpAddress(IpAddress.valueOf("192.168.10.1"),
183 IpPrefix.valueOf("192.168.10.0/24"));
Jonathan Hartce430a42014-10-16 20:44:29 -0700184 Interface intfsw1eth1 = new Interface(s1Eth1,
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -0700185 Collections.singleton(ia1),
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800186 MacAddress.valueOf("00:00:00:00:00:01"),
187 VlanId.NONE);
Jonathan Hartce430a42014-10-16 20:44:29 -0700188
189 configuredInterfaces.put(interfaceSw1Eth1, intfsw1eth1);
190 String interfaceSw2Eth1 = "s2-eth1";
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -0700191 InterfaceIpAddress ia2 =
192 new InterfaceIpAddress(IpAddress.valueOf("192.168.20.2"),
193 IpPrefix.valueOf("192.168.20.0/24"));
Jonathan Hartce430a42014-10-16 20:44:29 -0700194 Interface intfsw2eth1 = new Interface(s2Eth1,
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -0700195 Collections.singleton(ia2),
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800196 MacAddress.valueOf("00:00:00:00:00:02"),
197 VlanId.NONE);
Jonathan Hartce430a42014-10-16 20:44:29 -0700198 configuredInterfaces.put(interfaceSw2Eth1, intfsw2eth1);
199
Jonathan Hart90a02c22015-02-13 11:52:07 -0800200 expect(routingConfig.getInterface(s1Eth1))
Jonathan Hartce430a42014-10-16 20:44:29 -0700201 .andReturn(intfsw1eth1).anyTimes();
Jonathan Hart90a02c22015-02-13 11:52:07 -0800202 expect(routingConfig.getInterface(s2Eth1))
Jonathan Hartce430a42014-10-16 20:44:29 -0700203 .andReturn(intfsw2eth1).anyTimes();
204
205 // Non-existent interface used during one of the tests
Jonathan Hart90a02c22015-02-13 11:52:07 -0800206 expect(routingConfig.getInterface(new ConnectPoint(
Jonathan Hartce430a42014-10-16 20:44:29 -0700207 DeviceId.deviceId(SdnIp.dpidToUri("00:00:00:00:00:00:01:00")),
208 PortNumber.portNumber(1))))
209 .andReturn(null).anyTimes();
210
Jonathan Hart90a02c22015-02-13 11:52:07 -0800211 expect(routingConfig.getInterfaces()).andReturn(
Jonathan Hartce430a42014-10-16 20:44:29 -0700212 Sets.newHashSet(configuredInterfaces.values())).anyTimes();
Jonathan Hartce430a42014-10-16 20:44:29 -0700213
214 return configuredInterfaces;
215 }
216
217 /**
218 * Sets up BGP daemon peers.
219 *
220 * @return configured BGP peers as a MAP from peer IP address to BgpPeer
221 */
222 private Map<IpAddress, BgpPeer> setUpPeers() {
223
224 configuredPeers = new HashMap<>();
225
226 String peerSw1Eth1 = "192.168.10.1";
227 configuredPeers.put(IpAddress.valueOf(peerSw1Eth1),
228 new BgpPeer(dpid1, 1, peerSw1Eth1));
229
230 // Two BGP peers are connected to switch 2 port 1.
231 String peer1Sw2Eth1 = "192.168.20.1";
232 configuredPeers.put(IpAddress.valueOf(peer1Sw2Eth1),
233 new BgpPeer(dpid2, 1, peer1Sw2Eth1));
234
235 String peer2Sw2Eth1 = "192.168.20.2";
236 configuredPeers.put(IpAddress.valueOf(peer2Sw2Eth1),
237 new BgpPeer(dpid2, 1, peer2Sw2Eth1));
238
239 return configuredPeers;
240 }
241
242 /**
243 * Sets up expected point to point intent list.
244 *
245 * @return point to point intent list
246 */
247 private List<PointToPointIntent> setUpIntentList() {
248
Jonathan Hart90a02c22015-02-13 11:52:07 -0800249 intentList = new ArrayList<>();
Jonathan Hartce430a42014-10-16 20:44:29 -0700250
251 setUpBgpIntents();
252 setUpIcmpIntents();
253
254 return intentList;
255
256 }
257
258 /**
259 * Constructs a BGP intent and put it into the intentList.
260 * <p/>
261 * The purpose of this method is too simplify the setUpBgpIntents() method,
262 * and to make the setUpBgpIntents() easy to read.
263 *
264 * @param srcPrefix source IP prefix to match
265 * @param dstPrefix destination IP prefix to match
266 * @param srcTcpPort source TCP port to match
267 * @param dstTcpPort destination TCP port to match
268 * @param srcConnectPoint source connect point for PointToPointIntent
269 * @param dstConnectPoint destination connect point for PointToPointIntent
270 */
271 private void bgpPathintentConstructor(String srcPrefix, String dstPrefix,
272 Short srcTcpPort, Short dstTcpPort,
273 ConnectPoint srcConnectPoint, ConnectPoint dstConnectPoint) {
274
275 TrafficSelector.Builder builder = DefaultTrafficSelector.builder()
276 .matchEthType(Ethernet.TYPE_IPV4)
277 .matchIPProtocol(IPv4.PROTOCOL_TCP)
278 .matchIPSrc(IpPrefix.valueOf(srcPrefix))
279 .matchIPDst(IpPrefix.valueOf(dstPrefix));
280
281 if (srcTcpPort != null) {
282 builder.matchTcpSrc(srcTcpPort);
283 }
284 if (dstTcpPort != null) {
285 builder.matchTcpDst(dstTcpPort);
286 }
287
288 PointToPointIntent intent = new PointToPointIntent(
Thomas Vachuskab97cf282014-10-20 23:31:12 -0700289 APPID, builder.build(), noTreatment,
Jonathan Hartce430a42014-10-16 20:44:29 -0700290 srcConnectPoint, dstConnectPoint);
291
292 intentList.add(intent);
293 }
294
295 /**
296 * Sets up intents for BGP paths.
297 */
298 private void setUpBgpIntents() {
299
Jonathan Hart41349e92015-02-09 14:14:02 -0800300 Short bgpPort = 179;
Jonathan Hartce430a42014-10-16 20:44:29 -0700301
302 // Start to build intents between BGP speaker1 and BGP peer1
303 bgpPathintentConstructor(
304 "192.168.10.101/32", "192.168.10.1/32", null, bgpPort,
305 s1Eth100, s1Eth1);
306 bgpPathintentConstructor(
307 "192.168.10.101/32", "192.168.10.1/32", bgpPort, null,
308 s1Eth100, s1Eth1);
309
310 bgpPathintentConstructor(
311 "192.168.10.1/32", "192.168.10.101/32", null, bgpPort,
312 s1Eth1, s1Eth100);
313 bgpPathintentConstructor(
314 "192.168.10.1/32", "192.168.10.101/32", bgpPort, null,
315 s1Eth1, s1Eth100);
316
317 // Start to build intents between BGP speaker1 and BGP peer2
318 bgpPathintentConstructor(
319 "192.168.20.101/32", "192.168.20.1/32", null, bgpPort,
320 s1Eth100, s2Eth1);
321 bgpPathintentConstructor(
322 "192.168.20.101/32", "192.168.20.1/32", bgpPort, null,
323 s1Eth100, s2Eth1);
324
325 bgpPathintentConstructor(
326 "192.168.20.1/32", "192.168.20.101/32", null, bgpPort,
327 s2Eth1, s1Eth100);
328 bgpPathintentConstructor(
329 "192.168.20.1/32", "192.168.20.101/32", bgpPort, null,
330 s2Eth1, s1Eth100);
331
332 // Start to build intents between BGP speaker1 and BGP peer3
333 bgpPathintentConstructor(
334 "192.168.20.101/32", "192.168.20.2/32", null, bgpPort,
335 s1Eth100, s2Eth1);
336 bgpPathintentConstructor(
337 "192.168.20.101/32", "192.168.20.2/32", bgpPort, null,
338 s1Eth100, s2Eth1);
339
340 bgpPathintentConstructor(
341 "192.168.20.2/32", "192.168.20.101/32", null, bgpPort,
342 s2Eth1, s1Eth100);
343 bgpPathintentConstructor(
344 "192.168.20.2/32", "192.168.20.101/32", bgpPort, null,
345 s2Eth1, s1Eth100);
346
347 //
348 // Start to build intents between BGP speaker2 and BGP peer1
349 bgpPathintentConstructor(
350 "192.168.10.102/32", "192.168.10.1/32", null, bgpPort,
351 s1Eth100, s1Eth1);
352 bgpPathintentConstructor(
353 "192.168.10.102/32", "192.168.10.1/32", bgpPort, null,
354 s1Eth100, s1Eth1);
355
356 bgpPathintentConstructor(
357 "192.168.10.1/32", "192.168.10.102/32", null, bgpPort,
358 s1Eth1, s1Eth100);
359 bgpPathintentConstructor(
360 "192.168.10.1/32", "192.168.10.102/32", bgpPort, null,
361 s1Eth1, s1Eth100);
362 // Start to build intents between BGP speaker2 and BGP peer2
363 bgpPathintentConstructor(
364 "192.168.20.102/32", "192.168.20.1/32", null, bgpPort,
365 s1Eth100, s2Eth1);
366 bgpPathintentConstructor(
367 "192.168.20.102/32", "192.168.20.1/32", bgpPort, null,
368 s1Eth100, s2Eth1);
369
370 bgpPathintentConstructor(
371 "192.168.20.1/32", "192.168.20.102/32", null, bgpPort,
372 s2Eth1, s1Eth100);
373 bgpPathintentConstructor(
374 "192.168.20.1/32", "192.168.20.102/32", bgpPort, null,
375 s2Eth1, s1Eth100);
376
377 // Start to build intents between BGP speaker2 and BGP peer3
378 bgpPathintentConstructor(
379 "192.168.20.102/32", "192.168.20.2/32", null, bgpPort,
380 s1Eth100, s2Eth1);
381 bgpPathintentConstructor(
382 "192.168.20.102/32", "192.168.20.2/32", bgpPort, null,
383 s1Eth100, s2Eth1);
384
385 bgpPathintentConstructor(
386 "192.168.20.2/32", "192.168.20.102/32", null, bgpPort,
387 s2Eth1, s1Eth100);
388 bgpPathintentConstructor(
389 "192.168.20.2/32", "192.168.20.102/32", bgpPort, null,
390 s2Eth1, s1Eth100);
391
392 //
393 // Start to build intents between BGP speaker3 and BGP peer1
394 bgpPathintentConstructor(
395 "192.168.10.103/32", "192.168.10.1/32", null, bgpPort,
396 s2Eth100, s1Eth1);
397 bgpPathintentConstructor(
398 "192.168.10.103/32", "192.168.10.1/32", bgpPort, null,
399 s2Eth100, s1Eth1);
400
401 bgpPathintentConstructor(
402 "192.168.10.1/32", "192.168.10.103/32", null, bgpPort,
403 s1Eth1, s2Eth100);
404 bgpPathintentConstructor(
405 "192.168.10.1/32", "192.168.10.103/32", bgpPort, null,
406 s1Eth1, s2Eth100);
407
408 // Start to build intents between BGP speaker3 and BGP peer2
409 bgpPathintentConstructor(
410 "192.168.20.103/32", "192.168.20.1/32", null, bgpPort,
411 s2Eth100, s2Eth1);
412 bgpPathintentConstructor(
413 "192.168.20.103/32", "192.168.20.1/32", bgpPort, null,
414 s2Eth100, s2Eth1);
415
416 bgpPathintentConstructor(
417 "192.168.20.1/32", "192.168.20.103/32", null, bgpPort,
418 s2Eth1, s2Eth100);
419 bgpPathintentConstructor(
420 "192.168.20.1/32", "192.168.20.103/32", bgpPort, null,
421 s2Eth1, s2Eth100);
422
423 // Start to build intents between BGP speaker3 and BGP peer3
424 bgpPathintentConstructor(
425 "192.168.20.103/32", "192.168.20.2/32", null, bgpPort,
426 s2Eth100, s2Eth1);
427 bgpPathintentConstructor(
428 "192.168.20.103/32", "192.168.20.2/32", bgpPort, null,
429 s2Eth100, s2Eth1);
430
431 bgpPathintentConstructor(
432 "192.168.20.2/32", "192.168.20.103/32", null, bgpPort,
433 s2Eth1, s2Eth100);
434 bgpPathintentConstructor(
435 "192.168.20.2/32", "192.168.20.103/32", bgpPort, null,
436 s2Eth1, s2Eth100);
437 }
438
439 /**
440 * Constructs a BGP intent and put it into the intentList.
441 * <p/>
442 * The purpose of this method is too simplify the setUpBgpIntents() method,
443 * and to make the setUpBgpIntents() easy to read.
444 *
445 * @param srcPrefix source IP prefix to match
446 * @param dstPrefix destination IP prefix to match
447 * @param srcConnectPoint source connect point for PointToPointIntent
448 * @param dstConnectPoint destination connect point for PointToPointIntent
449 */
450 private void icmpPathintentConstructor(String srcPrefix, String dstPrefix,
451 ConnectPoint srcConnectPoint, ConnectPoint dstConnectPoint) {
452
453 TrafficSelector selector = DefaultTrafficSelector.builder()
454 .matchEthType(Ethernet.TYPE_IPV4)
455 .matchIPProtocol(IPv4.PROTOCOL_ICMP)
456 .matchIPSrc(IpPrefix.valueOf(srcPrefix))
457 .matchIPDst(IpPrefix.valueOf(dstPrefix))
458 .build();
459
460 PointToPointIntent intent = new PointToPointIntent(
Thomas Vachuskab97cf282014-10-20 23:31:12 -0700461 APPID, selector, noTreatment,
Jonathan Hartce430a42014-10-16 20:44:29 -0700462 srcConnectPoint, dstConnectPoint);
463
464 intentList.add(intent);
465 }
466
467 /**
468 * Sets up intents for ICMP paths.
469 */
470 private void setUpIcmpIntents() {
471
472 // Start to build intents between BGP speaker1 and BGP peer1
473 icmpPathintentConstructor(
474 "192.168.10.101/32", "192.168.10.1/32", s1Eth100, s1Eth1);
475 icmpPathintentConstructor(
476 "192.168.10.1/32", "192.168.10.101/32", s1Eth1, s1Eth100);
477
478 // Start to build intents between BGP speaker1 and BGP peer2
479 icmpPathintentConstructor(
480 "192.168.20.101/32", "192.168.20.1/32", s1Eth100, s2Eth1);
481 icmpPathintentConstructor(
482 "192.168.20.1/32", "192.168.20.101/32", s2Eth1, s1Eth100);
483
484 // Start to build intents between BGP speaker1 and BGP peer3
485 icmpPathintentConstructor(
486 "192.168.20.101/32", "192.168.20.2/32", s1Eth100, s2Eth1);
487 icmpPathintentConstructor(
488 "192.168.20.2/32", "192.168.20.101/32", s2Eth1, s1Eth100);
489
490 //
491 // Start to build intents between BGP speaker2 and BGP peer1
492 icmpPathintentConstructor(
493 "192.168.10.102/32", "192.168.10.1/32", s1Eth100, s1Eth1);
494 icmpPathintentConstructor(
495 "192.168.10.1/32", "192.168.10.102/32", s1Eth1, s1Eth100);
496
497 // Start to build intents between BGP speaker2 and BGP peer2
498 icmpPathintentConstructor(
499 "192.168.20.102/32", "192.168.20.1/32", s1Eth100, s2Eth1);
500 icmpPathintentConstructor(
501 "192.168.20.1/32", "192.168.20.102/32", s2Eth1, s1Eth100);
502
503 // Start to build intents between BGP speaker2 and BGP peer3
504 icmpPathintentConstructor(
505 "192.168.20.102/32", "192.168.20.2/32", s1Eth100, s2Eth1);
506 icmpPathintentConstructor(
507 "192.168.20.2/32", "192.168.20.102/32", s2Eth1, s1Eth100);
508
509 //
510 // Start to build intents between BGP speaker3 and BGP peer1
511 icmpPathintentConstructor(
512 "192.168.10.103/32", "192.168.10.1/32", s2Eth100, s1Eth1);
513 icmpPathintentConstructor(
514 "192.168.10.1/32", "192.168.10.103/32", s1Eth1, s2Eth100);
515
516 // Start to build intents between BGP speaker3 and BGP peer2
517 icmpPathintentConstructor(
518 "192.168.20.103/32", "192.168.20.1/32", s2Eth100, s2Eth1);
519 icmpPathintentConstructor(
520 "192.168.20.1/32", "192.168.20.103/32", s2Eth1, s2Eth100);
521
522 // Start to build intents between BGP speaker3 and BGP peer3
523 icmpPathintentConstructor(
524 "192.168.20.103/32", "192.168.20.2/32", s2Eth100, s2Eth1);
525 icmpPathintentConstructor(
526 "192.168.20.2/32", "192.168.20.103/32", s2Eth1, s2Eth100);
527
528 }
529
530 /**
531 * Initializes peer connectivity testing environment.
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800532 *
533 * @throws TestUtilsException if exceptions when using TestUtils
Jonathan Hartce430a42014-10-16 20:44:29 -0700534 */
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800535 private void initPeerConnectivity() throws TestUtilsException {
Jonathan Hartce430a42014-10-16 20:44:29 -0700536
Jonathan Hart90a02c22015-02-13 11:52:07 -0800537 expect(routingConfig.getBgpPeers()).andReturn(peers).anyTimes();
538 expect(routingConfig.getBgpSpeakers()).andReturn(bgpSpeakers).anyTimes();
539 replay(routingConfig);
Jonathan Hartce430a42014-10-16 20:44:29 -0700540
541 intentService = createMock(IntentService.class);
542 replay(intentService);
543
Jonathan Hart552e31f2015-02-06 11:11:59 -0800544 intentSynchronizer = new IntentSynchronizer(APPID, intentService,
Jonathan Hart90a02c22015-02-13 11:52:07 -0800545 routingConfig);
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800546 intentSynchronizer.leaderChanged(true);
547 TestUtils.setField(intentSynchronizer, "isActivatedLeader", true);
548
549 peerConnectivityManager =
550 new PeerConnectivityManager(APPID, intentSynchronizer,
Jonathan Hart90a02c22015-02-13 11:52:07 -0800551 routingConfig);
Jonathan Hartce430a42014-10-16 20:44:29 -0700552 }
553
Jonathan Hartce430a42014-10-16 20:44:29 -0700554 /**
555 * Tests whether peer connectivity manager can set up correct BGP and
556 * ICMP intents according to specific configuration.
557 * <p/>
558 * Two tricky cases included in the configuration are: 2 peers on a same
559 * switch port, peer on the same switch with BGPd.
560 */
561 @Test
562 public void testConnectionSetup() {
563
564 reset(intentService);
565
Pavlin Radoslavovdde22ae2014-11-24 11:47:17 -0800566 // Setup the expected intents
Pavlin Radoslavovdde22ae2014-11-24 11:47:17 -0800567 for (Intent intent : intentList) {
Jonathan Hartcb726fc2015-02-13 16:26:22 -0800568 intentService.submit(eqExceptId(intent));
Jonathan Hartce430a42014-10-16 20:44:29 -0700569 }
Jonathan Hartce430a42014-10-16 20:44:29 -0700570 replay(intentService);
571
572 // Running the interface to be tested.
573 peerConnectivityManager.start();
574
575 verify(intentService);
576
577 }
578
579 /**
580 * Tests a corner case, when there are no interfaces in the configuration.
581 */
582 @Test
583 public void testNullInterfaces() {
Jonathan Hart90a02c22015-02-13 11:52:07 -0800584 reset(routingConfig);
585 expect(routingConfig.getInterfaces()).andReturn(
Jonathan Hartce430a42014-10-16 20:44:29 -0700586 Sets.<Interface>newHashSet()).anyTimes();
Jonathan Hart90a02c22015-02-13 11:52:07 -0800587 expect(routingConfig.getInterface(s2Eth1))
Jonathan Hartce430a42014-10-16 20:44:29 -0700588 .andReturn(null).anyTimes();
Jonathan Hart90a02c22015-02-13 11:52:07 -0800589 expect(routingConfig.getInterface(s1Eth1))
Jonathan Hartce430a42014-10-16 20:44:29 -0700590 .andReturn(null).anyTimes();
Jonathan Hartce430a42014-10-16 20:44:29 -0700591
Jonathan Hart90a02c22015-02-13 11:52:07 -0800592 expect(routingConfig.getBgpPeers()).andReturn(peers).anyTimes();
593 expect(routingConfig.getBgpSpeakers()).andReturn(bgpSpeakers).anyTimes();
594 replay(routingConfig);
Jonathan Hartce430a42014-10-16 20:44:29 -0700595
596 reset(intentService);
597 replay(intentService);
598 peerConnectivityManager.start();
599 verify(intentService);
600 }
601
602 /**
603 * Tests a corner case, when there are no BGP peers in the configuration.
604 */
605 @Test
606 public void testNullBgpPeers() {
Jonathan Hart90a02c22015-02-13 11:52:07 -0800607 reset(routingConfig);
608 expect(routingConfig.getInterfaces()).andReturn(
Jonathan Hartce430a42014-10-16 20:44:29 -0700609 Sets.newHashSet(interfaces.values())).anyTimes();
Jonathan Hartce430a42014-10-16 20:44:29 -0700610
Jonathan Hart90a02c22015-02-13 11:52:07 -0800611 expect(routingConfig.getBgpPeers()).andReturn(new HashMap<>()).anyTimes();
612 expect(routingConfig.getBgpSpeakers()).andReturn(bgpSpeakers).anyTimes();
613 replay(routingConfig);
Jonathan Hartce430a42014-10-16 20:44:29 -0700614
615 reset(intentService);
Jonathan Hartce430a42014-10-16 20:44:29 -0700616 replay(intentService);
617 peerConnectivityManager.start();
618 verify(intentService);
619 }
620
621 /**
622 * Tests a corner case, when there is no BGP speakers in the configuration.
623 */
624 @Test
625 public void testNullBgpSpeakers() {
Jonathan Hart90a02c22015-02-13 11:52:07 -0800626 reset(routingConfig);
627 expect(routingConfig.getInterfaces()).andReturn(
Jonathan Hartce430a42014-10-16 20:44:29 -0700628 Sets.newHashSet(interfaces.values())).anyTimes();
Jonathan Hartce430a42014-10-16 20:44:29 -0700629
Jonathan Hart90a02c22015-02-13 11:52:07 -0800630 expect(routingConfig.getBgpPeers()).andReturn(peers).anyTimes();
631 expect(routingConfig.getBgpSpeakers()).andReturn(
Jonathan Hart51372182014-12-03 21:32:34 -0800632 Collections.emptyMap()).anyTimes();
Jonathan Hart90a02c22015-02-13 11:52:07 -0800633 replay(routingConfig);
Jonathan Hartce430a42014-10-16 20:44:29 -0700634
635 reset(intentService);
Jonathan Hartce430a42014-10-16 20:44:29 -0700636 replay(intentService);
637 peerConnectivityManager.start();
638 verify(intentService);
639 }
640
641 /**
642 * Tests a corner case, when there is no Interface configured for one BGP
643 * peer.
644 */
645 @Test
646 public void testNoPeerInterface() {
647 String peerSw100Eth1 = "192.168.200.1";
648 configuredPeers.put(IpAddress.valueOf(peerSw100Eth1),
649 new BgpPeer("00:00:00:00:00:00:01:00", 1, peerSw100Eth1));
650 testConnectionSetup();
651 }
652
653 /**
654 * Tests a corner case, when there is no Interface configured for one BGP
655 * speaker.
Jonathan Hartce430a42014-10-16 20:44:29 -0700656 */
657 @Ignore
658 @Test
659 public void testNoSpeakerInterface() {
660 BgpSpeaker bgpSpeaker100 = new BgpSpeaker(
661 "bgpSpeaker100",
662 "00:00:00:00:00:00:01:00", 100,
663 "00:00:00:00:01:00");
Jonathan Hart90a02c22015-02-13 11:52:07 -0800664 List<InterfaceAddress> interfaceAddresses100 = new LinkedList<>();
Jonathan Hartce430a42014-10-16 20:44:29 -0700665 interfaceAddresses100.add(new InterfaceAddress(dpid1, 1, "192.168.10.201"));
666 interfaceAddresses100.add(new InterfaceAddress(dpid2, 1, "192.168.20.201"));
667 bgpSpeaker100.setInterfaceAddresses(interfaceAddresses100);
668 configuredBgpSpeakers.put(bgpSpeaker100.name(), bgpSpeaker100);
669 testConnectionSetup();
670 }
671}