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