Multicast Routing Modelling In OMNeT++
PimNeighborTable.cc
Go to the documentation of this file.
00001 
00011 #include "PimNeighborTable.h"
00012 
00013 Define_Module(PimNeighborTable);
00014 
00015 using namespace std;
00016 
00017 
00019 std::ostream& operator<<(std::ostream& os, const PimNeighbor& e)
00020 {
00021     os << e.getId() << ": ID = " << e.getInterfaceID() << "; Addr = " << e.getAddr() << "; Ver = " << e.getVersion();
00022     return os;
00023 };
00024 
00026 std::string PimNeighbor::info() const
00027 {
00028         std::stringstream out;
00029         out << id << ": ID = " << intID << "; Addr = " << addr << "; Ver = " << ver;
00030         return out.str();
00031 }
00032 
00038 void PimNeighborTable::handleMessage(cMessage *msg)
00039 {
00040     opp_error("This module doesn't process messages");
00041 }
00042 
00043 void PimNeighborTable::initialize(int stage)
00044 {
00045         WATCH_VECTOR(nt);
00046         id = 0;
00047 }
00048 
00054 void PimNeighborTable::printPimNeighborTable()
00055 {
00056         for(std::vector<PimNeighbor>::iterator i = nt.begin(); i < nt.end(); i++)
00057         {
00058                 EV << (*i).info() << endl;
00059         }
00060 }
00061 
00070 std::vector<PimNeighbor> PimNeighborTable::getNeighborsByIntID(int intId)
00071 {
00072         vector<PimNeighbor> nbr;
00073 
00074         for(int i = 0; i < getNumNeighbors(); i++)
00075         {
00076                 if(intId == getNeighbor(i)->getInterfaceID())
00077                 {
00078                         nbr.push_back(*getNeighbor(i));
00079                 }
00080         }
00081         return nbr;
00082 }
00083 
00092 PimNeighbor *PimNeighborTable::getNeighborsByID(int id)
00093 {
00094         for(int i = 0; i < getNumNeighbors(); i++)
00095         {
00096                 if(id == getNeighbor(i)->getId())
00097                 {
00098                         return getNeighbor(i);
00099                         break;
00100                 }
00101         }
00102         return NULL;
00103 }
00104 
00113 bool PimNeighborTable::deleteNeighbor(int id)
00114 {
00115         for(int i = 0; i < getNumNeighbors(); i++)
00116         {
00117                 if(id == getNeighbor(i)->getId())
00118                 {
00119                         nt.erase(nt.begin() + i);
00120                         return true;
00121                 }
00122         }
00123         return false;
00124 }
00125 
00134 bool PimNeighborTable::isInTable(PimNeighbor entry)
00135 {
00136         for(int i = 0; i < getNumNeighbors(); i++)
00137         {
00138                 if((entry.getAddr() == getNeighbor(i)->getAddr()) && (entry.getInterfaceID() == getNeighbor(i)->getInterfaceID()))
00139                         return true;
00140         }
00141         return false;
00142 }
00143 
00153 PimNeighbor *PimNeighborTable::findNeighbor(int intId, IPAddress addr)
00154 {
00155         for(int i = 0; i < getNumNeighbors(); i++)
00156         {
00157                 if((addr == getNeighbor(i)->getAddr()) && (intId == getNeighbor(i)->getInterfaceID()))
00158                         return getNeighbor(i);
00159         }
00160         return NULL;
00161 }
00162 
00171 int PimNeighborTable::getNumNeighborsOnInt(int intId)
00172 {
00173         std::vector<PimNeighbor> neighbors = getNeighborsByIntID(intId);
00174         return neighbors.size();
00175 }