DNS: Domain Name System People: many identifies: m SSN, name, Passpot # Intenet hosts, outes: m IP addess (32 bit) - used fo addessing datagams (in IPv4) m name, e.g., gaia.cs.umass.edu - used by humans Q: map between IP addesses and name? Adding additional delays Domain Name System: distibuted database implemented in hieachy of many name seves application-laye potocol host, outes, name seves to communicate to esolve names (addess/name tanslation) m uns ove UDP, pot 53 m used by othe app pots. m note: coe Intenet function implemented as application-laye potocol m complexity at netwok s edge 2: Application Laye 2b-1
Othe DNS sevices Host aliasing: any canonical hostname may have one o moe aliases: e.g. cassius.ee.usyd.edu.au has aliases www.ee.usyd.edu.au and ee.usyd.edu.au Mail seve aliasing: use of simple hostnames fo email: hotmail.com might be elay1.west.hotmail.com DNS pemits to have same mail seve and web seve aliased hostnames; easie fo uses Load distibution: eplicated seves fo busy seves; e.g. fo cnn.com we may have many seves DNS database otates the IP addesses of all eplicated seves wheneve eply to an inquiy; client uses the fist IP addess in the list load distibution 2: Application Laye 2b-2
DNS name seves Why not centalize DNS? single point of failue taffic volume distant centalized database maintenance doesn t scale! no seve has all nameto-ip addess mappings local name seves: m each ISP, company has local (default) name seve m host DNS quey fist goes to local name seve authoitative name seve: m fo a host: stoes that host s IP addess, name m can pefom name/addess tanslation fo that host s name 2: Application Laye 2b-3
DNS: Root name seves contacted by local name seve that can not esolve name oot name seve: m contacts authoitative name seve if name mapping not known m gets mapping m etuns mapping to local name seve ~ dozen oot name seves woldwide 2: Application Laye 2b-4
Simple DNS example oot name seve host suf.euecom.f wants IP addess of gaia.cs.umass.edu 1. Contacts its local DNS seve, dns.euecom.f 2. dns.euecom.f contacts oot name seve, if necessay 3. oot name seve contacts authoitative name seve, dns.umass.edu, if necessay local name seve dns.euecom.f 1 2 6 equesting host suf.euecom.f 5 3 4 authoititive name seve dns.umass.edu gaia.cs.umass.edu 2: Application Laye 2b-5
DNS example oot name seve Root name seve: may not know authoatiative name seve may know intemediate name seve: who to contact to find authoitative name seve local name seve dns.euecom.f 1 2 8 equesting host suf.euecom.f 7 3 6 intemediate name seve dns.umass.edu 4 5 authoitative name seve dns.cs.umass.edu gaia.cs.umass.edu 2: Application Laye 2b-6
DNS: iteated queies oot name seve ecusive quey: puts buden of name esolution on contacted name seve heavy load? iteated quey: contacted seve eplies with name of seve to contact I don t know this name, but ask this seve local name seve dns.euecom.f 1 2 8 equesting host suf.euecom.f 3 4 7 iteated quey intemediate name seve dns.umass.edu 5 6 authoitative name seve dns.cs.umass.edu gaia.cs.umass.edu 2: Application Laye 2b-7
DNS: caching and updating ecods once (any) name seve leans mapping, it caches mapping m cache enties timeout (disappea) afte some time [specified in TTL(time to live) field of the DNS Resouce Recod (RR)] update/notify mechanisms unde design by IETF m RFC 2136 m http://www.ietf.og/html.chates/dnsindchate.html 2: Application Laye 2b-8
DNS ecods DNS: distibuted db stoing esouce ecods (RR) RR fomat: (name, value, type,ttl) Type=A Type=CNAME m name is hostname m value is IP addess Type=NS m name is domain (e.g. foo.com) m value is IP addess of authoitative name seve fo this domain m name is an alias name fo some canonical (the eal) name m value is canonical name Type=MX m value is hostname of mail seve associated with name 2: Application Laye 2b-9
DNS potocol, messages DNS potocol : quey and eply messages, both with same message fomat message heade identification: 16 bit # fo quey, eply to quey uses same # flags: m quey o eply m ecusion desied m ecusion available m eply is authoitative 2: Application Laye 2b-10
DNS potocol, messages Name, type fields fo a quey RRs in esponse to quey ecods fo authoitative seves additional helpful info that may be used 2: Application Laye 2b-11
Socket pogamming Goal: lean how to build a client/seve application that communicates using sockets Socket API intoduced in BSD4.1 UNIX, 1981 explicitly ceated, used, eleased by apps client/seve paadigm two types of tanspot sevice via socket API: m uneliable datagam m eliable, byte steamoiented develope decision socket a host-local, applicationceated/owned, OS-contolled inteface (a doo ) into which application pocess can both send and eceive messages to/fom anothe (emote o local) application pocess 2: Application Laye 2b-12
Two types of client/seve apps Implementation of a potocol standad in an RFC m Client/seve pogams obey ules of the RFC e.g., if it is FTP pocess, see RFC 959 and confom it m Client and seve pogams ae able to inteopeate m Client and seve pogams can be ceated independently m They must use the pot numbe associated with potocol A popietay client/seve application m No necessity in confoming any RFC m Client and seve pogams developed by same develope m Not to use aleady used pot numbes m This method is the one we use hee Use C, C ++, o Java pogamming 2: Application Laye 2b-13
Socket pogamming using TCP Socket: a doo between application pocess and endend-tanspot potocol (UDP o TCP) TCP sevice: eliable tansfe of bytes fom one pocess to anothe socket pogamming: client/seve application development contolled by application develope contolled by opeating system pocess socket TCP with buffes, vaiables Intenet pocess socket TCP with buffes, vaiables contolled by application develope contolled by opeating system client o seve client o seve 2: Application Laye 2b-14
Socket pogamming with TCP Client must contact seve seve pocess must fist be unning seve must have ceated socket (doo) that welcomes client s contact Client contacts seve by: ceating client-local TCP socket object specifying IP addess, pot numbe of seve pocess TCP thee way handshaking When client ceates socket: client TCP establishes connection to seve TCP When contacted by client, seve TCP ceates new socket fo seve pocess to communicate with client m allows seve to talk with multiple clients application viewpoint TCP povides eliable, in-ode tansfe of bytes ( pipe ) between client and seve 2: Application Laye 2b-15
Socket pogamming with TCP Example client-seve app: client eads line fom standad input (infomuse steam), sends to seve via socket (outtoseve steam) seve eads line fom socket seve convets line to uppecase, sends back to client client eads, pints modified line fom socket and pints the line on standad output (infomseve steam) Input steam: sequence of bytes into pocess Output steam: sequence of bytes out of pocess infomuse outtoseve client socket iinfomseve a typical TCPclient: 3 steams and 1 socket 2: Application Laye 2b-16
Client/seve socket inteaction: TCP Seve (unning on hostid) ceate socket, pot=x, fo incoming equest: welcomesocket = SeveSocket() wait fo incoming connection equest connectionsocket = welcomesocket.accept() ead equest fom connectionsocket wite eply to connectionsocket close connectionsocket TCP connection setup Client ceate socket, connect to hostid, pot=x clientsocket = Socket() send equest using clientsocket ead eply fom clientsocket close clientsocket 2: Application Laye 2b-17
Example: Java client (TCP) impot java.io.*; impot java.net.*; class TCPClient { Ceate input steam Ceate client socket, connect to seve Ceate output steam attached to socket public static void main(sting agv[]) thows Exception { Sting sentence; Sting modifiedsentence; BuffeedReade infomuse = new BuffeedReade(new InputSteamReade(System.in)); Socket clientsocket = new Socket("hostname", 6789); DataOutputSteam outtoseve = new DataOutputSteam(clientSocket.getOutputSteam()); 2: Application Laye 2b-18
Example: Java client (TCP), cont. Ceate input steam attached to socket Send line to seve Read line fom seve BuffeedReade infomseve = new BuffeedReade(new InputSteamReade(clientSocket.getInputSteam())); sentence = infomuse.eadline(); outtoseve.witebytes(sentence + '\n'); modifiedsentence = infomseve.eadline(); System.out.pintln("FROM SERVER: " + modifiedsentence); clientsocket.close(); } } 2: Application Laye 2b-19
Example: Java seve (TCP) impot java.io.*; impot java.net.*; class TCPSeve { Ceate welcoming socket at pot 6789 Wait, on welcoming socket fo contact by client Ceate input steam, attached to socket public static void main(sting agv[]) thows Exception { Sting clientsentence; Sting capitalizedsentence; SeveSocket welcomesocket = new SeveSocket(6789); while(tue) { Socket connectionsocket = welcomesocket.accept(); BuffeedReade infomclient = new BuffeedReade(new InputSteamReade(connectionSocket.getInputSteam())); 2: Application Laye 2b-20
Example: Java seve (TCP), cont Ceate output steam, attached to socket Read in line fom socket Wite out line to socket } } } DataOutputSteam outtoclient = new DataOutputSteam(connectionSocket.getOutputSteam()); clientsentence = infomclient.eadline(); capitalizedsentence = clientsentence.touppecase() + '\n'; outtoclient.witebytes(capitalizedsentence); End of while loop, loop back and wait fo anothe client connection 2: Application Laye 2b-21
Socket pogamming with UDP UDP: no connection between client and seve no handshaking sende explicitly attaches IP addess and pot of destination seve must extact IP addess, pot of sende fom eceived datagam UDP: tansmitted data may be eceived out of ode, o lost application viewpoint UDP povides uneliable tansfe of goups of bytes ( datagams ) between client and seve a typical UDP client: 1 steam and 1 socket 2: Application Laye 2b-22
Diffeences in SP with UDP no initial handshaking between two pocesses and thus no welcoming socket no steams attached to the sockets attaching IP destination addess and pot numbe to each packet by the sende etieving addess by eceive fo each packet Example: m client eads a line fom standad input and sends it out though its socket to the seve m seve eads a line fom its socket m convets it to uppecase m sends the modified line out to client m client eads the modified line though its socket and pints it on it standad output 2: Application Laye 2b-23
Client/seve socket inteaction: UDP Seve (unning on hostid) Client ceate socket, pot=x, fo incoming equest: sevesocket = DatagamSocket() ead equest fom sevesocket ceate socket, clientsocket = DatagamSocket() Ceate, addess (hostid, pot=x, send datagam equest using clientsocket wite eply to sevesocket specifying client host addess, pot umbe ead eply fom clientsocket close clientsocket 2: Application Laye 2b-24
Example: Java client (UDP) impot java.io.*; impot java.net.*; Ceate input steam Ceate client socket Tanslate hostname to IP addess using DNS class UDPClient { public static void main(sting ags[]) thows Exception { BuffeedReade infomuse = new BuffeedReade(new InputSteamReade(System.in)); DatagamSocket clientsocket = new DatagamSocket(); InetAddess IPAddess = InetAddess.getByName("hostname"); byte[] senddata = new byte[1024]; byte[] eceivedata = new byte[1024]; Sting sentence = infomuse.eadline(); senddata = sentence.getbytes(); 2: Application Laye 2b-25
Example: Java client (UDP), cont. Ceate datagam with data-to-send, length, IP add, pot Send datagam to seve Read datagam fom seve } DatagamPacket sendpacket = new DatagamPacket(sendData, senddata.length, IPAddess, 9876); clientsocket.send(sendpacket); DatagamPacket eceivepacket = new DatagamPacket(eceiveData, eceivedata.length); clientsocket.eceive(eceivepacket); Sting modifiedsentence = new Sting(eceivePacket.getData()); System.out.pintln("FROM SERVER:" + modifiedsentence); clientsocket.close(); } 2: Application Laye 2b-26
Example: Java seve (UDP) impot java.io.*; impot java.net.*; Ceate datagam socket at pot 9876 Ceate space fo eceived datagam Receive datagam class UDPSeve { public static void main(sting ags[]) thows Exception { DatagamSocket sevesocket = new DatagamSocket(9876); byte[] eceivedata = new byte[1024]; byte[] senddata = new byte[1024]; while(tue) { DatagamPacket eceivepacket = new DatagamPacket(eceiveData, eceivedata.length); sevesocket.eceive(eceivepacket); 2: Application Laye 2b-27
Example: Java seve (UDP), cont Get IP add pot #, of sende Sting sentence = new Sting(eceivePacket.getData()); InetAddess IPAddess = eceivepacket.getaddess(); int pot = eceivepacket.getpot(); Ceate datagam to send to client Wite out datagam to socket } } Sting capitalizedsentence = sentence.touppecase(); senddata = capitalizedsentence.getbytes(); DatagamPacket sendpacket = new DatagamPacket(sendData, senddata.length, IPAddess, pot); sevesocket.send(sendpacket); } End of while loop, loop back and wait fo anothe datagam 2: Application Laye 2b-28
Chapte 2: Summay Ou study of netwok apps now complete! application sevice equiements: m eliability, bandwidth, delay client-seve paadigm Intenet tanspot sevice model m connection-oiented, eliable: TCP m uneliable, datagams: UDP specific potocols: m http m ftp m smtp, pop3 m dns socket pogamming m client/seve implementation m using tcp, udp sockets 2: Application Laye 2b-29
Chapte 2: Summay Most impotantly: leaned about potocols typical equest/eply message exchange: m client equests info o sevice m seve esponds with data, status code message fomats: m heades: fields giving info about data m data: info being communicated contol vs. data msgs m in-based, out-of-band centalized vs. decentalized stateless vs. stateful eliable vs. uneliable msg tansfe complexity at netwok edge secuity: authentication 2: Application Laye 2b-30