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 | |
Jonathan Hart | e30fcda | 2015-08-06 16:22:34 -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; |
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; |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 29 | import org.onlab.packet.TpPort; |
Jonathan Hart | 6cd2f35 | 2015-01-13 17:44:45 -0800 | [diff] [blame] | 30 | import org.onlab.packet.VlanId; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 31 | import org.onosproject.core.ApplicationId; |
| 32 | import org.onosproject.net.ConnectPoint; |
| 33 | import org.onosproject.net.DeviceId; |
| 34 | import org.onosproject.net.PortNumber; |
| 35 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 36 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 37 | import org.onosproject.net.flow.TrafficSelector; |
| 38 | import org.onosproject.net.flow.TrafficTreatment; |
| 39 | import org.onosproject.net.host.InterfaceIpAddress; |
| 40 | import org.onosproject.net.intent.AbstractIntentTest; |
| 41 | import org.onosproject.net.intent.Intent; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 42 | import org.onosproject.net.intent.IntentService; |
| 43 | import org.onosproject.net.intent.PointToPointIntent; |
Jonathan Hart | 2da1e60 | 2015-02-18 19:09:24 -0800 | [diff] [blame] | 44 | import org.onosproject.routing.config.BgpPeer; |
| 45 | import org.onosproject.routing.config.BgpSpeaker; |
| 46 | import org.onosproject.routing.config.Interface; |
| 47 | import org.onosproject.routing.config.InterfaceAddress; |
| 48 | import org.onosproject.routing.config.RoutingConfigurationService; |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 49 | |
Jonathan Hart | e30fcda | 2015-08-06 16:22:34 -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; |
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")); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 147 | bgpSpeaker1.setInterfaceAddresses(interfaceAddresses1); |
| 148 | configuredBgpSpeakers.put(bgpSpeaker1.name(), bgpSpeaker1); |
| 149 | |
| 150 | // BGP speaker2 is attached to the same switch port with speaker1 |
| 151 | BgpSpeaker bgpSpeaker2 = new BgpSpeaker( |
| 152 | "bgpSpeaker2", |
| 153 | "00:00:00:00:00:00:00:01", 100, |
| 154 | "00:00:00:00:00:02"); |
Jonathan Hart | 90a02c2 | 2015-02-13 11:52:07 -0800 | [diff] [blame] | 155 | List<InterfaceAddress> interfaceAddresses2 = new LinkedList<>(); |
Jonathan Hart | e30fcda | 2015-08-06 16:22:34 -0700 | [diff] [blame] | 156 | interfaceAddresses2.add(new InterfaceAddress(dpid2, 1, "192.168.20.101")); |
| 157 | interfaceAddresses2.add(new InterfaceAddress(dpid2, 1, "192.168.30.101")); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 158 | bgpSpeaker2.setInterfaceAddresses(interfaceAddresses2); |
| 159 | configuredBgpSpeakers.put(bgpSpeaker2.name(), bgpSpeaker2); |
| 160 | |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 161 | return configuredBgpSpeakers; |
| 162 | } |
| 163 | |
| 164 | /** |
| 165 | * Sets up logical interfaces, which emulate the configured interfaces |
| 166 | * in SDN-IP application. |
| 167 | * |
| 168 | * @return configured interfaces as a MAP from Interface name to Interface |
| 169 | */ |
| 170 | private Map<String, Interface> setUpInterfaces() { |
| 171 | |
| 172 | configuredInterfaces = new HashMap<>(); |
| 173 | |
| 174 | String interfaceSw1Eth1 = "s1-eth1"; |
Pavlin Radoslavov | 76b0ae2 | 2014-10-27 15:33:19 -0700 | [diff] [blame] | 175 | InterfaceIpAddress ia1 = |
Jonathan Hart | e30fcda | 2015-08-06 16:22:34 -0700 | [diff] [blame] | 176 | new InterfaceIpAddress(IpAddress.valueOf("192.168.10.101"), |
Pavlin Radoslavov | 76b0ae2 | 2014-10-27 15:33:19 -0700 | [diff] [blame] | 177 | IpPrefix.valueOf("192.168.10.0/24")); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 178 | Interface intfsw1eth1 = new Interface(s1Eth1, |
Pavlin Radoslavov | 76b0ae2 | 2014-10-27 15:33:19 -0700 | [diff] [blame] | 179 | Collections.singleton(ia1), |
Jonathan Hart | 6cd2f35 | 2015-01-13 17:44:45 -0800 | [diff] [blame] | 180 | MacAddress.valueOf("00:00:00:00:00:01"), |
| 181 | VlanId.NONE); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 182 | |
| 183 | configuredInterfaces.put(interfaceSw1Eth1, intfsw1eth1); |
| 184 | String interfaceSw2Eth1 = "s2-eth1"; |
Pavlin Radoslavov | 76b0ae2 | 2014-10-27 15:33:19 -0700 | [diff] [blame] | 185 | InterfaceIpAddress ia2 = |
Jonathan Hart | e30fcda | 2015-08-06 16:22:34 -0700 | [diff] [blame] | 186 | new InterfaceIpAddress(IpAddress.valueOf("192.168.20.101"), |
Pavlin Radoslavov | 76b0ae2 | 2014-10-27 15:33:19 -0700 | [diff] [blame] | 187 | IpPrefix.valueOf("192.168.20.0/24")); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 188 | Interface intfsw2eth1 = new Interface(s2Eth1, |
Pavlin Radoslavov | 76b0ae2 | 2014-10-27 15:33:19 -0700 | [diff] [blame] | 189 | Collections.singleton(ia2), |
Jonathan Hart | 6cd2f35 | 2015-01-13 17:44:45 -0800 | [diff] [blame] | 190 | MacAddress.valueOf("00:00:00:00:00:02"), |
| 191 | VlanId.NONE); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 192 | configuredInterfaces.put(interfaceSw2Eth1, intfsw2eth1); |
| 193 | |
Jonathan Hart | e30fcda | 2015-08-06 16:22:34 -0700 | [diff] [blame] | 194 | String interfaceSw2Eth1intf2 = "s2-eth1_2"; |
| 195 | InterfaceIpAddress ia3 = |
| 196 | new InterfaceIpAddress(IpAddress.valueOf("192.168.30.101"), |
| 197 | IpPrefix.valueOf("192.168.30.0/24")); |
| 198 | Interface intfsw2eth1intf2 = new Interface(s2Eth1, |
| 199 | Collections.singleton(ia3), |
| 200 | MacAddress.valueOf("00:00:00:00:00:03"), |
| 201 | VlanId.NONE); |
| 202 | configuredInterfaces.put(interfaceSw2Eth1intf2, intfsw2eth1intf2); |
| 203 | |
Jonathan Hart | 90a02c2 | 2015-02-13 11:52:07 -0800 | [diff] [blame] | 204 | expect(routingConfig.getInterface(s1Eth1)) |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 205 | .andReturn(intfsw1eth1).anyTimes(); |
Jonathan Hart | e30fcda | 2015-08-06 16:22:34 -0700 | [diff] [blame] | 206 | expect(routingConfig.getInterface(IpAddress.valueOf("192.168.10.101"))) |
| 207 | .andReturn(intfsw1eth1).anyTimes(); |
Jonathan Hart | 90a02c2 | 2015-02-13 11:52:07 -0800 | [diff] [blame] | 208 | expect(routingConfig.getInterface(s2Eth1)) |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 209 | .andReturn(intfsw2eth1).anyTimes(); |
Jonathan Hart | e30fcda | 2015-08-06 16:22:34 -0700 | [diff] [blame] | 210 | expect(routingConfig.getInterface(IpAddress.valueOf("192.168.20.101"))) |
| 211 | .andReturn(intfsw2eth1).anyTimes(); |
| 212 | //expect(routingConfig.getInterface(s2Eth1)) |
| 213 | // .andReturn(intfsw2eth1intf2).anyTimes(); |
| 214 | expect(routingConfig.getInterface(IpAddress.valueOf("192.168.30.101"))) |
| 215 | .andReturn(intfsw2eth1intf2).anyTimes(); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 216 | |
| 217 | // Non-existent interface used during one of the tests |
Jonathan Hart | 90a02c2 | 2015-02-13 11:52:07 -0800 | [diff] [blame] | 218 | expect(routingConfig.getInterface(new ConnectPoint( |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 219 | DeviceId.deviceId(SdnIp.dpidToUri("00:00:00:00:00:00:01:00")), |
| 220 | PortNumber.portNumber(1)))) |
| 221 | .andReturn(null).anyTimes(); |
| 222 | |
Jonathan Hart | 90a02c2 | 2015-02-13 11:52:07 -0800 | [diff] [blame] | 223 | expect(routingConfig.getInterfaces()).andReturn( |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 224 | Sets.newHashSet(configuredInterfaces.values())).anyTimes(); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 225 | |
| 226 | return configuredInterfaces; |
| 227 | } |
| 228 | |
| 229 | /** |
| 230 | * Sets up BGP daemon peers. |
| 231 | * |
| 232 | * @return configured BGP peers as a MAP from peer IP address to BgpPeer |
| 233 | */ |
| 234 | private Map<IpAddress, BgpPeer> setUpPeers() { |
| 235 | |
| 236 | configuredPeers = new HashMap<>(); |
| 237 | |
| 238 | String peerSw1Eth1 = "192.168.10.1"; |
| 239 | configuredPeers.put(IpAddress.valueOf(peerSw1Eth1), |
| 240 | new BgpPeer(dpid1, 1, peerSw1Eth1)); |
| 241 | |
| 242 | // Two BGP peers are connected to switch 2 port 1. |
| 243 | String peer1Sw2Eth1 = "192.168.20.1"; |
| 244 | configuredPeers.put(IpAddress.valueOf(peer1Sw2Eth1), |
| 245 | new BgpPeer(dpid2, 1, peer1Sw2Eth1)); |
| 246 | |
Jonathan Hart | e30fcda | 2015-08-06 16:22:34 -0700 | [diff] [blame] | 247 | String peer2Sw2Eth1 = "192.168.30.1"; |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 248 | configuredPeers.put(IpAddress.valueOf(peer2Sw2Eth1), |
| 249 | new BgpPeer(dpid2, 1, peer2Sw2Eth1)); |
| 250 | |
| 251 | return configuredPeers; |
| 252 | } |
| 253 | |
| 254 | /** |
| 255 | * Sets up expected point to point intent list. |
| 256 | * |
| 257 | * @return point to point intent list |
| 258 | */ |
| 259 | private List<PointToPointIntent> setUpIntentList() { |
| 260 | |
Jonathan Hart | 90a02c2 | 2015-02-13 11:52:07 -0800 | [diff] [blame] | 261 | intentList = new ArrayList<>(); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 262 | |
| 263 | setUpBgpIntents(); |
| 264 | setUpIcmpIntents(); |
| 265 | |
| 266 | return intentList; |
| 267 | |
| 268 | } |
| 269 | |
| 270 | /** |
| 271 | * Constructs a BGP intent and put it into the intentList. |
| 272 | * <p/> |
| 273 | * The purpose of this method is too simplify the setUpBgpIntents() method, |
| 274 | * and to make the setUpBgpIntents() easy to read. |
| 275 | * |
| 276 | * @param srcPrefix source IP prefix to match |
| 277 | * @param dstPrefix destination IP prefix to match |
| 278 | * @param srcTcpPort source TCP port to match |
| 279 | * @param dstTcpPort destination TCP port to match |
| 280 | * @param srcConnectPoint source connect point for PointToPointIntent |
| 281 | * @param dstConnectPoint destination connect point for PointToPointIntent |
| 282 | */ |
| 283 | private void bgpPathintentConstructor(String srcPrefix, String dstPrefix, |
| 284 | Short srcTcpPort, Short dstTcpPort, |
| 285 | ConnectPoint srcConnectPoint, ConnectPoint dstConnectPoint) { |
| 286 | |
| 287 | TrafficSelector.Builder builder = DefaultTrafficSelector.builder() |
| 288 | .matchEthType(Ethernet.TYPE_IPV4) |
| 289 | .matchIPProtocol(IPv4.PROTOCOL_TCP) |
| 290 | .matchIPSrc(IpPrefix.valueOf(srcPrefix)) |
| 291 | .matchIPDst(IpPrefix.valueOf(dstPrefix)); |
| 292 | |
| 293 | if (srcTcpPort != null) { |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 294 | builder.matchTcpSrc(TpPort.tpPort(srcTcpPort)); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 295 | } |
| 296 | if (dstTcpPort != null) { |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 297 | builder.matchTcpDst(TpPort.tpPort(dstTcpPort)); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 298 | } |
| 299 | |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 300 | PointToPointIntent intent = PointToPointIntent.builder() |
| 301 | .appId(APPID) |
| 302 | .selector(builder.build()) |
| 303 | .treatment(noTreatment) |
| 304 | .ingressPoint(srcConnectPoint) |
| 305 | .egressPoint(dstConnectPoint) |
| 306 | .build(); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 307 | |
| 308 | intentList.add(intent); |
| 309 | } |
| 310 | |
| 311 | /** |
| 312 | * Sets up intents for BGP paths. |
| 313 | */ |
| 314 | private void setUpBgpIntents() { |
| 315 | |
Jonathan Hart | 41349e9 | 2015-02-09 14:14:02 -0800 | [diff] [blame] | 316 | Short bgpPort = 179; |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 317 | |
| 318 | // Start to build intents between BGP speaker1 and BGP peer1 |
| 319 | bgpPathintentConstructor( |
| 320 | "192.168.10.101/32", "192.168.10.1/32", null, bgpPort, |
| 321 | s1Eth100, s1Eth1); |
| 322 | bgpPathintentConstructor( |
| 323 | "192.168.10.101/32", "192.168.10.1/32", bgpPort, null, |
| 324 | s1Eth100, s1Eth1); |
| 325 | |
| 326 | bgpPathintentConstructor( |
| 327 | "192.168.10.1/32", "192.168.10.101/32", null, bgpPort, |
| 328 | s1Eth1, s1Eth100); |
| 329 | bgpPathintentConstructor( |
| 330 | "192.168.10.1/32", "192.168.10.101/32", bgpPort, null, |
| 331 | s1Eth1, s1Eth100); |
| 332 | |
| 333 | // Start to build intents between BGP speaker1 and BGP peer2 |
| 334 | bgpPathintentConstructor( |
| 335 | "192.168.20.101/32", "192.168.20.1/32", null, bgpPort, |
| 336 | s1Eth100, s2Eth1); |
| 337 | bgpPathintentConstructor( |
| 338 | "192.168.20.101/32", "192.168.20.1/32", bgpPort, null, |
| 339 | s1Eth100, s2Eth1); |
| 340 | |
| 341 | bgpPathintentConstructor( |
| 342 | "192.168.20.1/32", "192.168.20.101/32", null, bgpPort, |
| 343 | s2Eth1, s1Eth100); |
| 344 | bgpPathintentConstructor( |
| 345 | "192.168.20.1/32", "192.168.20.101/32", bgpPort, null, |
| 346 | s2Eth1, s1Eth100); |
| 347 | |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 348 | // |
| 349 | // Start to build intents between BGP speaker3 and BGP peer1 |
| 350 | bgpPathintentConstructor( |
Jonathan Hart | e30fcda | 2015-08-06 16:22:34 -0700 | [diff] [blame] | 351 | "192.168.30.101/32", "192.168.30.1/32", null, bgpPort, |
| 352 | s1Eth100, s2Eth1); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 353 | bgpPathintentConstructor( |
Jonathan Hart | e30fcda | 2015-08-06 16:22:34 -0700 | [diff] [blame] | 354 | "192.168.30.101/32", "192.168.30.1/32", bgpPort, null, |
| 355 | s1Eth100, s2Eth1); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 356 | |
| 357 | bgpPathintentConstructor( |
Jonathan Hart | e30fcda | 2015-08-06 16:22:34 -0700 | [diff] [blame] | 358 | "192.168.30.1/32", "192.168.30.101/32", null, bgpPort, |
| 359 | s2Eth1, s1Eth100); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 360 | bgpPathintentConstructor( |
Jonathan Hart | e30fcda | 2015-08-06 16:22:34 -0700 | [diff] [blame] | 361 | "192.168.30.1/32", "192.168.30.101/32", bgpPort, null, |
| 362 | s2Eth1, s1Eth100); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | /** |
| 366 | * Constructs a BGP intent and put it into the intentList. |
| 367 | * <p/> |
| 368 | * The purpose of this method is too simplify the setUpBgpIntents() method, |
| 369 | * and to make the setUpBgpIntents() easy to read. |
| 370 | * |
| 371 | * @param srcPrefix source IP prefix to match |
| 372 | * @param dstPrefix destination IP prefix to match |
| 373 | * @param srcConnectPoint source connect point for PointToPointIntent |
| 374 | * @param dstConnectPoint destination connect point for PointToPointIntent |
| 375 | */ |
| 376 | private void icmpPathintentConstructor(String srcPrefix, String dstPrefix, |
| 377 | ConnectPoint srcConnectPoint, ConnectPoint dstConnectPoint) { |
| 378 | |
| 379 | TrafficSelector selector = DefaultTrafficSelector.builder() |
| 380 | .matchEthType(Ethernet.TYPE_IPV4) |
| 381 | .matchIPProtocol(IPv4.PROTOCOL_ICMP) |
| 382 | .matchIPSrc(IpPrefix.valueOf(srcPrefix)) |
| 383 | .matchIPDst(IpPrefix.valueOf(dstPrefix)) |
| 384 | .build(); |
| 385 | |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 386 | PointToPointIntent intent = PointToPointIntent.builder() |
| 387 | .appId(APPID) |
| 388 | .selector(selector) |
| 389 | .treatment(noTreatment) |
| 390 | .ingressPoint(srcConnectPoint) |
| 391 | .egressPoint(dstConnectPoint) |
| 392 | .build(); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 393 | |
| 394 | intentList.add(intent); |
| 395 | } |
| 396 | |
| 397 | /** |
| 398 | * Sets up intents for ICMP paths. |
| 399 | */ |
| 400 | private void setUpIcmpIntents() { |
| 401 | |
| 402 | // Start to build intents between BGP speaker1 and BGP peer1 |
| 403 | icmpPathintentConstructor( |
| 404 | "192.168.10.101/32", "192.168.10.1/32", s1Eth100, s1Eth1); |
| 405 | icmpPathintentConstructor( |
| 406 | "192.168.10.1/32", "192.168.10.101/32", s1Eth1, s1Eth100); |
| 407 | |
| 408 | // Start to build intents between BGP speaker1 and BGP peer2 |
| 409 | icmpPathintentConstructor( |
| 410 | "192.168.20.101/32", "192.168.20.1/32", s1Eth100, s2Eth1); |
| 411 | icmpPathintentConstructor( |
| 412 | "192.168.20.1/32", "192.168.20.101/32", s2Eth1, s1Eth100); |
| 413 | |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 414 | icmpPathintentConstructor( |
Jonathan Hart | e30fcda | 2015-08-06 16:22:34 -0700 | [diff] [blame] | 415 | "192.168.30.101/32", "192.168.30.1/32", s1Eth100, s2Eth1); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 416 | icmpPathintentConstructor( |
Jonathan Hart | e30fcda | 2015-08-06 16:22:34 -0700 | [diff] [blame] | 417 | "192.168.30.1/32", "192.168.30.101/32", s2Eth1, s1Eth100); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 418 | |
| 419 | } |
| 420 | |
| 421 | /** |
| 422 | * Initializes peer connectivity testing environment. |
Pavlin Radoslavov | a7243cc | 2014-11-22 21:38:02 -0800 | [diff] [blame] | 423 | * |
| 424 | * @throws TestUtilsException if exceptions when using TestUtils |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 425 | */ |
Pavlin Radoslavov | a7243cc | 2014-11-22 21:38:02 -0800 | [diff] [blame] | 426 | private void initPeerConnectivity() throws TestUtilsException { |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 427 | |
Jonathan Hart | 90a02c2 | 2015-02-13 11:52:07 -0800 | [diff] [blame] | 428 | expect(routingConfig.getBgpPeers()).andReturn(peers).anyTimes(); |
| 429 | expect(routingConfig.getBgpSpeakers()).andReturn(bgpSpeakers).anyTimes(); |
| 430 | replay(routingConfig); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 431 | |
| 432 | intentService = createMock(IntentService.class); |
| 433 | replay(intentService); |
| 434 | |
Jonathan Hart | 552e31f | 2015-02-06 11:11:59 -0800 | [diff] [blame] | 435 | intentSynchronizer = new IntentSynchronizer(APPID, intentService, |
Pingping Lin | e28ae4c | 2015-03-13 11:37:03 -0700 | [diff] [blame] | 436 | null, routingConfig); |
Pavlin Radoslavov | a7243cc | 2014-11-22 21:38:02 -0800 | [diff] [blame] | 437 | intentSynchronizer.leaderChanged(true); |
| 438 | TestUtils.setField(intentSynchronizer, "isActivatedLeader", true); |
| 439 | |
| 440 | peerConnectivityManager = |
| 441 | new PeerConnectivityManager(APPID, intentSynchronizer, |
Jonathan Hart | 90a02c2 | 2015-02-13 11:52:07 -0800 | [diff] [blame] | 442 | routingConfig); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 443 | } |
| 444 | |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 445 | /** |
| 446 | * Tests whether peer connectivity manager can set up correct BGP and |
| 447 | * ICMP intents according to specific configuration. |
| 448 | * <p/> |
| 449 | * Two tricky cases included in the configuration are: 2 peers on a same |
| 450 | * switch port, peer on the same switch with BGPd. |
| 451 | */ |
| 452 | @Test |
| 453 | public void testConnectionSetup() { |
| 454 | |
| 455 | reset(intentService); |
| 456 | |
Pavlin Radoslavov | dde22ae | 2014-11-24 11:47:17 -0800 | [diff] [blame] | 457 | // Setup the expected intents |
Pavlin Radoslavov | dde22ae | 2014-11-24 11:47:17 -0800 | [diff] [blame] | 458 | for (Intent intent : intentList) { |
Jonathan Hart | cb726fc | 2015-02-13 16:26:22 -0800 | [diff] [blame] | 459 | intentService.submit(eqExceptId(intent)); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 460 | } |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 461 | replay(intentService); |
| 462 | |
| 463 | // Running the interface to be tested. |
| 464 | peerConnectivityManager.start(); |
| 465 | |
| 466 | verify(intentService); |
| 467 | |
| 468 | } |
| 469 | |
| 470 | /** |
| 471 | * Tests a corner case, when there are no interfaces in the configuration. |
| 472 | */ |
| 473 | @Test |
| 474 | public void testNullInterfaces() { |
Jonathan Hart | 90a02c2 | 2015-02-13 11:52:07 -0800 | [diff] [blame] | 475 | reset(routingConfig); |
| 476 | expect(routingConfig.getInterfaces()).andReturn( |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 477 | Sets.<Interface>newHashSet()).anyTimes(); |
Jonathan Hart | 90a02c2 | 2015-02-13 11:52:07 -0800 | [diff] [blame] | 478 | expect(routingConfig.getInterface(s2Eth1)) |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 479 | .andReturn(null).anyTimes(); |
Jonathan Hart | 90a02c2 | 2015-02-13 11:52:07 -0800 | [diff] [blame] | 480 | expect(routingConfig.getInterface(s1Eth1)) |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 481 | .andReturn(null).anyTimes(); |
Jonathan Hart | e30fcda | 2015-08-06 16:22:34 -0700 | [diff] [blame] | 482 | expect(routingConfig.getInterface(IpAddress.valueOf("192.168.10.101"))) |
| 483 | .andReturn(null).anyTimes(); |
| 484 | expect(routingConfig.getInterface(IpAddress.valueOf("192.168.20.101"))) |
| 485 | .andReturn(null).anyTimes(); |
| 486 | expect(routingConfig.getInterface(IpAddress.valueOf("192.168.30.101"))) |
| 487 | .andReturn(null).anyTimes(); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 488 | |
Jonathan Hart | 90a02c2 | 2015-02-13 11:52:07 -0800 | [diff] [blame] | 489 | expect(routingConfig.getBgpPeers()).andReturn(peers).anyTimes(); |
| 490 | expect(routingConfig.getBgpSpeakers()).andReturn(bgpSpeakers).anyTimes(); |
| 491 | replay(routingConfig); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 492 | |
| 493 | reset(intentService); |
| 494 | replay(intentService); |
| 495 | peerConnectivityManager.start(); |
| 496 | verify(intentService); |
| 497 | } |
| 498 | |
| 499 | /** |
| 500 | * Tests a corner case, when there are no BGP peers in the configuration. |
| 501 | */ |
| 502 | @Test |
| 503 | public void testNullBgpPeers() { |
Jonathan Hart | 90a02c2 | 2015-02-13 11:52:07 -0800 | [diff] [blame] | 504 | reset(routingConfig); |
| 505 | expect(routingConfig.getInterfaces()).andReturn( |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 506 | Sets.newHashSet(interfaces.values())).anyTimes(); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 507 | |
Jonathan Hart | 90a02c2 | 2015-02-13 11:52:07 -0800 | [diff] [blame] | 508 | expect(routingConfig.getBgpPeers()).andReturn(new HashMap<>()).anyTimes(); |
| 509 | expect(routingConfig.getBgpSpeakers()).andReturn(bgpSpeakers).anyTimes(); |
| 510 | replay(routingConfig); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 511 | |
| 512 | reset(intentService); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 513 | replay(intentService); |
| 514 | peerConnectivityManager.start(); |
| 515 | verify(intentService); |
| 516 | } |
| 517 | |
| 518 | /** |
| 519 | * Tests a corner case, when there is no BGP speakers in the configuration. |
| 520 | */ |
| 521 | @Test |
| 522 | public void testNullBgpSpeakers() { |
Jonathan Hart | 90a02c2 | 2015-02-13 11:52:07 -0800 | [diff] [blame] | 523 | reset(routingConfig); |
| 524 | expect(routingConfig.getInterfaces()).andReturn( |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 525 | Sets.newHashSet(interfaces.values())).anyTimes(); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 526 | |
Jonathan Hart | 90a02c2 | 2015-02-13 11:52:07 -0800 | [diff] [blame] | 527 | expect(routingConfig.getBgpPeers()).andReturn(peers).anyTimes(); |
| 528 | expect(routingConfig.getBgpSpeakers()).andReturn( |
Jonathan Hart | 5137218 | 2014-12-03 21:32:34 -0800 | [diff] [blame] | 529 | Collections.emptyMap()).anyTimes(); |
Jonathan Hart | 90a02c2 | 2015-02-13 11:52:07 -0800 | [diff] [blame] | 530 | replay(routingConfig); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 531 | |
| 532 | reset(intentService); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 533 | replay(intentService); |
| 534 | peerConnectivityManager.start(); |
| 535 | verify(intentService); |
| 536 | } |
| 537 | |
| 538 | /** |
| 539 | * Tests a corner case, when there is no Interface configured for one BGP |
| 540 | * peer. |
| 541 | */ |
| 542 | @Test |
| 543 | public void testNoPeerInterface() { |
| 544 | String peerSw100Eth1 = "192.168.200.1"; |
| 545 | configuredPeers.put(IpAddress.valueOf(peerSw100Eth1), |
| 546 | new BgpPeer("00:00:00:00:00:00:01:00", 1, peerSw100Eth1)); |
| 547 | testConnectionSetup(); |
| 548 | } |
| 549 | |
| 550 | /** |
| 551 | * Tests a corner case, when there is no Interface configured for one BGP |
| 552 | * speaker. |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 553 | */ |
| 554 | @Ignore |
| 555 | @Test |
| 556 | public void testNoSpeakerInterface() { |
| 557 | BgpSpeaker bgpSpeaker100 = new BgpSpeaker( |
| 558 | "bgpSpeaker100", |
| 559 | "00:00:00:00:00:00:01:00", 100, |
| 560 | "00:00:00:00:01:00"); |
Jonathan Hart | 90a02c2 | 2015-02-13 11:52:07 -0800 | [diff] [blame] | 561 | List<InterfaceAddress> interfaceAddresses100 = new LinkedList<>(); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 562 | interfaceAddresses100.add(new InterfaceAddress(dpid1, 1, "192.168.10.201")); |
| 563 | interfaceAddresses100.add(new InterfaceAddress(dpid2, 1, "192.168.20.201")); |
| 564 | bgpSpeaker100.setInterfaceAddresses(interfaceAddresses100); |
| 565 | configuredBgpSpeakers.put(bgpSpeaker100.name(), bgpSpeaker100); |
| 566 | testConnectionSetup(); |
| 567 | } |
| 568 | } |