Pavlin Radoslavov

Use a cleaner mechanism to test whether an IP address or prefix

is IPv4 or IPv6.

Change-Id: Ia88f76be87a30573a50eeeedb78d98713ac1ae27
......@@ -51,6 +51,24 @@ public class RouteEntry {
}
/**
* 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
......
......@@ -175,7 +175,7 @@ public class BgpSession extends SimpleChannelHandler {
* @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 @@ public class BgpSession extends SimpleChannelHandler {
* @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 @@ public class BgpSession extends SimpleChannelHandler {
* @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
......
......@@ -170,7 +170,7 @@ public class BgpSessionManager implements BgpInfoService, BgpService {
* @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 @@ public class BgpSessionManager implements BgpInfoService, BgpService {
* @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 @@ public class BgpSessionManager implements BgpInfoService, BgpService {
* @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
......
......@@ -29,7 +29,6 @@ import org.apache.felix.scr.annotations.Deactivate;
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 @@ public class Router implements RoutingService {
*/
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 @@ public class Router implements RoutingService {
* @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 @@ public class Router implements RoutingService {
* @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));
}
......
......@@ -17,7 +17,6 @@ package org.onosproject.sdnip;
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 @@ public class IntentSynchronizer implements FibListener {
// 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 {
......
......@@ -18,7 +18,6 @@ package org.onosproject.sdnip;
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 @@ public class PeerConnectivityManager {
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 @@ public class PeerConnectivityManager {
Short dstTcpPort) {
TrafficSelector.Builder builder = null;
if (dstIp.version() == Ip4Address.VERSION) {
if (dstIp.isIp4()) {
builder = DefaultTrafficSelector.builder()
.matchEthType(Ethernet.TYPE_IPV4)
.matchIPProtocol(ipProto)
......
......@@ -572,7 +572,7 @@ public class IntentSyncTest extends AbstractIntentTest {
TrafficSelector.Builder selectorBuilder =
DefaultTrafficSelector.builder();
if (ipPrefix.version() == Ip4Address.VERSION) {
if (ipPrefix.isIp4()) {
selectorBuilder.matchEthType(Ethernet.TYPE_IPV4); // IPv4
selectorBuilder.matchIPDst(ipPrefix);
} else {
......
......@@ -21,7 +21,6 @@ import org.onlab.packet.ARP;
import org.onlab.packet.Ethernet;
import org.onlab.packet.ICMP6;
import org.onlab.packet.IpAddress;
import org.onlab.packet.Ip4Address;
import org.onlab.packet.IPv6;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
......@@ -205,7 +204,7 @@ public class HostMonitor implements TimerTask {
VlanId vlan) {
Ethernet probePacket = null;
if (targetIp.version() == Ip4Address.VERSION) {
if (targetIp.isIp4()) {
// IPv4: Use ARP
probePacket = buildArpRequest(targetIp, sourceIp, sourceMac,
vlan);
......
......@@ -24,7 +24,6 @@ import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import org.jboss.netty.channel.Channel;
import org.onlab.packet.Ip4Address;
import org.onlab.packet.IpAddress;
import org.onosproject.openflow.controller.Dpid;
import org.onosproject.openflow.controller.RoleState;
......@@ -132,7 +131,7 @@ public abstract class AbstractOpenFlowSwitch implements OpenFlowSwitchDriver {
if (address instanceof InetSocketAddress) {
final InetSocketAddress inetAddress = (InetSocketAddress) address;
final IpAddress ipAddress = IpAddress.valueOf(inetAddress.getAddress());
if (ipAddress.version() == Ip4Address.VERSION) {
if (ipAddress.isIp4()) {
channelId = ipAddress.toString() + ':' + inetAddress.getPort();
} else {
channelId = '[' + ipAddress.toString() + "]:" + inetAddress.getPort();
......
......@@ -104,7 +104,7 @@ public class IpAddress implements Comparable<IpAddress> {
* otherwise null
*/
public Ip4Address getIp4Address() {
if (version() != Ip4Address.VERSION) {
if (!isIp4()) {
return null;
}
......@@ -122,7 +122,7 @@ public class IpAddress implements Comparable<IpAddress> {
* otherwise null
*/
public Ip6Address getIp6Address() {
if (version() != Ip6Address.VERSION) {
if (!isIp6()) {
return null;
}
......
......@@ -99,7 +99,7 @@ public class IpPrefix {
* otherwise null
*/
public Ip4Prefix getIp4Prefix() {
if (version() != Ip4Prefix.VERSION) {
if (!isIp4()) {
return null;
}
......@@ -117,7 +117,7 @@ public class IpPrefix {
* otherwise null
*/
public Ip6Prefix getIp6Prefix() {
if (version() != Ip6Prefix.VERSION) {
if (!isIp6()) {
return null;
}
......