@Test public void testConvertVxlan_localIpPrecedence() { Configuration c = new Configuration("c", ConfigurationFormat.CUMULUS_CONCATENATED); Vrf vrf = new Vrf("vrf"); c.setVrfs(ImmutableMap.of(vrf.getName(), vrf)); Ip vxlanLocalTunnelIp = Ip.parse("1.1.1.1"); Ip loopbackTunnelIp = Ip.parse("2.2.2.2"); Ip loopbackAnycastIp = Ip.parse("3.3.3.3"); Vxlan vxlan = new Vxlan("vxlan1001"); vxlan.setId(1001); vxlan.setBridgeAccessVlan(101); vxlan.setLocalTunnelip(vxlanLocalTunnelIp); CumulusNcluConfiguration vsConfig = new CumulusNcluConfiguration(); vsConfig.setVxlans(ImmutableMap.of(vxlan.getName(), vxlan)); convertVxlans( c, vsConfig, ImmutableMap.of(1001, vrf.getName()), null, loopbackTunnelIp, new Warnings()); assertThat(vrf.getLayer3Vnis().get(1001).getSourceAddress(), equalTo(vxlanLocalTunnelIp)); vrf.setLayer3Vnis(ImmutableList.of()); convertVxlans( c, vsConfig, ImmutableMap.of(1001, vrf.getName()), loopbackAnycastIp, loopbackTunnelIp, new Warnings()); assertThat(vrf.getLayer3Vnis().get(1001).getSourceAddress(), equalTo(loopbackAnycastIp)); vrf.setLayer3Vnis(ImmutableList.of()); vxlan.setLocalTunnelip(null); convertVxlans( c, vsConfig, ImmutableMap.of(1001, vrf.getName()), null, loopbackTunnelIp, new Warnings()); assertThat(vrf.getLayer3Vnis().get(1001).getSourceAddress(), equalTo(loopbackTunnelIp)); }
static void convertVxlans( Configuration c, CumulusNodeConfiguration vsConfig, Map<Integer, String> vniToVrf, @Nullable Ip loopbackClagVxlanAnycastIp, @Nullable Ip loopbackVxlanLocalTunnelIp, Warnings w) { vsConfig .getVxlans() .values() .forEach( vxlan -> { if (vxlan.getId() == null || vxlan.getBridgeAccessVlan() == null) { w.redFlag( String.format( "Vxlan %s is not configured properly: %s is not defined", vxlan.getName(), vxlan.getId() == null ? "vxlan id" : "bridge access vlan")); return; } Ip localIp = Stream.of( loopbackClagVxlanAnycastIp, vxlan.getLocalTunnelip(), loopbackVxlanLocalTunnelIp) .filter(Objects::nonNull) .findFirst() .orElse(null); if (localIp == null) { w.redFlag( String.format( "Local tunnel IP for vxlan %s is not configured", vxlan.getName())); return; } @Nullable String vrfName = vniToVrf.get(vxlan.getId()); if (vrfName != null) { Optional.ofNullable(c.getVrfs().get(vrfName)) .ifPresent( vrf -> vrf.addLayer3Vni( Layer3Vni.builder() .setVni(vxlan.getId()) .setSourceAddress(localIp) .setUdpPort(NamedPort.VXLAN.number()) .setBumTransportMethod(BumTransportMethod.UNICAST_FLOOD_GROUP) .setSrcVrf(DEFAULT_VRF_NAME) .build())); } else { vrfName = vsConfig.getVrfForVlan(vxlan.getBridgeAccessVlan()); if (vrfName == null) { vrfName = DEFAULT_VRF_NAME; } Optional.ofNullable(c.getVrfs().get(vrfName)) .ifPresent( vrf -> vrf.addLayer2Vni( Layer2Vni.builder() .setVni(vxlan.getId()) .setVlan(vxlan.getBridgeAccessVlan()) .setSourceAddress(localIp) .setUdpPort(NamedPort.VXLAN.number()) .setBumTransportMethod(BumTransportMethod.UNICAST_FLOOD_GROUP) .setSrcVrf(DEFAULT_VRF_NAME) .build())); } }); }
CumulusConversions { static void convertVxlans( Configuration c, CumulusNodeConfiguration vsConfig, Map<Integer, String> vniToVrf, @Nullable Ip loopbackClagVxlanAnycastIp, @Nullable Ip loopbackVxlanLocalTunnelIp, Warnings w) { vsConfig .getVxlans() .values() .forEach( vxlan -> { if (vxlan.getId() == null || vxlan.getBridgeAccessVlan() == null) { w.redFlag( String.format( "Vxlan %s is not configured properly: %s is not defined", vxlan.getName(), vxlan.getId() == null ? "vxlan id" : "bridge access vlan")); return; } Ip localIp = Stream.of( loopbackClagVxlanAnycastIp, vxlan.getLocalTunnelip(), loopbackVxlanLocalTunnelIp) .filter(Objects::nonNull) .findFirst() .orElse(null); if (localIp == null) { w.redFlag( String.format( "Local tunnel IP for vxlan %s is not configured", vxlan.getName())); return; } @Nullable String vrfName = vniToVrf.get(vxlan.getId()); if (vrfName != null) { Optional.ofNullable(c.getVrfs().get(vrfName)) .ifPresent( vrf -> vrf.addLayer3Vni( Layer3Vni.builder() .setVni(vxlan.getId()) .setSourceAddress(localIp) .setUdpPort(NamedPort.VXLAN.number()) .setBumTransportMethod(BumTransportMethod.UNICAST_FLOOD_GROUP) .setSrcVrf(DEFAULT_VRF_NAME) .build())); } else { vrfName = vsConfig.getVrfForVlan(vxlan.getBridgeAccessVlan()); if (vrfName == null) { vrfName = DEFAULT_VRF_NAME; } Optional.ofNullable(c.getVrfs().get(vrfName)) .ifPresent( vrf -> vrf.addLayer2Vni( Layer2Vni.builder() .setVni(vxlan.getId()) .setVlan(vxlan.getBridgeAccessVlan()) .setSourceAddress(localIp) .setUdpPort(NamedPort.VXLAN.number()) .setBumTransportMethod(BumTransportMethod.UNICAST_FLOOD_GROUP) .setSrcVrf(DEFAULT_VRF_NAME) .build())); } }); } }
CumulusConversions { static void convertVxlans( Configuration c, CumulusNodeConfiguration vsConfig, Map<Integer, String> vniToVrf, @Nullable Ip loopbackClagVxlanAnycastIp, @Nullable Ip loopbackVxlanLocalTunnelIp, Warnings w) { vsConfig .getVxlans() .values() .forEach( vxlan -> { if (vxlan.getId() == null || vxlan.getBridgeAccessVlan() == null) { w.redFlag( String.format( "Vxlan %s is not configured properly: %s is not defined", vxlan.getName(), vxlan.getId() == null ? "vxlan id" : "bridge access vlan")); return; } Ip localIp = Stream.of( loopbackClagVxlanAnycastIp, vxlan.getLocalTunnelip(), loopbackVxlanLocalTunnelIp) .filter(Objects::nonNull) .findFirst() .orElse(null); if (localIp == null) { w.redFlag( String.format( "Local tunnel IP for vxlan %s is not configured", vxlan.getName())); return; } @Nullable String vrfName = vniToVrf.get(vxlan.getId()); if (vrfName != null) { Optional.ofNullable(c.getVrfs().get(vrfName)) .ifPresent( vrf -> vrf.addLayer3Vni( Layer3Vni.builder() .setVni(vxlan.getId()) .setSourceAddress(localIp) .setUdpPort(NamedPort.VXLAN.number()) .setBumTransportMethod(BumTransportMethod.UNICAST_FLOOD_GROUP) .setSrcVrf(DEFAULT_VRF_NAME) .build())); } else { vrfName = vsConfig.getVrfForVlan(vxlan.getBridgeAccessVlan()); if (vrfName == null) { vrfName = DEFAULT_VRF_NAME; } Optional.ofNullable(c.getVrfs().get(vrfName)) .ifPresent( vrf -> vrf.addLayer2Vni( Layer2Vni.builder() .setVni(vxlan.getId()) .setVlan(vxlan.getBridgeAccessVlan()) .setSourceAddress(localIp) .setUdpPort(NamedPort.VXLAN.number()) .setBumTransportMethod(BumTransportMethod.UNICAST_FLOOD_GROUP) .setSrcVrf(DEFAULT_VRF_NAME) .build())); } }); }  }
CumulusConversions { static void convertVxlans( Configuration c, CumulusNodeConfiguration vsConfig, Map<Integer, String> vniToVrf, @Nullable Ip loopbackClagVxlanAnycastIp, @Nullable Ip loopbackVxlanLocalTunnelIp, Warnings w) { vsConfig .getVxlans() .values() .forEach( vxlan -> { if (vxlan.getId() == null || vxlan.getBridgeAccessVlan() == null) { w.redFlag( String.format( "Vxlan %s is not configured properly: %s is not defined", vxlan.getName(), vxlan.getId() == null ? "vxlan id" : "bridge access vlan")); return; } Ip localIp = Stream.of( loopbackClagVxlanAnycastIp, vxlan.getLocalTunnelip(), loopbackVxlanLocalTunnelIp) .filter(Objects::nonNull) .findFirst() .orElse(null); if (localIp == null) { w.redFlag( String.format( "Local tunnel IP for vxlan %s is not configured", vxlan.getName())); return; } @Nullable String vrfName = vniToVrf.get(vxlan.getId()); if (vrfName != null) { Optional.ofNullable(c.getVrfs().get(vrfName)) .ifPresent( vrf -> vrf.addLayer3Vni( Layer3Vni.builder() .setVni(vxlan.getId()) .setSourceAddress(localIp) .setUdpPort(NamedPort.VXLAN.number()) .setBumTransportMethod(BumTransportMethod.UNICAST_FLOOD_GROUP) .setSrcVrf(DEFAULT_VRF_NAME) .build())); } else { vrfName = vsConfig.getVrfForVlan(vxlan.getBridgeAccessVlan()); if (vrfName == null) { vrfName = DEFAULT_VRF_NAME; } Optional.ofNullable(c.getVrfs().get(vrfName)) .ifPresent( vrf -> vrf.addLayer2Vni( Layer2Vni.builder() .setVni(vxlan.getId()) .setVlan(vxlan.getBridgeAccessVlan()) .setSourceAddress(localIp) .setUdpPort(NamedPort.VXLAN.number()) .setBumTransportMethod(BumTransportMethod.UNICAST_FLOOD_GROUP) .setSrcVrf(DEFAULT_VRF_NAME) .build())); } }); }  static @Nonnull String computeBgpCommonExportPolicyName(String vrfName); @VisibleForTesting static @Nonnull String computeBgpPeerExportPolicyName(
      String vrfName, String peerInterface); static @Nonnull String computeBgpPeerImportPolicyName(String vrf, String peer); static String computeBgpGenerationPolicyName(boolean ipv4, String vrfName, String prefix); static String computeMatchSuppressedSummaryOnlyPolicyName(String vrfName); static String computeOspfExportPolicyName(String vrfName); }
CumulusConversions { static void convertVxlans( Configuration c, CumulusNodeConfiguration vsConfig, Map<Integer, String> vniToVrf, @Nullable Ip loopbackClagVxlanAnycastIp, @Nullable Ip loopbackVxlanLocalTunnelIp, Warnings w) { vsConfig .getVxlans() .values() .forEach( vxlan -> { if (vxlan.getId() == null || vxlan.getBridgeAccessVlan() == null) { w.redFlag( String.format( "Vxlan %s is not configured properly: %s is not defined", vxlan.getName(), vxlan.getId() == null ? "vxlan id" : "bridge access vlan")); return; } Ip localIp = Stream.of( loopbackClagVxlanAnycastIp, vxlan.getLocalTunnelip(), loopbackVxlanLocalTunnelIp) .filter(Objects::nonNull) .findFirst() .orElse(null); if (localIp == null) { w.redFlag( String.format( "Local tunnel IP for vxlan %s is not configured", vxlan.getName())); return; } @Nullable String vrfName = vniToVrf.get(vxlan.getId()); if (vrfName != null) { Optional.ofNullable(c.getVrfs().get(vrfName)) .ifPresent( vrf -> vrf.addLayer3Vni( Layer3Vni.builder() .setVni(vxlan.getId()) .setSourceAddress(localIp) .setUdpPort(NamedPort.VXLAN.number()) .setBumTransportMethod(BumTransportMethod.UNICAST_FLOOD_GROUP) .setSrcVrf(DEFAULT_VRF_NAME) .build())); } else { vrfName = vsConfig.getVrfForVlan(vxlan.getBridgeAccessVlan()); if (vrfName == null) { vrfName = DEFAULT_VRF_NAME; } Optional.ofNullable(c.getVrfs().get(vrfName)) .ifPresent( vrf -> vrf.addLayer2Vni( Layer2Vni.builder() .setVni(vxlan.getId()) .setVlan(vxlan.getBridgeAccessVlan()) .setSourceAddress(localIp) .setUdpPort(NamedPort.VXLAN.number()) .setBumTransportMethod(BumTransportMethod.UNICAST_FLOOD_GROUP) .setSrcVrf(DEFAULT_VRF_NAME) .build())); } }); }  static @Nonnull String computeBgpCommonExportPolicyName(String vrfName); @VisibleForTesting static @Nonnull String computeBgpPeerExportPolicyName(
      String vrfName, String peerInterface); static @Nonnull String computeBgpPeerImportPolicyName(String vrf, String peer); static String computeBgpGenerationPolicyName(boolean ipv4, String vrfName, String prefix); static String computeMatchSuppressedSummaryOnlyPolicyName(String vrfName); static String computeOspfExportPolicyName(String vrfName); static final int DEFAULT_STATIC_ROUTE_ADMINISTRATIVE_DISTANCE; static final int DEFAULT_STATIC_ROUTE_METRIC; static final Ip CLAG_LINK_LOCAL_IP; static final long DEFAULT_MAX_MED; static final double SPEED_CONVERSION_FACTOR; static final double DEFAULT_LOOPBACK_BANDWIDTH; static final double DEFAULT_PORT_BANDWIDTH; }