blob: 962a6ec31e32dbdb90edf8642e3c85c7a5afe07c [file] [log] [blame]
Jonathan Hartce430a42014-10-16 20:44:29 -07001package org.onlab.onos.sdnip;
2
Thomas Vachuskab97cf282014-10-20 23:31:12 -07003import com.google.common.collect.Sets;
Jonathan Hartce430a42014-10-16 20:44:29 -07004import org.easymock.IArgumentMatcher;
5import org.junit.Before;
6import org.junit.Ignore;
7import org.junit.Test;
Thomas Vachuskab97cf282014-10-20 23:31:12 -07008import org.onlab.onos.ApplicationId;
Jonathan Hartce430a42014-10-16 20:44:29 -07009import org.onlab.onos.net.ConnectPoint;
10import org.onlab.onos.net.DeviceId;
11import org.onlab.onos.net.PortNumber;
12import org.onlab.onos.net.flow.DefaultTrafficSelector;
13import org.onlab.onos.net.flow.DefaultTrafficTreatment;
14import org.onlab.onos.net.flow.TrafficSelector;
15import org.onlab.onos.net.flow.TrafficTreatment;
Jonathan Hartce430a42014-10-16 20:44:29 -070016import org.onlab.onos.net.intent.IntentService;
17import org.onlab.onos.net.intent.PointToPointIntent;
18import org.onlab.onos.sdnip.bgp.BgpConstants;
19import org.onlab.onos.sdnip.config.BgpPeer;
20import org.onlab.onos.sdnip.config.BgpSpeaker;
21import org.onlab.onos.sdnip.config.Interface;
22import org.onlab.onos.sdnip.config.InterfaceAddress;
23import org.onlab.onos.sdnip.config.SdnIpConfigService;
24import org.onlab.packet.Ethernet;
25import org.onlab.packet.IPv4;
26import org.onlab.packet.IpAddress;
27import org.onlab.packet.IpPrefix;
28import org.onlab.packet.MacAddress;
29
Thomas Vachuskab97cf282014-10-20 23:31:12 -070030import java.util.ArrayList;
31import java.util.Collections;
32import java.util.HashMap;
33import java.util.LinkedList;
34import java.util.List;
35import java.util.Map;
36
37import static org.easymock.EasyMock.*;
Jonathan Hartce430a42014-10-16 20:44:29 -070038
39/**
40 * Unit tests for PeerConnectivityManager interface.
41 */
42public class PeerConnectivityManagerTest {
43
Thomas Vachuskab97cf282014-10-20 23:31:12 -070044 private static final ApplicationId APPID = new ApplicationId() {
45 @Override
46 public short id() {
47 return 0;
48 }
49
50 @Override
51 public String name() {
52 return "foo";
53 }
54 };
55
Jonathan Hartce430a42014-10-16 20:44:29 -070056 private PeerConnectivityManager peerConnectivityManager;
57 private IntentService intentService;
58 private SdnIpConfigService configInfoService;
59 private InterfaceService interfaceService;
60
61 private Map<String, BgpSpeaker> bgpSpeakers;
62 private Map<String, Interface> interfaces;
63 private Map<IpAddress, BgpPeer> peers;
64
65 private Map<String, BgpSpeaker> configuredBgpSpeakers;
66 private Map<String, Interface> configuredInterfaces;
67 private Map<IpAddress, BgpPeer> configuredPeers;
68 private List<PointToPointIntent> intentList;
69
70 private final String dpid1 = "00:00:00:00:00:00:00:01";
71 private final String dpid2 = "00:00:00:00:00:00:00:02";
72
73 private final DeviceId deviceId1 =
74 DeviceId.deviceId(SdnIp.dpidToUri(dpid1));
75 private final DeviceId deviceId2 =
76 DeviceId.deviceId(SdnIp.dpidToUri(dpid2));
77
78 // Interfaces connected to BGP speakers
79 private final ConnectPoint s1Eth100 =
80 new ConnectPoint(deviceId1, PortNumber.portNumber(100));
81 private final ConnectPoint s2Eth100 =
82 new ConnectPoint(deviceId2, PortNumber.portNumber(100));
83
84 // Interfaces connected to BGP peers
85 private final ConnectPoint s1Eth1 =
86 new ConnectPoint(deviceId1, PortNumber.portNumber(1));
87 private final ConnectPoint s2Eth1 =
88 new ConnectPoint(deviceId2, PortNumber.portNumber(1));
89
Jonathan Hartce430a42014-10-16 20:44:29 -070090 private final TrafficTreatment noTreatment =
91 DefaultTrafficTreatment.builder().build();
92
93 @Before
94 public void setUp() throws Exception {
95 bgpSpeakers = Collections.unmodifiableMap(setUpBgpSpeakers());
96 interfaces = Collections.unmodifiableMap(setUpInterfaces());
97 peers = Collections.unmodifiableMap(setUpPeers());
98
99 initPeerConnectivity();
100 intentList = setUpIntentList();
101 }
102
103 /**
104 * Sets up BGP speakers.
105 *
106 * @return configured BGP speakers as a map from speaker name to speaker
107 */
108 private Map<String, BgpSpeaker> setUpBgpSpeakers() {
109
110 configuredBgpSpeakers = new HashMap<>();
111
112 BgpSpeaker bgpSpeaker1 = new BgpSpeaker(
113 "bgpSpeaker1",
114 "00:00:00:00:00:00:00:01", 100,
115 "00:00:00:00:00:01");
116 List<InterfaceAddress> interfaceAddresses1 =
117 new LinkedList<InterfaceAddress>();
118 interfaceAddresses1.add(new InterfaceAddress(dpid1, 1, "192.168.10.101"));
119 interfaceAddresses1.add(new InterfaceAddress(dpid2, 1, "192.168.20.101"));
120 bgpSpeaker1.setInterfaceAddresses(interfaceAddresses1);
121 configuredBgpSpeakers.put(bgpSpeaker1.name(), bgpSpeaker1);
122
123 // BGP speaker2 is attached to the same switch port with speaker1
124 BgpSpeaker bgpSpeaker2 = new BgpSpeaker(
125 "bgpSpeaker2",
126 "00:00:00:00:00:00:00:01", 100,
127 "00:00:00:00:00:02");
128 List<InterfaceAddress> interfaceAddresses2 =
129 new LinkedList<InterfaceAddress>();
130 interfaceAddresses2.add(new InterfaceAddress(dpid1, 1, "192.168.10.102"));
131 interfaceAddresses2.add(new InterfaceAddress(dpid2, 1, "192.168.20.102"));
132 bgpSpeaker2.setInterfaceAddresses(interfaceAddresses2);
133 configuredBgpSpeakers.put(bgpSpeaker2.name(), bgpSpeaker2);
134
135 BgpSpeaker bgpSpeaker3 = new BgpSpeaker(
136 "bgpSpeaker3",
137 "00:00:00:00:00:00:00:02", 100,
138 "00:00:00:00:00:03");
139 List<InterfaceAddress> interfaceAddresses3 =
140 new LinkedList<InterfaceAddress>();
141 interfaceAddresses3.add(new InterfaceAddress(dpid1, 1, "192.168.10.103"));
142 interfaceAddresses3.add(new InterfaceAddress(dpid2, 1, "192.168.20.103"));
143 bgpSpeaker3.setInterfaceAddresses(interfaceAddresses3);
144 configuredBgpSpeakers.put(bgpSpeaker3.name(), bgpSpeaker3);
145
146 return configuredBgpSpeakers;
147 }
148
149 /**
150 * Sets up logical interfaces, which emulate the configured interfaces
151 * in SDN-IP application.
152 *
153 * @return configured interfaces as a MAP from Interface name to Interface
154 */
155 private Map<String, Interface> setUpInterfaces() {
156
157 configuredInterfaces = new HashMap<>();
158
159 String interfaceSw1Eth1 = "s1-eth1";
160 Interface intfsw1eth1 = new Interface(s1Eth1,
161 Collections.singleton(IpPrefix.valueOf("192.168.10.0/24")),
162 MacAddress.valueOf("00:00:00:00:00:01"));
163
164 configuredInterfaces.put(interfaceSw1Eth1, intfsw1eth1);
165 String interfaceSw2Eth1 = "s2-eth1";
166 Interface intfsw2eth1 = new Interface(s2Eth1,
167 Collections.singleton(IpPrefix.valueOf("192.168.20.0/24")),
168 MacAddress.valueOf("00:00:00:00:00:02"));
169 configuredInterfaces.put(interfaceSw2Eth1, intfsw2eth1);
170
171 interfaceService = createMock(InterfaceService.class);
172
173 expect(interfaceService.getInterface(s1Eth1))
174 .andReturn(intfsw1eth1).anyTimes();
175 expect(interfaceService.getInterface(s2Eth1))
176 .andReturn(intfsw2eth1).anyTimes();
177
178 // Non-existent interface used during one of the tests
179 expect(interfaceService.getInterface(new ConnectPoint(
180 DeviceId.deviceId(SdnIp.dpidToUri("00:00:00:00:00:00:01:00")),
181 PortNumber.portNumber(1))))
182 .andReturn(null).anyTimes();
183
184 expect(interfaceService.getInterfaces()).andReturn(
185 Sets.newHashSet(configuredInterfaces.values())).anyTimes();
186 replay(interfaceService);
187
188 return configuredInterfaces;
189 }
190
191 /**
192 * Sets up BGP daemon peers.
193 *
194 * @return configured BGP peers as a MAP from peer IP address to BgpPeer
195 */
196 private Map<IpAddress, BgpPeer> setUpPeers() {
197
198 configuredPeers = new HashMap<>();
199
200 String peerSw1Eth1 = "192.168.10.1";
201 configuredPeers.put(IpAddress.valueOf(peerSw1Eth1),
202 new BgpPeer(dpid1, 1, peerSw1Eth1));
203
204 // Two BGP peers are connected to switch 2 port 1.
205 String peer1Sw2Eth1 = "192.168.20.1";
206 configuredPeers.put(IpAddress.valueOf(peer1Sw2Eth1),
207 new BgpPeer(dpid2, 1, peer1Sw2Eth1));
208
209 String peer2Sw2Eth1 = "192.168.20.2";
210 configuredPeers.put(IpAddress.valueOf(peer2Sw2Eth1),
211 new BgpPeer(dpid2, 1, peer2Sw2Eth1));
212
213 return configuredPeers;
214 }
215
216 /**
217 * Sets up expected point to point intent list.
218 *
219 * @return point to point intent list
220 */
221 private List<PointToPointIntent> setUpIntentList() {
222
223 intentList = new ArrayList<PointToPointIntent>();
224
225 setUpBgpIntents();
226 setUpIcmpIntents();
227
228 return intentList;
229
230 }
231
232 /**
233 * Constructs a BGP intent and put it into the intentList.
234 * <p/>
235 * The purpose of this method is too simplify the setUpBgpIntents() method,
236 * and to make the setUpBgpIntents() easy to read.
237 *
238 * @param srcPrefix source IP prefix to match
239 * @param dstPrefix destination IP prefix to match
240 * @param srcTcpPort source TCP port to match
241 * @param dstTcpPort destination TCP port to match
242 * @param srcConnectPoint source connect point for PointToPointIntent
243 * @param dstConnectPoint destination connect point for PointToPointIntent
244 */
245 private void bgpPathintentConstructor(String srcPrefix, String dstPrefix,
246 Short srcTcpPort, Short dstTcpPort,
247 ConnectPoint srcConnectPoint, ConnectPoint dstConnectPoint) {
248
249 TrafficSelector.Builder builder = DefaultTrafficSelector.builder()
250 .matchEthType(Ethernet.TYPE_IPV4)
251 .matchIPProtocol(IPv4.PROTOCOL_TCP)
252 .matchIPSrc(IpPrefix.valueOf(srcPrefix))
253 .matchIPDst(IpPrefix.valueOf(dstPrefix));
254
255 if (srcTcpPort != null) {
256 builder.matchTcpSrc(srcTcpPort);
257 }
258 if (dstTcpPort != null) {
259 builder.matchTcpDst(dstTcpPort);
260 }
261
262 PointToPointIntent intent = new PointToPointIntent(
Thomas Vachuskab97cf282014-10-20 23:31:12 -0700263 APPID, builder.build(), noTreatment,
Jonathan Hartce430a42014-10-16 20:44:29 -0700264 srcConnectPoint, dstConnectPoint);
265
266 intentList.add(intent);
267 }
268
269 /**
270 * Sets up intents for BGP paths.
271 */
272 private void setUpBgpIntents() {
273
274 Short bgpPort = Short.valueOf((short) BgpConstants.BGP_PORT);
275
276 // Start to build intents between BGP speaker1 and BGP peer1
277 bgpPathintentConstructor(
278 "192.168.10.101/32", "192.168.10.1/32", null, bgpPort,
279 s1Eth100, s1Eth1);
280 bgpPathintentConstructor(
281 "192.168.10.101/32", "192.168.10.1/32", bgpPort, null,
282 s1Eth100, s1Eth1);
283
284 bgpPathintentConstructor(
285 "192.168.10.1/32", "192.168.10.101/32", null, bgpPort,
286 s1Eth1, s1Eth100);
287 bgpPathintentConstructor(
288 "192.168.10.1/32", "192.168.10.101/32", bgpPort, null,
289 s1Eth1, s1Eth100);
290
291 // Start to build intents between BGP speaker1 and BGP peer2
292 bgpPathintentConstructor(
293 "192.168.20.101/32", "192.168.20.1/32", null, bgpPort,
294 s1Eth100, s2Eth1);
295 bgpPathintentConstructor(
296 "192.168.20.101/32", "192.168.20.1/32", bgpPort, null,
297 s1Eth100, s2Eth1);
298
299 bgpPathintentConstructor(
300 "192.168.20.1/32", "192.168.20.101/32", null, bgpPort,
301 s2Eth1, s1Eth100);
302 bgpPathintentConstructor(
303 "192.168.20.1/32", "192.168.20.101/32", bgpPort, null,
304 s2Eth1, s1Eth100);
305
306 // Start to build intents between BGP speaker1 and BGP peer3
307 bgpPathintentConstructor(
308 "192.168.20.101/32", "192.168.20.2/32", null, bgpPort,
309 s1Eth100, s2Eth1);
310 bgpPathintentConstructor(
311 "192.168.20.101/32", "192.168.20.2/32", bgpPort, null,
312 s1Eth100, s2Eth1);
313
314 bgpPathintentConstructor(
315 "192.168.20.2/32", "192.168.20.101/32", null, bgpPort,
316 s2Eth1, s1Eth100);
317 bgpPathintentConstructor(
318 "192.168.20.2/32", "192.168.20.101/32", bgpPort, null,
319 s2Eth1, s1Eth100);
320
321 //
322 // Start to build intents between BGP speaker2 and BGP peer1
323 bgpPathintentConstructor(
324 "192.168.10.102/32", "192.168.10.1/32", null, bgpPort,
325 s1Eth100, s1Eth1);
326 bgpPathintentConstructor(
327 "192.168.10.102/32", "192.168.10.1/32", bgpPort, null,
328 s1Eth100, s1Eth1);
329
330 bgpPathintentConstructor(
331 "192.168.10.1/32", "192.168.10.102/32", null, bgpPort,
332 s1Eth1, s1Eth100);
333 bgpPathintentConstructor(
334 "192.168.10.1/32", "192.168.10.102/32", bgpPort, null,
335 s1Eth1, s1Eth100);
336 // Start to build intents between BGP speaker2 and BGP peer2
337 bgpPathintentConstructor(
338 "192.168.20.102/32", "192.168.20.1/32", null, bgpPort,
339 s1Eth100, s2Eth1);
340 bgpPathintentConstructor(
341 "192.168.20.102/32", "192.168.20.1/32", bgpPort, null,
342 s1Eth100, s2Eth1);
343
344 bgpPathintentConstructor(
345 "192.168.20.1/32", "192.168.20.102/32", null, bgpPort,
346 s2Eth1, s1Eth100);
347 bgpPathintentConstructor(
348 "192.168.20.1/32", "192.168.20.102/32", bgpPort, null,
349 s2Eth1, s1Eth100);
350
351 // Start to build intents between BGP speaker2 and BGP peer3
352 bgpPathintentConstructor(
353 "192.168.20.102/32", "192.168.20.2/32", null, bgpPort,
354 s1Eth100, s2Eth1);
355 bgpPathintentConstructor(
356 "192.168.20.102/32", "192.168.20.2/32", bgpPort, null,
357 s1Eth100, s2Eth1);
358
359 bgpPathintentConstructor(
360 "192.168.20.2/32", "192.168.20.102/32", null, bgpPort,
361 s2Eth1, s1Eth100);
362 bgpPathintentConstructor(
363 "192.168.20.2/32", "192.168.20.102/32", bgpPort, null,
364 s2Eth1, s1Eth100);
365
366 //
367 // Start to build intents between BGP speaker3 and BGP peer1
368 bgpPathintentConstructor(
369 "192.168.10.103/32", "192.168.10.1/32", null, bgpPort,
370 s2Eth100, s1Eth1);
371 bgpPathintentConstructor(
372 "192.168.10.103/32", "192.168.10.1/32", bgpPort, null,
373 s2Eth100, s1Eth1);
374
375 bgpPathintentConstructor(
376 "192.168.10.1/32", "192.168.10.103/32", null, bgpPort,
377 s1Eth1, s2Eth100);
378 bgpPathintentConstructor(
379 "192.168.10.1/32", "192.168.10.103/32", bgpPort, null,
380 s1Eth1, s2Eth100);
381
382 // Start to build intents between BGP speaker3 and BGP peer2
383 bgpPathintentConstructor(
384 "192.168.20.103/32", "192.168.20.1/32", null, bgpPort,
385 s2Eth100, s2Eth1);
386 bgpPathintentConstructor(
387 "192.168.20.103/32", "192.168.20.1/32", bgpPort, null,
388 s2Eth100, s2Eth1);
389
390 bgpPathintentConstructor(
391 "192.168.20.1/32", "192.168.20.103/32", null, bgpPort,
392 s2Eth1, s2Eth100);
393 bgpPathintentConstructor(
394 "192.168.20.1/32", "192.168.20.103/32", bgpPort, null,
395 s2Eth1, s2Eth100);
396
397 // Start to build intents between BGP speaker3 and BGP peer3
398 bgpPathintentConstructor(
399 "192.168.20.103/32", "192.168.20.2/32", null, bgpPort,
400 s2Eth100, s2Eth1);
401 bgpPathintentConstructor(
402 "192.168.20.103/32", "192.168.20.2/32", bgpPort, null,
403 s2Eth100, s2Eth1);
404
405 bgpPathintentConstructor(
406 "192.168.20.2/32", "192.168.20.103/32", null, bgpPort,
407 s2Eth1, s2Eth100);
408 bgpPathintentConstructor(
409 "192.168.20.2/32", "192.168.20.103/32", bgpPort, null,
410 s2Eth1, s2Eth100);
411 }
412
413 /**
414 * Constructs a BGP intent and put it into the intentList.
415 * <p/>
416 * The purpose of this method is too simplify the setUpBgpIntents() method,
417 * and to make the setUpBgpIntents() easy to read.
418 *
419 * @param srcPrefix source IP prefix to match
420 * @param dstPrefix destination IP prefix to match
421 * @param srcConnectPoint source connect point for PointToPointIntent
422 * @param dstConnectPoint destination connect point for PointToPointIntent
423 */
424 private void icmpPathintentConstructor(String srcPrefix, String dstPrefix,
425 ConnectPoint srcConnectPoint, ConnectPoint dstConnectPoint) {
426
427 TrafficSelector selector = DefaultTrafficSelector.builder()
428 .matchEthType(Ethernet.TYPE_IPV4)
429 .matchIPProtocol(IPv4.PROTOCOL_ICMP)
430 .matchIPSrc(IpPrefix.valueOf(srcPrefix))
431 .matchIPDst(IpPrefix.valueOf(dstPrefix))
432 .build();
433
434 PointToPointIntent intent = new PointToPointIntent(
Thomas Vachuskab97cf282014-10-20 23:31:12 -0700435 APPID, selector, noTreatment,
Jonathan Hartce430a42014-10-16 20:44:29 -0700436 srcConnectPoint, dstConnectPoint);
437
438 intentList.add(intent);
439 }
440
441 /**
442 * Sets up intents for ICMP paths.
443 */
444 private void setUpIcmpIntents() {
445
446 // Start to build intents between BGP speaker1 and BGP peer1
447 icmpPathintentConstructor(
448 "192.168.10.101/32", "192.168.10.1/32", s1Eth100, s1Eth1);
449 icmpPathintentConstructor(
450 "192.168.10.1/32", "192.168.10.101/32", s1Eth1, s1Eth100);
451
452 // Start to build intents between BGP speaker1 and BGP peer2
453 icmpPathintentConstructor(
454 "192.168.20.101/32", "192.168.20.1/32", s1Eth100, s2Eth1);
455 icmpPathintentConstructor(
456 "192.168.20.1/32", "192.168.20.101/32", s2Eth1, s1Eth100);
457
458 // Start to build intents between BGP speaker1 and BGP peer3
459 icmpPathintentConstructor(
460 "192.168.20.101/32", "192.168.20.2/32", s1Eth100, s2Eth1);
461 icmpPathintentConstructor(
462 "192.168.20.2/32", "192.168.20.101/32", s2Eth1, s1Eth100);
463
464 //
465 // Start to build intents between BGP speaker2 and BGP peer1
466 icmpPathintentConstructor(
467 "192.168.10.102/32", "192.168.10.1/32", s1Eth100, s1Eth1);
468 icmpPathintentConstructor(
469 "192.168.10.1/32", "192.168.10.102/32", s1Eth1, s1Eth100);
470
471 // Start to build intents between BGP speaker2 and BGP peer2
472 icmpPathintentConstructor(
473 "192.168.20.102/32", "192.168.20.1/32", s1Eth100, s2Eth1);
474 icmpPathintentConstructor(
475 "192.168.20.1/32", "192.168.20.102/32", s2Eth1, s1Eth100);
476
477 // Start to build intents between BGP speaker2 and BGP peer3
478 icmpPathintentConstructor(
479 "192.168.20.102/32", "192.168.20.2/32", s1Eth100, s2Eth1);
480 icmpPathintentConstructor(
481 "192.168.20.2/32", "192.168.20.102/32", s2Eth1, s1Eth100);
482
483 //
484 // Start to build intents between BGP speaker3 and BGP peer1
485 icmpPathintentConstructor(
486 "192.168.10.103/32", "192.168.10.1/32", s2Eth100, s1Eth1);
487 icmpPathintentConstructor(
488 "192.168.10.1/32", "192.168.10.103/32", s1Eth1, s2Eth100);
489
490 // Start to build intents between BGP speaker3 and BGP peer2
491 icmpPathintentConstructor(
492 "192.168.20.103/32", "192.168.20.1/32", s2Eth100, s2Eth1);
493 icmpPathintentConstructor(
494 "192.168.20.1/32", "192.168.20.103/32", s2Eth1, s2Eth100);
495
496 // Start to build intents between BGP speaker3 and BGP peer3
497 icmpPathintentConstructor(
498 "192.168.20.103/32", "192.168.20.2/32", s2Eth100, s2Eth1);
499 icmpPathintentConstructor(
500 "192.168.20.2/32", "192.168.20.103/32", s2Eth1, s2Eth100);
501
502 }
503
504 /**
505 * Initializes peer connectivity testing environment.
506 */
507 private void initPeerConnectivity() {
508
509 configInfoService = createMock(SdnIpConfigService.class);
510 expect(configInfoService.getBgpPeers()).andReturn(peers).anyTimes();
511 expect(configInfoService.getBgpSpeakers()).andReturn(bgpSpeakers).anyTimes();
512 replay(configInfoService);
513
514 intentService = createMock(IntentService.class);
515 replay(intentService);
516
Thomas Vachuskab97cf282014-10-20 23:31:12 -0700517 peerConnectivityManager = new PeerConnectivityManager(APPID, configInfoService,
Jonathan Hartce430a42014-10-16 20:44:29 -0700518 interfaceService, intentService);
519 }
520
521 /*
522 * EasyMock matcher that matches {@link PointToPointIntent}s but
523 * ignores the {@link IntentId} when matching.
524 * <p/>
525 * The normal intent equals method tests that the intent IDs are equal,
526 * however in these tests we can't know what the intent IDs will be in
527 * advance, so we can't set up expected intents with the correct IDs. Thus,
528 * the solution is to use an EasyMock matcher that verifies that all the
529 * value properties of the provided intent match the expected values, but
530 * ignores the intent ID when testing equality.
531 */
532 private static final class IdAgnosticPointToPointIntentMatcher implements
533 IArgumentMatcher {
534
535 private final PointToPointIntent intent;
536 private String providedIntentString;
537
538 /**
539 * Constructor taking the expected intent to match against.
540 *
541 * @param intent the expected intent
542 */
543 public IdAgnosticPointToPointIntentMatcher(PointToPointIntent intent) {
544 this.intent = intent;
545 }
546
547 @Override
548 public void appendTo(StringBuffer strBuffer) {
549 strBuffer.append("PointToPointIntentMatcher unable to match: "
550 + providedIntentString);
551 }
552
553 @Override
554 public boolean matches(Object object) {
555 if (!(object instanceof PointToPointIntent)) {
556 return false;
557 }
558
559 PointToPointIntent providedIntent = (PointToPointIntent) object;
560 providedIntentString = providedIntent.toString();
561
562 PointToPointIntent matchIntent =
Thomas Vachuskab97cf282014-10-20 23:31:12 -0700563 new PointToPointIntent(providedIntent.appId(),
Jonathan Hartce430a42014-10-16 20:44:29 -0700564 intent.selector(), intent.treatment(),
565 intent.ingressPoint(), intent.egressPoint());
566
567 return matchIntent.equals(providedIntent);
568 }
569 }
570
571 /**
572 * Matcher method to set an expected intent to match against (ignoring the
573 * the intent ID).
574 *
575 * @param intent the expected intent
576 * @return something of type PointToPointIntent
577 */
578 private static PointToPointIntent eqExceptId(
579 PointToPointIntent intent) {
580 reportMatcher(new IdAgnosticPointToPointIntentMatcher(intent));
581 return null;
582 }
583
584 /**
585 * Tests whether peer connectivity manager can set up correct BGP and
586 * ICMP intents according to specific configuration.
587 * <p/>
588 * Two tricky cases included in the configuration are: 2 peers on a same
589 * switch port, peer on the same switch with BGPd.
590 */
591 @Test
592 public void testConnectionSetup() {
593
594 reset(intentService);
595
596 // Sets up the expected PointToPoint intents.
597 for (int i = 0; i < intentList.size(); i++) {
598 intentService.submit(eqExceptId(intentList.get(i)));
599 }
600
601 replay(intentService);
602
603 // Running the interface to be tested.
604 peerConnectivityManager.start();
605
606 verify(intentService);
607
608 }
609
610 /**
611 * Tests a corner case, when there are no interfaces in the configuration.
612 */
613 @Test
614 public void testNullInterfaces() {
615 reset(interfaceService);
616 expect(interfaceService.getInterfaces()).andReturn(
617 Sets.<Interface>newHashSet()).anyTimes();
618 expect(interfaceService.getInterface(s2Eth1))
619 .andReturn(null).anyTimes();
620 expect(interfaceService.getInterface(s1Eth1))
621 .andReturn(null).anyTimes();
622 replay(interfaceService);
623
624 reset(configInfoService);
625 expect(configInfoService.getBgpPeers()).andReturn(peers).anyTimes();
626 expect(configInfoService.getBgpSpeakers()).andReturn(bgpSpeakers).anyTimes();
627 replay(configInfoService);
628
629 reset(intentService);
630 replay(intentService);
631 peerConnectivityManager.start();
632 verify(intentService);
633 }
634
635 /**
636 * Tests a corner case, when there are no BGP peers in the configuration.
637 */
638 @Test
639 public void testNullBgpPeers() {
640 reset(interfaceService);
641 expect(interfaceService.getInterfaces()).andReturn(
642 Sets.newHashSet(interfaces.values())).anyTimes();
643 replay(interfaceService);
644
645 reset(configInfoService);
646 expect(configInfoService.getBgpPeers()).andReturn(
647 new HashMap<IpAddress, BgpPeer>()).anyTimes();
648 expect(configInfoService.getBgpSpeakers()).andReturn(
649 bgpSpeakers).anyTimes();
650 replay(configInfoService);
651
652 reset(intentService);
653 replay(intentService);
654 peerConnectivityManager.start();
655 verify(intentService);
656 }
657
658 /**
659 * Tests a corner case, when there is no BGP speakers in the configuration.
660 */
661 @Test
662 public void testNullBgpSpeakers() {
663 reset(interfaceService);
664 expect(interfaceService.getInterfaces()).andReturn(
665 Sets.newHashSet(interfaces.values())).anyTimes();
666 replay(interfaceService);
667
668 reset(configInfoService);
669 expect(configInfoService.getBgpPeers()).andReturn(
670 peers).anyTimes();
671 expect(configInfoService.getBgpSpeakers()).andReturn(
672 null).anyTimes();
673 replay(configInfoService);
674
675 reset(intentService);
676 replay(intentService);
677 peerConnectivityManager.start();
678 verify(intentService);
679 }
680
681 /**
682 * Tests a corner case, when there is no Interface configured for one BGP
683 * peer.
684 */
685 @Test
686 public void testNoPeerInterface() {
687 String peerSw100Eth1 = "192.168.200.1";
688 configuredPeers.put(IpAddress.valueOf(peerSw100Eth1),
689 new BgpPeer("00:00:00:00:00:00:01:00", 1, peerSw100Eth1));
690 testConnectionSetup();
691 }
692
693 /**
694 * Tests a corner case, when there is no Interface configured for one BGP
695 * speaker.
696 * TODO: we should add a configuration correctness checking module/method
697 * before testing this corner case.
698 */
699 @Ignore
700 @Test
701 public void testNoSpeakerInterface() {
702 BgpSpeaker bgpSpeaker100 = new BgpSpeaker(
703 "bgpSpeaker100",
704 "00:00:00:00:00:00:01:00", 100,
705 "00:00:00:00:01:00");
706 List<InterfaceAddress> interfaceAddresses100 =
707 new LinkedList<InterfaceAddress>();
708 interfaceAddresses100.add(new InterfaceAddress(dpid1, 1, "192.168.10.201"));
709 interfaceAddresses100.add(new InterfaceAddress(dpid2, 1, "192.168.20.201"));
710 bgpSpeaker100.setInterfaceAddresses(interfaceAddresses100);
711 configuredBgpSpeakers.put(bgpSpeaker100.name(), bgpSpeaker100);
712 testConnectionSetup();
713 }
714}