Networking: UDP & DNS - University of the Pacific · 2018-06-27 · User Datagram Protocol (UDP) ì...

31
ì Computer Systems and Networks ECPE 170 – Jeff Shafer – University of the Pacific Networking: UDP & DNS

Transcript of Networking: UDP & DNS - University of the Pacific · 2018-06-27 · User Datagram Protocol (UDP) ì...

ìComputer Systems and NetworksECPE170– JeffShafer– UniversityofthePacific

Networking:UDP&DNS

Lab Schedule

Activitiesì ThisWeek

ì Lab9– NetworkProgramming

ì NextWeekì StartAssembly

Programming(lecturefor1+day)

AssignmentsDueì Lab9

ì DuebyApr4th 5:00am

Spring2017ComputerSystemsandNetworks

2

ìUser Datagram Protocol (UDP)

Spring2017ComputerSystemsandNetworks

3

UDP versus TCP

Spring2017ComputerSystemsandNetworks

4

TCP UDPReliable? Yes

(Via acknowledgementsandretransmitting)

No

Connection-oriented?

Yes(Serverhasone socketperclient)

No(Serverhasonesocketandallmessagesfromallclientsarereceivedonit)

Programmingmodel?

Stream(continuousflow ofdata–maygetalittlebitatatime)

Datagram(data issentinitsentiretyornotatall.Sizeofeachdatagramissmall)

Applications HTTP(Lab8)Web,email,filetransfer

DNS(Lab9)StreamingAudio/Video, Gaming

User Datagram Protocol (UDP)

ì UDP:no“connection”betweenclientandserverì Nohandshakingì Senderexplicitly

attachesIPaddressandportofdestinationtoeachmessage

ì ReceivercanextractIPaddress,portofsenderfromreceiveddatagram

Spring2017ComputerSystemsandNetworks

5

applicationviewpoint

UDPprovidesunreliable transferofgroupsofbytes(“datagrams”)

betweenclientandserver

User Datagram Protocol (UDP)

ì EachUDPmessageisself-containedandcomplete

ì EachtimeyoureadfromaUDPsocket,yougetacompletemessageassentbythesenderì Thatis,assumingitwasn’tlostintransit!

ì ThinkofUDPsocketsasputtingastamponaletterandstickingitinthemailì Noneedtoestablishaconnectionfirstì Receiverhasnoidea“letter”isarrivinguntilthey

lookinthemailbox

6

Spring2017ComputerSystemsandNetworks

Python UDP Programming

ì Twonewfunctions:sendto() andrecvfrom()

Spring2017ComputerSystemsandNetworks

7

server_ip = 1.2.3.4port = 5678dest_addr = (server_ip, port)s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)......bytes_sent = s.sendto(raw_bytes, dest_addr)......max_bytes = 4096(raw_bytes, src_addr) = s.recvfrom(max_bytes)

ìDomain Name System (DNS)

Spring2017ComputerSystemsandNetworks

8

IP Addresses

ì IPversion4addressesare32bitslong

ì IPversion6addressare128bitslong

ì EverynetworkinterfacehasatleastoneIPaddressì Acomputermighthave2ormoreIPaddresses

ì IPv4addressesareusuallydisplayedindotteddecimalnotationì Eachbyterepresentedbydecimalvalueì Bytesareseparatedbyaperiodì IPaddress0x8002C2F2 = 128.2.194.242

9

Spring2017ComputerSystemsandNetworks

Motivation

ì IPaddressesarehardtorememberì 198.16.253.143?Orwasit.146?

ì Human-friendlynamesaremuchbetterì engineering.pacific.edu

ì Howcanwetranslatebetweenthetwo?

10

Spring2017ComputerSystemsandNetworks

Early Days (prior to 1983)

ì EachcomputerontheARPAnet (earlyInternet)hadasinglefileì hosts.txtmapsallknownhostnamestoIPaddress

ì MasterlistmaintainedbySRINetworkInformationCenterì Emailthemifyour

mappingchangesì Newlistproduced1-2

timesaweekì Allhostsdownloadthe

newlist

ì Problemswiththisapproach?

11

Spring2017ComputerSystemsandNetworks

Domain Name System (DNS)

ì Distributeddatabaseimplementedinhierarchyofmanynameservers

ì Application-layerprotocolì Hosts,routers,andnameserverscommunicateto

resolvenames(address/nametranslation)ì CoreInternetfunctionimplementedasapplication-

layerprotocol

12

Spring2017ComputerSystemsandNetworks

DNS is Decentralized

ì Nosinglepointoffailure

ì Nodistantcentralizeddatabase

ì Easiermaintenanceì Takeoneoradozenserversofflinewithoutissue

ì Supporthightrafficvolume

ì ***Scalability ***

13

Spring2017ComputerSystemsandNetworks

14

HowmanyDNSrequests/secondglobally?

Spring2017ComputerSystemsandNetworks

DNS: Scalability

ì Challengingtofinddataonglobal DNSrequests/secì Noglobalinternet“dashboard”ì Internetisa“networkofnetworks”

ì WouldhavetoinquirewithAT&T,Comcast,TimeWarner,Pacific,etcì Theywouldhavetocheckstatsonalloftheirlocalservers

ì GooglePublicDNSì 400billionrequests/dayasofDec2014ì 70%internationalì http://googlewebmastercentral.blogspot.com/2014/12/google-public-dns-and-location.html

ì OpenDNSì 80billionrequests/dayasofSept2015ì http://system.opendns.com/

15

Spring2017ComputerSystemsandNetworks

What’s in a Name?

ì engineering.pacific.edu

ì .edu istop-leveldomainì “pacific”belongsto.eduì “engineering”belongsto“pacific”ì Hierarchical!Readfromrighttoleft

16

Spring2017ComputerSystemsandNetworks

Root DNS Servers

com DNS servers org DNS servers edu DNS servers

poly.eduDNS servers

umass.eduDNS serversyahoo.com

DNS serversamazon.comDNS servers

pbs.orgDNS servers

Distributed, Hierarchical Database

Spring2017ComputerSystemsandNetworks

17

ì ClientwantsIPforwww.amazon.com1. Clientqueriesarootservertofindcom DNSserver2. ClientqueriescomDNSservertogetamazon.com DNS

server3. Clientqueriesamazon.com DNSservertogetIPaddress

forwww.amazon.com

DNS: Root Name Serversì Contactedbylocalnameserverthatcannotresolvetop-leveldomain

ì Rootnameserver:ì ContactsauthoritativenameserverforTLDifnamemappingnotknownì Getsmappingì Returnsmappingtolocalnameserver

18

13rootname“servers”worldwidelabeleda - m• Each“server”isreallya

cluster• Someclustersare

geographicallydistributed• 504totalinFall2014

Spring2017ComputerSystemsandNetworks

DNS: Root Name Servers

Spring2017ComputerSystemsandNetworks

19

http://www.root-servers.org/

DNS and UDP

ì DNSusesUDPbydefaultì Itcan useTCP,butit’srareì Isn’tthisunreliable?

ì WhyuseUDPì Reliabilitynotneeded

ì DNSwilljustre-requestifnoresponsereceived(2-5seconds)

ì Faster(inthreeways!)ì Noneedtoestablishaconnection(RTT/latency

overhead)ì Lowerper-packetbyteoverheadinUDPheaderì Lesspacketprocessingbyhosts

20

Spring2017ComputerSystemsandNetworks

ìDemonstrations

Spring2017ComputerSystemsandNetworks

21

Demonstrations

1. DNSClient:dns.py

2. Wireshark packetcapture

Spring2017ComputerSystemsandNetworks

22

ìProgramming Tips

Spring2017ComputerSystemsandNetworks

23

The struct Module

ì ThedetailsofvariablesarehiddeninPythonì Forexample,howmanybytesisaninteger?

ì NeedamethodtodealwithbinarydataforfileI/OornetworkI/O:thestructmoduleì ModuleperformsconversionsbetweenbasicPython

datatypes andarraysofbytes

Spring2017ComputerSystemsandNetworks

24

The struct Module

ì Twomainfunctionsinthestructmoduleì pack:convertagroupofvariablesintoanarrayof

bytesì unpack:convertanarrayofbytesintoagroupof

variables

ì SimilartoC’sprintf andscanf

ì Eachfunctionrequiresaformatstringtodescribehowtopackorunpackthearguments

Spring2017ComputerSystemsandNetworks

25

The struct Module

ì Commonformatstringoptions:ì Seehttps://docs.python.org/3/library/struct.html

ì raw_bytes = struct.pack("BH", val1, val2)

ì (val1, val2) = struct.unpack("BH", raw_bytes)

Spring2017ComputerSystemsandNetworks

26

Format PythonType Size(bytes)

B Integer 1

H Integer 2

L Integer 4

Q Integer 8

The struct Module

ì Endianness mustbeconsideredwhendoingfileornetworkI/Owithfieldsgreaterthanonebyte

ì Thefirstcharacteroftheformatstringdeterminestheendianness

Spring2017ComputerSystemsandNetworks

27

Character Byteorder Size Alignment

@ Native Native Native

= Native Standard None

< Little Standard None

> Big Standard None

! Network (Big) standard None

DNS Endianness

ì Whatendianness isyourcomputer?ì Littleendian(x86)

ì Whatendianness istheDNSprotocol?(ormostnetworkprotocols)ì Bigendian

ì WhatfieldsintheDNSheaderdoesthismatterfor?ì Two-byteintegerfields

(questioncount,answercount,etc…)

Spring2017ComputerSystemsandNetworks

28

Bit Fields

ì Warning! struct onlydealswithbytes.Itcannothandlefieldswithdimensionslessthanonebyte

ì Problem– SomeoftheDNSfieldsareonly1bit,3bits,or4bitsinsize

ì Howcanwehandlethis?ì Manualbitshifting(ala C)orctypes

Spring2017ComputerSystemsandNetworks

29

QR | OPCODE | AA | TC | RD | RA | Resvd | RCODE(1) (4) (1) (1) (1) (1) (3) (4)

2bytes(16bits)

CTypes

Spring2017ComputerSystemsandNetworks

30

import ctypes

# Define a 2-byte structure (equivalent to a 'uint16' variable in C)class CustomStruct(ctypes.BigEndianStructure):

_fields_ = [("fieldA", ctypes.c_uint16, 1), # 1-bit field - Most Sig BIT("fieldB", ctypes.c_uint16, 6), # 6-bit field("fieldC", ctypes.c_uint16, 4), # 4-bit field("fieldD", ctypes.c_uint16, 5) # 5-bit field - Least SIG BIT

]

# Create new instance of the 'CustomStruct' data typespecial_variable = CustomStruct()

# Access the fields of the structurespecial_variable.fieldA = 1special_variable.fieldB = 18special_variable.fieldC = 5special_variable.fieldD = 17

CTypes

Spring2017ComputerSystemsandNetworks

31

# Print out individual fieldsprint("Field A = %i" % special_variable.fieldA)print("Field B = %i" % special_variable.fieldB)print("Field C = %i" % special_variable.fieldC)print("Field D = %i" % special_variable.fieldD)

# Convert the structure to a byte array and print it outprint(bytes(special_variable))

# Alternate printing method (won't decode bytes as ASCII)hex_string = "".join("%02x " % b for b in bytes(special_variable))print("0x%s" % hex_string)