Search in sources :

Example 1 with BgpRoute

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

the class DecrementLocalPreference method evaluate.

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

Example 2 with BgpRoute

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

the class SetOrigin method execute.

@Override
public Result execute(Environment environment) {
    BgpRoute.Builder bgpRoute = (BgpRoute.Builder) environment.getOutputRoute();
    OriginType originType = _origin.evaluate(environment);
    bgpRoute.setOriginType(originType);
    if (environment.getWriteToIntermediateBgpAttributes()) {
        environment.getIntermediateBgpAttributes().setOriginType(originType);
    }
    Result result = new Result();
    return result;
}
Also used : OriginType(org.batfish.datamodel.OriginType) BgpRoute(org.batfish.datamodel.BgpRoute) Result(org.batfish.datamodel.routing_policy.Result)

Example 3 with BgpRoute

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

the class AddCommunity method execute.

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

Example 4 with BgpRoute

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

the class NamedAsPathSet method matches.

@Override
public boolean matches(Environment environment) {
    AsPathAccessList list = environment.getConfiguration().getAsPathAccessLists().get(_name);
    if (list != null) {
        boolean match = false;
        AsPath inputAsPath = null;
        if (environment.getUseOutputAttributes() && environment.getOutputRoute() instanceof BgpRoute.Builder) {
            BgpRoute.Builder bgpRouteBuilder = (BgpRoute.Builder) environment.getOutputRoute();
            inputAsPath = new AsPath(bgpRouteBuilder.getAsPath());
        } else if (environment.getReadFromIntermediateBgpAttributes()) {
            inputAsPath = new AsPath(environment.getIntermediateBgpAttributes().getAsPath());
        } else if (environment.getOriginalRoute() instanceof BgpRoute) {
            BgpRoute bgpRoute = (BgpRoute) environment.getOriginalRoute();
            inputAsPath = bgpRoute.getAsPath();
        }
        if (inputAsPath != null) {
            match = list.permits(inputAsPath);
        }
        return match;
    } else {
        environment.setError(true);
        return false;
    }
}
Also used : AsPath(org.batfish.datamodel.AsPath) AsPathAccessList(org.batfish.datamodel.AsPathAccessList) BgpRoute(org.batfish.datamodel.BgpRoute)

Example 5 with BgpRoute

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

the class VirtualRouter method initBgpAggregateRoutes.

/**
 * This function creates BGP routes from generated routes that go into the BGP RIB, but cannot be
 * imported into the main RIB. The purpose of these routes is to prevent the local router from
 * accepting advertisements less desirable than the local generated ones for the given network.
 * They are not themselves advertised.
 */
void initBgpAggregateRoutes() {
    // first import aggregates
    switch(_c.getConfigurationFormat()) {
        case JUNIPER:
        case JUNIPER_SWITCH:
            return;
        // $CASES-OMITTED$
        default:
            break;
    }
    for (AbstractRoute grAbstract : _generatedRib.getRoutes()) {
        GeneratedRoute gr = (GeneratedRoute) grAbstract;
        BgpRoute.Builder b = new BgpRoute.Builder();
        b.setAdmin(gr.getAdministrativeCost());
        b.setAsPath(gr.getAsPath().getAsSets());
        b.setMetric(gr.getMetric());
        b.setSrcProtocol(RoutingProtocol.AGGREGATE);
        b.setProtocol(RoutingProtocol.AGGREGATE);
        b.setNetwork(gr.getNetwork());
        b.setLocalPreference(BgpRoute.DEFAULT_LOCAL_PREFERENCE);
        /* Note: Origin type and originator IP should get overwritten, but are needed initially */
        b.setOriginatorIp(_vrf.getBgpProcess().getRouterId());
        b.setOriginType(OriginType.INCOMPLETE);
        b.setReceivedFromIp(Ip.ZERO);
        BgpRoute br = b.build();
        br.setNonRouting(true);
        _bgpMultipathRib.mergeRoute(br);
        _bgpBestPathRib.mergeRoute(br);
    }
}
Also used : AbstractRoute(org.batfish.datamodel.AbstractRoute) GeneratedRoute(org.batfish.datamodel.GeneratedRoute) 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