540 likes | 672 Views
Rensselaer Polytechnic Institute CSCI-4210 – Operating Systems David Goldschmidt, Ph.D. Networking and Protocols. Open Systems Interconnection (OSI) Reference Model. What’s the OSI Reference Model ?
E N D
Rensselaer Polytechnic Institute CSCI-4210 – Operating Systems David Goldschmidt, Ph.D. Networking and Protocols
Open Systems Interconnection (OSI) Reference Model • What’s the OSI Reference Model? • The International StandardsOrganization (ISO) proposalfor the standardization ofthe various protocols usedin computer networks • A seven-layer protocol stack
Open Systems Interconnection (OSI) Reference Model • In reality, notall layers arealways used.... • The Internet uses only four layers: • Application • Transport • Network • Physical
Q P Internet traffic • Each layer on the client side logically communicates with the same layer onthe server side server client intermediate router interfaces exist between layers
P Internet messages • Each layer prepends or appends its information in a header or trailer HTTP Request TCP Hdr | HTTP Request IP Hdr | TCP Hdr | HTTP Request Ethernet Hdr | IP Hdr | TCP Hdr | HTTP Request | Cksum
Ethernet • Ethernet encompasses boththe data link layer and thephysical layer • Ethernet (really IEEE 802.3) • Ethernet provides a sharedmedium (multi-access) Ethernet
Ethernet addressing • Every Ethernet interface is assigned a unique 48-bit (hardware) address • Represented as a sequence of 6 hexadecimal bytes delimited by ':' characters: • 00:50:56:9F:27:3E • (use /sbin/ifconfig to see network interfaces) • Also known as MAC address or physical address • Ethernet addresses are assigned tovendors by a central authority
Ethernet frames • Messages are sent over Ethernet via frames: • The Preamble is a sequence ofalternating 1s and 0s for synchronization • In hex: AAAAAAAAAAAAAAAB • Transmitters are required to sendan Interframe Gap of at least 12 octets Preamble Destination Address Source Address Len Data CRC 8 bytes 6 bytes 6 bytes 2 ≤1500 bytes 4 bytes
Sending frames • How does an Ethernet interface know when it can transmit a frame? • CSMA/CD • Carrier Sense (CS): a transmitter can tell when another host is transmitting data • Multiple Access (MA): many transmitters • Collision Detection (CD): a transmitter can tell when another host is transmitting data that collides with its own transmission
Receiving frames • How does an Ethernet interface know when it should receive a frame? • Receivers look at all frames, discarding frames not addressed to them • Receivers only receive frames addressed to them (or broadcast messages) Broadcast destination address isFF:FF:FF:FF:FF:FF
IP (the network layer) • IP is the network layer • IP provides host-to-host delivery serviceof packets (called datagrams) • IP is connectionless • IP is unreliable • IP also provides translation betweendifferent data link protocols
IP addresses • IP addresses are logical addresses atthe network layer • IP addresses are not Ethernet addresses • Why is this important? • IP must be able to provide communication between hosts on different types of networks (i.e. different data link implementations)
IP addressing scheme • An IP address contains information about what network the destination host is on • This enables routing at the network layer • An IP address (IPv4) is a series of 4 octets • 128.113.2.68 (www.rpi.edu) • 128.113.126.13 (www.cs.rpi.edu) • 128.213.56.14 (mary-kate.cs.rpi.edu)
Networks and hosts • Each IP address contains information that identifies the network ID and the host ID • Routing tables rely on IP address classes: from, you guessed it, Wikipedia!
Networks and hosts (again) Decoding IP Addresses: A B CLASS C D 0 NetID HostID 10 NetID HostID 110 NetID HostID 1110 Multicast Address 8 bits 8 bits 8 bits 8 bits
Subnetting • An organization can further subdivide its host (HostID) space into subnets: B 10 NetID HostID 10 NetID SubnetID HostID 8 bits 8 bits 8 bits 8 bits
Subnetting example router Subnet Q 128.213.1.x Subnet R 128.213.2.x Subnet S 128.213.3.x
Subnetting • Other subnetting notes: • Subnets can simplify routing • IP subnet broadcasts have a HostID of all 1s • It is possible to havea single wire networkwith multiple subnets: • How would this work?
IP services • IP provides the following: • Connectionless delivery • i.e. each datagram is individually routed • Unreliable (non-guaranteed) delivery • Fragmentation and reassembly • Only at the source and destination hosts • If fragments are lost, the entire datagram is discarded • Routing • Error detection (via ICMP)
IP datagram structure http://tools.ietf.org/html/rfc1122 8 bits 8 bits 8 bits 8 bits VERS HL Service Fragment Length Datagram ID FLAG Fragment Offset TTL Protocol Header Checksum Source Address max hops Destination Address Options (if any) Data
Transport layer • Two protocols at the Transport Layer: • Transmission Control Protocol (TCP) • Connection-oriented • Reliable byte-streaming • Full-duplex • 3-way handshake (SYN/ACK/ACK)to establish a connection • User Datagram Protocol (UDP) • Connectionless and unreliable click me
UDP datagram structure http://www.ietf.org/rfc/rfc768.txt Source Port Destination Port Length Checksum Data 8 bits 8 bits 8 bits 8 bits
TCP segment structure http://www.ietf.org/rfc/rfc793.txt 8 bits 8 bits 8 bits 8 bits Source Port Destination Port Sequence Number Acknowledgment Number Data Offset Reserved Control Window Urgent Pointer Checksum Options (if any) Data
TCP or UDP? • Which is better? TCP or UDP? • Serving up Web pages • Financial transaction processing • Video-streaming server • File transfer • Email • Chat • Robotic surgerycontrolled remotely Get out of my way, humans!
Protocols • A protocol is an agreed-upon convention that defines how communication occurs between two (or more?) endpoints • All endpoints must “understand” andcorrectly implement the protocol • Protocols must be formally defined, unambiguous, and well-documented • Protocols should address error conditionsand unexpected scenarios
HTTP • HTTP is the protocol for communication between browser apps and Web servers • Web servers are essentially HTTP servers • Protocols have versions • Most clients and servers support version 1.1 • But 1.0 is also in use (maybe also 0.9?!) why?
Q P Interprocess communication
A few relevant RFCs • RFC 1945 is the HTTP 1.0 standard • see http://www.ietf.org/rfc/rfc1945.txt • RFC 2616 is the HTTP 1.1 standard • see http://www.ietf.org/rfc/rfc2616.txt • RFC 2396 is the URI standard • see http://www.ietf.org/rfc/rfc2396.txt
What is HTTP? (i) • From the RFC: • HTTP is an application-levelprotocol with the lightnessand speed necessary fordistributed, hypermediainformation systems
What is HTTP? (ii) • Again from the RFC: • HTTP communication generally takes placeover TCP/IP connections • The default port is TCP 80,but other ports can be used • HTTP is not dependent ona specific transport layer https is typically TCP port 443
Connection-oriented • HTTP defines a very simple structure: • A client sends a request • The server sends a response • HTTP supports multiple request/response exchanges over a single connection • e.g. try using telnet to access a Web server....
HTTP 1.0/1.1 request structure (i) • HTTP requests are line-based ASCII text • Lines must alwaysend with "\r\n"(a.k.a. CRLF) • Headers are optional • A blank line separatesthe request from thecontent Request-Line Header(s) ... ... -- blank line -- Content ... ... ... what content?!
HTTP 1.0/1.1 request structure (ii) • The Request-Line consists of 3 tokens: • Each token is separated by a space character • Though "\r\n" is required by the protocol, "\n" seems to work in practice • The HTTP-Version is either HTTP/1.0or HTTP/1.1 Method URI HTTP-Version\r\n
HTTP request methods (i) Method URI HTTP-Version\r\n • The HTTP request’s Method can be: • GET – request information identified bythe given URI (absolute or relative?) • HEAD – request metadata regardingthe given URI (search engines!) • POST – send (i.e. post) informationto the given URI (e.g. via a form)
HTTP request methods (ii) Method URI HTTP-Version\r\n • The HTTP request’s Method can be: • PUT – store information in the locationidentified by the given URI • DELETE – remove the entity identifiedby the given URI (really?)
HTTP request methods (iii) Method URI HTTP-Version\r\n • The HTTP request’s Method can be: • TRACE – used to trace HTTP forwardingthrough proxies, tunnels, etc. • OPTIONS – determines the capabilities ofthe Web server or the characteristics of the named resource
HTTP request methods (iv) Method URI HTTP-Version\r\n • The GET, HEAD, and POST methods are supported everywhere • HTTP 1.1 servers often supportPUT, DELETE, TRACE, andOPTIONS (but not always!) why won’t this work?!
Universal Resource Identifier • The URI is defined in RFC 2396 • An absolute URI consists of four parts: • A relative URI omits the scheme and server: • The server is assumed(since we’re already connected) scheme://hostname[:port]/path /path which one should we use in our HTTP Request-Line?
URIs in practice • In general, relative URIs are used inthe HTTP Request-Line • HTTP 1.1 servers are required to supportabsolute URIs, but not all do • When using a proxy HTTP server, an absolute URI is required • Or else, the proxy server won’t know whereto find the resource (i.e. document)
Request headers (i) • After the Request-Line, the request might have header lines • Header lines specifyattribute name/valuepairs (e.g. User-Agent:) • Note that HTTP 1.1requires the Host:header always beincluded Request-Line Header(s) ... ... -- blank line -- Content ... ... ...
Request headers (ii) • Request headers provide information to the server about the client • Who is making the request • What kind of client is making the request • What kind of content will be accepted • In HTTP 1.0, all headers are optional • In HTTP 1.1, the Host: header must be sent
Example request headers (i) • Headers can be included in any order: • For GET and HEAD requests, that’s the end(though don’t forget the blank line!) GET /index.html HTTP/1.1 Accept: text/html Host: www.rpi.edu From: goldschmidt@gmail.com User-Agent: Mozilla/4.0 Referer: http://somewhere.else.com/rpi.html -- blank line --
Example request headers (ii) • If a POST request is made, the headers must include Content-Length: POST /~goldsd/changegrade.php HTTP/1.1 Accept: */* Host: www.cs.rpi.edu User-Agent: SecretAgent v3.0 Referer: http://somewhere.devious.com/x.php Content-Length: 36 -- blank line -- rin=660123456&item=midterm&grade=104
HTTP response structure (i) • HTTP responses are line-based ASCII text • A Status-Line isalways returned • A blank line separatesthe response from thecontent • Content is a sequenceof bytes (e.g. HTML,image, text, etc.) Status-Line Header(s) ... ... -- blank line -- Content ... ... ...
HTTP response structure (ii) • The Status-Line consists of 3 tokens: • The HTTP-Version is either HTTP/1.0or HTTP/1.1 (and does not necessarily match the corresponding request) • Response status is represented using a 3-digit Status-Code and a human-readable Message HTTP-Version Status-Code Message
HTTP status codes • Status codes are grouped as follows: • 1xx – Informational • 2xx – Success • 3xx – Redirection • 4xx – Client Error • 5xx – Server Error (click me)
Example status lines • Example status lines include: • HTTP/1.0 200 OK • HTTP/1.0 301 Moved Permanently • HTTP/1.0 400 Bad Request • HTTP/1.0 403 Forbidden • HTTP/1.0 500 Internal Server Error
Response headers (i) • After the Status-Line, the response typically has header lines • Header lines specifyattribute name/valuepairs (e.g. Date:) • As with request headers,response headers endwith a blank line Status-Line Header(s) ... ... -- blank line -- Content ... ... ...
Response headers (ii) • Response headers provide information to the client about the entity (i.e. document) • What kind of entity/document • How many bytes are in the document • How the document is encoded • When the document was last modified • The Content-Type header is required, as is the Content-Length header (usually)
Example response headers • Headers can be included in any order: HTTP/1.1 200 OK Date: Wed, 30 Jan 2002 12:48:17 EST Server: Apache/1.17 Content-Type: text/html Content-Length: 1756 Content-Encoding: gzip -- blank line -- 2309fjfjef0jefe0fje2f0je2f0je2f0e2jfe0fje20fj2e0fjef0jef0e2jf0efje0fje02fje20fje2f0ejf0jef2e09fj209g209fj20gag09ha0gh0agha0gjg0jg