16
16
// under the License.
17
17
package com .cloud .network ;
18
18
19
+ import static org .apache .commons .lang .StringUtils .isNotBlank ;
20
+
19
21
import java .net .Inet6Address ;
20
22
import java .net .InetAddress ;
21
23
import java .net .URI ;
@@ -995,6 +997,46 @@ private void checkSharedNetworkCidrOverlap(Long zoneId, long physicalNetworkId,
995
997
}
996
998
}
997
999
1000
+ private void validateRouterIps (String routerIp , String routerIpv6 , String startIp , String endIp , String gateway ,
1001
+ String netmask , String startIpv6 , String endIpv6 , String ip6Cidr ) {
1002
+ if (isNotBlank (routerIp )) {
1003
+ if (startIp != null && endIp == null ) {
1004
+ endIp = startIp ;
1005
+ }
1006
+ if (!NetUtils .isValidIp4 (routerIp )) {
1007
+ throw new CloudRuntimeException ("Router IPv4 IP provided is of incorrect format" );
1008
+ }
1009
+ if (isNotBlank (startIp ) && isNotBlank (endIp )) {
1010
+ if (!NetUtils .isIpInRange (routerIp , startIp , endIp )) {
1011
+ throw new CloudRuntimeException ("Router IPv4 IP provided is not within the specified range: " + startIp + " - " + endIp );
1012
+ }
1013
+ } else {
1014
+ String cidr = NetUtils .ipAndNetMaskToCidr (gateway , netmask );
1015
+ if (!NetUtils .isIpWithInCidrRange (routerIp , cidr )) {
1016
+ throw new CloudRuntimeException ("Router IP provided in not within the network range" );
1017
+ }
1018
+ }
1019
+ }
1020
+ if (isNotBlank (routerIpv6 )) {
1021
+ if (startIpv6 != null && endIpv6 == null ) {
1022
+ endIpv6 = startIpv6 ;
1023
+ }
1024
+ if (!NetUtils .isValidIp6 (routerIpv6 )) {
1025
+ throw new CloudRuntimeException ("Router IPv6 address provided is of incorrect format" );
1026
+ }
1027
+ if (isNotBlank (startIpv6 ) && isNotBlank (endIpv6 )) {
1028
+ String ipv6Range = startIpv6 + "-" + endIpv6 ;
1029
+ if (!NetUtils .isIp6InRange (routerIpv6 , ipv6Range )) {
1030
+ throw new CloudRuntimeException ("Router IPv6 address provided is not within the specified range: " + startIpv6 + " - " + endIpv6 );
1031
+ }
1032
+ } else {
1033
+ if (!NetUtils .isIp6InNetwork (routerIpv6 , ip6Cidr )) {
1034
+ throw new CloudRuntimeException ("Router IPv6 address provided is not with the network range" );
1035
+ }
1036
+ }
1037
+ }
1038
+ }
1039
+
998
1040
@ Override
999
1041
@ DB
1000
1042
@ ActionEvent (eventType = EventTypes .EVENT_NETWORK_CREATE , eventDescription = "creating network" )
@@ -1007,11 +1049,13 @@ public Network createGuestNetwork(CreateNetworkCmd cmd) throws InsufficientCapac
1007
1049
String networkDomain = cmd .getNetworkDomain ();
1008
1050
String vlanId = null ;
1009
1051
boolean bypassVlanOverlapCheck = false ;
1052
+ String routerIp = null ;
1053
+ String routerIpv6 = null ;
1010
1054
if (cmd instanceof CreateNetworkCmdByAdmin ) {
1011
1055
vlanId = ((CreateNetworkCmdByAdmin )cmd ).getVlan ();
1012
- }
1013
- if (cmd instanceof CreateNetworkCmdByAdmin ) {
1014
1056
bypassVlanOverlapCheck = ((CreateNetworkCmdByAdmin )cmd ).getBypassVlanOverlapCheck ();
1057
+ routerIp = ((CreateNetworkCmdByAdmin )cmd ).getRouterIp ();
1058
+ routerIpv6 = ((CreateNetworkCmdByAdmin )cmd ).getRouterIpv6 ();
1015
1059
}
1016
1060
1017
1061
String name = cmd .getNetworkName ();
@@ -1105,6 +1149,15 @@ public Network createGuestNetwork(CreateNetworkCmd cmd) throws InsufficientCapac
1105
1149
throw new InvalidParameterValueException ("Only Admins can create network with guest type " + GuestType .Shared );
1106
1150
}
1107
1151
1152
+ if (ntwkOff .getGuestType () != GuestType .Shared && (isNotBlank (routerIp ) || isNotBlank (routerIpv6 ))) {
1153
+ throw new InvalidParameterValueException ("Router IP can be specified only for Shared networks" );
1154
+ }
1155
+
1156
+ if (ntwkOff .getGuestType () == GuestType .Shared && !_networkModel .isProviderForNetworkOffering (Provider .VirtualRouter , networkOfferingId )
1157
+ && (isNotBlank (routerIp ) || isNotBlank (routerIpv6 ))) {
1158
+ throw new InvalidParameterValueException ("Virtual Router is not a supported provider for the Shared network, hence router ip should not be provided" );
1159
+ }
1160
+
1108
1161
// Check if the network is domain specific
1109
1162
if (aclType == ACLType .Domain ) {
1110
1163
// only Admin can create domain with aclType=Domain
@@ -1216,6 +1269,8 @@ public Network createGuestNetwork(CreateNetworkCmd cmd) throws InsufficientCapac
1216
1269
}
1217
1270
}
1218
1271
1272
+ validateRouterIps (routerIp , routerIpv6 , startIP , endIP , gateway , netmask , startIPv6 , endIPv6 , ip6Cidr );
1273
+
1219
1274
if (isolatedPvlan != null && (zone .getNetworkType () != NetworkType .Advanced || ntwkOff .getGuestType () != Network .GuestType .Shared )) {
1220
1275
throw new InvalidParameterValueException ("Can only support create Private VLAN network with advance shared network!" );
1221
1276
}
@@ -1293,7 +1348,7 @@ && areServicesSupportedByNetworkOffering(ntwkOff.getId(), Service.SourceNat))) {
1293
1348
1294
1349
Network network = commitNetwork (networkOfferingId , gateway , startIP , endIP , netmask , networkDomain , vlanId , bypassVlanOverlapCheck , name , displayText , caller , physicalNetworkId , zoneId , domainId ,
1295
1350
isDomainSpecific , subdomainAccess , vpcId , startIPv6 , endIPv6 , ip6Gateway , ip6Cidr , displayNetwork , aclId , isolatedPvlan , ntwkOff , pNtwk , aclType , owner , cidr ,
1296
- createVlan , externalId );
1351
+ createVlan , externalId , routerIp , routerIpv6 );
1297
1352
1298
1353
// if the network offering has persistent set to true, implement the network
1299
1354
if (ntwkOff .getIsPersistent ()) {
@@ -1326,7 +1381,7 @@ private Network commitNetwork(final Long networkOfferingId, final String gateway
1326
1381
final String vlanId , final Boolean bypassVlanOverlapCheck , final String name , final String displayText , final Account caller , final Long physicalNetworkId , final Long zoneId , final Long domainId ,
1327
1382
final boolean isDomainSpecific , final Boolean subdomainAccessFinal , final Long vpcId , final String startIPv6 , final String endIPv6 , final String ip6Gateway ,
1328
1383
final String ip6Cidr , final Boolean displayNetwork , final Long aclId , final String isolatedPvlan , final NetworkOfferingVO ntwkOff , final PhysicalNetwork pNtwk ,
1329
- final ACLType aclType , final Account ownerFinal , final String cidr , final boolean createVlan , final String externalId ) throws InsufficientCapacityException , ResourceAllocationException {
1384
+ final ACLType aclType , final Account ownerFinal , final String cidr , final boolean createVlan , final String externalId , String routerIp , String routerIpv6 ) throws InsufficientCapacityException , ResourceAllocationException {
1330
1385
try {
1331
1386
Network network = Transaction .execute (new TransactionCallbackWithException <Network , Exception >() {
1332
1387
@ Override
@@ -1381,7 +1436,7 @@ public Network doInTransaction(TransactionStatus status) throws InsufficientCapa
1381
1436
}
1382
1437
1383
1438
network = _networkMgr .createGuestNetwork (networkOfferingId , name , displayText , gateway , cidr , vlanId , bypassVlanOverlapCheck , networkDomain , owner , sharedDomainId , pNtwk , zoneId ,
1384
- aclType , subdomainAccess , vpcId , ip6Gateway , ip6Cidr , displayNetwork , isolatedPvlan , externalId );
1439
+ aclType , subdomainAccess , vpcId , ip6Gateway , ip6Cidr , displayNetwork , isolatedPvlan , externalId , routerIp , routerIpv6 );
1385
1440
}
1386
1441
1387
1442
if (_accountMgr .isRootAdmin (caller .getId ()) && createVlan && network != null ) {
@@ -4363,7 +4418,7 @@ public Network doInTransaction(TransactionStatus status) throws ResourceAllocati
4363
4418
if (privateNetwork == null ) {
4364
4419
//create Guest network
4365
4420
privateNetwork = _networkMgr .createGuestNetwork (ntwkOffFinal .getId (), networkName , displayText , gateway , cidr , uriString , false , null , owner , null , pNtwk ,
4366
- pNtwk .getDataCenterId (), ACLType .Account , null , vpcId , null , null , true , null , null );
4421
+ pNtwk .getDataCenterId (), ACLType .Account , null , vpcId , null , null , true , null , null , null , null );
4367
4422
if (privateNetwork != null ) {
4368
4423
s_logger .debug ("Successfully created guest network " + privateNetwork );
4369
4424
} else {
0 commit comments