@Test public void testConfigureNat() { Ip pvt1 = Ip.parse("10.10.10.1"); Ip pvt2 = Ip.parse("10.10.10.2"); Ip pub1 = Ip.parse("1.1.1.1"); Ip pub2 = Ip.parse("1.1.1.2"); Interface iface = Interface.builder().setName("iface").build(); configureNat(iface, ImmutableMap.of(pvt1, pub1, pvt2, pub2)); assertThat( iface.getIncomingTransformation(), equalTo( Transformation.when(matchDst(pub2)) .apply(shiftDestinationIp(pvt2.toPrefix())) .setOrElse( Transformation.when(matchDst(pub1)) .apply(shiftDestinationIp(pvt1.toPrefix())) .build()) .build())); assertThat( iface.getOutgoingTransformation(), equalTo( Transformation.when(matchSrc(pvt2)) .apply(shiftSourceIp(pub2.toPrefix())) .setOrElse( Transformation.when(matchSrc(pvt1)) .apply(shiftSourceIp(pub1.toPrefix())) .build()) .build())); }
@VisibleForTesting static void configureNat(Interface bbInterface, Map<Ip, Ip> privatePublicMap) { ImmutableList.Builder<Transformation.Builder> outgoingNatRules = ImmutableList.builder(); ImmutableList.Builder<Transformation.Builder> incomingNatRules = ImmutableList.builder(); privatePublicMap.forEach( (pvtIp, pubIp) -> { outgoingNatRules.add( Transformation.when(AclLineMatchExprs.matchSrc(pvtIp)) .apply(TransformationStep.shiftSourceIp(pubIp.toPrefix()))); incomingNatRules.add( Transformation.when(AclLineMatchExprs.matchDst(pubIp)) .apply(TransformationStep.shiftDestinationIp(pvtIp.toPrefix()))); }); bbInterface.setOutgoingTransformation(chain(outgoingNatRules.build())); bbInterface.setIncomingTransformation(chain(incomingNatRules.build())); }
InternetGateway implements AwsVpcEntity, Serializable { @VisibleForTesting static void configureNat(Interface bbInterface, Map<Ip, Ip> privatePublicMap) { ImmutableList.Builder<Transformation.Builder> outgoingNatRules = ImmutableList.builder(); ImmutableList.Builder<Transformation.Builder> incomingNatRules = ImmutableList.builder(); privatePublicMap.forEach( (pvtIp, pubIp) -> { outgoingNatRules.add( Transformation.when(AclLineMatchExprs.matchSrc(pvtIp)) .apply(TransformationStep.shiftSourceIp(pubIp.toPrefix()))); incomingNatRules.add( Transformation.when(AclLineMatchExprs.matchDst(pubIp)) .apply(TransformationStep.shiftDestinationIp(pvtIp.toPrefix()))); }); bbInterface.setOutgoingTransformation(chain(outgoingNatRules.build())); bbInterface.setIncomingTransformation(chain(incomingNatRules.build())); } }
InternetGateway implements AwsVpcEntity, Serializable { @VisibleForTesting static void configureNat(Interface bbInterface, Map<Ip, Ip> privatePublicMap) { ImmutableList.Builder<Transformation.Builder> outgoingNatRules = ImmutableList.builder(); ImmutableList.Builder<Transformation.Builder> incomingNatRules = ImmutableList.builder(); privatePublicMap.forEach( (pvtIp, pubIp) -> { outgoingNatRules.add( Transformation.when(AclLineMatchExprs.matchSrc(pvtIp)) .apply(TransformationStep.shiftSourceIp(pubIp.toPrefix()))); incomingNatRules.add( Transformation.when(AclLineMatchExprs.matchDst(pubIp)) .apply(TransformationStep.shiftDestinationIp(pvtIp.toPrefix()))); }); bbInterface.setOutgoingTransformation(chain(outgoingNatRules.build())); bbInterface.setIncomingTransformation(chain(incomingNatRules.build())); } InternetGateway(
      String internetGatewayId, List<String> attachmentVpcIds, Map<String, String> tags); }
InternetGateway implements AwsVpcEntity, Serializable { @VisibleForTesting static void configureNat(Interface bbInterface, Map<Ip, Ip> privatePublicMap) { ImmutableList.Builder<Transformation.Builder> outgoingNatRules = ImmutableList.builder(); ImmutableList.Builder<Transformation.Builder> incomingNatRules = ImmutableList.builder(); privatePublicMap.forEach( (pvtIp, pubIp) -> { outgoingNatRules.add( Transformation.when(AclLineMatchExprs.matchSrc(pvtIp)) .apply(TransformationStep.shiftSourceIp(pubIp.toPrefix()))); incomingNatRules.add( Transformation.when(AclLineMatchExprs.matchDst(pubIp)) .apply(TransformationStep.shiftDestinationIp(pvtIp.toPrefix()))); }); bbInterface.setOutgoingTransformation(chain(outgoingNatRules.build())); bbInterface.setIncomingTransformation(chain(incomingNatRules.build())); } InternetGateway(
      String internetGatewayId, List<String> attachmentVpcIds, Map<String, String> tags); @Override String getId(); @Nonnull List<String> getAttachmentVpcIds(); @Override boolean equals(Object o); @Override int hashCode(); }
InternetGateway implements AwsVpcEntity, Serializable { @VisibleForTesting static void configureNat(Interface bbInterface, Map<Ip, Ip> privatePublicMap) { ImmutableList.Builder<Transformation.Builder> outgoingNatRules = ImmutableList.builder(); ImmutableList.Builder<Transformation.Builder> incomingNatRules = ImmutableList.builder(); privatePublicMap.forEach( (pvtIp, pubIp) -> { outgoingNatRules.add( Transformation.when(AclLineMatchExprs.matchSrc(pvtIp)) .apply(TransformationStep.shiftSourceIp(pubIp.toPrefix()))); incomingNatRules.add( Transformation.when(AclLineMatchExprs.matchDst(pubIp)) .apply(TransformationStep.shiftDestinationIp(pvtIp.toPrefix()))); }); bbInterface.setOutgoingTransformation(chain(outgoingNatRules.build())); bbInterface.setIncomingTransformation(chain(incomingNatRules.build())); } InternetGateway(
      String internetGatewayId, List<String> attachmentVpcIds, Map<String, String> tags); @Override String getId(); @Nonnull List<String> getAttachmentVpcIds(); @Override boolean equals(Object o); @Override int hashCode();  }