blob: 0088d920ed3c93a8f6aa1a92729c0bfd99d71815 [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;
Brian O'Connorabafb502014-12-02 22:26:20 -080043import org.onosproject.sdnip.config.BgpPeer;
44import org.onosproject.sdnip.config.BgpSpeaker;
45import org.onosproject.sdnip.config.Interface;
46import org.onosproject.sdnip.config.InterfaceAddress;
47import org.onosproject.sdnip.config.SdnIpConfigurationService;
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 Hartce430a42014-10-16 20:44:29 -070057
58/**
Jonathan Hart51372182014-12-03 21:32:34 -080059 * Unit tests for PeerConnectivityManager.
Jonathan Hartce430a42014-10-16 20:44:29 -070060 */
Jonathan Hart4fd4ebb2015-02-04 17:38:48 -080061@Ignore
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 Hart9965d772014-12-02 10:28:34 -080078 private SdnIpConfigurationService configInfoService;
Jonathan Hartce430a42014-10-16 20:44:29 -070079 private InterfaceService interfaceService;
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -080080 private IntentService intentService;
Jonathan Hartce430a42014-10-16 20:44:29 -070081
82 private Map<String, BgpSpeaker> bgpSpeakers;
83 private Map<String, Interface> interfaces;
84 private Map<IpAddress, BgpPeer> peers;
85
86 private Map<String, BgpSpeaker> configuredBgpSpeakers;
87 private Map<String, Interface> configuredInterfaces;
88 private Map<IpAddress, BgpPeer> configuredPeers;
89 private List<PointToPointIntent> intentList;
90
91 private final String dpid1 = "00:00:00:00:00:00:00:01";
92 private final String dpid2 = "00:00:00:00:00:00:00:02";
93
94 private final DeviceId deviceId1 =
95 DeviceId.deviceId(SdnIp.dpidToUri(dpid1));
96 private final DeviceId deviceId2 =
97 DeviceId.deviceId(SdnIp.dpidToUri(dpid2));
98
99 // Interfaces connected to BGP speakers
100 private final ConnectPoint s1Eth100 =
101 new ConnectPoint(deviceId1, PortNumber.portNumber(100));
102 private final ConnectPoint s2Eth100 =
103 new ConnectPoint(deviceId2, PortNumber.portNumber(100));
104
105 // Interfaces connected to BGP peers
106 private final ConnectPoint s1Eth1 =
107 new ConnectPoint(deviceId1, PortNumber.portNumber(1));
108 private final ConnectPoint s2Eth1 =
109 new ConnectPoint(deviceId2, PortNumber.portNumber(1));
110
Jonathan Hartce430a42014-10-16 20:44:29 -0700111 private final TrafficTreatment noTreatment =
112 DefaultTrafficTreatment.builder().build();
113
114 @Before
115 public void setUp() throws Exception {
Brian O'Connor520c0522014-11-23 23:50:47 -0800116 super.setUp();
Jonathan Hartce430a42014-10-16 20:44:29 -0700117 bgpSpeakers = Collections.unmodifiableMap(setUpBgpSpeakers());
118 interfaces = Collections.unmodifiableMap(setUpInterfaces());
119 peers = Collections.unmodifiableMap(setUpPeers());
120
121 initPeerConnectivity();
122 intentList = setUpIntentList();
123 }
124
125 /**
126 * Sets up BGP speakers.
127 *
128 * @return configured BGP speakers as a map from speaker name to speaker
129 */
130 private Map<String, BgpSpeaker> setUpBgpSpeakers() {
131
132 configuredBgpSpeakers = new HashMap<>();
133
134 BgpSpeaker bgpSpeaker1 = new BgpSpeaker(
135 "bgpSpeaker1",
136 "00:00:00:00:00:00:00:01", 100,
137 "00:00:00:00:00:01");
138 List<InterfaceAddress> interfaceAddresses1 =
139 new LinkedList<InterfaceAddress>();
140 interfaceAddresses1.add(new InterfaceAddress(dpid1, 1, "192.168.10.101"));
141 interfaceAddresses1.add(new InterfaceAddress(dpid2, 1, "192.168.20.101"));
142 bgpSpeaker1.setInterfaceAddresses(interfaceAddresses1);
143 configuredBgpSpeakers.put(bgpSpeaker1.name(), bgpSpeaker1);
144
145 // BGP speaker2 is attached to the same switch port with speaker1
146 BgpSpeaker bgpSpeaker2 = new BgpSpeaker(
147 "bgpSpeaker2",
148 "00:00:00:00:00:00:00:01", 100,
149 "00:00:00:00:00:02");
150 List<InterfaceAddress> interfaceAddresses2 =
151 new LinkedList<InterfaceAddress>();
152 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");
161 List<InterfaceAddress> interfaceAddresses3 =
162 new LinkedList<InterfaceAddress>();
163 interfaceAddresses3.add(new InterfaceAddress(dpid1, 1, "192.168.10.103"));
164 interfaceAddresses3.add(new InterfaceAddress(dpid2, 1, "192.168.20.103"));
165 bgpSpeaker3.setInterfaceAddresses(interfaceAddresses3);
166 configuredBgpSpeakers.put(bgpSpeaker3.name(), bgpSpeaker3);
167
168 return configuredBgpSpeakers;
169 }
170
171 /**
172 * Sets up logical interfaces, which emulate the configured interfaces
173 * in SDN-IP application.
174 *
175 * @return configured interfaces as a MAP from Interface name to Interface
176 */
177 private Map<String, Interface> setUpInterfaces() {
178
179 configuredInterfaces = new HashMap<>();
180
181 String interfaceSw1Eth1 = "s1-eth1";
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -0700182 InterfaceIpAddress ia1 =
183 new InterfaceIpAddress(IpAddress.valueOf("192.168.10.1"),
184 IpPrefix.valueOf("192.168.10.0/24"));
Jonathan Hartce430a42014-10-16 20:44:29 -0700185 Interface intfsw1eth1 = new Interface(s1Eth1,
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -0700186 Collections.singleton(ia1),
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800187 MacAddress.valueOf("00:00:00:00:00:01"),
188 VlanId.NONE);
Jonathan Hartce430a42014-10-16 20:44:29 -0700189
190 configuredInterfaces.put(interfaceSw1Eth1, intfsw1eth1);
191 String interfaceSw2Eth1 = "s2-eth1";
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -0700192 InterfaceIpAddress ia2 =
193 new InterfaceIpAddress(IpAddress.valueOf("192.168.20.2"),
194 IpPrefix.valueOf("192.168.20.0/24"));
Jonathan Hartce430a42014-10-16 20:44:29 -0700195 Interface intfsw2eth1 = new Interface(s2Eth1,
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -0700196 Collections.singleton(ia2),
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800197 MacAddress.valueOf("00:00:00:00:00:02"),
198 VlanId.NONE);
Jonathan Hartce430a42014-10-16 20:44:29 -0700199 configuredInterfaces.put(interfaceSw2Eth1, intfsw2eth1);
200
201 interfaceService = createMock(InterfaceService.class);
202
203 expect(interfaceService.getInterface(s1Eth1))
204 .andReturn(intfsw1eth1).anyTimes();
205 expect(interfaceService.getInterface(s2Eth1))
206 .andReturn(intfsw2eth1).anyTimes();
207
208 // Non-existent interface used during one of the tests
209 expect(interfaceService.getInterface(new ConnectPoint(
210 DeviceId.deviceId(SdnIp.dpidToUri("00:00:00:00:00:00:01:00")),
211 PortNumber.portNumber(1))))
212 .andReturn(null).anyTimes();
213
214 expect(interfaceService.getInterfaces()).andReturn(
215 Sets.newHashSet(configuredInterfaces.values())).anyTimes();
216 replay(interfaceService);
217
218 return configuredInterfaces;
219 }
220
221 /**
222 * Sets up BGP daemon peers.
223 *
224 * @return configured BGP peers as a MAP from peer IP address to BgpPeer
225 */
226 private Map<IpAddress, BgpPeer> setUpPeers() {
227
228 configuredPeers = new HashMap<>();
229
230 String peerSw1Eth1 = "192.168.10.1";
231 configuredPeers.put(IpAddress.valueOf(peerSw1Eth1),
232 new BgpPeer(dpid1, 1, peerSw1Eth1));
233
234 // Two BGP peers are connected to switch 2 port 1.
235 String peer1Sw2Eth1 = "192.168.20.1";
236 configuredPeers.put(IpAddress.valueOf(peer1Sw2Eth1),
237 new BgpPeer(dpid2, 1, peer1Sw2Eth1));
238
239 String peer2Sw2Eth1 = "192.168.20.2";
240 configuredPeers.put(IpAddress.valueOf(peer2Sw2Eth1),
241 new BgpPeer(dpid2, 1, peer2Sw2Eth1));
242
243 return configuredPeers;
244 }
245
246 /**
247 * Sets up expected point to point intent list.
248 *
249 * @return point to point intent list
250 */
251 private List<PointToPointIntent> setUpIntentList() {
252
253 intentList = new ArrayList<PointToPointIntent>();
254
255 setUpBgpIntents();
256 setUpIcmpIntents();
257
258 return intentList;
259
260 }
261
262 /**
263 * Constructs a BGP intent and put it into the intentList.
264 * <p/>
265 * The purpose of this method is too simplify the setUpBgpIntents() method,
266 * and to make the setUpBgpIntents() easy to read.
267 *
268 * @param srcPrefix source IP prefix to match
269 * @param dstPrefix destination IP prefix to match
270 * @param srcTcpPort source TCP port to match
271 * @param dstTcpPort destination TCP port to match
272 * @param srcConnectPoint source connect point for PointToPointIntent
273 * @param dstConnectPoint destination connect point for PointToPointIntent
274 */
275 private void bgpPathintentConstructor(String srcPrefix, String dstPrefix,
276 Short srcTcpPort, Short dstTcpPort,
277 ConnectPoint srcConnectPoint, ConnectPoint dstConnectPoint) {
278
279 TrafficSelector.Builder builder = DefaultTrafficSelector.builder()
280 .matchEthType(Ethernet.TYPE_IPV4)
281 .matchIPProtocol(IPv4.PROTOCOL_TCP)
282 .matchIPSrc(IpPrefix.valueOf(srcPrefix))
283 .matchIPDst(IpPrefix.valueOf(dstPrefix));
284
285 if (srcTcpPort != null) {
286 builder.matchTcpSrc(srcTcpPort);
287 }
288 if (dstTcpPort != null) {
289 builder.matchTcpDst(dstTcpPort);
290 }
291
292 PointToPointIntent intent = new PointToPointIntent(
Thomas Vachuskab97cf282014-10-20 23:31:12 -0700293 APPID, builder.build(), noTreatment,
Jonathan Hartce430a42014-10-16 20:44:29 -0700294 srcConnectPoint, dstConnectPoint);
295
296 intentList.add(intent);
297 }
298
299 /**
300 * Sets up intents for BGP paths.
301 */
302 private void setUpBgpIntents() {
303
Jonathan Hart41349e92015-02-09 14:14:02 -0800304 Short bgpPort = 179;
Jonathan Hartce430a42014-10-16 20:44:29 -0700305
306 // Start to build intents between BGP speaker1 and BGP peer1
307 bgpPathintentConstructor(
308 "192.168.10.101/32", "192.168.10.1/32", null, bgpPort,
309 s1Eth100, s1Eth1);
310 bgpPathintentConstructor(
311 "192.168.10.101/32", "192.168.10.1/32", bgpPort, null,
312 s1Eth100, s1Eth1);
313
314 bgpPathintentConstructor(
315 "192.168.10.1/32", "192.168.10.101/32", null, bgpPort,
316 s1Eth1, s1Eth100);
317 bgpPathintentConstructor(
318 "192.168.10.1/32", "192.168.10.101/32", bgpPort, null,
319 s1Eth1, s1Eth100);
320
321 // Start to build intents between BGP speaker1 and BGP peer2
322 bgpPathintentConstructor(
323 "192.168.20.101/32", "192.168.20.1/32", null, bgpPort,
324 s1Eth100, s2Eth1);
325 bgpPathintentConstructor(
326 "192.168.20.101/32", "192.168.20.1/32", bgpPort, null,
327 s1Eth100, s2Eth1);
328
329 bgpPathintentConstructor(
330 "192.168.20.1/32", "192.168.20.101/32", null, bgpPort,
331 s2Eth1, s1Eth100);
332 bgpPathintentConstructor(
333 "192.168.20.1/32", "192.168.20.101/32", bgpPort, null,
334 s2Eth1, s1Eth100);
335
336 // Start to build intents between BGP speaker1 and BGP peer3
337 bgpPathintentConstructor(
338 "192.168.20.101/32", "192.168.20.2/32", null, bgpPort,
339 s1Eth100, s2Eth1);
340 bgpPathintentConstructor(
341 "192.168.20.101/32", "192.168.20.2/32", bgpPort, null,
342 s1Eth100, s2Eth1);
343
344 bgpPathintentConstructor(
345 "192.168.20.2/32", "192.168.20.101/32", null, bgpPort,
346 s2Eth1, s1Eth100);
347 bgpPathintentConstructor(
348 "192.168.20.2/32", "192.168.20.101/32", bgpPort, null,
349 s2Eth1, s1Eth100);
350
351 //
352 // Start to build intents between BGP speaker2 and BGP peer1
353 bgpPathintentConstructor(
354 "192.168.10.102/32", "192.168.10.1/32", null, bgpPort,
355 s1Eth100, s1Eth1);
356 bgpPathintentConstructor(
357 "192.168.10.102/32", "192.168.10.1/32", bgpPort, null,
358 s1Eth100, s1Eth1);
359
360 bgpPathintentConstructor(
361 "192.168.10.1/32", "192.168.10.102/32", null, bgpPort,
362 s1Eth1, s1Eth100);
363 bgpPathintentConstructor(
364 "192.168.10.1/32", "192.168.10.102/32", bgpPort, null,
365 s1Eth1, s1Eth100);
366 // Start to build intents between BGP speaker2 and BGP peer2
367 bgpPathintentConstructor(
368 "192.168.20.102/32", "192.168.20.1/32", null, bgpPort,
369 s1Eth100, s2Eth1);
370 bgpPathintentConstructor(
371 "192.168.20.102/32", "192.168.20.1/32", bgpPort, null,
372 s1Eth100, s2Eth1);
373
374 bgpPathintentConstructor(
375 "192.168.20.1/32", "192.168.20.102/32", null, bgpPort,
376 s2Eth1, s1Eth100);
377 bgpPathintentConstructor(
378 "192.168.20.1/32", "192.168.20.102/32", bgpPort, null,
379 s2Eth1, s1Eth100);
380
381 // Start to build intents between BGP speaker2 and BGP peer3
382 bgpPathintentConstructor(
383 "192.168.20.102/32", "192.168.20.2/32", null, bgpPort,
384 s1Eth100, s2Eth1);
385 bgpPathintentConstructor(
386 "192.168.20.102/32", "192.168.20.2/32", bgpPort, null,
387 s1Eth100, s2Eth1);
388
389 bgpPathintentConstructor(
390 "192.168.20.2/32", "192.168.20.102/32", null, bgpPort,
391 s2Eth1, s1Eth100);
392 bgpPathintentConstructor(
393 "192.168.20.2/32", "192.168.20.102/32", bgpPort, null,
394 s2Eth1, s1Eth100);
395
396 //
397 // Start to build intents between BGP speaker3 and BGP peer1
398 bgpPathintentConstructor(
399 "192.168.10.103/32", "192.168.10.1/32", null, bgpPort,
400 s2Eth100, s1Eth1);
401 bgpPathintentConstructor(
402 "192.168.10.103/32", "192.168.10.1/32", bgpPort, null,
403 s2Eth100, s1Eth1);
404
405 bgpPathintentConstructor(
406 "192.168.10.1/32", "192.168.10.103/32", null, bgpPort,
407 s1Eth1, s2Eth100);
408 bgpPathintentConstructor(
409 "192.168.10.1/32", "192.168.10.103/32", bgpPort, null,
410 s1Eth1, s2Eth100);
411
412 // Start to build intents between BGP speaker3 and BGP peer2
413 bgpPathintentConstructor(
414 "192.168.20.103/32", "192.168.20.1/32", null, bgpPort,
415 s2Eth100, s2Eth1);
416 bgpPathintentConstructor(
417 "192.168.20.103/32", "192.168.20.1/32", bgpPort, null,
418 s2Eth100, s2Eth1);
419
420 bgpPathintentConstructor(
421 "192.168.20.1/32", "192.168.20.103/32", null, bgpPort,
422 s2Eth1, s2Eth100);
423 bgpPathintentConstructor(
424 "192.168.20.1/32", "192.168.20.103/32", bgpPort, null,
425 s2Eth1, s2Eth100);
426
427 // Start to build intents between BGP speaker3 and BGP peer3
428 bgpPathintentConstructor(
429 "192.168.20.103/32", "192.168.20.2/32", null, bgpPort,
430 s2Eth100, s2Eth1);
431 bgpPathintentConstructor(
432 "192.168.20.103/32", "192.168.20.2/32", bgpPort, null,
433 s2Eth100, s2Eth1);
434
435 bgpPathintentConstructor(
436 "192.168.20.2/32", "192.168.20.103/32", null, bgpPort,
437 s2Eth1, s2Eth100);
438 bgpPathintentConstructor(
439 "192.168.20.2/32", "192.168.20.103/32", bgpPort, null,
440 s2Eth1, s2Eth100);
441 }
442
443 /**
444 * Constructs a BGP intent and put it into the intentList.
445 * <p/>
446 * The purpose of this method is too simplify the setUpBgpIntents() method,
447 * and to make the setUpBgpIntents() easy to read.
448 *
449 * @param srcPrefix source IP prefix to match
450 * @param dstPrefix destination IP prefix to match
451 * @param srcConnectPoint source connect point for PointToPointIntent
452 * @param dstConnectPoint destination connect point for PointToPointIntent
453 */
454 private void icmpPathintentConstructor(String srcPrefix, String dstPrefix,
455 ConnectPoint srcConnectPoint, ConnectPoint dstConnectPoint) {
456
457 TrafficSelector selector = DefaultTrafficSelector.builder()
458 .matchEthType(Ethernet.TYPE_IPV4)
459 .matchIPProtocol(IPv4.PROTOCOL_ICMP)
460 .matchIPSrc(IpPrefix.valueOf(srcPrefix))
461 .matchIPDst(IpPrefix.valueOf(dstPrefix))
462 .build();
463
464 PointToPointIntent intent = new PointToPointIntent(
Thomas Vachuskab97cf282014-10-20 23:31:12 -0700465 APPID, selector, noTreatment,
Jonathan Hartce430a42014-10-16 20:44:29 -0700466 srcConnectPoint, dstConnectPoint);
467
468 intentList.add(intent);
469 }
470
471 /**
472 * Sets up intents for ICMP paths.
473 */
474 private void setUpIcmpIntents() {
475
476 // Start to build intents between BGP speaker1 and BGP peer1
477 icmpPathintentConstructor(
478 "192.168.10.101/32", "192.168.10.1/32", s1Eth100, s1Eth1);
479 icmpPathintentConstructor(
480 "192.168.10.1/32", "192.168.10.101/32", s1Eth1, s1Eth100);
481
482 // Start to build intents between BGP speaker1 and BGP peer2
483 icmpPathintentConstructor(
484 "192.168.20.101/32", "192.168.20.1/32", s1Eth100, s2Eth1);
485 icmpPathintentConstructor(
486 "192.168.20.1/32", "192.168.20.101/32", s2Eth1, s1Eth100);
487
488 // Start to build intents between BGP speaker1 and BGP peer3
489 icmpPathintentConstructor(
490 "192.168.20.101/32", "192.168.20.2/32", s1Eth100, s2Eth1);
491 icmpPathintentConstructor(
492 "192.168.20.2/32", "192.168.20.101/32", s2Eth1, s1Eth100);
493
494 //
495 // Start to build intents between BGP speaker2 and BGP peer1
496 icmpPathintentConstructor(
497 "192.168.10.102/32", "192.168.10.1/32", s1Eth100, s1Eth1);
498 icmpPathintentConstructor(
499 "192.168.10.1/32", "192.168.10.102/32", s1Eth1, s1Eth100);
500
501 // Start to build intents between BGP speaker2 and BGP peer2
502 icmpPathintentConstructor(
503 "192.168.20.102/32", "192.168.20.1/32", s1Eth100, s2Eth1);
504 icmpPathintentConstructor(
505 "192.168.20.1/32", "192.168.20.102/32", s2Eth1, s1Eth100);
506
507 // Start to build intents between BGP speaker2 and BGP peer3
508 icmpPathintentConstructor(
509 "192.168.20.102/32", "192.168.20.2/32", s1Eth100, s2Eth1);
510 icmpPathintentConstructor(
511 "192.168.20.2/32", "192.168.20.102/32", s2Eth1, s1Eth100);
512
513 //
514 // Start to build intents between BGP speaker3 and BGP peer1
515 icmpPathintentConstructor(
516 "192.168.10.103/32", "192.168.10.1/32", s2Eth100, s1Eth1);
517 icmpPathintentConstructor(
518 "192.168.10.1/32", "192.168.10.103/32", s1Eth1, s2Eth100);
519
520 // Start to build intents between BGP speaker3 and BGP peer2
521 icmpPathintentConstructor(
522 "192.168.20.103/32", "192.168.20.1/32", s2Eth100, s2Eth1);
523 icmpPathintentConstructor(
524 "192.168.20.1/32", "192.168.20.103/32", s2Eth1, s2Eth100);
525
526 // Start to build intents between BGP speaker3 and BGP peer3
527 icmpPathintentConstructor(
528 "192.168.20.103/32", "192.168.20.2/32", s2Eth100, s2Eth1);
529 icmpPathintentConstructor(
530 "192.168.20.2/32", "192.168.20.103/32", s2Eth1, s2Eth100);
531
532 }
533
534 /**
535 * Initializes peer connectivity testing environment.
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800536 *
537 * @throws TestUtilsException if exceptions when using TestUtils
Jonathan Hartce430a42014-10-16 20:44:29 -0700538 */
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800539 private void initPeerConnectivity() throws TestUtilsException {
Jonathan Hartce430a42014-10-16 20:44:29 -0700540
Jonathan Hart9965d772014-12-02 10:28:34 -0800541 configInfoService = createMock(SdnIpConfigurationService.class);
Jonathan Hartce430a42014-10-16 20:44:29 -0700542 expect(configInfoService.getBgpPeers()).andReturn(peers).anyTimes();
543 expect(configInfoService.getBgpSpeakers()).andReturn(bgpSpeakers).anyTimes();
544 replay(configInfoService);
545
546 intentService = createMock(IntentService.class);
547 replay(intentService);
548
Jonathan Hart552e31f2015-02-06 11:11:59 -0800549 intentSynchronizer = new IntentSynchronizer(APPID, intentService,
550 configInfoService,
551 interfaceService);
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800552 intentSynchronizer.leaderChanged(true);
553 TestUtils.setField(intentSynchronizer, "isActivatedLeader", true);
554
555 peerConnectivityManager =
556 new PeerConnectivityManager(APPID, intentSynchronizer,
557 configInfoService, interfaceService);
Jonathan Hartce430a42014-10-16 20:44:29 -0700558 }
559
Jonathan Hartce430a42014-10-16 20:44:29 -0700560 /**
561 * Tests whether peer connectivity manager can set up correct BGP and
562 * ICMP intents according to specific configuration.
563 * <p/>
564 * Two tricky cases included in the configuration are: 2 peers on a same
565 * switch port, peer on the same switch with BGPd.
566 */
567 @Test
568 public void testConnectionSetup() {
569
570 reset(intentService);
571
Pavlin Radoslavovdde22ae2014-11-24 11:47:17 -0800572 // Setup the expected intents
Pavlin Radoslavovdde22ae2014-11-24 11:47:17 -0800573 for (Intent intent : intentList) {
Brian O'Connor03406a42015-02-03 17:28:57 -0800574 intentService.submit(intent);
Jonathan Hartce430a42014-10-16 20:44:29 -0700575 }
Jonathan Hartce430a42014-10-16 20:44:29 -0700576 replay(intentService);
577
578 // Running the interface to be tested.
579 peerConnectivityManager.start();
580
581 verify(intentService);
582
583 }
584
585 /**
586 * Tests a corner case, when there are no interfaces in the configuration.
587 */
588 @Test
589 public void testNullInterfaces() {
590 reset(interfaceService);
591 expect(interfaceService.getInterfaces()).andReturn(
592 Sets.<Interface>newHashSet()).anyTimes();
593 expect(interfaceService.getInterface(s2Eth1))
594 .andReturn(null).anyTimes();
595 expect(interfaceService.getInterface(s1Eth1))
596 .andReturn(null).anyTimes();
597 replay(interfaceService);
598
599 reset(configInfoService);
600 expect(configInfoService.getBgpPeers()).andReturn(peers).anyTimes();
601 expect(configInfoService.getBgpSpeakers()).andReturn(bgpSpeakers).anyTimes();
602 replay(configInfoService);
603
604 reset(intentService);
605 replay(intentService);
606 peerConnectivityManager.start();
607 verify(intentService);
608 }
609
610 /**
611 * Tests a corner case, when there are no BGP peers in the configuration.
612 */
613 @Test
614 public void testNullBgpPeers() {
615 reset(interfaceService);
616 expect(interfaceService.getInterfaces()).andReturn(
617 Sets.newHashSet(interfaces.values())).anyTimes();
618 replay(interfaceService);
619
620 reset(configInfoService);
621 expect(configInfoService.getBgpPeers()).andReturn(
622 new HashMap<IpAddress, BgpPeer>()).anyTimes();
623 expect(configInfoService.getBgpSpeakers()).andReturn(
624 bgpSpeakers).anyTimes();
625 replay(configInfoService);
626
627 reset(intentService);
Jonathan Hartce430a42014-10-16 20:44:29 -0700628 replay(intentService);
629 peerConnectivityManager.start();
630 verify(intentService);
631 }
632
633 /**
634 * Tests a corner case, when there is no BGP speakers in the configuration.
635 */
636 @Test
637 public void testNullBgpSpeakers() {
638 reset(interfaceService);
639 expect(interfaceService.getInterfaces()).andReturn(
640 Sets.newHashSet(interfaces.values())).anyTimes();
641 replay(interfaceService);
642
643 reset(configInfoService);
644 expect(configInfoService.getBgpPeers()).andReturn(
645 peers).anyTimes();
646 expect(configInfoService.getBgpSpeakers()).andReturn(
Jonathan Hart51372182014-12-03 21:32:34 -0800647 Collections.emptyMap()).anyTimes();
Jonathan Hartce430a42014-10-16 20:44:29 -0700648 replay(configInfoService);
649
650 reset(intentService);
Jonathan Hartce430a42014-10-16 20:44:29 -0700651 replay(intentService);
652 peerConnectivityManager.start();
653 verify(intentService);
654 }
655
656 /**
657 * Tests a corner case, when there is no Interface configured for one BGP
658 * peer.
659 */
660 @Test
661 public void testNoPeerInterface() {
662 String peerSw100Eth1 = "192.168.200.1";
663 configuredPeers.put(IpAddress.valueOf(peerSw100Eth1),
664 new BgpPeer("00:00:00:00:00:00:01:00", 1, peerSw100Eth1));
665 testConnectionSetup();
666 }
667
668 /**
669 * Tests a corner case, when there is no Interface configured for one BGP
670 * speaker.
Jonathan Hartce430a42014-10-16 20:44:29 -0700671 */
672 @Ignore
673 @Test
674 public void testNoSpeakerInterface() {
675 BgpSpeaker bgpSpeaker100 = new BgpSpeaker(
676 "bgpSpeaker100",
677 "00:00:00:00:00:00:01:00", 100,
678 "00:00:00:00:01:00");
679 List<InterfaceAddress> interfaceAddresses100 =
680 new LinkedList<InterfaceAddress>();
681 interfaceAddresses100.add(new InterfaceAddress(dpid1, 1, "192.168.10.201"));
682 interfaceAddresses100.add(new InterfaceAddress(dpid2, 1, "192.168.20.201"));
683 bgpSpeaker100.setInterfaceAddresses(interfaceAddresses100);
684 configuredBgpSpeakers.put(bgpSpeaker100.name(), bgpSpeaker100);
685 testConnectionSetup();
686 }
687}