The Transport Layer Aims To explain:- The need for the transport layer A simple exemplar Transport in IP and ATM Outcomes To understand the need for the layer and the solution adopted adopted when internetworking with the internet and the ATM. 1
The Transport Layer Aims to provide Efficient Reliable Cost effective Service to the applications layer. Using the services provided by the network layer. Why is it necessary? 2
Quality of Service Parameters Connection Establishment Delay Connection Failure Probability Throughput Transit Delay Residual error ratio Protection Priority Resilience 3
TP Data Units Frame header Packet header TPDU header TPDU payload Packet payload Frame payload The Nesting of TPDU Packets and Frames 4
The Transport Layer Primitives Primitive TPDU sent LISTEN - CONNECT CONNECTION REQ. SEND DATA RECEIVE DATA DISCONNECT DISCONNECTION REQ. CLIENTs Call servers. SERVERs wait to be asked. 5
Connection Management Connection request TPDU received IDLE Connect primitive executed PASSIVE ESTABLISHMENT PENDING ACTIVE ESTABLISHMENT PENDING Connect primitive executed Disconnection request TPDU received PASSIVE DISCONNECT PENDING ESTABLISHED Connection accepted TPDU received Disconnect primitive executed ACTIVE DISCONNECT PENDING Disconnect primitive executed IDLE Disconnection request TPDU received A State Diagram for a Connection Management Scheme Solid lines are client transitions. Dashed lines are server transitions. 6
Berkley Sockets Transport for Berkley Unix. Primitive SOCKET BIND LISTEN ACCEPT CONNECT SEND RECEIVE CLOSE Meaning Create a new end port Attach a local address to a socket Will accept connections Block unitl connection Establish a connection Send data Receive data Release connection The server issues SOCKET BIND LISTEN ACCEPT 7
Berkley Sockets II The client issues SOCKET CONNECT Both sides now issue SEND RECEIVE CLOSE 8
#include <stdio.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <netdb.h> #define SERVER_PORT 5432 #define MAX_LINE 256 A Client Server Echo int main(int argc, char *argv[]) { FILE *fp; struct hostent *hp; struct sockaddr_in sin; char *host; char buf[max_line]; int s,len; if(argc<2){ printf("give me a host name matey"); exit(0); } host=argv[1]; if(!(hp=gethostbyname(host))){ /*get IP address of the host */ printf("%s is unknown",host); exit(0); } /* build address structure */ bzero((char*)&sin, sizeof(sin)); sin.sin_family=af_inet; bcopy(hp->h_addr,(char*)&sin.sin_addr,hp->h_length); sin.sin_port=htons(server_port); 9
/* open as active */ if((s=socket(pf_inet,sock_stream,0))<0){ printf("socket creation error"); exit(0); } /* connect socket to address */ if(connect(s,(struct sockaddr*)&sin, sizeof(sin))<0) { printf("connection error"); close(s); exit(0); } /* send some lines */ while(fgets(buf,sizeof(buf),stdin)){ buf[max_line-1]= \0 ; len=strlen(buf)+1; send(s,buf,len,0); } }
#include <stdio.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <netdb.h> #define SERVER_PORT 5432 #define MAX_LINE 256 #define MAX_PENDING 5 int main() { struct sockaddr_in sin; char *host; char buf[max_line]; int s,new_s,len; A Client Server Echo /* build address structure */ bzero((char*)&sin, sizeof(sin)); sin.sin_family=af_inet; sin.sin_addr.s_addr=inaddr_any; sin.sin_port=htons(server_port); /* open as passive */ if((s=socket(pf_inet,sock_stream,0))<0){ printf("socket creation error"); exit(0); } 10
/* bind socket to address */ if(bind(s,(struct sockaddr*)&sin, sizeof(sin))<0) { printf("binding error"); close(s); exit(0); } listen(s,max_pending); /* get some lines */ while(1){ if((new_s=accept(s,(struct sockaddr *)&sin,&len))<0) { printf("acceptance error"); close(s); exit(0); } while(len=recv(new_s,buf,sizeof(buf),0)) puts(buf); close(new_s); } }
The Transport Layer Protocols The transport layer deals with:- error control sequencing flow control In common with the data link. Router Router Subnet Physical communication channel Host (a) (b) The Data Link and Transport Environments 11
Access Points Host 1 Host 2 Application process TSAP 6 Application layer Server Network connection starts here Transport connection starts here Transport layer TSAP 122 NSAP Network layer NSAP Data link layer Phys Physical layer TSAPs, NSAPs and Connections 12
Daemon Processes Host 1 Host 2 Host 1 Host 2 Layer User Process Server User Process Server Time of day server 4 TSAP (a) (b) Host 1 establishes a connection with host 2 process server Unix. Saves having lots of active daemons. name server might live here too. 13
Establishing a Connection I This is problematic when the network can lose, store and duplicate packets. Duplication is a big problem. new TSAPs connection IDs kill off the old 1. restrict subnet 2. hop counter 3. timeout 14
Establishing a Connection II Sequence numbers 120 80 70 60 Forbidden message Forbidden region T Restart after crash with 70 Sequence numbers 2 k 1 T 0 0 30 60 90 Time (a) 120 150 180 Actual sequence numbers used Time (b) a. TPDUs may not enter the forbidden region. b. The resynchronisation problem 15
Establishing a Connection III Host 1 Host 2 CR (seq = x) Host 1 Host 2 Old duplicate CR (seq = x) Time ACK (seq = y, ACK = x) ACK (seq = y, ACK = x) DATA (seq = x, ACK = y) REJECT (ACK = y) (a) (b) Host 1 Host 2 Old duplicate CR (seq = x) ACK (seq = y, ACK = x) Old duplicate DATA (seq = x, ACK = z) REJECT (ACK = y) (c) The 3-way handshake 16
Releasing a Connection I Host 1 Host 2 CR ACC Time DATA DATA DR No data are delivered after a disconnect request Asynchronous Release Host 2 issues a DISCONNECT REQ. before Host 1 has finished sending. The remaining data are lost. Synchronous Release Host 2 issues DR but link is still established Host 1 issues DC both disconnect. 17
Releasing over a Hostile Channel B Blue army #1 B Blue army #2 W White army The 2 Army Problem 1. #1 we attack at 2pm. ok? 2. #2 ok 3. #1 was that you who said ok #2? 4. #2 yes 5.... 18
Releasing a Connection III Host 1 Host 2 Send DR + start timer DR Host 1 Host 2 Send DR + start timer DR Release connection DR Send DR + start timer Release connection DR Send DR + start timer Send ACK ACK Release connection Send ACK ACK Lost (Timeout) release connection (a) (b) Host 1 Host 2 Send DR + start timer ( Timeout) send DR + start timer Release connection Lost DR DR DR DR Send DR & start timer Send DR & start timer Host 1 Host 2 Send DR + start timer ( Timeout) send DR + start timer Lost DR Lost Send DR & start timer Send ACK ACK Release connection (N Timeouts) release connection (Timeout) release connection (c) 4 scenarios for connection release (d) 19
Flow Control If the receiver knows that the sender keeps the TPDU until it is acknowledged then it need not buffer it. eg. If dynamic buffer allocation is used and space is exhausted, then the TPDU can be discarded. For an unreliable network connection the sender must keep a copy of everything. For a reliable connection in which the receiver always has room then the sender need not buffer. Whatever:- the network acknowledgement means only that the TPDU was delivered, not that it was accepted. 20
Flow Control Buffer Schemes TPDU 1 TPDU 2 TPDU 3 (a) (b) Unused space TPDU 4 (c) a. Chained fixed size b. chained variable size c. One circular per connection 21
A Credit Request Scheme A Message B Comments 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 < request 8 buffers> <ack = 15, buf = 4> <seq = 0, data = m0> <seq = 1, data = m1> <seq = 2, data = m2> <ack = 1, buf = 3> <seq = 3, data = m3> <seq = 4, data = m4> <seq = 2, data = m2> <ack = 4, buf = 0> <ack = 4, buf = 1> <ack = 4, buf = 2> <seq = 5, data = m5> <seq = 6, data = m6> <ack = 6, buf = 0> <ack = 6, buf = 4> A wants 8 buffers B grants messages 0-3 only A has 3 buffers left now A has 2 buffers left now Message lost but A thinks it has 1 left B acknowledges 0 and 1, permits 2-4 A has buffer left A has 0 buffers left, and must stop A times out and retransmits Everything acknowledged, but A still blocked A may now send 5 B found a new buffer somewhere A has 1 buffer left A is now blocked again A is still blocked Potential deadlock Dynamic buffer allocation.... is a lost TPDU 22
Multiplexing Layer 4 Transport address Network address 3 2 Router lines 1 (a) To router (b) a. Upward multiplexing b. downward multiplexing Lines in the network layer cost. Send everything out on one network connection and let the Transport layer sort it out. Bandwidth use. One high speed line. n-bits in protocol implies wait for all acks after 2 n messages. Use multiple network connections. 23
Crash Recovery If a router crashes the network layer can handle it. The transport layer expects lost TPDUs and should handle it. Host crashes are different. Strategy used by receiving host First ACK, then write First write, then ACK Strategy used by sending host AC(W) AWC C(AW) C(WA) W AC WC(A) Always retransmit OK DUP OK OK DUP DUP Never retransmit Retransmit in S0 Retransmit in S1 LOST OK LOST OK DUP LOST LOST OK OK LOST OK OK LOST DUP OK OK OK DUP OK = Protocol functions correctly DUP = Protocol generates a duplicate message LOST = Protocol loses a message Different combinations of client server strategy S0 - no outstanding packets S1 - an unacked TPDU outstanding. A - acknowledge. W - write to process. C - crash. 24