Added support for IPv6 addresses to class IpAddress:
- For some of the methods, the IP Version needs to be specified by the caller. This applies to the IpPrefix API as well. - For now, everywhere IpAddress is used and the IP version has to be explicitly specified by the caller, we assume/specify IPv4. - Added unit test for class IpAddress: for both IPv4 and IPv6 addresses.
Showing
13 changed files
with
54 additions
and
27 deletions
... | @@ -246,11 +246,13 @@ public class BgpSession extends SimpleChannelHandler { | ... | @@ -246,11 +246,13 @@ public class BgpSession extends SimpleChannelHandler { |
246 | InetAddress inetAddr; | 246 | InetAddress inetAddr; |
247 | if (localAddress instanceof InetSocketAddress) { | 247 | if (localAddress instanceof InetSocketAddress) { |
248 | inetAddr = ((InetSocketAddress) localAddress).getAddress(); | 248 | inetAddr = ((InetSocketAddress) localAddress).getAddress(); |
249 | - localIp4Address = IpAddress.valueOf(inetAddr.getAddress()); | 249 | + localIp4Address = IpAddress.valueOf(IpAddress.Version.INET, |
250 | + inetAddr.getAddress()); | ||
250 | } | 251 | } |
251 | if (remoteAddress instanceof InetSocketAddress) { | 252 | if (remoteAddress instanceof InetSocketAddress) { |
252 | inetAddr = ((InetSocketAddress) remoteAddress).getAddress(); | 253 | inetAddr = ((InetSocketAddress) remoteAddress).getAddress(); |
253 | - remoteIp4Address = IpAddress.valueOf(inetAddr.getAddress()); | 254 | + remoteIp4Address = IpAddress.valueOf(IpAddress.Version.INET, |
255 | + inetAddr.getAddress()); | ||
254 | } | 256 | } |
255 | 257 | ||
256 | log.debug("BGP Session Connected from {} on {}", | 258 | log.debug("BGP Session Connected from {} on {}", | ... | ... |
... | @@ -105,7 +105,8 @@ public class BgpSessionManager { | ... | @@ -105,7 +105,8 @@ public class BgpSessionManager { |
105 | if (bgpSession.getLocalAddress() instanceof InetSocketAddress) { | 105 | if (bgpSession.getLocalAddress() instanceof InetSocketAddress) { |
106 | InetAddress inetAddr = | 106 | InetAddress inetAddr = |
107 | ((InetSocketAddress) bgpSession.getLocalAddress()).getAddress(); | 107 | ((InetSocketAddress) bgpSession.getLocalAddress()).getAddress(); |
108 | - IpAddress ip4Address = IpAddress.valueOf(inetAddr.getAddress()); | 108 | + IpAddress ip4Address = IpAddress.valueOf(IpAddress.Version.INET, |
109 | + inetAddr.getAddress()); | ||
109 | updateMyBgpId(ip4Address); | 110 | updateMyBgpId(ip4Address); |
110 | } | 111 | } |
111 | return true; | 112 | return true; | ... | ... |
... | @@ -132,7 +132,8 @@ public class ProxyArpManager implements ProxyArpService { | ... | @@ -132,7 +132,8 @@ public class ProxyArpManager implements ProxyArpService { |
132 | // for one of our external addresses. | 132 | // for one of our external addresses. |
133 | if (isOutsidePort(inPort)) { | 133 | if (isOutsidePort(inPort)) { |
134 | IpAddress target = | 134 | IpAddress target = |
135 | - IpAddress.valueOf(arp.getTargetProtocolAddress()); | 135 | + IpAddress.valueOf(IpAddress.Version.INET, |
136 | + arp.getTargetProtocolAddress()); | ||
136 | PortAddresses addresses = | 137 | PortAddresses addresses = |
137 | hostService.getAddressBindingsForPort(inPort); | 138 | hostService.getAddressBindingsForPort(inPort); |
138 | 139 | ||
... | @@ -149,7 +150,8 @@ public class ProxyArpManager implements ProxyArpService { | ... | @@ -149,7 +150,8 @@ public class ProxyArpManager implements ProxyArpService { |
149 | // it could be a request from an internal host to an external | 150 | // it could be a request from an internal host to an external |
150 | // address. Forward it over to the correct port. | 151 | // address. Forward it over to the correct port. |
151 | IpAddress source = | 152 | IpAddress source = |
152 | - IpAddress.valueOf(arp.getSenderProtocolAddress()); | 153 | + IpAddress.valueOf(IpAddress.Version.INET, |
154 | + arp.getSenderProtocolAddress()); | ||
153 | PortAddresses sourceAddresses = findPortInSubnet(source); | 155 | PortAddresses sourceAddresses = findPortInSubnet(source); |
154 | if (sourceAddresses != null) { | 156 | if (sourceAddresses != null) { |
155 | for (InterfaceIpAddress ia : sourceAddresses.ipAddresses()) { | 157 | for (InterfaceIpAddress ia : sourceAddresses.ipAddresses()) { |
... | @@ -164,8 +166,9 @@ public class ProxyArpManager implements ProxyArpService { | ... | @@ -164,8 +166,9 @@ public class ProxyArpManager implements ProxyArpService { |
164 | // Continue with normal proxy ARP case | 166 | // Continue with normal proxy ARP case |
165 | 167 | ||
166 | VlanId vlan = VlanId.vlanId(eth.getVlanID()); | 168 | VlanId vlan = VlanId.vlanId(eth.getVlanID()); |
167 | - Set<Host> hosts = hostService.getHostsByIp(IpAddress.valueOf(arp | 169 | + Set<Host> hosts = |
168 | - .getTargetProtocolAddress())); | 170 | + hostService.getHostsByIp(IpAddress.valueOf(IpAddress.Version.INET, |
171 | + arp.getTargetProtocolAddress())); | ||
169 | 172 | ||
170 | Host dst = null; | 173 | Host dst = null; |
171 | Host src = hostService.getHost(HostId.hostId(eth.getSourceMAC(), | 174 | Host src = hostService.getHost(HostId.hostId(eth.getSourceMAC(), | ... | ... |
... | @@ -148,7 +148,8 @@ public class DistributedClusterStore | ... | @@ -148,7 +148,8 @@ public class DistributedClusterStore |
148 | 148 | ||
149 | private IpAddress memberAddress(Member member) { | 149 | private IpAddress memberAddress(Member member) { |
150 | byte[] address = member.getSocketAddress().getAddress().getAddress(); | 150 | byte[] address = member.getSocketAddress().getAddress().getAddress(); |
151 | - return IpAddress.valueOf(address); | 151 | + // TODO: Add support for IPv6 |
152 | + return IpAddress.valueOf(IpAddress.Version.INET, address); | ||
152 | } | 153 | } |
153 | 154 | ||
154 | // Interceptor for membership events. | 155 | // Interceptor for membership events. | ... | ... |
... | @@ -46,7 +46,8 @@ public class IpAddressSerializer extends Serializer<IpAddress> { | ... | @@ -46,7 +46,8 @@ public class IpAddressSerializer extends Serializer<IpAddress> { |
46 | final int octLen = input.readInt(); | 46 | final int octLen = input.readInt(); |
47 | byte[] octs = new byte[octLen]; | 47 | byte[] octs = new byte[octLen]; |
48 | input.readBytes(octs); | 48 | input.readBytes(octs); |
49 | - return IpAddress.valueOf(octs); | 49 | + // TODO: Add support for reading/writing the IP version |
50 | + return IpAddress.valueOf(IpAddress.Version.INET, octs); | ||
50 | } | 51 | } |
51 | 52 | ||
52 | } | 53 | } | ... | ... |
... | @@ -15,6 +15,7 @@ | ... | @@ -15,6 +15,7 @@ |
15 | */ | 15 | */ |
16 | package org.onlab.onos.store.serializers; | 16 | package org.onlab.onos.store.serializers; |
17 | 17 | ||
18 | +import org.onlab.packet.IpAddress; | ||
18 | import org.onlab.packet.IpPrefix; | 19 | import org.onlab.packet.IpPrefix; |
19 | 20 | ||
20 | import com.esotericsoftware.kryo.Kryo; | 21 | import com.esotericsoftware.kryo.Kryo; |
... | @@ -51,6 +52,7 @@ public final class IpPrefixSerializer extends Serializer<IpPrefix> { | ... | @@ -51,6 +52,7 @@ public final class IpPrefixSerializer extends Serializer<IpPrefix> { |
51 | byte[] octs = new byte[octLen]; | 52 | byte[] octs = new byte[octLen]; |
52 | input.readBytes(octs); | 53 | input.readBytes(octs); |
53 | int prefLen = input.readInt(); | 54 | int prefLen = input.readInt(); |
54 | - return IpPrefix.valueOf(octs, prefLen); | 55 | + // TODO: Add support for reading/writing the IP version |
56 | + return IpPrefix.valueOf(IpAddress.Version.INET, octs, prefLen); | ||
55 | } | 57 | } |
56 | } | 58 | } | ... | ... |
... | @@ -120,7 +120,8 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid | ... | @@ -120,7 +120,8 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid |
120 | if (eth.getEtherType() == Ethernet.TYPE_ARP) { | 120 | if (eth.getEtherType() == Ethernet.TYPE_ARP) { |
121 | ARP arp = (ARP) eth.getPayload(); | 121 | ARP arp = (ARP) eth.getPayload(); |
122 | IpAddress ip = | 122 | IpAddress ip = |
123 | - IpAddress.valueOf(arp.getSenderProtocolAddress()); | 123 | + IpAddress.valueOf(IpAddress.Version.INET, |
124 | + arp.getSenderProtocolAddress()); | ||
124 | HostDescription hdescr = | 125 | HostDescription hdescr = |
125 | new DefaultHostDescription(eth.getSourceMAC(), vlan, hloc, ip); | 126 | new DefaultHostDescription(eth.getSourceMAC(), vlan, hloc, ip); |
126 | providerService.hostDetected(hid, hdescr); | 127 | providerService.hostDetected(hid, hdescr); | ... | ... |
... | @@ -145,7 +145,8 @@ public abstract class FlowModBuilder { | ... | @@ -145,7 +145,8 @@ public abstract class FlowModBuilder { |
145 | ip = (IPCriterion) c; | 145 | ip = (IPCriterion) c; |
146 | if (ip.ip().prefixLength() != IpPrefix.MAX_INET_MASK_LENGTH) { | 146 | if (ip.ip().prefixLength() != IpPrefix.MAX_INET_MASK_LENGTH) { |
147 | IpAddress maskAddr = | 147 | IpAddress maskAddr = |
148 | - IpAddress.makeMaskPrefix(ip.ip().prefixLength()); | 148 | + IpAddress.makeMaskPrefix(ip.ip().address().version(), |
149 | + ip.ip().prefixLength()); | ||
149 | Masked<IPv4Address> maskedIp = | 150 | Masked<IPv4Address> maskedIp = |
150 | Masked.of(IPv4Address.of(ip.ip().address().toInt()), | 151 | Masked.of(IPv4Address.of(ip.ip().address().toInt()), |
151 | IPv4Address.of(maskAddr.toInt())); | 152 | IPv4Address.of(maskAddr.toInt())); |
... | @@ -159,7 +160,8 @@ public abstract class FlowModBuilder { | ... | @@ -159,7 +160,8 @@ public abstract class FlowModBuilder { |
159 | ip = (IPCriterion) c; | 160 | ip = (IPCriterion) c; |
160 | if (ip.ip().prefixLength() != IpPrefix.MAX_INET_MASK_LENGTH) { | 161 | if (ip.ip().prefixLength() != IpPrefix.MAX_INET_MASK_LENGTH) { |
161 | IpAddress maskAddr = | 162 | IpAddress maskAddr = |
162 | - IpAddress.makeMaskPrefix(ip.ip().prefixLength()); | 163 | + IpAddress.makeMaskPrefix(ip.ip().address().version(), |
164 | + ip.ip().prefixLength()); | ||
163 | Masked<IPv4Address> maskedIp = | 165 | Masked<IPv4Address> maskedIp = |
164 | Masked.of(IPv4Address.of(ip.ip().address().toInt()), | 166 | Masked.of(IPv4Address.of(ip.ip().address().toInt()), |
165 | IPv4Address.of(maskAddr.toInt())); | 167 | IPv4Address.of(maskAddr.toInt())); | ... | ... |
providers/openflow/host/src/main/java/org/onlab/onos/provider/of/host/impl/OpenFlowHostProvider.java
... | @@ -126,7 +126,8 @@ public class OpenFlowHostProvider extends AbstractProvider implements HostProvid | ... | @@ -126,7 +126,8 @@ public class OpenFlowHostProvider extends AbstractProvider implements HostProvid |
126 | if (eth.getEtherType() == Ethernet.TYPE_ARP) { | 126 | if (eth.getEtherType() == Ethernet.TYPE_ARP) { |
127 | ARP arp = (ARP) eth.getPayload(); | 127 | ARP arp = (ARP) eth.getPayload(); |
128 | IpAddress ip = | 128 | IpAddress ip = |
129 | - IpAddress.valueOf(arp.getSenderProtocolAddress()); | 129 | + IpAddress.valueOf(IpAddress.Version.INET, |
130 | + arp.getSenderProtocolAddress()); | ||
130 | HostDescription hdescr = | 131 | HostDescription hdescr = |
131 | new DefaultHostDescription(eth.getSourceMAC(), vlan, hloc, ip); | 132 | new DefaultHostDescription(eth.getSourceMAC(), vlan, hloc, ip); |
132 | providerService.hostDetected(hid, hdescr); | 133 | providerService.hostDetected(hid, hdescr); | ... | ... |
This diff is collapsed. Click to expand it.
... | @@ -76,12 +76,15 @@ public final class IpPrefix { | ... | @@ -76,12 +76,15 @@ public final class IpPrefix { |
76 | /** | 76 | /** |
77 | * Converts a byte array and a prefix length into an IP prefix. | 77 | * Converts a byte array and a prefix length into an IP prefix. |
78 | * | 78 | * |
79 | + * @param version the IP address version | ||
79 | * @param address the IP address value stored in network byte order | 80 | * @param address the IP address value stored in network byte order |
80 | * @param prefixLength the prefix length | 81 | * @param prefixLength the prefix length |
81 | * @return an IP prefix | 82 | * @return an IP prefix |
82 | */ | 83 | */ |
83 | - public static IpPrefix valueOf(byte[] address, int prefixLength) { | 84 | + public static IpPrefix valueOf(IpAddress.Version version, byte[] address, |
84 | - return new IpPrefix(IpAddress.valueOf(address), prefixLength); | 85 | + int prefixLength) { |
86 | + return new IpPrefix(IpAddress.valueOf(version, address), | ||
87 | + prefixLength); | ||
85 | } | 88 | } |
86 | 89 | ||
87 | /** | 90 | /** | ... | ... |
This diff is collapsed. Click to expand it.
... | @@ -38,9 +38,11 @@ public class IpPrefixTest { | ... | @@ -38,9 +38,11 @@ public class IpPrefixTest { |
38 | 38 | ||
39 | @Test | 39 | @Test |
40 | public void testEquality() { | 40 | public void testEquality() { |
41 | - IpPrefix ip1 = IpPrefix.valueOf(BYTES1, IpPrefix.MAX_INET_MASK_LENGTH); | 41 | + IpPrefix ip1 = IpPrefix.valueOf(IpAddress.Version.INET, |
42 | + BYTES1, IpPrefix.MAX_INET_MASK_LENGTH); | ||
42 | IpPrefix ip2 = IpPrefix.valueOf(INTVAL1, IpPrefix.MAX_INET_MASK_LENGTH); | 43 | IpPrefix ip2 = IpPrefix.valueOf(INTVAL1, IpPrefix.MAX_INET_MASK_LENGTH); |
43 | - IpPrefix ip3 = IpPrefix.valueOf(BYTES2, IpPrefix.MAX_INET_MASK_LENGTH); | 44 | + IpPrefix ip3 = IpPrefix.valueOf(IpAddress.Version.INET, |
45 | + BYTES2, IpPrefix.MAX_INET_MASK_LENGTH); | ||
44 | IpPrefix ip4 = IpPrefix.valueOf(INTVAL2, IpPrefix.MAX_INET_MASK_LENGTH); | 46 | IpPrefix ip4 = IpPrefix.valueOf(INTVAL2, IpPrefix.MAX_INET_MASK_LENGTH); |
45 | IpPrefix ip5 = IpPrefix.valueOf(STRVAL); | 47 | IpPrefix ip5 = IpPrefix.valueOf(STRVAL); |
46 | 48 | ||
... | @@ -50,16 +52,19 @@ public class IpPrefixTest { | ... | @@ -50,16 +52,19 @@ public class IpPrefixTest { |
50 | .testEquals(); | 52 | .testEquals(); |
51 | 53 | ||
52 | // string conversions | 54 | // string conversions |
53 | - IpPrefix ip6 = IpPrefix.valueOf(BYTES1, MASK_LENGTH); | 55 | + IpPrefix ip6 = IpPrefix.valueOf(IpAddress.Version.INET, |
56 | + BYTES1, MASK_LENGTH); | ||
54 | IpPrefix ip7 = IpPrefix.valueOf("10.0.0.10/16"); | 57 | IpPrefix ip7 = IpPrefix.valueOf("10.0.0.10/16"); |
55 | - IpPrefix ip8 = IpPrefix.valueOf(new byte [] {0xa, 0x0, 0x0, 0xc}, 16); | 58 | + IpPrefix ip8 = IpPrefix.valueOf(IpAddress.Version.INET, |
59 | + new byte [] {0xa, 0x0, 0x0, 0xc}, 16); | ||
56 | assertEquals("incorrect address conversion", ip6, ip7); | 60 | assertEquals("incorrect address conversion", ip6, ip7); |
57 | assertEquals("incorrect address conversion", ip5, ip8); | 61 | assertEquals("incorrect address conversion", ip5, ip8); |
58 | } | 62 | } |
59 | 63 | ||
60 | @Test | 64 | @Test |
61 | public void basics() { | 65 | public void basics() { |
62 | - IpPrefix ip1 = IpPrefix.valueOf(BYTES1, MASK_LENGTH); | 66 | + IpPrefix ip1 = IpPrefix.valueOf(IpAddress.Version.INET, |
67 | + BYTES1, MASK_LENGTH); | ||
63 | final byte [] bytes = new byte [] {0xa, 0x0, 0x0, 0x0}; | 68 | final byte [] bytes = new byte [] {0xa, 0x0, 0x0, 0x0}; |
64 | 69 | ||
65 | // check fields | 70 | // check fields |
... | @@ -74,7 +79,8 @@ public class IpPrefixTest { | ... | @@ -74,7 +79,8 @@ public class IpPrefixTest { |
74 | @Test | 79 | @Test |
75 | public void netmasks() { | 80 | public void netmasks() { |
76 | // masked | 81 | // masked |
77 | - IpPrefix ip1 = IpPrefix.valueOf(BYTES1, MASK_LENGTH); | 82 | + IpPrefix ip1 = IpPrefix.valueOf(IpAddress.Version.INET, |
83 | + BYTES1, MASK_LENGTH); | ||
78 | IpPrefix ip2 = IpPrefix.valueOf("10.0.0.10/16"); | 84 | IpPrefix ip2 = IpPrefix.valueOf("10.0.0.10/16"); |
79 | IpPrefix ip3 = IpPrefix.valueOf("10.0.0.0/16"); | 85 | IpPrefix ip3 = IpPrefix.valueOf("10.0.0.0/16"); |
80 | assertEquals("incorrect binary masked address", | 86 | assertEquals("incorrect binary masked address", |
... | @@ -87,9 +93,12 @@ public class IpPrefixTest { | ... | @@ -87,9 +93,12 @@ public class IpPrefixTest { |
87 | 93 | ||
88 | @Test | 94 | @Test |
89 | public void testContainsIpPrefix() { | 95 | public void testContainsIpPrefix() { |
90 | - IpPrefix slash31 = IpPrefix.valueOf(BYTES1, 31); | 96 | + IpPrefix slash31 = IpPrefix.valueOf(IpAddress.Version.INET, |
91 | - IpPrefix slash32 = IpPrefix.valueOf(BYTES1, 32); | 97 | + BYTES1, 31); |
92 | - IpPrefix differentSlash32 = IpPrefix.valueOf(BYTES2, 32); | 98 | + IpPrefix slash32 = IpPrefix.valueOf(IpAddress.Version.INET, |
99 | + BYTES1, 32); | ||
100 | + IpPrefix differentSlash32 = IpPrefix.valueOf(IpAddress.Version.INET, | ||
101 | + BYTES2, 32); | ||
93 | 102 | ||
94 | assertTrue(slash31.contains(differentSlash32)); | 103 | assertTrue(slash31.contains(differentSlash32)); |
95 | assertFalse(differentSlash32.contains(slash31)); | 104 | assertFalse(differentSlash32.contains(slash31)); |
... | @@ -109,8 +118,9 @@ public class IpPrefixTest { | ... | @@ -109,8 +118,9 @@ public class IpPrefixTest { |
109 | 118 | ||
110 | @Test | 119 | @Test |
111 | public void testContainsIpAddress() { | 120 | public void testContainsIpAddress() { |
112 | - IpPrefix slash31 = IpPrefix.valueOf(BYTES1, 31); | 121 | + IpPrefix slash31 = IpPrefix.valueOf(IpAddress.Version.INET, |
113 | - IpAddress addr32 = IpAddress.valueOf(BYTES1); | 122 | + BYTES1, 31); |
123 | + IpAddress addr32 = IpAddress.valueOf(IpAddress.Version.INET, BYTES1); | ||
114 | 124 | ||
115 | assertTrue(slash31.contains(addr32)); | 125 | assertTrue(slash31.contains(addr32)); |
116 | 126 | ... | ... |
-
Please register or login to post a comment