Skip to content

Batfish

batfish でレイヤー 1 トポロジーを定義する

Batfish は計算処理を行う際、「同じネットワーク (アドレス範囲) に所属していれば、インターフェイスが隣接している」と判定します。

file

しかし、例えば「同じアドレス帯を再利用している」「リンクローカルアドレスを利用している」というケースは「同じアドレスが・異なる箇所で複数回、利用される」ことは十分、有り得ます。 こういった場合は Batfish の Layer-1 topology 機能を利用することが出来ます。 この機能は公式サイトで以下のように説明されています。

Batfish can infer Layer-3 interface adjacencies based on IP address configuration on interfaces. For instance, if there are two interfaces in the network with IP assignments 192.168.1.1/24 and 192.128.1.2/24, Batfish will infer that these interfaces are adjacent.

Such inference does not work if the network re-uses IP address space or has link-local addresses. In those situations, you must provide a Layer-1 topology file that has cabling information. Then, Layer-3 adjacencies will be computed by combining the supplied Layer-1 adjacencies with Layer-2 and Layer-3 configuration to get a more accurate model.

The expected Layer-1 topology file is a JSON file that has a list of edge records, where each edge record has node and interface names of the two ends. See this file for an example.

The name of your Layer-1 topology file must be layer1_topology.json and it must be placed in a folder called batfish right below the top-level snapshot folder.

annotation で Batfish が処理出来なかった部分を把握する

Configuration file annotation によると Batfish は読み込んだコンフィグのうち、理解出来ないものは以下の 3 種類に分類するそうです。

  1. Batfish does not understand the content of the line (unrecognized syntax)
  2. Batfish does not support the feature mentioned in the line
  3. Batfish deems that the line is irrelevant to its network model

「実際に Batfish がコンフィグをどのように処理したか?」は annotation を使うことで確認することが出来ます。 確認結果は以下の 3 パターンに分類されるそうです。

  1. UNRECOGNIZED SYNTAX
  2. PARTIALLY UNSUPPORTED
  3. SILENTLY IGNORED

今回は実際に annotation の動作を試してみます。

batfish でダミーホストを利用する

batfish でルーティングや ACL のテストを実施する際、ルータやファイアウォールとは別にダミーのホストを利用したい場合があります。 こういった場合は .json ファイルを用意することで簡単にダミーホストを用意出来ます。 Modeling hosts に .json ファイルのフォーマットが書かれています。

pybatfish で対象コンフィグが更新されている場合のみ、スナップショットを再作成する

batfish に同梱されているサンプルスクリプトや、インターネット上で見かけるスクリプト例は「スナップショットの有無に関わらず、スナップショットを生成する」ものが多いと思います ("例" なので、そういうものなのだと思います)。 仮に何度もスクリプトを実行し直す場合は、「コンフィグに変化が無いのであれば、毎回のスナップショット再作成は不要」という場合もあると思います。 そういった場合の実装例をメモしておきます。

例として Question には ipOwners を利用していますが、どの Question を利用してもスナップショット初期化部分の考え方は同じです。

allinone では無い batfish イメージを起動する

以前に Batfish をインストールしてコンフィグを分析する というメモを書きました。 このメモでは Jupyter Notebook と batfish が同梱された allinone イメージ を利用する手順をメモしていました。 ですが、CLI から batfish を利用するのであれば Jupyter Notebook を含まない batfish だけのイメージ を利用する方が軽量です。

Batfish をインストールしてコンフィグを分析する

Batfish を Linux にインストールする手順をメモしておきます。 公式のインストール手順は Getting Started with Batfish にあります。 今回は Ubuntu 21.0.4 へインストールしました。 Batfish は Docker イメージで起動する為、Ubuntu21 に docker / docker-compose をインストールする などを参考に docker をインストールしておきます。

尚、Jupyter Notebook を含む batfish/allinone Docker イメージの起動手順もメモしておきますが、今回のメモでは Jupyter Notebook は利用しません (その為、batfish/allinone イメージを使う必要はありません)。