@@ -118,7 +118,7 @@ public Network implement(Network config, NetworkOffering offering, DeployDestina
118118 if (Boolean .parseBoolean (_configDao .getValue (Config .OvsTunnelNetwork .key ()))) {
119119 return null ;
120120 }
121-
121+
122122 if (!_networkModel .networkIsConfiguredForExternalNetworking (config .getDataCenterId (), config .getId ())) {
123123 return super .implement (config , offering , dest , context );
124124 }
@@ -145,25 +145,31 @@ public Network implement(Network config, NetworkOffering offering, DeployDestina
145145 implemented .setBroadcastUri (config .getBroadcastUri ());
146146 }
147147
148- // Determine the offset from the lowest vlan tag
149- int offset = getVlanOffset (config .getPhysicalNetworkId (), vlanTag );
150-
151148 // Determine the new gateway and CIDR
152149 String [] oldCidr = config .getCidr ().split ("/" );
153150 String oldCidrAddress = oldCidr [0 ];
154- int cidrSize = getGloballyConfiguredCidrSize ();
155-
156- // If the offset has more bits than there is room for, return null
157- long bitsInOffset = 32 - Integer .numberOfLeadingZeros (offset );
158- if (bitsInOffset > (cidrSize - 8 )) {
159- throw new CloudRuntimeException ("The offset " + offset + " needs " + bitsInOffset + " bits, but only have " + (cidrSize - 8 ) + " bits to work with." );
151+ int cidrSize = Integer .parseInt (oldCidr [1 ]);
152+ long newCidrAddress = (NetUtils .ip2Long (oldCidrAddress ));
153+ // if the implementing network is for vpc, no need to generate newcidr, use the cidr that came from super cidr
154+ if (config .getVpcId () != null ) {
155+ implemented .setGateway (config .getGateway ());
156+ implemented .setCidr (config .getCidr ());
157+ implemented .setState (State .Implemented );
158+ } else {
159+ // Determine the offset from the lowest vlan tag
160+ int offset = getVlanOffset (config .getPhysicalNetworkId (), vlanTag );
161+ cidrSize = getGloballyConfiguredCidrSize ();
162+ // If the offset has more bits than there is room for, return null
163+ long bitsInOffset = 32 - Integer .numberOfLeadingZeros (offset );
164+ if (bitsInOffset > (cidrSize - 8 )) {
165+ throw new CloudRuntimeException ("The offset " + offset + " needs " + bitsInOffset + " bits, but only have " + (cidrSize - 8 ) + " bits to work with." );
166+ }
167+ newCidrAddress = (NetUtils .ip2Long (oldCidrAddress ) & 0xff000000 ) | (offset << (32 - cidrSize ));
168+ implemented .setGateway (NetUtils .long2Ip (newCidrAddress + 1 ));
169+ implemented .setCidr (NetUtils .long2Ip (newCidrAddress ) + "/" + cidrSize );
170+ implemented .setState (State .Implemented );
160171 }
161172
162- long newCidrAddress = (NetUtils .ip2Long (oldCidrAddress ) & 0xff000000 ) | (offset << (32 - cidrSize ));
163- implemented .setGateway (NetUtils .long2Ip (newCidrAddress + 1 ));
164- implemented .setCidr (NetUtils .long2Ip (newCidrAddress ) + "/" + cidrSize );
165- implemented .setState (State .Implemented );
166-
167173 // Mask the Ipv4 address of all nics that use this network with the new guest VLAN offset
168174 List <NicVO > nicsInNetwork = _nicDao .listByNetworkId (config .getId ());
169175 for (NicVO nic : nicsInNetwork ) {
@@ -172,8 +178,8 @@ public Network implement(Network config, NetworkOffering offering, DeployDestina
172178 nic .setIp4Address (NetUtils .long2Ip (newCidrAddress | ipMask ));
173179 _nicDao .persist (nic );
174180 }
175- }
176-
181+ }
182+
177183 // Mask the destination address of all port forwarding rules in this network with the new guest VLAN offset
178184 List <PortForwardingRuleVO > pfRulesInNetwork = _pfRulesDao .listByNetwork (config .getId ());
179185 for (PortForwardingRuleVO pfRule : pfRulesInNetwork ) {
0 commit comments