Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
Ray Milkey | 34c9590 | 2015-04-15 09:47:53 -0700 | [diff] [blame] | 2 | * Copyright 2014-2015 Open Networking Laboratory |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.proxyarp.impl; |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 17 | |
Aaron Kruglikov | d812383 | 2015-07-06 14:20:25 -0700 | [diff] [blame^] | 18 | import com.google.common.collect.Lists; |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 19 | import com.google.common.collect.Sets; |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 20 | import org.junit.Before; |
| 21 | import org.junit.Test; |
Jonathan Hart | 3cfce8e | 2015-01-14 16:43:27 -0800 | [diff] [blame] | 22 | import org.onlab.packet.ARP; |
| 23 | import org.onlab.packet.Ethernet; |
| 24 | import org.onlab.packet.Ip4Address; |
| 25 | import org.onlab.packet.Ip4Prefix; |
| 26 | import org.onlab.packet.MacAddress; |
| 27 | import org.onlab.packet.VlanId; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 28 | import org.onosproject.net.ConnectPoint; |
| 29 | import org.onosproject.net.DefaultHost; |
| 30 | import org.onosproject.net.Device; |
| 31 | import org.onosproject.net.DeviceId; |
| 32 | import org.onosproject.net.Host; |
| 33 | import org.onosproject.net.HostId; |
| 34 | import org.onosproject.net.HostLocation; |
| 35 | import org.onosproject.net.Link; |
| 36 | import org.onosproject.net.Port; |
| 37 | import org.onosproject.net.PortNumber; |
| 38 | import org.onosproject.net.device.DeviceListener; |
| 39 | import org.onosproject.net.device.DeviceService; |
Aaron Kruglikov | d812383 | 2015-07-06 14:20:25 -0700 | [diff] [blame^] | 40 | import org.onosproject.net.edgeservice.impl.EdgeManager; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 41 | import org.onosproject.net.flow.instructions.Instruction; |
| 42 | import org.onosproject.net.flow.instructions.Instructions.OutputInstruction; |
| 43 | import org.onosproject.net.host.HostService; |
| 44 | import org.onosproject.net.host.InterfaceIpAddress; |
| 45 | import org.onosproject.net.host.PortAddresses; |
| 46 | import org.onosproject.net.link.LinkListener; |
| 47 | import org.onosproject.net.link.LinkService; |
| 48 | import org.onosproject.net.packet.OutboundPacket; |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 49 | import org.onosproject.net.packet.PacketServiceAdapter; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 50 | import org.onosproject.net.provider.ProviderId; |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 51 | |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 52 | import java.util.ArrayList; |
| 53 | import java.util.Collections; |
| 54 | import java.util.Comparator; |
| 55 | import java.util.List; |
| 56 | import java.util.Set; |
| 57 | |
Aaron Kruglikov | d812383 | 2015-07-06 14:20:25 -0700 | [diff] [blame^] | 58 | import static org.easymock.EasyMock.anyObject; |
| 59 | import static org.easymock.EasyMock.createMock; |
| 60 | import static org.easymock.EasyMock.expect; |
| 61 | import static org.easymock.EasyMock.replay; |
| 62 | import static org.junit.Assert.assertArrayEquals; |
| 63 | import static org.junit.Assert.assertEquals; |
| 64 | import static org.junit.Assert.assertFalse; |
| 65 | import static org.junit.Assert.assertTrue; |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 66 | |
| 67 | /** |
| 68 | * Tests for the {@link ProxyArpManager} class. |
| 69 | */ |
| 70 | public class ProxyArpManagerTest { |
| 71 | |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 72 | private static final int NUM_DEVICES = 6; |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 73 | private static final int NUM_PORTS_PER_DEVICE = 3; |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 74 | private static final int NUM_ADDRESS_PORTS = NUM_DEVICES / 2; |
| 75 | private static final int NUM_FLOOD_PORTS = 3; |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 76 | |
Pavlin Radoslavov | 5b5dc48 | 2014-11-05 14:48:08 -0800 | [diff] [blame] | 77 | private static final Ip4Address IP1 = Ip4Address.valueOf("192.168.1.1"); |
| 78 | private static final Ip4Address IP2 = Ip4Address.valueOf("192.168.1.2"); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 79 | |
| 80 | private static final ProviderId PID = new ProviderId("of", "foo"); |
| 81 | |
| 82 | private static final VlanId VLAN1 = VlanId.vlanId((short) 1); |
| 83 | private static final VlanId VLAN2 = VlanId.vlanId((short) 2); |
| 84 | private static final MacAddress MAC1 = MacAddress.valueOf("00:00:11:00:00:01"); |
| 85 | private static final MacAddress MAC2 = MacAddress.valueOf("00:00:22:00:00:02"); |
| 86 | private static final HostId HID1 = HostId.hostId(MAC1, VLAN1); |
| 87 | private static final HostId HID2 = HostId.hostId(MAC2, VLAN1); |
| 88 | |
| 89 | private static final DeviceId DID1 = getDeviceId(1); |
| 90 | private static final DeviceId DID2 = getDeviceId(2); |
| 91 | private static final PortNumber P1 = PortNumber.portNumber(1); |
| 92 | private static final HostLocation LOC1 = new HostLocation(DID1, P1, 123L); |
| 93 | private static final HostLocation LOC2 = new HostLocation(DID2, P1, 123L); |
Yuta HIGUCHI | 3e848a8 | 2014-11-02 20:19:42 -0800 | [diff] [blame] | 94 | private static final byte[] ZERO_MAC_ADDRESS = MacAddress.ZERO.toBytes(); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 95 | |
Aaron Kruglikov | d812383 | 2015-07-06 14:20:25 -0700 | [diff] [blame^] | 96 | //Return values used for various functions of the TestPacketService inner class. |
| 97 | private boolean isEdgePointReturn; |
| 98 | private List<ConnectPoint> getEdgePointsNoArg; |
| 99 | |
| 100 | |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 101 | private ProxyArpManager proxyArp; |
| 102 | |
| 103 | private TestPacketService packetService; |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 104 | private DeviceService deviceService; |
| 105 | private LinkService linkService; |
| 106 | private HostService hostService; |
| 107 | |
| 108 | @Before |
| 109 | public void setUp() throws Exception { |
| 110 | proxyArp = new ProxyArpManager(); |
| 111 | packetService = new TestPacketService(); |
| 112 | proxyArp.packetService = packetService; |
| 113 | |
Aaron Kruglikov | d812383 | 2015-07-06 14:20:25 -0700 | [diff] [blame^] | 114 | proxyArp.edgeService = new TestEdgePortService(); |
| 115 | |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 116 | // Create a host service mock here. Must be replayed by tests once the |
| 117 | // expectations have been set up |
| 118 | hostService = createMock(HostService.class); |
| 119 | proxyArp.hostService = hostService; |
| 120 | |
| 121 | createTopology(); |
| 122 | proxyArp.deviceService = deviceService; |
| 123 | proxyArp.linkService = linkService; |
| 124 | |
| 125 | proxyArp.activate(); |
| 126 | } |
| 127 | |
| 128 | /** |
| 129 | * Creates a fake topology to feed into the ARP module. |
Aaron Kruglikov | d812383 | 2015-07-06 14:20:25 -0700 | [diff] [blame^] | 130 | * <p> |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 131 | * The default topology is a unidirectional ring topology. Each switch has |
| 132 | * 3 ports. Ports 2 and 3 have the links to neighbor switches, and port 1 |
| 133 | * is free (edge port). |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 134 | * The first half of the switches have IP addresses configured on their |
| 135 | * free ports (port 1). The second half of the switches have no IP |
| 136 | * addresses configured. |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 137 | */ |
| 138 | private void createTopology() { |
| 139 | deviceService = createMock(DeviceService.class); |
| 140 | linkService = createMock(LinkService.class); |
| 141 | |
| 142 | deviceService.addListener(anyObject(DeviceListener.class)); |
| 143 | linkService.addListener(anyObject(LinkListener.class)); |
| 144 | |
| 145 | createDevices(NUM_DEVICES, NUM_PORTS_PER_DEVICE); |
| 146 | createLinks(NUM_DEVICES); |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 147 | addAddressBindings(); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | /** |
| 151 | * Creates the devices for the fake topology. |
| 152 | */ |
| 153 | private void createDevices(int numDevices, int numPorts) { |
| 154 | List<Device> devices = new ArrayList<>(); |
| 155 | |
| 156 | for (int i = 1; i <= numDevices; i++) { |
| 157 | DeviceId devId = getDeviceId(i); |
| 158 | Device device = createMock(Device.class); |
| 159 | expect(device.id()).andReturn(devId).anyTimes(); |
| 160 | replay(device); |
| 161 | |
| 162 | devices.add(device); |
| 163 | |
| 164 | List<Port> ports = new ArrayList<>(); |
| 165 | for (int j = 1; j <= numPorts; j++) { |
| 166 | Port port = createMock(Port.class); |
| 167 | expect(port.number()).andReturn(PortNumber.portNumber(j)).anyTimes(); |
| 168 | replay(port); |
| 169 | ports.add(port); |
| 170 | } |
| 171 | |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 172 | expect(deviceService.getPorts(devId)).andReturn(ports).anyTimes(); |
| 173 | expect(deviceService.getDevice(devId)).andReturn(device).anyTimes(); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 174 | } |
| 175 | |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 176 | expect(deviceService.getDevices()).andReturn(devices).anyTimes(); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 177 | replay(deviceService); |
| 178 | } |
| 179 | |
| 180 | /** |
| 181 | * Creates the links for the fake topology. |
| 182 | * NB: Only unidirectional links are created, as for this purpose all we |
| 183 | * need is to occupy the ports with some link. |
| 184 | */ |
| 185 | private void createLinks(int numDevices) { |
| 186 | List<Link> links = new ArrayList<Link>(); |
| 187 | |
| 188 | for (int i = 1; i <= numDevices; i++) { |
| 189 | ConnectPoint src = new ConnectPoint( |
| 190 | getDeviceId(i), |
| 191 | PortNumber.portNumber(2)); |
| 192 | ConnectPoint dst = new ConnectPoint( |
| 193 | getDeviceId((i + 1 > numDevices) ? 1 : i + 1), |
| 194 | PortNumber.portNumber(3)); |
| 195 | |
| 196 | Link link = createMock(Link.class); |
| 197 | expect(link.src()).andReturn(src).anyTimes(); |
| 198 | expect(link.dst()).andReturn(dst).anyTimes(); |
| 199 | replay(link); |
| 200 | |
| 201 | links.add(link); |
| 202 | } |
| 203 | |
| 204 | expect(linkService.getLinks()).andReturn(links).anyTimes(); |
| 205 | replay(linkService); |
| 206 | } |
| 207 | |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 208 | private void addAddressBindings() { |
| 209 | Set<PortAddresses> addresses = Sets.newHashSet(); |
| 210 | |
| 211 | for (int i = 1; i <= NUM_ADDRESS_PORTS; i++) { |
| 212 | ConnectPoint cp = new ConnectPoint(getDeviceId(i), P1); |
Pavlin Radoslavov | 5b5dc48 | 2014-11-05 14:48:08 -0800 | [diff] [blame] | 213 | Ip4Prefix prefix1 = |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 214 | Ip4Prefix.valueOf("10.0." + (2 * i - 1) + ".0/24"); |
Pavlin Radoslavov | 5b5dc48 | 2014-11-05 14:48:08 -0800 | [diff] [blame] | 215 | Ip4Address addr1 = |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 216 | Ip4Address.valueOf("10.0." + (2 * i - 1) + ".1"); |
Pavlin Radoslavov | 5b5dc48 | 2014-11-05 14:48:08 -0800 | [diff] [blame] | 217 | Ip4Prefix prefix2 = Ip4Prefix.valueOf("10.0." + (2 * i) + ".0/24"); |
| 218 | Ip4Address addr2 = Ip4Address.valueOf("10.0." + (2 * i) + ".1"); |
Pavlin Radoslavov | 76b0ae2 | 2014-10-27 15:33:19 -0700 | [diff] [blame] | 219 | InterfaceIpAddress ia1 = new InterfaceIpAddress(addr1, prefix1); |
| 220 | InterfaceIpAddress ia2 = new InterfaceIpAddress(addr2, prefix2); |
Jonathan Hart | a887ba8 | 2014-11-03 15:20:52 -0800 | [diff] [blame] | 221 | PortAddresses pa1 = |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 222 | new PortAddresses(cp, Sets.newHashSet(ia1), |
Aaron Kruglikov | d812383 | 2015-07-06 14:20:25 -0700 | [diff] [blame^] | 223 | MacAddress.valueOf(2 * i - 1), |
| 224 | VlanId.vlanId((short) 1)); |
Jonathan Hart | a887ba8 | 2014-11-03 15:20:52 -0800 | [diff] [blame] | 225 | PortAddresses pa2 = |
| 226 | new PortAddresses(cp, Sets.newHashSet(ia2), |
Aaron Kruglikov | d812383 | 2015-07-06 14:20:25 -0700 | [diff] [blame^] | 227 | MacAddress.valueOf(2 * i), |
| 228 | VlanId.NONE); |
Jonathan Hart | a887ba8 | 2014-11-03 15:20:52 -0800 | [diff] [blame] | 229 | |
| 230 | addresses.add(pa1); |
| 231 | addresses.add(pa2); |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 232 | |
| 233 | expect(hostService.getAddressBindingsForPort(cp)) |
Jonathan Hart | a887ba8 | 2014-11-03 15:20:52 -0800 | [diff] [blame] | 234 | .andReturn(Sets.newHashSet(pa1, pa2)).anyTimes(); |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | expect(hostService.getAddressBindings()).andReturn(addresses).anyTimes(); |
| 238 | |
| 239 | for (int i = 1; i <= NUM_FLOOD_PORTS; i++) { |
| 240 | ConnectPoint cp = new ConnectPoint(getDeviceId(i + NUM_ADDRESS_PORTS), |
Aaron Kruglikov | d812383 | 2015-07-06 14:20:25 -0700 | [diff] [blame^] | 241 | P1); |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 242 | expect(hostService.getAddressBindingsForPort(cp)) |
Jonathan Hart | a887ba8 | 2014-11-03 15:20:52 -0800 | [diff] [blame] | 243 | .andReturn(Collections.<PortAddresses>emptySet()).anyTimes(); |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 244 | } |
| 245 | } |
| 246 | |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 247 | /** |
Jonathan Hart | 7d1496b | 2015-03-10 22:00:48 -0700 | [diff] [blame] | 248 | * Tests {@link ProxyArpManager#isKnown(org.onlab.packet.IpAddress)} in the |
| 249 | * case where the IP address is not known. |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 250 | * Verifies the method returns false. |
| 251 | */ |
| 252 | @Test |
| 253 | public void testNotKnown() { |
| 254 | expect(hostService.getHostsByIp(IP1)).andReturn(Collections.<Host>emptySet()); |
| 255 | replay(hostService); |
| 256 | |
Jonathan Hart | f84591d | 2015-01-16 14:33:43 -0800 | [diff] [blame] | 257 | assertFalse(proxyArp.isKnown(IP1)); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | /** |
Jonathan Hart | 7d1496b | 2015-03-10 22:00:48 -0700 | [diff] [blame] | 261 | * Tests {@link ProxyArpManager#isKnown(org.onlab.packet.IpAddress)} in the |
| 262 | * case where the IP address is known. |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 263 | * Verifies the method returns true. |
| 264 | */ |
| 265 | @Test |
| 266 | public void testKnown() { |
| 267 | Host host1 = createMock(Host.class); |
| 268 | Host host2 = createMock(Host.class); |
| 269 | |
| 270 | expect(hostService.getHostsByIp(IP1)) |
| 271 | .andReturn(Sets.newHashSet(host1, host2)); |
| 272 | replay(hostService); |
| 273 | |
Jonathan Hart | f84591d | 2015-01-16 14:33:43 -0800 | [diff] [blame] | 274 | assertTrue(proxyArp.isKnown(IP1)); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | /** |
Jonathan Hart | 6cd2f35 | 2015-01-13 17:44:45 -0800 | [diff] [blame] | 278 | * Tests {@link ProxyArpManager#reply(Ethernet, ConnectPoint)} in the case where the |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 279 | * destination host is known. |
| 280 | * Verifies the correct ARP reply is sent out the correct port. |
| 281 | */ |
| 282 | @Test |
| 283 | public void testReplyKnown() { |
Aaron Kruglikov | d812383 | 2015-07-06 14:20:25 -0700 | [diff] [blame^] | 284 | //Set the return value of isEdgePoint from the edgemanager. |
| 285 | isEdgePointReturn = true; |
| 286 | |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 287 | Host replyer = new DefaultHost(PID, HID1, MAC1, VLAN1, getLocation(4), |
Aaron Kruglikov | d812383 | 2015-07-06 14:20:25 -0700 | [diff] [blame^] | 288 | Collections.singleton(IP1)); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 289 | |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 290 | Host requestor = new DefaultHost(PID, HID2, MAC2, VLAN1, getLocation(5), |
Aaron Kruglikov | d812383 | 2015-07-06 14:20:25 -0700 | [diff] [blame^] | 291 | Collections.singleton(IP2)); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 292 | |
Pavlin Radoslavov | 33f228a | 2014-10-27 19:33:16 -0700 | [diff] [blame] | 293 | expect(hostService.getHostsByIp(IP1)) |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 294 | .andReturn(Collections.singleton(replyer)); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 295 | expect(hostService.getHost(HID2)).andReturn(requestor); |
| 296 | |
| 297 | replay(hostService); |
| 298 | |
| 299 | Ethernet arpRequest = buildArp(ARP.OP_REQUEST, MAC2, null, IP2, IP1); |
| 300 | |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 301 | proxyArp.reply(arpRequest, getLocation(5)); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 302 | |
| 303 | assertEquals(1, packetService.packets.size()); |
| 304 | Ethernet arpReply = buildArp(ARP.OP_REPLY, MAC1, MAC2, IP1, IP2); |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 305 | verifyPacketOut(arpReply, getLocation(5), packetService.packets.get(0)); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | /** |
Jonathan Hart | 6cd2f35 | 2015-01-13 17:44:45 -0800 | [diff] [blame] | 309 | * Tests {@link ProxyArpManager#reply(Ethernet, ConnectPoint)} in the case where the |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 310 | * destination host is not known. |
| 311 | * Verifies the ARP request is flooded out the correct edge ports. |
| 312 | */ |
| 313 | @Test |
| 314 | public void testReplyUnknown() { |
Aaron Kruglikov | d812383 | 2015-07-06 14:20:25 -0700 | [diff] [blame^] | 315 | isEdgePointReturn = true; |
| 316 | |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 317 | Host requestor = new DefaultHost(PID, HID2, MAC2, VLAN1, getLocation(5), |
Aaron Kruglikov | d812383 | 2015-07-06 14:20:25 -0700 | [diff] [blame^] | 318 | Collections.singleton(IP2)); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 319 | |
Pavlin Radoslavov | 33f228a | 2014-10-27 19:33:16 -0700 | [diff] [blame] | 320 | expect(hostService.getHostsByIp(IP1)) |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 321 | .andReturn(Collections.<Host>emptySet()); |
| 322 | expect(hostService.getHost(HID2)).andReturn(requestor); |
| 323 | |
Aaron Kruglikov | d812383 | 2015-07-06 14:20:25 -0700 | [diff] [blame^] | 324 | |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 325 | replay(hostService); |
| 326 | |
| 327 | Ethernet arpRequest = buildArp(ARP.OP_REQUEST, MAC2, null, IP2, IP1); |
| 328 | |
Aaron Kruglikov | d812383 | 2015-07-06 14:20:25 -0700 | [diff] [blame^] | 329 | //Setup the set of edge ports to be used in the reply method |
| 330 | getEdgePointsNoArg = Lists.newLinkedList(); |
| 331 | getEdgePointsNoArg.add(new ConnectPoint(DeviceId.deviceId("5"), PortNumber.portNumber(1))); |
| 332 | getEdgePointsNoArg.add(new ConnectPoint(DeviceId.deviceId("4"), PortNumber.portNumber(1))); |
| 333 | |
Jonathan Hart | f84591d | 2015-01-16 14:33:43 -0800 | [diff] [blame] | 334 | proxyArp.reply(arpRequest, getLocation(6)); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 335 | |
| 336 | verifyFlood(arpRequest); |
| 337 | } |
| 338 | |
| 339 | /** |
Jonathan Hart | 6cd2f35 | 2015-01-13 17:44:45 -0800 | [diff] [blame] | 340 | * Tests {@link ProxyArpManager#reply(Ethernet, ConnectPoint)} in the case where the |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 341 | * destination host is known for that IP address, but is not on the same |
| 342 | * VLAN as the source host. |
| 343 | * Verifies the ARP request is flooded out the correct edge ports. |
| 344 | */ |
| 345 | @Test |
| 346 | public void testReplyDifferentVlan() { |
Aaron Kruglikov | d812383 | 2015-07-06 14:20:25 -0700 | [diff] [blame^] | 347 | |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 348 | Host replyer = new DefaultHost(PID, HID1, MAC1, VLAN2, getLocation(4), |
Aaron Kruglikov | d812383 | 2015-07-06 14:20:25 -0700 | [diff] [blame^] | 349 | Collections.singleton(IP1)); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 350 | |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 351 | Host requestor = new DefaultHost(PID, HID2, MAC2, VLAN1, getLocation(5), |
Aaron Kruglikov | d812383 | 2015-07-06 14:20:25 -0700 | [diff] [blame^] | 352 | Collections.singleton(IP2)); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 353 | |
Pavlin Radoslavov | 33f228a | 2014-10-27 19:33:16 -0700 | [diff] [blame] | 354 | expect(hostService.getHostsByIp(IP1)) |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 355 | .andReturn(Collections.singleton(replyer)); |
| 356 | expect(hostService.getHost(HID2)).andReturn(requestor); |
| 357 | |
| 358 | replay(hostService); |
| 359 | |
| 360 | Ethernet arpRequest = buildArp(ARP.OP_REQUEST, MAC2, null, IP2, IP1); |
| 361 | |
Aaron Kruglikov | d812383 | 2015-07-06 14:20:25 -0700 | [diff] [blame^] | 362 | //Setup for flood test |
| 363 | getEdgePointsNoArg = Lists.newLinkedList(); |
| 364 | getEdgePointsNoArg.add(new ConnectPoint(DeviceId.deviceId("5"), PortNumber.portNumber(1))); |
| 365 | getEdgePointsNoArg.add(new ConnectPoint(DeviceId.deviceId("4"), PortNumber.portNumber(1))); |
Jonathan Hart | f84591d | 2015-01-16 14:33:43 -0800 | [diff] [blame] | 366 | proxyArp.reply(arpRequest, getLocation(6)); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 367 | |
| 368 | verifyFlood(arpRequest); |
| 369 | } |
| 370 | |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 371 | @Test |
| 372 | public void testReplyToRequestForUs() { |
Pavlin Radoslavov | 5b5dc48 | 2014-11-05 14:48:08 -0800 | [diff] [blame] | 373 | Ip4Address theirIp = Ip4Address.valueOf("10.0.1.254"); |
| 374 | Ip4Address ourFirstIp = Ip4Address.valueOf("10.0.1.1"); |
| 375 | Ip4Address ourSecondIp = Ip4Address.valueOf("10.0.2.1"); |
Jonathan Hart | a887ba8 | 2014-11-03 15:20:52 -0800 | [diff] [blame] | 376 | MacAddress firstMac = MacAddress.valueOf(1L); |
| 377 | MacAddress secondMac = MacAddress.valueOf(2L); |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 378 | |
| 379 | Host requestor = new DefaultHost(PID, HID2, MAC2, VLAN1, LOC1, |
Aaron Kruglikov | d812383 | 2015-07-06 14:20:25 -0700 | [diff] [blame^] | 380 | Collections.singleton(theirIp)); |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 381 | |
| 382 | expect(hostService.getHost(HID2)).andReturn(requestor); |
| 383 | replay(hostService); |
| 384 | |
| 385 | Ethernet arpRequest = buildArp(ARP.OP_REQUEST, MAC2, null, theirIp, ourFirstIp); |
Aaron Kruglikov | d812383 | 2015-07-06 14:20:25 -0700 | [diff] [blame^] | 386 | isEdgePointReturn = true; |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 387 | proxyArp.reply(arpRequest, LOC1); |
| 388 | |
| 389 | assertEquals(1, packetService.packets.size()); |
Jonathan Hart | a887ba8 | 2014-11-03 15:20:52 -0800 | [diff] [blame] | 390 | Ethernet arpReply = buildArp(ARP.OP_REPLY, firstMac, MAC2, ourFirstIp, theirIp); |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 391 | verifyPacketOut(arpReply, LOC1, packetService.packets.get(0)); |
| 392 | |
| 393 | // Test a request for the second address on that port |
| 394 | packetService.packets.clear(); |
| 395 | arpRequest = buildArp(ARP.OP_REQUEST, MAC2, null, theirIp, ourSecondIp); |
| 396 | |
| 397 | proxyArp.reply(arpRequest, LOC1); |
| 398 | |
| 399 | assertEquals(1, packetService.packets.size()); |
Jonathan Hart | a887ba8 | 2014-11-03 15:20:52 -0800 | [diff] [blame] | 400 | arpReply = buildArp(ARP.OP_REPLY, secondMac, MAC2, ourSecondIp, theirIp); |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 401 | verifyPacketOut(arpReply, LOC1, packetService.packets.get(0)); |
| 402 | } |
| 403 | |
| 404 | @Test |
| 405 | public void testReplyExternalPortBadRequest() { |
| 406 | replay(hostService); // no further host service expectations |
| 407 | |
Pavlin Radoslavov | 5b5dc48 | 2014-11-05 14:48:08 -0800 | [diff] [blame] | 408 | Ip4Address theirIp = Ip4Address.valueOf("10.0.1.254"); |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 409 | |
| 410 | // Request for a valid external IP address but coming in the wrong port |
| 411 | Ethernet arpRequest = buildArp(ARP.OP_REQUEST, MAC1, null, theirIp, |
Aaron Kruglikov | d812383 | 2015-07-06 14:20:25 -0700 | [diff] [blame^] | 412 | Ip4Address.valueOf("10.0.3.1")); |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 413 | proxyArp.reply(arpRequest, LOC1); |
| 414 | assertEquals(0, packetService.packets.size()); |
| 415 | |
| 416 | // Request for a valid internal IP address but coming in an external port |
| 417 | packetService.packets.clear(); |
| 418 | arpRequest = buildArp(ARP.OP_REQUEST, MAC1, null, theirIp, IP1); |
| 419 | proxyArp.reply(arpRequest, LOC1); |
| 420 | assertEquals(0, packetService.packets.size()); |
| 421 | } |
| 422 | |
| 423 | @Test |
| 424 | public void testReplyToRequestFromUs() { |
Pavlin Radoslavov | 5b5dc48 | 2014-11-05 14:48:08 -0800 | [diff] [blame] | 425 | Ip4Address ourIp = Ip4Address.valueOf("10.0.1.1"); |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 426 | MacAddress ourMac = MacAddress.valueOf(1L); |
Pavlin Radoslavov | 5b5dc48 | 2014-11-05 14:48:08 -0800 | [diff] [blame] | 427 | Ip4Address theirIp = Ip4Address.valueOf("10.0.1.100"); |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 428 | |
Jonathan Hart | 7d1496b | 2015-03-10 22:00:48 -0700 | [diff] [blame] | 429 | expect(hostService.getHostsByIp(theirIp)).andReturn(Collections.emptySet()); |
| 430 | expect(hostService.getHost(HostId.hostId(ourMac, VLAN1))).andReturn(null); |
| 431 | replay(hostService); |
| 432 | |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 433 | // This is a request from something inside our network (like a BGP |
| 434 | // daemon) to an external host. |
| 435 | Ethernet arpRequest = buildArp(ARP.OP_REQUEST, ourMac, null, ourIp, theirIp); |
Aaron Kruglikov | d812383 | 2015-07-06 14:20:25 -0700 | [diff] [blame^] | 436 | //Ensure the packet is allowed through (it is not to an internal port) |
| 437 | isEdgePointReturn = true; |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 438 | |
Aaron Kruglikov | d812383 | 2015-07-06 14:20:25 -0700 | [diff] [blame^] | 439 | proxyArp.reply(arpRequest, getLocation(5)); |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 440 | assertEquals(1, packetService.packets.size()); |
| 441 | verifyPacketOut(arpRequest, getLocation(1), packetService.packets.get(0)); |
| 442 | |
| 443 | // The same request from a random external port should fail |
| 444 | packetService.packets.clear(); |
| 445 | proxyArp.reply(arpRequest, getLocation(2)); |
| 446 | assertEquals(0, packetService.packets.size()); |
| 447 | } |
| 448 | |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 449 | /** |
Jonathan Hart | 6cd2f35 | 2015-01-13 17:44:45 -0800 | [diff] [blame] | 450 | * Tests {@link ProxyArpManager#forward(Ethernet, ConnectPoint)} in the case where the |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 451 | * destination host is known. |
| 452 | * Verifies the correct ARP request is sent out the correct port. |
| 453 | */ |
| 454 | @Test |
| 455 | public void testForwardToHost() { |
| 456 | Host host1 = new DefaultHost(PID, HID1, MAC1, VLAN1, LOC1, |
Aaron Kruglikov | d812383 | 2015-07-06 14:20:25 -0700 | [diff] [blame^] | 457 | Collections.singleton(IP1)); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 458 | |
| 459 | expect(hostService.getHost(HID1)).andReturn(host1); |
| 460 | replay(hostService); |
| 461 | |
| 462 | Ethernet arpRequest = buildArp(ARP.OP_REPLY, MAC2, MAC1, IP2, IP1); |
| 463 | |
Jonathan Hart | f84591d | 2015-01-16 14:33:43 -0800 | [diff] [blame] | 464 | proxyArp.forward(arpRequest, LOC2); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 465 | |
| 466 | assertEquals(1, packetService.packets.size()); |
| 467 | OutboundPacket packet = packetService.packets.get(0); |
| 468 | |
| 469 | verifyPacketOut(arpRequest, LOC1, packet); |
| 470 | } |
| 471 | |
| 472 | /** |
Jonathan Hart | 6cd2f35 | 2015-01-13 17:44:45 -0800 | [diff] [blame] | 473 | * Tests {@link ProxyArpManager#forward(Ethernet, ConnectPoint)} in the case where the |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 474 | * destination host is not known. |
| 475 | * Verifies the correct ARP request is flooded out the correct edge ports. |
| 476 | */ |
| 477 | @Test |
| 478 | public void testForwardFlood() { |
| 479 | expect(hostService.getHost(HID1)).andReturn(null); |
| 480 | replay(hostService); |
| 481 | |
| 482 | Ethernet arpRequest = buildArp(ARP.OP_REPLY, MAC2, MAC1, IP2, IP1); |
| 483 | |
Aaron Kruglikov | d812383 | 2015-07-06 14:20:25 -0700 | [diff] [blame^] | 484 | //populate the list of edges when so that when forward hits flood in the manager it contains the values |
| 485 | //that should continue on |
| 486 | getEdgePointsNoArg = Lists.newLinkedList(); |
| 487 | getEdgePointsNoArg.add(new ConnectPoint(DeviceId.deviceId("3"), PortNumber.portNumber(1))); |
| 488 | getEdgePointsNoArg.add(new ConnectPoint(DeviceId.deviceId("5"), PortNumber.portNumber(1))); |
| 489 | getEdgePointsNoArg.add(new ConnectPoint(DeviceId.deviceId("4"), PortNumber.portNumber(1))); |
| 490 | |
Jonathan Hart | f84591d | 2015-01-16 14:33:43 -0800 | [diff] [blame] | 491 | proxyArp.forward(arpRequest, getLocation(6)); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 492 | |
| 493 | verifyFlood(arpRequest); |
| 494 | } |
| 495 | |
| 496 | /** |
Jonathan Hart | f84591d | 2015-01-16 14:33:43 -0800 | [diff] [blame] | 497 | * Verifies that the given packet was flooded out all available edge ports, |
| 498 | * except for the input port. |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 499 | * |
| 500 | * @param packet the packet that was expected to be flooded |
| 501 | */ |
| 502 | private void verifyFlood(Ethernet packet) { |
Jonathan Hart | f84591d | 2015-01-16 14:33:43 -0800 | [diff] [blame] | 503 | // There should be 1 less than NUM_FLOOD_PORTS; the inPort should be excluded. |
| 504 | assertEquals(NUM_FLOOD_PORTS - 1, packetService.packets.size()); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 505 | |
| 506 | Collections.sort(packetService.packets, |
Aaron Kruglikov | d812383 | 2015-07-06 14:20:25 -0700 | [diff] [blame^] | 507 | new Comparator<OutboundPacket>() { |
| 508 | @Override |
| 509 | public int compare(OutboundPacket o1, OutboundPacket o2) { |
| 510 | return o1.sendThrough().uri().compareTo(o2.sendThrough().uri()); |
| 511 | } |
| 512 | }); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 513 | |
Jonathan Hart | f84591d | 2015-01-16 14:33:43 -0800 | [diff] [blame] | 514 | |
| 515 | for (int i = 0; i < NUM_FLOOD_PORTS - 1; i++) { |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 516 | ConnectPoint cp = new ConnectPoint(getDeviceId(NUM_ADDRESS_PORTS + i + 1), |
Aaron Kruglikov | d812383 | 2015-07-06 14:20:25 -0700 | [diff] [blame^] | 517 | PortNumber.portNumber(1)); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 518 | |
| 519 | OutboundPacket outboundPacket = packetService.packets.get(i); |
| 520 | verifyPacketOut(packet, cp, outboundPacket); |
| 521 | } |
| 522 | } |
| 523 | |
| 524 | /** |
| 525 | * Verifies the given packet was sent out the given port. |
| 526 | * |
| 527 | * @param expected the packet that was expected to be sent |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 528 | * @param outPort the port the packet was expected to be sent out |
| 529 | * @param actual the actual OutboundPacket to verify |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 530 | */ |
| 531 | private void verifyPacketOut(Ethernet expected, ConnectPoint outPort, |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 532 | OutboundPacket actual) { |
Yuta HIGUCHI | 3e848a8 | 2014-11-02 20:19:42 -0800 | [diff] [blame] | 533 | assertArrayEquals(expected.serialize(), actual.data().array()); |
Ray Milkey | 4250735 | 2015-03-20 15:16:10 -0700 | [diff] [blame] | 534 | assertEquals(1, actual.treatment().immediate().size()); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 535 | assertEquals(outPort.deviceId(), actual.sendThrough()); |
Ray Milkey | 4250735 | 2015-03-20 15:16:10 -0700 | [diff] [blame] | 536 | Instruction instruction = actual.treatment().immediate().get(0); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 537 | assertTrue(instruction instanceof OutputInstruction); |
| 538 | assertEquals(outPort.port(), ((OutputInstruction) instruction).port()); |
| 539 | } |
| 540 | |
| 541 | /** |
| 542 | * Returns the device ID of the ith device. |
| 543 | * |
| 544 | * @param i device to get the ID of |
| 545 | * @return the device ID |
| 546 | */ |
| 547 | private static DeviceId getDeviceId(int i) { |
| 548 | return DeviceId.deviceId("" + i); |
| 549 | } |
| 550 | |
Jonathan Hart | dbdbdbb | 2014-10-06 18:35:30 -0700 | [diff] [blame] | 551 | private static HostLocation getLocation(int i) { |
| 552 | return new HostLocation(new ConnectPoint(getDeviceId(i), P1), 123L); |
| 553 | } |
| 554 | |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 555 | /** |
| 556 | * Builds an ARP packet with the given parameters. |
| 557 | * |
| 558 | * @param opcode opcode of the ARP packet |
| 559 | * @param srcMac source MAC address |
| 560 | * @param dstMac destination MAC address, or null if this is a request |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 561 | * @param srcIp source IP address |
| 562 | * @param dstIp destination IP address |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 563 | * @return the ARP packet |
| 564 | */ |
| 565 | private Ethernet buildArp(short opcode, MacAddress srcMac, MacAddress dstMac, |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 566 | Ip4Address srcIp, Ip4Address dstIp) { |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 567 | Ethernet eth = new Ethernet(); |
| 568 | |
| 569 | if (dstMac == null) { |
Yuta HIGUCHI | 3e848a8 | 2014-11-02 20:19:42 -0800 | [diff] [blame] | 570 | eth.setDestinationMACAddress(MacAddress.BROADCAST); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 571 | } else { |
Yuta HIGUCHI | 3e848a8 | 2014-11-02 20:19:42 -0800 | [diff] [blame] | 572 | eth.setDestinationMACAddress(dstMac); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 573 | } |
| 574 | |
Yuta HIGUCHI | 3e848a8 | 2014-11-02 20:19:42 -0800 | [diff] [blame] | 575 | eth.setSourceMACAddress(srcMac); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 576 | eth.setEtherType(Ethernet.TYPE_ARP); |
| 577 | eth.setVlanID(VLAN1.toShort()); |
| 578 | |
| 579 | ARP arp = new ARP(); |
| 580 | arp.setOpCode(opcode); |
| 581 | arp.setProtocolType(ARP.PROTO_TYPE_IP); |
| 582 | arp.setHardwareType(ARP.HW_TYPE_ETHERNET); |
| 583 | |
Pavlin Radoslavov | 5b5dc48 | 2014-11-05 14:48:08 -0800 | [diff] [blame] | 584 | arp.setProtocolAddressLength((byte) Ip4Address.BYTE_LENGTH); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 585 | arp.setHardwareAddressLength((byte) Ethernet.DATALAYER_ADDRESS_LENGTH); |
Yuta HIGUCHI | 3e848a8 | 2014-11-02 20:19:42 -0800 | [diff] [blame] | 586 | arp.setSenderHardwareAddress(srcMac.toBytes()); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 587 | |
| 588 | if (dstMac == null) { |
Yuta HIGUCHI | 3e848a8 | 2014-11-02 20:19:42 -0800 | [diff] [blame] | 589 | arp.setTargetHardwareAddress(ZERO_MAC_ADDRESS); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 590 | } else { |
Yuta HIGUCHI | 3e848a8 | 2014-11-02 20:19:42 -0800 | [diff] [blame] | 591 | arp.setTargetHardwareAddress(dstMac.toBytes()); |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 592 | } |
| 593 | |
| 594 | arp.setSenderProtocolAddress(srcIp.toOctets()); |
| 595 | arp.setTargetProtocolAddress(dstIp.toOctets()); |
| 596 | |
| 597 | eth.setPayload(arp); |
| 598 | return eth; |
| 599 | } |
| 600 | |
| 601 | /** |
| 602 | * Test PacketService implementation that simply stores OutboundPackets |
| 603 | * passed to {@link #emit(OutboundPacket)} for later verification. |
| 604 | */ |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 605 | class TestPacketService extends PacketServiceAdapter { |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 606 | |
| 607 | List<OutboundPacket> packets = new ArrayList<>(); |
| 608 | |
| 609 | @Override |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 610 | public void emit(OutboundPacket packet) { |
| 611 | packets.add(packet); |
| 612 | } |
Jonathan Hart | 3cfce8e | 2015-01-14 16:43:27 -0800 | [diff] [blame] | 613 | |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 614 | } |
Aaron Kruglikov | d812383 | 2015-07-06 14:20:25 -0700 | [diff] [blame^] | 615 | |
| 616 | class TestEdgePortService extends EdgeManager { |
| 617 | |
| 618 | @Override |
| 619 | public boolean isEdgePoint(ConnectPoint connectPoint) { |
| 620 | return isEdgePointReturn; |
| 621 | } |
| 622 | |
| 623 | @Override |
| 624 | public Iterable<ConnectPoint> getEdgePoints() { |
| 625 | return getEdgePointsNoArg; |
| 626 | } |
| 627 | } |
Jonathan Hart | 704ca14 | 2014-10-09 09:34:39 -0700 | [diff] [blame] | 628 | } |