2023-09-01 16:58:21 +01:00
|
|
|
.. only:: comment
|
|
|
|
|
|
2024-06-05 09:11:37 +01:00
|
|
|
© Crown-owned copyright 2024, Defence Science and Technology Laboratory UK
|
2023-09-01 16:58:21 +01:00
|
|
|
|
2023-09-11 16:15:03 +01:00
|
|
|
.. _network:
|
2023-09-01 16:58:21 +01:00
|
|
|
|
|
|
|
|
Network
|
|
|
|
|
=======
|
|
|
|
|
|
|
|
|
|
The ``Network`` class serves as the backbone of the simulation. It offers a framework to manage various network
|
|
|
|
|
components such as routers, switches, servers, and clients. This document provides a detailed explanation of how to
|
|
|
|
|
effectively use the ``Network`` class.
|
|
|
|
|
|
|
|
|
|
Example Usage
|
|
|
|
|
-------------
|
|
|
|
|
|
|
|
|
|
Below demonstrates how to use the Router node to connect Nodes, and block traffic using ACLs. For this demonstration,
|
|
|
|
|
we'll use the following Network that has a client, server, two switches, and a router.
|
|
|
|
|
|
|
|
|
|
.. code-block:: text
|
|
|
|
|
|
|
|
|
|
+------------+ +------------+ +------------+ +------------+ +------------+
|
|
|
|
|
| | | | | | | | | |
|
|
|
|
|
| client_1 +------+ switch_2 +------+ router_1 +------+ switch_1 +------+ server_1 |
|
|
|
|
|
| | | | | | | | | |
|
|
|
|
|
+------------+ +------------+ +------------+ +------------+ +------------+
|
|
|
|
|
|
|
|
|
|
1. Relevant imports
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
from primaite.simulator.network.container import Network
|
2024-02-23 16:49:01 +00:00
|
|
|
from primaite.simulator.network.hardware.base import NetworkInterface
|
|
|
|
|
from primaite.simulator.network.hardware.nodes.host.computer import Computer
|
|
|
|
|
from primaite.simulator.network.hardware.nodes.network.router import Router, ACLAction
|
|
|
|
|
from primaite.simulator.network.hardware.nodes.host.server import Server
|
|
|
|
|
from primaite.simulator.network.hardware.nodes.network.switch import Switch
|
2023-09-01 16:58:21 +01:00
|
|
|
from primaite.simulator.network.transmission.network_layer import IPProtocol
|
|
|
|
|
from primaite.simulator.network.transmission.transport_layer import Port
|
|
|
|
|
|
|
|
|
|
2. Create the Network
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
network = Network()
|
|
|
|
|
|
|
|
|
|
3. Create and configure the Router
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
router_1 = Router(hostname="router_1", num_ports=3)
|
|
|
|
|
router_1.power_on()
|
|
|
|
|
router_1.configure_port(port=1, ip_address="192.168.1.1", subnet_mask="255.255.255.0")
|
|
|
|
|
router_1.configure_port(port=2, ip_address="192.168.2.1", subnet_mask="255.255.255.0")
|
|
|
|
|
|
|
|
|
|
4. Create and configure the two Switches
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
switch_1 = Switch(hostname="switch_1", num_ports=6)
|
|
|
|
|
switch_1.power_on()
|
|
|
|
|
switch_2 = Switch(hostname="switch_2", num_ports=6)
|
|
|
|
|
switch_2.power_on()
|
|
|
|
|
|
|
|
|
|
5. Connect the Switches to the Router
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
#2248 - Enhances the PrimAITE documentation, covering the Node, network interfaces, Session Manager, Software Manager, PCAP service, SysLog functionality, and network devices like Routers, Switches, Computers, and Switch Nodes. It details their roles, workflows, and integration within the simulation, focusing on frame processing, software management, and logging. The documentation also clarifies the frame reception process, including port checks and application-level dispatching, ensuring a thorough understanding of network operations within the simulation
2024-02-08 22:37:21 +00:00
|
|
|
network.connect(endpoint_a=router_1.network_interfaces[1], endpoint_b=switch_1.network_interface[6])
|
2023-09-01 16:58:21 +01:00
|
|
|
router_1.enable_port(1)
|
#2248 - Enhances the PrimAITE documentation, covering the Node, network interfaces, Session Manager, Software Manager, PCAP service, SysLog functionality, and network devices like Routers, Switches, Computers, and Switch Nodes. It details their roles, workflows, and integration within the simulation, focusing on frame processing, software management, and logging. The documentation also clarifies the frame reception process, including port checks and application-level dispatching, ensuring a thorough understanding of network operations within the simulation
2024-02-08 22:37:21 +00:00
|
|
|
network.connect(endpoint_a=router_1.network_interfaces[2], endpoint_b=switch_2.network_interface[6])
|
2023-09-01 16:58:21 +01:00
|
|
|
router_1.enable_port(2)
|
|
|
|
|
|
|
|
|
|
6. Create the Client and Server nodes.
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
client_1 = Computer(
|
|
|
|
|
hostname="client_1",
|
|
|
|
|
ip_address="192.168.2.2",
|
|
|
|
|
subnet_mask="255.255.255.0",
|
|
|
|
|
default_gateway="192.168.2.1"
|
|
|
|
|
)
|
|
|
|
|
client_1.power_on()
|
|
|
|
|
server_1 = Server(
|
|
|
|
|
hostname="server_1",
|
|
|
|
|
ip_address="192.168.1.2",
|
|
|
|
|
subnet_mask="255.255.255.0",
|
|
|
|
|
default_gateway="192.168.1.1"
|
|
|
|
|
)
|
|
|
|
|
server_1.power_on()
|
|
|
|
|
|
|
|
|
|
7. Connect the Client and Server to the relevant Switch
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
#2248 - Enhances the PrimAITE documentation, covering the Node, network interfaces, Session Manager, Software Manager, PCAP service, SysLog functionality, and network devices like Routers, Switches, Computers, and Switch Nodes. It details their roles, workflows, and integration within the simulation, focusing on frame processing, software management, and logging. The documentation also clarifies the frame reception process, including port checks and application-level dispatching, ensuring a thorough understanding of network operations within the simulation
2024-02-08 22:37:21 +00:00
|
|
|
network.connect(endpoint_a=switch_2.network_interface[1], endpoint_b=client_1.network_interface[1])
|
|
|
|
|
network.connect(endpoint_a=switch_1.network_interface[1], endpoint_b=server_1.network_interface[1])
|
2023-09-01 16:58:21 +01:00
|
|
|
|
|
|
|
|
8. Add ACL rules on the Router to allow ARP and ICMP traffic.
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
router_1.acl.add_rule(
|
|
|
|
|
action=ACLAction.PERMIT,
|
|
|
|
|
src_port=Port.ARP,
|
|
|
|
|
dst_port=Port.ARP,
|
|
|
|
|
position=22
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
router_1.acl.add_rule(
|
|
|
|
|
action=ACLAction.PERMIT,
|
|
|
|
|
protocol=IPProtocol.ICMP,
|
|
|
|
|
position=23
|
|
|
|
|
)
|