blob: 1a7dee5a283a2cfd6132c233e77caed3234261f3 [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
Jonathan Hart00cddda2016-02-16 10:30:37 -0800299 Interface intf1 = new Interface(cp, Lists.newArrayList(ia1, ia3),
Jonathan Hart4cb39882015-08-12 23:50:55 -0400300 MacAddress.valueOf(2 * i - 1),
301 VlanId.vlanId((short) 1));
Jonathan Hart00cddda2016-02-16 10:30:37 -0800302 Interface intf2 = new Interface(cp, Lists.newArrayList(ia2, ia4),
Jonathan Hart4cb39882015-08-12 23:50:55 -0400303 MacAddress.valueOf(2 * i),
304 VlanId.NONE);
Luca Pretef70d3992015-10-30 16:24:14 -0700305
Jonathan Hart4cb39882015-08-12 23:50:55 -0400306 interfaces.add(intf1);
307 interfaces.add(intf2);
Jonathan Hartdbdbdbb2014-10-06 18:35:30 -0700308
Luca Pretef70d3992015-10-30 16:24:14 -0700309 vlanOneSet.add(intf1);
310
Jonathan Hart4cb39882015-08-12 23:50:55 -0400311 expect(interfaceService.getInterfacesByPort(cp))
312 .andReturn(Sets.newHashSet(intf1, intf2)).anyTimes();
Jonathan Hartdbdbdbb2014-10-06 18:35:30 -0700313 }
Luca Pretef70d3992015-10-30 16:24:14 -0700314 for (int i = LAST_CONF_DEVICE_INTF_VLAN_IP + 1; i <= LAST_CONF_DEVICE_INTF_VLAN; i++) {
315 ConnectPoint cp = new ConnectPoint(getDeviceId(i), P1);
Jonathan Hart00cddda2016-02-16 10:30:37 -0800316 Interface intf1 = new Interface(cp, Collections.emptyList(),
Luca Pretef70d3992015-10-30 16:24:14 -0700317 MacAddress.NONE,
318 VlanId.vlanId((short) 1));
Jonathan Hartdbdbdbb2014-10-06 18:35:30 -0700319
Luca Pretef70d3992015-10-30 16:24:14 -0700320 interfaces.add(intf1);
321 vlanOneSet.add(intf1);
Jonathan Hart4cb39882015-08-12 23:50:55 -0400322
323 expect(interfaceService.getInterfacesByPort(cp))
Luca Pretef70d3992015-10-30 16:24:14 -0700324 .andReturn(Sets.newHashSet(intf1)).anyTimes();
325 }
326 expect(interfaceService.getInterfacesByVlan(VLAN1))
327 .andReturn(vlanOneSet).anyTimes();
328 expect(interfaceService.getInterfacesByVlan(VLAN10))
329 .andReturn(Collections.emptySet()).anyTimes();
330 expect(interfaceService.getInterfaces()).andReturn(interfaces).anyTimes();
331
332 for (int i = LAST_CONF_DEVICE_INTF_VLAN + 1; i <= NUM_DEVICES; i++) {
333 ConnectPoint cp = new ConnectPoint(getDeviceId(i),
334 P1);
335 expect(interfaceService.getInterfacesByPort(cp))
Jonathan Hart4cb39882015-08-12 23:50:55 -0400336 .andReturn(Collections.emptySet()).anyTimes();
Jonathan Hartdbdbdbb2014-10-06 18:35:30 -0700337 }
338 }
339
Jonathan Hart704ca142014-10-09 09:34:39 -0700340 /**
Luca Pretef70d3992015-10-30 16:24:14 -0700341 * Populates edge ports in the EdgePortService to return all port 1
342 * as edge ports.
343 */
344 private void popluateEdgePortService() {
345 Set<ConnectPoint> edgeConnectPoints = new HashSet<>();
346
347 for (int i = 1; i <= NUM_DEVICES; i++) {
348 for (int j = 1; j <= NUM_PORTS_PER_DEVICE; j++) {
349 ConnectPoint edgeConnectPoint = new ConnectPoint(
350 getDeviceId(i),
351 PortNumber.portNumber(1));
352 ConnectPoint noEdgeConnectPointOne = new ConnectPoint(
353 getDeviceId(i),
354 PortNumber.portNumber(2));
355 ConnectPoint noEdgeConnectPointTwo = new ConnectPoint(
356 getDeviceId(i),
357 PortNumber.portNumber(3));
358
359 edgeConnectPoints.add(edgeConnectPoint);
360
361 expect(edgePortService.isEdgePoint(edgeConnectPoint))
362 .andReturn(true).anyTimes();
363 expect(edgePortService.isEdgePoint(noEdgeConnectPointOne))
364 .andReturn(false).anyTimes();
365 expect(edgePortService.isEdgePoint(noEdgeConnectPointTwo))
366 .andReturn(false).anyTimes();
367 }
368 }
369 expect(edgePortService.getEdgePoints())
370 .andReturn(edgeConnectPoints).anyTimes();
371
372 replay(edgePortService);
373 }
374
375 /**
376 * Creates a list of connect points used to verify floodling on ports
377 * with no interfaces configured (all ports without interface config).
378 */
379 private void setupNoConfigCPoints() {
380 for (int i = NUM_DEVICES / 2 + 2; i <= NUM_DEVICES; i++) {
381 ConnectPoint connectPoint = new ConnectPoint(
382 getDeviceId(i),
383 PortNumber.portNumber(1));
384 noConfigCPoints.add(connectPoint);
385 }
386 }
387
388 /**
389 * Creates a list of connect points used to verify floodling on ports
390 * with interfaces configured (both VLAN and IP).
391 */
392 private void setupconfigIpCPoints() {
393 for (int i = 1; i <= 3; i++) {
394 ConnectPoint connectPoint = new ConnectPoint(
395 getDeviceId(i),
396 PortNumber.portNumber(1));
397 configIpCPoints.add(connectPoint);
398 }
399 }
400
401 /**
402 * Creates a list of connect points used to verify floodling on ports
403 * with interfaces configured (both VLAN and IP).
404 */
405 private void setupconfigVlanCPoints() {
406 for (int i = LAST_CONF_DEVICE_INTF_VLAN_IP + 1; i <= LAST_CONF_DEVICE_INTF_VLAN; i++) {
407 ConnectPoint connectPoint = new ConnectPoint(
408 getDeviceId(i),
409 PortNumber.portNumber(1));
410 configVlanCPoints.add(connectPoint);
411 }
412 }
413
414 /**
Jonathan Hart7d1496b2015-03-10 22:00:48 -0700415 * Tests {@link ProxyArpManager#isKnown(org.onlab.packet.IpAddress)} in the
416 * case where the IP address is not known.
Jonathan Hart704ca142014-10-09 09:34:39 -0700417 * Verifies the method returns false.
418 */
419 @Test
420 public void testNotKnown() {
421 expect(hostService.getHostsByIp(IP1)).andReturn(Collections.<Host>emptySet());
422 replay(hostService);
Jonathan Hart4cb39882015-08-12 23:50:55 -0400423 replay(interfaceService);
Jonathan Hart704ca142014-10-09 09:34:39 -0700424
Jonathan Hartf84591d2015-01-16 14:33:43 -0800425 assertFalse(proxyArp.isKnown(IP1));
Jonathan Hart704ca142014-10-09 09:34:39 -0700426 }
427
428 /**
Jonathan Hart7d1496b2015-03-10 22:00:48 -0700429 * Tests {@link ProxyArpManager#isKnown(org.onlab.packet.IpAddress)} in the
430 * case where the IP address is known.
Jonathan Hart704ca142014-10-09 09:34:39 -0700431 * Verifies the method returns true.
432 */
433 @Test
434 public void testKnown() {
435 Host host1 = createMock(Host.class);
436 Host host2 = createMock(Host.class);
437
438 expect(hostService.getHostsByIp(IP1))
439 .andReturn(Sets.newHashSet(host1, host2));
440 replay(hostService);
Jonathan Hart4cb39882015-08-12 23:50:55 -0400441 replay(interfaceService);
Jonathan Hart704ca142014-10-09 09:34:39 -0700442
Jonathan Hartf84591d2015-01-16 14:33:43 -0800443 assertTrue(proxyArp.isKnown(IP1));
Jonathan Hart704ca142014-10-09 09:34:39 -0700444 }
445
446 /**
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800447 * Tests {@link ProxyArpManager#reply(Ethernet, ConnectPoint)} in the case where the
Jonathan Hart704ca142014-10-09 09:34:39 -0700448 * destination host is known.
Luca Pretef70d3992015-10-30 16:24:14 -0700449 * Two host using the same VLAN are registered on the host service on devices 5 and 6.
450 * Host on port 6 asks for the MAC of the device on port 5.
451 * Since the destination mac address is known, the request is not flooded to anywhere
452 * and ONOS directly builds an ARP reply, sended back to the requester on device 6.
453 * It's verified that a proper ARP reply is received on port 1 of device 6.
Jonathan Hart704ca142014-10-09 09:34:39 -0700454 */
455 @Test
456 public void testReplyKnown() {
Luca Pretef70d3992015-10-30 16:24:14 -0700457 Host requestor = new DefaultHost(PID, HID1, MAC1, VLAN1, getLocation(NUM_DEVICES),
Aaron Kruglikovd8123832015-07-06 14:20:25 -0700458 Collections.singleton(IP1));
Jonathan Hart704ca142014-10-09 09:34:39 -0700459
Luca Pretef70d3992015-10-30 16:24:14 -0700460 Host replyer = new DefaultHost(PID, HID2, MAC2, VLAN1, getLocation(NUM_DEVICES - 1),
Aaron Kruglikovd8123832015-07-06 14:20:25 -0700461 Collections.singleton(IP2));
Jonathan Hart704ca142014-10-09 09:34:39 -0700462
Luca Pretef70d3992015-10-30 16:24:14 -0700463 expect(hostService.getHostsByIp(IP2))
Thomas Vachuska27bee092015-06-23 19:03:10 -0700464 .andReturn(Collections.singleton(replyer));
Luca Pretef70d3992015-10-30 16:24:14 -0700465 expect(hostService.getHost(HID1)).andReturn(requestor);
Jonathan Hart704ca142014-10-09 09:34:39 -0700466
467 replay(hostService);
Jonathan Hart4cb39882015-08-12 23:50:55 -0400468 replay(interfaceService);
Jonathan Hart704ca142014-10-09 09:34:39 -0700469
Luca Pretef70d3992015-10-30 16:24:14 -0700470 Ethernet arpRequest = buildArp(ARP.OP_REQUEST, VLAN1, MAC1, null, IP1, IP2);
Jonathan Hart704ca142014-10-09 09:34:39 -0700471
Luca Pretef70d3992015-10-30 16:24:14 -0700472 proxyArp.reply(arpRequest, getLocation(NUM_DEVICES));
Jonathan Hart704ca142014-10-09 09:34:39 -0700473
474 assertEquals(1, packetService.packets.size());
Luca Pretef70d3992015-10-30 16:24:14 -0700475 Ethernet arpReply = buildArp(ARP.OP_REPLY, VLAN1, MAC2, MAC1, IP2, IP1);
476 verifyPacketOut(arpReply, getLocation(NUM_DEVICES), packetService.packets.get(0));
Jonathan Hart704ca142014-10-09 09:34:39 -0700477 }
478
479 /**
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800480 * Tests {@link ProxyArpManager#reply(Ethernet, ConnectPoint)} in the case where the
Charles Chanad3b5502015-10-23 16:24:20 -0700481 * destination host is known.
482 * Verifies the correct NDP reply is sent out the correct port.
483 */
484 @Test
485 public void testReplyKnownIpv6() {
Charles Chanad3b5502015-10-23 16:24:20 -0700486 Host replyer = new DefaultHost(PID, HID3, MAC3, VLAN1, getLocation(4),
487 Collections.singleton(IP3));
488
489 Host requestor = new DefaultHost(PID, HID4, MAC4, VLAN1, getLocation(5),
490 Collections.singleton(IP4));
491
492 expect(hostService.getHostsByIp(IP3))
493 .andReturn(Collections.singleton(replyer));
494 expect(hostService.getHost(HID4)).andReturn(requestor);
495
496 replay(hostService);
497 replay(interfaceService);
498
Jonathan Hartd9df7bd2015-11-10 17:10:25 -0800499 Ethernet ndpRequest = buildNdp(ICMP6.NEIGHBOR_SOLICITATION,
500 MAC4, SOLICITED_MAC3,
501 IP4, IP3);
Charles Chanad3b5502015-10-23 16:24:20 -0700502
503 proxyArp.reply(ndpRequest, getLocation(5));
504
505 assertEquals(1, packetService.packets.size());
Jonathan Hartd9df7bd2015-11-10 17:10:25 -0800506 Ethernet ndpReply = buildNdp(ICMP6.NEIGHBOR_ADVERTISEMENT,
507 MAC3, MAC4, IP3, IP4);
Charles Chanad3b5502015-10-23 16:24:20 -0700508 verifyPacketOut(ndpReply, getLocation(5), packetService.packets.get(0));
509 }
510
511 /**
512 * Tests {@link ProxyArpManager#reply(Ethernet, ConnectPoint)} in the case where the
Jonathan Hart704ca142014-10-09 09:34:39 -0700513 * destination host is not known.
Luca Pretef70d3992015-10-30 16:24:14 -0700514 * Only a requestor is present (on device 6, port 1). The device has a VLAN configured
515 * which is not configured anywhere in the system.
516 * Since the destination is not known, and since the ARP request can't be sent out of
517 * interfaces configured, the ARP request is flooded out of ports 4 and 5.
Jonathan Hart704ca142014-10-09 09:34:39 -0700518 * Verifies the ARP request is flooded out the correct edge ports.
519 */
520 @Test
521 public void testReplyUnknown() {
Luca Pretef70d3992015-10-30 16:24:14 -0700522 Host requestor = new DefaultHost(PID, HID10, MAC10, VLAN10, getLocation(NUM_DEVICES),
523 Collections.singleton(IP1));
Aaron Kruglikovd8123832015-07-06 14:20:25 -0700524
Luca Pretef70d3992015-10-30 16:24:14 -0700525 expect(hostService.getHostsByIp(IP2))
Jonathan Hart4cb39882015-08-12 23:50:55 -0400526 .andReturn(Collections.emptySet());
Luca Pretef70d3992015-10-30 16:24:14 -0700527 expect(interfaceService.getInterfacesByIp(IP1))
Jonathan Hart4cb39882015-08-12 23:50:55 -0400528 .andReturn(Collections.emptySet());
Luca Pretef70d3992015-10-30 16:24:14 -0700529 expect(hostService.getHost(HID10)).andReturn(requestor);
Jonathan Hart704ca142014-10-09 09:34:39 -0700530
531 replay(hostService);
Jonathan Hart4cb39882015-08-12 23:50:55 -0400532 replay(interfaceService);
Jonathan Hart704ca142014-10-09 09:34:39 -0700533
Luca Pretef70d3992015-10-30 16:24:14 -0700534 Ethernet arpRequest = buildArp(ARP.OP_REQUEST, VLAN10, MAC10, null, IP1, IP2);
Jonathan Hart704ca142014-10-09 09:34:39 -0700535
Luca Pretef70d3992015-10-30 16:24:14 -0700536 proxyArp.reply(arpRequest, getLocation(NUM_DEVICES));
Aaron Kruglikovd8123832015-07-06 14:20:25 -0700537
Luca Pretef70d3992015-10-30 16:24:14 -0700538 verifyFlood(arpRequest, noConfigCPoints);
Jonathan Hart704ca142014-10-09 09:34:39 -0700539 }
540
541 /**
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800542 * Tests {@link ProxyArpManager#reply(Ethernet, ConnectPoint)} in the case where the
Charles Chanad3b5502015-10-23 16:24:20 -0700543 * destination host is not known.
544 * Verifies the NDP request is flooded out the correct edge ports.
545 */
546 @Test
547 public void testReplyUnknownIpv6() {
Luca Pretef70d3992015-10-30 16:24:14 -0700548 Host requestor = new DefaultHost(PID, HID4, MAC4, VLAN1, getLocation(NUM_DEVICES),
Charles Chanad3b5502015-10-23 16:24:20 -0700549 Collections.singleton(IP4));
550
551 expect(hostService.getHostsByIp(IP3))
552 .andReturn(Collections.emptySet());
553 expect(interfaceService.getInterfacesByIp(IP4))
554 .andReturn(Collections.emptySet());
555 expect(hostService.getHost(HID4)).andReturn(requestor);
556
557 replay(hostService);
558 replay(interfaceService);
559
Jonathan Hartd9df7bd2015-11-10 17:10:25 -0800560 Ethernet ndpRequest = buildNdp(ICMP6.NEIGHBOR_SOLICITATION,
561 MAC4, SOLICITED_MAC3,
562 IP4, IP3);
Charles Chanad3b5502015-10-23 16:24:20 -0700563
Luca Pretef70d3992015-10-30 16:24:14 -0700564 proxyArp.reply(ndpRequest, getLocation(NUM_DEVICES));
Charles Chanad3b5502015-10-23 16:24:20 -0700565
Luca Pretef70d3992015-10-30 16:24:14 -0700566 verifyFlood(ndpRequest, noConfigCPoints);
Charles Chanad3b5502015-10-23 16:24:20 -0700567 }
568
569 /**
570 * Tests {@link ProxyArpManager#reply(Ethernet, ConnectPoint)} in the case where the
Jonathan Hart704ca142014-10-09 09:34:39 -0700571 * destination host is known for that IP address, but is not on the same
572 * VLAN as the source host.
Luca Pretef70d3992015-10-30 16:24:14 -0700573 * An host is connected on device 6, port 1 where no interfaces are defined. It sends
574 * ARP requests from VLAN10, not configured anywhere in the network. Another host with
575 * the IP address requested lives on device 5, port 1 in the network. Anyway, since the
576 * host uses another VLAN it's not found and the ARP packet is flooded out of port
577 * 4 and 5.
578 *
Jonathan Hart704ca142014-10-09 09:34:39 -0700579 * Verifies the ARP request is flooded out the correct edge ports.
580 */
581 @Test
582 public void testReplyDifferentVlan() {
Luca Pretef70d3992015-10-30 16:24:14 -0700583 Host requestor = new DefaultHost(PID, HID10, MAC10, VLAN10, getLocation(NUM_DEVICES),
Aaron Kruglikovd8123832015-07-06 14:20:25 -0700584 Collections.singleton(IP1));
Jonathan Hart704ca142014-10-09 09:34:39 -0700585
Luca Pretef70d3992015-10-30 16:24:14 -0700586 Host replyer = new DefaultHost(PID, HID2, MAC2, VLAN2, getLocation(NUM_DEVICES - 1),
Aaron Kruglikovd8123832015-07-06 14:20:25 -0700587 Collections.singleton(IP2));
Jonathan Hart704ca142014-10-09 09:34:39 -0700588
Luca Pretef70d3992015-10-30 16:24:14 -0700589 expect(hostService.getHostsByIp(IP2))
Jonathan Hart704ca142014-10-09 09:34:39 -0700590 .andReturn(Collections.singleton(replyer));
Luca Pretef70d3992015-10-30 16:24:14 -0700591 expect(interfaceService.getInterfacesByIp(IP1))
Jonathan Hart4cb39882015-08-12 23:50:55 -0400592 .andReturn(Collections.emptySet());
Luca Pretef70d3992015-10-30 16:24:14 -0700593 expect(hostService.getHost(HID10)).andReturn(requestor);
Jonathan Hart704ca142014-10-09 09:34:39 -0700594
595 replay(hostService);
Jonathan Hart4cb39882015-08-12 23:50:55 -0400596 replay(interfaceService);
Jonathan Hart704ca142014-10-09 09:34:39 -0700597
Luca Pretef70d3992015-10-30 16:24:14 -0700598 Ethernet arpRequest = buildArp(ARP.OP_REQUEST, VLAN10, MAC10, null, IP1, IP2);
Jonathan Hart704ca142014-10-09 09:34:39 -0700599
Luca Pretef70d3992015-10-30 16:24:14 -0700600 proxyArp.reply(arpRequest, getLocation(NUM_DEVICES));
601
602 verifyFlood(arpRequest, noConfigCPoints);
603 }
604
605 /**
606 * Tests {@link ProxyArpManager#reply(Ethernet, ConnectPoint)} in the case where the
607 * a vlan packet comes in from a port without interfaces configured. The destination
608 * host is unknown for that IP address and there are some interfaces configured on
609 * the same vlan.
610 * It's expected to see the ARP request going out through ports with no interfaces
611 * configured, devices 4 and 5, port 1.
612 *
613 * Verifies the ARP request is flooded out the correct edge ports.
614 */
615 @Test
616 public void testConfiguredVlan() {
617 Host requestor = new DefaultHost(PID, HID1, MAC1, VLAN1, getLocation(NUM_DEVICES),
618 Collections.singleton(IP1));
619
620 expect(hostService.getHostsByIp(IP2))
621 .andReturn(Collections.emptySet());
622 expect(interfaceService.getInterfacesByIp(IP1))
623 .andReturn(Collections.emptySet());
624 expect(hostService.getHost(HID1)).andReturn(requestor);
625
626 replay(hostService);
627 replay(interfaceService);
628
629 Ethernet arpRequest = buildArp(ARP.OP_REQUEST, VLAN1, MAC1, null, IP1, IP2);
630
631 proxyArp.reply(arpRequest, getLocation(NUM_DEVICES));
632
633 verifyFlood(arpRequest, noConfigCPoints);
634 }
635
636 /**
637 * Tests {@link ProxyArpManager#reply(Ethernet, ConnectPoint)} in the case where the
638 * a vlan packet comes in from a port without interfaces configured. The destination
639 * host is not known for that IP address and there are some interfaces configured on
640 * the same vlan.
641 * It's expected to see the ARP request going out through ports with no interfaces
642 * configured, devices 4 and 5, port 1.
643 *
644 * Verifies the ARP request is flooded out the correct edge ports.
645 */
646 @Test
647 public void testConfiguredVlanOnInterfaces() {
648 Host requestor = new DefaultHost(PID, HID1, MAC1, VLAN1, getLocation(6),
649 Collections.singleton(IP1));
650
651 expect(hostService.getHostsByIp(IP2))
652 .andReturn(Collections.emptySet());
653 expect(interfaceService.getInterfacesByIp(IP1))
654 .andReturn(Collections.emptySet());
655 expect(hostService.getHost(HID1)).andReturn(requestor);
656
657 replay(hostService);
658 replay(interfaceService);
659
660 Ethernet arpRequest = buildArp(ARP.OP_REQUEST, VLAN1, MAC1, null, IP1, IP2);
661
Jonathan Hartf84591d2015-01-16 14:33:43 -0800662 proxyArp.reply(arpRequest, getLocation(6));
Jonathan Hart704ca142014-10-09 09:34:39 -0700663
Luca Pretef70d3992015-10-30 16:24:14 -0700664 verifyFlood(arpRequest, configVlanCPoints);
Jonathan Hart704ca142014-10-09 09:34:39 -0700665 }
666
Charles Chanad3b5502015-10-23 16:24:20 -0700667 /**
668 * Tests {@link ProxyArpManager#reply(Ethernet, ConnectPoint)} in the case where the
669 * destination host is known for that IP address, but is not on the same
670 * VLAN as the source host.
671 * Verifies the NDP request is flooded out the correct edge ports.
672 */
673 @Test
674 public void testReplyDifferentVlanIpv6() {
Luca Pretef70d3992015-10-30 16:24:14 -0700675 Host requestor = new DefaultHost(PID, HID4, MAC4, VLAN1, getLocation(NUM_DEVICES),
Charles Chanad3b5502015-10-23 16:24:20 -0700676 Collections.singleton(IP4));
677
Luca Pretef70d3992015-10-30 16:24:14 -0700678 Host replyer = new DefaultHost(PID, HID3, MAC3, VLAN2, getLocation(NUM_DEVICES - 1),
679 Collections.singleton(IP3));
680
Charles Chanad3b5502015-10-23 16:24:20 -0700681 expect(hostService.getHostsByIp(IP3))
682 .andReturn(Collections.singleton(replyer));
683 expect(interfaceService.getInterfacesByIp(IP4))
684 .andReturn(Collections.emptySet());
685 expect(hostService.getHost(HID4)).andReturn(requestor);
686
687 replay(hostService);
688 replay(interfaceService);
689
Jonathan Hartd9df7bd2015-11-10 17:10:25 -0800690 Ethernet ndpRequest = buildNdp(ICMP6.NEIGHBOR_SOLICITATION,
691 MAC4, SOLICITED_MAC3,
692 IP4, IP3);
Charles Chanad3b5502015-10-23 16:24:20 -0700693
Luca Pretef70d3992015-10-30 16:24:14 -0700694 proxyArp.reply(ndpRequest, getLocation(NUM_DEVICES));
Charles Chanad3b5502015-10-23 16:24:20 -0700695
Luca Pretef70d3992015-10-30 16:24:14 -0700696 verifyFlood(ndpRequest, noConfigCPoints);
Charles Chanad3b5502015-10-23 16:24:20 -0700697 }
698
699 /**
700 * Test ARP request from external network to an internal host.
701 */
Jonathan Hartdbdbdbb2014-10-06 18:35:30 -0700702 @Test
703 public void testReplyToRequestForUs() {
Pavlin Radoslavov5b5dc482014-11-05 14:48:08 -0800704 Ip4Address theirIp = Ip4Address.valueOf("10.0.1.254");
705 Ip4Address ourFirstIp = Ip4Address.valueOf("10.0.1.1");
706 Ip4Address ourSecondIp = Ip4Address.valueOf("10.0.2.1");
Jonathan Harta887ba82014-11-03 15:20:52 -0800707 MacAddress firstMac = MacAddress.valueOf(1L);
708 MacAddress secondMac = MacAddress.valueOf(2L);
Jonathan Hartdbdbdbb2014-10-06 18:35:30 -0700709
Luca Pretef70d3992015-10-30 16:24:14 -0700710 Host requestor = new DefaultHost(PID, HID1, MAC1, VLAN1, LOC1,
Aaron Kruglikovd8123832015-07-06 14:20:25 -0700711 Collections.singleton(theirIp));
Jonathan Hartdbdbdbb2014-10-06 18:35:30 -0700712
Luca Pretef70d3992015-10-30 16:24:14 -0700713 expect(hostService.getHost(HID1)).andReturn(requestor);
Jonathan Hartdbdbdbb2014-10-06 18:35:30 -0700714 replay(hostService);
Jonathan Hart4cb39882015-08-12 23:50:55 -0400715 replay(interfaceService);
Jonathan Hartdbdbdbb2014-10-06 18:35:30 -0700716
Luca Pretef70d3992015-10-30 16:24:14 -0700717 Ethernet arpRequest = buildArp(ARP.OP_REQUEST, VLAN1, MAC1, null, theirIp, ourFirstIp);
718
Jonathan Hartdbdbdbb2014-10-06 18:35:30 -0700719 proxyArp.reply(arpRequest, LOC1);
720
721 assertEquals(1, packetService.packets.size());
Luca Pretef70d3992015-10-30 16:24:14 -0700722 Ethernet arpReply = buildArp(ARP.OP_REPLY, VLAN1, firstMac, MAC1, ourFirstIp, theirIp);
Jonathan Hartdbdbdbb2014-10-06 18:35:30 -0700723 verifyPacketOut(arpReply, LOC1, packetService.packets.get(0));
724
725 // Test a request for the second address on that port
726 packetService.packets.clear();
Luca Pretef70d3992015-10-30 16:24:14 -0700727 arpRequest = buildArp(ARP.OP_REQUEST, VLAN1, MAC1, null, theirIp, ourSecondIp);
Jonathan Hartdbdbdbb2014-10-06 18:35:30 -0700728
729 proxyArp.reply(arpRequest, LOC1);
730
731 assertEquals(1, packetService.packets.size());
Luca Pretef70d3992015-10-30 16:24:14 -0700732 arpReply = buildArp(ARP.OP_REPLY, VLAN1, secondMac, MAC1, ourSecondIp, theirIp);
Jonathan Hartdbdbdbb2014-10-06 18:35:30 -0700733 verifyPacketOut(arpReply, LOC1, packetService.packets.get(0));
734 }
735
Charles Chanad3b5502015-10-23 16:24:20 -0700736 /**
737 * Test NDP request from external network to an internal host.
738 */
739 @Test
740 public void testReplyToRequestForUsIpv6() {
741 Ip6Address theirIp = Ip6Address.valueOf("1000::ffff");
742 Ip6Address ourFirstIp = Ip6Address.valueOf("1000::1");
Luca Pretef70d3992015-10-30 16:24:14 -0700743 Ip6Address ourSecondIp = Ip6Address.valueOf("2000::2");
Charles Chanad3b5502015-10-23 16:24:20 -0700744 MacAddress firstMac = MacAddress.valueOf(1L);
745 MacAddress secondMac = MacAddress.valueOf(2L);
746
747 Host requestor = new DefaultHost(PID, HID2, MAC2, VLAN1, LOC1,
748 Collections.singleton(theirIp));
749
750 expect(hostService.getHost(HID2)).andReturn(requestor);
751 expect(hostService.getHostsByIp(ourFirstIp))
752 .andReturn(Collections.singleton(requestor));
753 replay(hostService);
754 replay(interfaceService);
755
Jonathan Hartd9df7bd2015-11-10 17:10:25 -0800756 Ethernet ndpRequest = buildNdp(ICMP6.NEIGHBOR_SOLICITATION,
757 MAC2,
758 MacAddress.valueOf("33:33:ff:00:00:01"),
759 theirIp,
760 ourFirstIp);
Luca Pretef70d3992015-10-30 16:24:14 -0700761
Charles Chanad3b5502015-10-23 16:24:20 -0700762 proxyArp.reply(ndpRequest, LOC1);
763 assertEquals(1, packetService.packets.size());
764
Jonathan Hartd9df7bd2015-11-10 17:10:25 -0800765 Ethernet ndpReply = buildNdp(ICMP6.NEIGHBOR_ADVERTISEMENT,
766 firstMac,
767 MAC2,
768 ourFirstIp,
769 theirIp);
Charles Chanad3b5502015-10-23 16:24:20 -0700770 verifyPacketOut(ndpReply, LOC1, packetService.packets.get(0));
771
772 // Test a request for the second address on that port
773 packetService.packets.clear();
Jonathan Hartd9df7bd2015-11-10 17:10:25 -0800774 ndpRequest = buildNdp(ICMP6.NEIGHBOR_SOLICITATION,
775 MAC2,
776 MacAddress.valueOf("33:33:ff:00:00:01"),
777 theirIp,
778 ourSecondIp);
Charles Chanad3b5502015-10-23 16:24:20 -0700779 proxyArp.reply(ndpRequest, LOC1);
780 assertEquals(1, packetService.packets.size());
781
Jonathan Hartd9df7bd2015-11-10 17:10:25 -0800782 ndpReply = buildNdp(ICMP6.NEIGHBOR_ADVERTISEMENT,
783 secondMac,
784 MAC2,
785 ourSecondIp,
786 theirIp);
Charles Chanad3b5502015-10-23 16:24:20 -0700787 verifyPacketOut(ndpReply, LOC1, packetService.packets.get(0));
788 }
789
790 /**
791 * Request for a valid external IPv4 address but coming in the wrong port.
792 */
Jonathan Hartdbdbdbb2014-10-06 18:35:30 -0700793 @Test
794 public void testReplyExternalPortBadRequest() {
795 replay(hostService); // no further host service expectations
Jonathan Hart4cb39882015-08-12 23:50:55 -0400796 replay(interfaceService);
Jonathan Hartdbdbdbb2014-10-06 18:35:30 -0700797
Pavlin Radoslavov5b5dc482014-11-05 14:48:08 -0800798 Ip4Address theirIp = Ip4Address.valueOf("10.0.1.254");
Jonathan Hartdbdbdbb2014-10-06 18:35:30 -0700799
800 // Request for a valid external IP address but coming in the wrong port
Luca Pretef70d3992015-10-30 16:24:14 -0700801 Ethernet arpRequest = buildArp(ARP.OP_REQUEST, VLAN1, MAC1, null, theirIp,
Aaron Kruglikovd8123832015-07-06 14:20:25 -0700802 Ip4Address.valueOf("10.0.3.1"));
Jonathan Hartdbdbdbb2014-10-06 18:35:30 -0700803 proxyArp.reply(arpRequest, LOC1);
804 assertEquals(0, packetService.packets.size());
805
806 // Request for a valid internal IP address but coming in an external port
807 packetService.packets.clear();
Luca Pretef70d3992015-10-30 16:24:14 -0700808 arpRequest = buildArp(ARP.OP_REQUEST, VLAN1, MAC1, null, theirIp, IP1);
Jonathan Hartdbdbdbb2014-10-06 18:35:30 -0700809 proxyArp.reply(arpRequest, LOC1);
810 assertEquals(0, packetService.packets.size());
811 }
812
Charles Chanad3b5502015-10-23 16:24:20 -0700813 /**
814 * Request for a valid external IPv6 address but coming in the wrong port.
815 */
816 @Test
817 public void testReplyExternalPortBadRequestIpv6() {
818 replay(hostService); // no further host service expectations
819 replay(interfaceService);
820
821 Ip6Address theirIp = Ip6Address.valueOf("1000::ffff");
822
Jonathan Hartd9df7bd2015-11-10 17:10:25 -0800823 Ethernet ndpRequest = buildNdp(ICMP6.NEIGHBOR_SOLICITATION,
824 MAC1,
825 MacAddress.valueOf("33:33:ff:00:00:01"),
826 theirIp,
827 Ip6Address.valueOf("3000::1"));
Charles Chanad3b5502015-10-23 16:24:20 -0700828 proxyArp.reply(ndpRequest, LOC1);
829 assertEquals(0, packetService.packets.size());
830
831 // Request for a valid internal IP address but coming in an external port
832 packetService.packets.clear();
Jonathan Hartd9df7bd2015-11-10 17:10:25 -0800833 ndpRequest = buildNdp(ICMP6.NEIGHBOR_SOLICITATION,
834 MAC1,
835 MacAddress.valueOf("33:33:ff:00:00:01"),
836 theirIp,
837 IP3);
Charles Chanad3b5502015-10-23 16:24:20 -0700838 proxyArp.reply(ndpRequest, LOC1);
839 assertEquals(0, packetService.packets.size());
840 }
841
842 /**
843 * Test ARP request from internal network to an external host.
844 */
Jonathan Hartdbdbdbb2014-10-06 18:35:30 -0700845 @Test
846 public void testReplyToRequestFromUs() {
Pavlin Radoslavov5b5dc482014-11-05 14:48:08 -0800847 Ip4Address ourIp = Ip4Address.valueOf("10.0.1.1");
Jonathan Hartdbdbdbb2014-10-06 18:35:30 -0700848 MacAddress ourMac = MacAddress.valueOf(1L);
Pavlin Radoslavov5b5dc482014-11-05 14:48:08 -0800849 Ip4Address theirIp = Ip4Address.valueOf("10.0.1.100");
Jonathan Hartdbdbdbb2014-10-06 18:35:30 -0700850
Jonathan Hart7d1496b2015-03-10 22:00:48 -0700851 expect(hostService.getHostsByIp(theirIp)).andReturn(Collections.emptySet());
Jonathan Hart4cb39882015-08-12 23:50:55 -0400852 expect(interfaceService.getInterfacesByIp(ourIp))
853 .andReturn(Collections.singleton(new Interface(getLocation(1),
Jonathan Hart00cddda2016-02-16 10:30:37 -0800854 Collections.singletonList(new InterfaceIpAddress(ourIp, IpPrefix.valueOf("10.0.1.1/24"))),
Jonathan Hart4cb39882015-08-12 23:50:55 -0400855 ourMac, VLAN1)));
Jonathan Hart7d1496b2015-03-10 22:00:48 -0700856 expect(hostService.getHost(HostId.hostId(ourMac, VLAN1))).andReturn(null);
857 replay(hostService);
Jonathan Hart4cb39882015-08-12 23:50:55 -0400858 replay(interfaceService);
Jonathan Hart7d1496b2015-03-10 22:00:48 -0700859
Jonathan Hartdbdbdbb2014-10-06 18:35:30 -0700860 // This is a request from something inside our network (like a BGP
861 // daemon) to an external host.
Luca Pretef70d3992015-10-30 16:24:14 -0700862 Ethernet arpRequest = buildArp(ARP.OP_REQUEST, VLAN1, ourMac, null, ourIp, theirIp);
Aaron Kruglikovd8123832015-07-06 14:20:25 -0700863 //Ensure the packet is allowed through (it is not to an internal port)
Jonathan Hartdbdbdbb2014-10-06 18:35:30 -0700864
Aaron Kruglikovd8123832015-07-06 14:20:25 -0700865 proxyArp.reply(arpRequest, getLocation(5));
Jonathan Hartdbdbdbb2014-10-06 18:35:30 -0700866 assertEquals(1, packetService.packets.size());
867 verifyPacketOut(arpRequest, getLocation(1), packetService.packets.get(0));
868
869 // The same request from a random external port should fail
870 packetService.packets.clear();
871 proxyArp.reply(arpRequest, getLocation(2));
872 assertEquals(0, packetService.packets.size());
873 }
874
Jonathan Hart704ca142014-10-09 09:34:39 -0700875 /**
Charles Chanad3b5502015-10-23 16:24:20 -0700876 * Test NDP request from internal network to an external host.
877 */
878 @Test
879 public void testReplyToRequestFromUsIpv6() {
880 Ip6Address ourIp = Ip6Address.valueOf("1000::1");
881 MacAddress ourMac = MacAddress.valueOf(1L);
882 Ip6Address theirIp = Ip6Address.valueOf("1000::100");
883
884 expect(hostService.getHostsByIp(theirIp)).andReturn(Collections.emptySet());
885 expect(interfaceService.getInterfacesByIp(ourIp))
886 .andReturn(Collections.singleton(new Interface(getLocation(1),
Jonathan Hart00cddda2016-02-16 10:30:37 -0800887 Collections.singletonList(new InterfaceIpAddress(
Charles Chanad3b5502015-10-23 16:24:20 -0700888 ourIp,
889 IpPrefix.valueOf("1000::1/64"))),
890 ourMac,
891 VLAN1)));
892 expect(hostService.getHost(HostId.hostId(ourMac, VLAN1))).andReturn(null);
893 replay(hostService);
894 replay(interfaceService);
895
896 // This is a request from something inside our network (like a BGP
897 // daemon) to an external host.
Jonathan Hartd9df7bd2015-11-10 17:10:25 -0800898 Ethernet ndpRequest = buildNdp(ICMP6.NEIGHBOR_SOLICITATION,
899 ourMac,
900 MacAddress.valueOf("33:33:ff:00:00:01"),
901 ourIp,
902 theirIp);
Charles Chanad3b5502015-10-23 16:24:20 -0700903
Charles Chanad3b5502015-10-23 16:24:20 -0700904 proxyArp.reply(ndpRequest, getLocation(5));
905 assertEquals(1, packetService.packets.size());
906 verifyPacketOut(ndpRequest, getLocation(1), packetService.packets.get(0));
907
908 // The same request from a random external port should fail
909 packetService.packets.clear();
910 proxyArp.reply(ndpRequest, getLocation(2));
911 assertEquals(0, packetService.packets.size());
912 }
913
914 /**
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800915 * Tests {@link ProxyArpManager#forward(Ethernet, ConnectPoint)} in the case where the
Jonathan Hart704ca142014-10-09 09:34:39 -0700916 * destination host is known.
917 * Verifies the correct ARP request is sent out the correct port.
918 */
919 @Test
920 public void testForwardToHost() {
921 Host host1 = new DefaultHost(PID, HID1, MAC1, VLAN1, LOC1,
Aaron Kruglikovd8123832015-07-06 14:20:25 -0700922 Collections.singleton(IP1));
Thomas Vachuskab2c47a72015-08-05 14:22:54 -0700923 Host host2 = new DefaultHost(PID, HID2, MAC2, VLAN1, LOC2,
924 Collections.singleton(IP2));
Jonathan Hart704ca142014-10-09 09:34:39 -0700925
926 expect(hostService.getHost(HID1)).andReturn(host1);
Thomas Vachuskab2c47a72015-08-05 14:22:54 -0700927 expect(hostService.getHost(HID2)).andReturn(host2);
Jonathan Hart704ca142014-10-09 09:34:39 -0700928 replay(hostService);
Jonathan Hart4cb39882015-08-12 23:50:55 -0400929 replay(interfaceService);
Jonathan Hart704ca142014-10-09 09:34:39 -0700930
Luca Pretef70d3992015-10-30 16:24:14 -0700931 Ethernet arpRequest = buildArp(ARP.OP_REPLY, VLAN1, MAC2, MAC1, IP2, IP1);
Jonathan Hart704ca142014-10-09 09:34:39 -0700932
Jonathan Hartf84591d2015-01-16 14:33:43 -0800933 proxyArp.forward(arpRequest, LOC2);
Jonathan Hart704ca142014-10-09 09:34:39 -0700934
935 assertEquals(1, packetService.packets.size());
936 OutboundPacket packet = packetService.packets.get(0);
937
938 verifyPacketOut(arpRequest, LOC1, packet);
939 }
940
941 /**
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800942 * Tests {@link ProxyArpManager#forward(Ethernet, ConnectPoint)} in the case where the
Charles Chanad3b5502015-10-23 16:24:20 -0700943 * destination host is known.
944 * Verifies the correct ARP request is sent out the correct port.
945 */
946 @Test
947 public void testForwardToHostIpv6() {
948 Host host1 = new DefaultHost(PID, HID3, MAC3, VLAN1, LOC1,
949 Collections.singleton(IP3));
950 Host host2 = new DefaultHost(PID, HID4, MAC4, VLAN1, LOC2,
951 Collections.singleton(IP4));
952
953 expect(hostService.getHost(SOLICITED_HID3)).andReturn(host1);
954 expect(hostService.getHost(HID4)).andReturn(host2);
955 replay(hostService);
956 replay(interfaceService);
957
Jonathan Hartd9df7bd2015-11-10 17:10:25 -0800958 Ethernet ndpRequest = buildNdp(ICMP6.NEIGHBOR_SOLICITATION,
959 MAC4, SOLICITED_MAC3,
960 IP4, IP3);
Charles Chanad3b5502015-10-23 16:24:20 -0700961
962 proxyArp.forward(ndpRequest, LOC2);
963
964 assertEquals(1, packetService.packets.size());
965 OutboundPacket packet = packetService.packets.get(0);
966
967 verifyPacketOut(ndpRequest, LOC1, packet);
968 }
969
970 /**
971 * Tests {@link ProxyArpManager#forward(Ethernet, ConnectPoint)} in the case where the
Jonathan Hart704ca142014-10-09 09:34:39 -0700972 * destination host is not known.
973 * Verifies the correct ARP request is flooded out the correct edge ports.
974 */
975 @Test
976 public void testForwardFlood() {
Luca Pretef70d3992015-10-30 16:24:14 -0700977 expect(hostService.getHost(HID2)).andReturn(null);
Jonathan Hart704ca142014-10-09 09:34:39 -0700978 replay(hostService);
Jonathan Hart4cb39882015-08-12 23:50:55 -0400979 replay(interfaceService);
Jonathan Hart704ca142014-10-09 09:34:39 -0700980
Luca Pretef70d3992015-10-30 16:24:14 -0700981 Ethernet arpRequest = buildArp(ARP.OP_REPLY, VLAN1, MAC1, MAC2, IP1, IP2);
Jonathan Hart704ca142014-10-09 09:34:39 -0700982
Luca Pretef70d3992015-10-30 16:24:14 -0700983 proxyArp.forward(arpRequest, getLocation(NUM_DEVICES));
Aaron Kruglikovd8123832015-07-06 14:20:25 -0700984
Luca Pretef70d3992015-10-30 16:24:14 -0700985 verifyFlood(arpRequest, noConfigCPoints);
Jonathan Hart704ca142014-10-09 09:34:39 -0700986 }
987
988 /**
Charles Chanad3b5502015-10-23 16:24:20 -0700989 * Tests {@link ProxyArpManager#forward(Ethernet, ConnectPoint)} in the case where the
990 * destination host is not known.
991 * Verifies the correct NDP request is flooded out the correct edge ports.
992 */
993 @Test
994 public void testForwardFloodIpv6() {
995 expect(hostService.getHost(SOLICITED_HID3)).andReturn(null);
996 replay(hostService);
997 replay(interfaceService);
998
Jonathan Hartd9df7bd2015-11-10 17:10:25 -0800999 Ethernet ndpRequest = buildNdp(ICMP6.NEIGHBOR_SOLICITATION,
1000 MAC4, SOLICITED_MAC3,
1001 IP4, IP3);
Charles Chanad3b5502015-10-23 16:24:20 -07001002
Luca Pretef70d3992015-10-30 16:24:14 -07001003 proxyArp.forward(ndpRequest, getLocation(NUM_DEVICES));
Charles Chanad3b5502015-10-23 16:24:20 -07001004
Luca Pretef70d3992015-10-30 16:24:14 -07001005 verifyFlood(ndpRequest, noConfigCPoints);
Charles Chanad3b5502015-10-23 16:24:20 -07001006 }
1007
1008 /**
Jonathan Hartf84591d2015-01-16 14:33:43 -08001009 * Verifies that the given packet was flooded out all available edge ports,
1010 * except for the input port.
Jonathan Hart704ca142014-10-09 09:34:39 -07001011 *
1012 * @param packet the packet that was expected to be flooded
Luca Pretef70d3992015-10-30 16:24:14 -07001013 * @param connectPoints the connectPoints where the outpacket should be
1014 * observed
Jonathan Hart704ca142014-10-09 09:34:39 -07001015 */
Luca Pretef70d3992015-10-30 16:24:14 -07001016 private void verifyFlood(Ethernet packet, List<ConnectPoint> connectPoints) {
1017
Jonathan Hartf84591d2015-01-16 14:33:43 -08001018 // There should be 1 less than NUM_FLOOD_PORTS; the inPort should be excluded.
Luca Pretef70d3992015-10-30 16:24:14 -07001019 assertEquals(connectPoints.size() - 1, packetService.packets.size());
Jonathan Hart704ca142014-10-09 09:34:39 -07001020
1021 Collections.sort(packetService.packets,
Jonathan Hart4cb39882015-08-12 23:50:55 -04001022 (o1, o2) -> o1.sendThrough().uri().compareTo(o2.sendThrough().uri()));
Jonathan Hart704ca142014-10-09 09:34:39 -07001023
Luca Pretef70d3992015-10-30 16:24:14 -07001024 for (int i = 0; i < connectPoints.size() - 1; i++) {
Jonathan Hart704ca142014-10-09 09:34:39 -07001025 OutboundPacket outboundPacket = packetService.packets.get(i);
Luca Pretef70d3992015-10-30 16:24:14 -07001026 verifyPacketOut(packet, connectPoints.get(i), outboundPacket);
Jonathan Hart704ca142014-10-09 09:34:39 -07001027 }
1028 }
1029
1030 /**
1031 * Verifies the given packet was sent out the given port.
1032 *
1033 * @param expected the packet that was expected to be sent
Thomas Vachuska27bee092015-06-23 19:03:10 -07001034 * @param outPort the port the packet was expected to be sent out
1035 * @param actual the actual OutboundPacket to verify
Jonathan Hart704ca142014-10-09 09:34:39 -07001036 */
1037 private void verifyPacketOut(Ethernet expected, ConnectPoint outPort,
Thomas Vachuska27bee092015-06-23 19:03:10 -07001038 OutboundPacket actual) {
Yuta HIGUCHI3e848a82014-11-02 20:19:42 -08001039 assertArrayEquals(expected.serialize(), actual.data().array());
Ray Milkey42507352015-03-20 15:16:10 -07001040 assertEquals(1, actual.treatment().immediate().size());
Jonathan Hart704ca142014-10-09 09:34:39 -07001041 assertEquals(outPort.deviceId(), actual.sendThrough());
Ray Milkey42507352015-03-20 15:16:10 -07001042 Instruction instruction = actual.treatment().immediate().get(0);
Jonathan Hart704ca142014-10-09 09:34:39 -07001043 assertTrue(instruction instanceof OutputInstruction);
1044 assertEquals(outPort.port(), ((OutputInstruction) instruction).port());
1045 }
1046
1047 /**
1048 * Returns the device ID of the ith device.
1049 *
1050 * @param i device to get the ID of
1051 * @return the device ID
1052 */
1053 private static DeviceId getDeviceId(int i) {
1054 return DeviceId.deviceId("" + i);
1055 }
1056
Jonathan Hartdbdbdbb2014-10-06 18:35:30 -07001057 private static HostLocation getLocation(int i) {
1058 return new HostLocation(new ConnectPoint(getDeviceId(i), P1), 123L);
1059 }
1060
Jonathan Hart704ca142014-10-09 09:34:39 -07001061 /**
1062 * Builds an ARP packet with the given parameters.
1063 *
1064 * @param opcode opcode of the ARP packet
1065 * @param srcMac source MAC address
1066 * @param dstMac destination MAC address, or null if this is a request
Thomas Vachuska27bee092015-06-23 19:03:10 -07001067 * @param srcIp source IP address
1068 * @param dstIp destination IP address
Jonathan Hart704ca142014-10-09 09:34:39 -07001069 * @return the ARP packet
1070 */
Luca Pretef70d3992015-10-30 16:24:14 -07001071 private Ethernet buildArp(short opcode, VlanId vlanId, MacAddress srcMac,
1072 MacAddress dstMac, Ip4Address srcIp, Ip4Address dstIp) {
Jonathan Hart704ca142014-10-09 09:34:39 -07001073 Ethernet eth = new Ethernet();
1074
1075 if (dstMac == null) {
Yuta HIGUCHI3e848a82014-11-02 20:19:42 -08001076 eth.setDestinationMACAddress(MacAddress.BROADCAST);
Jonathan Hart704ca142014-10-09 09:34:39 -07001077 } else {
Yuta HIGUCHI3e848a82014-11-02 20:19:42 -08001078 eth.setDestinationMACAddress(dstMac);
Jonathan Hart704ca142014-10-09 09:34:39 -07001079 }
1080
Yuta HIGUCHI3e848a82014-11-02 20:19:42 -08001081 eth.setSourceMACAddress(srcMac);
Jonathan Hart704ca142014-10-09 09:34:39 -07001082 eth.setEtherType(Ethernet.TYPE_ARP);
Luca Pretef70d3992015-10-30 16:24:14 -07001083 eth.setVlanID(vlanId.toShort());
Jonathan Hart704ca142014-10-09 09:34:39 -07001084
1085 ARP arp = new ARP();
1086 arp.setOpCode(opcode);
1087 arp.setProtocolType(ARP.PROTO_TYPE_IP);
1088 arp.setHardwareType(ARP.HW_TYPE_ETHERNET);
1089
Pavlin Radoslavov5b5dc482014-11-05 14:48:08 -08001090 arp.setProtocolAddressLength((byte) Ip4Address.BYTE_LENGTH);
Jonathan Hart704ca142014-10-09 09:34:39 -07001091 arp.setHardwareAddressLength((byte) Ethernet.DATALAYER_ADDRESS_LENGTH);
Yuta HIGUCHI3e848a82014-11-02 20:19:42 -08001092 arp.setSenderHardwareAddress(srcMac.toBytes());
Jonathan Hart704ca142014-10-09 09:34:39 -07001093
1094 if (dstMac == null) {
Luca Pretef70d3992015-10-30 16:24:14 -07001095 arp.setTargetHardwareAddress(zeroMacAddress);
Jonathan Hart704ca142014-10-09 09:34:39 -07001096 } else {
Yuta HIGUCHI3e848a82014-11-02 20:19:42 -08001097 arp.setTargetHardwareAddress(dstMac.toBytes());
Jonathan Hart704ca142014-10-09 09:34:39 -07001098 }
1099
1100 arp.setSenderProtocolAddress(srcIp.toOctets());
1101 arp.setTargetProtocolAddress(dstIp.toOctets());
1102
1103 eth.setPayload(arp);
1104 return eth;
1105 }
1106
1107 /**
Charles Chanad3b5502015-10-23 16:24:20 -07001108 * Builds an NDP packet with the given parameters.
1109 *
1110 * @param type NeighborSolicitation or NeighborAdvertisement
1111 * @param srcMac source MAC address
1112 * @param dstMac destination MAC address, or null if this is a request
1113 * @param srcIp source IP address
1114 * @param dstIp destination IP address
1115 * @return the NDP packet
1116 */
Jonathan Hartd9df7bd2015-11-10 17:10:25 -08001117 private Ethernet buildNdp(byte type, MacAddress srcMac, MacAddress dstMac,
Charles Chanad3b5502015-10-23 16:24:20 -07001118 Ip6Address srcIp, Ip6Address dstIp) {
1119 assertThat(type, anyOf(
1120 is(ICMP6.NEIGHBOR_SOLICITATION),
1121 is(ICMP6.NEIGHBOR_ADVERTISEMENT)
1122 ));
1123 assertNotNull(srcMac);
1124 assertNotNull(dstMac);
1125 assertNotNull(srcIp);
1126 assertNotNull(dstIp);
1127
1128 IPacket ndp;
1129 if (type == ICMP6.NEIGHBOR_SOLICITATION) {
1130 ndp = new NeighborSolicitation().setTargetAddress(dstIp.toOctets());
1131 } else {
1132 ndp = new NeighborAdvertisement()
1133 .setSolicitedFlag((byte) 1)
1134 .setOverrideFlag((byte) 1)
1135 .setTargetAddress(srcIp.toOctets())
1136 .addOption(NeighborDiscoveryOptions.TYPE_TARGET_LL_ADDRESS,
1137 srcMac.toBytes());
1138 }
1139
1140 ICMP6 icmp6 = new ICMP6();
1141 icmp6.setIcmpType(type);
1142 icmp6.setIcmpCode((byte) 0);
1143 icmp6.setPayload(ndp);
1144
1145 IPv6 ipv6 = new IPv6();
1146 ipv6.setDestinationAddress(dstIp.toOctets());
1147 ipv6.setSourceAddress(srcIp.toOctets());
1148 ipv6.setNextHeader(IPv6.PROTOCOL_ICMP6);
1149 ipv6.setHopLimit((byte) 255);
1150 ipv6.setPayload(icmp6);
1151
1152 Ethernet eth = new Ethernet();
1153 eth.setDestinationMACAddress(dstMac);
1154 eth.setSourceMACAddress(srcMac);
1155 eth.setEtherType(Ethernet.TYPE_IPV6);
1156 eth.setVlanID(VLAN1.toShort());
1157 eth.setPayload(ipv6);
1158
1159 return eth;
1160 }
1161
1162 /**
Jonathan Hart704ca142014-10-09 09:34:39 -07001163 * Test PacketService implementation that simply stores OutboundPackets
1164 * passed to {@link #emit(OutboundPacket)} for later verification.
1165 */
Thomas Vachuska27bee092015-06-23 19:03:10 -07001166 class TestPacketService extends PacketServiceAdapter {
Jonathan Hart704ca142014-10-09 09:34:39 -07001167
1168 List<OutboundPacket> packets = new ArrayList<>();
1169
1170 @Override
Jonathan Hart704ca142014-10-09 09:34:39 -07001171 public void emit(OutboundPacket packet) {
1172 packets.add(packet);
1173 }
Jonathan Hart3cfce8e2015-01-14 16:43:27 -08001174
Jonathan Hart704ca142014-10-09 09:34:39 -07001175 }
Aaron Kruglikovd8123832015-07-06 14:20:25 -07001176
Thomas Vachuskab2c47a72015-08-05 14:22:54 -07001177 private class TestProxyArpStoreAdapter implements ProxyArpStore {
1178 @Override
1179 public void forward(ConnectPoint outPort, Host subject, ByteBuffer packet) {
1180 TrafficTreatment tt = DefaultTrafficTreatment.builder().setOutput(outPort.port()).build();
1181 packetService.emit(new DefaultOutboundPacket(outPort.deviceId(), tt, packet));
1182 }
1183
1184 @Override
1185 public void setDelegate(ProxyArpStoreDelegate delegate) {
1186 }
1187 }
Jonathan Hart704ca142014-10-09 09:34:39 -07001188}