mirror of https://github.com/apache/cloudstack.git
CLOUDSTACK-1170: Redundant Router: Ensure MACs are same on other than first public nic
This commit is contained in:
parent
2630625260
commit
fbe6b273e3
|
|
@ -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());
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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"));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue