Byte Ordering - Unit 2
Byte Ordering - Unit 2
Ordering
UNIT - 2
BYTE ORDERING
• An arrangement of bytes when data is transmitted over
the network is called byte ordering.
• Different computers will use different byte ordering.
• When communication taking place between two machines
byte ordering should not make discomfort.
• Generally an Internet protocol will specify a common form
to allow different machines byte ordering. TCP/IP is the
Internet Protocol in use.
• Two ways to store bytes : Big endian and little endian
Big-endian
• High order byte is stored on starting address and low
order byte is stored on next address
Little-endian
• Low order byte is stored on starting address and high
order byte is stored on next address
Byte ordering functions
• Special functions are applied through routines to convert host’s
internal byte order representation to network byte order.
unsigned short htons()
• This function converts 16-bit (2-byte) data from host byte order to
network byte order.
unsigned long htonl()
• This function converts 32-bit (4-byte) data from host byte order to
network byte order.
unsigned short ntohs()
• This function converts 16-bit (2-byte) data from network byte order to
Byte Ordering Functions host byte order.
unsigned long ntohl()
• This function converts 32-bit (4- byte) data from network byte order to
host byte order.
SYSTEM CALLS & SOCKETS
System calls
• System Calls – An interface between process and operating systems.
It provides
• The services of the operating system to the user programs via Application Program
Interface(API).
• An interface to allow user-level processes to request services of the operating system.
• System calls are the only entry points into the kernel system.
SYSTEM CALLS & SOCKETS
Sockets
• Socket is an interface between applications and the network
services provided by operating systems.
APPLICATION
In UNIX systems, socket is just a special file, and socket descriptors are kept in the file descriptor table.
The Windows operating system keeps a separate table of socket descriptors (named socket descriptor table, or
SDT) for each process.
Socket creation
• The socket API contains a function socket() that can be called to create a socket.
Types of Sockets
Under protocol family AF_INET
○ Stream socket
■ Uses TCP for connection-oriented reliable communication
■ Identified by SOCK_STREAM
■ s = socket(AF_INET, SOCK_STREAM, 0) ;
○ Datagram socket
■ Uses UDP for connectionless communication
■ Identified by SOCK_DGRAM
■ s = socket(AF_INET, SOCK_DGRAM, 0) ;
○ RAW socket
■ Uses IP directly
■ Identified by SOCK_RAW
System Data Structures for Sockets
● When an application process calls socket(), the operating system allocates a
new data structure to hold the information needed for communication, and
fills in a new entry in the process’s socket descriptor table (SDT) with a pointer
to the data structure.
● A process may use multiple sockets at the same time. The socket descriptor
table is used to manage the sockets for this process.
● The internal data structure for a socket contains many fields, but the system
leaves most of them unfilled. The application must make additional procedure
calls to fill in the socket data structure before the socket can be used.
● The socket is used for data communication between two processes (which may
locate at different machines). So the socket data structure should at least contain
the address information, e.g., IP addresses, port numbers, etc.
Functions used in client program
Receiving data
• read(int sockfd, void *buf, size_t len)
• Arguments: socket descriptor, pointer to buffer to place the data, size of the buffer
• Returns the number of characters read (where 0 implies “end of file”), and -1 on error
● RPC allows programs to call the procedure which is located on the other
machines.
● RPC enables a procedure call that does not reside in the address space of
the calling process.
● In RPC, the caller and the callee has disjoint address space, hence there is
no access to data and variables in the callers environment.
● A client has a request message that the RPC translates and sends to the server.
● When the server receives the request, it sends the required response back to the client.
● The client is blocked while the server is processing the call and only resumed execution
after the server is finished.
Client Server RPC Model
Sequence of events in a RPC
● The client stub is called by the client.
● The client stub makes a system call to send the message to the
server and puts the parameters in the message.
● The message is sent from the client to the server by the client’s
operating system.
● The parameters are removed from the message by the server stub.
● The internal message passing mechanism of RPC is hidden from the user.
● The effort to re-write and re-develop the code is minimum in remote procedure calls.
● Remote procedure calls can be used in distributed environment as well as the local environment.
TCP Package
● TCP is a stream-service, connection-oriented
protocol with an involved state transition diagram.
• The output processing module handles all the details needed to send out data received from
application program when TCP is in the ESTABLISHED STATE.
✔ Located between application layer and network layer in the TCP/IP protocol suite
Limitations of UDP
● There is no flow control mechanism.
✔ Application which use small messages to be sent without reliability in that case UDP is the best.
✔ For small messages less no. of interactions is required between sender and receiver for UDP compared
to TCP.
UDP Services
Process to Process communication
UDP provides process-to-process communication
using sockets, a combination of IP addresses and
port numbers. Several port numbers used by UDP.
Connectionless services
Congestion control
Does not provide congestion control and has an assumption that the packets are small and sporadic
so they cant create congestion.
UDP Services
Checksum
• Three sections: a pseudo header, the UDP header, and the
data coming from the application layer.
Pseudo header
▪ It is a part of the IP header
The client process can send messages to the outgoing queue by using the source port number
UDP removes the messages one by one and, after adding the UDP header, delivers them to IP. An
It happens the operating system can ask the client process to wait before sending any more
messages
Demultiplexing
✔ One to many relationship.
✔ UDP receives the user datagram from IP and drops the header
then sends the message to appropriate process based on port
numbers.
UDP Features
✔ Connectionless services
✔ The overhead to establish and close a connection may be significant whereas in TCP it takes
9 packets for exchanges between client and server to achieve the above goal.
▪ In reliable service the transport layer needs to take care of the lost packet by resending it.
So there will be a uneven delay between different parts of the message delivered.
Lack of congestion control
▪ TCP leads to creation of congestion or additional congestion in network by resending packets several
times when a packet are lost.
UDP Applications
❑ Used for simple request response communication when size of data is less hence there
is lesser concern about flow and error control.
Output module
• The output module is responsible for creating and sending
user datagrams.
SCTP is a message-oriented, reliable protocol that combines the best features of UDP and TCP.
SCTP Services
Process-to-Process Communication
• SCTP uses all well-known ports in the TCP space
• If one of the streams is blocked, the other streams can still deliver
their data
Multiple-stream concept
SCTP Services Multihoming
• The sending and receiving host can define multiple IP addresses in
each end for an association.
• when one path fails, another interface can be used for data delivery
without interruption.
Multihoming concept • This fault-tolerant feature helps in sending and receiving a real-time
payload such as Internet telephony.
Full-Duplex Communication
• SCTP has sending and receiving buffer, hence packets are sent in both
directions.
SCTP Services
Connection-Oriented Service
• A connection is called an association in SCTP
• Steps to send and receive data in SCTP
1. The two SCTP’s establish an association between each other.
2. Data are exchanged in both directions.
3. The association is terminated.
Reliable Service
• It uses an acknowledgment mechanism to check the safe and sound arrival of data.
SCTP Services
Transmission Sequence Number (TSN)
• Unit of data in SCTP is called the data chunk.
• Data transfer in SCTP is controlled by numbering the data chunks.
• SCTP uses a TSN to number the data chunks with 32 bits long number which is randomly initialized
between 0 and 232− 1.
• Each data chunk carry their TSN in its header.
Packets
• Data are carried as data chunks, control information as control
Packet, data chunks, and streams chunks.
• Several control chunks and data chunks can be packed together in a
packet.
SCTP Features
Comparison between a TCP segment and an SCTP packet
Flow Control
• SCTP implements flow control to avoid overwhelming receiver
Error Control
• TSN numbers and acknowledgment numbers are used for error control.
Congestion Control
• SCTP implements congestion control to determine how many data chunks can be injected into the
network
SCTP Features
Types of chunks
• Control chunks - controls and maintains the association
• Data chunks - carries user data
SCTP packet format
SCTP Packet Format
General Header
• Defines the end points of each association to which the
packet belongs.
• Guarantees for a packet belongs to a particular association.
• Preserves the integrity of the contents of the packet.
There are four fields in the general header
• Source port address: 16-bit field defines the port number
of the sender process
• Destination port address: 16-bit field defines the port
General header number of the receiving process
• Verification tag: Number that matches a packet to an
association
• It serves as an identifier for the association
• Separate verification used for each direction in the
association.
• Checksum: 32-bit field contains a CRC-32 checksum
SCTP Packet Format
Chunks
• Control information or user data are carried
• First three fields are common to all chunks
• Type: 8-bit field define up to 256 types of chunks(few
have been defined, rest are reserved for future use)
• Flag: 8-bit field defines special flags that a particular
chunk may need.
• Length: 16-bit field defines the total size of the chunk, in
Types of Chunks bytes, including the type, flag, and length fields
• TSN - Sequence number initialized in an INIT chunk for one direction and in the
INIT ACK chunk for the opposite direction
• SI - all chunks of same stream in one direction have same stream identifier
DATA
chunk • Protocol identifier: 32-bit field used by the application program to define the
type of data which is ignored by SCTP
INIT chunk
SCTP Packet Format
INIT ack(initiation acknowledgment chunk)
• Second chunk sent during association establishment
• Value of the verification tag is the value of the initiation tag of INIT
chunk.
• The parameter of type 7 defines the state cookie sent by the sender of
this chunk
INIT ACK
chunk • Initiation tag field in this chunk initiates the value of the
verification tag for future packets traveling from the opposite
direction.
SCTP Packet Format
Cookie echo
• Third chunk sent during association establishment that carry
user data too.
• Sent by the end point that receives an INIT ACK chunk.
COOKIE ECHO chunk • Chunk of type 10.
COOKIE ACK
• fourth and last chunk sent during association establishment
with data chunk too.
COOKIE ACK • sent by an end point that receives a COOKIE ECHO chunk.
• chunk of type 11.
SCTP Packet Format
SACK(selective ACK chunk)
• Acknowledges the receipt of data packets
• Common fields
• Type field has 3
• Flag bits are set to 0s
• Cumulative tsn acknowledgment: 32-bit field defines the tsn of the last data chunk
received in sequence
• Advertised receiver window credit: 32-bit field that have updated value for the
receiver window size
• Number of gap ACK blocks: 16-bit field defines the number of gaps in the data chunk
received after the cumulative
TSN
• Number of duplicates: 16-bit field defines the number of duplicate chunks following
the cumulative TSN
SACK chunk • Gap ACK block start offset: 16-bit field gives the starting TSN relative to the cumulative
TSN
• Gap ACK block end offset: 16-bit field gives the ending TSN relative to the cumulative
TSN
• Duplicate tsn: 32-bit field gives the tsn of the duplicate chunk.
SCTP Packet Format
HEARTBEAT and HEARTBEAT ACK
• First has a type of 4 and the second a type of 5
• Used to periodically probe the condition of an association
• An end point sends a HEARTBEAT chunk, peer responds HEARTBEAT ACK if it is
alive
• Parameter fields provide sender-specific information like address and local time
HEARTBEAT and HEARTBEAT ACK
chunks • Same is copied into the HEARTBEAT ACK chunk.
ABORT
• Sent when an end point finds a fatal error and needs to abort the
Errors association.
FORWARD TSN
ERROR chunk
• This is a chunk recently added to the standard to inform the
receiver to adjust its cumulative TSN
ABORT chunk
SCTP Client/Server(Association)
Association Establishment
• Four-way handshake
1. First packet has INIT chunk sent by client
• Verification tag is 0
• Rwnd is advertised in a SACK chunk
• Inclusion of a DATA chunk in the third and fourth
packets
2. Second packet has INIT ACK chunk sent by server
• Verification tag is the initial tag field in the INIT chunk
• Initiates the tag to be used in the other direction
• Defines the initial TSN and sets the servers’ rwnd
3. Third packet has COOKIE ECHO chunk sent by client
• Echoes the cookie sent by the server
Four-way handshaking • Data chunks are included in this packet
4. Fourth packet has COOKIE ACK chunk sent by server
• Acknowledges the receipt of the COOKIE ECHO chunk
• Data chunks are included with this packet.
SCTP Client/Server(Association)
Number of Packets Exchanged
• Number of packets exchanged is four(3 for TCP)
• Allows the exchange of data in the third and fourth packets, so it is efficient
Verification tag
• It is a common value carried in all packets traveling in one direction in an association
• Blind attacker cannot inject a random packet into an association
• A packet from an old association cannot show up in an incarnation
Cookie
• Cookie is sent with the second packet to the address received in the first packet
• If the sender of the first packet is an attacker, the server never receives the third packet
• If the sender of the first packet is an honest client, it receives the second packet, with the cookie
SCTP Client/Server(Association)
Data transfer
• Purpose of an association is to transfer data between two ends.
Multistream delivery
• TSN numbers are used to handle data transfer whereas delivery of the data chunks are controlled by SIs
and SSNs.
• Two types of data delivery in each stream
• Ordered: SSNs define the order of data chunks in the stream.
• Unordered: U flag is set, it delivers the message carrying the chunk to the
destination application without waiting for the other messages.
SCTP Client/Server(Association)
Fragmentation
• SCTP preserves the boundaries of the message when creating DATA chunk from a message
• If the total size exceeds the MTU, the message needs to be fragmented
• If not, the data in the queue are sent and the association
is closed
Association termination
• Server may wish to abort since it has received an INIT chunk with
Association abortion
wrong parameters, requested resources are not available after
receiving the cookie, the operating system needs to shut down etc.
• For abortion process either end can send an abort chunk to abort the
association