blob: 6e91ab030970a40776969d06f9a04d59e2200459 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2014-present Open Networking Laboratory
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07003 *
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'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net.proxyarp.impl;
Jonathan Hart704ca142014-10-09 09:34:39 -070017
Jonathan Hart00cddda2016-02-16 10:30:37 -080018import com.google.common.collect.Lists;
Thomas Vachuska27bee092015-06-23 19:03:10 -070019import com.google.common.collect.Sets;
Jonathan Hart704ca142014-10-09 09:34:39 -070020import org.junit.Before;
21import org.junit.Test;
Jonathan Hart3cfce8e2015-01-14 16:43:27 -080022import org.onlab.packet.ARP;
23import org.onlab.packet.Ethernet;
Charles Chanad3b5502015-10-23 16:24:20 -070024import org.onlab.packet.ICMP6;
25import org.onlab.packet.IPacket;
26import org.onlab.packet.IPv6;
Jonathan Hart3cfce8e2015-01-14 16:43:27 -080027import org.onlab.packet.Ip4Address;
28import org.onlab.packet.Ip4Prefix;
Charles Chanad3b5502015-10-23 16:24:20 -070029import org.onlab.packet.Ip6Address;
30import org.onlab.packet.Ip6Prefix;
Jonathan Hart4cb39882015-08-12 23:50:55 -040031import org.onlab.packet.IpPrefix;
Jonathan Hart3cfce8e2015-01-14 16:43:27 -080032import org.onlab.packet.MacAddress;
33import org.onlab.packet.VlanId;
Charles Chanad3b5502015-10-23 16:24:20 -070034import org.onlab.packet.ndp.NeighborAdvertisement;
35import org.onlab.packet.ndp.NeighborDiscoveryOptions;
36import org.onlab.packet.ndp.NeighborSolicitation;
Jonathan Hart4cb39882015-08-12 23:50:55 -040037import org.onosproject.incubator.net.intf.Interface;
38import org.onosproject.incubator.net.intf.InterfaceService;
Brian O'Connorabafb502014-12-02 22:26:20 -080039import org.onosproject.net.ConnectPoint;
40import org.onosproject.net.DefaultHost;
41import org.onosproject.net.Device;
42import org.onosproject.net.DeviceId;
43import org.onosproject.net.Host;
44import org.onosproject.net.HostId;
45import org.onosproject.net.HostLocation;
46import org.onosproject.net.Link;
47import org.onosproject.net.Port;
48import org.onosproject.net.PortNumber;
49import org.onosproject.net.device.DeviceListener;
50import org.onosproject.net.device.DeviceService;
Luca Pretef70d3992015-10-30 16:24:14 -070051import org.onosproject.net.edge.EdgePortService;
Thomas Vachuskab2c47a72015-08-05 14:22:54 -070052import org.onosproject.net.flow.DefaultTrafficTreatment;
53import org.onosproject.net.flow.TrafficTreatment;
Brian O'Connorabafb502014-12-02 22:26:20 -080054import org.onosproject.net.flow.instructions.Instruction;
55import org.onosproject.net.flow.instructions.Instructions.OutputInstruction;
56import org.onosproject.net.host.HostService;
57import org.onosproject.net.host.InterfaceIpAddress;
Brian O'Connorabafb502014-12-02 22:26:20 -080058import org.onosproject.net.link.LinkListener;
59import org.onosproject.net.link.LinkService;
Thomas Vachuskab2c47a72015-08-05 14:22:54 -070060import org.onosproject.net.packet.DefaultOutboundPacket;
Brian O'Connorabafb502014-12-02 22:26:20 -080061import org.onosproject.net.packet.OutboundPacket;
Thomas Vachuska27bee092015-06-23 19:03:10 -070062import org.onosproject.net.packet.PacketServiceAdapter;
Brian O'Connorabafb502014-12-02 22:26:20 -080063import org.onosproject.net.provider.ProviderId;
Thomas Vachuskab2c47a72015-08-05 14:22:54 -070064import org.onosproject.net.proxyarp.ProxyArpStore;
65import org.onosproject.net.proxyarp.ProxyArpStoreDelegate;
Jonathan Hart704ca142014-10-09 09:34:39 -070066
Thomas Vachuskab2c47a72015-08-05 14:22:54 -070067import java.nio.ByteBuffer;
Thomas Vachuska27bee092015-06-23 19:03:10 -070068import java.util.ArrayList;
69import java.util.Collections;
Luca Pretef70d3992015-10-30 16:24:14 -070070import java.util.HashSet;
Thomas Vachuska27bee092015-06-23 19:03:10 -070071import java.util.List;
72import java.util.Set;
73
Jonathan Hart4cb39882015-08-12 23:50:55 -040074import static org.easymock.EasyMock.anyObject;
75import static org.easymock.EasyMock.createMock;
76import static org.easymock.EasyMock.expect;
77import static org.easymock.EasyMock.replay;
Charles Chanad3b5502015-10-23 16:24:20 -070078import static org.hamcrest.Matchers.anyOf;
79import static org.hamcrest.Matchers.is;
Jonathan Hart4cb39882015-08-12 23:50:55 -040080import static org.junit.Assert.assertArrayEquals;
81import static org.junit.Assert.assertEquals;
82import static org.junit.Assert.assertFalse;
Charles Chanad3b5502015-10-23 16:24:20 -070083import static org.junit.Assert.assertNotNull;
84import static org.junit.Assert.assertThat;
Jonathan Hart4cb39882015-08-12 23:50:55 -040085import static org.junit.Assert.assertTrue;
Jonathan Hart704ca142014-10-09 09:34:39 -070086
87/**
88 * Tests for the {@link ProxyArpManager} class.
89 */
90public class ProxyArpManagerTest {
91
Luca Pretef70d3992015-10-30 16:24:14 -070092 private static final int NUM_DEVICES = 10;
Jonathan Hart704ca142014-10-09 09:34:39 -070093 private static final int NUM_PORTS_PER_DEVICE = 3;
Luca Pretef70d3992015-10-30 16:24:14 -070094 private static final int LAST_CONF_DEVICE_INTF_VLAN_IP = 3;
95 private static final int LAST_CONF_DEVICE_INTF_VLAN = 6;
Jonathan Hart704ca142014-10-09 09:34:39 -070096
Pavlin Radoslavov5b5dc482014-11-05 14:48:08 -080097 private static final Ip4Address IP1 = Ip4Address.valueOf("192.168.1.1");
98 private static final Ip4Address IP2 = Ip4Address.valueOf("192.168.1.2");
Luca Pretef70d3992015-10-30 16:24:14 -070099 private static final Ip6Address IP3 = Ip6Address.valueOf("1000:ffff::1");
100 private static final Ip6Address IP4 = Ip6Address.valueOf("1000:ffff::2");
Jonathan Hart704ca142014-10-09 09:34:39 -0700101
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 Pretef70d3992015-10-30 16:24:14 -0700106 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 Chanad3b5502015-10-23 16:24:20 -0700114 private static final MacAddress SOLICITED_MAC3 = MacAddress.valueOf("33:33:FF:00:00:01");
Luca Pretef70d3992015-10-30 16:24:14 -0700115
Jonathan Hart704ca142014-10-09 09:34:39 -0700116 private static final HostId HID1 = HostId.hostId(MAC1, VLAN1);
117 private static final HostId HID2 = HostId.hostId(MAC2, VLAN1);
Charles Chanad3b5502015-10-23 16:24:20 -0700118 private static final HostId HID3 = HostId.hostId(MAC3, VLAN1);
119 private static final HostId HID4 = HostId.hostId(MAC4, VLAN1);
Luca Pretef70d3992015-10-30 16:24:14 -0700120 private static final HostId HID10 = HostId.hostId(MAC10, VLAN10);
121
Charles Chanad3b5502015-10-23 16:24:20 -0700122 private static final HostId SOLICITED_HID3 = HostId.hostId(SOLICITED_MAC3, VLAN1);
Jonathan Hart704ca142014-10-09 09:34:39 -0700123
124 private static final DeviceId DID1 = getDeviceId(1);
125 private static final DeviceId DID2 = getDeviceId(2);
Luca Pretef70d3992015-10-30 16:24:14 -0700126
Jonathan Hart704ca142014-10-09 09:34:39 -0700127 private static final PortNumber P1 = PortNumber.portNumber(1);
Luca Pretef70d3992015-10-30 16:24:14 -0700128
Jonathan Hart704ca142014-10-09 09:34:39 -0700129 private static final HostLocation LOC1 = new HostLocation(DID1, P1, 123L);
130 private static final HostLocation LOC2 = new HostLocation(DID2, P1, 123L);
131
Luca Pretef70d3992015-10-30 16:24:14 -0700132 private final byte[] zeroMacAddress = MacAddress.ZERO.toBytes();
Aaron Kruglikovd8123832015-07-06 14:20:25 -0700133
Luca Pretef70d3992015-10-30 16:24:14 -0700134 // 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 Kruglikovd8123832015-07-06 14:20:25 -0700145
Jonathan Hart704ca142014-10-09 09:34:39 -0700146 private ProxyArpManager proxyArp;
147
148 private TestPacketService packetService;
Jonathan Hart704ca142014-10-09 09:34:39 -0700149 private DeviceService deviceService;
Luca Pretef70d3992015-10-30 16:24:14 -0700150 private EdgePortService edgePortService;
Jonathan Hart704ca142014-10-09 09:34:39 -0700151 private LinkService linkService;
152 private HostService hostService;
Jonathan Hart4cb39882015-08-12 23:50:55 -0400153 private InterfaceService interfaceService;
Jonathan Hart704ca142014-10-09 09:34:39 -0700154
155 @Before
156 public void setUp() throws Exception {
157 proxyArp = new ProxyArpManager();
158 packetService = new TestPacketService();
159 proxyArp.packetService = packetService;
Thomas Vachuskab2c47a72015-08-05 14:22:54 -0700160 proxyArp.store = new TestProxyArpStoreAdapter();
Jonathan Hart704ca142014-10-09 09:34:39 -0700161
Luca Pretef70d3992015-10-30 16:24:14 -0700162 // Create a host service mock here.
Jonathan Hart704ca142014-10-09 09:34:39 -0700163 hostService = createMock(HostService.class);
164 proxyArp.hostService = hostService;
165
Luca Pretef70d3992015-10-30 16:24:14 -0700166 // Create an edge port service.
167 edgePortService = createMock(EdgePortService.class);
168 proxyArp.edgeService = edgePortService;
169
170 // Create interface service
Jonathan Hart4cb39882015-08-12 23:50:55 -0400171 interfaceService = createMock(InterfaceService.class);
172 proxyArp.interfaceService = interfaceService;
173
Luca Pretef70d3992015-10-30 16:24:14 -0700174 // Create the topology
Jonathan Hart704ca142014-10-09 09:34:39 -0700175 createTopology();
176 proxyArp.deviceService = deviceService;
177 proxyArp.linkService = linkService;
178
Luca Pretef70d3992015-10-30 16:24:14 -0700179 setupNoConfigCPoints();
180 setupconfigIpCPoints();
181 setupconfigVlanCPoints();
182
Jonathan Hart704ca142014-10-09 09:34:39 -0700183 proxyArp.activate();
184 }
185
186 /**
187 * Creates a fake topology to feed into the ARP module.
Aaron Kruglikovd8123832015-07-06 14:20:25 -0700188 * <p>
Jonathan Hart704ca142014-10-09 09:34:39 -0700189 * 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 Hartdbdbdbb2014-10-06 18:35:30 -0700192 * 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 Hart704ca142014-10-09 09:34:39 -0700195 */
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 Pretef70d3992015-10-30 16:24:14 -0700205 addIntfConfig();
206 popluateEdgePortService();
Jonathan Hart704ca142014-10-09 09:34:39 -0700207 }
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 Hartdbdbdbb2014-10-06 18:35:30 -0700231 expect(deviceService.getPorts(devId)).andReturn(ports).anyTimes();
232 expect(deviceService.getDevice(devId)).andReturn(device).anyTimes();
Jonathan Hart704ca142014-10-09 09:34:39 -0700233 }
234
Jonathan Hartdbdbdbb2014-10-06 18:35:30 -0700235 expect(deviceService.getDevices()).andReturn(devices).anyTimes();
Jonathan Hart704ca142014-10-09 09:34:39 -0700236 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 SHIMIZUd88db6f2015-09-09 14:22:06 -0700245 List<Link> links = new ArrayList<>();
Jonathan Hart704ca142014-10-09 09:34:39 -0700246
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 Pretef70d3992015-10-30 16:24:14 -0700267 /**
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 Hart4cb39882015-08-12 23:50:55 -0400275 Set<Interface> interfaces = Sets.newHashSet();
Jonathan Hartdbdbdbb2014-10-06 18:35:30 -0700276
Luca Pretef70d3992015-10-30 16:24:14 -0700277 Set<Interface> vlanOneSet = new HashSet<>();
278
279 for (int i = 1; i <= LAST_CONF_DEVICE_INTF_VLAN_IP; i++) {
Jonathan Hartdbdbdbb2014-10-06 18:35:30 -0700280 ConnectPoint cp = new ConnectPoint(getDeviceId(i), P1);
Charles Chanad3b5502015-10-23 16:24:20 -0700281
Luca Pretef70d3992015-10-30 16:24:14 -0700282 // Interface addresses for IPv4
Charles Chanad3b5502015-10-23 16:24:20 -0700283 Ip4Prefix prefix1 = Ip4Prefix.valueOf("10.0." + (2 * i - 1) + ".0/24");
284 Ip4Address addr1 = Ip4Address.valueOf("10.0." + (2 * i - 1) + ".1");
Pavlin Radoslavov5b5dc482014-11-05 14:48:08 -0800285 Ip4Prefix prefix2 = Ip4Prefix.valueOf("10.0." + (2 * i) + ".0/24");
286 Ip4Address addr2 = Ip4Address.valueOf("10.0." + (2 * i) + ".1");
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -0700287 InterfaceIpAddress ia1 = new InterfaceIpAddress(addr1, prefix1);
288 InterfaceIpAddress ia2 = new InterfaceIpAddress(addr2, prefix2);
Charles Chanad3b5502015-10-23 16:24:20 -0700289
Luca Pretef70d3992015-10-30 16:24:14 -0700290 // Interface addresses for IPv6
Charles Chanad3b5502015-10-23 16:24:20 -0700291 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 Pretef70d3992015-10-30 16:24:14 -0700294 Ip6Address addr4 = Ip6Address.valueOf((2 * i) + "000::2");
Charles Chanad3b5502015-10-23 16:24:20 -0700295 InterfaceIpAddress ia3 = new InterfaceIpAddress(addr3, prefix3);
296 InterfaceIpAddress ia4 = new InterfaceIpAddress(addr4, prefix4);
297
Luca Pretef70d3992015-10-30 16:24:14 -0700298 // Setting up interfaces
Sho SHIMIZU891162b2016-06-06 16:32:01 -0700299 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 Pretef70d3992015-10-30 16:24:14 -0700303
Jonathan Hart4cb39882015-08-12 23:50:55 -0400304 interfaces.add(intf1);
305 interfaces.add(intf2);
Jonathan Hartdbdbdbb2014-10-06 18:35:30 -0700306
Luca Pretef70d3992015-10-30 16:24:14 -0700307 vlanOneSet.add(intf1);
308
Jonathan Hart4cb39882015-08-12 23:50:55 -0400309 expect(interfaceService.getInterfacesByPort(cp))
310 .andReturn(Sets.newHashSet(intf1, intf2)).anyTimes();
Jonathan Hartdbdbdbb2014-10-06 18:35:30 -0700311 }
Luca Pretef70d3992015-10-30 16:24:14 -0700312 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 SHIMIZU891162b2016-06-06 16:32:01 -0700314 Interface intf1 = new Interface(Interface.NO_INTERFACE_NAME, cp, Collections.emptyList(),
Luca Pretef70d3992015-10-30 16:24:14 -0700315 MacAddress.NONE,
316 VlanId.vlanId((short) 1));
Jonathan Hartdbdbdbb2014-10-06 18:35:30 -0700317
Luca Pretef70d3992015-10-30 16:24:14 -0700318 interfaces.add(intf1);
319 vlanOneSet.add(intf1);
Jonathan Hart4cb39882015-08-12 23:50:55 -0400320
321 expect(interfaceService.getInterfacesByPort(cp))
Luca Pretef70d3992015-10-30 16:24:14 -0700322 .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 Hart4cb39882015-08-12 23:50:55 -0400334 .andReturn(Collections.emptySet()).anyTimes();
Jonathan Hartdbdbdbb2014-10-06 18:35:30 -0700335 }
336 }
337
Jonathan Hart704ca142014-10-09 09:34:39 -0700338 /**
Luca Pretef70d3992015-10-30 16:24:14 -0700339 * 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 Hart7d1496b2015-03-10 22:00:48 -0700413 * Tests {@link ProxyArpManager#isKnown(org.onlab.packet.IpAddress)} in the
414 * case where the IP address is not known.
Jonathan Hart704ca142014-10-09 09:34:39 -0700415 * Verifies the method returns false.
416 */
417 @Test
418 public void testNotKnown() {
Sho SHIMIZU21d00692016-08-15 11:15:28 -0700419 expect(hostService.getHostsByIp(IP1)).andReturn(Collections.emptySet());
Jonathan Hart704ca142014-10-09 09:34:39 -0700420 replay(hostService);
Jonathan Hart4cb39882015-08-12 23:50:55 -0400421 replay(interfaceService);
Jonathan Hart704ca142014-10-09 09:34:39 -0700422
Jonathan Hartf84591d2015-01-16 14:33:43 -0800423 assertFalse(proxyArp.isKnown(IP1));
Jonathan Hart704ca142014-10-09 09:34:39 -0700424 }
425
426 /**
Jonathan Hart7d1496b2015-03-10 22:00:48 -0700427 * Tests {@link ProxyArpManager#isKnown(org.onlab.packet.IpAddress)} in the
428 * case where the IP address is known.
Jonathan Hart704ca142014-10-09 09:34:39 -0700429 * 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 Hart4cb39882015-08-12 23:50:55 -0400439 replay(interfaceService);
Jonathan Hart704ca142014-10-09 09:34:39 -0700440
Jonathan Hartf84591d2015-01-16 14:33:43 -0800441 assertTrue(proxyArp.isKnown(IP1));
Jonathan Hart704ca142014-10-09 09:34:39 -0700442 }
443
444 /**
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800445 * Tests {@link ProxyArpManager#reply(Ethernet, ConnectPoint)} in the case where the
Jonathan Hart704ca142014-10-09 09:34:39 -0700446 * destination host is known.
Luca Pretef70d3992015-10-30 16:24:14 -0700447 * 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 Hart704ca142014-10-09 09:34:39 -0700452 */
453 @Test
454 public void testReplyKnown() {
Luca Pretef70d3992015-10-30 16:24:14 -0700455 Host requestor = new DefaultHost(PID, HID1, MAC1, VLAN1, getLocation(NUM_DEVICES),
Aaron Kruglikovd8123832015-07-06 14:20:25 -0700456 Collections.singleton(IP1));
Jonathan Hart704ca142014-10-09 09:34:39 -0700457
Luca Pretef70d3992015-10-30 16:24:14 -0700458 Host replyer = new DefaultHost(PID, HID2, MAC2, VLAN1, getLocation(NUM_DEVICES - 1),
Aaron Kruglikovd8123832015-07-06 14:20:25 -0700459 Collections.singleton(IP2));
Jonathan Hart704ca142014-10-09 09:34:39 -0700460
Luca Pretef70d3992015-10-30 16:24:14 -0700461 expect(hostService.getHostsByIp(IP2))
Thomas Vachuska27bee092015-06-23 19:03:10 -0700462 .andReturn(Collections.singleton(replyer));
Luca Pretef70d3992015-10-30 16:24:14 -0700463 expect(hostService.getHost(HID1)).andReturn(requestor);
Jonathan Hart704ca142014-10-09 09:34:39 -0700464
465 replay(hostService);
Jonathan Hart4cb39882015-08-12 23:50:55 -0400466 replay(interfaceService);
Jonathan Hart704ca142014-10-09 09:34:39 -0700467
Luca Pretef70d3992015-10-30 16:24:14 -0700468 Ethernet arpRequest = buildArp(ARP.OP_REQUEST, VLAN1, MAC1, null, IP1, IP2);
Jonathan Hart704ca142014-10-09 09:34:39 -0700469
Luca Pretef70d3992015-10-30 16:24:14 -0700470 proxyArp.reply(arpRequest, getLocation(NUM_DEVICES));
Jonathan Hart704ca142014-10-09 09:34:39 -0700471
472 assertEquals(1, packetService.packets.size());
Luca Pretef70d3992015-10-30 16:24:14 -0700473 Ethernet arpReply = buildArp(ARP.OP_REPLY, VLAN1, MAC2, MAC1, IP2, IP1);
474 verifyPacketOut(arpReply, getLocation(NUM_DEVICES), packetService.packets.get(0));
Jonathan Hart704ca142014-10-09 09:34:39 -0700475 }
476
477 /**
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800478 * Tests {@link ProxyArpManager#reply(Ethernet, ConnectPoint)} in the case where the
Charles Chanad3b5502015-10-23 16:24:20 -0700479 * destination host is known.
480 * Verifies the correct NDP reply is sent out the correct port.
481 */
482 @Test
483 public void testReplyKnownIpv6() {
Charles Chanad3b5502015-10-23 16:24:20 -0700484 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 Hartd9df7bd2015-11-10 17:10:25 -0800497 Ethernet ndpRequest = buildNdp(ICMP6.NEIGHBOR_SOLICITATION,
498 MAC4, SOLICITED_MAC3,
499 IP4, IP3);
Charles Chanad3b5502015-10-23 16:24:20 -0700500
501 proxyArp.reply(ndpRequest, getLocation(5));
502
503 assertEquals(1, packetService.packets.size());
Jonathan Hartd9df7bd2015-11-10 17:10:25 -0800504 Ethernet ndpReply = buildNdp(ICMP6.NEIGHBOR_ADVERTISEMENT,
505 MAC3, MAC4, IP3, IP4);
Charles Chanad3b5502015-10-23 16:24:20 -0700506 verifyPacketOut(ndpReply, getLocation(5), packetService.packets.get(0));
507 }
508
509 /**
510 * Tests {@link ProxyArpManager#reply(Ethernet, ConnectPoint)} in the case where the
Jonathan Hart704ca142014-10-09 09:34:39 -0700511 * destination host is not known.
Luca Pretef70d3992015-10-30 16:24:14 -0700512 * 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 Hart704ca142014-10-09 09:34:39 -0700516 * Verifies the ARP request is flooded out the correct edge ports.
517 */
518 @Test
519 public void testReplyUnknown() {
Luca Pretef70d3992015-10-30 16:24:14 -0700520 Host requestor = new DefaultHost(PID, HID10, MAC10, VLAN10, getLocation(NUM_DEVICES),
521 Collections.singleton(IP1));
Aaron Kruglikovd8123832015-07-06 14:20:25 -0700522
Luca Pretef70d3992015-10-30 16:24:14 -0700523 expect(hostService.getHostsByIp(IP2))
Jonathan Hart4cb39882015-08-12 23:50:55 -0400524 .andReturn(Collections.emptySet());
Luca Pretef70d3992015-10-30 16:24:14 -0700525 expect(interfaceService.getInterfacesByIp(IP1))
Jonathan Hart4cb39882015-08-12 23:50:55 -0400526 .andReturn(Collections.emptySet());
Luca Pretef70d3992015-10-30 16:24:14 -0700527 expect(hostService.getHost(HID10)).andReturn(requestor);
Jonathan Hart704ca142014-10-09 09:34:39 -0700528
529 replay(hostService);
Jonathan Hart4cb39882015-08-12 23:50:55 -0400530 replay(interfaceService);
Jonathan Hart704ca142014-10-09 09:34:39 -0700531
Luca Pretef70d3992015-10-30 16:24:14 -0700532 Ethernet arpRequest = buildArp(ARP.OP_REQUEST, VLAN10, MAC10, null, IP1, IP2);
Jonathan Hart704ca142014-10-09 09:34:39 -0700533
Luca Pretef70d3992015-10-30 16:24:14 -0700534 proxyArp.reply(arpRequest, getLocation(NUM_DEVICES));
Aaron Kruglikovd8123832015-07-06 14:20:25 -0700535
Luca Pretef70d3992015-10-30 16:24:14 -0700536 verifyFlood(arpRequest, noConfigCPoints);
Jonathan Hart704ca142014-10-09 09:34:39 -0700537 }
538
539 /**
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800540 * Tests {@link ProxyArpManager#reply(Ethernet, ConnectPoint)} in the case where the
Charles Chanad3b5502015-10-23 16:24:20 -0700541 * 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 Pretef70d3992015-10-30 16:24:14 -0700546 Host requestor = new DefaultHost(PID, HID4, MAC4, VLAN1, getLocation(NUM_DEVICES),
Charles Chanad3b5502015-10-23 16:24:20 -0700547 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 Hartd9df7bd2015-11-10 17:10:25 -0800558 Ethernet ndpRequest = buildNdp(ICMP6.NEIGHBOR_SOLICITATION,
559 MAC4, SOLICITED_MAC3,
560 IP4, IP3);
Charles Chanad3b5502015-10-23 16:24:20 -0700561
Luca Pretef70d3992015-10-30 16:24:14 -0700562 proxyArp.reply(ndpRequest, getLocation(NUM_DEVICES));
Charles Chanad3b5502015-10-23 16:24:20 -0700563
Luca Pretef70d3992015-10-30 16:24:14 -0700564 verifyFlood(ndpRequest, noConfigCPoints);
Charles Chanad3b5502015-10-23 16:24:20 -0700565 }
566
567 /**
568 * Tests {@link ProxyArpManager#reply(Ethernet, ConnectPoint)} in the case where the
Jonathan Hart704ca142014-10-09 09:34:39 -0700569 * destination host is known for that IP address, but is not on the same
570 * VLAN as the source host.
Luca Pretef70d3992015-10-30 16:24:14 -0700571 * 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 Hart704ca142014-10-09 09:34:39 -0700577 * Verifies the ARP request is flooded out the correct edge ports.
578 */
579 @Test
580 public void testReplyDifferentVlan() {
Luca Pretef70d3992015-10-30 16:24:14 -0700581 Host requestor = new DefaultHost(PID, HID10, MAC10, VLAN10, getLocation(NUM_DEVICES),
Aaron Kruglikovd8123832015-07-06 14:20:25 -0700582 Collections.singleton(IP1));
Jonathan Hart704ca142014-10-09 09:34:39 -0700583
Luca Pretef70d3992015-10-30 16:24:14 -0700584 Host replyer = new DefaultHost(PID, HID2, MAC2, VLAN2, getLocation(NUM_DEVICES - 1),
Aaron Kruglikovd8123832015-07-06 14:20:25 -0700585 Collections.singleton(IP2));
Jonathan Hart704ca142014-10-09 09:34:39 -0700586
Luca Pretef70d3992015-10-30 16:24:14 -0700587 expect(hostService.getHostsByIp(IP2))
Jonathan Hart704ca142014-10-09 09:34:39 -0700588 .andReturn(Collections.singleton(replyer));
Luca Pretef70d3992015-10-30 16:24:14 -0700589 expect(interfaceService.getInterfacesByIp(IP1))
Jonathan Hart4cb39882015-08-12 23:50:55 -0400590 .andReturn(Collections.emptySet());
Luca Pretef70d3992015-10-30 16:24:14 -0700591 expect(hostService.getHost(HID10)).andReturn(requestor);
Jonathan Hart704ca142014-10-09 09:34:39 -0700592
593 replay(hostService);
Jonathan Hart4cb39882015-08-12 23:50:55 -0400594 replay(interfaceService);
Jonathan Hart704ca142014-10-09 09:34:39 -0700595
Luca Pretef70d3992015-10-30 16:24:14 -0700596 Ethernet arpRequest = buildArp(ARP.OP_REQUEST, VLAN10, MAC10, null, IP1, IP2);
Jonathan Hart704ca142014-10-09 09:34:39 -0700597
Luca Pretef70d3992015-10-30 16:24:14 -0700598 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 Hartf84591d2015-01-16 14:33:43 -0800660 proxyArp.reply(arpRequest, getLocation(6));
Jonathan Hart704ca142014-10-09 09:34:39 -0700661
Luca Pretef70d3992015-10-30 16:24:14 -0700662 verifyFlood(arpRequest, configVlanCPoints);
Jonathan Hart704ca142014-10-09 09:34:39 -0700663 }
664
Charles Chanad3b5502015-10-23 16:24:20 -0700665 /**
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 Pretef70d3992015-10-30 16:24:14 -0700673 Host requestor = new DefaultHost(PID, HID4, MAC4, VLAN1, getLocation(NUM_DEVICES),
Charles Chanad3b5502015-10-23 16:24:20 -0700674 Collections.singleton(IP4));
675
Luca Pretef70d3992015-10-30 16:24:14 -0700676 Host replyer = new DefaultHost(PID, HID3, MAC3, VLAN2, getLocation(NUM_DEVICES - 1),
677 Collections.singleton(IP3));
678
Charles Chanad3b5502015-10-23 16:24:20 -0700679 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 Hartd9df7bd2015-11-10 17:10:25 -0800688 Ethernet ndpRequest = buildNdp(ICMP6.NEIGHBOR_SOLICITATION,
689 MAC4, SOLICITED_MAC3,
690 IP4, IP3);
Charles Chanad3b5502015-10-23 16:24:20 -0700691
Luca Pretef70d3992015-10-30 16:24:14 -0700692 proxyArp.reply(ndpRequest, getLocation(NUM_DEVICES));
Charles Chanad3b5502015-10-23 16:24:20 -0700693
Luca Pretef70d3992015-10-30 16:24:14 -0700694 verifyFlood(ndpRequest, noConfigCPoints);
Charles Chanad3b5502015-10-23 16:24:20 -0700695 }
696
697 /**
698 * Test ARP request from external network to an internal host.
699 */
Jonathan Hartdbdbdbb2014-10-06 18:35:30 -0700700 @Test
701 public void testReplyToRequestForUs() {
Pavlin Radoslavov5b5dc482014-11-05 14:48:08 -0800702 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 Harta887ba82014-11-03 15:20:52 -0800705 MacAddress firstMac = MacAddress.valueOf(1L);
706 MacAddress secondMac = MacAddress.valueOf(2L);
Jonathan Hartdbdbdbb2014-10-06 18:35:30 -0700707
Luca Pretef70d3992015-10-30 16:24:14 -0700708 Host requestor = new DefaultHost(PID, HID1, MAC1, VLAN1, LOC1,
Aaron Kruglikovd8123832015-07-06 14:20:25 -0700709 Collections.singleton(theirIp));
Jonathan Hartdbdbdbb2014-10-06 18:35:30 -0700710
Luca Pretef70d3992015-10-30 16:24:14 -0700711 expect(hostService.getHost(HID1)).andReturn(requestor);
Jonathan Hartdbdbdbb2014-10-06 18:35:30 -0700712 replay(hostService);
Jonathan Hart4cb39882015-08-12 23:50:55 -0400713 replay(interfaceService);
Jonathan Hartdbdbdbb2014-10-06 18:35:30 -0700714
Luca Pretef70d3992015-10-30 16:24:14 -0700715 Ethernet arpRequest = buildArp(ARP.OP_REQUEST, VLAN1, MAC1, null, theirIp, ourFirstIp);
716
Jonathan Hartdbdbdbb2014-10-06 18:35:30 -0700717 proxyArp.reply(arpRequest, LOC1);
718
719 assertEquals(1, packetService.packets.size());
Luca Pretef70d3992015-10-30 16:24:14 -0700720 Ethernet arpReply = buildArp(ARP.OP_REPLY, VLAN1, firstMac, MAC1, ourFirstIp, theirIp);
Jonathan Hartdbdbdbb2014-10-06 18:35:30 -0700721 verifyPacketOut(arpReply, LOC1, packetService.packets.get(0));
722
723 // Test a request for the second address on that port
724 packetService.packets.clear();
Luca Pretef70d3992015-10-30 16:24:14 -0700725 arpRequest = buildArp(ARP.OP_REQUEST, VLAN1, MAC1, null, theirIp, ourSecondIp);
Jonathan Hartdbdbdbb2014-10-06 18:35:30 -0700726
727 proxyArp.reply(arpRequest, LOC1);
728
729 assertEquals(1, packetService.packets.size());
Luca Pretef70d3992015-10-30 16:24:14 -0700730 arpReply = buildArp(ARP.OP_REPLY, VLAN1, secondMac, MAC1, ourSecondIp, theirIp);
Jonathan Hartdbdbdbb2014-10-06 18:35:30 -0700731 verifyPacketOut(arpReply, LOC1, packetService.packets.get(0));
732 }
733
Charles Chanad3b5502015-10-23 16:24:20 -0700734 /**
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 Pretef70d3992015-10-30 16:24:14 -0700741 Ip6Address ourSecondIp = Ip6Address.valueOf("2000::2");
Charles Chanad3b5502015-10-23 16:24:20 -0700742 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 Hartd9df7bd2015-11-10 17:10:25 -0800754 Ethernet ndpRequest = buildNdp(ICMP6.NEIGHBOR_SOLICITATION,
755 MAC2,
756 MacAddress.valueOf("33:33:ff:00:00:01"),
757 theirIp,
758 ourFirstIp);
Luca Pretef70d3992015-10-30 16:24:14 -0700759
Charles Chanad3b5502015-10-23 16:24:20 -0700760 proxyArp.reply(ndpRequest, LOC1);
761 assertEquals(1, packetService.packets.size());
762
Jonathan Hartd9df7bd2015-11-10 17:10:25 -0800763 Ethernet ndpReply = buildNdp(ICMP6.NEIGHBOR_ADVERTISEMENT,
764 firstMac,
765 MAC2,
766 ourFirstIp,
767 theirIp);
Charles Chanad3b5502015-10-23 16:24:20 -0700768 verifyPacketOut(ndpReply, LOC1, packetService.packets.get(0));
769
770 // Test a request for the second address on that port
771 packetService.packets.clear();
Jonathan Hartd9df7bd2015-11-10 17:10:25 -0800772 ndpRequest = buildNdp(ICMP6.NEIGHBOR_SOLICITATION,
773 MAC2,
774 MacAddress.valueOf("33:33:ff:00:00:01"),
775 theirIp,
776 ourSecondIp);
Charles Chanad3b5502015-10-23 16:24:20 -0700777 proxyArp.reply(ndpRequest, LOC1);
778 assertEquals(1, packetService.packets.size());
779
Jonathan Hartd9df7bd2015-11-10 17:10:25 -0800780 ndpReply = buildNdp(ICMP6.NEIGHBOR_ADVERTISEMENT,
781 secondMac,
782 MAC2,
783 ourSecondIp,
784 theirIp);
Charles Chanad3b5502015-10-23 16:24:20 -0700785 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 Hartdbdbdbb2014-10-06 18:35:30 -0700791 @Test
792 public void testReplyExternalPortBadRequest() {
793 replay(hostService); // no further host service expectations
Jonathan Hart4cb39882015-08-12 23:50:55 -0400794 replay(interfaceService);
Jonathan Hartdbdbdbb2014-10-06 18:35:30 -0700795
Pavlin Radoslavov5b5dc482014-11-05 14:48:08 -0800796 Ip4Address theirIp = Ip4Address.valueOf("10.0.1.254");
Jonathan Hartdbdbdbb2014-10-06 18:35:30 -0700797
798 // Request for a valid external IP address but coming in the wrong port
Luca Pretef70d3992015-10-30 16:24:14 -0700799 Ethernet arpRequest = buildArp(ARP.OP_REQUEST, VLAN1, MAC1, null, theirIp,
Aaron Kruglikovd8123832015-07-06 14:20:25 -0700800 Ip4Address.valueOf("10.0.3.1"));
Jonathan Hartdbdbdbb2014-10-06 18:35:30 -0700801 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 Pretef70d3992015-10-30 16:24:14 -0700806 arpRequest = buildArp(ARP.OP_REQUEST, VLAN1, MAC1, null, theirIp, IP1);
Jonathan Hartdbdbdbb2014-10-06 18:35:30 -0700807 proxyArp.reply(arpRequest, LOC1);
808 assertEquals(0, packetService.packets.size());
809 }
810
Charles Chanad3b5502015-10-23 16:24:20 -0700811 /**
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 Hartd9df7bd2015-11-10 17:10:25 -0800821 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 Chanad3b5502015-10-23 16:24:20 -0700826 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 Hartd9df7bd2015-11-10 17:10:25 -0800831 ndpRequest = buildNdp(ICMP6.NEIGHBOR_SOLICITATION,
832 MAC1,
833 MacAddress.valueOf("33:33:ff:00:00:01"),
834 theirIp,
835 IP3);
Charles Chanad3b5502015-10-23 16:24:20 -0700836 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 Hartdbdbdbb2014-10-06 18:35:30 -0700843 @Test
844 public void testReplyToRequestFromUs() {
Pavlin Radoslavov5b5dc482014-11-05 14:48:08 -0800845 Ip4Address ourIp = Ip4Address.valueOf("10.0.1.1");
Jonathan Hartdbdbdbb2014-10-06 18:35:30 -0700846 MacAddress ourMac = MacAddress.valueOf(1L);
Pavlin Radoslavov5b5dc482014-11-05 14:48:08 -0800847 Ip4Address theirIp = Ip4Address.valueOf("10.0.1.100");
Jonathan Hartdbdbdbb2014-10-06 18:35:30 -0700848
Jonathan Hart7d1496b2015-03-10 22:00:48 -0700849 expect(hostService.getHostsByIp(theirIp)).andReturn(Collections.emptySet());
Jonathan Hart4cb39882015-08-12 23:50:55 -0400850 expect(interfaceService.getInterfacesByIp(ourIp))
Sho SHIMIZU891162b2016-06-06 16:32:01 -0700851 .andReturn(Collections.singleton(new Interface(Interface.NO_INTERFACE_NAME, getLocation(1),
Jonathan Hart00cddda2016-02-16 10:30:37 -0800852 Collections.singletonList(new InterfaceIpAddress(ourIp, IpPrefix.valueOf("10.0.1.1/24"))),
Jonathan Hart4cb39882015-08-12 23:50:55 -0400853 ourMac, VLAN1)));
Jonathan Hart7d1496b2015-03-10 22:00:48 -0700854 expect(hostService.getHost(HostId.hostId(ourMac, VLAN1))).andReturn(null);
855 replay(hostService);
Jonathan Hart4cb39882015-08-12 23:50:55 -0400856 replay(interfaceService);
Jonathan Hart7d1496b2015-03-10 22:00:48 -0700857
Jonathan Hartdbdbdbb2014-10-06 18:35:30 -0700858 // This is a request from something inside our network (like a BGP
859 // daemon) to an external host.
Luca Pretef70d3992015-10-30 16:24:14 -0700860 Ethernet arpRequest = buildArp(ARP.OP_REQUEST, VLAN1, ourMac, null, ourIp, theirIp);
Aaron Kruglikovd8123832015-07-06 14:20:25 -0700861 //Ensure the packet is allowed through (it is not to an internal port)
Jonathan Hartdbdbdbb2014-10-06 18:35:30 -0700862
Aaron Kruglikovd8123832015-07-06 14:20:25 -0700863 proxyArp.reply(arpRequest, getLocation(5));
Jonathan Hartdbdbdbb2014-10-06 18:35:30 -0700864 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 Hart704ca142014-10-09 09:34:39 -0700873 /**
Charles Chanad3b5502015-10-23 16:24:20 -0700874 * 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 SHIMIZU891162b2016-06-06 16:32:01 -0700884 .andReturn(Collections.singleton(new Interface(Interface.NO_INTERFACE_NAME, getLocation(1),
Jonathan Hart00cddda2016-02-16 10:30:37 -0800885 Collections.singletonList(new InterfaceIpAddress(
Charles Chanad3b5502015-10-23 16:24:20 -0700886 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 Hartd9df7bd2015-11-10 17:10:25 -0800896 Ethernet ndpRequest = buildNdp(ICMP6.NEIGHBOR_SOLICITATION,
897 ourMac,
898 MacAddress.valueOf("33:33:ff:00:00:01"),
899 ourIp,
900 theirIp);
Charles Chanad3b5502015-10-23 16:24:20 -0700901
Charles Chanad3b5502015-10-23 16:24:20 -0700902 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 Hart6cd2f352015-01-13 17:44:45 -0800913 * Tests {@link ProxyArpManager#forward(Ethernet, ConnectPoint)} in the case where the
Jonathan Hart704ca142014-10-09 09:34:39 -0700914 * 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 Kruglikovd8123832015-07-06 14:20:25 -0700920 Collections.singleton(IP1));
Thomas Vachuskab2c47a72015-08-05 14:22:54 -0700921 Host host2 = new DefaultHost(PID, HID2, MAC2, VLAN1, LOC2,
922 Collections.singleton(IP2));
Jonathan Hart704ca142014-10-09 09:34:39 -0700923
924 expect(hostService.getHost(HID1)).andReturn(host1);
Thomas Vachuskab2c47a72015-08-05 14:22:54 -0700925 expect(hostService.getHost(HID2)).andReturn(host2);
Jonathan Hart704ca142014-10-09 09:34:39 -0700926 replay(hostService);
Jonathan Hart4cb39882015-08-12 23:50:55 -0400927 replay(interfaceService);
Jonathan Hart704ca142014-10-09 09:34:39 -0700928
Luca Pretef70d3992015-10-30 16:24:14 -0700929 Ethernet arpRequest = buildArp(ARP.OP_REPLY, VLAN1, MAC2, MAC1, IP2, IP1);
Jonathan Hart704ca142014-10-09 09:34:39 -0700930
Jonathan Hartf84591d2015-01-16 14:33:43 -0800931 proxyArp.forward(arpRequest, LOC2);
Jonathan Hart704ca142014-10-09 09:34:39 -0700932
933 assertEquals(1, packetService.packets.size());
934 OutboundPacket packet = packetService.packets.get(0);
935
936 verifyPacketOut(arpRequest, LOC1, packet);
937 }
938
939 /**
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800940 * Tests {@link ProxyArpManager#forward(Ethernet, ConnectPoint)} in the case where the
Charles Chanad3b5502015-10-23 16:24:20 -0700941 * 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 Hartd9df7bd2015-11-10 17:10:25 -0800956 Ethernet ndpRequest = buildNdp(ICMP6.NEIGHBOR_SOLICITATION,
957 MAC4, SOLICITED_MAC3,
958 IP4, IP3);
Charles Chanad3b5502015-10-23 16:24:20 -0700959
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 Hart704ca142014-10-09 09:34:39 -0700970 * 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 Pretef70d3992015-10-30 16:24:14 -0700975 expect(hostService.getHost(HID2)).andReturn(null);
Jonathan Hart704ca142014-10-09 09:34:39 -0700976 replay(hostService);
Jonathan Hart4cb39882015-08-12 23:50:55 -0400977 replay(interfaceService);
Jonathan Hart704ca142014-10-09 09:34:39 -0700978
Luca Pretef70d3992015-10-30 16:24:14 -0700979 Ethernet arpRequest = buildArp(ARP.OP_REPLY, VLAN1, MAC1, MAC2, IP1, IP2);
Jonathan Hart704ca142014-10-09 09:34:39 -0700980
Luca Pretef70d3992015-10-30 16:24:14 -0700981 proxyArp.forward(arpRequest, getLocation(NUM_DEVICES));
Aaron Kruglikovd8123832015-07-06 14:20:25 -0700982
Luca Pretef70d3992015-10-30 16:24:14 -0700983 verifyFlood(arpRequest, noConfigCPoints);
Jonathan Hart704ca142014-10-09 09:34:39 -0700984 }
985
986 /**
Charles Chanad3b5502015-10-23 16:24:20 -0700987 * 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 Hartd9df7bd2015-11-10 17:10:25 -0800997 Ethernet ndpRequest = buildNdp(ICMP6.NEIGHBOR_SOLICITATION,
998 MAC4, SOLICITED_MAC3,
999 IP4, IP3);
Charles Chanad3b5502015-10-23 16:24:20 -07001000
Luca Pretef70d3992015-10-30 16:24:14 -07001001 proxyArp.forward(ndpRequest, getLocation(NUM_DEVICES));
Charles Chanad3b5502015-10-23 16:24:20 -07001002
Luca Pretef70d3992015-10-30 16:24:14 -07001003 verifyFlood(ndpRequest, noConfigCPoints);
Charles Chanad3b5502015-10-23 16:24:20 -07001004 }
1005
1006 /**
Jonathan Hartf84591d2015-01-16 14:33:43 -08001007 * Verifies that the given packet was flooded out all available edge ports,
1008 * except for the input port.
Jonathan Hart704ca142014-10-09 09:34:39 -07001009 *
1010 * @param packet the packet that was expected to be flooded
Luca Pretef70d3992015-10-30 16:24:14 -07001011 * @param connectPoints the connectPoints where the outpacket should be
1012 * observed
Jonathan Hart704ca142014-10-09 09:34:39 -07001013 */
Luca Pretef70d3992015-10-30 16:24:14 -07001014 private void verifyFlood(Ethernet packet, List<ConnectPoint> connectPoints) {
1015
Jonathan Hartf84591d2015-01-16 14:33:43 -08001016 // There should be 1 less than NUM_FLOOD_PORTS; the inPort should be excluded.
Luca Pretef70d3992015-10-30 16:24:14 -07001017 assertEquals(connectPoints.size() - 1, packetService.packets.size());
Jonathan Hart704ca142014-10-09 09:34:39 -07001018
1019 Collections.sort(packetService.packets,
Jonathan Hart4cb39882015-08-12 23:50:55 -04001020 (o1, o2) -> o1.sendThrough().uri().compareTo(o2.sendThrough().uri()));
Jonathan Hart704ca142014-10-09 09:34:39 -07001021
Luca Pretef70d3992015-10-30 16:24:14 -07001022 for (int i = 0; i < connectPoints.size() - 1; i++) {
Jonathan Hart704ca142014-10-09 09:34:39 -07001023 OutboundPacket outboundPacket = packetService.packets.get(i);
Luca Pretef70d3992015-10-30 16:24:14 -07001024 verifyPacketOut(packet, connectPoints.get(i), outboundPacket);
Jonathan Hart704ca142014-10-09 09:34:39 -07001025 }
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 Vachuska27bee092015-06-23 19:03:10 -07001032 * @param outPort the port the packet was expected to be sent out
1033 * @param actual the actual OutboundPacket to verify
Jonathan Hart704ca142014-10-09 09:34:39 -07001034 */
1035 private void verifyPacketOut(Ethernet expected, ConnectPoint outPort,
Thomas Vachuska27bee092015-06-23 19:03:10 -07001036 OutboundPacket actual) {
Yuta HIGUCHI3e848a82014-11-02 20:19:42 -08001037 assertArrayEquals(expected.serialize(), actual.data().array());
Ray Milkey42507352015-03-20 15:16:10 -07001038 assertEquals(1, actual.treatment().immediate().size());
Jonathan Hart704ca142014-10-09 09:34:39 -07001039 assertEquals(outPort.deviceId(), actual.sendThrough());
Ray Milkey42507352015-03-20 15:16:10 -07001040 Instruction instruction = actual.treatment().immediate().get(0);
Jonathan Hart704ca142014-10-09 09:34:39 -07001041 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 Hartdbdbdbb2014-10-06 18:35:30 -07001055 private static HostLocation getLocation(int i) {
1056 return new HostLocation(new ConnectPoint(getDeviceId(i), P1), 123L);
1057 }
1058
Jonathan Hart704ca142014-10-09 09:34:39 -07001059 /**
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 Vachuska27bee092015-06-23 19:03:10 -07001065 * @param srcIp source IP address
1066 * @param dstIp destination IP address
Jonathan Hart704ca142014-10-09 09:34:39 -07001067 * @return the ARP packet
1068 */
Luca Pretef70d3992015-10-30 16:24:14 -07001069 private Ethernet buildArp(short opcode, VlanId vlanId, MacAddress srcMac,
1070 MacAddress dstMac, Ip4Address srcIp, Ip4Address dstIp) {
Jonathan Hart704ca142014-10-09 09:34:39 -07001071 Ethernet eth = new Ethernet();
1072
1073 if (dstMac == null) {
Yuta HIGUCHI3e848a82014-11-02 20:19:42 -08001074 eth.setDestinationMACAddress(MacAddress.BROADCAST);
Jonathan Hart704ca142014-10-09 09:34:39 -07001075 } else {
Yuta HIGUCHI3e848a82014-11-02 20:19:42 -08001076 eth.setDestinationMACAddress(dstMac);
Jonathan Hart704ca142014-10-09 09:34:39 -07001077 }
1078
Yuta HIGUCHI3e848a82014-11-02 20:19:42 -08001079 eth.setSourceMACAddress(srcMac);
Jonathan Hart704ca142014-10-09 09:34:39 -07001080 eth.setEtherType(Ethernet.TYPE_ARP);
Luca Pretef70d3992015-10-30 16:24:14 -07001081 eth.setVlanID(vlanId.toShort());
Jonathan Hart704ca142014-10-09 09:34:39 -07001082
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 Radoslavov5b5dc482014-11-05 14:48:08 -08001088 arp.setProtocolAddressLength((byte) Ip4Address.BYTE_LENGTH);
Jonathan Hart704ca142014-10-09 09:34:39 -07001089 arp.setHardwareAddressLength((byte) Ethernet.DATALAYER_ADDRESS_LENGTH);
Yuta HIGUCHI3e848a82014-11-02 20:19:42 -08001090 arp.setSenderHardwareAddress(srcMac.toBytes());
Jonathan Hart704ca142014-10-09 09:34:39 -07001091
1092 if (dstMac == null) {
Luca Pretef70d3992015-10-30 16:24:14 -07001093 arp.setTargetHardwareAddress(zeroMacAddress);
Jonathan Hart704ca142014-10-09 09:34:39 -07001094 } else {
Yuta HIGUCHI3e848a82014-11-02 20:19:42 -08001095 arp.setTargetHardwareAddress(dstMac.toBytes());
Jonathan Hart704ca142014-10-09 09:34:39 -07001096 }
1097
1098 arp.setSenderProtocolAddress(srcIp.toOctets());
1099 arp.setTargetProtocolAddress(dstIp.toOctets());
1100
1101 eth.setPayload(arp);
1102 return eth;
1103 }
1104
1105 /**
Charles Chanad3b5502015-10-23 16:24:20 -07001106 * 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 Hartd9df7bd2015-11-10 17:10:25 -08001115 private Ethernet buildNdp(byte type, MacAddress srcMac, MacAddress dstMac,
Charles Chanad3b5502015-10-23 16:24:20 -07001116 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 Hart704ca142014-10-09 09:34:39 -07001161 * Test PacketService implementation that simply stores OutboundPackets
1162 * passed to {@link #emit(OutboundPacket)} for later verification.
1163 */
Thomas Vachuska27bee092015-06-23 19:03:10 -07001164 class TestPacketService extends PacketServiceAdapter {
Jonathan Hart704ca142014-10-09 09:34:39 -07001165
1166 List<OutboundPacket> packets = new ArrayList<>();
1167
1168 @Override
Jonathan Hart704ca142014-10-09 09:34:39 -07001169 public void emit(OutboundPacket packet) {
1170 packets.add(packet);
1171 }
Jonathan Hart3cfce8e2015-01-14 16:43:27 -08001172
Jonathan Hart704ca142014-10-09 09:34:39 -07001173 }
Aaron Kruglikovd8123832015-07-06 14:20:25 -07001174
Thomas Vachuskab2c47a72015-08-05 14:22:54 -07001175 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 Hart704ca142014-10-09 09:34:39 -07001186}