2525import javax .inject .Inject ;
2626import javax .naming .ConfigurationException ;
2727
28+ import org .apache .cloudstack .api .ApiConstants ;
29+ import org .apache .cloudstack .api .response .ExternalFirewallResponse ;
30+ import org .apache .cloudstack .network .ExternalNetworkDeviceManager .NetworkDevice ;
2831import org .apache .log4j .Logger ;
2932
3033import com .cloud .agent .AgentManager ;
4245import com .cloud .agent .api .to .IpAddressTO ;
4346import com .cloud .agent .api .to .PortForwardingRuleTO ;
4447import com .cloud .agent .api .to .StaticNatRuleTO ;
45- import org .apache .cloudstack .api .ApiConstants ;
4648import com .cloud .configuration .Config ;
4749import com .cloud .configuration .dao .ConfigurationDao ;
4850import com .cloud .dc .DataCenter ;
6062import com .cloud .host .HostVO ;
6163import com .cloud .host .dao .HostDao ;
6264import com .cloud .host .dao .HostDetailsDao ;
63- import org .apache .cloudstack .network .ExternalNetworkDeviceManager .NetworkDevice ;
6465import com .cloud .network .Networks .TrafficType ;
6566import com .cloud .network .dao .ExternalFirewallDeviceDao ;
6667import com .cloud .network .dao .ExternalFirewallDeviceVO ;
8081import com .cloud .network .dao .PhysicalNetworkVO ;
8182import com .cloud .network .dao .VpnUserDao ;
8283import com .cloud .network .rules .FirewallRule ;
84+ import com .cloud .network .rules .FirewallRule .Purpose ;
8385import com .cloud .network .rules .FirewallRuleVO ;
8486import com .cloud .network .rules .PortForwardingRule ;
8587import com .cloud .network .rules .StaticNat ;
86- import com .cloud .network .rules .FirewallRule .Purpose ;
8788import com .cloud .network .rules .dao .PortForwardingRulesDao ;
8889import com .cloud .offering .NetworkOffering ;
8990import com .cloud .offerings .dao .NetworkOfferingDao ;
9293import com .cloud .resource .ResourceStateAdapter ;
9394import com .cloud .resource .ServerResource ;
9495import com .cloud .resource .UnableDeleteHostException ;
95- import org .apache .cloudstack .api .response .ExternalFirewallResponse ;
9696import com .cloud .user .Account ;
9797import com .cloud .user .AccountManager ;
9898import com .cloud .user .dao .AccountDao ;
105105import com .cloud .utils .exception .CloudRuntimeException ;
106106import com .cloud .utils .net .NetUtils ;
107107import com .cloud .utils .net .UrlUtil ;
108- import com .cloud .vm .Nic .ReservationStrategy ;
109- import com .cloud .vm .Nic .State ;
110108import com .cloud .vm .NicVO ;
109+ import com .cloud .vm .Nic .ReservationStrategy ;
111110import com .cloud .vm .dao .DomainRouterDao ;
112111import com .cloud .vm .dao .NicDao ;
113112
@@ -116,7 +115,8 @@ public abstract class ExternalFirewallDeviceManagerImpl extends AdapterBase impl
116115 @ Inject HostDao _hostDao ;
117116 @ Inject NetworkServiceMapDao _ntwkSrvcProviderDao ;
118117 @ Inject DataCenterDao _dcDao ;
119- @ Inject NetworkModel _networkMgr ;
118+ @ Inject NetworkModel _networkModel ;
119+ @ Inject NetworkManager _networkMgr ;
120120 @ Inject InlineLoadBalancerNicMapDao _inlineLoadBalancerNicMapDao ;
121121 @ Inject NicDao _nicDao ;
122122 @ Inject AgentManager _agentMgr ;
@@ -428,7 +428,7 @@ public boolean manageGuestNetworkWithExternalFirewall(boolean add, Network netwo
428428 IPAddressVO sourceNatIp = null ;
429429 if (!sharedSourceNat ) {
430430 // Get the source NAT IP address for this account
431- List <? extends IpAddress > sourceNatIps = _networkMgr .listPublicIpsAssignedToAccount (network .getAccountId (),
431+ List <? extends IpAddress > sourceNatIps = _networkModel .listPublicIpsAssignedToAccount (network .getAccountId (),
432432 zoneId , true );
433433
434434 if (sourceNatIps .size () != 1 ) {
@@ -455,7 +455,7 @@ public boolean manageGuestNetworkWithExternalFirewall(boolean add, Network netwo
455455 }
456456
457457 // Get network rate
458- Integer networkRate = _networkMgr .getNetworkRate (network .getId (), null );
458+ Integer networkRate = _networkModel .getNetworkRate (network .getId (), null );
459459
460460 IpAddressTO ip = new IpAddressTO (account .getAccountId (), sourceNatIpAddress , add , false , !sharedSourceNat , publicVlanTag , null , null , null , networkRate , false );
461461 IpAddressTO [] ips = new IpAddressTO [1 ];
@@ -483,7 +483,7 @@ public boolean manageGuestNetworkWithExternalFirewall(boolean add, Network netwo
483483
484484 if (add && (!reservedIpAddressesForGuestNetwork .contains (network .getGateway ()))) {
485485 // Insert a new NIC for this guest network to reserve the gateway address
486- savePlaceholderNic (network , network .getGateway ());
486+ _networkMgr . savePlaceholderNic (network , network .getGateway ());
487487 }
488488
489489 // Delete any mappings used for inline external load balancers in this network
@@ -499,14 +499,13 @@ public boolean manageGuestNetworkWithExternalFirewall(boolean add, Network netwo
499499
500500 // on network shutdown, delete placeHolder nics used for the firewall device
501501 if (!add ) {
502- List <NicVO > guestIps = _nicDao .listByNetworkId (network .getId ());
503- for (NicVO guestIp : guestIps ) {
504- // only external firewall and external load balancer will create NicVO with PlaceHolder reservation strategy
505- if ( guestIp . getReservationStrategy (). equals ( ReservationStrategy . PlaceHolder ) && guestIp . getIp4Address (). equals ( network . getGateway ())) {
506- _nicDao .remove (guestIp .getId ());
502+ List <NicVO > nics = _nicDao .listByNetworkId (network .getId ());
503+ for (NicVO nic : nics ) {
504+ if ( nic . getReservationStrategy (). equals ( ReservationStrategy . PlaceHolder ) && nic . getIp4Address (). equals ( network . getGateway ())) {
505+ s_logger . debug ( "Removing placeholder nic " + nic + " for the network " + network );
506+ _nicDao .remove (nic .getId ());
507507 }
508508 }
509-
510509 freeFirewallForNetwork (network );
511510 }
512511
@@ -516,6 +515,7 @@ public boolean manageGuestNetworkWithExternalFirewall(boolean add, Network netwo
516515 return true ;
517516 }
518517
518+
519519 @ Override
520520 public boolean applyFirewallRules (Network network , List <? extends FirewallRule > rules ) throws ResourceUnavailableException {
521521 // Find the external firewall in this zone
@@ -541,7 +541,7 @@ public boolean applyFirewallRules(Network network, List<? extends FirewallRule>
541541 if (rule .getSourceCidrList () == null && (rule .getPurpose () == Purpose .Firewall || rule .getPurpose () == Purpose .NetworkACL )) {
542542 _fwRulesDao .loadSourceCidrs ((FirewallRuleVO )rule );
543543 }
544- IpAddress sourceIp = _networkMgr .getIp (rule .getSourceIpAddressId ());
544+ IpAddress sourceIp = _networkModel .getIp (rule .getSourceIpAddressId ());
545545 FirewallRuleTO ruleTO = new FirewallRuleTO (rule , null , sourceIp .getAddress ().addr ());
546546 rulesTO .add (ruleTO );
547547 }
@@ -568,7 +568,7 @@ public boolean applyStaticNatRules(Network network, List<? extends StaticNat> ru
568568 List <StaticNatRuleTO > staticNatRules = new ArrayList <StaticNatRuleTO >();
569569
570570 for (StaticNat rule : rules ) {
571- IpAddress sourceIp = _networkMgr .getIp (rule .getSourceIpAddressId ());
571+ IpAddress sourceIp = _networkModel .getIp (rule .getSourceIpAddressId ());
572572 Vlan vlan = _vlanDao .findById (sourceIp .getVlanId ());
573573
574574 StaticNatRuleTO ruleTO = new StaticNatRuleTO (0 ,vlan .getVlanTag (), sourceIp .getAddress ().addr (), -1 , -1 , rule .getDestIpAddress (), -1 , -1 , "any" , rule .isForRevoke (), false );
@@ -632,7 +632,7 @@ public boolean manageRemoteAccessVpn(boolean create, Network network, RemoteAcce
632632 }
633633
634634 // Create/delete VPN
635- IpAddress ip = _networkMgr .getIp (vpn .getServerAddressId ());
635+ IpAddress ip = _networkModel .getIp (vpn .getServerAddressId ());
636636
637637 // Mask the IP range with the network's VLAN tag
638638 String [] ipRange = vpn .getIpRange ().split ("-" );
@@ -712,14 +712,6 @@ public int getVlanOffset(long physicalNetworkId, int vlanTag) {
712712 return vlanTag - lowestVlanTag ;
713713 }
714714
715- private NicVO savePlaceholderNic (Network network , String ipAddress ) {
716- NicVO nic = new NicVO (null , null , network .getId (), null );
717- nic .setIp4Address (ipAddress );
718- nic .setReservationStrategy (ReservationStrategy .PlaceHolder );
719- nic .setState (State .Reserved );
720- return _nicDao .persist (nic );
721- }
722-
723715 public int getGloballyConfiguredCidrSize () {
724716 try {
725717 String globalVlanBits = _configDao .getValue (Config .GuestVlanBits .key ());
@@ -771,7 +763,7 @@ public boolean applyPortForwardingRules(Network network, List<? extends PortForw
771763 List <PortForwardingRuleTO > pfRules = new ArrayList <PortForwardingRuleTO >();
772764
773765 for (PortForwardingRule rule : rules ) {
774- IpAddress sourceIp = _networkMgr .getIp (rule .getSourceIpAddressId ());
766+ IpAddress sourceIp = _networkModel .getIp (rule .getSourceIpAddressId ());
775767 Vlan vlan = _vlanDao .findById (sourceIp .getVlanId ());
776768
777769 PortForwardingRuleTO ruleTO = new PortForwardingRuleTO (rule , vlan .getVlanTag (), sourceIp .getAddress ().addr ());
0 commit comments