Use a cleaner mechanism to test whether an IP address or prefix
is IPv4 or IPv6.
Change-Id: Ia88f76be87a30573a50eeeedb78d98713ac1ae27
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));
}