Search in sources :

Example 21 with StaticNatRuleTO

use of com.cloud.agent.api.to.StaticNatRuleTO in project cloudstack by apache.

the class JuniperSrxResource method getActiveRules.

private Map<String, ArrayList<FirewallRuleTO>> getActiveRules(FirewallRuleTO[] allRules) {
    Map<String, ArrayList<FirewallRuleTO>> activeRules = new HashMap<String, ArrayList<FirewallRuleTO>>();
    for (FirewallRuleTO rule : allRules) {
        String ipPair;
        if (rule.getPurpose().equals(Purpose.StaticNat)) {
            StaticNatRuleTO staticNatRule = (StaticNatRuleTO) rule;
            ipPair = staticNatRule.getSrcIp() + "-" + staticNatRule.getDstIp();
        } else if (rule.getPurpose().equals(Purpose.PortForwarding)) {
            PortForwardingRuleTO portForwardingRule = (PortForwardingRuleTO) rule;
            ipPair = portForwardingRule.getSrcIp() + "-" + portForwardingRule.getDstIp();
        } else {
            continue;
        }
        ArrayList<FirewallRuleTO> activeRulesForIpPair = activeRules.get(ipPair);
        if (activeRulesForIpPair == null) {
            activeRulesForIpPair = new ArrayList<FirewallRuleTO>();
        }
        if (!rule.revoked() || rule.isAlreadyAdded()) {
            activeRulesForIpPair.add(rule);
        }
        activeRules.put(ipPair, activeRulesForIpPair);
    }
    return activeRules;
}
Also used : StaticNatRuleTO(com.cloud.agent.api.to.StaticNatRuleTO) PortForwardingRuleTO(com.cloud.agent.api.to.PortForwardingRuleTO) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FirewallRuleTO(com.cloud.agent.api.to.FirewallRuleTO)

Aggregations

StaticNatRuleTO (com.cloud.agent.api.to.StaticNatRuleTO)21 ArrayList (java.util.ArrayList)17 SetStaticNatRulesCommand (com.cloud.agent.api.routing.SetStaticNatRulesCommand)8 Answer (com.cloud.agent.api.Answer)7 Test (org.junit.Test)7 ConfigureStaticNatRulesOnLogicalRouterAnswer (com.cloud.agent.api.ConfigureStaticNatRulesOnLogicalRouterAnswer)6 ConfigureStaticNatRulesOnLogicalRouterCommand (com.cloud.agent.api.ConfigureStaticNatRulesOnLogicalRouterCommand)5 IpAssocAnswer (com.cloud.agent.api.routing.IpAssocAnswer)5 IpAddress (com.cloud.network.IpAddress)5 PublicIpAddress (com.cloud.network.PublicIpAddress)5 NatRule (com.cloud.network.nicira.NatRule)5 StaticNat (com.cloud.network.rules.StaticNat)5 DestinationNatRule (com.cloud.network.nicira.DestinationNatRule)4 SourceNatRule (com.cloud.network.nicira.SourceNatRule)4 ExecutionException (com.cloud.utils.exception.ExecutionException)4 ExternalNetworkResourceUsageAnswer (com.cloud.agent.api.ExternalNetworkResourceUsageAnswer)3 MaintainAnswer (com.cloud.agent.api.MaintainAnswer)3 ReadyAnswer (com.cloud.agent.api.ReadyAnswer)3 SetStaticNatRulesAnswer (com.cloud.agent.api.routing.SetStaticNatRulesAnswer)3 DataCenterVO (com.cloud.dc.DataCenterVO)3