Upload
others
View
3
Download
0
Embed Size (px)
Citation preview
Lab4Info
• Ittakesawhile,sostartnow• Watchthefirsttwoscreencaststogetstarted
• Today:talkaboutICMPandARPforthelab
• DueWednesday,withextensiontoSaturdayat5PM
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
IPWithinEthernet
• Inarouter,weoperateonrawEthernetframes,withanIPorARPpacketaspayload
• Toforwardapacketonehop,mustknow:– DesUnaUonIPaddress– Next‐hopMACaddressofthenext‐hopIPaddress
Byte0 Byte1 Byte2 Byte3
DestMACAddress
DestMACAddress(conUnued) SourceMACAddress
SourceMACAddress(conUnued)
Ethertype Payload
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
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
GeneraUngARPRequest
• Request:WhohasIP192.168.1.3?CreateARPrequestwithfields:– SourceHWaddr:MACsrc– Sourceprotocoladdr:IPsrc– TargetHWaddr:all0s
– Targetprotocoladdr:192.168.1.3• ARPrequestsaresenttotheEthernetbroadcastaddress
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
HandlingARPReply
• Reply:IhaveIPof192.168.1.3withMACaddressof00‐11‐22‐33‐44‐55‐66
• IfthetargetIPoftheARPreplyistheIPoftheinterfacethiscameinon:– AddtheIPtoMACmappingtotheARPcache
– SendoffanypacketsthatwerewaiUngonthisARPreply
Lab4ARPFuncUonality
• GenerateARPrequestsifanexthopMACisnotintheARPcache
• ProcessARPrepliesthattargetusandplacethemintotheARPcache
• ProcessARPrequeststhattargetusandgenerateanappropriateARPreply
• GothroughARPrequestqueueeverysecondandsendoffARPrequestseverysecond(editsr_arpcache_sweepreqsinsr_arpcache.c)
ICMP
• Usedtosendcontrolmessagesbacktosendinghost
• MustprocessICMPEchoRequest• Mustgenerate– ICMPEchoReply– ICMPDesUnaUonHostUnreachable– ICMPDesUnaUonPortUnreachable
• CheckNetworkSorcerypagesondetailsofhowtogeneratethemessage
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
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
MACAddressUniqueness
• IPsshouldbegloballyuniqueacrossallhosts– ExceptformulUcastIPsandprivateIPsusedbyNATs
• MACaddressesonlyhavetobelocallyunique– IfanodeisdirectlyconnectedtoothernodesoverasharedEthernet(orswitched/hubbedEthernet),MACaddressesonthissharedmediummustbeuniqueorwecouldn’taddressaframetojustoneframe
– Buttwonodesonoppositesidesoftheworlddon’tneeduniqueMACaddresses,sinceaswe’veseenwe’reonlyusingtheMACaddresstoforwardtheframeonehop
– NetworkcardscomefromthefactorywithauniqueMACaddressanyway,butuserscansettheirMACaddressinsokware,soduplicateMACscanoccur
ArbitraUonofSharedResources
• Generalsystemsproblem– IhaveasharedresourcethatonlyonepersoncanuseataUme
– HowdoIarbitrateaccesstoit?• SharedCPU,mulUpleprocessesneedit–OSscheduler• Sharedradiospectrum,mulUplebroadcasters–frequencydivisionmulUplexing
• OneEthernetcoax,mulUpleclientsconnectedtoit–CSMA/CD– Otherwaysofsharingamedium,e.g.TokenRing,Aloha,etc.inbook
CSMA/CDintheClassroom
• Wearestudentssharingtheairinthisroom,anddevelopthefollowingprotocoltoarbitrateaccesstoit:– BeforeItalk,Iseeifanyoneelseistalking– Ifanyoneelseistalking,don’ttalk– Ifnooneelseistalking,starttalking– IfIstarttalkingandsensethatsomeoneelsehasstartedtalking,stoptalking,andstarttalkingsomerandomUmethatincreasesexponenUallytohopethatnooneissendingthen
CSMA/CDinEthernet
• WearenodessharingthisEthernetwire,anddevelopthefollowingprotocoltoarbitrateaccesstoit:– BeforeIsend,Isensethewiretoseeifanyoneelseissending
– Ifanyoneelseissending,don’tsend– Ifnooneelseissending,startsending– IfIstartsendingandsensethatsomeoneelsehasstartedsending,stopsending,andstartsendingakerwaiUngsomerandomUmethatincreasesexponenUally,tohopethatnooneissendingthen
– ThisiswhyCSMA/CDisknownasan“exponenUalbackoff”algorithm
LengthLimitaUonofCSMA/CD
• Thereisaminimumsizeframeneededtobeabletodetectcollisions:– TransmissionDelay>2*PropagaUonDelay– TransmissionDelay=MinSize/TransferRate– MinSize=TransferRate*2*PropagaUonDelay
• Longerwire=largerpropdelay=largerMinSize• Fastertransferrate=largerMinSize– SeriousproblemwithGigabitEthernetandhigher– Puntproblembysayingthateveryoneisusingswitchednetworksanywayandnotgoingtogetcollisions
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”
Switchingvs.PointtoPoint
• Anothergeneralsystemstrend– Busesareslow,butrequirelesslinks– Pointtopointisfast,butrequiresmorelinks– Everythingisgoingfrombusestopointtopoint
• MulU‐coreCPUs:FrontSideBustoHyperTransport• Harddrives:ParallelATAtoSerialATA• Peripheralcards:PCItoPCIExpress• Networking:SharedEthernettoSwitchedEthernet
• Ifweuseswitching,noneoftheseMACarbitraUonprotocolsmaqer!
ManchesterEncoding
• Synchronousdigitalsystemsneedaclocktotriggersamplingofdata
• Manchesterencodingallowsustoencodetheclockwiththedatastream– ThepreambletotheEthernetframeisusedtosynchronizethesenderclockwiththereceiverclock
• InManchesterencoding:– Transmiqersamplesdataonedgeofclock(usuallyrisingedge)
– Ifwesamplea1,itisencodedbyarisingedge– Ifwesamplea0,itisencodedbyafallingedge