mirror of https://github.com/apache/cloudstack.git
Fix bug in Port Forwarding
Nicira NVP can't handle a range of port when implementing port forwarding, so return an error message when a rule is being implemented that uses port ranges. Include unittest to verify this behaviour
This commit is contained in:
parent
cfd2a0bdf8
commit
1fbf2a2864
|
|
@ -604,6 +604,10 @@ public class NiciraNvpResource implements ServerResource {
|
|||
continue;
|
||||
}
|
||||
|
||||
if (rule.getDstPortRange()[0] != rule.getDstPortRange()[1]) {
|
||||
return new ConfigurePortForwardingRulesOnLogicalRouterAnswer(cmd, false, "Nicira NVP doesn't support port ranges for port forwarding");
|
||||
}
|
||||
|
||||
NatRule[] rulepair = generatePortForwardingRulePair(rule.getDstIp(), rule.getDstPortRange(), rule.getSrcIp(), rule.getSrcPortRange(), rule.getProtocol());
|
||||
|
||||
NatRule incoming = null;
|
||||
|
|
|
|||
|
|
@ -758,7 +758,41 @@ public class NiciraNvpResourceTest {
|
|||
assertFalse(a.getResult());
|
||||
verify(_nvpApi, atLeastOnce()).deleteLogicalRouterNatRule(eq("aaaaa"), eq("bbbbb"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testConfigurePortForwardingRulesOnLogicalRouterPortRange() throws ConfigurationException, NiciraNvpApiException {
|
||||
_resource.configure("NiciraNvpResource", _parameters);
|
||||
/* StaticNat
|
||||
* Outside IP: 11.11.11.11
|
||||
* Inside IP: 10.10.10.10
|
||||
*/
|
||||
|
||||
// Mock the command
|
||||
ConfigurePortForwardingRulesOnLogicalRouterCommand cmd = mock(ConfigurePortForwardingRulesOnLogicalRouterCommand.class);
|
||||
PortForwardingRuleTO rule = new PortForwardingRuleTO(1,"11.11.11.11", 80, 85, "10.10.10.10", 80, 85, "tcp", false, false);
|
||||
List<PortForwardingRuleTO> rules = new ArrayList<PortForwardingRuleTO>();
|
||||
rules.add(rule);
|
||||
when(cmd.getRules()).thenReturn(rules);
|
||||
when(cmd.getLogicalRouterUuid()).thenReturn("aaaaa");
|
||||
|
||||
// Mock the api find call
|
||||
@SuppressWarnings("unchecked")
|
||||
NiciraNvpList<NatRule> storedRules = mock(NiciraNvpList.class);
|
||||
when(_nvpApi.findNatRulesByLogicalRouterUuid("aaaaa")).thenReturn(storedRules);
|
||||
|
||||
// Mock the api create calls
|
||||
NatRule[] rulepair = _resource.generatePortForwardingRulePair("10.10.10.10", new int[] { 80, 85 }, "11.11.11.11", new int[] { 80, 85}, "tcp");
|
||||
rulepair[0].setUuid("bbbbb");
|
||||
rulepair[1].setUuid("ccccc");
|
||||
when(_nvpApi.createLogicalRouterNatRule(eq("aaaaa"), (NatRule)any())).thenReturn(rulepair[0]).thenReturn(rulepair[1]);
|
||||
|
||||
ConfigurePortForwardingRulesOnLogicalRouterAnswer a = (ConfigurePortForwardingRulesOnLogicalRouterAnswer) _resource.executeRequest(cmd);
|
||||
|
||||
// The expected result is false, Nicira does not support port ranges in DNAT
|
||||
assertFalse(a.getResult());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateStaticNatRulePair() {
|
||||
NatRule[] rules = _resource.generateStaticNatRulePair("10.10.10.10", "11.11.11.11");
|
||||
|
|
|
|||
Loading…
Reference in New Issue