版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
OSILayer4:
TransportLayerOSILayer4:TransportLayerAnoverviewoflayer4
TCP(TransmissionControlProtocol)UDP(UserDatagramProtocol)Anapplication:NATandPATLayer4performsmultiplefunctions:segmentingupper-layerapplicationdataestablishingend-to-endoperationssendingsegmentsfromoneendhosttoanotherFlowcontrolandreliabilitycanbecomparedtotalkingtoaforeigner.Oftenyouwouldasktheforeignertorepeathis/herwords(reliability)andtospeakslowly(flowcontrol)OSILayer4:TransportLayer
TwoparticularlyimportantLayer4protocols:
TransmissionControlProtocol(TCP)UserDatagramProtocol(UDP)Layer4:TheTransportLayerDivideoutgoingmessagesintosegmentsReassemblemessagesatthedestinationstationTCP:reliableConnection-orientedSoftwarecheckingforsegmentRe-sendanythinglostorerrorUsesacknowledgmentsProvidesflowcontrolUDP:
unreliable
connectionless
providesnosoftwarecheckingforsegmentusesnoacknowledgmentsprovidesnoflowcontrolLayer4:TheTransportLayerBothTCPandUDPuseport
tokeeptrackofdifferentconversationsthatcrossthenetworkatthesametimeApplicationsoftwaredevelopershaveagreedtousethewell-knownportnumbersthataredefinedinRFC1700
Portnumbersbelow255arereservedforTCPandUDPpublicapplications.ServiceModelSocketispresentedas(IP_address,port)Everyconnectionisexpressedas(socketsource,socketdestination),whichisapoint-to-pointfull-duplexchannelDoesnotsupportmulticastandbroadcastSocketLayer4:TheTransportLayerAnoverviewoflayer4TCP(TransmissionControlProtocol)UDP(UserDatagramProtocol)Anapplication:NATandPATTCPServiceModelProblemsmustbesolvedinTCP:ReliabletransferFlowcontrolSlidingwindowcongestionavoidance…ConnectionmanagementEstablishconnection:threehandshakesReleaseconnection:fourhandshakesTCP首部20字节固定首部目的端口数据偏移检验和选项(长度可变)源端口序号紧急指针窗口确认号保留FINSYNRSTPSHACKURG位08162431填充源端口和目的端口字段——各占2字节端口是运输层与应用层的服务接口运输层的复用和分用功能都要通过端口才能实现TCP首部20字节固定首部目的端口数据偏移检验和选项(长度可变)源端口序号紧急指针窗口确认号保留FINSYNRSTPSHACKURG位08162431填充序号字段——占4字节TCP传送的数据流中的每一个字节都编上一个序号序号字段的值指本报文段所发送的数据的第一个字节的序号TCP首部20字节固定首部目的端口数据偏移检验和选项(长度可变)源端口序号紧急指针窗口确认号保留FINSYNRSTPSHACKURG位08162431填充确认号字段——占4字节,是期望收到对方的下一个报文段的数据的第一个字节的序号TCP首部20字节固定首部目的端口数据偏移检验和选项(长度可变)源端口序号紧急指针窗口确认号保留FINSYNRSTPSHACKURG位08162431填充数据偏移(即首部长度)——占4位指出TCP报文段的数据起始处距TCP报文段的起始处的长度单位是32位字(以4字节为计算单位)TCP首部20字节固定首部目的端口数据偏移检验和选项(长度可变)源端口序号紧急指针窗口确认号保留FINSYNRSTPSHACKURG位08162431填充保留字段——占6位,保留为今后使用,目前置0TCP首部20字节固定首部目的端口数据偏移检验和选项(长度可变)源端口序号紧急指针窗口确认号保留FINSYNRSTPSHACKURG位08162431填充紧急URG1时,表明紧急指针字段有效告诉系统此报文段中有紧急数据,应尽快传送(相当于高优先级的数据)
TCP首部20字节固定首部目的端口数据偏移检验和选项(长度可变)源端口序号紧急指针窗口确认号保留FINSYNRSTPSHACKURG位08162431填充ACK1时确认号字段有效ACK0时确认号字段无效TCP首部20字节固定首部目的端口数据偏移检验和选项(长度可变)源端口序号紧急指针窗口确认号保留FINSYNRSTPSHACKURG位08162431填充推送PSH(PuSH)——接收TCP收到PSH=1的报文段,就尽快地交付接收应用进程,而不再等到整个缓存都填满了后再向上交付TCP首部20字节固定首部目的端口数据偏移检验和选项(长度可变)源端口序号紧急指针窗口确认号保留FINSYNRSTPSHACKURG位08162431填充复位RST(ReSeT1时,表明TCP连接中出现严重差错(如由于主机崩溃或其他原因),必须释放连接,然后再重新建立运输连接TCP首部20字节固定首部目的端口数据偏移检验和选项(长度可变)源端口序号紧急指针窗口确认号保留FINSYNRSTPSHACKURG位08162431填充同步SYN=1表示这是一个连接请求或连接接受报文TCP首部20字节固定首部目的端口数据偏移检验和选项(长度可变)源端口序号紧急指针窗口确认号保留FINSYNRSTPSHACKURG位08162431填充终止FIN(FINis)——用来释放一个连接。FIN1表明此报文段的发送端的数据已发送完毕,并要求释放运输连接。TCP首部20字节固定首部目的端口数据偏移检验和选项(长度可变)源端口序号紧急指针窗口确认号保留FINSYNRSTPSHACKURG位08162431填充窗口字段——占2字节,用来让对方设置发送窗口的依据,单位为字节。TCP首部20字节固定首部目的端口数据偏移检验和选项(长度可变)源端口序号紧急指针窗口确认号保留FINSYNRSTPSHACKURG位08162431填充检验和——占2字节。检验和字段检验的范围包括首部和数据这两部分TCP首部20字节固定首部目的端口数据偏移检验和选项(长度可变)源端口序号紧急指针窗口确认号保留FINSYNRSTPSHACKURG位08162431填充紧急指针字段——占16位,指出在本报文段中紧急数据共有多少个字节(紧急数据放在本报文段数据的最前面)
TCP首部20字节固定首部目的端口数据偏移检验和选项(长度可变)源端口序号紧急指针窗口确认号保留FINSYNRSTPSHACKURG比特08162431填充TCP最初只有一种选项,即最大报文段长度MSS(MaximumSegmentSize)MSS告诉对方缓存所能接收的报文段的数据字段的最大长度是MSS个字节数据字段加上TCP首部才等于整个的TCP报文段。TCP首部20字节固定首部目的端口数据偏移检验和选项(长度可变)源端口序号紧急指针窗口确认号保留FINSYNRSTPSHACKURG位08162431填充填充字段——这是为了使整个首部长度是4字节的整数倍。TCPProtocolHostsexchangedatabyusingsegment(TPDU)Eachsegmenthas:aheaderof20bytes(exceptoptionalparts)
0ormoredatabytesThesizeofthesegmentmustbematchedwithIPpackets,andalsomustsatisfythedemandofbottomlayersForexample,theMTU(MaximalTransferUnit)ofEthernetis1500bytesEachbytehasa32bitssequencenumberReliableConnection?
Two-armyProblem
TCP:EstablishConnectionSYN=1,seq=xClosedClosedActiveopenPassiveopenABClientServerTheFirstHandshakeServer:executesLISTEN
andACCEPTprimitive,andmonitorspassivelyClient:executesCONNECTprimitive,generateaTCPsegmentwithSYN=1andACK=0,whichstandsforconnectionrequestSYN=1,seq=xSYN=1,ACK=1,seq=y,ack=x1TheSecondHandshakeServerchecksifexistsserviceprocessmonitoringtheportIfnoneprocess,answeraTCPsegmentwithRST=1Ifexistsprocess,decidestorejectortoaccepttherequestIfaccepttheconnectionrequest,sendasegmentwithSYN=1andACK=1ClosedClosedActiveopenPassiveopenABClientServer
TCP:EstablishConnectionSYN=1,seq=xACK=1,seq=x+1,ack=y1SYN=1,ACK=1,seq=y,ack=x1TheThirdHandshakeTheclientsendsasegmentwithSYN=0andACK=1
toacknowledgetheconnectionClosedClosedActiveopenPassiveopenABClientServer
TCP:EstablishConnectionSYN=1,seq=xACK=1,seq=x+1,ack=y1DataTransferSYN=1,ACK=1,seq=y,ack=x1Whentheserverreceivestheacknowledgement,itinformstheupperlayerapplications
TCP:EstablishConnectionClosedClosedActiveopenPassiveopenABClientServerSYN-SENTESTAB-LISHEDSYN-RCVDLISTENESTAB-LISHEDSYN=1,seq=xACK=1,seq=x+1,ack=y1DataTransferSYN=1,ACK=1,seq=y,ack=x1
TCP:EstablishConnectionClosedClosedActiveopenPassiveopenABClientServerExample:EstablishConnection
TCPATCPB1.CLOSEDLISTEN2.SYN-SENT--><SEQ=100><CTL=SYN>-->SYN-RECEIVED3.ESTABLISHED<--<SEQ=300><ACK=101><CTL=SYN,ACK><--SYN-RECEIVED4.ESTABLISHED--><SEQ=101><ACK=301><CTL=ACK>-->ESTABLISHED5.ESTABLISHED--><SEQ=101><ACK=301><CTL=ACK><DATA>-->ESTABLISHEDBasic3-WayHandshakeforConnectionSynchronizationNotethattheACKdoesnotoccupysequencenumberspace(ifitdid,wewouldwindupACKingACK's!)Datatransfer
——stop-and-waitprotocol(a)NoerrorASend
M1ACK
M1BSend
M2Send
M3ACKM2ACK
M3ASend
M1BResend
M1Send
M2ACK
M1Disposethesegment(b)OutoftimettttDatatransfer
——stop-and-waitprotocolAftersendingasegment,preserveabackuptemporarilyEachsegmentandACKmusthaveIDTheresend-timemustbemorethanaverage-travel-time*2stop-and-waitprotocolisasimpleprotocol,buthaspoorefficiencyDatatransfer
——LostACKandLateACKASend
M1BOutoftimeResendM1SendM2DisposetherepeatedM1andresendACKM2(a)LostACKACK
M1ASend
M1BOutoftimeResendM1Send
M2DisposetherepeatedM1andresendACKM1(b)LateACKACKM1ReceivethelateACKanddonothingttttReliableCommunicationARQ(AutomaticRepeatreQuest)。Itmeansthe‘resendrequest’isautomaticallysentandthereceiverneednotrequestthesendertoresendtheerrorsegmentContiguousARQProtocol123456789101112(a)发送方维持发送窗口(发送窗口是5)发送窗口(b)收到一个确认后发送窗口向前滑动向前123456789101112发送窗口SegmentttACKFIN=1,seq=uESTAB-LISHEDCLOSEDDataTransferESTAB-LISHEDTCP:ReleaseConnectionActiveClosePassiveCloseABClientServerFIN=1,seq=uACK=1,seq=v,ack=u1ESTAB-LISHEDDataTransferESTAB-LISHEDActiveCloseInformUpperLayerABClientServerTCP:ReleaseConnectionFIN=1,seq=uACK=1,seq=v,ack=u1FIN=1,ACK=1,seq=w,ack=u1PassiveCloseDataTransferESTAB-LISHEDDataTransferESTAB-LISHEDActiveCloseInformUpperLayerABClientServerTCP:ReleaseConnectionFIN=1,seq=uACK=1,seq=v,ack=u1FIN=1,ACK=1,seq=w,ack=u1ACK=1,seq=u+1,ack=w1TCP:ReleaseConnectionPassiveCloseDataTransferESTAB-LISHEDDataTransferESTAB-LISHEDActiveCloseInformUpperLayerABClientServerCLOSEDACK=1,seq=u+1,ack=w1FIN=1,seq=uACK=1,seq=v,ack=u1FIN=1,ACK=1,seq=w,ack=u1FIN-WAIT-1CLOSE-WAITFIN-WAIT-2LAST-ACKWait
2MSLTIME-WAITCLOSEDBeforereleasingconnection,theclientmustwaitfor2MSLTCP:ReleaseConnectionPassiveCloseDataTransferESTAB-LISHEDDataTransferESTAB-LISHEDActiveCloseInformUpperLayerABClientServerWhymustwaitfor2MSL?ToensurethelastACKsentbyAcanreachBTopreventanyinvalidconnectionrequestsegmentfromemergingAfterwaitingfor2MSL,wecanmakesurethatallsegmentsontheconnectionhavedisappearedT
C
P
的
有
限
状
态
机CLOSEDESTABLISHEDLISTENCLOSE_WAITFIN_WAIT_1SYN_RCVDFIN_WAIT_2CLOSINGTIME_WAITSYN_SENTLAST_ACK主动打开被动打开被动关闭主动关闭起点被动打开主动打开发送SYN同时打开收到SYN,发送SYN,ACK收到ACK数据传送阶段
关闭发送FIN
关闭发送FIN
关闭发送FIN收到RST
收到SYN发送SYN,ACK
关闭或超时收到ACK
收到SYN,ACK发送ACK收到ACK收到ACK收到FIN发送ACK收到FIN,ACK
发送ACK收到FIN发送ACK同时关闭收到FIN发送ACK发送SYN定时经过两倍报文段寿命后关闭Layer4:TheTransportLayerAnOverviewofLayer4TCP(TransmissionControlProtocol)UDP(UserDatagramProtocol)Anapplication:NATandPATUDP(UserDatagramProtocol)WhydoweneedUDP?Noconnectionestablishment(whichcanadddelay)Simple:noconnectionstateatsender,receiverSmallsegmentheaderNocongestioncontrol:UDPcanblastawayasfastasdesiredUDP(UserDatagramProtocol)Connectionless:nohandshakingbetweenUDPsender,receivereachUDPsegmenthandledindependentlyofothersOftenusedforstreamingmultimediaapplicationslosstolerantratesensitiveUDPareusedin:RIP:TosendtherouteinformationperiodicallyDNS:AvoidthedelaytosetuptheTCPconnectionSNMP:Whencongestion,SNMPmuststillrunable.Withoutthecongestionandreliabilitycontrolmechanism,UDPhasbetterperformancethanTCPunderthecircumstances.OtherprotocolsincludeTFTP,DHCPAddreliabilityatapplicationlayerifnecessaryUDP(UserDatagramProtocol)Layer4:TheTransportLayerAnOverviewofLayer4TCP(TransmissionControlProtocol)UDP(UserDatagramProtocol)Anapplication:NATandPATNAT,istheprocessofswappingoneaddressforanotherintheIPpacketheaderInpractice,NATisusedtoallowhoststhatareprivatelyaddressedtoaccesstheInternetOneofsolutionstoIPaddressdepletionConservesregistered(legal)addressesIncreasesFlexibilitywhenconnectingtoInternetRFC1631-
NetworkAddressTranslator(NAT)WhatisNAT?NATasimpleconceptPrivateaddresses
Registeredaddresses
NATtypesStaticNAT: FixedmappingofaninternaladdresstoanregisteredaddressDynamicNAT: Mappingisdonedynamicallyonafirstcomefirst
servedbasisPAT(Overload):
Portaddresstranslationisusedtoallowmanyinternaluserstoshareasingle‘insideglobal’
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
评论
0/150
提交评论