@Override protected Vrf featureValueOf(Configuration actual) { return actual.getDefaultVrf(); } }
private void convertInterfaces() { for (Entry<String, Interface> e : _interfaces.entrySet()) { String name = e.getKey(); Interface iface = e.getValue(); org.batfish.datamodel.Interface newIface = toInterface(iface); _c.getDefaultVrf().getInterfaces().put(name, newIface); } }
private void initAreaIds() { for (Entry<String, Configuration> entry : _configurations.entrySet()) { String router = entry.getKey(); Configuration conf = entry.getValue(); Set<Long> areaIds = new HashSet<>(); OspfProcess p = conf.getDefaultVrf().getOspfProcess(); if (p != null) { p.getAreas().forEach((id, area) -> areaIds.add(id)); } _areaIds.put(router, areaIds); } }
private Map<String, List<Protocol>> buildProtocolMap() { // Figure out which protocols are running on which devices Map<String, List<Protocol>> protocols = new HashMap<>(); for (Entry<String, Configuration> entry : _graph.getConfigurations().entrySet()) { String router = entry.getKey(); Configuration conf = entry.getValue(); List<Protocol> protos = new ArrayList<>(); protocols.put(router, protos); if (conf.getDefaultVrf().getOspfProcess() != null) { protos.add(Protocol.OSPF); } if (conf.getDefaultVrf().getBgpProcess() != null) { protos.add(Protocol.BGP); } if (!conf.getDefaultVrf().getStaticRoutes().isEmpty()) { protos.add(Protocol.STATIC); } if (!conf.getAllInterfaces().isEmpty()) { protos.add(Protocol.CONNECTED); } } return protocols; }
ips.put(router, ipList); neighbors.put(router, ns); if (conf.getDefaultVrf().getBgpProcess() != null) { BgpProcess bgp = conf.getDefaultVrf().getBgpProcess(); for (BgpActivePeerConfig neighbor : bgp.getActiveNeighbors().values()) { ipList.add(neighbor.getPeerAddress()); List<Ip> ipList = ips.get(router); List<BgpActivePeerConfig> ns = neighbors.get(router); if (conf.getDefaultVrf().getBgpProcess() != null) { List<GraphEdge> edges = _edgeMap.get(router); for (GraphEdge ge : edges) {
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); } } }); }
public static Set<Prefix> getOriginatedNetworks(Configuration conf) { Set<Prefix> allNetworks = new HashSet<>(); Vrf vrf = conf.getDefaultVrf(); if (vrf.getOspfProcess() != null) { allNetworks.addAll(getOriginatedNetworks(conf, Protocol.OSPF)); } if (vrf.getBgpProcess() != null) { allNetworks.addAll(getOriginatedNetworks(conf, Protocol.BGP)); } if (vrf.getStaticRoutes() != null) { allNetworks.addAll(getOriginatedNetworks(conf, Protocol.STATIC)); } allNetworks.addAll(getOriginatedNetworks(conf, Protocol.CONNECTED)); return allNetworks; }
private void initProtocols() { Graph g = _encoderSlice.getGraph(); g.getConfigurations().forEach((router, conf) -> getProtocols().put(router, new ArrayList<>())); g.getConfigurations() .forEach( (router, conf) -> { List<Protocol> protos = getProtocols().get(router); if (conf.getDefaultVrf().getOspfProcess() != null) { protos.add(Protocol.OSPF); } // TODO: re-evaluate this in the future // TODO: do we want to model BGP's impact on IGP in other slices? if (conf.getDefaultVrf().getBgpProcess() != null && _encoderSlice.isMainSlice()) { protos.add(Protocol.BGP); } if (needToModelConnected(conf)) { protos.add(Protocol.CONNECTED); } if (needToModelStatic(conf)) { protos.add(Protocol.STATIC); } }); }
private long routerId(Configuration conf, Protocol proto) { if (proto.isBgp()) { return conf.getDefaultVrf().getBgpProcess().getRouterId().asLong(); } if (proto.isOspf()) { return conf.getDefaultVrf().getOspfProcess().getRouterId().asLong(); } else { return 0; } }
@Nullable public static RoutingPolicy findCommonRoutingPolicy(Configuration conf, Protocol proto) { if (proto.isOspf()) { String exp = conf.getDefaultVrf().getOspfProcess().getExportPolicy(); return conf.getRoutingPolicies().get(exp); } if (proto.isBgp()) { for (Map.Entry<String, RoutingPolicy> entry : conf.getRoutingPolicies().entrySet()) { String name = entry.getKey(); if (name.contains(BGP_COMMON_FILTER_LIST_NAME)) { return entry.getValue(); } } return null; } if (proto.isStatic()) { return null; } if (proto.isConnected()) { return null; } throw new BatfishException("TODO: findCommonRoutingPolicy for " + proto.name()); }
private void computeRouterIdNeeded() { _encoderSlice .getGraph() .getConfigurations() .forEach( (router, conf) -> { // If iBGP is used, and no multipath, then we need the routerId boolean usesIbgp = false; for (GraphEdge ge : _encoderSlice.getGraph().getEdgeMap().get(router)) { if (_encoderSlice.getGraph().getIbgpNeighbors().get(ge) != null) { usesIbgp = true; break; } } // If eBGP is used, and no multipath, then we need the routerId boolean usesEbgp = _encoderSlice.getProtocols().get(router).contains(Protocol.BGP); // check if multipath is used boolean ibgpMultipath = false; boolean ebgpMultipath = false; BgpProcess p = conf.getDefaultVrf().getBgpProcess(); if (p != null) { ibgpMultipath = p.getMultipathIbgp(); ebgpMultipath = p.getMultipathEbgp(); } if ((usesIbgp && !ibgpMultipath) || (usesEbgp && !ebgpMultipath)) { _needRouterId.add(router); } }); }
public static Interface newInterface( String name, Configuration c, InterfaceAddress primaryAddress) { return FACTORY .interfaceBuilder() .setName(name) .setOwner(c) .setVrf(c.getDefaultVrf()) .setAddress(primaryAddress) .build(); }
@Nullable public RoutingPolicy findExportRoutingPolicy(String router, Protocol proto, GraphEdge ge) { Configuration conf = _configurations.get(router); if (proto.isConnected()) { return null; } if (proto.isStatic()) { return null; } if (proto.isOspf()) { OspfProcess p = conf.getDefaultVrf().getOspfProcess(); if (p == null) { return null; } String exp = p.getExportPolicy(); return conf.getRoutingPolicies().get(exp); } if (proto.isBgp()) { BgpPeerConfig n = findBgpNeighbor(ge); // if no neighbor (e.g., loopback), or no export policy if (n == null || n.getExportPolicy() == null) { return null; } return conf.getRoutingPolicies().get(n.getExportPolicy()); } throw new BatfishException("TODO: findExportRoutingPolicy for " + proto.name()); }
@Test public void testComputeNodeVlanProperties() { int vlan = 1; InterfaceSpecifier interfacesSpecifier = InterfaceSpecifierFactory.load(FlexibleInterfaceSpecifierFactory.NAME) .buildInterfaceSpecifier(null); boolean excludeShutInterfaces = false; IntegerSpace vlans = IntegerSpace.of(vlan); Map<Integer, ImmutableSet.Builder<NodeInterfacePair>> switchedVlanInterfaces = new HashMap<>(); ImmutableMap.Builder<Integer, Integer> vlanVnisBuilder = ImmutableMap.builder(); Interface iface = _ib.build(); iface.setSwitchport(true); iface.setSwitchportMode(SwitchportMode.ACCESS); iface.setAccessVlan(vlan); Configuration c = _configurations.values().iterator().next(); int vni = 10000; c.getDefaultVrf().getVniSettings().put(vni, _vnb.setVlan(vlan).setVni(vni).build()); computeNodeVlanProperties( _specifierContext, c, interfacesSpecifier, excludeShutInterfaces, vlans, switchedVlanInterfaces, vlanVnisBuilder); assertThat(switchedVlanInterfaces, hasKey(vlan)); assertThat( switchedVlanInterfaces.get(vlan).build(), contains(new NodeInterfacePair(NODE, INTERFACE))); assertThat(vlanVnisBuilder.build(), equalTo(ImmutableMap.of(vlan, vni))); }
.setMetric(Route.DEFAULT_STATIC_ROUTE_COST) .build(); cfgNode.getDefaultVrf().getStaticRoutes().add(igwVpcRoute); });
.setNetwork(Prefix.ZERO) .build(); cfgNode.getDefaultVrf().getStaticRoutes().add(defaultRoute);
.setNetwork(Prefix.ZERO) .build(); cfgNode.getDefaultVrf().getStaticRoutes().add(defaultRoute);
public Configuration toConfigurationNode( AwsConfiguration awsConfiguration, Region region, Warnings warnings) { Configuration cfgNode = Utils.newAwsConfiguration(_vpcId, "aws"); cfgNode.getVendorFamily().getAws().setRegion(region.getName()); cfgNode.getVendorFamily().getAws().setVpcId(_vpcId); cfgNode .getDefaultVrf() .getStaticRoutes() .add( StaticRoute.builder() .setAdministrativeCost(Route.DEFAULT_STATIC_ROUTE_ADMIN) .setMetric(Route.DEFAULT_STATIC_ROUTE_COST) .setNetwork(_cidrBlock) .setNextHopInterface(Interface.NULL_INTERFACE_NAME) .build()); // we only create a node here // interfaces are added to this node as we traverse subnets and // internetgateways return cfgNode; } }
_configurations .get(NODE) .getDefaultVrf() .getVniSettings() .put(vni, _vnb.setVni(vni).setVlan(vlan).build());
public Interface toInterface(Configuration configuration, Warnings warnings) { String name = _canonicalName != null ? _canonicalName : _name; Interface.Builder iface = Interface.builder() .setName(name) .setOwner(configuration) .setAddresses(_address, _otherAddresses) .setBandwidth(_bandwidth) .setDeclaredNames(ImmutableSortedSet.of(_name)) .setProxyArp(false) .setVrf(configuration.getDefaultVrf()); if (_shared) { Ip publicIp = _address.getIp(); iface.setOutgoingTransformation(always().apply(assignSourceIp(publicIp, publicIp)).build()); } return iface.build(); } }