Salta al contenuto
Note per Studenti Internet and Security - Mock Exam 3 Report

Internet and Security - Mock Exam 3

Questa pagina non ha ancora la versione ripasso: qui sotto c'è il testo completo.

In questa pagina 13

Mock exam built on the model of the written exams and official simulations of the equivalent Italian course Internet (UniPD): the practical module has two exercises (12 + 8 points) on transport-layer calculations and on network configuration, as in those papers. The theory module of the real papers of this course is not public: the ten quizzes (four options, one correct, 1 point each) are written on the course notes, with at least four on Network Security (here five). The official laboratory test is not simulated; Exercise 2 is its written counterpart, with the commands to type in Katharà. The numbers of questions, the points and the duration are a proposal: 30 points in total (quizzes 10×110\times1, Exercise 1 of 12 points, Exercise 2 of 8 points), 2 hours, quizzes without material and the exercises with the notes. All numerical results were checked with Python scripts (TCP rounds, send-rate formula, ALOHA and CSMA throughput, RSA, the ipaddress module for addresses and routes, and a simulation of the netfilter rules on a list of test packets).

Theory module

Quiz 1

A host asks its local DNS server for the address of www.assoc.example.org. The local DNS has in its cache the address of the server of the org top-level domain, but nothing about example.org. It queries the other servers iteratively, and processing times are negligible. The round-trip times are: host to local DNS 44 ms; local DNS to a root server 2828 ms; local DNS to the org server 2121 ms; local DNS to the authoritative server of example.org 3636 ms. How long does the host wait for the address?

  • a) 8989 ms
  • b) 4040 ms
  • c) 6161 ms
  • d) 6868 ms
Show the result

Answer c: 6161 ms.

Show the full solution

Each question-answer pair costs one RTT with its partner (DNS - Domain Name SystemDNS translates names such as www.amazon.com into IP addresses; it is a distributed hierarchical database (an inverted tree of up to 128 levels, with 13 root servers and domains registered through ICANN-accredited registrars), each ISP has a local DNS whose address the host gets from DHCP, the host asks it (usually over UDP) and it queries root, top-level and organisation servers, every server caches what it learns marking answers as non-authoritative until the TTL expires, records are (name, type, value, class, TTL), with NAT the DNS must return the public address, and there are four types of attack including cache poisoning.DNS - Domain Name System →). The root server is skipped because the address of the org server is already cached. The sequence is: host to local DNS (44 ms), local DNS to the org server, which answers "ask the authoritative server of example.org" (2121 ms), local DNS to the authoritative server, which returns the address (3636 ms), and the answer to the host is already counted in the first RTT. Total 4+21+36=614+21+36=61 ms.

The other options are typical mistakes: a is the full resolution with empty cache, 4+28+21+36=894+28+21+36=89 ms; b assumes that the address of the authoritative server was cached too (4+364+36); d asks the root server and skips the org server (4+28+364+28+36).

Quiz 2

A web cache (proxy) sits in front of a server and every request crosses it. A request answered from the cache (hit) takes 1212 ms; a request that is not in the cache (miss) takes the same 1212 ms plus 180180 ms to fetch the object from the origin server. The hit ratio is h=0.35h=0.35. What is the mean response time?

  • a) 129129 ms
  • b) 121.2121.2 ms
  • c) 6363 ms
  • d) 180180 ms
Show the result

Answer a: 129129 ms.

Show the full solution

In HTTP and the WebThe application layer is the top of the stack and only uses transport services; the Web is a distributed client-server hypertext service whose pages have URLs of the form protocol://host:port/path; HTTP runs over TCP (server port 80), is stateless and uses text messages (request or status line, headers, blank line, body) with methods GET, POST, HEAD, PUT, DELETE and status codes 2xx to 5xx; a page with N embedded objects needs 2(N+1) RTT with non-persistent connections and N+2 RTT with a persistent connection (transmission times neglected), cookies give HTTP a memory through Set-Cookie and Cookie headers, and a proxy (web cache) keeps copies of recent responses to cut load, traffic and delay.HTTP and the Web → the mean time with a cache is Tˉ=h Thit+(1−h) Tmiss\bar T=h\,T_{\text{hit}}+(1-h)\,T_{\text{miss}} with Tmiss=Thit+ToriginT_{\text{miss}}=T_{\text{hit}}+T_{\text{origin}}, because a miss still goes through the cache. Here Tmiss=12+180=192T_{\text{miss}}=12+180=192 ms and Tˉ=0.35⋅12+0.65⋅192=4.2+124.8=129 ms.\bar T=0.35\cdot12+0.65\cdot192=4.2+124.8=129\ \text{ms}. Equivalently Tˉ=192−180 h=129\bar T=192-180\,h=129 ms. Option b forgets that a miss also pays the 1212 ms of the cache (0.35⋅12+0.65⋅180=121.20.35\cdot12+0.65\cdot180=121.2); c is 0.35⋅1800.35\cdot180, which counts only the hits as if they took the origin time; d is the time without any cache. The cache pays off here since 129<180129<180, that is h>12/180≈6.7h>12/180\approx6.7 percent.

Quiz 3

A mail client sends an attachment of 10001000 bytes with MIME. The attachment is encoded in base64 (line breaks are not counted). How many characters does the encoded text contain, and how many of them are the padding character =?

  • a) 13331333 characters, no padding
  • b) 13341334 characters, one =
  • c) 13361336 characters, one =
  • d) 13361336 characters, two =
Show the result

Answer d: 13361336 characters, two =.

Show the full solution

Base64 takes 33 bytes (2424 bits) at a time and writes them as 44 characters of 66 bits each (E-mail - SMTP, POP3, IMAP and MIMEE-mail is a one-way transaction, so intermediate servers are used: two user agents (UA), push client-server programs (MTA, protocol SMTP, from sender to its server and between servers) and a pull program (MAA, POP3 or IMAP4, from the recipient's server to the recipient); SMTP uses TCP port 25 with commands HELO, MAIL FROM, RCPT TO, DATA, QUIT and three-digit replies (220 ready, 250 ok, 354 start mail input, 221 closing, 421 unavailable) in three phases (opening, transfer, closing), POP3 (port 110) downloads messages one by one after login while IMAP4 (port 143) adds header preview, search, partial download and server-side folders, and MIME turns non-ASCII data into 7-bit ASCII, for example with base64 (3 bytes become 4 characters).E-mail - SMTP, POP3, IMAP and MIME →). Since 1000=333⋅3+11000=333\cdot3+1, there are 333333 complete groups, which give 333⋅4=1332333\cdot4=1332 characters, and one byte is left. A single byte has 88 bits: it fills one group of 66 bits and a second group of 22 bits completed with zeros, so it gives 22 characters followed by ==, in total 44 characters. The length is 4⌈1000/3⌉=4⋅334=13364\lceil1000/3\rceil=4\cdot334=1336, with two padding characters (a final remainder of 22 bytes would give one =). Option a is 1000⋅4/31000\cdot4/3 rounded down, which ignores the incomplete group; b and c have the wrong length or the wrong number of =. A frequent mistake is to think that base64 encrypts: it is only an encoding, reversible by anybody.

Quiz 4

Router R1 learned the route to network N7 (cost 33) from the RIP update of its neighbour R2 received at time t=0t=0. R2 then fails and R1 never receives any other information about N7. What is the state of that route at t=200t=200 s?

  • a) It is still valid with cost 33: the router deletes a route only 300300 s after the last update.
  • b) It has expired, its cost is 1616, and it is still in the table; it will be deleted at t=300t=300 s.
  • c) It has already been deleted from the table, because it expired at t=180t=180 s.
  • d) It has expired with cost 1515 and stays in the table until t=300t=300 s.
Show the result

Answer b.

Show the full solution

In Internet Routing Protocols - RIP, OSPF and BGPInternet routing is hierarchical for scalability and administrative autonomy: each ISP is an autonomous system (AS) and uses an interior protocol inside it, either RIP (distance vector, hop count with maximum 15, updates about every 30 s, over UDP port 520) or OSPF (link state with Dijkstra, areas attached to backbone area 0, five LSA types, carried directly in IP), while BGP4 (path vector over TCP port 179, eBGP between ASes and iBGP inside) connects ASes with policy-based route choice and loop avoidance by discarding paths that contain the own AS.Internet Routing Protocols - RIP, OSPF and BGP → a RIP route has an expiration timer of 180180 s: if no update refreshes it, at t=180t=180 s the route expires and its cost becomes 1616, that is infinity (unreachable). Then the garbage-collection timer of 120120 s starts, during which the route stays in the table with cost 1616 so that the neighbours learn that it is invalid; it is deleted at 180+120=300180+120=300 s. At t=200t=200 s the route is therefore expired, with cost 1616, but not yet removed. Option a ignores the expiration timer; c forgets the 120120 s of garbage collection; d uses the wrong cost: 1515 is the largest valid cost, while 1616 means unreachable.

Quiz 5

In an OSPF autonomous system a router of area 22 must reach a network external to the AS. That network is announced by an AS boundary router (ASBR) placed in area 11. Which pair of LSA types lets the router of area 22 learn both the external network and the position of the ASBR?

  • a) types 11 and 22
  • b) types 22 and 33
  • c) types 44 and 55
  • d) types 33 and 55
Show the result

Answer c: types 44 and 55.

Show the full solution

From Internet Routing Protocols - RIP, OSPF and BGPInternet routing is hierarchical for scalability and administrative autonomy: each ISP is an autonomous system (AS) and uses an interior protocol inside it, either RIP (distance vector, hop count with maximum 15, updates about every 30 s, over UDP port 520) or OSPF (link state with Dijkstra, areas attached to backbone area 0, five LSA types, carried directly in IP), while BGP4 (path vector over TCP port 179, eBGP between ASes and iBGP inside) connects ASes with policy-based route choice and loop avoidance by discarding paths that contain the own AS.Internet Routing Protocols - RIP, OSPF and BGP →: the type 5 LSA (external link) is generated by the ASBR and announces the external network in the whole OSPF domain, but a router of another area does not know how to reach that ASBR; the area border router of area 11 therefore sends a type 4 LSA (summary link to the AS), which tells where the ASBR is. Types 11 and 22 (router link and network link) stay inside one area, and type 33 (summary link to network) announces networks of the AS, not the ASBR: so a, b and d cannot give both pieces of information.

Quiz 6

Bob chooses the RSA primes p=11p=11 and q=13q=13 and publishes the public key (N,e)=(143,7)(N,e)=(143,7). Alice wants to send him the message m=9m=9 encrypted with the plain RSA formula. Which value does she send?

  • a) 4848
  • b) 5353
  • c) 6363
  • d) 126126
Show the result

Answer a: c=48c=48.

Show the full solution

In Public-Key Cryptography, RSA and TLSPublic-key cryptography uses a public key to encrypt and a private key to decrypt; certificates issued by a Certificate Authority bind identities to public keys; digital signatures give authenticity, integrity and non-repudiation; RSA relies on the difficulty of factoring; TLS combines certificates, a symmetric session key (derived with Diffie-Hellman since TLS 1.3) and MACs.Public-Key Cryptography, RSA and TLS → encryption is c=me mod Nc=m^e\bmod N, with the recipient's public key: c=97 mod 143c=9^7\bmod143. Use square-and-multiply, reducing at each step: 92=819^2=81; 94=812=6561≡126(mod143)9^4=81^2=6561\equiv126\pmod{143} (6561=45⋅143+1266561=45\cdot143+126); 96=94⋅92≡126⋅81=10206≡539^6=9^4\cdot9^2\equiv126\cdot81=10206\equiv53 (10206=71⋅143+5310206=71\cdot143+53); 97≡53⋅9=477≡489^7\equiv53\cdot9=477\equiv48 (477=3⋅143+48477=3\cdot143+48). So c=48c=48.

Check: φ(N)=10⋅12=120\varphi(N)=10\cdot12=120, gcd⁡(7,120)=1\gcd(7,120)=1, and the private exponent is d=7−1 mod 120=103d=7^{-1}\bmod120=103 (7⋅103=721=6⋅120+17\cdot103=721=6\cdot120+1); decrypting, 48103 mod 143=948^{103}\bmod143=9. Options b and d are intermediate values of the computation (969^6 and 949^4); c is the product 7⋅97\cdot9, not a power.

Quiz 7

Alice sends Bob a message together with her digital signature, so that Bob can check authenticity, integrity and non-repudiation. Which procedure is correct?

  • a) Alice encrypts the whole message with Bob's public key; Bob decrypts it with his private key and the message is authenticated.
  • b) Alice encrypts the hash of the message with Bob's public key; Bob decrypts it with his private key and compares it with the hash he computes.
  • c) Alice encrypts the hash of the message with her public key; Bob decrypts it with Alice's private key and compares it with the hash he computes.
  • d) Alice encrypts the hash of the message with her private key; Bob decrypts the signature with Alice's public key and compares it with the hash he computes.
Show the result

Answer d.

Show the full solution

A signature uses the sender's private key and is verified with the sender's public key (Public-Key Cryptography, RSA and TLSPublic-key cryptography uses a public key to encrypt and a private key to decrypt; certificates issued by a Certificate Authority bind identities to public keys; digital signatures give authenticity, integrity and non-repudiation; RSA relies on the difficulty of factoring; TLS combines certificates, a symmetric session key (derived with Diffie-Hellman since TLS 1.3) and MACs.Public-Key Cryptography, RSA and TLS →). Alice computes the hash of the message (for example SHA-256), encrypts it with her private key and sends message and signature; Bob computes the hash of the received message, decrypts the signature with Alice's public key and accepts if the two hashes are equal. The hash is signed because it is short and fast to process. Only Alice can produce the signature (non-repudiation and authenticity), and any change of the message changes the hash (integrity).

Options a and b use the recipient's public key: that is the procedure for confidentiality, which anybody can perform (Bob's public key is public), so nobody is authenticated. Option c reverses the keys: Bob does not know Alice's private key, and anybody can encrypt with Alice's public key, so even a matching hash would prove nothing about who sent the message.

Quiz 8

A browser opens https://www.shop.example and receives the certificate of the site. Which checks must it do before trusting the public key in the certificate?

  • a) It asks the site to encrypt a random string with its private key and accepts any certificate that the site itself has signed.
  • b) It verifies the CA signature with the CA public key, going up the chain of trust to a root CA already present in the system, and checks the validity dates and that the name in the certificate matches the site.
  • c) It sends the certificate to the site's DNS server, which confirms that the IP address of the site is the one in the certificate.
  • d) It decrypts the certificate with the site's public key and accepts it if the result is readable text.
Show the result

Answer b.

Show the full solution

A certificate binds a name to a public key and is signed with the private key of a Certificate Authority; anyone who has the CA public key can verify it (Public-Key Cryptography, RSA and TLSPublic-key cryptography uses a public key to encrypt and a private key to decrypt; certificates issued by a Certificate Authority bind identities to public keys; digital signatures give authenticity, integrity and non-repudiation; RSA relies on the difficulty of factoring; TLS combines certificates, a symmetric session key (derived with Diffie-Hellman since TLS 1.3) and MACs.Public-Key Cryptography, RSA and TLS →). The browser therefore verifies the signature with the CA public key and, if the CA is not a root, goes up the chain of trust until it reaches a root CA already installed in the operating system or in the browser; it also checks that the certificate is within its validity period and that the site name matches the one requested. Only then does it use the public key to set up the session (authentication of the server).

Option a trusts a self-signed certificate: anybody can sign a certificate for any name, so it proves nothing. Option c has nothing to do with certificates: DNS maps names to addresses and does not vouch for a key. Option d is circular: the site's public key is exactly what is being certified, and "readable text" is not a signature check.

Quiz 9

A Linux router has eth0 on the private LAN 192.168.1.0/24 and eth1 on the Internet with the public address 130.10.4.2. The FORWARD chain has policy DROP. The administrator wants the web server 192.168.1.50 (port 8080) to be reachable from the Internet at the address 130.10.4.2 and port 80808080. Which pair of rules does it?

  • a) iptables --table nat --append POSTROUTING --protocol tcp --destination-port 8080 --jump DNAT --to 192.168.1.50:80 and the forwarding rule iptables --table filter --append FORWARD --protocol tcp --destination 192.168.1.50 --destination-port 80 --in-interface eth1 --out-interface eth0 --jump ACCEPT
  • b) iptables --table nat --append PREROUTING --protocol tcp --destination 130.10.4.2 --destination-port 8080 --in-interface eth1 --jump DNAT --to 192.168.1.50:80 and iptables --table filter --append FORWARD --protocol tcp --destination 192.168.1.50 --destination-port 8080 --in-interface eth1 --out-interface eth0 --jump ACCEPT
  • c) iptables --table nat --append PREROUTING --protocol tcp --destination 130.10.4.2 --destination-port 8080 --in-interface eth1 --jump DNAT --to 192.168.1.50:80 and iptables --table filter --append FORWARD --protocol tcp --destination 192.168.1.50 --destination-port 80 --in-interface eth1 --out-interface eth0 --jump ACCEPT
  • d) iptables --table nat --append PREROUTING --protocol tcp --destination 130.10.4.2 --destination-port 8080 --in-interface eth1 --jump DNAT --to 192.168.1.50:80 and iptables --table filter --append INPUT --protocol tcp --destination 192.168.1.50 --destination-port 80 --jump ACCEPT
Show the result

Answer c.

Show the full solution

From Firewall Configuration with iptables in KatharàLab 6 configures a packet-filter firewall on Linux with iptables (NetFilter): tables filter, nat, mangle and raw hold chains of rules, the first matching rule wins, otherwise the default policy applies; three experiences cover a firewall protecting a host (INPUT with DROP policy plus loopback, ping, SSH and ESTABLISHED,RELATED), a firewall on a LAN router (FORWARD) and NAT with SNAT and DNAT.Firewall Configuration with iptables in Katharà →: DNAT must act before routing, so it goes in the PREROUTING chain of the nat table; the packet then is routed towards the LAN, and since it is forwarded and not for the router itself, the filtering rule goes in FORWARD. At that point the packet already carries the translated destination 192.168.1.50:80, so the rule must test port 8080, not 80808080.

Option a puts DNAT in POSTROUTING, which is after routing and is used for SNAT; b has the correct DNAT but a FORWARD rule on port 80808080, which no packet matches any more (the packets are dropped by the policy); d uses INPUT, which sees only packets for the router: the forwarded packets would never match.

Quiz 10

An attacker sends ICMP echo requests at 500500 kbit/s to the broadcast address of a network where 120120 hosts answer, with the source address forged to be the victim's. Replies have the same size as the requests. What does the victim receive, and which security goal is attacked?

  • a) About 6060 Mbit/s of echo replies; the attack hits availability.
  • b) About 0.50.5 Mbit/s of echo requests; the attack hits availability.
  • c) About 6060 Mbit/s of echo replies; the attack hits confidentiality.
  • d) About 4.24.2 kbit/s of echo replies; the attack hits availability.
Show the result

Answer a.

Show the full solution

This is the Smurf attack of Network Security - Threats and AttacksA threat is any event that can violate a security goal (confidentiality, integrity, availability, accountability, privacy) and its realisation is an attack; security services and mechanisms counter the threats, and sniffing and spoofing underlie the main network attacks, DoS and man-in-the-middle.Network Security - Threats and Attacks →: the broadcast request is answered by every host, and the replies go to the forged source address, that is to the victim. The amplification factor equals the number of answering hosts, 120120, so the victim receives 120⋅0.5=60120\cdot0.5=60 Mbit/s of echo replies, enough to saturate a Fast Ethernet link. The goal hit is availability (a denial of service): the attacker does not read or change any data of the victim. Option b forgets that the victim never sees the requests (the attacker's address is not in the replies) and ignores the amplification; c has the right traffic but the wrong goal (confidentiality is violated by eavesdropping, not by flooding); d divides by 120120 instead of multiplying. Today the attack is rare, since routers normally do not forward directed broadcasts.

Practical module

Exercise 1 (points 12)

Host A (client) and host B (server) are connected through the routers R1 and R2 in a chain; the links are:

link ends capacity propagation
L1L_1 A - R1 5050 Mbit/s 22 ms
L2L_2 R1 - R2 66 Mbit/s 55 ms
L3L_3 R2 - B 3030 Mbit/s 33 ms

The routers work in store-and-forward mode. Segments carry MSS=1500\text{MSS}=1500 bytes; headers, SYN, ACK and processing times are negligible (only transmission and propagation count). B acknowledges every segment as soon as it arrives. Neglect all other traffic.

(a) (3 points) Connection opening and flow control. The initial sequence numbers are 70007000 for A and 52 00052\,000 for B; A announces rwnd=30 000\text{rwnd}=30\,000 bytes and B announces rwnd=15 000\text{rwnd}=15\,000 bytes (constant). A sends its first data segment together with the third segment of the opening.

  1. Give flags, sequence number, acknowledgment number and window of the three segments of the three-way handshake.
  2. Give the sequence and acknowledgment numbers of the first two data segments sent by A and of the ACK sent by B for the first one.
  3. Compute the RTT of a segment (from the start of its transmission to the arrival of its ACK), the bandwidth-delay product of the connection in segments, and the send window swnd∗\text{swnd}^* that allows a continuous flow. Does the window announced by B allow a continuous flow? What is the highest throughput that flow control alone would allow?

(b) (3 points) Transfer with a timeout. A sends a file of M=150 000M=150\,000 bytes. Initially cwnd=1\text{cwnd}=1 MSS and ssthresh=9000\text{ssthresh}=9000 bytes; data start as soon as possible after the opening. Time 00 is the instant A sends the SYN; the transfer ends when the last ACK arrives. Use the round convention of the course (in each round the sender sends a window and waits for its ACKs; if cwnd<ssthresh\text{cwnd}<\text{ssthresh} it goes to min⁡(2 cwnd,ssthresh)\min(2\,\text{cwnd},\text{ssthresh}), otherwise it adds 11 MSS; swnd=min⁡(cwnd,rwnd)\text{swnd}=\min(\text{cwnd},\text{rwnd})).

  1. Compute the total time if there are no losses.
  2. Now all the segments of the sixth window are lost (a burst), so no ACK comes back. The retransmission timeout is RTO=60\text{RTO}=60 ms, counted from the instant the first segment of the lost window is sent. After the timeout the segments are sent again with the rules of the course. Compute ssthresh\text{ssthresh} after the timeout, the window of every round and the total time.

(c) (2 points) Throughput and analytical model.

  1. Compute the average throughput (goodput) of the transfer of point (b.2) in Mbit/s, and its ratio to the bottleneck capacity.
  2. Consider now a very long transfer on the same path in congestion avoidance, with b=1b=1 (one ACK per segment), T0=1T_0=1 s and maximum window Wmax⁡=rwndW_{\max}=\text{rwnd}. The packets are lost independently on the links with probabilities 0.0020.002 on L1L_1, 0.010.01 on L2L_2 and 0.0030.003 on L3L_3. Compute the loss probability pp of the path, the send rate BB of the approximate model in segments per second and in Mbit/s (including the window cap), and say why it differs from the throughput of point (c.1).

(d) (2 points) Slotted ALOHA. Several stations share a 44 Mbit/s channel with slotted ALOHA; frames have 15001500 bytes and the slot is equal to the frame time. The new frames of all stations form a Poisson process of rate λ=45\lambda=45 frames/s. The propagation time is τp=0.3\tau_p=0.3 ms and the mean backoff is E[tb]=6E[t_b]=6 ms.

  1. Find the two offered loads GG compatible with the throughput, say which one is stable, and compute the success probability and the mean number of retransmissions per frame at the stable point.
  2. Compute the mean delay of a frame at the stable point.
  3. What is the largest rate λ\lambda for which a stable operating point exists?

(e) (2 points) Non-persistent CSMA. The same stations, on the same channel and with the same frames, use non-persistent CSMA with an offered load G=2G=2. Compute the throughput SS (normalized and in Mbit/s) for τp=0.3\tau_p=0.3 ms and for τp=3\tau_p=3 ms, and compare it with slotted ALOHA at the same GG and with its maximum.

Show the result

(a)

  1. SYN: SN =7000=7000, window 30 00030\,000. SYN+ACK: SN =52 000=52\,000, AN =7001=7001, window 15 00015\,000. ACK: SN =7001=7001, AN =52 001=52\,001, window 30 00030\,000.
  2. First data segment SN =7001=7001 (AN =52 001=52\,001), second SN =8501=8501 (AN =52 001=52\,001); B's ACK: SN =52 001=52\,001, AN =8501=8501, window 15 00015\,000.
  3. RTT=22.64\text{RTT}=22.64 ms; BDP=135.84\text{BDP}=135.84 kbit =11.32=11.32 MSS; swnd∗=12\text{swnd}^*=12 MSS. rwnd=10\text{rwnd}=10 MSS <12<12: not continuous. Flow control alone allows 10⋅12 000/22.64 ms=5.3010\cdot12\,000/22.64\ \text{ms}=5.30 Mbit/s (about 88.388.3 percent of the bottleneck).

(b)

  1. T=340.96T=340.96 ms (windows 1,2,4,6,7,8,9,10,10,10,10,10,10,31,2,4,6,7,8,9,10,10,10,10,10,10,3).
  2. ssthresh=4\text{ssthresh}=4 MSS; windows after the timeout 1,2,4,5,6,7,8,9,10,10,10,81,2,4,5,6,7,8,9,10,10,10,8; T=478.88T=478.88 ms (the loss costs 137.92137.92 ms).

(c)

  1. 2.5062.506 Mbit/s (208.8208.8 segments/s), 41.841.8 percent of 66 Mbit/s.
  2. p=0.014944p=0.014944; B=174.85B=174.85 segments/s =2.098=2.098 Mbit/s (the cap Wmax⁡/RTT=441.7W_{\max}/\text{RTT}=441.7 segments/s does not apply); the model is about 1616 percent below the measured goodput of the short transfer.

(d)

  1. tF=3t_F=3 ms, λtF=0.135\lambda t_F=0.135: G1=0.158G_1=0.158 (stable) and G2=3.15G_2=3.15 (unstable); PS=0.854P_S=0.854; 0.1710.171 retransmissions per frame.
  2. E[T]=6.70E[T]=6.70 ms.
  3. λmax⁡=1/(e tF)=122.6\lambda_{\max}=1/(e\,t_F)=122.6 frames/s.

(e) a=0.1a=0.1: S=0.509S=0.509 (2.032.03 Mbit/s); a=1a=1: S=0.044S=0.044 (0.180.18 Mbit/s). Slotted ALOHA at G=2G=2: 0.2710.271; maximum 1/e=0.3681/e=0.368.

Show the full solution

(a) Opening and flow control. The three-way handshake of TCP - Connection, Reliability and Flow ControlTCP is the connection-oriented, reliable transport protocol that turns IP's unreliable service into an ordered byte stream without errors or duplicates; the connection opens with a three-way handshake (SYN, SYN+ACK, ACK) and closes with FIN segments, bytes are numbered (sequence number = first byte of the segment, cumulative ACK = next byte expected), the sender may transmit min(rwnd, cwnd) unacknowledged bytes (rwnd, the receiver window in a 16-bit field, is flow control), errors are handled with checksum, ACKs, retransmission timeout and fast retransmit after three duplicate ACKs, and to fill the pipe the window must reach the bandwidth-delay product, with maximum throughput MSS times Wmax over RTT.TCP - Connection, Reliability and Flow Control →: SYN and FIN consume one sequence number, a plain ACK none. The window field of each segment is the receive window announced by its sender.

segment from flags SN AN window
1 A to B SYN 70007000 none 30 00030\,000
2 B to A SYN, ACK 52 00052\,000 70017001 15 00015\,000
3 A to B ACK (with the first data) 70017001 52 00152\,001 30 00030\,000

B's SYN consumed the number 52 00052\,000, so its next byte is 52 00152\,001: the AN of A's segments stays 52 00152\,001 because B sends no data. A's SYN consumed 70007000, so the first data byte is 70017001. The first data segment (SN =7001=7001) carries bytes 70017001 to 85008500; the second has SN =7001+1500=8501=7001+1500=8501. B acknowledges the first with AN =8501=8501 (next byte expected); its own SN is 52 00152\,001 and the window stays 15 00015\,000 if the application reads at once.

Times. Transmission time of a segment T=L/CT=L/C with L=1500⋅8=12 000L=1500\cdot8=12\,000 bit: L1L_1: 12 000/(50⋅106)=0.2412\,000/(50\cdot10^6)=0.24 ms; L2L_2: 12 000/(6⋅106)=212\,000/(6\cdot10^6)=2 ms; L3L_3: 12 000/(30⋅106)=0.412\,000/(30\cdot10^6)=0.4 ms. A data segment arrives at B after 0.24+2+2+5+0.4+3=12.640.24+2+2+5+0.4+3=12.64 ms (store-and-forward: each link transmits the whole segment after it has been received); the ACK is negligible and takes only the propagations back: 3+5+2=103+5+2=10 ms. Hence RTT=12.64+10=22.64 ms.\text{RTT}=12.64+10=22.64\ \text{ms}. The bottleneck is L2L_2 (66 Mbit/s): one segment every Tb=2T_b=2 ms. The BDP is 6 Mbit/s⋅22.64 ms=135 8406\ \text{Mbit/s}\cdot22.64\ \text{ms}=135\,840 bit, that is 135 840/12 000=11.32135\,840/12\,000=11.32 MSS (equivalently RTT/Tb=22.64/2\text{RTT}/T_b=22.64/2). To keep the bottleneck always busy at least 11.3211.32 segments must be in flight, so swnd∗=⌈11.32⌉=12\text{swnd}^*=\lceil11.32\rceil=12 MSS. B announces 15 000/1500=1015\,000/1500=10 MSS <12<12: the sender can never fill the pipe, flow control is the limit (the network is not saturated). With 1010 segments per RTT the maximum throughput is 10⋅12 000 bit22.64 ms=5.30 Mbit/s,\frac{10\cdot12\,000\ \text{bit}}{22.64\ \text{ms}}=5.30\ \text{Mbit/s}, that is 10/11.32=88.310/11.32=88.3 percent of the bottleneck. Typical errors: using L1L_1 as bottleneck (it is the fastest link); counting the transmission time in the ACK; rounding 11.3211.32 down to 1111.

(b) Transfer with a timeout. The file has 150 000/1500=100150\,000/1500=100 segments; ssthresh=9000/1500=6\text{ssthresh}=9000/1500=6 MSS and rwnd=10\text{rwnd}=10 MSS. The opening takes 2⋅(2+5+3)=202\cdot(2+5+3)=20 ms (SYN and SYN+ACK have negligible length, only propagation), and the data start at t=20t=20 ms (TCP Congestion ControlCongestion arises when fast links feed a slow one, router queues fill and packets are lost or delayed, possibly up to network collapse; TCP controls its congestion window cwnd using loss feedback (timeout or three duplicate ACKs): slow start doubles cwnd every RTT up to the threshold ssthresh, then congestion avoidance adds 1 MSS per RTT, and on a loss ssthresh becomes W/2; variants differ in reaction to three dupACKs: Tahoe restarts from cwnd=1, Reno uses fast recovery (ssthresh=cwnd/2, cwnd=ssthresh+3, +1 per further dupACK), NewReno handles partial ACKs and recovers several losses in one window, SACK acknowledges received blocks and resends only what is missing.TCP Congestion Control →).

(b.1) No losses. Windows: 1→2→4→61\to2\to4\to6 (the doubling stops at ssthresh=6\text{ssthresh}=6: min⁡(8,6)\min(8,6)), then congestion avoidance 7,8,9,107,8,9,10 and rwnd\text{rwnd} keeps it at 1010. Segments sent: 1,2,4,6,7,8,9,101,2,4,6,7,8,9,10 give 4747; then five windows of 1010 give 9797; the last window has the remaining 33. All the windows are below the BDP of 11.3211.32 MSS, so each round lasts one RTT (the sender sends the window and waits for the first ACK). The last window (33 segments) ends (3−1)Tb(3-1)T_b after its first segment arrives, plus the RTT: T=20+13⋅22.64+[22.64+(3−1)⋅2]=20+294.32+26.64=340.96 ms.T=20+13\cdot22.64+\big[22.64+(3-1)\cdot2\big]=20+294.32+26.64=340.96\ \text{ms}. The 1313 full rounds are those of the first 1313 windows; the last has RTT+(n−1)Tb\text{RTT}+(n-1)T_b.

(b.2) Loss of the sixth window. The windows before are 1,2,4,6,71,2,4,6,7 (2020 segments delivered); the sixth would be 88 MSS (7+17+1) and is lost completely. Nothing arrives, so no duplicate ACKs are generated: only the timeout can detect the loss (TCP Retransmission Timeout EstimationTCP retransmits a segment when its ACK does not arrive within the retransmission timeout RTO, which must track the round-trip time: too short causes spurious retransmissions, too long slows recovery; the RTT is measured with one timer per connection, smoothed with an exponential moving average SRTT = (1-alpha) SRTT + alpha rtt with alpha = 1/8, the mean deviation MAD = (1-rho) MAD + rho |rtt - SRTT| with rho = 1/4 is added four times, RTO = SRTT + 4 MAD with a minimum of 1 s, Karn's algorithm ignores samples of retransmitted segments and doubles the RTO at each consecutive timeout up to 64 times, and for a Gaussian RTT the mean deviation equals sigma times the square root of 2 over pi, about 0.797 sigma.TCP Retransmission Timeout Estimation → for the RTO). At the timeout the window in flight was W=min⁡(8,10)=8W=\min(8,10)=8 MSS: ssthresh=W2=4 MSS,cwnd=1 MSS,\text{ssthresh}=\frac W2=4\ \text{MSS},\qquad\text{cwnd}=1\ \text{MSS}, and a new slow start begins (a timeout is a severe signal, so cwnd=1\text{cwnd}=1 and not ssthresh+3\text{ssthresh}+3). The segments of the lost window are sent again, together with the rest of the file: 100−20=80100-20=80 segments remain. Windows after the timeout: 1,2,41,2,4 (reaching ssthresh=4\text{ssthresh}=4), then congestion avoidance 5,6,7,8,9,105,6,7,8,9,10 and 10,1010,10 limited by rwnd\text{rwnd}, last 88; check 1+2+4+5+6+7+8+9+10+10+10+8=801+2+4+5+6+7+8+9+10+10+10+8=80.

round window (MSS) segments delivered in all start (ms)
1 1 1 20.00
2 2 3 42.64
3 4 7 65.28
4 6 13 87.92
5 7 20 110.56
6 8, all lost 20 133.20
timeout 133.20+60=193.20133.20+60=193.20
7 1 21 193.20
8 2 23 215.84
9 4 27 238.48
10 5 32 261.12
11 6 38 283.76
12 7 45 306.40
13 8 53 329.04
14 9 62 351.68
15 10 72 374.32
16 10 82 396.96
17 10 92 419.60
18 8 100 442.24

Every window is below 11.3211.32, so each round lasts 22.6422.64 ms; the last window of 88 segments needs RTT+(8−1)⋅2\text{RTT}+(8-1)\cdot2 more: T=20+5 RTT+RTO+11 RTT+[RTT+(8−1)Tb]=20+17⋅22.64+60+14=478.88 ms.T=20+5\,\text{RTT}+\text{RTO}+11\,\text{RTT}+\big[\text{RTT}+(8-1)T_b\big]=20+17\cdot22.64+60+14=478.88\ \text{ms}. The timeout costs 478.88−340.96=137.92478.88-340.96=137.92 ms: the 6060 ms of waiting, plus the rounds spent in slow start and in the reduced congestion avoidance. Typical errors: computing ssthresh\text{ssthresh} from a window of 1010 (the window really in flight was 88); keeping cwnd=ssthresh+3\text{cwnd}=\text{ssthresh}+3 as after three duplicate ACKs; counting the lost segments as delivered; forgetting that after ssthresh=4\text{ssthresh}=4 the growth is linear.

(c) Throughput and model.

(c.1) The goodput is the file size over the total time: 150 000⋅8/0.47888 s=1.2⋅106 bit/0.47888 s=2.506150\,000\cdot8/0.47888\ \text{s}=1.2\cdot10^6\ \text{bit}/0.47888\ \text{s}=2.506 Mbit/s (208.8208.8 segments/s), that is 2.506/6=41.82.506/6=41.8 percent of the bottleneck capacity: far below the 5.305.30 Mbit/s allowed by flow control, because of the slow start phases and the timeout.

(c.2) The loss probability of the path is the complement of the probability that a packet survives all the links: p=1−(1−0.002)(1−0.01)(1−0.003)=1−0.998⋅0.99⋅0.997=0.014944.p=1-(1-0.002)(1-0.01)(1-0.003)=1-0.998\cdot0.99\cdot0.997=0.014944. The approximate model of Analytical Model of TCP Send RateThe analytical model gives the long-term send rate B (segments per second) of a TCP Reno flow as a function of the loss probability p, the RTT, the delayed-ACK parameter b and the timeout T0; time is divided into rounds of one RTT, the window cycle between two losses signalled by three duplicate ACKs (TDP) has mean window E[W] = (2-3b)/(3b) + sqrt(((3b-2)/(3b))^2 + 8(1-p)/(3bp)) and the rate is B = E[Y]/E[A], which for small p gives the square-root formula B = (1/RTT) sqrt(3/(2bp)) (about 1.22/(RTT sqrt p) for b=1 and 0.87/(RTT sqrt p) for b=2); timeouts add the probability Q that a loss ends in timeout, giving B = (E[Y] + Q E[R]) / (E[A] + Q E[Z_TO]), and a maximum window Wmax caps the rate at Wmax/RTT.Analytical Model of TCP Send Rate → with b=1b=1, T0=1T_0=1 s, RTT=22.64\text{RTT}=22.64 ms:

  • first term: RTT2bp3=0.02264⋅0.0099627=0.02264⋅0.099813=0.0022598\text{RTT}\sqrt{\dfrac{2bp}3}=0.02264\cdot\sqrt{0.0099627}=0.02264\cdot0.099813=0.0022598 s;
  • timeout probability: 33bp8=3⋅0.0056040=3⋅0.074860=0.224583\sqrt{\dfrac{3bp}8}=3\cdot\sqrt{0.0056040}=3\cdot0.074860=0.22458, below 11, so min⁡{1,0.22458}=0.22458\min\{1,0.22458\}=0.22458;
  • p(1+2p+4p2)=0.014944⋅(1+0.029888+0.000893)=0.014944⋅1.030781=0.015404p(1+2p+4p^2)=0.014944\cdot(1+0.029888+0.000893)=0.014944\cdot1.030781=0.015404; second term: T0⋅0.22458⋅0.015404=0.0034594T_0\cdot0.22458\cdot0.015404=0.0034594 s;
  • B=10.0022598+0.0034594=10.0057192=174.85B=\dfrac1{0.0022598+0.0034594}=\dfrac1{0.0057192}=174.85 segments/s.

The cap is Wmax⁡/RTT=10/0.02264=441.7W_{\max}/\text{RTT}=10/0.02264=441.7 segments/s: not binding, B=174.85B=174.85 segments/s. In bits, 174.85⋅12 000=2.098174.85\cdot12\,000=2.098 Mbit/s (not 174.85⋅1500174.85\cdot1500: the payload must be converted to bits). The goodput of the model would be B(1−p)=2.067B(1-p)=2.067 Mbit/s.

The model gives 2.102.10 Mbit/s against 2.512.51 Mbit/s of the transfer (about 1616 percent less), and the two numbers are not expected to coincide: the model describes the long-term average of a flow in congestion avoidance with random independent losses and a timeout of T0=1T_0=1 s, while the transfer is short, starts with slow start (not modelled) and has a single burst loss with a timeout of 6060 ms. The simple square-root formula 1RTT3/(2bp)=442.5\frac1{\text{RTT}}\sqrt{3/(2bp)}=442.5 segments/s would ignore the timeouts and be wrong by a factor 2.52.5: at p≈1.5p\approx1.5 percent timeouts matter.

(d) Slotted ALOHA. Frame time tF=12 000/(4⋅106)=3t_F=12\,000/(4\cdot10^6)=3 ms; in steady state the throughput equals the new traffic, S=λtF=45⋅0.003=0.135S=\lambda t_F=45\cdot0.003=0.135 (Performance of Multiple Access ProtocolsWith Poisson arrivals, the success probability of a frame is the probability that no other frame arrives in the vulnerable time: pure ALOHA P_S = e^(-2G), throughput S = G e^(-2G) with maximum 1/(2e) = 0.18 at G = 1/2; slotted ALOHA S = G e^(-G) with maximum 1/e = 0.37 at G = 1; non-persistent CSMA with a = tau_p/t_F: S = G e^(-aG) / (G(1+2a) + e^(-aG)), which tends to 1 as a tends to 0 but collapses for large a, where slotted ALOHA is better. For TDMA (M/D/1) E[T] = t_F (N_u/2 + S N_u / (2(1-S)) + 1 + a) and for FDMA E[T] = t_F (N_u + S N_u / (2(1-S)) + a): FDMA is slower by t_F (N_u/2 - 1).Performance of Multiple Access Protocols →, Multiple Access Protocols - ALOHA and CSMAWhen several stations share a medium a medium access (MAC) protocol must decide who transmits. Random access: pure ALOHA (transmit immediately, vulnerable time 2 t_F), slotted ALOHA (start only at slot boundaries, vulnerable t_F), CSMA (listen before talking, vulnerable tau_p) with 1-persistent, non-persistent and p-persistent variants, CSMA/CD (detects collisions while transmitting: needs t_F >= 2 tau_p, hence a minimum frame) and the Wi-Fi CSMA/CA (IFS, contention window with backoff, ACK, RTS/CTS and NAV). Controlled access: reservation, polling, token. Channelization: FDMA, TDMA, OFDMA, CDMA, SDMA.Multiple Access Protocols - ALOHA and CSMA →).

(d.1) For slotted ALOHA S=Ge−GS=Ge^{-G}, so Ge−G=0.135Ge^{-G}=0.135 has two solutions. Low branch: G=0.135 eGG=0.135\,e^{G} starting from 0.1350.135 gives 0.1545, 0.1576, 0.1580, 0.1581→G1=0.1580.1545,\ 0.1576,\ 0.1580,\ 0.1581\to G_1=0.158. High branch: G=ln⁡(G/0.135)G=\ln(G/0.135) starting from 33 gives 3.10, 3.134, 3.145, 3.149→G2=3.153.10,\ 3.134,\ 3.145,\ 3.149\to G_2=3.15. The point G1G_1 is stable (if GG rises, SS is above the arrival rate and the load decreases); G2G_2 is unstable (a peak of traffic beyond it makes the load grow without limit). At G1G_1: PS=e−G1=e−0.158=0.854,E[nretx]=eG1−1=0.171.P_S=e^{-G_1}=e^{-0.158}=0.854,\qquad E[n_{\text{retx}}]=e^{G_1}-1=0.171. Check: S=G1PS=0.158⋅0.854=0.135S=G_1P_S=0.158\cdot0.854=0.135 ✓.

(d.2) Mean delay: E[T]=3tF2+τp+(eG−1)(3tF2+2τp+E[tb])E[T]=\dfrac{3t_F}2+\tau_p+(e^{G}-1)\Big(\dfrac{3t_F}2+2\tau_p+E[t_b]\Big). The fixed part is 4.5+0.3=4.84.5+0.3=4.8 ms; each retransmission costs 4.5+0.6+6=11.14.5+0.6+6=11.1 ms; so E[T]=4.8+0.171⋅11.1=6.70E[T]=4.8+0.171\cdot11.1=6.70 ms.

(d.3) A stable point exists only if λtF≤Smax⁡=1/e\lambda t_F\le S_{\max}=1/e, that is λmax⁡=1e tF=12.71828⋅0.003=122.6\lambda_{\max}=\dfrac1{e\,t_F}=\dfrac1{2.71828\cdot0.003}=122.6 frames/s (G=1G=1 there); above it the system is never stable. Typical errors: using S=Ge−2GS=Ge^{-2G} (pure ALOHA); choosing G2G_2 as the operating point; forgetting the half slot of waiting in the delay.

(e) Non-persistent CSMA. The formula of the notes is S=G e−aGG(1+2a)+e−aGS=\dfrac{G\,e^{-aG}}{G(1+2a)+e^{-aG}} with a=τp/tFa=\tau_p/t_F.

  • τp=0.3\tau_p=0.3 ms: a=0.1a=0.1, e−0.2=0.8187e^{-0.2}=0.8187: S=2⋅0.81872⋅1.2+0.8187=1.63753.2187=0.509S=\dfrac{2\cdot0.8187}{2\cdot1.2+0.8187}=\dfrac{1.6375}{3.2187}=0.509, that is 0.509⋅4=2.030.509\cdot4=2.03 Mbit/s.
  • τp=3\tau_p=3 ms: a=1a=1, e−2=0.1353e^{-2}=0.1353: S=2⋅0.13532⋅3+0.1353=0.27076.1353=0.0441S=\dfrac{2\cdot0.1353}{2\cdot3+0.1353}=\dfrac{0.2707}{6.1353}=0.0441, that is 0.180.18 Mbit/s.

Slotted ALOHA at G=2G=2 gives S=2e−2=0.271S=2e^{-2}=0.271 (1.081.08 Mbit/s) and cannot exceed 1/e=0.3681/e=0.368. With a short propagation time (a=0.1a=0.1) CSMA at G=2G=2 delivers more than slotted ALOHA can ever do (0.509>0.3680.509>0.368); with a=1a=1 the sensing information is old, many frames collide in the vulnerable period and CSMA falls far below slotted ALOHA (0.044<0.2710.044<0.271). Typical errors: using a=τpa=\tau_p in seconds instead of τp/tF\tau_p/t_F; applying the CSMA formula with GG as a rate; comparing at equal throughput instead of equal GG.

Exercise 2 (points 8)

A company network is emulated with Katharà. The firewall fw is a Linux router with three interfaces; r2 is an internal router. The devices and the addresses are:

device interface collision domain address
pc1 eth0 A 192.168.20.10/24
r2 eth0 A 192.168.20.253/24
r2 eth1 B 192.168.21.254/24
pc2 eth0 B 192.168.21.10/24
fw eth0 A 192.168.20.254/24
fw eth1 C 192.168.30.14/28
fw eth2 D 151.12.50.2/30
web eth0 C 192.168.30.2/28
mail eth0 C 192.168.30.3/28
isp eth0 D 151.12.50.1/30
isp eth1 E 93.50.8.1/24
ext eth0 E 93.50.8.10/24

A is the office LAN, B the laboratory network behind r2, C the DMZ with the web and mail servers, D the link to the provider, E the network of an external host. The devices isp and ext are already configured: isp has only its two interface networks and no other route, ext has isp as default gateway. The company has the single public address 151.12.50.2. The policy of fw is:

  1. LAN A and network B (together 192.168.20.0/23) can start any connection towards the Internet, with NAT; they can use only the web server (TCP 8080) and the mail server (TCP 2525) in the DMZ; pc1 and pc2 must reach each other without crossing fw.
  2. From the Internet only TCP 8080 to the web server and TCP 2525 to the mail server are accepted, through the public address of fw; nothing else, not even ping to fw.
  3. The DMZ servers can start connections to the Internet only for DNS (UDP 5353) and, for the mail server only, SMTP (TCP 2525); nothing is allowed from the DMZ towards A and B.
  4. fw is managed with SSH (TCP 2222) only from pc1; fw itself can send anything. Replies to allowed connections always pass. Policies are restrictive (DROP) and rules are listed in a sensible order.

(a) (3 points) Write the lab.conf, the startup commands (interfaces and static routes) of fw, r2 and pc1, the route -n table of fw, and the command lines for pc2 and web. Explain why isp needs no static route, and what would happen to a ping from pc2 to ext if the NAT were missing.

(b) (3 points) Write the iptables commands that configure fw according to the policy (policies, INPUT, FORWARD, nat), numbering the filter rules.

(c) (2 points) For each of the following packets arriving at fw say, following the path of the packet, which rule decides (or the policy), whether it is accepted or dropped, and which translation is applied:

  • P1: from pc1 192.168.20.10:41000 to 93.50.8.10:443, TCP SYN.
  • P2: from ext 93.50.8.10:50000 to 151.12.50.2:80, TCP SYN.
  • P3: from ext 93.50.8.10:50001 to 151.12.50.2:22, TCP SYN.
  • P4: from web 192.168.30.2:45000 to pc1 192.168.20.10:22, TCP SYN.
  • P5: from pc2 192.168.21.10:42000 to mail 192.168.30.3:25, TCP SYN.
  • P6: from pc2 192.168.21.10:43000 to fw at 192.168.20.254:22, TCP SYN.
  • P7: from web 192.168.30.2:80 to 93.50.8.10:50000, TCP SYN+ACK, reply to P2.
  • P8: from mail 192.168.30.3:46000 to 93.50.8.10:25, TCP SYN.
Show the result

(a) lab.conf: pc1[0]=A; r2[0]=A; r2[1]=B; pc2[0]=B; fw[0]=A; fw[1]=C; fw[2]=D; web[0]=C; mail[0]=C; isp[0]=D; isp[1]=E; ext[0]=E.

bash
# fw.startup
ifconfig eth0 192.168.20.254/24 up
ifconfig eth1 192.168.30.14/28 up
ifconfig eth2 151.12.50.2/30 up
route add -net 192.168.21.0/24 gw 192.168.20.253 dev eth0
route add default gw 151.12.50.1 dev eth2

# r2.startup
ifconfig eth0 192.168.20.253/24 up
ifconfig eth1 192.168.21.254/24 up
route add default gw 192.168.20.254 dev eth0

# pc1.startup
ifconfig eth0 192.168.20.10/24 up
route add -net 192.168.21.0/24 gw 192.168.20.253 dev eth0
route add default gw 192.168.20.254 dev eth0

# pc2.startup
ifconfig eth0 192.168.21.10/24 up
route add default gw 192.168.21.254 dev eth0

# web.startup (mail.startup: address 192.168.30.3/28)
ifconfig eth0 192.168.30.2/28 up
route add default gw 192.168.30.14 dev eth0

Table of fw (five rows):

Destination Gateway Genmask Flags Iface
151.12.50.0 * 255.255.255.252 U eth2
192.168.20.0 * 255.255.255.0 U eth0
192.168.21.0 192.168.20.253 255.255.255.0 UG eth0
192.168.30.0 * 255.255.255.240 U eth1
0.0.0.0 151.12.50.1 0.0.0.0 UG eth2

isp needs no route because the packets reach it with source 151.12.50.2 (SNAT) and the replies go back to a directly connected network. Without NAT the echo requests of pc2 would arrive at ext with the private source 192.168.21.10, but isp has no route for it: the replies are not delivered and the ping gets 100100 percent loss.

(b)

bash
iptables --table filter --policy INPUT DROP
iptables --table filter --policy FORWARD DROP
iptables --table filter --policy OUTPUT ACCEPT
# INPUT
iptables --table filter --append INPUT --in-interface lo --jump ACCEPT                                        # I1
iptables --table filter --append INPUT --match state --state ESTABLISHED,RELATED --jump ACCEPT                # I2
iptables --table filter --append INPUT --protocol tcp --destination-port 22 --in-interface eth0 --source 192.168.20.10 --jump ACCEPT   # I3
# FORWARD
iptables --table filter --append FORWARD --match state --state ESTABLISHED,RELATED --jump ACCEPT              # F1
iptables --table filter --append FORWARD --in-interface eth0 --out-interface eth2 --source 192.168.20.0/23 --jump ACCEPT   # F2
iptables --table filter --append FORWARD --in-interface eth0 --out-interface eth1 --protocol tcp --destination 192.168.30.2 --destination-port 80 --jump ACCEPT   # F3
iptables --table filter --append FORWARD --in-interface eth0 --out-interface eth1 --protocol tcp --destination 192.168.30.3 --destination-port 25 --jump ACCEPT   # F4
iptables --table filter --append FORWARD --in-interface eth2 --out-interface eth1 --protocol tcp --destination 192.168.30.2 --destination-port 80 --jump ACCEPT   # F5
iptables --table filter --append FORWARD --in-interface eth2 --out-interface eth1 --protocol tcp --destination 192.168.30.3 --destination-port 25 --jump ACCEPT   # F6
iptables --table filter --append FORWARD --in-interface eth1 --out-interface eth2 --protocol tcp --source 192.168.30.3 --destination-port 25 --jump ACCEPT   # F7
iptables --table filter --append FORWARD --in-interface eth1 --out-interface eth2 --protocol udp --destination-port 53 --jump ACCEPT   # F8
# NAT
iptables --table nat --append PREROUTING --protocol tcp --destination 151.12.50.2 --destination-port 80 --in-interface eth2 --jump DNAT --to 192.168.30.2:80
iptables --table nat --append PREROUTING --protocol tcp --destination 151.12.50.2 --destination-port 25 --in-interface eth2 --jump DNAT --to 192.168.30.3:25
iptables --table nat --append POSTROUTING --source 192.168.20.0/23 --out-interface eth2 --jump SNAT --to 151.12.50.2
iptables --table nat --append POSTROUTING --source 192.168.30.0/28 --out-interface eth2 --jump SNAT --to 151.12.50.2

(c)

packet decided by outcome translation
P1 FORWARD F2 accepted SNAT: source becomes 151.12.50.2:41000
P2 FORWARD F5 (after DNAT) accepted DNAT: destination becomes 192.168.30.2:80
P3 INPUT policy dropped none
P4 FORWARD policy dropped none
P5 FORWARD F4 accepted none
P6 INPUT policy dropped none
P7 FORWARD F1 (ESTABLISHED) accepted source restored to 151.12.50.2:80 (reverse of the DNAT)
P8 FORWARD F7 accepted SNAT: source becomes 151.12.50.2:46000
Show the full solution

(a) Addresses and routes. Katharà (Emulating Networks with KatharàKatharà is a network emulator where every device is a Docker container joined to virtual collision domains; a lab is a folder with lab.conf (topology), one .startup file per machine and optional per-device folders; machines are configured with ifconfig, tested with ping and observed with tcpdump and Wireshark.Emulating Networks with Katharà →): each line device[i]=domain puts the interface eth i in a collision domain; devices in the same domain are on the same network. Check of the addressing: A 192.168.20.0/24, B 192.168.21.0/24, C 192.168.30.0/28 (mask 255.255.255.240, 1616 addresses, hosts .1 to .14, broadcast .15: the router takes the last usable address .14), D 151.12.50.0/30 (mask 255.255.255.252, hosts .1 and .2, broadcast .3: the minimum for a point-to-point link, Subnetting, VLSM and SupernettingSubnetting splits an address block into smaller subnets by lengthening the mask (2^s subnets when s bits are borrowed), supernetting does the opposite by shortening the prefix to merge contiguous blocks; design rules for variable-size subnets are power-of-two sizes M with M at least hosts plus 2, prefix 32 minus log2 M, and start addresses divisible by M (largest subnet first), while 2^j blocks of prefix n aggregate into one block of prefix n minus j only if contiguous and aligned.Subnetting, VLSM and Supernetting →), E 93.50.8.0/24. The two office networks aggregate into 192.168.20.0/23 (mask 255.255.254.0), and the DMZ block is outside it: a single /23 match in the rules is correct for A and B only.

Static routes (Static Routing and Diagnostic Tools in KatharàLab 2 builds by hand the routing tables of two LANs (195.11.14.0/24 and 200.1.1.0/24) joined by routers r1 and r2 over 100.0.0.8/30: an active interface adds only its directly connected network, hosts use a default route, routers need static routes in both directions, and ping, route -n, tcpdump and traceroute diagnose the result (ttl=62 after two routers).Static Routing and Diagnostic Tools in Katharà →, Forwarding and Routing TablesForwarding moves each packet one hop at a time toward its destination; it is direct when the destination is on a local network (ARP gives its MAC) and indirect otherwise (the packet goes to the next hop or default gateway given by the routing table). With netmasks, delivery is direct on interface x if the destination AND the mask equals the interface address AND the mask; otherwise the table is scanned from the longest mask (longest prefix match) and the default route 0.0.0.0/0 always matches; route aggregation shortens tables.Forwarding and Routing Tables →). When an interface is activated its network enters the table; everything else must be added.

  • fw: connected networks D, A and C; network B is behind r2, which is on the network A, so route add -net 192.168.21.0/24 gw 192.168.20.253 dev eth0 (the gateway must be directly reachable on eth0); everything else (Internet) goes through the provider with the default route. The Internet addresses (for example 93.50.8.10) match only the default route, the private B matches the /24 (longest prefix).
  • r2: connected A and B, default towards fw.
  • pc1: the specific route to B through r2 is necessary because of the policy: without it, traffic from pc1 to pc2 would go to fw (default), which would send it back through eth0 to r2; fw has no FORWARD rule for eth0 to eth0 and would drop it. With the route, pc1 sends to pc2 through r2 only. In the other direction pc2 uses its default gateway r2, which has eth0 in the network A and delivers to pc1 directly: fw is never crossed.
  • web, mail: default towards fw (192.168.30.14). The route is the same for both.

All the destinations were checked reachable with these routes by a script based on the ipaddress module (hop by hop walk with longest prefix match, for every pair among pc1, pc2, web, mail and ext).

Why isp needs nothing. All the packets towards the Internet carry the source 151.12.50.2 (SNAT of part b): isp knows the network D, directly connected, so the replies reach fw, which restores the private address. The private networks 192.168.0.0/16 are not routable on the Internet (NAT and Private AddressesPrivate networks (intranets) use TCP/IP with private address blocks (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16) that may be reused by different intranets but are never routed in the public Internet; to reach the Internet an intranet needs an application proxy or NAT, a router that translates private to public addresses using a NAT table and per-session mappings: Basic NAT translates only the IP address one to one, NAPT also translates the port so many sessions share one public IP, and Twice NAT adds DNS support and static mappings so sessions can also start from outside.NAT and Private Addresses →). Without NAT, a ping from pc2 would reach ext (it is routed correctly) but the echo reply to 192.168.21.10 would find no route in isp: Network unreachable, no reply. A ping without reply does not prove that the forward path is broken: two-way reachability is needed.

(b) Firewall rules. Rules of Firewall Configuration with iptables in KatharàLab 6 configures a packet-filter firewall on Linux with iptables (NetFilter): tables filter, nat, mangle and raw hold chains of rules, the first matching rule wins, otherwise the default policy applies; three experiences cover a firewall protecting a host (INPUT with DROP policy plus loopback, ping, SSH and ESTABLISHED,RELATED), a firewall on a LAN router (FORWARD) and NAT with SNAT and DNAT.Firewall Configuration with iptables in Katharà → and FirewallsA firewall blocks unauthorised traffic between networks using header information of layers 2-4: stateless packet filters apply ordered rules per packet, stateful firewalls track connections (NEW, ESTABLISHED, RELATED, INVALID), application firewalls act as proxies; in Linux netfilter provides five hooks and iptables organises rules in tables and chains.Firewalls →; the first matching rule decides, otherwise the policy. Packet paths: for the router itself PREROUTING, INPUT; forwarded PREROUTING, FORWARD, POSTROUTING; DNAT happens before routing (the filter sees the translated destination), SNAT after the filters.

  • Policies. INPUT and FORWARD to DROP (whitelist); OUTPUT ACCEPT (fw can send anything).
  • INPUT. I1: loopback (local processes). I2: replies to connections opened by fw. I3: SSH only from pc1 (192.168.20.10) arriving from eth0. Nothing else, so ping to fw and SSH from other hosts are dropped.
  • FORWARD. F1 first, for efficiency and generality: any packet of an existing conversation passes in both directions (replies, and the DNAT/SNAT translated connections). F2: from the offices to the Internet, any traffic; the source 192.168.20.0/23 covers A and B, and the interface pair excludes the DMZ. F3, F4: offices to the DMZ, only web and mail, with the destination server specified (the rule has four criteria together). F5, F6: Internet to the DMZ, only for the two servers and ports; being after DNAT the destination is the private address and the port is the real one. F7: DMZ to the Internet, SMTP only from the mail server. F8: DNS (UDP 5353) from any DMZ host. No rule lets DMZ traffic reach A or B (it falls into the DROP policy), nor lets the Internet reach anything else.
  • nat. The two DNAT rules in PREROUTING (before routing): only packets arriving from eth2 with destination 151.12.50.2 and port 8080 or 2525. The two SNAT rules in POSTROUTING replace the private source with 151.12.50.2 for the packets going out of eth2: one for the offices, one for the DMZ (the networks are not contiguous, so two rules). nat rules apply only to the first packet of a connection; the conntrack mechanism translates the others and the replies.

Typical errors: forgetting lo or ESTABLISHED,RELATED (replies dropped); writing the filter rule for the DNAT'd packet with the public address or port; putting a rule in INPUT for traffic crossing the router; writing --source 192.168.20.0/24 and leaving B without Internet access; changing the policy before adding I3 when working via SSH (the session is lost); forgetting that the rules are lost at restart, so they go in fw.startup.

(c) Packets (the path is PREROUTING DNAT for new packets, routing, INPUT or FORWARD, POSTROUTING SNAT; the rule list was evaluated also with a script that simulates the first-match logic, with the routing table of fw).

  • P1. No DNAT. Destination 93.50.8.10: routing on fw gives eth2 (default route). FORWARD: F1 requires ESTABLISHED or RELATED, the packet is NEW, no; F2 matches (in eth0, out eth2, source in 192.168.20.0/23): accepted. POSTROUTING: first SNAT rule: source 192.168.20.10:41000 becomes 151.12.50.2:41000.
  • P2. PREROUTING: first DNAT rule matches (in eth2, TCP, destination 151.12.50.2, port 8080): destination becomes 192.168.30.2:80. Routing: 192.168.30.2 is in the connected network C: out eth1. FORWARD: F1 no, F2 no (in eth2), F3 and F4 require in eth0, F5 matches (in eth2, out eth1, destination 192.168.30.2, port 8080): accepted.
  • P3. No DNAT rule for port 2222. The destination 151.12.50.2 is an address of fw, so the packet goes to INPUT: I1 no (not lo), I2 no (NEW), I3 no (arrives from eth2, source not pc1): policy DROP.
  • P4. Destination 192.168.20.10: out eth0. FORWARD: F1 no; F2 requires in eth0; F3 to F6 not for this direction; F7 and F8 require out eth2: no rule, policy DROP. The DMZ cannot start connections towards the LAN.
  • P5. Source 192.168.21.10 arrives from eth0 (through r2), destination in the DMZ: out eth1. F1 no, F2 no (out is eth1), F3 no (destination .2), F4 matches (port 2525, destination 192.168.30.3): accepted; no translation (both private, the DMZ is internal).
  • P6. The destination 192.168.20.254 is fw itself: INPUT. I1 no, I2 no, I3 requires source 192.168.20.10 and the source is 192.168.21.10: policy DROP. The management is allowed only to pc1, not to the whole /23.
  • P7. The packet is ESTABLISHED (reply of P2): conntrack restores the source to 151.12.50.2:80 (the reverse of the DNAT), routing gives eth2, and F1 accepts it in the first position. No SNAT rule is needed for it.
  • P8. Destination 93.50.8.10: out eth2. F1 no (NEW), F2 requires in eth0, F7 matches (in eth1, out eth2, TCP, source the mail server, port 2525): accepted. POSTROUTING: the first SNAT rule does not match (source in the DMZ), the second matches: source 192.168.30.3:46000 becomes 151.12.50.2:46000.

Typical errors: checking the interface or the destination before the DNAT; saying that P3 is dropped by FORWARD (it is for fw, so INPUT); accepting P6 because pc2 belongs to the same company; forgetting that P4 needs an explicit rule to be allowed.

Self-assessment grid
part points what must be there for full marks typical errors
Quiz 1-10 10×110\times1 the right option, with the reason counting the root server although cached; h Thit+(1−h)Toriginh\,T_{\text{hit}}+(1-h)T_{\text{origin}} without the cache crossing; base64 length without padding; expiration cost 1515; LSA types mixed; intermediate RSA values; confidentiality procedure used for a signature; trusting a self-signed certificate or skipping the name check; filter on the public port after DNAT; forgetting the amplification factor or naming the wrong goal in the Smurf attack
Ex. 1 (a) 3 handshake numbers (SYN consumes one), RTT=22.64\text{RTT}=22.64 ms, BDP=11.32\text{BDP}=11.32 MSS, swnd∗=12\text{swnd}^*=12, flow control limit 5.305.30 Mbit/s wrong bottleneck; ACK with transmission time; BDP\text{BDP} rounded down; AN of the data segments changed
Ex. 1 (b) 3 340.96340.96 ms without losses; ssthresh=4\text{ssthresh}=4 and windows after the timeout; 478.88478.88 ms ssthresh\text{ssthresh} from 1010; ssthresh+3\text{ssthresh}+3 after a timeout; lost segments counted as delivered; last window without (n−1)Tb(n-1)T_b
Ex. 1 (c) 2 2.5062.506 Mbit/s, p=0.014944p=0.014944, B=174.85B=174.85 segments/s =2.098=2.098 Mbit/s with a correct comment square-root formula at large pp; payload not in bits; no window cap check
Ex. 1 (d) 2 G1=0.158G_1=0.158 stable, PS=0.854P_S=0.854, E[T]=6.70E[T]=6.70 ms, λmax⁡=122.6\lambda_{\max}=122.6 frames/s pure ALOHA formula; unstable point; missing half slot
Ex. 1 (e) 2 a=0.1a=0.1 and a=1a=1, S=0.509S=0.509 and 0.0440.044, comparison with ALOHA aa in seconds; GG as a rate
Ex. 2 (a) 3 lab.conf, addresses, route to B on fw and pc1, default routes, no route on isp explained, effect of missing NAT route without gw reachable; missing route on pc1 (traffic through fw); wrong masks
Ex. 2 (b) 3 policies, lo, ESTABLISHED,RELATED, /23 source, DNAT in PREROUTING, FORWARD with the real destination, SNAT for A, B and DMZ, SSH only from pc1 filter on the public address after DNAT; INPUT for forwarded traffic; DMZ left open towards the LAN
Ex. 2 (c) 2 each of the eight packets with the deciding rule and the translation INPUT and FORWARD mixed up; DNAT order; SSH from pc2 accepted