@Test public void testApplyToGateway() { VpnGateway vgw = new VpnGateway("vpn", ImmutableList.of(), ImmutableMap.of()); Configuration vgwConfig = Utils.newAwsConfiguration(vgw.getId(), "awstest"); VpnConnection.initVpnConnectionsInfrastructure(vgwConfig); Vrf vpnVrf = Vrf.builder().setOwner(vgwConfig).setName("vpn").build(); BgpProcess bgpProc = BgpProcess.builder() .setRouterId(Ip.parse("1.1.1.1")) .setVrf(vpnVrf) .setAdminCostsToVendorDefaults(ConfigurationFormat.AWS) .build(); IpsecTunnel ipsecTunnel = new IpsecTunnel( 65301L, Ip.parse("169.254.15.194"), 30, Ip.parse("147.75.69.27"), "sha1", "aes-128-cbc", 28800, "main", "group2", "7db2fd6e9dcffcf826743b57bc0518cfcbca8f4db0b80a7a2c3f0c3b09deb49a", "hmac-sha1-96", "aes-128-cbc", 3600, "tunnel", "group2", "esp", 65401L, Ip.parse("169.254.15.193"), 30, Ip.parse("52.27.166.152")); List<Prefix> staticRoutes = ImmutableList.of(Prefix.parse("2.2.2.2/23")); VpnConnection vpnConnection = new VpnConnection( true, "vpn-ba2e34a8", "cgw-fb76ace5", GatewayType.VPN, vgw.getId(), ImmutableList.of(ipsecTunnel), staticRoutes, ImmutableList.of(), false); Warnings warnings = new Warnings(true, true, true); vpnConnection.applyToGateway(vgwConfig, vpnVrf, "ExportPolicy", "ImportPolicy", warnings); assertTrue(warnings.getRedFlagWarnings().isEmpty()); assertThat( vgwConfig.getAllInterfaces().keySet(), equalTo( ImmutableSet.of( BACKBONE_FACING_INTERFACE_NAME, vpnExternalInterfaceName(vpnTunnelId(vpnConnection.getVpnConnectionId(), 1)), vpnInterfaceName(vpnTunnelId(vpnConnection.getVpnConnectionId(), 1))))); assertThat( vgwConfig .getAllInterfaces() .get(vpnExternalInterfaceName(vpnTunnelId(vpnConnection.getVpnConnectionId(), 1))) .getVrfName(), equalTo(VPN_UNDERLAY_VRF_NAME)); assertThat( vgwConfig .getAllInterfaces() .get(vpnInterfaceName(vpnTunnelId(vpnConnection.getVpnConnectionId(), 1))) .getVrfName(), equalTo(vpnVrf.getName())); BgpActivePeerConfig bgpActivePeerConfig = getOnlyElement(vpnVrf.getBgpProcess().getActiveNeighbors().values()); assertThat( bgpActivePeerConfig, equalTo( BgpActivePeerConfig.builder() .setPeerAddress(ipsecTunnel.getCgwInsideAddress()) .setRemoteAs(ipsecTunnel.getCgwBgpAsn()) .setBgpProcess(bgpProc) .setLocalAs(ipsecTunnel.getVgwBgpAsn()) .setLocalIp(ipsecTunnel.getVgwInsideAddress()) .setIpv4UnicastAddressFamily( Ipv4UnicastAddressFamily.builder() .setExportPolicy("ExportPolicy") .setImportPolicy("ImportPolicy") .build()) .build())); assertThat( vgwConfig.getDefaultVrf().getStaticRoutes(), equalTo( staticRoutes.stream() .map(pfx -> toStaticRoute(pfx, ipsecTunnel.getCgwInsideAddress())) .collect(ImmutableSortedSet.toImmutableSortedSet(Comparator.naturalOrder())))); }
void applyToGateway( Configuration gwCfg, Vrf tunnelVrf, @Nullable String exportPolicyName, @Nullable String importPolicyName, Warnings warnings) { ImmutableSortedMap.Builder<String, IkePhase1Policy> ikePhase1PolicyMapBuilder = ImmutableSortedMap.naturalOrder(); ImmutableSortedMap.Builder<String, IkePhase1Key> ikePhase1KeyMapBuilder = ImmutableSortedMap.naturalOrder(); ImmutableSortedMap.Builder<String, IkePhase1Proposal> ikePhase1ProposalMapBuilder = ImmutableSortedMap.naturalOrder(); ImmutableSortedMap.Builder<String, IpsecPhase2Proposal> ipsecPhase2ProposalMapBuilder = ImmutableSortedMap.naturalOrder(); ImmutableSortedMap.Builder<String, IpsecPhase2Policy> ipsecPhase2PolicyMapBuilder = ImmutableSortedMap.naturalOrder(); ImmutableSortedMap.Builder<String, IpsecPeerConfig> ipsecPeerConfigMapBuilder = ImmutableSortedMap.naturalOrder(); if (gwCfg.getVrfs().get(VPN_UNDERLAY_VRF_NAME) == null) { warnings.redFlag( String.format("Underlay VRF does not exist on gateway %s", gwCfg.getHostname())); return; } if (gwCfg.getVrfs().get(tunnelVrf.getName()) == null) { warnings.redFlag( String.format("Tunnel VRF does not exist on gateway %s", gwCfg.getHostname())); return; } for (int i = 0; i < _ipsecTunnels.size(); i++) { String tunnelId = vpnTunnelId(_vpnConnectionId, i + 1); IpsecTunnel ipsecTunnel = _ipsecTunnels.get(i); String externalInterfaceName = vpnExternalInterfaceName(tunnelId); ConcreteInterfaceAddress externalInterfaceAddress = ConcreteInterfaceAddress.create( ipsecTunnel.getVgwOutsideAddress(), Prefix.MAX_PREFIX_LENGTH); Utils.newInterface( externalInterfaceName, gwCfg, VPN_UNDERLAY_VRF_NAME, externalInterfaceAddress, "IPSec tunnel " + tunnelId); String vpnIfaceName = vpnInterfaceName(tunnelId); ConcreteInterfaceAddress vpnInterfaceAddress = ConcreteInterfaceAddress.create( ipsecTunnel.getVgwInsideAddress(), ipsecTunnel.getVgwInsidePrefixLength()); Utils.newInterface( vpnIfaceName, gwCfg, tunnelVrf.getName(), vpnInterfaceAddress, "VPN " + tunnelId); ikePhase1ProposalMapBuilder.put(tunnelId, toIkePhase1Proposal(tunnelId, ipsecTunnel)); IkePhase1Key ikePhase1Key = toIkePhase1PreSharedKey( ipsecTunnel, ipsecTunnel.getCgwOutsideAddress(), externalInterfaceName); ikePhase1KeyMapBuilder.put(tunnelId, ikePhase1Key); ikePhase1PolicyMapBuilder.put( tunnelId, toIkePhase1Policy( tunnelId, tunnelId, ikePhase1Key, ipsecTunnel.getCgwOutsideAddress(), externalInterfaceName)); ipsecPhase2ProposalMapBuilder.put(tunnelId, toIpsecPhase2Proposal(ipsecTunnel, warnings)); ipsecPhase2PolicyMapBuilder.put(tunnelId, toIpsecPhase2Policy(ipsecTunnel, tunnelId)); ipsecPeerConfigMapBuilder.put( tunnelId, IpsecStaticPeerConfig.builder() .setTunnelInterface(vpnIfaceName) .setIkePhase1Policy(tunnelId) .setIpsecPolicy(tunnelId) .setSourceInterface(externalInterfaceName) .setLocalAddress(ipsecTunnel.getVgwOutsideAddress()) .setDestinationAddress(ipsecTunnel.getCgwOutsideAddress()) .build()); if (_isBgpConnection) { BgpActivePeerConfig.builder() .setPeerAddress(ipsecTunnel.getCgwInsideAddress()) .setRemoteAs(ipsecTunnel.getCgwBgpAsn()) .setBgpProcess(tunnelVrf.getBgpProcess()) .setLocalAs(ipsecTunnel.getVgwBgpAsn()) .setLocalIp(ipsecTunnel.getVgwInsideAddress()) .setIpv4UnicastAddressFamily( Ipv4UnicastAddressFamily.builder() .setExportPolicy(exportPolicyName) .setImportPolicy(importPolicyName) .build()) .build(); } _routes.forEach( pfx -> addStaticRoute(gwCfg, toStaticRoute(pfx, ipsecTunnel.getCgwInsideAddress()))); } gwCfg.setIkePhase1Proposals(ikePhase1ProposalMapBuilder.build()); gwCfg.setIkePhase1Keys(ikePhase1KeyMapBuilder.build()); gwCfg.setIkePhase1Policies(ikePhase1PolicyMapBuilder.build()); gwCfg.setIpsecPhase2Proposals(ipsecPhase2ProposalMapBuilder.build()); gwCfg.setIpsecPhase2Policies(ipsecPhase2PolicyMapBuilder.build()); gwCfg.setIpsecPeerConfigs(ipsecPeerConfigMapBuilder.build()); }
VpnConnection implements AwsVpcEntity, Serializable { void applyToGateway( Configuration gwCfg, Vrf tunnelVrf, @Nullable String exportPolicyName, @Nullable String importPolicyName, Warnings warnings) { ImmutableSortedMap.Builder<String, IkePhase1Policy> ikePhase1PolicyMapBuilder = ImmutableSortedMap.naturalOrder(); ImmutableSortedMap.Builder<String, IkePhase1Key> ikePhase1KeyMapBuilder = ImmutableSortedMap.naturalOrder(); ImmutableSortedMap.Builder<String, IkePhase1Proposal> ikePhase1ProposalMapBuilder = ImmutableSortedMap.naturalOrder(); ImmutableSortedMap.Builder<String, IpsecPhase2Proposal> ipsecPhase2ProposalMapBuilder = ImmutableSortedMap.naturalOrder(); ImmutableSortedMap.Builder<String, IpsecPhase2Policy> ipsecPhase2PolicyMapBuilder = ImmutableSortedMap.naturalOrder(); ImmutableSortedMap.Builder<String, IpsecPeerConfig> ipsecPeerConfigMapBuilder = ImmutableSortedMap.naturalOrder(); if (gwCfg.getVrfs().get(VPN_UNDERLAY_VRF_NAME) == null) { warnings.redFlag( String.format("Underlay VRF does not exist on gateway %s", gwCfg.getHostname())); return; } if (gwCfg.getVrfs().get(tunnelVrf.getName()) == null) { warnings.redFlag( String.format("Tunnel VRF does not exist on gateway %s", gwCfg.getHostname())); return; } for (int i = 0; i < _ipsecTunnels.size(); i++) { String tunnelId = vpnTunnelId(_vpnConnectionId, i + 1); IpsecTunnel ipsecTunnel = _ipsecTunnels.get(i); String externalInterfaceName = vpnExternalInterfaceName(tunnelId); ConcreteInterfaceAddress externalInterfaceAddress = ConcreteInterfaceAddress.create( ipsecTunnel.getVgwOutsideAddress(), Prefix.MAX_PREFIX_LENGTH); Utils.newInterface( externalInterfaceName, gwCfg, VPN_UNDERLAY_VRF_NAME, externalInterfaceAddress, "IPSec tunnel " + tunnelId); String vpnIfaceName = vpnInterfaceName(tunnelId); ConcreteInterfaceAddress vpnInterfaceAddress = ConcreteInterfaceAddress.create( ipsecTunnel.getVgwInsideAddress(), ipsecTunnel.getVgwInsidePrefixLength()); Utils.newInterface( vpnIfaceName, gwCfg, tunnelVrf.getName(), vpnInterfaceAddress, "VPN " + tunnelId); ikePhase1ProposalMapBuilder.put(tunnelId, toIkePhase1Proposal(tunnelId, ipsecTunnel)); IkePhase1Key ikePhase1Key = toIkePhase1PreSharedKey( ipsecTunnel, ipsecTunnel.getCgwOutsideAddress(), externalInterfaceName); ikePhase1KeyMapBuilder.put(tunnelId, ikePhase1Key); ikePhase1PolicyMapBuilder.put( tunnelId, toIkePhase1Policy( tunnelId, tunnelId, ikePhase1Key, ipsecTunnel.getCgwOutsideAddress(), externalInterfaceName)); ipsecPhase2ProposalMapBuilder.put(tunnelId, toIpsecPhase2Proposal(ipsecTunnel, warnings)); ipsecPhase2PolicyMapBuilder.put(tunnelId, toIpsecPhase2Policy(ipsecTunnel, tunnelId)); ipsecPeerConfigMapBuilder.put( tunnelId, IpsecStaticPeerConfig.builder() .setTunnelInterface(vpnIfaceName) .setIkePhase1Policy(tunnelId) .setIpsecPolicy(tunnelId) .setSourceInterface(externalInterfaceName) .setLocalAddress(ipsecTunnel.getVgwOutsideAddress()) .setDestinationAddress(ipsecTunnel.getCgwOutsideAddress()) .build()); if (_isBgpConnection) { BgpActivePeerConfig.builder() .setPeerAddress(ipsecTunnel.getCgwInsideAddress()) .setRemoteAs(ipsecTunnel.getCgwBgpAsn()) .setBgpProcess(tunnelVrf.getBgpProcess()) .setLocalAs(ipsecTunnel.getVgwBgpAsn()) .setLocalIp(ipsecTunnel.getVgwInsideAddress()) .setIpv4UnicastAddressFamily( Ipv4UnicastAddressFamily.builder() .setExportPolicy(exportPolicyName) .setImportPolicy(importPolicyName) .build()) .build(); } _routes.forEach( pfx -> addStaticRoute(gwCfg, toStaticRoute(pfx, ipsecTunnel.getCgwInsideAddress()))); } gwCfg.setIkePhase1Proposals(ikePhase1ProposalMapBuilder.build()); gwCfg.setIkePhase1Keys(ikePhase1KeyMapBuilder.build()); gwCfg.setIkePhase1Policies(ikePhase1PolicyMapBuilder.build()); gwCfg.setIpsecPhase2Proposals(ipsecPhase2ProposalMapBuilder.build()); gwCfg.setIpsecPhase2Policies(ipsecPhase2PolicyMapBuilder.build()); gwCfg.setIpsecPeerConfigs(ipsecPeerConfigMapBuilder.build()); } }
VpnConnection implements AwsVpcEntity, Serializable { void applyToGateway( Configuration gwCfg, Vrf tunnelVrf, @Nullable String exportPolicyName, @Nullable String importPolicyName, Warnings warnings) { ImmutableSortedMap.Builder<String, IkePhase1Policy> ikePhase1PolicyMapBuilder = ImmutableSortedMap.naturalOrder(); ImmutableSortedMap.Builder<String, IkePhase1Key> ikePhase1KeyMapBuilder = ImmutableSortedMap.naturalOrder(); ImmutableSortedMap.Builder<String, IkePhase1Proposal> ikePhase1ProposalMapBuilder = ImmutableSortedMap.naturalOrder(); ImmutableSortedMap.Builder<String, IpsecPhase2Proposal> ipsecPhase2ProposalMapBuilder = ImmutableSortedMap.naturalOrder(); ImmutableSortedMap.Builder<String, IpsecPhase2Policy> ipsecPhase2PolicyMapBuilder = ImmutableSortedMap.naturalOrder(); ImmutableSortedMap.Builder<String, IpsecPeerConfig> ipsecPeerConfigMapBuilder = ImmutableSortedMap.naturalOrder(); if (gwCfg.getVrfs().get(VPN_UNDERLAY_VRF_NAME) == null) { warnings.redFlag( String.format("Underlay VRF does not exist on gateway %s", gwCfg.getHostname())); return; } if (gwCfg.getVrfs().get(tunnelVrf.getName()) == null) { warnings.redFlag( String.format("Tunnel VRF does not exist on gateway %s", gwCfg.getHostname())); return; } for (int i = 0; i < _ipsecTunnels.size(); i++) { String tunnelId = vpnTunnelId(_vpnConnectionId, i + 1); IpsecTunnel ipsecTunnel = _ipsecTunnels.get(i); String externalInterfaceName = vpnExternalInterfaceName(tunnelId); ConcreteInterfaceAddress externalInterfaceAddress = ConcreteInterfaceAddress.create( ipsecTunnel.getVgwOutsideAddress(), Prefix.MAX_PREFIX_LENGTH); Utils.newInterface( externalInterfaceName, gwCfg, VPN_UNDERLAY_VRF_NAME, externalInterfaceAddress, "IPSec tunnel " + tunnelId); String vpnIfaceName = vpnInterfaceName(tunnelId); ConcreteInterfaceAddress vpnInterfaceAddress = ConcreteInterfaceAddress.create( ipsecTunnel.getVgwInsideAddress(), ipsecTunnel.getVgwInsidePrefixLength()); Utils.newInterface( vpnIfaceName, gwCfg, tunnelVrf.getName(), vpnInterfaceAddress, "VPN " + tunnelId); ikePhase1ProposalMapBuilder.put(tunnelId, toIkePhase1Proposal(tunnelId, ipsecTunnel)); IkePhase1Key ikePhase1Key = toIkePhase1PreSharedKey( ipsecTunnel, ipsecTunnel.getCgwOutsideAddress(), externalInterfaceName); ikePhase1KeyMapBuilder.put(tunnelId, ikePhase1Key); ikePhase1PolicyMapBuilder.put( tunnelId, toIkePhase1Policy( tunnelId, tunnelId, ikePhase1Key, ipsecTunnel.getCgwOutsideAddress(), externalInterfaceName)); ipsecPhase2ProposalMapBuilder.put(tunnelId, toIpsecPhase2Proposal(ipsecTunnel, warnings)); ipsecPhase2PolicyMapBuilder.put(tunnelId, toIpsecPhase2Policy(ipsecTunnel, tunnelId)); ipsecPeerConfigMapBuilder.put( tunnelId, IpsecStaticPeerConfig.builder() .setTunnelInterface(vpnIfaceName) .setIkePhase1Policy(tunnelId) .setIpsecPolicy(tunnelId) .setSourceInterface(externalInterfaceName) .setLocalAddress(ipsecTunnel.getVgwOutsideAddress()) .setDestinationAddress(ipsecTunnel.getCgwOutsideAddress()) .build()); if (_isBgpConnection) { BgpActivePeerConfig.builder() .setPeerAddress(ipsecTunnel.getCgwInsideAddress()) .setRemoteAs(ipsecTunnel.getCgwBgpAsn()) .setBgpProcess(tunnelVrf.getBgpProcess()) .setLocalAs(ipsecTunnel.getVgwBgpAsn()) .setLocalIp(ipsecTunnel.getVgwInsideAddress()) .setIpv4UnicastAddressFamily( Ipv4UnicastAddressFamily.builder() .setExportPolicy(exportPolicyName) .setImportPolicy(importPolicyName) .build()) .build(); } _routes.forEach( pfx -> addStaticRoute(gwCfg, toStaticRoute(pfx, ipsecTunnel.getCgwInsideAddress()))); } gwCfg.setIkePhase1Proposals(ikePhase1ProposalMapBuilder.build()); gwCfg.setIkePhase1Keys(ikePhase1KeyMapBuilder.build()); gwCfg.setIkePhase1Policies(ikePhase1PolicyMapBuilder.build()); gwCfg.setIpsecPhase2Proposals(ipsecPhase2ProposalMapBuilder.build()); gwCfg.setIpsecPhase2Policies(ipsecPhase2PolicyMapBuilder.build()); gwCfg.setIpsecPeerConfigs(ipsecPeerConfigMapBuilder.build()); } VpnConnection(
      boolean isBgpConnection,
      String vpnConnectionId,
      String customerGatewayId,
      GatewayType awsGatewayType,
      String awsGatewayId,
      List<IpsecTunnel> ipsecTunnels,
      List<Prefix> routes,
      List<VgwTelemetry> vgwTelemetrys,
      boolean staticRoutesOnly); }
VpnConnection implements AwsVpcEntity, Serializable { void applyToGateway( Configuration gwCfg, Vrf tunnelVrf, @Nullable String exportPolicyName, @Nullable String importPolicyName, Warnings warnings) { ImmutableSortedMap.Builder<String, IkePhase1Policy> ikePhase1PolicyMapBuilder = ImmutableSortedMap.naturalOrder(); ImmutableSortedMap.Builder<String, IkePhase1Key> ikePhase1KeyMapBuilder = ImmutableSortedMap.naturalOrder(); ImmutableSortedMap.Builder<String, IkePhase1Proposal> ikePhase1ProposalMapBuilder = ImmutableSortedMap.naturalOrder(); ImmutableSortedMap.Builder<String, IpsecPhase2Proposal> ipsecPhase2ProposalMapBuilder = ImmutableSortedMap.naturalOrder(); ImmutableSortedMap.Builder<String, IpsecPhase2Policy> ipsecPhase2PolicyMapBuilder = ImmutableSortedMap.naturalOrder(); ImmutableSortedMap.Builder<String, IpsecPeerConfig> ipsecPeerConfigMapBuilder = ImmutableSortedMap.naturalOrder(); if (gwCfg.getVrfs().get(VPN_UNDERLAY_VRF_NAME) == null) { warnings.redFlag( String.format("Underlay VRF does not exist on gateway %s", gwCfg.getHostname())); return; } if (gwCfg.getVrfs().get(tunnelVrf.getName()) == null) { warnings.redFlag( String.format("Tunnel VRF does not exist on gateway %s", gwCfg.getHostname())); return; } for (int i = 0; i < _ipsecTunnels.size(); i++) { String tunnelId = vpnTunnelId(_vpnConnectionId, i + 1); IpsecTunnel ipsecTunnel = _ipsecTunnels.get(i); String externalInterfaceName = vpnExternalInterfaceName(tunnelId); ConcreteInterfaceAddress externalInterfaceAddress = ConcreteInterfaceAddress.create( ipsecTunnel.getVgwOutsideAddress(), Prefix.MAX_PREFIX_LENGTH); Utils.newInterface( externalInterfaceName, gwCfg, VPN_UNDERLAY_VRF_NAME, externalInterfaceAddress, "IPSec tunnel " + tunnelId); String vpnIfaceName = vpnInterfaceName(tunnelId); ConcreteInterfaceAddress vpnInterfaceAddress = ConcreteInterfaceAddress.create( ipsecTunnel.getVgwInsideAddress(), ipsecTunnel.getVgwInsidePrefixLength()); Utils.newInterface( vpnIfaceName, gwCfg, tunnelVrf.getName(), vpnInterfaceAddress, "VPN " + tunnelId); ikePhase1ProposalMapBuilder.put(tunnelId, toIkePhase1Proposal(tunnelId, ipsecTunnel)); IkePhase1Key ikePhase1Key = toIkePhase1PreSharedKey( ipsecTunnel, ipsecTunnel.getCgwOutsideAddress(), externalInterfaceName); ikePhase1KeyMapBuilder.put(tunnelId, ikePhase1Key); ikePhase1PolicyMapBuilder.put( tunnelId, toIkePhase1Policy( tunnelId, tunnelId, ikePhase1Key, ipsecTunnel.getCgwOutsideAddress(), externalInterfaceName)); ipsecPhase2ProposalMapBuilder.put(tunnelId, toIpsecPhase2Proposal(ipsecTunnel, warnings)); ipsecPhase2PolicyMapBuilder.put(tunnelId, toIpsecPhase2Policy(ipsecTunnel, tunnelId)); ipsecPeerConfigMapBuilder.put( tunnelId, IpsecStaticPeerConfig.builder() .setTunnelInterface(vpnIfaceName) .setIkePhase1Policy(tunnelId) .setIpsecPolicy(tunnelId) .setSourceInterface(externalInterfaceName) .setLocalAddress(ipsecTunnel.getVgwOutsideAddress()) .setDestinationAddress(ipsecTunnel.getCgwOutsideAddress()) .build()); if (_isBgpConnection) { BgpActivePeerConfig.builder() .setPeerAddress(ipsecTunnel.getCgwInsideAddress()) .setRemoteAs(ipsecTunnel.getCgwBgpAsn()) .setBgpProcess(tunnelVrf.getBgpProcess()) .setLocalAs(ipsecTunnel.getVgwBgpAsn()) .setLocalIp(ipsecTunnel.getVgwInsideAddress()) .setIpv4UnicastAddressFamily( Ipv4UnicastAddressFamily.builder() .setExportPolicy(exportPolicyName) .setImportPolicy(importPolicyName) .build()) .build(); } _routes.forEach( pfx -> addStaticRoute(gwCfg, toStaticRoute(pfx, ipsecTunnel.getCgwInsideAddress()))); } gwCfg.setIkePhase1Proposals(ikePhase1ProposalMapBuilder.build()); gwCfg.setIkePhase1Keys(ikePhase1KeyMapBuilder.build()); gwCfg.setIkePhase1Policies(ikePhase1PolicyMapBuilder.build()); gwCfg.setIpsecPhase2Proposals(ipsecPhase2ProposalMapBuilder.build()); gwCfg.setIpsecPhase2Policies(ipsecPhase2PolicyMapBuilder.build()); gwCfg.setIpsecPeerConfigs(ipsecPeerConfigMapBuilder.build()); } VpnConnection(
      boolean isBgpConnection,
      String vpnConnectionId,
      String customerGatewayId,
      GatewayType awsGatewayType,
      String awsGatewayId,
      List<IpsecTunnel> ipsecTunnels,
      List<Prefix> routes,
      List<VgwTelemetry> vgwTelemetrys,
      boolean staticRoutesOnly); @Override String getId(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); }
VpnConnection implements AwsVpcEntity, Serializable { void applyToGateway( Configuration gwCfg, Vrf tunnelVrf, @Nullable String exportPolicyName, @Nullable String importPolicyName, Warnings warnings) { ImmutableSortedMap.Builder<String, IkePhase1Policy> ikePhase1PolicyMapBuilder = ImmutableSortedMap.naturalOrder(); ImmutableSortedMap.Builder<String, IkePhase1Key> ikePhase1KeyMapBuilder = ImmutableSortedMap.naturalOrder(); ImmutableSortedMap.Builder<String, IkePhase1Proposal> ikePhase1ProposalMapBuilder = ImmutableSortedMap.naturalOrder(); ImmutableSortedMap.Builder<String, IpsecPhase2Proposal> ipsecPhase2ProposalMapBuilder = ImmutableSortedMap.naturalOrder(); ImmutableSortedMap.Builder<String, IpsecPhase2Policy> ipsecPhase2PolicyMapBuilder = ImmutableSortedMap.naturalOrder(); ImmutableSortedMap.Builder<String, IpsecPeerConfig> ipsecPeerConfigMapBuilder = ImmutableSortedMap.naturalOrder(); if (gwCfg.getVrfs().get(VPN_UNDERLAY_VRF_NAME) == null) { warnings.redFlag( String.format("Underlay VRF does not exist on gateway %s", gwCfg.getHostname())); return; } if (gwCfg.getVrfs().get(tunnelVrf.getName()) == null) { warnings.redFlag( String.format("Tunnel VRF does not exist on gateway %s", gwCfg.getHostname())); return; } for (int i = 0; i < _ipsecTunnels.size(); i++) { String tunnelId = vpnTunnelId(_vpnConnectionId, i + 1); IpsecTunnel ipsecTunnel = _ipsecTunnels.get(i); String externalInterfaceName = vpnExternalInterfaceName(tunnelId); ConcreteInterfaceAddress externalInterfaceAddress = ConcreteInterfaceAddress.create( ipsecTunnel.getVgwOutsideAddress(), Prefix.MAX_PREFIX_LENGTH); Utils.newInterface( externalInterfaceName, gwCfg, VPN_UNDERLAY_VRF_NAME, externalInterfaceAddress, "IPSec tunnel " + tunnelId); String vpnIfaceName = vpnInterfaceName(tunnelId); ConcreteInterfaceAddress vpnInterfaceAddress = ConcreteInterfaceAddress.create( ipsecTunnel.getVgwInsideAddress(), ipsecTunnel.getVgwInsidePrefixLength()); Utils.newInterface( vpnIfaceName, gwCfg, tunnelVrf.getName(), vpnInterfaceAddress, "VPN " + tunnelId); ikePhase1ProposalMapBuilder.put(tunnelId, toIkePhase1Proposal(tunnelId, ipsecTunnel)); IkePhase1Key ikePhase1Key = toIkePhase1PreSharedKey( ipsecTunnel, ipsecTunnel.getCgwOutsideAddress(), externalInterfaceName); ikePhase1KeyMapBuilder.put(tunnelId, ikePhase1Key); ikePhase1PolicyMapBuilder.put( tunnelId, toIkePhase1Policy( tunnelId, tunnelId, ikePhase1Key, ipsecTunnel.getCgwOutsideAddress(), externalInterfaceName)); ipsecPhase2ProposalMapBuilder.put(tunnelId, toIpsecPhase2Proposal(ipsecTunnel, warnings)); ipsecPhase2PolicyMapBuilder.put(tunnelId, toIpsecPhase2Policy(ipsecTunnel, tunnelId)); ipsecPeerConfigMapBuilder.put( tunnelId, IpsecStaticPeerConfig.builder() .setTunnelInterface(vpnIfaceName) .setIkePhase1Policy(tunnelId) .setIpsecPolicy(tunnelId) .setSourceInterface(externalInterfaceName) .setLocalAddress(ipsecTunnel.getVgwOutsideAddress()) .setDestinationAddress(ipsecTunnel.getCgwOutsideAddress()) .build()); if (_isBgpConnection) { BgpActivePeerConfig.builder() .setPeerAddress(ipsecTunnel.getCgwInsideAddress()) .setRemoteAs(ipsecTunnel.getCgwBgpAsn()) .setBgpProcess(tunnelVrf.getBgpProcess()) .setLocalAs(ipsecTunnel.getVgwBgpAsn()) .setLocalIp(ipsecTunnel.getVgwInsideAddress()) .setIpv4UnicastAddressFamily( Ipv4UnicastAddressFamily.builder() .setExportPolicy(exportPolicyName) .setImportPolicy(importPolicyName) .build()) .build(); } _routes.forEach( pfx -> addStaticRoute(gwCfg, toStaticRoute(pfx, ipsecTunnel.getCgwInsideAddress()))); } gwCfg.setIkePhase1Proposals(ikePhase1ProposalMapBuilder.build()); gwCfg.setIkePhase1Keys(ikePhase1KeyMapBuilder.build()); gwCfg.setIkePhase1Policies(ikePhase1PolicyMapBuilder.build()); gwCfg.setIpsecPhase2Proposals(ipsecPhase2ProposalMapBuilder.build()); gwCfg.setIpsecPhase2Policies(ipsecPhase2PolicyMapBuilder.build()); gwCfg.setIpsecPeerConfigs(ipsecPeerConfigMapBuilder.build()); } VpnConnection(
      boolean isBgpConnection,
      String vpnConnectionId,
      String customerGatewayId,
      GatewayType awsGatewayType,
      String awsGatewayId,
      List<IpsecTunnel> ipsecTunnels,
      List<Prefix> routes,
      List<VgwTelemetry> vgwTelemetrys,
      boolean staticRoutesOnly); @Override String getId(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString();  }