IntentUtils { public static boolean validateIP(String ip) { if (ip == null || ip.isEmpty()) { return false; } ip = ip.trim(); if ((ip.length() < 7) || (ip.length() > 15)) { return false; } try { Pattern pattern = Pattern.compile(IP_PATTERN); Matcher matcher = pattern.matcher(ip); return matcher.matches(); } catch (PatternSyntaxException ex) { LOG.error("IP Pattern not matched"); return false; } } private  IntentUtils(); static boolean validateMAC(final String mac); static boolean validateIP(String ip); static boolean verifyIntent(final Intent intent); static boolean verifyIntentActions(final Intent intent); static boolean verifyIntentSubjects(final Intent intent); static List<String> extractEndPointGroup(final Intent intent); static List<EndPointGroup> extractEndPointGroups(final Intent intent); static EndPointGroup extractSrcEndPointGroup(final Intent intent); static EndPointGroup extractDstEndPointGroup(final Intent intent); static void verifySubjectInstance(final Subject subject, final Uuid intentId); static Action getAction(final Intent intent); static final Integer SRC_END_POINT_GROUP_INDEX; static final Integer DST_END_POINT_GROUP_INDEX; static final InstanceIdentifier<Intents> INTENTS_IID; static final InstanceIdentifier<IntentsLimiter> INTENTS_LIMITER_IDD; static final InstanceIdentifier<IntentIspPrefixes> INTENT_ISP_PREFIX_IID; }
@Test public void testValidateIP() { boolean result; final String ip = "0.0.0.1"; result = IntentUtils.validateIP(ip); Assert.assertTrue(result); }
@Test public void testValidateEmptyIP() { boolean result; final String ip = ""; result = IntentUtils.validateIP(ip); Assert.assertFalse(result); }
@Test public void testValidateNullIP() { boolean result; final String ip = null; result = IntentUtils.validateIP(ip); Assert.assertFalse(result); }
@Test public void testValidateIPWithLentghLessThan7() { boolean result; final String ip = "0.0.0."; result = IntentUtils.validateIP(ip); Assert.assertFalse(result); }
@Test public void testValidateIPWithLentghMoreThan15() { boolean result; final String ip = "200.100.100.1001"; result = IntentUtils.validateIP(ip); Assert.assertFalse(result); }