From 657d9e4789d73c7c8ed460e59f088b8cb9aa7697 Mon Sep 17 00:00:00 2001 From: Anthony Xu Date: Mon, 3 Feb 2014 15:02:36 -0800 Subject: [PATCH] Allow different VLANs have ovveride subnet for shared network --- .../ConfigurationManagerImpl.java | 63 ++++++++++++------- 1 file changed, 39 insertions(+), 24 deletions(-) diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index 0109b4b7b6d..49fee93f332 100755 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -2864,40 +2864,55 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati String otherVlanGateway = vlan.getVlanGateway(); String otherVlanNetmask = vlan.getVlanNetmask(); // Continue if it's not IPv4 - if (otherVlanGateway == null || otherVlanNetmask == null) { + if ( otherVlanGateway == null || otherVlanNetmask == null ) { continue; } - if (vlan.getNetworkId() == null) { + if ( vlan.getNetworkId() == null ) { continue; } String otherCidr = NetUtils.getCidrFromGatewayAndNetmask(otherVlanGateway, otherVlanNetmask); - if (!NetUtils.isNetworksOverlap(newCidr, otherCidr)) { + if( !NetUtils.isNetworksOverlap(newCidr, otherCidr)) { continue; } // from here, subnet overlaps - if (!NetUtils.isSameIsolationId(vlanId, vlan.getVlanTag())) { - throw new InvalidParameterValueException("The IP range with tag: " + vlan.getVlanTag() + " in zone " + zone.getName() - + " has overlapped with the subnet. Please specify a different gateway/netmask."); - } - if (vlan.getNetworkId() != networkId) { - throw new InvalidParameterValueException("This subnet is overlapped with subnet in other network " + vlan.getNetworkId() + " in zone " + zone.getName() - + " . Please specify a different gateway/netmask."); + if ( !vlanId.equals(vlan.getVlanTag()) ) { + boolean overlapped = false; + if( network.getTrafficType() == TrafficType.Public ) { + overlapped = true; + } else { + Long nwId = vlan.getNetworkId(); + if ( nwId != null ) { + Network nw = _networkModel.getNetwork(nwId); + if ( nw != null && nw.getTrafficType() == TrafficType.Public ) { + overlapped = true; + } + } - } - String[] otherVlanIpRange = vlan.getIpRange().split("\\-"); - String otherVlanStartIP = otherVlanIpRange[0]; - String otherVlanEndIP = null; - if (otherVlanIpRange.length > 1) { - otherVlanEndIP = otherVlanIpRange[1]; - } + } + if ( overlapped ) { + throw new InvalidParameterValueException("The IP range with tag: " + vlan.getVlanTag() + + " in zone " + zone.getName() + + " has overlapped with the subnet. Please specify a different gateway/netmask."); + } + } else { - //extend IP range - if (!vlanGateway.equals(otherVlanGateway) || !vlanNetmask.equals(vlan.getVlanNetmask())) { - throw new InvalidParameterValueException("The IP range has already been added with gateway " + otherVlanGateway + " ,and netmask " + otherVlanNetmask - + ", Please specify the gateway/netmask if you want to extend ip range"); - } - if (NetUtils.ipRangesOverlap(startIP, endIP, otherVlanStartIP, otherVlanEndIP)) { - throw new InvalidParameterValueException("The IP range already has IPs that overlap with the new range." + " Please specify a different start IP/end IP."); + String[] otherVlanIpRange = vlan.getIpRange().split("\\-"); + String otherVlanStartIP = otherVlanIpRange[0]; + String otherVlanEndIP = null; + if (otherVlanIpRange.length > 1) { + otherVlanEndIP = otherVlanIpRange[1]; + } + + // extend IP range + if (!vlanGateway.equals(otherVlanGateway) || !vlanNetmask.equals(vlan.getVlanNetmask())) { + throw new InvalidParameterValueException("The IP range has already been added with gateway " + + otherVlanGateway + " ,and netmask " + otherVlanNetmask + + ", Please specify the gateway/netmask if you want to extend ip range" ); + } + if (NetUtils.ipRangesOverlap(startIP, endIP, otherVlanStartIP, otherVlanEndIP)) { + throw new InvalidParameterValueException("The IP range already has IPs that overlap with the new range." + + " Please specify a different start IP/end IP."); + } } } }