Yevgeny Zaspitsky has posted comments on this change. Change subject: tools: CidrValidation Utils ......................................................................
Patch Set 7: (9 comments) http://gerrit.ovirt.org/#/c/32539/7/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/ValidationUtils.java File backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/ValidationUtils.java: Line 24: public static final String NO_TRIMMING_WHITE_SPACES_PATTERN = "^$|\\S.*\\S"; Line 25: public static final String IP_PATTERN = Line 26: "^\\b((25[0-5]|2[0-4]\\d|[01]\\d\\d|\\d?\\d)\\.){3}(25[0-5]|2[0-4]\\d|[01]\\d\\d|\\d?\\d)\\b$|^$"; Line 27: public static final String CIDR_FORMAT_PATTERN = Line 28: "\\b((25[0-5]|2[0-4]\\d|[01]\\d\\d|\\d?\\d)\\.){3}(25[0-5]|2[0-4]\\d|[01]\\d\\d|\\d?\\d)(?:/(?:3[0-2]|[12]?[0-9]))$"; I'd substitute '\b' by '^' Line 29: public static final String ISO_SUFFIX = ".iso"; Line 30: public static final String ISO_SUFFIX_PATTERN = "^$|^.+\\.iso$"; Line 31: Line 32: /** the mask will be replaced with zero-padded number in the generated names of the VMs in the pool, http://gerrit.ovirt.org/#/c/32539/7/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/validation/CidrValidator.java File backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/validation/CidrValidator.java: Line 12: * <li>y belongs to [0,32] Line 13: * <li>both inclusive Line 14: * </ul> Line 15: * <p> Line 16: * <b>Note!</b> the function is not validating that IP and mask match to a network address, please see @see not sure that I understand the note. what's "network address" you're talking about? Line 17: * {@link CidrValidator#isCidrFormatValid(String)} Line 18: * @param cidr Line 19: * @return true if correct format, false otherwise. Line 20: */ Line 14: * </ul> Line 15: * <p> Line 16: * <b>Note!</b> the function is not validating that IP and mask match to a network address, please see @see Line 17: * {@link CidrValidator#isCidrFormatValid(String)} Line 18: * @param cidr if you put @param , please add some description to it Line 19: * @return true if correct format, false otherwise. Line 20: */ Line 21: public static boolean isCidrFormatValid(String cidr) { Line 22: return (cidr == null || !cidr.matches(ValidationUtils.CIDR_FORMAT_PATTERN)) ? Line 17: * {@link CidrValidator#isCidrFormatValid(String)} Line 18: * @param cidr Line 19: * @return true if correct format, false otherwise. Line 20: */ Line 21: public static boolean isCidrFormatValid(String cidr) { can the methods be non-static? Line 22: return (cidr == null || !cidr.matches(ValidationUtils.CIDR_FORMAT_PATTERN)) ? Line 23: false : true; Line 24: } Line 25: Line 26: /*** Line 27: * check if CIDR represent valid network add Line 28: * <p> Line 29: * @param cidr Line 30: * - in correct format, please use the following function first: @see Providing a corresponding method is better than documentation Line 31: * {@link CidrValidator#isCidrFormatValid(String)} Line 32: * @return true if valid CIDR ,false otherwise Line 33: */ Line 34: public static boolean isCidrNetworkAddressValid(String cidr) { Line 41: private static int covnertIpToInt(String ipAdd) { Line 42: String[] subAdd = ipAdd.split("\\."); Line 43: int output = 0; Line 44: int temp; Line 45: for (int index = 3; index > -1; index--) { 1. OutOfBoundaries prone. 2. Why do you start from the less significant part? Line 46: temp = Integer.parseInt(subAdd[3 - index]); Line 47: temp <<= (index * 8); Line 48: output |= temp; Line 49: } Line 42: String[] subAdd = ipAdd.split("\\."); Line 43: int output = 0; Line 44: int temp; Line 45: for (int index = 3; index > -1; index--) { Line 46: temp = Integer.parseInt(subAdd[3 - index]); NumberFormatException? Line 47: temp <<= (index * 8); Line 48: output |= temp; Line 49: } Line 50: Line 50: Line 51: return output; Line 52: } Line 53: Line 54: private static boolean isNetworkAddress(int ip, int mask) { i'd call it isIpBelongToSubnet Line 55: int temp = 1; Line 56: for (int i = 0; i < 32-mask; i++) { Line 57: if ((temp & ip) != 0) { Line 58: return false; Line 52: } Line 53: Line 54: private static boolean isNetworkAddress(int ip, int mask) { Line 55: int temp = 1; Line 56: for (int i = 0; i < 32-mask; i++) { can the check be done without a loop? private boolean isIpBelongToSubnet(final int ipAsInt, final int subnetBits) { final int mask = 0xffffffff & (0xffffffff << (32 - subnetBits)); return (ipAsInt & mask) == mask; } Line 57: if ((temp & ip) != 0) { Line 58: return false; Line 59: } Line 60: -- To view, visit http://gerrit.ovirt.org/32539 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: comment Gerrit-Change-Id: Ib1277dbc815953926fe1648350cd55cb75e1084a Gerrit-PatchSet: 7 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Eliraz Levi <el...@redhat.com> Gerrit-Reviewer: Alona Kaplan <alkap...@redhat.com> Gerrit-Reviewer: Eliraz Levi <el...@redhat.com> Gerrit-Reviewer: Moti Asayag <masa...@redhat.com> Gerrit-Reviewer: Yevgeny Zaspitsky <yzasp...@redhat.com> Gerrit-Reviewer: automat...@ovirt.org Gerrit-Reviewer: oVirt Jenkins CI Server Gerrit-HasComments: Yes _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches