/** * Returns {@code true} iff the given process has any BGP peer configured as a route reflector * client. */ @VisibleForTesting static boolean isRouteReflector(BgpProcess p) { return p.getActiveNeighbors().values().stream() .anyMatch(BgpActivePeerConfig::getRouteReflectorClient) || p.getPassiveNeighbors().values().stream() .anyMatch(BgpPassivePeerConfig::getRouteReflectorClient); } }
@Override public BgpProcess build() { BgpProcess bgpProcess = new BgpProcess(); if (_vrf != null) { _vrf.setBgpProcess(bgpProcess); } if (_routerId != null) { bgpProcess.setRouterId(_routerId); } return bgpProcess; }
@Override protected Ip featureValueOf(BgpProcess actual) { return actual.getRouterId(); } }
@Before public void clearBgpProcesses() { _node1BgpProcess.setNeighbors(ImmutableSortedMap.of()); _node2BgpProcess.setNeighbors(ImmutableSortedMap.of()); _node3BgpProcess.setNeighbors(ImmutableSortedMap.of()); _node1BgpProcess.setPassiveNeighbors(ImmutableSortedMap.of()); _node2BgpProcess.setPassiveNeighbors(ImmutableSortedMap.of()); _node3BgpProcess.setPassiveNeighbors(ImmutableSortedMap.of()); }
BgpProcess abstractBgp = new BgpProcess(); abstractBgp.setMultipathEbgp(bgp.getMultipathEbgp()); abstractBgp.setMultipathIbgp(bgp.getMultipathIbgp()); abstractBgp.setRouterId(bgp.getRouterId()); abstractBgp.setOriginationSpace(bgp.getOriginationSpace()); for (Entry<Prefix, BgpActivePeerConfig> entry2 : bgp.getActiveNeighbors().entrySet()) { Prefix prefix = entry2.getKey(); BgpActivePeerConfig neighbor = entry2.getValue(); abstractBgp.setNeighbors(abstractBgpNeighbors); abstractVrf.setBgpProcess(abstractBgp);
CiscoNxBgpVrfConfiguration nxBgpVrf, String vrfName) { org.batfish.datamodel.BgpProcess newBgpProcess = new org.batfish.datamodel.BgpProcess(); org.batfish.datamodel.Vrf v = c.getVrfs().get(vrfName); newBgpProcess.setTieBreaker(BgpTieBreaker.ROUTER_ID); newBgpProcess.setRouterId(CiscoNxConversions.getNxBgpRouterId(nxBgpVrf, v, _w)); newBgpProcess.setMultipathEquivalentAsPathMatchMode( nxBgpVrf.getBestpathAsPathMultipathRelax() ? PATH_LENGTH : EXACT_PATH); if (ipv4af != null) { newBgpProcess.setMultipathEbgp(ipv4af.getMaximumPathsEbgp() > 1); newBgpProcess.setMultipathIbgp(ipv4af.getMaximumPathsIbgp() > 1); : BooleanExprs.TRUE, OriginType.IGP)); newBgpProcess.addToOriginationSpace(exportSpace); exportConditions.add(new Conjunction(exportNetworkConditions)); }); newBgpProcess.setNeighbors(ImmutableSortedMap.copyOf(activeNeighbors)); newBgpProcess.setPassiveNeighbors(ImmutableSortedMap.copyOf(passiveNeighbors));
private org.batfish.datamodel.BgpProcess toBgpProcess( final Configuration c, BgpProcess proc, String vrfName) { org.batfish.datamodel.BgpProcess newBgpProcess = new org.batfish.datamodel.BgpProcess(); org.batfish.datamodel.Vrf v = c.getVrfs().get(vrfName); BgpTieBreaker tieBreaker = proc.getTieBreaker(); if (tieBreaker != null) { newBgpProcess.setTieBreaker(tieBreaker); newBgpProcess.setMultipathEquivalentAsPathMatchMode(multipathEquivalentAsPathMatchMode); boolean multipathEbgp = false; boolean multipathIbgp = false; multipathIbgp = true; newBgpProcess.setMultipathEbgp(multipathEbgp); newBgpProcess.setMultipathIbgp(multipathIbgp); newBgpProcess.setRouterId(bgpRouterId); PrefixSpace space = new PrefixSpace(); space.addPrefix(prefix); newBgpProcess.addToOriginationSpace(space); exportNetworkConditions .getConjuncts()
@Override protected Map<Prefix, BgpActivePeerConfig> featureValueOf(BgpProcess actual) { return actual.getActiveNeighbors(); } }
@Test public void testIsRouteReflector() { BgpProcess emptyProcess = new BgpProcess(); assertFalse("no rr clients", isRouteReflector(emptyProcess)); BgpProcess hasActiveNeighbor = new BgpProcess(); hasActiveNeighbor.setNeighbors(ImmutableSortedMap.of(p32a, activePeerWithRRC)); assertTrue("has active rr client", isRouteReflector(hasActiveNeighbor)); BgpProcess hasPassiveNeighbor = new BgpProcess(); hasPassiveNeighbor.setPassiveNeighbors(ImmutableSortedMap.of(p30a, passivePeerWithRRC)); assertTrue("has passive rr client", isRouteReflector(hasPassiveNeighbor)); BgpProcess hasNeighborMix = new BgpProcess(); hasNeighborMix.setNeighbors( ImmutableSortedMap.of(p32a, activePeerWithoutRRC, p32b, activePeerWithRRC)); hasNeighborMix.setPassiveNeighbors( ImmutableSortedMap.of(p30a, passivePeerWithoutRRC, p30b, passivePeerWithRRC)); assertTrue("has mix of active and inactive rr client", isRouteReflector(hasNeighborMix)); BgpProcess hasAllInactive = new BgpProcess(); hasAllInactive.setNeighbors(ImmutableSortedMap.of(p32a, activePeerWithoutRRC)); hasAllInactive.setPassiveNeighbors(ImmutableSortedMap.of(p30a, passivePeerWithoutRRC)); assertFalse("has multiple inactive rr clients", isRouteReflector(hasAllInactive));
@Test public void testGetBgpEdges() { BgpProcess bgp1 = new BgpProcess(); bgp1.setRouterId(Ip.parse("1.1.1.1")); BgpActivePeerConfig peer1 = BgpActivePeerConfig.builder().setLocalIp(Ip.parse("1.1.1.1")).setLocalAs(1L).build(); bgp1.getActiveNeighbors().put(Prefix.create(Ip.parse("2.2.2.2"), 24), peer1); BgpPeerConfigId neighborId1 = new BgpPeerConfigId("host1", "vrf1", Prefix.create(Ip.parse("2.2.2.2"), 24), false); BgpProcess bgp2 = new BgpProcess(); bgp2.setRouterId(Ip.parse("2.2.2.2")); BgpActivePeerConfig peer2 = BgpActivePeerConfig.builder().setLocalIp(Ip.parse("2.2.2.2")).setLocalAs(2L).build(); bgp2.getActiveNeighbors().put(Prefix.create(Ip.parse("1.1.1.1"), 24), peer2); BgpPeerConfigId neighborId2 = new BgpPeerConfigId("host2", "vrf2", Prefix.create(Ip.parse("1.1.1.1"), 24), false);
@Test public void getProperties() { BgpProcess bgp1 = new BgpProcess(); bgp1.setRouterId(Ip.parse("1.1.1.1")); bgp1.setMultipathEbgp(true); bgp1.setTieBreaker(BgpTieBreaker.ARRIVAL_ORDER);
String vrfName = routingInstance.getName(); Vrf vrf = _c.getVrfs().get(vrfName); BgpProcess proc = new BgpProcess(); Ip routerId = routingInstance.getRouterId(); if (routerId == null) { proc.setRouterId(routerId); BgpGroup mg = routingInstance.getMasterBgpGroup(); boolean multipathEbgp = false; neighbor.build(); proc.setMultipathEbgp(multipathEbgpSet); proc.setMultipathIbgp(multipathIbgp); MultipathEquivalentAsPathMatchMode multipathEquivalentAsPathMatchMode = multipathMultipleAs ? MultipathEquivalentAsPathMatchMode.PATH_LENGTH : MultipathEquivalentAsPathMatchMode.FIRST_AS; proc.setMultipathEquivalentAsPathMatchMode(multipathEquivalentAsPathMatchMode);
originatorIp = bgpRemoteRoute.getOriginatorIp(); } else { originatorIp = fromVrf.getBgpProcess().getRouterId(); && toVrf.getBgpProcess().getRouterId().equals(remoteOriginatorIp)) { return null; fromVrf .getBgpProcess() .getActiveNeighbors() .get(Prefix.create(remoteReceivedFromIp, Prefix.MAX_PREFIX_LENGTH)); long newClusterId = remoteReceivedFromSession.getClusterId(); transformedOutgoingRouteBuilder.addToClusterList(newClusterId); Set<Long> localClusterIds = toVrf.getBgpProcess().getClusterIds(); Set<Long> outgoingClusterList = transformedOutgoingRouteBuilder.getClusterList(); if (localClusterIds.stream().anyMatch(outgoingClusterList::contains)) {
BgpProcess proc = vpnGatewayCfgNode.getDefaultVrf().getBgpProcess(); if (proc == null) { proc = new BgpProcess(); proc.setRouterId(ipsecTunnel.getVgwInsideAddress()); proc.setMultipathEquivalentAsPathMatchMode(MultipathEquivalentAsPathMatchMode.EXACT_PATH); vpnGatewayCfgNode.getDefaultVrf().setBgpProcess(proc); BgpProcess vpcProc = new BgpProcess(); vpcNode.getDefaultVrf().setBgpProcess(vpcProc); vpcProc.setMultipathEquivalentAsPathMatchMode( MultipathEquivalentAsPathMatchMode.EXACT_PATH); vpcProc.setRouterId(vpcIfaceAddress); vpcToVgwBgpPeerConfig.setBgpProcess(vpcProc); vpcToVgwBgpPeerConfig.setLocalAs(ipsecTunnel.getVgwBgpAsn());
private static Configuration createConfigurationWithDynamicSession( Configuration.Builder cb, Ip localIp, Prefix remotePrefix, List<Long> remoteAsList) { Configuration node = cb.setHostname("node4").build(); Interface iface = new Interface("iface", node, InterfaceType.PHYSICAL); iface.setAllAddresses( ImmutableList.of(new InterfaceAddress(localIp, Ip.numSubnetBitsToSubnetMask(32)))); BgpPassivePeerConfig peerConfig = BgpPassivePeerConfig.builder() .setLocalAs(3L) .setRemoteAs(remoteAsList) .setLocalIp(localIp) .setPeerPrefix(remotePrefix) .build(); BgpProcess bgpProcess = new BgpProcess(); bgpProcess.setPassiveNeighbors(ImmutableSortedMap.of(remotePrefix, peerConfig)); Vrf vrf1 = new Vrf("vrf"); vrf1.setBgpProcess(bgpProcess); node.setVrfs(ImmutableMap.of("vrf", vrf1)); node.setInterfaces(ImmutableSortedMap.of("iface", iface)); return node; }
private static Configuration createConfiguration( Configuration.Builder cb, String nodeName, Ip localIp, Ip remoteIp, Long localAs, Long remoteAs) { Configuration node = cb.setHostname(nodeName).build(); Interface iface = new Interface("iface", node, InterfaceType.PHYSICAL); iface.setAllAddresses( ImmutableList.of(new InterfaceAddress(localIp, Ip.numSubnetBitsToSubnetMask(32)))); BgpActivePeerConfig peerConfig = BgpActivePeerConfig.builder() .setLocalAs(localAs) .setRemoteAs(remoteAs) .setLocalIp(localIp) .setPeerAddress(remoteIp) .build(); BgpProcess bgpProcess = new BgpProcess(); bgpProcess.setNeighbors(ImmutableSortedMap.of(Prefix.create(remoteIp, 32), peerConfig)); Vrf vrf1 = new Vrf("vrf"); vrf1.setBgpProcess(bgpProcess); node.setVrfs(ImmutableMap.of("vrf", vrf1)); node.setInterfaces(ImmutableSortedMap.of("iface", iface)); return node; }
@Override protected BgpPassivePeerConfig featureValueOf(BgpProcess actual) { return actual.getPassiveNeighbors().get(_prefix); } }
private void computeRouterIdNeeded() { _encoderSlice .getGraph() .getConfigurations() .forEach( (router, conf) -> { // If iBGP is used, and no multipath, then we need the routerId boolean usesIbgp = false; for (GraphEdge ge : _encoderSlice.getGraph().getEdgeMap().get(router)) { if (_encoderSlice.getGraph().getIbgpNeighbors().get(ge) != null) { usesIbgp = true; break; } } // If eBGP is used, and no multipath, then we need the routerId boolean usesEbgp = _encoderSlice.getProtocols().get(router).contains(Protocol.BGP); // check if multipath is used boolean ibgpMultipath = false; boolean ebgpMultipath = false; BgpProcess p = conf.getDefaultVrf().getBgpProcess(); if (p != null) { ibgpMultipath = p.getMultipathIbgp(); ebgpMultipath = p.getMultipathEbgp(); } if ((usesIbgp && !ibgpMultipath) || (usesEbgp && !ebgpMultipath)) { _needRouterId.add(router); } }); }
BgpProcess bgpProcess = new BgpProcess(); vrf.setBgpProcess(bgpProcess); BgpPeerConfig neighbor =
private MultipathEquivalentAsPathMatchMode getBgpMpTieBreaker() { BgpProcess proc = _vrf.getBgpProcess(); return proc == null ? EXACT_PATH : firstNonNull(proc.getMultipathEquivalentAsPathMatchMode(), EXACT_PATH); }