---
# System prepended metadata

title: Comm. Networks and Network Analysis
tags: [college, exam, CNNA]

---

# Comm. Networks and Network Analysis
[BOOK] *Behrouz A. Forouzan - Data Communications and Networking -McGraw-Hill Higher Education (2007)*
[NOTES BY] [Rohit Lal](https://rohitlal.live/)

###### tags: `college` `CNNA` `exam` 

---

<!-- 
Chapters to study - Ch 2, 14, 13, 19, 20, 22

IMP INSTRUCTIONS FOR MAKING NOTES:

- Always keep the chapter name or Slide name in heading 1
- Try Add all info in points
- Try to add images/block diagram as well. Coz a picture says a thousand words ;) 
- Add sufficient and important points which will act as a revision 
- Table of content will be generated automatically 

PRODUCTIVITY FEATURES

- You can directly copy-paste images/screenshot here. No need to upload, HackMD will do that automatically for u (The most amazing feature of HackMD)
- There are tons of other features in HackMD, so go through this link once https://hackmd.io/features?both (will hardly take few minutes but totally worth it)

-->

## Table of Content
[TOC]

# Chapter 2 : NETWORK MODELS

:::info
:bulb: This chapter introduces basic concepts of OSI, TCP/IP and addressing only. Further reading of later chapters are required
:::

## Networking devices

### Repeater

- operates at the physical layer.
- job is to regenerate the signal over the same network before the signal becomes too weak or corrupted
- they do not amplify the signal. When the signal becomes weak, they copy the signal bit by bit and regenerate it at the original strength. 
- 2 port device

### Bridge 

- Bridge = Repeater + Functionality of reading MAC addr
- Layer 2 device (due to MAC)
- Used to interconnect 2 LANs on the same protocol
- It is also 2 port device

### Hub 

- Hub works at physical layer of OSI model
- Used to setup LAN
- Has multiple ports
- Hub comes under star topology
- when a packet arrives at one port it is copied to other ports that all devices of LAN can see those packets
- Hub has no memory


### Switch

- Used to setup LAN
- It has memory. Stores MAC address
- Used in Layer 2
- It doesnt broadcast like hub, rather it forwards to particular port. 
- Services: Each layer at the sending site uses the services of the layer immediately below it

![](https://i.imgur.com/RLZwKfI.png)

### Router

- Router forwards data packets between computer networks
- Operates in layer 3 (Network Layer)
- Works for LAN, WAN, MAN

## The OSI Model

- Consists of seven separate but related layers
- Seven ordered layers: physical (layer 1), data link (layer 2),network (layer 3), transport (layer 4), session (layer 5), presentation (layer 6), and application (layer 7).
- ![](https://i.imgur.com/kvrnw87.png)

:::warning
:brain: A mnemonics  to remeber all the layers is 
**P**lease **D**o **N**ot **T**hrow **S**ausage **P**izza **A**way 
:::

### Physical Layer (Layer 1)

- **Physical characteristics** of interfaces and medium. 
- **Representation of bits** consists of a stream of bits (sequence of Os or 1s) with no interpretation
- **The transmission rate**-the number of bits sent each second is also defined by the physical layer
- **Synchronization of bits**. The sender and receiver not only must use the same bit rate but also must be synchronized at the bit level. In other words, the sender and the receiver clocks must be synchronized
- **Line configuration**.
- **Physical topology**.
- **Transmission mode**. The physical layer also defines the direction of transmission between two devices: simplex, half-duplex, or full-duplex.
- ![](https://i.imgur.com/uOXmkbh.png)

### Data Link Layer (Layer 2)

- transforms the physical layer, a raw transmission facility, to a reliable link.
- makes the physical layer appear error-free to the upper layer
- **Framing**. The data link layer divides the stream of bits received from the network layer into manageable data units called frames.
- **Physical addressing**. If frames are to be distributed to different systems on the network, the data link layer adds a header to the frame to define the sender and/or receiver of the frame.
- **Flow control**. If the rate at which the data are absorbed by the receiver is less than the rate at which data are produced in the sender the data link layer imposes a flow control mechanism
- **Error control**. The data link layer adds reliability to the physical layer by adding mechanisms to detect and retransmit damaged or lost frames. Error control is normally achieved through a trailer added to the end of the frame.
- **Access control**. When two or more devices are connected to the same link, data link layer protocols are necessary to determine which device has control over the link at any given time.

### Network Layer (Layer 3)

- The network layer is responsible for the source-to-destination delivery of a packet, possibly across multiple networks (links).
- If two systems are connected to the same link, there is usually no need for a network layer.
- Logical addressing.
- Routing.

### Transport Layer (Layer 4)

- The transport layer is responsible for process-to-process delivery of the entire message.
- A process is an application program running on a host.
- **Service-point addressing**.The network layer gets each packet to the correct computer; the transport layer gets the entire message to the correct process on that computer. The transport layer header must therefore include a type of address called a service-point address (or port address).
- **Segmentation and reassembly.** A message is divided into transmittable segments, with each segment containing a sequence number
- **Connection control**. 
- **Flow control**. flow control at this layer is performed end to end rather than across a single link.
- **Error control**. error control at this layer is performed process-to process rather than across a single link.

### Session Layer (Layer 5)

- **Dialog control**. The session layer allows two systems to enter into a dialog. It allows the communication between two processes to take place in either halfduplex or full-duplex mode.
- **Synchronization.** The session layer allows a process to add checkpoints, or synchronization points, to a stream of data.

### Presentation Layer (Layer 6)

- Concerned with the syntax and semantics of the information exchanged between two systems.
- **Translation**. Because different computers use different encoding systems, the presentation layer is responsible for interoperability between these different encoding methods
- **Encryption**. 
- **Compression**.

### Application Layer (Layer 7)

- The application layer enables the user, whether human or software, to access the network
- It provides user interfaces and support for services such as electronic mail, remote file access and transfer, shared database management, etc
- **Network virtual terminal**. A network virtual terminal is a software version of a physical terminal, and it allows a user to log on to a remote host.
- **File transfer, access, and management.**
- **Mail services.**
- **Directory services.** provides distributed database sources and access for global information about various objects and services

### Summary of OSI Layers

![](https://i.imgur.com/pOGj25Y.png)

## TCP/IP PROTOCOL SUITE

- The original TCP/IP protocol suite was defined as having four layers. Corresponding OSI similarity is also given 
    * **host-to-network** - Similar to physical and data link layers.
    * **internet** - equivalent to the network layer, and the application layer
    * **transport** - takes care of transport and part of the duties of the session layer.
    * **application** - equivalent to session, presentation, and application layers

![](https://i.imgur.com/OlfUZw5.png)

Depths of these layers are explained later. Below are very short summary 

### Physical and Data Link Layers

- TCP/IP does not define any specific protocol
- supports all the standard and proprietary protocols

### Network Layer

- TCP/IP supports the Internetworking Protocol. IP, in turn, uses four supporting protocols: ARP, RARP, ICMP, and IGMP

### Transport Layer

- the transport layer was represented in TCP/IP by two protocols: TCP and UDP.
- UDP and TCP are responsible for delivery of a message from a process (running program) to another process.
- new transport layer protocol, SCTP, has been devised to meet the needs of some newer applications.

## ADDRESSING

Four levels of addresses are used in an internet employing the TCP/IP protocols:

- physical (link) addresses
- logical (IP) addresses
- port addresses
- specific addresses

![](https://i.imgur.com/HPJ2TqG.png)

### Physical Addresses

- It is the address of a node as defined by its LAN or WAN.
- It is included in the frame used by the data link layer
- lowest-level address.
- Ethernet uses a 6-byte (48-bit) physical address

### Logical Addresses

- It is necessary for universal communications that are independent of underlying physical networks
- A logical address in the Internet is currently a 32-bit address that can uniquely define a host connected to the Internet.
- No two publicly addressed and visible hosts on the Internet can have the same IP address.

### Port Addresses

- A port address in TCP/IP is 16 bits in length.
- end objective of Internet communication is a process communicating with another process.


| Variable |         Meaning         |
|:--------:|:-----------------------:|
|  a, b, c |    Source Port number   |
|   j, k   | Destination Port Number |
|   A, P   |  Src and Dst IP address |
|    H2    | Src and Dst Mac address |
|    T2    |      Error Control      |

![](https://i.imgur.com/4LmLzi6.png)



---

# Chapter 13 : WIRED LANS: ETHERNET

:::danger
This Chapter has incomplete summary. To be completed later. 
:::

The IEEE has subdivided the data link layer into two sublayers: 
* logical link control (LLC) 
    - flow control, error control, and part of the framing duties are collected into one sublayer called the logical link control.
* media access control (MAC).
    - IEEE Project 802 has created a sublayer called media access control that defines the specific access method for each LAN
    - it defines CSMA/CD as the media access method for Ethernet LANs and the tokenpassing method for Token Ring and Token Bus LANs

## STANDARD ETHERNET

four generations: Standard Ethernet (10 Mbps), Fast Ethernet (100 Mbps), Gigabit Ethernet (l Gbps), and Ten-Gigabit Ethernet (l0 Gbps)

## MAC Sublayer

### Frame Format
The Ethernet frame contains seven fields: preamble, SFD, DA, SA, length or type of protocol data unit (PDU), upper-layer data, and the CRe.

Ethernet does not provide any mechanism for acknowledging received frames, making it what is known as an unreliable medium

- **Preamble**: contains 7 bytes (56 bits) of alternating Os and 1s that alerts the receiving system to the coming frame and enables it to synchronize its input timing.
- **Start frame delimiter (SFD)**:The second field (1 byte: 10101011) signals the beginning of the frame. The last 2 bits is 11 and alerts the receiver that the next field is the destination address.
- **Destination address (DA)**: 6 bytes and contains the physical address of the destination station
- **Source address (SA)**: 6 bytes and contains the physical address of the sender of the packet.
- **Length or type**: IEEE standard used it as the length field to define the number of bytes in the data field
- **Data**: carries data encapsulated from the upper-layer protocols. Minimym 46 bytes and a maximum of 1500 bytes
- **CRC**: contains error detection information

---

# CHAPTER 19 Network Layer: Logical Addressing

Today, we use the term IP address to mean a logical address in the network layer of the TCP/IP protocol suite.

The Internet addresses are 32 bits in length; this gives us a maximum of $2^{32}$
addresses. These addresses are referred to as IPv4 (IP version 4) addresses. IPv6 has 128bit address 

## IPv4 Address

- An IPv4 address is a 32-bit address that uniquely and universally defines the connection of a device (for example, a computer or a router) to the Internet.
- each address defines one, and only one, connection to the Internet.

## Classful Addressing

:::info
This is probably the most important topic in terms of exams.
:::

![](https://i.imgur.com/9xbyLKc.png)
- Class D is for multicast networking
- Class E are reserved for experimental and research purposes.


![](https://i.imgur.com/bJ1r80W.png)

Range of special IP addresses:

* 169.254.0.0 – 169.254.0.16 : Link local addresses
* 127.0.0.0 – 127.0.0.8 : Loop-back addresses
* 0.0.0.0 – 0.0.0.8 : used to communicate within the current network.


### Netid and Hostid

- IP address in class A, B, or C is divided into netid and hostid.
- This concept does not apply to classes D and E
- In class A, one byte defines the netid and three bytes define the hostid. In class B,two bytes define the netid and two bytes define the hostid. In class C, three bytes define the netid and one byte defines the hostid.
![](https://i.imgur.com/pSY8V0L.png)

### Mask

- concept does not apply to classes D and E.
- The mask can help us to find the netid and the hostid.
- ![](https://i.imgur.com/ANW80Y5.png)
- Classless Interdomain Routing (CIDR) notation
- classful addressing is a special case of classless addressing

### Subnetting

- During the era of classful addressing, If an organization was granted a large block in class A or B, it could divide the addresses into several contiguous groups and assign each group to smaller networks (called subnets)
- Subnetting increases the number of 1s in the mask

### Supernetting

- In supernetting, an organization can combine several class C blocks to create a larger range of addresses

## Classless Addressing

- overcome address depletion and give more organizations access to the Internet
- addresses are still granted in blocks


### Address Blocks

- Restriction to simplify the handling of addresses, the Internet authorities impose three restrictions on classless address blocks:
    1. The addresses in a block must be contiguous, one after another.
    2. The number of addresses in a block must be a power of 2 (4, 2, 4, 8, ... ).
    3. The first address must be evenly divisible by the number of addresses

### Mask

- The address and the `/n` notation completely define the whole block (the first address, the last address, and the number of addresses).
- Do examples from book
 ![](https://i.imgur.com/bGecoKh.png)

### Network Addresses

- The first address is called the network address and defines the organization network.

### Two-Level Hierarchy: No Subnetting

- An IP address can define only two levels of hierarchy when not subnetted.
- The n leftmost bits of the address x.y.z.t/n define the network (organization network); the $32 - n$ rightmost bits define the particular host (computer or router) to the network.
- The part of the address that defines the network is called the prefix; the part that defines the host is called the suffix

### Three-Levels of Hierarchy: Subnetting

- An organization that is granted a large block of addresses may want to create clusters of networks (called subnets) and divide the addresses between the different subnets. The rest of the world still sees the organization as one entity; however, internally there are several subnets.
- The organization has its own mask; each subnet must also have its own
- Important Examples
    -  https://youtu.be/fTTfbxrYRE4
    -  Example 19.10 (Pg. 561)

### More Levels of Hierarchy

- The structure of classless addressing does not restrict the number of hierarchical levels
- A national ISP can divide a granted large block into smaller blocks- and assign each of them to a regional ISP.


# CHAPTER 20 : NETWORK LAYER - INTERNET PROTOCOL

:::danger
This Chapter has incomplete summary. To be completed later. 
:::

## Internetworking

- To solve the problem of delivery through several links, the network layer (or the internetwork layer, as it is sometimes called) was designed. The network layer is responsible for host-to-host delivery and for routing the packets through the routers or switches.
- The network layer is responsible for checking its routing table to find the routing information
- If the packet is too large, the packet is fragmented
- The network layer at the switch or router is responsible for routing the packet. When a packet arrives, the router or switch consults its routing table and finds the interface from which the packet must be sent. The packet, after some changes in the header, with the routing infonnation is passed to the data link layer again.
- The network layer at the destination is responsible for address verification; it makes sure that the destination address on the packet is the same as the address of the host


### Internet as a Datagram Network

- The Internet, at the network layer, is a packet-switched network.
- switching can be divided into three broad categories: circuit switching, packet switching, and message switching
- The Internet has chosen the datagram approach to switching in the network layer.

### Internet as a Connectionless Network

- In a **connection-oriented** service, the source first makes a connection with the destination before sending a packet
- In **conneetionless service**, the packets in a message may or may not travel the same path to their destination. This type of service is used in the datagram approach to packet switching. The Internet has chosen this type of service.
- The reason for this decision is that the Internet is made of so many heterogeneous networks that it is almost impossible to create a connection from the source to the destination without knowing the nature of the networks in advance.

## IPv4 

- IPv4 is an unreliable and connectionless datagram protocol - a *best-effort* delivery service.
- *best-effort* means that IPv4 provides no error control or flow control (except for error detection on the header)
- If reliability is important, IPv4 must be paired with a reliable protocol such as TCP.
- IPv4 is also a connectionless protocol for a packet-switching network that uses the datagram approach

### Datagram

![](https://i.imgur.com/tqJscBS.png)

- Packets in the IPv4 layer are called datagrams
- datagram is a variable-length packet consisting of two parts: header and data. The header is 20 to 60 bytes in length
- **Version (VER).** This 4-bit field defines the version of the IPv4 protocol.
- **Header length (HLEN).** This 4-bit field defines the total length of the datagram header in 4-byte words. When there are no options, the header length is 20 bytes, and the value of this field is 5 (5 x 4 = 20). When the option field is at its maximum size, the value of this field is 15 (15 x 4 = 60).
- **Services** - this 8-bit field. This field, previously called *service type*, is now called *differentiated services*. Comparision given below
    - *Service Type* In this interpretation, the first 3 bits are called precedence bits. The next 4 bits are called type of service (TOS) bits, and the last bit is not used.
        - *Precedence*: 3-bit subfield ranging from 0 (000 in binary) to 7 (111 in binary). The precedence defines the priority of the datagram in issues such as congestion. If a router is congested and needs to discard some datagrams, those datagrams with lowest precedence are discarded first.
        - *TOS bits:* 4-bit subfield. one and only one of the bits can have the value of 1 in each datagram. 
            ![](https://i.imgur.com/cs9OG2D.png)
            
    - **Differentiated Services** the first 6 bits make up the codepoint subfield, and the last 2 bits are not used.
        - *codepoint subfield* 3 rightmost bits are Os, the 3 leftmost bits are interpreted the same as the precedence bits in the service type interpretation. it is compatible with the old interpretation.


