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