@Test public void testConnectToVpc() { NatGateway ngw = new NatGateway("ngw", "subnet", "vpc", ImmutableList.of(), ImmutableMap.of()); Configuration ngwConfig = new Configuration("c", ConfigurationFormat.AWS); ngwConfig.getVrfs().put(DEFAULT_VRF_NAME, new Vrf(DEFAULT_VRF_NAME)); Vpc vpc = getTestVpc(ngw.getVpcId()); Region region = Region.builder("r1") .setVpcs(ImmutableMap.of(vpc.getId(), vpc)) .setNatGateways(ImmutableMap.of(ngw.getId(), ngw)) .build(); ConvertedConfiguration awsConfiguration = new ConvertedConfiguration(); Configuration vpcCfg = vpc.toConfigurationNode(awsConfiguration, region, new Warnings()); awsConfiguration.addNode(vpcCfg); ngw.connectToVpc(ngwConfig, awsConfiguration, region, new Warnings()); assertThat(vpcCfg.getVrfs(), hasKey(Vpc.vrfNameForLink(ngw.getId()))); assertThat( awsConfiguration.getLayer1Edges(), hasItem( new Layer1Edge( ngwConfig.getHostname(), Utils.interfaceNameToRemote(vpcCfg), vpcCfg.getHostname(), Utils.interfaceNameToRemote(ngwConfig)))); assertThat( vpcCfg.getVrfs().get(Vpc.vrfNameForLink(ngw.getId())).getStaticRoutes(), hasItem( toStaticRoute( Prefix.ZERO, Utils.interfaceNameToRemote(ngwConfig), Utils.getInterfaceLinkLocalIp(ngwConfig, Utils.interfaceNameToRemote(vpcCfg))))); }
@Nullable @VisibleForTesting Interface connectToVpc( Configuration natGwCfg, ConvertedConfiguration awsConfiguration, Region region, Warnings warnings) { Vpc vpc = region.getVpcs().get(_vpcId); if (vpc == null) { warnings.redFlag( String.format( "VPC %s for NAT gateway %s not found in region %s", _vpcId, _natGatewayId, region.getName())); return null; } Configuration vpcCfg = awsConfiguration.getNode(Vpc.nodeName(vpc.getId())); if (vpcCfg == null) { warnings.redFlag( String.format( "Configuration for VPC %s not found while building the NAT gateway node %s", _vpcId, _natGatewayId)); return null; } String vrfNameOnVpc = Vpc.vrfNameForLink(_natGatewayId); if (!vpcCfg.getVrfs().containsKey(vrfNameOnVpc)) { warnings.redFlag(String.format("VRF %s not found on VPC %s", vrfNameOnVpc, _vpcId)); return null; } connect(awsConfiguration, natGwCfg, DEFAULT_VRF_NAME, vpcCfg, vrfNameOnVpc, ""); addStaticRoute( vpcCfg.getVrfs().get(vrfNameOnVpc), toStaticRoute( Prefix.ZERO, Utils.interfaceNameToRemote(natGwCfg), Utils.getInterfaceLinkLocalIp(natGwCfg, Utils.interfaceNameToRemote(vpcCfg)))); return natGwCfg.getAllInterfaces().get(Utils.interfaceNameToRemote(vpcCfg)); }
NatGateway implements AwsVpcEntity, Serializable { @Nullable @VisibleForTesting Interface connectToVpc( Configuration natGwCfg, ConvertedConfiguration awsConfiguration, Region region, Warnings warnings) { Vpc vpc = region.getVpcs().get(_vpcId); if (vpc == null) { warnings.redFlag( String.format( "VPC %s for NAT gateway %s not found in region %s", _vpcId, _natGatewayId, region.getName())); return null; } Configuration vpcCfg = awsConfiguration.getNode(Vpc.nodeName(vpc.getId())); if (vpcCfg == null) { warnings.redFlag( String.format( "Configuration for VPC %s not found while building the NAT gateway node %s", _vpcId, _natGatewayId)); return null; } String vrfNameOnVpc = Vpc.vrfNameForLink(_natGatewayId); if (!vpcCfg.getVrfs().containsKey(vrfNameOnVpc)) { warnings.redFlag(String.format("VRF %s not found on VPC %s", vrfNameOnVpc, _vpcId)); return null; } connect(awsConfiguration, natGwCfg, DEFAULT_VRF_NAME, vpcCfg, vrfNameOnVpc, ""); addStaticRoute( vpcCfg.getVrfs().get(vrfNameOnVpc), toStaticRoute( Prefix.ZERO, Utils.interfaceNameToRemote(natGwCfg), Utils.getInterfaceLinkLocalIp(natGwCfg, Utils.interfaceNameToRemote(vpcCfg)))); return natGwCfg.getAllInterfaces().get(Utils.interfaceNameToRemote(vpcCfg)); } }
NatGateway implements AwsVpcEntity, Serializable { @Nullable @VisibleForTesting Interface connectToVpc( Configuration natGwCfg, ConvertedConfiguration awsConfiguration, Region region, Warnings warnings) { Vpc vpc = region.getVpcs().get(_vpcId); if (vpc == null) { warnings.redFlag( String.format( "VPC %s for NAT gateway %s not found in region %s", _vpcId, _natGatewayId, region.getName())); return null; } Configuration vpcCfg = awsConfiguration.getNode(Vpc.nodeName(vpc.getId())); if (vpcCfg == null) { warnings.redFlag( String.format( "Configuration for VPC %s not found while building the NAT gateway node %s", _vpcId, _natGatewayId)); return null; } String vrfNameOnVpc = Vpc.vrfNameForLink(_natGatewayId); if (!vpcCfg.getVrfs().containsKey(vrfNameOnVpc)) { warnings.redFlag(String.format("VRF %s not found on VPC %s", vrfNameOnVpc, _vpcId)); return null; } connect(awsConfiguration, natGwCfg, DEFAULT_VRF_NAME, vpcCfg, vrfNameOnVpc, ""); addStaticRoute( vpcCfg.getVrfs().get(vrfNameOnVpc), toStaticRoute( Prefix.ZERO, Utils.interfaceNameToRemote(natGwCfg), Utils.getInterfaceLinkLocalIp(natGwCfg, Utils.interfaceNameToRemote(vpcCfg)))); return natGwCfg.getAllInterfaces().get(Utils.interfaceNameToRemote(vpcCfg)); } NatGateway(
      String natGatewayId,
      String subnetId,
      String vpcId,
      List<NatGatewayAddress> natGatewayAddresses,
      Map<String, String> tags); }
NatGateway implements AwsVpcEntity, Serializable { @Nullable @VisibleForTesting Interface connectToVpc( Configuration natGwCfg, ConvertedConfiguration awsConfiguration, Region region, Warnings warnings) { Vpc vpc = region.getVpcs().get(_vpcId); if (vpc == null) { warnings.redFlag( String.format( "VPC %s for NAT gateway %s not found in region %s", _vpcId, _natGatewayId, region.getName())); return null; } Configuration vpcCfg = awsConfiguration.getNode(Vpc.nodeName(vpc.getId())); if (vpcCfg == null) { warnings.redFlag( String.format( "Configuration for VPC %s not found while building the NAT gateway node %s", _vpcId, _natGatewayId)); return null; } String vrfNameOnVpc = Vpc.vrfNameForLink(_natGatewayId); if (!vpcCfg.getVrfs().containsKey(vrfNameOnVpc)) { warnings.redFlag(String.format("VRF %s not found on VPC %s", vrfNameOnVpc, _vpcId)); return null; } connect(awsConfiguration, natGwCfg, DEFAULT_VRF_NAME, vpcCfg, vrfNameOnVpc, ""); addStaticRoute( vpcCfg.getVrfs().get(vrfNameOnVpc), toStaticRoute( Prefix.ZERO, Utils.interfaceNameToRemote(natGwCfg), Utils.getInterfaceLinkLocalIp(natGwCfg, Utils.interfaceNameToRemote(vpcCfg)))); return natGwCfg.getAllInterfaces().get(Utils.interfaceNameToRemote(vpcCfg)); } 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 { @Nullable @VisibleForTesting Interface connectToVpc( Configuration natGwCfg, ConvertedConfiguration awsConfiguration, Region region, Warnings warnings) { Vpc vpc = region.getVpcs().get(_vpcId); if (vpc == null) { warnings.redFlag( String.format( "VPC %s for NAT gateway %s not found in region %s", _vpcId, _natGatewayId, region.getName())); return null; } Configuration vpcCfg = awsConfiguration.getNode(Vpc.nodeName(vpc.getId())); if (vpcCfg == null) { warnings.redFlag( String.format( "Configuration for VPC %s not found while building the NAT gateway node %s", _vpcId, _natGatewayId)); return null; } String vrfNameOnVpc = Vpc.vrfNameForLink(_natGatewayId); if (!vpcCfg.getVrfs().containsKey(vrfNameOnVpc)) { warnings.redFlag(String.format("VRF %s not found on VPC %s", vrfNameOnVpc, _vpcId)); return null; } connect(awsConfiguration, natGwCfg, DEFAULT_VRF_NAME, vpcCfg, vrfNameOnVpc, ""); addStaticRoute( vpcCfg.getVrfs().get(vrfNameOnVpc), toStaticRoute( Prefix.ZERO, Utils.interfaceNameToRemote(natGwCfg), Utils.getInterfaceLinkLocalIp(natGwCfg, Utils.interfaceNameToRemote(vpcCfg)))); return natGwCfg.getAllInterfaces().get(Utils.interfaceNameToRemote(vpcCfg)); } 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();  }