Search in sources :

Example 6 with SetPortForwardingRulesCommand

use of com.cloud.agent.api.routing.SetPortForwardingRulesCommand in project cloudstack by apache.

the class CiscoVnmcElement method applyPFRules.

@Override
public boolean applyPFRules(Network network, List<PortForwardingRule> rules) throws ResourceUnavailableException {
    if (!_networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.PortForwarding, Provider.CiscoVnmc)) {
        s_logger.error("Port forwarding service is not provided by Cisco Vnmc device on network " + network.getName());
        return false;
    }
    // Find VNMC host for physical network
    List<CiscoVnmcControllerVO> devices = _ciscoVnmcDao.listByPhysicalNetwork(network.getPhysicalNetworkId());
    if (devices.isEmpty()) {
        s_logger.error("No Cisco Vnmc device on network " + network.getName());
        return true;
    }
    // Find if ASA 1000v is associated with network
    NetworkAsa1000vMapVO asaForNetwork = _networkAsa1000vMapDao.findByNetworkId(network.getId());
    if (asaForNetwork == null) {
        s_logger.debug("Cisco ASA 1000v device is not associated with network " + network.getName());
        return true;
    }
    if (network.getState() == Network.State.Allocated) {
        s_logger.debug("External firewall was asked to apply port forwarding rules for network with ID " + network.getId() + "; this network is not implemented. Skipping backend commands.");
        return true;
    }
    CiscoVnmcControllerVO ciscoVnmcDevice = devices.get(0);
    HostVO ciscoVnmcHost = _hostDao.findById(ciscoVnmcDevice.getHostId());
    List<PortForwardingRuleTO> rulesTO = new ArrayList<PortForwardingRuleTO>();
    for (PortForwardingRule rule : rules) {
        IpAddress sourceIp = _networkModel.getIp(rule.getSourceIpAddressId());
        Vlan vlan = _vlanDao.findById(sourceIp.getVlanId());
        PortForwardingRuleTO ruleTO = new PortForwardingRuleTO(rule, vlan.getVlanTag(), sourceIp.getAddress().addr());
        rulesTO.add(ruleTO);
    }
    if (!rulesTO.isEmpty()) {
        SetPortForwardingRulesCommand cmd = new SetPortForwardingRulesCommand(rulesTO);
        cmd.setContextParam(NetworkElementCommand.GUEST_VLAN_TAG, BroadcastDomainType.getValue(network.getBroadcastUri()));
        cmd.setContextParam(NetworkElementCommand.GUEST_NETWORK_CIDR, network.getCidr());
        Answer answer = _agentMgr.easySend(ciscoVnmcHost.getId(), cmd);
        if (answer == null || !answer.getResult()) {
            String details = (answer != null) ? answer.getDetails() : "details unavailable";
            String msg = "Unable to apply port forwarding rules to Cisco ASA 1000v appliance due to: " + details + ".";
            s_logger.error(msg);
            throw new ResourceUnavailableException(msg, DataCenter.class, network.getDataCenterId());
        }
    }
    return true;
}
Also used : PortForwardingRuleTO(com.cloud.agent.api.to.PortForwardingRuleTO) ArrayList(java.util.ArrayList) Vlan(com.cloud.dc.Vlan) PortForwardingRule(com.cloud.network.rules.PortForwardingRule) HostVO(com.cloud.host.HostVO) Answer(com.cloud.agent.api.Answer) SetPortForwardingRulesCommand(com.cloud.agent.api.routing.SetPortForwardingRulesCommand) NetworkAsa1000vMapVO(com.cloud.network.cisco.NetworkAsa1000vMapVO) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) CiscoVnmcControllerVO(com.cloud.network.cisco.CiscoVnmcControllerVO) IpAddress(com.cloud.network.IpAddress) PublicIpAddress(com.cloud.network.PublicIpAddress)

Example 7 with SetPortForwardingRulesCommand

use of com.cloud.agent.api.routing.SetPortForwardingRulesCommand in project cloudstack by apache.

the class CiscoVnmcResourceTest method testPortForwarding.

@Test
public void testPortForwarding() throws ConfigurationException, Exception {
    long vlanId = 123;
    List<PortForwardingRuleTO> rules = new ArrayList<PortForwardingRuleTO>();
    PortForwardingRuleTO active = new PortForwardingRuleTO(1, "1.2.3.4", 22, 22, "5.6.7.8", 22, 22, "tcp", false, false);
    rules.add(active);
    PortForwardingRuleTO revoked = new PortForwardingRuleTO(1, "1.2.3.4", 22, 22, "5.6.7.8", 22, 22, "tcp", false, false);
    rules.add(revoked);
    SetPortForwardingRulesCommand cmd = new SetPortForwardingRulesCommand(rules);
    cmd.setContextParam(NetworkElementCommand.GUEST_VLAN_TAG, Long.toString(vlanId));
    cmd.setContextParam(NetworkElementCommand.GUEST_NETWORK_CIDR, "1.2.3.4/32");
    _resource.setConnection(_connection);
    when(_connection.createTenantVDCNatPolicySet(anyString())).thenReturn(true);
    when(_connection.createTenantVDCAclPolicySet(anyString(), anyBoolean())).thenReturn(true);
    when(_connection.createTenantVDCPFPolicy(anyString(), anyString())).thenReturn(true);
    when(_connection.createTenantVDCPFPolicyRef(anyString(), anyString())).thenReturn(true);
    when(_connection.createTenantVDCAclPolicy(anyString(), anyString())).thenReturn(true);
    when(_connection.createTenantVDCAclPolicyRef(anyString(), anyString(), anyBoolean())).thenReturn(true);
    when(_connection.deleteTenantVDCPFRule(anyString(), anyLong(), anyString())).thenReturn(true);
    when(_connection.deleteTenantVDCAclRule(anyString(), anyLong(), anyString())).thenReturn(true);
    when(_connection.createTenantVDCPFIpPool(anyString(), anyString(), anyString())).thenReturn(true);
    when(_connection.createTenantVDCPFPortPool(anyString(), anyString(), anyString(), anyString())).thenReturn(true);
    when(_connection.createTenantVDCPFRule(anyString(), anyLong(), anyString(), anyString(), anyString(), anyString(), anyString())).thenReturn(true);
    when(_connection.createTenantVDCAclRuleForPF(anyString(), anyLong(), anyString(), anyString(), anyString(), anyString(), anyString())).thenReturn(true);
    when(_connection.associateAclPolicySet(anyString())).thenReturn(true);
    Answer answer = _resource.executeRequest(cmd);
    System.out.println(answer.getDetails());
    assertTrue(answer.getResult());
}
Also used : Answer(com.cloud.agent.api.Answer) PortForwardingRuleTO(com.cloud.agent.api.to.PortForwardingRuleTO) SetPortForwardingRulesCommand(com.cloud.agent.api.routing.SetPortForwardingRulesCommand) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 8 with SetPortForwardingRulesCommand

use of com.cloud.agent.api.routing.SetPortForwardingRulesCommand in project cloudstack by apache.

the class PaloAltoResourceTest method addPortForwardingRule.

@Test
public void addPortForwardingRule() throws ConfigurationException, Exception {
    if (_context.containsKey("enable_console_output") && _context.get("enable_console_output").equals("true")) {
        System.out.println("\nTEST: addPortForwardingRule");
        System.out.println("---------------------------------------------------");
    }
    _context.put("has_public_interface", "true");
    _context.put("has_private_interface", "true");
    _context.put("has_src_nat_rule", "true");
    _context.put("has_isolation_fw_rule", "true");
    _context.put("has_service_tcp_80", "true");
    _resource.setMockContext(_context);
    _resource.configure("PaloAltoResource", _resourceParams);
    long vlanId = 3954;
    List<PortForwardingRuleTO> rules = new ArrayList<PortForwardingRuleTO>();
    PortForwardingRuleTO active = new PortForwardingRuleTO(9, "192.168.80.103", 80, 80, "10.3.97.158", 8080, 8080, "tcp", false, false);
    rules.add(active);
    SetPortForwardingRulesCommand cmd = new SetPortForwardingRulesCommand(rules);
    cmd.setContextParam(NetworkElementCommand.GUEST_VLAN_TAG, Long.toString(vlanId));
    cmd.setContextParam(NetworkElementCommand.GUEST_NETWORK_CIDR, "10.3.96.1/20");
    Answer answer = _resource.executeRequest(cmd);
    assertTrue(answer.getResult());
}
Also used : Answer(com.cloud.agent.api.Answer) IpAssocAnswer(com.cloud.agent.api.routing.IpAssocAnswer) PortForwardingRuleTO(com.cloud.agent.api.to.PortForwardingRuleTO) SetPortForwardingRulesCommand(com.cloud.agent.api.routing.SetPortForwardingRulesCommand) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 9 with SetPortForwardingRulesCommand

use of com.cloud.agent.api.routing.SetPortForwardingRulesCommand in project cloudstack by apache.

the class VirtualRoutingResourceTest method testSetPortForwardingRulesCommand.

@Test
public void testSetPortForwardingRulesCommand() {
    final SetPortForwardingRulesCommand cmd = generateSetPortForwardingRulesCommand();
    // Reset rule check count
    _count = 0;
    final Answer answer = _resource.executeRequest(cmd);
    assertTrue(answer instanceof GroupAnswer);
    assertEquals(((GroupAnswer) answer).getResults().length, 2);
    assertTrue(answer.getResult());
}
Also used : GroupAnswer(com.cloud.agent.api.routing.GroupAnswer) Answer(com.cloud.agent.api.Answer) SetPortForwardingRulesCommand(com.cloud.agent.api.routing.SetPortForwardingRulesCommand) GroupAnswer(com.cloud.agent.api.routing.GroupAnswer) Test(org.junit.Test)

Example 10 with SetPortForwardingRulesCommand

use of com.cloud.agent.api.routing.SetPortForwardingRulesCommand in project cloudstack by apache.

the class VirtualRoutingResourceTest method generateSetPortForwardingRulesCommand.

protected SetPortForwardingRulesCommand generateSetPortForwardingRulesCommand() {
    final List<PortForwardingRuleTO> pfRules = new ArrayList<>();
    pfRules.add(new PortForwardingRuleTO(1, "64.1.1.10", 22, 80, "10.10.1.10", 22, 80, "TCP", false, false));
    pfRules.add(new PortForwardingRuleTO(2, "64.1.1.11", 8080, 8080, "10.10.1.11", 8080, 8080, "UDP", true, false));
    final SetPortForwardingRulesCommand cmd = new SetPortForwardingRulesCommand(pfRules);
    cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, ROUTERNAME);
    assertEquals(cmd.getAnswersCount(), 2);
    return cmd;
}
Also used : PortForwardingRuleTO(com.cloud.agent.api.to.PortForwardingRuleTO) SetPortForwardingRulesCommand(com.cloud.agent.api.routing.SetPortForwardingRulesCommand) ArrayList(java.util.ArrayList)

Aggregations

SetPortForwardingRulesCommand (com.cloud.agent.api.routing.SetPortForwardingRulesCommand)12 Answer (com.cloud.agent.api.Answer)9 PortForwardingRuleTO (com.cloud.agent.api.to.PortForwardingRuleTO)6 ArrayList (java.util.ArrayList)6 GetDomRVersionCmd (com.cloud.agent.api.GetDomRVersionCmd)3 NetworkUsageCommand (com.cloud.agent.api.NetworkUsageCommand)3 PingTestCommand (com.cloud.agent.api.PingTestCommand)3 Test (org.junit.Test)3 AttachIsoCommand (com.cloud.agent.api.AttachIsoCommand)2 BackupSnapshotCommand (com.cloud.agent.api.BackupSnapshotCommand)2 CheckHealthCommand (com.cloud.agent.api.CheckHealthCommand)2 CheckNetworkCommand (com.cloud.agent.api.CheckNetworkCommand)2 CheckRouterCommand (com.cloud.agent.api.CheckRouterCommand)2 CheckS2SVpnConnectionsCommand (com.cloud.agent.api.CheckS2SVpnConnectionsCommand)2 CleanupNetworkRulesCmd (com.cloud.agent.api.CleanupNetworkRulesCmd)2 ComputeChecksumCommand (com.cloud.agent.api.ComputeChecksumCommand)2 CreatePrivateTemplateFromSnapshotCommand (com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand)2 CreatePrivateTemplateFromVolumeCommand (com.cloud.agent.api.CreatePrivateTemplateFromVolumeCommand)2 CreateStoragePoolCommand (com.cloud.agent.api.CreateStoragePoolCommand)2 CreateVolumeFromSnapshotCommand (com.cloud.agent.api.CreateVolumeFromSnapshotCommand)2