Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2014-present 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; |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 20 | import org.junit.Test; |
Pavlin Radoslavov | a7243cc | 2014-11-22 21:38:02 -0800 | [diff] [blame] | 21 | import org.onlab.junit.TestUtils.TestUtilsException; |
Jonathan Hart | 5137218 | 2014-12-03 21:32:34 -0800 | [diff] [blame] | 22 | import org.onlab.packet.Ethernet; |
| 23 | import org.onlab.packet.IPv4; |
| 24 | import org.onlab.packet.IpAddress; |
| 25 | import org.onlab.packet.IpPrefix; |
| 26 | import org.onlab.packet.MacAddress; |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 27 | import org.onlab.packet.TpPort; |
Jonathan Hart | 6cd2f35 | 2015-01-13 17:44:45 -0800 | [diff] [blame] | 28 | import org.onlab.packet.VlanId; |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 29 | import org.onosproject.TestApplicationId; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 30 | import org.onosproject.core.ApplicationId; |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 31 | import org.onosproject.incubator.net.intf.Interface; |
Jonathan Hart | b14221c | 2016-03-07 09:55:50 -0800 | [diff] [blame] | 32 | import org.onosproject.incubator.net.intf.InterfaceListener; |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 33 | import org.onosproject.incubator.net.intf.InterfaceService; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 34 | import org.onosproject.net.ConnectPoint; |
| 35 | import org.onosproject.net.DeviceId; |
| 36 | import org.onosproject.net.PortNumber; |
Jonathan Hart | 08105be | 2015-10-10 18:31:06 -0700 | [diff] [blame] | 37 | import org.onosproject.net.config.NetworkConfigListener; |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 38 | import org.onosproject.net.config.NetworkConfigService; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 39 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 40 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 41 | import org.onosproject.net.flow.TrafficSelector; |
| 42 | import org.onosproject.net.flow.TrafficTreatment; |
| 43 | import org.onosproject.net.host.InterfaceIpAddress; |
| 44 | import org.onosproject.net.intent.AbstractIntentTest; |
| 45 | import org.onosproject.net.intent.Intent; |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 46 | import org.onosproject.net.intent.Key; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 47 | import org.onosproject.net.intent.PointToPointIntent; |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 48 | import org.onosproject.routing.IntentSynchronizationService; |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 49 | import org.onosproject.routing.config.BgpConfig; |
Jonathan Hart | 2da1e60 | 2015-02-18 19:09:24 -0800 | [diff] [blame] | 50 | import org.onosproject.routing.config.BgpPeer; |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 51 | |
Jonathan Hart | e30fcda | 2015-08-06 16:22:34 -0700 | [diff] [blame] | 52 | import java.util.ArrayList; |
| 53 | import java.util.Collections; |
| 54 | import java.util.HashMap; |
Jonathan Hart | e30fcda | 2015-08-06 16:22:34 -0700 | [diff] [blame] | 55 | import java.util.List; |
| 56 | import java.util.Map; |
Jonathan Hart | a862548 | 2015-09-08 16:14:56 -0700 | [diff] [blame] | 57 | import java.util.Optional; |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 58 | import java.util.Set; |
Jonathan Hart | 552e31f | 2015-02-06 11:11:59 -0800 | [diff] [blame] | 59 | |
Jonathan Hart | 08105be | 2015-10-10 18:31:06 -0700 | [diff] [blame] | 60 | import static org.easymock.EasyMock.anyObject; |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 61 | import static org.easymock.EasyMock.createMock; |
| 62 | import static org.easymock.EasyMock.expect; |
Jonathan Hart | 08105be | 2015-10-10 18:31:06 -0700 | [diff] [blame] | 63 | import static org.easymock.EasyMock.expectLastCall; |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 64 | import static org.easymock.EasyMock.replay; |
| 65 | import static org.easymock.EasyMock.reset; |
| 66 | import static org.easymock.EasyMock.verify; |
Jonathan Hart | 33b81f2 | 2016-02-05 09:25:50 -0800 | [diff] [blame] | 67 | import static org.onosproject.routing.TestIntentServiceHelper.eqExceptId; |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 68 | |
| 69 | /** |
Jonathan Hart | 5137218 | 2014-12-03 21:32:34 -0800 | [diff] [blame] | 70 | * Unit tests for PeerConnectivityManager. |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 71 | */ |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame] | 72 | public class PeerConnectivityManagerTest extends AbstractIntentTest { |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 73 | |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 74 | private static final ApplicationId APPID = TestApplicationId.create("foo"); |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 75 | |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 76 | private static final ApplicationId CONFIG_APP_ID = APPID; |
| 77 | |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 78 | private PeerConnectivityManager peerConnectivityManager; |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 79 | private IntentSynchronizationService intentSynchronizer; |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 80 | private InterfaceService interfaceService; |
| 81 | private NetworkConfigService networkConfigService; |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 82 | |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 83 | private Set<BgpConfig.BgpSpeakerConfig> bgpSpeakers; |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 84 | private Map<String, Interface> interfaces; |
| 85 | private Map<IpAddress, BgpPeer> peers; |
| 86 | |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 87 | private BgpConfig bgpConfig; |
| 88 | |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 89 | private List<PointToPointIntent> intentList; |
| 90 | |
| 91 | private final String dpid1 = "00:00:00:00:00:00:00:01"; |
| 92 | private final String dpid2 = "00:00:00:00:00:00:00:02"; |
Luca Prete | 8f2a3ce | 2016-03-29 16:13:01 -0700 | [diff] [blame] | 93 | private final String dpid3 = "00:00:00:00:00:00:00:03"; |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 94 | |
| 95 | private final DeviceId deviceId1 = |
| 96 | DeviceId.deviceId(SdnIp.dpidToUri(dpid1)); |
| 97 | private final DeviceId deviceId2 = |
| 98 | DeviceId.deviceId(SdnIp.dpidToUri(dpid2)); |
Luca Prete | 8f2a3ce | 2016-03-29 16:13:01 -0700 | [diff] [blame] | 99 | private final DeviceId deviceId3 = |
| 100 | DeviceId.deviceId(SdnIp.dpidToUri(dpid3)); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 101 | |
| 102 | // Interfaces connected to BGP speakers |
| 103 | private final ConnectPoint s1Eth100 = |
| 104 | new ConnectPoint(deviceId1, PortNumber.portNumber(100)); |
Luca Prete | 8f2a3ce | 2016-03-29 16:13:01 -0700 | [diff] [blame] | 105 | private final ConnectPoint s2Eth100 = |
| 106 | new ConnectPoint(deviceId2, PortNumber.portNumber(100)); |
| 107 | private final ConnectPoint s3Eth100 = |
| 108 | new ConnectPoint(deviceId3, PortNumber.portNumber(100)); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 109 | |
| 110 | // Interfaces connected to BGP peers |
| 111 | private final ConnectPoint s1Eth1 = |
| 112 | new ConnectPoint(deviceId1, PortNumber.portNumber(1)); |
| 113 | private final ConnectPoint s2Eth1 = |
| 114 | new ConnectPoint(deviceId2, PortNumber.portNumber(1)); |
Luca Prete | 8f2a3ce | 2016-03-29 16:13:01 -0700 | [diff] [blame] | 115 | private final ConnectPoint s3Eth1 = |
| 116 | new ConnectPoint(deviceId3, PortNumber.portNumber(1)); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 117 | |
Luca Prete | 8f2a3ce | 2016-03-29 16:13:01 -0700 | [diff] [blame] | 118 | private static final VlanId NO_VLAN = VlanId.NONE; |
| 119 | private static final VlanId VLAN10 = VlanId.vlanId(Short.valueOf("10")); |
| 120 | private static final VlanId VLAN20 = VlanId.vlanId(Short.valueOf("20")); |
| 121 | private static final VlanId VLAN30 = VlanId.vlanId(Short.valueOf("30")); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 122 | |
| 123 | @Before |
| 124 | public void setUp() throws Exception { |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame] | 125 | super.setUp(); |
Jonathan Hart | b14221c | 2016-03-07 09:55:50 -0800 | [diff] [blame] | 126 | |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 127 | interfaceService = createMock(InterfaceService.class); |
Jonathan Hart | b14221c | 2016-03-07 09:55:50 -0800 | [diff] [blame] | 128 | interfaceService.addListener(anyObject(InterfaceListener.class)); |
| 129 | expectLastCall().anyTimes(); |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 130 | networkConfigService = createMock(NetworkConfigService.class); |
Jonathan Hart | 08105be | 2015-10-10 18:31:06 -0700 | [diff] [blame] | 131 | networkConfigService.addListener(anyObject(NetworkConfigListener.class)); |
| 132 | expectLastCall().anyTimes(); |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 133 | bgpConfig = createMock(BgpConfig.class); |
Jonathan Hart | 90a02c2 | 2015-02-13 11:52:07 -0800 | [diff] [blame] | 134 | |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 135 | // These will set expectations on routingConfig and interfaceService |
| 136 | bgpSpeakers = setUpBgpSpeakers(); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 137 | interfaces = Collections.unmodifiableMap(setUpInterfaces()); |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 138 | peers = setUpPeers(); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 139 | |
| 140 | initPeerConnectivity(); |
| 141 | intentList = setUpIntentList(); |
| 142 | } |
| 143 | |
| 144 | /** |
| 145 | * Sets up BGP speakers. |
| 146 | * |
| 147 | * @return configured BGP speakers as a map from speaker name to speaker |
| 148 | */ |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 149 | private Set<BgpConfig.BgpSpeakerConfig> setUpBgpSpeakers() { |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 150 | |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 151 | BgpConfig.BgpSpeakerConfig speaker1 = new BgpConfig.BgpSpeakerConfig( |
Jonathan Hart | a862548 | 2015-09-08 16:14:56 -0700 | [diff] [blame] | 152 | Optional.empty(), |
Luca Prete | 8f2a3ce | 2016-03-29 16:13:01 -0700 | [diff] [blame] | 153 | NO_VLAN, s1Eth100, |
| 154 | Collections.singleton(IpAddress.valueOf("192.168.10.1"))); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 155 | |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 156 | BgpConfig.BgpSpeakerConfig speaker2 = new BgpConfig.BgpSpeakerConfig( |
Jonathan Hart | a862548 | 2015-09-08 16:14:56 -0700 | [diff] [blame] | 157 | Optional.empty(), |
Luca Prete | 8f2a3ce | 2016-03-29 16:13:01 -0700 | [diff] [blame] | 158 | NO_VLAN, s1Eth100, |
| 159 | Sets.newHashSet(IpAddress.valueOf("192.168.20.1"), |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 160 | IpAddress.valueOf("192.168.30.1"))); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 161 | |
Luca Prete | 8f2a3ce | 2016-03-29 16:13:01 -0700 | [diff] [blame] | 162 | BgpConfig.BgpSpeakerConfig speaker3 = new BgpConfig.BgpSpeakerConfig( |
| 163 | Optional.empty(), |
| 164 | VLAN30, s3Eth100, |
| 165 | Sets.newHashSet(IpAddress.valueOf("192.168.40.1"), |
| 166 | IpAddress.valueOf("192.168.50.1"))); |
| 167 | |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 168 | Set<BgpConfig.BgpSpeakerConfig> bgpSpeakers = Sets.newHashSet(); |
| 169 | bgpSpeakers.add(speaker1); |
| 170 | bgpSpeakers.add(speaker2); |
Luca Prete | 8f2a3ce | 2016-03-29 16:13:01 -0700 | [diff] [blame] | 171 | bgpSpeakers.add(speaker3); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 172 | |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 173 | return bgpSpeakers; |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | /** |
| 177 | * Sets up logical interfaces, which emulate the configured interfaces |
| 178 | * in SDN-IP application. |
| 179 | * |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 180 | * @return configured interfaces as a map from interface name to Interface |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 181 | */ |
| 182 | private Map<String, Interface> setUpInterfaces() { |
| 183 | |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 184 | Map<String, Interface> configuredInterfaces = new HashMap<>(); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 185 | |
| 186 | String interfaceSw1Eth1 = "s1-eth1"; |
Pavlin Radoslavov | 76b0ae2 | 2014-10-27 15:33:19 -0700 | [diff] [blame] | 187 | InterfaceIpAddress ia1 = |
Jonathan Hart | e30fcda | 2015-08-06 16:22:34 -0700 | [diff] [blame] | 188 | new InterfaceIpAddress(IpAddress.valueOf("192.168.10.101"), |
Pavlin Radoslavov | 76b0ae2 | 2014-10-27 15:33:19 -0700 | [diff] [blame] | 189 | IpPrefix.valueOf("192.168.10.0/24")); |
Jonathan Hart | b14221c | 2016-03-07 09:55:50 -0800 | [diff] [blame] | 190 | Interface intfsw1eth1 = new Interface(interfaceSw1Eth1, s1Eth1, |
Jonathan Hart | 00cddda | 2016-02-16 10:30:37 -0800 | [diff] [blame] | 191 | Collections.singletonList(ia1), |
Jonathan Hart | 6cd2f35 | 2015-01-13 17:44:45 -0800 | [diff] [blame] | 192 | MacAddress.valueOf("00:00:00:00:00:01"), |
| 193 | VlanId.NONE); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 194 | |
| 195 | configuredInterfaces.put(interfaceSw1Eth1, intfsw1eth1); |
Luca Prete | 8f2a3ce | 2016-03-29 16:13:01 -0700 | [diff] [blame] | 196 | |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 197 | String interfaceSw2Eth1 = "s2-eth1"; |
Pavlin Radoslavov | 76b0ae2 | 2014-10-27 15:33:19 -0700 | [diff] [blame] | 198 | InterfaceIpAddress ia2 = |
Jonathan Hart | e30fcda | 2015-08-06 16:22:34 -0700 | [diff] [blame] | 199 | new InterfaceIpAddress(IpAddress.valueOf("192.168.20.101"), |
Pavlin Radoslavov | 76b0ae2 | 2014-10-27 15:33:19 -0700 | [diff] [blame] | 200 | IpPrefix.valueOf("192.168.20.0/24")); |
Jonathan Hart | b14221c | 2016-03-07 09:55:50 -0800 | [diff] [blame] | 201 | Interface intfsw2eth1 = new Interface(interfaceSw2Eth1, s2Eth1, |
Jonathan Hart | 00cddda | 2016-02-16 10:30:37 -0800 | [diff] [blame] | 202 | Collections.singletonList(ia2), |
Jonathan Hart | 6cd2f35 | 2015-01-13 17:44:45 -0800 | [diff] [blame] | 203 | MacAddress.valueOf("00:00:00:00:00:02"), |
| 204 | VlanId.NONE); |
Luca Prete | 8f2a3ce | 2016-03-29 16:13:01 -0700 | [diff] [blame] | 205 | |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 206 | configuredInterfaces.put(interfaceSw2Eth1, intfsw2eth1); |
| 207 | |
Jonathan Hart | e30fcda | 2015-08-06 16:22:34 -0700 | [diff] [blame] | 208 | String interfaceSw2Eth1intf2 = "s2-eth1_2"; |
| 209 | InterfaceIpAddress ia3 = |
| 210 | new InterfaceIpAddress(IpAddress.valueOf("192.168.30.101"), |
| 211 | IpPrefix.valueOf("192.168.30.0/24")); |
Jonathan Hart | b14221c | 2016-03-07 09:55:50 -0800 | [diff] [blame] | 212 | Interface intfsw2eth1intf2 = new Interface(interfaceSw2Eth1intf2, s2Eth1, |
Jonathan Hart | 00cddda | 2016-02-16 10:30:37 -0800 | [diff] [blame] | 213 | Collections.singletonList(ia3), |
Jonathan Hart | e30fcda | 2015-08-06 16:22:34 -0700 | [diff] [blame] | 214 | MacAddress.valueOf("00:00:00:00:00:03"), |
| 215 | VlanId.NONE); |
Luca Prete | 8f2a3ce | 2016-03-29 16:13:01 -0700 | [diff] [blame] | 216 | |
Jonathan Hart | e30fcda | 2015-08-06 16:22:34 -0700 | [diff] [blame] | 217 | configuredInterfaces.put(interfaceSw2Eth1intf2, intfsw2eth1intf2); |
| 218 | |
Luca Prete | 8f2a3ce | 2016-03-29 16:13:01 -0700 | [diff] [blame] | 219 | String interfaceSw3Eth1 = "s3-eth1"; |
| 220 | InterfaceIpAddress ia4 = |
| 221 | new InterfaceIpAddress(IpAddress.valueOf("192.168.40.101"), |
| 222 | IpPrefix.valueOf("192.168.40.0/24")); |
| 223 | Interface intfsw3eth1 = new Interface(s3Eth1, |
| 224 | Collections.singleton(ia4), |
| 225 | MacAddress.valueOf("00:00:00:00:00:04"), |
| 226 | VLAN10); |
| 227 | |
| 228 | configuredInterfaces.put(interfaceSw3Eth1, intfsw3eth1); |
| 229 | |
| 230 | String interfaceSw3Eth1intf2 = "s3-eth1_2"; |
| 231 | InterfaceIpAddress ia5 = |
| 232 | new InterfaceIpAddress(IpAddress.valueOf("192.168.50.101"), |
| 233 | IpPrefix.valueOf("192.168.50.0/24")); |
| 234 | Interface intfsw3eth1intf2 = new Interface(s3Eth1, |
| 235 | Collections.singleton(ia5), |
| 236 | MacAddress.valueOf("00:00:00:00:00:05"), |
| 237 | VLAN20); |
| 238 | |
| 239 | configuredInterfaces.put(interfaceSw3Eth1intf2, intfsw3eth1intf2); |
| 240 | |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 241 | expect(interfaceService.getInterfacesByPort(s1Eth1)) |
| 242 | .andReturn(Collections.singleton(intfsw1eth1)).anyTimes(); |
| 243 | expect(interfaceService.getInterfacesByIp(IpAddress.valueOf("192.168.10.101"))) |
| 244 | .andReturn(Collections.singleton(intfsw1eth1)).anyTimes(); |
| 245 | expect(interfaceService.getMatchingInterface(IpAddress.valueOf("192.168.10.1"))) |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 246 | .andReturn(intfsw1eth1).anyTimes(); |
Luca Prete | 8f2a3ce | 2016-03-29 16:13:01 -0700 | [diff] [blame] | 247 | |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 248 | expect(interfaceService.getInterfacesByPort(s2Eth1)) |
| 249 | .andReturn(Collections.singleton(intfsw2eth1)).anyTimes(); |
| 250 | expect(interfaceService.getInterfacesByIp(IpAddress.valueOf("192.168.20.101"))) |
| 251 | .andReturn(Collections.singleton(intfsw2eth1)).anyTimes(); |
| 252 | expect(interfaceService.getMatchingInterface(IpAddress.valueOf("192.168.20.1"))) |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 253 | .andReturn(intfsw2eth1).anyTimes(); |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 254 | |
| 255 | expect(interfaceService.getInterfacesByIp(IpAddress.valueOf("192.168.30.101"))) |
| 256 | .andReturn(Collections.singleton(intfsw2eth1intf2)).anyTimes(); |
| 257 | expect(interfaceService.getMatchingInterface(IpAddress.valueOf("192.168.30.1"))) |
Jonathan Hart | e30fcda | 2015-08-06 16:22:34 -0700 | [diff] [blame] | 258 | .andReturn(intfsw2eth1intf2).anyTimes(); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 259 | |
Luca Prete | 8f2a3ce | 2016-03-29 16:13:01 -0700 | [diff] [blame] | 260 | expect(interfaceService.getInterfacesByIp(IpAddress.valueOf("192.168.40.101"))) |
| 261 | .andReturn(Collections.singleton(intfsw3eth1)).anyTimes(); |
| 262 | expect(interfaceService.getMatchingInterface(IpAddress.valueOf("192.168.40.1"))) |
| 263 | .andReturn(intfsw3eth1).anyTimes(); |
| 264 | |
| 265 | expect(interfaceService.getInterfacesByIp(IpAddress.valueOf("192.168.50.101"))) |
| 266 | .andReturn(Collections.singleton(intfsw3eth1intf2)).anyTimes(); |
| 267 | expect(interfaceService.getMatchingInterface(IpAddress.valueOf("192.168.50.1"))) |
| 268 | .andReturn(intfsw3eth1intf2).anyTimes(); |
| 269 | |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 270 | // Non-existent interface used during one of the tests |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 271 | expect(interfaceService.getInterfacesByPort(new ConnectPoint( |
| 272 | DeviceId.deviceId(SdnIp.dpidToUri("00:00:00:00:00:00:01:00")), |
| 273 | PortNumber.portNumber(1)))) |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 274 | .andReturn(null).anyTimes(); |
| 275 | |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 276 | expect(interfaceService.getInterfaces()).andReturn( |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 277 | Sets.newHashSet(configuredInterfaces.values())).anyTimes(); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 278 | |
| 279 | return configuredInterfaces; |
| 280 | } |
| 281 | |
| 282 | /** |
| 283 | * Sets up BGP daemon peers. |
| 284 | * |
| 285 | * @return configured BGP peers as a MAP from peer IP address to BgpPeer |
| 286 | */ |
| 287 | private Map<IpAddress, BgpPeer> setUpPeers() { |
| 288 | |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 289 | Map<IpAddress, BgpPeer> configuredPeers = new HashMap<>(); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 290 | |
| 291 | String peerSw1Eth1 = "192.168.10.1"; |
| 292 | configuredPeers.put(IpAddress.valueOf(peerSw1Eth1), |
| 293 | new BgpPeer(dpid1, 1, peerSw1Eth1)); |
| 294 | |
| 295 | // Two BGP peers are connected to switch 2 port 1. |
| 296 | String peer1Sw2Eth1 = "192.168.20.1"; |
| 297 | configuredPeers.put(IpAddress.valueOf(peer1Sw2Eth1), |
| 298 | new BgpPeer(dpid2, 1, peer1Sw2Eth1)); |
| 299 | |
Jonathan Hart | e30fcda | 2015-08-06 16:22:34 -0700 | [diff] [blame] | 300 | String peer2Sw2Eth1 = "192.168.30.1"; |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 301 | configuredPeers.put(IpAddress.valueOf(peer2Sw2Eth1), |
| 302 | new BgpPeer(dpid2, 1, peer2Sw2Eth1)); |
| 303 | |
Luca Prete | 8f2a3ce | 2016-03-29 16:13:01 -0700 | [diff] [blame] | 304 | String peer3Sw3Eth1 = "192.168.40.1"; |
| 305 | configuredPeers.put(IpAddress.valueOf(peer3Sw3Eth1), |
| 306 | new BgpPeer(dpid3, 1, peer3Sw3Eth1)); |
| 307 | |
| 308 | String peer4Sw3Eth1 = "192.168.50.1"; |
| 309 | configuredPeers.put(IpAddress.valueOf(peer4Sw3Eth1), |
| 310 | new BgpPeer(dpid3, 1, peer4Sw3Eth1)); |
| 311 | |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 312 | return configuredPeers; |
| 313 | } |
| 314 | |
| 315 | /** |
| 316 | * Sets up expected point to point intent list. |
| 317 | * |
| 318 | * @return point to point intent list |
| 319 | */ |
| 320 | private List<PointToPointIntent> setUpIntentList() { |
Jonathan Hart | 90a02c2 | 2015-02-13 11:52:07 -0800 | [diff] [blame] | 321 | intentList = new ArrayList<>(); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 322 | |
| 323 | setUpBgpIntents(); |
| 324 | setUpIcmpIntents(); |
| 325 | |
| 326 | return intentList; |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | /** |
| 330 | * Constructs a BGP intent and put it into the intentList. |
| 331 | * <p/> |
| 332 | * The purpose of this method is too simplify the setUpBgpIntents() method, |
| 333 | * and to make the setUpBgpIntents() easy to read. |
| 334 | * |
Luca Prete | 8f2a3ce | 2016-03-29 16:13:01 -0700 | [diff] [blame] | 335 | * @param srcVlanId ingress VlanId |
| 336 | * @param dstVlanId egress VlanId |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 337 | * @param srcPrefix source IP prefix to match |
| 338 | * @param dstPrefix destination IP prefix to match |
| 339 | * @param srcTcpPort source TCP port to match |
| 340 | * @param dstTcpPort destination TCP port to match |
| 341 | * @param srcConnectPoint source connect point for PointToPointIntent |
| 342 | * @param dstConnectPoint destination connect point for PointToPointIntent |
| 343 | */ |
Luca Prete | 8f2a3ce | 2016-03-29 16:13:01 -0700 | [diff] [blame] | 344 | private void bgpPathintentConstructor(VlanId srcVlanId, VlanId dstVlanId, |
| 345 | String srcPrefix, String dstPrefix, |
| 346 | Short srcTcpPort, Short dstTcpPort, |
| 347 | ConnectPoint srcConnectPoint, |
| 348 | ConnectPoint dstConnectPoint) { |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 349 | |
| 350 | TrafficSelector.Builder builder = DefaultTrafficSelector.builder() |
| 351 | .matchEthType(Ethernet.TYPE_IPV4) |
| 352 | .matchIPProtocol(IPv4.PROTOCOL_TCP) |
| 353 | .matchIPSrc(IpPrefix.valueOf(srcPrefix)) |
| 354 | .matchIPDst(IpPrefix.valueOf(dstPrefix)); |
| 355 | |
Luca Prete | 8f2a3ce | 2016-03-29 16:13:01 -0700 | [diff] [blame] | 356 | if (!srcVlanId.equals(VlanId.NONE)) { |
| 357 | builder.matchVlanId(VlanId.ANY); |
| 358 | } |
| 359 | |
| 360 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
| 361 | |
| 362 | if (!dstVlanId.equals(VlanId.NONE)) { |
| 363 | treatment.setVlanId(dstVlanId); |
| 364 | } |
| 365 | |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 366 | if (srcTcpPort != null) { |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 367 | builder.matchTcpSrc(TpPort.tpPort(srcTcpPort)); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 368 | } |
| 369 | if (dstTcpPort != null) { |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 370 | builder.matchTcpDst(TpPort.tpPort(dstTcpPort)); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 371 | } |
| 372 | |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 373 | Key key = Key.of(srcPrefix.split("/")[0] + "-" + dstPrefix.split("/")[0] |
| 374 | + "-" + ((srcTcpPort == null) ? "dst" : "src"), APPID); |
| 375 | |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 376 | PointToPointIntent intent = PointToPointIntent.builder() |
| 377 | .appId(APPID) |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 378 | .key(key) |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 379 | .selector(builder.build()) |
Luca Prete | 8f2a3ce | 2016-03-29 16:13:01 -0700 | [diff] [blame] | 380 | .treatment(treatment.build()) |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 381 | .ingressPoint(srcConnectPoint) |
| 382 | .egressPoint(dstConnectPoint) |
| 383 | .build(); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 384 | |
| 385 | intentList.add(intent); |
| 386 | } |
| 387 | |
| 388 | /** |
| 389 | * Sets up intents for BGP paths. |
| 390 | */ |
| 391 | private void setUpBgpIntents() { |
| 392 | |
Jonathan Hart | 41349e9 | 2015-02-09 14:14:02 -0800 | [diff] [blame] | 393 | Short bgpPort = 179; |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 394 | |
| 395 | // Start to build intents between BGP speaker1 and BGP peer1 |
| 396 | bgpPathintentConstructor( |
Luca Prete | 8f2a3ce | 2016-03-29 16:13:01 -0700 | [diff] [blame] | 397 | NO_VLAN, NO_VLAN, |
| 398 | "192.168.10.101/32", "192.168.10.1/32", |
| 399 | null, bgpPort, |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 400 | s1Eth100, s1Eth1); |
| 401 | bgpPathintentConstructor( |
Luca Prete | 8f2a3ce | 2016-03-29 16:13:01 -0700 | [diff] [blame] | 402 | NO_VLAN, NO_VLAN, |
| 403 | "192.168.10.101/32", "192.168.10.1/32", |
| 404 | bgpPort, null, |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 405 | s1Eth100, s1Eth1); |
| 406 | |
| 407 | bgpPathintentConstructor( |
Luca Prete | 8f2a3ce | 2016-03-29 16:13:01 -0700 | [diff] [blame] | 408 | NO_VLAN, NO_VLAN, |
| 409 | "192.168.10.1/32", "192.168.10.101/32", |
| 410 | null, bgpPort, |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 411 | s1Eth1, s1Eth100); |
| 412 | bgpPathintentConstructor( |
Luca Prete | 8f2a3ce | 2016-03-29 16:13:01 -0700 | [diff] [blame] | 413 | NO_VLAN, NO_VLAN, |
| 414 | "192.168.10.1/32", "192.168.10.101/32", |
| 415 | bgpPort, null, |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 416 | s1Eth1, s1Eth100); |
| 417 | |
| 418 | // Start to build intents between BGP speaker1 and BGP peer2 |
| 419 | bgpPathintentConstructor( |
Luca Prete | 8f2a3ce | 2016-03-29 16:13:01 -0700 | [diff] [blame] | 420 | NO_VLAN, NO_VLAN, |
| 421 | "192.168.20.101/32", "192.168.20.1/32", |
| 422 | null, bgpPort, |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 423 | s1Eth100, s2Eth1); |
| 424 | bgpPathintentConstructor( |
Luca Prete | 8f2a3ce | 2016-03-29 16:13:01 -0700 | [diff] [blame] | 425 | NO_VLAN, NO_VLAN, |
| 426 | "192.168.20.101/32", "192.168.20.1/32", |
| 427 | bgpPort, null, |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 428 | s1Eth100, s2Eth1); |
| 429 | |
| 430 | bgpPathintentConstructor( |
Luca Prete | 8f2a3ce | 2016-03-29 16:13:01 -0700 | [diff] [blame] | 431 | NO_VLAN, NO_VLAN, |
| 432 | "192.168.20.1/32", "192.168.20.101/32", |
| 433 | null, bgpPort, |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 434 | s2Eth1, s1Eth100); |
| 435 | bgpPathintentConstructor( |
Luca Prete | 8f2a3ce | 2016-03-29 16:13:01 -0700 | [diff] [blame] | 436 | NO_VLAN, NO_VLAN, |
| 437 | "192.168.20.1/32", "192.168.20.101/32", |
| 438 | bgpPort, null, |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 439 | s2Eth1, s1Eth100); |
| 440 | |
Luca Prete | 8f2a3ce | 2016-03-29 16:13:01 -0700 | [diff] [blame] | 441 | // Start to build intents between BGP speaker2 and BGP peer1 |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 442 | bgpPathintentConstructor( |
Luca Prete | 8f2a3ce | 2016-03-29 16:13:01 -0700 | [diff] [blame] | 443 | NO_VLAN, NO_VLAN, |
| 444 | "192.168.30.101/32", "192.168.30.1/32", |
| 445 | null, bgpPort, |
Jonathan Hart | e30fcda | 2015-08-06 16:22:34 -0700 | [diff] [blame] | 446 | s1Eth100, s2Eth1); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 447 | bgpPathintentConstructor( |
Luca Prete | 8f2a3ce | 2016-03-29 16:13:01 -0700 | [diff] [blame] | 448 | NO_VLAN, NO_VLAN, |
| 449 | "192.168.30.101/32", "192.168.30.1/32", |
| 450 | bgpPort, null, |
Jonathan Hart | e30fcda | 2015-08-06 16:22:34 -0700 | [diff] [blame] | 451 | s1Eth100, s2Eth1); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 452 | |
| 453 | bgpPathintentConstructor( |
Luca Prete | 8f2a3ce | 2016-03-29 16:13:01 -0700 | [diff] [blame] | 454 | NO_VLAN, NO_VLAN, |
| 455 | "192.168.30.1/32", "192.168.30.101/32", |
| 456 | null, bgpPort, |
Jonathan Hart | e30fcda | 2015-08-06 16:22:34 -0700 | [diff] [blame] | 457 | s2Eth1, s1Eth100); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 458 | bgpPathintentConstructor( |
Luca Prete | 8f2a3ce | 2016-03-29 16:13:01 -0700 | [diff] [blame] | 459 | NO_VLAN, NO_VLAN, |
| 460 | "192.168.30.1/32", "192.168.30.101/32", |
| 461 | bgpPort, null, |
Jonathan Hart | e30fcda | 2015-08-06 16:22:34 -0700 | [diff] [blame] | 462 | s2Eth1, s1Eth100); |
Luca Prete | 8f2a3ce | 2016-03-29 16:13:01 -0700 | [diff] [blame] | 463 | |
| 464 | // Start to build intents between BGP speaker3 and BGP peer4 |
| 465 | bgpPathintentConstructor( |
| 466 | VLAN30, VLAN10, |
| 467 | "192.168.40.101/32", "192.168.40.1/32", |
| 468 | null, bgpPort, |
| 469 | s3Eth100, s3Eth1); |
| 470 | bgpPathintentConstructor( |
| 471 | VLAN30, VLAN10, |
| 472 | "192.168.40.101/32", "192.168.40.1/32", |
| 473 | bgpPort, null, |
| 474 | s3Eth100, s3Eth1); |
| 475 | |
| 476 | bgpPathintentConstructor( |
| 477 | VLAN10, VLAN30, |
| 478 | "192.168.40.1/32", "192.168.40.101/32", |
| 479 | null, bgpPort, |
| 480 | s3Eth1, s3Eth100); |
| 481 | bgpPathintentConstructor( |
| 482 | VLAN10, VLAN30, |
| 483 | "192.168.40.1/32", "192.168.40.101/32", |
| 484 | bgpPort, null, |
| 485 | s3Eth1, s3Eth100); |
| 486 | |
| 487 | // Start to build intents between BGP speaker3 and BGP peer5 |
| 488 | bgpPathintentConstructor( |
| 489 | VLAN30, VLAN20, |
| 490 | "192.168.50.101/32", "192.168.50.1/32", |
| 491 | null, bgpPort, |
| 492 | s3Eth100, s3Eth1); |
| 493 | bgpPathintentConstructor( |
| 494 | VLAN30, VLAN20, |
| 495 | "192.168.50.101/32", "192.168.50.1/32", |
| 496 | bgpPort, null, |
| 497 | s3Eth100, s3Eth1); |
| 498 | |
| 499 | bgpPathintentConstructor( |
| 500 | VLAN20, VLAN30, |
| 501 | "192.168.50.1/32", "192.168.50.101/32", |
| 502 | null, bgpPort, |
| 503 | s3Eth1, s3Eth100); |
| 504 | bgpPathintentConstructor( |
| 505 | VLAN20, VLAN30, |
| 506 | "192.168.50.1/32", "192.168.50.101/32", |
| 507 | bgpPort, null, |
| 508 | s3Eth1, s3Eth100); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | /** |
| 512 | * Constructs a BGP intent and put it into the intentList. |
| 513 | * <p/> |
| 514 | * The purpose of this method is too simplify the setUpBgpIntents() method, |
| 515 | * and to make the setUpBgpIntents() easy to read. |
| 516 | * |
Luca Prete | 8f2a3ce | 2016-03-29 16:13:01 -0700 | [diff] [blame] | 517 | * @param srcVlanId ingress VlanId |
| 518 | * @param dstVlanId egress VlanId |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 519 | * @param srcPrefix source IP prefix to match |
| 520 | * @param dstPrefix destination IP prefix to match |
| 521 | * @param srcConnectPoint source connect point for PointToPointIntent |
| 522 | * @param dstConnectPoint destination connect point for PointToPointIntent |
| 523 | */ |
Luca Prete | 8f2a3ce | 2016-03-29 16:13:01 -0700 | [diff] [blame] | 524 | private void icmpPathintentConstructor(VlanId srcVlanId, VlanId dstVlanId, |
| 525 | String srcPrefix, String dstPrefix, |
| 526 | ConnectPoint srcConnectPoint, |
| 527 | ConnectPoint dstConnectPoint) { |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 528 | |
Luca Prete | 8f2a3ce | 2016-03-29 16:13:01 -0700 | [diff] [blame] | 529 | TrafficSelector.Builder builder = DefaultTrafficSelector.builder() |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 530 | .matchEthType(Ethernet.TYPE_IPV4) |
| 531 | .matchIPProtocol(IPv4.PROTOCOL_ICMP) |
| 532 | .matchIPSrc(IpPrefix.valueOf(srcPrefix)) |
Luca Prete | 8f2a3ce | 2016-03-29 16:13:01 -0700 | [diff] [blame] | 533 | .matchIPDst(IpPrefix.valueOf(dstPrefix)); |
| 534 | |
| 535 | if (!srcVlanId.equals(VlanId.NONE)) { |
| 536 | builder.matchVlanId(VlanId.ANY); |
| 537 | } |
| 538 | |
| 539 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
| 540 | |
| 541 | if (!dstVlanId.equals(VlanId.NONE)) { |
| 542 | treatment.setVlanId(dstVlanId); |
| 543 | } |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 544 | |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 545 | Key key = Key.of(srcPrefix.split("/")[0] + "-" + dstPrefix.split("/")[0] |
| 546 | + "-" + "icmp", APPID); |
| 547 | |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 548 | PointToPointIntent intent = PointToPointIntent.builder() |
| 549 | .appId(APPID) |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 550 | .key(key) |
Luca Prete | 8f2a3ce | 2016-03-29 16:13:01 -0700 | [diff] [blame] | 551 | .selector(builder.build()) |
| 552 | .treatment(treatment.build()) |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 553 | .ingressPoint(srcConnectPoint) |
| 554 | .egressPoint(dstConnectPoint) |
| 555 | .build(); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 556 | |
| 557 | intentList.add(intent); |
| 558 | } |
| 559 | |
| 560 | /** |
| 561 | * Sets up intents for ICMP paths. |
| 562 | */ |
| 563 | private void setUpIcmpIntents() { |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 564 | // Start to build intents between BGP speaker1 and BGP peer1 |
| 565 | icmpPathintentConstructor( |
Luca Prete | 8f2a3ce | 2016-03-29 16:13:01 -0700 | [diff] [blame] | 566 | NO_VLAN, NO_VLAN, |
| 567 | "192.168.10.101/32", "192.168.10.1/32", |
| 568 | s1Eth100, s1Eth1); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 569 | icmpPathintentConstructor( |
Luca Prete | 8f2a3ce | 2016-03-29 16:13:01 -0700 | [diff] [blame] | 570 | NO_VLAN, NO_VLAN, |
| 571 | "192.168.10.1/32", "192.168.10.101/32", |
| 572 | s1Eth1, s1Eth100); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 573 | |
| 574 | // Start to build intents between BGP speaker1 and BGP peer2 |
| 575 | icmpPathintentConstructor( |
Luca Prete | 8f2a3ce | 2016-03-29 16:13:01 -0700 | [diff] [blame] | 576 | NO_VLAN, NO_VLAN, |
| 577 | "192.168.20.101/32", "192.168.20.1/32", |
| 578 | s1Eth100, s2Eth1); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 579 | icmpPathintentConstructor( |
Luca Prete | 8f2a3ce | 2016-03-29 16:13:01 -0700 | [diff] [blame] | 580 | NO_VLAN, NO_VLAN, |
| 581 | "192.168.20.1/32", "192.168.20.101/32", |
| 582 | s2Eth1, s1Eth100); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 583 | |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 584 | icmpPathintentConstructor( |
Luca Prete | 8f2a3ce | 2016-03-29 16:13:01 -0700 | [diff] [blame] | 585 | NO_VLAN, NO_VLAN, |
| 586 | "192.168.30.101/32", "192.168.30.1/32", |
| 587 | s1Eth100, s2Eth1); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 588 | icmpPathintentConstructor( |
Luca Prete | 8f2a3ce | 2016-03-29 16:13:01 -0700 | [diff] [blame] | 589 | NO_VLAN, NO_VLAN, |
| 590 | "192.168.30.1/32", "192.168.30.101/32", |
| 591 | s2Eth1, s1Eth100); |
| 592 | |
| 593 | // Start to build intents between BGP speaker3 and BGP peer 4 |
| 594 | icmpPathintentConstructor( |
| 595 | VLAN10, VLAN30, |
| 596 | "192.168.40.1/32", "192.168.40.101/32", |
| 597 | s3Eth1, s3Eth100); |
| 598 | icmpPathintentConstructor( |
| 599 | VLAN30, VLAN10, |
| 600 | "192.168.40.101/32", "192.168.40.1/32", |
| 601 | s3Eth100, s3Eth1); |
| 602 | |
| 603 | // Start to build intents between BGP speaker3 and BGP peer 5 |
| 604 | icmpPathintentConstructor( |
| 605 | VLAN20, VLAN30, |
| 606 | "192.168.50.1/32", "192.168.50.101/32", |
| 607 | s3Eth1, s3Eth100); |
| 608 | icmpPathintentConstructor( |
| 609 | VLAN30, VLAN20, |
| 610 | "192.168.50.101/32", "192.168.50.1/32", |
| 611 | s3Eth100, s3Eth1); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | /** |
| 615 | * Initializes peer connectivity testing environment. |
Pavlin Radoslavov | a7243cc | 2014-11-22 21:38:02 -0800 | [diff] [blame] | 616 | * |
| 617 | * @throws TestUtilsException if exceptions when using TestUtils |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 618 | */ |
Pavlin Radoslavov | a7243cc | 2014-11-22 21:38:02 -0800 | [diff] [blame] | 619 | private void initPeerConnectivity() throws TestUtilsException { |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 620 | expect(bgpConfig.bgpSpeakers()).andReturn(bgpSpeakers).anyTimes(); |
| 621 | replay(bgpConfig); |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 622 | expect(networkConfigService.getConfig(APPID, BgpConfig.class)) |
| 623 | .andReturn(bgpConfig).anyTimes(); |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 624 | replay(networkConfigService); |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 625 | replay(interfaceService); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 626 | |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 627 | intentSynchronizer = createMock(IntentSynchronizationService.class); |
| 628 | replay(intentSynchronizer); |
Pavlin Radoslavov | a7243cc | 2014-11-22 21:38:02 -0800 | [diff] [blame] | 629 | |
| 630 | peerConnectivityManager = |
| 631 | new PeerConnectivityManager(APPID, intentSynchronizer, |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 632 | networkConfigService, |
| 633 | CONFIG_APP_ID, |
| 634 | interfaceService); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 635 | } |
| 636 | |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 637 | /** |
| 638 | * Tests whether peer connectivity manager can set up correct BGP and |
| 639 | * ICMP intents according to specific configuration. |
| 640 | * <p/> |
| 641 | * Two tricky cases included in the configuration are: 2 peers on a same |
| 642 | * switch port, peer on the same switch with BGPd. |
| 643 | */ |
| 644 | @Test |
| 645 | public void testConnectionSetup() { |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 646 | reset(intentSynchronizer); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 647 | |
Pavlin Radoslavov | dde22ae | 2014-11-24 11:47:17 -0800 | [diff] [blame] | 648 | // Setup the expected intents |
Pavlin Radoslavov | dde22ae | 2014-11-24 11:47:17 -0800 | [diff] [blame] | 649 | for (Intent intent : intentList) { |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 650 | intentSynchronizer.submit(eqExceptId(intent)); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 651 | } |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 652 | replay(intentSynchronizer); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 653 | |
| 654 | // Running the interface to be tested. |
| 655 | peerConnectivityManager.start(); |
| 656 | |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 657 | verify(intentSynchronizer); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 658 | } |
| 659 | |
| 660 | /** |
| 661 | * Tests a corner case, when there are no interfaces in the configuration. |
| 662 | */ |
| 663 | @Test |
| 664 | public void testNullInterfaces() { |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 665 | reset(interfaceService); |
Jonathan Hart | b14221c | 2016-03-07 09:55:50 -0800 | [diff] [blame] | 666 | interfaceService.addListener(anyObject(InterfaceListener.class)); |
| 667 | expectLastCall().anyTimes(); |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 668 | |
| 669 | expect(interfaceService.getInterfaces()).andReturn( |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 670 | Sets.newHashSet()).anyTimes(); |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 671 | expect(interfaceService.getInterfacesByPort(s2Eth1)) |
| 672 | .andReturn(Collections.emptySet()).anyTimes(); |
| 673 | expect(interfaceService.getInterfacesByPort(s1Eth1)) |
| 674 | .andReturn(Collections.emptySet()).anyTimes(); |
| 675 | expect(interfaceService.getInterfacesByIp(IpAddress.valueOf("192.168.10.101"))) |
| 676 | .andReturn(Collections.emptySet()).anyTimes(); |
| 677 | expect(interfaceService.getMatchingInterface(IpAddress.valueOf("192.168.10.1"))) |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 678 | .andReturn(null).anyTimes(); |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 679 | expect(interfaceService.getInterfacesByIp(IpAddress.valueOf("192.168.20.101"))) |
| 680 | .andReturn(Collections.emptySet()).anyTimes(); |
| 681 | expect(interfaceService.getMatchingInterface(IpAddress.valueOf("192.168.20.1"))) |
Jonathan Hart | e30fcda | 2015-08-06 16:22:34 -0700 | [diff] [blame] | 682 | .andReturn(null).anyTimes(); |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 683 | expect(interfaceService.getInterfacesByIp(IpAddress.valueOf("192.168.30.101"))) |
| 684 | .andReturn(Collections.emptySet()).anyTimes(); |
| 685 | expect(interfaceService.getMatchingInterface(IpAddress.valueOf("192.168.30.1"))) |
Jonathan Hart | e30fcda | 2015-08-06 16:22:34 -0700 | [diff] [blame] | 686 | .andReturn(null).anyTimes(); |
Luca Prete | 8f2a3ce | 2016-03-29 16:13:01 -0700 | [diff] [blame] | 687 | expect(interfaceService.getInterfacesByIp(IpAddress.valueOf("192.168.40.101"))) |
| 688 | .andReturn(Collections.emptySet()).anyTimes(); |
| 689 | expect(interfaceService.getMatchingInterface(IpAddress.valueOf("192.168.40.1"))) |
| 690 | .andReturn(null).anyTimes(); |
| 691 | expect(interfaceService.getInterfacesByIp(IpAddress.valueOf("192.168.50.101"))) |
| 692 | .andReturn(Collections.emptySet()).anyTimes(); |
| 693 | expect(interfaceService.getMatchingInterface(IpAddress.valueOf("192.168.50.1"))) |
| 694 | .andReturn(null).anyTimes(); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 695 | |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 696 | replay(interfaceService); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 697 | |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 698 | reset(intentSynchronizer); |
| 699 | replay(intentSynchronizer); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 700 | peerConnectivityManager.start(); |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 701 | verify(intentSynchronizer); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 702 | } |
| 703 | |
| 704 | /** |
| 705 | * Tests a corner case, when there is no BGP speakers in the configuration. |
| 706 | */ |
| 707 | @Test |
| 708 | public void testNullBgpSpeakers() { |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 709 | reset(bgpConfig); |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 710 | expect(bgpConfig.bgpSpeakers()).andReturn(Collections.emptySet()).anyTimes(); |
| 711 | replay(bgpConfig); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 712 | |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 713 | reset(intentSynchronizer); |
| 714 | replay(intentSynchronizer); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 715 | peerConnectivityManager.start(); |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 716 | verify(intentSynchronizer); |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | /** |
| 720 | * Tests a corner case, when there is no Interface configured for one BGP |
| 721 | * peer. |
| 722 | */ |
| 723 | @Test |
| 724 | public void testNoPeerInterface() { |
| 725 | String peerSw100Eth1 = "192.168.200.1"; |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 726 | peers.put(IpAddress.valueOf(peerSw100Eth1), |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 727 | new BgpPeer("00:00:00:00:00:00:01:00", 1, peerSw100Eth1)); |
| 728 | testConnectionSetup(); |
| 729 | } |
| 730 | |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 731 | } |