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 | */ |
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 | |
Jonathan Hart | 552e31f | 2015-02-06 11:11:59 -0800 | [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; |
Jonathan Hart | 5137218 | 2014-12-03 21:32:34 -0800 | [diff] [blame] | 24 | import org.onlab.packet.Ethernet; |
| 25 | import org.onlab.packet.IPv4; |
| 26 | import org.onlab.packet.IpAddress; |
| 27 | import org.onlab.packet.IpPrefix; |
| 28 | import org.onlab.packet.MacAddress; |
Jonathan Hart | 6cd2f35 | 2015-01-13 17:44:45 -0800 | [diff] [blame] | 29 | import org.onlab.packet.VlanId; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 30 | import org.onosproject.core.ApplicationId; |
| 31 | import org.onosproject.net.ConnectPoint; |
| 32 | import org.onosproject.net.DeviceId; |
| 33 | import org.onosproject.net.PortNumber; |
| 34 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 35 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 36 | import org.onosproject.net.flow.TrafficSelector; |
| 37 | import org.onosproject.net.flow.TrafficTreatment; |
| 38 | import org.onosproject.net.host.InterfaceIpAddress; |
| 39 | import org.onosproject.net.intent.AbstractIntentTest; |
| 40 | import org.onosproject.net.intent.Intent; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 41 | import org.onosproject.net.intent.IntentService; |
| 42 | import org.onosproject.net.intent.PointToPointIntent; |
Jonathan Hart | 2da1e60 | 2015-02-18 19:09:24 -0800 | [diff] [blame] | 43 | import org.onosproject.routing.config.BgpPeer; |
| 44 | import org.onosproject.routing.config.BgpSpeaker; |
| 45 | import org.onosproject.routing.config.Interface; |
| 46 | import org.onosproject.routing.config.InterfaceAddress; |
| 47 | import org.onosproject.routing.config.RoutingConfigurationService; |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 48 | |
Jonathan Hart | 552e31f | 2015-02-06 11:11:59 -0800 | [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 | cb726fc | 2015-02-13 16:26:22 -0800 | [diff] [blame] | 57 | import static org.onosproject.sdnip.TestIntentServiceHelper.eqExceptId; |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 58 | |
| 59 | /** |
Jonathan Hart | 5137218 | 2014-12-03 21:32:34 -0800 | [diff] [blame] | 60 | * Unit tests for PeerConnectivityManager. |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 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 | 90a02c2 | 2015-02-13 11:52:07 -0800 | [diff] [blame] | 78 | private RoutingConfigurationService routingConfig; |
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 = |
Brian O'Connor | 6b52813 | 2015-03-10 16:39:52 -0700 | [diff] [blame] | 111 | DefaultTrafficTreatment.emptyTreatment(); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 112 | |
| 113 | @Before |
| 114 | public void setUp() throws Exception { |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame] | 115 | super.setUp(); |
Jonathan Hart | 90a02c2 | 2015-02-13 11:52:07 -0800 | [diff] [blame] | 116 | routingConfig = createMock(RoutingConfigurationService.class); |
| 117 | |
| 118 | // These will set expectations on routingConfig |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 119 | bgpSpeakers = Collections.unmodifiableMap(setUpBgpSpeakers()); |
| 120 | interfaces = Collections.unmodifiableMap(setUpInterfaces()); |
| 121 | peers = Collections.unmodifiableMap(setUpPeers()); |
| 122 | |
| 123 | initPeerConnectivity(); |
| 124 | intentList = setUpIntentList(); |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * Sets up BGP speakers. |
| 129 | * |
| 130 | * @return configured BGP speakers as a map from speaker name to speaker |
| 131 | */ |
| 132 | private Map<String, BgpSpeaker> setUpBgpSpeakers() { |
| 133 | |
| 134 | configuredBgpSpeakers = new HashMap<>(); |
| 135 | |
| 136 | BgpSpeaker bgpSpeaker1 = new BgpSpeaker( |
| 137 | "bgpSpeaker1", |
| 138 | "00:00:00:00:00:00:00:01", 100, |
| 139 | "00:00:00:00:00:01"); |
Jonathan Hart | 90a02c2 | 2015-02-13 11:52:07 -0800 | [diff] [blame] | 140 | List<InterfaceAddress> interfaceAddresses1 = new LinkedList<>(); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 141 | interfaceAddresses1.add(new InterfaceAddress(dpid1, 1, "192.168.10.101")); |
| 142 | interfaceAddresses1.add(new InterfaceAddress(dpid2, 1, "192.168.20.101")); |
| 143 | bgpSpeaker1.setInterfaceAddresses(interfaceAddresses1); |
| 144 | configuredBgpSpeakers.put(bgpSpeaker1.name(), bgpSpeaker1); |
| 145 | |
| 146 | // BGP speaker2 is attached to the same switch port with speaker1 |
| 147 | BgpSpeaker bgpSpeaker2 = new BgpSpeaker( |
| 148 | "bgpSpeaker2", |
| 149 | "00:00:00:00:00:00:00:01", 100, |
| 150 | "00:00:00:00:00:02"); |
Jonathan Hart | 90a02c2 | 2015-02-13 11:52:07 -0800 | [diff] [blame] | 151 | List<InterfaceAddress> interfaceAddresses2 = new LinkedList<>(); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 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"); |
Jonathan Hart | 90a02c2 | 2015-02-13 11:52:07 -0800 | [diff] [blame] | 161 | List<InterfaceAddress> interfaceAddresses3 = new LinkedList<>(); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 162 | interfaceAddresses3.add(new InterfaceAddress(dpid1, 1, "192.168.10.103")); |
| 163 | interfaceAddresses3.add(new InterfaceAddress(dpid2, 1, "192.168.20.103")); |
| 164 | bgpSpeaker3.setInterfaceAddresses(interfaceAddresses3); |
| 165 | configuredBgpSpeakers.put(bgpSpeaker3.name(), bgpSpeaker3); |
| 166 | |
| 167 | return configuredBgpSpeakers; |
| 168 | } |
| 169 | |
| 170 | /** |
| 171 | * Sets up logical interfaces, which emulate the configured interfaces |
| 172 | * in SDN-IP application. |
| 173 | * |
| 174 | * @return configured interfaces as a MAP from Interface name to Interface |
| 175 | */ |
| 176 | private Map<String, Interface> setUpInterfaces() { |
| 177 | |
| 178 | configuredInterfaces = new HashMap<>(); |
| 179 | |
| 180 | String interfaceSw1Eth1 = "s1-eth1"; |
Pavlin Radoslavov | 76b0ae2 | 2014-10-27 15:33:19 -0700 | [diff] [blame] | 181 | InterfaceIpAddress ia1 = |
| 182 | new InterfaceIpAddress(IpAddress.valueOf("192.168.10.1"), |
| 183 | IpPrefix.valueOf("192.168.10.0/24")); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 184 | Interface intfsw1eth1 = new Interface(s1Eth1, |
Pavlin Radoslavov | 76b0ae2 | 2014-10-27 15:33:19 -0700 | [diff] [blame] | 185 | Collections.singleton(ia1), |
Jonathan Hart | 6cd2f35 | 2015-01-13 17:44:45 -0800 | [diff] [blame] | 186 | MacAddress.valueOf("00:00:00:00:00:01"), |
| 187 | VlanId.NONE); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 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 | 6cd2f35 | 2015-01-13 17:44:45 -0800 | [diff] [blame] | 196 | MacAddress.valueOf("00:00:00:00:00:02"), |
| 197 | VlanId.NONE); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 198 | configuredInterfaces.put(interfaceSw2Eth1, intfsw2eth1); |
| 199 | |
Jonathan Hart | 90a02c2 | 2015-02-13 11:52:07 -0800 | [diff] [blame] | 200 | expect(routingConfig.getInterface(s1Eth1)) |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 201 | .andReturn(intfsw1eth1).anyTimes(); |
Jonathan Hart | 90a02c2 | 2015-02-13 11:52:07 -0800 | [diff] [blame] | 202 | expect(routingConfig.getInterface(s2Eth1)) |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 203 | .andReturn(intfsw2eth1).anyTimes(); |
| 204 | |
| 205 | // Non-existent interface used during one of the tests |
Jonathan Hart | 90a02c2 | 2015-02-13 11:52:07 -0800 | [diff] [blame] | 206 | expect(routingConfig.getInterface(new ConnectPoint( |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 207 | DeviceId.deviceId(SdnIp.dpidToUri("00:00:00:00:00:00:01:00")), |
| 208 | PortNumber.portNumber(1)))) |
| 209 | .andReturn(null).anyTimes(); |
| 210 | |
Jonathan Hart | 90a02c2 | 2015-02-13 11:52:07 -0800 | [diff] [blame] | 211 | expect(routingConfig.getInterfaces()).andReturn( |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 212 | Sets.newHashSet(configuredInterfaces.values())).anyTimes(); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 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 | |
Jonathan Hart | 90a02c2 | 2015-02-13 11:52:07 -0800 | [diff] [blame] | 249 | intentList = new ArrayList<>(); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 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 | |
Jonathan Hart | 41349e9 | 2015-02-09 14:14:02 -0800 | [diff] [blame] | 300 | Short bgpPort = 179; |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 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 | |
Jonathan Hart | 90a02c2 | 2015-02-13 11:52:07 -0800 | [diff] [blame] | 537 | expect(routingConfig.getBgpPeers()).andReturn(peers).anyTimes(); |
| 538 | expect(routingConfig.getBgpSpeakers()).andReturn(bgpSpeakers).anyTimes(); |
| 539 | replay(routingConfig); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 540 | |
| 541 | intentService = createMock(IntentService.class); |
| 542 | replay(intentService); |
| 543 | |
Jonathan Hart | 552e31f | 2015-02-06 11:11:59 -0800 | [diff] [blame] | 544 | intentSynchronizer = new IntentSynchronizer(APPID, intentService, |
Jonathan Hart | 90a02c2 | 2015-02-13 11:52:07 -0800 | [diff] [blame] | 545 | routingConfig); |
Pavlin Radoslavov | a7243cc | 2014-11-22 21:38:02 -0800 | [diff] [blame] | 546 | intentSynchronizer.leaderChanged(true); |
| 547 | TestUtils.setField(intentSynchronizer, "isActivatedLeader", true); |
| 548 | |
| 549 | peerConnectivityManager = |
| 550 | new PeerConnectivityManager(APPID, intentSynchronizer, |
Jonathan Hart | 90a02c2 | 2015-02-13 11:52:07 -0800 | [diff] [blame] | 551 | routingConfig); |
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 |
Pavlin Radoslavov | dde22ae | 2014-11-24 11:47:17 -0800 | [diff] [blame] | 567 | for (Intent intent : intentList) { |
Jonathan Hart | cb726fc | 2015-02-13 16:26:22 -0800 | [diff] [blame] | 568 | intentService.submit(eqExceptId(intent)); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 569 | } |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 570 | replay(intentService); |
| 571 | |
| 572 | // Running the interface to be tested. |
| 573 | peerConnectivityManager.start(); |
| 574 | |
| 575 | verify(intentService); |
| 576 | |
| 577 | } |
| 578 | |
| 579 | /** |
| 580 | * Tests a corner case, when there are no interfaces in the configuration. |
| 581 | */ |
| 582 | @Test |
| 583 | public void testNullInterfaces() { |
Jonathan Hart | 90a02c2 | 2015-02-13 11:52:07 -0800 | [diff] [blame] | 584 | reset(routingConfig); |
| 585 | expect(routingConfig.getInterfaces()).andReturn( |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 586 | Sets.<Interface>newHashSet()).anyTimes(); |
Jonathan Hart | 90a02c2 | 2015-02-13 11:52:07 -0800 | [diff] [blame] | 587 | expect(routingConfig.getInterface(s2Eth1)) |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 588 | .andReturn(null).anyTimes(); |
Jonathan Hart | 90a02c2 | 2015-02-13 11:52:07 -0800 | [diff] [blame] | 589 | expect(routingConfig.getInterface(s1Eth1)) |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 590 | .andReturn(null).anyTimes(); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 591 | |
Jonathan Hart | 90a02c2 | 2015-02-13 11:52:07 -0800 | [diff] [blame] | 592 | expect(routingConfig.getBgpPeers()).andReturn(peers).anyTimes(); |
| 593 | expect(routingConfig.getBgpSpeakers()).andReturn(bgpSpeakers).anyTimes(); |
| 594 | replay(routingConfig); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 595 | |
| 596 | reset(intentService); |
| 597 | replay(intentService); |
| 598 | peerConnectivityManager.start(); |
| 599 | verify(intentService); |
| 600 | } |
| 601 | |
| 602 | /** |
| 603 | * Tests a corner case, when there are no BGP peers in the configuration. |
| 604 | */ |
| 605 | @Test |
| 606 | public void testNullBgpPeers() { |
Jonathan Hart | 90a02c2 | 2015-02-13 11:52:07 -0800 | [diff] [blame] | 607 | reset(routingConfig); |
| 608 | expect(routingConfig.getInterfaces()).andReturn( |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 609 | Sets.newHashSet(interfaces.values())).anyTimes(); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 610 | |
Jonathan Hart | 90a02c2 | 2015-02-13 11:52:07 -0800 | [diff] [blame] | 611 | expect(routingConfig.getBgpPeers()).andReturn(new HashMap<>()).anyTimes(); |
| 612 | expect(routingConfig.getBgpSpeakers()).andReturn(bgpSpeakers).anyTimes(); |
| 613 | replay(routingConfig); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 614 | |
| 615 | reset(intentService); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 616 | replay(intentService); |
| 617 | peerConnectivityManager.start(); |
| 618 | verify(intentService); |
| 619 | } |
| 620 | |
| 621 | /** |
| 622 | * Tests a corner case, when there is no BGP speakers in the configuration. |
| 623 | */ |
| 624 | @Test |
| 625 | public void testNullBgpSpeakers() { |
Jonathan Hart | 90a02c2 | 2015-02-13 11:52:07 -0800 | [diff] [blame] | 626 | reset(routingConfig); |
| 627 | expect(routingConfig.getInterfaces()).andReturn( |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 628 | Sets.newHashSet(interfaces.values())).anyTimes(); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 629 | |
Jonathan Hart | 90a02c2 | 2015-02-13 11:52:07 -0800 | [diff] [blame] | 630 | expect(routingConfig.getBgpPeers()).andReturn(peers).anyTimes(); |
| 631 | expect(routingConfig.getBgpSpeakers()).andReturn( |
Jonathan Hart | 5137218 | 2014-12-03 21:32:34 -0800 | [diff] [blame] | 632 | Collections.emptyMap()).anyTimes(); |
Jonathan Hart | 90a02c2 | 2015-02-13 11:52:07 -0800 | [diff] [blame] | 633 | replay(routingConfig); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 634 | |
| 635 | reset(intentService); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 636 | replay(intentService); |
| 637 | peerConnectivityManager.start(); |
| 638 | verify(intentService); |
| 639 | } |
| 640 | |
| 641 | /** |
| 642 | * Tests a corner case, when there is no Interface configured for one BGP |
| 643 | * peer. |
| 644 | */ |
| 645 | @Test |
| 646 | public void testNoPeerInterface() { |
| 647 | String peerSw100Eth1 = "192.168.200.1"; |
| 648 | configuredPeers.put(IpAddress.valueOf(peerSw100Eth1), |
| 649 | new BgpPeer("00:00:00:00:00:00:01:00", 1, peerSw100Eth1)); |
| 650 | testConnectionSetup(); |
| 651 | } |
| 652 | |
| 653 | /** |
| 654 | * Tests a corner case, when there is no Interface configured for one BGP |
| 655 | * speaker. |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 656 | */ |
| 657 | @Ignore |
| 658 | @Test |
| 659 | public void testNoSpeakerInterface() { |
| 660 | BgpSpeaker bgpSpeaker100 = new BgpSpeaker( |
| 661 | "bgpSpeaker100", |
| 662 | "00:00:00:00:00:00:01:00", 100, |
| 663 | "00:00:00:00:01:00"); |
Jonathan Hart | 90a02c2 | 2015-02-13 11:52:07 -0800 | [diff] [blame] | 664 | List<InterfaceAddress> interfaceAddresses100 = new LinkedList<>(); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 665 | interfaceAddresses100.add(new InterfaceAddress(dpid1, 1, "192.168.10.201")); |
| 666 | interfaceAddresses100.add(new InterfaceAddress(dpid2, 1, "192.168.20.201")); |
| 667 | bgpSpeaker100.setInterfaceAddresses(interfaceAddresses100); |
| 668 | configuredBgpSpeakers.put(bgpSpeaker100.name(), bgpSpeaker100); |
| 669 | testConnectionSetup(); |
| 670 | } |
| 671 | } |