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 29CE2104E2 for ; Thu, 13 Jun 2013 23:05:43 +0000 (UTC) Received: (qmail 93054 invoked by uid 500); 13 Jun 2013 23:05:42 -0000 Delivered-To: apmail-cloudstack-commits-archive@cloudstack.apache.org Received: (qmail 93012 invoked by uid 500); 13 Jun 2013 23:05:42 -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 92997 invoked by uid 99); 13 Jun 2013 23:05:42 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 13 Jun 2013 23:05:42 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id AD9BD816641; Thu, 13 Jun 2013 23:05:42 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: yasker@apache.org To: commits@cloudstack.apache.org Date: Thu, 13 Jun 2013 23:05:43 -0000 Message-Id: In-Reply-To: <838f7ea431694fbfbf705d661c89a36b@git.apache.org> References: <838f7ea431694fbfbf705d661c89a36b@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [2/2] git commit: updated refs/heads/master to 5a8a2a2 CLOUDSTACK-1170: Redundant Router: Ensure MACs are same on other than first public nic Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/fbe6b273 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/fbe6b273 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/fbe6b273 Branch: refs/heads/master Commit: fbe6b273e3112ce53b24d7a5db6be95b1bd8d5ae Parents: 2630625 Author: Sheng Yang Authored: Thu Jun 13 14:57:47 2013 -0700 Committer: Sheng Yang Committed: Thu Jun 13 16:05:15 2013 -0700 ---------------------------------------------------------------------- .../VirtualNetworkApplianceManagerImpl.java | 19 ++++++++++++++++++- utils/src/com/cloud/utils/net/NetUtils.java | 9 +++++++++ utils/test/com/cloud/utils/net/NetUtilsTest.java | 13 +++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fbe6b273/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index db4786a..01f86ec 100755 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -3144,6 +3144,16 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V vlanIpMap.put(vlanTag, ipList); } + List nics = _nicDao.listByVmId(router.getId()); + String baseMac = null; + for (NicVO nic : nics) { + NetworkVO nw = _networkDao.findById(nic.getNetworkId()); + if (nw.getTrafficType() == TrafficType.Public) { + baseMac = nic.getMacAddress(); + break; + } + } + for (Map.Entry> vlanAndIp : vlanIpMap.entrySet()) { List ipAddrList = vlanAndIp.getValue(); // Source nat ip address should always be sent first @@ -3175,7 +3185,14 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V String vlanId = ipAddr.getVlanTag(); String vlanGateway = ipAddr.getGateway(); String vlanNetmask = ipAddr.getNetmask(); - String vifMacAddress = ipAddr.getMacAddress(); + String vifMacAddress = null; + // For non-source nat IP, set the mac to be something based on first public nic's MAC + // We cannot depends on first ip because we need to deal with first ip of other nics + if (!ipAddr.isSourceNat() && ipAddr.getVlanId() != 0) { + vifMacAddress = NetUtils.generateMacOnIncrease(baseMac, ipAddr.getVlanId()); + } else { + vifMacAddress = ipAddr.getMacAddress(); + } IpAddressTO ip = new IpAddressTO(ipAddr.getAccountId(), ipAddr.getAddress().addr(), add, firstIP, sourceNat, vlanId, vlanGateway, vlanNetmask, vifMacAddress, networkRate, ipAddr.isOneToOneNat()); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fbe6b273/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 ec0ff05..5c13454 100755 --- a/utils/src/com/cloud/utils/net/NetUtils.java +++ b/utils/src/com/cloud/utils/net/NetUtils.java @@ -1394,4 +1394,13 @@ public class NetUtils { return null; } + public static String generateMacOnIncrease(String baseMac, long l) { + long mac = mac2Long(baseMac); + if (l > 0xFFFFl) { + return null; + } + mac = mac + (l << 24); + mac = mac & 0x06FFFFFFFFFFl; + return long2Mac(mac); + } } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fbe6b273/utils/test/com/cloud/utils/net/NetUtilsTest.java ---------------------------------------------------------------------- diff --git a/utils/test/com/cloud/utils/net/NetUtilsTest.java b/utils/test/com/cloud/utils/net/NetUtilsTest.java index 9952d3c..38fe21d 100644 --- a/utils/test/com/cloud/utils/net/NetUtilsTest.java +++ b/utils/test/com/cloud/utils/net/NetUtilsTest.java @@ -155,4 +155,17 @@ public class NetUtilsTest extends TestCase { //Check for Incorrect format of CIDR assertFalse(NetUtils.isSameIpRange(cidrFirst, "10.3.6.5/50")); } + + public void testMacGenerateion() { + String mac = "06:01:23:00:45:67"; + String newMac = NetUtils.generateMacOnIncrease(mac, 2); + assertTrue(newMac.equals("06:01:25:00:45:67")); + newMac = NetUtils.generateMacOnIncrease(mac, 16); + assertTrue(newMac.equals("06:01:33:00:45:67")); + mac = "06:ff:ff:00:45:67"; + newMac = NetUtils.generateMacOnIncrease(mac, 1); + assertTrue(newMac.equals("06:00:00:00:45:67")); + newMac = NetUtils.generateMacOnIncrease(mac, 16); + assertTrue(newMac.equals("06:00:0f:00:45:67")); + } }