Started work on exercise 13.

This commit is contained in:
Filipe Rodrigues 2023-12-16 16:25:35 +00:00
parent d7d86d2df5
commit ed8b8b61c4
7 changed files with 92 additions and 21 deletions

View File

@ -21,6 +21,7 @@
"logseq",
"maxs",
"packetsize",
"pktnet",
"pnet",
"Pollaczek",
"pracma",

View File

@ -15,6 +15,5 @@ flows <<- list(
list(rate = 5 * k, route = c(3))
)
throughput <- approx_kleinrock(link_capacities, flows, packet_size)
str(throughput)
approx <- approx_kleinrock(link_capacities, flows, packet_size)
str(approx)

View File

@ -1,31 +1,36 @@
# Calculates the throughput of a network using the kleinrock approximation
approx_kleinrock <- function(link_capacities, flows, packet_size) {
# (Bits / s)
λ_total <- 0
λ <- replicate(length(link_capacities), 0)
# Calculate the arrival rates per link and for the whole network
# (bits / s)
λ_network <- 0
λ_per_link <- replicate(length(link_capacities), 0)
for (flow in flows) {
λ_total <- λ_total + flow$rate
for (node_idx in flow$route) {
λ[node_idx] <- λ[node_idx] + flow$rate
λ_network <- λ_network + flow$rate
for (link_idx in flow$route) {
λ_per_link[link_idx] <- λ_per_link[link_idx] + flow$rate
}
}
# (Packets / s)
μ <- link_capacities / packet_size
# Then calculate the service rates
# (packets / s)
μ_per_link <- link_capacities / packet_size
# (Packets)
l <- λ / (μ - λ)
l_sum <- sum(l)
# Then the average packets per link and in the network
# (packets)
avg_packets_per_link <- λ_per_link / (μ_per_link - λ_per_link)
avg_packets_network <- sum(avg_packets_per_link)
total_wait <- l_sum / sum(λ_total)
waits_flows <- 1 / (μ - λ)
waits <- sapply(flows, function(flow) {
sum(sapply(flow$route, function(node_idx) waits_flows[node_idx]))
# And finally the average packet delay per link, then flow and in the network
# (seconds)
avg_packet_delay_network <- sum(avg_packets_per_link) / λ_network
avg_packet_delay_per_link <- 1 / (μ_per_link - λ_per_link)
avg_packet_delay_per_flow <- lapply(flows, function(flow) {
sum(sapply(flow$route, function(link_idx) avg_packet_delay_per_link[link_idx]))
})
list(
waits = waits,
total_wait = total_wait,
l_sum = l_sum
avg_packet_delay_per_flow = avg_packet_delay_per_flow,
avg_packet_delay_network = avg_packet_delay_network,
avg_packets_network = avg_packets_network
)
}

BIN
images/13-diagram.png (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -23,3 +23,5 @@
==== d. Remarking
#indent_par[After a packet is processed, it can be re-evaluated, similarly to the first step of classification, so that further equipment down the line can have a better idea of the nature of this packet.]
#pagebreak()

56
typst/exercises/13.typ Normal file
View File

@ -0,0 +1,56 @@
#import "@preview/tablex:0.0.6": tablex, rowspanx, colspanx
#import "/typst/util.typ" as util: indent_par, code_figure
#indent_par[The following code 10 is our implementation of the kleinrock approximation. It takes the link capacities, flows and packet size similarly to the `pnet` simulator.]
#code_figure(
text(size: 0.8em, raw(read("/code/kleinrock.R"), lang: "R", block: true)),
caption: "Code for Kleinrock approximation",
)
#indent_par[To test the simulator, we've used the following network from the course slides (`pktnet`, page 14).]
#figure(
image("/images/13-diagram.png", width: 75%),
caption: "3-DTMC"
)
#pagebreak()
#indent_par[We developed the following code 11 to test our implementation and obtained the results in table 18:]
#code_figure(
text(size: 0.8em, raw(read("/code/13.R"), lang: "R", block: true)),
caption: "Code for testing the Kleinrock approximation",
)
#figure(
pad(1em, tablex(
columns: (auto, 1fr, 1fr, 1fr),
align: center + horizon,
rowspanx(2)[ Flow ],
colspanx(2)[ Average packet delay ($"μs"$) ],
rowspanx(2)[ Average packets (network) ],
[ Per flow ],
[ Network ],
[1],
[600],
rowspanx(3)[644.4],
rowspanx(3)[14.5],
[2],
[800],
[3],
[400],
)),
kind: table,
caption: [Results]
)
#indent_par[Our values are the same as calculated manually, and thus we conclude our script is valid.]

View File

@ -92,3 +92,8 @@
=== 12. Exercise 12
#include "exercises/12.typ"
== G. Packet switched networks
=== 13. Exercise 13
#include "exercises/13.typ"