Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 1 | /* |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 2 | * Copyright 2014 Open Networking Laboratory |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 15 | */ |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 16 | package org.onlab.onos.sdnip; |
| 17 | |
Jonathan Hart | 31582d1 | 2014-10-22 13:52:41 -0700 | [diff] [blame] | 18 | import static org.easymock.EasyMock.anyObject; |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 19 | import static org.easymock.EasyMock.createMock; |
| 20 | import static org.easymock.EasyMock.expect; |
Jonathan Hart | 31582d1 | 2014-10-22 13:52:41 -0700 | [diff] [blame] | 21 | import static org.easymock.EasyMock.expectLastCall; |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 22 | import static org.easymock.EasyMock.replay; |
| 23 | import static org.easymock.EasyMock.reset; |
| 24 | import static org.easymock.EasyMock.verify; |
| 25 | import static org.junit.Assert.assertEquals; |
| 26 | import static org.junit.Assert.assertTrue; |
| 27 | |
| 28 | import java.util.HashMap; |
| 29 | import java.util.HashSet; |
| 30 | import java.util.Map; |
| 31 | import java.util.Set; |
| 32 | |
| 33 | import org.junit.Before; |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame^] | 34 | import org.junit.Ignore; |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 35 | import org.junit.Test; |
Pavlin Radoslavov | d26f57a | 2014-10-23 17:19:45 -0700 | [diff] [blame] | 36 | import org.onlab.junit.TestUtils; |
| 37 | import org.onlab.junit.TestUtils.TestUtilsException; |
Thomas Vachuska | e0f804a | 2014-10-27 23:40:48 -0700 | [diff] [blame] | 38 | import org.onlab.onos.core.ApplicationId; |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 39 | import org.onlab.onos.net.ConnectPoint; |
| 40 | import org.onlab.onos.net.DefaultHost; |
| 41 | import org.onlab.onos.net.DeviceId; |
| 42 | import org.onlab.onos.net.Host; |
| 43 | import org.onlab.onos.net.HostId; |
| 44 | import org.onlab.onos.net.HostLocation; |
| 45 | import org.onlab.onos.net.PortNumber; |
| 46 | import org.onlab.onos.net.flow.DefaultTrafficSelector; |
| 47 | import org.onlab.onos.net.flow.DefaultTrafficTreatment; |
| 48 | import org.onlab.onos.net.flow.TrafficSelector; |
| 49 | import org.onlab.onos.net.flow.TrafficTreatment; |
Jonathan Hart | 31582d1 | 2014-10-22 13:52:41 -0700 | [diff] [blame] | 50 | import org.onlab.onos.net.host.HostListener; |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 51 | import org.onlab.onos.net.host.HostService; |
Pavlin Radoslavov | 76b0ae2 | 2014-10-27 15:33:19 -0700 | [diff] [blame] | 52 | import org.onlab.onos.net.host.InterfaceIpAddress; |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 53 | import org.onlab.onos.net.intent.IntentService; |
| 54 | import org.onlab.onos.net.intent.MultiPointToSinglePointIntent; |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame^] | 55 | import org.onlab.onos.net.intent.AbstractIntentTest; |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 56 | import org.onlab.onos.net.provider.ProviderId; |
| 57 | import org.onlab.onos.sdnip.config.BgpPeer; |
| 58 | import org.onlab.onos.sdnip.config.Interface; |
| 59 | import org.onlab.onos.sdnip.config.SdnIpConfigService; |
| 60 | import org.onlab.packet.Ethernet; |
| 61 | import org.onlab.packet.IpAddress; |
Pavlin Radoslavov | 6b57073 | 2014-11-06 13:16:45 -0800 | [diff] [blame] | 62 | import org.onlab.packet.Ip4Address; |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 63 | import org.onlab.packet.IpPrefix; |
Pavlin Radoslavov | 6b57073 | 2014-11-06 13:16:45 -0800 | [diff] [blame] | 64 | import org.onlab.packet.Ip4Prefix; |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 65 | import org.onlab.packet.MacAddress; |
| 66 | import org.onlab.packet.VlanId; |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 67 | |
| 68 | import com.google.common.collect.Sets; |
| 69 | |
| 70 | /** |
| 71 | * This class tests adding a route, updating a route, deleting a route, |
| 72 | * and adding a route whose next hop is the local BGP speaker. |
Pingping | fc58467 | 2014-10-23 10:51:19 -0700 | [diff] [blame] | 73 | * <p/> |
| 74 | * ARP module answers the MAC address synchronously. |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 75 | */ |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame^] | 76 | public class RouterTest extends AbstractIntentTest { |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 77 | |
| 78 | private SdnIpConfigService sdnIpConfigService; |
| 79 | private InterfaceService interfaceService; |
| 80 | private IntentService intentService; |
| 81 | private HostService hostService; |
| 82 | |
Jonathan Hart | 31582d1 | 2014-10-22 13:52:41 -0700 | [diff] [blame] | 83 | private static final ConnectPoint SW1_ETH1 = new ConnectPoint( |
| 84 | DeviceId.deviceId("of:0000000000000001"), |
| 85 | PortNumber.portNumber(1)); |
| 86 | |
| 87 | private static final ConnectPoint SW2_ETH1 = new ConnectPoint( |
| 88 | DeviceId.deviceId("of:0000000000000002"), |
| 89 | PortNumber.portNumber(1)); |
| 90 | |
| 91 | private static final ConnectPoint SW3_ETH1 = new ConnectPoint( |
| 92 | DeviceId.deviceId("of:0000000000000003"), |
| 93 | PortNumber.portNumber(1)); |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 94 | |
| 95 | private static final ApplicationId APPID = new ApplicationId() { |
| 96 | @Override |
| 97 | public short id() { |
| 98 | return 1; |
| 99 | } |
| 100 | |
| 101 | @Override |
| 102 | public String name() { |
| 103 | return "SDNIP"; |
| 104 | } |
| 105 | }; |
| 106 | |
Pavlin Radoslavov | a071b1e | 2014-11-17 13:37:57 -0800 | [diff] [blame] | 107 | private IntentSynchronizer intentSynchronizer; |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 108 | private Router router; |
| 109 | |
| 110 | @Before |
| 111 | public void setUp() throws Exception { |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame^] | 112 | super.setUp(); |
| 113 | |
Jonathan Hart | 31582d1 | 2014-10-22 13:52:41 -0700 | [diff] [blame] | 114 | setUpBgpPeers(); |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 115 | |
Jonathan Hart | 31582d1 | 2014-10-22 13:52:41 -0700 | [diff] [blame] | 116 | setUpInterfaceService(); |
| 117 | setUpHostService(); |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 118 | |
| 119 | intentService = createMock(IntentService.class); |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 120 | |
Pavlin Radoslavov | a071b1e | 2014-11-17 13:37:57 -0800 | [diff] [blame] | 121 | intentSynchronizer = new IntentSynchronizer(APPID, intentService); |
Pavlin Radoslavov | a7243cc | 2014-11-22 21:38:02 -0800 | [diff] [blame] | 122 | router = new Router(APPID, intentSynchronizer, sdnIpConfigService, |
| 123 | interfaceService, hostService); |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | /** |
| 127 | * Sets up BGP peers in external networks. |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 128 | */ |
Jonathan Hart | 31582d1 | 2014-10-22 13:52:41 -0700 | [diff] [blame] | 129 | private void setUpBgpPeers() { |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 130 | |
Jonathan Hart | 31582d1 | 2014-10-22 13:52:41 -0700 | [diff] [blame] | 131 | Map<IpAddress, BgpPeer> peers = new HashMap<>(); |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 132 | |
| 133 | String peerSw1Eth1 = "192.168.10.1"; |
Jonathan Hart | 31582d1 | 2014-10-22 13:52:41 -0700 | [diff] [blame] | 134 | peers.put(IpAddress.valueOf(peerSw1Eth1), |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 135 | new BgpPeer("00:00:00:00:00:00:00:01", 1, peerSw1Eth1)); |
| 136 | |
| 137 | // Two BGP peers are connected to switch 2 port 1. |
| 138 | String peer1Sw2Eth1 = "192.168.20.1"; |
Jonathan Hart | 31582d1 | 2014-10-22 13:52:41 -0700 | [diff] [blame] | 139 | peers.put(IpAddress.valueOf(peer1Sw2Eth1), |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 140 | new BgpPeer("00:00:00:00:00:00:00:02", 1, peer1Sw2Eth1)); |
| 141 | |
| 142 | String peer2Sw2Eth1 = "192.168.20.2"; |
Jonathan Hart | 31582d1 | 2014-10-22 13:52:41 -0700 | [diff] [blame] | 143 | peers.put(IpAddress.valueOf(peer2Sw2Eth1), |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 144 | new BgpPeer("00:00:00:00:00:00:00:02", 1, peer2Sw2Eth1)); |
| 145 | |
Jonathan Hart | 31582d1 | 2014-10-22 13:52:41 -0700 | [diff] [blame] | 146 | sdnIpConfigService = createMock(SdnIpConfigService.class); |
| 147 | expect(sdnIpConfigService.getBgpPeers()).andReturn(peers).anyTimes(); |
| 148 | replay(sdnIpConfigService); |
| 149 | |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | /** |
| 153 | * Sets up logical interfaces, which emulate the configured interfaces |
| 154 | * in SDN-IP application. |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 155 | */ |
Jonathan Hart | 31582d1 | 2014-10-22 13:52:41 -0700 | [diff] [blame] | 156 | private void setUpInterfaceService() { |
| 157 | interfaceService = createMock(InterfaceService.class); |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 158 | |
Jonathan Hart | 31582d1 | 2014-10-22 13:52:41 -0700 | [diff] [blame] | 159 | Set<Interface> interfaces = Sets.newHashSet(); |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 160 | |
Pavlin Radoslavov | 76b0ae2 | 2014-10-27 15:33:19 -0700 | [diff] [blame] | 161 | InterfaceIpAddress ia1 = |
| 162 | new InterfaceIpAddress(IpAddress.valueOf("192.168.10.101"), |
| 163 | IpPrefix.valueOf("192.168.10.0/24")); |
Jonathan Hart | 31582d1 | 2014-10-22 13:52:41 -0700 | [diff] [blame] | 164 | Interface sw1Eth1 = new Interface(SW1_ETH1, |
Pavlin Radoslavov | 76b0ae2 | 2014-10-27 15:33:19 -0700 | [diff] [blame] | 165 | Sets.newHashSet(ia1), |
Jonathan Hart | 31582d1 | 2014-10-22 13:52:41 -0700 | [diff] [blame] | 166 | MacAddress.valueOf("00:00:00:00:00:01")); |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 167 | |
Jonathan Hart | 31582d1 | 2014-10-22 13:52:41 -0700 | [diff] [blame] | 168 | expect(interfaceService.getInterface(SW1_ETH1)).andReturn(sw1Eth1).anyTimes(); |
| 169 | interfaces.add(sw1Eth1); |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 170 | |
Pavlin Radoslavov | 76b0ae2 | 2014-10-27 15:33:19 -0700 | [diff] [blame] | 171 | InterfaceIpAddress ia2 = |
| 172 | new InterfaceIpAddress(IpAddress.valueOf("192.168.20.101"), |
| 173 | IpPrefix.valueOf("192.168.20.0/24")); |
Jonathan Hart | 31582d1 | 2014-10-22 13:52:41 -0700 | [diff] [blame] | 174 | Interface sw2Eth1 = new Interface(SW2_ETH1, |
Pavlin Radoslavov | 76b0ae2 | 2014-10-27 15:33:19 -0700 | [diff] [blame] | 175 | Sets.newHashSet(ia2), |
Jonathan Hart | 31582d1 | 2014-10-22 13:52:41 -0700 | [diff] [blame] | 176 | MacAddress.valueOf("00:00:00:00:00:02")); |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 177 | |
Jonathan Hart | 31582d1 | 2014-10-22 13:52:41 -0700 | [diff] [blame] | 178 | expect(interfaceService.getInterface(SW2_ETH1)).andReturn(sw2Eth1).anyTimes(); |
| 179 | interfaces.add(sw2Eth1); |
| 180 | |
Pavlin Radoslavov | 76b0ae2 | 2014-10-27 15:33:19 -0700 | [diff] [blame] | 181 | InterfaceIpAddress ia3 = |
| 182 | new InterfaceIpAddress(IpAddress.valueOf("192.168.30.101"), |
| 183 | IpPrefix.valueOf("192.168.30.0/24")); |
Jonathan Hart | 31582d1 | 2014-10-22 13:52:41 -0700 | [diff] [blame] | 184 | Interface sw3Eth1 = new Interface(SW3_ETH1, |
Pavlin Radoslavov | 76b0ae2 | 2014-10-27 15:33:19 -0700 | [diff] [blame] | 185 | Sets.newHashSet(ia3), |
Jonathan Hart | 31582d1 | 2014-10-22 13:52:41 -0700 | [diff] [blame] | 186 | MacAddress.valueOf("00:00:00:00:00:03")); |
| 187 | |
| 188 | expect(interfaceService.getInterface(SW3_ETH1)).andReturn(sw3Eth1).anyTimes(); |
| 189 | interfaces.add(sw3Eth1); |
| 190 | |
| 191 | expect(interfaceService.getInterfaces()).andReturn(interfaces).anyTimes(); |
| 192 | |
| 193 | replay(interfaceService); |
| 194 | } |
| 195 | |
| 196 | /** |
| 197 | * Sets up the host service with details of some hosts. |
| 198 | */ |
| 199 | private void setUpHostService() { |
| 200 | hostService = createMock(HostService.class); |
| 201 | |
| 202 | hostService.addListener(anyObject(HostListener.class)); |
| 203 | expectLastCall().anyTimes(); |
| 204 | |
Pavlin Radoslavov | 33f228a | 2014-10-27 19:33:16 -0700 | [diff] [blame] | 205 | IpAddress host1Address = IpAddress.valueOf("192.168.10.1"); |
Jonathan Hart | 31582d1 | 2014-10-22 13:52:41 -0700 | [diff] [blame] | 206 | Host host1 = new DefaultHost(ProviderId.NONE, HostId.NONE, |
| 207 | MacAddress.valueOf("00:00:00:00:00:01"), VlanId.NONE, |
| 208 | new HostLocation(SW1_ETH1, 1), |
Pavlin Radoslavov | 33f228a | 2014-10-27 19:33:16 -0700 | [diff] [blame] | 209 | Sets.newHashSet(host1Address)); |
Jonathan Hart | 31582d1 | 2014-10-22 13:52:41 -0700 | [diff] [blame] | 210 | |
| 211 | expect(hostService.getHostsByIp(host1Address)) |
| 212 | .andReturn(Sets.newHashSet(host1)).anyTimes(); |
Pavlin Radoslavov | 33f228a | 2014-10-27 19:33:16 -0700 | [diff] [blame] | 213 | hostService.startMonitoringIp(host1Address); |
Jonathan Hart | 31582d1 | 2014-10-22 13:52:41 -0700 | [diff] [blame] | 214 | expectLastCall().anyTimes(); |
| 215 | |
| 216 | |
Pavlin Radoslavov | 33f228a | 2014-10-27 19:33:16 -0700 | [diff] [blame] | 217 | IpAddress host2Address = IpAddress.valueOf("192.168.20.1"); |
Jonathan Hart | 31582d1 | 2014-10-22 13:52:41 -0700 | [diff] [blame] | 218 | Host host2 = new DefaultHost(ProviderId.NONE, HostId.NONE, |
| 219 | MacAddress.valueOf("00:00:00:00:00:02"), VlanId.NONE, |
| 220 | new HostLocation(SW2_ETH1, 1), |
Pavlin Radoslavov | 33f228a | 2014-10-27 19:33:16 -0700 | [diff] [blame] | 221 | Sets.newHashSet(host2Address)); |
Jonathan Hart | 31582d1 | 2014-10-22 13:52:41 -0700 | [diff] [blame] | 222 | |
| 223 | expect(hostService.getHostsByIp(host2Address)) |
| 224 | .andReturn(Sets.newHashSet(host2)).anyTimes(); |
Pavlin Radoslavov | 33f228a | 2014-10-27 19:33:16 -0700 | [diff] [blame] | 225 | hostService.startMonitoringIp(host2Address); |
Jonathan Hart | 31582d1 | 2014-10-22 13:52:41 -0700 | [diff] [blame] | 226 | expectLastCall().anyTimes(); |
| 227 | |
| 228 | |
| 229 | replay(hostService); |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | /** |
| 233 | * This method tests adding a route entry. |
| 234 | */ |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame^] | 235 | @Test @Ignore("needs fix from intents") |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 236 | public void testProcessRouteAdd() throws TestUtilsException { |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 237 | // Construct a route entry |
| 238 | RouteEntry routeEntry = new RouteEntry( |
Pavlin Radoslavov | 6b57073 | 2014-11-06 13:16:45 -0800 | [diff] [blame] | 239 | Ip4Prefix.valueOf("1.1.1.0/24"), |
| 240 | Ip4Address.valueOf("192.168.10.1")); |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 241 | |
| 242 | // Construct a MultiPointToSinglePointIntent intent |
| 243 | TrafficSelector.Builder selectorBuilder = |
| 244 | DefaultTrafficSelector.builder(); |
| 245 | selectorBuilder.matchEthType(Ethernet.TYPE_IPV4).matchIPDst( |
| 246 | routeEntry.prefix()); |
| 247 | |
| 248 | TrafficTreatment.Builder treatmentBuilder = |
| 249 | DefaultTrafficTreatment.builder(); |
| 250 | treatmentBuilder.setEthDst(MacAddress.valueOf("00:00:00:00:00:01")); |
| 251 | |
| 252 | Set<ConnectPoint> ingressPoints = new HashSet<ConnectPoint>(); |
Jonathan Hart | 31582d1 | 2014-10-22 13:52:41 -0700 | [diff] [blame] | 253 | ingressPoints.add(SW2_ETH1); |
| 254 | ingressPoints.add(SW3_ETH1); |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 255 | |
| 256 | MultiPointToSinglePointIntent intent = |
| 257 | new MultiPointToSinglePointIntent(APPID, |
| 258 | selectorBuilder.build(), treatmentBuilder.build(), |
Jonathan Hart | 31582d1 | 2014-10-22 13:52:41 -0700 | [diff] [blame] | 259 | ingressPoints, SW1_ETH1); |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 260 | |
| 261 | // Set up test expectation |
| 262 | reset(intentService); |
| 263 | intentService.submit(intent); |
| 264 | replay(intentService); |
| 265 | |
| 266 | // Call the processRouteAdd() method in Router class |
Pavlin Radoslavov | a071b1e | 2014-11-17 13:37:57 -0800 | [diff] [blame] | 267 | intentSynchronizer.leaderChanged(true); |
| 268 | TestUtils.setField(intentSynchronizer, "isActivatedLeader", true); |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 269 | router.processRouteAdd(routeEntry); |
| 270 | |
| 271 | // Verify |
| 272 | assertEquals(router.getRoutes().size(), 1); |
| 273 | assertTrue(router.getRoutes().contains(routeEntry)); |
Pavlin Radoslavov | a7243cc | 2014-11-22 21:38:02 -0800 | [diff] [blame] | 274 | assertEquals(intentSynchronizer.getRouteIntents().size(), 1); |
| 275 | assertEquals(intentSynchronizer.getRouteIntents().iterator().next(), |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 276 | intent); |
| 277 | verify(intentService); |
| 278 | } |
| 279 | |
| 280 | /** |
| 281 | * This method tests updating a route entry. |
| 282 | * |
| 283 | * @throws TestUtilsException |
| 284 | */ |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame^] | 285 | @Test @Ignore("needs fix from intents") |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 286 | public void testRouteUpdate() throws TestUtilsException { |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 287 | // Firstly add a route |
| 288 | testProcessRouteAdd(); |
| 289 | |
| 290 | // Construct the existing route entry |
| 291 | RouteEntry routeEntry = new RouteEntry( |
Pavlin Radoslavov | 6b57073 | 2014-11-06 13:16:45 -0800 | [diff] [blame] | 292 | Ip4Prefix.valueOf("1.1.1.0/24"), |
| 293 | Ip4Address.valueOf("192.168.10.1")); |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 294 | |
| 295 | // Construct the existing MultiPointToSinglePointIntent intent |
| 296 | TrafficSelector.Builder selectorBuilder = |
| 297 | DefaultTrafficSelector.builder(); |
| 298 | selectorBuilder.matchEthType(Ethernet.TYPE_IPV4).matchIPDst( |
| 299 | routeEntry.prefix()); |
| 300 | |
| 301 | TrafficTreatment.Builder treatmentBuilder = |
| 302 | DefaultTrafficTreatment.builder(); |
| 303 | treatmentBuilder.setEthDst(MacAddress.valueOf("00:00:00:00:00:01")); |
| 304 | |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 305 | Set<ConnectPoint> ingressPoints = new HashSet<ConnectPoint>(); |
Jonathan Hart | 31582d1 | 2014-10-22 13:52:41 -0700 | [diff] [blame] | 306 | ingressPoints.add(SW2_ETH1); |
| 307 | ingressPoints.add(SW3_ETH1); |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 308 | |
| 309 | MultiPointToSinglePointIntent intent = |
| 310 | new MultiPointToSinglePointIntent(APPID, |
| 311 | selectorBuilder.build(), treatmentBuilder.build(), |
Jonathan Hart | 31582d1 | 2014-10-22 13:52:41 -0700 | [diff] [blame] | 312 | ingressPoints, SW1_ETH1); |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 313 | |
| 314 | // Start to construct a new route entry and new intent |
| 315 | RouteEntry routeEntryUpdate = new RouteEntry( |
Pavlin Radoslavov | 6b57073 | 2014-11-06 13:16:45 -0800 | [diff] [blame] | 316 | Ip4Prefix.valueOf("1.1.1.0/24"), |
| 317 | Ip4Address.valueOf("192.168.20.1")); |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 318 | |
| 319 | // Construct a new MultiPointToSinglePointIntent intent |
| 320 | TrafficSelector.Builder selectorBuilderNew = |
| 321 | DefaultTrafficSelector.builder(); |
| 322 | selectorBuilderNew.matchEthType(Ethernet.TYPE_IPV4).matchIPDst( |
| 323 | routeEntryUpdate.prefix()); |
| 324 | |
| 325 | TrafficTreatment.Builder treatmentBuilderNew = |
| 326 | DefaultTrafficTreatment.builder(); |
| 327 | treatmentBuilderNew.setEthDst(MacAddress.valueOf("00:00:00:00:00:02")); |
| 328 | |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 329 | |
| 330 | Set<ConnectPoint> ingressPointsNew = new HashSet<ConnectPoint>(); |
Jonathan Hart | 31582d1 | 2014-10-22 13:52:41 -0700 | [diff] [blame] | 331 | ingressPointsNew.add(SW1_ETH1); |
| 332 | ingressPointsNew.add(SW3_ETH1); |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 333 | |
| 334 | MultiPointToSinglePointIntent intentNew = |
| 335 | new MultiPointToSinglePointIntent(APPID, |
| 336 | selectorBuilderNew.build(), |
| 337 | treatmentBuilderNew.build(), |
Jonathan Hart | 31582d1 | 2014-10-22 13:52:41 -0700 | [diff] [blame] | 338 | ingressPointsNew, SW2_ETH1); |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 339 | |
| 340 | // Set up test expectation |
| 341 | reset(intentService); |
| 342 | intentService.withdraw(intent); |
| 343 | intentService.submit(intentNew); |
| 344 | replay(intentService); |
| 345 | |
| 346 | // Call the processRouteAdd() method in Router class |
Pavlin Radoslavov | a071b1e | 2014-11-17 13:37:57 -0800 | [diff] [blame] | 347 | intentSynchronizer.leaderChanged(true); |
| 348 | TestUtils.setField(intentSynchronizer, "isActivatedLeader", true); |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 349 | router.processRouteAdd(routeEntryUpdate); |
| 350 | |
| 351 | // Verify |
| 352 | assertEquals(router.getRoutes().size(), 1); |
| 353 | assertTrue(router.getRoutes().contains(routeEntryUpdate)); |
Pavlin Radoslavov | a7243cc | 2014-11-22 21:38:02 -0800 | [diff] [blame] | 354 | assertEquals(intentSynchronizer.getRouteIntents().size(), 1); |
| 355 | assertEquals(intentSynchronizer.getRouteIntents().iterator().next(), |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 356 | intentNew); |
| 357 | verify(intentService); |
| 358 | } |
| 359 | |
| 360 | /** |
| 361 | * This method tests deleting a route entry. |
| 362 | */ |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame^] | 363 | @Test @Ignore("needs fix from intents") |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 364 | public void testProcessRouteDelete() throws TestUtilsException { |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 365 | // Firstly add a route |
| 366 | testProcessRouteAdd(); |
| 367 | |
| 368 | // Construct the existing route entry |
| 369 | RouteEntry routeEntry = new RouteEntry( |
Pavlin Radoslavov | 6b57073 | 2014-11-06 13:16:45 -0800 | [diff] [blame] | 370 | Ip4Prefix.valueOf("1.1.1.0/24"), |
| 371 | Ip4Address.valueOf("192.168.10.1")); |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 372 | |
| 373 | // Construct the existing MultiPointToSinglePointIntent intent |
| 374 | TrafficSelector.Builder selectorBuilder = |
| 375 | DefaultTrafficSelector.builder(); |
| 376 | selectorBuilder.matchEthType(Ethernet.TYPE_IPV4).matchIPDst( |
| 377 | routeEntry.prefix()); |
| 378 | |
| 379 | TrafficTreatment.Builder treatmentBuilder = |
| 380 | DefaultTrafficTreatment.builder(); |
| 381 | treatmentBuilder.setEthDst(MacAddress.valueOf("00:00:00:00:00:01")); |
| 382 | |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 383 | Set<ConnectPoint> ingressPoints = new HashSet<ConnectPoint>(); |
Jonathan Hart | 31582d1 | 2014-10-22 13:52:41 -0700 | [diff] [blame] | 384 | ingressPoints.add(SW2_ETH1); |
| 385 | ingressPoints.add(SW3_ETH1); |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 386 | |
| 387 | MultiPointToSinglePointIntent intent = |
| 388 | new MultiPointToSinglePointIntent(APPID, |
| 389 | selectorBuilder.build(), treatmentBuilder.build(), |
Jonathan Hart | 31582d1 | 2014-10-22 13:52:41 -0700 | [diff] [blame] | 390 | ingressPoints, SW1_ETH1); |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 391 | |
| 392 | // Set up expectation |
| 393 | reset(intentService); |
| 394 | intentService.withdraw(intent); |
| 395 | replay(intentService); |
| 396 | |
| 397 | // Call route deleting method in Router class |
Pavlin Radoslavov | a071b1e | 2014-11-17 13:37:57 -0800 | [diff] [blame] | 398 | intentSynchronizer.leaderChanged(true); |
| 399 | TestUtils.setField(intentSynchronizer, "isActivatedLeader", true); |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 400 | router.processRouteDelete(routeEntry); |
| 401 | |
| 402 | // Verify |
| 403 | assertEquals(router.getRoutes().size(), 0); |
Pavlin Radoslavov | a7243cc | 2014-11-22 21:38:02 -0800 | [diff] [blame] | 404 | assertEquals(intentSynchronizer.getRouteIntents().size(), 0); |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 405 | verify(intentService); |
| 406 | } |
| 407 | |
| 408 | /** |
| 409 | * This method tests when the next hop of a route is the local BGP speaker. |
| 410 | * |
| 411 | * @throws TestUtilsException |
| 412 | */ |
| 413 | @Test |
| 414 | public void testLocalRouteAdd() throws TestUtilsException { |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 415 | // Construct a route entry, the next hop is the local BGP speaker |
| 416 | RouteEntry routeEntry = new RouteEntry( |
Pavlin Radoslavov | 6b57073 | 2014-11-06 13:16:45 -0800 | [diff] [blame] | 417 | Ip4Prefix.valueOf("1.1.1.0/24"), |
| 418 | Ip4Address.valueOf("0.0.0.0")); |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 419 | |
| 420 | // Reset intentService to check whether the submit method is called |
| 421 | reset(intentService); |
| 422 | replay(intentService); |
| 423 | |
| 424 | // Call the processRouteAdd() method in Router class |
Pavlin Radoslavov | a071b1e | 2014-11-17 13:37:57 -0800 | [diff] [blame] | 425 | intentSynchronizer.leaderChanged(true); |
| 426 | TestUtils.setField(intentSynchronizer, "isActivatedLeader", true); |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 427 | router.processRouteAdd(routeEntry); |
| 428 | |
| 429 | // Verify |
| 430 | assertEquals(router.getRoutes().size(), 1); |
| 431 | assertTrue(router.getRoutes().contains(routeEntry)); |
Pavlin Radoslavov | a7243cc | 2014-11-22 21:38:02 -0800 | [diff] [blame] | 432 | assertEquals(intentSynchronizer.getRouteIntents().size(), 0); |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 433 | verify(intentService); |
| 434 | } |
| 435 | } |