blob: e542eb02aeb20437bb7b9913834646aee6fbdf87 [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 Hart51372182014-12-03 21:32:34 -080018import static org.easymock.EasyMock.createMock;
19import static org.easymock.EasyMock.expect;
20import static org.easymock.EasyMock.replay;
21import static org.easymock.EasyMock.reset;
22import static org.easymock.EasyMock.verify;
23
24import java.util.ArrayList;
25import java.util.Collections;
26import java.util.HashMap;
27import java.util.LinkedList;
28import java.util.List;
29import java.util.Map;
30
Jonathan Hartce430a42014-10-16 20:44:29 -070031import org.junit.Before;
32import org.junit.Ignore;
33import org.junit.Test;
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -080034import org.onlab.junit.TestUtils;
35import org.onlab.junit.TestUtils.TestUtilsException;
Jonathan Hart51372182014-12-03 21:32:34 -080036import org.onlab.packet.Ethernet;
37import org.onlab.packet.IPv4;
38import org.onlab.packet.IpAddress;
39import org.onlab.packet.IpPrefix;
40import org.onlab.packet.MacAddress;
Jonathan Hart6cd2f352015-01-13 17:44:45 -080041import org.onlab.packet.VlanId;
Brian O'Connorabafb502014-12-02 22:26:20 -080042import org.onosproject.core.ApplicationId;
43import org.onosproject.net.ConnectPoint;
44import org.onosproject.net.DeviceId;
45import org.onosproject.net.PortNumber;
46import org.onosproject.net.flow.DefaultTrafficSelector;
47import org.onosproject.net.flow.DefaultTrafficTreatment;
48import org.onosproject.net.flow.TrafficSelector;
49import org.onosproject.net.flow.TrafficTreatment;
50import org.onosproject.net.host.InterfaceIpAddress;
51import org.onosproject.net.intent.AbstractIntentTest;
52import org.onosproject.net.intent.Intent;
53import org.onosproject.net.intent.IntentOperations;
54import org.onosproject.net.intent.IntentService;
55import org.onosproject.net.intent.PointToPointIntent;
56import org.onosproject.sdnip.bgp.BgpConstants;
57import org.onosproject.sdnip.config.BgpPeer;
58import org.onosproject.sdnip.config.BgpSpeaker;
59import org.onosproject.sdnip.config.Interface;
60import org.onosproject.sdnip.config.InterfaceAddress;
61import org.onosproject.sdnip.config.SdnIpConfigurationService;
Jonathan Hartce430a42014-10-16 20:44:29 -070062
Jonathan Hart51372182014-12-03 21:32:34 -080063import com.google.common.collect.Sets;
Jonathan Hartce430a42014-10-16 20:44:29 -070064
65/**
Jonathan Hart51372182014-12-03 21:32:34 -080066 * Unit tests for PeerConnectivityManager.
Jonathan Hartce430a42014-10-16 20:44:29 -070067 */
Brian O'Connor520c0522014-11-23 23:50:47 -080068public class PeerConnectivityManagerTest extends AbstractIntentTest {
Jonathan Hartce430a42014-10-16 20:44:29 -070069
Thomas Vachuskab97cf282014-10-20 23:31:12 -070070 private static final ApplicationId APPID = new ApplicationId() {
71 @Override
72 public short id() {
73 return 0;
74 }
75
76 @Override
77 public String name() {
78 return "foo";
79 }
80 };
81
Jonathan Hartce430a42014-10-16 20:44:29 -070082 private PeerConnectivityManager peerConnectivityManager;
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -080083 private IntentSynchronizer intentSynchronizer;
Jonathan Hart9965d772014-12-02 10:28:34 -080084 private SdnIpConfigurationService configInfoService;
Jonathan Hartce430a42014-10-16 20:44:29 -070085 private InterfaceService interfaceService;
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -080086 private IntentService intentService;
Jonathan Hartce430a42014-10-16 20:44:29 -070087
88 private Map<String, BgpSpeaker> bgpSpeakers;
89 private Map<String, Interface> interfaces;
90 private Map<IpAddress, BgpPeer> peers;
91
92 private Map<String, BgpSpeaker> configuredBgpSpeakers;
93 private Map<String, Interface> configuredInterfaces;
94 private Map<IpAddress, BgpPeer> configuredPeers;
95 private List<PointToPointIntent> intentList;
96
97 private final String dpid1 = "00:00:00:00:00:00:00:01";
98 private final String dpid2 = "00:00:00:00:00:00:00:02";
99
100 private final DeviceId deviceId1 =
101 DeviceId.deviceId(SdnIp.dpidToUri(dpid1));
102 private final DeviceId deviceId2 =
103 DeviceId.deviceId(SdnIp.dpidToUri(dpid2));
104
105 // Interfaces connected to BGP speakers
106 private final ConnectPoint s1Eth100 =
107 new ConnectPoint(deviceId1, PortNumber.portNumber(100));
108 private final ConnectPoint s2Eth100 =
109 new ConnectPoint(deviceId2, PortNumber.portNumber(100));
110
111 // Interfaces connected to BGP peers
112 private final ConnectPoint s1Eth1 =
113 new ConnectPoint(deviceId1, PortNumber.portNumber(1));
114 private final ConnectPoint s2Eth1 =
115 new ConnectPoint(deviceId2, PortNumber.portNumber(1));
116
Jonathan Hartce430a42014-10-16 20:44:29 -0700117 private final TrafficTreatment noTreatment =
118 DefaultTrafficTreatment.builder().build();
119
120 @Before
121 public void setUp() throws Exception {
Brian O'Connor520c0522014-11-23 23:50:47 -0800122 super.setUp();
Jonathan Hartce430a42014-10-16 20:44:29 -0700123 bgpSpeakers = Collections.unmodifiableMap(setUpBgpSpeakers());
124 interfaces = Collections.unmodifiableMap(setUpInterfaces());
125 peers = Collections.unmodifiableMap(setUpPeers());
126
127 initPeerConnectivity();
128 intentList = setUpIntentList();
129 }
130
131 /**
132 * Sets up BGP speakers.
133 *
134 * @return configured BGP speakers as a map from speaker name to speaker
135 */
136 private Map<String, BgpSpeaker> setUpBgpSpeakers() {
137
138 configuredBgpSpeakers = new HashMap<>();
139
140 BgpSpeaker bgpSpeaker1 = new BgpSpeaker(
141 "bgpSpeaker1",
142 "00:00:00:00:00:00:00:01", 100,
143 "00:00:00:00:00:01");
144 List<InterfaceAddress> interfaceAddresses1 =
145 new LinkedList<InterfaceAddress>();
146 interfaceAddresses1.add(new InterfaceAddress(dpid1, 1, "192.168.10.101"));
147 interfaceAddresses1.add(new InterfaceAddress(dpid2, 1, "192.168.20.101"));
148 bgpSpeaker1.setInterfaceAddresses(interfaceAddresses1);
149 configuredBgpSpeakers.put(bgpSpeaker1.name(), bgpSpeaker1);
150
151 // BGP speaker2 is attached to the same switch port with speaker1
152 BgpSpeaker bgpSpeaker2 = new BgpSpeaker(
153 "bgpSpeaker2",
154 "00:00:00:00:00:00:00:01", 100,
155 "00:00:00:00:00:02");
156 List<InterfaceAddress> interfaceAddresses2 =
157 new LinkedList<InterfaceAddress>();
158 interfaceAddresses2.add(new InterfaceAddress(dpid1, 1, "192.168.10.102"));
159 interfaceAddresses2.add(new InterfaceAddress(dpid2, 1, "192.168.20.102"));
160 bgpSpeaker2.setInterfaceAddresses(interfaceAddresses2);
161 configuredBgpSpeakers.put(bgpSpeaker2.name(), bgpSpeaker2);
162
163 BgpSpeaker bgpSpeaker3 = new BgpSpeaker(
164 "bgpSpeaker3",
165 "00:00:00:00:00:00:00:02", 100,
166 "00:00:00:00:00:03");
167 List<InterfaceAddress> interfaceAddresses3 =
168 new LinkedList<InterfaceAddress>();
169 interfaceAddresses3.add(new InterfaceAddress(dpid1, 1, "192.168.10.103"));
170 interfaceAddresses3.add(new InterfaceAddress(dpid2, 1, "192.168.20.103"));
171 bgpSpeaker3.setInterfaceAddresses(interfaceAddresses3);
172 configuredBgpSpeakers.put(bgpSpeaker3.name(), bgpSpeaker3);
173
174 return configuredBgpSpeakers;
175 }
176
177 /**
178 * Sets up logical interfaces, which emulate the configured interfaces
179 * in SDN-IP application.
180 *
181 * @return configured interfaces as a MAP from Interface name to Interface
182 */
183 private Map<String, Interface> setUpInterfaces() {
184
185 configuredInterfaces = new HashMap<>();
186
187 String interfaceSw1Eth1 = "s1-eth1";
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -0700188 InterfaceIpAddress ia1 =
189 new InterfaceIpAddress(IpAddress.valueOf("192.168.10.1"),
190 IpPrefix.valueOf("192.168.10.0/24"));
Jonathan Hartce430a42014-10-16 20:44:29 -0700191 Interface intfsw1eth1 = new Interface(s1Eth1,
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -0700192 Collections.singleton(ia1),
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800193 MacAddress.valueOf("00:00:00:00:00:01"),
194 VlanId.NONE);
Jonathan Hartce430a42014-10-16 20:44:29 -0700195
196 configuredInterfaces.put(interfaceSw1Eth1, intfsw1eth1);
197 String interfaceSw2Eth1 = "s2-eth1";
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -0700198 InterfaceIpAddress ia2 =
199 new InterfaceIpAddress(IpAddress.valueOf("192.168.20.2"),
200 IpPrefix.valueOf("192.168.20.0/24"));
Jonathan Hartce430a42014-10-16 20:44:29 -0700201 Interface intfsw2eth1 = new Interface(s2Eth1,
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -0700202 Collections.singleton(ia2),
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800203 MacAddress.valueOf("00:00:00:00:00:02"),
204 VlanId.NONE);
Jonathan Hartce430a42014-10-16 20:44:29 -0700205 configuredInterfaces.put(interfaceSw2Eth1, intfsw2eth1);
206
207 interfaceService = createMock(InterfaceService.class);
208
209 expect(interfaceService.getInterface(s1Eth1))
210 .andReturn(intfsw1eth1).anyTimes();
211 expect(interfaceService.getInterface(s2Eth1))
212 .andReturn(intfsw2eth1).anyTimes();
213
214 // Non-existent interface used during one of the tests
215 expect(interfaceService.getInterface(new ConnectPoint(
216 DeviceId.deviceId(SdnIp.dpidToUri("00:00:00:00:00:00:01:00")),
217 PortNumber.portNumber(1))))
218 .andReturn(null).anyTimes();
219
220 expect(interfaceService.getInterfaces()).andReturn(
221 Sets.newHashSet(configuredInterfaces.values())).anyTimes();
222 replay(interfaceService);
223
224 return configuredInterfaces;
225 }
226
227 /**
228 * Sets up BGP daemon peers.
229 *
230 * @return configured BGP peers as a MAP from peer IP address to BgpPeer
231 */
232 private Map<IpAddress, BgpPeer> setUpPeers() {
233
234 configuredPeers = new HashMap<>();
235
236 String peerSw1Eth1 = "192.168.10.1";
237 configuredPeers.put(IpAddress.valueOf(peerSw1Eth1),
238 new BgpPeer(dpid1, 1, peerSw1Eth1));
239
240 // Two BGP peers are connected to switch 2 port 1.
241 String peer1Sw2Eth1 = "192.168.20.1";
242 configuredPeers.put(IpAddress.valueOf(peer1Sw2Eth1),
243 new BgpPeer(dpid2, 1, peer1Sw2Eth1));
244
245 String peer2Sw2Eth1 = "192.168.20.2";
246 configuredPeers.put(IpAddress.valueOf(peer2Sw2Eth1),
247 new BgpPeer(dpid2, 1, peer2Sw2Eth1));
248
249 return configuredPeers;
250 }
251
252 /**
253 * Sets up expected point to point intent list.
254 *
255 * @return point to point intent list
256 */
257 private List<PointToPointIntent> setUpIntentList() {
258
259 intentList = new ArrayList<PointToPointIntent>();
260
261 setUpBgpIntents();
262 setUpIcmpIntents();
263
264 return intentList;
265
266 }
267
268 /**
269 * Constructs a BGP intent and put it into the intentList.
270 * <p/>
271 * The purpose of this method is too simplify the setUpBgpIntents() method,
272 * and to make the setUpBgpIntents() easy to read.
273 *
274 * @param srcPrefix source IP prefix to match
275 * @param dstPrefix destination IP prefix to match
276 * @param srcTcpPort source TCP port to match
277 * @param dstTcpPort destination TCP port to match
278 * @param srcConnectPoint source connect point for PointToPointIntent
279 * @param dstConnectPoint destination connect point for PointToPointIntent
280 */
281 private void bgpPathintentConstructor(String srcPrefix, String dstPrefix,
282 Short srcTcpPort, Short dstTcpPort,
283 ConnectPoint srcConnectPoint, ConnectPoint dstConnectPoint) {
284
285 TrafficSelector.Builder builder = DefaultTrafficSelector.builder()
286 .matchEthType(Ethernet.TYPE_IPV4)
287 .matchIPProtocol(IPv4.PROTOCOL_TCP)
288 .matchIPSrc(IpPrefix.valueOf(srcPrefix))
289 .matchIPDst(IpPrefix.valueOf(dstPrefix));
290
291 if (srcTcpPort != null) {
292 builder.matchTcpSrc(srcTcpPort);
293 }
294 if (dstTcpPort != null) {
295 builder.matchTcpDst(dstTcpPort);
296 }
297
298 PointToPointIntent intent = new PointToPointIntent(
Thomas Vachuskab97cf282014-10-20 23:31:12 -0700299 APPID, builder.build(), noTreatment,
Jonathan Hartce430a42014-10-16 20:44:29 -0700300 srcConnectPoint, dstConnectPoint);
301
302 intentList.add(intent);
303 }
304
305 /**
306 * Sets up intents for BGP paths.
307 */
308 private void setUpBgpIntents() {
309
310 Short bgpPort = Short.valueOf((short) BgpConstants.BGP_PORT);
311
312 // Start to build intents between BGP speaker1 and BGP peer1
313 bgpPathintentConstructor(
314 "192.168.10.101/32", "192.168.10.1/32", null, bgpPort,
315 s1Eth100, s1Eth1);
316 bgpPathintentConstructor(
317 "192.168.10.101/32", "192.168.10.1/32", bgpPort, null,
318 s1Eth100, s1Eth1);
319
320 bgpPathintentConstructor(
321 "192.168.10.1/32", "192.168.10.101/32", null, bgpPort,
322 s1Eth1, s1Eth100);
323 bgpPathintentConstructor(
324 "192.168.10.1/32", "192.168.10.101/32", bgpPort, null,
325 s1Eth1, s1Eth100);
326
327 // Start to build intents between BGP speaker1 and BGP peer2
328 bgpPathintentConstructor(
329 "192.168.20.101/32", "192.168.20.1/32", null, bgpPort,
330 s1Eth100, s2Eth1);
331 bgpPathintentConstructor(
332 "192.168.20.101/32", "192.168.20.1/32", bgpPort, null,
333 s1Eth100, s2Eth1);
334
335 bgpPathintentConstructor(
336 "192.168.20.1/32", "192.168.20.101/32", null, bgpPort,
337 s2Eth1, s1Eth100);
338 bgpPathintentConstructor(
339 "192.168.20.1/32", "192.168.20.101/32", bgpPort, null,
340 s2Eth1, s1Eth100);
341
342 // Start to build intents between BGP speaker1 and BGP peer3
343 bgpPathintentConstructor(
344 "192.168.20.101/32", "192.168.20.2/32", null, bgpPort,
345 s1Eth100, s2Eth1);
346 bgpPathintentConstructor(
347 "192.168.20.101/32", "192.168.20.2/32", bgpPort, null,
348 s1Eth100, s2Eth1);
349
350 bgpPathintentConstructor(
351 "192.168.20.2/32", "192.168.20.101/32", null, bgpPort,
352 s2Eth1, s1Eth100);
353 bgpPathintentConstructor(
354 "192.168.20.2/32", "192.168.20.101/32", bgpPort, null,
355 s2Eth1, s1Eth100);
356
357 //
358 // Start to build intents between BGP speaker2 and BGP peer1
359 bgpPathintentConstructor(
360 "192.168.10.102/32", "192.168.10.1/32", null, bgpPort,
361 s1Eth100, s1Eth1);
362 bgpPathintentConstructor(
363 "192.168.10.102/32", "192.168.10.1/32", bgpPort, null,
364 s1Eth100, s1Eth1);
365
366 bgpPathintentConstructor(
367 "192.168.10.1/32", "192.168.10.102/32", null, bgpPort,
368 s1Eth1, s1Eth100);
369 bgpPathintentConstructor(
370 "192.168.10.1/32", "192.168.10.102/32", bgpPort, null,
371 s1Eth1, s1Eth100);
372 // Start to build intents between BGP speaker2 and BGP peer2
373 bgpPathintentConstructor(
374 "192.168.20.102/32", "192.168.20.1/32", null, bgpPort,
375 s1Eth100, s2Eth1);
376 bgpPathintentConstructor(
377 "192.168.20.102/32", "192.168.20.1/32", bgpPort, null,
378 s1Eth100, s2Eth1);
379
380 bgpPathintentConstructor(
381 "192.168.20.1/32", "192.168.20.102/32", null, bgpPort,
382 s2Eth1, s1Eth100);
383 bgpPathintentConstructor(
384 "192.168.20.1/32", "192.168.20.102/32", bgpPort, null,
385 s2Eth1, s1Eth100);
386
387 // Start to build intents between BGP speaker2 and BGP peer3
388 bgpPathintentConstructor(
389 "192.168.20.102/32", "192.168.20.2/32", null, bgpPort,
390 s1Eth100, s2Eth1);
391 bgpPathintentConstructor(
392 "192.168.20.102/32", "192.168.20.2/32", bgpPort, null,
393 s1Eth100, s2Eth1);
394
395 bgpPathintentConstructor(
396 "192.168.20.2/32", "192.168.20.102/32", null, bgpPort,
397 s2Eth1, s1Eth100);
398 bgpPathintentConstructor(
399 "192.168.20.2/32", "192.168.20.102/32", bgpPort, null,
400 s2Eth1, s1Eth100);
401
402 //
403 // Start to build intents between BGP speaker3 and BGP peer1
404 bgpPathintentConstructor(
405 "192.168.10.103/32", "192.168.10.1/32", null, bgpPort,
406 s2Eth100, s1Eth1);
407 bgpPathintentConstructor(
408 "192.168.10.103/32", "192.168.10.1/32", bgpPort, null,
409 s2Eth100, s1Eth1);
410
411 bgpPathintentConstructor(
412 "192.168.10.1/32", "192.168.10.103/32", null, bgpPort,
413 s1Eth1, s2Eth100);
414 bgpPathintentConstructor(
415 "192.168.10.1/32", "192.168.10.103/32", bgpPort, null,
416 s1Eth1, s2Eth100);
417
418 // Start to build intents between BGP speaker3 and BGP peer2
419 bgpPathintentConstructor(
420 "192.168.20.103/32", "192.168.20.1/32", null, bgpPort,
421 s2Eth100, s2Eth1);
422 bgpPathintentConstructor(
423 "192.168.20.103/32", "192.168.20.1/32", bgpPort, null,
424 s2Eth100, s2Eth1);
425
426 bgpPathintentConstructor(
427 "192.168.20.1/32", "192.168.20.103/32", null, bgpPort,
428 s2Eth1, s2Eth100);
429 bgpPathintentConstructor(
430 "192.168.20.1/32", "192.168.20.103/32", bgpPort, null,
431 s2Eth1, s2Eth100);
432
433 // Start to build intents between BGP speaker3 and BGP peer3
434 bgpPathintentConstructor(
435 "192.168.20.103/32", "192.168.20.2/32", null, bgpPort,
436 s2Eth100, s2Eth1);
437 bgpPathintentConstructor(
438 "192.168.20.103/32", "192.168.20.2/32", bgpPort, null,
439 s2Eth100, s2Eth1);
440
441 bgpPathintentConstructor(
442 "192.168.20.2/32", "192.168.20.103/32", null, bgpPort,
443 s2Eth1, s2Eth100);
444 bgpPathintentConstructor(
445 "192.168.20.2/32", "192.168.20.103/32", bgpPort, null,
446 s2Eth1, s2Eth100);
447 }
448
449 /**
450 * Constructs a BGP intent and put it into the intentList.
451 * <p/>
452 * The purpose of this method is too simplify the setUpBgpIntents() method,
453 * and to make the setUpBgpIntents() easy to read.
454 *
455 * @param srcPrefix source IP prefix to match
456 * @param dstPrefix destination IP prefix to match
457 * @param srcConnectPoint source connect point for PointToPointIntent
458 * @param dstConnectPoint destination connect point for PointToPointIntent
459 */
460 private void icmpPathintentConstructor(String srcPrefix, String dstPrefix,
461 ConnectPoint srcConnectPoint, ConnectPoint dstConnectPoint) {
462
463 TrafficSelector selector = DefaultTrafficSelector.builder()
464 .matchEthType(Ethernet.TYPE_IPV4)
465 .matchIPProtocol(IPv4.PROTOCOL_ICMP)
466 .matchIPSrc(IpPrefix.valueOf(srcPrefix))
467 .matchIPDst(IpPrefix.valueOf(dstPrefix))
468 .build();
469
470 PointToPointIntent intent = new PointToPointIntent(
Thomas Vachuskab97cf282014-10-20 23:31:12 -0700471 APPID, selector, noTreatment,
Jonathan Hartce430a42014-10-16 20:44:29 -0700472 srcConnectPoint, dstConnectPoint);
473
474 intentList.add(intent);
475 }
476
477 /**
478 * Sets up intents for ICMP paths.
479 */
480 private void setUpIcmpIntents() {
481
482 // Start to build intents between BGP speaker1 and BGP peer1
483 icmpPathintentConstructor(
484 "192.168.10.101/32", "192.168.10.1/32", s1Eth100, s1Eth1);
485 icmpPathintentConstructor(
486 "192.168.10.1/32", "192.168.10.101/32", s1Eth1, s1Eth100);
487
488 // Start to build intents between BGP speaker1 and BGP peer2
489 icmpPathintentConstructor(
490 "192.168.20.101/32", "192.168.20.1/32", s1Eth100, s2Eth1);
491 icmpPathintentConstructor(
492 "192.168.20.1/32", "192.168.20.101/32", s2Eth1, s1Eth100);
493
494 // Start to build intents between BGP speaker1 and BGP peer3
495 icmpPathintentConstructor(
496 "192.168.20.101/32", "192.168.20.2/32", s1Eth100, s2Eth1);
497 icmpPathintentConstructor(
498 "192.168.20.2/32", "192.168.20.101/32", s2Eth1, s1Eth100);
499
500 //
501 // Start to build intents between BGP speaker2 and BGP peer1
502 icmpPathintentConstructor(
503 "192.168.10.102/32", "192.168.10.1/32", s1Eth100, s1Eth1);
504 icmpPathintentConstructor(
505 "192.168.10.1/32", "192.168.10.102/32", s1Eth1, s1Eth100);
506
507 // Start to build intents between BGP speaker2 and BGP peer2
508 icmpPathintentConstructor(
509 "192.168.20.102/32", "192.168.20.1/32", s1Eth100, s2Eth1);
510 icmpPathintentConstructor(
511 "192.168.20.1/32", "192.168.20.102/32", s2Eth1, s1Eth100);
512
513 // Start to build intents between BGP speaker2 and BGP peer3
514 icmpPathintentConstructor(
515 "192.168.20.102/32", "192.168.20.2/32", s1Eth100, s2Eth1);
516 icmpPathintentConstructor(
517 "192.168.20.2/32", "192.168.20.102/32", s2Eth1, s1Eth100);
518
519 //
520 // Start to build intents between BGP speaker3 and BGP peer1
521 icmpPathintentConstructor(
522 "192.168.10.103/32", "192.168.10.1/32", s2Eth100, s1Eth1);
523 icmpPathintentConstructor(
524 "192.168.10.1/32", "192.168.10.103/32", s1Eth1, s2Eth100);
525
526 // Start to build intents between BGP speaker3 and BGP peer2
527 icmpPathintentConstructor(
528 "192.168.20.103/32", "192.168.20.1/32", s2Eth100, s2Eth1);
529 icmpPathintentConstructor(
530 "192.168.20.1/32", "192.168.20.103/32", s2Eth1, s2Eth100);
531
532 // Start to build intents between BGP speaker3 and BGP peer3
533 icmpPathintentConstructor(
534 "192.168.20.103/32", "192.168.20.2/32", s2Eth100, s2Eth1);
535 icmpPathintentConstructor(
536 "192.168.20.2/32", "192.168.20.103/32", s2Eth1, s2Eth100);
537
538 }
539
540 /**
541 * Initializes peer connectivity testing environment.
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800542 *
543 * @throws TestUtilsException if exceptions when using TestUtils
Jonathan Hartce430a42014-10-16 20:44:29 -0700544 */
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800545 private void initPeerConnectivity() throws TestUtilsException {
Jonathan Hartce430a42014-10-16 20:44:29 -0700546
Jonathan Hart9965d772014-12-02 10:28:34 -0800547 configInfoService = createMock(SdnIpConfigurationService.class);
Jonathan Hartce430a42014-10-16 20:44:29 -0700548 expect(configInfoService.getBgpPeers()).andReturn(peers).anyTimes();
549 expect(configInfoService.getBgpSpeakers()).andReturn(bgpSpeakers).anyTimes();
550 replay(configInfoService);
551
552 intentService = createMock(IntentService.class);
553 replay(intentService);
554
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800555 intentSynchronizer = new IntentSynchronizer(APPID, intentService);
556 intentSynchronizer.leaderChanged(true);
557 TestUtils.setField(intentSynchronizer, "isActivatedLeader", true);
558
559 peerConnectivityManager =
560 new PeerConnectivityManager(APPID, intentSynchronizer,
561 configInfoService, interfaceService);
Jonathan Hartce430a42014-10-16 20:44:29 -0700562 }
563
Jonathan Hartce430a42014-10-16 20:44:29 -0700564 /**
565 * Tests whether peer connectivity manager can set up correct BGP and
566 * ICMP intents according to specific configuration.
567 * <p/>
568 * Two tricky cases included in the configuration are: 2 peers on a same
569 * switch port, peer on the same switch with BGPd.
570 */
571 @Test
572 public void testConnectionSetup() {
573
574 reset(intentService);
575
Pavlin Radoslavovdde22ae2014-11-24 11:47:17 -0800576 // Setup the expected intents
Pavlin Radoslavov248c2ae2014-12-02 09:51:25 -0800577 IntentOperations.Builder builder = IntentOperations.builder(APPID);
Pavlin Radoslavovdde22ae2014-11-24 11:47:17 -0800578 for (Intent intent : intentList) {
579 builder.addSubmitOperation(intent);
Jonathan Hartce430a42014-10-16 20:44:29 -0700580 }
Pavlin Radoslavovdde22ae2014-11-24 11:47:17 -0800581 intentService.execute(TestIntentServiceHelper.eqExceptId(
582 builder.build()));
Jonathan Hartce430a42014-10-16 20:44:29 -0700583 replay(intentService);
584
585 // Running the interface to be tested.
586 peerConnectivityManager.start();
587
588 verify(intentService);
589
590 }
591
592 /**
593 * Tests a corner case, when there are no interfaces in the configuration.
594 */
595 @Test
596 public void testNullInterfaces() {
597 reset(interfaceService);
598 expect(interfaceService.getInterfaces()).andReturn(
599 Sets.<Interface>newHashSet()).anyTimes();
600 expect(interfaceService.getInterface(s2Eth1))
601 .andReturn(null).anyTimes();
602 expect(interfaceService.getInterface(s1Eth1))
603 .andReturn(null).anyTimes();
604 replay(interfaceService);
605
606 reset(configInfoService);
607 expect(configInfoService.getBgpPeers()).andReturn(peers).anyTimes();
608 expect(configInfoService.getBgpSpeakers()).andReturn(bgpSpeakers).anyTimes();
609 replay(configInfoService);
610
611 reset(intentService);
Pavlin Radoslavov248c2ae2014-12-02 09:51:25 -0800612 IntentOperations.Builder builder = IntentOperations.builder(APPID);
613 intentService.execute(builder.build());
Jonathan Hartce430a42014-10-16 20:44:29 -0700614 replay(intentService);
615 peerConnectivityManager.start();
616 verify(intentService);
617 }
618
619 /**
620 * Tests a corner case, when there are no BGP peers in the configuration.
621 */
622 @Test
623 public void testNullBgpPeers() {
624 reset(interfaceService);
625 expect(interfaceService.getInterfaces()).andReturn(
626 Sets.newHashSet(interfaces.values())).anyTimes();
627 replay(interfaceService);
628
629 reset(configInfoService);
630 expect(configInfoService.getBgpPeers()).andReturn(
631 new HashMap<IpAddress, BgpPeer>()).anyTimes();
632 expect(configInfoService.getBgpSpeakers()).andReturn(
633 bgpSpeakers).anyTimes();
634 replay(configInfoService);
635
636 reset(intentService);
Pavlin Radoslavov248c2ae2014-12-02 09:51:25 -0800637 IntentOperations.Builder builder = IntentOperations.builder(APPID);
638 intentService.execute(builder.build());
Jonathan Hartce430a42014-10-16 20:44:29 -0700639 replay(intentService);
640 peerConnectivityManager.start();
641 verify(intentService);
642 }
643
644 /**
645 * Tests a corner case, when there is no BGP speakers in the configuration.
646 */
647 @Test
648 public void testNullBgpSpeakers() {
649 reset(interfaceService);
650 expect(interfaceService.getInterfaces()).andReturn(
651 Sets.newHashSet(interfaces.values())).anyTimes();
652 replay(interfaceService);
653
654 reset(configInfoService);
655 expect(configInfoService.getBgpPeers()).andReturn(
656 peers).anyTimes();
657 expect(configInfoService.getBgpSpeakers()).andReturn(
Jonathan Hart51372182014-12-03 21:32:34 -0800658 Collections.emptyMap()).anyTimes();
Jonathan Hartce430a42014-10-16 20:44:29 -0700659 replay(configInfoService);
660
661 reset(intentService);
Jonathan Hart51372182014-12-03 21:32:34 -0800662 IntentOperations.Builder builder = IntentOperations.builder(APPID);
663 intentService.execute(builder.build());
Jonathan Hartce430a42014-10-16 20:44:29 -0700664 replay(intentService);
665 peerConnectivityManager.start();
666 verify(intentService);
667 }
668
669 /**
670 * Tests a corner case, when there is no Interface configured for one BGP
671 * peer.
672 */
673 @Test
674 public void testNoPeerInterface() {
675 String peerSw100Eth1 = "192.168.200.1";
676 configuredPeers.put(IpAddress.valueOf(peerSw100Eth1),
677 new BgpPeer("00:00:00:00:00:00:01:00", 1, peerSw100Eth1));
678 testConnectionSetup();
679 }
680
681 /**
682 * Tests a corner case, when there is no Interface configured for one BGP
683 * speaker.
Jonathan Hartce430a42014-10-16 20:44:29 -0700684 */
685 @Ignore
686 @Test
687 public void testNoSpeakerInterface() {
688 BgpSpeaker bgpSpeaker100 = new BgpSpeaker(
689 "bgpSpeaker100",
690 "00:00:00:00:00:00:01:00", 100,
691 "00:00:00:00:01:00");
692 List<InterfaceAddress> interfaceAddresses100 =
693 new LinkedList<InterfaceAddress>();
694 interfaceAddresses100.add(new InterfaceAddress(dpid1, 1, "192.168.10.201"));
695 interfaceAddresses100.add(new InterfaceAddress(dpid2, 1, "192.168.20.201"));
696 bgpSpeaker100.setInterfaceAddresses(interfaceAddresses100);
697 configuredBgpSpeakers.put(bgpSpeaker100.name(), bgpSpeaker100);
698 testConnectionSetup();
699 }
700}