Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -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 | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 3 | * |
| 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 |
| 7 | * |
| 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. |
| 15 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.proxyarp.impl; |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 17 | |
Jonathan Hart | 00cddda | 2016-02-16 10:30:37 -0800 | [diff] [blame] | 18 | import com.google.common.collect.Lists; |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 19 | import com.google.common.collect.Sets; |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 20 | import org.junit.Before; |
| 21 | import org.junit.Test; |
Jonathan Hart | 3cfce8e | 2015-01-14 16:43:27 -0800 | [diff] [blame] | 22 | import org.onlab.packet.ARP; |
| 23 | import org.onlab.packet.Ethernet; |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 24 | import org.onlab.packet.ICMP6; |
| 25 | import org.onlab.packet.IPacket; |
| 26 | import org.onlab.packet.IPv6; |
Jonathan Hart | 3cfce8e | 2015-01-14 16:43:27 -0800 | [diff] [blame] | 27 | import org.onlab.packet.Ip4Address; |
| 28 | import org.onlab.packet.Ip4Prefix; |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 29 | import org.onlab.packet.Ip6Address; |
| 30 | import org.onlab.packet.Ip6Prefix; |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 31 | import org.onlab.packet.IpPrefix; |
Jonathan Hart | 3cfce8e | 2015-01-14 16:43:27 -0800 | [diff] [blame] | 32 | import org.onlab.packet.MacAddress; |
| 33 | import org.onlab.packet.VlanId; |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 34 | import org.onlab.packet.ndp.NeighborAdvertisement; |
| 35 | import org.onlab.packet.ndp.NeighborDiscoveryOptions; |
| 36 | import org.onlab.packet.ndp.NeighborSolicitation; |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 37 | import org.onosproject.incubator.net.intf.Interface; |
| 38 | import org.onosproject.incubator.net.intf.InterfaceService; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 39 | import org.onosproject.net.ConnectPoint; |
| 40 | import org.onosproject.net.DefaultHost; |
| 41 | import org.onosproject.net.Device; |
| 42 | import org.onosproject.net.DeviceId; |
| 43 | import org.onosproject.net.Host; |
| 44 | import org.onosproject.net.HostId; |
| 45 | import org.onosproject.net.HostLocation; |
| 46 | import org.onosproject.net.Link; |
| 47 | import org.onosproject.net.Port; |
| 48 | import org.onosproject.net.PortNumber; |
| 49 | import org.onosproject.net.device.DeviceListener; |
| 50 | import org.onosproject.net.device.DeviceService; |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 51 | import org.onosproject.net.edge.EdgePortService; |
Thomas Vachuska | b2c47a7 | 2015-08-05 14:22:54 -0700 | [diff] [blame] | 52 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 53 | import org.onosproject.net.flow.TrafficTreatment; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 54 | import org.onosproject.net.flow.instructions.Instruction; |
| 55 | import org.onosproject.net.flow.instructions.Instructions.OutputInstruction; |
| 56 | import org.onosproject.net.host.HostService; |
| 57 | import org.onosproject.net.host.InterfaceIpAddress; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 58 | import org.onosproject.net.link.LinkListener; |
| 59 | import org.onosproject.net.link.LinkService; |
Thomas Vachuska | b2c47a7 | 2015-08-05 14:22:54 -0700 | [diff] [blame] | 60 | import org.onosproject.net.packet.DefaultOutboundPacket; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 61 | import org.onosproject.net.packet.OutboundPacket; |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 62 | import org.onosproject.net.packet.PacketServiceAdapter; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 63 | import org.onosproject.net.provider.ProviderId; |
Thomas Vachuska | b2c47a7 | 2015-08-05 14:22:54 -0700 | [diff] [blame] | 64 | import org.onosproject.net.proxyarp.ProxyArpStore; |
| 65 | import org.onosproject.net.proxyarp.ProxyArpStoreDelegate; |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 66 | |
Thomas Vachuska | b2c47a7 | 2015-08-05 14:22:54 -0700 | [diff] [blame] | 67 | import java.nio.ByteBuffer; |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 68 | import java.util.ArrayList; |
| 69 | import java.util.Collections; |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 70 | import java.util.HashSet; |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 71 | import java.util.List; |
| 72 | import java.util.Set; |
| 73 | |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 74 | import static org.easymock.EasyMock.anyObject; |
| 75 | import static org.easymock.EasyMock.createMock; |
| 76 | import static org.easymock.EasyMock.expect; |
| 77 | import static org.easymock.EasyMock.replay; |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 78 | import static org.hamcrest.Matchers.anyOf; |
| 79 | import static org.hamcrest.Matchers.is; |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 80 | import static org.junit.Assert.assertArrayEquals; |
| 81 | import static org.junit.Assert.assertEquals; |
| 82 | import static org.junit.Assert.assertFalse; |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 83 | import static org.junit.Assert.assertNotNull; |
| 84 | import static org.junit.Assert.assertThat; |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 85 | import static org.junit.Assert.assertTrue; |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 86 | |
| 87 | /** |
| 88 | * Tests for the {@link ProxyArpManager} class. |
| 89 | */ |
| 90 | public class ProxyArpManagerTest { |
| 91 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 92 | private static final int NUM_DEVICES = 10; |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 93 | private static final int NUM_PORTS_PER_DEVICE = 3; |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 94 | private static final int LAST_CONF_DEVICE_INTF_VLAN_IP = 3; |
| 95 | private static final int LAST_CONF_DEVICE_INTF_VLAN = 6; |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 96 | |
Pavlin Radoslavov | 5b5dc48 | 2014-11-05 14:48:08 -0800 | [diff] [blame] | 97 | private static final Ip4Address IP1 = Ip4Address.valueOf("192.168.1.1"); |
| 98 | private static final Ip4Address IP2 = Ip4Address.valueOf("192.168.1.2"); |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 99 | private static final Ip6Address IP3 = Ip6Address.valueOf("1000:ffff::1"); |
| 100 | private static final Ip6Address IP4 = Ip6Address.valueOf("1000:ffff::2"); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 101 | |
| 102 | private static final ProviderId PID = new ProviderId("of", "foo"); |
| 103 | |
| 104 | private static final VlanId VLAN1 = VlanId.vlanId((short) 1); |
| 105 | private static final VlanId VLAN2 = VlanId.vlanId((short) 2); |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 106 | private static final VlanId VLAN10 = VlanId.vlanId((short) 10); |
| 107 | |
| 108 | private static final MacAddress MAC1 = MacAddress.valueOf("00:00:00:00:00:01"); |
| 109 | private static final MacAddress MAC2 = MacAddress.valueOf("00:00:00:00:00:02"); |
| 110 | private static final MacAddress MAC3 = MacAddress.valueOf("00:00:00:00:00:03"); |
| 111 | private static final MacAddress MAC4 = MacAddress.valueOf("00:00:00:00:00:04"); |
| 112 | private static final MacAddress MAC10 = MacAddress.valueOf("00:00:00:00:00:0A"); |
| 113 | |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 114 | private static final MacAddress SOLICITED_MAC3 = MacAddress.valueOf("33:33:FF:00:00:01"); |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 115 | |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 116 | private static final HostId HID1 = HostId.hostId(MAC1, VLAN1); |
| 117 | private static final HostId HID2 = HostId.hostId(MAC2, VLAN1); |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 118 | private static final HostId HID3 = HostId.hostId(MAC3, VLAN1); |
| 119 | private static final HostId HID4 = HostId.hostId(MAC4, VLAN1); |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 120 | private static final HostId HID10 = HostId.hostId(MAC10, VLAN10); |
| 121 | |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 122 | private static final HostId SOLICITED_HID3 = HostId.hostId(SOLICITED_MAC3, VLAN1); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 123 | |
| 124 | private static final DeviceId DID1 = getDeviceId(1); |
| 125 | private static final DeviceId DID2 = getDeviceId(2); |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 126 | |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 127 | private static final PortNumber P1 = PortNumber.portNumber(1); |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 128 | |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 129 | private static final HostLocation LOC1 = new HostLocation(DID1, P1, 123L); |
| 130 | private static final HostLocation LOC2 = new HostLocation(DID2, P1, 123L); |
| 131 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 132 | private final byte[] zeroMacAddress = MacAddress.ZERO.toBytes(); |
Aaron Kruglikov | d812383 | 2015-07-06 14:20:25 -0700 | [diff] [blame] | 133 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 134 | // The first three devices in the topology have interfaces configured |
| 135 | // with VLANs and IPs |
| 136 | private final List<ConnectPoint> configIpCPoints = new ArrayList<>(); |
| 137 | |
| 138 | // Other three devices in the topology (from 4 to 6) have interfaces |
| 139 | // configured only with VLANs |
| 140 | private final List<ConnectPoint> configVlanCPoints = new ArrayList<>(); |
| 141 | |
| 142 | // Remaining devices in the network (id > 6) don't have any interface |
| 143 | // configured. |
| 144 | private final List<ConnectPoint> noConfigCPoints = new ArrayList<>(); |
Aaron Kruglikov | d812383 | 2015-07-06 14:20:25 -0700 | [diff] [blame] | 145 | |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 146 | private ProxyArpManager proxyArp; |
| 147 | |
| 148 | private TestPacketService packetService; |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 149 | private DeviceService deviceService; |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 150 | private EdgePortService edgePortService; |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 151 | private LinkService linkService; |
| 152 | private HostService hostService; |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 153 | private InterfaceService interfaceService; |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 154 | |
| 155 | @Before |
| 156 | public void setUp() throws Exception { |
| 157 | proxyArp = new ProxyArpManager(); |
| 158 | packetService = new TestPacketService(); |
| 159 | proxyArp.packetService = packetService; |
Thomas Vachuska | b2c47a7 | 2015-08-05 14:22:54 -0700 | [diff] [blame] | 160 | proxyArp.store = new TestProxyArpStoreAdapter(); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 161 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 162 | // Create a host service mock here. |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 163 | hostService = createMock(HostService.class); |
| 164 | proxyArp.hostService = hostService; |
| 165 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 166 | // Create an edge port service. |
| 167 | edgePortService = createMock(EdgePortService.class); |
| 168 | proxyArp.edgeService = edgePortService; |
| 169 | |
| 170 | // Create interface service |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 171 | interfaceService = createMock(InterfaceService.class); |
| 172 | proxyArp.interfaceService = interfaceService; |
| 173 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 174 | // Create the topology |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 175 | createTopology(); |
| 176 | proxyArp.deviceService = deviceService; |
| 177 | proxyArp.linkService = linkService; |
| 178 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 179 | setupNoConfigCPoints(); |
| 180 | setupconfigIpCPoints(); |
| 181 | setupconfigVlanCPoints(); |
| 182 | |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 183 | proxyArp.activate(); |
| 184 | } |
| 185 | |
| 186 | /** |
| 187 | * Creates a fake topology to feed into the ARP module. |
Aaron Kruglikov | d812383 | 2015-07-06 14:20:25 -0700 | [diff] [blame] | 188 | * <p> |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 189 | * The default topology is a unidirectional ring topology. Each switch has |
| 190 | * 3 ports. Ports 2 and 3 have the links to neighbor switches, and port 1 |
| 191 | * is free (edge port). |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 192 | * The first half of the switches have IP addresses configured on their |
| 193 | * free ports (port 1). The second half of the switches have no IP |
| 194 | * addresses configured. |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 195 | */ |
| 196 | private void createTopology() { |
| 197 | deviceService = createMock(DeviceService.class); |
| 198 | linkService = createMock(LinkService.class); |
| 199 | |
| 200 | deviceService.addListener(anyObject(DeviceListener.class)); |
| 201 | linkService.addListener(anyObject(LinkListener.class)); |
| 202 | |
| 203 | createDevices(NUM_DEVICES, NUM_PORTS_PER_DEVICE); |
| 204 | createLinks(NUM_DEVICES); |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 205 | addIntfConfig(); |
| 206 | popluateEdgePortService(); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | /** |
| 210 | * Creates the devices for the fake topology. |
| 211 | */ |
| 212 | private void createDevices(int numDevices, int numPorts) { |
| 213 | List<Device> devices = new ArrayList<>(); |
| 214 | |
| 215 | for (int i = 1; i <= numDevices; i++) { |
| 216 | DeviceId devId = getDeviceId(i); |
| 217 | Device device = createMock(Device.class); |
| 218 | expect(device.id()).andReturn(devId).anyTimes(); |
| 219 | replay(device); |
| 220 | |
| 221 | devices.add(device); |
| 222 | |
| 223 | List<Port> ports = new ArrayList<>(); |
| 224 | for (int j = 1; j <= numPorts; j++) { |
| 225 | Port port = createMock(Port.class); |
| 226 | expect(port.number()).andReturn(PortNumber.portNumber(j)).anyTimes(); |
| 227 | replay(port); |
| 228 | ports.add(port); |
| 229 | } |
| 230 | |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 231 | expect(deviceService.getPorts(devId)).andReturn(ports).anyTimes(); |
| 232 | expect(deviceService.getDevice(devId)).andReturn(device).anyTimes(); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 233 | } |
| 234 | |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 235 | expect(deviceService.getDevices()).andReturn(devices).anyTimes(); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 236 | replay(deviceService); |
| 237 | } |
| 238 | |
| 239 | /** |
| 240 | * Creates the links for the fake topology. |
| 241 | * NB: Only unidirectional links are created, as for this purpose all we |
| 242 | * need is to occupy the ports with some link. |
| 243 | */ |
| 244 | private void createLinks(int numDevices) { |
Sho SHIMIZU | d88db6f | 2015-09-09 14:22:06 -0700 | [diff] [blame] | 245 | List<Link> links = new ArrayList<>(); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 246 | |
| 247 | for (int i = 1; i <= numDevices; i++) { |
| 248 | ConnectPoint src = new ConnectPoint( |
| 249 | getDeviceId(i), |
| 250 | PortNumber.portNumber(2)); |
| 251 | ConnectPoint dst = new ConnectPoint( |
| 252 | getDeviceId((i + 1 > numDevices) ? 1 : i + 1), |
| 253 | PortNumber.portNumber(3)); |
| 254 | |
| 255 | Link link = createMock(Link.class); |
| 256 | expect(link.src()).andReturn(src).anyTimes(); |
| 257 | expect(link.dst()).andReturn(dst).anyTimes(); |
| 258 | replay(link); |
| 259 | |
| 260 | links.add(link); |
| 261 | } |
| 262 | |
| 263 | expect(linkService.getLinks()).andReturn(links).anyTimes(); |
| 264 | replay(linkService); |
| 265 | } |
| 266 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 267 | /** |
| 268 | * On the first three devices two config interfaces are binded on port 1. |
| 269 | * The first one with VLAN1, the second one with VLAN equals to none. |
| 270 | * Both interfaces have an IP. |
| 271 | * On devices 4, 5 and 6 it's binded a config interface on port 1. |
| 272 | * The interface is configured with VLAN 1 and no IP. |
| 273 | */ |
| 274 | private void addIntfConfig() { |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 275 | Set<Interface> interfaces = Sets.newHashSet(); |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 276 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 277 | Set<Interface> vlanOneSet = new HashSet<>(); |
| 278 | |
| 279 | for (int i = 1; i <= LAST_CONF_DEVICE_INTF_VLAN_IP; i++) { |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 280 | ConnectPoint cp = new ConnectPoint(getDeviceId(i), P1); |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 281 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 282 | // Interface addresses for IPv4 |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 283 | Ip4Prefix prefix1 = Ip4Prefix.valueOf("10.0." + (2 * i - 1) + ".0/24"); |
| 284 | Ip4Address addr1 = Ip4Address.valueOf("10.0." + (2 * i - 1) + ".1"); |
Pavlin Radoslavov | 5b5dc48 | 2014-11-05 14:48:08 -0800 | [diff] [blame] | 285 | Ip4Prefix prefix2 = Ip4Prefix.valueOf("10.0." + (2 * i) + ".0/24"); |
| 286 | Ip4Address addr2 = Ip4Address.valueOf("10.0." + (2 * i) + ".1"); |
Pavlin Radoslavov | 76b0ae2 | 2014-10-27 15:33:19 -0700 | [diff] [blame] | 287 | InterfaceIpAddress ia1 = new InterfaceIpAddress(addr1, prefix1); |
| 288 | InterfaceIpAddress ia2 = new InterfaceIpAddress(addr2, prefix2); |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 289 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 290 | // Interface addresses for IPv6 |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 291 | Ip6Prefix prefix3 = Ip6Prefix.valueOf((2 * i - 1) + "000::0/64"); |
| 292 | Ip6Address addr3 = Ip6Address.valueOf((2 * i - 1) + "000::1"); |
| 293 | Ip6Prefix prefix4 = Ip6Prefix.valueOf((2 * i) + "000::0/64"); |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 294 | Ip6Address addr4 = Ip6Address.valueOf((2 * i) + "000::2"); |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 295 | InterfaceIpAddress ia3 = new InterfaceIpAddress(addr3, prefix3); |
| 296 | InterfaceIpAddress ia4 = new InterfaceIpAddress(addr4, prefix4); |
| 297 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 298 | // Setting up interfaces |
Jonathan Hart | 00cddda | 2016-02-16 10:30:37 -0800 | [diff] [blame] | 299 | Interface intf1 = new Interface(cp, Lists.newArrayList(ia1, ia3), |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 300 | MacAddress.valueOf(2 * i - 1), |
| 301 | VlanId.vlanId((short) 1)); |
Jonathan Hart | 00cddda | 2016-02-16 10:30:37 -0800 | [diff] [blame] | 302 | Interface intf2 = new Interface(cp, Lists.newArrayList(ia2, ia4), |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 303 | MacAddress.valueOf(2 * i), |
| 304 | VlanId.NONE); |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 305 | |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 306 | interfaces.add(intf1); |
| 307 | interfaces.add(intf2); |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 308 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 309 | vlanOneSet.add(intf1); |
| 310 | |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 311 | expect(interfaceService.getInterfacesByPort(cp)) |
| 312 | .andReturn(Sets.newHashSet(intf1, intf2)).anyTimes(); |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 313 | } |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 314 | for (int i = LAST_CONF_DEVICE_INTF_VLAN_IP + 1; i <= LAST_CONF_DEVICE_INTF_VLAN; i++) { |
| 315 | ConnectPoint cp = new ConnectPoint(getDeviceId(i), P1); |
Jonathan Hart | 00cddda | 2016-02-16 10:30:37 -0800 | [diff] [blame] | 316 | Interface intf1 = new Interface(cp, Collections.emptyList(), |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 317 | MacAddress.NONE, |
| 318 | VlanId.vlanId((short) 1)); |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 319 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 320 | interfaces.add(intf1); |
| 321 | vlanOneSet.add(intf1); |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 322 | |
| 323 | expect(interfaceService.getInterfacesByPort(cp)) |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 324 | .andReturn(Sets.newHashSet(intf1)).anyTimes(); |
| 325 | } |
| 326 | expect(interfaceService.getInterfacesByVlan(VLAN1)) |
| 327 | .andReturn(vlanOneSet).anyTimes(); |
| 328 | expect(interfaceService.getInterfacesByVlan(VLAN10)) |
| 329 | .andReturn(Collections.emptySet()).anyTimes(); |
| 330 | expect(interfaceService.getInterfaces()).andReturn(interfaces).anyTimes(); |
| 331 | |
| 332 | for (int i = LAST_CONF_DEVICE_INTF_VLAN + 1; i <= NUM_DEVICES; i++) { |
| 333 | ConnectPoint cp = new ConnectPoint(getDeviceId(i), |
| 334 | P1); |
| 335 | expect(interfaceService.getInterfacesByPort(cp)) |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 336 | .andReturn(Collections.emptySet()).anyTimes(); |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 337 | } |
| 338 | } |
| 339 | |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 340 | /** |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 341 | * Populates edge ports in the EdgePortService to return all port 1 |
| 342 | * as edge ports. |
| 343 | */ |
| 344 | private void popluateEdgePortService() { |
| 345 | Set<ConnectPoint> edgeConnectPoints = new HashSet<>(); |
| 346 | |
| 347 | for (int i = 1; i <= NUM_DEVICES; i++) { |
| 348 | for (int j = 1; j <= NUM_PORTS_PER_DEVICE; j++) { |
| 349 | ConnectPoint edgeConnectPoint = new ConnectPoint( |
| 350 | getDeviceId(i), |
| 351 | PortNumber.portNumber(1)); |
| 352 | ConnectPoint noEdgeConnectPointOne = new ConnectPoint( |
| 353 | getDeviceId(i), |
| 354 | PortNumber.portNumber(2)); |
| 355 | ConnectPoint noEdgeConnectPointTwo = new ConnectPoint( |
| 356 | getDeviceId(i), |
| 357 | PortNumber.portNumber(3)); |
| 358 | |
| 359 | edgeConnectPoints.add(edgeConnectPoint); |
| 360 | |
| 361 | expect(edgePortService.isEdgePoint(edgeConnectPoint)) |
| 362 | .andReturn(true).anyTimes(); |
| 363 | expect(edgePortService.isEdgePoint(noEdgeConnectPointOne)) |
| 364 | .andReturn(false).anyTimes(); |
| 365 | expect(edgePortService.isEdgePoint(noEdgeConnectPointTwo)) |
| 366 | .andReturn(false).anyTimes(); |
| 367 | } |
| 368 | } |
| 369 | expect(edgePortService.getEdgePoints()) |
| 370 | .andReturn(edgeConnectPoints).anyTimes(); |
| 371 | |
| 372 | replay(edgePortService); |
| 373 | } |
| 374 | |
| 375 | /** |
| 376 | * Creates a list of connect points used to verify floodling on ports |
| 377 | * with no interfaces configured (all ports without interface config). |
| 378 | */ |
| 379 | private void setupNoConfigCPoints() { |
| 380 | for (int i = NUM_DEVICES / 2 + 2; i <= NUM_DEVICES; i++) { |
| 381 | ConnectPoint connectPoint = new ConnectPoint( |
| 382 | getDeviceId(i), |
| 383 | PortNumber.portNumber(1)); |
| 384 | noConfigCPoints.add(connectPoint); |
| 385 | } |
| 386 | } |
| 387 | |
| 388 | /** |
| 389 | * Creates a list of connect points used to verify floodling on ports |
| 390 | * with interfaces configured (both VLAN and IP). |
| 391 | */ |
| 392 | private void setupconfigIpCPoints() { |
| 393 | for (int i = 1; i <= 3; i++) { |
| 394 | ConnectPoint connectPoint = new ConnectPoint( |
| 395 | getDeviceId(i), |
| 396 | PortNumber.portNumber(1)); |
| 397 | configIpCPoints.add(connectPoint); |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | /** |
| 402 | * Creates a list of connect points used to verify floodling on ports |
| 403 | * with interfaces configured (both VLAN and IP). |
| 404 | */ |
| 405 | private void setupconfigVlanCPoints() { |
| 406 | for (int i = LAST_CONF_DEVICE_INTF_VLAN_IP + 1; i <= LAST_CONF_DEVICE_INTF_VLAN; i++) { |
| 407 | ConnectPoint connectPoint = new ConnectPoint( |
| 408 | getDeviceId(i), |
| 409 | PortNumber.portNumber(1)); |
| 410 | configVlanCPoints.add(connectPoint); |
| 411 | } |
| 412 | } |
| 413 | |
| 414 | /** |
Jonathan Hart | 7d1496b | 2015-03-10 22:00:48 -0700 | [diff] [blame] | 415 | * Tests {@link ProxyArpManager#isKnown(org.onlab.packet.IpAddress)} in the |
| 416 | * case where the IP address is not known. |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 417 | * Verifies the method returns false. |
| 418 | */ |
| 419 | @Test |
| 420 | public void testNotKnown() { |
| 421 | expect(hostService.getHostsByIp(IP1)).andReturn(Collections.<Host>emptySet()); |
| 422 | replay(hostService); |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 423 | replay(interfaceService); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 424 | |
Jonathan Hart | f84591d | 2015-01-16 14:33:43 -0800 | [diff] [blame] | 425 | assertFalse(proxyArp.isKnown(IP1)); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | /** |
Jonathan Hart | 7d1496b | 2015-03-10 22:00:48 -0700 | [diff] [blame] | 429 | * Tests {@link ProxyArpManager#isKnown(org.onlab.packet.IpAddress)} in the |
| 430 | * case where the IP address is known. |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 431 | * Verifies the method returns true. |
| 432 | */ |
| 433 | @Test |
| 434 | public void testKnown() { |
| 435 | Host host1 = createMock(Host.class); |
| 436 | Host host2 = createMock(Host.class); |
| 437 | |
| 438 | expect(hostService.getHostsByIp(IP1)) |
| 439 | .andReturn(Sets.newHashSet(host1, host2)); |
| 440 | replay(hostService); |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 441 | replay(interfaceService); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 442 | |
Jonathan Hart | f84591d | 2015-01-16 14:33:43 -0800 | [diff] [blame] | 443 | assertTrue(proxyArp.isKnown(IP1)); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | /** |
Jonathan Hart | 6cd2f35 | 2015-01-13 17:44:45 -0800 | [diff] [blame] | 447 | * Tests {@link ProxyArpManager#reply(Ethernet, ConnectPoint)} in the case where the |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 448 | * destination host is known. |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 449 | * Two host using the same VLAN are registered on the host service on devices 5 and 6. |
| 450 | * Host on port 6 asks for the MAC of the device on port 5. |
| 451 | * Since the destination mac address is known, the request is not flooded to anywhere |
| 452 | * and ONOS directly builds an ARP reply, sended back to the requester on device 6. |
| 453 | * It's verified that a proper ARP reply is received on port 1 of device 6. |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 454 | */ |
| 455 | @Test |
| 456 | public void testReplyKnown() { |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 457 | Host requestor = new DefaultHost(PID, HID1, MAC1, VLAN1, getLocation(NUM_DEVICES), |
Aaron Kruglikov | d812383 | 2015-07-06 14:20:25 -0700 | [diff] [blame] | 458 | Collections.singleton(IP1)); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 459 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 460 | Host replyer = new DefaultHost(PID, HID2, MAC2, VLAN1, getLocation(NUM_DEVICES - 1), |
Aaron Kruglikov | d812383 | 2015-07-06 14:20:25 -0700 | [diff] [blame] | 461 | Collections.singleton(IP2)); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 462 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 463 | expect(hostService.getHostsByIp(IP2)) |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 464 | .andReturn(Collections.singleton(replyer)); |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 465 | expect(hostService.getHost(HID1)).andReturn(requestor); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 466 | |
| 467 | replay(hostService); |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 468 | replay(interfaceService); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 469 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 470 | Ethernet arpRequest = buildArp(ARP.OP_REQUEST, VLAN1, MAC1, null, IP1, IP2); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 471 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 472 | proxyArp.reply(arpRequest, getLocation(NUM_DEVICES)); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 473 | |
| 474 | assertEquals(1, packetService.packets.size()); |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 475 | Ethernet arpReply = buildArp(ARP.OP_REPLY, VLAN1, MAC2, MAC1, IP2, IP1); |
| 476 | verifyPacketOut(arpReply, getLocation(NUM_DEVICES), packetService.packets.get(0)); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | /** |
Jonathan Hart | 6cd2f35 | 2015-01-13 17:44:45 -0800 | [diff] [blame] | 480 | * Tests {@link ProxyArpManager#reply(Ethernet, ConnectPoint)} in the case where the |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 481 | * destination host is known. |
| 482 | * Verifies the correct NDP reply is sent out the correct port. |
| 483 | */ |
| 484 | @Test |
| 485 | public void testReplyKnownIpv6() { |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 486 | Host replyer = new DefaultHost(PID, HID3, MAC3, VLAN1, getLocation(4), |
| 487 | Collections.singleton(IP3)); |
| 488 | |
| 489 | Host requestor = new DefaultHost(PID, HID4, MAC4, VLAN1, getLocation(5), |
| 490 | Collections.singleton(IP4)); |
| 491 | |
| 492 | expect(hostService.getHostsByIp(IP3)) |
| 493 | .andReturn(Collections.singleton(replyer)); |
| 494 | expect(hostService.getHost(HID4)).andReturn(requestor); |
| 495 | |
| 496 | replay(hostService); |
| 497 | replay(interfaceService); |
| 498 | |
Jonathan Hart | d9df7bd | 2015-11-10 17:10:25 -0800 | [diff] [blame] | 499 | Ethernet ndpRequest = buildNdp(ICMP6.NEIGHBOR_SOLICITATION, |
| 500 | MAC4, SOLICITED_MAC3, |
| 501 | IP4, IP3); |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 502 | |
| 503 | proxyArp.reply(ndpRequest, getLocation(5)); |
| 504 | |
| 505 | assertEquals(1, packetService.packets.size()); |
Jonathan Hart | d9df7bd | 2015-11-10 17:10:25 -0800 | [diff] [blame] | 506 | Ethernet ndpReply = buildNdp(ICMP6.NEIGHBOR_ADVERTISEMENT, |
| 507 | MAC3, MAC4, IP3, IP4); |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 508 | verifyPacketOut(ndpReply, getLocation(5), packetService.packets.get(0)); |
| 509 | } |
| 510 | |
| 511 | /** |
| 512 | * Tests {@link ProxyArpManager#reply(Ethernet, ConnectPoint)} in the case where the |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 513 | * destination host is not known. |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 514 | * Only a requestor is present (on device 6, port 1). The device has a VLAN configured |
| 515 | * which is not configured anywhere in the system. |
| 516 | * Since the destination is not known, and since the ARP request can't be sent out of |
| 517 | * interfaces configured, the ARP request is flooded out of ports 4 and 5. |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 518 | * Verifies the ARP request is flooded out the correct edge ports. |
| 519 | */ |
| 520 | @Test |
| 521 | public void testReplyUnknown() { |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 522 | Host requestor = new DefaultHost(PID, HID10, MAC10, VLAN10, getLocation(NUM_DEVICES), |
| 523 | Collections.singleton(IP1)); |
Aaron Kruglikov | d812383 | 2015-07-06 14:20:25 -0700 | [diff] [blame] | 524 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 525 | expect(hostService.getHostsByIp(IP2)) |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 526 | .andReturn(Collections.emptySet()); |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 527 | expect(interfaceService.getInterfacesByIp(IP1)) |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 528 | .andReturn(Collections.emptySet()); |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 529 | expect(hostService.getHost(HID10)).andReturn(requestor); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 530 | |
| 531 | replay(hostService); |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 532 | replay(interfaceService); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 533 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 534 | Ethernet arpRequest = buildArp(ARP.OP_REQUEST, VLAN10, MAC10, null, IP1, IP2); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 535 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 536 | proxyArp.reply(arpRequest, getLocation(NUM_DEVICES)); |
Aaron Kruglikov | d812383 | 2015-07-06 14:20:25 -0700 | [diff] [blame] | 537 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 538 | verifyFlood(arpRequest, noConfigCPoints); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 539 | } |
| 540 | |
| 541 | /** |
Jonathan Hart | 6cd2f35 | 2015-01-13 17:44:45 -0800 | [diff] [blame] | 542 | * Tests {@link ProxyArpManager#reply(Ethernet, ConnectPoint)} in the case where the |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 543 | * destination host is not known. |
| 544 | * Verifies the NDP request is flooded out the correct edge ports. |
| 545 | */ |
| 546 | @Test |
| 547 | public void testReplyUnknownIpv6() { |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 548 | Host requestor = new DefaultHost(PID, HID4, MAC4, VLAN1, getLocation(NUM_DEVICES), |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 549 | Collections.singleton(IP4)); |
| 550 | |
| 551 | expect(hostService.getHostsByIp(IP3)) |
| 552 | .andReturn(Collections.emptySet()); |
| 553 | expect(interfaceService.getInterfacesByIp(IP4)) |
| 554 | .andReturn(Collections.emptySet()); |
| 555 | expect(hostService.getHost(HID4)).andReturn(requestor); |
| 556 | |
| 557 | replay(hostService); |
| 558 | replay(interfaceService); |
| 559 | |
Jonathan Hart | d9df7bd | 2015-11-10 17:10:25 -0800 | [diff] [blame] | 560 | Ethernet ndpRequest = buildNdp(ICMP6.NEIGHBOR_SOLICITATION, |
| 561 | MAC4, SOLICITED_MAC3, |
| 562 | IP4, IP3); |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 563 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 564 | proxyArp.reply(ndpRequest, getLocation(NUM_DEVICES)); |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 565 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 566 | verifyFlood(ndpRequest, noConfigCPoints); |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 567 | } |
| 568 | |
| 569 | /** |
| 570 | * Tests {@link ProxyArpManager#reply(Ethernet, ConnectPoint)} in the case where the |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 571 | * destination host is known for that IP address, but is not on the same |
| 572 | * VLAN as the source host. |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 573 | * An host is connected on device 6, port 1 where no interfaces are defined. It sends |
| 574 | * ARP requests from VLAN10, not configured anywhere in the network. Another host with |
| 575 | * the IP address requested lives on device 5, port 1 in the network. Anyway, since the |
| 576 | * host uses another VLAN it's not found and the ARP packet is flooded out of port |
| 577 | * 4 and 5. |
| 578 | * |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 579 | * Verifies the ARP request is flooded out the correct edge ports. |
| 580 | */ |
| 581 | @Test |
| 582 | public void testReplyDifferentVlan() { |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 583 | Host requestor = new DefaultHost(PID, HID10, MAC10, VLAN10, getLocation(NUM_DEVICES), |
Aaron Kruglikov | d812383 | 2015-07-06 14:20:25 -0700 | [diff] [blame] | 584 | Collections.singleton(IP1)); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 585 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 586 | Host replyer = new DefaultHost(PID, HID2, MAC2, VLAN2, getLocation(NUM_DEVICES - 1), |
Aaron Kruglikov | d812383 | 2015-07-06 14:20:25 -0700 | [diff] [blame] | 587 | Collections.singleton(IP2)); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 588 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 589 | expect(hostService.getHostsByIp(IP2)) |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 590 | .andReturn(Collections.singleton(replyer)); |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 591 | expect(interfaceService.getInterfacesByIp(IP1)) |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 592 | .andReturn(Collections.emptySet()); |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 593 | expect(hostService.getHost(HID10)).andReturn(requestor); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 594 | |
| 595 | replay(hostService); |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 596 | replay(interfaceService); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 597 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 598 | Ethernet arpRequest = buildArp(ARP.OP_REQUEST, VLAN10, MAC10, null, IP1, IP2); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 599 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 600 | proxyArp.reply(arpRequest, getLocation(NUM_DEVICES)); |
| 601 | |
| 602 | verifyFlood(arpRequest, noConfigCPoints); |
| 603 | } |
| 604 | |
| 605 | /** |
| 606 | * Tests {@link ProxyArpManager#reply(Ethernet, ConnectPoint)} in the case where the |
| 607 | * a vlan packet comes in from a port without interfaces configured. The destination |
| 608 | * host is unknown for that IP address and there are some interfaces configured on |
| 609 | * the same vlan. |
| 610 | * It's expected to see the ARP request going out through ports with no interfaces |
| 611 | * configured, devices 4 and 5, port 1. |
| 612 | * |
| 613 | * Verifies the ARP request is flooded out the correct edge ports. |
| 614 | */ |
| 615 | @Test |
| 616 | public void testConfiguredVlan() { |
| 617 | Host requestor = new DefaultHost(PID, HID1, MAC1, VLAN1, getLocation(NUM_DEVICES), |
| 618 | Collections.singleton(IP1)); |
| 619 | |
| 620 | expect(hostService.getHostsByIp(IP2)) |
| 621 | .andReturn(Collections.emptySet()); |
| 622 | expect(interfaceService.getInterfacesByIp(IP1)) |
| 623 | .andReturn(Collections.emptySet()); |
| 624 | expect(hostService.getHost(HID1)).andReturn(requestor); |
| 625 | |
| 626 | replay(hostService); |
| 627 | replay(interfaceService); |
| 628 | |
| 629 | Ethernet arpRequest = buildArp(ARP.OP_REQUEST, VLAN1, MAC1, null, IP1, IP2); |
| 630 | |
| 631 | proxyArp.reply(arpRequest, getLocation(NUM_DEVICES)); |
| 632 | |
| 633 | verifyFlood(arpRequest, noConfigCPoints); |
| 634 | } |
| 635 | |
| 636 | /** |
| 637 | * Tests {@link ProxyArpManager#reply(Ethernet, ConnectPoint)} in the case where the |
| 638 | * a vlan packet comes in from a port without interfaces configured. The destination |
| 639 | * host is not known for that IP address and there are some interfaces configured on |
| 640 | * the same vlan. |
| 641 | * It's expected to see the ARP request going out through ports with no interfaces |
| 642 | * configured, devices 4 and 5, port 1. |
| 643 | * |
| 644 | * Verifies the ARP request is flooded out the correct edge ports. |
| 645 | */ |
| 646 | @Test |
| 647 | public void testConfiguredVlanOnInterfaces() { |
| 648 | Host requestor = new DefaultHost(PID, HID1, MAC1, VLAN1, getLocation(6), |
| 649 | Collections.singleton(IP1)); |
| 650 | |
| 651 | expect(hostService.getHostsByIp(IP2)) |
| 652 | .andReturn(Collections.emptySet()); |
| 653 | expect(interfaceService.getInterfacesByIp(IP1)) |
| 654 | .andReturn(Collections.emptySet()); |
| 655 | expect(hostService.getHost(HID1)).andReturn(requestor); |
| 656 | |
| 657 | replay(hostService); |
| 658 | replay(interfaceService); |
| 659 | |
| 660 | Ethernet arpRequest = buildArp(ARP.OP_REQUEST, VLAN1, MAC1, null, IP1, IP2); |
| 661 | |
Jonathan Hart | f84591d | 2015-01-16 14:33:43 -0800 | [diff] [blame] | 662 | proxyArp.reply(arpRequest, getLocation(6)); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 663 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 664 | verifyFlood(arpRequest, configVlanCPoints); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 665 | } |
| 666 | |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 667 | /** |
| 668 | * Tests {@link ProxyArpManager#reply(Ethernet, ConnectPoint)} in the case where the |
| 669 | * destination host is known for that IP address, but is not on the same |
| 670 | * VLAN as the source host. |
| 671 | * Verifies the NDP request is flooded out the correct edge ports. |
| 672 | */ |
| 673 | @Test |
| 674 | public void testReplyDifferentVlanIpv6() { |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 675 | Host requestor = new DefaultHost(PID, HID4, MAC4, VLAN1, getLocation(NUM_DEVICES), |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 676 | Collections.singleton(IP4)); |
| 677 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 678 | Host replyer = new DefaultHost(PID, HID3, MAC3, VLAN2, getLocation(NUM_DEVICES - 1), |
| 679 | Collections.singleton(IP3)); |
| 680 | |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 681 | expect(hostService.getHostsByIp(IP3)) |
| 682 | .andReturn(Collections.singleton(replyer)); |
| 683 | expect(interfaceService.getInterfacesByIp(IP4)) |
| 684 | .andReturn(Collections.emptySet()); |
| 685 | expect(hostService.getHost(HID4)).andReturn(requestor); |
| 686 | |
| 687 | replay(hostService); |
| 688 | replay(interfaceService); |
| 689 | |
Jonathan Hart | d9df7bd | 2015-11-10 17:10:25 -0800 | [diff] [blame] | 690 | Ethernet ndpRequest = buildNdp(ICMP6.NEIGHBOR_SOLICITATION, |
| 691 | MAC4, SOLICITED_MAC3, |
| 692 | IP4, IP3); |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 693 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 694 | proxyArp.reply(ndpRequest, getLocation(NUM_DEVICES)); |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 695 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 696 | verifyFlood(ndpRequest, noConfigCPoints); |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | /** |
| 700 | * Test ARP request from external network to an internal host. |
| 701 | */ |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 702 | @Test |
| 703 | public void testReplyToRequestForUs() { |
Pavlin Radoslavov | 5b5dc48 | 2014-11-05 14:48:08 -0800 | [diff] [blame] | 704 | Ip4Address theirIp = Ip4Address.valueOf("10.0.1.254"); |
| 705 | Ip4Address ourFirstIp = Ip4Address.valueOf("10.0.1.1"); |
| 706 | Ip4Address ourSecondIp = Ip4Address.valueOf("10.0.2.1"); |
Jonathan Hart | a887ba8 | 2014-11-03 15:20:52 -0800 | [diff] [blame] | 707 | MacAddress firstMac = MacAddress.valueOf(1L); |
| 708 | MacAddress secondMac = MacAddress.valueOf(2L); |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 709 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 710 | Host requestor = new DefaultHost(PID, HID1, MAC1, VLAN1, LOC1, |
Aaron Kruglikov | d812383 | 2015-07-06 14:20:25 -0700 | [diff] [blame] | 711 | Collections.singleton(theirIp)); |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 712 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 713 | expect(hostService.getHost(HID1)).andReturn(requestor); |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 714 | replay(hostService); |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 715 | replay(interfaceService); |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 716 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 717 | Ethernet arpRequest = buildArp(ARP.OP_REQUEST, VLAN1, MAC1, null, theirIp, ourFirstIp); |
| 718 | |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 719 | proxyArp.reply(arpRequest, LOC1); |
| 720 | |
| 721 | assertEquals(1, packetService.packets.size()); |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 722 | Ethernet arpReply = buildArp(ARP.OP_REPLY, VLAN1, firstMac, MAC1, ourFirstIp, theirIp); |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 723 | verifyPacketOut(arpReply, LOC1, packetService.packets.get(0)); |
| 724 | |
| 725 | // Test a request for the second address on that port |
| 726 | packetService.packets.clear(); |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 727 | arpRequest = buildArp(ARP.OP_REQUEST, VLAN1, MAC1, null, theirIp, ourSecondIp); |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 728 | |
| 729 | proxyArp.reply(arpRequest, LOC1); |
| 730 | |
| 731 | assertEquals(1, packetService.packets.size()); |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 732 | arpReply = buildArp(ARP.OP_REPLY, VLAN1, secondMac, MAC1, ourSecondIp, theirIp); |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 733 | verifyPacketOut(arpReply, LOC1, packetService.packets.get(0)); |
| 734 | } |
| 735 | |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 736 | /** |
| 737 | * Test NDP request from external network to an internal host. |
| 738 | */ |
| 739 | @Test |
| 740 | public void testReplyToRequestForUsIpv6() { |
| 741 | Ip6Address theirIp = Ip6Address.valueOf("1000::ffff"); |
| 742 | Ip6Address ourFirstIp = Ip6Address.valueOf("1000::1"); |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 743 | Ip6Address ourSecondIp = Ip6Address.valueOf("2000::2"); |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 744 | MacAddress firstMac = MacAddress.valueOf(1L); |
| 745 | MacAddress secondMac = MacAddress.valueOf(2L); |
| 746 | |
| 747 | Host requestor = new DefaultHost(PID, HID2, MAC2, VLAN1, LOC1, |
| 748 | Collections.singleton(theirIp)); |
| 749 | |
| 750 | expect(hostService.getHost(HID2)).andReturn(requestor); |
| 751 | expect(hostService.getHostsByIp(ourFirstIp)) |
| 752 | .andReturn(Collections.singleton(requestor)); |
| 753 | replay(hostService); |
| 754 | replay(interfaceService); |
| 755 | |
Jonathan Hart | d9df7bd | 2015-11-10 17:10:25 -0800 | [diff] [blame] | 756 | Ethernet ndpRequest = buildNdp(ICMP6.NEIGHBOR_SOLICITATION, |
| 757 | MAC2, |
| 758 | MacAddress.valueOf("33:33:ff:00:00:01"), |
| 759 | theirIp, |
| 760 | ourFirstIp); |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 761 | |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 762 | proxyArp.reply(ndpRequest, LOC1); |
| 763 | assertEquals(1, packetService.packets.size()); |
| 764 | |
Jonathan Hart | d9df7bd | 2015-11-10 17:10:25 -0800 | [diff] [blame] | 765 | Ethernet ndpReply = buildNdp(ICMP6.NEIGHBOR_ADVERTISEMENT, |
| 766 | firstMac, |
| 767 | MAC2, |
| 768 | ourFirstIp, |
| 769 | theirIp); |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 770 | verifyPacketOut(ndpReply, LOC1, packetService.packets.get(0)); |
| 771 | |
| 772 | // Test a request for the second address on that port |
| 773 | packetService.packets.clear(); |
Jonathan Hart | d9df7bd | 2015-11-10 17:10:25 -0800 | [diff] [blame] | 774 | ndpRequest = buildNdp(ICMP6.NEIGHBOR_SOLICITATION, |
| 775 | MAC2, |
| 776 | MacAddress.valueOf("33:33:ff:00:00:01"), |
| 777 | theirIp, |
| 778 | ourSecondIp); |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 779 | proxyArp.reply(ndpRequest, LOC1); |
| 780 | assertEquals(1, packetService.packets.size()); |
| 781 | |
Jonathan Hart | d9df7bd | 2015-11-10 17:10:25 -0800 | [diff] [blame] | 782 | ndpReply = buildNdp(ICMP6.NEIGHBOR_ADVERTISEMENT, |
| 783 | secondMac, |
| 784 | MAC2, |
| 785 | ourSecondIp, |
| 786 | theirIp); |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 787 | verifyPacketOut(ndpReply, LOC1, packetService.packets.get(0)); |
| 788 | } |
| 789 | |
| 790 | /** |
| 791 | * Request for a valid external IPv4 address but coming in the wrong port. |
| 792 | */ |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 793 | @Test |
| 794 | public void testReplyExternalPortBadRequest() { |
| 795 | replay(hostService); // no further host service expectations |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 796 | replay(interfaceService); |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 797 | |
Pavlin Radoslavov | 5b5dc48 | 2014-11-05 14:48:08 -0800 | [diff] [blame] | 798 | Ip4Address theirIp = Ip4Address.valueOf("10.0.1.254"); |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 799 | |
| 800 | // Request for a valid external IP address but coming in the wrong port |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 801 | Ethernet arpRequest = buildArp(ARP.OP_REQUEST, VLAN1, MAC1, null, theirIp, |
Aaron Kruglikov | d812383 | 2015-07-06 14:20:25 -0700 | [diff] [blame] | 802 | Ip4Address.valueOf("10.0.3.1")); |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 803 | proxyArp.reply(arpRequest, LOC1); |
| 804 | assertEquals(0, packetService.packets.size()); |
| 805 | |
| 806 | // Request for a valid internal IP address but coming in an external port |
| 807 | packetService.packets.clear(); |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 808 | arpRequest = buildArp(ARP.OP_REQUEST, VLAN1, MAC1, null, theirIp, IP1); |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 809 | proxyArp.reply(arpRequest, LOC1); |
| 810 | assertEquals(0, packetService.packets.size()); |
| 811 | } |
| 812 | |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 813 | /** |
| 814 | * Request for a valid external IPv6 address but coming in the wrong port. |
| 815 | */ |
| 816 | @Test |
| 817 | public void testReplyExternalPortBadRequestIpv6() { |
| 818 | replay(hostService); // no further host service expectations |
| 819 | replay(interfaceService); |
| 820 | |
| 821 | Ip6Address theirIp = Ip6Address.valueOf("1000::ffff"); |
| 822 | |
Jonathan Hart | d9df7bd | 2015-11-10 17:10:25 -0800 | [diff] [blame] | 823 | Ethernet ndpRequest = buildNdp(ICMP6.NEIGHBOR_SOLICITATION, |
| 824 | MAC1, |
| 825 | MacAddress.valueOf("33:33:ff:00:00:01"), |
| 826 | theirIp, |
| 827 | Ip6Address.valueOf("3000::1")); |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 828 | proxyArp.reply(ndpRequest, LOC1); |
| 829 | assertEquals(0, packetService.packets.size()); |
| 830 | |
| 831 | // Request for a valid internal IP address but coming in an external port |
| 832 | packetService.packets.clear(); |
Jonathan Hart | d9df7bd | 2015-11-10 17:10:25 -0800 | [diff] [blame] | 833 | ndpRequest = buildNdp(ICMP6.NEIGHBOR_SOLICITATION, |
| 834 | MAC1, |
| 835 | MacAddress.valueOf("33:33:ff:00:00:01"), |
| 836 | theirIp, |
| 837 | IP3); |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 838 | proxyArp.reply(ndpRequest, LOC1); |
| 839 | assertEquals(0, packetService.packets.size()); |
| 840 | } |
| 841 | |
| 842 | /** |
| 843 | * Test ARP request from internal network to an external host. |
| 844 | */ |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 845 | @Test |
| 846 | public void testReplyToRequestFromUs() { |
Pavlin Radoslavov | 5b5dc48 | 2014-11-05 14:48:08 -0800 | [diff] [blame] | 847 | Ip4Address ourIp = Ip4Address.valueOf("10.0.1.1"); |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 848 | MacAddress ourMac = MacAddress.valueOf(1L); |
Pavlin Radoslavov | 5b5dc48 | 2014-11-05 14:48:08 -0800 | [diff] [blame] | 849 | Ip4Address theirIp = Ip4Address.valueOf("10.0.1.100"); |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 850 | |
Jonathan Hart | 7d1496b | 2015-03-10 22:00:48 -0700 | [diff] [blame] | 851 | expect(hostService.getHostsByIp(theirIp)).andReturn(Collections.emptySet()); |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 852 | expect(interfaceService.getInterfacesByIp(ourIp)) |
| 853 | .andReturn(Collections.singleton(new Interface(getLocation(1), |
Jonathan Hart | 00cddda | 2016-02-16 10:30:37 -0800 | [diff] [blame] | 854 | Collections.singletonList(new InterfaceIpAddress(ourIp, IpPrefix.valueOf("10.0.1.1/24"))), |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 855 | ourMac, VLAN1))); |
Jonathan Hart | 7d1496b | 2015-03-10 22:00:48 -0700 | [diff] [blame] | 856 | expect(hostService.getHost(HostId.hostId(ourMac, VLAN1))).andReturn(null); |
| 857 | replay(hostService); |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 858 | replay(interfaceService); |
Jonathan Hart | 7d1496b | 2015-03-10 22:00:48 -0700 | [diff] [blame] | 859 | |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 860 | // This is a request from something inside our network (like a BGP |
| 861 | // daemon) to an external host. |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 862 | Ethernet arpRequest = buildArp(ARP.OP_REQUEST, VLAN1, ourMac, null, ourIp, theirIp); |
Aaron Kruglikov | d812383 | 2015-07-06 14:20:25 -0700 | [diff] [blame] | 863 | //Ensure the packet is allowed through (it is not to an internal port) |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 864 | |
Aaron Kruglikov | d812383 | 2015-07-06 14:20:25 -0700 | [diff] [blame] | 865 | proxyArp.reply(arpRequest, getLocation(5)); |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 866 | assertEquals(1, packetService.packets.size()); |
| 867 | verifyPacketOut(arpRequest, getLocation(1), packetService.packets.get(0)); |
| 868 | |
| 869 | // The same request from a random external port should fail |
| 870 | packetService.packets.clear(); |
| 871 | proxyArp.reply(arpRequest, getLocation(2)); |
| 872 | assertEquals(0, packetService.packets.size()); |
| 873 | } |
| 874 | |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 875 | /** |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 876 | * Test NDP request from internal network to an external host. |
| 877 | */ |
| 878 | @Test |
| 879 | public void testReplyToRequestFromUsIpv6() { |
| 880 | Ip6Address ourIp = Ip6Address.valueOf("1000::1"); |
| 881 | MacAddress ourMac = MacAddress.valueOf(1L); |
| 882 | Ip6Address theirIp = Ip6Address.valueOf("1000::100"); |
| 883 | |
| 884 | expect(hostService.getHostsByIp(theirIp)).andReturn(Collections.emptySet()); |
| 885 | expect(interfaceService.getInterfacesByIp(ourIp)) |
| 886 | .andReturn(Collections.singleton(new Interface(getLocation(1), |
Jonathan Hart | 00cddda | 2016-02-16 10:30:37 -0800 | [diff] [blame] | 887 | Collections.singletonList(new InterfaceIpAddress( |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 888 | ourIp, |
| 889 | IpPrefix.valueOf("1000::1/64"))), |
| 890 | ourMac, |
| 891 | VLAN1))); |
| 892 | expect(hostService.getHost(HostId.hostId(ourMac, VLAN1))).andReturn(null); |
| 893 | replay(hostService); |
| 894 | replay(interfaceService); |
| 895 | |
| 896 | // This is a request from something inside our network (like a BGP |
| 897 | // daemon) to an external host. |
Jonathan Hart | d9df7bd | 2015-11-10 17:10:25 -0800 | [diff] [blame] | 898 | Ethernet ndpRequest = buildNdp(ICMP6.NEIGHBOR_SOLICITATION, |
| 899 | ourMac, |
| 900 | MacAddress.valueOf("33:33:ff:00:00:01"), |
| 901 | ourIp, |
| 902 | theirIp); |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 903 | |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 904 | proxyArp.reply(ndpRequest, getLocation(5)); |
| 905 | assertEquals(1, packetService.packets.size()); |
| 906 | verifyPacketOut(ndpRequest, getLocation(1), packetService.packets.get(0)); |
| 907 | |
| 908 | // The same request from a random external port should fail |
| 909 | packetService.packets.clear(); |
| 910 | proxyArp.reply(ndpRequest, getLocation(2)); |
| 911 | assertEquals(0, packetService.packets.size()); |
| 912 | } |
| 913 | |
| 914 | /** |
Jonathan Hart | 6cd2f35 | 2015-01-13 17:44:45 -0800 | [diff] [blame] | 915 | * Tests {@link ProxyArpManager#forward(Ethernet, ConnectPoint)} in the case where the |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 916 | * destination host is known. |
| 917 | * Verifies the correct ARP request is sent out the correct port. |
| 918 | */ |
| 919 | @Test |
| 920 | public void testForwardToHost() { |
| 921 | Host host1 = new DefaultHost(PID, HID1, MAC1, VLAN1, LOC1, |
Aaron Kruglikov | d812383 | 2015-07-06 14:20:25 -0700 | [diff] [blame] | 922 | Collections.singleton(IP1)); |
Thomas Vachuska | b2c47a7 | 2015-08-05 14:22:54 -0700 | [diff] [blame] | 923 | Host host2 = new DefaultHost(PID, HID2, MAC2, VLAN1, LOC2, |
| 924 | Collections.singleton(IP2)); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 925 | |
| 926 | expect(hostService.getHost(HID1)).andReturn(host1); |
Thomas Vachuska | b2c47a7 | 2015-08-05 14:22:54 -0700 | [diff] [blame] | 927 | expect(hostService.getHost(HID2)).andReturn(host2); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 928 | replay(hostService); |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 929 | replay(interfaceService); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 930 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 931 | Ethernet arpRequest = buildArp(ARP.OP_REPLY, VLAN1, MAC2, MAC1, IP2, IP1); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 932 | |
Jonathan Hart | f84591d | 2015-01-16 14:33:43 -0800 | [diff] [blame] | 933 | proxyArp.forward(arpRequest, LOC2); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 934 | |
| 935 | assertEquals(1, packetService.packets.size()); |
| 936 | OutboundPacket packet = packetService.packets.get(0); |
| 937 | |
| 938 | verifyPacketOut(arpRequest, LOC1, packet); |
| 939 | } |
| 940 | |
| 941 | /** |
Jonathan Hart | 6cd2f35 | 2015-01-13 17:44:45 -0800 | [diff] [blame] | 942 | * Tests {@link ProxyArpManager#forward(Ethernet, ConnectPoint)} in the case where the |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 943 | * destination host is known. |
| 944 | * Verifies the correct ARP request is sent out the correct port. |
| 945 | */ |
| 946 | @Test |
| 947 | public void testForwardToHostIpv6() { |
| 948 | Host host1 = new DefaultHost(PID, HID3, MAC3, VLAN1, LOC1, |
| 949 | Collections.singleton(IP3)); |
| 950 | Host host2 = new DefaultHost(PID, HID4, MAC4, VLAN1, LOC2, |
| 951 | Collections.singleton(IP4)); |
| 952 | |
| 953 | expect(hostService.getHost(SOLICITED_HID3)).andReturn(host1); |
| 954 | expect(hostService.getHost(HID4)).andReturn(host2); |
| 955 | replay(hostService); |
| 956 | replay(interfaceService); |
| 957 | |
Jonathan Hart | d9df7bd | 2015-11-10 17:10:25 -0800 | [diff] [blame] | 958 | Ethernet ndpRequest = buildNdp(ICMP6.NEIGHBOR_SOLICITATION, |
| 959 | MAC4, SOLICITED_MAC3, |
| 960 | IP4, IP3); |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 961 | |
| 962 | proxyArp.forward(ndpRequest, LOC2); |
| 963 | |
| 964 | assertEquals(1, packetService.packets.size()); |
| 965 | OutboundPacket packet = packetService.packets.get(0); |
| 966 | |
| 967 | verifyPacketOut(ndpRequest, LOC1, packet); |
| 968 | } |
| 969 | |
| 970 | /** |
| 971 | * Tests {@link ProxyArpManager#forward(Ethernet, ConnectPoint)} in the case where the |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 972 | * destination host is not known. |
| 973 | * Verifies the correct ARP request is flooded out the correct edge ports. |
| 974 | */ |
| 975 | @Test |
| 976 | public void testForwardFlood() { |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 977 | expect(hostService.getHost(HID2)).andReturn(null); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 978 | replay(hostService); |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 979 | replay(interfaceService); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 980 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 981 | Ethernet arpRequest = buildArp(ARP.OP_REPLY, VLAN1, MAC1, MAC2, IP1, IP2); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 982 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 983 | proxyArp.forward(arpRequest, getLocation(NUM_DEVICES)); |
Aaron Kruglikov | d812383 | 2015-07-06 14:20:25 -0700 | [diff] [blame] | 984 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 985 | verifyFlood(arpRequest, noConfigCPoints); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 986 | } |
| 987 | |
| 988 | /** |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 989 | * Tests {@link ProxyArpManager#forward(Ethernet, ConnectPoint)} in the case where the |
| 990 | * destination host is not known. |
| 991 | * Verifies the correct NDP request is flooded out the correct edge ports. |
| 992 | */ |
| 993 | @Test |
| 994 | public void testForwardFloodIpv6() { |
| 995 | expect(hostService.getHost(SOLICITED_HID3)).andReturn(null); |
| 996 | replay(hostService); |
| 997 | replay(interfaceService); |
| 998 | |
Jonathan Hart | d9df7bd | 2015-11-10 17:10:25 -0800 | [diff] [blame] | 999 | Ethernet ndpRequest = buildNdp(ICMP6.NEIGHBOR_SOLICITATION, |
| 1000 | MAC4, SOLICITED_MAC3, |
| 1001 | IP4, IP3); |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 1002 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 1003 | proxyArp.forward(ndpRequest, getLocation(NUM_DEVICES)); |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 1004 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 1005 | verifyFlood(ndpRequest, noConfigCPoints); |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 1006 | } |
| 1007 | |
| 1008 | /** |
Jonathan Hart | f84591d | 2015-01-16 14:33:43 -0800 | [diff] [blame] | 1009 | * Verifies that the given packet was flooded out all available edge ports, |
| 1010 | * except for the input port. |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 1011 | * |
| 1012 | * @param packet the packet that was expected to be flooded |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 1013 | * @param connectPoints the connectPoints where the outpacket should be |
| 1014 | * observed |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 1015 | */ |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 1016 | private void verifyFlood(Ethernet packet, List<ConnectPoint> connectPoints) { |
| 1017 | |
Jonathan Hart | f84591d | 2015-01-16 14:33:43 -0800 | [diff] [blame] | 1018 | // There should be 1 less than NUM_FLOOD_PORTS; the inPort should be excluded. |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 1019 | assertEquals(connectPoints.size() - 1, packetService.packets.size()); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 1020 | |
| 1021 | Collections.sort(packetService.packets, |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 1022 | (o1, o2) -> o1.sendThrough().uri().compareTo(o2.sendThrough().uri())); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 1023 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 1024 | for (int i = 0; i < connectPoints.size() - 1; i++) { |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 1025 | OutboundPacket outboundPacket = packetService.packets.get(i); |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 1026 | verifyPacketOut(packet, connectPoints.get(i), outboundPacket); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 1027 | } |
| 1028 | } |
| 1029 | |
| 1030 | /** |
| 1031 | * Verifies the given packet was sent out the given port. |
| 1032 | * |
| 1033 | * @param expected the packet that was expected to be sent |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 1034 | * @param outPort the port the packet was expected to be sent out |
| 1035 | * @param actual the actual OutboundPacket to verify |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 1036 | */ |
| 1037 | private void verifyPacketOut(Ethernet expected, ConnectPoint outPort, |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 1038 | OutboundPacket actual) { |
Yuta HIGUCHI | 3e848a8 | 2014-11-02 20:19:42 -0800 | [diff] [blame] | 1039 | assertArrayEquals(expected.serialize(), actual.data().array()); |
Ray Milkey | 4250735 | 2015-03-20 15:16:10 -0700 | [diff] [blame] | 1040 | assertEquals(1, actual.treatment().immediate().size()); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 1041 | assertEquals(outPort.deviceId(), actual.sendThrough()); |
Ray Milkey | 4250735 | 2015-03-20 15:16:10 -0700 | [diff] [blame] | 1042 | Instruction instruction = actual.treatment().immediate().get(0); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 1043 | assertTrue(instruction instanceof OutputInstruction); |
| 1044 | assertEquals(outPort.port(), ((OutputInstruction) instruction).port()); |
| 1045 | } |
| 1046 | |
| 1047 | /** |
| 1048 | * Returns the device ID of the ith device. |
| 1049 | * |
| 1050 | * @param i device to get the ID of |
| 1051 | * @return the device ID |
| 1052 | */ |
| 1053 | private static DeviceId getDeviceId(int i) { |
| 1054 | return DeviceId.deviceId("" + i); |
| 1055 | } |
| 1056 | |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 1057 | private static HostLocation getLocation(int i) { |
| 1058 | return new HostLocation(new ConnectPoint(getDeviceId(i), P1), 123L); |
| 1059 | } |
| 1060 | |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 1061 | /** |
| 1062 | * Builds an ARP packet with the given parameters. |
| 1063 | * |
| 1064 | * @param opcode opcode of the ARP packet |
| 1065 | * @param srcMac source MAC address |
| 1066 | * @param dstMac destination MAC address, or null if this is a request |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 1067 | * @param srcIp source IP address |
| 1068 | * @param dstIp destination IP address |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 1069 | * @return the ARP packet |
| 1070 | */ |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 1071 | private Ethernet buildArp(short opcode, VlanId vlanId, MacAddress srcMac, |
| 1072 | MacAddress dstMac, Ip4Address srcIp, Ip4Address dstIp) { |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 1073 | Ethernet eth = new Ethernet(); |
| 1074 | |
| 1075 | if (dstMac == null) { |
Yuta HIGUCHI | 3e848a8 | 2014-11-02 20:19:42 -0800 | [diff] [blame] | 1076 | eth.setDestinationMACAddress(MacAddress.BROADCAST); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 1077 | } else { |
Yuta HIGUCHI | 3e848a8 | 2014-11-02 20:19:42 -0800 | [diff] [blame] | 1078 | eth.setDestinationMACAddress(dstMac); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 1079 | } |
| 1080 | |
Yuta HIGUCHI | 3e848a8 | 2014-11-02 20:19:42 -0800 | [diff] [blame] | 1081 | eth.setSourceMACAddress(srcMac); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 1082 | eth.setEtherType(Ethernet.TYPE_ARP); |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 1083 | eth.setVlanID(vlanId.toShort()); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 1084 | |
| 1085 | ARP arp = new ARP(); |
| 1086 | arp.setOpCode(opcode); |
| 1087 | arp.setProtocolType(ARP.PROTO_TYPE_IP); |
| 1088 | arp.setHardwareType(ARP.HW_TYPE_ETHERNET); |
| 1089 | |
Pavlin Radoslavov | 5b5dc48 | 2014-11-05 14:48:08 -0800 | [diff] [blame] | 1090 | arp.setProtocolAddressLength((byte) Ip4Address.BYTE_LENGTH); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 1091 | arp.setHardwareAddressLength((byte) Ethernet.DATALAYER_ADDRESS_LENGTH); |
Yuta HIGUCHI | 3e848a8 | 2014-11-02 20:19:42 -0800 | [diff] [blame] | 1092 | arp.setSenderHardwareAddress(srcMac.toBytes()); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 1093 | |
| 1094 | if (dstMac == null) { |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 1095 | arp.setTargetHardwareAddress(zeroMacAddress); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 1096 | } else { |
Yuta HIGUCHI | 3e848a8 | 2014-11-02 20:19:42 -0800 | [diff] [blame] | 1097 | arp.setTargetHardwareAddress(dstMac.toBytes()); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 1098 | } |
| 1099 | |
| 1100 | arp.setSenderProtocolAddress(srcIp.toOctets()); |
| 1101 | arp.setTargetProtocolAddress(dstIp.toOctets()); |
| 1102 | |
| 1103 | eth.setPayload(arp); |
| 1104 | return eth; |
| 1105 | } |
| 1106 | |
| 1107 | /** |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 1108 | * Builds an NDP packet with the given parameters. |
| 1109 | * |
| 1110 | * @param type NeighborSolicitation or NeighborAdvertisement |
| 1111 | * @param srcMac source MAC address |
| 1112 | * @param dstMac destination MAC address, or null if this is a request |
| 1113 | * @param srcIp source IP address |
| 1114 | * @param dstIp destination IP address |
| 1115 | * @return the NDP packet |
| 1116 | */ |
Jonathan Hart | d9df7bd | 2015-11-10 17:10:25 -0800 | [diff] [blame] | 1117 | private Ethernet buildNdp(byte type, MacAddress srcMac, MacAddress dstMac, |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 1118 | Ip6Address srcIp, Ip6Address dstIp) { |
| 1119 | assertThat(type, anyOf( |
| 1120 | is(ICMP6.NEIGHBOR_SOLICITATION), |
| 1121 | is(ICMP6.NEIGHBOR_ADVERTISEMENT) |
| 1122 | )); |
| 1123 | assertNotNull(srcMac); |
| 1124 | assertNotNull(dstMac); |
| 1125 | assertNotNull(srcIp); |
| 1126 | assertNotNull(dstIp); |
| 1127 | |
| 1128 | IPacket ndp; |
| 1129 | if (type == ICMP6.NEIGHBOR_SOLICITATION) { |
| 1130 | ndp = new NeighborSolicitation().setTargetAddress(dstIp.toOctets()); |
| 1131 | } else { |
| 1132 | ndp = new NeighborAdvertisement() |
| 1133 | .setSolicitedFlag((byte) 1) |
| 1134 | .setOverrideFlag((byte) 1) |
| 1135 | .setTargetAddress(srcIp.toOctets()) |
| 1136 | .addOption(NeighborDiscoveryOptions.TYPE_TARGET_LL_ADDRESS, |
| 1137 | srcMac.toBytes()); |
| 1138 | } |
| 1139 | |
| 1140 | ICMP6 icmp6 = new ICMP6(); |
| 1141 | icmp6.setIcmpType(type); |
| 1142 | icmp6.setIcmpCode((byte) 0); |
| 1143 | icmp6.setPayload(ndp); |
| 1144 | |
| 1145 | IPv6 ipv6 = new IPv6(); |
| 1146 | ipv6.setDestinationAddress(dstIp.toOctets()); |
| 1147 | ipv6.setSourceAddress(srcIp.toOctets()); |
| 1148 | ipv6.setNextHeader(IPv6.PROTOCOL_ICMP6); |
| 1149 | ipv6.setHopLimit((byte) 255); |
| 1150 | ipv6.setPayload(icmp6); |
| 1151 | |
| 1152 | Ethernet eth = new Ethernet(); |
| 1153 | eth.setDestinationMACAddress(dstMac); |
| 1154 | eth.setSourceMACAddress(srcMac); |
| 1155 | eth.setEtherType(Ethernet.TYPE_IPV6); |
| 1156 | eth.setVlanID(VLAN1.toShort()); |
| 1157 | eth.setPayload(ipv6); |
| 1158 | |
| 1159 | return eth; |
| 1160 | } |
| 1161 | |
| 1162 | /** |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 1163 | * Test PacketService implementation that simply stores OutboundPackets |
| 1164 | * passed to {@link #emit(OutboundPacket)} for later verification. |
| 1165 | */ |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 1166 | class TestPacketService extends PacketServiceAdapter { |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 1167 | |
| 1168 | List<OutboundPacket> packets = new ArrayList<>(); |
| 1169 | |
| 1170 | @Override |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 1171 | public void emit(OutboundPacket packet) { |
| 1172 | packets.add(packet); |
| 1173 | } |
Jonathan Hart | 3cfce8e | 2015-01-14 16:43:27 -0800 | [diff] [blame] | 1174 | |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 1175 | } |
Aaron Kruglikov | d812383 | 2015-07-06 14:20:25 -0700 | [diff] [blame] | 1176 | |
Thomas Vachuska | b2c47a7 | 2015-08-05 14:22:54 -0700 | [diff] [blame] | 1177 | private class TestProxyArpStoreAdapter implements ProxyArpStore { |
| 1178 | @Override |
| 1179 | public void forward(ConnectPoint outPort, Host subject, ByteBuffer packet) { |
| 1180 | TrafficTreatment tt = DefaultTrafficTreatment.builder().setOutput(outPort.port()).build(); |
| 1181 | packetService.emit(new DefaultOutboundPacket(outPort.deviceId(), tt, packet)); |
| 1182 | } |
| 1183 | |
| 1184 | @Override |
| 1185 | public void setDelegate(ProxyArpStoreDelegate delegate) { |
| 1186 | } |
| 1187 | } |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 1188 | } |