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 |
Sho SHIMIZU | 891162b | 2016-06-06 16:32:01 -0700 | [diff] [blame^] | 299 | Interface intf1 = new Interface(Interface.NO_INTERFACE_NAME, cp, |
| 300 | Lists.newArrayList(ia1, ia3), MacAddress.valueOf(2 * i - 1), VlanId.vlanId((short) 1)); |
| 301 | Interface intf2 = new Interface(Interface.NO_INTERFACE_NAME, cp, |
| 302 | Lists.newArrayList(ia2, ia4), MacAddress.valueOf(2 * i), VlanId.NONE); |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 303 | |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 304 | interfaces.add(intf1); |
| 305 | interfaces.add(intf2); |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 306 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 307 | vlanOneSet.add(intf1); |
| 308 | |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 309 | expect(interfaceService.getInterfacesByPort(cp)) |
| 310 | .andReturn(Sets.newHashSet(intf1, intf2)).anyTimes(); |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 311 | } |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 312 | for (int i = LAST_CONF_DEVICE_INTF_VLAN_IP + 1; i <= LAST_CONF_DEVICE_INTF_VLAN; i++) { |
| 313 | ConnectPoint cp = new ConnectPoint(getDeviceId(i), P1); |
Sho SHIMIZU | 891162b | 2016-06-06 16:32:01 -0700 | [diff] [blame^] | 314 | Interface intf1 = new Interface(Interface.NO_INTERFACE_NAME, cp, Collections.emptyList(), |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 315 | MacAddress.NONE, |
| 316 | VlanId.vlanId((short) 1)); |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 317 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 318 | interfaces.add(intf1); |
| 319 | vlanOneSet.add(intf1); |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 320 | |
| 321 | expect(interfaceService.getInterfacesByPort(cp)) |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 322 | .andReturn(Sets.newHashSet(intf1)).anyTimes(); |
| 323 | } |
| 324 | expect(interfaceService.getInterfacesByVlan(VLAN1)) |
| 325 | .andReturn(vlanOneSet).anyTimes(); |
| 326 | expect(interfaceService.getInterfacesByVlan(VLAN10)) |
| 327 | .andReturn(Collections.emptySet()).anyTimes(); |
| 328 | expect(interfaceService.getInterfaces()).andReturn(interfaces).anyTimes(); |
| 329 | |
| 330 | for (int i = LAST_CONF_DEVICE_INTF_VLAN + 1; i <= NUM_DEVICES; i++) { |
| 331 | ConnectPoint cp = new ConnectPoint(getDeviceId(i), |
| 332 | P1); |
| 333 | expect(interfaceService.getInterfacesByPort(cp)) |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 334 | .andReturn(Collections.emptySet()).anyTimes(); |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 335 | } |
| 336 | } |
| 337 | |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 338 | /** |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 339 | * Populates edge ports in the EdgePortService to return all port 1 |
| 340 | * as edge ports. |
| 341 | */ |
| 342 | private void popluateEdgePortService() { |
| 343 | Set<ConnectPoint> edgeConnectPoints = new HashSet<>(); |
| 344 | |
| 345 | for (int i = 1; i <= NUM_DEVICES; i++) { |
| 346 | for (int j = 1; j <= NUM_PORTS_PER_DEVICE; j++) { |
| 347 | ConnectPoint edgeConnectPoint = new ConnectPoint( |
| 348 | getDeviceId(i), |
| 349 | PortNumber.portNumber(1)); |
| 350 | ConnectPoint noEdgeConnectPointOne = new ConnectPoint( |
| 351 | getDeviceId(i), |
| 352 | PortNumber.portNumber(2)); |
| 353 | ConnectPoint noEdgeConnectPointTwo = new ConnectPoint( |
| 354 | getDeviceId(i), |
| 355 | PortNumber.portNumber(3)); |
| 356 | |
| 357 | edgeConnectPoints.add(edgeConnectPoint); |
| 358 | |
| 359 | expect(edgePortService.isEdgePoint(edgeConnectPoint)) |
| 360 | .andReturn(true).anyTimes(); |
| 361 | expect(edgePortService.isEdgePoint(noEdgeConnectPointOne)) |
| 362 | .andReturn(false).anyTimes(); |
| 363 | expect(edgePortService.isEdgePoint(noEdgeConnectPointTwo)) |
| 364 | .andReturn(false).anyTimes(); |
| 365 | } |
| 366 | } |
| 367 | expect(edgePortService.getEdgePoints()) |
| 368 | .andReturn(edgeConnectPoints).anyTimes(); |
| 369 | |
| 370 | replay(edgePortService); |
| 371 | } |
| 372 | |
| 373 | /** |
| 374 | * Creates a list of connect points used to verify floodling on ports |
| 375 | * with no interfaces configured (all ports without interface config). |
| 376 | */ |
| 377 | private void setupNoConfigCPoints() { |
| 378 | for (int i = NUM_DEVICES / 2 + 2; i <= NUM_DEVICES; i++) { |
| 379 | ConnectPoint connectPoint = new ConnectPoint( |
| 380 | getDeviceId(i), |
| 381 | PortNumber.portNumber(1)); |
| 382 | noConfigCPoints.add(connectPoint); |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | /** |
| 387 | * Creates a list of connect points used to verify floodling on ports |
| 388 | * with interfaces configured (both VLAN and IP). |
| 389 | */ |
| 390 | private void setupconfigIpCPoints() { |
| 391 | for (int i = 1; i <= 3; i++) { |
| 392 | ConnectPoint connectPoint = new ConnectPoint( |
| 393 | getDeviceId(i), |
| 394 | PortNumber.portNumber(1)); |
| 395 | configIpCPoints.add(connectPoint); |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | /** |
| 400 | * Creates a list of connect points used to verify floodling on ports |
| 401 | * with interfaces configured (both VLAN and IP). |
| 402 | */ |
| 403 | private void setupconfigVlanCPoints() { |
| 404 | for (int i = LAST_CONF_DEVICE_INTF_VLAN_IP + 1; i <= LAST_CONF_DEVICE_INTF_VLAN; i++) { |
| 405 | ConnectPoint connectPoint = new ConnectPoint( |
| 406 | getDeviceId(i), |
| 407 | PortNumber.portNumber(1)); |
| 408 | configVlanCPoints.add(connectPoint); |
| 409 | } |
| 410 | } |
| 411 | |
| 412 | /** |
Jonathan Hart | 7d1496b | 2015-03-10 22:00:48 -0700 | [diff] [blame] | 413 | * Tests {@link ProxyArpManager#isKnown(org.onlab.packet.IpAddress)} in the |
| 414 | * case where the IP address is not known. |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 415 | * Verifies the method returns false. |
| 416 | */ |
| 417 | @Test |
| 418 | public void testNotKnown() { |
| 419 | expect(hostService.getHostsByIp(IP1)).andReturn(Collections.<Host>emptySet()); |
| 420 | replay(hostService); |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 421 | replay(interfaceService); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 422 | |
Jonathan Hart | f84591d | 2015-01-16 14:33:43 -0800 | [diff] [blame] | 423 | assertFalse(proxyArp.isKnown(IP1)); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 424 | } |
| 425 | |
| 426 | /** |
Jonathan Hart | 7d1496b | 2015-03-10 22:00:48 -0700 | [diff] [blame] | 427 | * Tests {@link ProxyArpManager#isKnown(org.onlab.packet.IpAddress)} in the |
| 428 | * case where the IP address is known. |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 429 | * Verifies the method returns true. |
| 430 | */ |
| 431 | @Test |
| 432 | public void testKnown() { |
| 433 | Host host1 = createMock(Host.class); |
| 434 | Host host2 = createMock(Host.class); |
| 435 | |
| 436 | expect(hostService.getHostsByIp(IP1)) |
| 437 | .andReturn(Sets.newHashSet(host1, host2)); |
| 438 | replay(hostService); |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 439 | replay(interfaceService); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 440 | |
Jonathan Hart | f84591d | 2015-01-16 14:33:43 -0800 | [diff] [blame] | 441 | assertTrue(proxyArp.isKnown(IP1)); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | /** |
Jonathan Hart | 6cd2f35 | 2015-01-13 17:44:45 -0800 | [diff] [blame] | 445 | * Tests {@link ProxyArpManager#reply(Ethernet, ConnectPoint)} in the case where the |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 446 | * destination host is known. |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 447 | * Two host using the same VLAN are registered on the host service on devices 5 and 6. |
| 448 | * Host on port 6 asks for the MAC of the device on port 5. |
| 449 | * Since the destination mac address is known, the request is not flooded to anywhere |
| 450 | * and ONOS directly builds an ARP reply, sended back to the requester on device 6. |
| 451 | * 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] | 452 | */ |
| 453 | @Test |
| 454 | public void testReplyKnown() { |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 455 | Host requestor = new DefaultHost(PID, HID1, MAC1, VLAN1, getLocation(NUM_DEVICES), |
Aaron Kruglikov | d812383 | 2015-07-06 14:20:25 -0700 | [diff] [blame] | 456 | Collections.singleton(IP1)); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 457 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 458 | Host replyer = new DefaultHost(PID, HID2, MAC2, VLAN1, getLocation(NUM_DEVICES - 1), |
Aaron Kruglikov | d812383 | 2015-07-06 14:20:25 -0700 | [diff] [blame] | 459 | Collections.singleton(IP2)); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 460 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 461 | expect(hostService.getHostsByIp(IP2)) |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 462 | .andReturn(Collections.singleton(replyer)); |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 463 | expect(hostService.getHost(HID1)).andReturn(requestor); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 464 | |
| 465 | replay(hostService); |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 466 | replay(interfaceService); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 467 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 468 | Ethernet arpRequest = buildArp(ARP.OP_REQUEST, VLAN1, MAC1, null, IP1, IP2); |
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 | proxyArp.reply(arpRequest, getLocation(NUM_DEVICES)); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 471 | |
| 472 | assertEquals(1, packetService.packets.size()); |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 473 | Ethernet arpReply = buildArp(ARP.OP_REPLY, VLAN1, MAC2, MAC1, IP2, IP1); |
| 474 | verifyPacketOut(arpReply, getLocation(NUM_DEVICES), packetService.packets.get(0)); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | /** |
Jonathan Hart | 6cd2f35 | 2015-01-13 17:44:45 -0800 | [diff] [blame] | 478 | * Tests {@link ProxyArpManager#reply(Ethernet, ConnectPoint)} in the case where the |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 479 | * destination host is known. |
| 480 | * Verifies the correct NDP reply is sent out the correct port. |
| 481 | */ |
| 482 | @Test |
| 483 | public void testReplyKnownIpv6() { |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 484 | Host replyer = new DefaultHost(PID, HID3, MAC3, VLAN1, getLocation(4), |
| 485 | Collections.singleton(IP3)); |
| 486 | |
| 487 | Host requestor = new DefaultHost(PID, HID4, MAC4, VLAN1, getLocation(5), |
| 488 | Collections.singleton(IP4)); |
| 489 | |
| 490 | expect(hostService.getHostsByIp(IP3)) |
| 491 | .andReturn(Collections.singleton(replyer)); |
| 492 | expect(hostService.getHost(HID4)).andReturn(requestor); |
| 493 | |
| 494 | replay(hostService); |
| 495 | replay(interfaceService); |
| 496 | |
Jonathan Hart | d9df7bd | 2015-11-10 17:10:25 -0800 | [diff] [blame] | 497 | Ethernet ndpRequest = buildNdp(ICMP6.NEIGHBOR_SOLICITATION, |
| 498 | MAC4, SOLICITED_MAC3, |
| 499 | IP4, IP3); |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 500 | |
| 501 | proxyArp.reply(ndpRequest, getLocation(5)); |
| 502 | |
| 503 | assertEquals(1, packetService.packets.size()); |
Jonathan Hart | d9df7bd | 2015-11-10 17:10:25 -0800 | [diff] [blame] | 504 | Ethernet ndpReply = buildNdp(ICMP6.NEIGHBOR_ADVERTISEMENT, |
| 505 | MAC3, MAC4, IP3, IP4); |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 506 | verifyPacketOut(ndpReply, getLocation(5), packetService.packets.get(0)); |
| 507 | } |
| 508 | |
| 509 | /** |
| 510 | * Tests {@link ProxyArpManager#reply(Ethernet, ConnectPoint)} in the case where the |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 511 | * destination host is not known. |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 512 | * Only a requestor is present (on device 6, port 1). The device has a VLAN configured |
| 513 | * which is not configured anywhere in the system. |
| 514 | * Since the destination is not known, and since the ARP request can't be sent out of |
| 515 | * 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] | 516 | * Verifies the ARP request is flooded out the correct edge ports. |
| 517 | */ |
| 518 | @Test |
| 519 | public void testReplyUnknown() { |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 520 | Host requestor = new DefaultHost(PID, HID10, MAC10, VLAN10, getLocation(NUM_DEVICES), |
| 521 | Collections.singleton(IP1)); |
Aaron Kruglikov | d812383 | 2015-07-06 14:20:25 -0700 | [diff] [blame] | 522 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 523 | expect(hostService.getHostsByIp(IP2)) |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 524 | .andReturn(Collections.emptySet()); |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 525 | expect(interfaceService.getInterfacesByIp(IP1)) |
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(hostService.getHost(HID10)).andReturn(requestor); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 528 | |
| 529 | replay(hostService); |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 530 | replay(interfaceService); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 531 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 532 | Ethernet arpRequest = buildArp(ARP.OP_REQUEST, VLAN10, MAC10, null, IP1, IP2); |
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 | proxyArp.reply(arpRequest, getLocation(NUM_DEVICES)); |
Aaron Kruglikov | d812383 | 2015-07-06 14:20:25 -0700 | [diff] [blame] | 535 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 536 | verifyFlood(arpRequest, noConfigCPoints); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | /** |
Jonathan Hart | 6cd2f35 | 2015-01-13 17:44:45 -0800 | [diff] [blame] | 540 | * Tests {@link ProxyArpManager#reply(Ethernet, ConnectPoint)} in the case where the |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 541 | * destination host is not known. |
| 542 | * Verifies the NDP request is flooded out the correct edge ports. |
| 543 | */ |
| 544 | @Test |
| 545 | public void testReplyUnknownIpv6() { |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 546 | Host requestor = new DefaultHost(PID, HID4, MAC4, VLAN1, getLocation(NUM_DEVICES), |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 547 | Collections.singleton(IP4)); |
| 548 | |
| 549 | expect(hostService.getHostsByIp(IP3)) |
| 550 | .andReturn(Collections.emptySet()); |
| 551 | expect(interfaceService.getInterfacesByIp(IP4)) |
| 552 | .andReturn(Collections.emptySet()); |
| 553 | expect(hostService.getHost(HID4)).andReturn(requestor); |
| 554 | |
| 555 | replay(hostService); |
| 556 | replay(interfaceService); |
| 557 | |
Jonathan Hart | d9df7bd | 2015-11-10 17:10:25 -0800 | [diff] [blame] | 558 | Ethernet ndpRequest = buildNdp(ICMP6.NEIGHBOR_SOLICITATION, |
| 559 | MAC4, SOLICITED_MAC3, |
| 560 | IP4, IP3); |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 561 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 562 | proxyArp.reply(ndpRequest, getLocation(NUM_DEVICES)); |
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 | verifyFlood(ndpRequest, noConfigCPoints); |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | /** |
| 568 | * Tests {@link ProxyArpManager#reply(Ethernet, ConnectPoint)} in the case where the |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 569 | * destination host is known for that IP address, but is not on the same |
| 570 | * VLAN as the source host. |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 571 | * An host is connected on device 6, port 1 where no interfaces are defined. It sends |
| 572 | * ARP requests from VLAN10, not configured anywhere in the network. Another host with |
| 573 | * the IP address requested lives on device 5, port 1 in the network. Anyway, since the |
| 574 | * host uses another VLAN it's not found and the ARP packet is flooded out of port |
| 575 | * 4 and 5. |
| 576 | * |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 577 | * Verifies the ARP request is flooded out the correct edge ports. |
| 578 | */ |
| 579 | @Test |
| 580 | public void testReplyDifferentVlan() { |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 581 | Host requestor = new DefaultHost(PID, HID10, MAC10, VLAN10, getLocation(NUM_DEVICES), |
Aaron Kruglikov | d812383 | 2015-07-06 14:20:25 -0700 | [diff] [blame] | 582 | Collections.singleton(IP1)); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 583 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 584 | Host replyer = new DefaultHost(PID, HID2, MAC2, VLAN2, getLocation(NUM_DEVICES - 1), |
Aaron Kruglikov | d812383 | 2015-07-06 14:20:25 -0700 | [diff] [blame] | 585 | Collections.singleton(IP2)); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 586 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 587 | expect(hostService.getHostsByIp(IP2)) |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 588 | .andReturn(Collections.singleton(replyer)); |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 589 | expect(interfaceService.getInterfacesByIp(IP1)) |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 590 | .andReturn(Collections.emptySet()); |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 591 | expect(hostService.getHost(HID10)).andReturn(requestor); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 592 | |
| 593 | replay(hostService); |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 594 | replay(interfaceService); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 595 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 596 | Ethernet arpRequest = buildArp(ARP.OP_REQUEST, VLAN10, MAC10, null, IP1, IP2); |
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 | proxyArp.reply(arpRequest, getLocation(NUM_DEVICES)); |
| 599 | |
| 600 | verifyFlood(arpRequest, noConfigCPoints); |
| 601 | } |
| 602 | |
| 603 | /** |
| 604 | * Tests {@link ProxyArpManager#reply(Ethernet, ConnectPoint)} in the case where the |
| 605 | * a vlan packet comes in from a port without interfaces configured. The destination |
| 606 | * host is unknown for that IP address and there are some interfaces configured on |
| 607 | * the same vlan. |
| 608 | * It's expected to see the ARP request going out through ports with no interfaces |
| 609 | * configured, devices 4 and 5, port 1. |
| 610 | * |
| 611 | * Verifies the ARP request is flooded out the correct edge ports. |
| 612 | */ |
| 613 | @Test |
| 614 | public void testConfiguredVlan() { |
| 615 | Host requestor = new DefaultHost(PID, HID1, MAC1, VLAN1, getLocation(NUM_DEVICES), |
| 616 | Collections.singleton(IP1)); |
| 617 | |
| 618 | expect(hostService.getHostsByIp(IP2)) |
| 619 | .andReturn(Collections.emptySet()); |
| 620 | expect(interfaceService.getInterfacesByIp(IP1)) |
| 621 | .andReturn(Collections.emptySet()); |
| 622 | expect(hostService.getHost(HID1)).andReturn(requestor); |
| 623 | |
| 624 | replay(hostService); |
| 625 | replay(interfaceService); |
| 626 | |
| 627 | Ethernet arpRequest = buildArp(ARP.OP_REQUEST, VLAN1, MAC1, null, IP1, IP2); |
| 628 | |
| 629 | proxyArp.reply(arpRequest, getLocation(NUM_DEVICES)); |
| 630 | |
| 631 | verifyFlood(arpRequest, noConfigCPoints); |
| 632 | } |
| 633 | |
| 634 | /** |
| 635 | * Tests {@link ProxyArpManager#reply(Ethernet, ConnectPoint)} in the case where the |
| 636 | * a vlan packet comes in from a port without interfaces configured. The destination |
| 637 | * host is not known for that IP address and there are some interfaces configured on |
| 638 | * the same vlan. |
| 639 | * It's expected to see the ARP request going out through ports with no interfaces |
| 640 | * configured, devices 4 and 5, port 1. |
| 641 | * |
| 642 | * Verifies the ARP request is flooded out the correct edge ports. |
| 643 | */ |
| 644 | @Test |
| 645 | public void testConfiguredVlanOnInterfaces() { |
| 646 | Host requestor = new DefaultHost(PID, HID1, MAC1, VLAN1, getLocation(6), |
| 647 | Collections.singleton(IP1)); |
| 648 | |
| 649 | expect(hostService.getHostsByIp(IP2)) |
| 650 | .andReturn(Collections.emptySet()); |
| 651 | expect(interfaceService.getInterfacesByIp(IP1)) |
| 652 | .andReturn(Collections.emptySet()); |
| 653 | expect(hostService.getHost(HID1)).andReturn(requestor); |
| 654 | |
| 655 | replay(hostService); |
| 656 | replay(interfaceService); |
| 657 | |
| 658 | Ethernet arpRequest = buildArp(ARP.OP_REQUEST, VLAN1, MAC1, null, IP1, IP2); |
| 659 | |
Jonathan Hart | f84591d | 2015-01-16 14:33:43 -0800 | [diff] [blame] | 660 | proxyArp.reply(arpRequest, getLocation(6)); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 661 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 662 | verifyFlood(arpRequest, configVlanCPoints); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 663 | } |
| 664 | |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 665 | /** |
| 666 | * Tests {@link ProxyArpManager#reply(Ethernet, ConnectPoint)} in the case where the |
| 667 | * destination host is known for that IP address, but is not on the same |
| 668 | * VLAN as the source host. |
| 669 | * Verifies the NDP request is flooded out the correct edge ports. |
| 670 | */ |
| 671 | @Test |
| 672 | public void testReplyDifferentVlanIpv6() { |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 673 | Host requestor = new DefaultHost(PID, HID4, MAC4, VLAN1, getLocation(NUM_DEVICES), |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 674 | Collections.singleton(IP4)); |
| 675 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 676 | Host replyer = new DefaultHost(PID, HID3, MAC3, VLAN2, getLocation(NUM_DEVICES - 1), |
| 677 | Collections.singleton(IP3)); |
| 678 | |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 679 | expect(hostService.getHostsByIp(IP3)) |
| 680 | .andReturn(Collections.singleton(replyer)); |
| 681 | expect(interfaceService.getInterfacesByIp(IP4)) |
| 682 | .andReturn(Collections.emptySet()); |
| 683 | expect(hostService.getHost(HID4)).andReturn(requestor); |
| 684 | |
| 685 | replay(hostService); |
| 686 | replay(interfaceService); |
| 687 | |
Jonathan Hart | d9df7bd | 2015-11-10 17:10:25 -0800 | [diff] [blame] | 688 | Ethernet ndpRequest = buildNdp(ICMP6.NEIGHBOR_SOLICITATION, |
| 689 | MAC4, SOLICITED_MAC3, |
| 690 | IP4, IP3); |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 691 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 692 | proxyArp.reply(ndpRequest, getLocation(NUM_DEVICES)); |
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 | verifyFlood(ndpRequest, noConfigCPoints); |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 695 | } |
| 696 | |
| 697 | /** |
| 698 | * Test ARP request from external network to an internal host. |
| 699 | */ |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 700 | @Test |
| 701 | public void testReplyToRequestForUs() { |
Pavlin Radoslavov | 5b5dc48 | 2014-11-05 14:48:08 -0800 | [diff] [blame] | 702 | Ip4Address theirIp = Ip4Address.valueOf("10.0.1.254"); |
| 703 | Ip4Address ourFirstIp = Ip4Address.valueOf("10.0.1.1"); |
| 704 | Ip4Address ourSecondIp = Ip4Address.valueOf("10.0.2.1"); |
Jonathan Hart | a887ba8 | 2014-11-03 15:20:52 -0800 | [diff] [blame] | 705 | MacAddress firstMac = MacAddress.valueOf(1L); |
| 706 | MacAddress secondMac = MacAddress.valueOf(2L); |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 707 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 708 | Host requestor = new DefaultHost(PID, HID1, MAC1, VLAN1, LOC1, |
Aaron Kruglikov | d812383 | 2015-07-06 14:20:25 -0700 | [diff] [blame] | 709 | Collections.singleton(theirIp)); |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 710 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 711 | expect(hostService.getHost(HID1)).andReturn(requestor); |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 712 | replay(hostService); |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 713 | replay(interfaceService); |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 714 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 715 | Ethernet arpRequest = buildArp(ARP.OP_REQUEST, VLAN1, MAC1, null, theirIp, ourFirstIp); |
| 716 | |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 717 | proxyArp.reply(arpRequest, LOC1); |
| 718 | |
| 719 | assertEquals(1, packetService.packets.size()); |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 720 | Ethernet arpReply = buildArp(ARP.OP_REPLY, VLAN1, firstMac, MAC1, ourFirstIp, theirIp); |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 721 | verifyPacketOut(arpReply, LOC1, packetService.packets.get(0)); |
| 722 | |
| 723 | // Test a request for the second address on that port |
| 724 | packetService.packets.clear(); |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 725 | arpRequest = buildArp(ARP.OP_REQUEST, VLAN1, MAC1, null, theirIp, ourSecondIp); |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 726 | |
| 727 | proxyArp.reply(arpRequest, LOC1); |
| 728 | |
| 729 | assertEquals(1, packetService.packets.size()); |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 730 | arpReply = buildArp(ARP.OP_REPLY, VLAN1, secondMac, MAC1, ourSecondIp, theirIp); |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 731 | verifyPacketOut(arpReply, LOC1, packetService.packets.get(0)); |
| 732 | } |
| 733 | |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 734 | /** |
| 735 | * Test NDP request from external network to an internal host. |
| 736 | */ |
| 737 | @Test |
| 738 | public void testReplyToRequestForUsIpv6() { |
| 739 | Ip6Address theirIp = Ip6Address.valueOf("1000::ffff"); |
| 740 | Ip6Address ourFirstIp = Ip6Address.valueOf("1000::1"); |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 741 | Ip6Address ourSecondIp = Ip6Address.valueOf("2000::2"); |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 742 | MacAddress firstMac = MacAddress.valueOf(1L); |
| 743 | MacAddress secondMac = MacAddress.valueOf(2L); |
| 744 | |
| 745 | Host requestor = new DefaultHost(PID, HID2, MAC2, VLAN1, LOC1, |
| 746 | Collections.singleton(theirIp)); |
| 747 | |
| 748 | expect(hostService.getHost(HID2)).andReturn(requestor); |
| 749 | expect(hostService.getHostsByIp(ourFirstIp)) |
| 750 | .andReturn(Collections.singleton(requestor)); |
| 751 | replay(hostService); |
| 752 | replay(interfaceService); |
| 753 | |
Jonathan Hart | d9df7bd | 2015-11-10 17:10:25 -0800 | [diff] [blame] | 754 | Ethernet ndpRequest = buildNdp(ICMP6.NEIGHBOR_SOLICITATION, |
| 755 | MAC2, |
| 756 | MacAddress.valueOf("33:33:ff:00:00:01"), |
| 757 | theirIp, |
| 758 | ourFirstIp); |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 759 | |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 760 | proxyArp.reply(ndpRequest, LOC1); |
| 761 | assertEquals(1, packetService.packets.size()); |
| 762 | |
Jonathan Hart | d9df7bd | 2015-11-10 17:10:25 -0800 | [diff] [blame] | 763 | Ethernet ndpReply = buildNdp(ICMP6.NEIGHBOR_ADVERTISEMENT, |
| 764 | firstMac, |
| 765 | MAC2, |
| 766 | ourFirstIp, |
| 767 | theirIp); |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 768 | verifyPacketOut(ndpReply, LOC1, packetService.packets.get(0)); |
| 769 | |
| 770 | // Test a request for the second address on that port |
| 771 | packetService.packets.clear(); |
Jonathan Hart | d9df7bd | 2015-11-10 17:10:25 -0800 | [diff] [blame] | 772 | ndpRequest = buildNdp(ICMP6.NEIGHBOR_SOLICITATION, |
| 773 | MAC2, |
| 774 | MacAddress.valueOf("33:33:ff:00:00:01"), |
| 775 | theirIp, |
| 776 | ourSecondIp); |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 777 | proxyArp.reply(ndpRequest, LOC1); |
| 778 | assertEquals(1, packetService.packets.size()); |
| 779 | |
Jonathan Hart | d9df7bd | 2015-11-10 17:10:25 -0800 | [diff] [blame] | 780 | ndpReply = buildNdp(ICMP6.NEIGHBOR_ADVERTISEMENT, |
| 781 | secondMac, |
| 782 | MAC2, |
| 783 | ourSecondIp, |
| 784 | theirIp); |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 785 | verifyPacketOut(ndpReply, LOC1, packetService.packets.get(0)); |
| 786 | } |
| 787 | |
| 788 | /** |
| 789 | * Request for a valid external IPv4 address but coming in the wrong port. |
| 790 | */ |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 791 | @Test |
| 792 | public void testReplyExternalPortBadRequest() { |
| 793 | replay(hostService); // no further host service expectations |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 794 | replay(interfaceService); |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 795 | |
Pavlin Radoslavov | 5b5dc48 | 2014-11-05 14:48:08 -0800 | [diff] [blame] | 796 | Ip4Address theirIp = Ip4Address.valueOf("10.0.1.254"); |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 797 | |
| 798 | // 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] | 799 | Ethernet arpRequest = buildArp(ARP.OP_REQUEST, VLAN1, MAC1, null, theirIp, |
Aaron Kruglikov | d812383 | 2015-07-06 14:20:25 -0700 | [diff] [blame] | 800 | Ip4Address.valueOf("10.0.3.1")); |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 801 | proxyArp.reply(arpRequest, LOC1); |
| 802 | assertEquals(0, packetService.packets.size()); |
| 803 | |
| 804 | // Request for a valid internal IP address but coming in an external port |
| 805 | packetService.packets.clear(); |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 806 | arpRequest = buildArp(ARP.OP_REQUEST, VLAN1, MAC1, null, theirIp, IP1); |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 807 | proxyArp.reply(arpRequest, LOC1); |
| 808 | assertEquals(0, packetService.packets.size()); |
| 809 | } |
| 810 | |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 811 | /** |
| 812 | * Request for a valid external IPv6 address but coming in the wrong port. |
| 813 | */ |
| 814 | @Test |
| 815 | public void testReplyExternalPortBadRequestIpv6() { |
| 816 | replay(hostService); // no further host service expectations |
| 817 | replay(interfaceService); |
| 818 | |
| 819 | Ip6Address theirIp = Ip6Address.valueOf("1000::ffff"); |
| 820 | |
Jonathan Hart | d9df7bd | 2015-11-10 17:10:25 -0800 | [diff] [blame] | 821 | Ethernet ndpRequest = buildNdp(ICMP6.NEIGHBOR_SOLICITATION, |
| 822 | MAC1, |
| 823 | MacAddress.valueOf("33:33:ff:00:00:01"), |
| 824 | theirIp, |
| 825 | Ip6Address.valueOf("3000::1")); |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 826 | proxyArp.reply(ndpRequest, LOC1); |
| 827 | assertEquals(0, packetService.packets.size()); |
| 828 | |
| 829 | // Request for a valid internal IP address but coming in an external port |
| 830 | packetService.packets.clear(); |
Jonathan Hart | d9df7bd | 2015-11-10 17:10:25 -0800 | [diff] [blame] | 831 | ndpRequest = buildNdp(ICMP6.NEIGHBOR_SOLICITATION, |
| 832 | MAC1, |
| 833 | MacAddress.valueOf("33:33:ff:00:00:01"), |
| 834 | theirIp, |
| 835 | IP3); |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 836 | proxyArp.reply(ndpRequest, LOC1); |
| 837 | assertEquals(0, packetService.packets.size()); |
| 838 | } |
| 839 | |
| 840 | /** |
| 841 | * Test ARP request from internal network to an external host. |
| 842 | */ |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 843 | @Test |
| 844 | public void testReplyToRequestFromUs() { |
Pavlin Radoslavov | 5b5dc48 | 2014-11-05 14:48:08 -0800 | [diff] [blame] | 845 | Ip4Address ourIp = Ip4Address.valueOf("10.0.1.1"); |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 846 | MacAddress ourMac = MacAddress.valueOf(1L); |
Pavlin Radoslavov | 5b5dc48 | 2014-11-05 14:48:08 -0800 | [diff] [blame] | 847 | Ip4Address theirIp = Ip4Address.valueOf("10.0.1.100"); |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 848 | |
Jonathan Hart | 7d1496b | 2015-03-10 22:00:48 -0700 | [diff] [blame] | 849 | expect(hostService.getHostsByIp(theirIp)).andReturn(Collections.emptySet()); |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 850 | expect(interfaceService.getInterfacesByIp(ourIp)) |
Sho SHIMIZU | 891162b | 2016-06-06 16:32:01 -0700 | [diff] [blame^] | 851 | .andReturn(Collections.singleton(new Interface(Interface.NO_INTERFACE_NAME, getLocation(1), |
Jonathan Hart | 00cddda | 2016-02-16 10:30:37 -0800 | [diff] [blame] | 852 | Collections.singletonList(new InterfaceIpAddress(ourIp, IpPrefix.valueOf("10.0.1.1/24"))), |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 853 | ourMac, VLAN1))); |
Jonathan Hart | 7d1496b | 2015-03-10 22:00:48 -0700 | [diff] [blame] | 854 | expect(hostService.getHost(HostId.hostId(ourMac, VLAN1))).andReturn(null); |
| 855 | replay(hostService); |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 856 | replay(interfaceService); |
Jonathan Hart | 7d1496b | 2015-03-10 22:00:48 -0700 | [diff] [blame] | 857 | |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 858 | // This is a request from something inside our network (like a BGP |
| 859 | // daemon) to an external host. |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 860 | Ethernet arpRequest = buildArp(ARP.OP_REQUEST, VLAN1, ourMac, null, ourIp, theirIp); |
Aaron Kruglikov | d812383 | 2015-07-06 14:20:25 -0700 | [diff] [blame] | 861 | //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] | 862 | |
Aaron Kruglikov | d812383 | 2015-07-06 14:20:25 -0700 | [diff] [blame] | 863 | proxyArp.reply(arpRequest, getLocation(5)); |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 864 | assertEquals(1, packetService.packets.size()); |
| 865 | verifyPacketOut(arpRequest, getLocation(1), packetService.packets.get(0)); |
| 866 | |
| 867 | // The same request from a random external port should fail |
| 868 | packetService.packets.clear(); |
| 869 | proxyArp.reply(arpRequest, getLocation(2)); |
| 870 | assertEquals(0, packetService.packets.size()); |
| 871 | } |
| 872 | |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 873 | /** |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 874 | * Test NDP request from internal network to an external host. |
| 875 | */ |
| 876 | @Test |
| 877 | public void testReplyToRequestFromUsIpv6() { |
| 878 | Ip6Address ourIp = Ip6Address.valueOf("1000::1"); |
| 879 | MacAddress ourMac = MacAddress.valueOf(1L); |
| 880 | Ip6Address theirIp = Ip6Address.valueOf("1000::100"); |
| 881 | |
| 882 | expect(hostService.getHostsByIp(theirIp)).andReturn(Collections.emptySet()); |
| 883 | expect(interfaceService.getInterfacesByIp(ourIp)) |
Sho SHIMIZU | 891162b | 2016-06-06 16:32:01 -0700 | [diff] [blame^] | 884 | .andReturn(Collections.singleton(new Interface(Interface.NO_INTERFACE_NAME, getLocation(1), |
Jonathan Hart | 00cddda | 2016-02-16 10:30:37 -0800 | [diff] [blame] | 885 | Collections.singletonList(new InterfaceIpAddress( |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 886 | ourIp, |
| 887 | IpPrefix.valueOf("1000::1/64"))), |
| 888 | ourMac, |
| 889 | VLAN1))); |
| 890 | expect(hostService.getHost(HostId.hostId(ourMac, VLAN1))).andReturn(null); |
| 891 | replay(hostService); |
| 892 | replay(interfaceService); |
| 893 | |
| 894 | // This is a request from something inside our network (like a BGP |
| 895 | // daemon) to an external host. |
Jonathan Hart | d9df7bd | 2015-11-10 17:10:25 -0800 | [diff] [blame] | 896 | Ethernet ndpRequest = buildNdp(ICMP6.NEIGHBOR_SOLICITATION, |
| 897 | ourMac, |
| 898 | MacAddress.valueOf("33:33:ff:00:00:01"), |
| 899 | ourIp, |
| 900 | theirIp); |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 901 | |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 902 | proxyArp.reply(ndpRequest, getLocation(5)); |
| 903 | assertEquals(1, packetService.packets.size()); |
| 904 | verifyPacketOut(ndpRequest, getLocation(1), packetService.packets.get(0)); |
| 905 | |
| 906 | // The same request from a random external port should fail |
| 907 | packetService.packets.clear(); |
| 908 | proxyArp.reply(ndpRequest, getLocation(2)); |
| 909 | assertEquals(0, packetService.packets.size()); |
| 910 | } |
| 911 | |
| 912 | /** |
Jonathan Hart | 6cd2f35 | 2015-01-13 17:44:45 -0800 | [diff] [blame] | 913 | * Tests {@link ProxyArpManager#forward(Ethernet, ConnectPoint)} in the case where the |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 914 | * destination host is known. |
| 915 | * Verifies the correct ARP request is sent out the correct port. |
| 916 | */ |
| 917 | @Test |
| 918 | public void testForwardToHost() { |
| 919 | Host host1 = new DefaultHost(PID, HID1, MAC1, VLAN1, LOC1, |
Aaron Kruglikov | d812383 | 2015-07-06 14:20:25 -0700 | [diff] [blame] | 920 | Collections.singleton(IP1)); |
Thomas Vachuska | b2c47a7 | 2015-08-05 14:22:54 -0700 | [diff] [blame] | 921 | Host host2 = new DefaultHost(PID, HID2, MAC2, VLAN1, LOC2, |
| 922 | Collections.singleton(IP2)); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 923 | |
| 924 | expect(hostService.getHost(HID1)).andReturn(host1); |
Thomas Vachuska | b2c47a7 | 2015-08-05 14:22:54 -0700 | [diff] [blame] | 925 | expect(hostService.getHost(HID2)).andReturn(host2); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 926 | replay(hostService); |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 927 | replay(interfaceService); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 928 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 929 | Ethernet arpRequest = buildArp(ARP.OP_REPLY, VLAN1, MAC2, MAC1, IP2, IP1); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 930 | |
Jonathan Hart | f84591d | 2015-01-16 14:33:43 -0800 | [diff] [blame] | 931 | proxyArp.forward(arpRequest, LOC2); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 932 | |
| 933 | assertEquals(1, packetService.packets.size()); |
| 934 | OutboundPacket packet = packetService.packets.get(0); |
| 935 | |
| 936 | verifyPacketOut(arpRequest, LOC1, packet); |
| 937 | } |
| 938 | |
| 939 | /** |
Jonathan Hart | 6cd2f35 | 2015-01-13 17:44:45 -0800 | [diff] [blame] | 940 | * Tests {@link ProxyArpManager#forward(Ethernet, ConnectPoint)} in the case where the |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 941 | * destination host is known. |
| 942 | * Verifies the correct ARP request is sent out the correct port. |
| 943 | */ |
| 944 | @Test |
| 945 | public void testForwardToHostIpv6() { |
| 946 | Host host1 = new DefaultHost(PID, HID3, MAC3, VLAN1, LOC1, |
| 947 | Collections.singleton(IP3)); |
| 948 | Host host2 = new DefaultHost(PID, HID4, MAC4, VLAN1, LOC2, |
| 949 | Collections.singleton(IP4)); |
| 950 | |
| 951 | expect(hostService.getHost(SOLICITED_HID3)).andReturn(host1); |
| 952 | expect(hostService.getHost(HID4)).andReturn(host2); |
| 953 | replay(hostService); |
| 954 | replay(interfaceService); |
| 955 | |
Jonathan Hart | d9df7bd | 2015-11-10 17:10:25 -0800 | [diff] [blame] | 956 | Ethernet ndpRequest = buildNdp(ICMP6.NEIGHBOR_SOLICITATION, |
| 957 | MAC4, SOLICITED_MAC3, |
| 958 | IP4, IP3); |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 959 | |
| 960 | proxyArp.forward(ndpRequest, LOC2); |
| 961 | |
| 962 | assertEquals(1, packetService.packets.size()); |
| 963 | OutboundPacket packet = packetService.packets.get(0); |
| 964 | |
| 965 | verifyPacketOut(ndpRequest, LOC1, packet); |
| 966 | } |
| 967 | |
| 968 | /** |
| 969 | * Tests {@link ProxyArpManager#forward(Ethernet, ConnectPoint)} in the case where the |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 970 | * destination host is not known. |
| 971 | * Verifies the correct ARP request is flooded out the correct edge ports. |
| 972 | */ |
| 973 | @Test |
| 974 | public void testForwardFlood() { |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 975 | expect(hostService.getHost(HID2)).andReturn(null); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 976 | replay(hostService); |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 977 | replay(interfaceService); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 978 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 979 | Ethernet arpRequest = buildArp(ARP.OP_REPLY, VLAN1, MAC1, MAC2, IP1, IP2); |
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 | proxyArp.forward(arpRequest, getLocation(NUM_DEVICES)); |
Aaron Kruglikov | d812383 | 2015-07-06 14:20:25 -0700 | [diff] [blame] | 982 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 983 | verifyFlood(arpRequest, noConfigCPoints); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 984 | } |
| 985 | |
| 986 | /** |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 987 | * Tests {@link ProxyArpManager#forward(Ethernet, ConnectPoint)} in the case where the |
| 988 | * destination host is not known. |
| 989 | * Verifies the correct NDP request is flooded out the correct edge ports. |
| 990 | */ |
| 991 | @Test |
| 992 | public void testForwardFloodIpv6() { |
| 993 | expect(hostService.getHost(SOLICITED_HID3)).andReturn(null); |
| 994 | replay(hostService); |
| 995 | replay(interfaceService); |
| 996 | |
Jonathan Hart | d9df7bd | 2015-11-10 17:10:25 -0800 | [diff] [blame] | 997 | Ethernet ndpRequest = buildNdp(ICMP6.NEIGHBOR_SOLICITATION, |
| 998 | MAC4, SOLICITED_MAC3, |
| 999 | IP4, IP3); |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 1000 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 1001 | proxyArp.forward(ndpRequest, getLocation(NUM_DEVICES)); |
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 | verifyFlood(ndpRequest, noConfigCPoints); |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 1004 | } |
| 1005 | |
| 1006 | /** |
Jonathan Hart | f84591d | 2015-01-16 14:33:43 -0800 | [diff] [blame] | 1007 | * Verifies that the given packet was flooded out all available edge ports, |
| 1008 | * except for the input port. |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 1009 | * |
| 1010 | * @param packet the packet that was expected to be flooded |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 1011 | * @param connectPoints the connectPoints where the outpacket should be |
| 1012 | * observed |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 1013 | */ |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 1014 | private void verifyFlood(Ethernet packet, List<ConnectPoint> connectPoints) { |
| 1015 | |
Jonathan Hart | f84591d | 2015-01-16 14:33:43 -0800 | [diff] [blame] | 1016 | // 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] | 1017 | assertEquals(connectPoints.size() - 1, packetService.packets.size()); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 1018 | |
| 1019 | Collections.sort(packetService.packets, |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 1020 | (o1, o2) -> o1.sendThrough().uri().compareTo(o2.sendThrough().uri())); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 1021 | |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 1022 | for (int i = 0; i < connectPoints.size() - 1; i++) { |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 1023 | OutboundPacket outboundPacket = packetService.packets.get(i); |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 1024 | verifyPacketOut(packet, connectPoints.get(i), outboundPacket); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 1025 | } |
| 1026 | } |
| 1027 | |
| 1028 | /** |
| 1029 | * Verifies the given packet was sent out the given port. |
| 1030 | * |
| 1031 | * @param expected the packet that was expected to be sent |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 1032 | * @param outPort the port the packet was expected to be sent out |
| 1033 | * @param actual the actual OutboundPacket to verify |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 1034 | */ |
| 1035 | private void verifyPacketOut(Ethernet expected, ConnectPoint outPort, |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 1036 | OutboundPacket actual) { |
Yuta HIGUCHI | 3e848a8 | 2014-11-02 20:19:42 -0800 | [diff] [blame] | 1037 | assertArrayEquals(expected.serialize(), actual.data().array()); |
Ray Milkey | 4250735 | 2015-03-20 15:16:10 -0700 | [diff] [blame] | 1038 | assertEquals(1, actual.treatment().immediate().size()); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 1039 | assertEquals(outPort.deviceId(), actual.sendThrough()); |
Ray Milkey | 4250735 | 2015-03-20 15:16:10 -0700 | [diff] [blame] | 1040 | Instruction instruction = actual.treatment().immediate().get(0); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 1041 | assertTrue(instruction instanceof OutputInstruction); |
| 1042 | assertEquals(outPort.port(), ((OutputInstruction) instruction).port()); |
| 1043 | } |
| 1044 | |
| 1045 | /** |
| 1046 | * Returns the device ID of the ith device. |
| 1047 | * |
| 1048 | * @param i device to get the ID of |
| 1049 | * @return the device ID |
| 1050 | */ |
| 1051 | private static DeviceId getDeviceId(int i) { |
| 1052 | return DeviceId.deviceId("" + i); |
| 1053 | } |
| 1054 | |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 1055 | private static HostLocation getLocation(int i) { |
| 1056 | return new HostLocation(new ConnectPoint(getDeviceId(i), P1), 123L); |
| 1057 | } |
| 1058 | |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 1059 | /** |
| 1060 | * Builds an ARP packet with the given parameters. |
| 1061 | * |
| 1062 | * @param opcode opcode of the ARP packet |
| 1063 | * @param srcMac source MAC address |
| 1064 | * @param dstMac destination MAC address, or null if this is a request |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 1065 | * @param srcIp source IP address |
| 1066 | * @param dstIp destination IP address |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 1067 | * @return the ARP packet |
| 1068 | */ |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 1069 | private Ethernet buildArp(short opcode, VlanId vlanId, MacAddress srcMac, |
| 1070 | MacAddress dstMac, Ip4Address srcIp, Ip4Address dstIp) { |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 1071 | Ethernet eth = new Ethernet(); |
| 1072 | |
| 1073 | if (dstMac == null) { |
Yuta HIGUCHI | 3e848a8 | 2014-11-02 20:19:42 -0800 | [diff] [blame] | 1074 | eth.setDestinationMACAddress(MacAddress.BROADCAST); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 1075 | } else { |
Yuta HIGUCHI | 3e848a8 | 2014-11-02 20:19:42 -0800 | [diff] [blame] | 1076 | eth.setDestinationMACAddress(dstMac); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 1077 | } |
| 1078 | |
Yuta HIGUCHI | 3e848a8 | 2014-11-02 20:19:42 -0800 | [diff] [blame] | 1079 | eth.setSourceMACAddress(srcMac); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 1080 | eth.setEtherType(Ethernet.TYPE_ARP); |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 1081 | eth.setVlanID(vlanId.toShort()); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 1082 | |
| 1083 | ARP arp = new ARP(); |
| 1084 | arp.setOpCode(opcode); |
| 1085 | arp.setProtocolType(ARP.PROTO_TYPE_IP); |
| 1086 | arp.setHardwareType(ARP.HW_TYPE_ETHERNET); |
| 1087 | |
Pavlin Radoslavov | 5b5dc48 | 2014-11-05 14:48:08 -0800 | [diff] [blame] | 1088 | arp.setProtocolAddressLength((byte) Ip4Address.BYTE_LENGTH); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 1089 | arp.setHardwareAddressLength((byte) Ethernet.DATALAYER_ADDRESS_LENGTH); |
Yuta HIGUCHI | 3e848a8 | 2014-11-02 20:19:42 -0800 | [diff] [blame] | 1090 | arp.setSenderHardwareAddress(srcMac.toBytes()); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 1091 | |
| 1092 | if (dstMac == null) { |
Luca Prete | f70d399 | 2015-10-30 16:24:14 -0700 | [diff] [blame] | 1093 | arp.setTargetHardwareAddress(zeroMacAddress); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 1094 | } else { |
Yuta HIGUCHI | 3e848a8 | 2014-11-02 20:19:42 -0800 | [diff] [blame] | 1095 | arp.setTargetHardwareAddress(dstMac.toBytes()); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 1096 | } |
| 1097 | |
| 1098 | arp.setSenderProtocolAddress(srcIp.toOctets()); |
| 1099 | arp.setTargetProtocolAddress(dstIp.toOctets()); |
| 1100 | |
| 1101 | eth.setPayload(arp); |
| 1102 | return eth; |
| 1103 | } |
| 1104 | |
| 1105 | /** |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 1106 | * Builds an NDP packet with the given parameters. |
| 1107 | * |
| 1108 | * @param type NeighborSolicitation or NeighborAdvertisement |
| 1109 | * @param srcMac source MAC address |
| 1110 | * @param dstMac destination MAC address, or null if this is a request |
| 1111 | * @param srcIp source IP address |
| 1112 | * @param dstIp destination IP address |
| 1113 | * @return the NDP packet |
| 1114 | */ |
Jonathan Hart | d9df7bd | 2015-11-10 17:10:25 -0800 | [diff] [blame] | 1115 | private Ethernet buildNdp(byte type, MacAddress srcMac, MacAddress dstMac, |
Charles Chan | ad3b550 | 2015-10-23 16:24:20 -0700 | [diff] [blame] | 1116 | Ip6Address srcIp, Ip6Address dstIp) { |
| 1117 | assertThat(type, anyOf( |
| 1118 | is(ICMP6.NEIGHBOR_SOLICITATION), |
| 1119 | is(ICMP6.NEIGHBOR_ADVERTISEMENT) |
| 1120 | )); |
| 1121 | assertNotNull(srcMac); |
| 1122 | assertNotNull(dstMac); |
| 1123 | assertNotNull(srcIp); |
| 1124 | assertNotNull(dstIp); |
| 1125 | |
| 1126 | IPacket ndp; |
| 1127 | if (type == ICMP6.NEIGHBOR_SOLICITATION) { |
| 1128 | ndp = new NeighborSolicitation().setTargetAddress(dstIp.toOctets()); |
| 1129 | } else { |
| 1130 | ndp = new NeighborAdvertisement() |
| 1131 | .setSolicitedFlag((byte) 1) |
| 1132 | .setOverrideFlag((byte) 1) |
| 1133 | .setTargetAddress(srcIp.toOctets()) |
| 1134 | .addOption(NeighborDiscoveryOptions.TYPE_TARGET_LL_ADDRESS, |
| 1135 | srcMac.toBytes()); |
| 1136 | } |
| 1137 | |
| 1138 | ICMP6 icmp6 = new ICMP6(); |
| 1139 | icmp6.setIcmpType(type); |
| 1140 | icmp6.setIcmpCode((byte) 0); |
| 1141 | icmp6.setPayload(ndp); |
| 1142 | |
| 1143 | IPv6 ipv6 = new IPv6(); |
| 1144 | ipv6.setDestinationAddress(dstIp.toOctets()); |
| 1145 | ipv6.setSourceAddress(srcIp.toOctets()); |
| 1146 | ipv6.setNextHeader(IPv6.PROTOCOL_ICMP6); |
| 1147 | ipv6.setHopLimit((byte) 255); |
| 1148 | ipv6.setPayload(icmp6); |
| 1149 | |
| 1150 | Ethernet eth = new Ethernet(); |
| 1151 | eth.setDestinationMACAddress(dstMac); |
| 1152 | eth.setSourceMACAddress(srcMac); |
| 1153 | eth.setEtherType(Ethernet.TYPE_IPV6); |
| 1154 | eth.setVlanID(VLAN1.toShort()); |
| 1155 | eth.setPayload(ipv6); |
| 1156 | |
| 1157 | return eth; |
| 1158 | } |
| 1159 | |
| 1160 | /** |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 1161 | * Test PacketService implementation that simply stores OutboundPackets |
| 1162 | * passed to {@link #emit(OutboundPacket)} for later verification. |
| 1163 | */ |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 1164 | class TestPacketService extends PacketServiceAdapter { |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 1165 | |
| 1166 | List<OutboundPacket> packets = new ArrayList<>(); |
| 1167 | |
| 1168 | @Override |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 1169 | public void emit(OutboundPacket packet) { |
| 1170 | packets.add(packet); |
| 1171 | } |
Jonathan Hart | 3cfce8e | 2015-01-14 16:43:27 -0800 | [diff] [blame] | 1172 | |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 1173 | } |
Aaron Kruglikov | d812383 | 2015-07-06 14:20:25 -0700 | [diff] [blame] | 1174 | |
Thomas Vachuska | b2c47a7 | 2015-08-05 14:22:54 -0700 | [diff] [blame] | 1175 | private class TestProxyArpStoreAdapter implements ProxyArpStore { |
| 1176 | @Override |
| 1177 | public void forward(ConnectPoint outPort, Host subject, ByteBuffer packet) { |
| 1178 | TrafficTreatment tt = DefaultTrafficTreatment.builder().setOutput(outPort.port()).build(); |
| 1179 | packetService.emit(new DefaultOutboundPacket(outPort.deviceId(), tt, packet)); |
| 1180 | } |
| 1181 | |
| 1182 | @Override |
| 1183 | public void setDelegate(ProxyArpStoreDelegate delegate) { |
| 1184 | } |
| 1185 | } |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 1186 | } |