use of org.batfish.datamodel.GeneratedRoute 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);
}
}
use of org.batfish.datamodel.GeneratedRoute in project batfish by batfish.
the class Optimizations method computeRelevantAggregates.
/*
* Computes aggregates that are applicable to the encoding.
*/
private void computeRelevantAggregates() {
_encoderSlice.getGraph().getConfigurations().forEach((router, conf) -> {
List<GeneratedRoute> routes = new ArrayList<>();
_relevantAggregates.put(router, routes);
for (GeneratedRoute gr : conf.getDefaultVrf().getGeneratedRoutes()) {
Prefix p = gr.getNetwork();
if (_encoderSlice.relevantPrefix(p)) {
routes.add(gr);
}
}
});
}
use of org.batfish.datamodel.GeneratedRoute in project batfish by batfish.
the class TransferSSA method aggregateRoutes.
/*
* Determines whether to model each aggregate route as
* suppressing a more specific, or including the more specific
*/
private Map<Prefix, Boolean> aggregateRoutes() {
Map<Prefix, Boolean> acc = new HashMap<>();
String name = _conf.getName();
List<GeneratedRoute> aggregates = _enc.getOptimizations().getRelevantAggregates().get(name);
Set<Prefix> suppressed = _enc.getOptimizations().getSuppressedAggregates().get(name);
for (GeneratedRoute gr : aggregates) {
Prefix p = gr.getNetwork();
acc.put(p, suppressed.contains(p));
}
return acc;
}
use of org.batfish.datamodel.GeneratedRoute in project batfish by batfish.
the class VirtualRouter method activateGeneratedRoutes.
boolean activateGeneratedRoutes() {
boolean changed = false;
for (GeneratedRoute gr : _vrf.getGeneratedRoutes()) {
boolean active = true;
String generationPolicyName = gr.getGenerationPolicy();
GeneratedRoute.Builder grb = new GeneratedRoute.Builder();
grb.setNetwork(gr.getNetwork());
grb.setAdmin(gr.getAdministrativeCost());
grb.setMetric(gr.getMetric() != null ? gr.getMetric() : 0);
grb.setAttributePolicy(gr.getAttributePolicy());
grb.setGenerationPolicy(gr.getGenerationPolicy());
boolean discard = gr.getDiscard();
grb.setDiscard(discard);
if (discard) {
grb.setNextHopInterface(Interface.NULL_INTERFACE_NAME);
}
if (generationPolicyName != null) {
RoutingPolicy generationPolicy = _c.getRoutingPolicies().get(generationPolicyName);
if (generationPolicy != null) {
active = false;
for (AbstractRoute contributingRoute : _prevMainRib.getRoutes()) {
boolean accept = generationPolicy.process(contributingRoute, grb, null, _key, Direction.OUT);
if (accept) {
if (!discard) {
grb.setNextHopIp(contributingRoute.getNextHopIp());
}
active = true;
break;
}
}
}
}
if (active) {
GeneratedRoute newGr = grb.build();
if (_generatedRib.mergeRoute(newGr)) {
changed = true;
}
}
}
return changed;
}
Aggregations