Batfish runs as a service that can be accessed via RESTful APIs. A Python client comes bundled with the suggested allinone Docker container or can be set up separately.
- Java 11 JDK
- git
- bazelisk
We provide OS-specific advice below.
Ubuntu
: Read Ubuntu notes firstmacOS
: Read macOS notes first
Do the following before doing anything
-
Install XCode command-line tools.
xcode-select --install
-
Install Homebrew. Follow these steps.
-
Open a fresh terminal to ensure the utilities are correctly picked up.
-
If you don't already have the Java 11 JDK installed, first install homebrew cask and then Java 11 using the following commands.
brew tap homebrew/cask-versions
brew install --cask temurin11
-
If you don't already have it, install Bazelisk.
brew install bazelisk
Do the following before doing anything
-
Install Java 11 and corresponding debug symbols
sudo apt install openjdk-11-jdk openjdk-11-dbg
-
If you don't already have it, install
wget
:sudo apt-get install wget
-
If you don't already have it, install Bazelisk.
-
Open the bazelisk release page
-
Copy the link for the
bazelisk-linux-amd64
release asset for the latest version -
Download and install bazelisk using the copied link (example url below is for
v1.12.2
, but you should use the latest version):wget -O- https://github.com/bazelbuild/bazelisk/releases/download/v1.12.2/bazelisk-linux-amd64 | sudo tee /usr/local/bin/bazelisk > /dev/null
-
Make bazelisk executable:
sudo chmod +x /usr/local/bin/bazelisk
-
Symlink bazel to bazelisk:
sudo ln -s bazelisk /usr/local/bin/bazel
-
If you have multiple versions of Java installed on your machine, the default java
/javac
commands may still not be
using JVM 11. In that case, you can force the version of Java in use by setting JAVA_HOME
. @dhalperi has these aliases
in his .zshrc
to control which Java is running in a given shell on macOS:
# Java options
# j8q switches to Java 8, quietly. Could make a loud version that runs `java -version` after.
function j8q() {
export JAVA_HOME=`/usr/libexec/java_home -v 1.8`
}
function j11q() {
export JAVA_HOME=`/usr/libexec/java_home -v 11`
}
# Default to Java 11.
j11q
- Check out the Batfish code
git clone https://github.com/batfish/batfish.git
cd batfish
- To build any unbuilt changes and run the Batfish service:
tools/bazel_run.sh
-
(Optional, done automatically in next step) Compile Batfish
-
bazel build //projects/allinone:allinone_main
-
-
Run the Batfish service
-
will start Batfish in service mode using the library of questions within the Batfish repository.
bazel run //projects/allinone:allinone_main -- -runclient false -coordinatorargs "-templatedirs $(git rev-parse --show-toplevel)/questions -containerslocation $(git rev-parse --show-toplevel)/containers"
Data stored by the service to analyze a network will be stored in a
containers
folder.If you wish to provide Java arguments, use the
--jvmopt
option once for each java argument in betweenrun
and//projects/allinone:allinone_main
:To set the RAM:
bazel run --jvmopt=-Xmx2g //projects/allinone:allinone_main -- -runclient false -coordinatorargs "-templatedirs $(git rev-parse --show-toplevel)/questions -containerslocation $(git rev-parse --show-toplevel)/containers"
To turn on assertions and enable a debugger to attach:
bazel run --jvmopt=-ea --jvmopt=-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5009 //projects/allinone:allinone_main -- -runclient false -coordinatorargs "-templatedirs $(git rev-parse --show-toplevel)/questions -containerslocation $(git rev-parse --show-toplevel)/containers"
For more info, see the Bazel documentation.
-
-
Explore using Pybatfish
Once the service is running, you can use Pybatfish to analyze your network.
You can run all tests in this repository by running:
bazel test //...
The above is a specific instance of the general form for running all tests in all Bazel packages
in a subtree. The above uses the entire repository //
as the root; to test only the coordinator
:
bazel test //projects/coordinator/...
To run a specific test, just use its Bazel target:
bazel test //projects/batfish:pmd
You can also combine multiple test target expressions:
bazel test //projects/coordinator/... //projects/batfish:pmd
If you want to test just a single function of a rule of type junit_test
, do:
bazel test --test_filter=<fully-qualified-class-name>#test-function$ -- <test-target-containing-test-class>
For example, to run just the getNonExistNetwork
test function of the WorkMgrServiceTest
class,
do:
bazel test --test_filter=org.batfish.coordinator.WorkMgrServiceTest#getNonExistNetwork$ -- //projects/coordinator:coordinator_tests
We use Bazel's rules_jvm_external
to manage our Java dependencies
from Maven. Refer to that
project's documentation
to understand how it works, how Maven dependencies are versioned and captured in maven_install.json
, and
other information.
Commonly, some Java library will have a CVE and we will want to upgrade our dependence on it. While the true reference
for upgrading should be
the rules_jvm_external
instructions on re-pinning,
here is a summary of the steps involved:
- Edit
library_deps.bzl
to update the version of the library used to a non-vulnerable release. - Run
bazel run @unpinned_maven//:pin
to re-generatemaven_install.json
. - Manually review the changes (e.g., with
git diff
) to ensure all needed upgrades are achieved. - Run all the tests (e.g.,
bazel test //...
) to ensure that Batfish still builds and the tests still pass. - Submit a PR to this repository as usual.
- Use the batfish image if you just want the batfish service.
- Use the allinone image if you want the batfish service and a built-in jupyter notebook server.
This section of the doc is still in progress. Check back later!
This section of the doc is still in progress. Check back later!