cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject [1/5] sdn hosted vpc gateways (using lswitch)
Date Wed, 18 Sep 2013 15:08:03 GMT
Updated Branches:
  refs/heads/master 62b0ad03c -> 2614b00c5


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2614b00c/server/src/com/cloud/network/NetworkServiceImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/NetworkServiceImpl.java b/server/src/com/cloud/network/NetworkServiceImpl.java
index eb63fe0..06c9526 100755
--- a/server/src/com/cloud/network/NetworkServiceImpl.java
+++ b/server/src/com/cloud/network/NetworkServiceImpl.java
@@ -18,6 +18,7 @@ package com.cloud.network;
 
 import java.net.Inet6Address;
 import java.net.InetAddress;
+import java.net.URI;
 import java.net.UnknownHostException;
 import java.security.InvalidParameterException;
 import java.sql.PreparedStatement;
@@ -1124,8 +1125,7 @@ public class NetworkServiceImpl extends ManagerBase implements  NetworkService {
         		} else {
         			ipv4 = true;
         		}
-        	}
-        	catch (UnknownHostException e) {
+            } catch (UnknownHostException e) {
         		s_logger.error("Unable to convert gateway IP to a InetAddress", e);
         		throw new InvalidParameterValueException("Gateway parameter is invalid");
         	}
@@ -3805,13 +3805,21 @@ public class NetworkServiceImpl extends ManagerBase implements  NetworkService {
 
     @Override @DB
     public Network createPrivateNetwork(String networkName, String displayText, long physicalNetworkId,
-                                        String vlan, String startIp, String endIp, String gateway, String netmask, long networkOwnerId, Long vpcId, Boolean sourceNat)
+            String broadcastUriString, String startIp, String endIp, String gateway, String netmask, long networkOwnerId, Long vpcId, Boolean sourceNat, Long networkOfferingId)
                     throws ResourceAllocationException, ConcurrentOperationException, InsufficientCapacityException {
 
         Account owner = _accountMgr.getAccount(networkOwnerId);
 
-        // Get system network offeirng
-        NetworkOfferingVO ntwkOff = findSystemNetworkOffering(NetworkOffering.SystemPrivateGatewayNetworkOffering);
+        // Get system network offering
+        NetworkOfferingVO ntwkOff = null;
+        if (networkOfferingId != null)
+        {
+            ntwkOff = _networkOfferingDao.findById(networkOfferingId);
+        }
+        if (ntwkOff == null)
+        {
+            ntwkOff = findSystemNetworkOffering(NetworkOffering.SystemPrivateGatewayNetworkOffering);
+        }
 
         // Validate physical network
         PhysicalNetwork pNtwk = _physicalNetworkDao.findById(physicalNetworkId);
@@ -3843,6 +3851,15 @@ public class NetworkServiceImpl extends ManagerBase implements  NetworkService {
 
         cidr = NetUtils.ipAndNetMaskToCidr(gateway, netmask);
 
+        URI uri = BroadcastDomainType.fromString(broadcastUriString);
+        String uriString = uri.toString();
+        BroadcastDomainType tiep = BroadcastDomainType.getSchemeValue(uri);
+        // numeric vlan or vlan uri are ok for now
+        // TODO make a test for any supported scheme
+        if (!(tiep == BroadcastDomainType.Vlan
+        || tiep == BroadcastDomainType.Lswitch)) {
+            throw new InvalidParameterValueException("unsupported type of broadcastUri specified: " + broadcastUriString);
+        }
 
         Transaction txn = Transaction.currentTxn();
         txn.start();
@@ -3851,18 +3868,18 @@ public class NetworkServiceImpl extends ManagerBase implements  NetworkService {
         DataCenterVO dc = _dcDao.lockRow(pNtwk.getDataCenterId(), true);
 
         //check if we need to create guest network
-        Network privateNetwork = _networksDao.getPrivateNetwork(BroadcastDomainType.Vlan.toUri(vlan).toString(), cidr,
-                networkOwnerId, pNtwk.getDataCenterId());
+        Network privateNetwork = _networksDao.getPrivateNetwork(uriString, cidr,
+                networkOwnerId, pNtwk.getDataCenterId(), null);
         if (privateNetwork == null) {
             //create Guest network
-            privateNetwork = _networkMgr.createGuestNetwork(ntwkOff.getId(), networkName, displayText, gateway, cidr, vlan,
+            privateNetwork = _networkMgr.createGuestNetwork(ntwkOff.getId(), networkName, displayText, gateway, cidr, uriString,
                     null, owner, null, pNtwk, pNtwk.getDataCenterId(), ACLType.Account, null, vpcId, null, null, true, null);
             s_logger.debug("Created private network " + privateNetwork);
         } else {
             s_logger.debug("Private network already exists: " + privateNetwork);
             //Do not allow multiple private gateways with same Vlan within a VPC
             if(vpcId.equals(privateNetwork.getVpcId())){
-                throw new InvalidParameterValueException("Private network for the vlan: " + vlan + " and cidr  "+ cidr +"  already exists " +
+                throw new InvalidParameterValueException("Private network for the vlan: " + uriString + " and cidr  "+ cidr +"  already exists " +
                         "for Vpc "+vpcId+" in zone " + _entityMgr.findById(DataCenter.class, pNtwk.getDataCenterId()).getName());
             }
         }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2614b00c/server/src/com/cloud/network/guru/DirectPodBasedNetworkGuru.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/guru/DirectPodBasedNetworkGuru.java b/server/src/com/cloud/network/guru/DirectPodBasedNetworkGuru.java
index 67ebef1..31bc021 100755
--- a/server/src/com/cloud/network/guru/DirectPodBasedNetworkGuru.java
+++ b/server/src/com/cloud/network/guru/DirectPodBasedNetworkGuru.java
@@ -102,11 +102,11 @@ public class DirectPodBasedNetworkGuru extends DirectNetworkGuru {
         if ("external".equalsIgnoreCase(dhcpStrategy)) {
             rsStrategy = ReservationStrategy.Create;
         }
-        
+
         if (nic != null && nic.getRequestedIpv4() != null) {
             throw new CloudRuntimeException("Does not support custom ip allocation at this time: " + nic);
         }
-       
+
         if (nic == null) {
             nic = new NicProfile(rsStrategy, null, null, null, null);
         } else if (nic.getIp4Address() == null) {
@@ -114,7 +114,7 @@ public class DirectPodBasedNetworkGuru extends DirectNetworkGuru {
         } else {
             nic.setStrategy(ReservationStrategy.Create);
         }
-        
+
         if (rsStrategy == ReservationStrategy.Create) {
             String mac = _networkModel.getNextAvailableMacAddressInNetwork(network.getId());
             nic.setMacAddress(mac);
@@ -139,24 +139,24 @@ public class DirectPodBasedNetworkGuru extends DirectNetworkGuru {
                 if (mapVO.getPodId() != dest.getPod().getId()) {
                     Transaction txn = Transaction.currentTxn();
                     txn.start();
-                    
+
                     //release the old ip here
                     _ipAddrMgr.markIpAsUnavailable(ipVO.getId());
                     _ipAddressDao.unassignIpAddress(ipVO.getId());
-                    
+
                     txn.commit();
-                    
+
                     nic.setIp4Address(null);
                     getNewIp = true;
                 }
             }
         }
-        
+
         if (getNewIp) {
             //we don't set reservationStrategy to Create because we need this method to be called again for the case when vm fails to deploy in Pod1, and we try to redeploy it in Pod2
             getIp(nic, dest.getPod(), vm, network);
         }
-        
+
         DataCenter dc = _dcDao.findById(network.getDataCenterId());
         nic.setDns1(dc.getDns1());
         nic.setDns2(dc.getDns2());
@@ -215,5 +215,5 @@ public class DirectPodBasedNetworkGuru extends DirectNetworkGuru {
         nic.setDns1(dc.getDns1());
         nic.setDns2(dc.getDns2());
     }
-    
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2614b00c/server/src/com/cloud/network/guru/ExternalGuestNetworkGuru.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/guru/ExternalGuestNetworkGuru.java b/server/src/com/cloud/network/guru/ExternalGuestNetworkGuru.java
index 55a33cc..7a7da68 100644
--- a/server/src/com/cloud/network/guru/ExternalGuestNetworkGuru.java
+++ b/server/src/com/cloud/network/guru/ExternalGuestNetworkGuru.java
@@ -78,10 +78,9 @@ public class ExternalGuestNetworkGuru extends GuestNetworkGuru {
     @Inject
     IpAddressManager _ipAddrMgr;
 
-
     public ExternalGuestNetworkGuru() {
         super();
-        _isolationMethods = new IsolationMethod[] { IsolationMethod.GRE, IsolationMethod.L3, IsolationMethod.VLAN };
+        _isolationMethods = new IsolationMethod[] {IsolationMethod.GRE, IsolationMethod.L3, IsolationMethod.VLAN};
     }
 
     @Override
@@ -101,15 +100,15 @@ public class ExternalGuestNetworkGuru extends GuestNetworkGuru {
             return false;
         }
     }
-    
+
     @Override
     public Network design(NetworkOffering offering, DeploymentPlan plan, Network userSpecified, Account owner) {
-    	
+
         if (Boolean.parseBoolean(_configDao.getValue(Config.OvsTunnelNetwork.key()))) {
             return null;
         }
 
-        NetworkVO config = (NetworkVO) super.design(offering, plan, userSpecified, owner);
+        NetworkVO config = (NetworkVO)super.design(offering, plan, userSpecified, owner);
         if (config == null) {
             return null;
         } else if (_networkModel.networkIsConfiguredForExternalNetworking(plan.getDataCenterId(), config.getId())) {
@@ -151,7 +150,8 @@ public class ExternalGuestNetworkGuru extends GuestNetworkGuru {
             }
 
             implemented.setBroadcastUri(BroadcastDomainType.Vlan.toUri(vlanTag));
-            ActionEventUtils.onCompletedActionEvent(CallContext.current().getCallingUserId(), config.getAccountId(), EventVO.LEVEL_INFO, EventTypes.EVENT_ZONE_VLAN_ASSIGN, "Assigned Zone Vlan: " + vnet + " Network Id: " + config.getId(), 0);
+            ActionEventUtils.onCompletedActionEvent(CallContext.current().getCallingUserId(), config.getAccountId(), EventVO.LEVEL_INFO, EventTypes.EVENT_ZONE_VLAN_ASSIGN,
+                    "Assigned Zone Vlan: " + vnet + " Network Id: " + config.getId(), 0);
         } else {
             vlanTag = Integer.parseInt(BroadcastDomainType.getValue(config.getBroadcastUri()));
             implemented.setBroadcastUri(config.getBroadcastUri());
@@ -195,20 +195,20 @@ public class ExternalGuestNetworkGuru extends GuestNetworkGuru {
         // Mask the destination address of all port forwarding rules in this network with the new guest VLAN offset
         List<PortForwardingRuleVO> pfRulesInNetwork = _pfRulesDao.listByNetwork(config.getId());
         for (PortForwardingRuleVO pfRule : pfRulesInNetwork) {
-        	if (pfRule.getDestinationIpAddress() != null) {
-        		long ipMask = getIpMask(pfRule.getDestinationIpAddress().addr(), cidrSize);
-        		String maskedDestinationIpAddress = NetUtils.long2Ip(newCidrAddress | ipMask);
-        		pfRule.setDestinationIpAddress(new Ip(maskedDestinationIpAddress));
-        		_pfRulesDao.update(pfRule.getId(), pfRule);
-        	}
+            if (pfRule.getDestinationIpAddress() != null) {
+                long ipMask = getIpMask(pfRule.getDestinationIpAddress().addr(), cidrSize);
+                String maskedDestinationIpAddress = NetUtils.long2Ip(newCidrAddress | ipMask);
+                pfRule.setDestinationIpAddress(new Ip(maskedDestinationIpAddress));
+                _pfRulesDao.update(pfRule.getId(), pfRule);
+            }
         }
         // Mask the destination address of all static nat rules in this network with the new guest VLAN offset
         // Here the private ip of the nic get updated. When secondary ip are present the gc will not triggered
-        List <IPAddressVO> ipAddrsOfNw = _ipAddressDao.listStaticNatPublicIps(config.getId());
-        for (IPAddressVO ip: ipAddrsOfNw) {
+        List<IPAddressVO> ipAddrsOfNw = _ipAddressDao.listStaticNatPublicIps(config.getId());
+        for (IPAddressVO ip : ipAddrsOfNw) {
             if (ip.getVmIp() != null) {
                 long ipMask = getIpMask(ip.getVmIp(), cidrSize);
-                String maskedVmIp =  NetUtils.long2Ip(newCidrAddress | ipMask);
+                String maskedVmIp = NetUtils.long2Ip(newCidrAddress | ipMask);
                 ip.setVmIp(maskedVmIp);
                 _ipAddressDao.update(ip.getId(), ip);
             }
@@ -224,10 +224,10 @@ public class ExternalGuestNetworkGuru extends GuestNetworkGuru {
         if (_networkModel.networkIsConfiguredForExternalNetworking(config.getDataCenterId(), config.getId()) && nic != null && nic.getRequestedIpv4() != null) {
             throw new CloudRuntimeException("Does not support custom ip allocation at this time: " + nic);
         }
-        
+
         NicProfile profile = super.allocate(config, nic, vm);
 
-    	boolean _isEnabled = Boolean.parseBoolean(_configDao.getValue(Config.OvsTunnelNetwork.key()));
+        boolean _isEnabled = Boolean.parseBoolean(_configDao.getValue(Config.OvsTunnelNetwork.key()));
         if (_isEnabled) {
             return null;
         }
@@ -243,14 +243,15 @@ public class ExternalGuestNetworkGuru extends GuestNetworkGuru {
         return profile;
     }
 
-    @Override @DB
+    @Override
+    @DB
     public void deallocate(Network config, NicProfile nic, VirtualMachineProfile vm) {
         super.deallocate(config, nic, vm);
 
         if (Boolean.parseBoolean(_configDao.getValue(Config.OvsTunnelNetwork.key()))) {
             return;
         }
-        
+
         if (_networkModel.networkIsConfiguredForExternalNetworking(config.getDataCenterId(), config.getId())) {
             nic.setIp4Address(null);
             nic.setGateway(null);
@@ -264,11 +265,11 @@ public class ExternalGuestNetworkGuru extends GuestNetworkGuru {
     public void reserve(NicProfile nic, Network config, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context)
             throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException {
         assert (nic.getReservationStrategy() == ReservationStrategy.Start) : "What can I do for nics that are not allocated at start? ";
-    	boolean _isEnabled = Boolean.parseBoolean(_configDao.getValue(Config.OvsTunnelNetwork.key()));
+        boolean _isEnabled = Boolean.parseBoolean(_configDao.getValue(Config.OvsTunnelNetwork.key()));
         if (_isEnabled) {
             return;
         }
-        
+
         DataCenter dc = _dcDao.findById(config.getDataCenterId());
 
         if (_networkModel.networkIsConfiguredForExternalNetworking(config.getDataCenterId(), config.getId())) {
@@ -305,16 +306,16 @@ public class ExternalGuestNetworkGuru extends GuestNetworkGuru {
         }
 
         NetworkVO network = _networkDao.findById(nic.getNetworkId());
-        
+
         if (network != null && _networkModel.networkIsConfiguredForExternalNetworking(network.getDataCenterId(), network.getId())) {
             return true;
         } else {
             return super.release(nic, vm, reservationId);
         }
     }
-    
+
     private long getIpMask(String ipAddress, long cidrSize) {
-    	return NetUtils.ip2Long(ipAddress) & ~(0xffffffffffffffffl << (32 - cidrSize));
+        return NetUtils.ip2Long(ipAddress) & ~(0xffffffffffffffffl << (32 - cidrSize));
     }
 
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2614b00c/server/src/com/cloud/network/guru/GuestNetworkGuru.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/guru/GuestNetworkGuru.java b/server/src/com/cloud/network/guru/GuestNetworkGuru.java
index e90b84b..20b0ce5 100755
--- a/server/src/com/cloud/network/guru/GuestNetworkGuru.java
+++ b/server/src/com/cloud/network/guru/GuestNetworkGuru.java
@@ -114,7 +114,7 @@ public abstract class GuestNetworkGuru extends AdapterBase implements NetworkGur
 
     // Currently set to anything except STT for the Nicira integration.
     protected IsolationMethod[] _isolationMethods;
-    
+
     String _defaultGateway;
     String _defaultCidr;
 
@@ -143,7 +143,7 @@ public abstract class GuestNetworkGuru extends AdapterBase implements NetworkGur
             // Can't tell if there is no physical network
             return false;
         }
-        
+
         List<String> methods = physicalNetwork.getIsolationMethods();
         if (methods.isEmpty()) {
             // The empty isolation method is assumed to be VLAN
@@ -151,16 +151,16 @@ public abstract class GuestNetworkGuru extends AdapterBase implements NetworkGur
             methods = new ArrayList<String>(1);
             methods.add("VLAN");
         }
-        
+
         for (IsolationMethod m : _isolationMethods) {
             if (methods.contains(m.toString())) {
                 return true;
             }
         }
-        
+
         return false;
     }
-    
+
     public IsolationMethod[] getIsolationMethods() {
         return _isolationMethods;
     }
@@ -215,7 +215,8 @@ public abstract class GuestNetworkGuru extends AdapterBase implements NetworkGur
         return network;
     }
 
-    @Override @DB
+    @Override
+    @DB
     public void deallocate(Network network, NicProfile nic, VirtualMachineProfile vm) {
         if (network.getSpecifyIpRanges()) {
             if (s_logger.isDebugEnabled()) {
@@ -233,7 +234,6 @@ public abstract class GuestNetworkGuru extends AdapterBase implements NetworkGur
             nic.deallocate();
         }
     }
-    
 
     public int getVlanOffset(long physicalNetworkId, int vlanTag) {
         PhysicalNetworkVO pNetwork = _physicalNetworkDao.findById(physicalNetworkId);
@@ -247,13 +247,13 @@ public abstract class GuestNetworkGuru extends AdapterBase implements NetworkGur
         Integer lowestVlanTag = null;
         List<Pair<Integer, Integer>> vnetList = pNetwork.getVnet();
         //finding the vlanrange in which the vlanTag lies.
-        for (Pair <Integer,Integer> vnet : vnetList){
-            if (vlanTag >= vnet.first() && vlanTag <= vnet.second()){
+        for (Pair<Integer, Integer> vnet : vnetList) {
+            if (vlanTag >= vnet.first() && vlanTag <= vnet.second()) {
                 lowestVlanTag = vnet.first();
             }
         }
         if (lowestVlanTag == null) {
-            throw new InvalidParameterValueException ("The vlan tag does not belong to any of the existing vlan ranges");
+            throw new InvalidParameterValueException("The vlan tag does not belong to any of the existing vlan ranges");
         }
         return vlanTag - lowestVlanTag;
     }
@@ -268,12 +268,12 @@ public abstract class GuestNetworkGuru extends AdapterBase implements NetworkGur
     }
 
     protected void allocateVnet(Network network, NetworkVO implemented, long dcId,
-    		long physicalNetworkId, String reservationId) throws InsufficientVirtualNetworkCapcityException {
+            long physicalNetworkId, String reservationId) throws InsufficientVirtualNetworkCapcityException {
         if (network.getBroadcastUri() == null) {
             String vnet = _dcDao.allocateVnet(dcId, physicalNetworkId, network.getAccountId(), reservationId, UseSystemGuestVlans.valueIn(network.getAccountId()));
             if (vnet == null) {
                 throw new InsufficientVirtualNetworkCapcityException("Unable to allocate vnet as a " +
-                		"part of network " + network + " implement ", DataCenter.class, dcId);
+                        "part of network " + network + " implement ", DataCenter.class, dcId);
             }
             implemented.setBroadcastUri(BroadcastDomainType.Vlan.toUri(vnet));
             ActionEventUtils.onCompletedActionEvent(CallContext.current().getCallingUserId(), network.getAccountId(),
@@ -282,7 +282,7 @@ public abstract class GuestNetworkGuru extends AdapterBase implements NetworkGur
             implemented.setBroadcastUri(network.getBroadcastUri());
         }
     }
-    
+
     @Override
     public Network implement(Network network, NetworkOffering offering, DeployDestination dest,
             ReservationContext context) throws InsufficientVirtualNetworkCapcityException {
@@ -292,7 +292,7 @@ public abstract class GuestNetworkGuru extends AdapterBase implements NetworkGur
 
         //get physical network id
         Long physicalNetworkId = network.getPhysicalNetworkId();
-        
+
        // physical network id can be null in Guest Network in Basic zone, so locate the physical network
        if (physicalNetworkId == null) {
            physicalNetworkId = _networkModel.findPhysicalNetworkId(dcId, offering.getTags(), offering.getTrafficType());
@@ -317,10 +317,10 @@ public abstract class GuestNetworkGuru extends AdapterBase implements NetworkGur
     @Override
     public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfile vm)
             throws InsufficientVirtualNetworkCapcityException,
-    InsufficientAddressCapacityException {
+            InsufficientAddressCapacityException {
 
         assert (network.getTrafficType() == TrafficType.Guest) : "Look at my name!  Why are you calling" +
-        		" me when the traffic type is : " + network.getTrafficType();
+                " me when the traffic type is : " + network.getTrafficType();
 
         if (nic == null) {
             nic = new NicProfile(ReservationStrategy.Start, null, null, null, null);
@@ -350,7 +350,7 @@ public abstract class GuestNetworkGuru extends AdapterBase implements NetworkGur
                         }
                     }
                 }
-                
+
                 if (isGateway) {
                     guestIp = network.getGateway();
                 } else {
@@ -410,10 +410,10 @@ public abstract class GuestNetworkGuru extends AdapterBase implements NetworkGur
 
     @Override
     public void shutdown(NetworkProfile profile, NetworkOffering offering) {
-        
+
         if (profile.getBroadcastDomainType() == BroadcastDomainType.Vlan &&
         		profile.getBroadcastUri() != null && !offering.getSpecifyVlan()) {
-        s_logger.debug("Releasing vnet for the network id=" + profile.getId());
+            s_logger.debug("Releasing vnet for the network id=" + profile.getId());
             _dcDao.releaseVnet(BroadcastDomainType.getValue(profile.getBroadcastUri()), profile.getDataCenterId(),
                     profile.getPhysicalNetworkId(), profile.getAccountId(), profile.getReservationId());
             ActionEventUtils.onCompletedActionEvent(CallContext.current().getCallingUserId(), profile.getAccountId(),

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2614b00c/server/src/com/cloud/network/guru/PrivateNetworkGuru.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/guru/PrivateNetworkGuru.java b/server/src/com/cloud/network/guru/PrivateNetworkGuru.java
index 12dce85..11e2c05 100644
--- a/server/src/com/cloud/network/guru/PrivateNetworkGuru.java
+++ b/server/src/com/cloud/network/guru/PrivateNetworkGuru.java
@@ -65,7 +65,7 @@ public class PrivateNetworkGuru extends AdapterBase implements NetworkGuru {
     protected NetworkModel _networkMgr;
     @Inject
     EntityManager _entityMgr;
-    
+
     private static final TrafficType[] _trafficTypes = {TrafficType.Guest};
 
     protected PrivateNetworkGuru() {
@@ -106,7 +106,16 @@ public class PrivateNetworkGuru extends AdapterBase implements NetworkGuru {
             return null;
         }
 
-        NetworkVO network = new NetworkVO(offering.getTrafficType(), Mode.Static, BroadcastDomainType.Vlan, offering.getId(),
+        BroadcastDomainType broadcastType;
+        if (userSpecified != null)
+        {
+            broadcastType = userSpecified.getBroadcastDomainType();
+        }
+        else
+        {
+            broadcastType = BroadcastDomainType.Vlan;
+        }
+        NetworkVO network = new NetworkVO(offering.getTrafficType(), Mode.Static, broadcastType, offering.getId(),
                 State.Allocated, plan.getDataCenterId(), plan.getPhysicalNetworkId());
         if (userSpecified != null) {
             if ((userSpecified.getCidr() == null && userSpecified.getGateway() != null) ||
@@ -127,7 +136,7 @@ public class PrivateNetworkGuru extends AdapterBase implements NetworkGuru {
             }
         } else {
             throw new CloudRuntimeException("Can't design network " + network + "; netmask/gateway must be passed in");
-           
+
         }
 
         return network;
@@ -138,19 +147,18 @@ public class PrivateNetworkGuru extends AdapterBase implements NetworkGuru {
         if (s_logger.isDebugEnabled()) {
             s_logger.debug("Deallocate network: networkId: " + nic.getNetworkId() + ", ip: " + nic.getIp4Address());
         }
-        
+
         PrivateIpVO ip = _privateIpDao.findByIpAndSourceNetworkId(nic.getNetworkId(), nic.getIp4Address());
         if (ip != null) {
             _privateIpDao.releaseIpAddress(nic.getIp4Address(), nic.getNetworkId());
         }
         nic.deallocate();
     }
-    
-    
+
     @Override
     public Network implement(Network network, NetworkOffering offering, DeployDestination dest,
             ReservationContext context) throws InsufficientVirtualNetworkCapcityException {
-        
+
         return network;
     }
 
@@ -162,11 +170,11 @@ public class PrivateNetworkGuru extends AdapterBase implements NetworkGuru {
         if (!canHandle(offering, dc)) {
             return null;
         }
-        
+
         if (nic == null) {
             nic = new NicProfile(ReservationStrategy.Create, null, null, null, null);
         }
-        
+
         getIp(nic, dc, network);
 
         if (nic.getIp4Address() == null) {
@@ -177,10 +185,9 @@ public class PrivateNetworkGuru extends AdapterBase implements NetworkGuru {
 
         return nic;
     }
-    
-    
+
     protected void getIp(NicProfile nic, DataCenter dc, Network network)
-            throws InsufficientVirtualNetworkCapcityException,InsufficientAddressCapacityException {
+            throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException {
         if (nic.getIp4Address() == null) {
             PrivateIpVO ipVO = _privateIpDao.allocateIpAddress(network.getDataCenterId(), network.getId(), null);
             String vlanTag = BroadcastDomainType.getValue(network.getBroadcastUri());
@@ -191,18 +198,17 @@ public class PrivateNetworkGuru extends AdapterBase implements NetworkGuru {
             nic.setIp4Address(ip.getIpAddress());
             nic.setGateway(ip.getGateway());
             nic.setNetmask(ip.getNetmask());
-            nic.setIsolationUri(IsolationType.Vlan.toUri(ip.getVlanTag()));
-            nic.setBroadcastUri(IsolationType.Vlan.toUri(ip.getVlanTag()));
+            nic.setIsolationUri(IsolationType.Vlan.toUri(ip.getBroadcastUri()));
+            nic.setBroadcastUri(IsolationType.Vlan.toUri(ip.getBroadcastUri()));
             nic.setBroadcastType(BroadcastDomainType.Vlan);
             nic.setFormat(AddressFormat.Ip4);
-            nic.setReservationId(String.valueOf(ip.getVlanTag()));
+            nic.setReservationId(String.valueOf(ip.getBroadcastUri()));
             nic.setMacAddress(ip.getMacAddress());
         }
 
         nic.setDns1(dc.getDns1());
         nic.setDns2(dc.getDns2());
     }
-    
 
     @Override
     public void updateNicProfile(NicProfile profile, Network network) {
@@ -230,7 +236,7 @@ public class PrivateNetworkGuru extends AdapterBase implements NetworkGuru {
 
     @Override
     public void shutdown(NetworkProfile profile, NetworkOffering offering) {
-        
+
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2614b00c/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
index 566f1e4..ea2d7c4 100644
--- a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
+++ b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
@@ -433,7 +433,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
             for (final PublicIpAddress ipAddr : ipAddrList) {
                 boolean add = (ipAddr.getState() == IpAddress.State.Releasing ? false : true);
                 
-                String macAddress = vlanMacAddress.get(ipAddr.getVlanTag());
+                String macAddress = vlanMacAddress.get(BroadcastDomainType.getValue(BroadcastDomainType.fromString(ipAddr.getVlanTag())));
                 
                 IpAddressTO ip = new IpAddressTO(ipAddr.getAccountId(), ipAddr.getAddress().addr(), add, false,
                         ipAddr.isSourceNat(), ipAddr.getVlanTag(), ipAddr.getGateway(), ipAddr.getNetmask(), macAddress,
@@ -580,7 +580,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
                                 " as its nic is already gone from VPC router " + router);
                     } else {
                         macAddress = nic.getMacAddress();
-                        vlanMacAddress.put(ipAddr.getVlanTag(), macAddress);
+                        vlanMacAddress.put(BroadcastDomainType.getValue(BroadcastDomainType.fromString(ipAddr.getVlanTag())), macAddress);
                         ipsToSend.add(ipAddr);
                     }
                 }
@@ -653,7 +653,6 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
         });
     }
 
-    
     protected boolean sendNetworkACLs(VirtualRouter router, List<? extends NetworkACLItem> rules, long guestNetworkId, boolean isPrivateGateway)
             throws ResourceUnavailableException {
         Commands cmds = new Commands(Command.OnError.Continue);
@@ -1118,7 +1117,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
         // Ensure that in multiple vlans case we first send all ip addresses of vlan1, then all ip addresses of vlan2, etc..
         Map<String, ArrayList<PrivateIpAddress>> vlanIpMap = new HashMap<String, ArrayList<PrivateIpAddress>>();
         for (final PrivateIpAddress ipAddress : ips) {
-            String vlanTag = ipAddress.getVlanTag();
+            String vlanTag = ipAddress.getBroadcastUri();
             ArrayList<PrivateIpAddress> ipList = vlanIpMap.get(vlanTag);
             if (ipList == null) {
                 ipList = new ArrayList<PrivateIpAddress>();
@@ -1136,7 +1135,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
             for (final PrivateIpAddress ipAddr : ipAddrList) {
                 Network network = _networkModel.getNetwork(ipAddr.getNetworkId());
                 IpAddressTO ip = new IpAddressTO(Account.ACCOUNT_ID_SYSTEM, ipAddr.getIpAddress(), add, false,
-                        ipAddr.getSourceNat(), ipAddr.getVlanTag(), ipAddr.getGateway(), ipAddr.getNetmask(), ipAddr.getMacAddress(),
+                        ipAddr.getSourceNat(), ipAddr.getBroadcastUri(), ipAddr.getGateway(), ipAddr.getNetmask(), ipAddr.getMacAddress(),
                         null, false);
 
                 ip.setTrafficType(network.getTrafficType());
@@ -1210,7 +1209,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
                 publicVlans.add(publicIp.getVlanTag());
             }
         }
-        
+
         return networks;
     }
 
@@ -1229,20 +1228,21 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
                     _networkModel.isSecurityGroupSupportedInNetwork(privateNetwork),
                     _networkModel.getNetworkTag(vm.getHypervisorType(), privateNetwork));
         } else {
-            String vlanTag = BroadcastDomainType.getValue(privateNetwork.getBroadcastUri());
             String netmask = NetUtils.getCidrNetmask(privateNetwork.getCidr());
-            PrivateIpAddress ip = new PrivateIpAddress(ipVO, vlanTag, privateNetwork.getGateway(), netmask,
+            PrivateIpAddress ip = new PrivateIpAddress(ipVO, privateNetwork.getBroadcastUri().toString(), privateNetwork.getGateway(), netmask,
                     NetUtils.long2Mac(NetUtils.createSequenceBasedMacAddress(ipVO.getMacAddress())));
             
-            URI netUri = BroadcastDomainType.fromString(ip.getVlanTag());
+            URI netUri = BroadcastDomainType.fromString(ip.getBroadcastUri());
             privateNicProfile.setIp4Address(ip.getIpAddress());
             privateNicProfile.setGateway(ip.getGateway());
             privateNicProfile.setNetmask(ip.getNetmask());
             privateNicProfile.setIsolationUri(netUri);
             privateNicProfile.setBroadcastUri(netUri);
-            privateNicProfile.setBroadcastType(BroadcastDomainType.Vlan);
+            // can we solve this in setBroadcastUri()???
+            // or more plugable construct is desirable
+            privateNicProfile.setBroadcastType(BroadcastDomainType.getSchemeValue(netUri));
             privateNicProfile.setFormat(AddressFormat.Ip4);
-            privateNicProfile.setReservationId(String.valueOf(ip.getVlanTag()));
+            privateNicProfile.setReservationId(String.valueOf(ip.getBroadcastUri()));
             privateNicProfile.setMacAddress(ip.getMacAddress());
         }
        

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2614b00c/server/src/com/cloud/network/vpc/PrivateGatewayProfile.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/vpc/PrivateGatewayProfile.java b/server/src/com/cloud/network/vpc/PrivateGatewayProfile.java
index 74ce002..421c2ab 100644
--- a/server/src/com/cloud/network/vpc/PrivateGatewayProfile.java
+++ b/server/src/com/cloud/network/vpc/PrivateGatewayProfile.java
@@ -67,8 +67,8 @@ public class PrivateGatewayProfile implements PrivateGateway {
     }
 
     @Override
-    public String getVlanTag() {
-        return vpcGateway.getVlanTag();
+    public String getBroadcastUri() {
+        return vpcGateway.getBroadcastUri();
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2614b00c/server/src/com/cloud/network/vpc/PrivateIpAddress.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/vpc/PrivateIpAddress.java b/server/src/com/cloud/network/vpc/PrivateIpAddress.java
index 2f3cf53..a1b794b 100644
--- a/server/src/com/cloud/network/vpc/PrivateIpAddress.java
+++ b/server/src/com/cloud/network/vpc/PrivateIpAddress.java
@@ -19,7 +19,7 @@ package com.cloud.network.vpc;
 
 
 public class PrivateIpAddress implements PrivateIp{
-    String vlanTag;
+    String broadcastUri;
     String gateway;
     String netmask;
     String ipAddress;
@@ -29,16 +29,16 @@ public class PrivateIpAddress implements PrivateIp{
     
     /**
      * @param privateIp
-     * @param vlanTag
+     * @param broadcastUri
      * @param gateway
      * @param netmask
      * @param macAddress TODO
      * @param physicalNetworkId TODO
      */
-    public PrivateIpAddress(PrivateIpVO privateIp, String vlanTag, String gateway, String netmask, String macAddress) {
+    public PrivateIpAddress(PrivateIpVO privateIp, String broadcastUri, String gateway, String netmask, String macAddress) {
         super();
         this.ipAddress = privateIp.getIpAddress();
-        this.vlanTag = vlanTag;
+        this.broadcastUri = broadcastUri;
         this.gateway = gateway;
         this.netmask = netmask;
         this.macAddress = macAddress;
@@ -47,8 +47,8 @@ public class PrivateIpAddress implements PrivateIp{
     }
 
     @Override
-    public String getVlanTag() {
-        return vlanTag;
+    public String getBroadcastUri() {
+        return broadcastUri;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2614b00c/server/src/com/cloud/network/vpc/VpcManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/vpc/VpcManagerImpl.java b/server/src/com/cloud/network/vpc/VpcManagerImpl.java
index 6cace7e..a07b9ef 100644
--- a/server/src/com/cloud/network/vpc/VpcManagerImpl.java
+++ b/server/src/com/cloud/network/vpc/VpcManagerImpl.java
@@ -45,6 +45,7 @@ import com.cloud.configuration.Config;
 import com.cloud.configuration.ConfigurationManager;
 import com.cloud.configuration.Resource.ResourceType;
 import com.cloud.dc.DataCenter;
+import com.cloud.dc.DataCenterVO;
 import com.cloud.dc.Vlan.VlanType;
 import com.cloud.dc.VlanVO;
 import com.cloud.dc.dao.DataCenterDao;
@@ -297,6 +298,9 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
         Map<Network.Service, Set<Network.Provider>> svcProviderMap = new HashMap<Network.Service, Set<Network.Provider>>();
         Set<Network.Provider> defaultProviders = new HashSet<Network.Provider>();
         defaultProviders.add(Provider.VPCVirtualRouter);
+        // Just here for 4.1, replaced by commit 836ce6c1 in newer versions
+        Set<Network.Provider> sdnProviders = new HashSet<Network.Provider>();
+        sdnProviders.add(Provider.NiciraNvp);
 
         boolean sourceNatSvc = false;
         boolean firewallSvs = false;
@@ -308,7 +312,13 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
                 throw new InvalidParameterValueException("Service " + serviceName + " is not supported in VPC");
             }
 
-            svcProviderMap.put(service, defaultProviders);
+            if (service == Service.Connectivity) {
+                s_logger.debug("Applying Connectivity workaround, setting provider to NiciraNvp");
+                svcProviderMap.put(service, sdnProviders);
+            }
+            else {
+                svcProviderMap.put(service, defaultProviders);
+            }
             if (service == Service.NetworkACL) {
                 firewallSvs = true;
             }
@@ -319,7 +329,8 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
         }
         
         if (!sourceNatSvc) {
-            throw new InvalidParameterValueException("SourceNat service is required by VPC offering");
+            s_logger.debug("Automatically adding source nat service to the list of VPC services");
+            svcProviderMap.put(Service.SourceNat, defaultProviders);
         }
         
         if (!firewallSvs) {
@@ -1327,7 +1338,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
         List<VpcGatewayVO> gateways = _vpcGatewayDao.listByVpcIdAndType(vpcId, VpcGateway.Type.Private);
 
         if (gateways != null) {
-            List<PrivateGateway> pvtGateway = new ArrayList();
+            List<PrivateGateway> pvtGateway = new ArrayList<PrivateGateway>();
             for (VpcGatewayVO gateway: gateways) {
                 pvtGateway.add(getPrivateGatewayProfile(gateway));
             }
@@ -1355,8 +1366,8 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
     @Override
     @DB
     @ActionEvent(eventType = EventTypes.EVENT_PRIVATE_GATEWAY_CREATE, eventDescription = "creating vpc private gateway", create=true)
-    public PrivateGateway createVpcPrivateGateway(long vpcId, Long physicalNetworkId, String vlan, String ipAddress,
-           String gateway, String netmask, long gatewayOwnerId, Boolean isSourceNat, Long aclId) throws ResourceAllocationException,
+    public PrivateGateway createVpcPrivateGateway(long vpcId, Long physicalNetworkId, String broadcastUri, String ipAddress,
+            String gateway, String netmask, long gatewayOwnerId, Long networkOfferingId, Boolean isSourceNat, Long aclId) throws ResourceAllocationException,
             ConcurrentOperationException, InsufficientCapacityException {
         
         //Validate parameters
@@ -1367,22 +1378,58 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
             throw ex;
         }
 
+        PhysicalNetwork physNet = null;
         //Validate physical network
         if (physicalNetworkId == null) {
             List<? extends PhysicalNetwork> pNtwks = _ntwkModel.getPhysicalNtwksSupportingTrafficType(vpc.getZoneId(), TrafficType.Guest);
             if (pNtwks.isEmpty() || pNtwks.size() != 1) {
                 throw new InvalidParameterValueException("Physical network can't be determined; pass physical network id");
             }
-            physicalNetworkId = pNtwks.get(0).getId();
+            physNet = pNtwks.get(0);
+            physicalNetworkId = physNet.getId();
+        }
+        
+        if (physNet == null) {
+            physNet = _entityMgr.findById(PhysicalNetwork.class,physicalNetworkId);
         }
+        Long dcId = physNet.getDataCenterId();
         
         Transaction txn = Transaction.currentTxn();
         txn.start();
         s_logger.debug("Creating Private gateway for VPC " + vpc);
-        //1) create private network
-        String networkName = "vpc-" + vpc.getName() + "-privateNetwork";
-        Network privateNtwk = _ntwkSvc.createPrivateNetwork(networkName, networkName, physicalNetworkId,
-                vlan, ipAddress, null, gateway, netmask, gatewayOwnerId, vpcId, isSourceNat);
+        //1) create private network unless it is existing and lswitch'd
+        Network privateNtwk = null;
+        if (BroadcastDomainType.getSchemeValue(BroadcastDomainType.fromString(broadcastUri)) == BroadcastDomainType.Lswitch) {
+            String cidr = NetUtils.ipAndNetMaskToCidr(gateway, netmask);
+
+            privateNtwk = _ntwkDao.getPrivateNetwork(broadcastUri, cidr,
+                    gatewayOwnerId, dcId, networkOfferingId);
+            s_logger.info("found and using existing network for vpc " + vpc + ": " + broadcastUri);
+        }
+        if (privateNtwk == null) {
+            s_logger.info("creating new network for vpc " + vpc + " using broadcast uri: " + broadcastUri);
+            String networkName = "vpc-" + vpc.getName() + "-privateNetwork";
+            privateNtwk = _ntwkSvc.createPrivateNetwork(networkName, networkName, physicalNetworkId, 
+                broadcastUri, ipAddress, null, gateway, netmask, gatewayOwnerId, vpcId, isSourceNat, networkOfferingId);
+        } else { // create the nic/ip as createPrivateNetwork doesn''t do that work for us now
+            DataCenterVO dc = _dcDao.lockRow(physNet.getDataCenterId(), true);
+
+            //add entry to private_ip_address table
+            PrivateIpVO privateIp = _privateIpDao.findByIpAndSourceNetworkId(privateNtwk.getId(), ipAddress);
+            if (privateIp != null) {
+                throw new InvalidParameterValueException("Private ip address " + ipAddress + " already used for private gateway" +
+                        " in zone " + _entityMgr.findById(DataCenter.class,dcId).getName());
+            }
+
+            Long mac = dc.getMacAddress();
+            Long nextMac = mac + 1;
+            dc.setMacAddress(nextMac);
+
+            privateIp = new PrivateIpVO(ipAddress, privateNtwk.getId(), nextMac, vpcId, true);
+            _privateIpDao.persist(privateIp);
+
+            _dcDao.update(dc.getId(), dc);
+        }
 
         long networkAclId = NetworkACL.DEFAULT_DENY;
         if (aclId != null) {
@@ -1399,7 +1446,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
 
         //2) create gateway entry
         VpcGatewayVO gatewayVO = new VpcGatewayVO(ipAddress, VpcGateway.Type.Private, vpcId, privateNtwk.getDataCenterId(),
-                privateNtwk.getId(), vlan, gateway, netmask, vpc.getAccountId(), vpc.getDomainId(), isSourceNat, networkAclId);
+                privateNtwk.getId(), broadcastUri, gateway, netmask, vpc.getAccountId(), vpc.getDomainId(), isSourceNat, networkAclId);
         _vpcGatewayDao.persist(gatewayVO);
         
         s_logger.debug("Created vpc gateway entry " + gatewayVO);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2614b00c/server/test/com/cloud/network/CreatePrivateNetworkTest.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/network/CreatePrivateNetworkTest.java b/server/test/com/cloud/network/CreatePrivateNetworkTest.java
index ed9efd6..0e57b02 100644
--- a/server/test/com/cloud/network/CreatePrivateNetworkTest.java
+++ b/server/test/com/cloud/network/CreatePrivateNetworkTest.java
@@ -24,6 +24,8 @@ import static org.mockito.Matchers.anyString;
 import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.when;
 
+import java.util.ArrayList;
+import java.util.List;
 import java.util.UUID;
 
 import junit.framework.Assert;
@@ -61,8 +63,9 @@ import com.cloud.user.AccountManager;
 import com.cloud.user.AccountVO;
 import com.cloud.utils.db.DB;
 import com.cloud.utils.db.Transaction;
+import com.cloud.utils.exception.CloudRuntimeException;
 
-@Ignore("Requires database to be set up")
+//@Ignore("Requires database to be set up")
 public class CreatePrivateNetworkTest {
 
     private static final Logger s_logger = Logger
@@ -109,6 +112,10 @@ public class CreatePrivateNetworkTest {
                 false, false, false, false);
         when(networkService._networkOfferingDao.findById(anyLong()))
                 .thenReturn(ntwkOff);
+        List<NetworkOfferingVO>netofferlist = new ArrayList<NetworkOfferingVO>();
+        netofferlist.add(ntwkOff);
+        when(networkService._networkOfferingDao.listSystemNetworkOfferings())
+                .thenReturn(netofferlist);
 
         PhysicalNetworkVO physicalNetwork = new PhysicalNetworkVO(1L, 1L,
                 "2-5", "200", 1L, null, "testphysicalnetwork");
@@ -122,7 +129,7 @@ public class CreatePrivateNetworkTest {
                 .thenReturn(dc);
 
         when(networkService._networksDao.getPrivateNetwork(anyString(),
-                anyString(), eq(1L), eq(1L))).thenReturn(null);
+                anyString(), eq(1L), eq(1L), anyLong())).thenReturn(null);
 
         Network net = new NetworkVO(1L, TrafficType.Guest, Mode.None,
                 BroadcastDomainType.Vlan, 1L, 1L, 1L, 1L, "bla", "fake",
@@ -139,6 +146,7 @@ public class CreatePrivateNetworkTest {
 
         when(networkService._privateIpDao.findByIpAndSourceNetworkId(
                 net.getId(), "10.1.1.2")).thenReturn(null);
+        when(networkService._privateIpDao.findByIpAndSourceNetworkIdAndVpcId(eq(1L), anyString(), eq(1L))).thenReturn(null);
     }
 
     @Test
@@ -149,26 +157,26 @@ public class CreatePrivateNetworkTest {
         /* Network nw; */
         try {
             /* nw = */
-            networkService.createPrivateNetwork("bla", "fake", 1L, "vlan:1", "10.1.1.2", null, "10.1.1.1", "255.255.255.0", 1L, 1L, null);
+            networkService.createPrivateNetwork("bla", "fake", 1L, "vlan:1", "10.1.1.2", null, "10.1.1.1", "255.255.255.0", 1L, 1L, true, 1L);
             /* nw = */
-            networkService.createPrivateNetwork("bla", "fake", 1L, "lswitch:3", "10.1.1.2", null, "10.1.1.1", "255.255.255.0", 1L, 1L, null);
+            networkService.createPrivateNetwork("bla", "fake", 1L, "lswitch:3", "10.1.1.2", null, "10.1.1.1", "255.255.255.0", 1L, 1L, false, 1L);
             boolean invalid = false;
             boolean unsupported = false;
             try {
                 /* nw = */
-                networkService.createPrivateNetwork("bla", "fake", 1, "bla:2", "10.1.1.2", null, "10.1.1.1", "255.255.255.0", 1, 1L, null);
-            } catch (InvalidParameterValueException e) {
+                networkService.createPrivateNetwork("bla", "fake", 1, "bla:2", "10.1.1.2", null, "10.1.1.1", "255.255.255.0", 1, 1L, true, 1L);
+            } catch (CloudRuntimeException e) {
                 Assert.assertEquals("unexpected parameter exception",
-                        "unsupported type of broadcastUri specified: bla:2",
+                        "string 'bla:2' has an unknown BroadcastDomainType.",
                         e.getMessage());
                 invalid = true;
             }
             try {
                 /* nw = */
-                networkService.createPrivateNetwork("bla", "fake", 1, "mido:4", "10.1.1.2", null, "10.1.1.1", "255.255.255.0", 1, 1L, null);
+                networkService.createPrivateNetwork("bla", "fake", 1, "mido://4", "10.1.1.2", null, "10.1.1.1", "255.255.255.0", 1, 1L, false, 1L);
             } catch (InvalidParameterValueException e) {
                 Assert.assertEquals("unexpected parameter exception",
-                        "unsupported type of broadcastUri specified: mido:4",
+                        "unsupported type of broadcastUri specified: mido://4",
                         e.getMessage());
                 unsupported = true;
             }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2614b00c/server/test/com/cloud/vpc/MockNetworkManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/vpc/MockNetworkManagerImpl.java b/server/test/com/cloud/vpc/MockNetworkManagerImpl.java
index 003b774..35fde8e 100644
--- a/server/test/com/cloud/vpc/MockNetworkManagerImpl.java
+++ b/server/test/com/cloud/vpc/MockNetworkManagerImpl.java
@@ -640,7 +640,7 @@ public class MockNetworkManagerImpl extends ManagerBase implements NetworkOrches
      */
     @Override
     public Network createPrivateNetwork(String networkName, String displayText, long physicalNetworkId, String vlan,
-                                        String startIp, String endIP, String gateway, String netmask, long networkOwnerId, Long vpcId, Boolean sourceNat)
+            String startIp, String endIP, String gateway, String netmask, long networkOwnerId, Long vpcId, Boolean sourceNat, Long networkOfferingId)
             throws ResourceAllocationException, ConcurrentOperationException, InsufficientCapacityException {
         // TODO Auto-generated method stub
         return null;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2614b00c/server/test/com/cloud/vpc/dao/MockNetworkDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/vpc/dao/MockNetworkDaoImpl.java b/server/test/com/cloud/vpc/dao/MockNetworkDaoImpl.java
index ec1a017..145b6c5 100644
--- a/server/test/com/cloud/vpc/dao/MockNetworkDaoImpl.java
+++ b/server/test/com/cloud/vpc/dao/MockNetworkDaoImpl.java
@@ -328,7 +328,7 @@ public class MockNetworkDaoImpl extends GenericDaoBase<NetworkVO, Long> implemen
      * @see com.cloud.network.dao.NetworkDao#getPrivateNetwork(java.lang.String, java.lang.String, long, long)
      */
     @Override
-    public NetworkVO getPrivateNetwork(String broadcastUri, String cidr, long accountId, long zoneId) {
+    public NetworkVO getPrivateNetwork(String broadcastUri, String cidr, long accountId, long zoneId, Long netofferid) {
         // TODO Auto-generated method stub
         return null;
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2614b00c/utils/src/com/cloud/utils/net/NetUtils.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/net/NetUtils.java b/utils/src/com/cloud/utils/net/NetUtils.java
index 7a89103..1e72e22 100755
--- a/utils/src/com/cloud/utils/net/NetUtils.java
+++ b/utils/src/com/cloud/utils/net/NetUtils.java
@@ -26,10 +26,18 @@ import java.net.NetworkInterface;
 import java.net.SocketException;
 import java.net.URI;
 import java.net.UnknownHostException;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Formatter;
+import java.util.List;
+import java.util.Random;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.StringTokenizer;
+import java.util.TreeSet;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import org.apache.commons.lang.SystemUtils;
 import org.apache.log4j.Logger;
 
 import com.googlecode.ipv6.IPv6Address;
@@ -39,7 +47,6 @@ import com.googlecode.ipv6.IPv6Network;
 import com.cloud.utils.IteratorUtil;
 import com.cloud.utils.Pair;
 import com.cloud.utils.script.Script;
-import org.apache.commons.lang.SystemUtils;
 
 public class NetUtils {
     protected final static Logger s_logger = Logger.getLogger(NetUtils.class);
@@ -64,7 +71,7 @@ public class NetUtils {
     private final static Random _rand = new Random(System.currentTimeMillis());
 
     public static long createSequenceBasedMacAddress(long macAddress) {
-        return macAddress | 0x060000000000l | (((long) _rand.nextInt(32768) << 25) & 0x00fffe000000l);
+        return macAddress | 0x060000000000l | (((long)_rand.nextInt(32768) << 25) & 0x00fffe000000l);
     }
 
     public static String getHostName() {
@@ -131,7 +138,7 @@ public class NetUtils {
                         int prefixLength = address.getNetworkPrefixLength();
                         if (prefixLength < 32 && prefixLength > 0) {
                             String ip = ipFromInetAddress(addr);
-                            if(ip.equalsIgnoreCase(defaultHostIp))
+                            if (ip.equalsIgnoreCase(defaultHostIp))
                                 cidrList.add(ipAndNetMaskToCidr(ip, getCidrNetmask(prefixLength)));
                         }
                     }
@@ -146,16 +153,14 @@ public class NetUtils {
 
     private static boolean isWindows() {
         String os = System.getProperty("os.name");
-        if(os != null && os.startsWith("Windows"))
+        if (os != null && os.startsWith("Windows"))
             return true;
 
         return false;
     }
 
-
-
     public static String getDefaultHostIp() {
-        if(SystemUtils.IS_OS_WINDOWS) {
+        if (SystemUtils.IS_OS_WINDOWS) {
             Pattern pattern = Pattern.compile("\\s*0.0.0.0\\s*0.0.0.0\\s*(\\S*)\\s*(\\S*)\\s*");
             try {
                 Process result = Runtime.getRuntime().exec("route print -4");
@@ -163,15 +168,15 @@ public class NetUtils {
                         (new InputStreamReader(result.getInputStream()));
 
                 String line = output.readLine();
-                while(line != null){
+                while (line != null) {
                     Matcher matcher = pattern.matcher(line);
                     if (matcher.find()) {
                         return matcher.group(2);
                     }
                     line = output.readLine();
                 }
-            } catch( Exception e ) { 
-            }    	
+            } catch (Exception e) {
+            }
             return null;
         } else {
             NetworkInterface nic = null;
@@ -212,8 +217,6 @@ public class NetUtils {
         return defaultRouteList[7];
     }
 
-
-
     public static InetAddress getFirstNonLoopbackLocalInetAddress() {
         InetAddress[] addrs = getAllLocalInetAddresses();
         if (addrs != null) {
@@ -322,7 +325,7 @@ public class NetUtils {
             byte[] mac = ni.getHardwareAddress();
 
             for (int i = 0; i < mac.length; i++) {
-                macAddressAsLong |= ((long) (mac[i] & 0xff) << (mac.length - i - 1) * 8);
+                macAddressAsLong |= ((long)(mac[i] & 0xff) << (mac.length - i - 1) * 8);
             }
 
         } catch (SocketException e) {
@@ -451,7 +454,8 @@ public class NetUtils {
     public static String long2Mac(long macAddress) {
         StringBuilder result = new StringBuilder(17);
         Formatter formatter = new Formatter(result);
-        formatter.format("%02x:%02x:%02x:%02x:%02x:%02x", (macAddress >> 40) & 0xff, (macAddress >> 32) & 0xff, (macAddress >> 24) & 0xff, (macAddress >> 16) & 0xff, (macAddress >> 8) & 0xff,
+        formatter.format("%02x:%02x:%02x:%02x:%02x:%02x", (macAddress >> 40) & 0xff, (macAddress >> 32) & 0xff, (macAddress >> 24) & 0xff, (macAddress >> 16) & 0xff,
+                (macAddress >> 8) & 0xff,
                 (macAddress & 0xff));
 
         return result.toString();
@@ -593,7 +597,7 @@ public class NetUtils {
         if (st.countTokens() == 4) {
             try {
                 for (int i = 0; i < 4; i++) {
-                    bytes[i] = (byte) Integer.parseInt(st.nextToken());
+                    bytes[i] = (byte)Integer.parseInt(st.nextToken());
                 }
                 return InetAddress.getByAddress(address, bytes);
             } catch (NumberFormatException nfe) {
@@ -646,7 +650,7 @@ public class NetUtils {
         end = (end << (32 - size)) - 2;
         int maxIps = 255; // get 255 ips as maximum
         while (start <= end && maxIps > 0) {
-            if (!usedIps.contains(start)){
+            if (!usedIps.contains(start)) {
                 result.add(start);
                 maxIps--;
             }
@@ -686,7 +690,7 @@ public class NetUtils {
         long startNetMask = ip2Long(getCidrNetmask(size));
         long startIp = (cidr & startNetMask) + 1; //exclude the first ip since it isnt valid, e.g., 192.168.10.0
         int range = 1 << (32 - size); //e.g., /24 = 2^8 = 256
-        range = range -1; //exclude end of the range since that is the broadcast address, e.g., 192.168.10.255
+        range = range - 1; //exclude end of the range since that is the broadcast address, e.g., 192.168.10.255
 
         if (avoid.size() >= range) {
             return -1;
@@ -788,7 +792,7 @@ public class NetUtils {
         end++;
         end = (end << (32 - bits)) - 2;
 
-        return new String[] { long2Ip(start), long2Ip(end) };
+        return new String[] {long2Ip(start), long2Ip(end)};
 
     }
 
@@ -797,17 +801,18 @@ public class NetUtils {
         return new Pair<String, Integer>(tokens[0], Integer.parseInt(tokens[1]));
     }
 
-    public  static enum supersetOrSubset {
+    public static enum supersetOrSubset {
         isSuperset,
         isSubset,
         neitherSubetNorSuperset,
         sameSubnet,
         errorInCidrFormat
     }
-    public static supersetOrSubset isNetowrkASubsetOrSupersetOfNetworkB (String cidrA, String cidrB) {
+
+    public static supersetOrSubset isNetowrkASubsetOrSupersetOfNetworkB(String cidrA, String cidrB) {
         Long[] cidrALong = cidrToLong(cidrA);
         Long[] cidrBLong = cidrToLong(cidrB);
-        long shift =0;
+        long shift = 0;
         if (cidrALong == null || cidrBLong == null) {
             //implies error in the cidr format
             return supersetOrSubset.errorInCidrFormat;
@@ -825,7 +830,7 @@ public class NetUtils {
                 return supersetOrSubset.isSuperset;
             }
             else if (cidrALong[1] == cidrBLong[1]) {
-             //this implies both the cidrs are equal
+                //this implies both the cidrs are equal
                 return supersetOrSubset.sameSubnet;
             }
             // implies cidrA is subset of cidrB
@@ -867,7 +872,7 @@ public class NetUtils {
         }
         long numericNetmask = (0xffffffff >> (32 - cidrSizeNum)) << (32 - cidrSizeNum);
         long ipAddr = ip2Long(cidrAddress);
-        Long[] cidrlong = { ipAddr & numericNetmask, (long) cidrSizeNum };
+        Long[] cidrlong = {ipAddr & numericNetmask, (long)cidrSizeNum};
         return cidrlong;
 
     }
@@ -1008,7 +1013,6 @@ public class NetUtils {
         return Integer.toString(portRange[0]) + ":" + Integer.toString(portRange[1]);
     }
 
-
     public static boolean verifyDomainNameLabel(String hostName, boolean isHostName) {
         // must be between 1 and 63 characters long and may contain only the ASCII letters 'a' through 'z' (in a
         // case-insensitive manner),
@@ -1064,13 +1068,13 @@ public class NetUtils {
     }
 
     // Check if 2 CIDRs have exactly same IP Range
-    public static boolean isSameIpRange (String cidrA, String cidrB) {
+    public static boolean isSameIpRange(String cidrA, String cidrB) {
 
-        if(!NetUtils.isValidCIDR(cidrA)) {
+        if (!NetUtils.isValidCIDR(cidrA)) {
             s_logger.info("Invalid value of cidr " + cidrA);
             return false;
         }
-         if (!NetUtils.isValidCIDR(cidrB)) {
+        if (!NetUtils.isValidCIDR(cidrB)) {
             s_logger.info("Invalid value of cidr " + cidrB);
             return false;
         }
@@ -1079,18 +1083,19 @@ public class NetUtils {
 
         Long networkSizeFirst = Long.valueOf(cidrPairFirst[1]);
         Long networkSizeSecond = Long.valueOf(cidrPairSecond[1]);
-        String ipRangeFirst [] = NetUtils.getIpRangeFromCidr(cidrPairFirst[0], networkSizeFirst);
-        String ipRangeSecond [] = NetUtils.getIpRangeFromCidr(cidrPairFirst[0], networkSizeSecond);
+        String ipRangeFirst[] = NetUtils.getIpRangeFromCidr(cidrPairFirst[0], networkSizeFirst);
+        String ipRangeSecond[] = NetUtils.getIpRangeFromCidr(cidrPairFirst[0], networkSizeSecond);
 
         long startIpFirst = NetUtils.ip2Long(ipRangeFirst[0]);
         long endIpFirst = NetUtils.ip2Long(ipRangeFirst[1]);
         long startIpSecond = NetUtils.ip2Long(ipRangeSecond[0]);
         long endIpSecond = NetUtils.ip2Long(ipRangeSecond[1]);
-        if(startIpFirst == startIpSecond && endIpFirst == endIpSecond) {
+        if (startIpFirst == startIpSecond && endIpFirst == endIpSecond) {
             return true;
         }
         return false;
     }
+
     public static boolean validateGuestCidr(String cidr) {
         // RFC 1918 - The Internet Assigned Numbers Authority (IANA) has reserved the
         // following three blocks of the IP address space for private internets:
@@ -1120,7 +1125,7 @@ public class NetUtils {
         if (instanceName.contains("-") || instanceName.contains(" ") || instanceName.contains("+")) {
             s_logger.warn("Instance name can not contain hyphen, spaces and \"+\" char");
             return false;
-        } 
+        }
 
         return true;
     }
@@ -1181,7 +1186,7 @@ public class NetUtils {
 
     public static boolean validateIcmpType(long icmpType) {
         //Source - http://www.erg.abdn.ac.uk/~gorry/course/inet-pages/icmp-code.html
-        if(!(icmpType >=0 && icmpType <=255)) {
+        if (!(icmpType >= 0 && icmpType <= 255)) {
             s_logger.warn("impcType is not within 0-255 range");
             return false;
         }
@@ -1191,7 +1196,7 @@ public class NetUtils {
     public static boolean validateIcmpCode(long icmpCode) {
 
         //Source - http://www.erg.abdn.ac.uk/~gorry/course/inet-pages/icmp-code.html
-        if(!(icmpCode >=0 && icmpCode <=15)) {
+        if (!(icmpCode >= 0 && icmpCode <= 15)) {
             s_logger.warn("Icmp code should be within 0-15 range");
             return false;
         }
@@ -1199,172 +1204,172 @@ public class NetUtils {
         return true;
     }
 
-	public static boolean isValidIpv6(String ip) {
-		try {
-			IPv6Address address = IPv6Address.fromString(ip);
-		} catch (IllegalArgumentException ex) {
-			return false;
-		}
-		return true;
-	}
-
-	public static boolean isValidIp6Cidr(String ip6Cidr) {
-		try {
-			IPv6Network network = IPv6Network.fromString(ip6Cidr);
-		} catch (IllegalArgumentException ex) {
-			return false;
-		}
-		return true;
-	}
-
-	public static int getIp6CidrSize(String ip6Cidr) {
-		IPv6Network network = null;
-		try {
-			network = IPv6Network.fromString(ip6Cidr);
-		} catch (IllegalArgumentException ex) {
-			return 0;
-		}
-		return network.getNetmask().asPrefixLength();
-	}
-
-	// Can cover 127 bits
-	public static String getIp6FromRange(String ip6Range) {
-    	String[] ips = ip6Range.split("-");
-    	String startIp = ips[0];
-    	IPv6Address start = IPv6Address.fromString(startIp);
-    	BigInteger gap = countIp6InRange(ip6Range);
-    	BigInteger next = new BigInteger(gap.bitLength(), _rand);
-    	while (next.compareTo(gap) >= 0) {
-    		next = new BigInteger(gap.bitLength(), _rand);
-    	}
-    	BigInteger startInt = convertIPv6AddressToBigInteger(start);
-    	BigInteger resultInt = startInt.add(next);
-    	InetAddress resultAddr;
-		try {
-			resultAddr = InetAddress.getByAddress(resultInt.toByteArray());
-		} catch (UnknownHostException e) {
-			return null;
-		}
-    	IPv6Address ip = IPv6Address.fromInetAddress(resultAddr);
-    	return ip.toString();
-	}
-
-	//RFC3315, section 9.4
-	public static String getDuidLL(String macAddress) {
-		String duid = "00:03:00:01:" + macAddress;
-		return duid;
-	}
-	
-	private static BigInteger convertIPv6AddressToBigInteger(IPv6Address addr) {
-		InetAddress inetAddr;
-		try {
-			inetAddr = addr.toInetAddress();
-		} catch (UnknownHostException e) {
-			return null;
-		}
-		return new BigInteger(inetAddr.getAddress());
-	}
-	
-	// Can cover 127 bits
-	public static BigInteger countIp6InRange(String ip6Range) {
-		if (ip6Range == null) {
-			return null;
-		}
-    	String[] ips = ip6Range.split("-");
-    	String startIp = ips[0];
-    	String endIp = ips[0];
-    	if (ips.length > 1) {
-    		endIp = ips[1];
-    	}
-    	IPv6Address start, end;
-    	try {
-    		start = IPv6Address.fromString(startIp);
-    		end = IPv6Address.fromString(endIp);
-		} catch (IllegalArgumentException ex) {
-			return null;
-		}
-    	BigInteger startInt = convertIPv6AddressToBigInteger(start);
-    	BigInteger endInt = convertIPv6AddressToBigInteger(end);
-    	if (startInt.compareTo(endInt) > 0) {
-    		return null;
-    	}
-    	return endInt.subtract(startInt).add(BigInteger.ONE);
-	}
-
-	public static boolean isIp6InRange(String ip6, String ip6Range) {
-		if (ip6Range == null) {
-			return false;
-		}
-    	String[] ips = ip6Range.split("-");
-    	String startIp = ips[0];
-    	String endIp = null;
-    	if (ips.length > 1) {
-    		endIp = ips[1];
-    	}
-    	IPv6Address start = IPv6Address.fromString(startIp);
-    	IPv6Address end = IPv6Address.fromString(endIp);
-    	IPv6Address ip = IPv6Address.fromString(ip6);
-    	if (start.compareTo(ip) <= 0 && end.compareTo(ip) >= 0) {
-    		return true;
-    	}
-		return false;
-	}
-	
-	public static boolean isIp6InNetwork(String ip6, String ip6Cidr) {
-		IPv6Network network = null;
-		try {
-			network = IPv6Network.fromString(ip6Cidr);
-		} catch (IllegalArgumentException ex) {
-			return false;
-		}
-    	IPv6Address ip = IPv6Address.fromString(ip6);
-		return network.contains(ip);
-	}
-	
-	public static boolean isIp6RangeOverlap(String ipRange1, String ipRange2) {
-		String[] ips = ipRange1.split("-");
-    	String startIp1 = ips[0];
-    	String endIp1 = null;
-    	if (ips.length > 1) {
-    		endIp1 = ips[1];
-    	}
-    	IPv6Address start1 = IPv6Address.fromString(startIp1);
-    	IPv6Address end1 = IPv6Address.fromString(endIp1);
-    	IPv6AddressRange range1 = IPv6AddressRange.fromFirstAndLast(start1, end1);
-		ips = ipRange2.split("-");
-    	String startIp2 = ips[0];
-    	String endIp2 = null;
-    	if (ips.length > 1) {
-    		endIp2 = ips[1];
-    	}
-    	IPv6Address start2 = IPv6Address.fromString(startIp2);
-    	IPv6Address end2 = IPv6Address.fromString(endIp2);
-    	IPv6AddressRange range2 = IPv6AddressRange.fromFirstAndLast(start2, end2);
-    	return range1.overlaps(range2);
-	}
-
-	public static String getNextIp6InRange(String currentIp, String ipRange) {
-		String[] ips = ipRange.split("-");
-    	String startIp = ips[0];
-    	String endIp = null;
-    	if (ips.length > 1) {
-    		endIp = ips[1];
-    	}
-    	IPv6Address start = IPv6Address.fromString(startIp);
-    	IPv6Address end = IPv6Address.fromString(endIp);
-    	IPv6Address current = IPv6Address.fromString(currentIp); 
-    	IPv6Address result = null;
-    	if (current.equals(end)) {
-    		result = start;
-    	} else{
-    		result = current.add(1);
-    	}
-    	String resultIp = null;
-    	if (result != null) {
-    		resultIp = result.toString();
-    	}
-		return resultIp;
-	}
+    public static boolean isValidIpv6(String ip) {
+        try {
+            IPv6Address address = IPv6Address.fromString(ip);
+        } catch (IllegalArgumentException ex) {
+            return false;
+        }
+        return true;
+    }
+
+    public static boolean isValidIp6Cidr(String ip6Cidr) {
+        try {
+            IPv6Network network = IPv6Network.fromString(ip6Cidr);
+        } catch (IllegalArgumentException ex) {
+            return false;
+        }
+        return true;
+    }
+
+    public static int getIp6CidrSize(String ip6Cidr) {
+        IPv6Network network = null;
+        try {
+            network = IPv6Network.fromString(ip6Cidr);
+        } catch (IllegalArgumentException ex) {
+            return 0;
+        }
+        return network.getNetmask().asPrefixLength();
+    }
+
+    // Can cover 127 bits
+    public static String getIp6FromRange(String ip6Range) {
+        String[] ips = ip6Range.split("-");
+        String startIp = ips[0];
+        IPv6Address start = IPv6Address.fromString(startIp);
+        BigInteger gap = countIp6InRange(ip6Range);
+        BigInteger next = new BigInteger(gap.bitLength(), _rand);
+        while (next.compareTo(gap) >= 0) {
+            next = new BigInteger(gap.bitLength(), _rand);
+        }
+        BigInteger startInt = convertIPv6AddressToBigInteger(start);
+        BigInteger resultInt = startInt.add(next);
+        InetAddress resultAddr;
+        try {
+            resultAddr = InetAddress.getByAddress(resultInt.toByteArray());
+        } catch (UnknownHostException e) {
+            return null;
+        }
+        IPv6Address ip = IPv6Address.fromInetAddress(resultAddr);
+        return ip.toString();
+    }
+
+    //RFC3315, section 9.4
+    public static String getDuidLL(String macAddress) {
+        String duid = "00:03:00:01:" + macAddress;
+        return duid;
+    }
+
+    private static BigInteger convertIPv6AddressToBigInteger(IPv6Address addr) {
+        InetAddress inetAddr;
+        try {
+            inetAddr = addr.toInetAddress();
+        } catch (UnknownHostException e) {
+            return null;
+        }
+        return new BigInteger(inetAddr.getAddress());
+    }
+
+    // Can cover 127 bits
+    public static BigInteger countIp6InRange(String ip6Range) {
+        if (ip6Range == null) {
+            return null;
+        }
+        String[] ips = ip6Range.split("-");
+        String startIp = ips[0];
+        String endIp = ips[0];
+        if (ips.length > 1) {
+            endIp = ips[1];
+        }
+        IPv6Address start, end;
+        try {
+            start = IPv6Address.fromString(startIp);
+            end = IPv6Address.fromString(endIp);
+        } catch (IllegalArgumentException ex) {
+            return null;
+        }
+        BigInteger startInt = convertIPv6AddressToBigInteger(start);
+        BigInteger endInt = convertIPv6AddressToBigInteger(end);
+        if (startInt.compareTo(endInt) > 0) {
+            return null;
+        }
+        return endInt.subtract(startInt).add(BigInteger.ONE);
+    }
+
+    public static boolean isIp6InRange(String ip6, String ip6Range) {
+        if (ip6Range == null) {
+            return false;
+        }
+        String[] ips = ip6Range.split("-");
+        String startIp = ips[0];
+        String endIp = null;
+        if (ips.length > 1) {
+            endIp = ips[1];
+        }
+        IPv6Address start = IPv6Address.fromString(startIp);
+        IPv6Address end = IPv6Address.fromString(endIp);
+        IPv6Address ip = IPv6Address.fromString(ip6);
+        if (start.compareTo(ip) <= 0 && end.compareTo(ip) >= 0) {
+            return true;
+        }
+        return false;
+    }
+
+    public static boolean isIp6InNetwork(String ip6, String ip6Cidr) {
+        IPv6Network network = null;
+        try {
+            network = IPv6Network.fromString(ip6Cidr);
+        } catch (IllegalArgumentException ex) {
+            return false;
+        }
+        IPv6Address ip = IPv6Address.fromString(ip6);
+        return network.contains(ip);
+    }
+
+    public static boolean isIp6RangeOverlap(String ipRange1, String ipRange2) {
+        String[] ips = ipRange1.split("-");
+        String startIp1 = ips[0];
+        String endIp1 = null;
+        if (ips.length > 1) {
+            endIp1 = ips[1];
+        }
+        IPv6Address start1 = IPv6Address.fromString(startIp1);
+        IPv6Address end1 = IPv6Address.fromString(endIp1);
+        IPv6AddressRange range1 = IPv6AddressRange.fromFirstAndLast(start1, end1);
+        ips = ipRange2.split("-");
+        String startIp2 = ips[0];
+        String endIp2 = null;
+        if (ips.length > 1) {
+            endIp2 = ips[1];
+        }
+        IPv6Address start2 = IPv6Address.fromString(startIp2);
+        IPv6Address end2 = IPv6Address.fromString(endIp2);
+        IPv6AddressRange range2 = IPv6AddressRange.fromFirstAndLast(start2, end2);
+        return range1.overlaps(range2);
+    }
+
+    public static String getNextIp6InRange(String currentIp, String ipRange) {
+        String[] ips = ipRange.split("-");
+        String startIp = ips[0];
+        String endIp = null;
+        if (ips.length > 1) {
+            endIp = ips[1];
+        }
+        IPv6Address start = IPv6Address.fromString(startIp);
+        IPv6Address end = IPv6Address.fromString(endIp);
+        IPv6Address current = IPv6Address.fromString(currentIp);
+        IPv6Address result = null;
+        if (current.equals(end)) {
+            result = start;
+        } else {
+            result = current.add(1);
+        }
+        String resultIp = null;
+        if (result != null) {
+            resultIp = result.toString();
+        }
+        return resultIp;
+    }
 
     public static boolean isValidVlan(String vlan) {
         try {
@@ -1383,36 +1388,36 @@ public class NetUtils {
     // types of BroadcastDomainTypes
 	public static URI generateUriForPvlan(String primaryVlan, String isolatedPvlan) {
         return URI.create("pvlan://" + primaryVlan + "-i" + isolatedPvlan);
-	}
-	
-	public static String getPrimaryPvlanFromUri(URI uri) {
-		String[] vlans = uri.getHost().split("-");
-		if (vlans.length < 1) {
-			return null;
-		}
-		return vlans[0];
-	}
-	
-	public static String getIsolatedPvlanFromUri(URI uri) {
-		String[] vlans = uri.getHost().split("-");
-		if (vlans.length < 2) {
-			return null;
-		}
-		for (String vlan : vlans) {
-			if (vlan.startsWith("i")) {
-				return vlan.replace("i", " ").trim();
-			}
-		}
-		return null;
-	}
-
-	public static String generateMacOnIncrease(String baseMac, long l) {
-		long mac = mac2Long(baseMac);
-		if (l > 0xFFFFl) {
-			return null;
-		}
-		mac = mac + (l << 24);
-		mac = mac & 0x06FFFFFFFFFFl;
-		return long2Mac(mac);
-	}
+    }
+
+    public static String getPrimaryPvlanFromUri(URI uri) {
+        String[] vlans = uri.getHost().split("-");
+        if (vlans.length < 1) {
+            return null;
+        }
+        return vlans[0];
+    }
+
+    public static String getIsolatedPvlanFromUri(URI uri) {
+        String[] vlans = uri.getHost().split("-");
+        if (vlans.length < 2) {
+            return null;
+        }
+        for (String vlan : vlans) {
+            if (vlan.startsWith("i")) {
+                return vlan.replace("i", " ").trim();
+            }
+        }
+        return null;
+    }
+
+    public static String generateMacOnIncrease(String baseMac, long l) {
+        long mac = mac2Long(baseMac);
+        if (l > 0xFFFFl) {
+            return null;
+        }
+        mac = mac + (l << 24);
+        mac = mac & 0x06FFFFFFFFFFl;
+        return long2Mac(mac);
+    }
 }


Mime
View raw message