use of org.batfish.datamodel.RouteBuilder in project batfish by batfish.
the class BdpEngine method computeOutputRoutes.
private SortedSet<Route> computeOutputRoutes(Map<String, Node> nodes, Map<Ip, String> ipOwners) {
SortedSet<Route> outputRoutes = new TreeSet<>();
nodes.forEach((hostname, node) -> {
node._virtualRouters.forEach((vrName, vr) -> {
for (AbstractRoute route : vr._mainRib.getRoutes()) {
RouteBuilder rb = new RouteBuilder();
rb.setNode(hostname);
rb.setNetwork(route.getNetwork());
Ip nextHopIp = route.getNextHopIp();
if (route.getProtocol() == RoutingProtocol.CONNECTED || (route.getProtocol() == RoutingProtocol.STATIC && nextHopIp.equals(Route.UNSET_ROUTE_NEXT_HOP_IP)) || Interface.NULL_INTERFACE_NAME.equals(route.getNextHopInterface())) {
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);
}
}
rb.setNextHopInterface(route.getNextHopInterface());
rb.setAdministrativeCost(route.getAdministrativeCost());
rb.setCost(route.getMetric());
rb.setProtocol(route.getProtocol());
rb.setTag(route.getTag());
rb.setVrf(vrName);
Route outputRoute = rb.build();
outputRoutes.add(outputRoute);
}
});
});
return outputRoutes;
}
use of org.batfish.datamodel.RouteBuilder 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.RouteBuilder in project batfish by batfish.
the class EosRoutingTableExtractor method exitRoute.
@Override
public void exitRoute(RouteContext ctx) {
if (_currentVrfName == null) {
_currentVrfName = Configuration.DEFAULT_VRF_NAME;
initVrf(_currentVrfName);
}
RoutingProtocol protocol = toProtocol(ctx.protocol());
Prefix prefix = Prefix.parse(ctx.IP_PREFIX().getText());
int admin;
int cost;
Ip nextHopIp;
for (int i = 0; i < ctx.nexthopifaces.size(); i++) {
String nextHopInterface = ctx.nexthopifaces.get(i).getText();
// TODO: support EOS route tags
int tag = Route.UNSET_ROUTE_TAG;
// TODO: support EOS next hop
if (ctx.IS_DIRECTLY_CONNECTED() != null) {
admin = 0;
cost = 0;
nextHopIp = Route.UNSET_ROUTE_NEXT_HOP_IP;
} else {
admin = toInteger(ctx.admin);
cost = toInteger(ctx.cost);
nextHopIp = new Ip(ctx.nexthops.get(i).getText());
}
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);
}
}
use of org.batfish.datamodel.RouteBuilder 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