operating systems and networks network lecture 4: link layer … · 2018-01-27 · possible...
TRANSCRIPT
OperatingSystemsandNetworks
NetworkLecture4:LinkLayer(2)
AdrianPerrigNetworkSecurityGroupETHZürich
2
PendingIssues• Howtoreadthecoursetextbook?• Howtopreparefortheexamgiventhatthereisahugeamountofmaterial?
3
WhereweareintheCourse• FinishingofftheLinkLayer!
– Buildsonthephysicallayertotransfer framesoverconnectedlinks
PhysicalLink
NetworkTransportApplication
4
Topics1. Framing
– Delimitingstart/endofframes
2. Errordetection/correction– Handlingerrors
Done
DSL
5
Topics(2)3. Retransmissions
– Handlingloss
4. MultipleAccess– ClassicEthernet,802.11
5. Switching– ModernEthernet
6
Retransmissions(ARQ)(§3.3)• Twostrategiestohandleerrors:1. Detecterrorsandretransmitframe(AutomaticRepeatreQuest,
ARQ)
2. Correcterrorswithanerrorcorrectingcode
Donethis
7
ContextonReliability• Whereinthestackshouldweplacereliabilityfunctions?
PhysicalLink
NetworkTransportApplication
8
ContextonReliability(2)• Everywhere!Itisakeyissue
– Different layerscontributedifferently
PhysicalLink
NetworkTransportApplication
Recoveractions(correctness)
Maskerrors(performanceoptimization)
9
ARQ(AutomaticRepeatreQuest)• ARQoftenusedwhenerrorsarecommonormustbecorrected– E.g.,WiFi,andTCP(later)
• Rulesatsenderandreceiver:– Receiverautomaticallyacknowledges correct frameswithanACK
– Senderautomaticallyresendsafteratimeout,untilanACKisreceived
10
ARQ(2)• Normaloperation(noloss,noerror)
Frame
ACKTimeout Time
Sender Receiver
11
ARQ(3)• Lossandretransmission
Frame
Timeout Time
Sender Receiver
Frame
ACK
X
12
SoWhat’sTrickyAboutARQ?• Twonon-trivialissues:
– Howlongtosetthetimeout?– Howtoavoidacceptingduplicate framesasnewframes
• Wantperformanceinthecommoncaseandcorrectnessalways
13
Timeouts• Timeoutshouldbe:
– Nottoobig(linkgoesidle)– Nottoosmall(spuriousresend)
• FairlyeasyonaLAN– Clearworstcase,littlevariation
• FairlydifficultovertheInternet– Muchvariation,noobviousbound– We’llrevisitthiswithTCP(later)
14
Duplicates• WhathappensifanACKislost?
Frame
ACK
X
Frame
ACKTimeout
Sender Receiver
NewFrame??
15
Duplicates(2)• Orthetimeoutisearly?
Frame
ACK
Frame
ACK
Timeout
Sender Receiver
NewFrame??
16
SequenceNumbers• FramesandACKsmustbothcarrysequencenumbersforcorrectness
• Todistinguishthecurrentframefromthenextone,asinglebit(twonumbers)issufficient– CalledStop-and-Wait
17
Stop-and-Wait• Inthenormalcase:
Time
Sender Receiver
18
Stop-and-Wait(2)• Inthenormalcase:
Frame0
ACK0Timeout Time
Sender Receiver
Frame1
ACK1
19
Stop-and-Wait(3)• WithACKloss:
Frame0
ACK0
X
Frame0
ACK0Timeout
Sender Receiver
It’saResend!
20
Stop-and-Wait(4)• Withearlytimeout:
Frame0
ACK0
Frame0
ACK0
Timeout
Sender Receiver
It’saResend
OK…
21
LimitationofStop-and-Wait• Itallowsonlyasingleframetobeoutstandingfromthesender:– GoodforLAN,inefficient forhighBD(bandwidth-delay product)
• Ex:R=1Mbps,D=50ms– Howmanyframes/sec? IfR=10Mbps?
22
SlidingWindow• Generalizationofstop-and-wait
– AllowsWframestobeoutstanding– CansendWframesperRTT (=2D)
– Variousoptionsfornumbering frames/ACKsandhandlingloss• WilllookatalongwithTCP(later)
Multiplexing(§2.5.3,2.5.4)• Multiplexingisthenetworkwordforthesharingofaresource
• Classicscenarioissharingalinkamongdifferentusers– TimeDivisionMultiplexing(TDM)– FrequencyDivisionMultiplexing(FDM)
23
TimeDivisionMultiplexing(TDM)
• Userstaketurnsonafixedschedule
24
2 2 2 2
FrequencyDivisionMultiplexing (FDM)• Putdifferentusersondifferentfrequencybands
25
Overall FDMchannel
26
TDMversusFDM• InTDMausersendsatahighrateafractionofthetime;inFDM,ausersendsatalowrateallthetime
Rate
TimeFDM
TDM
27
TDM/FDMUsage• Staticallydividearesource
– Suitedforcontinuous traffic,fixednumberofusers
• Widelyusedintelecommunications– TVandradiostations(FDM)– GSM(2Gcellular)allocatescallsusingTDMwithinFDM
28
MultiplexingNetworkTraffic• Networktrafficisbursty
– ON/OFF sources– Loadvariesgreatlyovertime
Rate
TimeRate
Time
29
MultiplexingNetworkTraffic(2)• Networktrafficisbursty
– Inefficient toalwaysallocateusertheirON needswithTDM/FDM
Rate
TimeRate
Time
R
R
MultiplexingNetworkTraffic(3)• Multipleaccessschemesmultiplexusersaccordingtotheirdemands– forgainsofstatisticalmultiplexing
30
Rate
TimeRate
Time
Rate
Time
R
R
R’<2R
Twousers,eachneedR TogethertheyneedR’<2R
31
MultipleAccess• Wewilllookattwokindsofmultipleaccessprotocols1. Randomized.Nodesrandomize their resourceaccessattempts
– Goodforlowloadsituations
2. Contention-free. Nodesordertheirresourceaccessattempts– Goodforhighloadorguaranteedqualityofservicesituations
32
RandomizedMultipleAccess(§4.2.1-4.2.2,4.3.1-4.3.3)
• Howdonodesshareasinglelink?Whosendswhen,e.g.,inWiFI?– Explorewithasimplemodel
• Assumeno-oneisincharge;thisisadistributedsystem
33
RandomizedMultipleAccess(2)• Wewillexplorerandommultipleaccesscontrol ormediumaccesscontrol (MAC)protocols– ThisisthebasisforclassicEthernet– Remember:datatraffic isbursty
Zzzz..Busy! Hohum
34
ALOHANetwork• SeminalcomputernetworkconnectingtheHawaiianislandsinthelate1960s– Whenshouldnodessend?– A newprotocolwasdevisedbyNormAbramson…
Hawaii
35
ALOHAProtocol• Simpleidea:
– Nodejustsendswhenithastraffic.– Iftherewasacollision(noACKreceived) thenwaitarandomtimeandresend
• That’sit!
36
ALOHAProtocol(2)• Someframeswillbelost,butmanymaygetthrough…
• Goodidea?
37
ALOHAProtocol(3)• Simple,decentralizedprotocolthatworkswellunderlowload!
• Notefficientunderhighload– Analysisshowsatmost18%efficiency– Improvement:divide timeintoslotsandefficiency goesupto36%
• We’lllookatotherimprovements
38
ClassicEthernet• ALOHAinspiredBobMetcalfetoinventEthernetforLANsin1973– Nodesshare10Mbpscoaxialcable– Hugelypopular in1980s,1990s
:©2009IEEE
39
CSMA(CarrierSenseMultipleAccess)
• ImproveALOHAbylisteningforactivitybeforewesend(Doh!)– Candoeasilywithwires,notwireless
• Sodoesthiseliminatecollisions?– Whyorwhynot?
40
CSMA(2)• Stillpossibletolistenandhearnothingwhenanothernodeissendingbecauseofdelay
41
CSMA/CD(withCollisionDetection)• Canreducethecostofcollisionsbydetectingthemandaborting(Jam)therestoftheframetime– Again,wecandothiswithwires
XX X X X X X XJam! Jam!
42
CSMA/CDComplications• Wanteveryonewhocollidestoknowthatithappened
– Timewindow inwhichanodemayhearofacollisionis2Dseconds
X
43
CSMA/CDComplications(2)• Imposeaminimumframesizethatlastsfor2D seconds
– Sonodecan’tfinishbeforecollision– Ethernetminimumframeis64bytes
X
44
CSMA“Persistence”• Whatshouldanodedoifanothernodeissending?
• Idea:Waituntilitisdone,andsend
Whatnow?
45
CSMA“Persistence”(2)• Problemisthatmultiplewaitingnodeswillqueueupthencollide– Moreload,moreofaproblem
Now! Now!Uhoh
46
CSMA“Persistence”(3)• Intuitionforabettersolution
– IfthereareNqueuedsenders,wewanteachtosendnextwithprobability1/N
Sendp=½WhewSendp=½
47
BinaryExponentialBackoff(BEB)• Cleverlyestimatestheprobability
– 1stcollision,wait0or1frametimes– 2ndcollision,waitfrom0to3times– 3rdcollision,waitfrom0to7times…
• BEBdoublesintervalforeachsuccessivecollision– Quicklygetslargeenoughtowork– Veryefficient inpractice
ClassicEthernet,orIEEE802.3• MostpopularLANofthe1980s,1990s
– 10Mbpsoversharedcoaxialcable,withbasebandsignals– Multipleaccesswith“1-persistentCSMA/CDwithBEB”– Withreasonableparameters,85%efficiency (Book4.3.3)
48
EthernetFrameFormat• Hasaddressestoidentifythesenderandreceiver• CRC-32forerrordetection;noACKsorretransmission• Startofframeidentifiedwithphysicallayerpreamble
49
PacketfromNetworklayer(IP)
50
ModernEthernet• Basedonswitches,notmultipleaccess,butstillcalledEthernet– We’llgettoitlater
Switch
TwistedpairSwitchports
51
WirelessMultipleAccess(§4.2.5,4.4)• Howdowirelessnodesshareasinglelink?(Yes,thisisWiFi!)– Buildonoursimple,wiredmodel
Send? Send?
52
WirelessComplications• Wirelessismorecomplicatedthanthewiredcase(Surprise!)1. Nodesmayhavedifferentareasofcoverage– doesn’tfit
CarrierSense2. Nodescan’thearwhilesending– can’tCollisionDetect
≠CSMA/CD
53
DifferentCoverageAreas• Wirelesssignalisbroadcastandreceivednearby,wherethereissufficientSNR
HiddenTerminals• NodesAandCarehiddenterminals whensendingtoB
– Can’theareachother(tocoordinate)yetcollideatB– Wewanttoavoidtheinefficiency ofcollisions
54
ExposedTerminals• BandCareexposedterminals whensendingtoAandD
– Canheareachotheryetdon’tcollideatreceiversAandD– Wewanttosendconcurrently toincreaseperformance
55
56
NodesCan’tHearWhileSending• Withwires,detectingcollisions(andaborting)lowerstheircost
• Morewastedtimewithwireless
Time XXXXXXXXX
XXXXXXXXX
WirelessCollision
ResendX
X
WiredCollision
Resend
PossibleSolution:MACA• MACAusesashorthandshakeinsteadofCSMA(Karn,1990)
– 802.11usesarefinementofMACA(later)
• Protocolrules:1. AsendernodetransmitsaRTS(Request-To-Send,withframelength)2. ThereceiverreplieswithaCTS(Clear-To-Send,withframelength)3. SendertransmitstheframewhilenodeshearingtheCTSstaysilent– CollisionsontheRTS/CTSarestillpossible,butlesslikely
57
58
MACA– HiddenTerminals• AàBwithhiddenterminalC
1. AsendsRTS,toB
DCBA
59
MACA– HiddenTerminals(2)• AàBwithhiddenterminalC
2. BsendsCTS,toA,andCtoo
DCBARTS
60
MACA– HiddenTerminals(3)• AàBwithhiddenterminalC
2. BsendsCTS,toA,andCtoo
DCBARTS
CTSCTS
Alert!
61
MACA– HiddenTerminals(4)• AàBwithhiddenterminalC
3. AsendsframewhileCdefers
FrameQuiet...
62
MACA– ExposedTerminals• BàA,CàDasexposedterminals– BandCsendRTStoAandD
DCBA
63
MACA– ExposedTerminals(2)• BàA,CàDasexposedterminals– AandDsendCTStoBandC
DCBARTSRTS
64
MACA– ExposedTerminals(3)• BàA,CàDasexposedterminals– AandDsendCTStoBandC
DCBARTSRTS
CTSCTS
AllOKAllOK
65
MACA– ExposedTerminals(4)• BàA,CàDasexposedterminals– AandDsendCTStoBandC
DCBAFrameFrame
66
802.11,orWiFi• VerypopularwirelessLAN
startedinthe1990s• Clientsgetconnectivity froma
(wired)AP(AccessPoint)• It’samulti-accessproblemJ• Variousflavorshavebeen
developed overtime– Faster,morefeatures
AccessPoint
Client
ToNetwork
67
802.11PhysicalLayer• Uses20/40MHzchannelsonISMbands
– 802.11b/g/non2.4GHz– 802.11a/non5GHz
• OFDMmodulation (except legacy802.11b)– Differentamplitudes/phasesforvaryingSNRs– Ratesfrom6to54Mbpspluserrorcorrection– 802.11nusesmultipleantennas;see“802.11withMultipleAntennasfor
Dummies”
802.11LinkLayer• MultipleaccessusesCSMA/CA(next);RTS/CTSoptional• FramesareACKed andretransmittedwithARQ• Funkyaddressing(threeaddresses!)duetoAP• Errorsaredetectedwitha32-bitCRC• Many,manyfeatures(e.g.,encryption,powersave)
68
PacketfromNetworklayer(IP)
802.11CSMA/CAforMultipleAccess• Senderavoidscollisionsbyinsertingsmallrandomgaps
– E.g.,whenbothBandCsend,Cpicksasmallergap,goesfirst
69
Time
Send?
Send?
TheFutureof802.11(Guess)• LikelyubiquitousforInternetconnectivity– Greaterdiversity,fromlow- tohigh-enddevices
• Innovationinphysical layerdrivesspeed– Andpower-efficientoperationtoo
• Moreseamlessintegrationofconnectivity– Toomanualnow,andlimited(e.g.,device-to-device)
70
71
Contention-FreeMultipleAccess(§4.2.3)• Anotherapproachtomultipleaccess
– Basedonturns,notrandomization
1
32
4
72
IssueswithRandomMultipleAccess• CSMAisgoodunderlowload:– Grantsimmediateaccess– Littleoverhead(fewcollisions)
• Butnotsogoodunderhighload:– Highoverhead(expectcollisions)– Accesstimevaries(lucky/unlucky)
• Wewanttodobetterunderload!
73
Turn-TakingMultipleAccessProtocols
• Theydefineanorderinwhichnodesgetachancetosend– Orpass,ifnotrafficatpresent
• Wejustneedsomeordering…– E.g.,TokenRing– E.g.,nodeaddresses
TokenRing• Arrangenodesinaring;tokenrotates“permissiontosend”toeachnodeinturn
74
Node
Directionoftransmission
Token
75
Turn-TakingAdvantages• Fixedoverheadwithnocollisions–Moreefficientunderload
• Regularchancetosendwithnounluckynodes– Predictableservice,easilyextendedtoguaranteedqualityofservice
76
Turn-TakingDisadvantages• Complexity–Morethingsthatcangowrongthanrandomaccessprotocols!• E.g.,whatifthetokenislost?• Electaleaderwhomanagesthetoken,whattodoifleadercrashes?
– Higheroverheadatlowload
77
Turn-TakinginPractice• Regularlytriedasanimprovementofferingbetterservice– E.g.,qualitiesofservice
• Butrandommultipleaccessishardtobeat– Simple,andusuallygoodenough– Scalesfromfewtomanynodes
78
LANSwitches(§4.3.4,4.8.1-4.8.2,4.8.4)• Howdoweconnectnodeswithaswitch insteadofmultipleaccess– Usesmultiplelinks/wires– Basisofmodern(switched)Ethernet
Switch
79
SwitchedEthernet• HostsarewiredtoEthernetswitcheswithtwistedpair
– Switchservestoconnect thehosts– Wiresusuallyruntoacloset
Switch
TwistedpairSwitchports
80
What’sinthebox?• Rememberfromprotocollayers:
Network
LinkNetwork
Link
Link Link
Physical PhysicalHub,orrepeater
Switch
Router
Alllooklikethis:
InsideaHub• Allportsarewiredtogether;moreconvenientandreliablethanasinglesharedwire
81
↔
InsideaSwitch• Usesframeaddressestoconnectinputporttotherightoutputport;multipleframesmaybeswitchedinparallel
82
...
Fabric
InsideaSwitch(2)• Portmaybeusedforbothinputandoutput(full-duplex)
– Justsend,nomultipleaccessprotocol
83
...
123
4
1à 4and2à 3
InsideaSwitch(3)• Needbuffersformultipleinputstosendtooneoutput
84
...
...
... ...
InputBuffer OutputBufferFabric
Input Output
InsideaSwitch(4)• Sustainedoverloadwillfillbufferandleadtoframeloss
85
...
...
... ...
InputBuffer OutputBufferFabric
Input Output
XXX
Loss!
86
AdvantagesofSwitches• Switchesandhubshavereplacedthesharedcableofclassic
Ethernet– Convenienttorunwirestoonelocation– Morereliable;wirecutisnotasinglepointoffailurethatishardto
find
• Switchesofferscalableperformance– E.g.,100Mbpsperportinsteadof100Mbpsforallnodesofshared
cable/hub
SwitchForwarding• SwitchneedstofindtherightoutputportforthedestinationaddressintheEthernetframe.How?– Wanttolethostsbemovedaroundreadily;don’tlookatIP
87
...
...
... ...
Source
Destination
EthernetFrame
88
BackwardLearning• Switchforwardsframeswithaport/addresstableasfollows:1. Tofillthetable,itlooksatthesourceaddressofinput
frames2. Toforward,itsendstotheport,orelsebroadcaststo
allports
89
BackwardLearning(2)• 1:AsendstoD
Switch
D
Address PortABCD
90
BackwardLearning(3)• 2:DsendstoA
Switch
D
Address PortA 1BCD
91
BackwardLearning(4)• 3:AsendstoD
Switch
D
Address PortA 1BCD 4
92
BackwardLearning(5)• 3:AsendstoD
Switch
D
Address PortA 1BCD 4
LearningwithMultipleSwitches• Justworkswithmultipleswitchesandamixofhubsassumingnoloops,e.g.,AsendstoDthenDsendstoA
93
Switch
94
SwitchSpanningTree(§4.8.3)• Howcanweconnectswitchesinanytopologysotheyjustwork?
Loops– yikes!
95
Problem– ForwardingLoops• Mayhavealoopinthetopology
– Redundancy incaseoffailures– Orasimplemistake
• WantLANswitchesto“justwork”– Plug-and-play,nochangestohosts– Butloopscauseaproblem…
RedundantLinks
96
ForwardingLoops(2)• SupposethenetworkisstartedandAsendstoF.Whathappens?
Left/Right
A B
C
D
E F
97
ForwardingLoops(3)• SupposethenetworkisstartedandAsendstoF.Whathappens?– Aà Cà B,D-left,D-right– D-leftà C-right,E,F– D-rightà C-left,E,F– C-rightà D-left,A,B– C-leftà D-right,A,B– D-leftà…– D-rightà …
Left/Right
A B
C
D
E F
98
SpanningTreeSolution• Switchescollectivelyfindaspanningtreeforthetopology– Asubsetoflinksthatisatree(noloops)andreachesallswitches
– Switchesforwardasnormalbutonlyonspanningtree– Broadcastswillgouptotherootofthetreeanddownallthebranches
SpanningTree(2)
99
Topology OneST AnotherST
Root
100
Radia Perlman(1951–)• Keyearlyworkonroutingprotocols– RoutingintheARPANET– SpanningTreeforswitches(next)– Link-staterouting(later)
• Nowfocusedonnetworksecurity
101
SpanningTreeAlgorithm• Rulesofthedistributedgame:
– Allswitchesrunthesamealgorithm– Theystartwithnoinformation– Operate inparallel andsendmessages– Alwayssearchforthebestsolution
• Ensuresahighlyrobustsolution– Anytopology,withnoconfiguration– Adaptstolink/switch failures,…
102
SpanningTreeAlgorithm(2)• Outline:
1. Electarootnodeofthetree(switchwiththelowestaddress)
2. Growtreeasshortestdistancesfromtheroot(usinglowestaddresstobreakdistanceties)
3. Turnoffportsforforwardingiftheyarenotonthespanningtree
SpanningTreeAlgorithm(3)• Details:
– Eachswitchinitiallybelievesitistherootofthetree– Eachswitchsendsperiodic updatestoneighborswith:
• Itsaddress,addressoftheroot,anddistance(inhops)toroot– Switchesfavorsportswithshorterdistancestolowestroot
• Useslowestaddressasatiefordistances
103
C
Hi,I’mC,therootisA,it’s2 hopsaway or(C,A,2)
104
SpanningTreeExample• 1st round,sending:
– Asends(A,A,0)tosayitisroot– B,C,D,E,andFdolikewise
• 1st round,receiving:– Astillthinksisit(A,A,0)– Bstillthinks(B,B,0)– Cupdatesto(C,A,1)– Dupdatesto(D,C,1)– Eupdatesto(E,A,1)– Fupdatesto(F,B,1)
A,A,0 B,B,0
C,C,0
D,D,0
E,E,0 F,F,0
105
SpanningTreeExample(2)• 2nd round,sending
– Nodessendtheirupdatedstate• 2nd roundreceiving:
– Aremains(A,A,0)– Bupdatesto(B,A,2)viaC– Cremains(C,A,1)– Dupdatesto(D,A,2)viaC– Eremains(E,A,1)– Fremains(F,B,1)
A,A,0 B,B,0
C,A,1
D,C,1
E,A,1 F,B,1
106
SpanningTreeExample(3)• 3rd round,sending
– Nodessendtheirupdatedstate• 3rd roundreceiving:
– Aremains(A,A,0)– Bremains(B,A,2)viaC– Cremains(C,A,1)– Dremains(D,A,2)viaC-left– Eremains(E,A,1)– Fupdatesto(F,A,3)viaB
A,A,0 B,A,2
C,A,1
D,A,2
E,A,1 F,B,1
107
SpanningTreeExample(4)• 4th round
– Steady-statehasbeenreached– Nodesturnoffforwarding thatisnotonthespanningtree
• Algorithmcontinuestorun– Adaptsbytimingoutinformation– E.g.,ifAfails,othernodesforgetit,andBwillbecomethenewroot
A,A,0 B,A,2
C,A,1
D,A,2
E,A,1 F,A,3
108
SpanningTreeExample(5)• ForwardingproceedsasusualontheST• InitiallyDsendstoF:
• AndFsendsbacktoD:
A,A,0 B,A,2
C,A,1
D,A,2
E,A,1 F,A,3
109
SpanningTreeExample(6)• ForwardingproceedsasusualontheST• InitiallyDsendstoF:
– Dà C-left– Cà A,B– Aà E– Bà F
• AndFsendsbacktoD:– Fà B– Bà C– Cà D(hm,notsuchagreatroute)
A,A,0 B,A,2
C,A,1
D,A,2
E,A,1 F,A,3