Return-Path: X-Original-To: apmail-cloudstack-commits-archive@www.apache.org Delivered-To: apmail-cloudstack-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id AAFE610094 for ; Mon, 23 Dec 2013 13:03:54 +0000 (UTC) Received: (qmail 70747 invoked by uid 500); 23 Dec 2013 13:03:53 -0000 Delivered-To: apmail-cloudstack-commits-archive@cloudstack.apache.org Received: (qmail 70486 invoked by uid 500); 23 Dec 2013 13:03:52 -0000 Mailing-List: contact commits-help@cloudstack.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cloudstack.apache.org Delivered-To: mailing list commits@cloudstack.apache.org Received: (qmail 70404 invoked by uid 99); 23 Dec 2013 13:03:51 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 23 Dec 2013 13:03:51 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 4310488F1BD; Mon, 23 Dec 2013 13:03:51 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: dahn@apache.org To: commits@cloudstack.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: git commit: updated refs/heads/4.3 to 94abbb1 Date: Mon, 23 Dec 2013 13:03:51 +0000 (UTC) Updated Branches: refs/heads/4.3 689798497 -> 94abbb136 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/94abbb13 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/94abbb13 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/94abbb13 Branch: refs/heads/4.3 Commit: 94abbb1367bc817bae98f369e78679f0ddb7727f Parents: 6897984 Author: Daan Hoogland Authored: Fri Dec 20 16:47:58 2013 +0100 Committer: Daan Hoogland Committed: Mon Dec 23 13:51:34 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/94abbb13/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 11a483c..a315b93 100755 --- a/utils/src/com/cloud/utils/net/NetUtils.java +++ b/utils/src/com/cloud/utils/net/NetUtils.java @@ -1375,10 +1375,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; @@ -1387,6 +1394,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