CSE 4213 Computer Networks II Suprakash Datta dattacs

  • Slides: 39
Download presentation
CSE 4213: Computer Networks II Suprakash Datta datta@cs. yorku. ca Office: CSEB 3043 Phone:

CSE 4213: Computer Networks II Suprakash Datta datta@cs. yorku. ca Office: CSEB 3043 Phone: 416 -736 -2100 ext 77875 Course page: http: //www. cs. yorku. ca/course/4213 Some slides are adapted from Jim Kurose’s slides. 12/17/2021 COSC 4213 - S. Datta 1

Administrivia Course webpage: http: //www. cs. yorku. ca/course/4213 Textbook: Lectures: Tue-Thu 2: 30 -4:

Administrivia Course webpage: http: //www. cs. yorku. ca/course/4213 Textbook: Lectures: Tue-Thu 2: 30 -4: 00 pm (VH 3005) Exams: midterm (25%), final (40%) Homework (35%): divided between lab assignments (20%) and project (15%). Slides: should be available the morning of the class Office hours: Tuesday 4 -6 pm, Th 12 noon -2 pm or by appointment at CSB 3043 12/17/2021 COSC 4213 - S. Datta Computer Networking: A Top Down Approach Featuring the Internet, 4 th edition. Jim Kurose, Keith Ross; Addison. Wesley, 2008. ISBN: 0 -321 -49770 -8 2

Administrivia – contd. n n n Cheating will not be tolerated. Visit the webpage

Administrivia – contd. n n n Cheating will not be tolerated. Visit the webpage for more details on policies etc. Be careful not to misuse packet sniffing software. I would like to have a 2 -hour midterm. Your cooperation is greatly appreciated. TA: none. There will be some non-credit homework to help you study. I may have an extra-credit assignment. This will be announced beforehand. 12/17/2021 COSC 4213 - S. Datta 3

Course objectives n n Understand the full TCP/IP architecture. Become familiar with “advanced topics”

Course objectives n n Understand the full TCP/IP architecture. Become familiar with “advanced topics” - P 2 P systems, multimedia communication (including Vo. IP), network security, wireless sensor networks. n Learn about active research areas. 12/17/2021 COSC 4213 - S. Datta 4

Major differences with 3213 n n More algorithmic (less math!) More hands-on – TCP/IP

Major differences with 3213 n n More algorithmic (less math!) More hands-on – TCP/IP programming. 12/17/2021 COSC 4213 - S. Datta 5

Internet structure: network of networks n n roughly hierarchical at center: “tier-1” ISPs (e.

Internet structure: network of networks n n roughly hierarchical at center: “tier-1” ISPs (e. g. , UUNet, BBN/Genuity, Sprint, AT&T), national/international coverage n treat each other as equals Tier-1 providers interconnect (peer) privately 12/17/2021 Tier 1 ISP NAP Tier-1 providers also interconnect at public network access points (NAPs) Tier 1 ISP COSC 4213 - S. Datta 6

Tier-1 ISP: e. g. , Sprint US backbone network 12/17/2021 COSC 4213 - S.

Tier-1 ISP: e. g. , Sprint US backbone network 12/17/2021 COSC 4213 - S. Datta 7

Internet structure: network of networks n “Tier-2” ISPs: smaller (often regional) ISPs n Connect

Internet structure: network of networks n “Tier-2” ISPs: smaller (often regional) ISPs n Connect to one or more tier-1 ISPs, possibly other tier-2 ISPs Tier-2 ISP pays tier-1 ISP for connectivity to rest of Internet q tier-2 ISP is customer of tier-1 provider Tier-2 ISP Tier 1 ISP Tier-2 ISP 12/17/2021 Tier-2 ISP NAP Tier 1 ISP Tier-2 ISPs also peer privately with each other, interconnect at NAP Tier-2 ISP COSC 4213 - S. Datta 8

Internet structure: network of networks n “Tier-3” ISPs and local ISPs n last hop

Internet structure: network of networks n “Tier-3” ISPs and local ISPs n last hop (“access”) network (closest to end systems) local ISP Local and tier 3 ISPs are customers of higher tier ISPs connecting them to rest of Internet Tier 3 ISP Tier-2 ISP local ISP Tier-2 ISP Tier 1 ISP Tier-2 ISP local ISP 12/17/2021 local ISP NAP Tier 1 ISP Tier-2 ISP local ISP COSC 4213 - S. Datta Tier-2 ISP local ISP 9

Internet structure: network of networks n a packet passes through many networks! local ISP

Internet structure: network of networks n a packet passes through many networks! local ISP Tier 3 ISP Tier-2 ISP local ISP Tier-2 ISP Tier 1 ISP Tier-2 ISP local ISP 12/17/2021 NAP Tier 1 ISP Tier-2 ISP local ISP COSC 4213 - S. Datta Tier-2 ISP local ISP 10

A closer look at network structure: n network edge: applications and hosts access networks,

A closer look at network structure: n network edge: applications and hosts access networks, physical media: wired, wireless communication links network core: n n interconnected routers network of networks 12/17/2021 COSC 4213 - S. Datta 11

The network edge: n end systems (hosts): n n peer-peer client/server model n n

The network edge: n end systems (hosts): n n peer-peer client/server model n n n run application programs e. g. Web, email at “edge of network” client host requests, receives service from always-on server e. g. Web browser/server; email client/server peer-peer model: n n minimal (or no) use of dedicated servers e. g. Skype, Bit. Torrent 12/17/2021 COSC 4213 - S. Datta 12

Network edge: reliable data transfer service Goal: data transfer between end n systems handshaking:

Network edge: reliable data transfer service Goal: data transfer between end n systems handshaking: setup (prepare for) data transfer ahead of time n n n Hello, hello back human protocol set up “state” in two communicating hosts reliable, in-order byte-stream data transfer n n loss: acknowledgements and retransmissions flow control: n Internet’s reliable data transfer service 12/17/2021 n n TCP - Transmission Control Protocol n TCP service [RFC 793] sender won’t overwhelm receiver congestion control: n senders “slow down sending rate” when network congested COSC 4213 - S. Datta 13

Network edge: best effort (unreliable) data transfer service Goal: data transfer between end systems

Network edge: best effort (unreliable) data transfer service Goal: data transfer between end systems n n App’s using TCP: n same as before! UDP - User Datagram Protocol [RFC 768]: n connectionless n unreliable data transfer n no flow control n no congestion control 12/17/2021 HTTP (Web), FTP (file transfer), Telnet (remote login), SMTP (email) App’s using UDP: n streaming media, teleconferencing, DNS, Internet telephony COSC 4213 - S. Datta 14

Internet Design Philosophy n n n Simple core, complex edge Best effort service Great

Internet Design Philosophy n n n Simple core, complex edge Best effort service Great support for heterogeneity Dynamic by design One network for many, many purposes Designed primarily for non-real-time text traffic with no Qo. S requirements other than reliable delivery. Q: Does this explain why the internet does not work well for many applications? 12/17/2021 COSC 4213 - S. Datta 15

Protocol “Layers” Networks are complex! n many “pieces”: n hosts n routers n links

Protocol “Layers” Networks are complex! n many “pieces”: n hosts n routers n links of various media n applications n protocols n hardware, software 12/17/2021 Pros and cons of layering: n explicit structure allows identification, relationship of complex system’s pieces n modularization eases maintenance, updating of system n change of implementation of layer’s service transparent to rest of system n Inefficient? COSC 4213 - S. Datta 16

Internet protocol “stack” n application: supporting network applications n n transport: host-host data transfer

Internet protocol “stack” n application: supporting network applications n n transport: host-host data transfer n n application transport network IP, routing protocols link: data transfer between neighboring network elements n n TCP, UDP network: routing of datagrams from source to destination n n FTP, SMTP, STTP PPP, Ethernet link physical: bits “on the wire” 12/17/2021 COSC 4213 - S. Datta 17

source message segment Ht datagram Hn Ht frame Hl Hn Ht M M Encapsulation

source message segment Ht datagram Hn Ht frame Hl Hn Ht M M Encapsulation application transport network link physical Hl Hn Ht M switch destination M Ht M Hn Ht Hl Hn Ht M M application transport network link physical 12/17/2021 Hn Ht Hl Hn Ht M M network link physical Hn Ht Hl Hn Ht M M router COSC 4213 - S. Datta 18

Internet History 1961 -1972: Early packet-switching principles n n 1961: Kleinrock queueing theory shows

Internet History 1961 -1972: Early packet-switching principles n n 1961: Kleinrock queueing theory shows effectiveness of packetswitching 1964: Baran - packetswitching in military nets 1967: ARPAnet conceived by Advanced Research Projects Agency 1969: first ARPAnet node operational 12/17/2021 n 1972: n ARPAnet demonstrated publicly n NCP (Network Control Protocol) first host-host protocol n first e-mail program n ARPAnet has 15 nodes COSC 4213 - S. Datta 19

Internet History 1972 -1980: Internetworking, new and proprietary nets n n n 1970: ALOHAnet

Internet History 1972 -1980: Internetworking, new and proprietary nets n n n 1970: ALOHAnet satellite network in Hawaii 1973: Metcalfe’s Ph. D thesis proposes Ethernet 1974: Cerf and Kahn architecture for interconnecting networks late 70’s: proprietary architectures: DECnet, SNA, XNA late 70’s: switching fixed length packets (ATM precursor) 1979: ARPAnet has 200 nodes 12/17/2021 Cerf and Kahn’s internetworking principles: n minimalism, autonomy - no internal changes required to interconnect networks n best effort service model n stateless routers n decentralized control define today’s Internet architecture COSC 4213 - S. Datta 20

Internet History 1990, 2000’s: commercialization, the Web, new apps n n n Early 1990’s:

Internet History 1990, 2000’s: commercialization, the Web, new apps n n n Early 1990’s: ARPAnet decommissioned 1991: NSF lifts restrictions on commercial use of NSFnet (decommissioned, 1995) early 1990 s: Web n hypertext [Bush 1945, Nelson 1960’s] n HTML, HTTP: Berners-Lee n 1994: Mosaic, later Netscape n late 1990’s: commercialization Late 1990’s – 2000’s: n n more killer apps: instant messaging, P 2 P file sharing network security to forefront est. 50 million host, 100 million+ users backbone links running at Gbps of the Web 12/17/2021 COSC 4213 - S. Datta 21

Next: the programming API n n Reading: Ch 2. 7 -2. 8. TCP vs

Next: the programming API n n Reading: Ch 2. 7 -2. 8. TCP vs UDP 12/17/2021 COSC 4213 - S. Datta 22

Socket programming Goal: learn how to build client/server application that communicate using sockets Socket

Socket programming Goal: learn how to build client/server application that communicate using sockets Socket API n n introduced in BSD 4. 1 UNIX, 1981 explicitly created, used, released by apps client/server paradigm two types of transport service via socket API: n unreliable datagram n reliable, byte stream-oriented 12/17/2021 socket 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 COSC 4213 - S. Datta 23

Socket-programming using TCP Socket: a door between application process and endend-transport protocol (UCP or

Socket-programming using TCP Socket: a door between application process and endend-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 12/17/2021 socket TCP with buffers, variables controlled by application developer COSC 4213 - S. Datta 24

Socket programming with TCP Client must contact server n server process must first be

Socket programming with TCP Client must contact server n server process must first be running n server must have created socket (door) that welcomes client’s contact Client contacts server by: n creating client-local TCP socket n specifying IP address, port number of server process n When client creates socket: client TCP establishes connection to server TCP 12/17/2021 n When contacted by client, server TCP creates new socket for server process to communicate with client n allows server to talk with multiple clients n source port numbers used to distinguish clients (more in Chap 3) application viewpoint TCP provides reliable, in-order transfer of bytes (“pipe”) between client and server COSC 4213 - S. Datta 25

Client/server socket interaction: TCP Server Client (running on hostid) create socket, port=x, for incoming

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() read request from connection. Socket write reply to connection. Socket close connection. Socket 12/17/2021 setup create socket, connect to hostid, port=x client. Socket = Socket() send request using client. Socket read reply from client. Socket close client. Socket COSC 4213 - S. Datta 26

Stream jargon n A stream is a sequence of characters that flow into or

Stream jargon n 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. Client process client TCP socket 12/17/2021 COSC 4213 - S. Datta 27

Socket programming with TCP Example client-server app: 1) client reads line from standard input

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) 12/17/2021 COSC 4213 - S. Datta 28

Example: Java client (TCP) import java. io. *; import java. net. *; class TCPClient

Example: Java client (TCP) 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 12/17/2021 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()); COSC 4213 - S. Datta 29

Example: Java client (TCP), cont. Create input stream attached to socket Buffered. Reader in.

Example: Java client (TCP), cont. 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(); } } 12/17/2021 COSC 4213 - S. Datta 30

Example: Java server (TCP) import java. io. *; import java. net. *; class TCPServer

Example: Java server (TCP) 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 12/17/2021 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())); COSC 4213 - S. Datta 31

Example: Java server (TCP), cont Create output stream, attached to socket Data. Output. Stream

Example: Java server (TCP), cont 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); } } } 12/17/2021 End of while loop, loop back and wait for another client connection COSC 4213 - S. Datta 32

Socket programming with UDP: no “connection” between client and server n no handshaking n

Socket programming with UDP: no “connection” between client and server n no handshaking n sender explicitly attaches IP address and port of destination to each packet application viewpoint n server must extract IP address, UDP provides unreliable transfer port of sender from received of groups of bytes (“datagrams”) packet between client and server UDP: transmitted data may be received out of order, or lost 12/17/2021 COSC 4213 - S. Datta 33

Client/server socket interaction: UDP Server (running on hostid) create socket, port=x, for incoming request:

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 Client create socket, client. Socket = Datagram. Socket() Create, address (hostid, port=x, send datagram request using client. Socket write reply to server. Socket specifying client host address, port number 12/17/2021 read reply from client. Socket close client. Socket COSC 4213 - S. Datta 34

Example: Java client (UDP) Client process Input: receives packet (recall that. TCP received “byte

Example: Java client (UDP) Client process Input: receives packet (recall that. TCP received “byte stream”) Output: sends packet (recall that TCP sent “byte stream”) client UDP socket 12/17/2021 COSC 4213 - S. Datta 35

Example: Java client (UDP) import java. io. *; import java. net. *; class UDPClient

Example: Java client (UDP) import java. io. *; import java. net. *; class UDPClient { public static void main(String args[]) throws Exception { Create input stream Create client socket Translate hostname to IP address using DNS 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(); 12/17/2021 COSC 4213 - S. Datta 36

Example: Java client (UDP), cont. Create datagram with data-to-send, length, IP addr, port Send

Example: Java client (UDP), cont. 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(); } } 12/17/2021 COSC 4213 - S. Datta 37

Example: Java server (UDP) import java. io. *; import java. net. *; Create datagram

Example: Java server (UDP) 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 12/17/2021 Datagram. Packet receive. Packet = new Datagram. Packet(receive. Data, receive. Data. length); server. Socket. receive(receive. Packet); COSC 4213 - S. Datta 38

Example: Java server (UDP), cont String sentence = new String(receive. Packet. get. Data()); Get

Example: Java server (UDP), cont 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 } 12/17/2021 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 COSC 4213 - S. Datta 39