Presentation is loading. Please wait.

Presentation is loading. Please wait.

IHA præsentation1 Protocol Design Lesson 4. IHA præsentation2 Outline for today Guidelines for implementing protocols Protocol Design Patterns.

Similar presentations


Presentation on theme: "IHA præsentation1 Protocol Design Lesson 4. IHA præsentation2 Outline for today Guidelines for implementing protocols Protocol Design Patterns."— Presentation transcript:

1 IHA præsentation1 Protocol Design Lesson 4

2 IHA præsentation2 Outline for today Guidelines for implementing protocols Protocol Design Patterns

3 IHA præsentation3 Guidelines for implementing protocols

4 Where is the protocol entity positioned in the complete protocol stack Clear picture of the services our protocol provides Procedure/functionality descriptions Clear picture of which other protocol entities our protocol interfaces to Service Access Points, service primitives or other Definition of messages/PDUs ASN.1, Augmented BNF or other Protocol Specification Ready Requirements to lower layer services IHA præsentation4

5 Guidelines for implementing protocols Consider Task and module decomposition Shall our protocol run as separate task? Interaction with the Operating System Memory management Dynamic memory allocation needed? Timer management Are timers needed? (Inter process communication) Queues, etc. (Security management) Passwords, authentication where are they stored? IHA præsentation5

6 Guidelines for implementing protocols Protocol states Finite State Machine (State-event machines) Identify all states and all internal events –How do we do this? –Message sequence charts (sequence diagrams) for normal scenarios –MSCs for timer expiry scenarios –MSC for abnormal scenarios IHA præsentation6

7 7 Guidelines Task and module decomposition ? Protocol functions that need to manage their own timers may have their own task Protocol functions that need to have their own transmit/receive messages to/from peer protocol entities may also have their own task However, consider context switching overhead

8 Traditionally…… Tasks

9 IHA præsentation9 Guidelines Designing for Reentrancy AVOID USING GLOBAL DATA STRUCTURES

10 Guidelines for implementing protocols We have protocol related design patterns? Are they useful? Can they handle all kind of protocols? IHA præsentation10

11 IHA præsentation11 Protocol Design Patterns

12 IHA præsentation12

13 IHA præsentation13 Protocol Layer Design Pattern Motivation A typical protocol layer interfaces with an upper and a lower layer of the protocol stack In most designs there is a lot of dependency bewteen different layers of the protocol => inflexibility The Protocol Layer Design Pattern addresses these limitations by decopling the individual protocol layers

14 IHA præsentation14 Protocol Layer Design Pattern Structure Communication between layers takes place using standard interfaces defined by a Protocol Layer base class All implementations of the protocol layer inherit from this class The inheriting class should implement the standard interfaces: Transmit is invoked by the upper layer to transfer a packet to the lower layer Handle Receive is invoked by the lower layer to transfer a packet to the upper layer

15 IHA præsentation15 Protocol Layer Design Pattern Example Transmitting Direction: 1. The application invokes the Network layer's Transmit method. 2. The Network layer performs its actions and invokes the Transmit method for the lower layer. 3. This invokes the Datalink layers transmit method. The Datalink layer performs the layer specific actions and invokes the lower layer's Transmit method. 4.The Physical layer's Transmit method is invoked. This layer programs the appropriate hardware device and transmits the message.

16 IHA præsentation16 Protocol Layer Design Pattern Participants Protocol Layer: This is the base class for all protocol layers. The individual layers interface with each other via pointers to this class. The actual type of the upper layer and lower layer classes is not known to the implementers of a certain layer. Protocol Packet: This class manages addition and removal of headers and trailers for various protocol layers.

17 IHA præsentation17 Protocol Layer Design Pattern Consequences The implementation of one layer is completely decoupled from the adjacent layers Layers can be added and removed without needing any changes to the code for individual layers an IPsec layer can be added between IP and physical layer without any changes to the IP or physical layer code A single layer could interface with multiple upper and lower layer protocols using the same interface an IP layer could interface with an ATM or Ethernet physical layer. No changes to the IP layer needed.

18 IHA præsentation18 Protocol Layer Design Pattern #ifndef PROTOCOL_LAYER_H #define PROTOCOL_LAYER_H #include class Protocol_Packet;Protocol_Packet class Protocol_LayerProtocol_Layer { Protocol_Layer *m_p_Lower_Layer;Protocol_Layerm_p_Lower_Layer Protocol_Layer *m_p_Upper_Layer;Protocol_Layerm_p_Upper_Layer public: Protocol_Layer()Protocol_Layer { m_p_Lower_Layer = NULL;m_p_Lower_Layer m_p_Upper_Layer = NULL;m_p_Upper_Layer } virtual void Transmit(Protocol_Packet *p_Packet) = 0;TransmitProtocol_Packet virtual void Handle_Receive(Protocol_Packet *p_Packet) = 0;Handle_ReceiveProtocol_Packet void Set_Upper_Layer(Protocol_Layer *p_Layer)Set_Upper_LayerProtocol_Layer { m_p_Upper_Layer = p_Layer; }m_p_Upper_Layer void Set_Lower_Layer(Protocol_Layer *p_Layer)Set_Lower_LayerProtocol_Layer { m_p_Lower_Layer = p_Layer; }m_p_Lower_Layer Protocol_Layer *Get_Upper_Layer() constProtocol_LayerGet_Upper_Layer { return m_p_Upper_Layer; }m_p_Upper_Layer Protocol_Layer *Get_Lower_Layer() constProtocol_LayerGet_Lower_Layer { return m_p_Lower_Layer; }m_p_Lower_Layer }; #endif

19 IHA præsentation19 Protocol Packet Design Pattern Motivation A protocol stack generally handles multiple layers of a protocol Each layer adds its own headers and trailers Size of the buffer containing the message keeps changing In most implementations this results in each layers allocating a new buffer to adjust the changed buffer size The Protocol Packet Design Pattern addresses this issue with a simple and efficient buffering architecture

20 IHA præsentation20 Protocol Packet Design Pattern Structure This pattern is implemented by just one class, the Protocol Packet. This class works on a raw buffer that is capable of holding the entire packet with protocol headers added for all the layers in the protocol stack. The raw buffer is dynamically partitioned into three regions: Header Body Trailer As the message moves from one layer the other the location of the different regions is adjusted. Let see:

21 IHA præsentation21 Protocol Packet Design Pattern Transmitting a Packet 1.The Protocol Packet object is constructed with just the application body. Notice that the body does not start from the first byte of the buffer. The application body is placed at an offset, leaving enough space for the protocol headers. At this point, the header and trailer regions are of zero size. 2.The packet is passed to Layer 3. This layer adds its own headers and trailers regions into the same buffer. 3.Layer 2 adds its own headers and trailers regions. The previous header and trailer regions get merged into the body 4.Layer 1 adds headers and trailers. Again, the body region grows to accommodate the headers and trailers for Layer 2 5.Finally, zero length header and trailers are added, resulting in the entire packet moving to the body region. At this point the header and trailer regions are of 0 length.

22 IHA præsentation22 Protocol Packet Design Pattern 1.The received packet is created with all the bytes in the body region of the message. At this point, the header and trailer regions are of zero length. 2.Layer 1 extracts its headers and trailer regions. The two regions have been carved out of the received body region. The size of the body region is reduced. 3.Layer 2 also extracts its own header and trailer regions. Again shrinking the body region. 4.Layer 3 similarly extracts its header and trailer regions. Shrinking the body to the original application body. 5.The application extracts a zero length header and trailer. This leaves only the packet with only the body region. Receiving a Packet

23 IHA præsentation23 Protocol Packet Design Pattern Participants This pattern is implemented by just one class, the Protocol Packet. The class has three internal constituent regions. These regions are defined by the Region private structure. Collaboration The Protocol Packet class contains the header, body and trailer regions. This relationship is shown in the following collaboration graph:

24 Protocol Packet Design Pattern class Protocol_PacketProtocol_Packet { enum { MAXIMUM_PACKET_LENGTH = 1500}; struct RegionRegion { int offset;offset int length;length }; Region m_header;Regionm_header Region m_body;Regionm_body Region m_trailer;Regionm_trailer char m_buffer[MAXIMUM_PACKET_LENGTH];m_buffer … }

25 IHA præsentation25 Protocol Packet Design Pattern Consequences Using this pattern provides allows efficient handling of packets as different layers are added or extracted. A single buffer is used across layers. This reduces the overhead in buffer processing In addition, this pattern brings uniformity to the design of the protocol stack.

26 IHA præsentation26 Protocol Packet Design Pattern Implementation Add_Header: Add the header to the transmit packet. Add_Trailer: Add the trailer to the transmit packet. Extract_Header: Extract the header from the received packet. Extract_Trailer: Extract the trailer from the received packet. Get_Header: Get a pointer to the current packet header. Get_Body: Get a pointer to the current packet body. Get_Trailer: Get a pointer to the current packet trailer. Get_Length: Get the total length. The length includes the header, body and trailer. The Protocol Packet class consists of the following methods:

27 IHA præsentation27 Protocol Stack Design Pattern We have already seen that Protocol Layer and Protocol Packet provide a standardized interface between different layers of a protocol.Protocol LayerProtocol Packet The Protocol Stack design pattern takes advantage of the layer decoupling and provides a mechanism for dynamic insertion and removal of protocol layers from a stack

28 IHA præsentation28 Protocol Stack Design Pattern Motivation Protocol stacks tend to be rigid in design and protocol layers cannot be dynamically added or removed from a protocol stack Limits the use of protocol stacks in the even changing world of protocol standards Example: The user has enabled encryption and this requires the sandwiching of the encryption layer between the network layer and the data-link layer The Protocol Stack Design Pattern addresses this issue and introduces a flexible architecture for dynamic addition and removal of protocol layers

29 IHA præsentation29 Protocol Stack Design Pattern Structure The Protocol Stack Design Pattern is implemented by the Protocol Stack class. This class maintains a doubly linked list of active layers. Participants The key actors of this design pattern: Protocol Stack: This class maintains a doubly linked list of Protocol layers. It supports dynamic addition and removal of protocol layers. Protocol Layer: This is the base class for all protocol layers. The individual layers interface with each other via pointers to this class. The actual type of the upper layer and lower layer classes is not known to the implementers of a certain layer.

30 IHA præsentation30 Protocol Stack Design Pattern Consequences The Protocol Stack design pattern breaks down the rigid protocol layer structure and provides a very flexible solution where layers can be dynamically added and removed from the stack. Examples

31 IHA præsentation31 Protocol Stack Design Pattern A debug pass-through layer that displays the messages being exchanged between the datalink layer and the physical layer

32 IHA præsentation32 Protocol Stack Design Pattern A loopback layer that facilitates the testing of the datalink and network layers by just looping back all transmitted messages back for receive

33 IHA præsentation33 Protocol Stack Design Pattern An echo-back layer allows the protocol stack to emulate a node by just echoing back all higher layer messages back for transmission.

34 IHA præsentation34 Protocol Stack Design Pattern An encryption layer sandwiched between the datalink and physical layers. This layers encrypts and decrypts data that is passed between these layers

35 IHA præsentation35 Protocol Stack Design Pattern Implementation Handle_Transmit: This handler is invoked by the application to transmit messages using the protocol stack. Handle_Recieve: This handler is invoked by the device to pass received messages to the protocol stack. Add_Layer: Add a protocol layer at a specific position in the protocol stack. Remove_Layer: Remove a layer from the protocol stack. The Protocol Stack is implemented as a single class. The class maintains a doubly linked list of Protocol Layers. Important methods of the class are:

36 IHA præsentation36 Protocol Stack Design Pattern Discussion: Any issues in implementing these patterns?

37 Protocol Stack Design Pattern UMTS:

38 Protocol Stack Design Pattern DECT

39 Protocol Stack Design Pattern ZigBee

40 IHA præsentation40 Protocol Stack Design Pattern 010010100111000000 Timer running Handle Receive Transmit Timeout – send NWK PDU When is control released so we can handle timeout?

41 Protocol Stack Design Pattern

42 IHA præsentation42 Receive Protocol Handler Pattern Motivation Different sliding window protocols have a lot of similarity. This similarity can be captured in a common design pattern for their implementation. Here we will focus on the receive side of the protocol. Applicability Receive Protocol Handler Pattern can be used to implement protocols at any layer.

43 IHA præsentation43 Receive Protocol Handler Pattern Structure This pattern is implemented by just one class, Receive Protocol Handler. This class receives the packets from the other end and performs the following operations: Check validity of the received packet Ask Transmit Protocol Handler to acknowledge the received packet Check if the remote end has acknowledged that was sent by Transmit Protocol Handler. Inform Transmit Protocol Handler about acknowledged packet.

44 Receive Protocol Handler Pattern To achieve this functionality, the following sequence numbers are maintained: Next Expected Sequence Number: Transmit sequence number expected in the next packet from the remote end. Last Acknowledged Sequence Number: Last receive sequence number received from the remote end. This sequence number is used by the remote end to acknowledge packets. Participants The Transmit and Receive Protocol Handlers are the main participants in this pattern. The received messages are added to the Receive Queue. The received message will be picked by the next higher layer. IHA præsentation44

45 Transmit Protocol Handler Motivation Different sliding window protocols have a lot of similarity. This similarity can be captured in a common design pattern for their implementation. Here we will focus on the transmit side of the protocol. Applicability Transmit Protocol Handler Pattern can be used to implement protocols at any layer. IHA præsentation45

46 Transmit Protocol Handler Structure This pattern provides a framework for implementing a sliding window protocol. The Transmit Protocol Handler receives a packet from the higher layer and transmits it to the lower layer after assigning a sequence number The packet is also stored in an internal retransmission buffer. The packet is removed from the retransmission queue if the remote end acknowledges the packet. The Transmit Protocol Handler retransmits the packet if it times out for an acknowledgement. IHA præsentation46

47 Transmit Protocol Handler Participants The key actors of this design pattern: Transmit_Protocol_Handler: Class that manages the transmit end of the protocol. This class interfaces with the receive end and the retransmission queue. Transmit_Queue: Enqueues messages that wait for transmission when the window is full. Retransmission_Buffer: Manages buffers until an acknowledgement is received from the other end. The messages are retransmitted If no ack is received,. IHA præsentation47

48 Example – Data Link Layer

49 A packet is received from the upper layer 1.The upper layer uses its "Lower Layer" pointer to invoke the Transmit method for the lower layer. The "Protocol Packet" to be transmitted is passed to the Transmit method. 2.This invokes the Datalink Layer's Transmit method. 3.The Datalink Layer passes the "Protocol Packet" to the "Transmit Protocol Handler" object. 4.The "Transmit Protocol Handler" processes the "Protocol Packet" and adds the datalink layer header to the packet. 5.The "Transmit Protocol Handler" uses its parent layer to obtain a pointer to the lower layer. 6.The "Protocol Packet" is passed to the lower layer by invoking the Transmit method. IHA præsentation49

50 Example – Data Link Layer A packet is received from the lower layer 1.The lower layer uses its "Upper Layer" pointer to invoke the "Handle Receive" method for the upper layer. The received "Protocol Packet" is passed to the "Handle Receive" method. 2.This invokes the Datalink Layer's "Handle Receive" method. 3.The Datalink Layer passes the "Protocol Packet" to the "Receive Protocol Handler" object. 4.The "Receive Protocol Handler" object uses the parent layer to obtain a pointer to the upper layer. 5.The "Protocol Packet" is passed to the higher layer by invoking the "Handle Receive" method. IHA præsentation50

51 State Pattern


Download ppt "IHA præsentation1 Protocol Design Lesson 4. IHA præsentation2 Outline for today Guidelines for implementing protocols Protocol Design Patterns."

Similar presentations


Ads by Google