Data Communication and Networks Lecture 2 ADTs in Protocol Design (Ring Buffer, Queue, FSM) September 16, 2004 Joseph Conron Computer Science Department.

Slides:



Advertisements
Similar presentations
Data Structures Through C
Advertisements

Pointers.
Computer Architecture
Categories of I/O Devices
1 Lecture 6: Directory Protocols Topics: directory-based cache coherence implementations (wrap-up of SGI Origin and Sequent NUMA case study)
Data Structures Lecture 13: QUEUES Azhar Maqsood NUST Institute of Information Technology (NIIT)
Umut Girit  One of the core members of the Internet Protocol Suite, the set of network protocols used for the Internet. With UDP, computer.
Computer Networking Error Control Coding
Module R2 CS450. Next Week R1 is due next Friday ▫Bring manuals in a binder - make sure to have a cover page with group number, module, and date. You.
Stacks, Queues, and Deques. 2 A stack is a last in, first out (LIFO) data structure Items are removed from a stack in the reverse order from the way they.
CS 206 Introduction to Computer Science II 03 / 04 / 2009 Instructor: Michael Eckmann.
Fundamentals of Python: From First Programs Through Data Structures
Computer Networks 2 Lecture 2 TCP – I - Transport Protocols: TCP Segments, Flow control and Connection Setup.
Input/Output Management and Disk Scheduling
A CHAT CLIENT-SERVER MODULE IN JAVA BY MAHTAB M HUSSAIN MAYANK MOHAN ISE 582 FALL 2003 PROJECT.
Page: 1 Director 1.0 TECHNION Department of Computer Science The Computer Communication Lab (236340) Summer 2002 Submitted by: David Schwartz Idan Zak.
Device Management.
TCP: Software for Reliable Communication. Spring 2002Computer Networks Applications Internet: a Collection of Disparate Networks Different goals: Speed,
FreeRTOS.
02/06/05 “Investigating a Finite–State Machine Notation for Discrete–Event Systems” Nikolay Stoimenov.
FINAL MPX DELIVERABLE Due when you schedule your interview and presentation.
ICOM 6115©Manuel Rodriguez-Martinez ICOM 6115 – Computer Networks and the WWW Manuel Rodriguez-Martinez, Ph.D. Lecture 26.
ICS 145B -- L. Bic1 Project: Main Memory Management Textbook: pages ICS 145B L. Bic.
Data Structures Using C++ 2E Chapter 8 Queues. Data Structures Using C++ 2E2 Objectives Learn about queues Examine various queue operations Learn how.
Stacks. A stack is a data structure that holds a sequence of elements and stores and retrieves items in a last-in first- out manner (LIFO). This means.
Mohammad Amin Kuhail M.Sc. (York, UK) University of Palestine Faculty of Engineering and Urban planning Software Engineering Department Computer Science.
I/O Computer Organization II 1 Interconnecting Components Need interconnections between – CPU, memory, I/O controllers Bus: shared communication channel.
Queues, Pipes and Sockets. QUEUE A structure with a series of data elements with the first element waiting for an operation Used when an element is not.
Week 4 - Monday.  What did we talk about last time?  Queues  Implementing queues with circular arrays.
Standard Template Library The Standard Template Library was recently added to standard C++. –The STL contains generic template classes. –The STL permits.
Stacks and Queues. Announcements USACO Open competition results are out o Congrats to Johnny for scoring 2nd in the US USACO Finalists are also announced.
Kovács Zita 2014/2015. II. félév DATA STRUCTURES AND ALGORITHMS 26 February 2015, Linked list.
CE Operating Systems Lecture 17 File systems – interface and implementation.
Linked List by Chapter 5 Linked List by
Chapter 16 – Data Structures and Recursion. Data Structures u Built-in –Array –struct u User developed –linked list –stack –queue –tree Lesson 16.1.
File Systems cs550 Operating Systems David Monismith.
Data Design and Implementation. Definitions Atomic or primitive type A data type whose elements are single, non-decomposable data items Composite type.
Chapter 5 Linked List by Before you learn Linked List 3 rd level of Data Structures Intermediate Level of Understanding for C++ Please.
1 CSE 5346 Spring Network Simulator Project.
2005MEE Software Engineering Lecture 7 –Stacks, Queues.
Time Management.  Time management is concerned with OS facilities and services which measure real time.  These services include:  Keeping track of.
1 Kyung Hee University Chapter 11 User Datagram Protocol.
Silberschatz, Galvin and Gagne ©2011 Operating System Concepts Essentials – 8 th Edition Chapter 2: The Linux System Part 5.
Govt. Engineering College- Gandhinagar. It is all about……  STATE MACHINE.
© Oxford University Press All rights reserved. Data Structures Using C, 2e Reema Thareja.
Review Array Array Elements Accessing array elements
Data Structures Using C, 2e
Queues.
Week 4 - Monday CS221.
Data Structure By Amee Trivedi.
Queue ADT (Abstract Data Type) N …
Design & Analysis of Algorithm Priority Queue
Communication Networks: Technology & Protocols
March 29 – Testing and Priority QUeues
Lectures Queues Chapter 8 of textbook 1. Concepts of queue
Circular Buffers, Linked Lists
CS4470 Computer Networking Protocols
CSC 143 Queues [Chapter 7].
CS703 - Advanced Operating Systems
Cs212: Data Structures Computer Science Department Lecture 7: Queues.
Chapter 2: The Linux System Part 5
CS210- Lecture 5 Jun 9, 2005 Agenda Queues
Introduction to Data Structure
CS4470 Computer Networking Protocols
Transport Protocols: TCP Segments, Flow control and Connection Setup
Stacks, Queues, and Deques
Transport Protocols: TCP Segments, Flow control and Connection Setup
Transport Layer 9/22/2019.
Chapter 13: I/O Systems “The two main jobs of a computer are I/O and [CPU] processing. In many cases, the main job is I/O, and the [CPU] processing is.
Presentation transcript:

Data Communication and Networks Lecture 2 ADTs in Protocol Design (Ring Buffer, Queue, FSM) September 16, 2004 Joseph Conron Computer Science Department New York University

Common Issues in Design 1.How to handle data that arrives from two independent sources. a)Down from the higher layer b)Up from the lower layer 2.How to implement the protocol When building protocol software, there are two common problems that you’ll face:

Data from Two Sources: Down from the Higher Layer (HL) –Higher layer (HL) sends requests (control and data) –Cannot always process the request immediately, so we need a place to hold the request. –We may get “many” HL users (e.g., many TCP, only one IP) –Requests may need to be processed out of order (out of band, QOS, etc).

Data from Two Sources: Up from the Lower Layer (LL) –Lower layer sends requests, data, and indications. –Data must be separated from requests and indications. –Read requests from HL may use different data boundaries than LL. –LL may be providing data at same time as HL wants to read it.

N-1 Ring Buffer of Size N Inititial State Input: 0 Output: 0

N-1 Ring Buffer of Size N New Element Arrives Input: 1 Output: 0 Element 0

N-1 Ring Buffer of Size N New Element Arrives Input: 2 Output: 0 Element 0 Element 1

N-1 Ring Buffer of Size N Read next (element 0) Input: 2 Output: 1 Element 0 Element 1 Read next (element 1) Input: 2 Output: 2

N-1 Ring Buffer of Size N After Nth input: Input: 0 Output: 2 Element 0 Element 1 How many more input elements can we accept? Element 2 Element N-1

Ring Buffer Spec (1 of 3) Let B be a buffer. Let S be the size of the buffer B in bytes. Let I be an index into the buffer where the producer will store the next new byte of data. Let O be the index of the next byte that the consumer should remove from the buffer. Let N be the number of unconsumed bytes in the buffer. Define % as the modulus operator. Initially, I = O = N = 0. The buffer is full (has no room for new data) when N == S. The available space (for new data) A = S - N

Ring Buffer Spec (2 of 3) To Add m bytes of data from buffer D to the buffer B the producer will: (1) Check that m <= A (if not an error has occurred) (2) put bytes into the buffer using this model: int j = I; I = (I+m)%S N += m; for (int q = 0; q < m; q++) B[(j+q)%S] = D[q]

Ring Buffer Spec (3 of 3) To remove r bytes from the buffer B to buffer D, the consumer will: (1) Check that r <= N. If not, adjust r (r = N) or signal error. (2) take bytes from the buffer using this model: int j = O; O = (O+r)%S N -= r for (int q = 0; q < r; q++) D[q] = B[(j+q)%S]

Ring Buffer: Making it thread-safe So, you see that the idea is that the input (I) and output (O) pointers change continuously from the beginning of the buffer to the end and then wrap around back to the beginning again. Conceptually, it appears as if the end of the buffer is connected back the front of the buffer as if to form a ring (or circle). We enforce that the input pointer never tries to overtake the output pointer! To make these two methods thread safe, we need only to protect the 3 lines of code that update the class variables O, N, I: NOT the loops that move data! This is a better real-time approach than serializing access to the loop itself, or worse, the entire object.

Ring Buffer Characteristics Elements are all same size and type –Elements are typically primitives (byte, int, etc) but can be pointers or even structures. Finite –Fixed space must be allocated a priori Low overhead –No “per element” costs like we have in a Queue Elements MUST be processed in order.

Queue Elements are linked together in a list. List can be single (forward) or double (forward and backward) linked. Queue Control Block contains (as a minimum) pointer to first element (head) and last element (tail) Queues are almost always used as FIFOs, but can support iteration, random access, and reverse (LIFO) processing

Queue (Singly Linked) head tail Queue Control Block a z bznull element aelement belement z Forward link Payload Payload can be ANY object or structure. Elements need not contain similar payloads.

Queue (Doubly Linked) head tail Queue Control Block a z bznull element aelement belement z banull Forward link Payload Backward link

Queue Operations Required Operations –Put (add to tail) –Get (get from head) Nice to Have Operations –Remove (remove specific element) –Insert (add element after a specific element) Deluxe Operations –Peek (non-destructive Get) –Put to head –Get from tail –Iterate (head to tail or tail to head)

Queue Characteristics Not fixed in length (“unlimited” in length) Does not require pre-allocated memory Allows processing of elements in arbitrary order Can accommodate elements of different type Additional per element cost (links)

Queue or Ring Buffer? Stream data: Use a ring buffer –Arriving elements are primitives that make up a data “stream” (no record boundaries). TCP data is an example. Service requests: Use a queue –Arriving elements are requests from a user layer (or clients) and must be processed individually.

What is a FSM? Let’s define the idea of a “machine” –organism (real or synthetic) that responds to a countable (finite) set of stimuli (events) by generating predictable responses (outputs) based on a history of prior events (current state). A finite state machine (fsm) is a computational model of a machine.

FSM Elements States represent the particular configurations that our machine can assume. Events define the various inputs that a machine will recognize Transitions represent a change of state from a current state to another (possibly the same) state that is dependent upon a specific event. The Start State is the state of the machine before is has received any events

Machine Types Mealy machine –one that generates an output for each transition, Moore machine –one that generates an output for each state. Moore machines can do anything a Mealy machine can do (and vice versa). In my experience, Mealy machines are more useful for implementing communications protocols. The fsm that I’ll provide is a Mealy machine.

State Diagram

From State Diagram to FSM Identify –states –events –Transitions –Actions (outputs) Program these elements into an FSM Define an event classification process Drive the events through the FSM Example ….