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