use of org.batfish.grammar.routing_table.ios.IosRoutingTableParser.RouteContext in project batfish by batfish.
the class IosRoutingTableExtractor method exitRoute.
@Override
public void exitRoute(RouteContext ctx) {
if (_currentVrfName == null) {
_currentVrfName = Configuration.DEFAULT_VRF_NAME;
initVrf(_currentVrfName);
}
RoutingProtocol protocol = toProtocol(ctx.protocol());
if (protocol == RoutingProtocol.LOCAL) {
return;
}
Prefix prefix = Prefix.parse(ctx.IP_PREFIX().getText());
int admin;
int cost;
List<String> nextHopInterfaces = ctx.nexthopifaces.stream().map(nextHopIfaceCtx -> nextHopIfaceCtx.getText()).collect(Collectors.toList());
List<Ip> nextHopIps = ctx.nexthops.stream().map(nextHopIpCtx -> new Ip(nextHopIpCtx.getText())).collect(Collectors.toList());
int numIterations = Math.max(nextHopIps.size(), nextHopInterfaces.size());
for (int i = 0; i < numIterations; i++) {
String nextHopInterface;
Ip nextHopIp;
if (nextHopInterfaces.isEmpty()) {
nextHopInterface = Route.UNSET_NEXT_HOP_INTERFACE;
} else {
nextHopInterface = nextHopInterfaces.get(i);
}
if (ctx.IS_DIRECTLY_CONNECTED() != null) {
if (protocol == RoutingProtocol.STATIC) {
// static
if (ctx.admin != null) {
admin = toInteger(ctx.admin);
} else {
admin = 1;
}
if (ctx.cost != null) {
cost = toInteger(ctx.cost);
} else {
cost = 0;
}
} else {
// connected
admin = 0;
cost = 0;
}
nextHopIp = Route.UNSET_ROUTE_NEXT_HOP_IP;
} else {
admin = toInteger(ctx.admin);
cost = toInteger(ctx.cost);
nextHopIp = nextHopIps.get(i);
}
// TODO: support IOS route tags
int tag = Route.UNSET_ROUTE_TAG;
// TODO: support IOS next hop
if (protocol == RoutingProtocol.BGP && admin > RoutingProtocol.BGP.getDefaultAdministrativeCost(ConfigurationFormat.CISCO_IOS)) {
protocol = RoutingProtocol.IBGP;
}
RouteBuilder rb = new RouteBuilder();
rb.setNode(_hostname);
rb.setNetwork(prefix);
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(tag);
rb.setVrf(_currentVrfName);
Route route = rb.build();
_currentVrfRoutes.add(route);
}
}
Aggregations