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