Network Programming: MT-24C Assignment-1
Network Programming: MT-24C Assignment-1
Network Programming: MT-24C Assignment-1
MT-24C
ASSIGNMENT-1
1
Q.1 Explain the OSI Reference Model?
The OSI model has seven layers shown in Figure 2. The principles that were
applied to arrive at the seven layers are as follows:
The set of rules for communication between entities in a layer is called protocol
for that layer. The seven layers of ISO OSI reference model are:
(a) Physical Layer
(b) Data Link Layer
(c) Network Layer
(d) Transport Layer
(e) Session Layer
(f) Presentation Layer
(g) Application Layer.
2
The Network Layer
Whereas the datalink layer is responsible for delivery on a hop, the network
layer ensures that each packet travels from its sources to destination
successfully and efficiently. A key design issue is determining how packets are
routed from source to destination. Routes can be based on static tables that are
“wired into” the network and rarely changed. They can also be determined at
the start of each conversation, for example a terminal session. Finally, they can
be highly dynamic, being determined anew for each packet, to reflect the
current network load. When a packet has to travel from one network to another
to get its destination, many problems can arise. The addressing used by the
second network may be different from the first one. The second network one
may not accept the packet at all because it is too large. The protocols may
differ, and so on. It is up to the network layer to overcome all these problems to
allow heterogeneous networks to be interconnected.
One of the services of the session layer is to manage dialogue control. Sessions
can allow traffic to go in both directions at the same time, or in only one
direction at a time. If traffic can only go one way at a time (analogous to a single
railroad track), the session layer can help keep track of whose turn it is. A
related session service is token management. For some protocols, it is essential
that both sides do not attempt the same operation at the same time. To manage
these activities, the session layer provides tokens that can be exchanged. Only
the side holding the token may perform the desired operation. Another session
service is synchronization. Consider the problem that might occur when trying to
do a 2 hour file transfer between two machines with a 1 hour mean time
between crashes. After each transfer was aborted, the whole transfer would
have to start over again and would probably fail again the next time as well. To
eliminate
this problem, the session layer provides a way to insert markers after the
appropriate checkpoints.
Application Layer
4
Application Layer supports functions that control and supervise OSI application
processes such as start/maintain/stop application, allocate/deallocate OSI
resources, accounting, check point and recovering. It also supports remote job
execution, file transfer protocol, message transfer and virtual terminal.
The Internet Control Message Protocol (ICMP) is part of the internet protocol
suite and defined in RFC 792. ICMP messages are typically generated in
response to errors in IP datagrams (as specified in RFC1122) or for diagnostic or
routing purposes.
Many commonly used network utilities are based on ICMP messages. The ping
utility (well known on Unix) is implemented using the ICMP "Echo" and "Echo
reply" messages. The related traceroute command is implemented by
transmitting UDP datagrams with manipulated IP Time-to-live (TTL) header fields
and looking for ICMP "Time to live exceeded in transit" and "Destination
unreachable" messages in response. Every machine (such as intermediate
routers) that forwards an IP datagram has to decrement the TTL by one. If the
TTL reaches 0, an ICMP "Time to live exceeded in transit" message is sent to the
source of the datagram.
5
35 - Mobile Registration Request
36 - Mobile Registration Reply
37 - Domain Name Request
38 - Domain Name Reply
39 - SKIP
40 - Photuris
41-255 – Reserved
Q.3 Explain UDP. State the difference between TCP and UDP.
TCP is a Transmission Control Protocol. UDP is a User Datagram Protocol.
1. TCP(Transmission Control Protocol): TCP is a connection-oriented
protocol, a connection can be made from client to server, and from then on any
data can be sent along that connection.
Reliable - when you send a message along a TCP socket, you know it will get
there unless the connection fails completely. If it gets lost along the way, the
server
will re-request the lost part. This means complete integrity, things don't get
corrupted.
Ordered - if you send two messages along a connection, one after the other,
you know the first message will get there first. You don't have to worry about
data
arriving in the wrong order.
Heavyweight - when the low level parts of the TCP "stream" arrive in the wrong
order, resend requests have to be sent, and all the out of sequence parts have to
be put back together, so requires a bit of work to piece together.
Not ordered - If you send two messages out, you don't know what order they'll
arrive in.
6
time then it takes for TCP to establish a
connection.
To establish a connection, each device must send a SYN and receive an ACK for
it from the other device. Thus, conceptually, we need to have four control
messages pass between the devices. However, it's inefficient to send a SYN and
an ACK in separate messages when one could communicate both
simultaneously. Thus, in the normal sequence of events in connection
establishment, one of the SYNs and one of the ACKs is sent together by setting
both of the relevant bits (a message sometimes called a SYN+ACK). This makes
a total of three messages, and for this reason the connection procedure is called
a three-way handshake.
Connection Establishment Functions
o Contact and Communication: The client and server make contact with
each other and establish communication by sending each other
messages. The server usually doesn’t even know what client it will be
talking to before this point, so it discovers this during connection
establishment.
8
Q.5 What is I/O multiplexing?
9
Example internetwork
Indirect routing
When a machine wishing to send an IP packet to a second machine must
send that packet through a third machine, the route the packet will travel
is said to be an ``indirect route'' and the selection of the intermediary
machine is called ``indirect routing''. The intermediary machine, a router,
has connections to more than one network and is said to provide a
gateway between the networks. Therefore, a router may also be called a
``network gateway''. In ``Example internetwork'', the machine volga is a
network gateway between the 10.0.118 network and the 10.0.246
network. If the machine seine needs to send an IP packet to paris, it must
send the packet to volga, which forwards the packet to paris.
Sometimes the source and destination hosts are more than one network
away from each other.
The function of the network layer is routing packets from the source machine to
the destination machine. In most subnets, packets will require multiple hops to
10
reach the destination. The only notable exception is for broadcast networks, but
even here routing is an issue if the source and destination are not on the same
network. The algorithms that choose the routes and the data structures that
they use are a major area of network layer design.
The routing algorithm is that part of the network layer software responsible for
deciding which output line an incoming packet should be transmitted on.
Regardless of whether routes are chosen independently for each packet or only
when new connection are established, there are certain properties that are
desirable in a routing algorithm: correctness, simplicity, robustness, stability,
fairness and optimality.
Stability is an important goal for the routing algorithm. Routing algorithms can
be grouped into two major classes: non-adaptive and adaptive. Non-adaptive
algorithms do not base their routing decisions on measurements or estimates of
the current traffic and topology. Instead, the choice of the route to use to get
form I to J is computed in advance, off-line, and downloaded to the routers when
the network is booted. This procedure is sometimes called static routing
Flooding
Another static algorithm is flooding, in which every incoming packet is sent out
on every outgoing line except the one it arrived on. Flooding obviously generates
vast numbers of duplicate packets, in fact an infinite number unless some
measure are taken, but it is one of the simplest routing algorithm. Routers need
to communicate with other routers so they can exchange routing information.
Most network operating systems have associated routing protocols which
support the transfer of routing information. Typical routing protocols and their
associated network protocol stakes are:
11
Q.8 What is the difference b/w OSI Reference Model and TCP/IP
Reference Model?
As in the OSI model, data is passed down the stack when it is being sent to the
network and up the stack when it is being received from the network. The four-
layered structure of TCP/IP is seen in the way data is handled as it passes down
the protocol stack from the application layer to the underlying physical network.
Important differences are:
OSI Reference Model TCP Reference Model
6. Protocol in OSI model are better 6. Protocols in TCP/IP are not hidden
hidden and can be replaced relatively
and thus cannot be replaced easily.
easily (No Transparency).
(Transparency)
12
Header : The IPv4 packet header consists of 13 fields, of which 12 are required.
The 13th field is optional (red background in table) and aptly named: options. The
fields in the header are packed with the most significant byte first, and for the
diagram and discussion, the most significant bits are considered to come first.
The most significant bit is numbered 0, so the version field is actually found in
the four most significant bits of the first byte, for example.
bit offset 0-3 4-7 8-15 16-18 19-31
0 Version Header length Differentiated Total Length
Services
32 Identification Flags Fragment Offset
64 Time to Live Protocol Header Checksum
96 Source Address
128 Destination Address
160 Options ( if Header Length > 5 )
160 or 192+
Data
Version : The first header field in an IP packet is the four-bit version field. For
IPv4, this has a value of 4 (hence the name IPv4).
Internet Header Length (IHL) :The second field (4 bits) is the Internet Header
Length (IHL) telling the number of 32-bit words in the header. Since an IPv4
header may contain a variable number of options, this field specifies the size of
the header (this also coincides with the offset to the data). The minimum value
for this field is 5 (RFC 791), which is a length of 5×32 = 160 bits. Being a 4-bit
value, the maximum length is 15 words (15×32 bits) or 480 bits.
Differentiated Services (DS) :Originally defined as the TOS field, this field is
now defined by RFC 2474 for Differentiated services (DiffServ) and by RFC 3168
for Explicit Congestion Notification (ECN), matching IPv6. New technologies are
emerging that require real-time data streaming and therefore will make use of
the DS field. An example is Voice over IP (VoIP) that is used for interactive data
voice exchange.
The original intention of the Type of Services (TOS) field was for a sending host
to specify a preference for how the datagram would be handled as it made its
way through an internet. For instance, one host could set its IPv4 datagrams'
TOS field value to prefer low delay, while another might prefer high reliability. In
practice, the TOS field was not widely implemented. However, a great deal of
experimental, research and deployment work has focused on how to make use
of these eight bits, resulting in the current DS field definition.
As defined in RFC 791, the following eight bits were allocated to a Type of
Service (TOS) field:
13
Total Length : This 16-bit field defines the entire datagram size, including
header and data, in bytes. The minimum-length datagram is 20 bytes (20-byte
header + 0 bytes data) and the maximum is 65,535 — the maximum value of a
16-bit word. The minimum size datagram that any host is required to be able to
handle is 576 bytes, but most modern hosts handle much larger packets.
Sometimes subnetworks impose further restrictions on the size, in which case
datagrams must be fragmented. Fragmentation is handled in either the host or
packet switch in IPv4
Flags : A three-bit field follows and is used to control or identify fragments. They
are (in order, from high order to low order):
• Reserved; must be zero. As an April Fools joke, proposed for use in RFC
3514 as the "Evil bit".
• Don't Fragment (DF)
• More Fragments (MF)
If the DF flag is set and fragmentation is required to route the packet then the
packet will be dropped. This can be used when sending packets to a host that
does not have sufficient resources to handle fragmentation.
When a packet is fragmented all fragments have the MF flag set except the last
fragment, which does not have the MF flag set. The MF flag is also not set on
packets that are not fragmented — an unfragmented packet is its own last
fragment.
Time To Live (TTL) : An eight-bit time to live (TTL) field helps prevent
datagrams from persisting (e.g. going in circles) on an internet. This field limits a
datagram's lifetime. It is specified in seconds, but time intervals less than 1
second are rounded up to 1. In latencies typical in practice, it has come to be a
hop count field. Each packet switch (or router) that a datagram crosses
decrements the TTL field by one. When the TTL field hits zero, the packet is no
longer forwarded by a packet switch and is discarded. Typically, an ICMP
message (specifically the time exceeded) is sent back to the sender that it has
been discarded. The reception of these ICMP messages is at the heart of how
traceroute works.
Protocol : This field defines the protocol used in the data portion of the IP
datagram. The Internet Assigned Numbers Authority maintains a list of Protocol
numbers which was originally defined in RFC 790. Common protocols and their
decimal values are shown below
14
Header Checksum : The 16-bit checksum field is used for error-checking of the
header. At each hop, the checksum of the header must be compared to the
value of this field. If a header checksum is found to be mismatched, then the
packet is discarded. Note that errors in the data field are up to the encapsulated
protocol to handle — indeed, both UDP and TCP have checksum fields.
Since the TTL field is decremented on each hop and fragmentation is possible at
each hop then at each hop the checksum will have to be recomputed. The
method used to compute the checksum is defined within RFC 1071:
The checksum field is the 16-bit one's complement of the one's complement
sum of all 16-bit words in the header. For purposes of computing the checksum,
the value of the checksum field is zero.
In other words, all 16-bit words are summed together using one's complement
(with the checksum field set to zero). The sum is then one's complemented and
this final value is inserted as the checksum field.
4500 + 0030 + 4422 + 4000 + 8006 + 0000 + 8c7c + 19ac + ae24 + 1e2b =
2BBCF 2 + BBCF = BBD1 = 1011101111010001, the 1'S of sum =
0100010000101110 = 442E
Source address : An IPv4 address is a group of four octets for a total of 32 bits.
The value for this field is determined by taking the binary value of each octet
and concatenating them together to make a single 32-bit value.
This address is the address of the sender of the packet. Note that this address
may not be the "true" sender of the packet due to network address translation.
Instead, the source address will be translated by the NATing machine to its own
address. Thus, reply packets sent by the receiver are routed to the NATing
machine, which translates the destination address to the original sender's
address.
Destination address : Identical to the source address field but indicates the
receiver of the packet.
Options : Additional header fields may follow the destination address field, but
these are not often used. Note that the value in the IHL field must include
enough extra 32-bit words to hold all the options (plus any padding needed to
ensure that the header contains an integral number of 32-bit words). The list of
options may be terminated with an EOL (End of Options List, 0x00) option; this is
only necessary if the end of the options would not otherwise coincide with the
end of the header. The possible options that can be put in the header are as
follows:
15
Field Size (bits) Description
Copied 1 Set to 1 if the options need to be copied into all
fragments of a fragmented packet.
Option Class 2 A general options category. 0 is for "control"
options, and 2 is for "debugging and
measurement". 1, and 3 are reserved.
Option Number 5 Specifies an option.
Option Length 8 Indicates the size of the entire option (including
this field). This field may not exist for simple
options.
Option Data Variable Option-specific data. This field may not exist for
simple options.
The use of the LSRR and SSRR options (Loose and Strict Source and Record
Route) is discouraged because they create security concerns; many routers
block packets containing these options
16
TCP provides a highly reliable, connection oriented, end-to-end transport service
between processes in end systems connected to the subnet. TCP assumes that
the layer below offers an unreliable datagram service. TCP provides the types of
facility associated with the ISO Class 4 transport service, including error
recovery, sequencing of packets, flow control by the windowing method, and the
support of multiplexed connections from the layer above
Format of TCP Header : The sender’s TCP layer communicates with the
receiver’s TCP layer using the TCP protocol data unit. It defines parameters such
as the source port, destination port, sequence number and so on. It is described
below:
• Source and destination port number – which are 16 bit values to identify the
local port number.
• Sequence number – which identifies the current sequence number of the data
segment. This allows the receiver to keep track of the data segments
received. Any segments that are missing can be easily identified.
• Data offset – which is a 32-bit value and identifies the start of the data.
• Flags the flag field is defined as UAPRSE, where U is the urgent Flag, A the
acknowledgment flag, P the push function, R the reset flag, S the sequence
synchronise flag and F the end – of transmission flag.
• Windows – which is a 16 bit value and gives the number of data blocks that
the receiving host can accept at a time.
• Checksum – which is a 16 bit checksum for the data and header. UrgPtr –
which is the urgent pointer and is used to identify an important area of data.
***
17