CN Module2
CN Module2
(BCSC 0008)
MODULE-2
NOTES
BY: ROHIT AGARWAL
(Teaching Associate)
(CSE Dept)
MODULE-2
NETWORK LAYER
TRANSPORT LAYER
APPLICATION LAYER
IPv4 VS IPv6
NETWORK
LAYER
DOTTED DECIMAL NOTATION OF
IP ADDRESS
HEXADECIMAL NOTATION OF IP
ADDRESS
IP ADDRESS CLASSES
IP ADDRESS CLASSES
IP ADDRESS DISTRIBUTION
WITHIN A NETWORK
Subnetting
• What is subnetting
– Process of subdividing a single class of network
into multiple subnetworks.
– A subnetted network address contains a network
address, subnet address and host address.
Subnetting
• What is subnetting
– Process of subdividing a single class of network
into multiple subnetworks.
– A subnetted network address contains a network
address, subnet address and host address.
Subnet Masks
BLOCK ID HOST ID
Notation Used
x.y.z.w/n
Here n shows number of network bits
Of following IP 200.10.20.40/28
On comparing given IP 200.10.20.40/28
with Notation x.y.z.w/n
Here n=28
So total network bits=28 out of 32
So host bits=32 – 28 = 4
Total no. of Possible Hosts= 24 = 16
32 BITS
BLOCK ID HOST ID
28 Bits 4 Bits
As network is 28 bits and host is 4 bits
So subnet mask is
11111111.11111111.11111111.11110000
255 . 255 . 255 . 240
Given IP is 200.10.20.40
On doing AND operation over binary of Last Octet
of given IP with Subnet Mask we get network ID
240 11110000
40 00101000
------------------------
32 00100000
So Network id/Block id is 200.110.200.32/28
Rules for CIDR Addressing
• Address should be contiguous.
• Number of addresses in a block must be
in power of 2
195.10.20.128/27 –
195.10.20.159/27
Subnetwork
Network Divide S1
S
Subnetwork
S2
195.10.20.128/26 195.10.20.160/27 –
195.10.20.191/27
Variable Length Subnet Masking(VLSM)
Technique to make subnetworks of different
different sizes
Network allow of different size
subnetworks are known as Flexibility
Subnetwork
Network Divide S1 Subnetwork
S S2
Subnetwork
S3
200.10.20.0
200.10.20.00000000
200.10.20.00000000 200.10.20.10000000
S1
200.10.20.10000000 200.10.20.11000000
S2 S3
Subnetwork
Network Divide S1
Subnetwork
S2
S
Subnetwork
S3
Subnet Mask S1
255.255.255.128
Availlable Subnet Mask S2
Subnetwork 255.255.255.192
hosts
S1
128-2=126 Availlable
Subnetwork hosts
200.10.20.00000000 – S2
200.10.20.01111111 64-2=62
200.10.20.10000000 –
200.10.20.0 - 200.10.20.127 200.10.20.101111111
200.10.20.128 –
Subnetwork 200.10.20.191
S3
200.10.20.11000000 –
200.10.20.111111111
Total Availlable
200.10.20.192 - 200.10.20.255
hosts
256-6=250
Availlable
Subnet Mask S3 hosts
255.255.255.192 64-2=62
Variable Length Subnet Masking(VLSM)
If n=number of Subnets
Subnetwork
Network Divide S1 Subnetwork
S S2
Subnetwork
S3
245.248.128.0/20
245.248.10000000.00000000
245.248.10000000.00000000 245.248.10001000.00000000
S1
245.248.10001000.00000000 245.248.10001100.00000000
S2 S3
Subnetwork
Network Divide S1
Subnetwork
S2
S
Subnetwork
S3
Subnetwork
S1
245.248.10000000.00000000 – Subnetwork
245.248.10000111.11111111 S2
245.248.10001000.00000000 –
245.248.128.0/21 – 245.248.10001011.11111111
245.248.135.255/21 245.248.136.0/22 –
Subnetwork 245.248.139.255/22
S3
245.248.10001100.00000000 –
245.248.10001111.11111111
245.248.140.0/22 –
245.248.143.255/22
INTERNETWORKING
&
CONNECTING
DEVICES
ADDRESS
MAPPING
IP Address
Physical IP Logical IP
(MAC) (IP)
(Private) (Publically Shared)
48 Bit or 6 Byte 32 Bit or 4 Byte
Mapping
Logical IP Physical IP
X X
B E
A A A C D
(MAC) (IP) FFFFFFFF
(IP)
X X
B E
A D
C C A A
(IP) (MAC) (IP) (MAC)
X X
B E
A D
Address Mapping
Host to Host
(H to H)
Host to Router
(H to R)
Router to Host
(R to H)
Router to Router
(R to R)
FORWARDING
&
DELIVERY
DELIVERY
The network layer supervises the handling of the
packets by the underlying physical networks. We define
this handling as the delivery of a packet.
DELIVERY
DIRECT INDIRECT
Figure 22.1 Direct and indirect delivery
22.58
FORWARDING
22.60
Figure 22.3 Host-specific versus network-specific method
22.61
Figure 22.4 Default method
22.62
Figure 22.5 Simplified forwarding module in classless address
22.63
Example 22.1
Solution
Table 22.1 shows the corresponding table.
22.64
Figure 22.6 Configuration for Example 22.1
22.65
Table 22.1 Routing table for router R1 in Figure 22.6
22.66
Figure 20.5 IPv4 datagram format
20.67
Figure 20.6 Service type or differentiated services
20.68
Note
20.69
Table 20.1 Types of service
20.70
Table 20.2 Default types of service
20.71
Table 20.3 Values for codepoints
20.72
Note
20.73
Figure 20.7 Encapsulation of a small datagram in an Ethernet frame
20.74
Figure 20.8 Protocol field and encapsulated data
20.75
Table 20.4 Protocol values
20.76
Example 20.1
Solution
There is an error in this packet. The 4 leftmost bits (0100)
show the version, which is correct. The next 4 bits (0010)
show an invalid header length (2 × 4 = 8). The minimum
number of bytes in the header must be 20. The packet has
been corrupted in transmission.
20.77
Example 20.2
Solution
The HLEN value is 8, which means the total number of
bytes in the header is 8 × 4, or 32 bytes. The first 20 bytes
are the base header, the next 12 bytes are the options.
20.78
Example 20.3
Solution
The HLEN value is 5, which means the total number of
bytes in the header is 5 × 4, or 20 bytes (no options). The
total length is 40 bytes, which means the packet is
carrying 20 bytes of data (40 − 20).
20.79
Example 20.4
Solution
To find the time-to-live field, we skip 8 bytes. The time-to-
live field is the ninth byte, which is 01. This means the
packet can travel only one hop. The protocol field is the
next byte (02), which means that the upper-layer protocol
is IGMP.
20.80
Figure 20.9 Maximum transfer unit (MTU)
20.81
Table 20.5 MTUs for some networks
20.82
ROUTING
With in Between
Autonomous System Autonomous System
Figure 14.1 Autonomous systems
86
Figure 14.2 Popular routing protocols
87
14.2 DISTANCE VECTOR ROUTING
89
Figure 14.4 Initialization of tables in distance vector routing
In distance vector routing, each node shares its table with its
immediate neighbor periodically (eg every 30s) and when
there is a change.
90
Figure 14.5 Updating in distance vector routing
91
Figure 14.6 Two-node instability – what can happen with distance vector routing
Count to Infinity Problem
Both A and B know
where X is.
1. Define infinity to be a much smaller value, such as 100. Then it doesn’t take too
long to become stable. But now you can’t use distance vector routing in large
networks.
2. Split Horizon – instead of flooding entire table to each node, only part of its
table is sent. More precisely, if node B thinks that the optimum router to
reach X is via A, then B does not need to advertise this piece of info to A – the
info has already come from A.
3. Split Horizon and Poison Reverse – Normally, the distance vector protocol uses
a timer. If there is no news about a route, the node deletes the route from its
table. So when A never hears from B about the route to X, it deletes it.
Instead, Node B still advertises the value for X, but if the source of info is A, it
replaces the distance with infinity, saying “Do not use this value; what I know
about this route comes from you.”
93
Three-node instability – no solutions here!
94
14.3 RIP
100
Figure 14.15 Concept of link state routing
Each router floods this info (via a Link State Packet) to other
routers periodically (when there is a change in the topology,
or every 60 to 120 minutes).
102
Figure 14.17 Dijkstra algorithm
103
Figure 14.18 Example of formation of shortest path tree
104
Table 14.1 Routing table for node A
105
106
OSPF
The Open Shortest Path First (OSPF)
protocol is an intradomain routing
protocol based on link state routing.
108
LSPs (Link State Packets)
109
LSPs
1. Router Link: A router link advertises the existence of a
router as a node. In addition to giving the address of the
announcing router, this type of advertisement can define one or
more types of links that connect the advertising router to other
entities.
Figure 14.21 Point-to-point link
111
Types of link
• A transient link announces a link to a transient network,
a network that is connected to the rest of the networks
by one or more routers. This type of advertisement
should define the address of the transient network and
the cost of the link.
• A stub link advertises a link to a stub network, a
network that is not a through network. Again, the
advertisement should define the address of the network
and the cost.
• A point-to-point link should define the address of the
router at the end of the point-to-point line and the cost
to get there.
2. Network Link: A network link advertises the
network as a node. However, since a network
cannot do announcements itself (it is a passive
entity), one of the routers is assigned as the
designated router and does the advertising.
3. Summary link to network: This is done by an
area border router; it advertises the summary of
links collected by the backbone to an area or the
summary of links collected by the area to the
backbone.
LSPs
4. Summary link to AS: This is done by an AS router
that advertises the summary links from other ASs to
the backbone area of the current AS, information
which later can be disseminated to the areas so
that they will know about the networks in other
ASs.
5. External link. This is also done by an AS router to
announce the existence of a single network outside
the AS to the backbone area to be disseminated
into the areas.
OSPF message format
14.6 PATH VECTOR ROUTING
Path vector routing is similar to distance vector routing. There is at least
one node, called the speaker node, in each AS that creates a routing table
and advertises it to other speaker nodes in the neighboring ASs..
Initialization
Sharing
Updating
119
Figure 14.50 Internal and external BGP sessions
20.1
Figure 20.4 Position of IPv4 in TCP/IP protocol suite
20.2
Figure 20.5 IPv4 datagram format
20.3
Header length (HLEN). This is a 4-bit field
20.4
Service Type
First 3 bits are called precedence bits.
Next 4 bits are called type of service (TOS) bits.
Last bit is not used.
20.6
Table 20.2 Default types of service
20.7
Note
20.8
Identification
20.9
Figure 20.10 Flags used in fragmentation
20.10
Flags. This is a 3-bit field.
The first bit is reserved.
The second bit is called the do Not fragment bit. If
its value is 1, the machine must not fragment the
datagram If its value is 0, the datagram can be
fragmented if necessary.
The third bit is called the more fragment bit. If its
value is 1, it means the datagram is not the last
fragment; there are more fragments after this one. If
its value is 0, it means this is the last or only
fragment
20.11
Figure 20.8 Protocol field and encapsulated data
20.12
Table 20.4 Protocol values
20.13
Example 20.1
Solution
There is an error in this packet. The 4 leftmost bits (0100)
show the version, which is correct. The next 4 bits (0010)
show an invalid header length (2 × 4 = 8). The minimum
number of bytes in the header must be 20. The packet has
been corrupted in transmission.
20.14
Example 20.2
Solution
The HLEN value is 8, which means the total number of
bytes in the header is 8 × 4, or 32 bytes. The first 20 bytes
are the base header, the next 12 bytes are the options.
20.15
Example 20.3
Solution
The HLEN value is 5, which means the total number of
bytes in the header is 5 × 4, or 20 bytes (no options). The
total length is 40 bytes, which means the packet is
carrying 20 bytes of data (40 − 20).
20.16
Example 20.4
Solution
To find the time-to-live field, we skip 8 bytes. The time-to-
live field is the ninth byte, which is 01. This means the
packet can travel only one hop. The protocol field is the
next byte (02), which means that the upper-layer protocol
is IGMP.
20.17
A Datagram of 3000 B (20 B header +2980 B
Data) reached at router and must be forwarded
to a link with MTU of 500 B. how many
fragmentations will be generated and also write
MF (more fragment), offset and total length
value for all
3000 B
500 B
Router N/W
20+480
20+2980
2980/480= 7 fragment
20.18
P7 P6 P5 P4 P3 P2 P1
100+20 480+20 480+20 480+20 480+20 480+20 480+20
0 1 1 1 1 1 1 MF
360 300 240 180 120 60 0 Offset
For P2
Offset=480/8=60
For P3
Offset=480+480/8=120
20.19
An IP datagram of size 1000 bytes arrives at a router. The router has
to forward this packet on a link whose MTU (maximum
transmission unit) is 100 bytes. Assume that the size of the IP header
is 20 bytes. The number of fragments that the IP datagram will be
divided into for transmission is :
20.20
MTU = 100 bytes
Size of IP header = 20 bytes
So, size of data that can be transmitted in one
fragment = 100 – 20 = 80 bytes
Size of data to be transmitted = Size of datagram –
size of header = 1000 – 20 = 980 bytes
20.21
An IP router with a Maximum Transmission Unit
(MTU) of 1500 bytes has received an IP packet of size
4404 bytes with an IP header of length 20 bytes. The
values of the relevant fields in the header of the third IP
fragment generated by the router for this packet are
20.22
Number of packet fragments = ⌈ (total size of packet)/(MTU) ⌉
= ⌈ 4384/1480 ⌉
= ⌈ 2.962 ⌉
=3
The second fragment carries byte 1480 to 2959. The offset for this
datagram is 1480/8 = 185.finally the third fragment carries byte
2960 to 4404.the offset is 370.and for all fragments except last one
the M bit is 1.so in the third bit M is 0..
20.23
Figure 20.9 Maximum transfer unit (MTU)
20.24
Table 20.5 MTUs for some networks
20.25
Figure 20.11 Fragmentation example
20.26
Figure 20.12 Detailed fragmentation example
20.27
Example 20.5
Solution
If the M bit is 0, it means that there are no more
fragments; the fragment is the last one. However, we
cannot say if the original packet was fragmented or not. A
non-fragmented packet is considered the last fragment.
20.28
Example 20.6
Solution
If the M bit is 1, it means that there is at least one more
fragment. This fragment can be the first one or a middle
one, but not the last one. We don’t know if it is the first
one or a middle one; we need more information (the value
of the fragmentation offset).
20.29
Example 20.7
Solution
Because the M bit is 1, it is either the first fragment or a
middle one. Because the offset value is 0, it is the first
fragment.
20.30
Example 20.8
Solution
To find the number of the first byte, we multiply the offset
value by 8. This means that the first byte number is 800.
We cannot determine the number of the last byte unless
we know the length.
20.31
Example 20.9
20.32
Example 20.10
20.33
Figure 20.13 Example of checksum calculation in IPv4
20.34
20-3 IPv6
20.36
Figure 20.16 Format of an IPv6 datagram
20.37
Flow label. The flow label is a 3-byte (24-bit) field that
is designed to provide special handling for a particular
flow of data. We will discuss this field later.
o Payload length. The 2-byte payload length field
defines the length of the IP datagram
excluding the base header.
o Next header. The next header is an 8-bit field defining
the header that follows the
base header in the datagram. The next header is either
one of the optional extension
headers used by IP or the header of an encapsulated
packet such as UDP or
TCP.
20.38
Table 20.6 Next header codes for IPv6
20.39
Table 20.9 Comparison between IPv4 and IPv6 packet headers
20.40
20-4 TRANSITION FROM IPv4 TO IPv6
20.42
20.43
20.44
20.45
20.46
20.47
20.48
20.49
Table 20.11 Header translation
20.50
TRANSPORT
LAYER
INTRODUCTION
• The transport layer is responsible for message delivery from
process running in source computer to process running
destination computer (PROCESS TO PROCESS DELIVERY))
• It provides logical communication between app processes running
on different hosts
• transport protocols run in end systems
• Send side: breaks app messages into segments, passes to
network layer
• Recieve side: reassembles segments into messages, passes to
app layer
• more than one transport protocol available to apps
• Internet: TCP and UDP
Types of data deliveries: Internet
Stack
TRANSPORT LAYER SERVICES
Connectionless Vs Connection Oriented Service
Unreliable
• Own Flow & Error control mechanism as
required
• Fast & Easy to implement
For Eg: UDP
TRANSPORT LAYER DESIGN ISSUE
Connection Management
Addressing
Data Transfer
Multiplexing & Demultiplexing
Flow Control
Error Control
Congestion Control
Addressing
• Using Port address (16 bit)
• Ranges from 0 to 65,535
IP addresses versus port numbers
23.10
IANA ranges
23.11
Socket address (IP address + Port Address)
= socket = process
Multiplexing/demultiplexing
Demultiplexing at rcv host: Multiplexing at send host:
delivering received segments gathering data from multiple
to correct socket sockets, enveloping data with
header (later used for
= socket = process demultiplexing)
application P3 P1
P1 application P2 P4 application
host 2 host 3
host 1
15
Transport Layer Protocols (UDP and
TCP)
• UDP provides
• best effort delivery
• Connectionless
• Unreliable
• Out of order delivery
• TCP
• Reliable
• In-order delivery
• Congestion control
• Flow control
• Connection setup
USER DATAGRAM PROTOCOL (UDP)
23.18
Well-known ports used with UDP
23.19
User datagram format
23.20
Pseudoheader for checksum calculation
23.21
TCP
23.22
Stream delivery
23.23
Figure Sending and receiving buffers
23.24
TCP segments
23.25
Note
Solution
The following shows the sequence number for each segment:
23.31
Control field
23.32
Description of flags in the control field
23.33
15-4 A TCP CONNECTION
TCP is connection-oriented. It establishes a virtual
path between the source and destination. All of the
segments belonging to a message are then sent over
this virtual path. You may wonder how TCP, which
uses the services of IP, a connectionless protocol,
can be connection-oriented. The point is that a TCP
connection is virtual, not physical. TCP operates at a
higher level. TCP uses the services of IP to deliver
individual segments to the receiver, but it controls the
connection itself. If a segment is lost or corrupted, it is
retransmitted.
TCP/IP Protocol Suite 34
Figure 15.9 Connection establishment using three-way handshake
seq: 8000
UAPRS F
SYN
seq: 15000
ack: 8001
nd: 5000
U A P R S F rw
SYN + ACK
seq: 8000
ack: 15001
UAPRS F
rwnd: 10000
ACK
Means “no data” !
seq: 8001 if piggybacking
TCP/IP Protocol Suite 35
Figure 15.10 Data Transfer
Pushing data
Urgent data
Connection Termination
23.37
TCP Flow Control
&
Window Size
TCP Window Management
23.46
Note
23.47
Example 23.4
Solution
The value of rwnd = 5000 − 1000 = 4000. Host B can
receive only 4000 bytes of data before overflowing its
buffer. Host B advertises this value in its next segment to
A.
23.48
Example 23.5
Solution
The size of the window is the smaller of rwnd and cwnd,
which is 3000 bytes.
23.49
Example 23.6
23.50
Figure 23.23 Example 23.6
23.51
Figure 23.24 Normal operation
23.52
Figure 23.25 Lost segment
23.53
Note
23.54
Figure 23.26 Fast retransmission
23.55
15-9 CONGESTION CONTROL
24.58
Congestion Control in TCP
• Slow Start
• Additive Increase (Congestion Avoidance)
• Multiplicative decrease
Slow start, exponential increase
INTERNET
KEY
PLAIN CIPHER
TEXT TEXT
DECRYPTION
ALGORITHM
RECEIVER
Data Encryption Keys
Data Encryption keys are value or property by which
we can perform encryption and decryption.
SYMMETRIC ASYMMETRIC
For Eg. DES For Eg. RSA
Symmetric Data Encryption
When Encryption and Decryption can be performed
by using only same type of key
KEY-1
PLAIN CIPHER
TEXT ENCRYPTION TEXT
ALGORITHM
SENDER
INTERNET
KEY-1
PLAIN CIPHER
TEXT TEXT
DECRYPTION
ALGORITHM
RECEIVER
DES Data Encryption
Asymmetric Data Encryption
When Encryption and Decryption can be performed
by using two different type of key(Public or Private)
RECEIVER
PLAIN PUBLIC KEY CIPHER
TEXT ENCRYPTION TEXT
ALGORITHM
SENDER
INTERNET
RECEIVER
PLAIN PRIVATE KEY CIPHER
TEXT TEXT
DECRYPTION
ALGORITHM
RECEIVER
Q. Let p=3 and q=11 and plain text message length
M=31. Encrypt and Decrypt it using RSA and also
calculate its Public Key ‘e’ and Private Key ‘d’.
Compression Factor= 1
_________________
Compression Ratio
Compression Time: Total Time Taken by Encoder to
compress the data.
Decompression Time: Total Time Taken by Decoder to
uncompress the data.
RUN LENGTH ENCODING
• Pick the first character from the source string.
• Append the picked character to the
destination string.
• Count the number of subsequent occurrences
of the picked character and append the count
to the destination string.
• Pick the next character and repeat steps 2, 3
and 4 if the end of the string is NOT reached.
RUN LENGTH ENCODING
Huffman Encoding
• Calculate the frequency of each character in
the string.
_
______________________
_
______________________
_____________________________________
001 1 0001
_____________________________________
010 0 0000
_____________________________________
011 10 0010
_____________________________________
100 11 0011
_____________________________________
101 01
_____________________________________
0101
110 101 0111
_____________________________________
111 010 1010
_____________________________________
1010 1100
_____________________________________
Required Digital Code:
00010000001000110101011110101100
File Transfer
Transfer of data from Sender to
Receiver in OSI Model is possible
using FTP Protocol
FILE TRANSFER
PROTOCOL (FTP)
50
FTP
51
FTP uses the services of TCP.
It needs two TCP
connections.
The well-known port 21 is
used for the control
connection and the well-
known port 20 for the data
52
connection.
Opening the control connection
53
Creating the data connection
54
Using the control connection
55
Using the data connection
56
Command processing
57
Access commands
58
File management commands
59
Data formatting commands
60
Port defining commands
61
File transfer commands
62
File transfer commands (continued)
63
Miscellaneous commands
64
Responses
65
Responses (continued)
66
Responses (continued)
67
Responses (continued)
68
Responses (continued)
69
File transfer
70
Example
1
Next Figure shows an example of using FTP for
retrieving a list of items in a directory.
1. After the control connection to port 21 is
created, the FTP
server sends the 220 (service ready) response
on the control
connection.
2. The client sends the USER command.
3. The server responds with 331 (user name is
OK, password is
required).
4. The client sends the PASS command.
5. The server responds with 230 (user login is
71
OK)
Example 1 (cONTINUED)
74
Example
2
The following shows an actual FTP session that
parallels Example 1. The colored lines show the
responses from the server control connection;
the black lines show the commands sent by the
client. The lines in white with black background
shows data transfer.
$ ftp voyager.deanza.fhda.edu
Connected to voyager.deanza.fhda.edu.
220 (vsFTPd 1.2.1)
530 Please login with USER and PASS.
Name (voyager.deanza.fhda.edu:forouzan): forouzan
331 Please specify the password.
75
Example
2
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls reports
227 Entering Passive Mode (153,18,17,11,238,169)
150 Here comes the directory listing.
76
Example
3
Next Figure shows an example of how an image
(binary) file is stored.
1. After the control connection to port 21 is created,
the FTP
server sends the 220 (service
ready) response on the control connection.
2. The client sends the USER command.
3. The server responds with 331 (user name is OK, a
password
is required).
4. The client sends the PASS command.
5. The server responds with 230 (user login is OK).
6. The client issues a passive open on an ephemeral
port for
the data connection and sends the PORT 77
Example 3 (cONTINUED)
80
Example
4
We show an example of anonymous FTP. We
assume that
some public data are available at internic.net.
$ ftp internic.net
Connected to internic.net
220 Server ready
Name: anonymous
331 Guest login OK, send “guest” as password
Password: guest
ftp > pwd
257 ’/’ is current directory
81
Example
4
bin
...
...
...
ftp > close
221 Goodbye
ftp > quit
82
Figure 17.19 Resource record format