The Protocol class provides a set of common services for protocol layers. Each layer has to be a subclass of Protocol and override a number of methods (typically just
up()
,
Down
and
getName
. Layers are stacked in a certain order to form a protocol stack.
Events are passed from lower layers to upper ones and vice versa. E.g. a Message received by the UDP layer at the bottom will be passed to its higher layer as an Event. That layer will in turn pass the Event to its layer and so on, until a layer handles the Message and sends a response or discards it, the former resulting in another Event being passed down the stack.
Each layer has 2 FIFO queues, one for up Events and one for down Events. When an Event is received by a layer (calling the internal upcall ReceiveUpEvent
), it is placed in the up-queue where it will be retrieved by the up-handler thread which will invoke method Up
of the layer. The same applies for Events traveling down the stack. Handling of the up-handler and down-handler threads and the 2 FIFO queues is donw by the Protocol class, subclasses will almost never have to override this behavior.
The important thing to bear in mind is that Events have to passed on between layers in FIFO order which is guaranteed by the Protocol implementation and must be guranteed by subclasses implementing their on Event queuing.
Note that each class implementing interface Protocol MUST provide an empty, public constructor !