Logical Addreessing CN
Logical Addreessing CN
Logical Addreessing CN
• The network layer is the third layer (from bottom) in the OSI Model.
• The network layer is concerned with the delivery of a packet across
multiple networks (responsible for host-to-host delivery).
• The network layer is considered the backbone of the OSI Model.
• It selects and manages the best logical path for data transfer between
nodes. This layer contains hardware devices such as routers, bridges,
firewalls, and switches, but it actually creates a logical image of the
most efficient communication route and implements it with a physical
medium.
• Network layer protocols exist in every host or router. The router
examines the header fields of all the IP packets that pass through it.
• In the OSI model, the network layer responds to requests from the
layer above it (transport layer) and issues requests to the layer below it
(data link layer).
• Responsibilities of Network Layer:
• Packet forwarding/Routing of packets: Relaying of data packets from one
network segment to another by nodes in a computer network
• Connectionless communication(IP): A data transmission method used in
packet-switched networks in which each data unit is separately addressed and
routed based on information carried by it
• Fragmentation of data packets: Splitting of data packets that are too large to
be transmitted on the network
Datagram
• Packets in IP layer are called datagrams.
• A datagram has two parts namely the header and data. The length of
datagram is not fixed it varies from 20 bytes to 65535 bytes .
• The length of header is 20 to 60 bytes. The information necessary for
the routing and delivery of the datagram has been stored in the header.
• The other part of the datagram is the data field which is of variable
length.
IPv4
• IPv4 is a connectionless protocol used for packet-switched networks. It operates on a best effort
delivery model, in which neither delivery is guaranteed, nor proper sequencing or avoidance of
duplicate delivery is assured.
• Internet Protocol Version 4 (IPv4) is the fourth revision of the Internet Protocol and a widely used
protocol in data communication over different kinds of networks. IPv4 is a connectionless protocol
used in packet-switched layer networks, such as Ethernet.
• It provides a logical connection between network devices by providing identification for each
device. There are many ways to configure IPv4 with all kinds of devices – including manual and
automatic configurations – depending on the network type.
• IPv4 uses 32-bit addresses for Ethernet communication in five classes: A, B, C, D and E. Classes
A, B and C have a different bit length for addressing the network host. Class D addresses are
reserved for military purposes, while class E addresses are reserved for future use.
• IPv4 uses 32-bit (4 byte) addressing, which gives 232 addresses. IPv4 addresses are written in the
dot-decimal notation, which comprises of four octets of the address expressed individually in
decimal and separated by periods, for instance, 192.168.1.5.
IPv4 HEADER
• Version Number. The 4-bit version number (VER) field defines the version of the IPv4 protocol,
which, obviously, has the value of 4.
• Header Length.
• Header length is a 4 bit field that contains the length of the IP header.
• It helps in knowing from where the actual data begins.
Minimum And Maximum Header Length-
• The initial 5 rows of the IP header are always used.
• So, minimum length of IP header = 5 x 4 bytes = 20 bytes.
• The size of Options field can go up to 40 bytes.
• So, maximum length of IP header = 20 bytes + 40 bytes = 60 bytes.
Concept of Scaling Factor-
• Header length is a 4 bit field.
• So, the range of decimal values that can be represented is [0, 15].
• But the range of header length is [20, 60].
• So, to represent the header length, we use a scaling factor of 4.
In general,
Header length = Header length field value x 4 bytes
Examples-
• If header length field contains decimal value 5 (represented as 0101), then-
Header length = 5 x 4 = 20 bytes
• If header length field contains decimal value 10 (represented as 1010), then-
Header length = 10 x 4 = 40 bytes
• If header length field contains decimal value 15 (represented as 1111), then-
Header length = 15 x 4 = 60 bytes
Question-
In an IPv4 packet, the value of HLEN is 1000 in binary. How many
bytes of options are being carried by this packet?
• Service Type. Differentiated services (DiffServ) is 8-bit field its job is to define the class of the
datagram for quality of service (QoS).
• Total Length. This 16-bit field defines the total length (header plus data) of the IP datagram in
bytes. A 16-bit number can define a total length of up to 65,535 (when all bits are 1s). However,
the size of the datagram is normally much less than this. This field helps the receiving device to
know when the packet has completely arrived. To find the length of the data coming from the
upper layer, subtract the header length from the total length. The header length can be found by
multiplying the value in the HLEN field by 4.
Length of data = total length - (HLEN) * 4
• Identification, Flags, and Fragmentation Offset. These three fields are related to the
fragmentation of the IP datagram when the size of the datagram is larger than the underlying
network can carry.
• Time-to-live. Due to some malfunctioning of routing protocols a datagram may be circulating in
the Internet, visiting some networks over and over without reaching the destination. This may
create extra traffic in the Internet. The time-to-live (TTL) field is used to control the maximum
number of hops (routers) visited by the datagram. When a source host sends the datagram, it stores
a number in this field. This value is approximately two times the maximum number of routers
between any two hosts. Each router that processes the datagram decrements this number by one. If
this value, after being decremented, is zero, the router discards the datagram.
• Protocol. In TCP/IP, the data section of a packet, called the payload, carries the whole packet from another
protocol. A datagram, for example, can carry a packet belonging to any transport-layer protocol such as UDP
or TCP. A datagram can also carry a packet from other protocols that directly use the service of the IP, such as
some routing protocols or some auxiliary protocols. The Internet authority has given any protocol that uses
the service of IP a unique 8-bit number which is inserted in the protocol field. When the payload is
encapsulated in a datagram at the source IP, the corresponding protocol number is inserted in this field; when
the datagram arrives at the destination, the value of this field helps to define to which protocol the payload
should be delivered. In other words, this field provides multiplexing at the source and demultiplexing at the
destination.
• Header checksum. IP is not a reliable protocol; it does not check whether the payload carried by a datagram
is corrupted during the transmission. IP puts the burden of error checking of the payload on the protocol that
owns the payload, such as UDP or TCP. The datagram header, however, is added by IP, and its error-checking
is the responsibility of IP. Errors in the IP header can be a disaster. For example, if the destination IP address
is corrupted, the packet can be delivered to the wrong host. If the protocol field is corrupted, the payload may
be delivered to the wrong protocol. If the fields related to the fragmentation are corrupted, the datagram
cannot be reassembled correctly at the destination, and so on. For these reasons, IP adds a header checksum
field to check the header, but not the payload. We need to remember that, since the value of some fields, such
as TTL, which are related to fragmentation and options, may change from router to router, the checksum
needs to be recalculated at each router.
• Source and Destination Addresses. These 32-bit source and destination address fields define the IP address of
the source and destination respectively. The source host should know its IP address. The destination IP
address is either known by the protocol that uses the service of IP or is provided by the DNS.
• Options. A datagram header can have up to 40 bytes of options. Options can be used for network
testing and debugging. Although options are not a required part of the IP header, option processing
is required of the IP software. This means that all implementations must be able to handle options
if they are present in the header. The existence of options in a header creates some burden on the
datagram handling; some options can be changed by routers, which forces each router to
recalculate the header checksum.
• Payload. Payload, or data, is the main reason for creating a datagram. Payload is the packet coming
from other protocols that use the service of IP. Comparing a datagram to a postal package, payload
is the content of the package; the header is only the information written on the package.
Question1
An IPv4 packet has arrived with the first 8 bits as shown: 01000010 The receiver discards the packet. Why?
Question2
In an IPv4 packet, the value of HLEN is 5, and the value of the total length field is Ox0028. How many bytes of data
are being carried by this packet?
Question3
An IPv4 packet has arrived with the first few hexadecimal digits as shown. Ox45000028000100000102 ...
How many hops can this packet travel before being dropped? The data belong to what upper-layer protocol?
Sol. To find the time-to-live field, we skip 8 bytes (16 hexadecimal digits). 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.
Protocol values
Value Protocol
1 ICMP
2 IGMP
6 TCP
17 UDP
89 OSPF
IP Header Checksum Example
let IP header from an IP packet received at destination :
4500 003c 1c46 4000 4006 b1e6 ac10 0a63 ac10 0a0c
• 45’ corresponds to the first two fields in the header ie ‘4’ corresponds to the IP version and ‘5’ corresponds to
the header length. Since header length is described in 4 byte words so actual header length comes out to be
5×4=20 bytes.
• ’00’ corresponds to TOS or the type of service. This value of TOS indicated normal operation.
• ‘003c’ corresponds to total length field of IP header. So in this case the total length of IP packet is 60.
• ‘1c46’ corresponds to the identification field.
• ‘4000’ can be divided into two bytes. These two bytes (divided into 3 bits and 13 bits respectively) correspond
to the flags and fragment offset of IP header fields.
• ‘4006’ can be divided into ’40’ and ’06’. The first byte ’40’ corresponds to the TTL field and the byte ’06’
corresponds to the protocol field of the IP header. ’06’ indicates that the protocol is TCP.
• ‘b1e6’ corresponds to the checksum which is set at the source end (which sent the packet). Please note
that as already discussed this field will be set to zero while computing the checksum at destination end.
• The next set of bytes ‘ac10’ to ‘0a0c’ correspond to the source IP address and the destination IP address in the
IP header.
Maximum Transmission Unit
• Maximum size of IP datagram is 65535, but the data link layer protocol generally
imposes a limit that is much smaller
• Example:
• Ethernet frames have a maximum payload of 1500 bytes
→ IP datagrams encapsulated in Ethernet frame cannot be longer than 1500
bytes
• The limit on the maximum IP datagram size, imposed by the data link protocol is
called maximum transmission unit (MTU)
14
IP Fragmentation
• What if the size of an IP datagram exceeds the MTU?
IP datagram is fragmented into smaller units.
Ethernet
FDDI
Ring
Host A Router Host B
MTUs: FDDI: 4352 Ethernet: 1500
• Fragmentation:
• IP router splits the datagram into several datagram
• Fragments are reassembled at receiver
15
Where is Fragmentation done?
• Fragmentation can be done at the sender or at intermediate routers
• The same datagram can be fragmented several times.
• Reassembly of original datagram is only done at destination hosts !!
Router
16
Fields of the IP Header Fragmentation
• Identification (16 bits): Unique identification of a datagram from a
host. Incremented whenever a datagram is transmitted
• Flags (3 bits):
• First bit is always set to 0
• DF bit (Do not fragment)
• MF bit (More fragments)
17
What’s involved in Fragmentation?
• The following fields in the IP header are involved:
header
version
length
DS ECN total length (in bytes)
DM
Identification 0 Fragment offset
F F
time-to-live (TTL) protocol header checksum
Fragment offset Offset of the payload of the current fragment in the original
datagram (number of bytes a head from current fragment)
19
Question: A datagram of 3000 byte (20 byte of IP header + 2980 bytes of IP payload)
reached at the router and must be forwarded to link with MTU of 500 bytes how many
fragments will generate and also write MF , offset, total length value for all.
22
Determining the length of fragments
• To determine the size of the fragments we recall that, since there are only 13
bits available for the fragment offset, the offset is given as a multiple of
eight bytes. As a result, the first and second fragment have a size of 996
bytes (and not 1000 bytes). This number is chosen since 976 is the largest
number smaller than 1000–20= 980 that is divisible by eight. The payload
for the first and second fragments is 976 bytes long, with bytes 0 through
975 of the original IP payload in the first fragment, and bytes 976 through
1951 in the second fragment. The payload of the third fragment has the
remaining 428 bytes, from byte 1952 through 2379. With these
considerations, we can determine the values of the fragment offset, which
are 0, 976 / 8 = 122, and 1952 / 8 = 244, respectively, for the first, second
and third fragment.
23
Q. Draw IPv4 datagram. An IPv4 datagram has arrived with
the following information in the header (in hexadecimal):
Ox45 00 00 54 00 03 58 50 20 06 00 00 7C 4E 03 02 B4 OE OF
02
a. Is the packet corrupted?
b. Are there any options?
c. Is the packet fragmented?
d. What is the size of the data?
e. How many more routers can the packet travel to?
f. What is the identification number of the packet?
g. What is the type of service?
19-2 IPv6 ADDRESSES
Solution
We first need to align the left side of the double colon to
the left of the original pattern and the right side of the
double colon to the right of the original pattern to find
how many 0s we need to replace the double colon.
IPv4 addresses are 32 bit length. IPv6 addresses are 128 bit length.
IPv4 addresses are binary numbers represented in decimals. IPv6 addresses are binary numbers represented in hexadecimals.
Fragmentation is done by sender and forwarding routers. Fragmentation is done only by sender.
Solution
We replace each group of 8 bits with its equivalent
decimal number and add dots for separation.
Change the following IPv4 addresses from dotted-decimal
notation to binary notation.
Change the following IPv4 addresses from dotted-decimal
notation to binary notation.
Solution
We replace each decimal number with its binary
equivalent.
Find the error, if any, in the following IPv4 addresses.
Solution
a. There must be no leading zero (045).
b. There can be no more than four numbers.
c. Each number needs to be less than or equal to 255.
d. A mixture of binary notation and dotted-decimal
notation is not allowed.
Note
In classful addressing, the address
space is divided into five classes:
A, B, C, D, and E.
To accommodate both small and large networks, three fixed length prefixes were
designed instead of one (n=8,n=16 and n=24)
Solution
a. The first bit is 0. This is a class A address.
b. The first 2 bits are 1; the third bit is 0. This is a class C
address.
c. The first byte is 14; the class is A.
d. The first byte is 252; the class is E.
Table 19.1 Number of blocks and block size in classful IPv4 addressing
Note
We can see that the restrictions are applied to this block. The
addresses are contiguous. The number of addresses is a power of
2 (16 = 24), and the first address is divisible by 16. The first
address, when converted to a decimal number, is 3,440,387,360,
which when divided by 16 results in 215,024,210.
Figure 19.3 A block of 16 addresses granted to a small organization
Note
Solution
The binary representation of the given address is
11001101 00010000 00100101 00100111
If we set 32−28 rightmost bits to 0, we get
11001101 00010000 00100101 0010000
or
205.16.37.32.
This is actually the block shown in Figure 19.3.
Note
Solution
The binary representation of the given address is
11001101 00010000 00100101 00100111
If we set 32 − 28 rightmost bits to 1, we get
11001101 00010000 00100101 00101111
or
205.16.37.47
This is actually the block shown in Figure 19.3.
Note
Solution
The value of n is 28, which means that number
of addresses is 2 32−28 or 16.
Example 19.9
Another way to find the first address, the last address, and the
number of addresses is to represent the mask as a 32-bit binary (or
8-digit hexadecimal) number. This is particularly useful when we
are writing a program to find these pieces of information. In
Example 19.5 the /28 can be represented as
11111111 11111111 11111111 11110000
(twenty-eight 1s and four 0s).
Find
a. The first address
b. The last address
c. The number of addresses.
Example 19.9 (continued)
Solution
a. The first address can be found by ANDing the given
addresses with the mask. ANDing here is done bit by
bit. The result of ANDing 2 bits is 1 if both bits are 1s;
the result is 0 otherwise.
Example 19.9 (continued)
6 bits 10 bits
• To design the subnets, we need to determine the subnet mask from the given
prefix length of 27. The subnet mask can be obtained by setting the first 27
bits to 1 and the remaining bits to 0. In binary, this is:
• 11111111.11111111.11111111.11100000
• The next step is to divide the network into subnets. Since we have a /27
prefix length, we can borrow 3 bits from the host portion to create subnets.
This gives us 2^3 = 8 subnets.
• To find the network address of each subnet, we can increment the host portion of the
original network address by the number of hosts per subnet (which is 2^(32-27)-2 =
30).
• Subnet 1: Network address = 200.198.160.0, Broadcast address = 200.198.160.31,
First host = 200.198.160.1, Last host = 200.198.160.30, Number of hosts = 30
• Subnet 2: Network address = 200.198.160.32, Broadcast address = 200.198.160.63,
First host = 200.198.160.33, Last host = 200.198.160.62, Number of hosts = 30
• Subnet 3: Network address = 200.198.160.64, Broadcast address = 200.198.160.95,
First host = 200.198.160.65, Last host = 200.198.160.94, Number of hosts = 30
• Subnet 4: Network address = 200.198.160.96, Broadcast address = 200.198.160.127,
First host = 200.198.160.97, Last host = 200.198.160.126, Number of hosts = 30
• Subnet 5: Network address = 200.198.160.128, Broadcast address = 200.198.160.159,
First host = 200.198.160.129, Last host = 200.198.160.158, Number of hosts = 30
• Subnet 6: Network address = 200.198.160.160, Broadcast address = 200.198.160.191,
First host = 200.198.160.161, Last host = 200.198.160.190, Number of hosts = 30
• Subnet 7: Network address = 200.198.160.192, Broadcast address = 200.198.160.223,
First host = 200.198.160.193, Last host = 200.198.160.222, Number of hosts = 30
• Subnet 8: Network address = 200.198.160.224, Broadcast address = 200.198.160.255,
First host = 200.198.160.225, Last host = 200.198.160.254, Number of hosts = 30
As an example, suppose an organization is given the block 17.12.14.0/26, which
contains 64 addresses. The organization has three offices and needs to divide
the addresses into three subblocks of 32, 16, and 16 addresses. We can find the
new masks by using the following arguments:
Solution
Figure 19.9 shows the situation.
Group 1
For this group, each customer needs 256 addresses. This
means that 8 (log2 256) bits are needed to define each host.
The prefix length is then 32 − 8 = 24. The addresses are
Example 19.10 (continued)
Group 2
For this group, each customer needs 128 addresses. This
means that 7 (log2 128) bits are needed to define each
host. The prefix length is then 32 − 7 = 25. The addresses
are
Example 19.10 (continued)
Group 3
For this group, each customer needs 64 addresses. This
means that 6 (log264) bits are needed to each host. The
prefix length is then 32 − 6 = 26. The addresses are
20
172.16.0.0/12 172.16.0.0 172.31.255.255 1,048,576 (2 )
16
192.168.0.0/16 192.168.0.0 192.168.255.255 65,536 (2 )
Network Address Translation (NAT)
• Network Address Translation (NAT) is a process in which
one or more local IP address is translated into one or more
Global IP address and vice versa in order to provide Internet
access to the local hosts.
• NAT generally operates on router or firewall.
Figure 19.11 Addresses in a NAT