next up previous contents
Next: Adding new protocols to Up: Making new protocols Previous: Node Process Control Block   Contents

Implementation

The framework of all protocol source codes in LYDIAN is as follow:

Figure 13: The framework of protocol source code
\begin{figure}
\hrule\begin{tabbing}
{\bf typ}\={\bf edef struct} \{ \\
\>{\em...
...\em /* Below are your own procedures */} \\
...
\end{tabbing}\hrule\end{figure}

where processes is one of globle variables in LYDIAN.


With the Broadcast with ACK protocol, we need two local variables parent to keep the sender and ack to keep a list of receivers. Therefore, we have the first part of code as in Figure 14

Figure 14: Initialization part of protocol Broadcast with ACK
\begin{figure}
\hrule\begin{tabbing}
{\bf typ}\={\bf edef struct} \{ \\
\>{\bf...
...\
\>\>$init\_list(REG[i].ack)$;\\
\>\}\\
\}
\end{tabbing}\hrule\end{figure}

where init_list is one of available routines in LYDIAN (Section 7.2).

From Table 1, we can see that the protocol needs three procedures corresponding to its three cells. Moreover, an additional procedure is needed to start the protocol, start(). These four procedures are pictured in Figure 15.

start()
is used to initialize the simulation by only one process which is the initiator in network file description. Therefore, the network descritption file used for the protocol must have only one initiator. The procedure sends BRD messages for all its adjacent nodes and keeps track of these messages in list ack in other to wait for necessary ACK messages.

sleeping_brd()
contains actions the process must execute in the case that it receives a BRD message when its state is SLEEPING. If in the network the node the process runs on has only one adjacent node, the sender, the process will reply with ACK message immediately. Otherwise, it sends further BRD messages to all other adjacent nodes (except sender) and keeps track of these BRD messages in list ack.

waiting_brd()
replies the sender with ACK message immediately as described in the algorithm.

waiting_ack()
deletes the sender from list ack. If the list is empty and the process has no parent, the simulation finishs because the process is the initiator. If the list is empty and the process has a parent, it sends ACK meassage back to its parent.

Figure 15: Procedures of protocol Broadcast with ACK
\begin{figure}
\hrule\begin{tabular}{p{3in}p{3in}}
\begin{tabbing}
{\bf sl}\={\b...
...$new\_state = WAITING$; \\
\>\}
\}
\end{tabbing}\end{tabular}\hrule\end{figure}

After programming the protocol code, we need to add the code into LYDIAN so that it becomes a protocol in LYDIAN library.


next up previous contents
Next: Adding new protocols to Up: Making new protocols Previous: Node Process Control Block   Contents
Ha Hoai Phuong
2002-11-11