cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yas...@apache.org
Subject [2/2] git commit: updated refs/heads/master to 5a8a2a2
Date Thu, 13 Jun 2013 23:05:43 GMT
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 <sheng.yang@citrix.com>
Authored: Thu Jun 13 14:57:47 2013 -0700
Committer: Sheng Yang <sheng.yang@citrix.com>
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<NicVO> 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<String, ArrayList<PublicIpAddress>> vlanAndIp : vlanIpMap.entrySet())
{
             List<PublicIpAddress> 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"));
+    }
 }


Mime
View raw message