@Test public void testGeneratePortForwardingRulePair() { final NatRule[] rules = resource.generatePortForwardingRulePair("10.10.10.10", new int[]{8080, 8080}, "11.11.11.11", new int[]{80, 80}, "tcp"); 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() == 8080); assertTrue(dnr.getMatch().getDestinationIpAddresses().equals("11.11.11.11")); assertTrue(dnr.getMatch().getDestinationPort() == 80); assertTrue(dnr.getMatch().getEthertype().equals("IPv4") && dnr.getMatch().getProtocol() == 6); final SourceNatRule snr = (SourceNatRule) rules[1]; assertTrue(snr.getToSourceIpAddressMin().equals("11.11.11.11") && snr.getToSourceIpAddressMax().equals("11.11.11.11")); assertTrue(snr.getToSourcePort() == 80); assertTrue(snr.getMatch().getSourceIpAddresses().equals("10.10.10.10")); assertTrue(snr.getMatch().getSourcePort() == 8080); assertTrue(snr.getMatch().getEthertype().equals("IPv4") && rules[1].getMatch().getProtocol() == 6); }
public NatRule[] generatePortForwardingRulePair(final String insideIp, final int[] insidePorts, final String outsideIp, final int[] outsidePorts, final String protocol) { final NatRule[] rulepair = generateStaticNatRulePair(insideIp, outsideIp); ((DestinationNatRule) rulepair[0]).setToDestinationPort(insidePorts[0]); rulepair[0].getMatch().setDestinationPort(outsidePorts[0]); rulepair[0].setOrder(50); rulepair[0].getMatch().setEthertype("IPv4"); if ("tcp".equals(protocol)) { rulepair[0].getMatch().setProtocol(6); } else if ("udp".equals(protocol)) { rulepair[0].getMatch().setProtocol(17); } ((SourceNatRule) rulepair[1]).setToSourcePort(outsidePorts[0]); rulepair[1].getMatch().setSourcePort(insidePorts[0]); rulepair[1].setOrder(50); rulepair[1].getMatch().setEthertype("IPv4"); if ("tcp".equals(protocol)) { rulepair[1].getMatch().setProtocol(6); } else if ("udp".equals(protocol)) { rulepair[1].getMatch().setProtocol(17); } return rulepair; }
NiciraNvpResource implements ServerResource { public NatRule[] generatePortForwardingRulePair(final String insideIp, final int[] insidePorts, final String outsideIp, final int[] outsidePorts, final String protocol) { final NatRule[] rulepair = generateStaticNatRulePair(insideIp, outsideIp); ((DestinationNatRule) rulepair[0]).setToDestinationPort(insidePorts[0]); rulepair[0].getMatch().setDestinationPort(outsidePorts[0]); rulepair[0].setOrder(50); rulepair[0].getMatch().setEthertype("IPv4"); if ("tcp".equals(protocol)) { rulepair[0].getMatch().setProtocol(6); } else if ("udp".equals(protocol)) { rulepair[0].getMatch().setProtocol(17); } ((SourceNatRule) rulepair[1]).setToSourcePort(outsidePorts[0]); rulepair[1].getMatch().setSourcePort(insidePorts[0]); rulepair[1].setOrder(50); rulepair[1].getMatch().setEthertype("IPv4"); if ("tcp".equals(protocol)) { rulepair[1].getMatch().setProtocol(6); } else if ("udp".equals(protocol)) { rulepair[1].getMatch().setProtocol(17); } return rulepair; } }
NiciraNvpResource implements ServerResource { public NatRule[] generatePortForwardingRulePair(final String insideIp, final int[] insidePorts, final String outsideIp, final int[] outsidePorts, final String protocol) { final NatRule[] rulepair = generateStaticNatRulePair(insideIp, outsideIp); ((DestinationNatRule) rulepair[0]).setToDestinationPort(insidePorts[0]); rulepair[0].getMatch().setDestinationPort(outsidePorts[0]); rulepair[0].setOrder(50); rulepair[0].getMatch().setEthertype("IPv4"); if ("tcp".equals(protocol)) { rulepair[0].getMatch().setProtocol(6); } else if ("udp".equals(protocol)) { rulepair[0].getMatch().setProtocol(17); } ((SourceNatRule) rulepair[1]).setToSourcePort(outsidePorts[0]); rulepair[1].getMatch().setSourcePort(insidePorts[0]); rulepair[1].setOrder(50); rulepair[1].getMatch().setEthertype("IPv4"); if ("tcp".equals(protocol)) { rulepair[1].getMatch().setProtocol(6); } else if ("udp".equals(protocol)) { rulepair[1].getMatch().setProtocol(17); } return rulepair; }  }
NiciraNvpResource implements ServerResource { public NatRule[] generatePortForwardingRulePair(final String insideIp, final int[] insidePorts, final String outsideIp, final int[] outsidePorts, final String protocol) { final NatRule[] rulepair = generateStaticNatRulePair(insideIp, outsideIp); ((DestinationNatRule) rulepair[0]).setToDestinationPort(insidePorts[0]); rulepair[0].getMatch().setDestinationPort(outsidePorts[0]); rulepair[0].setOrder(50); rulepair[0].getMatch().setEthertype("IPv4"); if ("tcp".equals(protocol)) { rulepair[0].getMatch().setProtocol(6); } else if ("udp".equals(protocol)) { rulepair[0].getMatch().setProtocol(17); } ((SourceNatRule) rulepair[1]).setToSourcePort(outsidePorts[0]); rulepair[1].getMatch().setSourcePort(insidePorts[0]); rulepair[1].setOrder(50); rulepair[1].getMatch().setEthertype("IPv4"); if ("tcp".equals(protocol)) { rulepair[1].getMatch().setProtocol(6); } else if ("udp".equals(protocol)) { rulepair[1].getMatch().setProtocol(17); } return rulepair; }  NiciraNvpApi getNiciraNvpApi(); NiciraNvpUtilities getNiciraNvpUtilities(); @Override boolean configure(final String ignoredName, final Map<String, Object> params); CommandRetryUtility getRetryUtility(); @Override String getName(); @Override void setName(final String name); @Override HostType getType(); @Override boolean start(); @Override StartupCommand[] initialize(); @Override boolean stop(); @Override PingCommand getCurrentStatus(final long id); @Override Answer executeRequest(final Command cmd); @Override void disconnected(); @Override IAgentControl getAgentControl(); @Override void setAgentControl(final IAgentControl agentControl); String natRuleToString(final NatRule rule); String truncate(final String string, final int length); NatRule[] generatePortForwardingRulePair(final String insideIp, final int[] insidePorts, final String outsideIp, final int[] outsidePorts,
                                                    final String protocol); NatRule[] generateStaticNatRulePair(final String insideIp, final String outsideIp); @Override void setConfigParams(final Map<String, Object> params); @Override Map<String, Object> getConfigParams(); @Override int getRunLevel(); @Override void setRunLevel(final int level); }
NiciraNvpResource implements ServerResource { public NatRule[] generatePortForwardingRulePair(final String insideIp, final int[] insidePorts, final String outsideIp, final int[] outsidePorts, final String protocol) { final NatRule[] rulepair = generateStaticNatRulePair(insideIp, outsideIp); ((DestinationNatRule) rulepair[0]).setToDestinationPort(insidePorts[0]); rulepair[0].getMatch().setDestinationPort(outsidePorts[0]); rulepair[0].setOrder(50); rulepair[0].getMatch().setEthertype("IPv4"); if ("tcp".equals(protocol)) { rulepair[0].getMatch().setProtocol(6); } else if ("udp".equals(protocol)) { rulepair[0].getMatch().setProtocol(17); } ((SourceNatRule) rulepair[1]).setToSourcePort(outsidePorts[0]); rulepair[1].getMatch().setSourcePort(insidePorts[0]); rulepair[1].setOrder(50); rulepair[1].getMatch().setEthertype("IPv4"); if ("tcp".equals(protocol)) { rulepair[1].getMatch().setProtocol(6); } else if ("udp".equals(protocol)) { rulepair[1].getMatch().setProtocol(17); } return rulepair; }  NiciraNvpApi getNiciraNvpApi(); NiciraNvpUtilities getNiciraNvpUtilities(); @Override boolean configure(final String ignoredName, final Map<String, Object> params); CommandRetryUtility getRetryUtility(); @Override String getName(); @Override void setName(final String name); @Override HostType getType(); @Override boolean start(); @Override StartupCommand[] initialize(); @Override boolean stop(); @Override PingCommand getCurrentStatus(final long id); @Override Answer executeRequest(final Command cmd); @Override void disconnected(); @Override IAgentControl getAgentControl(); @Override void setAgentControl(final IAgentControl agentControl); String natRuleToString(final NatRule rule); String truncate(final String string, final int length); NatRule[] generatePortForwardingRulePair(final String insideIp, final int[] insidePorts, final String outsideIp, final int[] outsidePorts,
                                                    final String protocol); NatRule[] generateStaticNatRulePair(final String insideIp, final String outsideIp); @Override void setConfigParams(final Map<String, Object> params); @Override Map<String, Object> getConfigParams(); @Override int getRunLevel(); @Override void setRunLevel(final int level); static final int NAME_MAX_LEN; static final int NUM_RETRIES; }