Search in sources :

Example 6 with DestinationNatRule

use of com.cloud.network.nicira.DestinationNatRule in project cloudstack by apache.

the class NiciraNvpResourceTest method testGenerateStaticNatRulePair.

@Test
public void testGenerateStaticNatRulePair() {
    final NatRule[] rules = resource.generateStaticNatRulePair("10.10.10.10", "11.11.11.11");
    assertTrue("DestinationNatRule".equals(rules[0].getType()));
    assertTrue("SourceNatRule".equals(rules[1].getType()));
    final DestinationNatRule dnr = (DestinationNatRule) rules[0];
    assertTrue(dnr.getToDestinationIpAddress().equals("10.10.10.10"));
    assertTrue(dnr.getToDestinationPort() == null);
    assertTrue(dnr.getMatch().getDestinationIpAddresses().equals("11.11.11.11"));
    final SourceNatRule snr = (SourceNatRule) rules[1];
    assertTrue(snr.getToSourceIpAddressMin().equals("11.11.11.11") && snr.getToSourceIpAddressMax().equals("11.11.11.11"));
    assertTrue(snr.getToSourcePort() == null);
    assertTrue(snr.getMatch().getSourceIpAddresses().equals("10.10.10.10"));
}
Also used : DestinationNatRule(com.cloud.network.nicira.DestinationNatRule) NatRule(com.cloud.network.nicira.NatRule) SourceNatRule(com.cloud.network.nicira.SourceNatRule) DestinationNatRule(com.cloud.network.nicira.DestinationNatRule) SourceNatRule(com.cloud.network.nicira.SourceNatRule) Test(org.junit.Test)

Example 7 with DestinationNatRule

use of com.cloud.network.nicira.DestinationNatRule in project cloudstack by apache.

the class NiciraNvpResource method generateStaticNatRulePair.

public NatRule[] generateStaticNatRulePair(final String insideIp, final String outsideIp) {
    final NatRule[] rulepair = new NatRule[2];
    rulepair[0] = new DestinationNatRule();
    rulepair[0].setType("DestinationNatRule");
    rulepair[0].setOrder(100);
    rulepair[1] = new SourceNatRule();
    rulepair[1].setType("SourceNatRule");
    rulepair[1].setOrder(100);
    Match m = new Match();
    m.setDestinationIpAddresses(outsideIp);
    rulepair[0].setMatch(m);
    ((DestinationNatRule) rulepair[0]).setToDestinationIpAddress(insideIp);
    // create matching snat rule
    m = new Match();
    m.setSourceIpAddresses(insideIp);
    rulepair[1].setMatch(m);
    ((SourceNatRule) rulepair[1]).setToSourceIpAddressMin(outsideIp);
    ((SourceNatRule) rulepair[1]).setToSourceIpAddressMax(outsideIp);
    return rulepair;
}
Also used : DestinationNatRule(com.cloud.network.nicira.DestinationNatRule) SourceNatRule(com.cloud.network.nicira.SourceNatRule) NatRule(com.cloud.network.nicira.NatRule) DestinationNatRule(com.cloud.network.nicira.DestinationNatRule) SourceNatRule(com.cloud.network.nicira.SourceNatRule) Match(com.cloud.network.nicira.Match)

Aggregations

DestinationNatRule (com.cloud.network.nicira.DestinationNatRule)7 NatRule (com.cloud.network.nicira.NatRule)7 SourceNatRule (com.cloud.network.nicira.SourceNatRule)7 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)4 ArgumentMatcher (org.mockito.ArgumentMatcher)4 ConfigurePortForwardingRulesOnLogicalRouterAnswer (com.cloud.agent.api.ConfigurePortForwardingRulesOnLogicalRouterAnswer)2 ConfigurePortForwardingRulesOnLogicalRouterCommand (com.cloud.agent.api.ConfigurePortForwardingRulesOnLogicalRouterCommand)2 ConfigureStaticNatRulesOnLogicalRouterAnswer (com.cloud.agent.api.ConfigureStaticNatRulesOnLogicalRouterAnswer)2 ConfigureStaticNatRulesOnLogicalRouterCommand (com.cloud.agent.api.ConfigureStaticNatRulesOnLogicalRouterCommand)2 PortForwardingRuleTO (com.cloud.agent.api.to.PortForwardingRuleTO)2 StaticNatRuleTO (com.cloud.agent.api.to.StaticNatRuleTO)2 Match (com.cloud.network.nicira.Match)1