講義の演習手順とコピー可能なコマンドは、docs/README.mdを参照してください。
- Windows 10 または Windows 11
- WSL2 (Windows Subsystem for Linux 2)
- Ubuntu 24.04 LTS (WSL2)
- Docker Desktop for Windows
WSL2を起動し、講義用の workspace を作成して、その直下に
zenoh-tutorial と hakoniwa-business-pack を配置します。
mkdir -p workspace
cd workspace
git clone --recursive https://github.com/tmori/zenoh-tutorial.git
git clone https://github.com/hakoniwalab/hakoniwa-business-pack.git
cd zenoh-tutorialworkspace/
├── zenoh-tutorial/
└── hakoniwa-business-pack/
通常のZenoh演習では hakoniwa-business-pack を使用しません。
ブラウザで接続Topologyを確認するオプション演習で使用します。
docker compose up -d
講義参加者向けの既定構成は linux/amd64 のままです。Apple Silicon Macで
ローカル確認を行う場合は、arm64用のComposeオーバーライドを追加して起動します。
docker compose --parallel 1 -f docker-compose.yml -f docker-compose.mac.yml up -d --build
--parallel 1 は、Docker Desktopで node_r を2つのネットワークへ確実に接続するため、コンテナを直列に作成する指定です。
停止する場合も同じComposeファイルを指定します。
docker compose -f docker-compose.yml -f docker-compose.mac.yml down
成功すると、以下のメッセージが表示されます。
[+] Running 8/8
✔ zenoh-tutorial-node_a Built 0.0s
✔ zenoh-tutorial-node_b Built 0.0s
✔ zenoh-tutorial-node_c Built 0.0s
✔ Network zenoh-tutorial_local_net_1 Created 0.2s
✔ Network zenoh-tutorial_local_net_2 Created 0.0s
✔ Container node_c Started 0.3s
✔ Container node_b Started 0.4s
✔ Container node_a Started
また、以下のようにコンテナが起動されていることを確認できます。
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
node_a zenoh-tutorial-node_a "sh -c '\n for i in …" node_a 50 minutes ago Up 50 minutes (unhealthy) 7447/tcp, 8000/tcp
node_b zenoh-tutorial-node_b "sh -c '\n for i in …" node_b 50 minutes ago Up 50 minutes (unhealthy) 7447/tcp, 8000/tcp
node_c zenoh-tutorial-node_c "sh -c '\n for i in …" node_c 50 minutes ago Up 50 minutes (unhealthy) 7447/tcp, 8000/tcp
node_r alpine:3.20 "sh -c '\n apk add -…" node_r 50 minutes ago Up 50 minutes (healthy)
起動しているコンテナに接続するには、以下のコマンドを実行します。
docker exec -it <コンテナ名> /bin/bash
例:node_a コンテナに接続する場合
docker exec -it node_a /bin/bash
docker compose down
docker compose down --rmi all
Zenoh-c をインストールするには、以下の手順を実行します。
cd /root/workspace/zenoh-c
cmake -S . -B build \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/root/workspace/zenoh-c-install \
-DBUILD_SHARED_LIBS=ON \
-DZENOHC_BUILD_WITH_UNSTABLE_API=ON \
-DZENOHC_BUILD_WITH_SHARED_MEMORY=OFF \
-DZENOHC_BUILD_IN_SOURCE_TREE=ON
cmake --build build --config Release
cmake --install build --config Release
この設定では、通常のサンプルとTopology Viewer用FoundationでRustのビルド成果物を 共有できます。通常のサンプルは安定APIだけを使用します。
cd sample/c-sample
bash build.bash
Zenohd を起動します。
RUST_LOG=trace zenohd -c sample/c-sample/config.json
Zenoh のsubscriber サンプルを実行します。
./cmake-build/sub --mode client -e udp/127.0.0.1:7448
Zenoh のpublisher サンプルを実行します。
./cmake-build/pub --mode client -e udp/127.0.0.1:7448
Zenohの動作モードを指定します。
- peer: ピアツーピアモード。すべてのノードが対等で、データの中継も行う
- client: クライアントモード。データの送受信のみ、中継は行わない
- router: ルーターモード。主にデータ中継とルーティングを担当
"listen": {
"endpoints": ["udp/0.0.0.0:7448"]
}- 役割: このノードが接続を受け入れるアドレスとポート
- 0.0.0.0: すべてのネットワークインターフェースで待受け
- 7448: 使用するポート番号
- udp: UDP プロトコルを使用
"connect": {
"endpoints": ["udp/192.168.1.100:7448"]
}- 役割: 接続先を明示的に指定
- 自動検出を使う場合は不要
"scouting": {
"multicast": {
"address": "224.0.0.225:7449",
"interface": "auto",
"ttl": 1
}
}- マルチキャストアドレス: ピア発見用の共有アドレス
- 224.0.0.0-239.255.255.255: IPv4マルチキャスト範囲
- 224.0.0.225: 選択したマルチキャストアドレス
- 7449: 発見用ポート(データ通信用の7448と分離)
- auto: システムが最適なネットワークインターフェースを自動選択
- eth0, wlan0など: 特定のインターフェースを指定可能
TTL (Time To Live) の説明:
- 意味: パケットがネットワーク上で生存できるホップ数
- 1: 同一ネットワークセグメント内のみ(ルーターを超えない)
- 2以上: 複数のルーターを経由可能
TTL値の使い分け:
ttl: 1 → 同じLAN内のピアのみ発見
ttl: 2 → 1つのルーターを超えて発見
ttl: 32 → より広いネットワーク範囲で発見
"gossip": {
"multihop": false
}- gossip: ピア間での情報拡散プロトコル
- multihop: 複数ホップでの情報伝播を許可するか
- false: 直接接続されたピアとのみ情報交換
- 起動: UDP 7448でリッスン開始
- 発見: マルチキャスト 224.0.0.225:7449 で「私はここにいます」を送信
- 応答: 他のピアが同じマルチキャストアドレスで応答
- 接続: 発見されたピア同士がUDP 7448で直接通信開始
- データ交換: Zenohメッセージの送受信
- 自動発見: 手動でIPアドレスを設定不要
- 動的接続: ノードの追加・削除が容易
- ネットワーク効率: ブロードキャストより効率的
- ファイアウォール: UDP 7448, 7449ポートの開放が必要
- マルチキャスト対応: ネットワーク機器がマルチキャストをサポートしている必要
- TTL設定: ネットワーク構成に応じた適切な値の設定
echo "deb [trusted=yes] https://download.eclipse.org/zenoh/debian-repo/ /" | sudo tee -a /etc/apt/sources.list.d/zenoh.list > /dev/null
sudo apt update
sudo apt install zenoh
Topology visualization is an opt-in exercise. The normal build, ./pub,
./sub, and the default docker-compose.yml do not require Hakoniwa Business
Pack. The observer is attached only when both the optional build and the
-A <name> (or --topology-agent <name>) runtime option is selected.
This section assumes the host workspace layout shown above. Run Compose from
workspace/zenoh-tutorial; the sibling workspace/hakoniwa-business-pack
directory is mounted into the tutorial containers.
Start the tutorial containers with the optional overlay (add
-f docker-compose.mac.yml on Apple Silicon):
docker compose -f docker-compose.yml -f docker-compose.viewer.yml up -d --buildIn node_a, let Business Pack build and install the optional, core-free
dependency graph, then build the tutorial samples against that install:
docker compose exec node_a bash
cd /root/workspace/hakoniwa-business-pack
python3 tools/recipe.py doctor --recipe recipes/examples/zenoh-tutorial-topology-viewer.yaml
python3 tools/recipe.py plan --recipe recipes/examples/zenoh-tutorial-topology-viewer.yaml
python3 tools/recipe.py configure --recipe recipes/examples/zenoh-tutorial-topology-viewer.yaml
cd /root/workspace/zenoh-tutorial/sample/c-sample
./build-viewer.bashStart the Viewer from node_a in one terminal. This uses Launcher
activate-only; Hakoniwa Core and hako-cmd are not involved.
cd /root/workspace/hakoniwa-business-pack
python3 tools/recipe.py launch --recipe recipes/examples/zenoh-tutorial-topology-viewer.yamlStart the subscriber in another node_a terminal and the publisher in a
node_b terminal:
# node_a
cd /root/workspace/zenoh-tutorial/sample/c-sample
./cmake-build-viewer/sub -A node_a-sub -c config-multicast.json
# node_b
cd /root/workspace/zenoh-tutorial/sample/c-sample
./cmake-build-viewer/pub -A node_b-pub -c config-multicast.jsonOpen http://localhost:5173. The tutorial data continues to flow directly between the two Zenoh peers while their process-local agents send topology snapshots to the single Aggregator multiplexer port.
The Viewer does not require a separate Zenoh configuration. For later
exercises, keep each exercise's existing -c file and other options, switch
the executable from cmake-build to cmake-build-viewer, and add
-A <display-name>.
Agents are registered dynamically, including an Agent started in node_c.
See docs/06-viewer-setup.md for the complete
lecture procedure and shutdown steps.