diff options
| author | mo khan <mo@mokhan.ca> | 2025-09-30 16:08:57 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-09-30 16:08:57 -0600 |
| commit | 98e5eff870009e8f42c599c1bd1b78dc8f3b9cb7 (patch) | |
| tree | 2a4a0de774aab0bf6b0d2dde9c5504609c00d14e /assignments/2 | |
| parent | b614c08b8faa78d6e3da7dcec2f8e2e6ab1b2f43 (diff) | |
add ruby code to verify CIDR routes
Diffstat (limited to 'assignments/2')
| -rw-r--r-- | assignments/2/README.md | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/assignments/2/README.md b/assignments/2/README.md index b51499e..9fab554 100644 --- a/assignments/2/README.md +++ b/assignments/2/README.md @@ -332,6 +332,26 @@ b. 135.46.53.16 -> no /22 match -> forward using Default -> Router 3. c. 192.53.40.6 -> matches 192.53.40.0/23 -> forward to Router 2. d. 192.53.56.7 -> no /23 match -> forward using Default -> Router 3. +```ruby +require 'ipaddr' + +routes = [ + IPAddr.new('135.46.56.0/22'), + IPAddr.new('135.46.60.0/22'), + IPAddr.new('192.53.40.0/23'), +] + +a = IPAddr.new("135.46.61.10") +b = IPAddr.new("135.46.53.16") +c = IPAddr.new("192.53.40.6") +d = IPAddr.new("192.53.56.7") + +puts routes.find { |route| route.include?(a) } || "Default" +puts routes.find { |route| route.include?(b) } || "Default" +puts routes.find { |route| route.include?(c) } || "Default" +puts routes.find { |route| route.include?(d) } || "Default" +``` + ## 2.4 TCP Congestion Control (20%) > (20%) Consider that only a single TCP connection uses a 1 Gbps link, |
