Network 3

Network 3

[Network layer] Checksum

  • != checkdigit
  • Error detection method used by most TCP / IP protocols
  • Protects against corruption that may occur during transmission of a packet
  • It1 is a redundant information added to packet
  • Calculated at sender → value obtained is sent with the packet
  • Receiver repeats same calculation on the whole packet including the checksum
  • If result is correct, packet is accepted (else, rejected)
  • Checksum calculation at the sender
  • Packet is divided into k sections of n bits each
  • All sections added together using one’s complement arithmetic
  • Final result is complemented to make the checksum
  • Checksum calculation at the receiver
  • Received packet is divided into k sections of n bits each
  • All sections added together using one’s complement arithmetic
  • Result is complemented (i.e. flip 1 to 0; 0 to 1)
  • If final result is 0, packet is accepted (else, rejected)
  • Binary addition
ABSumCarry
2340000
5670110
89101010
1112131101 (carry)
1101
1011
Result: 11000 (starts from the LSB on the right)
  • One’s complement arithmetic
  • Similar to binary addition, except when there’s a carry out of the most significant bit (MSB), the carry is wrapped around and added back into the least significant bit (LSB)
  • E.g.
Word 1: 1111 1111 1111 1111 (0xFFFF)
Word 2: 0000 0000 0000 0001 (0x0001)
1 0000 0000 0000 0000 (17 bits – overflowed 16 bits)
Final result: 0000 0000 0000 0001 (drop carry bit and add to result)
  • IP header
  • Checksum in IP header covers only the header, not the data
  • All higher-level protocols that encapsulate data in the IP datagram have a checksum fields that covers the whole packet
  • Thus checksum for IP datagram does not have to check the encapsulated data
  • Header of IP packet changes with each visited router, but data do not
  • ⇒ checksum includes only the part that has changed
  • If data were included, each router would need to recalculate the checksum for the whole packet → increases processing time
  • E.g.
Checksum calculation at:
header
receiver

[Transport layer] Protocols

  • User Datagram Protocol (UDP)
  • Unreliable communication: no guarantee of delivery or order
  • Connectionless: no handshake before communication starts
  • Lightweight, simple protocol using minimum overhead
  • Faster (than TCP) and efficient: UDP packets (user datagrams) have a fixed-size header of 8 bytes
  • Typically used for transferring small amount of data
FieldSize (byte)Description
Source Port2Port of sending application
Destination Port2Port of receiving application
Length2Length of UDP header + data
Checksum2Used for error-checking of header and data
  • ⇒ Used when speed is more important than reliability
  • Checksum – UDP header
  • UDP checksum calculation is different from IP
  • Includes 3 sections:
  • Pseudoheader (part of IP packet header)
  • UDP header
  • Data
  • E.g. of checksum calculation at the sender:
  • Real-time applications (fast, low latency)
  • VoIP (Voice over IP)
  • Online gaming
  • Streaming media
  • Application: Lightweight services
  • Domain Name System (DNS), part 53
  • Dynamic Host Configuration Protocol (DHCP), port 67 (header) / 68 (client)
  • Trivial File Transfer Protocol (TFTP), port: 69
  • Application: Broadcast / Multicast
  • Routing Information Protocol (RIP), port 520
  • Multicast DNS (mDNS), port 5353
  • Transmission Control Protocol (TCP)
  • Reliable communication / delivery: ensure data integrity (no loss or corruption); uses acknowledgements and timeouts
  • Connection-oriented: before any data can be transmitted, a reliable connection must be obtained and acknowledged
  • Provides ordered and error-checked delivery of data between applications over a network
  • Ordered delivery: reassembled in correct order with sequence number
  • Error checking: errors detected using checksum
  • Flow control: prevent overwhelming of receiver
  • Congestion control: manage traffic load to avoid congestion
  • ⇒ Slower (than UDP) and used for transferring large amounts of data to ensure that it is not sent again
  • TCP packets (segments)
  • TCP sees user data as a stream of bytes, each byte has a number
FieldSize (bits)Description
Source Port16Port of sending application
Destination Port16Port of receiving application
Sequence Number32No. assigned to the 1st byte of data contained in this segment
Acknowledge Number32Number of the next byte that the receiver expects to receive from the sender
Header Length4No. of 4-byte words in TCP header
Reserved6Reserved for future use
FieldSize (bits)Description
Control**66 diff control bits / flags
1 or more of these bits can be set at a time
Window size16No. of bytes the sender of this segment is willing to accept
Checksum16Mandatory checksum of header + data
Urgent pointer16Offset no. that must be added to the sequence no. to obtain the no. of the last urgent byte in the data section of the segment. Only valid if the urgent (URG) flag is set.
Options40x8 bitsOptional information in TCP header

  • Connection establishment: uses a three-way handshake process to establish connection
  • ⇒ Ensures both sender & receiver agree on the connection state
  • 3 messages are exchanged that allow each side to agree to form a connection and know what the other side has agreed
  • Client sent a SYN segment for synchronisation of sequence no.
  • The no. is called the initial sequence number (ISN)
  • Client chooses a random number as the 1st sequence no.
  1. SYN: client sends synchronisation request (seq no. = x) to server
  • Note: must write all the sequence no.s!
  1. SYN + ACK: Server acknowledges (seq no. = x + 1) and sends own synchronisation (seq no. = y)
  2. ACK: client acknowledges back to server (seq no. = y + 1)
  • Mechanisms to ensure reliable data transmission:
  • Sequence numbers: every byte of data is assigned a sequence no.
  • ⇒ Allows receiver to reorder segments and detect missing data
  • Each segment, from a large group of segments composing the user data, is assigned a sequence no. that represents the sequence no. of the first byte of user data carried in this segment
  • Acknowledgements (ACK): receiver sends an ACK with the next expected byte number
  • ⇒ Confirms that data was received correctly & in order
  • Each side of the communication has its own sequence no.s for the data it wants to transfer (e.g. pic on left)
  • Sender sends acknowledgement no. that is the sequence no. of the last byte received from receiver plus 1
  • Receiver sends acknowledgement no. that is the sequence no. of the last byte received from sender plus 1
  • Retransmission: sender retransmits data if it does not receive an ACK within a time
  • TCP sets a retransmission timer for each sent segment
  • Ensures that lost ACKs or segments are detected & resent
  • TCP has mechanism that allows faster recovery from packet loss by allowing sender to retransmit after receiving 3 duplicate ACK
  • E.g. Lost segment and retransmission due to timeout
  • E.g. Lost segment and sending of 3 duplicated ACK that triggers a fast retransmission
  • Checksum: each TCP segment includes a 16-bit checksum covering header & data (same procedure in TCP & in UDP)
  • ⇒ Detects corruption during transmission
  • If a segment is corrupted (invalid checksum), segment is discarded by the destination TCP and is considered as lost
  • Includes 3 sections:
  • Pseudoheader (part of IP packet header)
  • UDP header
  • Data
  • Flow control: receiver advertises a window size to control how much data the sender can transmit
  • ⇒ Prevents buffer overflow at the receiver
  • TCP sliding window mechanism operates at the octet level, not at the packet or segment level
  • Window size changes over time
  • Each ACK contains a receiver window size that specifies how much more octet it can receive without overflowing its buffer
  • Sender uses a sliding window to determine how many octet it can send without waiting for an ACK
  • Window size inc. when receiver process the data and is able to free up buffer
  • Window size dec. when receiver buffer fills up
  • Window size of 0 is possible if receiver wants sender to stop all transmissions
  • Ordered delivery: receiver stores out-of-order segments and waits to deliver them in sequence to the application
  • ⇒ Ensures in-order delivery to the application layer
  • Sliding window: mechanism to improve overall throughput 17
  • Allows a sender to transmit multiple packets (window size) before waiting for an acknowledgement
  • Since a simple acknowledgement protocol must delay sending a new packet until it receives an acknowledge for the previous packet → wastes a substantial amount of network capacity
  • Connection termination: uses a three-way handshake process or a 4 step termination/teardown process (half-close) to terminate connection
  • ⇒ Ensures all data has been delivered and acknowledged before a connection is closed
  • Using 3-way handshake process
  1. FIN: client sends FIN segment (seq no. = x) to server
  2. FIN + ACK: server sends FIN+ACK segment to confirm receipt of the FIN (finish) segment from client, and announce the closing of the connection. ACK (seq no. = x + 1) and FIN (seq no. = y)
  3. ACK: client acknowledges the receipt of the FIN segment (seq no. = y+1)
  • Using 4-step teardown process
  • I.e. half-close request ⇒ one end can stop sending data while still receiving data
  • Either server or client can issue the request
  • 2nd FIN segment is not generated immediately
  1. FIN: client requests for connection closure (seq no. = x)
  2. ACK: server acknowledges (seq no. = x + 1). Client cannot send any more data to server
  3. FIN: server sends own FIN (seq no. = y) with ACK (seq no. = x + 1)
  4. ACK: client acknowledges closure (seq no. = y+1)

[Transport layer] Port numbers

NamePurpose
Well-known / System PortsPorts ranging from 0 to 1,023 are assigned and controlled by Internet Assigned Numbers Authority (IANA)
E.g. TCP port for HyperText Transfer Protocol (HTTP)
Registered / User PortsPorts ranging from 1,024 to 49,151 are not assigned or controlled by IANA. They can only be registered with IANA to prevent duplication
E.g. PostgreSQL uses 5432
Dynamic / Private PortsPorts ranging from 49,152 to 65,535 are neither controlled nor registered. They can be used as temporary or private port numbers. Most systems do not follow the original recommendation that the ephemeral18 port numbers for clients be chosen from this range.

Addresses

FeatureMAC AddressIP AddressPort Address
Also calledPhysical / hardware addressLogical AddressService Address
Used atData Link Layer (Layer 2)Network Layer (Layer 3)Transport Layer (Layer 4)
PurposeIdentifies a device on a local networkIdentifies a device on a global networkIdentifies a specific process / service on a device
UniquenessUnique to each network interfaceUnique per device (in a given network)Not globally unique; reused across device
Format48-bit, e.g. 00:1A:2B:3C:4D:5EIPv4: 192.168.1.1
IPv6: 2001:db8::1
16-bit, e.g. 80 for HTTP, 53 for DNS
Assigned byManufacturer (burned into NIC)Network administrator or DHCPApplication or system
Changes over timeUsually fixedCan change (e.g. DHCP)Changes as apps open / close
ScopeLocal Network (LAN) onlyNetwork-wide / Internet-wideLocal to device (used for multiplexing)

Comments from the Word document

Footnotes

  1. Comment by ANDREA TAN KAI XUAN HCI: referring to checksum or to corruption?

  2. Comment by ANDREA TAN KAI XUAN HCI: from chatgpt:
    Sum = A XOR B
    Carry = A AND B
    XOR gate gives 1 when inputs are different → used for Sum
    AND gate gives 1 only when both inputs are 1 → used for Carry

  3. Comment by ANDREA TAN KAI XUAN HCI: carry means carry over like math e.g. 9+5 = 14, 1 is carried over

  4. Comment by ANDREA TAN KAI XUAN HCI: because 1 + 1 = 10 in binary

  5. Comment by ANDREA TAN KAI XUAN HCI: from chatgpt:
    Sum = A XOR B
    Carry = A AND B
    XOR gate gives 1 when inputs are different → used for Sum
    AND gate gives 1 only when both inputs are 1 → used for Carry

  6. Comment by ANDREA TAN KAI XUAN HCI: carry means carry over like math e.g. 9+5 = 14, 1 is carried over

  7. Comment by ANDREA TAN KAI XUAN HCI: because 1 + 1 = 10 in binary

  8. Comment by ANDREA TAN KAI XUAN HCI: from chatgpt:
    Sum = A XOR B
    Carry = A AND B
    XOR gate gives 1 when inputs are different → used for Sum
    AND gate gives 1 only when both inputs are 1 → used for Carry

  9. Comment by ANDREA TAN KAI XUAN HCI: carry means carry over like math e.g. 9+5 = 14, 1 is carried over

  10. Comment by ANDREA TAN KAI XUAN HCI: because 1 + 1 = 10 in binary

  11. Comment by ANDREA TAN KAI XUAN HCI: from chatgpt:
    Sum = A XOR B
    Carry = A AND B
    XOR gate gives 1 when inputs are different → used for Sum
    AND gate gives 1 only when both inputs are 1 → used for Carry

  12. Comment by ANDREA TAN KAI XUAN HCI: carry means carry over like math e.g. 9+5 = 14, 1 is carried over

  13. Comment by ANDREA TAN KAI XUAN HCI: because 1 + 1 = 10 in binary

  14. Comment by ANDREA TAN KAI XUAN HCI: from chatgpt:
    Sum = A XOR B
    Carry = A AND B
    XOR gate gives 1 when inputs are different → used for Sum
    AND gate gives 1 only when both inputs are 1 → used for Carry

  15. Comment by ANDREA TAN KAI XUAN HCI: carry means carry over like math e.g. 9+5 = 14, 1 is carried over

  16. Comment by ANDREA TAN KAI XUAN HCI: because 1 + 1 = 10 in binary

  17. Comment by ANDREA TAN KAI XUAN HCI: from google: the amount of material or items passing through a system or process

  18. Comment by ANDREA TAN KAI XUAN HCI: from google: lasting for a very short time