Search in sources :

Example 11 with BgpAdvertisement

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

the class BdpDataPlanePlugin method computeDataPlane.

@Override
public ComputeDataPlaneResult computeDataPlane(boolean differentialContext, Map<String, Configuration> configurations, Topology topology) {
    BdpAnswerElement ae = new BdpAnswerElement();
    Set<BgpAdvertisement> externalAdverts = _batfish.loadExternalBgpAnnouncements(configurations);
    BdpDataPlane dp = _engine.computeDataPlane(differentialContext, configurations, topology, externalAdverts, ae);
    double averageRoutes = dp.getNodes().values().stream().flatMap(n -> n._virtualRouters.values().stream()).mapToInt(vr -> vr._mainRib.getRoutes().size()).average().orElse(0.00d);
    _logger.infof("Generated data plane for testrig:%s in container:%s; iterations:%s, total nodes:%s, " + "avg entries per node:%.2f, work-id:%s\n", _batfish.getTestrigName(), _batfish.getContainerName(), ae.getDependentRoutesIterations(), configurations.size(), averageRoutes, _batfish.getTaskId());
    return new ComputeDataPlaneResult(ae, dp);
}
Also used : Plugin(org.batfish.common.plugin.Plugin) DataPlane(org.batfish.datamodel.DataPlane) SortedSet(java.util.SortedSet) BdpAnswerElement(org.batfish.datamodel.answers.BdpAnswerElement) Set(java.util.Set) HashMap(java.util.HashMap) FlowTrace(org.batfish.datamodel.FlowTrace) DataPlanePlugin(org.batfish.common.plugin.DataPlanePlugin) ArrayList(java.util.ArrayList) BgpAdvertisement(org.batfish.datamodel.BgpAdvertisement) Flow(org.batfish.datamodel.Flow) List(java.util.List) AbstractRoute(org.batfish.datamodel.AbstractRoute) Topology(org.batfish.datamodel.Topology) IbgpTopology(org.batfish.datamodel.collections.IbgpTopology) AutoService(com.google.auto.service.AutoService) Map(java.util.Map) Configuration(org.batfish.datamodel.Configuration) LinkedHashSet(java.util.LinkedHashSet) SortedMap(java.util.SortedMap) BgpAdvertisement(org.batfish.datamodel.BgpAdvertisement) BdpAnswerElement(org.batfish.datamodel.answers.BdpAnswerElement)

Example 12 with BgpAdvertisement

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

the class Batfish method loadExternalBgpAnnouncements.

@Override
public Set<BgpAdvertisement> loadExternalBgpAnnouncements(Map<String, Configuration> configurations) {
    Set<BgpAdvertisement> advertSet = new LinkedHashSet<>();
    for (ExternalBgpAdvertisementPlugin plugin : _externalBgpAdvertisementPlugins) {
        Set<BgpAdvertisement> currentAdvertisements = plugin.loadExternalBgpAdvertisements();
        advertSet.addAll(currentAdvertisements);
    }
    return advertSet;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) BgpAdvertisement(org.batfish.datamodel.BgpAdvertisement) ExternalBgpAdvertisementPlugin(org.batfish.common.plugin.ExternalBgpAdvertisementPlugin)

Example 13 with BgpAdvertisement

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

the class Batfish method processExternalBgpAnnouncements.

/**
 * Reads the external bgp announcement specified in the environment, and populates the
 * vendor-independent configurations with data about those announcements
 *
 * @param configurations The vendor-independent configurations to be modified
 */
public Set<BgpAdvertisement> processExternalBgpAnnouncements(Map<String, Configuration> configurations, SortedSet<Long> allCommunities) {
    Set<BgpAdvertisement> advertSet = new LinkedHashSet<>();
    Path externalBgpAnnouncementsPath = _testrigSettings.getEnvironmentSettings().getExternalBgpAnnouncementsPath();
    if (Files.exists(externalBgpAnnouncementsPath)) {
        String externalBgpAnnouncementsFileContents = CommonUtil.readFile(externalBgpAnnouncementsPath);
        try {
            JSONObject jsonObj = new JSONObject(externalBgpAnnouncementsFileContents);
            JSONArray announcements = jsonObj.getJSONArray(BfConsts.PROP_BGP_ANNOUNCEMENTS);
            for (int index = 0; index < announcements.length(); index++) {
                JSONObject announcement = new JSONObject();
                announcement.put("@id", index);
                JSONObject announcementSrc = announcements.getJSONObject(index);
                for (Iterator<?> i = announcementSrc.keys(); i.hasNext(); ) {
                    String key = (String) i.next();
                    if (!key.equals("@id")) {
                        announcement.put(key, announcementSrc.get(key));
                    }
                }
                BgpAdvertisement bgpAdvertisement = BatfishObjectMapper.mapper().readValue(announcement.toString(), BgpAdvertisement.class);
                allCommunities.addAll(bgpAdvertisement.getCommunities());
                advertSet.add(bgpAdvertisement);
            }
        } catch (JSONException | IOException e) {
            throw new BatfishException("Problems parsing JSON in " + externalBgpAnnouncementsPath, e);
        }
    }
    return advertSet;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Path(java.nio.file.Path) CleanBatfishException(org.batfish.common.CleanBatfishException) BatfishException(org.batfish.common.BatfishException) JSONArray(org.codehaus.jettison.json.JSONArray) JSONException(org.codehaus.jettison.json.JSONException) IOException(java.io.IOException) BgpAdvertisement(org.batfish.datamodel.BgpAdvertisement) JSONObject(org.codehaus.jettison.json.JSONObject)

Example 14 with BgpAdvertisement

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

the class CounterExample method buildFlowHistory.

/*
   * Creates a trace-based example of what happens
   * to a packet (e.g., why it is not reachable).
   */
FlowHistory buildFlowHistory(String testrigName, Collection<String> sourceRouters, Encoder enc, Map<String, Boolean> reach) {
    FlowHistory fh = new FlowHistory();
    for (String source : sourceRouters) {
        Boolean sourceVar = reach.get(source);
        if (!sourceVar) {
            Tuple<Flow, FlowTrace> tup = buildFlowTrace(enc, source);
            SortedSet<Edge> failedLinks = buildFailedLinks(enc);
            SortedSet<BgpAdvertisement> envRoutes = buildEnvRoutingTable(enc);
            Environment baseEnv = new Environment("BASE", testrigName, failedLinks, null, null, null, null, envRoutes);
            fh.addFlowTrace(tup.getFirst(), "BASE", baseEnv, tup.getSecond());
        }
    }
    return fh;
}
Also used : BgpAdvertisement(org.batfish.datamodel.BgpAdvertisement) FlowHistory(org.batfish.datamodel.FlowHistory) FlowTrace(org.batfish.datamodel.FlowTrace) Environment(org.batfish.datamodel.pojo.Environment) Edge(org.batfish.datamodel.Edge) GraphEdge(org.batfish.symbolic.GraphEdge) Flow(org.batfish.datamodel.Flow)

Example 15 with BgpAdvertisement

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

the class VirtualRouterTest method computeBgpAdvertisementsSentToOutsideIgp.

@Test
public void computeBgpAdvertisementsSentToOutsideIgp() {
    RoutingPolicy exportPolicy = _routingPolicyBuilder.setStatements(ImmutableList.of(new SetOrigin(new LiteralOrigin(OriginType.INCOMPLETE, null)), _exitAcceptStatement)).build();
    _bgpNeighborBuilder.setExportPolicy(exportPolicy.getName()).setRemoteAs(TEST_AS2).build();
    _testVirtualRouter._mainRib.mergeRoute(new OspfInternalRoute.Builder().setNetwork(TEST_NETWORK).setMetric(TEST_METRIC).setArea(TEST_AREA).setAdmin(TEST_ADMIN).setProtocol(RoutingProtocol.OSPF).build());
    // checking number of bgp advertisements
    assertThat(_testVirtualRouter.computeBgpAdvertisementsToOutside(_ipOwners), equalTo(1));
    BgpAdvertisement bgpAdvertisement = _testVirtualRouter._sentBgpAdvertisements.iterator().next();
    // checking the attributes of the bgp advertisement
    assertThat(bgpAdvertisement, hasDestinationIp(TEST_DEST_IP));
    assertThat(bgpAdvertisement, hasNetwork(TEST_NETWORK));
    assertThat(bgpAdvertisement, hasOriginatorIp(TEST_SRC_IP));
    assertThat(bgpAdvertisement, hasType(BgpAdvertisementType.EBGP_SENT));
    assertThat(bgpAdvertisement, hasSourceIp(TEST_SRC_IP));
}
Also used : BgpAdvertisement(org.batfish.datamodel.BgpAdvertisement) LiteralOrigin(org.batfish.datamodel.routing_policy.expr.LiteralOrigin) OspfInternalRoute(org.batfish.datamodel.OspfInternalRoute) SetOrigin(org.batfish.datamodel.routing_policy.statement.SetOrigin) RoutingPolicy(org.batfish.datamodel.routing_policy.RoutingPolicy) Test(org.junit.Test)

Aggregations

BgpAdvertisement (org.batfish.datamodel.BgpAdvertisement)16 BatfishException (org.batfish.common.BatfishException)7 Ip (org.batfish.datamodel.Ip)7 LinkedHashSet (java.util.LinkedHashSet)6 AsPath (org.batfish.datamodel.AsPath)6 Prefix (org.batfish.datamodel.Prefix)6 TreeSet (java.util.TreeSet)5 AbstractRoute (org.batfish.datamodel.AbstractRoute)5 Configuration (org.batfish.datamodel.Configuration)5 Flow (org.batfish.datamodel.Flow)5 RoutingPolicy (org.batfish.datamodel.routing_policy.RoutingPolicy)5 SortedSet (java.util.SortedSet)4 BgpAdvertisementType (org.batfish.datamodel.BgpAdvertisement.BgpAdvertisementType)4 BgpNeighbor (org.batfish.datamodel.BgpNeighbor)4 FlowTrace (org.batfish.datamodel.FlowTrace)4 InterfaceAddress (org.batfish.datamodel.InterfaceAddress)4 Test (org.junit.Test)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3