Summary
Characteristicsofdatagramworkingmode:
1.Differentpacketsofthesamemessagecanbetransmittedthroughdifferenttransmissionpathsthroughthecommunicationsubnet;
2.Whendifferentpacketsofthesamemessagearriveatthedestinationnode,theremaybedisorder,duplicationandloss;
3.Eachpacketmusthaveadestinationaddressandadestinationaddressduringtransmission.Sourceaddress;
4.Thedatagrammodehasalargemessagetransmissiondelay,whichissuitableforburstcommunication,notsuitableforlongmessageandconversationalcommunication.
IPDatagram
TheTCP/IPprotocoldefinesapackettransmittedontheInternet,calledIPDatagram.Thisisavirtualpackagethathasnothingtodowithhardware,whichiscomposedoftwoparts:headeranddata.Thefirstpartoftheheaderisafixedlength,atotalof20bytes,whichismandatoryforallIPdatagrams.Behindthefixedpartoftheheaderaresomeoptionalfields,thelengthofwhichisvariable.ThesourceaddressanddestinationaddressintheheaderarebothIPprotocoladdresses.
ThefieldsinthefixedpartoftheIPdatagramheader
(1)Version:occupies4bitsandreferstotheversionoftheIPprotocol.TheversionoftheIPprotocolusedbybothpartiesmustbethesame.ThewidelyusedIPprotocolversionnumberis4(thatis,IPv4).
(2)Headerlength:occupies4digits,andthelargestdecimalvaluethatcanberepresentedis15.Pleasenotethattheunitofthenumberrepresentedbythisfieldis32-bitwords(a32-bitwordlengthis4bytes).Therefore,whentheIPheaderlengthis1111(ie15indecimal),theheaderlengthreaches60wordsFestival.WhenthelengthoftheheaderoftheIPpacketisnotanintegermultipleof4bytes,thelastpaddingfieldmustbeusedtofillit.Therefore,thedatapartalwaysstartsatanintegermultipleof4bytes,whichismoreconvenientwhenimplementingtheIPprotocol.Thedisadvantageoftheheaderlengthbeinglimitedto60bytesisthatitmaynotbeenoughsometimes.Butthisisdoneinthehopethatuserswillminimizeoverhead.Themostcommonlyusedheaderlengthis20bytes(thatis,theheaderlengthis0101),andnooptionsareusedatthistime.
(3)Differentiatedservices:8positionsareusedtoobtainbetterservices.Thisfieldwascalledtheservicetypeintheoldstandard,butithasnotactuallybeenused.In1998,theIETFrenamedthisfieldasDifferentiatedServices(DS).Thisfieldonlyworkswhenusingdifferentiatedservices.
(4)Totallength:Thetotallengthreferstothelengthofthesumoftheheaderandthedata,inbytes.Thetotallengthfieldis16bits,sothemaximumlengthofthedatagramis216-1=65535bytes.
EachdatalinklayerbelowtheIPlayerhasitsownframeformat,includingthemaximumlengthofthedatafieldintheframeformat,whichiscalledtheMaximumTransferUnit(MTU).Whenadatagramisencapsulatedintoalinklayerframe,thetotallengthofthedatagram(thatis,theheaderplusthedatapart)mustnotexceedtheMTUvalueofthedatalinklayerbelow.
(5)Identification(identification):occupies16digits.TheIPsoftwaremaintainsacounterinthememory.Eachtimeadatagramisgenerated,thecounterisincrementedby1,andthisvalueisassignedtotheidentificationfield.Butthis"identification"isnotasequencenumber,becauseIPisaconnectionlessservice,andthereisnoproblemofsequentialreceptionofdatagrams.WhenadatagrammustbefragmentedbecauseitslengthexceedstheMTUofthenetwork,thevalueofthisidentificationfieldiscopiedtotheidentificationfieldofalldatagrams.Thevalueofthesameidentificationfieldenableseachdatagramafterfragmentationtobefinallyreassembledintotheoriginaldatagramcorrectly.
(6)Flag:occupies3bits,butonly2bitsaremeaningful.
①ThelowestbitintheflagfieldismarkedasMF(MoreFragment).MF=1meansthatthereare"fragmented"datagramsbehind.MF=0meansthisisthelastofseveraldatagramfragments.
②TheonebitinthemiddleoftheflagfieldismarkedasDF(Don’tFragment),whichmeans"cannotbefragmented".FragmentationisallowedonlywhenDF=0.
(7)Chipoffset:13bits.Thesliceoffsetindicatestherelativepositionofasliceintheoriginalgroupafterthelongergroupissliced.Thatis,relativetothebeginningoftheuserdatafield,wheredoesthepiecestart.Thechipoffsetuses8bytesastheoffsetunit.Thismeansthatthelengthofeachfragmentmustbeanintegermultipleof8bytes(64bits).
(8)Timetolive:occupies8bits.ThecommonlyusedEnglishabbreviationforthetimetolivefieldisTTL(TimeToLive),whichindicatesthelifeofthedatagraminthenetwork.Thisfieldissetbythesourceofthedatagram.ItspurposeistopreventundeliverabledatagramsfromgoingaroundtheInternetindefinitely,thusconsumingnetworkresourcesinvain.TheoriginaldesignusessecondsastheunitofTTL.Everytimeitpassesthrougharouter,theTTLissubtractedfromtheperiodoftimethedatagramisconsumedbytherouter.Ifthetimeconsumedbythedatagramontherouterislessthan1second,theTTLvalueisreducedby1.WhentheTTLvalueis0,thedatagramisdiscarded.
(9)Protocol:Itoccupies8bits,andtheprotocolfieldindicateswhichprotocolisusedforthedatacarriedinthisdatagram,sothattheIPlayerofthedestinationhostknowswhichprocessingprocedureshouldbehandedoverthedatapart.
(10)Firstchecksum:16digits.Thisfieldonlycheckstheheaderofthedatagram,butdoesnotincludethedatapart.Thisisbecauseeverytimeadatagrampassesthrougharouter,theroutermustrecalculatetheheaderchecksum(somefields,suchastimetolive,flags,sliceoffset,etc.,maychange).Notcheckingthedatapartcanreducetheworkloadofcalculation.
(11)Sourceaddress:32bits.
(12)Destinationaddress:32bits.
ThevariablepartoftheIPdatagramheader
ThevariablepartoftheIPheaderisanoptionalfield.Theoptionfieldisusedtosupporttroubleshooting,measurement,andsecuritymeasures,andthecontentisveryrich.Thelengthofthisfieldisvariable,rangingfrom1byteto40bytes,dependingontheselecteditem.Someoptionitemsonlyrequire1byte,anditonlyincludes1byteofoptioncode.Buttherearesomeoptionsthatrequiremultiplebytes.Theseoptionsaresplicedonebyonewithoutaseparatorinthemiddle.Finally,apaddingfieldofall0sisusedtofillinanintegermultipleof4bytes.
AddingthevariablepartoftheheaderistoincreasethefunctionoftheIPdatagram,butitalsomakesthelengthoftheheaderoftheIPdatagramvariable.Thisincreasestheoverheadforeachroutertoprocessdatagrams.Infact,theseoptionsarerarelyused.ThenewIPversionIPv6makestheheaderlengthoftheIPdatagramfixed.
Theseoptionsaredefinedasfollows:
(1)Securityandprocessingrestrictions(usedinthemilitaryfield)
(2)Recordthepath(leteachrouterWritedownitsIPaddress)
(3)Timestamp(leteachrouterwritedownitsIPaddressandtime)
(4)Loosesourcesiterouting(SpecifyaseriesofIPaddressesthatmustbepassedthroughforthedatagram)
(5)Strictsourcesiterouting(similartoloosesourcesiterouting,butitisrequiredtoonlypassthroughthesespecifiedaddresses,nototherAddress)
Theseoptionsarerarelyused,andnotallhostsandrouterssupporttheseoptions.