@@ -2073,13 +2073,34 @@ public Vlan createVlanAndPublicIpRange(CreateVlanIpRangeCmd cmd) throws Insuffic
20732073 String accountName = cmd .getAccountName ();
20742074 Long projectId = cmd .getProjectId ();
20752075 Long domainId = cmd .getDomainId ();
2076+ String startIPv6 = cmd .getStartIpv6 ();
2077+ String endIPv6 = cmd .getEndIpv6 ();
2078+ String ip6Gateway = cmd .getIp6Gateway ();
2079+ String ip6Cidr = cmd .getIp6Cidr ();
2080+
20762081 Account vlanOwner = null ;
20772082
2078- // if end ip is not specified, default it to startIp
2079- if (endIP == null && startIP != null ) {
2080- endIP = startIP ;
2083+ boolean ipv4 = (startIP != null );
2084+ boolean ipv6 = (startIPv6 != null );
2085+
2086+ if (!ipv4 && !ipv6 ) {
2087+ throw new InvalidParameterValueException ("StartIP or StartIPv6 is missing in the parameters!" );
20812088 }
2082-
2089+
2090+ if (ipv4 ) {
2091+ // if end ip is not specified, default it to startIp
2092+ if (endIP == null && startIP != null ) {
2093+ endIP = startIP ;
2094+ }
2095+ }
2096+
2097+ if (ipv6 ) {
2098+ // if end ip is not specified, default it to startIp
2099+ if (endIPv6 == null && startIPv6 != null ) {
2100+ endIPv6 = startIPv6 ;
2101+ }
2102+ }
2103+
20832104 if (projectId != null ) {
20842105 if (accountName != null ) {
20852106 throw new InvalidParameterValueException ("Account and projectId are mutually exclusive" );
@@ -2109,6 +2130,8 @@ public Vlan createVlanAndPublicIpRange(CreateVlanIpRangeCmd cmd) throws Insuffic
21092130 zoneId = network .getDataCenterId ();
21102131 physicalNetworkId = network .getPhysicalNetworkId ();
21112132 }
2133+ } else if (ipv6 ) {
2134+ throw new InvalidParameterValueException ("Only support IPv6 on extending existed network" );
21122135 }
21132136
21142137 // Verify that zone exists
@@ -2117,6 +2140,11 @@ public Vlan createVlanAndPublicIpRange(CreateVlanIpRangeCmd cmd) throws Insuffic
21172140 throw new InvalidParameterValueException ("Unable to find zone by id " + zoneId );
21182141 }
21192142
2143+ if (ipv6 ) {
2144+ if (network .getGuestType () != GuestType .Shared || zone .isSecurityGroupEnabled ()) {
2145+ throw new InvalidParameterValueException ("Only support IPv6 on extending existed share network without SG" );
2146+ }
2147+ }
21202148 // verify that physical network exists
21212149 PhysicalNetworkVO pNtwk = null ;
21222150 if (physicalNetworkId != null ) {
@@ -2163,7 +2191,7 @@ public Vlan createVlanAndPublicIpRange(CreateVlanIpRangeCmd cmd) throws Insuffic
21632191 if (zone .isSecurityGroupEnabled () && zone .getNetworkType () != DataCenter .NetworkType .Basic && forVirtualNetwork ) {
21642192 throw new InvalidParameterValueException ("Can't add virtual ip range into a zone with security group enabled" );
21652193 }
2166-
2194+
21672195 // If networkId is not specified, and vlan is Virtual or Direct Untagged, try to locate default networks
21682196 if (forVirtualNetwork ) {
21692197 if (network == null ) {
@@ -2196,11 +2224,6 @@ public Vlan createVlanAndPublicIpRange(CreateVlanIpRangeCmd cmd) throws Insuffic
21962224 throw new InvalidParameterValueException ("Network " + network + " doesn't support adding ip ranges" );
21972225 }
21982226
2199- // if end ip is not specified, default it to startIp
2200- if (endIP == null && startIP != null ) {
2201- endIP = startIP ;
2202- }
2203-
22042227 if ( zone .getNetworkType () == DataCenter .NetworkType .Advanced ) {
22052228 if (network .getTrafficType () == TrafficType .Guest ) {
22062229 if (network .getGuestType () != GuestType .Shared ) {
@@ -2216,19 +2239,38 @@ public Vlan createVlanAndPublicIpRange(CreateVlanIpRangeCmd cmd) throws Insuffic
22162239 throw new InvalidParameterValueException ("there is already one vlan " + vlan .getVlanTag () + " on network :" +
22172240 + network .getId () + ", only one vlan is allowed on guest network" );
22182241 }
2219- vlanGateway = vlan .getVlanGateway ();
2220- vlanNetmask = vlan .getVlanNetmask ();
2242+ if (ipv4 ) {
2243+ vlanGateway = vlan .getVlanGateway ();
2244+ vlanNetmask = vlan .getVlanNetmask ();
2245+ // Check if ip addresses are in network range
2246+ if (!NetUtils .sameSubnet (startIP , vlanGateway , vlanNetmask )) {
2247+ throw new InvalidParameterValueException ("Start ip is not in vlan range!" );
2248+ }
2249+ if (!NetUtils .sameSubnet (endIP , vlanGateway , vlanNetmask )) {
2250+ throw new InvalidParameterValueException ("End ip is not in vlan range!" );
2251+ }
2252+ }
2253+ if (ipv6 ) {
2254+ if (ip6Gateway != null && !ip6Gateway .equals (network .getIp6Gateway ())) {
2255+ throw new InvalidParameterValueException ("The input gateway " + ip6Gateway + " is not same as network gateway " + network .getIp6Gateway ());
2256+ }
2257+ if (ip6Cidr != null && !ip6Cidr .equals (network .getIp6Cidr ())) {
2258+ throw new InvalidParameterValueException ("The input cidr " + ip6Cidr + " is not same as network ciddr " + network .getIp6Cidr ());
2259+ }
2260+ ip6Gateway = network .getIp6Gateway ();
2261+ ip6Cidr = network .getIp6Cidr ();
2262+ _networkModel .checkIp6Parameters (startIPv6 , endIPv6 , ip6Gateway , ip6Cidr );
2263+ }
22212264 }
22222265 } else if (network .getTrafficType () == TrafficType .Management ) {
22232266 throw new InvalidParameterValueException ("Cannot execute createVLANIpRanges on management network" );
22242267 }
22252268 }
22262269
2227- if (vlanGateway == null || vlanNetmask == null || zoneId == null ) {
2270+ if (zoneId == null || ( ipv4 && ( vlanGateway == null || vlanNetmask == null )) || ( ipv6 && ( ip6Gateway == null || ip6Cidr == null )) ) {
22282271 throw new InvalidParameterValueException ("Gateway, netmask and zoneId have to be passed in for virtual and direct untagged networks" );
22292272 }
22302273
2231-
22322274 // if it's an account specific range, associate ip address list to the account
22332275 boolean associateIpRangeToAccount = false ;
22342276
@@ -2245,12 +2287,14 @@ public Vlan createVlanAndPublicIpRange(CreateVlanIpRangeCmd cmd) throws Insuffic
22452287 }
22462288
22472289 // Check if the IP range overlaps with the private ip
2248- checkOverlapPrivateIpRange (zoneId , startIP , endIP );
2290+ if (ipv4 ) {
2291+ checkOverlapPrivateIpRange (zoneId , startIP , endIP );
2292+ }
22492293 Transaction txn = Transaction .currentTxn ();
22502294 txn .start ();
22512295
22522296 Vlan vlan = createVlanAndPublicIpRange (zoneId , networkId , physicalNetworkId , forVirtualNetwork , podId , startIP ,
2253- endIP , vlanGateway , vlanNetmask , vlanId , vlanOwner , null , null , null , null );
2297+ endIP , vlanGateway , vlanNetmask , vlanId , vlanOwner , startIPv6 , endIPv6 , ip6Gateway , ip6Cidr );
22542298
22552299 if (associateIpRangeToAccount ) {
22562300 _networkMgr .associateIpAddressListToAccount (userId , vlanOwner .getId (), zoneId , vlan .getId (), null );
0 commit comments