Search in sources :

Example 11 with BgpRoute

use of org.batfish.datamodel.BgpRoute in project batfish by batfish.

the class IncrementLocalPreference method evaluate.

@Override
public int evaluate(Environment environment) {
    BgpRoute oldRoute = (BgpRoute) environment.getOriginalRoute();
    int oldLp = oldRoute.getLocalPreference();
    int newVal = oldLp + _addend;
    return newVal;
}
Also used : BgpRoute(org.batfish.datamodel.BgpRoute)

Example 12 with BgpRoute

use of org.batfish.datamodel.BgpRoute in project batfish by batfish.

the class SetCommunity method execute.

@Override
public Result execute(Environment environment) {
    Result result = new Result();
    BgpRoute.Builder bgpRoute = (BgpRoute.Builder) environment.getOutputRoute();
    SortedSet<Long> communities = _expr.allCommunities(environment);
    bgpRoute.getCommunities().clear();
    bgpRoute.getCommunities().addAll(communities);
    if (environment.getWriteToIntermediateBgpAttributes()) {
        environment.getIntermediateBgpAttributes().getCommunities().clear();
        environment.getIntermediateBgpAttributes().getCommunities().addAll(communities);
    }
    return result;
}
Also used : BgpRoute(org.batfish.datamodel.BgpRoute) Result(org.batfish.datamodel.routing_policy.Result)

Example 13 with BgpRoute

use of org.batfish.datamodel.BgpRoute in project batfish by batfish.

the class MatchCommunitySet method evaluate.

@Override
public Result evaluate(Environment environment) {
    Result result = new Result();
    boolean match = false;
    SortedSet<Long> inputCommunities = null;
    if (environment.getUseOutputAttributes() && environment.getOutputRoute() instanceof BgpRoute.Builder) {
        BgpRoute.Builder bgpRouteBuilder = (BgpRoute.Builder) environment.getOutputRoute();
        inputCommunities = bgpRouteBuilder.getCommunities();
    } else if (environment.getReadFromIntermediateBgpAttributes()) {
        inputCommunities = environment.getIntermediateBgpAttributes().getCommunities();
    } else if (environment.getOriginalRoute() instanceof BgpRoute) {
        BgpRoute bgpRoute = (BgpRoute) environment.getOriginalRoute();
        inputCommunities = bgpRoute.getCommunities();
    }
    if (inputCommunities != null) {
        match = _expr.matchSingleCommunity(environment, inputCommunities);
    }
    result.setBooleanValue(match);
    return result;
}
Also used : BgpRoute(org.batfish.datamodel.BgpRoute) Result(org.batfish.datamodel.routing_policy.Result)

Example 14 with BgpRoute

use of org.batfish.datamodel.BgpRoute in project batfish by batfish.

the class BdpDataPlanePluginTest method testBgpAsPathMultipathHelper.

private void testBgpAsPathMultipathHelper(MultipathEquivalentAsPathMatchMode multipathEquivalentAsPathMatchMode, boolean primeBestPathInMultipathBgpRib, boolean expectRoute2, boolean expectRoute3a, boolean expectRoute3b, boolean expectRoute3c, boolean expectRoute3d) {
    /*
     * Properties of the routes
     */
    // Should appear only for path-length match
    List<SortedSet<Integer>> asPath2 = AsPath.ofSingletonAsSets(2, 4, 6).getAsSets();
    // Should appear only for first-as match and path-length match
    List<SortedSet<Integer>> asPath3a = AsPath.ofSingletonAsSets(3, 5, 6).getAsSets();
    // Should never appear
    List<SortedSet<Integer>> asPath3b = AsPath.ofSingletonAsSets(3, 4, 4, 6).getAsSets();
    // Should always appear
    AsPath bestAsPath = AsPath.ofSingletonAsSets(3, 4, 6);
    List<SortedSet<Integer>> asPath3c = bestAsPath.getAsSets();
    List<SortedSet<Integer>> asPath3d = bestAsPath.getAsSets();
    Ip nextHop2 = new Ip("2.0.0.0");
    Ip nextHop3a = new Ip("3.0.0.1");
    Ip nextHop3b = new Ip("3.0.0.2");
    Ip nextHop3c = new Ip("3.0.0.3");
    Ip nextHop3d = new Ip("3.0.0.4");
    /*
     * Common attributes for all routes
     */
    Prefix p = Prefix.ZERO;
    BgpRoute.Builder b = new BgpRoute.Builder().setNetwork(p).setProtocol(RoutingProtocol.BGP).setOriginType(OriginType.INCOMPLETE);
    /*
     * Boilerplate virtual-router setup
     */
    String hostname = "r1";
    Configuration c = BatfishTestUtils.createTestConfiguration(hostname, ConfigurationFormat.CISCO_IOS);
    BgpProcess proc = new BgpProcess();
    c.getVrfs().computeIfAbsent(DEFAULT_VRF_NAME, Vrf::new).setBgpProcess(proc);
    Map<String, Node> nodes = new HashMap<String, Node>();
    Node node = new Node(c);
    nodes.put(hostname, node);
    VirtualRouter vr = new VirtualRouter(DEFAULT_VRF_NAME, c);
    /*
     * Instantiate routes
     */
    BgpRoute route2 = b.setAsPath(asPath2).setNextHopIp(nextHop2).setOriginatorIp(nextHop2).setReceivedFromIp(nextHop2).build();
    BgpRoute route3a = b.setAsPath(asPath3a).setNextHopIp(nextHop3a).setOriginatorIp(nextHop3a).setReceivedFromIp(nextHop3a).build();
    BgpRoute route3b = b.setAsPath(asPath3b).setNextHopIp(nextHop3b).setOriginatorIp(nextHop3b).setReceivedFromIp(nextHop3b).build();
    BgpRoute route3c = b.setAsPath(asPath3c).setNextHopIp(nextHop3c).setOriginatorIp(nextHop3c).setReceivedFromIp(nextHop3c).build();
    BgpRoute route3d = b.setAsPath(asPath3d).setNextHopIp(nextHop3d).setOriginatorIp(nextHop3d).setReceivedFromIp(nextHop3d).build();
    /*
     * Set the as-path match mode prior to instantiating bgp multipath RIB
     */
    proc.setMultipathEquivalentAsPathMatchMode(multipathEquivalentAsPathMatchMode);
    BgpMultipathRib bmr = new BgpMultipathRib(vr);
    /*
     * Prime bgp multipath RIB with best path for the prefix
     */
    if (primeBestPathInMultipathBgpRib) {
        bmr.setBestAsPaths(Collections.singletonMap(p, bestAsPath));
    }
    /*
     * Add routes to multipath RIB.
     */
    bmr.mergeRoute(route2);
    bmr.mergeRoute(route3a);
    bmr.mergeRoute(route3b);
    bmr.mergeRoute(route3c);
    bmr.mergeRoute(route3d);
    /*
     * Initialize the matchers with respect to the output route set
     */
    Set<BgpRoute> postMergeRoutes = bmr.getRoutes();
    Matcher<BgpRoute> present = isIn(postMergeRoutes);
    Matcher<BgpRoute> absent = not(present);
    /*
     * ASSERTIONS:
     * Only the expected routes for the given match mode should be present at end
     */
    assertThat(route2, expectRoute2 ? present : absent);
    assertThat(route3a, expectRoute3a ? present : absent);
    assertThat(route3b, expectRoute3b ? present : absent);
    assertThat(route3c, expectRoute3c ? present : absent);
    assertThat(route3c, expectRoute3d ? present : absent);
}
Also used : Configuration(org.batfish.datamodel.Configuration) BgpProcess(org.batfish.datamodel.BgpProcess) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Ip(org.batfish.datamodel.Ip) Prefix(org.batfish.datamodel.Prefix) Matchers.containsString(org.hamcrest.Matchers.containsString) SortedSet(java.util.SortedSet) AsPath(org.batfish.datamodel.AsPath) BgpRoute(org.batfish.datamodel.BgpRoute)

Aggregations

BgpRoute (org.batfish.datamodel.BgpRoute)14 AsPath (org.batfish.datamodel.AsPath)5 OriginType (org.batfish.datamodel.OriginType)5 Prefix (org.batfish.datamodel.Prefix)5 Configuration (org.batfish.datamodel.Configuration)4 Ip (org.batfish.datamodel.Ip)4 Result (org.batfish.datamodel.routing_policy.Result)4 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 TreeSet (java.util.TreeSet)3 BatfishException (org.batfish.common.BatfishException)3 AbstractRoute (org.batfish.datamodel.AbstractRoute)3 BgpAdvertisement (org.batfish.datamodel.BgpAdvertisement)3 BgpAdvertisementType (org.batfish.datamodel.BgpAdvertisement.BgpAdvertisementType)3 BgpNeighbor (org.batfish.datamodel.BgpNeighbor)3 BgpProcess (org.batfish.datamodel.BgpProcess)3 RoutingProtocol (org.batfish.datamodel.RoutingProtocol)3 RoutingPolicy (org.batfish.datamodel.routing_policy.RoutingPolicy)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 InterfaceAddress (org.batfish.datamodel.InterfaceAddress)2