Search in sources :

Example 11 with OspfProcess

use of org.batfish.datamodel.OspfProcess in project batfish by batfish.

the class VirtualRouter method initOspfExports.

void initOspfExports() {
    OspfProcess proc = _vrf.getOspfProcess();
    // Nothing to do
    if (proc == null) {
        return;
    }
    // get OSPF export policy name
    String exportPolicyName = _vrf.getOspfProcess().getExportPolicy();
    if (exportPolicyName == null) {
        // nothing to export
        return;
    }
    RoutingPolicy exportPolicy = _c.getRoutingPolicies().get(exportPolicyName);
    if (exportPolicy == null) {
        // nothing to export
        return;
    }
    // RIB.
    for (AbstractRoute potentialExport : _prevMainRib.getRoutes()) {
        OspfExternalRoute outputRoute = computeOspfExportRoute(potentialExport, exportPolicy, proc);
        if (outputRoute == null) {
            // no need to export
            continue;
        }
        if (outputRoute.getOspfMetricType() == OspfMetricType.E1) {
            _ospfExternalType1Rib.mergeRoute((OspfExternalType1Route) outputRoute);
        } else {
            // assuming here that MetricType exists. Or E2 is the default
            _ospfExternalType2Rib.mergeRoute((OspfExternalType2Route) outputRoute);
        }
    }
}
Also used : AbstractRoute(org.batfish.datamodel.AbstractRoute) OspfProcess(org.batfish.datamodel.OspfProcess) RoutingPolicy(org.batfish.datamodel.routing_policy.RoutingPolicy) OspfExternalRoute(org.batfish.datamodel.OspfExternalRoute)

Example 12 with OspfProcess

use of org.batfish.datamodel.OspfProcess in project batfish by batfish.

the class JuniperConfiguration method toVendorIndependentConfiguration.

@Override
public Configuration toVendorIndependentConfiguration() throws VendorConversionException {
    String hostname = getHostname();
    _c = new Configuration(hostname, _vendor);
    _c.setAuthenticationKeyChains(convertAuthenticationKeyChains(_authenticationKeyChains));
    _c.setRoles(_roles);
    _c.setDnsServers(_dnsServers);
    _c.setDomainName(_defaultRoutingInstance.getDomainName());
    _c.setLoggingServers(_syslogHosts);
    _c.setNtpServers(_ntpServers);
    _c.setTacacsServers(_tacplusServers);
    _c.getVendorFamily().setJuniper(_jf);
    for (String riName : _routingInstances.keySet()) {
        _c.getVrfs().put(riName, new Vrf(riName));
    }
    // convert prefix lists to route filter lists
    for (Entry<String, PrefixList> e : _prefixLists.entrySet()) {
        String name = e.getKey();
        PrefixList pl = e.getValue();
        RouteFilterList rfl = new RouteFilterList(name);
        for (Prefix prefix : pl.getPrefixes()) {
            int prefixLength = prefix.getPrefixLength();
            org.batfish.datamodel.RouteFilterLine line = new org.batfish.datamodel.RouteFilterLine(LineAction.ACCEPT, prefix, new SubRange(prefixLength, prefixLength));
            rfl.addLine(line);
        }
        _c.getRouteFilterLists().put(name, rfl);
    }
    // remove ipv6 lines from firewall filters
    for (FirewallFilter filter : _filters.values()) {
        Set<String> toRemove = new HashSet<>();
        for (Entry<String, FwTerm> e2 : filter.getTerms().entrySet()) {
            String termName = e2.getKey();
            FwTerm term = e2.getValue();
            if (term.getIpv6()) {
                toRemove.add(termName);
            }
        }
        for (String termName : toRemove) {
            filter.getTerms().remove(termName);
        }
    }
    // remove empty firewall filters (ipv6-only filters)
    Map<String, FirewallFilter> allFilters = new LinkedHashMap<>();
    allFilters.putAll(_filters);
    for (Entry<String, FirewallFilter> e : allFilters.entrySet()) {
        String name = e.getKey();
        FirewallFilter filter = e.getValue();
        if (filter.getTerms().size() == 0) {
            _filters.remove(name);
        }
    }
    // convert firewall filters to ipaccesslists
    for (Entry<String, FirewallFilter> e : _filters.entrySet()) {
        String name = e.getKey();
        FirewallFilter filter = e.getValue();
        // TODO: support other filter families
        if (filter.getFamily() != Family.INET) {
            continue;
        }
        IpAccessList list = toIpAccessList(filter);
        _c.getIpAccessLists().put(name, list);
    }
    // objects
    for (Entry<String, FirewallFilter> e : _filters.entrySet()) {
        String name = e.getKey();
        FirewallFilter filter = e.getValue();
        if (filter.getRoutingPolicy()) {
            // TODO: support other filter families
            if (filter.getFamily() != Family.INET) {
                continue;
            }
            RoutingPolicy routingPolicy = toRoutingPolicy(filter);
            _c.getRoutingPolicies().put(name, routingPolicy);
        }
    }
    // convert route filters to route filter lists
    for (Entry<String, RouteFilter> e : _routeFilters.entrySet()) {
        String name = e.getKey();
        RouteFilter rf = e.getValue();
        if (rf.getIpv4()) {
            RouteFilterList rfl = new RouteFilterList(name);
            for (RouteFilterLine line : rf.getLines()) {
                if (line.getThens().size() == 0) {
                    line.applyTo(rfl);
                }
            }
            _c.getRouteFilterLists().put(name, rfl);
        }
        if (rf.getIpv6()) {
            Route6FilterList rfl = new Route6FilterList(name);
            for (RouteFilterLine line : rf.getLines()) {
                if (line.getThens().size() == 0) {
                    line.applyTo(rfl);
                }
            }
            _c.getRoute6FilterLists().put(name, rfl);
        }
    }
    // convert community lists
    for (Entry<String, CommunityList> e : _communityLists.entrySet()) {
        String name = e.getKey();
        CommunityList cl = e.getValue();
        org.batfish.datamodel.CommunityList newCl = toCommunityList(cl);
        _c.getCommunityLists().put(name, newCl);
    }
    // convert policy-statements to RoutingPolicy objects
    for (Entry<String, PolicyStatement> e : _policyStatements.entrySet()) {
        String name = e.getKey();
        PolicyStatement ps = e.getValue();
        RoutingPolicy routingPolicy = toRoutingPolicy(ps);
        _c.getRoutingPolicies().put(name, routingPolicy);
    }
    // convert interfaces
    Map<String, Interface> allInterfaces = new LinkedHashMap<>();
    for (Interface iface : _interfaces.values()) {
        allInterfaces.putAll(iface.getUnits());
    }
    for (NodeDevice nd : _nodeDevices.values()) {
        for (Interface iface : nd.getInterfaces().values()) {
            allInterfaces.putAll(iface.getUnits());
        }
    }
    for (Entry<String, Interface> eUnit : allInterfaces.entrySet()) {
        String unitName = eUnit.getKey();
        Interface unitIface = eUnit.getValue();
        unitIface.inheritUnsetFields();
        org.batfish.datamodel.Interface newUnitIface = toInterface(unitIface);
        _c.getInterfaces().put(unitName, newUnitIface);
        Vrf vrf = newUnitIface.getVrf();
        String vrfName = vrf.getName();
        vrf.getInterfaces().put(unitName, newUnitIface);
        _routingInstances.get(vrfName).getInterfaces().put(unitName, unitIface);
    }
    // set router-id
    if (_defaultRoutingInstance.getRouterId() == null) {
        Interface loopback0 = _defaultRoutingInstance.getInterfaces().get(FIRST_LOOPBACK_INTERFACE_NAME);
        if (loopback0 != null) {
            Interface loopback0unit0 = loopback0.getUnits().get(FIRST_LOOPBACK_INTERFACE_NAME + ".0");
            if (loopback0unit0 != null) {
                InterfaceAddress address = loopback0unit0.getPrimaryAddress();
                if (address != null) {
                    // now we should set router-id
                    Ip routerId = address.getIp();
                    _defaultRoutingInstance.setRouterId(routerId);
                }
            }
        }
    }
    // copy ike proposals
    _c.getIkeProposals().putAll(_ikeProposals);
    // convert ike policies
    for (Entry<String, IkePolicy> e : _ikePolicies.entrySet()) {
        String name = e.getKey();
        IkePolicy oldIkePolicy = e.getValue();
        org.batfish.datamodel.IkePolicy newPolicy = toIkePolicy(oldIkePolicy);
        _c.getIkePolicies().put(name, newPolicy);
    }
    // convert ike gateways
    for (Entry<String, IkeGateway> e : _ikeGateways.entrySet()) {
        String name = e.getKey();
        IkeGateway oldIkeGateway = e.getValue();
        org.batfish.datamodel.IkeGateway newIkeGateway = toIkeGateway(oldIkeGateway);
        _c.getIkeGateways().put(name, newIkeGateway);
    }
    // copy ipsec proposals
    _c.getIpsecProposals().putAll(_ipsecProposals);
    // convert ipsec policies
    for (Entry<String, IpsecPolicy> e : _ipsecPolicies.entrySet()) {
        String name = e.getKey();
        IpsecPolicy oldIpsecPolicy = e.getValue();
        org.batfish.datamodel.IpsecPolicy newPolicy = toIpsecPolicy(oldIpsecPolicy);
        _c.getIpsecPolicies().put(name, newPolicy);
    }
    // convert ipsec vpns
    for (Entry<String, IpsecVpn> e : _ipsecVpns.entrySet()) {
        String name = e.getKey();
        IpsecVpn oldIpsecVpn = e.getValue();
        org.batfish.datamodel.IpsecVpn newIpsecVpn = toIpsecVpn(oldIpsecVpn);
        _c.getIpsecVpns().put(name, newIpsecVpn);
    }
    // zones
    for (Zone zone : _zones.values()) {
        org.batfish.datamodel.Zone newZone = toZone(zone);
        _c.getZones().put(zone.getName(), newZone);
    }
    // default zone behavior
    _c.setDefaultCrossZoneAction(_defaultCrossZoneAction);
    _c.setDefaultInboundAction(_defaultInboundAction);
    for (Entry<String, RoutingInstance> e : _routingInstances.entrySet()) {
        String riName = e.getKey();
        RoutingInstance ri = e.getValue();
        Vrf vrf = _c.getVrfs().get(riName);
        // dhcp relay
        for (Entry<String, DhcpRelayGroup> e2 : ri.getDhcpRelayGroups().entrySet()) {
            DhcpRelayGroup rg = e2.getValue();
            List<org.batfish.datamodel.Interface> interfaces = new ArrayList<>();
            if (rg.getAllInterfaces()) {
                interfaces.addAll(_c.getInterfaces().values());
            } else {
                for (String ifaceName : rg.getInterfaces()) {
                    org.batfish.datamodel.Interface iface = _c.getInterfaces().get(ifaceName);
                    interfaces.add(iface);
                }
            }
            String asgName = rg.getActiveServerGroup();
            if (asgName != null) {
                DhcpRelayServerGroup asg = ri.getDhcpRelayServerGroups().get(asgName);
                if (asg == null) {
                    int asgLine = rg.getActiveServerGroupLine();
                    undefined(JuniperStructureType.DHCP_RELAY_SERVER_GROUP, asgName, JuniperStructureUsage.DHCP_RELAY_GROUP_ACTIVE_SERVER_GROUP, asgLine);
                } else {
                    for (org.batfish.datamodel.Interface iface : interfaces) {
                        iface.getDhcpRelayAddresses().addAll(asg.getServers());
                    }
                }
            }
        }
        // snmp
        SnmpServer snmpServer = ri.getSnmpServer();
        vrf.setSnmpServer(snmpServer);
        if (snmpServer != null) {
            for (SnmpCommunity community : snmpServer.getCommunities().values()) {
                String listName = community.getAccessList();
                if (listName != null) {
                    int listLine = community.getAccessListLine();
                    PrefixList prefixList = _prefixLists.get(listName);
                    if (prefixList != null) {
                        prefixList.getReferers().put(community, "prefix-list for community: " + community.getName());
                    } else {
                        undefined(JuniperStructureType.PREFIX_LIST, listName, JuniperStructureUsage.SNMP_COMMUNITY_PREFIX_LIST, listLine);
                    }
                }
            }
        }
        // static routes
        for (StaticRoute route : _defaultRoutingInstance.getRibs().get(RoutingInformationBase.RIB_IPV4_UNICAST).getStaticRoutes().values()) {
            org.batfish.datamodel.StaticRoute newStaticRoute = toStaticRoute(route);
            vrf.getStaticRoutes().add(newStaticRoute);
        }
        // aggregate routes
        for (AggregateRoute route : _defaultRoutingInstance.getRibs().get(RoutingInformationBase.RIB_IPV4_UNICAST).getAggregateRoutes().values()) {
            org.batfish.datamodel.GeneratedRoute newAggregateRoute = toAggregateRoute(route);
            vrf.getGeneratedRoutes().add(newAggregateRoute);
        }
        // generated routes
        for (GeneratedRoute route : _defaultRoutingInstance.getRibs().get(RoutingInformationBase.RIB_IPV4_UNICAST).getGeneratedRoutes().values()) {
            org.batfish.datamodel.GeneratedRoute newGeneratedRoute = toGeneratedRoute(route);
            vrf.getGeneratedRoutes().add(newGeneratedRoute);
        }
        // create ospf process
        if (ri.getOspfAreas().size() > 0) {
            OspfProcess oproc = createOspfProcess(ri);
            vrf.setOspfProcess(oproc);
        }
        // create is-is process
        // is-is runs only if iso address is configured on lo0 unit 0
        Interface loopback0 = _defaultRoutingInstance.getInterfaces().get(FIRST_LOOPBACK_INTERFACE_NAME);
        if (loopback0 != null) {
            Interface loopback0unit0 = loopback0.getUnits().get(FIRST_LOOPBACK_INTERFACE_NAME + ".0");
            if (loopback0unit0 != null) {
                IsoAddress isisNet = loopback0unit0.getIsoAddress();
                if (isisNet != null) {
                    // now we should create is-is process
                    IsisProcess proc = createIsisProcess(ri, isisNet);
                    vrf.setIsisProcess(proc);
                }
            }
        }
        // create bgp process
        if (ri.getNamedBgpGroups().size() > 0 || ri.getIpBgpGroups().size() > 0) {
            BgpProcess proc = createBgpProcess(ri);
            vrf.setBgpProcess(proc);
        }
    }
    // mark forwarding table export policy if it exists
    String forwardingTableExportPolicyName = _defaultRoutingInstance.getForwardingTableExportPolicy();
    if (forwardingTableExportPolicyName != null) {
        int forwardingTableExportPolicyLine = _defaultRoutingInstance.getForwardingTableExportPolicyLine();
        PolicyStatement forwardingTableExportPolicy = _policyStatements.get(forwardingTableExportPolicyName);
        if (forwardingTableExportPolicy != null) {
            setPolicyStatementReferent(forwardingTableExportPolicyName, _defaultRoutingInstance, "Forwarding-table export policy");
        } else {
            undefined(JuniperStructureType.POLICY_STATEMENT, forwardingTableExportPolicyName, JuniperStructureUsage.FORWARDING_TABLE_EXPORT_POLICY, forwardingTableExportPolicyLine);
        }
    }
    // mark references to authentication key chain that may not appear in data model
    markAuthenticationKeyChains(JuniperStructureUsage.AUTHENTICATION_KEY_CHAINS_POLICY, _c);
    markStructure(JuniperStructureType.FIREWALL_FILTER, JuniperStructureUsage.INTERFACE_FILTER, _filters);
    // warn about unreferenced data structures
    warnUnreferencedAuthenticationKeyChains();
    warnUnreferencedBgpGroups();
    warnUnreferencedDhcpRelayServerGroups();
    warnUnreferencedPolicyStatements();
    warnUnreferencedFirewallFilters();
    warnUnreferencedIkeProposals();
    warnUnreferencedIkePolicies();
    warnUnreferencedIkeGateways();
    warnUnreferencedIpsecProposals();
    warnUnreferencedIpsecPolicies();
    warnUnusedPrefixLists();
    warnEmptyPrefixLists();
    warnAndDisableUnreferencedStInterfaces();
    _c.computeRoutingPolicySources(_w);
    return _c;
}
Also used : VendorConfiguration(org.batfish.vendor.VendorConfiguration) Configuration(org.batfish.datamodel.Configuration) BgpProcess(org.batfish.datamodel.BgpProcess) ArrayList(java.util.ArrayList) Vrf(org.batfish.datamodel.Vrf) LinkedHashMap(java.util.LinkedHashMap) HashSet(java.util.HashSet) SnmpCommunity(org.batfish.datamodel.SnmpCommunity) InterfaceAddress(org.batfish.datamodel.InterfaceAddress) IpAccessList(org.batfish.datamodel.IpAccessList) Ip(org.batfish.datamodel.Ip) Prefix(org.batfish.datamodel.Prefix) SubRange(org.batfish.datamodel.SubRange) IsisProcess(org.batfish.datamodel.IsisProcess) RoutingPolicy(org.batfish.datamodel.routing_policy.RoutingPolicy) OspfProcess(org.batfish.datamodel.OspfProcess) Route6FilterList(org.batfish.datamodel.Route6FilterList) IsoAddress(org.batfish.datamodel.IsoAddress) RouteFilterList(org.batfish.datamodel.RouteFilterList) SnmpServer(org.batfish.datamodel.SnmpServer)

Example 13 with OspfProcess

use of org.batfish.datamodel.OspfProcess in project batfish by batfish.

the class OspfTest method getOspfRoutes.

/*
   * Int:1/2   2/1      2/3   3/2      3/4   4/3
   * R1 <=========> R2 <=========> R3 <=========> R4
   *  A      B       C      D       E      F       G
   *
   *  Areas:
   *  A: R1 Loopback0
   *  B: R1 E1/2, R2 E2/1
   *  C: R2 Loopback0
   *  D: R2 E2/3, R3 E3/2
   *  E: R3 Loopback0
   *  F: R3 E3/4, R4 E4/3
   *  G: R4 Loopback0
   */
private SortedMap<String, SortedMap<String, SortedSet<AbstractRoute>>> getOspfRoutes(long areaA, long areaB, long areaC, long areaD, long areaE, long areaF, long areaG, Long maxMetricExternalNetworks, Long maxMetricStubNetworks, Long maxMetricSummaryNetworks, Long maxMetricTransitLinks) {
    String l0Name = "Loopback0";
    String l1Name = "Loopback1";
    String c1E1To2Name = "Ethernet1/2";
    String c2E2To1Name = "Ethernet2/1";
    String c2E2To3Name = "Ethernet2/3";
    String c3E3To2Name = "Ethernet3/2";
    String c3E3To4Name = "Ethernet3/4";
    String c4E4To3Name = "Ethernet4/3";
    RoutingPolicy.Builder rpb = _nf.routingPolicyBuilder();
    OspfArea.Builder oaba = _nf.ospfAreaBuilder().setNumber(areaA);
    OspfArea.Builder oabb = _nf.ospfAreaBuilder().setNumber(areaB);
    OspfArea.Builder oabc = _nf.ospfAreaBuilder().setNumber(areaC);
    OspfArea.Builder oabd = _nf.ospfAreaBuilder().setNumber(areaD);
    OspfArea.Builder oabe = _nf.ospfAreaBuilder().setNumber(areaE);
    OspfArea.Builder oabf = _nf.ospfAreaBuilder().setNumber(areaF);
    OspfArea.Builder oabg = _nf.ospfAreaBuilder().setNumber(areaG);
    Configuration c1 = _cb.setHostname(C1_NAME).build();
    Vrf v1 = _vb.setOwner(c1).build();
    RoutingPolicy c1ExportPolicy = rpb.setOwner(c1).setStatements(getExportPolicyStatements(C1_L1_ADDRESS)).build();
    OspfProcess op1 = _opb.setVrf(v1).setExportPolicy(c1ExportPolicy).build();
    OspfArea oa1a = oaba.setOspfProcess(op1).build();
    OspfArea oa1b = areaA == areaB ? oa1a : oabb.setOspfProcess(op1).build();
    _ib.setOwner(c1).setVrf(v1).setOspfArea(oa1a);
    _ib.setOspfPassive(true).setName(l0Name).setAddress(C1_L0_ADDRESS).build();
    _ib.setOspfEnabled(false).setOspfPassive(false).setOspfArea(null).setName(l1Name).setAddress(C1_L1_ADDRESS).build();
    _ib.setOspfEnabled(true).setOspfArea(oa1b);
    _ib.setName(c1E1To2Name).setAddress(C1_E1_2_ADDRESS).build();
    Configuration c2 = _cb.setHostname(C2_NAME).build();
    Vrf v2 = _vb.setOwner(c2).build();
    RoutingPolicy c2ExportPolicy = rpb.setOwner(c2).setStatements(getExportPolicyStatements(C2_L1_ADDRESS)).build();
    OspfProcess op2 = _opb.setVrf(v2).setMaxMetricExternalNetworks(maxMetricExternalNetworks).setMaxMetricStubNetworks(maxMetricStubNetworks).setMaxMetricSummaryNetworks(maxMetricSummaryNetworks).setMaxMetricTransitLinks(maxMetricTransitLinks).setExportPolicy(c2ExportPolicy).build();
    _opb.setMaxMetricExternalNetworks(null).setMaxMetricStubNetworks(null).setMaxMetricSummaryNetworks(null).setMaxMetricTransitLinks(null);
    OspfArea oa2b = oabb.setOspfProcess(op2).build();
    OspfArea oa2c = areaB == areaC ? oa2b : oabc.setOspfProcess(op2).build();
    OspfArea oa2d = areaB == areaD ? oa2b : areaC == areaD ? oa2c : oabd.setOspfProcess(op2).build();
    _ib.setOwner(c2).setVrf(v2).setOspfArea(oa2c);
    _ib.setOspfPassive(true).setName(l0Name).setAddress(C2_L0_ADDRESS).build();
    _ib.setOspfEnabled(false).setOspfPassive(false).setOspfArea(null).setName(l1Name).setAddress(C2_L1_ADDRESS).build();
    _ib.setOspfEnabled(true).setOspfArea(oa2b);
    _ib.setName(c2E2To1Name).setAddress(C2_E2_1_ADDRESS).setOspfPointToPoint(true).build();
    _ib.setOspfPointToPoint(false).setOspfArea(oa2d);
    _ib.setName(c2E2To3Name).setAddress(C2_E2_3_ADDRESS).build();
    Configuration c3 = _cb.setHostname(C3_NAME).build();
    Vrf v3 = _vb.setOwner(c3).build();
    RoutingPolicy c3ExportPolicy = rpb.setOwner(c3).setStatements(getExportPolicyStatements(C3_L1_ADDRESS)).build();
    OspfProcess op3 = _opb.setVrf(v3).setExportPolicy(c3ExportPolicy).build();
    OspfArea oa3d = oabd.setOspfProcess(op3).build();
    OspfArea oa3e = areaD == areaE ? oa3d : oabe.setOspfProcess(op3).build();
    OspfArea oa3f = areaD == areaF ? oa3d : areaE == areaF ? oa3e : oabf.setOspfProcess(op3).build();
    _ib.setOwner(c3).setVrf(v3).setOspfArea(oa3e);
    _ib.setOspfPassive(true).setName(l0Name).setAddress(C3_L0_ADDRESS).build();
    _ib.setOspfEnabled(false).setOspfPassive(false).setOspfArea(null).setName(l1Name).setAddress(C3_L1_ADDRESS).build();
    _ib.setOspfEnabled(true).setOspfArea(oa3d);
    _ib.setName(c3E3To2Name).setAddress(C3_E3_2_ADDRESS).build();
    _ib.setName(c3E3To4Name).setAddress(C3_E3_4_ADDRESS).setOspfArea(oa3f).build();
    Configuration c4 = _cb.setHostname(C4_NAME).build();
    Vrf v4 = _vb.setOwner(c4).build();
    RoutingPolicy c4ExportPolicy = rpb.setOwner(c4).setStatements(getExportPolicyStatements(C4_L1_ADDRESS)).build();
    OspfProcess op4 = _opb.setVrf(v4).setExportPolicy(c4ExportPolicy).build();
    OspfArea oa4f = oabf.setOspfProcess(op4).build();
    OspfArea oa4g = areaF == areaG ? oa4f : oabg.setOspfProcess(op4).build();
    _ib.setOwner(c4).setVrf(v4).setOspfArea(oa4g);
    _ib.setOspfPassive(true).setName(l0Name).setAddress(C4_L0_ADDRESS).build();
    _ib.setOspfEnabled(false).setOspfPassive(false).setOspfArea(null).setName(l1Name).setAddress(C4_L1_ADDRESS).build();
    _ib.setOspfEnabled(true).setOspfArea(oa4f);
    _ib.setName(c4E4To3Name).setAddress(C4_E4_3_ADDRESS).build();
    SortedMap<String, Configuration> configurations = new ImmutableSortedMap.Builder<String, Configuration>(String::compareTo).put(c1.getName(), c1).put(c2.getName(), c2).put(c3.getName(), c3).put(c4.getName(), c4).build();
    BdpEngine engine = new BdpEngine(new MockBdpSettings(), new BatfishLogger(BatfishLogger.LEVELSTR_OUTPUT, false), (s, i) -> new AtomicInteger());
    Topology topology = CommonUtil.synthesizeTopology(configurations);
    BdpDataPlane dp = engine.computeDataPlane(false, configurations, topology, Collections.emptySet(), new BdpAnswerElement());
    return engine.getRoutes(dp);
}
Also used : OspfArea(org.batfish.datamodel.OspfArea) BdpAnswerElement(org.batfish.datamodel.answers.BdpAnswerElement) Configuration(org.batfish.datamodel.Configuration) BatfishLogger(org.batfish.common.BatfishLogger) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) RoutingPolicy(org.batfish.datamodel.routing_policy.RoutingPolicy) OspfProcess(org.batfish.datamodel.OspfProcess) Vrf(org.batfish.datamodel.Vrf) Topology(org.batfish.datamodel.Topology) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 14 with OspfProcess

use of org.batfish.datamodel.OspfProcess in project batfish by batfish.

the class OspfTest method testOspfNonDefaultVrfAdjacency.

@Test
public void testOspfNonDefaultVrfAdjacency() {
    OspfArea.Builder oab = _nf.ospfAreaBuilder().setNumber(1L);
    Prefix adjacencyPrefix = Prefix.parse("1.0.0.0/31");
    InterfaceAddress i1Address = new InterfaceAddress(adjacencyPrefix.getStartIp(), adjacencyPrefix.getPrefixLength());
    InterfaceAddress i2Address = new InterfaceAddress(adjacencyPrefix.getEndIp(), adjacencyPrefix.getPrefixLength());
    Configuration c1 = _cb.build();
    Vrf v1 = _vb.setOwner(c1).build();
    OspfProcess o1 = _opb.setVrf(v1).build();
    OspfArea oa1 = oab.setOspfProcess(o1).build();
    // Interface in default VRF on c1
    _ib.setOwner(c1).setVrf(v1).setAddress(i1Address).setOspfArea(oa1).build();
    Configuration c2 = _cb.build();
    // default vrf
    Vrf v2Default = _vb.setOwner(c2).build();
    // default OSPF process
    _opb.setVrf(v2Default).build();
    Vrf v2Other = _vb.setName("v2Other").build();
    OspfProcess o2Other = _opb.setVrf(v2Other).build();
    OspfArea oa2 = oab.setOspfProcess(o2Other).build();
    // Interface in VRF v2Other on c2
    _ib.setOwner(c2).setVrf(v2Other).setAddress(i2Address).setOspfArea(oa2).build();
    Map<String, Configuration> configurations = ImmutableMap.of(c1.getName(), c1, c2.getName(), c2);
    Map<Ip, Set<String>> ipOwners = CommonUtil.computeIpOwners(configurations, true);
    Topology topology = CommonUtil.synthesizeTopology(configurations);
    CommonUtil.initRemoteOspfNeighbors(configurations, ipOwners, topology);
    IpLink expectedIpEdge1 = new IpLink(i1Address.getIp(), i2Address.getIp());
    IpLink expectedIpEdge2 = new IpLink(i2Address.getIp(), i1Address.getIp());
    assertThat(o1, hasOspfNeighbors(hasKey(expectedIpEdge1)));
    OspfNeighbor on1 = o1.getOspfNeighbors().get(expectedIpEdge1);
    assertThat(o2Other, hasOspfNeighbors(hasKey(expectedIpEdge2)));
    OspfNeighbor on2 = o2Other.getOspfNeighbors().get(expectedIpEdge2);
    assertThat(on1, hasRemoteOspfNeighbor(sameInstance(on2)));
    assertThat(on2, hasRemoteOspfNeighbor(sameInstance(on1)));
}
Also used : IpLink(org.batfish.datamodel.IpLink) OspfNeighbor(org.batfish.datamodel.OspfNeighbor) OspfNeighborMatchers.hasRemoteOspfNeighbor(org.batfish.datamodel.matchers.OspfNeighborMatchers.hasRemoteOspfNeighbor) OspfArea(org.batfish.datamodel.OspfArea) SortedSet(java.util.SortedSet) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) ExplicitPrefixSet(org.batfish.datamodel.routing_policy.expr.ExplicitPrefixSet) MatchPrefixSet(org.batfish.datamodel.routing_policy.expr.MatchPrefixSet) Configuration(org.batfish.datamodel.Configuration) InterfaceAddress(org.batfish.datamodel.InterfaceAddress) Ip(org.batfish.datamodel.Ip) OspfProcess(org.batfish.datamodel.OspfProcess) AbstractRouteMatchers.hasPrefix(org.batfish.datamodel.matchers.AbstractRouteMatchers.hasPrefix) Prefix(org.batfish.datamodel.Prefix) Vrf(org.batfish.datamodel.Vrf) Topology(org.batfish.datamodel.Topology) Test(org.junit.Test)

Example 15 with OspfProcess

use of org.batfish.datamodel.OspfProcess in project batfish by batfish.

the class CommonUtil method initRemoteOspfNeighbors.

public static void initRemoteOspfNeighbors(Map<String, Configuration> configurations, Map<Ip, Set<String>> ipOwners, Topology topology) {
    for (Entry<String, Configuration> e : configurations.entrySet()) {
        String hostname = e.getKey();
        Configuration c = e.getValue();
        for (Entry<String, Vrf> e2 : c.getVrfs().entrySet()) {
            Vrf vrf = e2.getValue();
            OspfProcess proc = vrf.getOspfProcess();
            if (proc != null) {
                proc.setOspfNeighbors(new TreeMap<>());
                String vrfName = e2.getKey();
                for (Entry<Long, OspfArea> e3 : proc.getAreas().entrySet()) {
                    long areaNum = e3.getKey();
                    OspfArea area = e3.getValue();
                    for (String ifaceName : area.getInterfaces()) {
                        Interface iface = c.getInterfaces().get(ifaceName);
                        if (iface.getOspfPassive()) {
                            continue;
                        }
                        SortedSet<Edge> ifaceEdges = topology.getInterfaceEdges().get(new NodeInterfacePair(hostname, ifaceName));
                        boolean hasNeighbor = false;
                        Ip localIp = iface.getAddress().getIp();
                        if (ifaceEdges != null) {
                            for (Edge edge : ifaceEdges) {
                                if (edge.getNode1().equals(hostname)) {
                                    String remoteHostname = edge.getNode2();
                                    String remoteIfaceName = edge.getInt2();
                                    Configuration remoteNode = configurations.get(remoteHostname);
                                    Interface remoteIface = remoteNode.getInterfaces().get(remoteIfaceName);
                                    if (remoteIface.getOspfPassive()) {
                                        continue;
                                    }
                                    Vrf remoteVrf = remoteIface.getVrf();
                                    String remoteVrfName = remoteVrf.getName();
                                    OspfProcess remoteProc = remoteVrf.getOspfProcess();
                                    if (remoteProc != null) {
                                        if (remoteProc.getOspfNeighbors() == null) {
                                            remoteProc.setOspfNeighbors(new TreeMap<>());
                                        }
                                        OspfArea remoteArea = remoteProc.getAreas().get(areaNum);
                                        if (remoteArea != null && remoteArea.getInterfaces().contains(remoteIfaceName)) {
                                            Ip remoteIp = remoteIface.getAddress().getIp();
                                            IpLink localKey = new IpLink(localIp, remoteIp);
                                            OspfNeighbor neighbor = proc.getOspfNeighbors().get(localKey);
                                            if (neighbor == null) {
                                                hasNeighbor = true;
                                                // initialize local neighbor
                                                neighbor = new OspfNeighbor(localKey);
                                                neighbor.setArea(areaNum);
                                                neighbor.setVrf(vrfName);
                                                neighbor.setOwner(c);
                                                neighbor.setInterface(iface);
                                                proc.getOspfNeighbors().put(localKey, neighbor);
                                                // initialize remote neighbor
                                                IpLink remoteKey = new IpLink(remoteIp, localIp);
                                                OspfNeighbor remoteNeighbor = new OspfNeighbor(remoteKey);
                                                remoteNeighbor.setArea(areaNum);
                                                remoteNeighbor.setVrf(remoteVrfName);
                                                remoteNeighbor.setOwner(remoteNode);
                                                remoteNeighbor.setInterface(remoteIface);
                                                remoteProc.getOspfNeighbors().put(remoteKey, remoteNeighbor);
                                                // link neighbors
                                                neighbor.setRemoteOspfNeighbor(remoteNeighbor);
                                                remoteNeighbor.setRemoteOspfNeighbor(neighbor);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        if (!hasNeighbor) {
                            IpLink key = new IpLink(localIp, Ip.ZERO);
                            OspfNeighbor neighbor = new OspfNeighbor(key);
                            neighbor.setArea(areaNum);
                            neighbor.setVrf(vrfName);
                            neighbor.setOwner(c);
                            neighbor.setInterface(iface);
                            proc.getOspfNeighbors().put(key, neighbor);
                        }
                    }
                }
            }
        }
    }
}
Also used : IpLink(org.batfish.datamodel.IpLink) OspfNeighbor(org.batfish.datamodel.OspfNeighbor) OspfArea(org.batfish.datamodel.OspfArea) Configuration(org.batfish.datamodel.Configuration) NodeInterfacePair(org.batfish.datamodel.collections.NodeInterfacePair) Ip(org.batfish.datamodel.Ip) OspfProcess(org.batfish.datamodel.OspfProcess) Vrf(org.batfish.datamodel.Vrf) Edge(org.batfish.datamodel.Edge) Interface(org.batfish.datamodel.Interface)

Aggregations

OspfProcess (org.batfish.datamodel.OspfProcess)15 Configuration (org.batfish.datamodel.Configuration)9 OspfArea (org.batfish.datamodel.OspfArea)7 Interface (org.batfish.datamodel.Interface)6 Prefix (org.batfish.datamodel.Prefix)6 Vrf (org.batfish.datamodel.Vrf)5 RoutingPolicy (org.batfish.datamodel.routing_policy.RoutingPolicy)5 Ip (org.batfish.datamodel.Ip)4 HashSet (java.util.HashSet)3 Edge (org.batfish.datamodel.Edge)3 InterfaceAddress (org.batfish.datamodel.InterfaceAddress)3 IpLink (org.batfish.datamodel.IpLink)3 OspfNeighbor (org.batfish.datamodel.OspfNeighbor)3 BatfishException (org.batfish.common.BatfishException)2 BgpNeighbor (org.batfish.datamodel.BgpNeighbor)2 BgpProcess (org.batfish.datamodel.BgpProcess)2 OspfIntraAreaRoute (org.batfish.datamodel.OspfIntraAreaRoute)2 Topology (org.batfish.datamodel.Topology)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)1