Use a cleaner mechanism to test whether an IP address or prefix
is IPv4 or IPv6. Change-Id: Ia88f76be87a30573a50eeeedb78d98713ac1ae27
Showing
11 changed files
with
37 additions
and
24 deletions
... | @@ -51,6 +51,24 @@ public class RouteEntry { | ... | @@ -51,6 +51,24 @@ public class RouteEntry { |
51 | } | 51 | } |
52 | 52 | ||
53 | /** | 53 | /** |
54 | + * Tests whether the IP version of this address is IPv4. | ||
55 | + * | ||
56 | + * @return true if the IP version of this address is IPv4, otherwise false. | ||
57 | + */ | ||
58 | + public boolean isIp4() { | ||
59 | + return nextHop.isIp4(); | ||
60 | + } | ||
61 | + | ||
62 | + /** | ||
63 | + * Tests whether the IP version of this address is IPv6. | ||
64 | + * | ||
65 | + * @return true if the IP version of this address is IPv6, otherwise false. | ||
66 | + */ | ||
67 | + public boolean isIp6() { | ||
68 | + return nextHop.isIp6(); | ||
69 | + } | ||
70 | + | ||
71 | + /** | ||
54 | * Returns the IP prefix of the route. | 72 | * Returns the IP prefix of the route. |
55 | * | 73 | * |
56 | * @return the IP prefix of the route | 74 | * @return the IP prefix of the route | ... | ... |
... | @@ -175,7 +175,7 @@ public class BgpSession extends SimpleChannelHandler { | ... | @@ -175,7 +175,7 @@ public class BgpSession extends SimpleChannelHandler { |
175 | * @return the BGP routing entry if found, otherwise null | 175 | * @return the BGP routing entry if found, otherwise null |
176 | */ | 176 | */ |
177 | public BgpRouteEntry findBgpRoute(IpPrefix prefix) { | 177 | public BgpRouteEntry findBgpRoute(IpPrefix prefix) { |
178 | - if (prefix.version() == Ip4Address.VERSION) { | 178 | + if (prefix.isIp4()) { |
179 | // IPv4 prefix | 179 | // IPv4 prefix |
180 | Ip4Prefix ip4Prefix = prefix.getIp4Prefix(); | 180 | Ip4Prefix ip4Prefix = prefix.getIp4Prefix(); |
181 | return bgpRibIn4.get(ip4Prefix); | 181 | return bgpRibIn4.get(ip4Prefix); |
... | @@ -192,7 +192,7 @@ public class BgpSession extends SimpleChannelHandler { | ... | @@ -192,7 +192,7 @@ public class BgpSession extends SimpleChannelHandler { |
192 | * @param bgpRouteEntry the BGP route entry to use | 192 | * @param bgpRouteEntry the BGP route entry to use |
193 | */ | 193 | */ |
194 | void addBgpRoute(BgpRouteEntry bgpRouteEntry) { | 194 | void addBgpRoute(BgpRouteEntry bgpRouteEntry) { |
195 | - if (bgpRouteEntry.version() == Ip4Address.VERSION) { | 195 | + if (bgpRouteEntry.isIp4()) { |
196 | // IPv4 route | 196 | // IPv4 route |
197 | Ip4Prefix ip4Prefix = bgpRouteEntry.prefix().getIp4Prefix(); | 197 | Ip4Prefix ip4Prefix = bgpRouteEntry.prefix().getIp4Prefix(); |
198 | bgpRibIn4.put(ip4Prefix, bgpRouteEntry); | 198 | bgpRibIn4.put(ip4Prefix, bgpRouteEntry); |
... | @@ -230,7 +230,7 @@ public class BgpSession extends SimpleChannelHandler { | ... | @@ -230,7 +230,7 @@ public class BgpSession extends SimpleChannelHandler { |
230 | * @return true if the route was found and removed, otherwise false | 230 | * @return true if the route was found and removed, otherwise false |
231 | */ | 231 | */ |
232 | boolean removeBgpRoute(IpPrefix prefix) { | 232 | boolean removeBgpRoute(IpPrefix prefix) { |
233 | - if (prefix.version() == Ip4Address.VERSION) { | 233 | + if (prefix.isIp4()) { |
234 | return (bgpRibIn4.remove(prefix.getIp4Prefix()) != null); // IPv4 | 234 | return (bgpRibIn4.remove(prefix.getIp4Prefix()) != null); // IPv4 |
235 | } | 235 | } |
236 | return (bgpRibIn6.remove(prefix.getIp6Prefix()) != null); // IPv6 | 236 | return (bgpRibIn6.remove(prefix.getIp6Prefix()) != null); // IPv6 | ... | ... |
... | @@ -170,7 +170,7 @@ public class BgpSessionManager implements BgpInfoService, BgpService { | ... | @@ -170,7 +170,7 @@ public class BgpSessionManager implements BgpInfoService, BgpService { |
170 | * @return the BGP route if found, otherwise null | 170 | * @return the BGP route if found, otherwise null |
171 | */ | 171 | */ |
172 | BgpRouteEntry findBgpRoute(IpPrefix prefix) { | 172 | BgpRouteEntry findBgpRoute(IpPrefix prefix) { |
173 | - if (prefix.version() == Ip4Address.VERSION) { | 173 | + if (prefix.isIp4()) { |
174 | return bgpRoutes4.get(prefix.getIp4Prefix()); // IPv4 | 174 | return bgpRoutes4.get(prefix.getIp4Prefix()); // IPv4 |
175 | } | 175 | } |
176 | return bgpRoutes6.get(prefix.getIp6Prefix()); // IPv6 | 176 | return bgpRoutes6.get(prefix.getIp6Prefix()); // IPv6 |
... | @@ -182,7 +182,7 @@ public class BgpSessionManager implements BgpInfoService, BgpService { | ... | @@ -182,7 +182,7 @@ public class BgpSessionManager implements BgpInfoService, BgpService { |
182 | * @param bgpRouteEntry the BGP route entry to use | 182 | * @param bgpRouteEntry the BGP route entry to use |
183 | */ | 183 | */ |
184 | void addBgpRoute(BgpRouteEntry bgpRouteEntry) { | 184 | void addBgpRoute(BgpRouteEntry bgpRouteEntry) { |
185 | - if (bgpRouteEntry.version() == Ip4Address.VERSION) { | 185 | + if (bgpRouteEntry.isIp4()) { |
186 | bgpRoutes4.put(bgpRouteEntry.prefix().getIp4Prefix(), // IPv4 | 186 | bgpRoutes4.put(bgpRouteEntry.prefix().getIp4Prefix(), // IPv4 |
187 | bgpRouteEntry); | 187 | bgpRouteEntry); |
188 | } else { | 188 | } else { |
... | @@ -198,7 +198,7 @@ public class BgpSessionManager implements BgpInfoService, BgpService { | ... | @@ -198,7 +198,7 @@ public class BgpSessionManager implements BgpInfoService, BgpService { |
198 | * @return true if the route was found and removed, otherwise false | 198 | * @return true if the route was found and removed, otherwise false |
199 | */ | 199 | */ |
200 | boolean removeBgpRoute(IpPrefix prefix) { | 200 | boolean removeBgpRoute(IpPrefix prefix) { |
201 | - if (prefix.version() == Ip4Address.VERSION) { | 201 | + if (prefix.isIp4()) { |
202 | return (bgpRoutes4.remove(prefix.getIp4Prefix()) != null); // IPv4 | 202 | return (bgpRoutes4.remove(prefix.getIp4Prefix()) != null); // IPv4 |
203 | } | 203 | } |
204 | return (bgpRoutes6.remove(prefix.getIp6Prefix()) != null); // IPv6 | 204 | return (bgpRoutes6.remove(prefix.getIp6Prefix()) != null); // IPv6 | ... | ... |
... | @@ -29,7 +29,6 @@ import org.apache.felix.scr.annotations.Deactivate; | ... | @@ -29,7 +29,6 @@ import org.apache.felix.scr.annotations.Deactivate; |
29 | import org.apache.felix.scr.annotations.Reference; | 29 | import org.apache.felix.scr.annotations.Reference; |
30 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 30 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
31 | import org.apache.felix.scr.annotations.Service; | 31 | import org.apache.felix.scr.annotations.Service; |
32 | -import org.onlab.packet.Ip4Address; | ||
33 | import org.onlab.packet.IpAddress; | 32 | import org.onlab.packet.IpAddress; |
34 | import org.onlab.packet.IpPrefix; | 33 | import org.onlab.packet.IpPrefix; |
35 | import org.onlab.packet.MacAddress; | 34 | import org.onlab.packet.MacAddress; |
... | @@ -241,7 +240,7 @@ public class Router implements RoutingService { | ... | @@ -241,7 +240,7 @@ public class Router implements RoutingService { |
241 | */ | 240 | */ |
242 | RouteEntry findRibRoute(IpPrefix prefix) { | 241 | RouteEntry findRibRoute(IpPrefix prefix) { |
243 | String binaryString = RouteEntry.createBinaryString(prefix); | 242 | String binaryString = RouteEntry.createBinaryString(prefix); |
244 | - if (prefix.version() == Ip4Address.VERSION) { | 243 | + if (prefix.isIp4()) { |
245 | // IPv4 | 244 | // IPv4 |
246 | return ribTable4.getValueForExactKey(binaryString); | 245 | return ribTable4.getValueForExactKey(binaryString); |
247 | } | 246 | } |
... | @@ -255,7 +254,7 @@ public class Router implements RoutingService { | ... | @@ -255,7 +254,7 @@ public class Router implements RoutingService { |
255 | * @param routeEntry the route entry to use | 254 | * @param routeEntry the route entry to use |
256 | */ | 255 | */ |
257 | void addRibRoute(RouteEntry routeEntry) { | 256 | void addRibRoute(RouteEntry routeEntry) { |
258 | - if (routeEntry.prefix().version() == Ip4Address.VERSION) { | 257 | + if (routeEntry.isIp4()) { |
259 | // IPv4 | 258 | // IPv4 |
260 | ribTable4.put(RouteEntry.createBinaryString(routeEntry.prefix()), | 259 | ribTable4.put(RouteEntry.createBinaryString(routeEntry.prefix()), |
261 | routeEntry); | 260 | routeEntry); |
... | @@ -274,7 +273,7 @@ public class Router implements RoutingService { | ... | @@ -274,7 +273,7 @@ public class Router implements RoutingService { |
274 | * @return true if the route was found and removed, otherwise false | 273 | * @return true if the route was found and removed, otherwise false |
275 | */ | 274 | */ |
276 | boolean removeRibRoute(IpPrefix prefix) { | 275 | boolean removeRibRoute(IpPrefix prefix) { |
277 | - if (prefix.version() == Ip4Address.VERSION) { | 276 | + if (prefix.isIp4()) { |
278 | // IPv4 | 277 | // IPv4 |
279 | return ribTable4.remove(RouteEntry.createBinaryString(prefix)); | 278 | return ribTable4.remove(RouteEntry.createBinaryString(prefix)); |
280 | } | 279 | } | ... | ... |
... | @@ -17,7 +17,6 @@ package org.onosproject.sdnip; | ... | @@ -17,7 +17,6 @@ package org.onosproject.sdnip; |
17 | 17 | ||
18 | import com.google.common.util.concurrent.ThreadFactoryBuilder; | 18 | import com.google.common.util.concurrent.ThreadFactoryBuilder; |
19 | import org.onlab.packet.Ethernet; | 19 | import org.onlab.packet.Ethernet; |
20 | -import org.onlab.packet.Ip4Address; | ||
21 | import org.onlab.packet.IpAddress; | 20 | import org.onlab.packet.IpAddress; |
22 | import org.onlab.packet.IpPrefix; | 21 | import org.onlab.packet.IpPrefix; |
23 | import org.onlab.packet.MacAddress; | 22 | import org.onlab.packet.MacAddress; |
... | @@ -315,7 +314,7 @@ public class IntentSynchronizer implements FibListener { | ... | @@ -315,7 +314,7 @@ public class IntentSynchronizer implements FibListener { |
315 | 314 | ||
316 | // Match the destination IP prefix at the first hop | 315 | // Match the destination IP prefix at the first hop |
317 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); | 316 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
318 | - if (prefix.version() == Ip4Address.VERSION) { | 317 | + if (prefix.isIp4()) { |
319 | selector.matchEthType(Ethernet.TYPE_IPV4); | 318 | selector.matchEthType(Ethernet.TYPE_IPV4); |
320 | selector.matchIPDst(prefix); | 319 | selector.matchIPDst(prefix); |
321 | } else { | 320 | } else { | ... | ... |
... | @@ -18,7 +18,6 @@ package org.onosproject.sdnip; | ... | @@ -18,7 +18,6 @@ package org.onosproject.sdnip; |
18 | import org.onlab.packet.Ethernet; | 18 | import org.onlab.packet.Ethernet; |
19 | import org.onlab.packet.IPv4; | 19 | import org.onlab.packet.IPv4; |
20 | import org.onlab.packet.IPv6; | 20 | import org.onlab.packet.IPv6; |
21 | -import org.onlab.packet.Ip4Address; | ||
22 | import org.onlab.packet.IpAddress; | 21 | import org.onlab.packet.IpAddress; |
23 | import org.onlab.packet.IpPrefix; | 22 | import org.onlab.packet.IpPrefix; |
24 | import org.onosproject.core.ApplicationId; | 23 | import org.onosproject.core.ApplicationId; |
... | @@ -175,7 +174,7 @@ public class PeerConnectivityManager { | ... | @@ -175,7 +174,7 @@ public class PeerConnectivityManager { |
175 | byte tcpProtocol; | 174 | byte tcpProtocol; |
176 | byte icmpProtocol; | 175 | byte icmpProtocol; |
177 | 176 | ||
178 | - if (bgpdAddress.version() == Ip4Address.VERSION) { | 177 | + if (bgpdAddress.isIp4()) { |
179 | tcpProtocol = IPv4.PROTOCOL_TCP; | 178 | tcpProtocol = IPv4.PROTOCOL_TCP; |
180 | icmpProtocol = IPv4.PROTOCOL_ICMP; | 179 | icmpProtocol = IPv4.PROTOCOL_ICMP; |
181 | } else { | 180 | } else { |
... | @@ -261,7 +260,7 @@ public class PeerConnectivityManager { | ... | @@ -261,7 +260,7 @@ public class PeerConnectivityManager { |
261 | Short dstTcpPort) { | 260 | Short dstTcpPort) { |
262 | TrafficSelector.Builder builder = null; | 261 | TrafficSelector.Builder builder = null; |
263 | 262 | ||
264 | - if (dstIp.version() == Ip4Address.VERSION) { | 263 | + if (dstIp.isIp4()) { |
265 | builder = DefaultTrafficSelector.builder() | 264 | builder = DefaultTrafficSelector.builder() |
266 | .matchEthType(Ethernet.TYPE_IPV4) | 265 | .matchEthType(Ethernet.TYPE_IPV4) |
267 | .matchIPProtocol(ipProto) | 266 | .matchIPProtocol(ipProto) | ... | ... |
... | @@ -572,7 +572,7 @@ public class IntentSyncTest extends AbstractIntentTest { | ... | @@ -572,7 +572,7 @@ public class IntentSyncTest extends AbstractIntentTest { |
572 | 572 | ||
573 | TrafficSelector.Builder selectorBuilder = | 573 | TrafficSelector.Builder selectorBuilder = |
574 | DefaultTrafficSelector.builder(); | 574 | DefaultTrafficSelector.builder(); |
575 | - if (ipPrefix.version() == Ip4Address.VERSION) { | 575 | + if (ipPrefix.isIp4()) { |
576 | selectorBuilder.matchEthType(Ethernet.TYPE_IPV4); // IPv4 | 576 | selectorBuilder.matchEthType(Ethernet.TYPE_IPV4); // IPv4 |
577 | selectorBuilder.matchIPDst(ipPrefix); | 577 | selectorBuilder.matchIPDst(ipPrefix); |
578 | } else { | 578 | } else { | ... | ... |
... | @@ -21,7 +21,6 @@ import org.onlab.packet.ARP; | ... | @@ -21,7 +21,6 @@ import org.onlab.packet.ARP; |
21 | import org.onlab.packet.Ethernet; | 21 | import org.onlab.packet.Ethernet; |
22 | import org.onlab.packet.ICMP6; | 22 | import org.onlab.packet.ICMP6; |
23 | import org.onlab.packet.IpAddress; | 23 | import org.onlab.packet.IpAddress; |
24 | -import org.onlab.packet.Ip4Address; | ||
25 | import org.onlab.packet.IPv6; | 24 | import org.onlab.packet.IPv6; |
26 | import org.onlab.packet.MacAddress; | 25 | import org.onlab.packet.MacAddress; |
27 | import org.onlab.packet.VlanId; | 26 | import org.onlab.packet.VlanId; |
... | @@ -205,7 +204,7 @@ public class HostMonitor implements TimerTask { | ... | @@ -205,7 +204,7 @@ public class HostMonitor implements TimerTask { |
205 | VlanId vlan) { | 204 | VlanId vlan) { |
206 | Ethernet probePacket = null; | 205 | Ethernet probePacket = null; |
207 | 206 | ||
208 | - if (targetIp.version() == Ip4Address.VERSION) { | 207 | + if (targetIp.isIp4()) { |
209 | // IPv4: Use ARP | 208 | // IPv4: Use ARP |
210 | probePacket = buildArpRequest(targetIp, sourceIp, sourceMac, | 209 | probePacket = buildArpRequest(targetIp, sourceIp, sourceMac, |
211 | vlan); | 210 | vlan); | ... | ... |
... | @@ -24,7 +24,6 @@ import java.util.List; | ... | @@ -24,7 +24,6 @@ import java.util.List; |
24 | import java.util.concurrent.atomic.AtomicInteger; | 24 | import java.util.concurrent.atomic.AtomicInteger; |
25 | 25 | ||
26 | import org.jboss.netty.channel.Channel; | 26 | import org.jboss.netty.channel.Channel; |
27 | -import org.onlab.packet.Ip4Address; | ||
28 | import org.onlab.packet.IpAddress; | 27 | import org.onlab.packet.IpAddress; |
29 | import org.onosproject.openflow.controller.Dpid; | 28 | import org.onosproject.openflow.controller.Dpid; |
30 | import org.onosproject.openflow.controller.RoleState; | 29 | import org.onosproject.openflow.controller.RoleState; |
... | @@ -132,7 +131,7 @@ public abstract class AbstractOpenFlowSwitch implements OpenFlowSwitchDriver { | ... | @@ -132,7 +131,7 @@ public abstract class AbstractOpenFlowSwitch implements OpenFlowSwitchDriver { |
132 | if (address instanceof InetSocketAddress) { | 131 | if (address instanceof InetSocketAddress) { |
133 | final InetSocketAddress inetAddress = (InetSocketAddress) address; | 132 | final InetSocketAddress inetAddress = (InetSocketAddress) address; |
134 | final IpAddress ipAddress = IpAddress.valueOf(inetAddress.getAddress()); | 133 | final IpAddress ipAddress = IpAddress.valueOf(inetAddress.getAddress()); |
135 | - if (ipAddress.version() == Ip4Address.VERSION) { | 134 | + if (ipAddress.isIp4()) { |
136 | channelId = ipAddress.toString() + ':' + inetAddress.getPort(); | 135 | channelId = ipAddress.toString() + ':' + inetAddress.getPort(); |
137 | } else { | 136 | } else { |
138 | channelId = '[' + ipAddress.toString() + "]:" + inetAddress.getPort(); | 137 | channelId = '[' + ipAddress.toString() + "]:" + inetAddress.getPort(); | ... | ... |
... | @@ -104,7 +104,7 @@ public class IpAddress implements Comparable<IpAddress> { | ... | @@ -104,7 +104,7 @@ public class IpAddress implements Comparable<IpAddress> { |
104 | * otherwise null | 104 | * otherwise null |
105 | */ | 105 | */ |
106 | public Ip4Address getIp4Address() { | 106 | public Ip4Address getIp4Address() { |
107 | - if (version() != Ip4Address.VERSION) { | 107 | + if (!isIp4()) { |
108 | return null; | 108 | return null; |
109 | } | 109 | } |
110 | 110 | ||
... | @@ -122,7 +122,7 @@ public class IpAddress implements Comparable<IpAddress> { | ... | @@ -122,7 +122,7 @@ public class IpAddress implements Comparable<IpAddress> { |
122 | * otherwise null | 122 | * otherwise null |
123 | */ | 123 | */ |
124 | public Ip6Address getIp6Address() { | 124 | public Ip6Address getIp6Address() { |
125 | - if (version() != Ip6Address.VERSION) { | 125 | + if (!isIp6()) { |
126 | return null; | 126 | return null; |
127 | } | 127 | } |
128 | 128 | ... | ... |
... | @@ -99,7 +99,7 @@ public class IpPrefix { | ... | @@ -99,7 +99,7 @@ public class IpPrefix { |
99 | * otherwise null | 99 | * otherwise null |
100 | */ | 100 | */ |
101 | public Ip4Prefix getIp4Prefix() { | 101 | public Ip4Prefix getIp4Prefix() { |
102 | - if (version() != Ip4Prefix.VERSION) { | 102 | + if (!isIp4()) { |
103 | return null; | 103 | return null; |
104 | } | 104 | } |
105 | 105 | ||
... | @@ -117,7 +117,7 @@ public class IpPrefix { | ... | @@ -117,7 +117,7 @@ public class IpPrefix { |
117 | * otherwise null | 117 | * otherwise null |
118 | */ | 118 | */ |
119 | public Ip6Prefix getIp6Prefix() { | 119 | public Ip6Prefix getIp6Prefix() { |
120 | - if (version() != Ip6Prefix.VERSION) { | 120 | + if (!isIp6()) { |
121 | return null; | 121 | return null; |
122 | } | 122 | } |
123 | 123 | ... | ... |
-
Please register or login to post a comment