CS 241 Section Week - PowerPoint PPT Presentation

1 / 65
About This Presentation
Title:

CS 241 Section Week

Description:

LMP1 attempts to encode or decode a number of files the ... Reassemble these messages at the receiving end. Application. Presentation. Session. Transport ... – PowerPoint PPT presentation

Number of Views:27
Avg rating:3.0/5.0
Slides: 66
Provided by: Alej203
Category:
Tags: reassemble | run | section | up | week

less

Transcript and Presenter's Notes

Title: CS 241 Section Week


1
CS 241 Section Week 12(11/13/08)
2
Outline
  • LMP1 Overview
  • Brief intro to Networking
  • What is a protocol?
  • OSI Model
  • TCP/IP Model
  • UDP and TCP
  • Socket Programming Library Functions
  • Hypertext Transfer Protocol

3
LMP1 Overview
4
LMP1 Overview
  • LMP1 attempts to encode or decode a number of
    files the following way
  • encode gt ./mmap -e -b16 file1 file2 ...
  • decode gt ./mmap -d -b8 file1 file2 ...
  • It has the following parameters
  • It reads whether it has to encode (-e) or
    decode(-d)
  • the number of bytes (rw_units) for each
    read/write from the file

5
LMP1 Overview
  • You have TWO weeks to complete and submit LMP1.
    We have divided LMP1 into two stages
  • Stage 1
  • Implement a simple virtual memory.
  • It is recommended you implement the my_mmap()
    function during this week.
  • You will need to complete various data structures
    to deal with the file mapping table, the page
    table, the physical memory, etc.

6
LMP1 Overview
  • You have TWO weeks to complete and submit LMP1.
    We have divided LMP1 into two stages
  • Stage 2
  • Implement various functions for memory mapped
    files including
  • my_mread() , my_mwrite() and my_munmap()
  • Handle page faults in your my_mread() and
    my_mwrite() functions
  • Implement two simple manipulations on files
  • encoding
  • decoding

7
LMP1 Overview
  • For N files, -The Table of File-Mappings has
    exactly N entries -The Virtual Page Table has
    enough entries to fit each file's length divided
    by 4096B -The Physical Memory Frame Table has 16
    entries
  • Example 3 files of length 3072bytes, 2048bytes,
    and 8192bytes -The Table of File-Mappings has 3
    entries-The Virtual Page Table has
  • (3072/4096gt1) (2048/4096gt1) (8192/4096gt2)
    4 entries -The Physical Memory Frame Table has
    16 entries and four of them are filled

8
Brief intro to Networking
9
Networking
  • Allows computers and other networked devices to
    talk to each other
  • How can we tell what the packet we just received
    means?
  • Interactions between applications on different
    machines are governed by protocols
  • Protocols dictate the format and sequence of the
    information exchange

10
Names and Addresses
  • A network address identifies a specific computer
    on the network
  • Several kinds of addresses exist MAC address
    (for LANs), IP address (for the Internet), etc.
  • Domain or DNS names are used for convenience, so
    we dont have to remember numerical addresses

11
Ports
  • Ports are numbers that represent an end-point for
    communication
  • Ports are logical, not physical, entities
  • All packets arrive to the same physical
    interface, and are then differentiated based on
    the port number (and other contents of the packet
    header)
  • Usually, distinct ports are used for
    communication via different protocols
  • E.g., port 80 is for HTTP, 22 is for SSH, etc.
  • See /etc/services for a list

12
What is a protocol?
13
What is a protocol?
  • It is a formal description of message formats and
    the rules that two computers must follow in order
    to exchange messages.
  • This set of rules describes how data is
    transmitted over a network.

14
Why are protocols needed?
  • Protocols are needed for communication between
    any two devices.
  • In what format will the messages be transmitted?
  • At what speed should messages be transmitted?
  • What to do if errors take place?
  • What to do if parts of a message are lost?

15
Network Model
  • What is a model? A hypothetical description of
    a complex entity or process.
  • Network model - A method of describing and
    analyzing data communications networks by
    breaking the entire set of communications process
    into a number of layers
  • Each layer has a specific function

16
Open Systems Interconnect (OSI) Model
  • Who made
  • International Standards Organization (ISO)
  • A Model of How Protocols and Networking
    Components Could be Made
  • Open means the concepts are non-proprietary
    can be used by anyone.
  • OSI is not a protocol. It is a model for
    understanding and designing a network
    architecture that is flexible and robust.

17
Network Architecture
  • A set of layers and protocols is called a network
    architecture
  • It refers to the physical and logical design of a
    network

18
7-layer OSI model
  • Why so many layers?
  • To reduce complexity, networks are organized as a
    stack of layers, one below the other
  • Each layer performs a specific task. It provides
    services to an adjacent layer
  • This is similar to the concept of a function in
    programming languages function do a specific
    task

19
The Layers of the OSI Model
20
The Layers of the OSI ModelSome Mnemonics
All People Seem To Need Data Processing
Please Do Not Tell Secret Passwords Anytime
21
Physical layer
  • Specifications for the physical components of the
    network
  • Bit representation encode bits into electrical
    or optical signals
  • Transmission rate the number of bits sent each
    second

22
Data Link Layer
  • Responsible for delivery of data between two
    systems on the same network. Main functions are
  • Framing divides the stream of bits received from
    network layer into manageable data units called
    frames.
  • Physical Addressing add a header to the frame to
    define the physical address of the source and the
    destination machines.

23
Network Layer
  • Main functions of this layer are
  • Responsible for delivery of packets across
    multiple networks.
  • Routing Provide mechanisms to transmit data over
    independent networks that are linked together.

24
Transport Layer
  • Main functions of this layer are
  • Responsible for source-to-destination delivery of
    the entire message.
  • Segmentation and reassembly divide message into
    smaller segments, number them and transmit.
    Reassemble these messages at the receiving end.

25
Session Layer
  • Main functions of this layer are
  • Dialog control allows two systems to enter into
    a dialog, keep a track of whose turn it is to
    transmit.

26
Presentation Layer
  • Responsibilities of this layer are
  • Translation since different computers use
    different encoding systems (bit order translation

27
Application Layer
  • Contains protocols that allow the users to
    access the network (FTP, HTTP, SMTP, etc)
  • DOES NOT include application programs such as
    email, browsers, word processing applications,
    etc.

28
Summary of Functions of Layers
29
TCP/IP Model
  • Layers in the TCP/IP model
  • Physical Layer
  • Data Link Layer (MAC)
  • Network Layer (IPv4, IPv6)
  • Transport Layer (UDP, TCP)
  • Application Layer (HTTP, SSH)

30
Networking
  • Each layer is (traditionally) self-contained.
  • The data-link layer doesnt care if its running
    IPv4 or IPv6, doesnt care it its TCP or UDP.
  • When processing the data-link layer, no other
    layer is (traditionally) considered.

31
Networking
32
Networking
  • Data Link Layer
  • Purpose To transfer packets in a flat addressing
    space.
  • Multiple packets go into a hub.
  • The hub bundles packets together to send them
    upstream if necessary, based only on the MAC
    address.
  • Not significantly covered in this class.

33
Networking
  • Network Layer
  • Purpose To transfer packets in a hierarchical
    addressing space.
  • Streams of packets go into switches.
  • Switches determine if the address is within its
    subnet and will route based on subnets
    (IPv4/IPv6).
  • Also, not significantly covered in this class.

34
Networking
  • Transport Layer
  • After the data link and network layer, packets
    have arrived at the destination computer.
  • The transport layer
  • Provides port multiplexing, allowing for
    multiple programs all communicate without
    receiving every packet.
  • Protocol-specific assurances.

35
UDP
  • User Datagram Protocol (UDP)
  • The simplest commonly used transport protocol.
  • Provides
  • Port multiplexing
  • Error-checking (via simple checksum)

36
UDP
  • User Datagram Protocol (UDP)
  • Does NOT provide
  • Ordering
  • Packet A may be sent before Packet B, but Packet
    B may arrive after Packet A
  • Reliability
  • The sender has no way to know that Destination
    received some packet sent by Sender (assured by
    retransmissions)
  • Flow / Congestion Control
  • Theres no mechanism to tweak packet size

37
UDP
  • User Datagram Protocol (UDP)
  • Only a few parameters are needed for UDP
  • Source Port
  • Destination Port
  • From the network layer (IP), you have two more
    parameters
  • Source IP
  • Destination IP

38
UDP
  • UDP Packet

Source Port
Destination Port
Data Length
Checksum
Data
39
TCP
  • Transmission Control Protocol
  • TCP provides an alternative to UDP to allow for
    more assurances
  • Provides
  • Port multiplexing
  • Ordered data / no duplicates
  • Error-free transmission
  • Flow control
  • Congestion control

40
TCP
  • TCP Packet

Source Port
Destination Port
SEQ Number
ACK Number
Offset / Flags
Window Size
Checksum
Urgent Pointer
Optional Fields
Data
41
Socket Programming
42
Socket
  • Standard APIs for sending and receiving data
    across computer networks
  • Introduced by BSD operating systems in 1983
  • POSIX incorporated 4.3BSD sockets and XTI in 2001
  • include ltsys/socket.hgt

43
Typical TCP Server-Client
44
Typical UDP Server-Client
45
Programming Sockets
  • Lucky for us, the OS does most the work between
    UDP and TCP!
  • TCP Socket
  • socket(PF_INET, SOCK_STREAM,
    IPPROTO_TCP)
  • UDP Socket
  • socket(PF_INET, SOCK_DGRAM, 0)

46
Programming Sockets
  • To create a socket in C, you need to run two
    commands
  • socket()

47
socket
  • int socket(int domain, int type, int protocol)
  • Creates a communication endpoint
  • Parameters
  • domain AF_INET (IPv4)
  • type SOCK_STREAM (TCP) or SOCK_DGRAM (UDP)
  • protocol 0 (socket chooses the correct protocol
    based on type)
  • Returns a nonnegative integer corresponding to a
    socket file descriptor if successful, -1 with
    errno set if unsuccessful

48
Programming Sockets
  • To create a socket in C, you need to run two
    commands
  • socket()
  • bind()

49
bind
  • int bind(int socket, const struct sockaddr
    address, socklen_t address_len)
  • Associates the socket with a port on your local
    machine
  • struct sockaddr_in used for struct sockaddr
  • sa_family_t sin_family / AF_INET /
  • in_port_t sinport / port number /
  • struct in_addr sin_addr / IP address /
  • Returns 0 if successful, -1 with errno set if
    unsuccessful

50
Programming Sockets
  • Since UDP is packet-based and TCP is
    connection-based, you need to establish a
    connection in TCP
  • Server listen(), accept()

51
listen
  • int listen(int socket, int backlog)
  • Puts the socket into the passive state to accept
    incoming requests
  • Internally, it causes the network infrastructure
    to allocate queues to hold pending requests
  • backlog number of connections allowed on the
    incoming queue
  • bind should be called beforehand
  • Returns 0 if successful, -1 with errno set if
    unsuccessful

52
accept
  • int accept(int socket, struct sockaddr restrict
    address, socklen_t restrict address_len)
  • Accepts the pending requests in the incoming
    queue
  • address is used to return the information about
    the client making the connection.
  • sin_addr.s_addr holds the Internet address
  • listen should be called beforehand
  • Returns nonnegative file descriptor corresponding
    to the accepted socket if successful, -1 with
    errno set if unsuccessful

53
Programming Sockets
  • Since UDP is packet-based and TCP is
    connection-based, you need to establish a
    connection in TCP
  • Server listen(), accept()
  • Client connect()

54
connect
  • int connect(int socket, const struct sockaddr
    address, socklen_t address_len)
  • Establishes a link to the well-known port of the
    remote server
  • Initiates the TCP 3-way handshake
  • Cannot be restarted even if interrupted
  • Returns 0 if successful, -1 with errno set if
    unsuccessful

55
Programming Sockets
  • In both TCP and UDP, you send and receive by
    using the same calls
  • recv() / recvfrom()

56
recv and recvfrom
  • int recv(int socket, void buf, int len, int
    flags)
  • int recvfrom(int socket, void buf, int len, int
    flags, const struct sockaddr from, socklet_t
    fromlen)
  • receives data into the buffer buf
  • recvfrom is used for unconnected datagram
    sockets. If used in connection-mode, last two
    parameters are ignored.
  • Returns the number of bytes actually read if
    successful, -1 with errno set if unsuccessful

57
Programming Sockets
  • In both TCP and UDP, you send and receive by
    using the same calls
  • recv() / recvfrom()
  • send() / sendto()

58
send and sendto
  • int send(int socket, const void msg, int len,
    int flags)
  • int sendto(int socket, const void msg, int len,
    int flags, const struct sockaddr to, socklet_t
    tolen)
  • sends data pointed by msg
  • sendto is used for unconnected datagram sockets.
    If used in connection-mode, last two parameters
    are ignored.
  • Returns the number of bytes actually sent out if
    successful, -1 with errno set if unsuccessful

59
close and shutdown
  • int close(int socket)
  • int shutdown(int socket, int how)
  • close
  • Prevents any more reads and writes
  • same function covered in file systems
  • shutdown
  • provides a little more control
  • how
  • 0 Further receives are disallowed
  • 1 Further sends are disallowed
  • 2 same as close
  • Returns 0 if successful, -1 with errno set if
    unsuccessful

60
HyperText Transfer Protocol
61
HTTP
  • Hypertext Transfer Protocol
  • Delivers virtually all files and resources on the
    World Wide Web
  • Uses Client-Server Model
  • HTTP transaction
  • HTTP client opens a connection and sends a
    request to HTTP server
  • HTTP server returns a response message

62
HTTP (continued)
  • Request
  • GET /path/to/file/index.html HTTP/1.0
  • Other methods (POST, HEAD) possible for request
  • Response
  • HTTP/1.0 200 OK
  • Common Status Codes
  • 200 OK
  • 404 Not Found
  • 500 Server Error

63
Sample HTTP exchange
  • Scenario
  • Client wants to retrieve the file at the
    following URL (http//www.somehost.com/path/file.h
    tml)
  • What a client does
  • Client opens a socket to the host
    www.somehost.com, port 80
  • Client sends the following message through the
    socket
  • GET /path/file.html HTTP/1.0
  • From someuser_at_uiuc.edu
  • User-Agent HTTPTool/1.0
  • blank line here

64
Sample HTTP exchange
  • What a server does
  • Server responds through the same socket
  • HTTP/1.0 200 OK
  • Date Mon, 17 Apr 2006 235959 GMT
  • Content-Type text/html
  • Content-Length 1354
  • lthtmlgt
  • ltbodygt
  • (more file contents)
  • .
  • .
  • .
  • lt/bodygt
  • lt/htmlgt

65
Reference
  • Beej's Guide to Network Programming
  • http//beej.us/guide/bgnet/

66
Summary
  • Protocols
  • Socket Programming
  • Library Functions
  • Hypertext Transfer Protocol
  • Request
  • Response
Write a Comment
User Comments (0)
About PowerShow.com