X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fsal%2Fapi%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Futils%2FNetUtils.java;h=e94021119d14f11e7581d5e68b6e096921a07725;hb=5e20076e352bae1f6b0bd0f8ac8f7c85235e4b27;hp=a3f21cff3eb50ad3d062b1c381a79abf35b81f2e;hpb=7b8542bde88493834288782e7280c0fe72f3763b;p=controller.git diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/utils/NetUtils.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/utils/NetUtils.java index a3f21cff3e..e94021119d 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/utils/NetUtils.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/utils/NetUtils.java @@ -12,6 +12,7 @@ import java.net.Inet4Address; import java.net.Inet6Address; import java.net.InetAddress; import java.net.UnknownHostException; +import java.util.Arrays; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -246,11 +247,18 @@ public abstract class NetUtils { * Checks if the test address and mask conflicts with the filter address and * mask * - * For example: testAddress: 172.28.2.23 testMask: 255.255.255.0 - * filtAddress: 172.28.1.10 testMask: 255.255.255.0 conflict + * For example: + * testAddress: 172.28.2.23 + * testMask: 255.255.255.0 + * filterAddress: 172.28.1.10 + * testMask: 255.255.255.0 + * do conflict * - * testAddress: 172.28.2.23 testMask: 255.255.255.0 filtAddress: 172.28.1.10 - * testMask: 255.255.0.0 do not conflict + * testAddress: 172.28.2.23 + * testMask: 255.255.255.0 + * filterAddress: 172.28.1.10 + * testMask: 255.255.0.0 + * do not conflict * * Null parameters are permitted * @@ -274,7 +282,8 @@ public abstract class NetUtils { int testMaskLen = (testMask == null) ? ((testAddress instanceof Inet4Address) ? 32 : 128) : NetUtils .getSubnetMaskLength(testMask); - int filterMaskLen = NetUtils.getSubnetMaskLength(filterMask); + int filterMaskLen = (filterMask == null) ? ((testAddress instanceof Inet4Address) ? 32 : 128) : NetUtils + .getSubnetMaskLength(filterMask); // Mask length check. Test mask has to be more specific than filter one if (testMaskLen < filterMaskLen) { @@ -322,6 +331,19 @@ public abstract class NetUtils { return false; } + /** + * Returns true if the MAC address is a unicast MAC address and false + * otherwise. + * + * @param MACAddress + * @return + */ + public static boolean isUnicastMACAddr(byte[] MACAddress) { + if (MACAddress.length == MACAddrLengthInBytes) { + return (MACAddress[0] & 1) == 0; + } + return false; + } /** * Returns true if the MAC address is a multicast MAC address and false @@ -450,7 +472,7 @@ public abstract class NetUtils { /* * Following utilities are useful when you need to compare or bit shift java - * primitive type variable which are inerently signed + * primitive type variable which are inherently signed */ /** * Returns the unsigned value of the passed byte variable @@ -489,4 +511,14 @@ public abstract class NetUtils { return null; } } + + /** + * Returns Broadcast MAC Address + * + * @return the byte array containing broadcaset mac address + */ + public static byte[] getBroadcastMACAddr() { + return Arrays.copyOf(BroadcastMACAddr, BroadcastMACAddr.length); + } + }