Updated the ProxyArpManager to use Ip4Address instead of
the more generic IpAddress. The ProxyArpManager is defined and works only for IPv4, hence we should use the concrete IPv4 addresses. Change-Id: Ie43ca17ce03ea86d2efb6b33f55a5dcafb2ab985
Showing
3 changed files
with
48 additions
and
40 deletions
... | @@ -18,7 +18,7 @@ package org.onlab.onos.net.proxyarp; | ... | @@ -18,7 +18,7 @@ package org.onlab.onos.net.proxyarp; |
18 | import org.onlab.onos.net.ConnectPoint; | 18 | import org.onlab.onos.net.ConnectPoint; |
19 | import org.onlab.onos.net.packet.PacketContext; | 19 | import org.onlab.onos.net.packet.PacketContext; |
20 | import org.onlab.packet.Ethernet; | 20 | import org.onlab.packet.Ethernet; |
21 | -import org.onlab.packet.IpAddress; | 21 | +import org.onlab.packet.Ip4Address; |
22 | 22 | ||
23 | /** | 23 | /** |
24 | * Service for processing arp requests on behalf of applications. | 24 | * Service for processing arp requests on behalf of applications. |
... | @@ -27,12 +27,12 @@ import org.onlab.packet.IpAddress; | ... | @@ -27,12 +27,12 @@ import org.onlab.packet.IpAddress; |
27 | public interface ProxyArpService { | 27 | public interface ProxyArpService { |
28 | 28 | ||
29 | /** | 29 | /** |
30 | - * Returns whether this particular ip address is known to the system. | 30 | + * Returns whether this particular IPv4 address is known to the system. |
31 | * | 31 | * |
32 | - * @param addr a ip address | 32 | + * @param addr an IPv4 address |
33 | * @return true if know, false otherwise | 33 | * @return true if know, false otherwise |
34 | */ | 34 | */ |
35 | - boolean known(IpAddress addr); | 35 | + boolean known(Ip4Address addr); |
36 | 36 | ||
37 | /** | 37 | /** |
38 | * Sends a reply for a given request. If the host is not known then the arp | 38 | * Sends a reply for a given request. If the host is not known then the arp | ... | ... |
... | @@ -56,6 +56,7 @@ import org.onlab.onos.net.proxyarp.ProxyArpService; | ... | @@ -56,6 +56,7 @@ import org.onlab.onos.net.proxyarp.ProxyArpService; |
56 | import org.onlab.packet.ARP; | 56 | import org.onlab.packet.ARP; |
57 | import org.onlab.packet.Ethernet; | 57 | import org.onlab.packet.Ethernet; |
58 | import org.onlab.packet.IpAddress; | 58 | import org.onlab.packet.IpAddress; |
59 | +import org.onlab.packet.Ip4Address; | ||
59 | import org.onlab.packet.MacAddress; | 60 | import org.onlab.packet.MacAddress; |
60 | import org.onlab.packet.VlanId; | 61 | import org.onlab.packet.VlanId; |
61 | import org.slf4j.Logger; | 62 | import org.slf4j.Logger; |
... | @@ -113,7 +114,7 @@ public class ProxyArpManager implements ProxyArpService { | ... | @@ -113,7 +114,7 @@ public class ProxyArpManager implements ProxyArpService { |
113 | } | 114 | } |
114 | 115 | ||
115 | @Override | 116 | @Override |
116 | - public boolean known(IpAddress addr) { | 117 | + public boolean known(Ip4Address addr) { |
117 | checkNotNull(addr, MAC_ADDR_NULL); | 118 | checkNotNull(addr, MAC_ADDR_NULL); |
118 | Set<Host> hosts = hostService.getHostsByIp(addr); | 119 | Set<Host> hosts = hostService.getHostsByIp(addr); |
119 | return !hosts.isEmpty(); | 120 | return !hosts.isEmpty(); |
... | @@ -131,9 +132,8 @@ public class ProxyArpManager implements ProxyArpService { | ... | @@ -131,9 +132,8 @@ public class ProxyArpManager implements ProxyArpService { |
131 | // If the request came from outside the network, only reply if it was | 132 | // If the request came from outside the network, only reply if it was |
132 | // for one of our external addresses. | 133 | // for one of our external addresses. |
133 | if (isOutsidePort(inPort)) { | 134 | if (isOutsidePort(inPort)) { |
134 | - IpAddress target = | 135 | + Ip4Address target = |
135 | - IpAddress.valueOf(IpAddress.Version.INET, | 136 | + Ip4Address.valueOf(arp.getTargetProtocolAddress()); |
136 | - arp.getTargetProtocolAddress()); | ||
137 | Set<PortAddresses> addressSet = | 137 | Set<PortAddresses> addressSet = |
138 | hostService.getAddressBindingsForPort(inPort); | 138 | hostService.getAddressBindingsForPort(inPort); |
139 | 139 | ||
... | @@ -141,7 +141,7 @@ public class ProxyArpManager implements ProxyArpService { | ... | @@ -141,7 +141,7 @@ public class ProxyArpManager implements ProxyArpService { |
141 | for (InterfaceIpAddress ia : addresses.ipAddresses()) { | 141 | for (InterfaceIpAddress ia : addresses.ipAddresses()) { |
142 | if (ia.ipAddress().equals(target)) { | 142 | if (ia.ipAddress().equals(target)) { |
143 | Ethernet arpReply = | 143 | Ethernet arpReply = |
144 | - buildArpReply(ia.ipAddress(), addresses.mac(), eth); | 144 | + buildArpReply(target, addresses.mac(), eth); |
145 | sendTo(arpReply, inPort); | 145 | sendTo(arpReply, inPort); |
146 | } | 146 | } |
147 | } | 147 | } |
... | @@ -151,9 +151,8 @@ public class ProxyArpManager implements ProxyArpService { | ... | @@ -151,9 +151,8 @@ public class ProxyArpManager implements ProxyArpService { |
151 | // If the source address matches one of our external addresses | 151 | // If the source address matches one of our external addresses |
152 | // it could be a request from an internal host to an external | 152 | // it could be a request from an internal host to an external |
153 | // address. Forward it over to the correct port. | 153 | // address. Forward it over to the correct port. |
154 | - IpAddress source = | 154 | + Ip4Address source = |
155 | - IpAddress.valueOf(IpAddress.Version.INET, | 155 | + Ip4Address.valueOf(arp.getSenderProtocolAddress()); |
156 | - arp.getSenderProtocolAddress()); | ||
157 | PortAddresses sourceAddresses = findPortInSubnet(source); | 156 | PortAddresses sourceAddresses = findPortInSubnet(source); |
158 | if (sourceAddresses != null) { | 157 | if (sourceAddresses != null) { |
159 | for (InterfaceIpAddress ia : sourceAddresses.ipAddresses()) { | 158 | for (InterfaceIpAddress ia : sourceAddresses.ipAddresses()) { |
... | @@ -168,9 +167,8 @@ public class ProxyArpManager implements ProxyArpService { | ... | @@ -168,9 +167,8 @@ public class ProxyArpManager implements ProxyArpService { |
168 | // Continue with normal proxy ARP case | 167 | // Continue with normal proxy ARP case |
169 | 168 | ||
170 | VlanId vlan = VlanId.vlanId(eth.getVlanID()); | 169 | VlanId vlan = VlanId.vlanId(eth.getVlanID()); |
171 | - Set<Host> hosts = | 170 | + Set<Host> hosts = hostService.getHostsByIp( |
172 | - hostService.getHostsByIp(IpAddress.valueOf(IpAddress.Version.INET, | 171 | + Ip4Address.valueOf(arp.getTargetProtocolAddress())); |
173 | - arp.getTargetProtocolAddress())); | ||
174 | 172 | ||
175 | Host dst = null; | 173 | Host dst = null; |
176 | Host src = hostService.getHost(HostId.hostId(eth.getSourceMAC(), | 174 | Host src = hostService.getHost(HostId.hostId(eth.getSourceMAC(), |
... | @@ -188,11 +186,19 @@ public class ProxyArpManager implements ProxyArpService { | ... | @@ -188,11 +186,19 @@ public class ProxyArpManager implements ProxyArpService { |
188 | return; | 186 | return; |
189 | } | 187 | } |
190 | 188 | ||
191 | - // TODO find the correct IP address | 189 | + // |
192 | - IpAddress ipAddress = dst.ipAddresses().iterator().next(); | 190 | + // TODO find the correct IP address. |
193 | - Ethernet arpReply = buildArpReply(ipAddress, dst.mac(), eth); | 191 | + // Right now we use the first IPv4 address that is found. |
192 | + // | ||
193 | + for (IpAddress ipAddress : dst.ipAddresses()) { | ||
194 | + Ip4Address ip4Address = ipAddress.getIp4Address(); | ||
195 | + if (ip4Address != null) { | ||
196 | + Ethernet arpReply = buildArpReply(ip4Address, dst.mac(), eth); | ||
194 | // TODO: check send status with host service. | 197 | // TODO: check send status with host service. |
195 | sendTo(arpReply, src.location()); | 198 | sendTo(arpReply, src.location()); |
199 | + break; | ||
200 | + } | ||
201 | + } | ||
196 | } | 202 | } |
197 | 203 | ||
198 | /** | 204 | /** |
... | @@ -223,7 +229,7 @@ public class ProxyArpManager implements ProxyArpService { | ... | @@ -223,7 +229,7 @@ public class ProxyArpManager implements ProxyArpService { |
223 | * @param target the target address to find a matching port for | 229 | * @param target the target address to find a matching port for |
224 | * @return a PortAddresses object if one was found, otherwise null | 230 | * @return a PortAddresses object if one was found, otherwise null |
225 | */ | 231 | */ |
226 | - private PortAddresses findPortInSubnet(IpAddress target) { | 232 | + private PortAddresses findPortInSubnet(Ip4Address target) { |
227 | for (PortAddresses addresses : hostService.getAddressBindings()) { | 233 | for (PortAddresses addresses : hostService.getAddressBindings()) { |
228 | for (InterfaceIpAddress ia : addresses.ipAddresses()) { | 234 | for (InterfaceIpAddress ia : addresses.ipAddresses()) { |
229 | if (ia.subnetAddress().contains(target)) { | 235 | if (ia.subnetAddress().contains(target)) { |
... | @@ -358,7 +364,7 @@ public class ProxyArpManager implements ProxyArpService { | ... | @@ -358,7 +364,7 @@ public class ProxyArpManager implements ProxyArpService { |
358 | * @param request the ARP request we got | 364 | * @param request the ARP request we got |
359 | * @return an Ethernet frame containing the ARP reply | 365 | * @return an Ethernet frame containing the ARP reply |
360 | */ | 366 | */ |
361 | - private Ethernet buildArpReply(IpAddress srcIp, MacAddress srcMac, | 367 | + private Ethernet buildArpReply(Ip4Address srcIp, MacAddress srcMac, |
362 | Ethernet request) { | 368 | Ethernet request) { |
363 | 369 | ||
364 | Ethernet eth = new Ethernet(); | 370 | Ethernet eth = new Ethernet(); |
... | @@ -372,7 +378,7 @@ public class ProxyArpManager implements ProxyArpService { | ... | @@ -372,7 +378,7 @@ public class ProxyArpManager implements ProxyArpService { |
372 | arp.setProtocolType(ARP.PROTO_TYPE_IP); | 378 | arp.setProtocolType(ARP.PROTO_TYPE_IP); |
373 | arp.setHardwareType(ARP.HW_TYPE_ETHERNET); | 379 | arp.setHardwareType(ARP.HW_TYPE_ETHERNET); |
374 | 380 | ||
375 | - arp.setProtocolAddressLength((byte) IpAddress.INET_BYTE_LENGTH); | 381 | + arp.setProtocolAddressLength((byte) Ip4Address.BYTE_LENGTH); |
376 | arp.setHardwareAddressLength((byte) Ethernet.DATALAYER_ADDRESS_LENGTH); | 382 | arp.setHardwareAddressLength((byte) Ethernet.DATALAYER_ADDRESS_LENGTH); |
377 | arp.setSenderHardwareAddress(srcMac.toBytes()); | 383 | arp.setSenderHardwareAddress(srcMac.toBytes()); |
378 | arp.setTargetHardwareAddress(request.getSourceMACAddress()); | 384 | arp.setTargetHardwareAddress(request.getSourceMACAddress()); | ... | ... |
... | @@ -57,8 +57,8 @@ import org.onlab.onos.net.packet.PacketService; | ... | @@ -57,8 +57,8 @@ import org.onlab.onos.net.packet.PacketService; |
57 | import org.onlab.onos.net.provider.ProviderId; | 57 | import org.onlab.onos.net.provider.ProviderId; |
58 | import org.onlab.packet.ARP; | 58 | import org.onlab.packet.ARP; |
59 | import org.onlab.packet.Ethernet; | 59 | import org.onlab.packet.Ethernet; |
60 | -import org.onlab.packet.IpAddress; | 60 | +import org.onlab.packet.Ip4Address; |
61 | -import org.onlab.packet.IpPrefix; | 61 | +import org.onlab.packet.Ip4Prefix; |
62 | import org.onlab.packet.MacAddress; | 62 | import org.onlab.packet.MacAddress; |
63 | import org.onlab.packet.VlanId; | 63 | import org.onlab.packet.VlanId; |
64 | 64 | ||
... | @@ -74,8 +74,8 @@ public class ProxyArpManagerTest { | ... | @@ -74,8 +74,8 @@ public class ProxyArpManagerTest { |
74 | private static final int NUM_ADDRESS_PORTS = NUM_DEVICES / 2; | 74 | private static final int NUM_ADDRESS_PORTS = NUM_DEVICES / 2; |
75 | private static final int NUM_FLOOD_PORTS = 3; | 75 | private static final int NUM_FLOOD_PORTS = 3; |
76 | 76 | ||
77 | - private static final IpAddress IP1 = IpAddress.valueOf("192.168.1.1"); | 77 | + private static final Ip4Address IP1 = Ip4Address.valueOf("192.168.1.1"); |
78 | - private static final IpAddress IP2 = IpAddress.valueOf("192.168.1.2"); | 78 | + private static final Ip4Address IP2 = Ip4Address.valueOf("192.168.1.2"); |
79 | 79 | ||
80 | private static final ProviderId PID = new ProviderId("of", "foo"); | 80 | private static final ProviderId PID = new ProviderId("of", "foo"); |
81 | 81 | ||
... | @@ -204,10 +204,12 @@ public class ProxyArpManagerTest { | ... | @@ -204,10 +204,12 @@ public class ProxyArpManagerTest { |
204 | 204 | ||
205 | for (int i = 1; i <= NUM_ADDRESS_PORTS; i++) { | 205 | for (int i = 1; i <= NUM_ADDRESS_PORTS; i++) { |
206 | ConnectPoint cp = new ConnectPoint(getDeviceId(i), P1); | 206 | ConnectPoint cp = new ConnectPoint(getDeviceId(i), P1); |
207 | - IpPrefix prefix1 = IpPrefix.valueOf("10.0." + (2 * i - 1) + ".0/24"); | 207 | + Ip4Prefix prefix1 = |
208 | - IpAddress addr1 = IpAddress.valueOf("10.0." + (2 * i - 1) + ".1"); | 208 | + Ip4Prefix.valueOf("10.0." + (2 * i - 1) + ".0/24"); |
209 | - IpPrefix prefix2 = IpPrefix.valueOf("10.0." + (2 * i) + ".0/24"); | 209 | + Ip4Address addr1 = |
210 | - IpAddress addr2 = IpAddress.valueOf("10.0." + (2 * i) + ".1"); | 210 | + Ip4Address.valueOf("10.0." + (2 * i - 1) + ".1"); |
211 | + Ip4Prefix prefix2 = Ip4Prefix.valueOf("10.0." + (2 * i) + ".0/24"); | ||
212 | + Ip4Address addr2 = Ip4Address.valueOf("10.0." + (2 * i) + ".1"); | ||
211 | InterfaceIpAddress ia1 = new InterfaceIpAddress(addr1, prefix1); | 213 | InterfaceIpAddress ia1 = new InterfaceIpAddress(addr1, prefix1); |
212 | InterfaceIpAddress ia2 = new InterfaceIpAddress(addr2, prefix2); | 214 | InterfaceIpAddress ia2 = new InterfaceIpAddress(addr2, prefix2); |
213 | PortAddresses pa1 = | 215 | PortAddresses pa1 = |
... | @@ -235,7 +237,7 @@ public class ProxyArpManagerTest { | ... | @@ -235,7 +237,7 @@ public class ProxyArpManagerTest { |
235 | } | 237 | } |
236 | 238 | ||
237 | /** | 239 | /** |
238 | - * Tests {@link ProxyArpManager#known(IpAddress)} in the case where the | 240 | + * Tests {@link ProxyArpManager#known(Ip4Address)} in the case where the |
239 | * IP address is not known. | 241 | * IP address is not known. |
240 | * Verifies the method returns false. | 242 | * Verifies the method returns false. |
241 | */ | 243 | */ |
... | @@ -248,7 +250,7 @@ public class ProxyArpManagerTest { | ... | @@ -248,7 +250,7 @@ public class ProxyArpManagerTest { |
248 | } | 250 | } |
249 | 251 | ||
250 | /** | 252 | /** |
251 | - * Tests {@link ProxyArpManager#known(IpAddress)} in the case where the | 253 | + * Tests {@link ProxyArpManager#known(Ip4Address)} in the case where the |
252 | * IP address is known. | 254 | * IP address is known. |
253 | * Verifies the method returns true. | 255 | * Verifies the method returns true. |
254 | */ | 256 | */ |
... | @@ -344,9 +346,9 @@ public class ProxyArpManagerTest { | ... | @@ -344,9 +346,9 @@ public class ProxyArpManagerTest { |
344 | 346 | ||
345 | @Test | 347 | @Test |
346 | public void testReplyToRequestForUs() { | 348 | public void testReplyToRequestForUs() { |
347 | - IpAddress theirIp = IpAddress.valueOf("10.0.1.254"); | 349 | + Ip4Address theirIp = Ip4Address.valueOf("10.0.1.254"); |
348 | - IpAddress ourFirstIp = IpAddress.valueOf("10.0.1.1"); | 350 | + Ip4Address ourFirstIp = Ip4Address.valueOf("10.0.1.1"); |
349 | - IpAddress ourSecondIp = IpAddress.valueOf("10.0.2.1"); | 351 | + Ip4Address ourSecondIp = Ip4Address.valueOf("10.0.2.1"); |
350 | MacAddress firstMac = MacAddress.valueOf(1L); | 352 | MacAddress firstMac = MacAddress.valueOf(1L); |
351 | MacAddress secondMac = MacAddress.valueOf(2L); | 353 | MacAddress secondMac = MacAddress.valueOf(2L); |
352 | 354 | ||
... | @@ -379,11 +381,11 @@ public class ProxyArpManagerTest { | ... | @@ -379,11 +381,11 @@ public class ProxyArpManagerTest { |
379 | public void testReplyExternalPortBadRequest() { | 381 | public void testReplyExternalPortBadRequest() { |
380 | replay(hostService); // no further host service expectations | 382 | replay(hostService); // no further host service expectations |
381 | 383 | ||
382 | - IpAddress theirIp = IpAddress.valueOf("10.0.1.254"); | 384 | + Ip4Address theirIp = Ip4Address.valueOf("10.0.1.254"); |
383 | 385 | ||
384 | // Request for a valid external IP address but coming in the wrong port | 386 | // Request for a valid external IP address but coming in the wrong port |
385 | Ethernet arpRequest = buildArp(ARP.OP_REQUEST, MAC1, null, theirIp, | 387 | Ethernet arpRequest = buildArp(ARP.OP_REQUEST, MAC1, null, theirIp, |
386 | - IpAddress.valueOf("10.0.3.1")); | 388 | + Ip4Address.valueOf("10.0.3.1")); |
387 | proxyArp.reply(arpRequest, LOC1); | 389 | proxyArp.reply(arpRequest, LOC1); |
388 | assertEquals(0, packetService.packets.size()); | 390 | assertEquals(0, packetService.packets.size()); |
389 | 391 | ||
... | @@ -398,9 +400,9 @@ public class ProxyArpManagerTest { | ... | @@ -398,9 +400,9 @@ public class ProxyArpManagerTest { |
398 | public void testReplyToRequestFromUs() { | 400 | public void testReplyToRequestFromUs() { |
399 | replay(hostService); // no further host service expectations | 401 | replay(hostService); // no further host service expectations |
400 | 402 | ||
401 | - IpAddress ourIp = IpAddress.valueOf("10.0.1.1"); | 403 | + Ip4Address ourIp = Ip4Address.valueOf("10.0.1.1"); |
402 | MacAddress ourMac = MacAddress.valueOf(1L); | 404 | MacAddress ourMac = MacAddress.valueOf(1L); |
403 | - IpAddress theirIp = IpAddress.valueOf("10.0.1.100"); | 405 | + Ip4Address theirIp = Ip4Address.valueOf("10.0.1.100"); |
404 | 406 | ||
405 | // This is a request from something inside our network (like a BGP | 407 | // This is a request from something inside our network (like a BGP |
406 | // daemon) to an external host. | 408 | // daemon) to an external host. |
... | @@ -523,7 +525,7 @@ public class ProxyArpManagerTest { | ... | @@ -523,7 +525,7 @@ public class ProxyArpManagerTest { |
523 | * @return the ARP packet | 525 | * @return the ARP packet |
524 | */ | 526 | */ |
525 | private Ethernet buildArp(short opcode, MacAddress srcMac, MacAddress dstMac, | 527 | private Ethernet buildArp(short opcode, MacAddress srcMac, MacAddress dstMac, |
526 | - IpAddress srcIp, IpAddress dstIp) { | 528 | + Ip4Address srcIp, Ip4Address dstIp) { |
527 | Ethernet eth = new Ethernet(); | 529 | Ethernet eth = new Ethernet(); |
528 | 530 | ||
529 | if (dstMac == null) { | 531 | if (dstMac == null) { |
... | @@ -541,7 +543,7 @@ public class ProxyArpManagerTest { | ... | @@ -541,7 +543,7 @@ public class ProxyArpManagerTest { |
541 | arp.setProtocolType(ARP.PROTO_TYPE_IP); | 543 | arp.setProtocolType(ARP.PROTO_TYPE_IP); |
542 | arp.setHardwareType(ARP.HW_TYPE_ETHERNET); | 544 | arp.setHardwareType(ARP.HW_TYPE_ETHERNET); |
543 | 545 | ||
544 | - arp.setProtocolAddressLength((byte) IpAddress.INET_BYTE_LENGTH); | 546 | + arp.setProtocolAddressLength((byte) Ip4Address.BYTE_LENGTH); |
545 | arp.setHardwareAddressLength((byte) Ethernet.DATALAYER_ADDRESS_LENGTH); | 547 | arp.setHardwareAddressLength((byte) Ethernet.DATALAYER_ADDRESS_LENGTH); |
546 | arp.setSenderHardwareAddress(srcMac.toBytes()); | 548 | arp.setSenderHardwareAddress(srcMac.toBytes()); |
547 | 549 | ... | ... |
-
Please register or login to post a comment