Committed by
Gerrit Code Review
Refactor ProxyManager Tests and added functionality to manage traffic coming and…
… going through vlan interfaces Change-Id: I8d748c42b48d0956c670be12ff2742cb2022fa62
Showing
2 changed files
with
391 additions
and
170 deletions
... | @@ -53,6 +53,7 @@ import org.slf4j.Logger; | ... | @@ -53,6 +53,7 @@ import org.slf4j.Logger; |
53 | 53 | ||
54 | import java.nio.ByteBuffer; | 54 | import java.nio.ByteBuffer; |
55 | import java.util.Set; | 55 | import java.util.Set; |
56 | +import java.util.stream.Collectors; | ||
56 | 57 | ||
57 | import static com.google.common.base.Preconditions.checkArgument; | 58 | import static com.google.common.base.Preconditions.checkArgument; |
58 | import static com.google.common.base.Preconditions.checkNotNull; | 59 | import static com.google.common.base.Preconditions.checkNotNull; |
... | @@ -199,11 +200,49 @@ public class ProxyArpManager implements ProxyArpService { | ... | @@ -199,11 +200,49 @@ public class ProxyArpManager implements ProxyArpService { |
199 | return; | 200 | return; |
200 | } | 201 | } |
201 | 202 | ||
203 | + // If the packets has a vlanId look if there are some other | ||
204 | + // interfaces in the configuration on the same vlan and broadcast | ||
205 | + // the packet out just of through those interfaces. | ||
206 | + VlanId vlanId = context.vlan(); | ||
207 | + | ||
208 | + Set<Interface> filteredVlanInterfaces = | ||
209 | + filterVlanInterfacesNoIp(interfaceService.getInterfacesByVlan(vlanId)); | ||
210 | + | ||
211 | + if (vlanId != null | ||
212 | + && !vlanId.equals(VlanId.NONE) | ||
213 | + && confContainsVlans(vlanId, context.inPort())) { | ||
214 | + vlanFlood(context.packet(), filteredVlanInterfaces, context.inPort); | ||
215 | + return; | ||
216 | + } | ||
217 | + | ||
202 | // The request couldn't be resolved. | 218 | // The request couldn't be resolved. |
203 | // Flood the request on all ports except the incoming port. | 219 | // Flood the request on all ports except the incoming port. |
204 | flood(context.packet(), context.inPort()); | 220 | flood(context.packet(), context.inPort()); |
205 | } | 221 | } |
206 | 222 | ||
223 | + private Set<Interface> filterVlanInterfacesNoIp(Set<Interface> vlanInterfaces) { | ||
224 | + return vlanInterfaces | ||
225 | + .stream() | ||
226 | + .filter(intf -> intf.ipAddresses().isEmpty()) | ||
227 | + .collect(Collectors.toSet()); | ||
228 | + } | ||
229 | + | ||
230 | + /** | ||
231 | + * States if the interface configuration contains more than one interface configured | ||
232 | + * on a specific vlan, including the interface passed as argument. | ||
233 | + * | ||
234 | + * @param vlanId the vlanid to look for in the interface configuration | ||
235 | + * @param connectPoint the connect point to exclude from the search | ||
236 | + * @return true if interfaces are found. False otherwise | ||
237 | + */ | ||
238 | + private boolean confContainsVlans(VlanId vlanId, ConnectPoint connectPoint) { | ||
239 | + Set<Interface> vlanInterfaces = interfaceService.getInterfacesByVlan(vlanId); | ||
240 | + return interfaceService.getInterfacesByVlan(vlanId) | ||
241 | + .stream() | ||
242 | + .anyMatch(intf -> intf.connectPoint().equals(connectPoint) && intf.ipAddresses().isEmpty()) | ||
243 | + && vlanInterfaces.size() > 1; | ||
244 | + } | ||
245 | + | ||
207 | /** | 246 | /** |
208 | * Builds and sends a reply message given a request context and the resolved | 247 | * Builds and sends a reply message given a request context and the resolved |
209 | * MAC address to answer with. | 248 | * MAC address to answer with. |
... | @@ -259,14 +298,29 @@ public class ProxyArpManager implements ProxyArpService { | ... | @@ -259,14 +298,29 @@ public class ProxyArpManager implements ProxyArpService { |
259 | /** | 298 | /** |
260 | * Returns whether the given port has any IP addresses configured or not. | 299 | * Returns whether the given port has any IP addresses configured or not. |
261 | * | 300 | * |
262 | - * @param port the port to check | 301 | + * @param connectPoint the port to check |
263 | * @return true if the port has at least one IP address configured, | 302 | * @return true if the port has at least one IP address configured, |
264 | - * otherwise false | 303 | + * false otherwise |
304 | + */ | ||
305 | + private boolean hasIpAddress(ConnectPoint connectPoint) { | ||
306 | + return interfaceService.getInterfacesByPort(connectPoint) | ||
307 | + .stream() | ||
308 | + .flatMap(intf -> intf.ipAddresses().stream()) | ||
309 | + .findAny() | ||
310 | + .isPresent(); | ||
311 | + } | ||
312 | + | ||
313 | + /** | ||
314 | + * Returns whether the given port has any VLAN configured or not. | ||
315 | + * | ||
316 | + * @param connectPoint the port to check | ||
317 | + * @return true if the port has at least one VLAN configured, | ||
318 | + * false otherwise | ||
265 | */ | 319 | */ |
266 | - private boolean hasIpAddress(ConnectPoint port) { | 320 | + private boolean hasVlan(ConnectPoint connectPoint) { |
267 | - return interfaceService.getInterfacesByPort(port) | 321 | + return interfaceService.getInterfacesByPort(connectPoint) |
268 | .stream() | 322 | .stream() |
269 | - .map(intf -> intf.ipAddresses()) | 323 | + .filter(intf -> !intf.vlan().equals(VlanId.NONE)) |
270 | .findAny() | 324 | .findAny() |
271 | .isPresent(); | 325 | .isPresent(); |
272 | } | 326 | } |
... | @@ -322,6 +376,30 @@ public class ProxyArpManager implements ProxyArpService { | ... | @@ -322,6 +376,30 @@ public class ProxyArpManager implements ProxyArpService { |
322 | } | 376 | } |
323 | 377 | ||
324 | /** | 378 | /** |
379 | + * Flood the arp request at all edges on a specifc VLAN. | ||
380 | + * | ||
381 | + * @param request the arp request | ||
382 | + * @param dsts the destination interfaces | ||
383 | + * @param inPort the connect point the arp request was received on | ||
384 | + */ | ||
385 | + private void vlanFlood(Ethernet request, Set<Interface> dsts, ConnectPoint inPort) { | ||
386 | + TrafficTreatment.Builder builder = null; | ||
387 | + ByteBuffer buf = ByteBuffer.wrap(request.serialize()); | ||
388 | + | ||
389 | + for (Interface intf : dsts) { | ||
390 | + ConnectPoint cPoint = intf.connectPoint(); | ||
391 | + if (cPoint.equals(inPort)) { | ||
392 | + continue; | ||
393 | + } | ||
394 | + | ||
395 | + builder = DefaultTrafficTreatment.builder(); | ||
396 | + builder.setOutput(cPoint.port()); | ||
397 | + packetService.emit(new DefaultOutboundPacket(cPoint.deviceId(), | ||
398 | + builder.build(), buf)); | ||
399 | + } | ||
400 | + } | ||
401 | + | ||
402 | + /** | ||
325 | * Flood the arp request at all edges in the network. | 403 | * Flood the arp request at all edges in the network. |
326 | * | 404 | * |
327 | * @param request the arp request | 405 | * @param request the arp request |
... | @@ -332,7 +410,9 @@ public class ProxyArpManager implements ProxyArpService { | ... | @@ -332,7 +410,9 @@ public class ProxyArpManager implements ProxyArpService { |
332 | ByteBuffer buf = ByteBuffer.wrap(request.serialize()); | 410 | ByteBuffer buf = ByteBuffer.wrap(request.serialize()); |
333 | 411 | ||
334 | for (ConnectPoint connectPoint : edgeService.getEdgePoints()) { | 412 | for (ConnectPoint connectPoint : edgeService.getEdgePoints()) { |
335 | - if (hasIpAddress(connectPoint) || connectPoint.equals(inPort)) { | 413 | + if (hasIpAddress(connectPoint) |
414 | + || hasVlan(connectPoint) | ||
415 | + || connectPoint.equals(inPort)) { | ||
336 | continue; | 416 | continue; |
337 | } | 417 | } |
338 | 418 | ... | ... |
... | @@ -15,7 +15,6 @@ | ... | @@ -15,7 +15,6 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.net.proxyarp.impl; | 16 | package org.onosproject.net.proxyarp.impl; |
17 | 17 | ||
18 | -import com.google.common.collect.Lists; | ||
19 | import com.google.common.collect.Sets; | 18 | import com.google.common.collect.Sets; |
20 | import org.junit.Before; | 19 | import org.junit.Before; |
21 | import org.junit.Test; | 20 | import org.junit.Test; |
... | @@ -48,7 +47,7 @@ import org.onosproject.net.Port; | ... | @@ -48,7 +47,7 @@ import org.onosproject.net.Port; |
48 | import org.onosproject.net.PortNumber; | 47 | import org.onosproject.net.PortNumber; |
49 | import org.onosproject.net.device.DeviceListener; | 48 | import org.onosproject.net.device.DeviceListener; |
50 | import org.onosproject.net.device.DeviceService; | 49 | import org.onosproject.net.device.DeviceService; |
51 | -import org.onosproject.net.edgeservice.impl.EdgeManager; | 50 | +import org.onosproject.net.edge.EdgePortService; |
52 | import org.onosproject.net.flow.DefaultTrafficTreatment; | 51 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
53 | import org.onosproject.net.flow.TrafficTreatment; | 52 | import org.onosproject.net.flow.TrafficTreatment; |
54 | import org.onosproject.net.flow.instructions.Instruction; | 53 | import org.onosproject.net.flow.instructions.Instruction; |
... | @@ -67,6 +66,7 @@ import org.onosproject.net.proxyarp.ProxyArpStoreDelegate; | ... | @@ -67,6 +66,7 @@ import org.onosproject.net.proxyarp.ProxyArpStoreDelegate; |
67 | import java.nio.ByteBuffer; | 66 | import java.nio.ByteBuffer; |
68 | import java.util.ArrayList; | 67 | import java.util.ArrayList; |
69 | import java.util.Collections; | 68 | import java.util.Collections; |
69 | +import java.util.HashSet; | ||
70 | import java.util.List; | 70 | import java.util.List; |
71 | import java.util.Set; | 71 | import java.util.Set; |
72 | 72 | ||
... | @@ -88,47 +88,65 @@ import static org.junit.Assert.assertTrue; | ... | @@ -88,47 +88,65 @@ import static org.junit.Assert.assertTrue; |
88 | */ | 88 | */ |
89 | public class ProxyArpManagerTest { | 89 | public class ProxyArpManagerTest { |
90 | 90 | ||
91 | - private static final int NUM_DEVICES = 6; | 91 | + private static final int NUM_DEVICES = 10; |
92 | private static final int NUM_PORTS_PER_DEVICE = 3; | 92 | private static final int NUM_PORTS_PER_DEVICE = 3; |
93 | - private static final int NUM_ADDRESS_PORTS = NUM_DEVICES / 2; | 93 | + private static final int LAST_CONF_DEVICE_INTF_VLAN_IP = 3; |
94 | - private static final int NUM_FLOOD_PORTS = 3; | 94 | + private static final int LAST_CONF_DEVICE_INTF_VLAN = 6; |
95 | 95 | ||
96 | private static final Ip4Address IP1 = Ip4Address.valueOf("192.168.1.1"); | 96 | private static final Ip4Address IP1 = Ip4Address.valueOf("192.168.1.1"); |
97 | private static final Ip4Address IP2 = Ip4Address.valueOf("192.168.1.2"); | 97 | private static final Ip4Address IP2 = Ip4Address.valueOf("192.168.1.2"); |
98 | - private static final Ip6Address IP3 = Ip6Address.valueOf("1000::1"); | 98 | + private static final Ip6Address IP3 = Ip6Address.valueOf("1000:ffff::1"); |
99 | - private static final Ip6Address IP4 = Ip6Address.valueOf("1000::2"); | 99 | + private static final Ip6Address IP4 = Ip6Address.valueOf("1000:ffff::2"); |
100 | 100 | ||
101 | private static final ProviderId PID = new ProviderId("of", "foo"); | 101 | private static final ProviderId PID = new ProviderId("of", "foo"); |
102 | 102 | ||
103 | private static final VlanId VLAN1 = VlanId.vlanId((short) 1); | 103 | private static final VlanId VLAN1 = VlanId.vlanId((short) 1); |
104 | private static final VlanId VLAN2 = VlanId.vlanId((short) 2); | 104 | private static final VlanId VLAN2 = VlanId.vlanId((short) 2); |
105 | - private static final MacAddress MAC1 = MacAddress.valueOf("00:00:11:00:00:01"); | 105 | + private static final VlanId VLAN10 = VlanId.vlanId((short) 10); |
106 | - private static final MacAddress MAC2 = MacAddress.valueOf("00:00:22:00:00:02"); | 106 | + |
107 | - private static final MacAddress MAC3 = MacAddress.valueOf("00:00:33:00:00:03"); | 107 | + private static final MacAddress MAC1 = MacAddress.valueOf("00:00:00:00:00:01"); |
108 | - private static final MacAddress MAC4 = MacAddress.valueOf("00:00:44:00:00:04"); | 108 | + private static final MacAddress MAC2 = MacAddress.valueOf("00:00:00:00:00:02"); |
109 | + private static final MacAddress MAC3 = MacAddress.valueOf("00:00:00:00:00:03"); | ||
110 | + private static final MacAddress MAC4 = MacAddress.valueOf("00:00:00:00:00:04"); | ||
111 | + private static final MacAddress MAC10 = MacAddress.valueOf("00:00:00:00:00:0A"); | ||
112 | + | ||
109 | private static final MacAddress SOLICITED_MAC3 = MacAddress.valueOf("33:33:FF:00:00:01"); | 113 | private static final MacAddress SOLICITED_MAC3 = MacAddress.valueOf("33:33:FF:00:00:01"); |
114 | + | ||
110 | private static final HostId HID1 = HostId.hostId(MAC1, VLAN1); | 115 | private static final HostId HID1 = HostId.hostId(MAC1, VLAN1); |
111 | private static final HostId HID2 = HostId.hostId(MAC2, VLAN1); | 116 | private static final HostId HID2 = HostId.hostId(MAC2, VLAN1); |
112 | private static final HostId HID3 = HostId.hostId(MAC3, VLAN1); | 117 | private static final HostId HID3 = HostId.hostId(MAC3, VLAN1); |
113 | private static final HostId HID4 = HostId.hostId(MAC4, VLAN1); | 118 | private static final HostId HID4 = HostId.hostId(MAC4, VLAN1); |
119 | + private static final HostId HID10 = HostId.hostId(MAC10, VLAN10); | ||
120 | + | ||
114 | private static final HostId SOLICITED_HID3 = HostId.hostId(SOLICITED_MAC3, VLAN1); | 121 | private static final HostId SOLICITED_HID3 = HostId.hostId(SOLICITED_MAC3, VLAN1); |
115 | 122 | ||
116 | private static final DeviceId DID1 = getDeviceId(1); | 123 | private static final DeviceId DID1 = getDeviceId(1); |
117 | private static final DeviceId DID2 = getDeviceId(2); | 124 | private static final DeviceId DID2 = getDeviceId(2); |
125 | + | ||
118 | private static final PortNumber P1 = PortNumber.portNumber(1); | 126 | private static final PortNumber P1 = PortNumber.portNumber(1); |
127 | + | ||
119 | private static final HostLocation LOC1 = new HostLocation(DID1, P1, 123L); | 128 | private static final HostLocation LOC1 = new HostLocation(DID1, P1, 123L); |
120 | private static final HostLocation LOC2 = new HostLocation(DID2, P1, 123L); | 129 | private static final HostLocation LOC2 = new HostLocation(DID2, P1, 123L); |
121 | - private static final byte[] ZERO_MAC_ADDRESS = MacAddress.ZERO.toBytes(); | ||
122 | 130 | ||
123 | - //Return values used for various functions of the TestPacketService inner class. | 131 | + private final byte[] zeroMacAddress = MacAddress.ZERO.toBytes(); |
124 | - private boolean isEdgePointReturn; | 132 | + |
125 | - private List<ConnectPoint> getEdgePointsNoArg; | 133 | + // The first three devices in the topology have interfaces configured |
134 | + // with VLANs and IPs | ||
135 | + private final List<ConnectPoint> configIpCPoints = new ArrayList<>(); | ||
126 | 136 | ||
137 | + // Other three devices in the topology (from 4 to 6) have interfaces | ||
138 | + // configured only with VLANs | ||
139 | + private final List<ConnectPoint> configVlanCPoints = new ArrayList<>(); | ||
140 | + | ||
141 | + // Remaining devices in the network (id > 6) don't have any interface | ||
142 | + // configured. | ||
143 | + private final List<ConnectPoint> noConfigCPoints = new ArrayList<>(); | ||
127 | 144 | ||
128 | private ProxyArpManager proxyArp; | 145 | private ProxyArpManager proxyArp; |
129 | 146 | ||
130 | private TestPacketService packetService; | 147 | private TestPacketService packetService; |
131 | private DeviceService deviceService; | 148 | private DeviceService deviceService; |
149 | + private EdgePortService edgePortService; | ||
132 | private LinkService linkService; | 150 | private LinkService linkService; |
133 | private HostService hostService; | 151 | private HostService hostService; |
134 | private InterfaceService interfaceService; | 152 | private InterfaceService interfaceService; |
... | @@ -140,20 +158,27 @@ public class ProxyArpManagerTest { | ... | @@ -140,20 +158,27 @@ public class ProxyArpManagerTest { |
140 | proxyArp.packetService = packetService; | 158 | proxyArp.packetService = packetService; |
141 | proxyArp.store = new TestProxyArpStoreAdapter(); | 159 | proxyArp.store = new TestProxyArpStoreAdapter(); |
142 | 160 | ||
143 | - proxyArp.edgeService = new TestEdgePortService(); | 161 | + // Create a host service mock here. |
144 | - | ||
145 | - // Create a host service mock here. Must be replayed by tests once the | ||
146 | - // expectations have been set up | ||
147 | hostService = createMock(HostService.class); | 162 | hostService = createMock(HostService.class); |
148 | proxyArp.hostService = hostService; | 163 | proxyArp.hostService = hostService; |
149 | 164 | ||
165 | + // Create an edge port service. | ||
166 | + edgePortService = createMock(EdgePortService.class); | ||
167 | + proxyArp.edgeService = edgePortService; | ||
168 | + | ||
169 | + // Create interface service | ||
150 | interfaceService = createMock(InterfaceService.class); | 170 | interfaceService = createMock(InterfaceService.class); |
151 | proxyArp.interfaceService = interfaceService; | 171 | proxyArp.interfaceService = interfaceService; |
152 | 172 | ||
173 | + // Create the topology | ||
153 | createTopology(); | 174 | createTopology(); |
154 | proxyArp.deviceService = deviceService; | 175 | proxyArp.deviceService = deviceService; |
155 | proxyArp.linkService = linkService; | 176 | proxyArp.linkService = linkService; |
156 | 177 | ||
178 | + setupNoConfigCPoints(); | ||
179 | + setupconfigIpCPoints(); | ||
180 | + setupconfigVlanCPoints(); | ||
181 | + | ||
157 | proxyArp.activate(); | 182 | proxyArp.activate(); |
158 | } | 183 | } |
159 | 184 | ||
... | @@ -176,7 +201,8 @@ public class ProxyArpManagerTest { | ... | @@ -176,7 +201,8 @@ public class ProxyArpManagerTest { |
176 | 201 | ||
177 | createDevices(NUM_DEVICES, NUM_PORTS_PER_DEVICE); | 202 | createDevices(NUM_DEVICES, NUM_PORTS_PER_DEVICE); |
178 | createLinks(NUM_DEVICES); | 203 | createLinks(NUM_DEVICES); |
179 | - addAddressBindings(); | 204 | + addIntfConfig(); |
205 | + popluateEdgePortService(); | ||
180 | } | 206 | } |
181 | 207 | ||
182 | /** | 208 | /** |
... | @@ -237,13 +263,22 @@ public class ProxyArpManagerTest { | ... | @@ -237,13 +263,22 @@ public class ProxyArpManagerTest { |
237 | replay(linkService); | 263 | replay(linkService); |
238 | } | 264 | } |
239 | 265 | ||
240 | - private void addAddressBindings() { | 266 | + /** |
267 | + * On the first three devices two config interfaces are binded on port 1. | ||
268 | + * The first one with VLAN1, the second one with VLAN equals to none. | ||
269 | + * Both interfaces have an IP. | ||
270 | + * On devices 4, 5 and 6 it's binded a config interface on port 1. | ||
271 | + * The interface is configured with VLAN 1 and no IP. | ||
272 | + */ | ||
273 | + private void addIntfConfig() { | ||
241 | Set<Interface> interfaces = Sets.newHashSet(); | 274 | Set<Interface> interfaces = Sets.newHashSet(); |
242 | 275 | ||
243 | - for (int i = 1; i <= NUM_ADDRESS_PORTS; i++) { | 276 | + Set<Interface> vlanOneSet = new HashSet<>(); |
277 | + | ||
278 | + for (int i = 1; i <= LAST_CONF_DEVICE_INTF_VLAN_IP; i++) { | ||
244 | ConnectPoint cp = new ConnectPoint(getDeviceId(i), P1); | 279 | ConnectPoint cp = new ConnectPoint(getDeviceId(i), P1); |
245 | 280 | ||
246 | - // Interface address for IPv4 | 281 | + // Interface addresses for IPv4 |
247 | Ip4Prefix prefix1 = Ip4Prefix.valueOf("10.0." + (2 * i - 1) + ".0/24"); | 282 | Ip4Prefix prefix1 = Ip4Prefix.valueOf("10.0." + (2 * i - 1) + ".0/24"); |
248 | Ip4Address addr1 = Ip4Address.valueOf("10.0." + (2 * i - 1) + ".1"); | 283 | Ip4Address addr1 = Ip4Address.valueOf("10.0." + (2 * i - 1) + ".1"); |
249 | Ip4Prefix prefix2 = Ip4Prefix.valueOf("10.0." + (2 * i) + ".0/24"); | 284 | Ip4Prefix prefix2 = Ip4Prefix.valueOf("10.0." + (2 * i) + ".0/24"); |
... | @@ -251,39 +286,131 @@ public class ProxyArpManagerTest { | ... | @@ -251,39 +286,131 @@ public class ProxyArpManagerTest { |
251 | InterfaceIpAddress ia1 = new InterfaceIpAddress(addr1, prefix1); | 286 | InterfaceIpAddress ia1 = new InterfaceIpAddress(addr1, prefix1); |
252 | InterfaceIpAddress ia2 = new InterfaceIpAddress(addr2, prefix2); | 287 | InterfaceIpAddress ia2 = new InterfaceIpAddress(addr2, prefix2); |
253 | 288 | ||
254 | - // Interface address for IPv6 | 289 | + // Interface addresses for IPv6 |
255 | Ip6Prefix prefix3 = Ip6Prefix.valueOf((2 * i - 1) + "000::0/64"); | 290 | Ip6Prefix prefix3 = Ip6Prefix.valueOf((2 * i - 1) + "000::0/64"); |
256 | Ip6Address addr3 = Ip6Address.valueOf((2 * i - 1) + "000::1"); | 291 | Ip6Address addr3 = Ip6Address.valueOf((2 * i - 1) + "000::1"); |
257 | Ip6Prefix prefix4 = Ip6Prefix.valueOf((2 * i) + "000::0/64"); | 292 | Ip6Prefix prefix4 = Ip6Prefix.valueOf((2 * i) + "000::0/64"); |
258 | - Ip6Address addr4 = Ip6Address.valueOf((2 * i) + "000::1"); | 293 | + Ip6Address addr4 = Ip6Address.valueOf((2 * i) + "000::2"); |
259 | InterfaceIpAddress ia3 = new InterfaceIpAddress(addr3, prefix3); | 294 | InterfaceIpAddress ia3 = new InterfaceIpAddress(addr3, prefix3); |
260 | InterfaceIpAddress ia4 = new InterfaceIpAddress(addr4, prefix4); | 295 | InterfaceIpAddress ia4 = new InterfaceIpAddress(addr4, prefix4); |
261 | 296 | ||
297 | + // Setting up interfaces | ||
262 | Interface intf1 = new Interface(cp, Sets.newHashSet(ia1, ia3), | 298 | Interface intf1 = new Interface(cp, Sets.newHashSet(ia1, ia3), |
263 | MacAddress.valueOf(2 * i - 1), | 299 | MacAddress.valueOf(2 * i - 1), |
264 | VlanId.vlanId((short) 1)); | 300 | VlanId.vlanId((short) 1)); |
265 | Interface intf2 = new Interface(cp, Sets.newHashSet(ia2, ia4), | 301 | Interface intf2 = new Interface(cp, Sets.newHashSet(ia2, ia4), |
266 | MacAddress.valueOf(2 * i), | 302 | MacAddress.valueOf(2 * i), |
267 | VlanId.NONE); | 303 | VlanId.NONE); |
304 | + | ||
268 | interfaces.add(intf1); | 305 | interfaces.add(intf1); |
269 | interfaces.add(intf2); | 306 | interfaces.add(intf2); |
270 | 307 | ||
308 | + vlanOneSet.add(intf1); | ||
309 | + | ||
271 | expect(interfaceService.getInterfacesByPort(cp)) | 310 | expect(interfaceService.getInterfacesByPort(cp)) |
272 | .andReturn(Sets.newHashSet(intf1, intf2)).anyTimes(); | 311 | .andReturn(Sets.newHashSet(intf1, intf2)).anyTimes(); |
273 | } | 312 | } |
313 | + for (int i = LAST_CONF_DEVICE_INTF_VLAN_IP + 1; i <= LAST_CONF_DEVICE_INTF_VLAN; i++) { | ||
314 | + ConnectPoint cp = new ConnectPoint(getDeviceId(i), P1); | ||
315 | + Interface intf1 = new Interface(cp, null, | ||
316 | + MacAddress.NONE, | ||
317 | + VlanId.vlanId((short) 1)); | ||
274 | 318 | ||
319 | + interfaces.add(intf1); | ||
320 | + vlanOneSet.add(intf1); | ||
321 | + | ||
322 | + expect(interfaceService.getInterfacesByPort(cp)) | ||
323 | + .andReturn(Sets.newHashSet(intf1)).anyTimes(); | ||
324 | + } | ||
325 | + expect(interfaceService.getInterfacesByVlan(VLAN1)) | ||
326 | + .andReturn(vlanOneSet).anyTimes(); | ||
327 | + expect(interfaceService.getInterfacesByVlan(VLAN10)) | ||
328 | + .andReturn(Collections.emptySet()).anyTimes(); | ||
275 | expect(interfaceService.getInterfaces()).andReturn(interfaces).anyTimes(); | 329 | expect(interfaceService.getInterfaces()).andReturn(interfaces).anyTimes(); |
276 | 330 | ||
277 | - for (int i = 1; i <= NUM_FLOOD_PORTS; i++) { | 331 | + for (int i = LAST_CONF_DEVICE_INTF_VLAN + 1; i <= NUM_DEVICES; i++) { |
278 | - ConnectPoint cp = new ConnectPoint(getDeviceId(i + NUM_ADDRESS_PORTS), | 332 | + ConnectPoint cp = new ConnectPoint(getDeviceId(i), |
279 | P1); | 333 | P1); |
280 | - | ||
281 | expect(interfaceService.getInterfacesByPort(cp)) | 334 | expect(interfaceService.getInterfacesByPort(cp)) |
282 | .andReturn(Collections.emptySet()).anyTimes(); | 335 | .andReturn(Collections.emptySet()).anyTimes(); |
283 | } | 336 | } |
284 | } | 337 | } |
285 | 338 | ||
286 | /** | 339 | /** |
340 | + * Populates edge ports in the EdgePortService to return all port 1 | ||
341 | + * as edge ports. | ||
342 | + */ | ||
343 | + private void popluateEdgePortService() { | ||
344 | + Set<ConnectPoint> edgeConnectPoints = new HashSet<>(); | ||
345 | + | ||
346 | + for (int i = 1; i <= NUM_DEVICES; i++) { | ||
347 | + for (int j = 1; j <= NUM_PORTS_PER_DEVICE; j++) { | ||
348 | + ConnectPoint edgeConnectPoint = new ConnectPoint( | ||
349 | + getDeviceId(i), | ||
350 | + PortNumber.portNumber(1)); | ||
351 | + ConnectPoint noEdgeConnectPointOne = new ConnectPoint( | ||
352 | + getDeviceId(i), | ||
353 | + PortNumber.portNumber(2)); | ||
354 | + ConnectPoint noEdgeConnectPointTwo = new ConnectPoint( | ||
355 | + getDeviceId(i), | ||
356 | + PortNumber.portNumber(3)); | ||
357 | + | ||
358 | + edgeConnectPoints.add(edgeConnectPoint); | ||
359 | + | ||
360 | + expect(edgePortService.isEdgePoint(edgeConnectPoint)) | ||
361 | + .andReturn(true).anyTimes(); | ||
362 | + expect(edgePortService.isEdgePoint(noEdgeConnectPointOne)) | ||
363 | + .andReturn(false).anyTimes(); | ||
364 | + expect(edgePortService.isEdgePoint(noEdgeConnectPointTwo)) | ||
365 | + .andReturn(false).anyTimes(); | ||
366 | + } | ||
367 | + } | ||
368 | + expect(edgePortService.getEdgePoints()) | ||
369 | + .andReturn(edgeConnectPoints).anyTimes(); | ||
370 | + | ||
371 | + replay(edgePortService); | ||
372 | + } | ||
373 | + | ||
374 | + /** | ||
375 | + * Creates a list of connect points used to verify floodling on ports | ||
376 | + * with no interfaces configured (all ports without interface config). | ||
377 | + */ | ||
378 | + private void setupNoConfigCPoints() { | ||
379 | + for (int i = NUM_DEVICES / 2 + 2; i <= NUM_DEVICES; i++) { | ||
380 | + ConnectPoint connectPoint = new ConnectPoint( | ||
381 | + getDeviceId(i), | ||
382 | + PortNumber.portNumber(1)); | ||
383 | + noConfigCPoints.add(connectPoint); | ||
384 | + } | ||
385 | + } | ||
386 | + | ||
387 | + /** | ||
388 | + * Creates a list of connect points used to verify floodling on ports | ||
389 | + * with interfaces configured (both VLAN and IP). | ||
390 | + */ | ||
391 | + private void setupconfigIpCPoints() { | ||
392 | + for (int i = 1; i <= 3; i++) { | ||
393 | + ConnectPoint connectPoint = new ConnectPoint( | ||
394 | + getDeviceId(i), | ||
395 | + PortNumber.portNumber(1)); | ||
396 | + configIpCPoints.add(connectPoint); | ||
397 | + } | ||
398 | + } | ||
399 | + | ||
400 | + /** | ||
401 | + * Creates a list of connect points used to verify floodling on ports | ||
402 | + * with interfaces configured (both VLAN and IP). | ||
403 | + */ | ||
404 | + private void setupconfigVlanCPoints() { | ||
405 | + for (int i = LAST_CONF_DEVICE_INTF_VLAN_IP + 1; i <= LAST_CONF_DEVICE_INTF_VLAN; i++) { | ||
406 | + ConnectPoint connectPoint = new ConnectPoint( | ||
407 | + getDeviceId(i), | ||
408 | + PortNumber.portNumber(1)); | ||
409 | + configVlanCPoints.add(connectPoint); | ||
410 | + } | ||
411 | + } | ||
412 | + | ||
413 | + /** | ||
287 | * Tests {@link ProxyArpManager#isKnown(org.onlab.packet.IpAddress)} in the | 414 | * Tests {@link ProxyArpManager#isKnown(org.onlab.packet.IpAddress)} in the |
288 | * case where the IP address is not known. | 415 | * case where the IP address is not known. |
289 | * Verifies the method returns false. | 416 | * Verifies the method returns false. |
... | @@ -318,33 +445,34 @@ public class ProxyArpManagerTest { | ... | @@ -318,33 +445,34 @@ public class ProxyArpManagerTest { |
318 | /** | 445 | /** |
319 | * Tests {@link ProxyArpManager#reply(Ethernet, ConnectPoint)} in the case where the | 446 | * Tests {@link ProxyArpManager#reply(Ethernet, ConnectPoint)} in the case where the |
320 | * destination host is known. | 447 | * destination host is known. |
321 | - * Verifies the correct ARP reply is sent out the correct port. | 448 | + * Two host using the same VLAN are registered on the host service on devices 5 and 6. |
449 | + * Host on port 6 asks for the MAC of the device on port 5. | ||
450 | + * Since the destination mac address is known, the request is not flooded to anywhere | ||
451 | + * and ONOS directly builds an ARP reply, sended back to the requester on device 6. | ||
452 | + * It's verified that a proper ARP reply is received on port 1 of device 6. | ||
322 | */ | 453 | */ |
323 | @Test | 454 | @Test |
324 | public void testReplyKnown() { | 455 | public void testReplyKnown() { |
325 | - //Set the return value of isEdgePoint from the edgemanager. | 456 | + Host requestor = new DefaultHost(PID, HID1, MAC1, VLAN1, getLocation(NUM_DEVICES), |
326 | - isEdgePointReturn = true; | ||
327 | - | ||
328 | - Host replyer = new DefaultHost(PID, HID1, MAC1, VLAN1, getLocation(4), | ||
329 | Collections.singleton(IP1)); | 457 | Collections.singleton(IP1)); |
330 | 458 | ||
331 | - Host requestor = new DefaultHost(PID, HID2, MAC2, VLAN1, getLocation(5), | 459 | + Host replyer = new DefaultHost(PID, HID2, MAC2, VLAN1, getLocation(NUM_DEVICES - 1), |
332 | Collections.singleton(IP2)); | 460 | Collections.singleton(IP2)); |
333 | 461 | ||
334 | - expect(hostService.getHostsByIp(IP1)) | 462 | + expect(hostService.getHostsByIp(IP2)) |
335 | .andReturn(Collections.singleton(replyer)); | 463 | .andReturn(Collections.singleton(replyer)); |
336 | - expect(hostService.getHost(HID2)).andReturn(requestor); | 464 | + expect(hostService.getHost(HID1)).andReturn(requestor); |
337 | 465 | ||
338 | replay(hostService); | 466 | replay(hostService); |
339 | replay(interfaceService); | 467 | replay(interfaceService); |
340 | 468 | ||
341 | - Ethernet arpRequest = buildArp(ARP.OP_REQUEST, MAC2, null, IP2, IP1); | 469 | + Ethernet arpRequest = buildArp(ARP.OP_REQUEST, VLAN1, MAC1, null, IP1, IP2); |
342 | 470 | ||
343 | - proxyArp.reply(arpRequest, getLocation(5)); | 471 | + proxyArp.reply(arpRequest, getLocation(NUM_DEVICES)); |
344 | 472 | ||
345 | assertEquals(1, packetService.packets.size()); | 473 | assertEquals(1, packetService.packets.size()); |
346 | - Ethernet arpReply = buildArp(ARP.OP_REPLY, MAC1, MAC2, IP1, IP2); | 474 | + Ethernet arpReply = buildArp(ARP.OP_REPLY, VLAN1, MAC2, MAC1, IP2, IP1); |
347 | - verifyPacketOut(arpReply, getLocation(5), packetService.packets.get(0)); | 475 | + verifyPacketOut(arpReply, getLocation(NUM_DEVICES), packetService.packets.get(0)); |
348 | } | 476 | } |
349 | 477 | ||
350 | /** | 478 | /** |
... | @@ -354,9 +482,6 @@ public class ProxyArpManagerTest { | ... | @@ -354,9 +482,6 @@ public class ProxyArpManagerTest { |
354 | */ | 482 | */ |
355 | @Test | 483 | @Test |
356 | public void testReplyKnownIpv6() { | 484 | public void testReplyKnownIpv6() { |
357 | - //Set the return value of isEdgePoint from the edgemanager. | ||
358 | - isEdgePointReturn = true; | ||
359 | - | ||
360 | Host replyer = new DefaultHost(PID, HID3, MAC3, VLAN1, getLocation(4), | 485 | Host replyer = new DefaultHost(PID, HID3, MAC3, VLAN1, getLocation(4), |
361 | Collections.singleton(IP3)); | 486 | Collections.singleton(IP3)); |
362 | 487 | ||
... | @@ -385,34 +510,31 @@ public class ProxyArpManagerTest { | ... | @@ -385,34 +510,31 @@ public class ProxyArpManagerTest { |
385 | /** | 510 | /** |
386 | * Tests {@link ProxyArpManager#reply(Ethernet, ConnectPoint)} in the case where the | 511 | * Tests {@link ProxyArpManager#reply(Ethernet, ConnectPoint)} in the case where the |
387 | * destination host is not known. | 512 | * destination host is not known. |
513 | + * Only a requestor is present (on device 6, port 1). The device has a VLAN configured | ||
514 | + * which is not configured anywhere in the system. | ||
515 | + * Since the destination is not known, and since the ARP request can't be sent out of | ||
516 | + * interfaces configured, the ARP request is flooded out of ports 4 and 5. | ||
388 | * Verifies the ARP request is flooded out the correct edge ports. | 517 | * Verifies the ARP request is flooded out the correct edge ports. |
389 | */ | 518 | */ |
390 | @Test | 519 | @Test |
391 | public void testReplyUnknown() { | 520 | public void testReplyUnknown() { |
392 | - isEdgePointReturn = true; | 521 | + Host requestor = new DefaultHost(PID, HID10, MAC10, VLAN10, getLocation(NUM_DEVICES), |
393 | - | 522 | + Collections.singleton(IP1)); |
394 | - Host requestor = new DefaultHost(PID, HID2, MAC2, VLAN1, getLocation(5), | ||
395 | - Collections.singleton(IP2)); | ||
396 | 523 | ||
397 | - expect(hostService.getHostsByIp(IP1)) | 524 | + expect(hostService.getHostsByIp(IP2)) |
398 | .andReturn(Collections.emptySet()); | 525 | .andReturn(Collections.emptySet()); |
399 | - expect(interfaceService.getInterfacesByIp(IP2)) | 526 | + expect(interfaceService.getInterfacesByIp(IP1)) |
400 | .andReturn(Collections.emptySet()); | 527 | .andReturn(Collections.emptySet()); |
401 | - expect(hostService.getHost(HID2)).andReturn(requestor); | 528 | + expect(hostService.getHost(HID10)).andReturn(requestor); |
402 | 529 | ||
403 | replay(hostService); | 530 | replay(hostService); |
404 | replay(interfaceService); | 531 | replay(interfaceService); |
405 | 532 | ||
406 | - Ethernet arpRequest = buildArp(ARP.OP_REQUEST, MAC2, null, IP2, IP1); | 533 | + Ethernet arpRequest = buildArp(ARP.OP_REQUEST, VLAN10, MAC10, null, IP1, IP2); |
407 | 534 | ||
408 | - //Setup the set of edge ports to be used in the reply method | 535 | + proxyArp.reply(arpRequest, getLocation(NUM_DEVICES)); |
409 | - getEdgePointsNoArg = Lists.newLinkedList(); | ||
410 | - getEdgePointsNoArg.add(new ConnectPoint(DeviceId.deviceId("5"), PortNumber.portNumber(1))); | ||
411 | - getEdgePointsNoArg.add(new ConnectPoint(DeviceId.deviceId("4"), PortNumber.portNumber(1))); | ||
412 | 536 | ||
413 | - proxyArp.reply(arpRequest, getLocation(6)); | 537 | + verifyFlood(arpRequest, noConfigCPoints); |
414 | - | ||
415 | - verifyFlood(arpRequest); | ||
416 | } | 538 | } |
417 | 539 | ||
418 | /** | 540 | /** |
... | @@ -422,9 +544,7 @@ public class ProxyArpManagerTest { | ... | @@ -422,9 +544,7 @@ public class ProxyArpManagerTest { |
422 | */ | 544 | */ |
423 | @Test | 545 | @Test |
424 | public void testReplyUnknownIpv6() { | 546 | public void testReplyUnknownIpv6() { |
425 | - isEdgePointReturn = true; | 547 | + Host requestor = new DefaultHost(PID, HID4, MAC4, VLAN1, getLocation(NUM_DEVICES), |
426 | - | ||
427 | - Host requestor = new DefaultHost(PID, HID4, MAC4, VLAN1, getLocation(5), | ||
428 | Collections.singleton(IP4)); | 548 | Collections.singleton(IP4)); |
429 | 549 | ||
430 | expect(hostService.getHostsByIp(IP3)) | 550 | expect(hostService.getHostsByIp(IP3)) |
... | @@ -440,49 +560,107 @@ public class ProxyArpManagerTest { | ... | @@ -440,49 +560,107 @@ public class ProxyArpManagerTest { |
440 | MAC4, SOLICITED_MAC3, | 560 | MAC4, SOLICITED_MAC3, |
441 | IP4, IP3); | 561 | IP4, IP3); |
442 | 562 | ||
443 | - //Setup the set of edge ports to be used in the reply method | 563 | + proxyArp.reply(ndpRequest, getLocation(NUM_DEVICES)); |
444 | - getEdgePointsNoArg = Lists.newLinkedList(); | ||
445 | - getEdgePointsNoArg.add(new ConnectPoint(DeviceId.deviceId("5"), PortNumber.portNumber(1))); | ||
446 | - getEdgePointsNoArg.add(new ConnectPoint(DeviceId.deviceId("4"), PortNumber.portNumber(1))); | ||
447 | 564 | ||
448 | - proxyArp.reply(ndpRequest, getLocation(6)); | 565 | + verifyFlood(ndpRequest, noConfigCPoints); |
449 | - | ||
450 | - verifyFlood(ndpRequest); | ||
451 | } | 566 | } |
452 | 567 | ||
453 | /** | 568 | /** |
454 | * Tests {@link ProxyArpManager#reply(Ethernet, ConnectPoint)} in the case where the | 569 | * Tests {@link ProxyArpManager#reply(Ethernet, ConnectPoint)} in the case where the |
455 | * destination host is known for that IP address, but is not on the same | 570 | * destination host is known for that IP address, but is not on the same |
456 | * VLAN as the source host. | 571 | * VLAN as the source host. |
572 | + * An host is connected on device 6, port 1 where no interfaces are defined. It sends | ||
573 | + * ARP requests from VLAN10, not configured anywhere in the network. Another host with | ||
574 | + * the IP address requested lives on device 5, port 1 in the network. Anyway, since the | ||
575 | + * host uses another VLAN it's not found and the ARP packet is flooded out of port | ||
576 | + * 4 and 5. | ||
577 | + * | ||
457 | * Verifies the ARP request is flooded out the correct edge ports. | 578 | * Verifies the ARP request is flooded out the correct edge ports. |
458 | */ | 579 | */ |
459 | @Test | 580 | @Test |
460 | public void testReplyDifferentVlan() { | 581 | public void testReplyDifferentVlan() { |
461 | - | 582 | + Host requestor = new DefaultHost(PID, HID10, MAC10, VLAN10, getLocation(NUM_DEVICES), |
462 | - Host replyer = new DefaultHost(PID, HID1, MAC1, VLAN2, getLocation(4), | ||
463 | Collections.singleton(IP1)); | 583 | Collections.singleton(IP1)); |
464 | 584 | ||
465 | - Host requestor = new DefaultHost(PID, HID2, MAC2, VLAN1, getLocation(5), | 585 | + Host replyer = new DefaultHost(PID, HID2, MAC2, VLAN2, getLocation(NUM_DEVICES - 1), |
466 | Collections.singleton(IP2)); | 586 | Collections.singleton(IP2)); |
467 | 587 | ||
468 | - expect(hostService.getHostsByIp(IP1)) | 588 | + expect(hostService.getHostsByIp(IP2)) |
469 | .andReturn(Collections.singleton(replyer)); | 589 | .andReturn(Collections.singleton(replyer)); |
470 | - expect(interfaceService.getInterfacesByIp(IP2)) | 590 | + expect(interfaceService.getInterfacesByIp(IP1)) |
471 | .andReturn(Collections.emptySet()); | 591 | .andReturn(Collections.emptySet()); |
472 | - expect(hostService.getHost(HID2)).andReturn(requestor); | 592 | + expect(hostService.getHost(HID10)).andReturn(requestor); |
473 | 593 | ||
474 | replay(hostService); | 594 | replay(hostService); |
475 | replay(interfaceService); | 595 | replay(interfaceService); |
476 | 596 | ||
477 | - Ethernet arpRequest = buildArp(ARP.OP_REQUEST, MAC2, null, IP2, IP1); | 597 | + Ethernet arpRequest = buildArp(ARP.OP_REQUEST, VLAN10, MAC10, null, IP1, IP2); |
598 | + | ||
599 | + proxyArp.reply(arpRequest, getLocation(NUM_DEVICES)); | ||
600 | + | ||
601 | + verifyFlood(arpRequest, noConfigCPoints); | ||
602 | + } | ||
603 | + | ||
604 | + /** | ||
605 | + * Tests {@link ProxyArpManager#reply(Ethernet, ConnectPoint)} in the case where the | ||
606 | + * a vlan packet comes in from a port without interfaces configured. The destination | ||
607 | + * host is unknown for that IP address and there are some interfaces configured on | ||
608 | + * the same vlan. | ||
609 | + * It's expected to see the ARP request going out through ports with no interfaces | ||
610 | + * configured, devices 4 and 5, port 1. | ||
611 | + * | ||
612 | + * Verifies the ARP request is flooded out the correct edge ports. | ||
613 | + */ | ||
614 | + @Test | ||
615 | + public void testConfiguredVlan() { | ||
616 | + Host requestor = new DefaultHost(PID, HID1, MAC1, VLAN1, getLocation(NUM_DEVICES), | ||
617 | + Collections.singleton(IP1)); | ||
618 | + | ||
619 | + expect(hostService.getHostsByIp(IP2)) | ||
620 | + .andReturn(Collections.emptySet()); | ||
621 | + expect(interfaceService.getInterfacesByIp(IP1)) | ||
622 | + .andReturn(Collections.emptySet()); | ||
623 | + expect(hostService.getHost(HID1)).andReturn(requestor); | ||
624 | + | ||
625 | + replay(hostService); | ||
626 | + replay(interfaceService); | ||
627 | + | ||
628 | + Ethernet arpRequest = buildArp(ARP.OP_REQUEST, VLAN1, MAC1, null, IP1, IP2); | ||
629 | + | ||
630 | + proxyArp.reply(arpRequest, getLocation(NUM_DEVICES)); | ||
631 | + | ||
632 | + verifyFlood(arpRequest, noConfigCPoints); | ||
633 | + } | ||
634 | + | ||
635 | + /** | ||
636 | + * Tests {@link ProxyArpManager#reply(Ethernet, ConnectPoint)} in the case where the | ||
637 | + * a vlan packet comes in from a port without interfaces configured. The destination | ||
638 | + * host is not known for that IP address and there are some interfaces configured on | ||
639 | + * the same vlan. | ||
640 | + * It's expected to see the ARP request going out through ports with no interfaces | ||
641 | + * configured, devices 4 and 5, port 1. | ||
642 | + * | ||
643 | + * Verifies the ARP request is flooded out the correct edge ports. | ||
644 | + */ | ||
645 | + @Test | ||
646 | + public void testConfiguredVlanOnInterfaces() { | ||
647 | + Host requestor = new DefaultHost(PID, HID1, MAC1, VLAN1, getLocation(6), | ||
648 | + Collections.singleton(IP1)); | ||
649 | + | ||
650 | + expect(hostService.getHostsByIp(IP2)) | ||
651 | + .andReturn(Collections.emptySet()); | ||
652 | + expect(interfaceService.getInterfacesByIp(IP1)) | ||
653 | + .andReturn(Collections.emptySet()); | ||
654 | + expect(hostService.getHost(HID1)).andReturn(requestor); | ||
655 | + | ||
656 | + replay(hostService); | ||
657 | + replay(interfaceService); | ||
658 | + | ||
659 | + Ethernet arpRequest = buildArp(ARP.OP_REQUEST, VLAN1, MAC1, null, IP1, IP2); | ||
478 | 660 | ||
479 | - //Setup for flood test | ||
480 | - getEdgePointsNoArg = Lists.newLinkedList(); | ||
481 | - getEdgePointsNoArg.add(new ConnectPoint(DeviceId.deviceId("5"), PortNumber.portNumber(1))); | ||
482 | - getEdgePointsNoArg.add(new ConnectPoint(DeviceId.deviceId("4"), PortNumber.portNumber(1))); | ||
483 | proxyArp.reply(arpRequest, getLocation(6)); | 661 | proxyArp.reply(arpRequest, getLocation(6)); |
484 | 662 | ||
485 | - verifyFlood(arpRequest); | 663 | + verifyFlood(arpRequest, configVlanCPoints); |
486 | } | 664 | } |
487 | 665 | ||
488 | /** | 666 | /** |
... | @@ -493,13 +671,12 @@ public class ProxyArpManagerTest { | ... | @@ -493,13 +671,12 @@ public class ProxyArpManagerTest { |
493 | */ | 671 | */ |
494 | @Test | 672 | @Test |
495 | public void testReplyDifferentVlanIpv6() { | 673 | public void testReplyDifferentVlanIpv6() { |
496 | - | 674 | + Host requestor = new DefaultHost(PID, HID4, MAC4, VLAN1, getLocation(NUM_DEVICES), |
497 | - Host replyer = new DefaultHost(PID, HID3, MAC3, VLAN2, getLocation(4), | ||
498 | - Collections.singleton(IP3)); | ||
499 | - | ||
500 | - Host requestor = new DefaultHost(PID, HID4, MAC4, VLAN1, getLocation(5), | ||
501 | Collections.singleton(IP4)); | 675 | Collections.singleton(IP4)); |
502 | 676 | ||
677 | + Host replyer = new DefaultHost(PID, HID3, MAC3, VLAN2, getLocation(NUM_DEVICES - 1), | ||
678 | + Collections.singleton(IP3)); | ||
679 | + | ||
503 | expect(hostService.getHostsByIp(IP3)) | 680 | expect(hostService.getHostsByIp(IP3)) |
504 | .andReturn(Collections.singleton(replyer)); | 681 | .andReturn(Collections.singleton(replyer)); |
505 | expect(interfaceService.getInterfacesByIp(IP4)) | 682 | expect(interfaceService.getInterfacesByIp(IP4)) |
... | @@ -513,13 +690,9 @@ public class ProxyArpManagerTest { | ... | @@ -513,13 +690,9 @@ public class ProxyArpManagerTest { |
513 | MAC4, SOLICITED_MAC3, | 690 | MAC4, SOLICITED_MAC3, |
514 | IP4, IP3); | 691 | IP4, IP3); |
515 | 692 | ||
516 | - //Setup for flood test | 693 | + proxyArp.reply(ndpRequest, getLocation(NUM_DEVICES)); |
517 | - getEdgePointsNoArg = Lists.newLinkedList(); | ||
518 | - getEdgePointsNoArg.add(new ConnectPoint(DeviceId.deviceId("5"), PortNumber.portNumber(1))); | ||
519 | - getEdgePointsNoArg.add(new ConnectPoint(DeviceId.deviceId("4"), PortNumber.portNumber(1))); | ||
520 | - proxyArp.reply(ndpRequest, getLocation(6)); | ||
521 | 694 | ||
522 | - verifyFlood(ndpRequest); | 695 | + verifyFlood(ndpRequest, noConfigCPoints); |
523 | } | 696 | } |
524 | 697 | ||
525 | /** | 698 | /** |
... | @@ -533,29 +706,29 @@ public class ProxyArpManagerTest { | ... | @@ -533,29 +706,29 @@ public class ProxyArpManagerTest { |
533 | MacAddress firstMac = MacAddress.valueOf(1L); | 706 | MacAddress firstMac = MacAddress.valueOf(1L); |
534 | MacAddress secondMac = MacAddress.valueOf(2L); | 707 | MacAddress secondMac = MacAddress.valueOf(2L); |
535 | 708 | ||
536 | - Host requestor = new DefaultHost(PID, HID2, MAC2, VLAN1, LOC1, | 709 | + Host requestor = new DefaultHost(PID, HID1, MAC1, VLAN1, LOC1, |
537 | Collections.singleton(theirIp)); | 710 | Collections.singleton(theirIp)); |
538 | 711 | ||
539 | - expect(hostService.getHost(HID2)).andReturn(requestor); | 712 | + expect(hostService.getHost(HID1)).andReturn(requestor); |
540 | replay(hostService); | 713 | replay(hostService); |
541 | replay(interfaceService); | 714 | replay(interfaceService); |
542 | 715 | ||
543 | - Ethernet arpRequest = buildArp(ARP.OP_REQUEST, MAC2, null, theirIp, ourFirstIp); | 716 | + Ethernet arpRequest = buildArp(ARP.OP_REQUEST, VLAN1, MAC1, null, theirIp, ourFirstIp); |
544 | - isEdgePointReturn = true; | 717 | + |
545 | proxyArp.reply(arpRequest, LOC1); | 718 | proxyArp.reply(arpRequest, LOC1); |
546 | 719 | ||
547 | assertEquals(1, packetService.packets.size()); | 720 | assertEquals(1, packetService.packets.size()); |
548 | - Ethernet arpReply = buildArp(ARP.OP_REPLY, firstMac, MAC2, ourFirstIp, theirIp); | 721 | + Ethernet arpReply = buildArp(ARP.OP_REPLY, VLAN1, firstMac, MAC1, ourFirstIp, theirIp); |
549 | verifyPacketOut(arpReply, LOC1, packetService.packets.get(0)); | 722 | verifyPacketOut(arpReply, LOC1, packetService.packets.get(0)); |
550 | 723 | ||
551 | // Test a request for the second address on that port | 724 | // Test a request for the second address on that port |
552 | packetService.packets.clear(); | 725 | packetService.packets.clear(); |
553 | - arpRequest = buildArp(ARP.OP_REQUEST, MAC2, null, theirIp, ourSecondIp); | 726 | + arpRequest = buildArp(ARP.OP_REQUEST, VLAN1, MAC1, null, theirIp, ourSecondIp); |
554 | 727 | ||
555 | proxyArp.reply(arpRequest, LOC1); | 728 | proxyArp.reply(arpRequest, LOC1); |
556 | 729 | ||
557 | assertEquals(1, packetService.packets.size()); | 730 | assertEquals(1, packetService.packets.size()); |
558 | - arpReply = buildArp(ARP.OP_REPLY, secondMac, MAC2, ourSecondIp, theirIp); | 731 | + arpReply = buildArp(ARP.OP_REPLY, VLAN1, secondMac, MAC1, ourSecondIp, theirIp); |
559 | verifyPacketOut(arpReply, LOC1, packetService.packets.get(0)); | 732 | verifyPacketOut(arpReply, LOC1, packetService.packets.get(0)); |
560 | } | 733 | } |
561 | 734 | ||
... | @@ -566,7 +739,7 @@ public class ProxyArpManagerTest { | ... | @@ -566,7 +739,7 @@ public class ProxyArpManagerTest { |
566 | public void testReplyToRequestForUsIpv6() { | 739 | public void testReplyToRequestForUsIpv6() { |
567 | Ip6Address theirIp = Ip6Address.valueOf("1000::ffff"); | 740 | Ip6Address theirIp = Ip6Address.valueOf("1000::ffff"); |
568 | Ip6Address ourFirstIp = Ip6Address.valueOf("1000::1"); | 741 | Ip6Address ourFirstIp = Ip6Address.valueOf("1000::1"); |
569 | - Ip6Address ourSecondIp = Ip6Address.valueOf("2000::1"); | 742 | + Ip6Address ourSecondIp = Ip6Address.valueOf("2000::2"); |
570 | MacAddress firstMac = MacAddress.valueOf(1L); | 743 | MacAddress firstMac = MacAddress.valueOf(1L); |
571 | MacAddress secondMac = MacAddress.valueOf(2L); | 744 | MacAddress secondMac = MacAddress.valueOf(2L); |
572 | 745 | ||
... | @@ -584,7 +757,7 @@ public class ProxyArpManagerTest { | ... | @@ -584,7 +757,7 @@ public class ProxyArpManagerTest { |
584 | MacAddress.valueOf("33:33:ff:00:00:01"), | 757 | MacAddress.valueOf("33:33:ff:00:00:01"), |
585 | theirIp, | 758 | theirIp, |
586 | ourFirstIp); | 759 | ourFirstIp); |
587 | - isEdgePointReturn = true; | 760 | + |
588 | proxyArp.reply(ndpRequest, LOC1); | 761 | proxyArp.reply(ndpRequest, LOC1); |
589 | assertEquals(1, packetService.packets.size()); | 762 | assertEquals(1, packetService.packets.size()); |
590 | 763 | ||
... | @@ -599,9 +772,9 @@ public class ProxyArpManagerTest { | ... | @@ -599,9 +772,9 @@ public class ProxyArpManagerTest { |
599 | packetService.packets.clear(); | 772 | packetService.packets.clear(); |
600 | ndpRequest = buildNDP(ICMP6.NEIGHBOR_SOLICITATION, | 773 | ndpRequest = buildNDP(ICMP6.NEIGHBOR_SOLICITATION, |
601 | MAC2, | 774 | MAC2, |
602 | - MacAddress.valueOf("33:33:ff:00:00:01"), | 775 | + MacAddress.valueOf("33:33:ff:00:00:01"), |
603 | - theirIp, | 776 | + theirIp, |
604 | - ourSecondIp); | 777 | + ourSecondIp); |
605 | proxyArp.reply(ndpRequest, LOC1); | 778 | proxyArp.reply(ndpRequest, LOC1); |
606 | assertEquals(1, packetService.packets.size()); | 779 | assertEquals(1, packetService.packets.size()); |
607 | 780 | ||
... | @@ -624,14 +797,14 @@ public class ProxyArpManagerTest { | ... | @@ -624,14 +797,14 @@ public class ProxyArpManagerTest { |
624 | Ip4Address theirIp = Ip4Address.valueOf("10.0.1.254"); | 797 | Ip4Address theirIp = Ip4Address.valueOf("10.0.1.254"); |
625 | 798 | ||
626 | // Request for a valid external IP address but coming in the wrong port | 799 | // Request for a valid external IP address but coming in the wrong port |
627 | - Ethernet arpRequest = buildArp(ARP.OP_REQUEST, MAC1, null, theirIp, | 800 | + Ethernet arpRequest = buildArp(ARP.OP_REQUEST, VLAN1, MAC1, null, theirIp, |
628 | Ip4Address.valueOf("10.0.3.1")); | 801 | Ip4Address.valueOf("10.0.3.1")); |
629 | proxyArp.reply(arpRequest, LOC1); | 802 | proxyArp.reply(arpRequest, LOC1); |
630 | assertEquals(0, packetService.packets.size()); | 803 | assertEquals(0, packetService.packets.size()); |
631 | 804 | ||
632 | // Request for a valid internal IP address but coming in an external port | 805 | // Request for a valid internal IP address but coming in an external port |
633 | packetService.packets.clear(); | 806 | packetService.packets.clear(); |
634 | - arpRequest = buildArp(ARP.OP_REQUEST, MAC1, null, theirIp, IP1); | 807 | + arpRequest = buildArp(ARP.OP_REQUEST, VLAN1, MAC1, null, theirIp, IP1); |
635 | proxyArp.reply(arpRequest, LOC1); | 808 | proxyArp.reply(arpRequest, LOC1); |
636 | assertEquals(0, packetService.packets.size()); | 809 | assertEquals(0, packetService.packets.size()); |
637 | } | 810 | } |
... | @@ -647,20 +820,20 @@ public class ProxyArpManagerTest { | ... | @@ -647,20 +820,20 @@ public class ProxyArpManagerTest { |
647 | Ip6Address theirIp = Ip6Address.valueOf("1000::ffff"); | 820 | Ip6Address theirIp = Ip6Address.valueOf("1000::ffff"); |
648 | 821 | ||
649 | Ethernet ndpRequest = buildNDP(ICMP6.NEIGHBOR_SOLICITATION, | 822 | Ethernet ndpRequest = buildNDP(ICMP6.NEIGHBOR_SOLICITATION, |
650 | - MAC1, | 823 | + MAC1, |
651 | - MacAddress.valueOf("33:33:ff:00:00:01"), | 824 | + MacAddress.valueOf("33:33:ff:00:00:01"), |
652 | - theirIp, | 825 | + theirIp, |
653 | - Ip6Address.valueOf("3000::1")); | 826 | + Ip6Address.valueOf("3000::1")); |
654 | proxyArp.reply(ndpRequest, LOC1); | 827 | proxyArp.reply(ndpRequest, LOC1); |
655 | assertEquals(0, packetService.packets.size()); | 828 | assertEquals(0, packetService.packets.size()); |
656 | 829 | ||
657 | // Request for a valid internal IP address but coming in an external port | 830 | // Request for a valid internal IP address but coming in an external port |
658 | packetService.packets.clear(); | 831 | packetService.packets.clear(); |
659 | ndpRequest = buildNDP(ICMP6.NEIGHBOR_SOLICITATION, | 832 | ndpRequest = buildNDP(ICMP6.NEIGHBOR_SOLICITATION, |
660 | - MAC1, | 833 | + MAC1, |
661 | - MacAddress.valueOf("33:33:ff:00:00:01"), | 834 | + MacAddress.valueOf("33:33:ff:00:00:01"), |
662 | - theirIp, | 835 | + theirIp, |
663 | - IP3); | 836 | + IP3); |
664 | proxyArp.reply(ndpRequest, LOC1); | 837 | proxyArp.reply(ndpRequest, LOC1); |
665 | assertEquals(0, packetService.packets.size()); | 838 | assertEquals(0, packetService.packets.size()); |
666 | } | 839 | } |
... | @@ -685,9 +858,8 @@ public class ProxyArpManagerTest { | ... | @@ -685,9 +858,8 @@ public class ProxyArpManagerTest { |
685 | 858 | ||
686 | // This is a request from something inside our network (like a BGP | 859 | // This is a request from something inside our network (like a BGP |
687 | // daemon) to an external host. | 860 | // daemon) to an external host. |
688 | - Ethernet arpRequest = buildArp(ARP.OP_REQUEST, ourMac, null, ourIp, theirIp); | 861 | + Ethernet arpRequest = buildArp(ARP.OP_REQUEST, VLAN1, ourMac, null, ourIp, theirIp); |
689 | //Ensure the packet is allowed through (it is not to an internal port) | 862 | //Ensure the packet is allowed through (it is not to an internal port) |
690 | - isEdgePointReturn = true; | ||
691 | 863 | ||
692 | proxyArp.reply(arpRequest, getLocation(5)); | 864 | proxyArp.reply(arpRequest, getLocation(5)); |
693 | assertEquals(1, packetService.packets.size()); | 865 | assertEquals(1, packetService.packets.size()); |
... | @@ -728,9 +900,6 @@ public class ProxyArpManagerTest { | ... | @@ -728,9 +900,6 @@ public class ProxyArpManagerTest { |
728 | ourIp, | 900 | ourIp, |
729 | theirIp); | 901 | theirIp); |
730 | 902 | ||
731 | - //Ensure the packet is allowed through (it is not to an internal port) | ||
732 | - isEdgePointReturn = true; | ||
733 | - | ||
734 | proxyArp.reply(ndpRequest, getLocation(5)); | 903 | proxyArp.reply(ndpRequest, getLocation(5)); |
735 | assertEquals(1, packetService.packets.size()); | 904 | assertEquals(1, packetService.packets.size()); |
736 | verifyPacketOut(ndpRequest, getLocation(1), packetService.packets.get(0)); | 905 | verifyPacketOut(ndpRequest, getLocation(1), packetService.packets.get(0)); |
... | @@ -758,7 +927,7 @@ public class ProxyArpManagerTest { | ... | @@ -758,7 +927,7 @@ public class ProxyArpManagerTest { |
758 | replay(hostService); | 927 | replay(hostService); |
759 | replay(interfaceService); | 928 | replay(interfaceService); |
760 | 929 | ||
761 | - Ethernet arpRequest = buildArp(ARP.OP_REPLY, MAC2, MAC1, IP2, IP1); | 930 | + Ethernet arpRequest = buildArp(ARP.OP_REPLY, VLAN1, MAC2, MAC1, IP2, IP1); |
762 | 931 | ||
763 | proxyArp.forward(arpRequest, LOC2); | 932 | proxyArp.forward(arpRequest, LOC2); |
764 | 933 | ||
... | @@ -804,22 +973,15 @@ public class ProxyArpManagerTest { | ... | @@ -804,22 +973,15 @@ public class ProxyArpManagerTest { |
804 | */ | 973 | */ |
805 | @Test | 974 | @Test |
806 | public void testForwardFlood() { | 975 | public void testForwardFlood() { |
807 | - expect(hostService.getHost(HID1)).andReturn(null); | 976 | + expect(hostService.getHost(HID2)).andReturn(null); |
808 | replay(hostService); | 977 | replay(hostService); |
809 | replay(interfaceService); | 978 | replay(interfaceService); |
810 | 979 | ||
811 | - Ethernet arpRequest = buildArp(ARP.OP_REPLY, MAC2, MAC1, IP2, IP1); | 980 | + Ethernet arpRequest = buildArp(ARP.OP_REPLY, VLAN1, MAC1, MAC2, IP1, IP2); |
812 | - | ||
813 | - //populate the list of edges when so that when forward hits flood in the manager it contains the values | ||
814 | - //that should continue on | ||
815 | - getEdgePointsNoArg = Lists.newLinkedList(); | ||
816 | - getEdgePointsNoArg.add(new ConnectPoint(DeviceId.deviceId("3"), PortNumber.portNumber(1))); | ||
817 | - getEdgePointsNoArg.add(new ConnectPoint(DeviceId.deviceId("5"), PortNumber.portNumber(1))); | ||
818 | - getEdgePointsNoArg.add(new ConnectPoint(DeviceId.deviceId("4"), PortNumber.portNumber(1))); | ||
819 | 981 | ||
820 | - proxyArp.forward(arpRequest, getLocation(6)); | 982 | + proxyArp.forward(arpRequest, getLocation(NUM_DEVICES)); |
821 | 983 | ||
822 | - verifyFlood(arpRequest); | 984 | + verifyFlood(arpRequest, noConfigCPoints); |
823 | } | 985 | } |
824 | 986 | ||
825 | /** | 987 | /** |
... | @@ -837,16 +999,9 @@ public class ProxyArpManagerTest { | ... | @@ -837,16 +999,9 @@ public class ProxyArpManagerTest { |
837 | MAC4, SOLICITED_MAC3, | 999 | MAC4, SOLICITED_MAC3, |
838 | IP4, IP3); | 1000 | IP4, IP3); |
839 | 1001 | ||
840 | - //populate the list of edges when so that when forward hits flood in the manager it contains the values | 1002 | + proxyArp.forward(ndpRequest, getLocation(NUM_DEVICES)); |
841 | - //that should continue on | ||
842 | - getEdgePointsNoArg = Lists.newLinkedList(); | ||
843 | - getEdgePointsNoArg.add(new ConnectPoint(DeviceId.deviceId("3"), PortNumber.portNumber(1))); | ||
844 | - getEdgePointsNoArg.add(new ConnectPoint(DeviceId.deviceId("5"), PortNumber.portNumber(1))); | ||
845 | - getEdgePointsNoArg.add(new ConnectPoint(DeviceId.deviceId("4"), PortNumber.portNumber(1))); | ||
846 | 1003 | ||
847 | - proxyArp.forward(ndpRequest, getLocation(6)); | 1004 | + verifyFlood(ndpRequest, noConfigCPoints); |
848 | - | ||
849 | - verifyFlood(ndpRequest); | ||
850 | } | 1005 | } |
851 | 1006 | ||
852 | /** | 1007 | /** |
... | @@ -854,21 +1009,20 @@ public class ProxyArpManagerTest { | ... | @@ -854,21 +1009,20 @@ public class ProxyArpManagerTest { |
854 | * except for the input port. | 1009 | * except for the input port. |
855 | * | 1010 | * |
856 | * @param packet the packet that was expected to be flooded | 1011 | * @param packet the packet that was expected to be flooded |
1012 | + * @param connectPoints the connectPoints where the outpacket should be | ||
1013 | + * observed | ||
857 | */ | 1014 | */ |
858 | - private void verifyFlood(Ethernet packet) { | 1015 | + private void verifyFlood(Ethernet packet, List<ConnectPoint> connectPoints) { |
1016 | + | ||
859 | // There should be 1 less than NUM_FLOOD_PORTS; the inPort should be excluded. | 1017 | // There should be 1 less than NUM_FLOOD_PORTS; the inPort should be excluded. |
860 | - assertEquals(NUM_FLOOD_PORTS - 1, packetService.packets.size()); | 1018 | + assertEquals(connectPoints.size() - 1, packetService.packets.size()); |
861 | 1019 | ||
862 | Collections.sort(packetService.packets, | 1020 | Collections.sort(packetService.packets, |
863 | (o1, o2) -> o1.sendThrough().uri().compareTo(o2.sendThrough().uri())); | 1021 | (o1, o2) -> o1.sendThrough().uri().compareTo(o2.sendThrough().uri())); |
864 | 1022 | ||
865 | - | 1023 | + for (int i = 0; i < connectPoints.size() - 1; i++) { |
866 | - for (int i = 0; i < NUM_FLOOD_PORTS - 1; i++) { | ||
867 | - ConnectPoint cp = new ConnectPoint(getDeviceId(NUM_ADDRESS_PORTS + i + 1), | ||
868 | - PortNumber.portNumber(1)); | ||
869 | - | ||
870 | OutboundPacket outboundPacket = packetService.packets.get(i); | 1024 | OutboundPacket outboundPacket = packetService.packets.get(i); |
871 | - verifyPacketOut(packet, cp, outboundPacket); | 1025 | + verifyPacketOut(packet, connectPoints.get(i), outboundPacket); |
872 | } | 1026 | } |
873 | } | 1027 | } |
874 | 1028 | ||
... | @@ -913,8 +1067,8 @@ public class ProxyArpManagerTest { | ... | @@ -913,8 +1067,8 @@ public class ProxyArpManagerTest { |
913 | * @param dstIp destination IP address | 1067 | * @param dstIp destination IP address |
914 | * @return the ARP packet | 1068 | * @return the ARP packet |
915 | */ | 1069 | */ |
916 | - private Ethernet buildArp(short opcode, MacAddress srcMac, MacAddress dstMac, | 1070 | + private Ethernet buildArp(short opcode, VlanId vlanId, MacAddress srcMac, |
917 | - Ip4Address srcIp, Ip4Address dstIp) { | 1071 | + MacAddress dstMac, Ip4Address srcIp, Ip4Address dstIp) { |
918 | Ethernet eth = new Ethernet(); | 1072 | Ethernet eth = new Ethernet(); |
919 | 1073 | ||
920 | if (dstMac == null) { | 1074 | if (dstMac == null) { |
... | @@ -925,7 +1079,7 @@ public class ProxyArpManagerTest { | ... | @@ -925,7 +1079,7 @@ public class ProxyArpManagerTest { |
925 | 1079 | ||
926 | eth.setSourceMACAddress(srcMac); | 1080 | eth.setSourceMACAddress(srcMac); |
927 | eth.setEtherType(Ethernet.TYPE_ARP); | 1081 | eth.setEtherType(Ethernet.TYPE_ARP); |
928 | - eth.setVlanID(VLAN1.toShort()); | 1082 | + eth.setVlanID(vlanId.toShort()); |
929 | 1083 | ||
930 | ARP arp = new ARP(); | 1084 | ARP arp = new ARP(); |
931 | arp.setOpCode(opcode); | 1085 | arp.setOpCode(opcode); |
... | @@ -937,7 +1091,7 @@ public class ProxyArpManagerTest { | ... | @@ -937,7 +1091,7 @@ public class ProxyArpManagerTest { |
937 | arp.setSenderHardwareAddress(srcMac.toBytes()); | 1091 | arp.setSenderHardwareAddress(srcMac.toBytes()); |
938 | 1092 | ||
939 | if (dstMac == null) { | 1093 | if (dstMac == null) { |
940 | - arp.setTargetHardwareAddress(ZERO_MAC_ADDRESS); | 1094 | + arp.setTargetHardwareAddress(zeroMacAddress); |
941 | } else { | 1095 | } else { |
942 | arp.setTargetHardwareAddress(dstMac.toBytes()); | 1096 | arp.setTargetHardwareAddress(dstMac.toBytes()); |
943 | } | 1097 | } |
... | @@ -1019,19 +1173,6 @@ public class ProxyArpManagerTest { | ... | @@ -1019,19 +1173,6 @@ public class ProxyArpManagerTest { |
1019 | 1173 | ||
1020 | } | 1174 | } |
1021 | 1175 | ||
1022 | - class TestEdgePortService extends EdgeManager { | ||
1023 | - | ||
1024 | - @Override | ||
1025 | - public boolean isEdgePoint(ConnectPoint connectPoint) { | ||
1026 | - return isEdgePointReturn; | ||
1027 | - } | ||
1028 | - | ||
1029 | - @Override | ||
1030 | - public Iterable<ConnectPoint> getEdgePoints() { | ||
1031 | - return getEdgePointsNoArg; | ||
1032 | - } | ||
1033 | - } | ||
1034 | - | ||
1035 | private class TestProxyArpStoreAdapter implements ProxyArpStore { | 1176 | private class TestProxyArpStoreAdapter implements ProxyArpStore { |
1036 | @Override | 1177 | @Override |
1037 | public void forward(ConnectPoint outPort, Host subject, ByteBuffer packet) { | 1178 | public void forward(ConnectPoint outPort, Host subject, ByteBuffer packet) { | ... | ... |
-
Please register or login to post a comment