You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by hu...@apache.org on 2014/01/03 11:17:35 UTC
[02/50] [abbrv] git commit: updated refs/heads/opendaylight to 858fb69
check vlans and other isolation types
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/04570eef
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/04570eef
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/04570eef
Branch: refs/heads/opendaylight
Commit: 04570eefed9a0ee1eca1fd700ed5732ba67150ce
Parents: d50517e
Author: Daan Hoogland <da...@onecht.net>
Authored: Fri Dec 20 16:47:58 2013 +0100
Committer: Daan Hoogland <dh...@schubergphilis.com>
Committed: Tue Dec 31 12:21:08 2013 +0100
----------------------------------------------------------------------
utils/src/com/cloud/utils/net/NetUtils.java | 44 +++++++++++++++++++++++-
1 file changed, 43 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/04570eef/utils/src/com/cloud/utils/net/NetUtils.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/net/NetUtils.java b/utils/src/com/cloud/utils/net/NetUtils.java
index f6f6285..5f600e5 100755
--- a/utils/src/com/cloud/utils/net/NetUtils.java
+++ b/utils/src/com/cloud/utils/net/NetUtils.java
@@ -1367,10 +1367,17 @@ public class NetUtils {
return resultIp;
}
+ static final String VLAN_PREFIX = "vlan://";
+ static final int VLAN_PREFIX_LENGTH = VLAN_PREFIX.length();
+
public static boolean isValidVlan(String vlan) {
+ if (null == vlan || "".equals(vlan))
+ return false;
+ if (vlan.startsWith(VLAN_PREFIX))
+ vlan = vlan.substring(VLAN_PREFIX_LENGTH);
try {
int vnet = Integer.parseInt(vlan);
- if (vnet < 0 || vnet > 4096) {
+ if (vnet <= 0 || vnet >= 4095) { // the valid range is 1- 4094
return false;
}
return true;
@@ -1379,6 +1386,41 @@ public class NetUtils {
}
}
+ static final String VLAN_UNTAGGED = "untagged";
+
+ public static boolean sameIsolationId(String one, String other)
+ {
+ // check nulls
+ // check empty strings
+ if ((one == null || one.equals(""))
+ &&
+ (other == null || other.equals("")))
+ {
+ return true;
+ }
+ // check 'untagged'
+ if (VLAN_UNTAGGED.equalsIgnoreCase(one) && VLAN_UNTAGGED.equalsIgnoreCase(other))
+ {
+ return true;
+ }
+ // if one is a number check the other as number and as 'vlan://' + number
+ if (one.startsWith(VLAN_PREFIX))
+ {
+ one = one.substring(VLAN_PREFIX_LENGTH);
+ }
+ if (other.startsWith(VLAN_PREFIX))
+ {
+ other = other.substring(VLAN_PREFIX_LENGTH);
+ }
+ // check valid uris or numbers
+ if (one.equals(other))
+ {
+ return true;
+ }
+
+ return false;
+ }
+
// Attention maintainers: these pvlan functions should take into account code
// in Networks.BroadcastDomainType, where URI construction is done for other
// types of BroadcastDomainTypes