Tải bản đầy đủ - 0 (trang)
Chapter 5. Rules of the Road: How to Use the Local (Network) Roadway

Chapter 5. Rules of the Road: How to Use the Local (Network) Roadway

Tải bản đầy đủ - 0trang

PreparingforaTrip:HowtoMakeYourCar

(Data)"StreetLegal"

BeforeyoucandriveacarontoaDOT-built,government-owned

road,youneedtohavearegisteredstreet-legalcar.Streetlegal

simplymeansthatthecarmeetsthegovernment'sstandards

forwhatkindsofcarsareallowedontheroad.Forinstance,

youcan'tuseacarthatgoes230milesperhourarounda

racetrackonpublicroads.Likewise,youcan'tdrivearoundina

truckwitha40-foottalltrailerbehinditbecauseyouwould

almostcertainlyhitroadsigns,powerlines,andbridgesasyou

triedtopassunderthem.

Similarly,LANsrequirethatthedatasentacrossthewiresina

LANconformtosomerulesaswell,whichyoucanthinkofas

makingthedatastreetlegal,orLANlegal.Likemostrulesin

thenetworkingworld,oneormorestandardsdefinetherules.

Thisbookwillfocusontheworld'smostpopularLAN

standardEthernet.

EthernetconsistsofasetofstandardsandprotocolsforLAN

communication,asdefinedbytheIEEE.Forinstance,Ethernet

standardsdefinehowanetworkinterfacecard(NIC)should

encodebinary0sand1sonawirebyvaryingthevoltage,as

discussedinChapter4,"HowtoBuildaLocal(Network)

Roadway."Ethernetstandardsspecifymanymoredetailsas

well,someofwhichyou'llseeinthischapter.



LAN-LegalData:AnEthernetFrame

BeforeaNICcansenddataoveraLAN,allthedetailscovered

inChapter4mustbecomplete.TheLANmusthavetheproper

cablinginstalled.TheNICsmustknowtheelectricalencoding

schemeusedtosignala0ora1.Atthatpoint,thecomputer



couldasktheNICtosenddata,andelectrically,thebitscould

besentovertheLAN.

However,computerscan'tsimplysendenduserdataoverthe

LAN.BeforeaPCcansendtheenduserdataoveraLAN,thePC

mustencapsulatetheenduserdatainsideanEthernetframe.

Encapsulationreferstotheprocessoftakingthedataand

puttingitinsidetheEthernetheaderandtrailer.

Encapsulationissimilarinconcepttoputtingaletterinan

envelopebeforesendingtheletterthroughthepostalservice.

Thepostalservicerequiresthatlettersmeetcertain

requirements,andtheenvelopemusthaveaproperlyformatted

address.Thepostalserviceevendefineswhataproperly

formattedaddresslookslike.Similarly,Ethernetstandards

definetheheadersandtrailerssothataNICcancorrectly

encapsulatethedata.

Theresultingbunchofbitscreatedbytheencapsulation

process,includingtheEthernetheaderandtrailer,iscalledan

Ethernetframe.Figure5-1showsanEthernetframe,created

byencapsulatingthedatainaheaderandtrailer,forframes

senttoLarryfromBob.



Figure5-1.EthernetFrameSentfromBobto

Larry



Thelawscreatedbygovernmenttypicallydonotallowyouto

rideyourbicycleonasuperhighway.Likewise,Ethernetdoes

notallowyoutosendtheenduserdataovertheLAN.Youmust

putthedatainthepropervehiclenamely,anEthernetframe.

Afteryouputthedataintoaframe,youcansenditacrossthe

LAN.

TheEthernetheaderandtraileraresimplyadditionalbytesof

datathatareusedbythecomputers,NICs,andnetworking

devicestomaketheEthernetworksmoothly.Forinstance,the

first8bytesinanEthernetheaderarecalledthepreamble.

Thepreamblecontainsalternating1sand0ssothattheNICs

receivingthedataknowthatanewframeisbeingsentacross

theLAN.

Thewordframehappenstobeaparticularlyimportantterm.

BackinChapter3,"BuildingaNetwork:ItAllStartswitha

Plan,"youreadaboutnetworkingstandardsandhowtheterms

fromtheOSImodeldescribenetworkingstandardsand

protocolstoday.Theterm"frame"referstotheheadersand

trailersdefinedbyanyLayer2standard,aswellasthedata

insidetheframe.Theterm"Ethernetframe"referstoaframe

createdforuseonanEthernet,conformingtoEthernetprotocol

specifications.

Asyouwillreadinlaterchapters,protocolsthatmatchother

OSIlayersalsohaveheaders,andthenetworkingworlduses

namesbesides"frame"torefertothoseheadersanddata.

Throughoutthischapter,Iwillcovermoredetailsaboutwhatis

insidetheEthernetframeheaderandtrailer.Tomoveforward,

justthinkofanEthernetframeasthecarthatcanactuallybe

sentovertheLAN,withtheenduserdatabeingtheequivalent

ofwhomeverorwhateverisinthecar.



DrivingWhereIWantandWhenIWantIsPretty



Cool

Inreallife,it'sobviouswhyyoucan'tjustdriveanywhereyou

want,anytimeyouwantyou'llhaveawreck.Orworseyet,

someoneelse'sblatantdisregardforthelawmightcauseyouto

beinawreck!

Interesting,whenyouuseEthernethubs,evenifyouobeythe

rules,wrecks(calledcollisionsinEthernetlingo)occur.A

collisionoccurswhentwoormoreframesaresentovera

singletwistedpairatthesamepointintime.Theresultisthat

noneoftheframesisintelligible.However,it'sbettertoavoid

thecollisionsifpossible.So,Ethernetdefinessomerulesofthe

roadrulesthatsaywhenyoucanusetheLANandwhenyou

can'tandwhattodoifyouhaveawreck.



WhyWrecks(Collisions)HappenonEthernet

Evenifyouobeyallthelawsoftheland,youcanstillhavea

wreck.Likewise,evenwhenalldevicesfollowEthernetrules,

wrecksorcollisionscanhappen.Tounderstandwhy,focuson

thesetwokeyfacts:

Whentwoormoreelectricalsignalstraveloverthesame

pair,bothelectricalsignalsaredistortedandbecomea

singlesignal.Thereceivingdevicecannotinterpretthe

signalas0sand1s.

Ahubrepeatsreceivedelectricalsignalsoutallother

physicalportsonthehub,excepttheoneinwhichthe

signalwasreceived,evenifotherelectricalsignalsare

alreadybeingrepeated.

Knowingthosetwofacts,considerwhathappensinFigure5-2,



whenbothBobandArchiesendanEthernetframetoLarryat

thesametime.



Figure5-2.CollisionBetweenBob'sandArchie's

Frames



ThehubblindlyrepeatseachoftheframessentbyBoband

Archieoutallotherports,includingtheoneconnectedtoLarry.

AlthoughbothBobandArchiewantedtosenddatatoLarry,

Larrycan'tunderstandeitherframebecausethehubistryingto

sendbothelectricalsignalsoverthecabletoLarryatthesame

time.



HowtoAvoidMostWrecks

Ethernetstandardsdefineabasicalgorithmthathelpsreduce

collisions,aswellasdefiningwhattodowhencollisionsoccur.

Thealgorithmiscalledthecarriersensemultipleaccess

collisiondetect(CSMA/CD)algorithm.Boy,there'safun

triviaquestionforyournextparty,huh?

ThenameCSMA/CDisnotasimportantastheideasbehindit.

First,thealgorithmstartswiththissimpleconcept:

Listenbeforesending,andwaituntilyouarenotreceiving

aframebeforeyoutrytosendyourframe.



Theconceptisprettysimple.Imaginethatyouareconnectedto

ahub,andyouarecurrentlyreceivingaframe.Whatwould

happenifyousentaframeatthattime?Well,youwouldcause

acollision.Sowhynotjustwaitamoment?Well,that'sexactly

whatthealgorithmcallsfor.Figure5-3showsthebasiclogic,

withBobwaitingonLarrytofinishsendinghisframebefore

sendinghisownframe.



Figure5-3.CollisionAvoidancebyListening

BeforeSending



WhattoDoWhenaWreckHappens

Evenwhenyou'reusingCSMA/CD,collisionscanstilloccur.

Why?Well,considerthissameexample,butunbeknownstto

Bob,ArchiewasalsowaitingforLarrytofinishsendinghis

framebeforesendingaframe.So,Larry'sframehasfinished,

andtheLANissilent.Figure5-4showsbothBob'sandArchie's

logic.



Figure5-4.AnImminentandUnavoidable



Collision



Ethernetstandardsstatethatwhennooneissendinganything,

theLANissilentinotherwords,thereisnoelectricityflowing

overthewires.BothBobandArchierealizethatLarryis

finishedwhentheystopreceivinganelectricalsignal.So,they

bothtrytosendtheirframesatroughlythesametime,because

theybothrealizeatroughlythesametimethattheLANis

silent.AndaswasshowninFigure5-2,whenBobandArchie

bothsendatthesametime,acollisionoccurs.

ThehubwillrepeatbothframesouttoLarry,soLarrywillknow

aboutthecollision.However,thehubwon'tforwardBob'sframe

backtoBoborArchie'sframebacktoArchie,sobothBoband

Archiewillonlybereceivingoneframe.Withthelogicdiscussed

sofar,BobandArchiewon'tknowthere'sacollision!Tomake

sureBobandArchieknowwhenacollisionhappens,whena

NICtransmitsaframe,theNICalsoconnectswhatitsendsto

itsownreceivepair,rightonthecard.Thisbitofhardwareis

calledaloopbackcircuit,anditsimplymeansthattheNIC

receivesitsownframeaswell.

Byusingloopback,whenBobsendsaframe,hereceivesthe

sameelectricalsignalthathesends.WhenArchiesendsa

frameatthesametime,thehubforwardsArchie'sframeto



BobandnowBobknowsthereisacollision.

So,whatdoyoudowhenthecollisionoccurs?CSMA/CD

suggeststhefollowing:

Thesendersofthecollidedframessendajammingsignalto

makesureeveryoneknowsacollisionhasoccurred.

Thesendersofthecollidedframesindependentlypicka

randomtimervalue.

Eachsenderwaitsuntilhisownrandomtimerhasexpired

andthentriestosendhisframesagain.

ThejammingsignalisanelectricalsignalthatEthernet

standardsspecifytoleteveryoneknow"Hey,acollisionhas

occurred,solet'scleanitup."Next,byhavingbothBoband

Archiewaitbeforetryingtosendagain,butwitheachofthem

choosinghisownrandomnumberforthetimer,BobandArchie

shouldnottrytosendagainatthesametime.

Sofarinthischapter,youhavelearnedthatcomputerssend

EthernetframeswhichincludetheEthernetheader,trailer,and

enduserdataoveranEthernetLAN.Youhavealsolearnedhow

CSMA/CDregulateswhentheLANisused,muchliketrafficlaws

dictatewhenaroadisused.So,enoughofthisdiscussionof

howtogetdataacrosstheLAN.Now,let'sthinkaboutwhat

happenswhentheframeactuallygetstothedestination.



StoppingattheDestination:WhatHappens

WhenSomeoneComestoSeeYou

WhenusinganEthernetwithahub,everyonegetsacopyof

everyframethat'sjustasideeffectofthefactthatthehub

repeatsincomingframesoutallotherportsonthehub.You

mightrecallthatahubdoesthistoalloweachcomputer'sNIC

tohaveasinglecableconnectingittothehub,whilestillbeing

abletocommunicatewithallotherdevicesontheLAN.

Inthesecondhalfofthischapter,I'llexplainEthernetfromthe

perspectiveofthecomputerreceivingtheframe,andalongthe

way,I'lltalkalittlemoreaboutwhat'sinsidetheheaderand

trailerofanEthernetframe.



AreTheyComingtoOurHouseorthe

Neighbor'sHouse?

InanEthernetLANwithahub,acomputerreceivesalotof

Ethernetframes,butonlysomeofthemcontaindatathatis

meantforthatcomputer.Forinstance,Larrymightneedto

senddatatoBob,butbecauseofthehub'sbehavior,both

ArchieandBobgetacopyoftheframe.

Now,considerthecasewhenLarrywantstosenddatatoBob.

BothBobandArchiereceivetheframe,butArchieshould

simplyignoretheframe,andBobshouldexaminethedataand

processit.ButhowdoArchieandBobknow?Well,beforeLarry

sendstheframe,heputsBob'sEthernetaddressintoafield

intheEthernetheadercalledthedestinationaddressfield.

ByputtingBob'sEthernetaddressinthedestinationaddress

fieldoftheheader,BobcanusethelogicshowninFigure5-5.



Figure5-5.HowBobDecidestheFrameWasSent

toHim



[Viewfullsizeimage]



Thelogicissimple.EachNIChasauniqueEthernetaddress,

whichisputontotheNICbytheNICmanufacturer.Thesender

justputsthecorrectEthernetaddressintheheader,sowhen

anotherNICreceivestheframe,itcandecidewhetherto

processtheframeorignoreit.

TheEthernetheaderincludesbothasourceaddressfieldand

adestinationaddressfield.Forinstance,Larryincludedhisown

Ethernetaddressinthesourceaddressfieldoftheframein

Figure5-5.Ofcourse,LarryputBob'sEthernetaddressintothe

destinationaddressfield.

Ethernetstandardsspecifythataddressesbe48bitslong(6

bytes).YoucanwritedownEthernetaddressesasbinary

numbers,butwritingdown48binary0sand1scanbeapainin

theneck.ThecreatorsofEthernetcouldhavedecidedtorecord

Ethernetaddressesasdecimalnumbers,butasitturnsout,

convertingbetweendecimalandbinaryisn'tthateasytodo.



However,there'sabetterwaytorepresentbinarynumbersby

usingfewerdigits:hexadecimal(hex).Hexisanalternative

numberingsystem,similartodecimalandbinary.Withdecimal,

youhave10numerals(0,1,2,andsoon,through9).With

hexadecimal,thenumeralsare0,1,2,3,4,5,6,7,8,9,A,B,

C,D,E,F.Essentially,Arepresentsdecimal10,Brepresents

decimal11,andsoon,withFrepresentingdecimal15.

Hexcanbeusedeasilytorepresentbinarynumbers.Infact,a

singlehexdigitcanrepresentfourbinarydigits.Forinstance,

Table5-1showseachcombinationofa4-digitbinarynumber

anditshexequivalent.

Table5-1.BinaryNumbersandTheirHexEquivalents

Four-DigitBinary

Number



HexNumber



0000



0



0001



1



0010



2



0011



3



0100



4



0101



5



0110



6



0111



7



1000



8



1001



9



1010



A



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Chapter 5. Rules of the Road: How to Use the Local (Network) Roadway

Tải bản đầy đủ ngay(0 tr)

×