|
16 | 16 | // under the License. |
17 | 17 | package com.cloud.network.element; |
18 | 18 |
|
| 19 | +import java.net.URISyntaxException; |
19 | 20 | import java.util.ArrayList; |
20 | 21 | import java.util.Collections; |
21 | 22 | import java.util.HashMap; |
@@ -253,25 +254,29 @@ public boolean implement(Network network, NetworkOffering offering, |
253 | 254 | network.getId(), Service.SourceNat, Provider.NiciraNvp)) { |
254 | 255 | s_logger.debug("Apparently we are supposed to provide SourceNat on this network"); |
255 | 256 |
|
256 | | - PublicIp sourceNatIp = _ipAddrMgr |
257 | | - .assignSourceNatIpAddressToGuestNetwork(owner, network); |
258 | | - String publicCidr = sourceNatIp.getAddress().addr() + "/" |
259 | | - + NetUtils.getCidrSize(sourceNatIp.getVlanNetmask()); |
260 | | - String internalCidr = network.getGateway() + "/" |
261 | | - + network.getCidr().split("/")[1]; |
262 | | - long vlanid = (Vlan.UNTAGGED.equals(sourceNatIp.getVlanTag())) ? 0 |
263 | | - : Long.parseLong(sourceNatIp.getVlanTag()); |
264 | | - |
265 | | - CreateLogicalRouterCommand cmd = new CreateLogicalRouterCommand( |
266 | | - niciraNvpHost.getDetail("l3gatewayserviceuuid"), vlanid, |
267 | | - BroadcastDomainType.getValue(network.getBroadcastUri()), |
268 | | - "router-" + network.getDisplayText(), publicCidr, |
269 | | - sourceNatIp.getGateway(), internalCidr, context |
270 | | - .getDomain().getName() |
271 | | - + "-" |
272 | | - + context.getAccount().getAccountName()); |
273 | | - CreateLogicalRouterAnswer answer = (CreateLogicalRouterAnswer)_agentMgr |
274 | | - .easySend(niciraNvpHost.getId(), cmd); |
| 257 | + PublicIp sourceNatIp = _ipAddrMgr.assignSourceNatIpAddressToGuestNetwork(owner, network); |
| 258 | + String publicCidr = sourceNatIp.getAddress().addr() + "/" + NetUtils.getCidrSize(sourceNatIp.getVlanNetmask()); |
| 259 | + String internalCidr = network.getGateway() + "/" + network.getCidr().split("/")[1]; |
| 260 | + // assuming a vlan: |
| 261 | + String vtag = sourceNatIp.getVlanTag(); |
| 262 | + BroadcastDomainType tiep = null; |
| 263 | + try { |
| 264 | + tiep = BroadcastDomainType.getTypeOf(vtag); |
| 265 | + } catch (URISyntaxException use) { |
| 266 | + throw new CloudRuntimeException("vlantag for sourceNatIp is not valid: " + vtag, use); |
| 267 | + } |
| 268 | + if (tiep == BroadcastDomainType.Vlan) { |
| 269 | + vtag = BroadcastDomainType.Vlan.getValueFrom(BroadcastDomainType.fromString(vtag)); |
| 270 | + } else if (!(tiep == BroadcastDomainType.UnDecided || tiep == BroadcastDomainType.Native)) { |
| 271 | + throw new CloudRuntimeException("only vlans are supported for sourceNatIp, at this moment: " + vtag); |
| 272 | + } |
| 273 | + long vlanid = (Vlan.UNTAGGED.equals(vtag)) ? 0 : Long.parseLong(vtag); |
| 274 | + |
| 275 | + CreateLogicalRouterCommand cmd = |
| 276 | + new CreateLogicalRouterCommand(niciraNvpHost.getDetail("l3gatewayserviceuuid"), vlanid, BroadcastDomainType.getValue(network.getBroadcastUri()), |
| 277 | + "router-" + network.getDisplayText(), publicCidr, sourceNatIp.getGateway(), internalCidr, context.getDomain().getName() + "-" + |
| 278 | + context.getAccount().getAccountName()); |
| 279 | + CreateLogicalRouterAnswer answer = (CreateLogicalRouterAnswer)_agentMgr.easySend(niciraNvpHost.getId(), cmd); |
275 | 280 | if (answer.getResult() == false) { |
276 | 281 | s_logger.error("Failed to create Logical Router for network " |
277 | 282 | + network.getDisplayText()); |
|
0 commit comments