240 likes | 374 Views
CS 453 Computer Networks. Lecture 9 Layer 2 – Data Link Layer. Data Link Protocols. The Data Link Layer is responsible for moving frames of bit, via the physical layer, across the communications medium to a destination machine
E N D
CS 453Computer Networks Lecture 9 Layer 2 – Data Link Layer
Data Link Protocols • The Data Link Layer is responsible for • moving frames of bit, • via the physical layer, • across the communications medium • to a destination machine • …not a bit siphon,… these frames of bit don’t just leak across the physical layer and communications medium • We need a procedure or protocol to make this happen
Data Link Protocols • In order to explore the issue of data link protocols we need to make some assumptions (Some of which we will abandon later)
Data Link Protocols • Assumptions • Data link layer services the physical layer and the network layer • Although the implementation of the data link layer can vary – sometimes in hardware, sometimes as a software process, we will consider the physical layer, data link layer and the network layer as three independent processes • Computer A wants to send data to computer B (unidirectional) • Computer A has a ready supply of data to send
Data Link Protocols • Assumptions • Computers A and B do not crash • So we don’t have to deal with crash recovery • Frame transmitted from DLL (Data Link Layer) to DLL is considered pure data to the DLL (excluding its own control information) • DLL on the sending computer • receives a packet from the Network Layer • Adds DLL headers/trailer to it • Hands it off the physical layer
Data Link Protocols • Assumptions • DLL on the receiving computer • receives a frame from the physical layer • Extracts a packet (payload) from the DLL frame • Hands the packet off the physical layer • Network layer never sees a frame – only packet • Data (frames) at DLL level is clean • We have a suitable set of procedures (functions) to implement the protocol
Data Link Protocols • To implement a very simple simplex DLL protocol • Lets look at some definitions (in C)
Data Link ProtocolsBasic Definitions From: Tanenbaum (2003) pg. 203
Data Link ProtocolsBasic Definitions • MAX_PKT 1024 – packet size • typedef enum (false, true) boolean; define a boolean data type • typedef unsigned int seq_nr – frame sequence number • typedef struct{unsigned char data[MAX_PKT];} packet; - define packet as char array • typedef enum {data, ack, nak} frame_kind - define a type to classify the type of frame From: Tanenbaum (2003) pg. 203
Data Link ProtocolsBasic Procedure Definitions From: Tanenbaum (2003) pg. 203
Data Link ProtocolsBasic Procedure Definitions • wait_for_event(event_type *event) – wait for a network event and return the type of event in event • from_network_layer(packet *p) – take a packet from the network layer • to_network_layer(packet *p) – send a packet to the network layer • from_physical_layer(frame *r) – take a frame from the physical layer, return as r • to_physical_layer(frame *s) – send the frame s to the physical layer for transmission From: Tanenbaum (2003) pg. 203
Data Link ProtocolsBasic Procedure Definitions • start_timer(seq_nr k) – start timer – look for timeout • stop_timer(seq_nr k) – stop timer and disable timeout • start_ack_timer(void) – start aux timer, enable ack timeouts • stop_ack_timer(void) – stop aux timer, disable ack timeouts • enable_network_layer(void) – enable the interface to the network layer • disable_network_layer(void) – disable the interface to the network layer • #define inc(k) if (k<MAX_SEQ) k=k+1; else k=0 -- macro to increment a sequence counter modulo(MAX_SEQ) From: Tanenbaum (2003) pg. 203
Data Link ProtocolsSimple Simplex DLL Protocol • General Logic- • receiver - • goes into wait state until a frame_arrival event (only event possible in this simple protocol) • On frame_arrival event receiver fetches frame from the physical layer • passes packet (frame less frame control header/trailer, etc.) to network layer • returns to wait state
Data Link ProtocolsSimple Simplex DLL Protocol • General Logic- • sender – • fetches a packet from the network layer • stores it in frame buffer where it is wrapped with frame header/trailer to make it a frame • passes it to the physical layer for transmission • returns to first step
Data Link ProtocolsSimple Simplex DLL Protocol From: Tanenbaum (2003) pg. 203
Data Link ProtocolsSimple Simplex DLL Protocol • Things to note: • network layers on both machines always ready • No error or lost data between DLLs on the two machines • No acknowledgements – no sequence numbers • No error control – no flow control
Data Link Protocol • Lets get rid of the assumption that the receiver can process frames to packet and move them to the network layer as fast as the sender can send them.. • Not realistic – results in data overruns, lost data • We need some form of flow control • Clock or rate synchronization possible but not good • Us a control frame
Data Link ProtocolSimplex with Flow Control from: Tanenbaum (2003) pg. 207
Data Link ProtocolSimplex with Flow Control • Sender – • fetches a packet • places the packet in a frame • sends the frame to the physical layer for transmission • then, waits for a control frame from the receiver saying it it OK to send another frame • Receiver – • listens for frame arrival event, when it happens • fetches frame from the physical layer • extracts packet from frame and send to network layer, and when completed… • sends control frame to sender to say it is ok to send another frame from: Tanenbaum (2003) pg. 207
Data Link ProtocolSimplex with Flow Control and Error Control from: Tanenbaum (2003) pg. 207
Data Link ProtocolSimplex with Flow and Error Control • Sender – • fetches a packet • places the packet in a frame • sends the frame to the physical layer for transmission • Starts a time-out timer • then, waits for a reply frame • If the wait event was a frame_arrival, fetch frame from physical layer • Check packet in frame for “all clear” acknowledgement, • If “all clear” • turn off time-out timer • Fetch next packet from network layer • Increment frame sequence number • Go to step 2 from: Tanenbaum (2003) pg. 207
Data Link ProtocolSimplex with Flow Control and Error Control from: Tanenbaum (2003) pg. 207
Data Link ProtocolSimplex with Flow and Error Control • Receiver – • Defines expected frame sequence number • Enters wait state for event • If event is frame_arrival • Fetch frame from physical layer • If frame sequence number is what is expected • Extract packet from frame and send to network layer • Increment expected frame counter • Create acknowledgement frame • Send acknowledgement frame to physical layer – and therefore , back to sender from: Tanenbaum (2003) pg. 207