blob: 19c1d501a323ad234eea20ec09ae26bfe8c38415 [file] [log] [blame]
Thomas Vachuska781d18b2014-10-27 10:31:25 -07001/*
Ray Milkey34c95902015-04-15 09:47:53 -07002 * Copyright 2014-2015 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 Harte30fcda2015-08-06 16:22:34 -070018import 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;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -070029import org.onlab.packet.TpPort;
Jonathan Hart6cd2f352015-01-13 17:44:45 -080030import org.onlab.packet.VlanId;
Brian O'Connorabafb502014-12-02 22:26:20 -080031import org.onosproject.core.ApplicationId;
32import org.onosproject.net.ConnectPoint;
33import org.onosproject.net.DeviceId;
34import org.onosproject.net.PortNumber;
35import org.onosproject.net.flow.DefaultTrafficSelector;
36import org.onosproject.net.flow.DefaultTrafficTreatment;
37import org.onosproject.net.flow.TrafficSelector;
38import org.onosproject.net.flow.TrafficTreatment;
39import org.onosproject.net.host.InterfaceIpAddress;
40import org.onosproject.net.intent.AbstractIntentTest;
41import org.onosproject.net.intent.Intent;
Brian O'Connorabafb502014-12-02 22:26:20 -080042import org.onosproject.net.intent.IntentService;
43import org.onosproject.net.intent.PointToPointIntent;
Jonathan Hart2da1e602015-02-18 19:09:24 -080044import org.onosproject.routing.config.BgpPeer;
45import org.onosproject.routing.config.BgpSpeaker;
46import org.onosproject.routing.config.Interface;
47import org.onosproject.routing.config.InterfaceAddress;
48import org.onosproject.routing.config.RoutingConfigurationService;
Jonathan Hartce430a42014-10-16 20:44:29 -070049
Jonathan Harte30fcda2015-08-06 16:22:34 -070050import java.util.ArrayList;
51import java.util.Collections;
52import java.util.HashMap;
53import java.util.LinkedList;
54import java.util.List;
55import java.util.Map;
Jonathan Hart552e31f2015-02-06 11:11:59 -080056
Ray Milkey3e3ec5f2015-03-17 17:00:38 -070057import static org.easymock.EasyMock.createMock;
58import static org.easymock.EasyMock.expect;
59import static org.easymock.EasyMock.replay;
60import static org.easymock.EasyMock.reset;
61import static org.easymock.EasyMock.verify;
Jonathan Hartcb726fc2015-02-13 16:26:22 -080062import static org.onosproject.sdnip.TestIntentServiceHelper.eqExceptId;
Jonathan Hartce430a42014-10-16 20:44:29 -070063
64/**
Jonathan Hart51372182014-12-03 21:32:34 -080065 * Unit tests for PeerConnectivityManager.
Jonathan Hartce430a42014-10-16 20:44:29 -070066 */
Brian O'Connor520c0522014-11-23 23:50:47 -080067public class PeerConnectivityManagerTest extends AbstractIntentTest {
Jonathan Hartce430a42014-10-16 20:44:29 -070068
Thomas Vachuskab97cf282014-10-20 23:31:12 -070069 private static final ApplicationId APPID = new ApplicationId() {
70 @Override
71 public short id() {
72 return 0;
73 }
74
75 @Override
76 public String name() {
77 return "foo";
78 }
79 };
80
Jonathan Hartce430a42014-10-16 20:44:29 -070081 private PeerConnectivityManager peerConnectivityManager;
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -080082 private IntentSynchronizer intentSynchronizer;
Jonathan Hart90a02c22015-02-13 11:52:07 -080083 private RoutingConfigurationService routingConfig;
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -080084 private IntentService intentService;
Jonathan Hartce430a42014-10-16 20:44:29 -070085
86 private Map<String, BgpSpeaker> bgpSpeakers;
87 private Map<String, Interface> interfaces;
88 private Map<IpAddress, BgpPeer> peers;
89
90 private Map<String, BgpSpeaker> configuredBgpSpeakers;
91 private Map<String, Interface> configuredInterfaces;
92 private Map<IpAddress, BgpPeer> configuredPeers;
93 private List<PointToPointIntent> intentList;
94
95 private final String dpid1 = "00:00:00:00:00:00:00:01";
96 private final String dpid2 = "00:00:00:00:00:00:00:02";
97
98 private final DeviceId deviceId1 =
99 DeviceId.deviceId(SdnIp.dpidToUri(dpid1));
100 private final DeviceId deviceId2 =
101 DeviceId.deviceId(SdnIp.dpidToUri(dpid2));
102
103 // Interfaces connected to BGP speakers
104 private final ConnectPoint s1Eth100 =
105 new ConnectPoint(deviceId1, PortNumber.portNumber(100));
106 private final ConnectPoint s2Eth100 =
107 new ConnectPoint(deviceId2, PortNumber.portNumber(100));
108
109 // Interfaces connected to BGP peers
110 private final ConnectPoint s1Eth1 =
111 new ConnectPoint(deviceId1, PortNumber.portNumber(1));
112 private final ConnectPoint s2Eth1 =
113 new ConnectPoint(deviceId2, PortNumber.portNumber(1));
114
Jonathan Hartce430a42014-10-16 20:44:29 -0700115 private final TrafficTreatment noTreatment =
Brian O'Connor6b528132015-03-10 16:39:52 -0700116 DefaultTrafficTreatment.emptyTreatment();
Jonathan Hartce430a42014-10-16 20:44:29 -0700117
118 @Before
119 public void setUp() throws Exception {
Brian O'Connor520c0522014-11-23 23:50:47 -0800120 super.setUp();
Jonathan Hart90a02c22015-02-13 11:52:07 -0800121 routingConfig = createMock(RoutingConfigurationService.class);
122
123 // These will set expectations on routingConfig
Jonathan Hartce430a42014-10-16 20:44:29 -0700124 bgpSpeakers = Collections.unmodifiableMap(setUpBgpSpeakers());
125 interfaces = Collections.unmodifiableMap(setUpInterfaces());
126 peers = Collections.unmodifiableMap(setUpPeers());
127
128 initPeerConnectivity();
129 intentList = setUpIntentList();
130 }
131
132 /**
133 * Sets up BGP speakers.
134 *
135 * @return configured BGP speakers as a map from speaker name to speaker
136 */
137 private Map<String, BgpSpeaker> setUpBgpSpeakers() {
138
139 configuredBgpSpeakers = new HashMap<>();
140
141 BgpSpeaker bgpSpeaker1 = new BgpSpeaker(
142 "bgpSpeaker1",
143 "00:00:00:00:00:00:00:01", 100,
144 "00:00:00:00:00:01");
Jonathan Hart90a02c22015-02-13 11:52:07 -0800145 List<InterfaceAddress> interfaceAddresses1 = new LinkedList<>();
Jonathan Hartce430a42014-10-16 20:44:29 -0700146 interfaceAddresses1.add(new InterfaceAddress(dpid1, 1, "192.168.10.101"));
Jonathan Hartce430a42014-10-16 20:44:29 -0700147 bgpSpeaker1.setInterfaceAddresses(interfaceAddresses1);
148 configuredBgpSpeakers.put(bgpSpeaker1.name(), bgpSpeaker1);
149
150 // BGP speaker2 is attached to the same switch port with speaker1
151 BgpSpeaker bgpSpeaker2 = new BgpSpeaker(
152 "bgpSpeaker2",
153 "00:00:00:00:00:00:00:01", 100,
154 "00:00:00:00:00:02");
Jonathan Hart90a02c22015-02-13 11:52:07 -0800155 List<InterfaceAddress> interfaceAddresses2 = new LinkedList<>();
Jonathan Harte30fcda2015-08-06 16:22:34 -0700156 interfaceAddresses2.add(new InterfaceAddress(dpid2, 1, "192.168.20.101"));
157 interfaceAddresses2.add(new InterfaceAddress(dpid2, 1, "192.168.30.101"));
Jonathan Hartce430a42014-10-16 20:44:29 -0700158 bgpSpeaker2.setInterfaceAddresses(interfaceAddresses2);
159 configuredBgpSpeakers.put(bgpSpeaker2.name(), bgpSpeaker2);
160
Jonathan Hartce430a42014-10-16 20:44:29 -0700161 return configuredBgpSpeakers;
162 }
163
164 /**
165 * Sets up logical interfaces, which emulate the configured interfaces
166 * in SDN-IP application.
167 *
168 * @return configured interfaces as a MAP from Interface name to Interface
169 */
170 private Map<String, Interface> setUpInterfaces() {
171
172 configuredInterfaces = new HashMap<>();
173
174 String interfaceSw1Eth1 = "s1-eth1";
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -0700175 InterfaceIpAddress ia1 =
Jonathan Harte30fcda2015-08-06 16:22:34 -0700176 new InterfaceIpAddress(IpAddress.valueOf("192.168.10.101"),
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -0700177 IpPrefix.valueOf("192.168.10.0/24"));
Jonathan Hartce430a42014-10-16 20:44:29 -0700178 Interface intfsw1eth1 = new Interface(s1Eth1,
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -0700179 Collections.singleton(ia1),
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800180 MacAddress.valueOf("00:00:00:00:00:01"),
181 VlanId.NONE);
Jonathan Hartce430a42014-10-16 20:44:29 -0700182
183 configuredInterfaces.put(interfaceSw1Eth1, intfsw1eth1);
184 String interfaceSw2Eth1 = "s2-eth1";
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -0700185 InterfaceIpAddress ia2 =
Jonathan Harte30fcda2015-08-06 16:22:34 -0700186 new InterfaceIpAddress(IpAddress.valueOf("192.168.20.101"),
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -0700187 IpPrefix.valueOf("192.168.20.0/24"));
Jonathan Hartce430a42014-10-16 20:44:29 -0700188 Interface intfsw2eth1 = new Interface(s2Eth1,
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -0700189 Collections.singleton(ia2),
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800190 MacAddress.valueOf("00:00:00:00:00:02"),
191 VlanId.NONE);
Jonathan Hartce430a42014-10-16 20:44:29 -0700192 configuredInterfaces.put(interfaceSw2Eth1, intfsw2eth1);
193
Jonathan Harte30fcda2015-08-06 16:22:34 -0700194 String interfaceSw2Eth1intf2 = "s2-eth1_2";
195 InterfaceIpAddress ia3 =
196 new InterfaceIpAddress(IpAddress.valueOf("192.168.30.101"),
197 IpPrefix.valueOf("192.168.30.0/24"));
198 Interface intfsw2eth1intf2 = new Interface(s2Eth1,
199 Collections.singleton(ia3),
200 MacAddress.valueOf("00:00:00:00:00:03"),
201 VlanId.NONE);
202 configuredInterfaces.put(interfaceSw2Eth1intf2, intfsw2eth1intf2);
203
Jonathan Hart90a02c22015-02-13 11:52:07 -0800204 expect(routingConfig.getInterface(s1Eth1))
Jonathan Hartce430a42014-10-16 20:44:29 -0700205 .andReturn(intfsw1eth1).anyTimes();
Jonathan Harte30fcda2015-08-06 16:22:34 -0700206 expect(routingConfig.getInterface(IpAddress.valueOf("192.168.10.101")))
207 .andReturn(intfsw1eth1).anyTimes();
Jonathan Hart90a02c22015-02-13 11:52:07 -0800208 expect(routingConfig.getInterface(s2Eth1))
Jonathan Hartce430a42014-10-16 20:44:29 -0700209 .andReturn(intfsw2eth1).anyTimes();
Jonathan Harte30fcda2015-08-06 16:22:34 -0700210 expect(routingConfig.getInterface(IpAddress.valueOf("192.168.20.101")))
211 .andReturn(intfsw2eth1).anyTimes();
212 //expect(routingConfig.getInterface(s2Eth1))
213 // .andReturn(intfsw2eth1intf2).anyTimes();
214 expect(routingConfig.getInterface(IpAddress.valueOf("192.168.30.101")))
215 .andReturn(intfsw2eth1intf2).anyTimes();
Jonathan Hartce430a42014-10-16 20:44:29 -0700216
217 // Non-existent interface used during one of the tests
Jonathan Hart90a02c22015-02-13 11:52:07 -0800218 expect(routingConfig.getInterface(new ConnectPoint(
Jonathan Hartce430a42014-10-16 20:44:29 -0700219 DeviceId.deviceId(SdnIp.dpidToUri("00:00:00:00:00:00:01:00")),
220 PortNumber.portNumber(1))))
221 .andReturn(null).anyTimes();
222
Jonathan Hart90a02c22015-02-13 11:52:07 -0800223 expect(routingConfig.getInterfaces()).andReturn(
Jonathan Hartce430a42014-10-16 20:44:29 -0700224 Sets.newHashSet(configuredInterfaces.values())).anyTimes();
Jonathan Hartce430a42014-10-16 20:44:29 -0700225
226 return configuredInterfaces;
227 }
228
229 /**
230 * Sets up BGP daemon peers.
231 *
232 * @return configured BGP peers as a MAP from peer IP address to BgpPeer
233 */
234 private Map<IpAddress, BgpPeer> setUpPeers() {
235
236 configuredPeers = new HashMap<>();
237
238 String peerSw1Eth1 = "192.168.10.1";
239 configuredPeers.put(IpAddress.valueOf(peerSw1Eth1),
240 new BgpPeer(dpid1, 1, peerSw1Eth1));
241
242 // Two BGP peers are connected to switch 2 port 1.
243 String peer1Sw2Eth1 = "192.168.20.1";
244 configuredPeers.put(IpAddress.valueOf(peer1Sw2Eth1),
245 new BgpPeer(dpid2, 1, peer1Sw2Eth1));
246
Jonathan Harte30fcda2015-08-06 16:22:34 -0700247 String peer2Sw2Eth1 = "192.168.30.1";
Jonathan Hartce430a42014-10-16 20:44:29 -0700248 configuredPeers.put(IpAddress.valueOf(peer2Sw2Eth1),
249 new BgpPeer(dpid2, 1, peer2Sw2Eth1));
250
251 return configuredPeers;
252 }
253
254 /**
255 * Sets up expected point to point intent list.
256 *
257 * @return point to point intent list
258 */
259 private List<PointToPointIntent> setUpIntentList() {
260
Jonathan Hart90a02c22015-02-13 11:52:07 -0800261 intentList = new ArrayList<>();
Jonathan Hartce430a42014-10-16 20:44:29 -0700262
263 setUpBgpIntents();
264 setUpIcmpIntents();
265
266 return intentList;
267
268 }
269
270 /**
271 * Constructs a BGP intent and put it into the intentList.
272 * <p/>
273 * The purpose of this method is too simplify the setUpBgpIntents() method,
274 * and to make the setUpBgpIntents() easy to read.
275 *
276 * @param srcPrefix source IP prefix to match
277 * @param dstPrefix destination IP prefix to match
278 * @param srcTcpPort source TCP port to match
279 * @param dstTcpPort destination TCP port to match
280 * @param srcConnectPoint source connect point for PointToPointIntent
281 * @param dstConnectPoint destination connect point for PointToPointIntent
282 */
283 private void bgpPathintentConstructor(String srcPrefix, String dstPrefix,
284 Short srcTcpPort, Short dstTcpPort,
285 ConnectPoint srcConnectPoint, ConnectPoint dstConnectPoint) {
286
287 TrafficSelector.Builder builder = DefaultTrafficSelector.builder()
288 .matchEthType(Ethernet.TYPE_IPV4)
289 .matchIPProtocol(IPv4.PROTOCOL_TCP)
290 .matchIPSrc(IpPrefix.valueOf(srcPrefix))
291 .matchIPDst(IpPrefix.valueOf(dstPrefix));
292
293 if (srcTcpPort != null) {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700294 builder.matchTcpSrc(TpPort.tpPort(srcTcpPort));
Jonathan Hartce430a42014-10-16 20:44:29 -0700295 }
296 if (dstTcpPort != null) {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700297 builder.matchTcpDst(TpPort.tpPort(dstTcpPort));
Jonathan Hartce430a42014-10-16 20:44:29 -0700298 }
299
Ray Milkey3e3ec5f2015-03-17 17:00:38 -0700300 PointToPointIntent intent = PointToPointIntent.builder()
301 .appId(APPID)
302 .selector(builder.build())
303 .treatment(noTreatment)
304 .ingressPoint(srcConnectPoint)
305 .egressPoint(dstConnectPoint)
306 .build();
Jonathan Hartce430a42014-10-16 20:44:29 -0700307
308 intentList.add(intent);
309 }
310
311 /**
312 * Sets up intents for BGP paths.
313 */
314 private void setUpBgpIntents() {
315
Jonathan Hart41349e92015-02-09 14:14:02 -0800316 Short bgpPort = 179;
Jonathan Hartce430a42014-10-16 20:44:29 -0700317
318 // Start to build intents between BGP speaker1 and BGP peer1
319 bgpPathintentConstructor(
320 "192.168.10.101/32", "192.168.10.1/32", null, bgpPort,
321 s1Eth100, s1Eth1);
322 bgpPathintentConstructor(
323 "192.168.10.101/32", "192.168.10.1/32", bgpPort, null,
324 s1Eth100, s1Eth1);
325
326 bgpPathintentConstructor(
327 "192.168.10.1/32", "192.168.10.101/32", null, bgpPort,
328 s1Eth1, s1Eth100);
329 bgpPathintentConstructor(
330 "192.168.10.1/32", "192.168.10.101/32", bgpPort, null,
331 s1Eth1, s1Eth100);
332
333 // Start to build intents between BGP speaker1 and BGP peer2
334 bgpPathintentConstructor(
335 "192.168.20.101/32", "192.168.20.1/32", null, bgpPort,
336 s1Eth100, s2Eth1);
337 bgpPathintentConstructor(
338 "192.168.20.101/32", "192.168.20.1/32", bgpPort, null,
339 s1Eth100, s2Eth1);
340
341 bgpPathintentConstructor(
342 "192.168.20.1/32", "192.168.20.101/32", null, bgpPort,
343 s2Eth1, s1Eth100);
344 bgpPathintentConstructor(
345 "192.168.20.1/32", "192.168.20.101/32", bgpPort, null,
346 s2Eth1, s1Eth100);
347
Jonathan Hartce430a42014-10-16 20:44:29 -0700348 //
349 // Start to build intents between BGP speaker3 and BGP peer1
350 bgpPathintentConstructor(
Jonathan Harte30fcda2015-08-06 16:22:34 -0700351 "192.168.30.101/32", "192.168.30.1/32", null, bgpPort,
352 s1Eth100, s2Eth1);
Jonathan Hartce430a42014-10-16 20:44:29 -0700353 bgpPathintentConstructor(
Jonathan Harte30fcda2015-08-06 16:22:34 -0700354 "192.168.30.101/32", "192.168.30.1/32", bgpPort, null,
355 s1Eth100, s2Eth1);
Jonathan Hartce430a42014-10-16 20:44:29 -0700356
357 bgpPathintentConstructor(
Jonathan Harte30fcda2015-08-06 16:22:34 -0700358 "192.168.30.1/32", "192.168.30.101/32", null, bgpPort,
359 s2Eth1, s1Eth100);
Jonathan Hartce430a42014-10-16 20:44:29 -0700360 bgpPathintentConstructor(
Jonathan Harte30fcda2015-08-06 16:22:34 -0700361 "192.168.30.1/32", "192.168.30.101/32", bgpPort, null,
362 s2Eth1, s1Eth100);
Jonathan Hartce430a42014-10-16 20:44:29 -0700363 }
364
365 /**
366 * Constructs a BGP intent and put it into the intentList.
367 * <p/>
368 * The purpose of this method is too simplify the setUpBgpIntents() method,
369 * and to make the setUpBgpIntents() easy to read.
370 *
371 * @param srcPrefix source IP prefix to match
372 * @param dstPrefix destination IP prefix to match
373 * @param srcConnectPoint source connect point for PointToPointIntent
374 * @param dstConnectPoint destination connect point for PointToPointIntent
375 */
376 private void icmpPathintentConstructor(String srcPrefix, String dstPrefix,
377 ConnectPoint srcConnectPoint, ConnectPoint dstConnectPoint) {
378
379 TrafficSelector selector = DefaultTrafficSelector.builder()
380 .matchEthType(Ethernet.TYPE_IPV4)
381 .matchIPProtocol(IPv4.PROTOCOL_ICMP)
382 .matchIPSrc(IpPrefix.valueOf(srcPrefix))
383 .matchIPDst(IpPrefix.valueOf(dstPrefix))
384 .build();
385
Ray Milkey3e3ec5f2015-03-17 17:00:38 -0700386 PointToPointIntent intent = PointToPointIntent.builder()
387 .appId(APPID)
388 .selector(selector)
389 .treatment(noTreatment)
390 .ingressPoint(srcConnectPoint)
391 .egressPoint(dstConnectPoint)
392 .build();
Jonathan Hartce430a42014-10-16 20:44:29 -0700393
394 intentList.add(intent);
395 }
396
397 /**
398 * Sets up intents for ICMP paths.
399 */
400 private void setUpIcmpIntents() {
401
402 // Start to build intents between BGP speaker1 and BGP peer1
403 icmpPathintentConstructor(
404 "192.168.10.101/32", "192.168.10.1/32", s1Eth100, s1Eth1);
405 icmpPathintentConstructor(
406 "192.168.10.1/32", "192.168.10.101/32", s1Eth1, s1Eth100);
407
408 // Start to build intents between BGP speaker1 and BGP peer2
409 icmpPathintentConstructor(
410 "192.168.20.101/32", "192.168.20.1/32", s1Eth100, s2Eth1);
411 icmpPathintentConstructor(
412 "192.168.20.1/32", "192.168.20.101/32", s2Eth1, s1Eth100);
413
Jonathan Hartce430a42014-10-16 20:44:29 -0700414 icmpPathintentConstructor(
Jonathan Harte30fcda2015-08-06 16:22:34 -0700415 "192.168.30.101/32", "192.168.30.1/32", s1Eth100, s2Eth1);
Jonathan Hartce430a42014-10-16 20:44:29 -0700416 icmpPathintentConstructor(
Jonathan Harte30fcda2015-08-06 16:22:34 -0700417 "192.168.30.1/32", "192.168.30.101/32", s2Eth1, s1Eth100);
Jonathan Hartce430a42014-10-16 20:44:29 -0700418
419 }
420
421 /**
422 * Initializes peer connectivity testing environment.
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800423 *
424 * @throws TestUtilsException if exceptions when using TestUtils
Jonathan Hartce430a42014-10-16 20:44:29 -0700425 */
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800426 private void initPeerConnectivity() throws TestUtilsException {
Jonathan Hartce430a42014-10-16 20:44:29 -0700427
Jonathan Hart90a02c22015-02-13 11:52:07 -0800428 expect(routingConfig.getBgpPeers()).andReturn(peers).anyTimes();
429 expect(routingConfig.getBgpSpeakers()).andReturn(bgpSpeakers).anyTimes();
430 replay(routingConfig);
Jonathan Hartce430a42014-10-16 20:44:29 -0700431
432 intentService = createMock(IntentService.class);
433 replay(intentService);
434
Jonathan Hart552e31f2015-02-06 11:11:59 -0800435 intentSynchronizer = new IntentSynchronizer(APPID, intentService,
Pingping Line28ae4c2015-03-13 11:37:03 -0700436 null, routingConfig);
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800437 intentSynchronizer.leaderChanged(true);
438 TestUtils.setField(intentSynchronizer, "isActivatedLeader", true);
439
440 peerConnectivityManager =
441 new PeerConnectivityManager(APPID, intentSynchronizer,
Jonathan Hart90a02c22015-02-13 11:52:07 -0800442 routingConfig);
Jonathan Hartce430a42014-10-16 20:44:29 -0700443 }
444
Jonathan Hartce430a42014-10-16 20:44:29 -0700445 /**
446 * Tests whether peer connectivity manager can set up correct BGP and
447 * ICMP intents according to specific configuration.
448 * <p/>
449 * Two tricky cases included in the configuration are: 2 peers on a same
450 * switch port, peer on the same switch with BGPd.
451 */
452 @Test
453 public void testConnectionSetup() {
454
455 reset(intentService);
456
Pavlin Radoslavovdde22ae2014-11-24 11:47:17 -0800457 // Setup the expected intents
Pavlin Radoslavovdde22ae2014-11-24 11:47:17 -0800458 for (Intent intent : intentList) {
Jonathan Hartcb726fc2015-02-13 16:26:22 -0800459 intentService.submit(eqExceptId(intent));
Jonathan Hartce430a42014-10-16 20:44:29 -0700460 }
Jonathan Hartce430a42014-10-16 20:44:29 -0700461 replay(intentService);
462
463 // Running the interface to be tested.
464 peerConnectivityManager.start();
465
466 verify(intentService);
467
468 }
469
470 /**
471 * Tests a corner case, when there are no interfaces in the configuration.
472 */
473 @Test
474 public void testNullInterfaces() {
Jonathan Hart90a02c22015-02-13 11:52:07 -0800475 reset(routingConfig);
476 expect(routingConfig.getInterfaces()).andReturn(
Jonathan Hartce430a42014-10-16 20:44:29 -0700477 Sets.<Interface>newHashSet()).anyTimes();
Jonathan Hart90a02c22015-02-13 11:52:07 -0800478 expect(routingConfig.getInterface(s2Eth1))
Jonathan Hartce430a42014-10-16 20:44:29 -0700479 .andReturn(null).anyTimes();
Jonathan Hart90a02c22015-02-13 11:52:07 -0800480 expect(routingConfig.getInterface(s1Eth1))
Jonathan Hartce430a42014-10-16 20:44:29 -0700481 .andReturn(null).anyTimes();
Jonathan Harte30fcda2015-08-06 16:22:34 -0700482 expect(routingConfig.getInterface(IpAddress.valueOf("192.168.10.101")))
483 .andReturn(null).anyTimes();
484 expect(routingConfig.getInterface(IpAddress.valueOf("192.168.20.101")))
485 .andReturn(null).anyTimes();
486 expect(routingConfig.getInterface(IpAddress.valueOf("192.168.30.101")))
487 .andReturn(null).anyTimes();
Jonathan Hartce430a42014-10-16 20:44:29 -0700488
Jonathan Hart90a02c22015-02-13 11:52:07 -0800489 expect(routingConfig.getBgpPeers()).andReturn(peers).anyTimes();
490 expect(routingConfig.getBgpSpeakers()).andReturn(bgpSpeakers).anyTimes();
491 replay(routingConfig);
Jonathan Hartce430a42014-10-16 20:44:29 -0700492
493 reset(intentService);
494 replay(intentService);
495 peerConnectivityManager.start();
496 verify(intentService);
497 }
498
499 /**
500 * Tests a corner case, when there are no BGP peers in the configuration.
501 */
502 @Test
503 public void testNullBgpPeers() {
Jonathan Hart90a02c22015-02-13 11:52:07 -0800504 reset(routingConfig);
505 expect(routingConfig.getInterfaces()).andReturn(
Jonathan Hartce430a42014-10-16 20:44:29 -0700506 Sets.newHashSet(interfaces.values())).anyTimes();
Jonathan Hartce430a42014-10-16 20:44:29 -0700507
Jonathan Hart90a02c22015-02-13 11:52:07 -0800508 expect(routingConfig.getBgpPeers()).andReturn(new HashMap<>()).anyTimes();
509 expect(routingConfig.getBgpSpeakers()).andReturn(bgpSpeakers).anyTimes();
510 replay(routingConfig);
Jonathan Hartce430a42014-10-16 20:44:29 -0700511
512 reset(intentService);
Jonathan Hartce430a42014-10-16 20:44:29 -0700513 replay(intentService);
514 peerConnectivityManager.start();
515 verify(intentService);
516 }
517
518 /**
519 * Tests a corner case, when there is no BGP speakers in the configuration.
520 */
521 @Test
522 public void testNullBgpSpeakers() {
Jonathan Hart90a02c22015-02-13 11:52:07 -0800523 reset(routingConfig);
524 expect(routingConfig.getInterfaces()).andReturn(
Jonathan Hartce430a42014-10-16 20:44:29 -0700525 Sets.newHashSet(interfaces.values())).anyTimes();
Jonathan Hartce430a42014-10-16 20:44:29 -0700526
Jonathan Hart90a02c22015-02-13 11:52:07 -0800527 expect(routingConfig.getBgpPeers()).andReturn(peers).anyTimes();
528 expect(routingConfig.getBgpSpeakers()).andReturn(
Jonathan Hart51372182014-12-03 21:32:34 -0800529 Collections.emptyMap()).anyTimes();
Jonathan Hart90a02c22015-02-13 11:52:07 -0800530 replay(routingConfig);
Jonathan Hartce430a42014-10-16 20:44:29 -0700531
532 reset(intentService);
Jonathan Hartce430a42014-10-16 20:44:29 -0700533 replay(intentService);
534 peerConnectivityManager.start();
535 verify(intentService);
536 }
537
538 /**
539 * Tests a corner case, when there is no Interface configured for one BGP
540 * peer.
541 */
542 @Test
543 public void testNoPeerInterface() {
544 String peerSw100Eth1 = "192.168.200.1";
545 configuredPeers.put(IpAddress.valueOf(peerSw100Eth1),
546 new BgpPeer("00:00:00:00:00:00:01:00", 1, peerSw100Eth1));
547 testConnectionSetup();
548 }
549
550 /**
551 * Tests a corner case, when there is no Interface configured for one BGP
552 * speaker.
Jonathan Hartce430a42014-10-16 20:44:29 -0700553 */
554 @Ignore
555 @Test
556 public void testNoSpeakerInterface() {
557 BgpSpeaker bgpSpeaker100 = new BgpSpeaker(
558 "bgpSpeaker100",
559 "00:00:00:00:00:00:01:00", 100,
560 "00:00:00:00:01:00");
Jonathan Hart90a02c22015-02-13 11:52:07 -0800561 List<InterfaceAddress> interfaceAddresses100 = new LinkedList<>();
Jonathan Hartce430a42014-10-16 20:44:29 -0700562 interfaceAddresses100.add(new InterfaceAddress(dpid1, 1, "192.168.10.201"));
563 interfaceAddresses100.add(new InterfaceAddress(dpid2, 1, "192.168.20.201"));
564 bgpSpeaker100.setInterfaceAddresses(interfaceAddresses100);
565 configuredBgpSpeakers.put(bgpSpeaker100.name(), bgpSpeaker100);
566 testConnectionSetup();
567 }
568}