Limit string field lengths for network/configuration objects

Change-Id: Ic375854bb697ee21a8fd7b15fccd0b0878212869
diff --git a/core/api/src/main/java/org/onosproject/net/config/Config.java b/core/api/src/main/java/org/onosproject/net/config/Config.java
index c7d821e..eb138b8 100644
--- a/core/api/src/main/java/org/onosproject/net/config/Config.java
+++ b/core/api/src/main/java/org/onosproject/net/config/Config.java
@@ -52,6 +52,7 @@
 
     private static final String TRUE_LITERAL = "true";
     private static final String FALSE_LITERAL = "false";
+    private static final String EMPTY_STRING = "";
 
     protected S subject;
     protected String key;
@@ -440,6 +441,20 @@
     }
 
     /**
+     * Indicates whether the specified field is of a valid length.
+     *
+     * @param field the field to validate
+     * @param maxLength the maximum allowed length of the field
+     * @return true if the field lenth is less than the required length
+     */
+    protected boolean isValidLength(String field, int maxLength) {
+        if (object.path(field).asText(EMPTY_STRING).length() > maxLength) {
+            throw new InvalidFieldException(field, "exceeds maximum length " + maxLength);
+        }
+        return true;
+    }
+
+    /**
      * Returns true if this config contains a field with the given name.
      *
      * @param name the field name