#2453 - Example Notebooks Require Refactor

- create_simulation_demo and network_simulator_demo notebooks have been updated with correct import paths to reflect refactoring within condebase.
 - Corrected typo within create-simulation_demo: my_swtich -> my_switch
 - updates to ARP implementation. This is now a property in HostNode and NetworkNode, meaning router.arp.show() now works in network_simulator_demo notebook as intended.
This commit is contained in:
Charlie Crane
2024-04-09 13:26:35 +01:00
parent bce32fb376
commit f8432bf53b
6 changed files with 8494 additions and 111 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@@ -59,7 +59,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"id": "de57ac8c-5b28-4847-a759-2ceaf5593329",
"metadata": {
"tags": []
@@ -71,7 +71,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"id": "a1e2e4df-67c0-4584-ab27-47e2c7c7fcd2",
"metadata": {
"tags": []
@@ -91,12 +91,70 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"id": "cc199741-ef2e-47f5-b2f0-e20049ccf40f",
"metadata": {
"tags": []
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"+------------------------------------------------+\n",
"| Nodes |\n",
"+-------------------+----------+-----------------+\n",
"| Node | Type | Operating State |\n",
"+-------------------+----------+-----------------+\n",
"| router_1 | Router | ON |\n",
"| switch_1 | Switch | ON |\n",
"| switch_2 | Switch | ON |\n",
"| domain_controller | Server | ON |\n",
"| database_server | Server | ON |\n",
"| web_server | Server | ON |\n",
"| backup_server | Server | ON |\n",
"| security_suite | Server | ON |\n",
"| client_1 | Computer | ON |\n",
"| client_2 | Computer | ON |\n",
"+-------------------+----------+-----------------+\n",
"+-----------------------------------------------------------------------------+\n",
"| IP Addresses |\n",
"+-------------------+------+----------------+---------------+-----------------+\n",
"| Node | Port | IP Address | Subnet Mask | Default Gateway |\n",
"+-------------------+------+----------------+---------------+-----------------+\n",
"| router_1 | 1 | 192.168.1.1 | 255.255.255.0 | None |\n",
"| router_1 | 2 | 192.168.10.1 | 255.255.255.0 | None |\n",
"| router_1 | 3 | 127.0.0.1 | 255.0.0.0 | None |\n",
"| router_1 | 4 | 127.0.0.1 | 255.0.0.0 | None |\n",
"| router_1 | 5 | 127.0.0.1 | 255.0.0.0 | None |\n",
"| domain_controller | 1 | 192.168.1.10 | 255.255.255.0 | 192.168.1.1 |\n",
"| database_server | 1 | 192.168.1.14 | 255.255.255.0 | 192.168.1.1 |\n",
"| web_server | 1 | 192.168.1.12 | 255.255.255.0 | 192.168.1.1 |\n",
"| backup_server | 1 | 192.168.1.16 | 255.255.255.0 | 192.168.1.1 |\n",
"| security_suite | 1 | 192.168.1.110 | 255.255.255.0 | 192.168.1.1 |\n",
"| security_suite | 2 | 192.168.10.110 | 255.255.255.0 | 192.168.1.1 |\n",
"| client_1 | 1 | 192.168.10.21 | 255.255.255.0 | 192.168.10.1 |\n",
"| client_2 | 1 | 192.168.10.22 | 255.255.255.0 | 192.168.10.1 |\n",
"+-------------------+------+----------------+---------------+-----------------+\n",
"+---------------------------------------------------------------------------------------------------------------------------------------------------------------+\n",
"| Links |\n",
"+------------+----------------------------------------+-------------------+------------------------------------------+-------+-------------------+--------------+\n",
"| Endpoint A | A Port | Endpoint B | B Port | is Up | Bandwidth (MBits) | Current Load |\n",
"+------------+----------------------------------------+-------------------+------------------------------------------+-------+-------------------+--------------+\n",
"| router_1 | Port 2: eb:31:e8:11:28:ac/192.168.10.1 | switch_2 | Port 8: d3:59:e2:73:4e:b8 | True | 100.0 | 0.00006% |\n",
"| router_1 | Port 1: 3f:c3:3d:00:74:c4/192.168.1.1 | switch_1 | Port 8: a9:ea:54:9f:35:f8 | True | 100.0 | 0.00018% |\n",
"| switch_1 | Port 7: 63:ea:45:e6:f4:22 | security_suite | Port 1: 18:9d:a1:f0:6f:0b/192.168.1.110 | True | 100.0 | 0.00003% |\n",
"| switch_1 | Port 4: 08:0e:a9:03:d7:3c | backup_server | Port 1: c3:e5:81:c9:8b:74/192.168.1.16 | True | 100.0 | 0.00003% |\n",
"| switch_1 | Port 2: 75:c5:30:0f:5d:92 | web_server | Port 1: 90:94:52:a6:1f:c5/192.168.1.12 | True | 100.0 | 0.00015% |\n",
"| switch_1 | Port 3: f1:62:75:5d:d9:59 | database_server | Port 1: 2e:e8:cb:a5:97:12/192.168.1.14 | True | 100.0 | 0.00017% |\n",
"| switch_1 | Port 1: 08:79:a7:3f:b5:96 | domain_controller | Port 1: 00:c3:ff:62:87:8f/192.168.1.10 | True | 100.0 | 0.00003% |\n",
"| switch_2 | Port 7: 88:9c:57:5c:53:5e | security_suite | Port 2: 9e:b2:c8:04:d8:97/192.168.10.110 | True | 100.0 | 0.00000% |\n",
"| switch_2 | Port 2: a8:1b:b2:78:12:34 | client_2 | Port 1: 6a:b1:ff:36:ef:40/192.168.10.22 | True | 100.0 | 0.00003% |\n",
"| switch_2 | Port 1: 42:08:3f:1e:ea:dd | client_1 | Port 1: f6:6d:35:8a:67:d8/192.168.10.21 | True | 100.0 | 0.00003% |\n",
"+------------+----------------------------------------+-------------------+------------------------------------------+-------+-------------------+--------------+\n"
]
}
],
"source": [
"network.show()"
]
@@ -133,12 +191,30 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"id": "e76d1854-961e-438c-b40f-77fd9c3abe38",
"metadata": {
"tags": []
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"+---------------------------------------------------------------+\n",
"| router_1 Network Interfaces |\n",
"+------+-------------------+-----------------+-------+----------+\n",
"| Port | MAC Address | Address | Speed | Status |\n",
"+------+-------------------+-----------------+-------+----------+\n",
"| 1 | 3f:c3:3d:00:74:c4 | 192.168.1.1/24 | 100 | Enabled |\n",
"| 2 | eb:31:e8:11:28:ac | 192.168.10.1/24 | 100 | Enabled |\n",
"| 3 | 7b:4f:23:8d:b5:18 | 127.0.0.1/8 | 100 | Disabled |\n",
"| 4 | cd:89:ba:42:ee:04 | 127.0.0.1/8 | 100 | Disabled |\n",
"| 5 | 8d:92:27:76:79:c5 | 127.0.0.1/8 | 100 | Disabled |\n",
"+------+-------------------+-----------------+-------+----------+\n"
]
}
],
"source": [
"network.get_node_by_hostname(\"router_1\").show()"
]
@@ -153,12 +229,32 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"id": "92de8b42-92d7-4934-9c12-50bf724c9eb2",
"metadata": {
"tags": []
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"+-------------------------------------------------------+\n",
"| router_1 ARP Cache |\n",
"+---------------+-------------------+-------------------+\n",
"| IP Address | MAC Address | Via |\n",
"+---------------+-------------------+-------------------+\n",
"| 192.168.10.21 | f6:6d:35:8a:67:d8 | eb:31:e8:11:28:ac |\n",
"| 192.168.10.22 | 6a:b1:ff:36:ef:40 | eb:31:e8:11:28:ac |\n",
"| 192.168.1.10 | 00:c3:ff:62:87:8f | 3f:c3:3d:00:74:c4 |\n",
"| 192.168.1.14 | 2e:e8:cb:a5:97:12 | 3f:c3:3d:00:74:c4 |\n",
"| 192.168.1.12 | 90:94:52:a6:1f:c5 | 3f:c3:3d:00:74:c4 |\n",
"| 192.168.1.16 | c3:e5:81:c9:8b:74 | 3f:c3:3d:00:74:c4 |\n",
"| 192.168.1.110 | 18:9d:a1:f0:6f:0b | 3f:c3:3d:00:74:c4 |\n",
"+---------------+-------------------+-------------------+\n"
]
}
],
"source": [
"network.get_node_by_hostname(\"router_1\").arp.show()"
]
@@ -173,12 +269,32 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"id": "5922282a-d22b-4e55-9176-f3f3654c849f",
"metadata": {
"tags": []
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"+---------------------------------------------------------------------------------------------------------------------------------------+\n",
"| router_1 Access Control List |\n",
"+-------+--------+----------+--------+--------------+------------------------+--------+--------------+------------------------+---------+\n",
"| Index | Action | Protocol | Src IP | Src Wildcard | Src Port | Dst IP | Dst Wildcard | Dst Port | Matched |\n",
"+-------+--------+----------+--------+--------------+------------------------+--------+--------------+------------------------+---------+\n",
"| 0 | PERMIT | ANY | ANY | ANY | 5432 (POSTGRES_SERVER) | ANY | ANY | 5432 (POSTGRES_SERVER) | 0 |\n",
"| 1 | PERMIT | ANY | ANY | ANY | 53 (DNS) | ANY | ANY | 53 (DNS) | 0 |\n",
"| 2 | PERMIT | ANY | ANY | ANY | 21 (FTP) | ANY | ANY | 21 (FTP) | 0 |\n",
"| 3 | PERMIT | ANY | ANY | ANY | 80 (HTTP) | ANY | ANY | 80 (HTTP) | 0 |\n",
"| 22 | PERMIT | ANY | ANY | ANY | 219 (ARP) | ANY | ANY | 219 (ARP) | 0 |\n",
"| 23 | PERMIT | ICMP | ANY | ANY | ANY | ANY | ANY | ANY | 0 |\n",
"| 24 | DENY | ANY | ANY | ANY | ANY | ANY | ANY | ANY | 0 |\n",
"+-------+--------+----------+--------+--------------+------------------------+--------+--------------+------------------------+---------+\n"
]
}
],
"source": [
"network.get_node_by_hostname(\"router_1\").acl.show()"
]
@@ -193,12 +309,25 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"id": "327203be-f475-4727-82a1-e992d3b70ed8",
"metadata": {
"tags": []
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"+-------------------------------------+\n",
"| router_1 Route Table |\n",
"+-------+---------+----------+--------+\n",
"| Index | Address | Next Hop | Metric |\n",
"+-------+---------+----------+--------+\n",
"+-------+---------+----------+--------+\n"
]
}
],
"source": [
"network.get_node_by_hostname(\"router_1\").route_table.show()"
]
@@ -213,12 +342,25 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"id": "3d0aa004-b10c-445f-aaab-340e0e716c74",
"metadata": {
"tags": []
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"+-----------------------------+\n",
"| router_1 Sys Log |\n",
"+-----------+-------+---------+\n",
"| Timestamp | Level | Message |\n",
"+-----------+-------+---------+\n",
"+-----------+-------+---------+\n"
]
}
],
"source": [
"network.get_node_by_hostname(\"router_1\").sys_log.show(last_n=10)"
]
@@ -238,17 +380,52 @@
"id": "4879394d-2981-40de-a229-e19b09a34e6e",
"metadata": {},
"source": [
"Calling `switch.show()` displays the Switch orts on the Switch."
"Calling `switch.show()` displays the Switch ports on the Switch."
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 30,
"id": "e7fd439b-5442-4e9d-9e7d-86dacb77f458",
"metadata": {
"tags": []
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"+---------------------------------------------+\n",
"| switch_1 Switch Ports |\n",
"+------+-------------------+-------+----------+\n",
"| Port | MAC Address | Speed | Status |\n",
"+------+-------------------+-------+----------+\n",
"| 1 | 08:79:a7:3f:b5:96 | 100 | Enabled |\n",
"| 2 | 75:c5:30:0f:5d:92 | 100 | Enabled |\n",
"| 3 | f1:62:75:5d:d9:59 | 100 | Enabled |\n",
"| 4 | 08:0e:a9:03:d7:3c | 100 | Enabled |\n",
"| 5 | ae:40:29:58:c7:95 | 100 | Disabled |\n",
"| 6 | 7d:54:38:7f:79:e8 | 100 | Disabled |\n",
"| 7 | 63:ea:45:e6:f4:22 | 100 | Enabled |\n",
"| 8 | a9:ea:54:9f:35:f8 | 100 | Enabled |\n",
"+------+-------------------+-------+----------+\n",
"+---------------------------------------------+\n",
"| switch_2 Switch Ports |\n",
"+------+-------------------+-------+----------+\n",
"| Port | MAC Address | Speed | Status |\n",
"+------+-------------------+-------+----------+\n",
"| 1 | 42:08:3f:1e:ea:dd | 100 | Enabled |\n",
"| 2 | a8:1b:b2:78:12:34 | 100 | Enabled |\n",
"| 3 | 43:e4:54:fe:e7:1f | 100 | Disabled |\n",
"| 4 | 24:bf:74:7c:c4:11 | 100 | Disabled |\n",
"| 5 | 4b:57:f7:46:c9:4f | 100 | Disabled |\n",
"| 6 | 10:03:9d:39:0c:81 | 100 | Disabled |\n",
"| 7 | 88:9c:57:5c:53:5e | 100 | Enabled |\n",
"| 8 | d3:59:e2:73:4e:b8 | 100 | Enabled |\n",
"+------+-------------------+-------+----------+\n"
]
}
],
"source": [
"network.get_node_by_hostname(\"switch_1\").show()"
]
@@ -265,14 +442,28 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 10,
"id": "d06e1310-4a77-4315-a59f-cb1b49ca2352",
"metadata": {
"tags": []
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"+--------------------------------+\n",
"| switch_1 ARP Cache |\n",
"+------------+-------------+-----+\n",
"| IP Address | MAC Address | Via |\n",
"+------------+-------------+-----+\n",
"+------------+-------------+-----+\n"
]
}
],
"source": [
"network.get_node_by_hostname(\"switch_1\").arp.show()"
"network.get_node_by_hostname(\"switch_1\").arp.show()\n",
"#network.get_node_by_hostname(\"switch_1\").software_manager"
]
},
{
@@ -285,12 +476,25 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 11,
"id": "a0d984b7-a7c1-4bbd-aa5a-9d3caecb08dc",
"metadata": {
"tags": []
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"+-----------------------------+\n",
"| switch_1 Sys Log |\n",
"+-----------+-------+---------+\n",
"| Timestamp | Level | Message |\n",
"+-----------+-------+---------+\n",
"+-----------+-------+---------+\n"
]
}
],
"source": [
"network.get_node_by_hostname(\"switch_1\").sys_log.show()"
]
@@ -317,12 +521,38 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 12,
"id": "656c37f6-b145-42af-9714-8d2886d0eff8",
"metadata": {
"tags": []
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"+-----------------------------------------------------------------------+\n",
"| security_suite Network Interface Cards |\n",
"+------+------+-------------------+-------------------+-------+---------+\n",
"| Port | Type | MAC Address | Address | Speed | Status |\n",
"+------+------+-------------------+-------------------+-------+---------+\n",
"| 1 | NIC | 18:9d:a1:f0:6f:0b | 192.168.1.110/24 | 100 | Enabled |\n",
"| 2 | NIC | 9e:b2:c8:04:d8:97 | 192.168.10.110/24 | 100 | Enabled |\n",
"+------+------+-------------------+-------------------+-------+---------+\n",
"+---------------------------+\n",
"| security_suite Open Ports |\n",
"+-------------+-------------+\n",
"| Port | Name |\n",
"+-------------+-------------+\n",
"| 21 | FTP |\n",
"| 53 | DNS |\n",
"| 80 | HTTP |\n",
"| 123 | NTP |\n",
"| 219 | ARP |\n",
"+-------------+-------------+\n"
]
}
],
"source": [
"network.get_node_by_hostname(\"security_suite\").show()"
]
@@ -337,12 +567,26 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 13,
"id": "66b267d6-2308-486a-b9aa-cb8d3bcf0753",
"metadata": {
"tags": []
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"+-----------------------------------------------------+\n",
"| security_suite ARP Cache |\n",
"+-------------+-------------------+-------------------+\n",
"| IP Address | MAC Address | Via |\n",
"+-------------+-------------------+-------------------+\n",
"| 192.168.1.1 | 3f:c3:3d:00:74:c4 | 18:9d:a1:f0:6f:0b |\n",
"+-------------+-------------------+-------------------+\n"
]
}
],
"source": [
"network.get_node_by_hostname(\"security_suite\").arp.show()"
]
@@ -357,12 +601,25 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 14,
"id": "1b5debe8-ef1b-445d-8fa9-6a45568f21f3",
"metadata": {
"tags": []
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"+-----------------------------+\n",
"| security_suite Sys Log |\n",
"+-----------+-------+---------+\n",
"| Timestamp | Level | Message |\n",
"+-----------+-------+---------+\n",
"+-----------+-------+---------+\n"
]
}
],
"source": [
"network.get_node_by_hostname(\"security_suite\").sys_log.show()"
]
@@ -379,12 +636,38 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 15,
"id": "495b7de4-b6ce-41a6-9114-f74752ab4491",
"metadata": {
"tags": []
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"+-----------------------------------------------------------------------------+\n",
"| IP Addresses |\n",
"+-------------------+------+----------------+---------------+-----------------+\n",
"| Node | Port | IP Address | Subnet Mask | Default Gateway |\n",
"+-------------------+------+----------------+---------------+-----------------+\n",
"| router_1 | 1 | 192.168.1.1 | 255.255.255.0 | None |\n",
"| router_1 | 2 | 192.168.10.1 | 255.255.255.0 | None |\n",
"| router_1 | 3 | 127.0.0.1 | 255.0.0.0 | None |\n",
"| router_1 | 4 | 127.0.0.1 | 255.0.0.0 | None |\n",
"| router_1 | 5 | 127.0.0.1 | 255.0.0.0 | None |\n",
"| domain_controller | 1 | 192.168.1.10 | 255.255.255.0 | 192.168.1.1 |\n",
"| database_server | 1 | 192.168.1.14 | 255.255.255.0 | 192.168.1.1 |\n",
"| web_server | 1 | 192.168.1.12 | 255.255.255.0 | 192.168.1.1 |\n",
"| backup_server | 1 | 192.168.1.16 | 255.255.255.0 | 192.168.1.1 |\n",
"| security_suite | 1 | 192.168.1.110 | 255.255.255.0 | 192.168.1.1 |\n",
"| security_suite | 2 | 192.168.10.110 | 255.255.255.0 | 192.168.1.1 |\n",
"| client_1 | 1 | 192.168.10.21 | 255.255.255.0 | 192.168.10.1 |\n",
"| client_2 | 1 | 192.168.10.22 | 255.255.255.0 | 192.168.10.1 |\n",
"+-------------------+------+----------------+---------------+-----------------+\n"
]
}
],
"source": [
"network.show(nodes=False, links=False)"
]
@@ -399,24 +682,60 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 16,
"id": "a38abb71-994e-49e8-8f51-e9a550e95b99",
"metadata": {
"tags": []
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Pinging 192.168.10.1:\n",
"Reply from 192.168.10.1: bytes=32, time=<1ms, TTL=62\n",
"Reply from 192.168.10.1: bytes=32, time=<1ms, TTL=62\n",
"Reply from 192.168.10.1: bytes=32, time=<1ms, TTL=62\n",
"Reply from 192.168.10.1: bytes=32, time=<1ms, TTL=62\n",
"Ping statistics for 192.168.10.1: Packets: Sent = 4, Received = 4, Lost = 0 (0.0% loss)\n"
]
},
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"network.get_node_by_hostname(\"client_1\").ping(\"192.168.10.1\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 17,
"id": "8388e1e9-30e3-4534-8e5a-c6e9144149d2",
"metadata": {
"tags": []
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"+-----------------------------+\n",
"| client_1 Sys Log |\n",
"+-----------+-------+---------+\n",
"| Timestamp | Level | Message |\n",
"+-----------+-------+---------+\n",
"+-----------+-------+---------+\n"
]
}
],
"source": [
"network.get_node_by_hostname(\"client_1\").sys_log.show(15)"
]
@@ -431,12 +750,35 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 18,
"id": "ff8e976a-c16b-470c-8923-325713a30d6c",
"metadata": {
"tags": []
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Pinging 192.168.1.1:\n",
"Reply from 192.168.10.1: bytes=32, time=<1ms, TTL=62\n",
"Reply from 192.168.10.1: bytes=32, time=<1ms, TTL=62\n",
"Reply from 192.168.10.1: bytes=32, time=<1ms, TTL=62\n",
"Reply from 192.168.10.1: bytes=32, time=<1ms, TTL=62\n",
"Ping statistics for 192.168.1.1: Packets: Sent = 4, Received = 4, Lost = 0 (0.0% loss)\n"
]
},
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"network.get_node_by_hostname(\"client_1\").ping(\"192.168.1.1\")"
]
@@ -451,12 +793,35 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 19,
"id": "c4163f8d-6a72-410c-9f5c-4f881b7de45e",
"metadata": {
"tags": []
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Pinging 192.168.1.12:\n",
"Reply from 192.168.1.12: bytes=32, time=<1ms, TTL=59\n",
"Reply from 192.168.1.12: bytes=32, time=<1ms, TTL=59\n",
"Reply from 192.168.1.12: bytes=32, time=<1ms, TTL=59\n",
"Reply from 192.168.1.12: bytes=32, time=<1ms, TTL=59\n",
"Ping statistics for 192.168.1.12: Packets: Sent = 4, Received = 4, Lost = 0 (0.0% loss)\n"
]
},
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"network.get_node_by_hostname(\"client_1\").ping(\"192.168.1.12\")"
]
@@ -471,12 +836,25 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 20,
"id": "e79a523a-5780-45b6-8798-c434e0e522bd",
"metadata": {
"tags": []
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"+-----------------------------+\n",
"| web_server Sys Log |\n",
"+-----------+-------+---------+\n",
"| Timestamp | Level | Message |\n",
"+-----------+-------+---------+\n",
"+-----------+-------+---------+\n"
]
}
],
"source": [
"network.get_node_by_hostname(\"web_server\").sys_log.show()"
]
@@ -501,12 +879,35 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 21,
"id": "603cf913-e261-49da-a7dd-85e1bb6dec56",
"metadata": {
"tags": []
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Pinging 192.168.1.12:\n",
"Reply from 192.168.1.12: bytes=32, time=<1ms, TTL=59\n",
"Reply from 192.168.1.12: bytes=32, time=<1ms, TTL=59\n",
"Reply from 192.168.1.12: bytes=32, time=<1ms, TTL=59\n",
"Reply from 192.168.1.12: bytes=32, time=<1ms, TTL=59\n",
"Ping statistics for 192.168.1.12: Packets: Sent = 4, Received = 4, Lost = 0 (0.0% loss)\n"
]
},
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"network.get_node_by_hostname(\"client_2\").ping(\"192.168.1.12\")"
]
@@ -521,12 +922,25 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 22,
"id": "e047de00-3de4-4823-b26a-2c8d64c7a663",
"metadata": {
"tags": []
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"+-----------------------------+\n",
"| client_2 Sys Log |\n",
"+-----------+-------+---------+\n",
"| Timestamp | Level | Message |\n",
"+-----------+-------+---------+\n",
"+-----------+-------+---------+\n"
]
}
],
"source": [
"network.get_node_by_hostname(\"client_2\").sys_log.show()"
]
@@ -541,16 +955,27 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 23,
"id": "6db355ae-b99a-441b-a2c4-4ffe78f46bff",
"metadata": {
"tags": []
},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from primaite.simulator.network.transmission.network_layer import IPProtocol\n",
"from primaite.simulator.network.transmission.transport_layer import Port\n",
"from primaite.simulator.network.hardware.nodes.router import ACLAction\n",
"from primaite.simulator.network.hardware.nodes.network.router import ACLAction\n",
"network.get_node_by_hostname(\"router_1\").acl.add_rule(\n",
" action=ACLAction.DENY,\n",
" protocol=IPProtocol.ICMP,\n",
@@ -561,12 +986,32 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 24,
"id": "a345e000-8842-4827-af96-adc0fbe390fb",
"metadata": {
"tags": []
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"+----------------------------------------------------------------------------------------------------------------------------------------------+\n",
"| router_1 Access Control List |\n",
"+-------+--------+----------+---------------+--------------+------------------------+--------+--------------+------------------------+---------+\n",
"| Index | Action | Protocol | Src IP | Src Wildcard | Src Port | Dst IP | Dst Wildcard | Dst Port | Matched |\n",
"+-------+--------+----------+---------------+--------------+------------------------+--------+--------------+------------------------+---------+\n",
"| 0 | PERMIT | ANY | ANY | ANY | 5432 (POSTGRES_SERVER) | ANY | ANY | 5432 (POSTGRES_SERVER) | 0 |\n",
"| 1 | DENY | ICMP | 192.168.10.22 | ANY | ANY | ANY | ANY | ANY | 0 |\n",
"| 2 | PERMIT | ANY | ANY | ANY | 21 (FTP) | ANY | ANY | 21 (FTP) | 0 |\n",
"| 3 | PERMIT | ANY | ANY | ANY | 80 (HTTP) | ANY | ANY | 80 (HTTP) | 0 |\n",
"| 22 | PERMIT | ANY | ANY | ANY | 219 (ARP) | ANY | ANY | 219 (ARP) | 0 |\n",
"| 23 | PERMIT | ICMP | ANY | ANY | ANY | ANY | ANY | ANY | 24 |\n",
"| 24 | DENY | ANY | ANY | ANY | ANY | ANY | ANY | ANY | 0 |\n",
"+-------+--------+----------+---------------+--------------+------------------------+--------+--------------+------------------------+---------+\n"
]
}
],
"source": [
"network.get_node_by_hostname(\"router_1\").acl.show()"
]
@@ -581,12 +1026,31 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 25,
"id": "a4f4ff31-590f-40fb-b13d-efaa8c2720b6",
"metadata": {
"tags": []
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Pinging 192.168.1.12:\n",
"Ping statistics for 192.168.1.12: Packets: Sent = 4, Received = 0, Lost = 4 (100.0% loss)\n"
]
},
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"network.get_node_by_hostname(\"client_2\").ping(\"192.168.1.12\")"
]
@@ -601,12 +1065,25 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 26,
"id": "f62b8a4e-fd3b-4059-b108-3d4a0b18f2a0",
"metadata": {
"tags": []
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"+-----------------------------+\n",
"| client_2 Sys Log |\n",
"+-----------+-------+---------+\n",
"| Timestamp | Level | Message |\n",
"+-----------+-------+---------+\n",
"+-----------+-------+---------+\n"
]
}
],
"source": [
"network.get_node_by_hostname(\"client_2\").sys_log.show()"
]
@@ -621,12 +1098,25 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 27,
"id": "7e53d776-99da-4d2c-a2a7-bd7ce27bff4c",
"metadata": {
"tags": []
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"+-----------------------------+\n",
"| router_1 Sys Log |\n",
"+-----------+-------+---------+\n",
"| Timestamp | Level | Message |\n",
"+-----------+-------+---------+\n",
"+-----------+-------+---------+\n"
]
}
],
"source": [
"network.get_node_by_hostname(\"router_1\").sys_log.show()"
]
@@ -641,24 +1131,60 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 28,
"id": "d542734b-7582-4af7-8254-bda3de50d091",
"metadata": {
"tags": []
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Pinging 192.168.1.12:\n",
"Reply from 192.168.1.12: bytes=32, time=<1ms, TTL=59\n",
"Reply from 192.168.1.12: bytes=32, time=<1ms, TTL=59\n",
"Reply from 192.168.1.12: bytes=32, time=<1ms, TTL=59\n",
"Reply from 192.168.1.12: bytes=32, time=<1ms, TTL=59\n",
"Ping statistics for 192.168.1.12: Packets: Sent = 4, Received = 4, Lost = 0 (0.0% loss)\n"
]
},
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"network.get_node_by_hostname(\"client_1\").ping(\"192.168.1.12\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 29,
"id": "d78e9fe3-02c6-4792-944f-5622e26e0412",
"metadata": {
"tags": []
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"+-----------------------------+\n",
"| client_1 Sys Log |\n",
"+-----------+-------+---------+\n",
"| Timestamp | Level | Message |\n",
"+-----------+-------+---------+\n",
"+-----------+-------+---------+\n"
]
}
],
"source": [
"network.get_node_by_hostname(\"client_1\").sys_log.show()"
]

View File

@@ -316,6 +316,10 @@ class HostNode(Node):
super().__init__(**kwargs)
self.connect_nic(NIC(ip_address=ip_address, subnet_mask=subnet_mask))
@property
def arp(self) -> Optional[ARP]:
return self.software_manager.software.get("ARP")
def _install_system_software(self):
"""
Installs the system software and network services typically found on an operating system.

View File

@@ -1,8 +1,9 @@
from abc import abstractmethod
from typing import Optional
from primaite.simulator.network.hardware.base import NetworkInterface, Node
from primaite.simulator.network.transmission.data_link_layer import Frame
from primaite.simulator.system.services.arp.arp import ARP
class NetworkNode(Node):
"""
@@ -28,3 +29,7 @@ class NetworkNode(Node):
:type from_network_interface: NetworkInterface
"""
pass
@property
def arp(self) -> Optional[ARP]:
return self.software_manager.software.get("ARP")

View File

@@ -1215,8 +1215,7 @@ class Router(NetworkNode):
icmp: RouterICMP = self.software_manager.icmp # noqa
icmp.router = self
self.software_manager.install(RouterARP)
arp: RouterARP = self.software_manager.arp # noqa
arp.router = self
self.arp.router = self
def _set_default_acl(self):
"""