CSC263 Computer Networks

Computer NetworksUnit 114 min read

Introduction to Computer Networks – fundamentals, topologies, IP/subnetting, socket programming, client‑server vs P2P, SDN

Unit 1 of Computer Networks: this note introduces basic networking concepts, OSI layers, network types and topologies, IP addressing and subnetting, connection‑oriented services, socket programming with UDP/TCP, client‑server and peer‑to‑peer models, and a brief overview of Software Defined Networking.

Key points

  • A computer network is a collection of interconnected devices that share resources and data using standardized protocols.
  • Network topology determines physical and logical layout; each topology has distinct performance and fault‑tolerance characteristics.
  • IP addressing and subnetting enable efficient use of address space and isolate broadcast domains.
  • Socket programming provides the API for creating TCP (connection‑oriented) and UDP (connectionless) network applications.
  • Client‑server and peer‑to‑peer are two fundamental communication paradigms with different scalability and management implications.
  • Software Defined Networking separates the control plane from the data plane, allowing centralized network management and programmability.

1. What is a Computer Network?

A computer network is a set of autonomous computing devices (hosts, routers, switches, etc.) linked by communication links to exchange data, share resources, and provide services. Networks are built on protocols—formal rules that define syntax, semantics, and timing of communication. The most widely used protocol suite is the Internet Protocol Suite (TCP/IP), which maps closely to the OSI reference model.

1.1. Why Networks Matter

  • Resource sharing – printers, storage, Internet connection.
  • Data communication – email, file transfer, remote login.
  • Scalability – adding new devices without redesigning the whole system.
  • Reliability – redundant paths increase fault tolerance.

2. Network Types

Type Scope Typical Addressing Example Technologies
PAN (Personal Area Network) < 10 m No IP (Bluetooth MAC) Bluetooth, IR
LAN (Local Area Network) Building or campus Private IPv4/IPv6 (e.g., 192.168.x.x) Ethernet, Wi‑Fi
MAN (Metropolitan Area Network) City‑wide Public or private IP blocks Metro‑Ethernet, FDDI
WAN (Wide Area Network) Country/continent Public IP (assigned by ISP) MPLS, Leased lines, Internet
CAN (Campus Area Network) University/Corporate campus Private IP, often hierarchical Fiber backbone, VLANs
GAN (Global Area Network) Worldwide Public IP, IPv6 increasingly Satellite, Internet backbone
ULANWANMANLocal (e.g., Ethernet)Global (e.g., Internet)City-wide (e.g., Metro-Ethernet)Hybrid (e.g., VPN)Campus (e.g., University)Wide-area (e.g., MPLS)Global (e.g., Satellite)Standalone
Overlap of LAN, WAN, and MAN scopes with hybrid examples.

2.1. Connection‑Oriented vs Connectionless Services

  • Connection‑oriented (e.g., TCP) establishes a logical session before data transfer, guaranteeing order, reliability, and flow control.
  • Connectionless (e.g., UDP) sends datagrams without prior handshake; lower overhead, suitable for real‑time or loss‑tolerant applications.

3. Network Topologies

Topology describes the arrangement of nodes and links. Two perspectives are common:

graph TD
    A[Bus Topology] -->|Single cable| B[All nodes]
    C[Star Topology] -->|Central hub| D[Nodes]
    E[Ring Topology] -->|Closed loop| F[Token passing]
    G[Mesh Topology] -->|Direct links| H[Redundancy]
    I[Tree Topology] -->|Hierarchical| J[Backbone]
    K[Hybrid Topology] -->|Combination| L[Flexibility]

Classification of physical topologies with key characteristics.

  1. Physical topology – actual cabling and device placement.
  2. Logical topology – how data flows over the network, independent of physical layout.

3.1. Common Physical Topologies

Topology Description Merits Demerits
Bus All nodes share a single coaxial cable; terminators at both ends. Simple, inexpensive, easy to extend. Single point of failure, limited bandwidth, collisions increase with nodes.
Star Central hub/switch connects to each node via separate links. Easy to manage, failure of one link doesn’t affect others, scalable. Hub/switch is a single point of failure; more cabling required.
Ring Nodes connected in a closed loop; token passing controls access. Predictable performance, no collisions. Failure of one node/link breaks the ring (unless dual‑ring).
Mesh Every node may have a direct link to many others; can be full or partial. High redundancy, fault tolerance, optimal routing. Expensive, complex cabling and management.
Tree (Hierarchical) Multiple star networks connected in a hierarchy. Scalable, easy to segment. Higher layers become bottlenecks; failure of backbone affects many nodes.
Hybrid Combination of two or more basic topologies. Flexibility to meet specific needs. Design and troubleshooting can be complex.

3.2. Logical Topologies

  • Ethernet (CSMA/CD) – logical bus, even if physical star.
  • Token Ring – logical ring regardless of physical wiring.
  • ATM – cell‑based logical point‑to‑point.

4. OSI Model Overview (relevant to Unit 1)

Layer Primary Function Typical Devices
7 – Application End‑user services (HTTP, FTP) Application software
6 – Presentation Data representation, encryption Gateways
5 – Session Dialog control, synchronization Gateways
4 – Transport End‑to‑end reliability (TCP) / best‑effort (UDP) Host OS
3 – Network Routing, logical addressing (IP) Router
2 – Data Link Frame delimiting, MAC addressing, error detection Switch, Bridge
1 – Physical Bit transmission over media Hub, NIC, Repeater

Only Layer 1 (Physical) and Layer 2 (Data Link) are directly concerned with cabling and media, but understanding the full stack helps in troubleshooting and design.

5. IP Addressing and Subnetting

5.1. IPv4 Address Structure

An IPv4 address is a 32‑bit number, usually written in dotted‑decimal notation:

A subnet mask determines the network portion (bits set to 1) and host portion (bits set to 0). CIDR notation (e.g., /24) is a compact way to express the mask.

5.2. Worked Example – Subnetting a Class C Network

Problem: A class C network 192.34.12.0/24 must be divided into three subnets, each supporting at least 30 hosts. Find the new subnet mask, network addresses, and broadcast addresses.

Solution Steps

  1. Determine required host bits.
    Minimum hosts per subnet = 30 → need at least .
    → 5 host bits are required.

  2. Calculate subnet bits.
    Class C provides 8 host bits originally.
    Subnet bits = 8 – 5 = 3 bits.

  3. New subnet mask.
    Original /24 + 3 subnet bits = /27 → binary mask: 11111111.11111111.11111111.11100000 → 255.255.255.224.

  4. Number of subnets.
    subnets (more than needed, but acceptable).

  5. List first three subnets

Subnet # Network Address First Host Last Host Broadcast
0 192.34.12.0/27 192.34.12.1 192.34.12.30 192.34.12.31
1 192.34.12.32/27 192.34.12.33 192.34.12.62 192.34.12.63
2 192.34.12.64/27 192.34.12.65 192.34.12.94 192.34.12.95

Each subnet supports 30 usable hosts (32 total addresses minus network & broadcast).

5.3. Quick Check Questions

  • First address (network) and last address (broadcast) for 192.34.12.56/28?
    /28 → mask 255.255.255.240, block size = 16.
    Network = 192.34.12.48, Broadcast = 192.34.12.63.

  • Is 192.16.144.64/27 a host, network, or broadcast address?
    /27 block size = 32. Subnet boundaries: 0, 32, 64, 96 … → 192.16.144.64 is the network address of the third subnet.

6. Socket Programming – UDP and TCP

Sockets are the programming interface that abstracts the transport layer. In C (POSIX) the workflow is similar for both protocols; the key differences lie in the socket type and the need for connection establishment.

6.1. UDP (Connectionless) Example (C)

/* udp_server.c – simple UDP echo server */
#include <stdio.h>
#include <string.h>
#include <arpa/inet.h>
#include <sys/socket.h>

#define PORT 5000
#define BUFSZ 1024

int main() {
    int sockfd;
    struct sockaddr_in servaddr, cliaddr;
    char buffer[BUFSZ];
    socklen_t len = sizeof(cliaddr);

    sockfd = socket(AF_INET, SOCK_DGRAM, 0);
    memset(&servaddr, 0, sizeof(servaddr));
    servaddr.sin_family = AF_INET;
    servaddr.sin_addr.s_addr = INADDR_ANY;
    servaddr.sin_port = htons(PORT);

    bind(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr));
    printf("UDP server listening on port %d\n", PORT);

    while (1) {
        int n = recvfrom(sockfd, buffer, BUFSZ, 0,
                         (struct sockaddr *)&cliaddr, &len);
        buffer[n] = '\0';
        printf("Received: %s\n", buffer);
        sendto(sockfd, buffer, n, 0,
               (struct sockaddr *)&cliaddr, len);
    }
    return 0;
}

Diagram (logical flow)

Client (UDP socket) --> sendto() --> Network (IP/UDP) --> recvfrom() --> Server
Server --> sendto() (echo) --> Network --> Client recv()

6.2. TCP (Connection‑Oriented) Example (C)

/* tcp_server.c – simple TCP echo server */
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <sys/socket.h>

#define PORT 6000
#define BUFSZ 1024

int main() {
    int listenfd, connfd;
    struct sockaddr_in servaddr, cliaddr;
    char buffer[BUFSZ];
    socklen_t len = sizeof(cliaddr);

    listenfd = socket(AF_INET, SOCK_STREAM, 0);
    memset(&servaddr, 0, sizeof(servaddr));
    servaddr.sin_family = AF_INET;
    servaddr.sin_addr.s_addr = INADDR_ANY;
    servaddr.sin_port = htons(PORT);

    bind(listenfd, (struct sockaddr *)&servaddr, sizeof(servaddr));
    listen(listenfd, 5);
    printf("TCP server listening on port %d\n", PORT);

    connfd = accept(listenfd, (struct sockaddr *)&cliaddr, &len);
    printf("Client connected.\n");

    while (1) {
        int n = read(connfd, buffer, BUFSZ);
        if (n <= 0) break;
        write(connfd, buffer, n);   // echo back
    }
    close(connfd);
    close(listenfd);
    return 0;
}

Diagram (logical flow)

Client: socket() → connect() → send() → Server: accept() → read() → write() → Client: recv()

Key Differences Highlighted

Feature UDP TCP
Connection None (stateless) Three‑way handshake (SYN, SYN‑ACK, ACK)
Reliability No guarantee, no retransmission Guarantees delivery, ordering, flow control
Overhead Small (header 8 bytes) Larger (header 20 bytes + options)
Use Cases DNS, streaming, VoIP HTTP, FTP, SSH, email (SMTP)

7. Communication Paradigms

7.1. Client/Server Model

  • Server provides resources/services, runs continuously, listens on well‑known ports.
  • Client initiates requests, may be transient.
  • Centralized control simplifies security and management but can become a bottleneck.

7.2. Peer‑to‑Peer (P2P) Model

  • Every node can act as both client and server.
  • Resources are distributed; scalability improves as more peers join.
  • Challenges: NAT traversal, security, and consistency.
Aspect Client/Server Peer‑to‑Peer
Control Centralized Decentralized
Scalability Limited by server capacity Grows with peers
Fault tolerance Server failure = service loss Redundant copies mitigate loss
Typical applications Web, email, DBMS File‑sharing (BitTorrent), VoIP (Skype)

8. Software Defined Networking (SDN) – A Brief Introduction

SDN separates the control plane (decision making) from the data plane (packet forwarding).

  • Controller (e.g., OpenDaylight, ONOS) runs on a general‑purpose server, using southbound APIs (OpenFlow, NETCONF) to program switches.
  • Switches become simple forwarding devices that obey flow rules installed by the controller.

8.1. Core Features

  1. Centralized network view – global topology and policies.
  2. Programmability – network behavior can be changed via software APIs.
  3. Abstraction – applications see a virtual network rather than physical hardware.
  4. Automation – rapid provisioning, dynamic load balancing, and security enforcement.

8.2. Advantages & Limitations

Advantages Limitations
Faster innovation (new services via software) Controller becomes a critical single point of failure (mitigated by clustering)
Simplified management and troubleshooting Requires compatible hardware or firmware upgrades
Better resource utilization (dynamic flow rules) Learning curve for network engineers accustomed to traditional CLI

9. Designing a Small LAN – Application of Concepts

Scenario: An office has 3 departments, each with 50 computers spread over 10 rooms (5 PCs per room).

Design decisions

  1. Topology – Choose star per floor with a core‑distribution hierarchy (tree). Each room connects to a switch; all switches uplink to a distribution switch; distribution switches connect to a core router.

  2. Media – Use Category 6 twisted‑pair for intra‑room links (up to 1 Gbps) and fiber optic (e.g., 10 Gbps) for backbone between distribution and core to avoid congestion.

  3. IP Scheme – Private Class B 172.16.0.0/16. Subnet per department:

    • Dept A: 172.16.0.0/18 → 16 384 hosts (more than enough)
    • Dept B: 172.16.64.0/18
    • Dept C: 172.16.128.0/18

    Each department can be further segmented per floor using /24 subnets if needed.

  4. Devices –

    • Switches (Layer 2) for room aggregation.
    • Layer 3 Switch or Router at distribution for inter‑department routing.
    • Wireless Access Points for mobile devices, connected to switches.
  5. Security – VLANs per department, ACLs on the router, and optional SDN controller for centralized policy enforcement.

This design illustrates how topology, media choice, IP addressing, and device selection intertwine.

10. Summary of Key OSI Layer Mappings for Common Devices

Device OSI Layer(s) Operated On
Hub Physical (Layer 1) – repeats electrical signals
Switch (Layer 2) Data Link (MAC address learning)
Router Network (IP routing)
Bridge Data Link (segment interconnection)
Firewall (stateful) Network & Transport (inspects IP/TCP/UDP)
SDN Switch (OpenFlow) Data Link (forwarding) + Control via external controller

Exam tip

  • Memorize the subnet‑mask calculation steps; many exam questions ask for network, first host, last host, and broadcast addresses. Practice with /28, /27, /24 examples.
  • Topologies: be ready to draw a small diagram and list at least two merits and two demerits for each. A comparison table earns quick marks.
  • Socket programming: know the sequence of system calls for TCP (socket → bind → listen → accept → read/write) and UDP (socket → bind → recvfrom/sendto). Sketch the logical flow; you don’t need full code, but a short snippet shows depth.
  • Client/Server vs P2P: focus on control, scalability, and typical applications; a 2‑column table is a concise answer.
  • SDN: remember the three pillars—centralized control, programmability, and separation of planes. A bullet list of features plus one advantage/disadvantage scores well.

By covering definitions, diagrams, worked examples, and comparison tables, you will address all likely marks distribution for Unit 1. Good luck!

Based on the TU BSc CSIT syllabus for Computer Networks (CSC263), unit 1.

Discussion

Loading…