@Test public void testToTransformationSteps() { String prefixName = "entry"; Prefix prefix = Prefix.parse("1.1.1.1/24"); Map<String, AddressBookEntry> entryMap = ImmutableMap.of("entry", new AddressAddressBookEntry("entry", IpWildcard.create(prefix))); NatRuleThenPrefixName then = new NatRuleThenPrefixName(prefixName, DESTINATION); List<TransformationStep> steps = then.toTransformationSteps(new Nat(STATIC), entryMap, null, null); assertThat(steps, contains(new ShiftIpAddressIntoSubnet(STATIC_NAT, DESTINATION, prefix))); then = new NatRuleThenPrefixName(prefixName, SOURCE); steps = then.toTransformationSteps(new Nat(STATIC), entryMap, null, null); assertThat(steps, contains(new ShiftIpAddressIntoSubnet(STATIC_NAT, SOURCE, prefix))); }
@Override public List<TransformationStep> toTransformationSteps( Nat nat, @Nullable Map<String, AddressBookEntry> addressBookEntryMap, Ip interfaceIp, Warnings warnings) { checkArgument(nat.getType() == Type.STATIC, "prefix name is only supported in static nat"); checkArgument(addressBookEntryMap != null, "address book cannot be null"); AddressBookEntry addressBookEntry = addressBookEntryMap.get(_name); if (!(addressBookEntry instanceof AddressAddressBookEntry)) { throw new BatfishException("unknown address book entry"); } AddressAddressBookEntry addressAddressBookEntry = (AddressAddressBookEntry) addressBookEntry; Prefix subnet = addressAddressBookEntry.getIpWildcard().toPrefix(); return ImmutableList.of( new ShiftIpAddressIntoSubnet(TransformationType.STATIC_NAT, _ipField, subnet)); }
NatRuleThenPrefixName implements NatRuleThen, Serializable { @Override public List<TransformationStep> toTransformationSteps( Nat nat, @Nullable Map<String, AddressBookEntry> addressBookEntryMap, Ip interfaceIp, Warnings warnings) { checkArgument(nat.getType() == Type.STATIC, "prefix name is only supported in static nat"); checkArgument(addressBookEntryMap != null, "address book cannot be null"); AddressBookEntry addressBookEntry = addressBookEntryMap.get(_name); if (!(addressBookEntry instanceof AddressAddressBookEntry)) { throw new BatfishException("unknown address book entry"); } AddressAddressBookEntry addressAddressBookEntry = (AddressAddressBookEntry) addressBookEntry; Prefix subnet = addressAddressBookEntry.getIpWildcard().toPrefix(); return ImmutableList.of( new ShiftIpAddressIntoSubnet(TransformationType.STATIC_NAT, _ipField, subnet)); } }
NatRuleThenPrefixName implements NatRuleThen, Serializable { @Override public List<TransformationStep> toTransformationSteps( Nat nat, @Nullable Map<String, AddressBookEntry> addressBookEntryMap, Ip interfaceIp, Warnings warnings) { checkArgument(nat.getType() == Type.STATIC, "prefix name is only supported in static nat"); checkArgument(addressBookEntryMap != null, "address book cannot be null"); AddressBookEntry addressBookEntry = addressBookEntryMap.get(_name); if (!(addressBookEntry instanceof AddressAddressBookEntry)) { throw new BatfishException("unknown address book entry"); } AddressAddressBookEntry addressAddressBookEntry = (AddressAddressBookEntry) addressBookEntry; Prefix subnet = addressAddressBookEntry.getIpWildcard().toPrefix(); return ImmutableList.of( new ShiftIpAddressIntoSubnet(TransformationType.STATIC_NAT, _ipField, subnet)); } NatRuleThenPrefixName(String name, IpField ipField); }
NatRuleThenPrefixName implements NatRuleThen, Serializable { @Override public List<TransformationStep> toTransformationSteps( Nat nat, @Nullable Map<String, AddressBookEntry> addressBookEntryMap, Ip interfaceIp, Warnings warnings) { checkArgument(nat.getType() == Type.STATIC, "prefix name is only supported in static nat"); checkArgument(addressBookEntryMap != null, "address book cannot be null"); AddressBookEntry addressBookEntry = addressBookEntryMap.get(_name); if (!(addressBookEntry instanceof AddressAddressBookEntry)) { throw new BatfishException("unknown address book entry"); } AddressAddressBookEntry addressAddressBookEntry = (AddressAddressBookEntry) addressBookEntry; Prefix subnet = addressAddressBookEntry.getIpWildcard().toPrefix(); return ImmutableList.of( new ShiftIpAddressIntoSubnet(TransformationType.STATIC_NAT, _ipField, subnet)); } NatRuleThenPrefixName(String name, IpField ipField); String getName(); @Override boolean equals(Object o); @Override int hashCode(); @Override List<TransformationStep> toTransformationSteps(
      Nat nat,
      @Nullable Map<String, AddressBookEntry> addressBookEntryMap,
      Ip interfaceIp,
      Warnings warnings); }
NatRuleThenPrefixName implements NatRuleThen, Serializable { @Override public List<TransformationStep> toTransformationSteps( Nat nat, @Nullable Map<String, AddressBookEntry> addressBookEntryMap, Ip interfaceIp, Warnings warnings) { checkArgument(nat.getType() == Type.STATIC, "prefix name is only supported in static nat"); checkArgument(addressBookEntryMap != null, "address book cannot be null"); AddressBookEntry addressBookEntry = addressBookEntryMap.get(_name); if (!(addressBookEntry instanceof AddressAddressBookEntry)) { throw new BatfishException("unknown address book entry"); } AddressAddressBookEntry addressAddressBookEntry = (AddressAddressBookEntry) addressBookEntry; Prefix subnet = addressAddressBookEntry.getIpWildcard().toPrefix(); return ImmutableList.of( new ShiftIpAddressIntoSubnet(TransformationType.STATIC_NAT, _ipField, subnet)); } NatRuleThenPrefixName(String name, IpField ipField); String getName(); @Override boolean equals(Object o); @Override int hashCode(); @Override List<TransformationStep> toTransformationSteps(
      Nat nat,
      @Nullable Map<String, AddressBookEntry> addressBookEntryMap,
      Ip interfaceIp,
      Warnings warnings);  }