Protocols

  • View
    65

  • Download
    0

Embed Size (px)

DESCRIPTION

Protocols. Application Level Protocol Design. atomic units used by protocol: " messages " encoding reusable , protocol independent, TCP server, LinePrinting protocol implementation. Protocol Definition. set of rules, governing the communication details between two parties (processes) - PowerPoint PPT Presentation

Text of Protocols

Protocols

Protocols1SPL/2010

SPL/2010

Application Level Protocol Designatomic units used by protocol: "messages"encoding reusable, protocol independent, TCP server, LinePrinting protocol implementation2SPL/2010

SPL/2010

Protocol Definitionset of rules, governing the communication details between two parties (processes)different forms and levels; protocols for exchange bits across a wireprotocols governing administration of super computers. application level protocols - define interaction between computer applications3SPL/2010

SPL/2010

Protocol Communication Rulessyntax: how do we phrase the information we exchange.semantics: what actions/response for information received.synchronization: whose turn it is to speak (given the above defined semantics).

4SPL/2010

SPL/2010

Protocols Skeletonall protocols follow a simple skeleton.exchange information using messages, which define the syntax. difference between protocols: syntax used for messages, and semantics of protocol.

5SPL/2010

SPL/2010

Protocol Initialization (hand-shake) communication begins when party sends initiation message to other party. synchronization - each party sends one message in a round robin fashion.

6SPL/2010

SPL/2010

TCP 3-Way HandshakeEstablish/ tear down TCPsocket connections computersattempting to communicate can negotiate network TCP socket connection both ends can initiate and negotiate separate TCPsocket connections at the same time7SPL/2010

SPL/2010

TCP 3-Way Handshake (SYN,SYN-ACK,ACK)8

SPL/2010

SPL/2010

Asendsa SYNchronize packet to BB receives A'sSYNBsendsaSYNchronize-ACKnowledgementA receives B'sSYN-ACKAsendsACKnowledgeB receivesACK.TCP socket connection isESTABLISHED.

9SPL/2010

SPL/2010

HTTP (Hyper Text Transfer Protocol) exchanging special text files over the network. brief (not complete) protocol description:synchronization: client initiates connection, sends single request, receive reply from server.syntax: text based, seerfc2616.semantics: server either sends to the client the page asked for, or returns an error.

10SPL/2010

SPL/2010

What next?syntax and semantics aspects of protocols. assume: synchronization works in round robin, i.e., each party sends one message at a time.

11SPL/2010

SPL/2010

Message FormatProtocol syntax: message is the atomic unit of data exchanged throughout the protocol. message = letterconcentrate on the delivery mechanism.12SPL/2010

SPL/2010

Framingstreaming protocols - TCPseparate between different messagesall messages are sent on the same stream, one after the other, receiver should distinguish between different messages. Solution: messageframing - taking the content of the message, and encapsulating it in a frame (letter - envelop). 13SPL/2010

SPL/2010

Framing what is it good for?sender and receiver agree on the framing method beforehand framing is part of message format/protocol enable receiver to discover in a stream of bytes where message starts/ends

14SPL/2010

SPL/2010

Framing how?Simple framing protocol for strings:special FRAMINGcharacter (e.g., a line break). each message is framed by twoFRAMING characters at beginning and end. message will not contain aFRAMINGcharacterframing protocol by adding a special tag at start and end. message can be framed using / strings. avoid having/in message body.15SPL/2010

SPL/2010

Framing how?framing protocol by employing a variable length message formatspecial tag to mark start of a framemessage contains information on message's length

16SPL/2010

SPL/2010

17

SPL/2010

SPL/2010

Textual dataMany protocols exchange data in textual form strings of characters, in character encoding, (UTF-8)very easy to document/debug - print messages Limitation: difficult to send non-textual data. how do we send a picture? video? audio file? 18SPL/2010

SPL/2010

Binary Datanon-textual data is calledbinary data. all data is eventually encoded in "binary" format, as a sequence of bits"binary data" = data that cannot be encoded as a readable string of characters?19SPL/2010

SPL/2010

Binary DataSending binary data in raw binary format in a stream protocol is dangerous.may contain any byte sequence, may corrupt framing protocol. Devising a variable length message format.

20SPL/2010

SPL/2010

Base64 Encoding Binary Data encode binary data using encoding algorithmBase64 encoding - encodes binary data into a string Convert every 2 bytes sequence from the binary data into 3 ASCII characters. used by many "standard" protocols (email to encode file attachments of any type of data).21SPL/2010

SPL/2010

Encoding using PocoIn C++, Poco library includes module for encoding/decoding byte arrays into/from Base64 encoded ASCII data. functionality is modeled as a stream "filter" performs encode/decode on all data flowing through the stream classesBase64Encoder/Base64Decoder.

22SPL/2010

SPL/2010

Encoding in Javaiharder library. modeled as stream filters (wrappers around Input/Output Java streams).

23SPL/2010

SPL/2010

Encoding binary dataadvantage: any stream of bytes can be "framed" as ASCII data regardless of character encoding used by protocol. disadvantage - size of the message, increased by 50%.

(we will use UTF-8 encoding scheme)

24SPL/2010

SPL/2010

Protocol and Server Separation25SPL/2010

SPL/2010

Protocol and Server Separationcode reuse is one of our design goals!generic implementation of server, which handles all communication detailsgeneric protocol interface:handles incoming messagesimplements protocol's semanticsgenerates the reply messages. 26SPL/2010

SPL/2010

Protocol-Server Separation: protocol objectprotocol object is in charge of implementing expected behavior of our server:What actions should be performed upon the arrival of a request. requests may be correlated one to another, meaning protocol should save an appropriate state per client.

27SPL/2010

SPL/2010

Example: authenticated sessionprotocols require user authentication (login), only authorized users can perform certain actions. protocol isstatefull- serving requests of client can be in at least 2 distinct states: authenticated (user has already logged in) non-authenticated (user has not provided login). by state of the protocol object, behavior of protocol object is different28SPL/2010

SPL/2010

Protocol and Server Separationseparate different tasks server must perform. Accept new connections from new clients.Receive new bytes from connected clients.Parse incoming bytes from clients into messages ("de-serialization" / "unframing").Dispatch message to right method on server side to execute requested operation.Send back an answer to a connected client after an action has been executed.

29SPL/2010

SPL/2010

a software architecture that separates tasks into separate interfaces30

SPL/2010

SPL/2010

The key participants in this architecture are:Tokenizer - syntax, tokenizing a stream of data into messages.MessagingProtocol semantics, handling received messages and generating responses.

31SPL/2010

SPL/2010

implementations of interfaces: generic serverMessageTokenizerLinePrinitingProtocol,

32SPL/2010

SPL/2010

Interfacesimplement separation between protocol and server. Define:message (can be encoded in various ways: Base64, XML, text). Our messages encoded as plain UTF-8 text.framing of messages - delimiters between messages sent in stream.protocol interface which handles each individual message.

33SPL/2010

SPL/2010

ConnectionHandlerserver accepted new connection from client. server creates ConnectionHandler- will handle all incoming messages from this client. ConnectionHandler- maintains state of connection for specific client Ex: user perform "login" -ConnectionHandler object remembers this in its state34SPL/2010

SPL/2010

ConnectionHandler - SocketConnectionHandlerhas access to Socket connecting server to client process.TCP server - Socketconnection is viewed as a pair ofInputStreamandOutputStream. streams of bytes client and the server exchange a bunch of bytes.

35SPL/2010

SPL/2010

Tokenizer - in charge of parsing a stream of bytes into a stream of messagesTokenizerinterface: filter between Socket input stream and protocolProtocol accesses the input stream only through the tokenizer. instead of "seeing" a stream of bytes, it sees a stream of messages. Many libraries model such "filters" on streams as wrappers around a lower-level stream.OutputStreamWriter - wraps stream and performs encoding from one character encoding to anotherBufferedReader - adds a layer of buffering around a non-buffered input stream.

36SPL/2010

SPL/2010

Tokenizersplits incoming bytes from the socket into messages. For simplicity, we model the Tokenizer as an iteratorprotocol will see the input stream from the socket as an iterator over messages (instead of an iterator over bytes).

37SPL/2010

SPL/2010

38

SPL/2010

SPL/2010

Messaging Protocolprotocol interface wraps together: socket and Tokenizer Pass incoming messages to MessagingProtocol - execute action requested by client. look at the message and decide on actiondecision may depend on the state Once the action is performed - answer back from theMessagingProtocol.

39SPL/2010

SPL/2010

40

SPL/2010

SPL/2010

We use aStringto pass data from Tokenizer to Protocol