@Test public void testConnectSenderReceiver() { Configuration sendTgwCfg = Utils.newAwsConfiguration("tgw-send", "aws"); Configuration recvTgwCfg = Utils.newAwsConfiguration("tgw-recv", "aws"); TransitGatewayRouteTable sendRoutingTable1 = new TransitGatewayRouteTable("rtb-send-1", sendTgwCfg.getHostname(), true, true); TransitGatewayRouteTable sendRoutingTable2 = new TransitGatewayRouteTable("rtb-send-2", sendTgwCfg.getHostname(), true, true); String associatedRouteTableId = "rtb-recv-associated"; TransitGatewayAttachment sendSideAttachment = new TransitGatewayAttachment( "attach", sendTgwCfg.getHostname(), "account-send", ResourceType.PEERING, recvTgwCfg.getHostname(), "account-recv", null); TransitGatewayAttachment recvSideAttachment = new TransitGatewayAttachment( sendSideAttachment.getId(), recvTgwCfg.getHostname(), sendSideAttachment.getResourceOwnerId(), ResourceType.PEERING, sendTgwCfg.getHostname(), sendSideAttachment.getGatewayOwnerId(), new Association(associatedRouteTableId, "associated")); Vrf.builder() .setOwner(sendTgwCfg) .setName(vrfNameForRouteTable(sendRoutingTable1.getId())) .build(); Utils.newInterface( sendSidePeeringInterfaceName(sendRoutingTable1.getId(), sendSideAttachment.getId()), sendTgwCfg, vrfNameForRouteTable(sendRoutingTable1.getId()), LinkLocalAddress.of(LINK_LOCAL_IP), "test"); Vrf.builder() .setOwner(sendTgwCfg) .setName(vrfNameForRouteTable(sendRoutingTable2.getId())) .build(); Utils.newInterface( sendSidePeeringInterfaceName(sendRoutingTable2.getId(), sendSideAttachment.getId()), sendTgwCfg, vrfNameForRouteTable(sendRoutingTable2.getId()), LinkLocalAddress.of(LINK_LOCAL_IP), "test"); Vrf.builder() .setOwner(recvTgwCfg) .setName(vrfNameForRouteTable(associatedRouteTableId)) .build(); ConvertedConfiguration viConfigs = new ConvertedConfiguration(); viConfigs.addNode(sendTgwCfg); viConfigs.addNode(recvTgwCfg); TransitGateway sendTgw = new TransitGateway( sendTgwCfg.getHostname(), new TransitGatewayOptions(1L, false, "rt", false, "rt", false), sendSideAttachment.getGatewayOwnerId(), ImmutableMap.of()); Region sendSideRegion = Region.builder("r1") .setTransitGatewayRouteTables( ImmutableMap.of( sendRoutingTable1.getId(), sendRoutingTable1, sendRoutingTable2.getId(), sendRoutingTable2)) .setTransitGateways(ImmutableMap.of(sendTgw.getId(), sendTgw)) .build(); AwsConfiguration vsConfig = new AwsConfiguration(); vsConfig.addOrGetAccount(sendSideAttachment.getGatewayOwnerId()).addRegion(sendSideRegion); connectSenderReceiver( sendSideAttachment, recvSideAttachment, vsConfig, viConfigs, new Warnings()); ImmutableList.of(sendRoutingTable1, sendRoutingTable2) .forEach( rt -> { String recvSideInterfaceName = receiveSidePeeringInterfaceName( rt.getId(), sendSideAttachment.getId(), associatedRouteTableId); assertTrue(recvTgwCfg.getAllInterfaces().containsKey(recvSideInterfaceName)); assertTrue( viConfigs .getLayer1Edges() .contains( new Layer1Edge( sendTgwCfg.getHostname(), sendSidePeeringInterfaceName(rt.getId(), sendSideAttachment.getId()), recvTgwCfg.getHostname(), recvSideInterfaceName))); }); }
@VisibleForTesting static void connectSenderReceiver( TransitGatewayAttachment sendSideAttachment, TransitGatewayAttachment recvSideAttachment, AwsConfiguration vsConfigs, ConvertedConfiguration viConfigs, Warnings warnings) { Configuration sendSideTgw = viConfigs.getNode(sendSideAttachment.getGatewayId()); if (sendSideTgw == null) { warnings.redFlag( String.format("Configuration not found for TGW %s", sendSideAttachment.getGatewayId())); return; } Configuration recvSideTgw = viConfigs.getNode(recvSideAttachment.getGatewayId()); if (recvSideTgw == null) { warnings.redFlag( String.format("Configuration not found for TGW %s", recvSideAttachment.getGatewayId())); return; } String associatedRouteTableId = recvSideAttachment.getAssociation() == null ? null : recvSideAttachment.getAssociation().getRouteTableId(); if (associatedRouteTableId == null) { warnings.redFlag( String.format( "No route table associated for peering attachment %s on TGW %s", recvSideAttachment.getId(), recvSideAttachment.getGatewayId())); return; } List<Region> sendSideRegions = vsConfigs.getAccounts().stream() .filter(a -> a.getId().equals(sendSideAttachment.getGatewayOwnerId())) .flatMap(a -> a.getRegions().stream()) .filter(r -> r.getTransitGateways().containsKey(sendSideAttachment.getGatewayId())) .collect(ImmutableList.toImmutableList()); if (sendSideRegions.isEmpty()) { warnings.redFlag( String.format( "TGW %s not found in any region of account %s", sendSideAttachment.getGatewayId(), sendSideAttachment.getGatewayOwnerId())); return; } if (sendSideRegions.size() > 1) { warnings.redFlag( String.format( "TGW %s found in multiple regions for account %s. Skipping its peering attachments.", sendSideAttachment.getGatewayId(), sendSideAttachment.getGatewayOwnerId())); return; } Set<TransitGatewayRouteTable> sendSideRouteTables = sendSideRegions.get(0).getTransitGatewayRouteTables().values().stream() .filter( routeTable -> routeTable.getGatewayId().equals(sendSideAttachment.getGatewayId())) .collect(ImmutableSet.toImmutableSet()); sendSideRouteTables.forEach( rt -> { Interface sendSideIface = sendSideTgw .getAllInterfaces() .get(sendSidePeeringInterfaceName(rt.getId(), sendSideAttachment.getId())); if (sendSideIface == null) { warnings.redFlag( String.format( "Interface for route table %s for peering attachment %s on TGW %s not found", rt.getId(), sendSideAttachment.getId(), sendSideAttachment.getGatewayId())); return; } Interface recvSideIface = Utils.newInterface( receiveSidePeeringInterfaceName( rt.getId(), recvSideAttachment.getId(), associatedRouteTableId), recvSideTgw, vrfNameForRouteTable(associatedRouteTableId), LinkLocalAddress.of(LINK_LOCAL_IP), "From " + recvSideAttachment.getResourceId()); Utils.addLayer1Edge( viConfigs, sendSideTgw.getHostname(), sendSideIface.getName(), recvSideTgw.getHostname(), recvSideIface.getName()); }); }
TransitGatewayPeeringConnector { @VisibleForTesting static void connectSenderReceiver( TransitGatewayAttachment sendSideAttachment, TransitGatewayAttachment recvSideAttachment, AwsConfiguration vsConfigs, ConvertedConfiguration viConfigs, Warnings warnings) { Configuration sendSideTgw = viConfigs.getNode(sendSideAttachment.getGatewayId()); if (sendSideTgw == null) { warnings.redFlag( String.format("Configuration not found for TGW %s", sendSideAttachment.getGatewayId())); return; } Configuration recvSideTgw = viConfigs.getNode(recvSideAttachment.getGatewayId()); if (recvSideTgw == null) { warnings.redFlag( String.format("Configuration not found for TGW %s", recvSideAttachment.getGatewayId())); return; } String associatedRouteTableId = recvSideAttachment.getAssociation() == null ? null : recvSideAttachment.getAssociation().getRouteTableId(); if (associatedRouteTableId == null) { warnings.redFlag( String.format( "No route table associated for peering attachment %s on TGW %s", recvSideAttachment.getId(), recvSideAttachment.getGatewayId())); return; } List<Region> sendSideRegions = vsConfigs.getAccounts().stream() .filter(a -> a.getId().equals(sendSideAttachment.getGatewayOwnerId())) .flatMap(a -> a.getRegions().stream()) .filter(r -> r.getTransitGateways().containsKey(sendSideAttachment.getGatewayId())) .collect(ImmutableList.toImmutableList()); if (sendSideRegions.isEmpty()) { warnings.redFlag( String.format( "TGW %s not found in any region of account %s", sendSideAttachment.getGatewayId(), sendSideAttachment.getGatewayOwnerId())); return; } if (sendSideRegions.size() > 1) { warnings.redFlag( String.format( "TGW %s found in multiple regions for account %s. Skipping its peering attachments.", sendSideAttachment.getGatewayId(), sendSideAttachment.getGatewayOwnerId())); return; } Set<TransitGatewayRouteTable> sendSideRouteTables = sendSideRegions.get(0).getTransitGatewayRouteTables().values().stream() .filter( routeTable -> routeTable.getGatewayId().equals(sendSideAttachment.getGatewayId())) .collect(ImmutableSet.toImmutableSet()); sendSideRouteTables.forEach( rt -> { Interface sendSideIface = sendSideTgw .getAllInterfaces() .get(sendSidePeeringInterfaceName(rt.getId(), sendSideAttachment.getId())); if (sendSideIface == null) { warnings.redFlag( String.format( "Interface for route table %s for peering attachment %s on TGW %s not found", rt.getId(), sendSideAttachment.getId(), sendSideAttachment.getGatewayId())); return; } Interface recvSideIface = Utils.newInterface( receiveSidePeeringInterfaceName( rt.getId(), recvSideAttachment.getId(), associatedRouteTableId), recvSideTgw, vrfNameForRouteTable(associatedRouteTableId), LinkLocalAddress.of(LINK_LOCAL_IP), "From " + recvSideAttachment.getResourceId()); Utils.addLayer1Edge( viConfigs, sendSideTgw.getHostname(), sendSideIface.getName(), recvSideTgw.getHostname(), recvSideIface.getName()); }); } }
TransitGatewayPeeringConnector { @VisibleForTesting static void connectSenderReceiver( TransitGatewayAttachment sendSideAttachment, TransitGatewayAttachment recvSideAttachment, AwsConfiguration vsConfigs, ConvertedConfiguration viConfigs, Warnings warnings) { Configuration sendSideTgw = viConfigs.getNode(sendSideAttachment.getGatewayId()); if (sendSideTgw == null) { warnings.redFlag( String.format("Configuration not found for TGW %s", sendSideAttachment.getGatewayId())); return; } Configuration recvSideTgw = viConfigs.getNode(recvSideAttachment.getGatewayId()); if (recvSideTgw == null) { warnings.redFlag( String.format("Configuration not found for TGW %s", recvSideAttachment.getGatewayId())); return; } String associatedRouteTableId = recvSideAttachment.getAssociation() == null ? null : recvSideAttachment.getAssociation().getRouteTableId(); if (associatedRouteTableId == null) { warnings.redFlag( String.format( "No route table associated for peering attachment %s on TGW %s", recvSideAttachment.getId(), recvSideAttachment.getGatewayId())); return; } List<Region> sendSideRegions = vsConfigs.getAccounts().stream() .filter(a -> a.getId().equals(sendSideAttachment.getGatewayOwnerId())) .flatMap(a -> a.getRegions().stream()) .filter(r -> r.getTransitGateways().containsKey(sendSideAttachment.getGatewayId())) .collect(ImmutableList.toImmutableList()); if (sendSideRegions.isEmpty()) { warnings.redFlag( String.format( "TGW %s not found in any region of account %s", sendSideAttachment.getGatewayId(), sendSideAttachment.getGatewayOwnerId())); return; } if (sendSideRegions.size() > 1) { warnings.redFlag( String.format( "TGW %s found in multiple regions for account %s. Skipping its peering attachments.", sendSideAttachment.getGatewayId(), sendSideAttachment.getGatewayOwnerId())); return; } Set<TransitGatewayRouteTable> sendSideRouteTables = sendSideRegions.get(0).getTransitGatewayRouteTables().values().stream() .filter( routeTable -> routeTable.getGatewayId().equals(sendSideAttachment.getGatewayId())) .collect(ImmutableSet.toImmutableSet()); sendSideRouteTables.forEach( rt -> { Interface sendSideIface = sendSideTgw .getAllInterfaces() .get(sendSidePeeringInterfaceName(rt.getId(), sendSideAttachment.getId())); if (sendSideIface == null) { warnings.redFlag( String.format( "Interface for route table %s for peering attachment %s on TGW %s not found", rt.getId(), sendSideAttachment.getId(), sendSideAttachment.getGatewayId())); return; } Interface recvSideIface = Utils.newInterface( receiveSidePeeringInterfaceName( rt.getId(), recvSideAttachment.getId(), associatedRouteTableId), recvSideTgw, vrfNameForRouteTable(associatedRouteTableId), LinkLocalAddress.of(LINK_LOCAL_IP), "From " + recvSideAttachment.getResourceId()); Utils.addLayer1Edge( viConfigs, sendSideTgw.getHostname(), sendSideIface.getName(), recvSideTgw.getHostname(), recvSideIface.getName()); }); }  }
TransitGatewayPeeringConnector { @VisibleForTesting static void connectSenderReceiver( TransitGatewayAttachment sendSideAttachment, TransitGatewayAttachment recvSideAttachment, AwsConfiguration vsConfigs, ConvertedConfiguration viConfigs, Warnings warnings) { Configuration sendSideTgw = viConfigs.getNode(sendSideAttachment.getGatewayId()); if (sendSideTgw == null) { warnings.redFlag( String.format("Configuration not found for TGW %s", sendSideAttachment.getGatewayId())); return; } Configuration recvSideTgw = viConfigs.getNode(recvSideAttachment.getGatewayId()); if (recvSideTgw == null) { warnings.redFlag( String.format("Configuration not found for TGW %s", recvSideAttachment.getGatewayId())); return; } String associatedRouteTableId = recvSideAttachment.getAssociation() == null ? null : recvSideAttachment.getAssociation().getRouteTableId(); if (associatedRouteTableId == null) { warnings.redFlag( String.format( "No route table associated for peering attachment %s on TGW %s", recvSideAttachment.getId(), recvSideAttachment.getGatewayId())); return; } List<Region> sendSideRegions = vsConfigs.getAccounts().stream() .filter(a -> a.getId().equals(sendSideAttachment.getGatewayOwnerId())) .flatMap(a -> a.getRegions().stream()) .filter(r -> r.getTransitGateways().containsKey(sendSideAttachment.getGatewayId())) .collect(ImmutableList.toImmutableList()); if (sendSideRegions.isEmpty()) { warnings.redFlag( String.format( "TGW %s not found in any region of account %s", sendSideAttachment.getGatewayId(), sendSideAttachment.getGatewayOwnerId())); return; } if (sendSideRegions.size() > 1) { warnings.redFlag( String.format( "TGW %s found in multiple regions for account %s. Skipping its peering attachments.", sendSideAttachment.getGatewayId(), sendSideAttachment.getGatewayOwnerId())); return; } Set<TransitGatewayRouteTable> sendSideRouteTables = sendSideRegions.get(0).getTransitGatewayRouteTables().values().stream() .filter( routeTable -> routeTable.getGatewayId().equals(sendSideAttachment.getGatewayId())) .collect(ImmutableSet.toImmutableSet()); sendSideRouteTables.forEach( rt -> { Interface sendSideIface = sendSideTgw .getAllInterfaces() .get(sendSidePeeringInterfaceName(rt.getId(), sendSideAttachment.getId())); if (sendSideIface == null) { warnings.redFlag( String.format( "Interface for route table %s for peering attachment %s on TGW %s not found", rt.getId(), sendSideAttachment.getId(), sendSideAttachment.getGatewayId())); return; } Interface recvSideIface = Utils.newInterface( receiveSidePeeringInterfaceName( rt.getId(), recvSideAttachment.getId(), associatedRouteTableId), recvSideTgw, vrfNameForRouteTable(associatedRouteTableId), LinkLocalAddress.of(LINK_LOCAL_IP), "From " + recvSideAttachment.getResourceId()); Utils.addLayer1Edge( viConfigs, sendSideTgw.getHostname(), sendSideIface.getName(), recvSideTgw.getHostname(), recvSideIface.getName()); }); }  static void connect(
      AwsConfiguration vsConfigs, ConvertedConfiguration viConfigs, Warnings warnings); }
TransitGatewayPeeringConnector { @VisibleForTesting static void connectSenderReceiver( TransitGatewayAttachment sendSideAttachment, TransitGatewayAttachment recvSideAttachment, AwsConfiguration vsConfigs, ConvertedConfiguration viConfigs, Warnings warnings) { Configuration sendSideTgw = viConfigs.getNode(sendSideAttachment.getGatewayId()); if (sendSideTgw == null) { warnings.redFlag( String.format("Configuration not found for TGW %s", sendSideAttachment.getGatewayId())); return; } Configuration recvSideTgw = viConfigs.getNode(recvSideAttachment.getGatewayId()); if (recvSideTgw == null) { warnings.redFlag( String.format("Configuration not found for TGW %s", recvSideAttachment.getGatewayId())); return; } String associatedRouteTableId = recvSideAttachment.getAssociation() == null ? null : recvSideAttachment.getAssociation().getRouteTableId(); if (associatedRouteTableId == null) { warnings.redFlag( String.format( "No route table associated for peering attachment %s on TGW %s", recvSideAttachment.getId(), recvSideAttachment.getGatewayId())); return; } List<Region> sendSideRegions = vsConfigs.getAccounts().stream() .filter(a -> a.getId().equals(sendSideAttachment.getGatewayOwnerId())) .flatMap(a -> a.getRegions().stream()) .filter(r -> r.getTransitGateways().containsKey(sendSideAttachment.getGatewayId())) .collect(ImmutableList.toImmutableList()); if (sendSideRegions.isEmpty()) { warnings.redFlag( String.format( "TGW %s not found in any region of account %s", sendSideAttachment.getGatewayId(), sendSideAttachment.getGatewayOwnerId())); return; } if (sendSideRegions.size() > 1) { warnings.redFlag( String.format( "TGW %s found in multiple regions for account %s. Skipping its peering attachments.", sendSideAttachment.getGatewayId(), sendSideAttachment.getGatewayOwnerId())); return; } Set<TransitGatewayRouteTable> sendSideRouteTables = sendSideRegions.get(0).getTransitGatewayRouteTables().values().stream() .filter( routeTable -> routeTable.getGatewayId().equals(sendSideAttachment.getGatewayId())) .collect(ImmutableSet.toImmutableSet()); sendSideRouteTables.forEach( rt -> { Interface sendSideIface = sendSideTgw .getAllInterfaces() .get(sendSidePeeringInterfaceName(rt.getId(), sendSideAttachment.getId())); if (sendSideIface == null) { warnings.redFlag( String.format( "Interface for route table %s for peering attachment %s on TGW %s not found", rt.getId(), sendSideAttachment.getId(), sendSideAttachment.getGatewayId())); return; } Interface recvSideIface = Utils.newInterface( receiveSidePeeringInterfaceName( rt.getId(), recvSideAttachment.getId(), associatedRouteTableId), recvSideTgw, vrfNameForRouteTable(associatedRouteTableId), LinkLocalAddress.of(LINK_LOCAL_IP), "From " + recvSideAttachment.getResourceId()); Utils.addLayer1Edge( viConfigs, sendSideTgw.getHostname(), sendSideIface.getName(), recvSideTgw.getHostname(), recvSideIface.getName()); }); }  static void connect(
      AwsConfiguration vsConfigs, ConvertedConfiguration viConfigs, Warnings warnings);  }