@Test public void testToConfigurationNode() { NatGatewayAddress ngwAddress = new NatGatewayAddress( "allocationId", "netInterface", Ip.parse("10.10.10.10"), Ip.parse("1.1.1.1")); NatGateway ngw = new NatGateway("ngw", "subnet", "vpc", ImmutableList.of(ngwAddress), ImmutableMap.of()); Vpc vpc = getTestVpc(ngw.getVpcId()); Subnet subnet = getTestSubnet(Prefix.parse("10.10.10.0/24"), ngw.getSubnetId(), ngw.getVpcId()); NetworkAcl nacl = new NetworkAcl( "netAcl", vpc.getId(), ImmutableList.of(new NetworkAclAssociation(subnet.getId())), ImmutableList.of(), true); NetworkInterface netInterface = new NetworkInterface( "netInterface", subnet.getId(), subnet.getVpcId(), ImmutableList.of(), ImmutableList.of( new PrivateIpAddress(true, ngwAddress.getPrivateIp(), ngw.getPublicIp())), "desc", null, ImmutableMap.of()); Region region = Region.builder("r1") .setSubnets(ImmutableMap.of(subnet.getId(), subnet)) .setNetworkInterfaces(ImmutableMap.of(netInterface.getId(), netInterface)) .setNetworkAcls(ImmutableMap.of(nacl.getId(), nacl)) .setVpcs(ImmutableMap.of(vpc.getId(), vpc)) .build(); ConvertedConfiguration awsConfiguration = new ConvertedConfiguration(); Configuration vpcCfg = vpc.toConfigurationNode(awsConfiguration, region, new Warnings()); awsConfiguration.addNode(vpcCfg); String vrfNameOnVpc = vrfNameForLink(ngw.getId()); vpcCfg .getVrfs() .put(vrfNameOnVpc, Vrf.builder().setName(vrfNameOnVpc).setOwner(vpcCfg).build()); Configuration ngwConfig = ngw.toConfigurationNode(awsConfiguration, region, new Warnings()); assertThat(ngwConfig.getDeviceModel(), equalTo(AWS_NAT_GATEWAY)); assertThat(ngwConfig.getVendorFamily().getAws().getSubnetId(), equalTo(ngw.getSubnetId())); assertThat(ngwConfig.getVendorFamily().getAws().getVpcId(), equalTo(ngw.getVpcId())); assertThat(ngwConfig.getVendorFamily().getAws().getRegion(), equalTo(region.getName())); assertThat(ngwConfig.getIpAccessLists(), hasKey(ILLEGAL_PACKET_FILTER_NAME)); assertThat( awsConfiguration.getLayer1Edges(), hasItem( new Layer1Edge( ngw.getId(), netInterface.getId(), Subnet.nodeName(subnet.getId()), Subnet.instancesInterfaceName(subnet.getId())))); Interface ifaceToSubnet = ngwConfig.getAllInterfaces().get(netInterface.getId()); assertThat( ifaceToSubnet.getFirewallSessionInterfaceInfo(), equalTo( new FirewallSessionInterfaceInfo( false, ImmutableList.of(ifaceToSubnet.getName()), null, null))); assertThat( ifaceToSubnet.getPostTransformationIncomingFilter().getName(), equalTo(ILLEGAL_PACKET_FILTER_NAME)); assertThat(ngwConfig.getAllInterfaces(), hasKey(vpc.getId())); assertThat(ngwConfig.getIpAccessLists(), hasKey(nacl.getIngressAcl().getName())); assertThat(ngwConfig.getIpAccessLists(), hasKey(nacl.getEgressAcl().getName())); Interface ifaceToVpc = ngwConfig.getAllInterfaces().get(vpc.getId()); assertThat(ifaceToVpc.getIncomingFilter().getName(), equalTo(INCOMING_NAT_FILTER_NAME)); assertThat( ifaceToVpc.getFirewallSessionInterfaceInfo(), equalTo( new FirewallSessionInterfaceInfo( false, ImmutableList.of(ifaceToVpc.getName()), null, nacl.getEgressAcl().getName()))); assertThat( ngwConfig.getGeneratedReferenceBooks(), hasKey(GeneratedRefBookUtils.getName(ngwConfig.getHostname(), BookType.PublicIps))); assertThat( ngwConfig.getLocationInfo(), equalTo( ImmutableMap.of( interfaceLocation(ifaceToSubnet), INFRASTRUCTURE_LOCATION_INFO, interfaceLinkLocation(ifaceToSubnet), INFRASTRUCTURE_LOCATION_INFO))); }
Configuration toConfigurationNode( ConvertedConfiguration awsConfiguration, Region region, Warnings warnings) { Configuration cfgNode = Utils.newAwsConfiguration(_natGatewayId, "aws", _tags, DeviceModel.AWS_NAT_GATEWAY); cfgNode.getVendorFamily().getAws().setVpcId(_vpcId); cfgNode.getVendorFamily().getAws().setSubnetId(_subnetId); cfgNode.getVendorFamily().getAws().setRegion(region.getName()); String networkInterfaceId = _natGatewayAddresses.get(0).getNetworkInterfaceId(); NetworkInterface networkInterface = region.getNetworkInterfaces().get(networkInterfaceId); if (networkInterface == null) { warnings.redFlag( String.format( "Network interface %s not found for NAT gateway %s.", networkInterfaceId, _natGatewayId)); return cfgNode; } createPublicIpsRefBook(Collections.singleton(networkInterface), cfgNode); Subnet subnet = region.getSubnets().get(_subnetId); if (subnet == null) { warnings.redFlag( String.format("Subnet %s not found for NAT gateway %s.", _subnetId, _natGatewayId)); return cfgNode; } Interface ifaceToSubnet = addNodeToSubnet(cfgNode, networkInterface, subnet, awsConfiguration, warnings); ifaceToSubnet.setFirewallSessionInterfaceInfo( new FirewallSessionInterfaceInfo( false, ImmutableList.of(ifaceToSubnet.getName()), null, null)); IpAccessList postTransformationFilter = computePostTransformationIllegalPacketFilter(getPrivateIp()); cfgNode.getIpAccessLists().put(postTransformationFilter.getName(), postTransformationFilter); ifaceToSubnet.setPostTransformationIncomingFilter(postTransformationFilter); Interface ifaceToVpc = connectToVpc(cfgNode, awsConfiguration, region, warnings); if (ifaceToVpc != null) { List<NetworkAcl> networkAcls = findSubnetNetworkAcl(region.getNetworkAcls(), _vpcId, _subnetId); IpAccessList egressAcl = null; if (!networkAcls.isEmpty()) { installIncomingFilter(cfgNode, ifaceToVpc, networkAcls.get(0).getIngressAcl()); egressAcl = networkAcls.get(0).getEgressAcl(); cfgNode.getIpAccessLists().put(egressAcl.getName(), egressAcl); } ifaceToVpc.setIncomingTransformation(computeOutgoingNatTransformation(getPrivateIp())); ifaceToVpc.setFirewallSessionInterfaceInfo( new FirewallSessionInterfaceInfo( false, ImmutableList.of(ifaceToVpc.getName()), null, egressAcl == null ? null : egressAcl.getName())); } cfgNode.setLocationInfo( ImmutableMap.of( interfaceLocation(ifaceToSubnet), INFRASTRUCTURE_LOCATION_INFO, interfaceLinkLocation(ifaceToSubnet), INFRASTRUCTURE_LOCATION_INFO)); return cfgNode; }
NatGateway implements AwsVpcEntity, Serializable { Configuration toConfigurationNode( ConvertedConfiguration awsConfiguration, Region region, Warnings warnings) { Configuration cfgNode = Utils.newAwsConfiguration(_natGatewayId, "aws", _tags, DeviceModel.AWS_NAT_GATEWAY); cfgNode.getVendorFamily().getAws().setVpcId(_vpcId); cfgNode.getVendorFamily().getAws().setSubnetId(_subnetId); cfgNode.getVendorFamily().getAws().setRegion(region.getName()); String networkInterfaceId = _natGatewayAddresses.get(0).getNetworkInterfaceId(); NetworkInterface networkInterface = region.getNetworkInterfaces().get(networkInterfaceId); if (networkInterface == null) { warnings.redFlag( String.format( "Network interface %s not found for NAT gateway %s.", networkInterfaceId, _natGatewayId)); return cfgNode; } createPublicIpsRefBook(Collections.singleton(networkInterface), cfgNode); Subnet subnet = region.getSubnets().get(_subnetId); if (subnet == null) { warnings.redFlag( String.format("Subnet %s not found for NAT gateway %s.", _subnetId, _natGatewayId)); return cfgNode; } Interface ifaceToSubnet = addNodeToSubnet(cfgNode, networkInterface, subnet, awsConfiguration, warnings); ifaceToSubnet.setFirewallSessionInterfaceInfo( new FirewallSessionInterfaceInfo( false, ImmutableList.of(ifaceToSubnet.getName()), null, null)); IpAccessList postTransformationFilter = computePostTransformationIllegalPacketFilter(getPrivateIp()); cfgNode.getIpAccessLists().put(postTransformationFilter.getName(), postTransformationFilter); ifaceToSubnet.setPostTransformationIncomingFilter(postTransformationFilter); Interface ifaceToVpc = connectToVpc(cfgNode, awsConfiguration, region, warnings); if (ifaceToVpc != null) { List<NetworkAcl> networkAcls = findSubnetNetworkAcl(region.getNetworkAcls(), _vpcId, _subnetId); IpAccessList egressAcl = null; if (!networkAcls.isEmpty()) { installIncomingFilter(cfgNode, ifaceToVpc, networkAcls.get(0).getIngressAcl()); egressAcl = networkAcls.get(0).getEgressAcl(); cfgNode.getIpAccessLists().put(egressAcl.getName(), egressAcl); } ifaceToVpc.setIncomingTransformation(computeOutgoingNatTransformation(getPrivateIp())); ifaceToVpc.setFirewallSessionInterfaceInfo( new FirewallSessionInterfaceInfo( false, ImmutableList.of(ifaceToVpc.getName()), null, egressAcl == null ? null : egressAcl.getName())); } cfgNode.setLocationInfo( ImmutableMap.of( interfaceLocation(ifaceToSubnet), INFRASTRUCTURE_LOCATION_INFO, interfaceLinkLocation(ifaceToSubnet), INFRASTRUCTURE_LOCATION_INFO)); return cfgNode; } }
NatGateway implements AwsVpcEntity, Serializable { Configuration toConfigurationNode( ConvertedConfiguration awsConfiguration, Region region, Warnings warnings) { Configuration cfgNode = Utils.newAwsConfiguration(_natGatewayId, "aws", _tags, DeviceModel.AWS_NAT_GATEWAY); cfgNode.getVendorFamily().getAws().setVpcId(_vpcId); cfgNode.getVendorFamily().getAws().setSubnetId(_subnetId); cfgNode.getVendorFamily().getAws().setRegion(region.getName()); String networkInterfaceId = _natGatewayAddresses.get(0).getNetworkInterfaceId(); NetworkInterface networkInterface = region.getNetworkInterfaces().get(networkInterfaceId); if (networkInterface == null) { warnings.redFlag( String.format( "Network interface %s not found for NAT gateway %s.", networkInterfaceId, _natGatewayId)); return cfgNode; } createPublicIpsRefBook(Collections.singleton(networkInterface), cfgNode); Subnet subnet = region.getSubnets().get(_subnetId); if (subnet == null) { warnings.redFlag( String.format("Subnet %s not found for NAT gateway %s.", _subnetId, _natGatewayId)); return cfgNode; } Interface ifaceToSubnet = addNodeToSubnet(cfgNode, networkInterface, subnet, awsConfiguration, warnings); ifaceToSubnet.setFirewallSessionInterfaceInfo( new FirewallSessionInterfaceInfo( false, ImmutableList.of(ifaceToSubnet.getName()), null, null)); IpAccessList postTransformationFilter = computePostTransformationIllegalPacketFilter(getPrivateIp()); cfgNode.getIpAccessLists().put(postTransformationFilter.getName(), postTransformationFilter); ifaceToSubnet.setPostTransformationIncomingFilter(postTransformationFilter); Interface ifaceToVpc = connectToVpc(cfgNode, awsConfiguration, region, warnings); if (ifaceToVpc != null) { List<NetworkAcl> networkAcls = findSubnetNetworkAcl(region.getNetworkAcls(), _vpcId, _subnetId); IpAccessList egressAcl = null; if (!networkAcls.isEmpty()) { installIncomingFilter(cfgNode, ifaceToVpc, networkAcls.get(0).getIngressAcl()); egressAcl = networkAcls.get(0).getEgressAcl(); cfgNode.getIpAccessLists().put(egressAcl.getName(), egressAcl); } ifaceToVpc.setIncomingTransformation(computeOutgoingNatTransformation(getPrivateIp())); ifaceToVpc.setFirewallSessionInterfaceInfo( new FirewallSessionInterfaceInfo( false, ImmutableList.of(ifaceToVpc.getName()), null, egressAcl == null ? null : egressAcl.getName())); } cfgNode.setLocationInfo( ImmutableMap.of( interfaceLocation(ifaceToSubnet), INFRASTRUCTURE_LOCATION_INFO, interfaceLinkLocation(ifaceToSubnet), INFRASTRUCTURE_LOCATION_INFO)); return cfgNode; } NatGateway(
      String natGatewayId,
      String subnetId,
      String vpcId,
      List<NatGatewayAddress> natGatewayAddresses,
      Map<String, String> tags); }
NatGateway implements AwsVpcEntity, Serializable { Configuration toConfigurationNode( ConvertedConfiguration awsConfiguration, Region region, Warnings warnings) { Configuration cfgNode = Utils.newAwsConfiguration(_natGatewayId, "aws", _tags, DeviceModel.AWS_NAT_GATEWAY); cfgNode.getVendorFamily().getAws().setVpcId(_vpcId); cfgNode.getVendorFamily().getAws().setSubnetId(_subnetId); cfgNode.getVendorFamily().getAws().setRegion(region.getName()); String networkInterfaceId = _natGatewayAddresses.get(0).getNetworkInterfaceId(); NetworkInterface networkInterface = region.getNetworkInterfaces().get(networkInterfaceId); if (networkInterface == null) { warnings.redFlag( String.format( "Network interface %s not found for NAT gateway %s.", networkInterfaceId, _natGatewayId)); return cfgNode; } createPublicIpsRefBook(Collections.singleton(networkInterface), cfgNode); Subnet subnet = region.getSubnets().get(_subnetId); if (subnet == null) { warnings.redFlag( String.format("Subnet %s not found for NAT gateway %s.", _subnetId, _natGatewayId)); return cfgNode; } Interface ifaceToSubnet = addNodeToSubnet(cfgNode, networkInterface, subnet, awsConfiguration, warnings); ifaceToSubnet.setFirewallSessionInterfaceInfo( new FirewallSessionInterfaceInfo( false, ImmutableList.of(ifaceToSubnet.getName()), null, null)); IpAccessList postTransformationFilter = computePostTransformationIllegalPacketFilter(getPrivateIp()); cfgNode.getIpAccessLists().put(postTransformationFilter.getName(), postTransformationFilter); ifaceToSubnet.setPostTransformationIncomingFilter(postTransformationFilter); Interface ifaceToVpc = connectToVpc(cfgNode, awsConfiguration, region, warnings); if (ifaceToVpc != null) { List<NetworkAcl> networkAcls = findSubnetNetworkAcl(region.getNetworkAcls(), _vpcId, _subnetId); IpAccessList egressAcl = null; if (!networkAcls.isEmpty()) { installIncomingFilter(cfgNode, ifaceToVpc, networkAcls.get(0).getIngressAcl()); egressAcl = networkAcls.get(0).getEgressAcl(); cfgNode.getIpAccessLists().put(egressAcl.getName(), egressAcl); } ifaceToVpc.setIncomingTransformation(computeOutgoingNatTransformation(getPrivateIp())); ifaceToVpc.setFirewallSessionInterfaceInfo( new FirewallSessionInterfaceInfo( false, ImmutableList.of(ifaceToVpc.getName()), null, egressAcl == null ? null : egressAcl.getName())); } cfgNode.setLocationInfo( ImmutableMap.of( interfaceLocation(ifaceToSubnet), INFRASTRUCTURE_LOCATION_INFO, interfaceLinkLocation(ifaceToSubnet), INFRASTRUCTURE_LOCATION_INFO)); return cfgNode; } NatGateway(
      String natGatewayId,
      String subnetId,
      String vpcId,
      List<NatGatewayAddress> natGatewayAddresses,
      Map<String, String> tags); @Override String getId(); @Nonnull String getVpcId(); @Override boolean equals(Object o); @Override int hashCode(); }
NatGateway implements AwsVpcEntity, Serializable { Configuration toConfigurationNode( ConvertedConfiguration awsConfiguration, Region region, Warnings warnings) { Configuration cfgNode = Utils.newAwsConfiguration(_natGatewayId, "aws", _tags, DeviceModel.AWS_NAT_GATEWAY); cfgNode.getVendorFamily().getAws().setVpcId(_vpcId); cfgNode.getVendorFamily().getAws().setSubnetId(_subnetId); cfgNode.getVendorFamily().getAws().setRegion(region.getName()); String networkInterfaceId = _natGatewayAddresses.get(0).getNetworkInterfaceId(); NetworkInterface networkInterface = region.getNetworkInterfaces().get(networkInterfaceId); if (networkInterface == null) { warnings.redFlag( String.format( "Network interface %s not found for NAT gateway %s.", networkInterfaceId, _natGatewayId)); return cfgNode; } createPublicIpsRefBook(Collections.singleton(networkInterface), cfgNode); Subnet subnet = region.getSubnets().get(_subnetId); if (subnet == null) { warnings.redFlag( String.format("Subnet %s not found for NAT gateway %s.", _subnetId, _natGatewayId)); return cfgNode; } Interface ifaceToSubnet = addNodeToSubnet(cfgNode, networkInterface, subnet, awsConfiguration, warnings); ifaceToSubnet.setFirewallSessionInterfaceInfo( new FirewallSessionInterfaceInfo( false, ImmutableList.of(ifaceToSubnet.getName()), null, null)); IpAccessList postTransformationFilter = computePostTransformationIllegalPacketFilter(getPrivateIp()); cfgNode.getIpAccessLists().put(postTransformationFilter.getName(), postTransformationFilter); ifaceToSubnet.setPostTransformationIncomingFilter(postTransformationFilter); Interface ifaceToVpc = connectToVpc(cfgNode, awsConfiguration, region, warnings); if (ifaceToVpc != null) { List<NetworkAcl> networkAcls = findSubnetNetworkAcl(region.getNetworkAcls(), _vpcId, _subnetId); IpAccessList egressAcl = null; if (!networkAcls.isEmpty()) { installIncomingFilter(cfgNode, ifaceToVpc, networkAcls.get(0).getIngressAcl()); egressAcl = networkAcls.get(0).getEgressAcl(); cfgNode.getIpAccessLists().put(egressAcl.getName(), egressAcl); } ifaceToVpc.setIncomingTransformation(computeOutgoingNatTransformation(getPrivateIp())); ifaceToVpc.setFirewallSessionInterfaceInfo( new FirewallSessionInterfaceInfo( false, ImmutableList.of(ifaceToVpc.getName()), null, egressAcl == null ? null : egressAcl.getName())); } cfgNode.setLocationInfo( ImmutableMap.of( interfaceLocation(ifaceToSubnet), INFRASTRUCTURE_LOCATION_INFO, interfaceLinkLocation(ifaceToSubnet), INFRASTRUCTURE_LOCATION_INFO)); return cfgNode; } NatGateway(
      String natGatewayId,
      String subnetId,
      String vpcId,
      List<NatGatewayAddress> natGatewayAddresses,
      Map<String, String> tags); @Override String getId(); @Nonnull String getVpcId(); @Override boolean equals(Object o); @Override int hashCode();  }