Skip to content
Book 3: Advanced Theory

Book 3 · Chapter 14

Communication and internet technologies

§14.1§14.2Core · ≈ 7.7 m · ↘B3·14

This chapter is in the ebook.

Read it in full on cswithzak.com. Every question has its mark scheme and every program is ready to run. The free practice for each section is below, with the short code the book prints beside it.

Open in the ebook

§14.1 Protocols

Short code B3·14·1

§14.2 Circuit switching and packet switching

Short code B3·14·2

Why computers need protocols

Short code B3·14·10

Practice for this page of the book: the quiz, flashcards and past-paper questions for its section are listed above.

Protocols as a stack

Short code B3·14·11

Practice for this page of the book: the quiz, flashcards and past-paper questions for its section are listed above.

The four layers of TCP/IP

Short code B3·14·12

Practice for this page of the book: the quiz, flashcards and past-paper questions for its section are listed above.

A message from one host to another

Short code B3·14·13

DECLARE Data : STRING
DECLARE Segment : STRING
DECLARE Packet : STRING
DECLARE Frame : STRING
Data ← "GET /home"
Segment ← "[T:80 #1]" & Data
Packet ← "[I:203.0.113.9]" & Segment
Frame ← "[L:b2]" & Packet & "[chk]"
OUTPUT Data
OUTPUT Segment
OUTPUT Packet
OUTPUT Frame
Encapsulation as strings. Each layer puts its own header in front of what it was given (T = TCP, I = IP, L = link), and the Link layer adds a trailer. Notice the data GET /home is untouched inside every wrapping.

Output

GET /home
[T:80 #1]GET /home
[I:203.0.113.9][T:80 #1]GET /home
[L:b2][I:203.0.113.9][T:80 #1]GET /home[chk]
Run and checked before printing

The web and file transfer: HTTP and FTP

Short code B3·14·14

Practice for this page of the book: the quiz, flashcards and past-paper questions for its section are listed above.

Email: SMTP, POP3 and IMAP

Short code B3·14·15

Practice for this page of the book: the quiz, flashcards and past-paper questions for its section are listed above.

BitTorrent: peer-to-peer file sharing

Short code B3·14·16

DECLARE Have : ARRAY[1:3, 1:6] OF BOOLEAN
DECLARE PeerName : ARRAY[1:3] OF STRING
DECLARE p : INTEGER
DECLARE k : INTEGER
DECLARE Source : INTEGER
PeerName[1] ← "the seed"
PeerName[2] ← "Ali"
PeerName[3] ← "Ben"
FOR k ← 1 TO 6
   Have[1, k] ← TRUE
   Have[2, k] ← k <= 3
   Have[3, k] ← k = 4 OR k = 5
NEXT k
FOR k ← 1 TO 6
   Source ← 1
   FOR p ← 2 TO 3
      IF Have[p, k] = TRUE
         THEN
            Source ← p
      ENDIF
   NEXT p
   OUTPUT "Piece ", k, " from ", PeerName[Source]
NEXT k
Where Nadia's six pieces come from. Have[p, k] is TRUE when peer p holds piece k; the seed (peer 1) is used only when no other peer has the piece. Notice the seed sends just one piece of six.

Output

Piece 1 from Ali
Piece 2 from Ali
Piece 3 from Ali
Piece 4 from Ben
Piece 5 from Ben
Piece 6 from the seed
Run and checked before printing

Circuit switching

Short code B3·14·17

Practice for this page of the book: the quiz, flashcards and past-paper questions for its section are listed above.

Packet switching

Short code B3·14·18

DECLARE Slot : ARRAY[1:5] OF STRING
DECLARE ArrivedSeq : ARRAY[1:5] OF INTEGER
DECLARE ArrivedData : ARRAY[1:5] OF STRING
DECLARE i : INTEGER
DECLARE Message : STRING
// the packets in the order they arrived: 2, 5, 1, 4, 3
ArrivedSeq[1] ← 2
ArrivedData[1] ← "T A"
ArrivedSeq[2] ← 5
ArrivedData[2] ← " 4"
ArrivedSeq[3] ← 1
ArrivedData[3] ← "MEE"
ArrivedSeq[4] ← 4
ArrivedData[4] ← "ATE"
ArrivedSeq[5] ← 3
ArrivedData[5] ← "T G"
FOR i ← 1 TO 5
   Slot[ArrivedSeq[i]] ← ArrivedData[i]
NEXT i
Message ← ""
FOR i ← 1 TO 5
   Message ← Message & Slot[i]
NEXT i
OUTPUT Message
Reassembly by sequence number: each packet goes into the slot its number names, whatever order it arrived in.

Output

MEET AT GATE 4
Run and checked before printing
DECLARE Got : ARRAY[1:6] OF BOOLEAN
DECLARE Arrived : ARRAY[1:4] OF INTEGER
DECLARE i : INTEGER
FOR i ← 1 TO 6
   Got[i] ← FALSE
NEXT i
Arrived[1] ← 2
Arrived[2] ← 6
Arrived[3] ← 1
Arrived[4] ← 4
FOR i ← 1 TO 4
   Got[Arrived[i]] ← TRUE
NEXT i
FOR i ← 1 TO 6
   IF Got[i] = FALSE
      THEN
         OUTPUT "Ask for packet ", i, " again"
   ENDIF
NEXT i
Finding the gaps. The header says 6 packets were sent; packets 2, 6, 1 and 4 arrived. Notice the receiver asks only for the two that are missing.

Output

Ask for packet 3 again
Ask for packet 5 again
Run and checked before printing

The router in packet switching

Short code B3·14·19

FUNCTION NextHopFor(Dest : STRING) RETURNS STRING
   DECLARE Best : STRING
   DECLARE BestCost : INTEGER
   DECLARE r : INTEGER
   Best ← "ISP"
   BestCost ← 999
   FOR r ← 1 TO 4
      IF Table[r].Network = Dest AND Table[r].Cost < BestCost
         THEN
            Best ← Table[r].NextHop
            BestCost ← Table[r].Cost
      ENDIF
   NEXT r
   RETURN Best
ENDFUNCTION
OUTPUT NextHopFor("10.4.0.0")
OUTPUT NextHopFor("172.16.0.0")
OUTPUT NextHopFor("192.168.5.0")
The routing table above as an array of TRoute records (Chapter 13), filled in before this runs. For a destination network the router keeps the matching entry with the lowest cost, and falls back on the default route (ISP) when nothing matches.

Output

R3
R2
ISP
Run and checked before printing
DECLARE HopLimit : INTEGER
DECLARE R : INTEGER
DECLARE Alive : BOOLEAN
HopLimit ← 3
Alive ← TRUE
R ← 0
WHILE Alive = TRUE AND R < 5
   R ← R + 1
   HopLimit ← HopLimit - 1
   IF HopLimit = 0
      THEN
         OUTPUT "R", R, " discards the packet"
         Alive ← FALSE
      ELSE
         OUTPUT "R", R, " forwards it, hop limit now ", HopLimit
   ENDIF
ENDWHILE
IF Alive = TRUE
   THEN
      OUTPUT "Delivered"
ENDIF
A packet sent with a hop limit of 3 towards a destination five routers away. Notice which router discards it.

Output

R1 forwards it, hop limit now 2
R2 forwards it, hop limit now 1
R3 discards the packet
Run and checked before printing

Circuit or packet? Choosing a method

Short code B3·14·20

Practice for this page of the book: the quiz, flashcards and past-paper questions for its section are listed above.

Past-paper practice

Short code B3·14·90

Practice for this page of the book: the quiz, flashcards and past-paper questions for its section are listed above.

Workbook 3: Communication and internet technologies

Short code W3·14 · Advanced Theory Workbook

The write-in workbook for this chapter has drills, exam-style practice, trace tables, fix-the-mistake and mark-it-yourself pages. Its full mark schemes and an interactive version arrive here with the chapter.

Ask Z about Communication and internet technologies
Buy ZAK's books — WhatsApp the books desk: Buy the booksPrint or ebook