⚡ TechVani: AI, Technology, Apps, Coding & Digital World
TechVaniAI • Technology • Apps • Coding • Digital World
HomeAI & TechAppsCodingFree AI ToolsStudent TechSecurityAboutContactPrivacy
TECHVANI // LEARN. BUILD. TEST.

Learn the tech. Build the idea.

Clear study notes, tested lab files and practical guides for coding, AI and digital safety.

Explore Latest →
šŸ¤– AI & TechAI news, tools & guides šŸ“± Apps & ToolsUseful apps & websites šŸ’» CodingProgramming & web development šŸŽ“ Student TechStudy & career technology šŸ” Cyber SecuritySafety & awareness

Latest Posts

Circuit Notebook theme

Exam Notes

šŸ“š BTech CSE Exam Notes

Find Semester 1-8 subjects in one place. Choose a semester and open the notes you need. This is a general study guide, not an official syllabus.

Open Exam Notes →🧪 Open Lab Files →

Exam Numericals & Study Series

Practice CPU scheduling and explore OS and DBMS topics in separate, easy-to-follow parts. New topics will appear in the hub as they are published.

Open Numericals Hub →

Start here and stay in touch

New to TechVani? Start with our free AI tools guide for students. It covers which tools to try and what to check before relying on an answer.

For step-by-step videos, visit SiteSudhar on YouTube.

Join TechVani on WhatsApp

Get new AI tools and coding guides in your WhatsApp Updates tab.

Browse Topics

Popular Posts

TechVani

Computer Networks | Semester 5 Core Notes

Semester 5 - Page 2: Computer Networks. 27 numbered topics, highlighted rules, packet diagrams, worked subnet/rate examples, answered exam questions, comparison tables and three complete Python demos. General common-core guide, not an official syllabus or past-paper prediction.

Run each Python block separately: Python 3, standard library only. These are offline teaching calculations, not network scans or packet captures. Existing C lab and compiler links are retained below. A zero CRC remainder is an error-detection result, not proof of authenticity.

Topic map

  1. Protocols, networks and layering
  2. OSI and Internet models
  3. Encapsulation and addresses
  4. Topologies, devices and switching
  5. Transmission, propagation and bandwidth-delay
  6. Physical media, signals and multiplexing
  7. Framing and error detection
  8. CRC worked polynomial check
  9. Stop-and-wait and sliding-window ARQ
  10. Go-Back-N and Selective Repeat
  11. Ethernet, Wi-Fi and medium access
  12. IPv 4, CIDR and subnetting
  13. IPv 6 and neighbor discovery
  14. Forwarding, longest prefix and routing
  15. Distance-vector and link-state routing
  16. ARP, ICMP and NAT
  17. UDP and application reliability
  18. TCP byte stream and handshake
  19. TCP ACKs, retransmission and termination
  20. Flow control versus congestion control
  21. DNS hierarchy, caching and records
  22. HTTP, TLS and a browser trace
  23. Email, file transfer and application protocols
  24. Sockets and message framing
  25. Network security and segmentation
  26. Troubleshooting and measurement
  27. Revision and calculation checklist

1. Protocols, networks and layering

A protocol defines message format and behavior. Layering lets components use services below them while hiding implementation details; the Internet is a network of networks.

Worked example: A browser request passes through application, transport, IP and link functions; each layer adds or interprets its own information.
Exam question: Is the OSI model identical to every real Internet implementation?
Answer: No. It is a teaching model; Internet layer mappings are approximate.

2. OSI and Internet models

OSI has physical, data link, network, transport, session, presentation and application layers. The Internet suite is commonly taught with four or five layers; some OSI functions are integrated into applications/libraries.

Worked example: HTTP is application, TCP transport, IP network and Ethernet link. TLS does not fit every teaching diagram as one neat separate layer.
Exam question: Why learn the responsibilities rather than names alone?
Answer: It makes packet traces and diagnosis useful across different implementations.

3. Encapsulation and addresses

Application data is carried by transport segments/datagrams, IP packets and link frames. Link addresses identify a local hop; IP addresses identify network interfaces; ports help demultiplex transport endpoints.

Worked example: For a remote web server, the first Ethernet destination is usually the local gateway's MAC, not the server's MAC.
Exam question: Which addresses normally change at each routed hop?
Answer: Link-layer addresses; final IP addresses normally stay unchanged except translation/tunneling.
Application data
  -> TCP segment / UDP datagram
    -> IP packet
      -> Link frame
        -> Physical signals
Encapsulation: headers serve different scopes. Link delivery changes at routed hops.

4. Topologies, devices and switching

A switch forwards link frames; a router forwards IP packets; an access point joins wireless clients to a LAN. Packet switching shares capacity, while circuit switching reserves a path/resource model.

Worked example: A home router can combine switch, AP, NAT and routing, but these functions remain distinct.
Exam question: Does a faster switch remove all network latency?
Answer: No. Propagation, processing, queueing and endpoint work remain.

5. Transmission, propagation and bandwidth-delay

Transmission delay is packet bits/link rate; propagation is distance/signal speed. Throughput is achieved useful rate, not necessarily the nominal bandwidth. Bandwidth-delay product estimates in-flight data.

Worked example: 1000 bytes at 1 Mb/s takes 8 ms transmission.10 Mb/s times 0.1 s is 1Mb=125000 bytes in flight.
Exam question: Does doubling bandwidth halve propagation delay?
Answer: No. Propagation depends on path distance and medium.

6. Physical media, signals and multiplexing

Copper, fiber and radio have different attenuation, interference and propagation properties. Multiplexing shares a medium by time, frequency, wavelength or codes; modulation and line coding serve different roles.

Worked example: Time-division allocates time slots; frequency-division allocates bands. Practical capacity depends on bandwidth and noise.
Exam question: Can a digital bit be transmitted without physical signal constraints?
Answer: No. Receivers must distinguish signals under real noise/timing limits.

7. Framing and error detection

Data-link framing marks boundaries; parity, checksums and CRC detect selected error patterns. Detection is not automatically correction or security authentication. Different CRC generators have different guarantees.

Worked example: A one-bit parity check misses every even number of flips. A CRC divides a bit polynomial modulo 2 and appends a remainder.
Exam question: Does an unchanged checksum prove no tampering?
Answer: No. Noncryptographic checks are not a defense against deliberate forgery.

8. CRC worked polynomial check

CRC arithmetic uses XOR, not ordinary carries. For a generator of degree r, append r zeros to data, divide modulo 2 and replace those zeros by the r-bit remainder; receiver divides the full codeword.

Worked example: Data 1101 and generator 1011 yield remainder 001 and frame 1101001. A flipped leading bit gives nonzero remainder 101 in the demo.
Exam question: Does a zero remainder detect every possible error?
Answer: No. Some error patterns are divisible by the generator; guarantees depend on the polynomial and length.

Teaching CRC remainder and corruption check

def remainder(bits, divisor):
    if not bits or any(x not in "01" for x in bits):
        raise ValueError("binary data required")
    if len(divisor) < 2 or divisor[0] != "1" or divisor[-1] != "1" or any(x not in "01" for x in divisor):
        raise ValueError("invalid generator")
    work = list(map(int, bits))
    poly = list(map(int, divisor))
    for i in range(len(work) - len(poly) + 1):
        if work[i]:
            for j, bit in enumerate(poly):
                work[i+j] ^= bit
    return "".join(map(str, work[-(len(poly)-1):]))

data, generator = "1101", "1011"
check = remainder(data + "0" * (len(generator)-1), generator)
frame = data + check
print("CRC:", check)
print("frame:", frame)
print("valid remainder:", remainder(frame, generator))
corrupt = ("0" if frame[0] == "1" else "1") + frame[1:]
print("corrupt remainder:", remainder(corrupt, generator))

Checked output:

CRC: 001
frame: 1101001
valid remainder: 000
corrupt remainder: 101

9. Stop-and-wait and sliding-window ARQ

ARQ combines error detection, acknowledgments, timeouts and retransmission. Sequence numbers distinguish duplicates; a sliding window permits multiple frames in flight.

Worked example: Stop-and-wait sends one frame then waits; a lost ACK can cause retransmission, so the receiver must suppress duplicate delivery.
Exam question: Why use a timeout rather than waiting forever for an ACK?
Answer: Loss or failure can prevent an ACK from arriving.

10. Go-Back-N and Selective Repeat

Go-Back-N commonly retransmits the outstanding suffix after loss; Selective Repeat acknowledges/buffers individual frames. Sequence-number/window limits must avoid confusing new frames with old duplicates.

Worked example: With a k-bit sequence space, standard Selective Repeat limits window size to at most 2^(k-1). State protocol assumptions before applying the rule.
Exam question: Does Selective Repeat always use less memory?
Answer: No. Out-of-order buffering can require more receiver state.

11. Ethernet, Wi-Fi and medium access

Classic shared Ethernet uses CSMA/CD; modern switched full-duplex Ethernet does not need collision detection. Wi-Fi uses contention/avoidance mechanisms and cannot assume Ethernet's collision model.

Worked example: A switch learns source MAC locations; unknown destinations may be flooded within the allowed broadcast domain.
Exam question: Does every Ethernet frame traverse the whole LAN?
Answer: No. Learned unicast forwarding can select one output port.

12. IPv 4, CIDR and subnetting

IPv 4 has 32-bit addresses; a /p prefix leaves 32-p address bits. Network/broadcast conventions reserve two addresses in ordinary subnets, with /31 point-to-point and /32 host-route exceptions.

Worked example: 192.0.2.42/26 belongs to 192.0.2.0..63:64 total addresses, 62 conventional host addresses. The demo prints exact mask and boundaries.
Exam question: Is an address being in a block the same as usable host eligibility?
Answer: No. Membership includes network/broadcast addresses under ordinary conventions.

IPv4 subnet calculation with standard library

from ipaddress import ip_interface, ip_network
interface = ip_interface("192.0.2.42/26")
network = interface.network
print("network:", network.network_address)
print("mask:", network.netmask)
print("broadcast:", network.broadcast_address)
print("total:", network.num_addresses)
print("conventional hosts:", network.num_addresses - 2)
print("192.0.2.63 in block:", ip_interface("192.0.2.63/32").ip in network)
print("192.0.2.64 in block:", ip_interface("192.0.2.64/32").ip in network)
print("/31 total:", ip_network("192.0.2.0/31").num_addresses)
print("/32 total:", ip_network("192.0.2.0/32").num_addresses)

Checked output:

network: 192.0.2.0
mask: 255.255.255.192
broadcast: 192.0.2.63
total: 64
conventional hosts: 62
192.0.2.63 in block: True
192.0.2.64 in block: False
/31 total: 2
/32 total: 1

13. IPv 6 and neighbor discovery

IPv 6 uses 128-bit addresses, extension headers and no IPv 4-style broadcast. Neighbor Discovery uses ICMPv 6 instead of ARP. Routers do not fragment IPv 6 packets; source handling and path MTU matter.

Worked example: A link-local IPv 6 address serves local-link purposes and may need an interface scope identifier.
Exam question: Can IPv 4 NAT/broadcast rules be copied unchanged to IPv 6?
Answer: No. Addressing and protocol mechanisms differ.

14. Forwarding, longest prefix and routing

Forwarding selects the next hop for one packet; routing computes/distributes reachability. Choose the longest matching prefix, not simply the first textual route. Default /0 is the least-specific fallback.

Worked example: 192.0.2.70 matches /24 and 192.0.2.64/26, so the /26 next hop wins; the demo compares three destinations.
Exam question: Does a more-specific route always mean a shorter physical path?
Answer: No. Specificity is an address match rule, not distance.

Longest-prefix route selection

from ipaddress import ip_address, ip_network
routes = [(ip_network("0.0.0.0/0"), "default"),
          (ip_network("192.0.2.0/24"), "gateway-A"),
          (ip_network("192.0.2.64/26"), "gateway-B")]
def choose(text):
    address = ip_address(text)
    candidates = [(n.prefixlen, hop) for n, hop in routes if address in n]
    return max(candidates, default=(None, None))[1]
for text in ["192.0.2.70", "192.0.2.42", "198.51.100.8"]:
    print(text, choose(text))

Checked output:

192.0.2.70 gateway-B
192.0.2.42 gateway-A
198.51.100.8 default

15. Distance-vector and link-state routing

Distance-vector shares route-distance information with neighbors; link-state distributes topology information and computes paths. Both need convergence and loop handling. BGP policy routing is a different interdomain setting.

Worked example: A link-state node runs shortest-path computation on its topology database; distance-vector failures can lead to count-to-infinity without safeguards.
Exam question: Is a routing metric necessarily geographic distance?
Answer: No. It may represent cost, hop count, delay or policy-related preference.

16. ARP, ICMP and NAT

ARP resolves IPv 4 next-hop link addresses on suitable local links. ICMP carries control/error information. NAT rewrites addressing/ports at a boundary but does not encrypt data or replace firewall policy.

Worked example: To send to a remote IPv 4 host, ARP usually resolves the gateway. Traceroute relies on hop-limit/TTL expiration responses under suitable conditions.
Exam question: Does a ping reply prove the HTTPS application works?
Answer: No. It tests limited reachability, not DNS, TLS or application routing.

17. UDP and application reliability

UDP transports datagrams with ports and checksum rules but no built-in retransmission, ordering or congestion control. Applications/protocols above it can add those features.

Worked example: DNS often uses UDP; QUIC supplies transport features over UDP. UDP is not synonymous with unconditionally unreliable applications.
Exam question: Does one UDP send correspond to one TCP read?
Answer: No. UDP preserves datagram boundaries; TCP presents a byte stream.

18. TCP byte stream and handshake

TCP offers an ordered reliable byte stream with connection state. The three-way handshake synchronizes initial sequence state; application message boundaries require their own framing. It does not authenticate identity or encrypt.

Worked example: SYN, SYN-ACK, ACK establishes state under normal conditions. A read may return part of a message or several messages' bytes.
Exam question: Why not assume one send equals one recv?
Answer: TCP may split or combine data independently of application writes.
Client                 Server
  |--- SYN ------------->|
  |<-- SYN + ACK --------|
  |--- ACK ------------->|
  |   byte-stream data   |
Teaching handshake: no encryption or application identity proof is supplied by these flags.

19. TCP ACKs, retransmission and termination

TCP sequence numbers identify bytes; ACKs report progress and retransmission recovers loss. FIN closes one direction; RST aborts. Timers and duplicate data handling are part of the state machine.

Worked example: If a segment is lost, the sender can retransmit after timeout or loss inference; a duplicate retransmission must not duplicate application bytes.
Exam question: Does successful send mean the receiving application processed the data?
Answer: No. It can mean local buffering; transport delivery and application commitment differ.

20. Flow control versus congestion control

Flow control protects receiver buffer space; congestion control adapts to network capacity/loss signals. Sender flight size is constrained by both advertised receiver window and congestion state.

Worked example: A large receiver window cannot prevent a congested router queue from overflowing. Slow start is a sender congestion mechanism, not encryption.
Exam question: Can these controls be treated as the same window?
Answer: No. They protect different resources and are tracked separately.

21. DNS hierarchy, caching and records

DNS maps names to records through delegated authority and resolvers, caching answers according to TTL. A/AAAA name addresses, MX mail routing, and CNAME aliases; DNS does not fetch web content.

Worked example: Cached answers may avoid a new query; an NXDOMAIN is distinct from a reachable server returning HTTP 404.
Exam question: Does a DNS answer prove server identity for HTTPS?
Answer: No. TLS certificate/name validation supplies separate authentication.

22. HTTP, TLS and a browser trace

A common HTTPS trace resolves DNS, establishes TCP, negotiates TLS and exchanges HTTP; connection reuse/cache can skip work. HTTP/3 uses QUIC over UDP instead. TLS protects a properly authenticated transit channel, not compromised endpoints.

Worked example: DNS success plus 404 indicates application/resource routing, not failure to resolve a hostname.
Exam question: Should TLS verification be disabled to fix a certificate error?
Answer: No. Diagnose hostname, time, chain or server configuration instead.
Name -> DNS answer
     -> route and next hop
     -> TCP connection
     -> authenticated TLS
     -> HTTP request/response
One common HTTPS flow. Caching, connection reuse and HTTP/3 change the steps.

23. Email, file transfer and application protocols

Application protocols define messages and workflow above transport. SMTP handles mail transfer; IMAP/POP support retrieval; FTP has a distinct channel/security design. Use secure supported deployments rather than assuming plaintext protocols protect credentials.

Worked example: A mail message may cross multiple servers; transport encryption and end-to-end content protection are different properties.
Exam question: Does knowing a protocol's default port identify every live service?
Answer: No. Services can use other ports; verify the actual endpoint/configuration.

24. Sockets and message framing

A socket API exposes transport operations, not automatic domain-message handling. Stream applications need framing, partial-read/write handling, timeouts and cleanup. Bind/listen/accept differ from connect.

Worked example: A length-prefixed TCP message reads its length then exactly that many bytes, with bounds; EOF before completion is failure.
Exam question: Why impose a message-size bound?
Answer: To prevent unbounded allocation or resource exhaustion on malicious/broken input.

25. Network security and segmentation

Firewalls enforce traffic policy; TLS/VPNs protect selected channels; segmentation limits reach. Authentication/authorization and endpoint hygiene remain necessary. Test only networks/accounts you are permitted to inspect.

Worked example: An encrypted connection to a compromised endpoint can still leak data at that endpoint. NAT alone is not a security policy.
Exam question: Does encryption grant access permission?
Answer: No. Confidentiality and authorization are independent.

26. Troubleshooting and measurement

Work layer by layer:local link/address, route, DNS, transport, TLS, HTTP and application. Distinguish timeout, refusal, name failure and resource error. Measure latency/loss/throughput before assigning cause.

Worked example: If hostname fails but an appropriate known address works, investigate DNS; if TLS fails, check certificate/name/time rather than bypassing it.
Exam question: Can one successful ping settle intermittent performance problems?
Answer: No. A single limited test does not represent the full workload/path behavior.

27. Revision and calculation checklist

State units, width, prefix, protocol assumptions and the exact objective. Draw encapsulation and one request path; solve subnet/rate problems by arithmetic and test boundary addresses.

Worked example: For /26, total addresses=2^6=64; for 1000 bytes at 1 Mb/s, time=.008 s. Do not confuse bits and bytes.
Exam question: What makes a complete network exam answer?
Answer: Definition, layer responsibility, worked trace/calculation, assumptions and a relevant limitation.

Address and delivery scope

ItemScopeCommon mistake
MAC/link addressOne local linkUsing remote MAC across routers
IP address/prefixNetwork interface and route matchTreating prefix as port
PortTransport endpoint demultiplexingAssuming port proves identity
DNS nameName-to-record mappingAssuming DNS fetches web page
TLS certificateAuthenticated channel identity under validationDisabling verification

TCP and UDP comparison

PropertyTCPUDP
AbstractionByte streamDatagrams
Ordering/retransmissionBuilt inNot built in
Message boundaryApplication defines itDatagram boundaries retained
ControlFlow and congestion mechanismsHigher layer must handle needs
SecurityNot encrypted by itselfNot encrypted by itself

Subnet and rate calculations

QuestionWorkingResult
/24 total addresses2^(32-24)256
/26 total addresses2^(32-26)64
/26 conventional hosts64 - 262; exceptions do not use this formula
1000 bytes at 1 Mb/s8000 / 1000000 seconds8 ms transmission only
10 Mb/s x 100 ms10000000 x 0.1 bits1000000 bits = 125000 bytes

Revision and exam checklist

Explain each layer, draw a request trace, calculate subnet boundaries, distinguish flow/congestion control and diagnose errors by stage. State ordinary IPv4 subnet assumptions before subtracting two addresses. For CRC, state generator and arithmetic. Network testing requires permission.

Resources and sources

Standards and open textbooks support the rules. Diagrams and examples here are original; lab resources retain their own runtime requirements.

Comments