Use a cleaner mechanism to test whether an IP address or prefix
is IPv4 or IPv6.
Change-Id: Ia88f76be87a30573a50eeeedb78d98713ac1ae27
diff --git a/apps/routing-api/src/main/java/org/onosproject/routing/RouteEntry.java b/apps/routing-api/src/main/java/org/onosproject/routing/RouteEntry.java
index 358f707..a7a4512 100644
--- a/apps/routing-api/src/main/java/org/onosproject/routing/RouteEntry.java
+++ b/apps/routing-api/src/main/java/org/onosproject/routing/RouteEntry.java
@@ -51,6 +51,24 @@
}
/**
+ * Tests whether the IP version of this address is IPv4.
+ *
+ * @return true if the IP version of this address is IPv4, otherwise false.
+ */
+ public boolean isIp4() {
+ return nextHop.isIp4();
+ }
+
+ /**
+ * Tests whether the IP version of this address is IPv6.
+ *
+ * @return true if the IP version of this address is IPv6, otherwise false.
+ */
+ public boolean isIp6() {
+ return nextHop.isIp6();
+ }
+
+ /**
* Returns the IP prefix of the route.
*
* @return the IP prefix of the route
diff --git a/apps/routing/src/main/java/org/onosproject/routing/bgp/BgpSession.java b/apps/routing/src/main/java/org/onosproject/routing/bgp/BgpSession.java
index e0a2617..c890576 100644
--- a/apps/routing/src/main/java/org/onosproject/routing/bgp/BgpSession.java
+++ b/apps/routing/src/main/java/org/onosproject/routing/bgp/BgpSession.java
@@ -175,7 +175,7 @@
* @return the BGP routing entry if found, otherwise null
*/
public BgpRouteEntry findBgpRoute(IpPrefix prefix) {
- if (prefix.version() == Ip4Address.VERSION) {
+ if (prefix.isIp4()) {
// IPv4 prefix
Ip4Prefix ip4Prefix = prefix.getIp4Prefix();
return bgpRibIn4.get(ip4Prefix);
@@ -192,7 +192,7 @@
* @param bgpRouteEntry the BGP route entry to use
*/
void addBgpRoute(BgpRouteEntry bgpRouteEntry) {
- if (bgpRouteEntry.version() == Ip4Address.VERSION) {
+ if (bgpRouteEntry.isIp4()) {
// IPv4 route
Ip4Prefix ip4Prefix = bgpRouteEntry.prefix().getIp4Prefix();
bgpRibIn4.put(ip4Prefix, bgpRouteEntry);
@@ -230,7 +230,7 @@
* @return true if the route was found and removed, otherwise false
*/
boolean removeBgpRoute(IpPrefix prefix) {
- if (prefix.version() == Ip4Address.VERSION) {
+ if (prefix.isIp4()) {
return (bgpRibIn4.remove(prefix.getIp4Prefix()) != null); // IPv4
}
return (bgpRibIn6.remove(prefix.getIp6Prefix()) != null); // IPv6
diff --git a/apps/routing/src/main/java/org/onosproject/routing/bgp/BgpSessionManager.java b/apps/routing/src/main/java/org/onosproject/routing/bgp/BgpSessionManager.java
index 45b5d8b..1f38846 100644
--- a/apps/routing/src/main/java/org/onosproject/routing/bgp/BgpSessionManager.java
+++ b/apps/routing/src/main/java/org/onosproject/routing/bgp/BgpSessionManager.java
@@ -170,7 +170,7 @@
* @return the BGP route if found, otherwise null
*/
BgpRouteEntry findBgpRoute(IpPrefix prefix) {
- if (prefix.version() == Ip4Address.VERSION) {
+ if (prefix.isIp4()) {
return bgpRoutes4.get(prefix.getIp4Prefix()); // IPv4
}
return bgpRoutes6.get(prefix.getIp6Prefix()); // IPv6
@@ -182,7 +182,7 @@
* @param bgpRouteEntry the BGP route entry to use
*/
void addBgpRoute(BgpRouteEntry bgpRouteEntry) {
- if (bgpRouteEntry.version() == Ip4Address.VERSION) {
+ if (bgpRouteEntry.isIp4()) {
bgpRoutes4.put(bgpRouteEntry.prefix().getIp4Prefix(), // IPv4
bgpRouteEntry);
} else {
@@ -198,7 +198,7 @@
* @return true if the route was found and removed, otherwise false
*/
boolean removeBgpRoute(IpPrefix prefix) {
- if (prefix.version() == Ip4Address.VERSION) {
+ if (prefix.isIp4()) {
return (bgpRoutes4.remove(prefix.getIp4Prefix()) != null); // IPv4
}
return (bgpRoutes6.remove(prefix.getIp6Prefix()) != null); // IPv6
diff --git a/apps/routing/src/main/java/org/onosproject/routing/impl/Router.java b/apps/routing/src/main/java/org/onosproject/routing/impl/Router.java
index ddbc5ee..fcab78e 100644
--- a/apps/routing/src/main/java/org/onosproject/routing/impl/Router.java
+++ b/apps/routing/src/main/java/org/onosproject/routing/impl/Router.java
@@ -29,7 +29,6 @@
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
-import org.onlab.packet.Ip4Address;
import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
@@ -241,7 +240,7 @@
*/
RouteEntry findRibRoute(IpPrefix prefix) {
String binaryString = RouteEntry.createBinaryString(prefix);
- if (prefix.version() == Ip4Address.VERSION) {
+ if (prefix.isIp4()) {
// IPv4
return ribTable4.getValueForExactKey(binaryString);
}
@@ -255,7 +254,7 @@
* @param routeEntry the route entry to use
*/
void addRibRoute(RouteEntry routeEntry) {
- if (routeEntry.prefix().version() == Ip4Address.VERSION) {
+ if (routeEntry.isIp4()) {
// IPv4
ribTable4.put(RouteEntry.createBinaryString(routeEntry.prefix()),
routeEntry);
@@ -274,7 +273,7 @@
* @return true if the route was found and removed, otherwise false
*/
boolean removeRibRoute(IpPrefix prefix) {
- if (prefix.version() == Ip4Address.VERSION) {
+ if (prefix.isIp4()) {
// IPv4
return ribTable4.remove(RouteEntry.createBinaryString(prefix));
}
diff --git a/apps/sdnip/src/main/java/org/onosproject/sdnip/IntentSynchronizer.java b/apps/sdnip/src/main/java/org/onosproject/sdnip/IntentSynchronizer.java
index c10df94..cc65ccc 100644
--- a/apps/sdnip/src/main/java/org/onosproject/sdnip/IntentSynchronizer.java
+++ b/apps/sdnip/src/main/java/org/onosproject/sdnip/IntentSynchronizer.java
@@ -17,7 +17,6 @@
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import org.onlab.packet.Ethernet;
-import org.onlab.packet.Ip4Address;
import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
@@ -315,7 +314,7 @@
// Match the destination IP prefix at the first hop
TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
- if (prefix.version() == Ip4Address.VERSION) {
+ if (prefix.isIp4()) {
selector.matchEthType(Ethernet.TYPE_IPV4);
selector.matchIPDst(prefix);
} else {
diff --git a/apps/sdnip/src/main/java/org/onosproject/sdnip/PeerConnectivityManager.java b/apps/sdnip/src/main/java/org/onosproject/sdnip/PeerConnectivityManager.java
index caca1cf..fd99c6a 100644
--- a/apps/sdnip/src/main/java/org/onosproject/sdnip/PeerConnectivityManager.java
+++ b/apps/sdnip/src/main/java/org/onosproject/sdnip/PeerConnectivityManager.java
@@ -18,7 +18,6 @@
import org.onlab.packet.Ethernet;
import org.onlab.packet.IPv4;
import org.onlab.packet.IPv6;
-import org.onlab.packet.Ip4Address;
import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
import org.onosproject.core.ApplicationId;
@@ -175,7 +174,7 @@
byte tcpProtocol;
byte icmpProtocol;
- if (bgpdAddress.version() == Ip4Address.VERSION) {
+ if (bgpdAddress.isIp4()) {
tcpProtocol = IPv4.PROTOCOL_TCP;
icmpProtocol = IPv4.PROTOCOL_ICMP;
} else {
@@ -261,7 +260,7 @@
Short dstTcpPort) {
TrafficSelector.Builder builder = null;
- if (dstIp.version() == Ip4Address.VERSION) {
+ if (dstIp.isIp4()) {
builder = DefaultTrafficSelector.builder()
.matchEthType(Ethernet.TYPE_IPV4)
.matchIPProtocol(ipProto)
diff --git a/apps/sdnip/src/test/java/org/onosproject/sdnip/IntentSyncTest.java b/apps/sdnip/src/test/java/org/onosproject/sdnip/IntentSyncTest.java
index c613007..9f29c1b 100644
--- a/apps/sdnip/src/test/java/org/onosproject/sdnip/IntentSyncTest.java
+++ b/apps/sdnip/src/test/java/org/onosproject/sdnip/IntentSyncTest.java
@@ -572,7 +572,7 @@
TrafficSelector.Builder selectorBuilder =
DefaultTrafficSelector.builder();
- if (ipPrefix.version() == Ip4Address.VERSION) {
+ if (ipPrefix.isIp4()) {
selectorBuilder.matchEthType(Ethernet.TYPE_IPV4); // IPv4
selectorBuilder.matchIPDst(ipPrefix);
} else {