X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fsal%2Fapi%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Futils%2FNetUtils.java;h=6b303f09f11955a053f7bcf740bf9f647b5df2ce;hp=0fce4f4b0aea447a26c2884a1d6b6b3814ba9df5;hb=c1d6c147a5fdd6b18cf9f00e1bb7855020f2361f;hpb=27b845b753f14e44fe46938d7980b06635dd058f 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 0fce4f4b0a..6b303f09f1 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 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2013-2014 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -247,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 * @@ -275,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) { @@ -347,9 +355,7 @@ public abstract class NetUtils { */ public static boolean isMulticastMACAddr(byte[] MACAddress) { if (MACAddress.length == MACAddrLengthInBytes && !isBroadcastMACAddr(MACAddress)) { - if (MACAddress[0] % 2 == 1) { - return true; - } + return (MACAddress[0] & 1) != 0; } return false; } @@ -464,7 +470,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 @@ -474,7 +480,7 @@ public abstract class NetUtils { * @return the int variable containing the unsigned byte value */ public static int getUnsignedByte(byte b) { - return (b > 0) ? (int) b : (b & 0x7F | 0x80); + return b & 0xFF; } /** @@ -485,7 +491,7 @@ public abstract class NetUtils { * @return the int variable containing the unsigned short value */ public static int getUnsignedShort(short s) { - return (s > 0) ? (int) s : (s & 0x7FFF | 0x8000); + return s & 0xFFFF; } /** @@ -507,10 +513,9 @@ public abstract class NetUtils { /** * Returns Broadcast MAC Address * - * @return the byte array containing broadcaset mac address + * @return the byte array containing broadcast mac address */ public static byte[] getBroadcastMACAddr() { return Arrays.copyOf(BroadcastMACAddr, BroadcastMACAddr.length); } - }