@Test public void testToTransformationStep() { Ip ip = Ip.parse("1.1.1.1"); Nat snat = new Nat(Type.SOURCE); List<TransformationStep> step = INSTANCE.toTransformationSteps(snat, null, ip, null); assertThat( step, contains( new AssignIpAddressFromPool(SOURCE_NAT, SOURCE, ip, ip), new AssignPortFromPool( SOURCE_NAT, PortField.SOURCE, Nat.DEFAULT_FROM_PORT, Nat.DEFAULT_TO_PORT))); snat.setDefaultFromPort(10000); snat.setDefaultToPort(20000); step = INSTANCE.toTransformationSteps(snat, null, ip, null); assertThat( step, contains( new AssignIpAddressFromPool(SOURCE_NAT, SOURCE, ip, ip), new AssignPortFromPool(SOURCE_NAT, PortField.SOURCE, 10000, 20000))); }
@Override public List<TransformationStep> toTransformationSteps( Nat nat, @Nullable Map<String, AddressBookEntry> addressBookEntryMap, Ip interfaceIp, Warnings warnings) { checkArgument( nat.getType() == SOURCE || nat.getType() == DESTINATION, "Interface actions can only be used in source nat and dest nat"); TransformationType type = nat.getType().toTransformationType(); IpField ipField = nat.getType() == SOURCE ? IpField.SOURCE : IpField.DESTINATION; ImmutableList.Builder<TransformationStep> builder = new Builder<>(); builder.add(new AssignIpAddressFromPool(type, ipField, interfaceIp, interfaceIp)); if (type == SOURCE_NAT) { builder.add( new AssignPortFromPool( type, PortField.SOURCE, nat.getDefaultFromPort(), nat.getDefaultToPort())); } return builder.build(); }
NatRuleThenInterface implements NatRuleThen, Serializable { @Override public List<TransformationStep> toTransformationSteps( Nat nat, @Nullable Map<String, AddressBookEntry> addressBookEntryMap, Ip interfaceIp, Warnings warnings) { checkArgument( nat.getType() == SOURCE || nat.getType() == DESTINATION, "Interface actions can only be used in source nat and dest nat"); TransformationType type = nat.getType().toTransformationType(); IpField ipField = nat.getType() == SOURCE ? IpField.SOURCE : IpField.DESTINATION; ImmutableList.Builder<TransformationStep> builder = new Builder<>(); builder.add(new AssignIpAddressFromPool(type, ipField, interfaceIp, interfaceIp)); if (type == SOURCE_NAT) { builder.add( new AssignPortFromPool( type, PortField.SOURCE, nat.getDefaultFromPort(), nat.getDefaultToPort())); } return builder.build(); } }
NatRuleThenInterface implements NatRuleThen, Serializable { @Override public List<TransformationStep> toTransformationSteps( Nat nat, @Nullable Map<String, AddressBookEntry> addressBookEntryMap, Ip interfaceIp, Warnings warnings) { checkArgument( nat.getType() == SOURCE || nat.getType() == DESTINATION, "Interface actions can only be used in source nat and dest nat"); TransformationType type = nat.getType().toTransformationType(); IpField ipField = nat.getType() == SOURCE ? IpField.SOURCE : IpField.DESTINATION; ImmutableList.Builder<TransformationStep> builder = new Builder<>(); builder.add(new AssignIpAddressFromPool(type, ipField, interfaceIp, interfaceIp)); if (type == SOURCE_NAT) { builder.add( new AssignPortFromPool( type, PortField.SOURCE, nat.getDefaultFromPort(), nat.getDefaultToPort())); } return builder.build(); } private  NatRuleThenInterface(); }
NatRuleThenInterface implements NatRuleThen, Serializable { @Override public List<TransformationStep> toTransformationSteps( Nat nat, @Nullable Map<String, AddressBookEntry> addressBookEntryMap, Ip interfaceIp, Warnings warnings) { checkArgument( nat.getType() == SOURCE || nat.getType() == DESTINATION, "Interface actions can only be used in source nat and dest nat"); TransformationType type = nat.getType().toTransformationType(); IpField ipField = nat.getType() == SOURCE ? IpField.SOURCE : IpField.DESTINATION; ImmutableList.Builder<TransformationStep> builder = new Builder<>(); builder.add(new AssignIpAddressFromPool(type, ipField, interfaceIp, interfaceIp)); if (type == SOURCE_NAT) { builder.add( new AssignPortFromPool( type, PortField.SOURCE, nat.getDefaultFromPort(), nat.getDefaultToPort())); } return builder.build(); } private  NatRuleThenInterface(); @Override List<TransformationStep> toTransformationSteps(
      Nat nat,
      @Nullable Map<String, AddressBookEntry> addressBookEntryMap,
      Ip interfaceIp,
      Warnings warnings); @Override boolean equals(Object obj); @Override int hashCode(); }
NatRuleThenInterface implements NatRuleThen, Serializable { @Override public List<TransformationStep> toTransformationSteps( Nat nat, @Nullable Map<String, AddressBookEntry> addressBookEntryMap, Ip interfaceIp, Warnings warnings) { checkArgument( nat.getType() == SOURCE || nat.getType() == DESTINATION, "Interface actions can only be used in source nat and dest nat"); TransformationType type = nat.getType().toTransformationType(); IpField ipField = nat.getType() == SOURCE ? IpField.SOURCE : IpField.DESTINATION; ImmutableList.Builder<TransformationStep> builder = new Builder<>(); builder.add(new AssignIpAddressFromPool(type, ipField, interfaceIp, interfaceIp)); if (type == SOURCE_NAT) { builder.add( new AssignPortFromPool( type, PortField.SOURCE, nat.getDefaultFromPort(), nat.getDefaultToPort())); } return builder.build(); } private  NatRuleThenInterface(); @Override List<TransformationStep> toTransformationSteps(
      Nat nat,
      @Nullable Map<String, AddressBookEntry> addressBookEntryMap,
      Ip interfaceIp,
      Warnings warnings); @Override boolean equals(Object obj); @Override int hashCode(); static final NatRuleThenInterface INSTANCE; }