Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
395 changes: 305 additions & 90 deletions docs/designs/container_bundle.md

Large diffs are not rendered by default.

331 changes: 331 additions & 0 deletions docs/designs/eth_explorer.md

Large diffs are not rendered by default.

95 changes: 95 additions & 0 deletions docs/designs/internet_map.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# InternetMap design

`seedemu.containerBundle.InternetMap` extends `ContainerBundle` to provide
an emulator API, topology UI, geographic UI, and traffic observer. See the
[ContainerBundle design](container_bundle.md) for shared lifecycle behavior.

## Services and construction

| Logical service name | Role | Network behavior |
| --- | --- | --- |
| `seedemu_emulator_service_backend` | REST and WebSocket APIs | Bundle network; optionally emulator network |
| `seedemu_internet_map_toplogy` | Topology frontend | Bundle network |
| `seedemu_internet_map_geographic` | Geographic frontend | Bundle network and `host.docker.internal` mapping |
| `seedemu_traffic_observer_service_backend` | Host traffic capture | `network_mode: host` |

The constructor accepts `emulator` and `suffix="map.seed"`. It creates four
prepared containers, sets `_default_external_network = DEFAULT_NETWORK`,
requires three host ports, and requests one emulator-network address. Internal
network access starts disabled; construction does not allocate an address.

Registration keys, Compose service keys, container names, hostnames, and build
folders use the logical name plus the suffix. Use distinct suffixes, external
networks, subnets, and host ports for separate instances.

## Optional internal network

Call `enableInternalNetwork()` before compilation to enable emulator access:

```python
internet_map = InternetMap(emu, ".map.seed")
internet_map.enableInternalNetwork()
internet_map.setPorts([8081, 8082, 8083])
docker.addContainerBundle(internet_map)
```

This method sets a flag and returns the bundle. During `configure()`, only the
API backend joins the internal network. If no manual internal network has
been supplied, `allocateEmuNetworkAddress()` reserves one address on a rendered
host network, starting at network-address offset 10. It skips occupied and
reserved addresses and the gateway. The selected `ip_addresses[0]` and
`default_route` are passed explicitly to `joinInternalNetwork()`, together
with the backend's own hostname. A usable network with enough capacity is
required when this option is enabled.

To choose the internal attachment explicitly before compilation:

```python
internet_map.setDefaultInternalNetwork(
name="net_150_net0",
ip_addresses=["10.150.0.10"],
default_route="10.150.0.254",
)
internet_map.enableInternalNetwork()
```

The manual address must be free; the setter does not reserve or validate it.
When a gateway is supplied, generated startup commands replace the backend's
Docker default route. Its build context is enabled for this startup setup.
Both frontends continue to reach the API through the external bundle network.

## Configuration and compilation

`configure()` performs these steps:

1. Calls the base port validation using the constructor's requirement of three
ports. The observer consumes the last supplied port, the topology frontend
the next, and the geographic frontend the next. The API uses internal port
`7071` without a host-published port.
2. Configures the observer with host networking, privileged mode, host PID,
kernel/BPF mounts, and the Docker socket. It skips bridge attachment.
3. Attaches the API and both frontends to the external bundle network with
static addresses in container creation order.
4. Configures the API image, Docker socket, and production environment, and
attaches its optional internal network.
5. Configures frontend dependencies using the suffixed backend service key.
Both Nginx upstreams target the API's external-network static IP on `7071`.
The geographic proxy also targets the configured traffic-observer endpoint.
6. Stages Nginx configuration and `/etc/hosts` mappings for both frontends.
Their configured startup script path is `/entrypoint.sh`; shared
`PreparedContainer` installation handles startup wrapping and staged files.

The external network can be overridden before compilation:

```python
internet_map.setDefaultExternalNetwork(
name="internetMap_network",
prefix="172.30.0.0/24",
ip_addresses=[f"172.30.0.{i}" for i in range(10, 14)],
default_router="172.30.0.1",
)
```

The address list must cover all four prepared containers, although the
observer's entry remains unused because it uses host networking. The compiler
calls `configure()` and `install()` to generate build contexts and Compose YAML.
15 changes: 13 additions & 2 deletions examples/basic/A00_simple_as/simple_as.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from seedemu.core import Binding, Emulator, Filter
from seedemu.layers import Base, Ebgp, Routing
from seedemu.services import WebService
from seedemu.containerBundle import InternetMap


def parse_args() -> argparse.Namespace:
Expand Down Expand Up @@ -87,7 +88,17 @@ def run(

output_dir = Path(output or SCRIPT_DIR / "output").resolve()
output_dir.parent.mkdir(parents=True, exist_ok=True)
emu.compile(Docker(platform=platform), str(output_dir), override=override)
docker = Docker(platform=platform)

# Add Internet visualization services: topology, geographic map, and traffic observation.
# The second argument is a container name suffix that distinguishes bundle instances.
internet_map_bundle = InternetMap(emu, ".map.seed")
# Provide a host port pool (range excludes the stop value); InternetMap needs at least 3 ports.
internet_map_bundle.setPorts(list(range(8081, 8089)))
# Register the bundle with the Docker compiler to generate its containers during emu.compile().
docker.addContainerBundle(internet_map_bundle)

emu.compile(docker, str(output_dir), override=override)


def main() -> int:
Expand All @@ -103,4 +114,4 @@ def main() -> int:


if __name__ == "__main__":
raise SystemExit(main())
raise SystemExit(main())
9 changes: 8 additions & 1 deletion examples/basic/A01_transit_as/transit_as.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,13 @@ def run(
###############################################################################
# Final step: Generate the docker files
docker = Docker(internetMapEnabled=True, platform=platform)
# Add Internet visualization services: topology, geographic map, and traffic observation.
# The second argument is a container name suffix that distinguishes bundle instances.
internet_map_bundle = InternetMap(emu, ".map.seed")
# Provide a host port pool (range excludes the stop value); InternetMap needs at least 3 ports.
internet_map_bundle.setPorts(list(range(8081, 8089)))
# Register the bundle with the Docker compiler to generate its containers during emu.compile().
docker.addContainerBundle(internet_map_bundle)
emu.compile(docker, output or './output', override=override)


Expand All @@ -150,4 +157,4 @@ def main() -> int:


if __name__ == "__main__":
raise SystemExit(main())
raise SystemExit(main())
11 changes: 10 additions & 1 deletion examples/basic/A02a_transit_as_mpls/transit_as_mpls.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from seedemu.core import Binding, Emulator, Filter
from seedemu.layers import Base, Ebgp, Ibgp, Mpls, Ospf, PeerRelationship, Routing
from seedemu.services import WebService
from seedemu.containerBundle import InternetMap


def parse_args() -> argparse.Namespace:
Expand Down Expand Up @@ -130,7 +131,15 @@ def run(
# Generate the Docker files.
output_dir = Path(output or SCRIPT_DIR / "output").resolve()
output_dir.parent.mkdir(parents=True, exist_ok=True)
emu.compile(Docker(platform=platform), str(output_dir), override=override)
docker = Docker(platform=platform)
# Add Internet visualization services: topology, geographic map, and traffic observation.
# The second argument is a container name suffix that distinguishes bundle instances.
internet_map_bundle = InternetMap(emu, ".map.seed")
# Provide a host port pool (range excludes the stop value); InternetMap needs at least 3 ports.
internet_map_bundle.setPorts(list(range(8081, 8089)))
# Register the bundle with the Docker compiler to generate its containers during emu.compile().
docker.addContainerBundle(internet_map_bundle)
emu.compile(docker, str(output_dir), override=override)


def main() -> int:
Expand Down
13 changes: 11 additions & 2 deletions examples/basic/A02b_manual_mpls/manual_mpls.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from seedemu.core import Binding, Emulator, Filter
from seedemu.layers import Base, Ebgp, Ibgp, Ospf, PeerRelationship, Routing
from seedemu.services import WebService
from seedemu.containerBundle import InternetMap


MANUAL_MPLS = {
Expand Down Expand Up @@ -196,7 +197,15 @@ def run(

output_dir = Path(output or SCRIPT_DIR / "output").resolve()
output_dir.parent.mkdir(parents=True, exist_ok=True)
emu.compile(Docker(platform=platform), str(output_dir), override=override)
docker = Docker(platform=platform)
# Add Internet visualization services: topology, geographic map, and traffic observation.
# The second argument is a container name suffix that distinguishes bundle instances.
internet_map_bundle = InternetMap(emu, ".map.seed")
# Provide a host port pool (range excludes the stop value); InternetMap needs at least 3 ports.
internet_map_bundle.setPorts(list(range(8081, 8089)))
# Register the bundle with the Docker compiler to generate its containers during emu.compile().
docker.addContainerBundle(internet_map_bundle)
emu.compile(docker, str(output_dir), override=override)


def main() -> int:
Expand All @@ -212,4 +221,4 @@ def main() -> int:


if __name__ == "__main__":
raise SystemExit(main())
raise SystemExit(main())
13 changes: 11 additions & 2 deletions examples/basic/A03a_out_to_real_world/out_to_real_world.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from seedemu.core import Binding, Emulator, Filter
from seedemu.layers import Base, Ebgp, Ibgp, Ospf, PeerRelationship, Routing
from seedemu.services import WebService
from seedemu.containerBundle import InternetMap


AKAMAI_ASN = 20940
Expand Down Expand Up @@ -113,7 +114,15 @@ def run(

output_dir = Path(output or SCRIPT_DIR / "output").resolve()
output_dir.parent.mkdir(parents=True, exist_ok=True)
emu.compile(Docker(platform=platform), str(output_dir), override=override)
docker = Docker(platform=platform)
# Add Internet visualization services: topology, geographic map, and traffic observation.
# The second argument is a container name suffix that distinguishes bundle instances.
internet_map_bundle = InternetMap(emu, ".map.seed")
# Provide a host port pool (range excludes the stop value); InternetMap needs at least 3 ports.
internet_map_bundle.setPorts(list(range(8081, 8089)))
# Register the bundle with the Docker compiler to generate its containers during emu.compile().
docker.addContainerBundle(internet_map_bundle)
emu.compile(docker, str(output_dir), override=override)


def main() -> int:
Expand All @@ -130,4 +139,4 @@ def main() -> int:


if __name__ == "__main__":
raise SystemExit(main())
raise SystemExit(main())
13 changes: 11 additions & 2 deletions examples/basic/A03b_from_real_world/from_real_world.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from seedemu.layers import Base, Ebgp, Ibgp, Ospf, PeerRelationship, Routing
from seedemu.raps import OpenVpnRemoteAccessProvider
from seedemu.services import WebService
from seedemu.containerBundle import InternetMap


def parse_args() -> argparse.Namespace:
Expand Down Expand Up @@ -100,7 +101,15 @@ def run(

output_dir = Path(output or SCRIPT_DIR / "output").resolve()
output_dir.parent.mkdir(parents=True, exist_ok=True)
emu.compile(Docker(platform=platform), str(output_dir), override=override)
docker = Docker(platform=platform)
# Add Internet visualization services: topology, geographic map, and traffic observation.
# The second argument is a container name suffix that distinguishes bundle instances.
internet_map_bundle = InternetMap(emu, ".map.seed")
# Provide a host port pool (range excludes the stop value); InternetMap needs at least 3 ports.
internet_map_bundle.setPorts(list(range(8081, 8089)))
# Register the bundle with the Docker compiler to generate its containers during emu.compile().
docker.addContainerBundle(internet_map_bundle)
emu.compile(docker, str(output_dir), override=override)


def main() -> int:
Expand All @@ -116,4 +125,4 @@ def main() -> int:


if __name__ == "__main__":
raise SystemExit(main())
raise SystemExit(main())
11 changes: 10 additions & 1 deletion examples/basic/A04_visualization/visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from seedemu.compiler import Docker, Platform
from examples.basic.A01_transit_as import transit_as
import sys, os
from seedemu.containerBundle import InternetMap

###############################################################################
# Set the platform information
Expand Down Expand Up @@ -55,4 +56,12 @@
# Render and compile

emu.render()
emu.compile(Docker(platform=platform), './output', override=True)
docker = Docker(platform=platform)
# Add Internet visualization services: topology, geographic map, and traffic observation.
# The second argument is a container name suffix that distinguishes bundle instances.
internet_map_bundle = InternetMap(emu, ".map.seed")
# Provide a host port pool (range excludes the stop value); InternetMap needs at least 3 ports.
internet_map_bundle.setPorts(list(range(8081, 8089)))
# Register the bundle with the Docker compiler to generate its containers during emu.compile().
docker.addContainerBundle(internet_map_bundle)
emu.compile(docker, './output', override=True)
13 changes: 11 additions & 2 deletions examples/basic/A05_components/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from seedemu.services import WebService
from seedemu.compiler import Docker, Platform
from examples.basic.A01_transit_as import transit_as
from seedemu.containerBundle import InternetMap


def parse_args() -> argparse.Namespace:
Expand Down Expand Up @@ -116,7 +117,15 @@ def run(

output_dir = Path(output or SCRIPT_DIR / "output").resolve()
output_dir.parent.mkdir(parents=True, exist_ok=True)
emu.compile(Docker(platform=platform), str(output_dir), override=override)
docker = Docker(platform=platform)
# Add Internet visualization services: topology, geographic map, and traffic observation.
# The second argument is a container name suffix that distinguishes bundle instances.
internet_map_bundle = InternetMap(emu, ".map.seed")
# Provide a host port pool (range excludes the stop value); InternetMap needs at least 3 ports.
internet_map_bundle.setPorts(list(range(8081, 8089)))
# Register the bundle with the Docker compiler to generate its containers during emu.compile().
docker.addContainerBundle(internet_map_bundle)
emu.compile(docker, str(output_dir), override=override)


def main() -> int:
Expand All @@ -133,4 +142,4 @@ def main() -> int:


if __name__ == "__main__":
raise SystemExit(main())
raise SystemExit(main())
11 changes: 10 additions & 1 deletion examples/basic/A06_merge_emulation/merge_emulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from seedemu.mergers import DEFAULT_MERGERS
from seedemu.layers import Base, Routing, Ebgp
from seedemu.compiler import Docker, Platform
from seedemu.containerBundle import InternetMap


SCRIPT_DIR = Path(__file__).resolve().parent
Expand Down Expand Up @@ -99,7 +100,15 @@ def run(

output_dir = Path(output or SCRIPT_DIR / "output").resolve()
output_dir.parent.mkdir(parents=True, exist_ok=True)
emu_merged.compile(Docker(platform=platform), str(output_dir), override=override)
docker = Docker(platform=platform)
# Add Internet visualization services: topology, geographic map, and traffic observation.
# The second argument is a container name suffix that distinguishes bundle instances.
internet_map_bundle = InternetMap(emu_merged, ".map.seed")
# Provide a host port pool (range excludes the stop value); InternetMap needs at least 3 ports.
internet_map_bundle.setPorts(list(range(8081, 8089)))
# Register the bundle with the Docker compiler to generate its containers during emu.compile().
docker.addContainerBundle(internet_map_bundle)
emu_merged.compile(docker, str(output_dir), override=override)


def main() -> int:
Expand Down
13 changes: 11 additions & 2 deletions examples/basic/A07_compilers/compilers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from seedemu.core import Emulator
import os, sys
from examples.basic.A01_transit_as import transit_as
from seedemu.containerBundle import InternetMap

###############################################################################
# Set the platform information
Expand Down Expand Up @@ -49,7 +50,15 @@
script_dir = os.path.dirname(os.path.abspath(__file__))
output_dir = os.path.join(script_dir, 'output')
os.makedirs(output_dir, exist_ok=True)
emu.compile(Docker(platform=platform), './output/regular-docker', override=True)
docker = Docker(platform=platform)
# Add Internet visualization services: topology, geographic map, and traffic observation.
# The second argument is a container name suffix that distinguishes bundle instances.
internet_map_bundle = InternetMap(emu, ".map.seed")
# Provide a host port pool (range excludes the stop value); InternetMap needs at least 3 ports.
internet_map_bundle.setPorts(list(range(8081, 8089)))
# Register the bundle with the Docker compiler to generate its containers during emu.compile().
docker.addContainerBundle(internet_map_bundle)
emu.compile(docker, './output/regular-docker', override=True)
emu.compile(Graphviz(), './output/graphs', override=True)
emu.compile(DistributedDocker(), './output/distributed-docker', override=True)
emu.compile(GcpDistributedDocker(), './output/gcp-distributed-docker', override=True)
emu.compile(GcpDistributedDocker(), './output/gcp-distributed-docker', override=True)
12 changes: 10 additions & 2 deletions examples/basic/A09_node_customization/node_customization.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,16 @@ def main() -> None:
node.appendStartCommand("python3 /myprog.py", fork=True)

emu.render()
emu.compile(Docker(platform=platform), str(output), override=True)
docker = Docker(platform=platform)
# Add Internet visualization services: topology, geographic map, and traffic observation.
# The second argument is a container name suffix that distinguishes bundle instances.
internet_map_bundle = InternetMap(emu, ".map.seed")
# Provide a host port pool (range excludes the stop value); InternetMap needs at least 3 ports.
internet_map_bundle.setPorts(list(range(8081, 8089)))
# Register the bundle with the Docker compiler to generate its containers during emu.compile().
docker.addContainerBundle(internet_map_bundle)
emu.compile(docker, str(output), override=True)


if __name__ == "__main__":
main()
main()
Loading
Loading