計算機網絡復習資料-network講稿-tcp_第1頁
計算機網絡復習資料-network講稿-tcp_第2頁
計算機網絡復習資料-network講稿-tcp_第3頁
計算機網絡復習資料-network講稿-tcp_第4頁
計算機網絡復習資料-network講稿-tcp_第5頁
已閱讀5頁,還剩175頁未讀 繼續免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

P663

TransportProtocols

2

其它的網絡系統結構

?其它網絡體系結構

-ARPANET

—SNA(SystemNetworkArchitecture)

-DNA(DECNET)

-TCP/IP

其它的網絡系統結構

ISO/OSITCP/1PARPASNADNA

應用層用戶層端用戶端用戶

表示層功能管理服務網絡應用

應用文件傳輸協議

會話層遠程通信協議數據流控制會話控制

傳輸層TCP/UDPHOST-HOST傳輸控制網絡服務

源IMP-目的IMP

路由控制

網絡層IP通路傳輸控制

控制傳輸組

IMP-IMP

數據鏈路層數據鏈路數據鏈路控制

數據鏈路控制

物理層物理層物理層物理層物理層

P602

IPv6

?Expandedaddressspace

?Improvedoptionmechanism

?Addressautoconfiguration

?Increasedaddressingflexibility

?Supportforresourceallocation

IPv6headerExtensionheader...ExtensionheaderTransport-levelPDU

_、_,__________J

Y

40octets0ormore

Extensionheaders

?Hop-by-HopOptionheader

?Routingheader

?Fragmentheader

?Authenticationheader

?EncapsulatingSecurityPayloadheader

?DestinationOptionsheader5

P604

IPv6Header

t?o423

Bi?1624

VersionTrafficClassFlowLabel

■■■■一■■■■■”■'■■■■

BB<S:?ir:ZMi(I?=■>,■

files'■-*im■■IL*g*?J?!IB

PayloadLength■■■■■■■■■Ml■■■■■■■■■■!■■■■■HopLimit

■■■■■■■■■■■■■■■■■■■■)■■■■■

S

gJ

toJ

。SoureceAddress

H

S

J

I

q

DestinationAddress

6

TCP/IP協議族圖示

H/WDeviceDriversandMediaAccessProtocols

TCP/IPOSI

OSITCP/IP

Application

Application

Presentation

User

Space

Session

▲Software

1ransport

Transport(host-to-host)

Internet

NetworkFirmware

Network

Operating

DataLinkAccess

System

▼3

PhysicalPhysical

8

Figure16.1InternetworkingProtocolsContext9

InternetworkingProtocolsinContext

10

TCP

AbbreviationofTransmissionControlProtocol,andpronouncedasseparate

letters.TCPisoneofthemainprotocolsinTCP/IPnetworks.WhereastheIP

protocoldealsonlywithpackets,TCPenablestwohoststoestablisha

connectionandexchangestreamsofdata.TCPguaranteesdeliveryofdataand

alsoguaranteesthatpacketswillbedeliveredinthesameorderinwhichthey

weresent.

TCPstandsforTransmissionControlProtocol.ItisdescribedinSTD-7/RFC-793.

TCPisaconnection-orientedprotocolthatisresponsibleforreliable

communicationbetweentwoendprocesses.Theunitofdatatransferrediscalled

astream,whichissimplyasequenceofbytes.

Beingconnection-orientedmeansthatbeforeactuallytransmittingdata,youmust

opentheconnectionbetweenthetwoendpoints.Thedatacanbetransferredin

fullduplex(sendandreceiveonasingleconnection).Whenthetransferisdone,

youhavetoclosetheconnectiontofreesystemresources.Bothendsknowwhen

thesessionisopened(begin)andisclosed(end).Thedatatransfercannottake

placebeforebothendshaveagreedupontheconnection.Theconnectioncanbe

closedbyeitherside;theotherisnotified.Provisionismadetoclosegracefullyor

justaborttheconnection.

Beingstreamorientedmeansthatthedataisananonymoussequenceofbytes.

Thereisnothingtomakedataboundariesapparent.Thereceiverhasnomeansof

knowinghowthedatawasactuallytransmitted.Thesendercansendmanysmall

datachunksandthereceiverreceiveonlyonebigchunk,orthesendercansenda

bigchunk,thereceiverreceivingitinanumberofsmallerchunks.Theonlything

thatisguaranteedisthatalldatasentwillbereceivedwithoutanyerrorandin

thecorrectorder.Shouldanyerroroccur,itwillautomaticallybecorrected

(retransmittedasneeded)ortheerrorwillbenotifiedifitcan'tbecorrected.

Attheprogramlevel,theTCPstreamlooklikeaflatfile.Whenyouwrite

datatoaflatfile,andreaditbacklater,youareabsolutelyunableto

knowifthedatahasbeenwritteninonlyonechunkorinseveralchunks.

Unlessyouwritesomethingspecialtoidentifyrecordboundaries,thereis

nothingyoucandotolearnitafterward.Youcan,forexample,useCRor

CRLFtodelimityourrecordsjustlikeaflattextfile.

Attheprogramminglevel,TWSocketisfairlysimpletouse.Tosenddata,

youjustneedtocalltheSendmethod(oranyvariationsuchasSendStr)

togivethedatatobetransmitted.TWSocketwillputitinabufferuntilit

canbeactuallytransmitted.Eventuallythedatawillbesentinthe

background(theSendmethodreturnsimmediatelywithoutwaitingforthe

datatobetransmitted)andtheOnDataSenteventwillbegeneratedonce

thebufferisemptied.

Toreceivedata,aprogrammustwaituntilitreceivestheOnDataAvailable

event.Thiseventistriggeredeachtimeadatapacketcomesfromthe

lowerlevel.TheapplicationmustcalltheReceivemethodtoactuallyget

thedatafromthelow-levelbuffers.YouhavetoReceiveallthedata

availableoryourprogramwillgoinanendlessloopbecauseTWSocket

willtriggertheOnDataAvailableagainifyoudidn'tReceiveallthedata.

Asthedataisastreamofbytes,yourapplicationmustbepreparedto

receivedataassentfromthesender,fragmentedinseveralchunksor

mergedinbiggerchunks.Forexample,ifthesendersent"Hello"and

then"World!",itispossibletogetonlyoneOnDataAvailableeventand

receive"HelloWorld!"inonechunk,ortogettwoevents,onefor"Hello"

andtheotherfor"World!".Youcanevenreceivemoresmallerchunkslike

"Hei","Iowo"and"rid!".Whathappensdependsontrafficload,router

algorithms,randomerrorsandmanyotherparametersyoucan'tcontrol.

Onthesubjectofclient/serverapplications,mostapplicationsneedto

knowcommandboundariesbeforebeingabletoprocessdata.Asdata

boundariesarenotalwayspreserved,youcannotsupposeyourserverwill

receiveasinglecompletecommandinoneOnDataAvailableevent.You

canreceiveonlypartofarequestormaybetwoormorerequestmerged

inonechunk.Toovercomethisdifficulty,youmustusedelimiters.

MostTCP/IPprotocols,likeSMTP,POP3,FTPandothers,useCR/LFpair

ascommanddelimiter.EachclientrequestissentasiswithaCR/LFpair

appended.Theserverreceivesthedataasitarrives,assemblesitina

receivebuffer,scansforCR/LFpairstoextractcommandsfromthe

receivedstream,andremovesthemfromthereceivebuffer.

UDP

ShortforUserDatagramProtocol,aconnectionlessprotocolthat,like

TCP,runsontopofIPnetworks.UnlikeTCP/IP,UDP/IPprovidesvery

fewerrorrecoveryservices,offeringinsteadadirectwaytosendand

receivedatagramsoveranIPnetwork.It'susedprimarilyfor

broadcastingmessagesoveranetwork.

UDPstandsforUserDatagramProtocol.ItisdescribedinSTD-6/RFC-

768andprovidesaconnectionlesshost-to-hostcommunicationpath.

UDPhasminimaloverhead:;eachpacketonthenetworkiscomposedof

asmallheaderanduserdata.ItiscalledaUDPdatagram.

UDPpreservesdatagramboundariesbetweenthesenderandthe

receiver.Itmeansthatthereceiversocketwillreceivean

OnDataAvailableeventforeachdatagramsentandtheReceivemethod

willreturnacompletedatagramforeachcall.Ifthebufferistoosmall,

thedatagramwillbetruncated.Ifthebufferistoolarge,onlyone

datagramisreturned,theremainingbufferspaceisnottouched.

UDPisconnectionless.Itmeansthatadatagramcanbesentatany

momentwithoutprioradvertising,negotiationorpreparation.Justsend

thedatagramandhopethereceiverisabletohandleit.

UDPisanunreliableprotocol.Thereisabsolutelynoguaranteethatthe

datagramwillbedeliveredtothedestinationhost.Buttobehonest,the

failurerateisverylowontheInternetandnearlynullonaLANunlessthe

bandwidthisfull.

Notonlythedatagramcanbeundelivered,butitcanbedeliveredinan

incorrectorder.Itmeansyoucanreceiveapacketbeforeanotherone,

evenifthesecondhasbeensentbeforethefirstyoujustreceived.Youcan

alsoreceivethesamepackettwice.

Yourapplicationmustbepreparedtohandleallthosesituations:missing

datagram,duplicatedatagramordatagramintheincorrectorder.Youmust

programerrordetectionandcorrection.Forexample,ifyouneedto

transfersomefile,you'dbettersetupakindofzmodemprotocol.

ThemainadvantagesforUDParethatdatagramboundariesarerespected,

youcanbroadcast,anditisfast.

Themaindisadvantageisunreliabilityandthereforecomplicatedto

programattheapplicationlevel.

ADDRESSING

TCPandUDPusethesameaddressingscheme.AnIPaddress(32bits

number,alwayswrittenasfour8-bitnumberexpressedasunsigned3-digit

decimalnumbersseparatedbydotssuchas6)andaport

number(a16-bitnumberexpressedasaunsigneddecimalnumber).

TheIPaddressisusedbythelow-levelprotocol(IP)toroutethedatagram

tothecorrecthostonthespecifiednetwork.Thentheportnumberisused

toroutethedatagramtothecorrecthostprocess(aprogramonthehost).

Foragivenprotocol(TCPorUDP),asinglehostprocesscanexistatatime

toreceivedatasenttothegivenport.Usuallyoneportisdedicatedtoone

process.

tcpvs.udpforfiletransfer

ithinktcpisanoverusedprotocol;ithinkudpisanunderusedprotocol,

thisisanargumenti'vebeenhavingquiteabitwithpeoplelately,soi've

decidedi'lllayoutmyreasoningheresoidon'thavetotypeorreciteitat

peopleoverandover.

sinceifirstwrotethis(jan1998orso),tcpextensionsthatfixmanyofmy

complaints(selectiveacknowledgment,largewindows,tcpfortransactions)

haveseenmorewidespreadimplementation,whiletheyareastepinthe

rightdirection(well,t/tcpwasaterriblesecurityblunder...),tcpwillalways

beastreamprotocol,andthuswillneverbeanoptimaltransportforsome

advantagesoftcp

?theoperatingsystemdoesallthework,youjustsitbackandwatchthe

show.noneedtohavethesamebugsinyourcodethateveryoneelsedid

ontheirfirsttry;it'sallbeenfiguredoutforyou.

?sinceit'sintheos,handlingincomingpacketshasfewercontext

switchesfromkerneltouserspaceandback;allthereassembly,acking,

flowcontrol,etcisdonebythekernel.

?tcpguaranteesthreethings:thatyourdatagetsthere,thatitgetsthere

inorder,andthatitgetstherewithoutduplication.(thetruth,thewhole

truth,andnothingbutthetruth...)

?routersmaynoticetcppacketsandtreatthemspecially.theycanbuffer

andretransmitthem,andinlimitedcasespreackthem.

?tcphasgoodrelativethroughputonamodemoraIan.

disadvantagesoftcp

?theoperatingsystemmaybebuggy,andyoucan'tescapeit.itmaybe

inefficient,andyouhavetoputupwithit.itmaybeoptimizedfor

conditionsotherthantheonesyouarefacing,andyoumaynotbeableto

retuneit.

?tcpmakesitverydifficulttotryharder;youcansetafewsocket

options,butbeyondthatyouhavetotoleratethebuiltinflowcontrol.

?tcpmayhavelotsoffeaturesyoudon'tneed,itmaywastebandwidth,

time,oreffortonensuringthingsthatareirrelevanttothetaskathand.

?tcphasnoblockboundaries;youmustcreateyourown.

?routersontheinternettodayareoutofmemory,theycan'tpaymuch

attentiontotcpflyingby,andtrytohelpit.designassumptionsoftcp

breakdowninthisenvironment.

?tcphasrelativelypoorthroughputonalossy,highbandwidth,high

latencylink,suchasasatelliteconnectionoranoverfullt1.

?tcpcannotbeusedforbroadcastormulticasttransmission.

?tcpcannotconcludeatransmissionwithoutalldatainmotionbeing

explicitlyacked.

disadvantagesofudp

?therearenoguaranteeswithudp.apacketmaynotbedelivered,or

deliveredtwice,ordeliveredoutoforder;yougetnoindicationofthis

unlessthelisteningprogramattheotherenddecidestosaysomething,

tcpisreallyworkinginthesameenvironment;yougetroughlythesame

servicesfromipandudp.however,tcpmakesupforitfairlywell,andina

standardizedmanner.

?udphasnoflowcontrol.implementationisthedutyofuserprograms.

?routersarequitecarelesswithudp.theyneverretransmititifitcollides,

anditseemstobethefirstthingdroppedwhenarouterisshorton

memory,udpsuffersfromworsepacketlossthantcp.

advantagesofudp

?itdoesn'trestrictyoutoaconnectionbasedcommunicationmodel,so

startuplatencyindistributedapplicationsismuchlower,asisoperating

systemoverhead.

?allflowcontrol,acking,transactionlogging,etcisuptouserprograms;a

brokenosimplementationisnotgoingtogetinyourway.additionally,

youonlyneedtoimplementandusethefeaturesyouneed.

?therecipientofudppacketsgetsthemunmangled,includingblock

boundaries.

?broadcastandmulticasttransmissionareavailablewithudp.19

disadvantagesoftcpforfiletransfer

?startuplatencyissignificant,ittakesatleasttwicertttostartgetting

databack.

?tcpallowsawindowofatmost64k,andtheackingmechanismmeans

thatpacketlossismisdetected,tcpstallseasilyunderpacketloss,tcpis

morethrottledbyrttthanbandwidth.

?tcptransferservershavetomaintainaseparatesocket(andoften

separatethread)foreachclient.

?loadbalancingiscrudeandapproximate,especiallyonlocalnetworks

thatallowcollisions,twosimultaneoustcptransfershaveatendencyto

fightwitheachother,evenifthesenderisthesame.

advantagesofudpforfiletransfer

?latencycanbeaslowasrttiftheprotocolissuitablydesigned.

?flowcontrolisuptouserspace;windowscanbeinfinite,artificialstalls

nonexistant,latencywelltolerated,andmaximumspeedsenforcedonly

byrealnetworkbandwidth,yetactualspeedschosenbyagreementof

senderandreceiver.

?receivinganimagesimultaneouslyfrommultiplehostsismucheasier

withudp,asissendingonetomultiplehosts,especiallyiftheyhappento

bepartofthesamebroadcastormulticastgroup.

asinglesendinghostwithmultipletransfersproceedingcanbalance20

themwithexcellentprecision.

TheInternetrunsonahierarchicalprotocolstack.Asimplifiedversionof

thisisshowninfigure1.ThelayercommontoallInternetapplicationsis

theIP(InternetProtocol)layer.Thislayerprovidesaconnectionless,

unreliablepacketbaseddeliveryservice.Itcanbedescribedas

connectionlessbecausepacketsaretreatedindependentlyofallothers.

Theserviceisunreliablebecausethereisnoguaranteeofdelivery.

Packetsmaybesilentlydropped,duplicatedordelayedandmayarrive

outoforder.Theserviceisalsocalledabesteffortservice,allattemptsto

deliverapacketwillbemade,withunreliabilityonlycausedbyhardware

faultsorexhaustedresources.

AsthereisnosenseofaconnectionattheIPleveltherearenosimple

methodstoprovideaqualityofservice(QoS).QoSisarequestfroman

applicationtothenetworktoprovideaguaranteeonthequalityofa

connection.Thisallowsanapplicationtorequestafixedamountof

bandwidthfromthenetwork,andassumeitwillbeprovided,oncethe

QoSrequesthasbeenaccepted.Alsoafixeddelay,i.e.nojitterandin

orderdeliverycanbeassumed.AnetworkthatsupportsQoSwillbe

protectedfromcongestionproblems,asthenetworkwillrefuse

connectionsthatrequestlargerresourcesthancanbesupplied.An

exampleofanetworkthatsupportsQoSisthecurrenttelephonenetwork,

whereeverycallisguaranteedthebandwidthforthecall.Mostusersat

somepointhaveheardtheoverloadedsignalwherethenetworkcannot21

providetherequestedresourcerequiredtomakeacall.

Theapplicationdecideswhichtransportprotocolisused.Thetwo

protocolsshownhere,TCPandUDParethemostcommonlyusedones.

TCPprovidesareliableconnectionandisusedbythemajorityofcurrent

Internetapplications.TCP,besidesbeingresponsibleforerrorchecking

andcorrecting,isalsoresponsibleforcontrollingthespeedatwhichthis

dataissent.TCPiscapableofdetectingcongestioninthenetworkand

willbackofftransmissionspeedwhencongestionoccurs.Thesefeatures

protectthenetworkfromcongestioncollapse.

Asdiscussedintheintroduction,VolPisareal-timeservice.Forreal-time

propertiestobeguaranteedtobemet,anetworkwithQoSmustbeused

toprovidefixeddelayandbandwidth.IthasalreadybeensaidthatIP

cannotprovidethis.Thisthenpresentsachoice.IfIPisarequirement,

whichtransportlayershouldbeusedtoprovideasystemthatismost

likelytomeetreal-timeconstraints.

AsTCPprovidesfeaturessuchascongestioncontrol,itwouldbethe

preferredprotocoltouse.UnfortunatelyduetothefactthatTCPisa

reliableservice,delayswillbeintroducedwheneverabiterrororpacket

lossoccurs.Thisdelayiscausedbyretransmissionofthebrokenpacket,

alongwithanysuccessivepacketsthatmayhavealreadybeensent.This

canbealargesourceofjitter.22

TCPusesacombinationoffouralgorithmstoprovidecongestioncontrol,

slowstart,congestionavoidance,fastretransmitandfastrecovery.These

algorithmsallusepacketlossasanindicationofcongestion,andallalter

thenumberofpacketsTCPwillsendbeforewaitingforacknowledgments

ofthosepackets.Thesealterationsaffectthebandwidthavailableandalso

changedelaysseenonalink,providinganothersourceofjitter.

ApplicationWWWFTPE-mailNFSVoIPDNS

TuaiuportTCPUDP

NetuaockIP

Plwskal

4TEthernetAAL-5HDLC

SimplifiedIPprotocolstack

23

Combined,TCPraisesjittertoanunacceptablelevelrenderingTCP

unusableforreal-timeservices.Voicecommunicationhastheadvantage

ofnotrequiringacompletelyreliabletransportlevel.Thelossofapacket

orbiterrorwilloftenonlyintroduceaclickoraminorbreakintothe

output.

ForthesereasonsmostVoIPapplicationsuseUDPforthevoicedata

transmission.UDPisathinlayerontopofIPthatprovidesawayto

distinguishamongmultipleprogramsrunningonasinglemachine.UDP

alsoinheritsallofthepropertiesofIPthatTCPattemptstohide.UDPis

thereforealsoapacketbased,connectionless,best-effortservice.Itisup

totheapplicationtosplitdataintopackets,andprovideanynecessary

errorcheckingthatisrequired.

Becauseofthis,UDPallowsthefastestandmostsimplewayof

transmittingdatatothereceiver.Thereisnointerferenceinthestream

ofdatathatcanbepossiblyavoided.Thisprovidesthewayforan

applicationtogetasclosetomeetingreal-timeconstraintsaspossible.

UDPhoweverprovidesnocongestioncontrolsystems.Acongestedlink

thatisonlyrunningTCPwillbeapproximatelyfairtoallusers.WhenUDP

dataisintroducedintothislink,thereisnorequirementfortheUDPdata

ratestobackoff,forcingtheremainingTCPconnectionstobackoffeven

further.ThiscanbethoughofasUDPdatanotbeinga“goodcitizen”.

Theaimofthisprojectistocharacterisethequantityofthisdropoffin24

TCPperformance.

TCPUDP

?Connection-Oriented?Connectionless

?Reliabilityindeliveryof?Noattempttofragment

messagesmessages

?Splittingmessagesinto?Noreassemblyand

datagramsynchronization

?Keeptrackoforder(or?Incaseoferror,messageis

sequence)retransmitted

?Noacknowledgment

?Usechecksumsfordetecting

errors

?Reliabilityisamust?Serverandclientmessagesfit

completelywithinapacket

?MessagesexceedUDPpacket?Theserverhandlesmultiple

sizeclients(UDPisstateless)

P664

ApplicationprogramApplicationprogram

(Process)(Process)

DomainofTCPprotocol

26

P664

Socket:(hostIP,port)

TELNETTELNET

(Client)(Server)

27

P665

ConnectionOrientedTransportProtocolMechanisms

?ConnectionOrientedMechanisms

-Logicalconnection

—Establishment

—Maintenance

—Termination

-Reliable

-e.g.TCP

?Datalink:X.25,LAPF,LLCofaLAN

-Addressing

-Multiplexing

-Flowcontrol

-Connectionestablishment/termination

?ReliableSequencingNetworkService

使用端口號標識FTP連接和Web連接

0007E942AC280007E963CE53192.168.1,5192.168.1,7130521UserdataCRC

MACDAMACSAIPSAIPDAS-PortD-Port

FTPConnection

FTP

FTPServerPort:21FTPClientPort:1305

S

D

WebServerPort:80£5WebClientPort:1089

DestinationSource

0007E942AC28WEB0007E963CE53

WEBConnection

0007E942AC280007E963CE53192.168.1,5192.168.1,7108980UserdataCRC

MACDAMACSAIPSAIPDAS-PortD-Port

29

P665

ReliableSequencingNetworkService

?Assumearbitrarylengthmessage

?Assumevirtually100%reliabledeliveryby

networkservice

一e.g.reliablepacketswitchednetworkusingX.25

—e.g.framerelayusingLAPFcontrolprotocol

—e.g.IEEE802.3usingconnectionorientedLLC

service

?Transportserviceisendtoendprotocolbetween

twosystemsonsamenetwork

30

85

61

P3

s)

thit

gb

nt-

lereer16

loizt

apsinf

otnoo

tiowpnle

Ptdotp

Cnannoti

Ttiigel

stsrWriu

esbieeUtm

sr-Dba

ed6m

rd1erupta

dabna

adPt

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論