Network Layer - Computer Networks
Theory
- Categories of Network
- Local Area Network (LAN)
- Network in a single office, building, or campus
- Metropolitan Area Network (MAN)
- Network extended over an entire city
- Wide Area Network (WAN)
- Network providing long-distance communication over a country, a continent, or the whole world
- Responsibilities
- Host to Host (Source to Destination/Machine to Machine) Delivery
- Delivery of Packets across multiple networks
- Uses Logical Address (IP Address) to perform Packet delivery
- IP gives information about message to be sent and to which Host in that network
- Routing => Decides the path to be followed using Router
- Fragmentation
- Diving a larger message into small Fragments
- Congestion Control
- Addressing (TCP/IP Protocol) => Each address is related to one layer in the TCP/IP architecture
- Physical
- Logical
- Port => A port address is a 16-bit address represented by one decimal number
- Application Specific
- Address Resolution Protocol (ARP)
- Converting Logical address to Physical address => Converts IP address into Mac address (48 bit)
- Level 3 protocol
- Source sends
- Source IP | Mac address | Destination IP | Broadcast Message
- Message is sent to all, then destination reply in unicast way giving its Mac address
- Types
- Host - Host
- Host - Router
- Router - Host
- Router - Router
Classful Addressing
- Before 1980 => Total 32 bits in IPV4 => 8 bit Network number and 24 bit Host number
- Classful Addressing => Dotted Decimal Representation
- 32 bits are divided into 8 bits octet
- NID → HID → PID
- Broadcast Address
- Limited
- Address is 255.255.255.255
- Broadcast to all hosts of the network from inside the network
- Direct
- Address is Last address of that network
- Broadcast to all hosts of the network from different network
- Problems of Classful Addressing
- Wastage of IP Address
- Maintenance is time consuming
- More prone to errors
- Network Address Translation (NAT)
- To solve IPv4 low number problem
- Translates IP address
- Public IP to Private IP
- Private IP to Public IP
- NAT Translation Table
- | Port | Private IP | Public IP |
Class A
- First 1 bit of 1st octet = 0
- Used as a Prefix representing Class A
- First 1 octet represents Network ID
- Number of IP address = 231
- Number of Networks = 27 - 2 = 128 - 2 = 126
- 00000000 & 01111111 are not given to anyone
- Last 24 bits (3 octet) represents Host ID
- Number of hosts/users possible in every Networks = 224 - 2
- N.0.0.0 represents the whole network
- N.255.255.255 is used as Directed Broadcast Address (DBA) to send packet to every host
- Default Mask = 255.0.0.0
- Doing
&
operation of IP address will give Network ID
- It is number of continuous 1
Class B
- First 2 bit of 1st octet = 10
- Range = 128 to 191 = 64 values
- First 2 octet represents Network ID
- Number of IP address = 230 => About 25% of total
- Number of Networks = 214 = 16384
- Last 2 octet represents Host ID
- Number of Host possible in every Network = 216 - 2 = 65536 - 2 = 65534
- 10N.M.0.0 represents the whole network
- 10N.M.255.255 is used as DBA
- Default Mask = 255.255.0.0
Class C
- First 3 bit of 1st octet = 110
- Range = 192 to 223 = 32 values
- First 3 octet represents Network ID
- Number of IP address = 229 => About 12.5% of total
- Number of Networks = 221 = About 20 Lakh
- Last 1 octet represents Host ID
- Number of Host possible in every Network = 28 - 2 = 256 - 2 = 254
- 110N.M.P.0 represents the whole network
- 110N.M.P.255 is used as DBA
- Default Mask = 255.255.255.0
Class D
- First 4 bit of 1st octet = 1110
- Range = 224 to 239 = 15 values
- All 4 octet represents Network ID
- Number of IP address = 228 => About 6.25% of total => About 250 Million
- Number of Networks = 0
- Number of Host = 0
- All address are reserved for multi-casting or Group email/broadcast
Class E
- First 4 bit of 1st octet = 1111
- Range = 240 to 255 = 15 values
- All 4 octet represents Network ID
- Number of IP address = 228 => About 6.25% of total => About 250 Million
- All address are reserved for Military purpose
Classless Addressing (CIDR)
- After 1993 => No classes => Only Blocks
- Format
- Block ID => Represents network
- Host ID
- Notation
- x.y.z.w/n
- Number of bits for Block ID = n
- Number of bits for Host ID = 32 - n
- Network ID = n & IP address
- Rules
- Address should be contiguous
- Number of address in a block must be in power of 2
- First address of every block must be evenly divisible with size of block
- Last n bits of the first address should be 0, where n is power of 2
Subnetting
- Dividing the big network into small network
- Classful Addressing
- Divide the hosts into 2 parts by fixing the 1st bit of the host
- Subnet ID = 1st address
- Subnet DBA = Last address
- Number of hosts gets reduced
- One router is placed inside the network to decide subnet for sending packets
- Calculated by subnet mask => Number of continuous 1
- Computation increased
- Variable length Subnet Masking (VLSM)
- Keep fixing the MSB bit to divide the remaining hosts into 2 parts
- Available Hosts => 2n - 2n, where n is number of division
- Router is set up inside the network
- Classless Addressing (CIDR)
- Fix the MSB bit of host ID to divide the remaining hosts into 2 parts
- Mask will increase by 1, each time of a division
- Router is set up inside the network
- Do & operation of the packet received with the Default mask of all the interface, if you get that interface then it is the interface
- If more than one answer than choose the interface will more number of 1 in prefix, as searching will become easier due to lesser number of 1
- VLSM
- Keep fixing the MSB bit of host ID to divide the remaining hosts into 2 parts
- Mask will increase by 1, each time of a division
IPv4
- Connectionless
- Datagram Service => Can choose any path
- Use a 32-bit (4-byte) physical address written as decimal digits, Every byte (2 hexadecimal digits) is separated by a dot
- Payload => Data received from Transport Layer
- Size from 0 to 65525 bytes
- Total value is 216
- Version (VER) = 0100 = 4
- Header Length (HLEN)
- Header Size => 160 bits => 20 - 60 Bytes
- Its actual value is written by multiplying by 4
- Differentiated Services Code Point (DSCP)
- Traffic Type
- First 3 bits represents precedence => Like Priority defined, Routine packet, Immediate send
- 4th Bit => Delayed => Can afford delay or not
- Voice call cannot afford delay
- 5th Bit => Throughput => Rate of transfer more or less
- 6th Bit => Reliability => Packet reach reliably and does not drop in the way
- File transfer needs to be reliable
- 7th Bit => Cost => Less cost by following shortest path or Routine send
- 8th Bit => Reserved for future like DSCP
- DSCP
- Changes made later
- 0 to 5 bits are reserved for DSCP
- 6 to 7 bits are reserved for Explicit Congestion Notification (ESN) => To reduce the speed if congestion increases
- Total Length = 65535 = 216
- Fragmentation
- Identification Bits
- Identify if the packet belongs to one Packet when they reach the destination from different routes
- Flag
- 1st Bit, MSB is reserved = 0
- 2nd Bit, Do not Fragment (DF)
- 0 means Fragmentation is done
- 1 means Fragmentation is not done
- 3nd Bit, More Fragment (MF)
- 1 if there is more fragment behind it
- Fragment Offset
- Number of Payload Bytes ahead of it
- Answer is written after diving by 8
- Time To Live (TTL)
- If Packet is struck on loop due to data changes or router does not contains proper information
- Else will create congestion
- Protocols => Which protocols are being used
- Header Checksum => Used for error detection
- Options & Padding => Some extra information, Not mandatory
- If header is of 10 Byte than this is 0, If header is of 60 Byte than this is of 40 Byte
- Record Route
- Route of the node is recorded
- Maximum possible number of router whose address can be stored is 40B/4B < 10
- Source Routing => Source will give the information about which address it will pass through
- Strict Source Routing => Exact route is defined
- Loose Source Routing => Exact route is not defined
- Padding
- Adding extra bytes to the size of address to make it in multiple of 4
IPv6
- Connectionless, Datagram Service
- Low processing for routers as size of base header is reduced
- Version (VER) = 0110 = 6
- Priority
- Traffic Type
- Used for Congestion control
- Flow Label
- Used for real time data processing
- Datagram circuit is converted into virtual circuit
- Makes sure that all packets follow same path, Reservation is used for less data loss
- Payload Length = 65535
- Jumbograms => Extra Packets up to 4 GB
- Next Header => Contains information about Extension header if added
- Format => Base Header | Extension Headers | Data
- Base Header => 40 bytes = 320 bits
- Mandatory field, Fixed size
- Hop Limit
- Maximum hops it can go to
- Values keeps on decreasing and Packet removed to avoid congestion
- Extension Headers
- Routing Header
- Sender decides which router the Packet should go through
- Hop by Hop Option
- Information that you want to provide to the hops you go through
- Fragment Header
- Like IPv4 but Fragmentation cannot be done by router but the source only
- Authentication Header
- To send User password, Data integration maintain, Hash values
- Destination options
- Data that only destination should read
- Encapsulating Security Payload
- Uses encryption & decryption for security
Routing Protocols
- Works on Uni-casting
- Forwarding
- Sending the Packet in the right path
- Inter-networks
- Two or more networks connected become an inter-network, or internet
- Internet is divided into Autonomous systems
- Opens the Packet and decides by the help of Routing table, where to send, Every router maintains its Routing table
- Static Routing Table => Made Manually
- Dynamic Routing Table => Made Automatically
- Types
- Intra Domain => Within same Autonomous Systems
- Distance Vector Routing (DVR) => Routing Information Protocol (RIP)
- Link State Routing (LSR) => Open Shortest Path First (OSPF)
- Inter Domain => Within different Autonomous Systems
- Path Vector Routing (PVR) => Border Gateway Protocol (BGP)
- Distance Vector Routing (DVR) => Routing Information Protocol (RIP)
- Routing Table (RT)
- | Destination/Node/Router | Cost/Distance/Propagation Delay | Next |
- Steps
- Every Router in the network will know the total number of Router in network
- First RT will only contain information about its neighbors, all others cost will be infinite, creating a local RT
- Then information of Distance vector will be shared with all its neighbors
- Now each will update and create its new Routing Table
- All the route will go thorough its neighbor, If more than one neighbor than choose the minimum value
- Similarly it goes on
- Count to Infinity Problem
- When link breaks and wrong interpretation is received as only Distance vector is being sent and not the actual path
- Link State Routing (LSR) => Open Shortest Path First (OSPF)
- First Link state table is created
- Contains information about its neighbor and their distance
- Also contains extra information about Sequence number and TTL
- Flooding
- Each router will sent its Link state table to every other Router
- High Bandwidth & Congestion
- Global Knowledge => Each node will know the entire connection diagram
- Dijkstra's Algorithm => Single source shortest path
- Each node will find its shortest path to every other node
- Routing Table (RT)
- | Node/Router | Cost/Distance | Via |
- Path Vector Routing (PVR) => Border Gateway Protocol (BGP)
- IP Security (IPSec)
- Used both by IPv4 & IPv6
- Uses
- Confidentiality, Authentication/Integrity, Replay attack protection
- Collection of protocols
- Encapsulating security payload (ESP)
- Authentication header (AH)
- Internet key exchange (IKE)
- Two modes of operation
- Transport mode
- Used for end to end communication
- Encapsulates the message received from the transport layer with IPSec header & tail before adding IPv4 or IPv6 header
- Tunnel mode
- Generally used in VPN
- Used for router to router, More secure
- Encapsulates the message received from the transport layer with IPSec header & tail after adding IPv4 or IPv6 header
- Again IPv4 or IPv6 header needs to be added as original header gets hidden