You are on page 1of 53

UNIT 3

TCP/IP-1
1
 Internet Protocol (IP) enables the communication across
a vast and heterogeneous collection of networks that are
based on the different technology.
 Any host computer that is connected to the Internet can
communicate with any other computer that is also
connected to the internet
 The transport layer offer two basic communication
services that operate on top of IP: Transmission Control
Protocol (TCP) and User Datagram Protocol (UDP)

2
THE TCP/IP ARCHITECTURE
 TCP/IP protocol suits not only TCP and IP but also to
other related protocols such as User Datagram Protocol
(UDP), the Internet Control Message Protocol (ICMP)
and basic application such as HTTP, TELNET and FTP.
 Appplication layer protocol such as FTP and HTTP send
messages using TCP.
 Application layer protocols such as SNMP and DNS
send their messages using UDP
 PDU exchanged by TCP protocols are called TCP
segments or segments while those exchanged by UDP
protocols are called UDP datagrams or datagrams

3
CONTD..
Protocol Data Units exchanged by IP are called IP
packets or packets.
 Receiving IP determines whether packets should be
sent to TCP or UDP
 TCP/UDP sends each packet to appropriate application
based on the port number

4
5
HTTP Request

TCP Header contains:


ephemeral port number of client TCP
Header
Well known port 80 for server

IP Header contains:
source and destination IP addresses;
IP
transport protocol type Header

Ethernet FCS
Header

Ethernet Header contains: source and destination physical addresses; network protocol type
Encapsulation of PDUs in TCP/IP
 Here HTTP command is passed to the TCP layer which encapsulates the
message into a TCP segment.

 Segment header contains port number for the client process and well
known port 80 for the HTTP server process.
 The TCP segment is then passed to the IP layer where it is encapsulated
in an IP packet.

 IP packet header contains an IP network address for the sender and an


IP network address for the destination.
 IP address are said to be logical because they are defined in terms of
logical topology of routers and end system

 IP packet is then transferred through the network interface and


encapsulated into a PDU of underlying network

7
CONTD
 IP packet is encapsulated into Ethernet frames
 The frame header contains physical address that identify
the physical end points for the Ethernet sender and the
receiver.
 Logical IP address need to be converted into specific
physical address to carry out the transfer of bits from one
device to another
 This conversion is done by address resolution protocol.

 Each host in the internet is identified by a globally


unique IP address
8
CONTD..
 An IP address is divided into two parts: network ID and
host ID
 The network ID must be obtained from an organization
authorized to issue IP address.
 IP packets are exchanged between routers without a
connection setup they routed independently and may
traverse different paths
 The router that interconnect the intermediate network
may discard packets when they encounter congestion.
 At each router the network interface layer is used to
encapsulate the IP packet into a packet or frame of
underlying network or link.
9
CONTD..
 IP packet is recovered at an exit router of the given
network
 This router must determine the next hop in the route to
destination and then encapsulate the IP packet into the
frame of the type of the next network or link.

10
INTERNET PROTOCOL APPROACH
 IP packets transfer information across Internet
 Host A IP  router router… routerHost B IP
 IP layer in each router determines next hop; router
 Routing + encapsulation + segmentation/assembly
 Network interfaces transfer IP packets across networks

11
THE INTERNET PROTOCOL
 Internet protocol (IP) is the heart of the TCP/IP protocol
suit
 IP corresponds to the network layer in the OSI reference
model and provides a connectionless best effort delivery
service to the transport layer.

12
IP PACKET
 To understand the service provided by IP entity, it is
useful to examine the IP packet format which contains a
header part and a data part
 The header has a fixed length component of 20 bytes
plus a variable length component consisting of options
that can be up to 40 bytes

13
0 4 8 16 19 24 31

Version IHL Type of Service Total Length

Identification Flags Fragment Offset

Time to Live Protocol Header Checksum

Source IP Address

Destination IP Address

Options Padding

20 bytes +variable length component –up to 40 bytes

● Version: current IP version is 4.


● Internet header length (IHL): length of the header in 32-bit
words. Default :5
CONTD..
● Type of service (TOS): priority of packet at each router.
● 3 bits : for priority levels
● 4 bits: for specific requirements (delay, throughput, reliability, cost)
 Total length: number of bytes of the IP packet including header
and data maximum length is 65535 bytes.
 Identification, Flags, and Fragment Offset: used for
fragmentation and reassembly.
 Time to live (TTL): number of hops packet is allowed to traverse
in the network.
 Each router along the path to the destination decrements this value by one.
 If the value reaches zero before the packet reaches the destination, the router
discards the packet and sends an error message back to the source.
 Protocol: specifies upper-layer protocol that is to receive IP data at
the destination. [ Value of this field For TCP 6, UDP 17, and
ICMP  1]

15
CONTD…
 Header checksum: verifies the integrity of the IP header.
 Source IP address and destination IP address: contain the
addresses of the source and destination hosts.
 Options: Variable length field, allows packet to request special
features such as security level, route to be taken by the packet,
and timestamp at each router.
 Padding: This field is used to make the header a multiple of
32-bit words

16
IP ADDRESSING
 Each host on Internet has unique 32 bit IP address
 Each address has two parts: netid and hostid
 The network ID identifies the network the host connected to
 Host ID identifies the network connection to the host
netid unique & administered by
 American Registry for Internet Numbers (ARIN)

 Reseaux IP Europeens (RIPE)

 Asia Pacific Network Information Centre (APNIC)

 Facilitates routing

 A separate address is required for each physical connection of a host to a network;


“multi-homed” hosts

 Dotted-Decimal Notation:
 int1.int2.int3.int4 where intj = integer value of jth octet
 IP address of 10000000 10000111 01000100 00000101
 is 128.135.68.5 in dotted-decimal notation
17
Bit position: 0 1 2 3 8 16 31
Class A 0 Net ID Host ID

Class B 1 0 Net ID Host ID

Class C 1 1 0 Net ID Host ID

Class D 1 1 1 0 Multicast address

Class E 1 1 1 1 Reserved for experiments

Five class of IP addresses


18
19
 Up to 250 million multicast groups –can send information to a
group of hosts simultaneously
 Class E reserved for experimental purposes

20
Reserved Host IDs
 A host ID that contains all 1s is meant to broadcast the packet to all
hosts on the network specified by the network ID.

 If network ID also contains all 1’s, the packet is broadcast on the local
network

 A host ID that contains all 0’s refers to the network specified by the
network ID, this is used during booting, host transmits packets with all
0’s in the source address –it is an attempt to find out its IP address.

21
PRIVATE IP ADDRESSES
 Specific ranges of IP addresses set aside for use in private
networks
 Loopback address: 127.X.Y.Z

 Use is restricted to private intranets;

 routers in public Internet discard packets with these addresses


 Range 1: 10.0.0.0 to 10.255.255.255
 Range 2: 172.16.0.0 to 172.31.255.255
 Range 3: 192.168.0.0 to 192.168.255.255(For Home LAN)
 Network Address Translation (NAT) used to convert between
private & global IP addresses

22
Subnet Addressing

•Subnet addressing introduces another hierarchical level


•Transparent to remote networks
•Simplifies management of multiplicity of LANs
•Masking used to find subnet number

Original 1 0 Net ID Host ID


address

Subnetted
address 1 0 Net ID Subnet ID Host ID

To find subnet number Router needs to store subnet mask-


which consist binary 1’s for every bit position of the address but the in host ID field,
binary 0s are used.
SUBNETTING EXAMPLE
 Organization has Class B address (16 hostID bits) with netID:
150.100.0.0
 Create subnets with up to 100 hosts each
 7 bits sufficient for each subnet, 16-7=9 bits for subnet ID
 Apply subnet mask to IP addresses to find corresponding subnet
 Example: Find subnet for 150.100.12.176
 IP add = 10010110 01100100 00001100 10110000
 Mask = 11111111 11111111 11111111 10000000
 AND = 10010110 01100100 00001100 10000000 24
CONTD..
 IP address 150.100.12.128 is used to identify the sub network
 IP address 150.100.12.255 is used to broadcast inside the sub
network
 A host of this must have IP address 150.100.12.129 to
150.100.12.254

25
CONTD..
At R1: IP Packet with address : 150.100.15.11 arrived from outside
network
R1 has to know next hop router to send packet
Binary of above IP: 10010101011001000000111100001011
Mask: 11111111111111111111111110000000
Result: 10010110011001000000111100000000
IP: 150.100.15.0
Router R1 looks up this subnet address in its table
Corresponding entry to specify the next hop router address for R2-
150.100.12.1
R2 receives and perform same operation and send packet directly to
the destination
26
FIND THE SUB NETWORK
ADDRESS
 IP: 140.11.36.22 Mask:255.255.255.0
 IP: 120.14.22.16 Mask:255.255.128.0

Hint: Binary equivalent of IP address AND with Binary equivalent


mask
Result Sub network address
i.e Binary(IP) .Binary(Mask) subnetwork address

27
ROUTING WITH SUBNETWORKS
 IP layer in hosts and routers maintain a routing table
 Originating host: To send an IP packet, consult routing table
 If destination host is in same network, send packet directly using appropriate
network interface
 Otherwise, send packet indirectly; typically, routing table indicates a default
router

 Router: Examine IP destination address in arriving packet


 If destination IP address not own, router consults routing table to determine
next-hop and associated network interface & forwards packet

28
SEARCHING ROUTING TABLE
 Each row in routing table contains:

 Destination IP address, IP address of next-hop router,outgoing interface,Flags


 H=1 indicates route,H=0indicates network
 G=1 Gateway ,G=0 Directly destination is connected

 Routing table search order & action

 First destination column is searched to see ccomplete destination address;


 If found so send as per nexthop & G flag

 Second , the routing table is searched for destination network ID;


 If found so send as per next-hop & G flag

 Third , the table is searched for a Default router entry;


 If found packet is forwarded

 Otherwise the packet is declared undeliverable and


 ICMP “ Host unreachable error” packet is sent to the originating host

29
CLASSLESS INTER DOMAIN
ROUTING
 To overcome address inefficiency
 To give more organizations access to the Internet
 No concept of class
 Addresses are granted in blocks
 Restrictions
 Addresses in a block must be contiguous
 The number of addresses in a block must be a power of 2
 The first address must be evenly divisible by the number of address

 Ex:
 205.16.37.32 to 205.16.37.47
 First address is divisible by 16 which is power of 2
30
CIDR
 Mask is used to define the block of addresses
 Mask is a 32-bit number ; n leftmost bits are 1s
 Find first address, last address and number of address
 Given that one of the address: 205.16.37.39/28

IP address: 11001101000100000010010100100111
Mask : 11111111111111111111111111110000
First address : 11001101000100000010010100100000
(32-n right most 0’s) (205.16.37.32)
Last address: 11001101000100000010010100101111
(32-n right most 1’s) (205.16.37.47)
Number of address: Difference between last and first address
47-32=16
31
SUPERNETTING
 Using a CIDR notation a prefix 205.100.0.0 of length 22 bits id
written as 205.100.0.0/22
 The /22 notation indicates that the network mask is 22 bits

 A router has the following CIDR entries in its routing table:

Address/mask Next hop


128.56.24.0/22 Interface 0
128.56.60.0/22 Interface 1
Default Router 2

32
CONTD..
 CIDR allows technique called supernetting to allow a
single routing entry to cover a block of classful address
 Here address assignment should reflect the physical
topology of the network, in this case IP address prefix
should correspond to continents or nations
 Tranit routing domains that carry traffic between domain
should have unique IP and domains that are attached to
them should begin with the transit routing domains
prefix

33
ADDRESS RESOLUTION
PROTOCOL
 IP address identifies a host, the packet is physically delivered by an
underlying network (e.g., Ethernet) which uses its own physical
address (MAC address in Ethernet)

34
REVERSE ADDRESS RESOLUTION
 Used when a host knows its MAC but not its IP-which is kept in
separate disk at server.
 Host broadcast its RARP request packet containing its MAC on the
network
 All host receives but server responds with IP along with host’s
MAC address
 Server must be located in the same physical network.

35
36
FRAGMENTATION AND
REASSEMBLY
 Fragmentation based on Maximum Transmission Unit (MTU)
(Ethernet-MTU-1500)
 IP breaks packets into segments whose size can not be greater than
MTU.
 To reassemble the fragments, the destination waits until it has
received starts only after host has received all the packets belonging
to the same packet.
 If one or more fragments are lost, reassembly will be stopped and
discards the rest of the fragment
 To detect lost fragments, destination sets timer, if timer expires
before receiving all packets then hosts assumes missing fragments
37
were lost
FIELDS USED IN IP HEADER FOR
FRAGMENTATION
 Identification-to identify which packet a fragment belongs; to
avoid mix up
 Flags-
 Unused bit
 Don’t Fragment bit-1- forces the router not to fragment, discards if packet
length> MTU
 More Fragment (MF)
 Tells the destination host whether or not more fragments follow.
 MF is set to 1 if there are more fragments,Otherwise set to 0

 Fragment offset
 Identifies the location of a fragment in packet
 For first fragment this value is 0
38
EX: FRAGMENTING A PACKET
 A packet is to be forwarded to a network with MTU of 576 bytes.
The packet has an IP header of 20 bytes and a data part of 1484
bytes. and of each fragment.
 Maximum data length per fragment = 576 - 20 = 556 bytes.
 Set maximum data length to 552 bytes to get multiple of 8.

39
INTERNET CONTROL MESSAGE
PROTOCOL(ICMP)
 Encapsulated in IP packet (protocol type = 1)
 Handles error and control messages

 If router cannot deliver or forward a packet, it sends an ICMP “host


unreachable” message to the source
 If router receives packet that should have been sent to another
router, it sends an ICMP “redirect” message to the sender; Sender
modifies its routing table
 ICMP “router discovery” messages allow host to learn about
routers in its network and to initialise and update its routing tables
 ICMP echo request and reply facilitate diagnostic and used in
“ping”
40
41
ICMP FIELD
 Type: type of message
 Type 8: Echo request, Type 0: Echo reply
 Code: Describes the purpose of the message
 Type 3: Destination not reachable
 0-network unreachable
 1-host unreachable
 2-protocol unreachable
 3-port unreachable
 4-fragmentation needed and DF set
 5-Source route failed.
 Checksum: Used to detect errors in the ICMP message
 IP header plus original datagram: used for diagnostic purposes

 Sequence number: used to match echo reply message with corresponding


echo reply message
 Identifier: to differentiate different sessions

42
NETWORK ADDRESS TRANSLATION NAT
 Within the company every machine has unique address (say
10.x.y.z).
 When packet leaves the company,it passes through NAT box.

 NAT box converts internal IP to global IP.

 Whenever an outgoing packet enters the NAT,source address is


replaced by true IP address of the company.
 TCP source port filed is replaced by an index into the NAT box
65536 entry-which contains original IP address and original
source port.
 TCP and IP header checksums are recomputed.

43
44
PROBLEMS
 An address space has a total of 1024 addresses. How may bits
are needed to represent an address??????????
 Hint 2x=1024 x=?

45
DRAW A DIAGRAM OF A NETWORK WITH ADDRESS 8.0.0.0 THAT IS

CONNECTED THROUGH A ROUTER TO A NETWORK WITH IP ADDRESS

131.45.0.0. CHOOSE IP ADDRESSES FOR EACH INTERFACE OF THE ROUTER.

SHOW ALSO SOME NON EACH NETWORK WITH THEIR IP ADDRESSES.

WHAT IS THE CLASS OF EACH NETWORK?

131.45.0.1

8.0.0.3

8.0.0.0 8.0.0.3 131.45.0.0


131.45.0.3

131.45.0.2
8.0.0.2
8.0.0.1
46
In a class A subnet,
IP address: 25.34.12.56, Mask 255.255.0.0
What is the first address (subnet address)?
IP Address: 25 . 34 . 12 . 56
Mask: 255 . 255 . 0 . 0
------ ------ ------ ------
Subnet Address: 25 . 34 . 0 . 0
Host connected to this sub network must have IP address in the range
25.34.0.0- to 25.34.0.254
25.34.0.255 is used to broadcast the packet

47
 In a network, the address of one computer is 201.78.24.56 and
the address of another computer is 201.78.120.202.

 How many addresses are in between?


Ans: the last address is 201.78.120.202
 The first address is 201.78.24.56
 Subtract -----------------------
96:146

multiply 96 by base 256 and add 146 to the product and subtract
result by1, will get :24721 addresses

48
PROBLEMS-IDENTIFY CLASS
FOR BELOW IP ADDRESS
● 1.22.200.10
● 201.240.200.2
● 217.3.6.8
● 180.170.0.2

Hint Convert Left most digit to binary


• If LSB 4 bits are 1: Class E
• If LSB 3 bits are 1, next bit is 0: Class D
• If LSB 2 bits are 1, next bit is 0: Class C
• If LSB 1 bit is 1, next bit is 0: Class B
49
• If LSB bit is 0, then it class A address.
PROBLEM
 Find the netid and host id
1) 18.25.98.4
2) 190.18.75.45
3) 246.3.8.17
4) 201.2.7.1

Hint: Convert all digits to binary place in groups of 8 bits


If A: MSB 24 bits are used for Host ID, next 7 bits for NetId
If B: MSB 16 bits are used for Host ID, next 15 bits for NetId
If C: MSB 8 bits are used for Host ID, next 21 bits for NetId
If D: MSB 20 bits are used for multicast address; not netid and Host id
If E: MSB 20 bits are reserved; not netid and Host id
50
51
52
53

You might also like