EventHelix.com: CASE Tools; Real-time and Embedded System Design; Object Oriented Design EventStudio 2.0: System Engineering CASE ToolEventStudio 2.5
Sequence diagram based system design and modeling
Home   What's New   EventStudio 2.5   Real-time Mantra   Thought Projects   Contact Us
Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

Routing_Table Class Reference

#include <Routing_Table.h>

List of all members.


Detailed Description

Routing Table is another pattern that can easily be implemented using map.

In this routing table, a mapping is maintained from the Node Id to the Link Id. Each routing table entry is specified as a pair of Node Id and Link Id. Given a Node Id, the Routing Table returns the Link Id. We could write pretty much the same code as Terminal_Manager to implement it, but we will take a different route to implement the same functionality. This time we will use another feature of STL, the iterator.

Think of iterators as pointers on steroids. Iterators are special types defined by the map that give the appearance of a pointer. Iterators allow you to iterate through the complete data structure. For example the iterator in a map allows you to iterate through the complete map. The iterator points to a structure containing the key (marked as first) and the actual value stored in the as second.

Definition at line 28 of file Routing_Table.h.

Public Member Functions

void Print ()
 This method prints all the routing table entries.

Status Add_Routing_Entry (Node_Id node_Id, Link_Id link_Id)
 Add a new entry to the routing table.

Status Remove_Routing_Entry (Node_Id node_Id)
 Remove an entry from the routing table.

Link_Id Route (Node_Id node_Id)
 This method performs the actual routing from Node_Id to Link_Id.


Private Types

typedef map< Node_Id, Link_Id > Routing_Map
 The Routing_Map type is defined in terms of a map.


Private Attributes

Routing_Map m_routing_Map
 STL based type Routing_Map is used to define the routing table map.


Member Typedef Documentation

typedef map<Node_Id, Link_Id> Routing_Table::Routing_Map [private]
 

The Routing_Map type is defined in terms of a map.

The map is keyed with the Node_Id and stores the Link_Id. The map provides Node_Id to Link_Id mapping where the Node_Id can be any arbitrary value. Most of the time the map can be accessed using array type syntax. The main advantages of using map are:

  • Any value of Node_Id can be associated with a Link_Id. This is not practical with an an array.
  • map works well better than a search and find implementation. Search times in a map increase logrithmically with size.
  • Adding and removing entries from the map does not require any memeory management. STL takes care of managing the memory.

Definition at line 41 of file Routing_Table.h.


Member Function Documentation

void Routing_Table::Print  ) [inline]
 

This method prints all the routing table entries.

STL interators are used to loop through the map and print all entries.

  • An interator is declared
  • The iterator points to a structure as shown below

 struct Pair
       {
          Node_Id first;
          Link_Id second;
       };
  • Now loop using the iterator from the beginning to the end of the map and print first and second entries from the map.

Definition at line 63 of file Routing_Table.h.

00064    {
00065       // STL defines a nested type iterator. Here we have declared an instance
00066       // of this nested type.
00067       Routing_Map::iterator it;
00068       
00069       // Iterator it "points" to a structure defined as:
00070       // struct Pair
00071       // {
00072       //     Node_Id first;
00073       //     Link_Id second;
00074       // }; 
00075       
00076       // map supports predefined begin() and end() markers. begin() "points"
00077       // to the first entry in the map. end() points BEYOND the last entry
00078       // in the map (i.e. the last entry is the entry just before end()
00079       
00080       // STL provides pointer like symantics to iterators, thus it++ moves
00081       // the iterator to the next entry in the map.
00082       
00083       for (it = m_routing_Map.begin(); it != m_routing_Map.end(); it++)
00084       {
00085           printf ("Node_Id = %d, Link_Id = %d\n", it->first, it->second); 
00086       }
00087    }

Status Routing_Table::Add_Routing_Entry Node_Id node_Id,
Link_Id link_Id
[inline]
 

Add a new entry to the routing table.

The routine goes through the following steps:

  • Make sure that the routing entry is not already present
  • Add the routing table entry by storing the mapping from node_id to link_id.
    Parameters:
    node_Id The node for which the link_id is being defined.
    link_Id All message meant for node_id should be forwarded to the link with the specified link_id
    Return values:
    Status Return the status of routing addition as SUCCESS or FAILURE.

Definition at line 99 of file Routing_Table.h.

00100    {
00101       Status status;
00102       
00103       // First check if the entry already exists
00104       if (m_routing_Map.find(node_Id) != m_routing_Map.end())
00105       {
00106           // Iterator returns a value other than end, thus this
00107           // is a duplicate addition, return failure
00108          status = FAILURE;
00109       }
00110       else
00111       {
00112          // The end iterator was returned, signifying that
00113          // no entry currently exists, so a new one can be added.
00114          m_routing_Map[node_Id] = link_Id;
00115          
00116          status = SUCCESS;      
00117       }
00118    }

Status Routing_Table::Remove_Routing_Entry Node_Id node_Id  ) [inline]
 

Remove an entry from the routing table.

The routine goes through the following steps:

  • Make sure that the routing entry is present
  • Remove the routing table entry by calling erase
    Parameters:
    node_Id The node that needs to be removed from the routing table.
    Return values:
    Status Return the status of routing addition as SUCCESS or FAILURE.

Definition at line 127 of file Routing_Table.h.

00128    {
00129       Status status;
00130       // Check if the terminal is present
00131       if (m_routing_Map.find(node_Id) != m_routing_Map.end())
00132       {         
00133          // Erase the entry from the map.
00134          m_routing_Map.erase(node_Id);                  
00135          status = SUCCESS;
00136       }
00137       else
00138       {
00139          status = FAILURE;
00140       }
00141       
00142       return status;
00143    }

Link_Id Routing_Table::Route Node_Id node_Id  ) [inline]
 

This method performs the actual routing from Node_Id to Link_Id.

This method will be called for every message that needs to be routed.

  • Make sure that the routing entry is present
  • Obtain the link_Id from the map
    Parameters:
    node_Id Node for which the link id needs to be found.
    Return values:
    Link_Id Returns the link id where the message has to be sent. If no routing entry is found, the INVALID_LINK_ID is returned.

Definition at line 153 of file Routing_Table.h.

00154   {
00155       Link_Id link_Id = INVALID_LINK_ID;
00156       // Check if the route entry is present
00157       if (m_routing_Map.find(node_Id) != m_routing_Map.end())
00158       {         
00159          link_Id = m_routing_Map[node_Id];
00160       }
00161       return link_Id;      
00162   }   


Member Data Documentation

Routing_Map Routing_Table::m_routing_Map [private]
 

STL based type Routing_Map is used to define the routing table map.

All node id to link id mappings are stored inside this map.

Definition at line 45 of file Routing_Table.h.


The documentation for this class was generated from the following file:
Generated on Sun Feb 13 21:30:37 2005 for Object Oriented Design Examples by doxygen 1.3.4
 Home   What's New   EventStudio 2.5   Real-time Mantra   Thought Projects   Contact Us
Copyright © 2000-2005 EventHelix.com Inc. All Rights Reserved.