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