Top Banner
Lab 4 and Link Layer CS144 Review Session 6 May 9, 2008 Ben Nham
22

Lab 4 and Link Layer - Stanford University

Dec 11, 2021

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Lab 4 and Link Layer - Stanford University

Lab4andLinkLayer

CS144ReviewSession6May9,2008

BenNham

Page 2: Lab 4 and Link Layer - Stanford University

Lab4Info

•  Ittakesawhile,sostartnow• Watchthefirsttwoscreencaststogetstarted

•  Today:talkaboutICMPandARPforthelab

•  DueWednesday,withextensiontoSaturdayat5PM

Page 3: Lab 4 and Link Layer - Stanford University

IPAddressesandMACAddresses

•  EachIPaddressisassociatedwithasingleinterface

•  EachinterfacehasaMACaddress•  Therefore,eachIPaddressis

associatedwithasingleMACaddress

•  Routerwith4interfaceshas4IPsand4MACaddresses!–  eth0hassomeIP0–  eth1hassomeIP1–  eth2hassomeIP2–  eth3hassomeIP3

•  Conclusion:AnIPaddressnamesaninterface,notahost

eth0

eth1

eth2

eth3

5.10.1.1

12.1.1.20012.1.1.1

12.1.0.1 IP1

IP2

IP0

IP3

Page 4: Lab 4 and Link Layer - Stanford University

IPWithinEthernet

•  Inarouter,weoperateonrawEthernetframes,withanIPorARPpacketaspayload

•  Toforwardapacketonehop,mustknow:– DesUnaUonIPaddress– Next‐hopMACaddressofthenext‐hopIPaddress

Byte0 Byte1 Byte2 Byte3

DestMACAddress

DestMACAddress(conUnued) SourceMACAddress

SourceMACAddress(conUnued)

Ethertype Payload

Page 5: Lab 4 and Link Layer - Stanford University

NecessityofARPIPAddress Netmask Gateway Interface

0.0.0.0 0.0.0.0 5.10.1.1 eth0

12.1.0.0 255.255.0.0 12.1.0.1 eth1

12.1.1.0 255.255.255.0 12.1.1.1 eth2

12.1.1.200 255.255.255.255 12.1.1.200 eth3

•  SupposeIgetapacketdesUnedfor128.12.94.3– Matchesdefaultroute

only(firstentry)•  Needtosendraw

EthernetframetotheMACaddressof5.10.1.1

•  ButourrouUngtablehasonlyIPaddresses,notMACaddresses

eth0

eth1

eth2

eth3

5.10.1.1

12.1.1.20012.1.1.1

12.1.0.1

Page 6: Lab 4 and Link Layer - Stanford University

ARPPacketFormat

•  Correspondstostructsr_arphdr–  HTYPE=ar_hrd=htons(ARPHDR_ETHER)–  PTYPE=ar_pro=htons(ETHERTYPE_IP)–  HLEN=ar_hln=#bytesinMACaddress–  PLEN=ar_pln=#bytesinIPaddress–  OPER=ar_op=htons(ARP_REQUEST)orhtons(ARP_REPLY)–  SHA/SPA=senderMAC/IPaddress(copyfromsr_ifofoutgoingIF)–  THA/TPA=targetMAC/IPaddress

Page 7: Lab 4 and Link Layer - Stanford University

GeneraUngARPRequest

•  Request:WhohasIP192.168.1.3?CreateARPrequestwithfields:– SourceHWaddr:MACsrc– Sourceprotocoladdr:IPsrc– TargetHWaddr:all0s

– Targetprotocoladdr:192.168.1.3•  ARPrequestsaresenttotheEthernetbroadcastaddress

Page 8: Lab 4 and Link Layer - Stanford University

HandlingARPRequest

•  Getrequest:Whohas192.168.1.3•  IfoneoftheIPsofmyrouteris192.168.1.3,sendanARPreply:IhaveIPof192.168.1.3withMACaddressof00‐11‐22‐33‐44‐55‐66(sixbytesinhex,or48bits)– SourceHWaddr:00‐11‐22‐33‐44‐55‐66– Sourceprotocoladdress:192.168.1.3– TargetHWaddr:MACsrc– Targetprotocoladdr:IPsrc

•  ARPreplyissentdirectlytoMACsrc

Page 9: Lab 4 and Link Layer - Stanford University

HandlingARPReply

•  Reply:IhaveIPof192.168.1.3withMACaddressof00‐11‐22‐33‐44‐55‐66

•  IfthetargetIPoftheARPreplyistheIPoftheinterfacethiscameinon:– AddtheIPtoMACmappingtotheARPcache

– SendoffanypacketsthatwerewaiUngonthisARPreply

Page 10: Lab 4 and Link Layer - Stanford University

Lab4ARPFuncUonality

•  GenerateARPrequestsifanexthopMACisnotintheARPcache

•  ProcessARPrepliesthattargetusandplacethemintotheARPcache

•  ProcessARPrequeststhattargetusandgenerateanappropriateARPreply

•  GothroughARPrequestqueueeverysecondandsendoffARPrequestseverysecond(editsr_arpcache_sweepreqsinsr_arpcache.c)

Page 11: Lab 4 and Link Layer - Stanford University

ICMP

•  Usedtosendcontrolmessagesbacktosendinghost

•  MustprocessICMPEchoRequest•  Mustgenerate– ICMPEchoReply– ICMPDesUnaUonHostUnreachable– ICMPDesUnaUonPortUnreachable

•  CheckNetworkSorcerypagesondetailsofhowtogeneratethemessage

Page 12: Lab 4 and Link Layer - Stanford University

BasicLab4FlowDiagramReceiveRaw

EthernetFrame

ProcessIPPacket

ProcessPacketSenttoSelf

ForwardPacket

ProcessARPRequest/Reply

IfICMPechoreq,sendICMPechoreply

IfIP+TCP/UDP,sendICMPportunreachable

DoLPMonrouUngtable

Seepreviousslides

SendICMPhostunreachable

CheckARPcache

Sendframetonexthop

AddrequesttoARPqueue,sendingifnecessary

Nomatch

Ifalreadysent5Umes

Match

Nohit

Hit

NotsenttoselfSenttoself

Page 13: Lab 4 and Link Layer - Stanford University

MoreLab4Thoughts

•  Organizeyourcode–  SUckingeverythingsr_router.cwillprobablygiveyoua

headache– Makesomenewfiles(suggesUons):

•  sr_arp.c/hforhandling/generaUngARPpackets•  sr_icmp.c/hforhandling/generaUngICMPpackets•  sr_ip.c/hfortohandlegeneraUngIPpackets•  AddthesourcesandheaderstotheMakefile

•  DoonethingataUme– NeedARPtosendanythingatall–  IfyoujustdotheforwardingpathwithoutICMP,shouldbeable

toroutepacketstotheappservers–  CanaddICMPsupportlast

Page 14: Lab 4 and Link Layer - Stanford University

MACAddressUniqueness

•  IPsshouldbegloballyuniqueacrossallhosts– ExceptformulUcastIPsandprivateIPsusedbyNATs

•  MACaddressesonlyhavetobelocallyunique–  IfanodeisdirectlyconnectedtoothernodesoverasharedEthernet(orswitched/hubbedEthernet),MACaddressesonthissharedmediummustbeuniqueorwecouldn’taddressaframetojustoneframe

– Buttwonodesonoppositesidesoftheworlddon’tneeduniqueMACaddresses,sinceaswe’veseenwe’reonlyusingtheMACaddresstoforwardtheframeonehop

– NetworkcardscomefromthefactorywithauniqueMACaddressanyway,butuserscansettheirMACaddressinsokware,soduplicateMACscanoccur

Page 15: Lab 4 and Link Layer - Stanford University

ArbitraUonofSharedResources

•  Generalsystemsproblem–  IhaveasharedresourcethatonlyonepersoncanuseataUme

– HowdoIarbitrateaccesstoit?•  SharedCPU,mulUpleprocessesneedit–OSscheduler•  Sharedradiospectrum,mulUplebroadcasters–frequencydivisionmulUplexing

•  OneEthernetcoax,mulUpleclientsconnectedtoit–CSMA/CD– Otherwaysofsharingamedium,e.g.TokenRing,Aloha,etc.inbook

Page 16: Lab 4 and Link Layer - Stanford University

CSMA/CDintheClassroom

• Wearestudentssharingtheairinthisroom,anddevelopthefollowingprotocoltoarbitrateaccesstoit:– BeforeItalk,Iseeifanyoneelseistalking– Ifanyoneelseistalking,don’ttalk– Ifnooneelseistalking,starttalking– IfIstarttalkingandsensethatsomeoneelsehasstartedtalking,stoptalking,andstarttalkingsomerandomUmethatincreasesexponenUallytohopethatnooneissendingthen

Page 17: Lab 4 and Link Layer - Stanford University

CSMA/CDinEthernet

•  WearenodessharingthisEthernetwire,anddevelopthefollowingprotocoltoarbitrateaccesstoit:– BeforeIsend,Isensethewiretoseeifanyoneelseissending

–  Ifanyoneelseissending,don’tsend–  Ifnooneelseissending,startsending–  IfIstartsendingandsensethatsomeoneelsehasstartedsending,stopsending,andstartsendingakerwaiUngsomerandomUmethatincreasesexponenUally,tohopethatnooneissendingthen

– ThisiswhyCSMA/CDisknownasan“exponenUalbackoff”algorithm

Page 18: Lab 4 and Link Layer - Stanford University

LengthLimitaUonofCSMA/CD

•  Thereisaminimumsizeframeneededtobeabletodetectcollisions:– TransmissionDelay>2*PropagaUonDelay– TransmissionDelay=MinSize/TransferRate– MinSize=TransferRate*2*PropagaUonDelay

•  Longerwire=largerpropdelay=largerMinSize•  Fastertransferrate=largerMinSize– SeriousproblemwithGigabitEthernetandhigher– Puntproblembysayingthateveryoneisusingswitchednetworksanywayandnotgoingtogetcollisions

Page 19: Lab 4 and Link Layer - Stanford University

Credit:CS244aHandout10

CSMA/CDNetworkSizeRestricUonToensurethatapacketistransmiqedwithoutacollision,ahostmustbeabletodetectacollisionbeforeitfinishestransmirngapacket.

PROPPROP

t=0

t=PROP‐‐

t=PROP

t=2PROP‐

A B

Events:t=0:HostAstartstransmirngapacket.t=PROP‐‐:JustbeforethefirstbitreachesHostB,HostBsensesthelinetobeidleandstartstotransmitapacket.t=PROP‐:AcollisiontakesplacenearHostB.

t=PROP:HostBreceivesdatawhilsttransmirng,andsodetectsthecollision.t=2PROP‐:HostAreceivesdatawhilsttransmirng,andsodetectsthecollision.

“Lineisidle”

t=PROP‐

“Lineisidle”

Page 20: Lab 4 and Link Layer - Stanford University

Switchingvs.PointtoPoint

•  Anothergeneralsystemstrend– Busesareslow,butrequirelesslinks– Pointtopointisfast,butrequiresmorelinks– Everythingisgoingfrombusestopointtopoint

• MulU‐coreCPUs:FrontSideBustoHyperTransport•  Harddrives:ParallelATAtoSerialATA•  Peripheralcards:PCItoPCIExpress• Networking:SharedEthernettoSwitchedEthernet

•  Ifweuseswitching,noneoftheseMACarbitraUonprotocolsmaqer!

Page 21: Lab 4 and Link Layer - Stanford University

ManchesterEncoding

•  Synchronousdigitalsystemsneedaclocktotriggersamplingofdata

•  Manchesterencodingallowsustoencodetheclockwiththedatastream– ThepreambletotheEthernetframeisusedtosynchronizethesenderclockwiththereceiverclock

•  InManchesterencoding:– Transmiqersamplesdataonedgeofclock(usuallyrisingedge)

– Ifwesamplea1,itisencodedbyarisingedge– Ifwesamplea0,itisencodedbyafallingedge

Page 22: Lab 4 and Link Layer - Stanford University

ManchesterEncodingQuesUon

•  Supposea10MbpsNICsendsintoalinkaninfinitestreamofzerosusingManchesterencoding.ThesignalemergingfromtheadapterwillhavehowmanytransiUonspersecond?‐  2transiUonsperbitUme

‐  BitUmesoccuratclockfrequencyof10MHz

‐  TransiUonsoccurat20MHz

clk

data

encoding