Giter VIP home page Giter VIP logo

batfish / batfish Goto Github PK

View Code? Open in Web Editor NEW
1.0K 55.0 228.0 376.59 MB

Batfish is a network configuration analysis tool that can find bugs and guarantee the correctness of (planned or current) network configurations. It enables network engineers to rapidly and safely evolve their network, without fear of outages or security breaches.

Home Page: http://www.batfish.org

License: Apache License 2.0

Shell 0.02% Java 92.08% ANTLR 6.95% Python 0.04% Starlark 0.74% HCL 0.17%
network configuration configuration-parser configuration-analysis network-verification network-analysis network-security network-validation network-automation

batfish's Introduction

Got questions, feedback, or feature requests? Join our community on Slack!

codecov

What is Batfish?

Batfish is a network validation tool that provides correctness guarantees for security, reliability, and compliance by analyzing the configuration of network devices. It builds complete models of network behavior from device configurations and finds violations of network policies (built-in, user-defined, and best-practices).

A primary use case for Batfish is to validate configuration changes before deployment (though it can be used to validate deployed configurations as well). Pre-deployment validation is a critical gap in existing network automation workflows. By including Batfish in automation workflows, network engineers can close this gap and ensure that only correct changes are deployed.

Batfish does NOT require direct access to network devices. The core analysis requires only the configuration of network devices. This analysis may be enhanced using additional information from the network such as:

  • BGP routes received from external peers
  • Topology information represented by LLDP/CDP

See www.batfish.org for technical information on how it works.

What kinds of correctness checks does Batfish support?

The Batfish YouTube channel (subscribe!) and Python notebooks illustrate many checks. Batfish checks span a range of network behaviors.

Configuration Compliance

  • Flag undefined-but-referenced or defined-but-unreferenced structures (e.g., ACLs, route maps)
  • Configuration settings for MTUs, AAA, NTP, logging, etc. match templates
  • Devices can only be accessed using SSHv2 and password is not null

Reliability

  • End-to-end reachability is not impacted for any flow after any single-link or single-device failure
  • Certain services (e.g., DNS) are globally reachable

Security

  • Sensitive services can be reached only from specific subnets or devices
  • Paths between endpoints are as expected (e.g., traverse a firewall, have at least 2 way ECMP, etc...)

Change Analysis

  • End-to-end reachability is identical across the current and a planned configuration
  • Planned ACL or firewall changes are provably correct and causes no collateral damage for other traffic
  • Two configurations, potentially from different vendors, are functionally equivalent

How do I get started?

1. Run the Batfish service

Getting started with Batfish is easy. Just pull and run the latest allinone Docker container that includes Batfish as well as example Jupyter notebooks.

docker pull batfish/allinone

docker run --name batfish -v batfish-data:/data -p 8888:8888 -p 9997:9997 -p 9996:9996 batfish/allinone

The second command starts the Batfish service and maps the necessary TCP ports.

Advanced Docker configuration:

The amount of memory available to Batfish is determined by the Docker configuration. You may wish to supply the --memory command-line argument to explicitly set this value.

On Linux systems that run the OOM Killer, you may also wish to supply the --oom-kill-disable argument, which runs in conjunction with the --memory argument to prevent Linux from killing Batfish when there is memory pressure on the system.

2. Browse example notebooks (optional)

If you are new to Batfish, consider walking through our notebooks which highlight different capabilities and use cases of Batfish. Point your browser to http://localhost:8888, and in the Password or token: prompt, enter the token that Jupyter showed when you ran the container (e.g. token=abcdef123456...).

Jupyter will show you the list of available notebooks. "Getting Started with Batfish" is a good one to start with. This README explains what each notebook does.

3. Install Pybatfish

To analyze your network configurations, you also need Pybatfish, a Python 3 SDK to interact with the Batfish service. Though not strictly necessary, we recommend that you install Pybatfish in a virtual environment.

To install Pybatfish run the following commands (in a virtual environment if applicable):

python3 -m pip install --upgrade pybatfish

4. Develop your analysis

After installing Pybatfish, use your Python environment of choice (e.g., PyCharm, interactive Python shell, Jupyter, ..) to interact with Batfish. The notebooks provide examples of such scripts.

See complete documentation of Pybatfish on readthedocs.

System Requirements for running Batfish

Batfish can be run on any operating system that supports Docker. The containers are actively tested on Mac OS X and Ubuntu 16.04 LTS.

To get started with the example Jupyter notebooks, all you need is a reasonably capable laptop:

  • Dual core CPU
  • 8 GB RAM
  • 256 GB hard-drive

When you transition to running Batfish on your own network, we recommend a server that at least has:

  • Quad-core CPU with 2 threads per CPU
  • 32 GB RAM
  • 256 GB hard-drive

Supported Network Device and Operating System List

Batfish supports configurations for a large and growing set of (physical and virtual) devices, including:

  • A10 Networks
  • Arista
  • AWS (VPCs, Network ACLs, VPN GW, NAT GW, Internet GW, Security Groups, etc…)
  • Cisco (All Cisco NX-OS, IOS, IOS-XE, IOS-XR and ASA devices)
  • Check Point
  • Cumulus
  • F5 BIG-IP
  • Fortinet
  • Free-Range Routing (FRR)
  • iptables (on hosts)
  • Juniper (All JunOS platforms: MX, EX, QFX, SRX, T-series, PTX)
  • Palo Alto Networks
  • SONiC

Batfish has limited support for the following platforms:

  • Aruba
  • Dell Force10
  • Foundry

If you'd like support for additional vendors or currently-unsupported configuration features, let us know via Slack or GitHub. We'll try to add support. Or, you can — we welcome pull requests! :)

License and Dependencies

Batfish is released under The Apache Software License, Version 2.0. All third-party dependencies are compatible with this licensing.

batfish's People

Contributors

adrianliaw avatar agember avatar anothermattbrown avatar arifogel avatar corinaminer avatar dhalperi avatar dspicuzzbbn avatar erikljungman avatar github-actions[bot] avatar haverma avatar jeffkala avatar jkhourybbn avatar kidsbear avatar kylehoferamzn avatar millstein avatar mkremerbbn avatar nickgian avatar nunoplopes avatar pranavbj-amzn avatar progwriter avatar rabeckett avatar ratulm avatar raveranj avatar saparikh avatar sfraint avatar slarkworthy avatar vasu018 avatar virtuald avatar yifeiyuan avatar zergling-aws avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

batfish's Issues

Unimplemented BDP feature (NamesAsPathSet?)

Status: FAILURE
Question: null
{
"class" : "org.batfish.common.BatfishException$BatfishStackTrace",
"contents" : [
"org.batfish.common.BatfishException: Batfish job failed",
" at org.batfish.main.Driver$1.run(Driver.java:302)",
"Caused by: org.batfish.common.BatfishException: unimplemented",
" at org.batfish.datamodel.routing_policy.expr.NamedAsPathSet.matches(NamedAsPathSet.java:31)",
" at org.batfish.datamodel.routing_policy.expr.MatchAsPath.evaluate(MatchAsPath.java:27)",
" at org.batfish.datamodel.routing_policy.statement.If.execute(If.java:35)",
" at org.batfish.datamodel.routing_policy.RoutingPolicy.call(RoutingPolicy.java:38)",
" at org.batfish.datamodel.routing_policy.RoutingPolicy.process(RoutingPolicy.java:78)",
" at org.batfish.bdp.Node.propagateBgpRoutes(Node.java:801)",
" at org.batfish.bdp.BdpDataPlanePlugin.lambda$computeFixedPoint$15(BdpDataPlanePlugin.java:369)",
" at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)",
" at java.util.TreeMap$ValueSpliterator.forEachRemaining(TreeMap.java:2893)",
" at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)",
" at java.util.stream.ForEachOps$ForEachTask.compute(ForEachOps.java:291)",
" at java.util.concurrent.CountedCompleter.exec(CountedCompleter.java:731)",
" at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)",
" at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)",
" at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)",
" at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)"
]
}

implement additional-paths

bgp additional-paths select all
bgp additional-paths send receive
neighbor xxx advertise additional-paths all

System does not complain when specifying a non-existing interface in bf_init_environment

And then it crashes when running a query. Ideally, checks should be done during both environment creation and when a non-existing interface in encountered during analysis.

The following exception occurs when running reduced reachability query after creating an environment with non-existing interface

org.batfish.common.BatfishException: Batfish job failed
at org.batfish.main.Driver$1.run(Driver.java:388)
Caused by: java.lang.NullPointerException
at org.batfish.main.Batfish.processInterfaceBlacklist(Batfish.java:3456)
at org.batfish.main.Batfish.loadConfigurations(Batfish.java:2452)
at org.batfish.bdp.BdpDataPlanePlugin.computeDataPlane(BdpDataPlanePlugin.java:259)
at org.batfish.main.Batfish.computeDataPlane(Batfish.java:853)
at org.batfish.main.Batfish.initQuestionEnvironment(Batfish.java:2170)
at org.batfish.main.Batfish.initQuestionEnvironments(Batfish.java:2183)
at org.batfish.main.Batfish.answer(Batfish.java:493)
at org.batfish.main.Batfish.run(Batfish.java:3858)
at org.batfish.main.Driver$1.run(Driver.java:356)

include routing tables with testrig

Provide standard way to include per-node routing tables with testrig. These should be usable for route validation as well as external bgp announcement inference.

add testing to travis and probably also ant

if we add test to the arguments to batfish_build_all.sh it will run the test target in every ant build.xml. This will make sure the unit tests that exist (if any) will run.

We'll need to add the test ant target everywhere.

parsing post-processing fails with neighbor activate peer-group before definition

On Cisco, a peer-group must be defined before it can be activated. Batfish currently enforces this.
On Arista, activating a non-existent peer-group creates that peer-group. Batfish should detect configuration format and behave accordingly.
Furthermore, activating a non-existent peer-group on Cisco should generate a warning rather than failure.

Legal on Arista / illegal on Cisco:

router bgp 1
 address-family ipv4
  neighbor UNDEFINED_PEER_GROUP activate

add caching to Synthesizer for efficiency

When executing a query, batfish.standard() creates many NOD jobs (one per ingress), each of which ends up completely regenerating the NOD program even though the program is identical. So in the example rig, we are generating the program 15 times (instead of one)

One way to mitigate this is to add caching to the z3.Synthesizer to reuse the same statements and program -- since all the jobs are using the same synthesizer instance

Ability to grab config files for a specific testrig.

Current js client relies on the underlying structure of the batfish directory to get the text of each config file. An API call to coordinator currently exists to get a list of all config files for a given testrig, but not the file text. It would be beneficial to have a filetext element in the answer of that API call.

Audit use of Streams especially as regards files

We've got some fairly big file descriptor leaks due to use of various Stream<Path> APIs rooted in Files. We need to audit the codebase for cleaning this up.

A sample fix:

@@ -780,9 +783,13 @@ public class Batfish extends PluginConsumer implements AutoCloseable, IBatfish {
          throw new CleanBatfishException(
                "Missing compiled vendor-independent configurations for this test-rig\n");
       }
-      else if (CommonUtil.list(path).count() == 0) {
-         throw new CleanBatfishException(
-               "Nothing to do: Set of vendor-independent configurations for this test-rig is empty\n");
+      else {
+         try (Stream<Path> paths = CommonUtil.list(path)) {
+            if (paths.count() == 0) {
+               throw new CleanBatfishException(
+                     "Nothing to do: Set of vendor-independent configurations for this test-rig is empty\n");
+            }
+         }
       }
    }
 

[Geeze I hope there's a more concise way to do this.]

Fix documentation for testing

Run tests from the root of the batfish repository
allinone -cmdfile tests/java/commands

There are different command files
./demos/java/commands
./test_rigs/parsing-tests/commands
./tests/basic/commands
./tests/ui-focused/commands

Record setting of 'spanning-tree portfast'

Record instances of spanning-tree portfast at interface-level and top-level.
On Arista, this must be configured per-interface.
On Cisco, the default can be configured at top-level.

Fix ant->maven antlr4 build regressions

  • Change to an imported grammar file should trigger regeneration of grammar importing it
    Currently, only master parser/lexer grammar changes trigger a rebuild. Fixing this is HIGHEST priority

  • .tokens files should only be generated in target
    The .tokens files are now being generated in the src/main/antlr4/... directories. These should ideally not be produced in a src folder.

  • Only recompile relevant java files when grammars are regenerated
    After any MASTER grammar file is changed, it appears that ALL java files are recompiled - rather than just the ones that have changed (or rely on ones that have changed). While this will certainly work, it seems heavy-handed. Please see behavior of old ant build.xml for a lighter-weight method.

  • Parallel processing of grammars
    Grammars are currently processed one at a time. When we used ant, all out-of-date lexers were generated in parallel, and then all out-of-date parsers were generated in parallel. While we could replicate this behavior, I'd like to do better:
    Each grammar should be its own task. Each parser task should depend on its corresponding lexer task. All such tasks should be executed in parallel to the extent feasible.

Make batfish systemd unit depend on coordinator systemd unit

In the RPM/DEB building scripts, we install batfish and the batfish coordinator as system services. Right now they are not linked, so we have to restart each service independently.

It would be good to link them, so that we can restart a single service and have them all restart.

Rethink question preprocessing

Right now the logic in Batfish#preprocessQuestion is complicated/brittle and also incomplete (specifically for the case of CompositeQuestion, which might have question-valued variables). We'd like to rewrite this code to be simpler, better tested, and potentially more powerful.

Specifically,

  • add comprehensive tests.
  • support composite question with question-valued variables.
  • consider adding much more functionality than simple variable replacement like we have now.

new example test rigs base on c7200

After fixing BGP in BDP, the example testrig does not actually perform as indicated. A new example testrig called example2 has been added. It uses bgp additional-path to recover the expected BGP multipath behavior in presence of route-reflectors. This should supplant the original example testrig. Depends on #133

automatically trigger testrig parsing when a question is asked

automatically trigger parsing a testrig when a question is asked, if the testrig hasn't already been parsed? (like we do for data plane generation.)

with asynch clients, there may be testrigs that have not been parsed (e.g., because the client was killed right after the upload happened). then, we ask question of this testrig, we currently get:
FATAL ERROR: Missing compiled vendor-independent configurations for this test-rig)

we can do more complicated logic, e.g., the UI checks readiness before issuing the command to answer, but that seems unnecessary front end complexity if the backend can handle things.

AS-path loops

It looks like BGP receivers in Batfish detect AS-path loops only by looking for their AS number in the first position of the AS-path. That would allow for loopy AS-paths such as A-X-Y-A-Z. In reality, such paths will not be allowed.

infrastructure for 'analysis'

Implement infrastructure for creating, manipulating, and answering an analysis, which is a collection of questions.

Helpful error message when delta testrig is not set

If a differential question is asked when the delta testrig is not set, we get the following error message. A more direct message pointing out the problem will be more helpful.

org.batfish.common.BatfishException: Batfish job failed
at org.batfish.main.Driver$1.run(Driver.java:366)
Caused by: java.lang.NullPointerException
at java.nio.file.Files.provider(Files.java:97)
at java.nio.file.Files.exists(Files.java:2385)
at org.batfish.main.Batfish.checkBaseDirExists(Batfish.java:662)
at org.batfish.main.Batfish.environmentExists(Batfish.java:1211)
at org.batfish.main.Batfish.initQuestionEnvironment(Batfish.java:1969)
at org.batfish.main.Batfish.initQuestionEnvironments(Batfish.java:1988)
at org.batfish.main.Batfish.answer(Batfish.java:425)
at org.batfish.main.Batfish.run(Batfish.java:3340)
at org.batfish.main.Driver$1.run(Driver.java:333)

Create an uber-jar for z3 native libraries

Right now, a pain point for Batfish setup is installing z3. It would be better if we could simply produce an uber-jar that contains native libraries for major platforms and let users just use that jar.

This would reduce developer requirements for main batfish to just JDK.

rearrange grammar files into natural directory structure

Currently the master grammar files are in projects/batfish/src/main/antlr4/org/batfish/grammar/(name)/(name){Parser,Lexer}.g4.
The imported (subordinate) grammars are all bunched together in projects/batfish/src/main/antlr4/imports/(subordinate_grammar_file).g4.
Ideally each imported grammar would reside in the same directory as the master grammar that imports it.

Eliminate overlapping classes from dependencies

Current maven build spews warnings about overlapping classes. For each such class, we should choose a representative jar and exclude those classes from all other jars. This should eliminate the warnings.

Unify environment creation APIs, add validation/finalization

Currently environment creation can be done one of two ways, neither of which is fully featured:

  1. Upload a whole directory as a new environment, which coordinator plops down without doing any validation.
  2. Submit the name of a base testrig/environment, and submit node/interface/edge blacklists. Batfish receives these and creates a delta environment off of the base environment for the same testrig. Then it creates blacklist files and writes them to the environment, potentially overwriting any existing blacklists.

In case 1, we are unable to supply base information. In case 2, we are unable to provide all of the things an environment might contain, e.g. changed configs, dumped routes, dumped bgp advertisements.

We should unify these 2 into a two step process with 1 environment-related API call to coordinator, and 1 new batfish command.
The coordinator API call should accept a base testrig and an environment zip. The base environment would be optional. Blacklists, etc. should be packaged in the zip before coordinator receives them.
We should add a new batfish command to validate and finalize an environment. Clients should call this command after initializing a new environment via coordinator before using the new environment.
Environment validation will initially consist of:

  • checking blacklists for references to non-existent nodes/interfaces/edges
  • processing provided routing and bgp tables
  • processing provided changed configs
  • providing pass/fail answer (strictness wrt parsing should be configurable)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.