@Test public void testPropagateRoutesVpc() { String routeTableId = "tgw-rtb"; TransitGateway tgw = new TransitGateway( "tgw", new TransitGatewayOptions(0L, true, routeTableId, true, "tgw-rtb", true), "123456789012", ImmutableMap.of()); Prefix vpcPrefix = Prefix.parse("2.2.2.2/32"); Vpc vpc = getTestVpc("vpc", ImmutableSet.of(vpcPrefix)); TransitGatewayAttachment tgwAttachment = new TransitGatewayAttachment( "tgw-attach", tgw.getId(), "account", ResourceType.VPC, vpc.getId(), "account", new Association(routeTableId, STATE_ASSOCIATED)); TransitGatewayVpcAttachment vpcAttachment = new TransitGatewayVpcAttachment( tgwAttachment.getId(), tgw.getId(), vpc.getId(), ImmutableList.of()); TransitGatewayRouteTable routeTable = new TransitGatewayRouteTable(routeTableId, tgw.getId(), true, true); TransitGatewayPropagations propagations = new TransitGatewayPropagations( routeTableId, ImmutableList.of( new Propagation(tgwAttachment.getId(), ResourceType.VPC, vpc.getId(), true), new Propagation("dummy", ResourceType.VPC, "dummy", false))); Region region = Region.builder("region") .setTransitGateways(ImmutableMap.of(tgw.getId(), tgw)) .setTransitGatewayAttachments(ImmutableMap.of(tgwAttachment.getId(), tgwAttachment)) .setTransitGatewayVpcAttachments(ImmutableMap.of(vpcAttachment.getId(), vpcAttachment)) .setTransitGatewayRouteTables(ImmutableMap.of(routeTableId, routeTable)) .setTransitGatewayPropagations(ImmutableMap.of(routeTableId, propagations)) .setVpcs(ImmutableMap.of(vpc.getId(), vpc)) .build(); Configuration vpcCfg = vpc.toConfigurationNode(new ConvertedConfiguration(), region, new Warnings()); AwsConfiguration vsConfig = new AwsConfiguration(); vsConfig.addOrGetAccount("acc").addRegion(region); ConvertedConfiguration awsConfiguration = new ConvertedConfiguration(ImmutableList.of(vpcCfg)); Warnings warnings = new Warnings(true, true, true); Configuration tgwCfg = tgw.toConfigurationNode(vsConfig, awsConfiguration, region, warnings); assertThat(tgwCfg, hasDeviceModel(DeviceModel.AWS_TRANSIT_GATEWAY)); assertTrue(tgwCfg.getVrfs().containsKey(vrfNameForRouteTable(routeTableId))); assertThat( tgwCfg.getVrfs().get(vrfNameForRouteTable(routeTableId)).getStaticRoutes(), equalTo( ImmutableSet.of( toStaticRoute( vpcPrefix, tgwCfg .getAllInterfaces() .get(Utils.interfaceNameToRemote(vpcCfg, routeTableId)) .getName(), vpcCfg .getAllInterfaces() .get(Utils.interfaceNameToRemote(tgwCfg, routeTableId)) .getLinkLocalAddress() .getIp())))); }
private static void propagateRoutesVpc( Configuration tgwCfg, TransitGatewayRouteTable table, Vpc vpc, ConvertedConfiguration awsConfiguration, Warnings warnings) { Configuration vpcCfg = awsConfiguration.getNode(Vpc.nodeName(vpc.getId())); if (vpcCfg == null) { warnings.redFlag(String.format("VPC configuration node for VPC %s not found", vpc.getId())); return; } Interface localIface = tgwCfg.getAllInterfaces().get(Utils.interfaceNameToRemote(vpcCfg, table.getId())); if (localIface == null) { warnings.redFlag(String.format("Interface facing VPC %s not found on TGW", vpc.getId())); return; } Interface remoteIface = vpcCfg.getAllInterfaces().get(Utils.interfaceNameToRemote(tgwCfg, table.getId())); if (remoteIface == null) { warnings.redFlag(String.format("Interface facing TGW not found on VPC %s", vpc.getId())); return; } String vrfName = vrfNameForRouteTable(table.getId()); Vrf tgwVrf = tgwCfg.getVrfs().get(vrfName); if (tgwVrf == null) { warnings.redFlag(String.format("VRF %s not found on TGW %s", vrfName, tgwCfg.getHostname())); return; } if (!localIface.getVrfName().equals(vrfName)) { warnings.redFlag( String.format( "Unexpected interface VRF %s. Expected %s", localIface.getVrfName(), vrfName)); return; } vpc.getCidrBlockAssociations() .forEach( pfx -> addStaticRoute( tgwVrf, toStaticRoute( pfx, localIface.getName(), remoteIface.getLinkLocalAddress().getIp()))); }
TransitGateway implements AwsVpcEntity, Serializable { private static void propagateRoutesVpc( Configuration tgwCfg, TransitGatewayRouteTable table, Vpc vpc, ConvertedConfiguration awsConfiguration, Warnings warnings) { Configuration vpcCfg = awsConfiguration.getNode(Vpc.nodeName(vpc.getId())); if (vpcCfg == null) { warnings.redFlag(String.format("VPC configuration node for VPC %s not found", vpc.getId())); return; } Interface localIface = tgwCfg.getAllInterfaces().get(Utils.interfaceNameToRemote(vpcCfg, table.getId())); if (localIface == null) { warnings.redFlag(String.format("Interface facing VPC %s not found on TGW", vpc.getId())); return; } Interface remoteIface = vpcCfg.getAllInterfaces().get(Utils.interfaceNameToRemote(tgwCfg, table.getId())); if (remoteIface == null) { warnings.redFlag(String.format("Interface facing TGW not found on VPC %s", vpc.getId())); return; } String vrfName = vrfNameForRouteTable(table.getId()); Vrf tgwVrf = tgwCfg.getVrfs().get(vrfName); if (tgwVrf == null) { warnings.redFlag(String.format("VRF %s not found on TGW %s", vrfName, tgwCfg.getHostname())); return; } if (!localIface.getVrfName().equals(vrfName)) { warnings.redFlag( String.format( "Unexpected interface VRF %s. Expected %s", localIface.getVrfName(), vrfName)); return; } vpc.getCidrBlockAssociations() .forEach( pfx -> addStaticRoute( tgwVrf, toStaticRoute( pfx, localIface.getName(), remoteIface.getLinkLocalAddress().getIp()))); } }
TransitGateway implements AwsVpcEntity, Serializable { private static void propagateRoutesVpc( Configuration tgwCfg, TransitGatewayRouteTable table, Vpc vpc, ConvertedConfiguration awsConfiguration, Warnings warnings) { Configuration vpcCfg = awsConfiguration.getNode(Vpc.nodeName(vpc.getId())); if (vpcCfg == null) { warnings.redFlag(String.format("VPC configuration node for VPC %s not found", vpc.getId())); return; } Interface localIface = tgwCfg.getAllInterfaces().get(Utils.interfaceNameToRemote(vpcCfg, table.getId())); if (localIface == null) { warnings.redFlag(String.format("Interface facing VPC %s not found on TGW", vpc.getId())); return; } Interface remoteIface = vpcCfg.getAllInterfaces().get(Utils.interfaceNameToRemote(tgwCfg, table.getId())); if (remoteIface == null) { warnings.redFlag(String.format("Interface facing TGW not found on VPC %s", vpc.getId())); return; } String vrfName = vrfNameForRouteTable(table.getId()); Vrf tgwVrf = tgwCfg.getVrfs().get(vrfName); if (tgwVrf == null) { warnings.redFlag(String.format("VRF %s not found on TGW %s", vrfName, tgwCfg.getHostname())); return; } if (!localIface.getVrfName().equals(vrfName)) { warnings.redFlag( String.format( "Unexpected interface VRF %s. Expected %s", localIface.getVrfName(), vrfName)); return; } vpc.getCidrBlockAssociations() .forEach( pfx -> addStaticRoute( tgwVrf, toStaticRoute( pfx, localIface.getName(), remoteIface.getLinkLocalAddress().getIp()))); } TransitGateway(
      String gatewayId, TransitGatewayOptions options, String ownerId, Map<String, String> tags); }
TransitGateway implements AwsVpcEntity, Serializable { private static void propagateRoutesVpc( Configuration tgwCfg, TransitGatewayRouteTable table, Vpc vpc, ConvertedConfiguration awsConfiguration, Warnings warnings) { Configuration vpcCfg = awsConfiguration.getNode(Vpc.nodeName(vpc.getId())); if (vpcCfg == null) { warnings.redFlag(String.format("VPC configuration node for VPC %s not found", vpc.getId())); return; } Interface localIface = tgwCfg.getAllInterfaces().get(Utils.interfaceNameToRemote(vpcCfg, table.getId())); if (localIface == null) { warnings.redFlag(String.format("Interface facing VPC %s not found on TGW", vpc.getId())); return; } Interface remoteIface = vpcCfg.getAllInterfaces().get(Utils.interfaceNameToRemote(tgwCfg, table.getId())); if (remoteIface == null) { warnings.redFlag(String.format("Interface facing TGW not found on VPC %s", vpc.getId())); return; } String vrfName = vrfNameForRouteTable(table.getId()); Vrf tgwVrf = tgwCfg.getVrfs().get(vrfName); if (tgwVrf == null) { warnings.redFlag(String.format("VRF %s not found on TGW %s", vrfName, tgwCfg.getHostname())); return; } if (!localIface.getVrfName().equals(vrfName)) { warnings.redFlag( String.format( "Unexpected interface VRF %s. Expected %s", localIface.getVrfName(), vrfName)); return; } vpc.getCidrBlockAssociations() .forEach( pfx -> addStaticRoute( tgwVrf, toStaticRoute( pfx, localIface.getName(), remoteIface.getLinkLocalAddress().getIp()))); } TransitGateway(
      String gatewayId, TransitGatewayOptions options, String ownerId, Map<String, String> tags); @Nonnull TransitGatewayOptions getOptions(); @Override String getId(); @Nonnull String getOwnerId(); @Override boolean equals(@Nullable Object o); @Override int hashCode(); }
TransitGateway implements AwsVpcEntity, Serializable { private static void propagateRoutesVpc( Configuration tgwCfg, TransitGatewayRouteTable table, Vpc vpc, ConvertedConfiguration awsConfiguration, Warnings warnings) { Configuration vpcCfg = awsConfiguration.getNode(Vpc.nodeName(vpc.getId())); if (vpcCfg == null) { warnings.redFlag(String.format("VPC configuration node for VPC %s not found", vpc.getId())); return; } Interface localIface = tgwCfg.getAllInterfaces().get(Utils.interfaceNameToRemote(vpcCfg, table.getId())); if (localIface == null) { warnings.redFlag(String.format("Interface facing VPC %s not found on TGW", vpc.getId())); return; } Interface remoteIface = vpcCfg.getAllInterfaces().get(Utils.interfaceNameToRemote(tgwCfg, table.getId())); if (remoteIface == null) { warnings.redFlag(String.format("Interface facing TGW not found on VPC %s", vpc.getId())); return; } String vrfName = vrfNameForRouteTable(table.getId()); Vrf tgwVrf = tgwCfg.getVrfs().get(vrfName); if (tgwVrf == null) { warnings.redFlag(String.format("VRF %s not found on TGW %s", vrfName, tgwCfg.getHostname())); return; } if (!localIface.getVrfName().equals(vrfName)) { warnings.redFlag( String.format( "Unexpected interface VRF %s. Expected %s", localIface.getVrfName(), vrfName)); return; } vpc.getCidrBlockAssociations() .forEach( pfx -> addStaticRoute( tgwVrf, toStaticRoute( pfx, localIface.getName(), remoteIface.getLinkLocalAddress().getIp()))); } TransitGateway(
      String gatewayId, TransitGatewayOptions options, String ownerId, Map<String, String> tags); @Nonnull TransitGatewayOptions getOptions(); @Override String getId(); @Nonnull String getOwnerId(); @Override boolean equals(@Nullable Object o); @Override int hashCode();  }