EEC484584 Computer Networks Lecture 6 Wenbing Zhao wenbingieee
EEC-484/584 Computer Networks Lecture 6 Wenbing Zhao wenbing@ieee. org (Part of the slides are based on Drs. Kurose & Ross’s slides for their Computer Networking book, and on materials supplied by Dr. Louise Moser at UCSB and Prentice-Hall) Spring Semester 2006 EEC-484/584: Computer Networks
2 Outline • • • Mock quiz Email, FTP Socket programming Physical layer – transmission theory Ethereal Labs: can be downloaded at – http: //www-net. cs. umass. edu/ethereal-labs/ Spring Semester 2006 EEC-484/584: Computer Networks 2
3 Electronic Mail user mailbox Three major components: • user agents • mail servers • simple mail transfer protocol: SMTP outgoing message queue user agent mail server SMTP User Agent • “mail reader” mail • composing, editing, reading server mail messages • outgoing, incoming messages user stored on server SMTP user agent mail server user agent Spring Semester 2006 EEC-484/584: Computer Networks 3
4 Electronic Mail: Mail Servers user agent Mail Servers mail • mailbox contains incoming server messages for user SMTP • message queue of outgoing (to be sent) mail messages SMTP • SMTP protocol between mail SMTP servers to send email messages server – client: sending mail server user agent – “server”: receiving mail user server agent Spring Semester 2006 EEC-484/584: Computer Networks user agent mail server user agent 4
5 SMTP [RFC 2821] • Uses TCP to reliably transfer email message from client to server, port 25 • Direct transfer: sending server to receiving server – The receiving server may be either the ultimate destination or an intermediate • Three phases of transfer – Handshaking (greeting) – Transfer of messages – Closure Spring Semester 2006 EEC-484/584: Computer Networks 5
6 SMTP [RFC 2821] • Command/response interaction – Commands: ASCII text – Response: status code and phrase • SMTP requires message (header & body) to be in 7 -bit ASCII • SMTP server uses CRLF to determine end of message Spring Semester 2006 EEC-484/584: Computer Networks 6
7 Alice Sends Message to Bob 1) Alice uses UA to compose message and “to” bob@someschool. edu 2) Alice’s UA sends message to her mail server; message placed in message queue 3) Client side of SMTP opens TCP connection with Bob’s mail server 1 user agent Spring Semester 2006 2 mail server 3 4) SMTP client sends Alice’s message over the TCP connection 5) Bob’s mail server places the message in Bob’s mailbox 6) Bob invokes his user agent to read message mail server 4 5 EEC-484/584: Computer Networks 6 user agent 7
8 Sample SMTP Interaction S: C: S: C: C: C: S: 220 hamburger. edu HELO crepes. fr 250 Hello crepes. fr, pleased to meet you MAIL FROM: <alice@crepes. fr> 250 alice@crepes. fr. . . Sender ok RCPT TO: <bob@hamburger. edu> 250 bob@hamburger. edu. . . Recipient ok DATA 354 Enter mail, end with ". " on a line by itself Do you like ketchup? How about pickles? . 250 Message accepted for delivery QUIT 221 hamburger. edu closing connection Spring Semester 2006 EEC-484/584: Computer Networks 8
9 Comparison of SMTP and HTTP • HTTP: pull • SMTP: push • Both have ASCII command/response interaction, status codes • HTTP: each object encapsulated in its own response message • SMTP: multiple objects sent in multipart message Spring Semester 2006 EEC-484/584: Computer Networks 9
10 Mail Message Format SMTP: protocol for exchanging email msgs RFC 822: standard for text message format: • Header lines, e. g. , header blank line body – To: – From: – Subject: different from SMTP commands! • Body: the “message”, ASCII characters only Spring Semester 2006 EEC-484/584: Computer Networks 10
11 Message Format: Multimedia Extensions • MIME: Multipurpose Internet Mail Extensions, RFC 2045, 2056 • Additional lines in msg header declare MIME content type • Purpose: Define encoding rules for non-ASCII messages MIME version method used to encode data multimedia data type, subtype, parameter declaration encoded data Spring Semester 2006 From: alice@crepes. fr To: bob@hamburger. edu Subject: Picture of yummy crepe. MIME-Version: 1. 0 Content-Transfer-Encoding: base 64 Content-Type: image/jpeg base 64 encoded data. . . . . base 64 encoded data EEC-484/584: Computer Networks 11
12 FTP: File Transfer Protocol user at host FTP user client interface file transfer local file system FTP server remote file system • Transfer file to/from remote host, server on port 21 • Client/server model – Client: side initiates transfer (either to/from remote) – Server: remote host • FTP: RFC 959 Spring Semester 2006 EEC-484/584: Computer Networks 12
13 FTP: Separate Control, Data Connections • Control connection: “out of band” • FTP server maintains “state”: current directory, earlier authentication TCP control connection port 21 FTP client TCP data connection port 20 FTP server Active FTP is shown Spring Semester 2006 EEC-484/584: Computer Networks 13
14 FTP Commands and Responses Sample commands: • sent as ASCII text over control channel • USER username • PASS password • LIST return list of file in current directory • RETR filename retrieves (gets) file • STOR filename stores (puts) file onto remote host Spring Semester 2006 EEC-484/584: Computer Networks 14
15 FTP Commands and Responses Sample return codes • status code and phrase (as in HTTP) • 331 Username OK, password required • 125 data connection already open; transfer starting • 425 Can’t open data connection • 452 Error writing file Spring Semester 2006 EEC-484/584: Computer Networks 15
16 Socket Programming Goal: Learn how to build client/server application that communicate using sockets socket Socket API • Explicitly created, used, released by apps • Client/server paradigm • Two types of transport service via socket API: – Unreliable datagram – Reliable, byte streamoriented Spring Semester 2006 a host-local, application-created, OS-controlled interface (a “door”) into which application process can both send and receive messages to/from another application process EEC-484/584: Computer Networks 16
17 Socket Programming with TCP Socket: a door between application process and end-to-end transport protocol (UCP or TCP) TCP service: reliable transfer of bytes from one process to another controlled by application developer controlled by operating system process socket TCP with buffers, variables internet controlled by operating system host or server Spring Semester 2006 socket TCP with buffers, variables controlled by application developer EEC-484/584: Computer Networks 17
18 Socket Programming with TCP Client must contact server • Server process must first be running • Server must have created socket (door) that welcomes client’s contact Client contacts server by: • Creating client-local TCP socket • Specifying IP address, port number of server process • When client creates socket: client TCP establishes connection to server TCP (Java only) – For C/C++, you need to call connect() explicitly Spring Semester 2006 EEC-484/584: Computer Networks 18
19 Socket Programming with TCP • When contacted by client, server TCP creates new socket for server process to communicate with client – Allows server to talk with multiple clients – Source port numbers used to distinguish clients application viewpoint TCP provides reliable, in-order transfer of bytes (“pipe”) between client and server Spring Semester 2006 EEC-484/584: Computer Networks 19
20 Client/Server Socket Interaction: TCP Server Client (running on hostid) create socket, port=x, for incoming request: welcome. Socket = Server. Socket() TCP wait for incoming connection request connection. Socket = welcome. Socket. accept() setup create socket, connect to hostid, port=x client. Socket = Socket() send request using client. Socket read request from connection. Socket write reply to connection. Socket read reply from client. Socket close connection. Socket Spring Semester 2006 close client. Socket EEC-484/584: Computer Networks 20
21 Stream Jargon (Java) Spring Semester 2006 Clien t Process proc Output Stream ess client. Socket TCP socket to network EEC-484/584: Computer Networks in. From. Server Input Stream out. To. Server • A stream is a sequence of characters that flow into or out of a process • An input stream is attached to some input source for the process, e. g. , keyboard or socket • An output stream is attached to an output source, e. g. , monitor or socket in. From. User Keyboard Monitor Input Stream TCP Socket from network 21
22 Socket Programming with TCP Example client-server app: 1) Client reads line from standard input (in. From. User stream) , sends to server via socket (out. To. Server stream) 2) Server reads line from socket 3) Server converts line to uppercase, sends back to client 4) Client reads, prints modified line from socket (in. From. Server stream) Spring Semester 2006 EEC-484/584: Computer Networks 22
Example: Java client (TCP) 23 import java. io. *; import java. net. *; class TCPClient { public static void main(String argv[]) throws Exception { String sentence; String modified. Sentence; Create input stream Create client socket, connect to server Create output stream attached to socket Spring Semester 2006 Buffered. Reader in. From. User = new Buffered. Reader(new Input. Stream. Reader(System. in)); Socket client. Socket = new Socket("hostname", 6789); Data. Output. Stream out. To. Server = new Data. Output. Stream(client. Socket. get. Output. Stream()); EEC-484/584: Computer Networks 23
24 Example: Java Client (TCP) Create input stream attached to socket Buffered. Reader in. From. Server = new Buffered. Reader(new Input. Stream. Reader(client. Socket. get. Input. Stream())); sentence = in. From. User. read. Line(); Send line to server out. To. Server. write. Bytes(sentence + 'n'); Read line from server modified. Sentence = in. From. Server. read. Line(); System. out. println("FROM SERVER: " + modified. Sentence); client. Socket. close(); } } Spring Semester 2006 EEC-484/584: Computer Networks 24
Example: Java Server (TCP) 25 import java. io. *; import java. net. *; class TCPServer { Create welcoming socket at port 6789 Wait, on welcoming socket for contact by client Create input stream, attached to socket Spring Semester 2006 public static void main(String argv[]) throws Exception { String client. Sentence; String capitalized. Sentence; Server. Socket welcome. Socket = new Server. Socket(6789); while(true) { Socket connection. Socket = welcome. Socket. accept(); Buffered. Reader in. From. Client = new Buffered. Reader(new Input. Stream. Reader(connection. Socket. get. Input. Stream())); EEC-484/584: Computer Networks 25
26 Example: Java Server (TCP) Create output stream, attached to socket Data. Output. Stream out. To. Client = new Data. Output. Stream(connection. Socket. get. Output. Stream()); Read in line from socket client. Sentence = in. From. Client. read. Line(); capitalized. Sentence = client. Sentence. to. Upper. Case() + 'n'; Write out line to socket out. To. Client. write. Bytes(capitalized. Sentence); } } } Spring Semester 2006 End of while loop, loop back and wait for another client connection EEC-484/584: Computer Networks 26
27 Socket Programming with UDP: no “connection” between client and server • No handshaking • Sender explicitly attaches IP address and port of destination to each packet • Server must extract IP address, port of sender from received packet Spring Semester 2006 UDP: transmitted data may be received out of order, or lost application viewpoint UDP provides unreliable transfer of groups of bytes (“datagrams”) between client and server EEC-484/584: Computer Networks 27
28 Client/Server Socket Interaction: UDP Server (running on hostid) create socket, port=x, for incoming request: server. Socket = Datagram. Socket() read request from server. Socket write reply to server. Socket specifying client host address, port number Spring Semester 2006 Client create socket, client. Socket = Datagram. Socket() Create, address (hostid, port=x, send datagram request using client. Socket read reply from client. Socket close client. Socket EEC-484/584: Computer Networks 28
29 Example: Java Client (UDP) packet (recall that TCP sent “byte stream”) send. Packet Output: sends Clien t Process proc UDP Packet ess packet (recall that TCP received “byte stream”) UDP Packet client Client UDP TCP Socket socket to network Spring Semester 2006 Input: receives receive. Packet Input Stream Monitor in. From. User Keyboard from network EEC-484/584: Computer Networks 29
30 Example: Java Client (UDP) import java. io. *; import java. net. *; Create input stream Create client socket Translate hostname to IP address using DNS class UDPClient { public static void main(String args[]) throws Exception { Buffered. Reader in. From. User = new Buffered. Reader(new Input. Stream. Reader(System. in)); Datagram. Socket client. Socket = new Datagram. Socket(); Inet. Address IPAddress = Inet. Address. get. By. Name("hostname"); byte[] send. Data = new byte[1024]; byte[] receive. Data = new byte[1024]; String sentence = in. From. User. read. Line(); send. Data = sentence. get. Bytes(); Spring Semester 2006 EEC-484/584: Computer Networks 30
31 Example: Java Client (UDP) Create datagram with data-to-send, length, IP addr, port Send datagram to server Datagram. Packet send. Packet = new Datagram. Packet(send. Data, send. Data. length, IPAddress, 9876); client. Socket. send(send. Packet); Datagram. Packet receive. Packet = new Datagram. Packet(receive. Data, receive. Data. length); Read datagram from server client. Socket. receive(receive. Packet); String modified. Sentence = new String(receive. Packet. get. Data()); System. out. println("FROM SERVER: " + modified. Sentence); client. Socket. close(); } } Spring Semester 2006 EEC-484/584: Computer Networks 31
Example: Java Server (UDP) 32 import java. io. *; import java. net. *; Create datagram socket at port 9876 class UDPServer { public static void main(String args[]) throws Exception { Datagram. Socket server. Socket = new Datagram. Socket(9876); byte[] receive. Data = new byte[1024]; byte[] send. Data = new byte[1024]; while(true) { Create space for received datagram Receive datagram Spring Semester 2006 Datagram. Packet receive. Packet = new Datagram. Packet(receive. Data, receive. Data. length); server. Socket. receive(receive. Packet); EEC-484/584: Computer Networks 32
Example: Java Server (UDP) 33 String sentence = new String(receive. Packet. get. Data()); Get IP addr port #, of sender Inet. Address IPAddress = receive. Packet. get. Address(); int port = receive. Packet. get. Port(); String capitalized. Sentence = sentence. to. Upper. Case(); send. Data = capitalized. Sentence. get. Bytes(); Create datagram to send to client Write out datagram to socket } Spring Semester 2006 Datagram. Packet send. Packet = new Datagram. Packet(send. Data, send. Data. length, IPAddress, port); server. Socket. send(send. Packet); } } End of while loop, loop back and wait for another datagram EEC-484/584: Computer Networks 33
Theoretical Basis for Data Communication 34 • Fourier analysis • Bandwidth-limited signals • Maximum data rate of channel Spring Semester 2006 EEC-484/584: Computer Networks 34
35 Fourier Analysis • Info is transmitted by varying voltage or current • Let f(t) be value of voltage or current at time t, any well-behaved periodic function g(t) with period T can be represented as Fourier series n-th harmonics Spring Semester 2006 EEC-484/584: Computer Networks 35
36 Fourier Analysis • Fundamental frequency f=1/T • an and bn are sine and cosine amplitudes of nth harmonics (terms) • The amplitudes and constant are given by Spring Semester 2006 EEC-484/584: Computer Networks 36
37 Fourier Analysis • The more harmonics we include in transmission, the more accurate the signal is • Bottom line: we must at least include 1 harmonic Sending a byte ‘b’ Spring Semester 2006 EEC-484/584: Computer Networks 37
38 Fourier Analysis • The more harmonics we include in transmission, the easier to reconstruct the signal Spring Semester 2006 EEC-484/584: Computer Networks 38
39 Bandwidth-Limited Signals • Problem with physical medium – Signal attenuates during propagation – Signals with different frequencies might attenuate different => distortion of the signal shape • Cutoff frequency: The Fourier amplitudes are transmitted undiminished from 0 up to some frequency fc – fc is measured in cycles/sec or Hertz (Hz) – fc is usually determined as the frequency at which half the power gets through Spring Semester 2006 EEC-484/584: Computer Networks 39
40 Bandwidth-Limited Signals • Bandwidth: The range of frequencies transmitted without being strongly attenuated, i. e. , 0 - fc • The bandwidth is a physical property of the transmission medium and usually depends the construction, thickness, and length of the medium Spring Semester 2006 EEC-484/584: Computer Networks 40
41 Bandwidth-Limited Signals • Artificial limitation on bandwidth: A filter is introduced into the circuit to limit the amount of bandwidth available to each customer – For example, a telephone wire may have a bandwidth of 1 MHz for short distances, but telephone companies add a filter restricting each customer to about 3100 Hz Spring Semester 2006 EEC-484/584: Computer Networks 41
42 Bandwidth and Data Rate • Data rate: how many bits can you send per second? – Higher data rate, shorter T, or higher fundamental frequency f – You need to allow at least a couple of harmonics to go through to reconstruct the signal • Higher data rate => requires higher bandwidth Spring Semester 2006 EEC-484/584: Computer Networks 42
43 Bandwidth and Data Rate • Example: – – – Voice line cut off frequency ~ 3000 Hz Data rate is b bits/sec During each period, send 8 bits => f = b/8 Hz If b = 9600 bps Number of highest harmonic ~ 3000/(b/8) = 24000/b = 2. 5 => poor reception Spring Semester 2006 EEC-484/584: Computer Networks 43
44 Nyquist Theorem • For noiseless channels • Number of sampling needed to reconstruct an arbitrary signal transmitted through a low-pass filter of bandwidth H => 2 H • Sampling: measuring the continuous signal's value every T units of time Shown in Frequency domain Spring Semester 2006 EEC-484/584: Computer Networks 44
45 Nyquist Theorem • Max data rate = 2 H log 2 V bits/sec, where signal consists of V discrete levels – Ex: H = 3000 Hz, V = 2 (binary) max data rate = 2*3000*log 22 = 6000 bits/sec – Ex: H = 3000 Hz, V = 64 max data rate = 2*3000*log 264 = 36, 000 bits/sec Spring Semester 2006 EEC-484/584: Computer Networks 45
46 Shannon Theorem • • • For noisy channels: actual medium has thermal noise Max data rate = H log 2(1+S/N) bits/sec Signal to noise ratio = signal power / noise power = S/N Often use decibel (d. B) as unit for S/N: 10 log 10 S/N Ex: H = 3000 Hz, S/N = 30 d. B = 1000 max data rate = 3000*log 2(1+1000) = 30, 000 upper bound is hard to reach, 9600 bits/sec is good Spring Semester 2006 EEC-484/584: Computer Networks 46
47 Optional Homework • Q 1. Television channels are 6 MHz wide. How many bits/sec can be sent if four-level digital signals are used? Assume a noiseless channel. • Q 2. A noiseless 4 -k. Hz channel is sampled every 1 msec. What is the maximum data rate? (Assuming each sample is 16 bits) Spring Semester 2006 EEC-484/584: Computer Networks 47
48 Optional Homework • Q 3. What signal-to-noise ratio is needed to put a T 1 carrier (1. 544 Mbps) on a 50 -k. Hz line? • Q 4. If a binary signal is sent over a 3 -k. Hz channel whose signal-to-noise ratio is 20 d. B, what is the maximum achievable data rate? Spring Semester 2006 EEC-484/584: Computer Networks 48
- Slides: 48