use of org.batfish.datamodel.RoutingProtocol in project batfish by batfish.
the class CiscoControlPlaneExtractor method exitRo_redistribute_static.
@Override
public void exitRo_redistribute_static(Ro_redistribute_staticContext ctx) {
OspfProcess proc = _currentOspfProcess;
RoutingProtocol sourceProtocol = RoutingProtocol.STATIC;
OspfRedistributionPolicy r = new OspfRedistributionPolicy(sourceProtocol);
proc.getRedistributionPolicies().put(sourceProtocol, r);
if (ctx.metric != null) {
int metric = toInteger(ctx.metric);
r.setMetric(metric);
}
if (ctx.map != null) {
String map = ctx.map.getText();
int mapLine = ctx.map.getLine();
r.setRouteMap(map);
r.setRouteMapLine(mapLine);
}
if (ctx.type != null) {
int typeInt = toInteger(ctx.type);
OspfMetricType type = OspfMetricType.fromInteger(typeInt);
r.setOspfMetricType(type);
} else {
r.setOspfMetricType(OspfRedistributionPolicy.DEFAULT_METRIC_TYPE);
}
if (ctx.tag != null) {
long tag = toLong(ctx.tag);
r.setTag(tag);
}
r.setSubnets(ctx.subnets != null);
}
use of org.batfish.datamodel.RoutingProtocol in project batfish by batfish.
the class CiscoControlPlaneExtractor method exitRedistribute_static_is_stanza.
@Override
public void exitRedistribute_static_is_stanza(Redistribute_static_is_stanzaContext ctx) {
IsisProcess proc = currentVrf().getIsisProcess();
RoutingProtocol sourceProtocol = RoutingProtocol.STATIC;
IsisRedistributionPolicy r = new IsisRedistributionPolicy(sourceProtocol);
proc.getRedistributionPolicies().put(sourceProtocol, r);
if (ctx.metric != null) {
int metric = toInteger(ctx.metric);
r.setMetric(metric);
}
if (ctx.map != null) {
String map = ctx.map.getText();
r.setMap(map);
}
if (ctx.LEVEL_1() != null) {
r.setLevel(IsisLevel.LEVEL_1);
} else if (ctx.LEVEL_2() != null) {
r.setLevel(IsisLevel.LEVEL_2);
} else if (ctx.LEVEL_1_2() != null) {
r.setLevel(IsisLevel.LEVEL_1_2);
} else {
r.setLevel(IsisRedistributionPolicy.DEFAULT_LEVEL);
}
}
use of org.batfish.datamodel.RoutingProtocol in project batfish by batfish.
the class CiscoControlPlaneExtractor method exitRo_redistribute_connected.
@Override
public void exitRo_redistribute_connected(Ro_redistribute_connectedContext ctx) {
OspfProcess proc = _currentOspfProcess;
RoutingProtocol sourceProtocol = RoutingProtocol.CONNECTED;
OspfRedistributionPolicy r = new OspfRedistributionPolicy(sourceProtocol);
proc.getRedistributionPolicies().put(sourceProtocol, r);
if (ctx.metric != null) {
int metric = toInteger(ctx.metric);
r.setMetric(metric);
}
if (ctx.map != null) {
String map = ctx.map.getText();
int mapLine = ctx.map.getLine();
r.setRouteMap(map);
r.setRouteMapLine(mapLine);
}
if (ctx.type != null) {
int typeInt = toInteger(ctx.type);
OspfMetricType type = OspfMetricType.fromInteger(typeInt);
r.setOspfMetricType(type);
} else {
r.setOspfMetricType(OspfRedistributionPolicy.DEFAULT_METRIC_TYPE);
}
if (ctx.tag != null) {
long tag = toLong(ctx.tag);
r.setTag(tag);
}
r.setSubnets(ctx.subnets != null);
}
use of org.batfish.datamodel.RoutingProtocol in project batfish by batfish.
the class NxosRoutingTableExtractor method exitRoute.
@Override
public void exitRoute(RouteContext ctx) {
if (ctx.protocol().LOCAL() != null) {
return;
}
if (_currentVrfRoutes == null) {
initVrf(Configuration.DEFAULT_VRF_NAME);
}
RoutingProtocol protocol = toProtocol(ctx.protocol());
String nextHopInterface = Route.UNSET_NEXT_HOP_INTERFACE;
if (ctx.nexthopint != null) {
nextHopInterface = ctx.nexthopint.getText();
}
int admin = toInteger(ctx.admin);
int cost = toInteger(ctx.cost);
Ip nextHopIp = Route.UNSET_ROUTE_NEXT_HOP_IP;
if (protocol != RoutingProtocol.CONNECTED && ctx.nexthop != null) {
nextHopIp = new Ip(ctx.nexthop.getText());
}
RouteBuilder rb = new RouteBuilder();
rb.setNode(_hostname);
rb.setNetwork(_currentPrefix);
if (protocol == RoutingProtocol.CONNECTED || (protocol == RoutingProtocol.STATIC && nextHopIp.equals(Route.UNSET_ROUTE_NEXT_HOP_IP)) || Interface.NULL_INTERFACE_NAME.equals(nextHopInterface)) {
rb.setNextHop(Configuration.NODE_NONE_NAME);
}
if (!nextHopIp.equals(Route.UNSET_ROUTE_NEXT_HOP_IP)) {
rb.setNextHopIp(nextHopIp);
String nextHop = _ipOwners.get(nextHopIp);
if (nextHop != null) {
rb.setNextHop(nextHop);
}
}
if (nextHopInterface != null) {
rb.setNextHopInterface(nextHopInterface);
}
rb.setAdministrativeCost(admin);
rb.setCost(cost);
rb.setProtocol(protocol);
rb.setTag(Route.UNSET_ROUTE_TAG);
rb.setVrf(_currentVrfName);
Route route = rb.build();
_currentVrfRoutes.add(route);
}
use of org.batfish.datamodel.RoutingProtocol in project batfish by batfish.
the class Graph method findRedistributedProtocols.
/*
* Find the set of all protocols that might be redistributed into
* protocol p given the current configuration and routing policy.
* This is based on structure of the AST.
*/
public Set<Protocol> findRedistributedProtocols(Configuration conf, RoutingPolicy pol, Protocol p) {
Set<Protocol> protos = new HashSet<>();
AstVisitor v = new AstVisitor();
v.visit(conf, pol.getStatements(), stmt -> {
}, expr -> {
if (expr instanceof MatchProtocol) {
MatchProtocol mp = (MatchProtocol) expr;
RoutingProtocol other = mp.getProtocol();
Protocol otherP = Protocol.fromRoutingProtocol(other);
if (otherP != null && otherP != p) {
switch(other) {
case BGP:
protos.add(otherP);
break;
case OSPF:
protos.add(otherP);
break;
case STATIC:
protos.add(otherP);
break;
case CONNECTED:
protos.add(otherP);
break;
default:
throw new BatfishException("Unrecognized protocol: " + other.protocolName());
}
}
}
});
return protos;
}
Aggregations