Skip to main content

Simple Docker based Network Simulator

Project description

L3 Network Simulator repository

With the aid of Python scripts, this library may be used to describe and manage virtual networks running inside Docker containers.

Installation

  1. L3NS requires Docker (https://docs.docker.com/engine/install/)
  2. Without sudo, further configuration is required for Docker and L3NS (https://docs.docker.com/engine/install/linux-postinstall/)
  3. pip3 install l3ns-dev

First look

Examples of how to use the library can be found in the examples subdirectory. The best option is to use [this example](examples/simple/basic docker lab.py) to obtain a general understanding of the library and api docs.

from l3ns.ldc import DockerNode
from l3ns import defaults

n1 = DockerNode('test1', image='alpine', command='tail -f /dev/null')
n2 = DockerNode('test2', image='alpine', command='tail -f /dev/null')

n1.connect_to(n2)

print(n1.get_ip())
print(n2.get_ip())

defaults.network.start(interactive=True)

The script can be executed by typing "python3".

    # python3 basic_docker_lab.py
    10.0.0.1
    10.0.0.2 

Docker will build two containers (named "test1" and "test2") from the "alpine" docker image as the script executes, and these containers will execute the "tail -f /dev/null" command. This command has no effect and lets the container keep running until manually terminating it. The IP addresses of both containers will be shown during the script and they will both be linked to the same subnet. By executing "ping" on any of the containers, you can verify this:

    docker exec -it node1 ping 10.0.0.2

IP packets are allowed to flow between nodes if you see a response.

Introduction

The three categories of objects that make up the operation of L3NS are "Node" (the emulated network's node), "Subnet" (the network's IP subnet), and "Network" (a separate emulated network, local - LAN, or global - WAN). The same network encompasses all subnets, and nodes might be a part of both one global and many local networks.

L3NS offers a variety of node implementations, subnets, and networks with various scopes but the same API. The l3ns.base submodule contains the abstract classes that describe the overall API. L3NS now offers l3ns.ldc (Local Docker Container) and l3ns.cluster as its two implementations.

API Reference

The API REFERENCE.md file contains comprehensive documentation of L3NS modules. It is created using the command pydoc-markdown (you must install the package with the same name from PyPI), and it is based on the documentation provided in the source code.

Writing your own simulation script

There are numerous fundamental steps that go up describing a virtual network model using l3ns:

  1. Building the network's central hub, which will have many routers that will transfer traffic between its various nodes. This phase may be done multiple times for networks with a high level of complexity.
  2. Establishing subnets across routers. The simplest method is to add all routers to the same subnet, although this may restrict your ability to manage the dynamic network state while testing. In this situation, there is no need to update the routing overlays; you may need to divide some routers into separate subnets.
  3. Configuring routers using dynamic routing protocols. Of course, the protocol used depends on the objectives set, but if you're unsure or have no idea which protocol to pick, utilize OSPF.
  4. Establishing end subnets connected to routers and populating them with payload nodes—aspects of the application being tested.
  5. The network's test launch. It can be beneficial to confirm that the network is configured appropriately before moving on to test the application.

The simplest method to accomplish this is to, as shown in [some examples](examples/sto_k/ping scalable.py), replace the entrypoint/cmd nodes with the logic application that is being tested. Ping will terminate if it is unable to deliver packets to the target node, such as when routing is wrongly setup or there is no network path between hosts, such as when a subnet is forgotten. The debugging of l3ns models is made a great deal simpler by this method. 6. Use the completed network.

When distant resources are required for modeling and the submodule l3ns.cluster is used, a preparatory stage is added: the preliminary configuration of cluster nodes. Examples (examples/simple/basic swarm lab.py) show how it appears.

Litrature on L3NS:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

l3ns-dev-0.0.2.tar.gz (22.3 kB view hashes)

Uploaded Source

Built Distribution

l3ns_dev-0.0.2-py3-none-any.whl (27.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page