INET Framework for OMNeT++/OMNEST
Stp Class Reference

#include <stp.h>

List of all members.

Public Member Functions

bool learning (unsigned int, unsigned int)
bool forwarding (unsigned int, unsigned int)
void dispatchALL ()
void dispatch (unsigned int)
int getInstanceIndex (unsigned int)
void setBridgePriority (unsigned int, unsigned int)
void setPortPriority (unsigned int, std::vector< unsigned int > &, std::vector< unsigned int > &)
void setLinkCost (unsigned int, std::vector< unsigned int > &, std::vector< unsigned int > &)
void setForwardDelay (unsigned int, unsigned int)
void setMaxAge (unsigned int, unsigned int)
void setHelloTime (unsigned int, unsigned int)

Protected Member Functions

virtual void initialize (int stage)
virtual int numInitStages () const
virtual void handleMessage (cMessage *msg)
virtual void finish ()
void handleSelfMessage (cMessage *msg)
void handleBPDU (STPBPDU *bpdu)
void handleTCN (STPTCN *tcn)
void setPortPriority (unsigned int, unsigned int, unsigned int)
void setLinkCost (unsigned int, unsigned int, unsigned int)

Protected Attributes

unsigned int portCount
MACAddress bridgeAddress
std::vector< unsigned int > instReg
std::vector< stpiinst
cMessage * tick
MACTableaddrTable

Detailed Description

Definition at line 30 of file stp.h.


Member Function Documentation

void Stp::dispatch ( unsigned int  idx)

Definition at line 49 of file stp.cc.

Referenced by dispatchALL(), handleBPDU(), and handleTCN().

                                   {
        for (unsigned int i = 0; i < inst.at(idx).msgList.size(); i++) {
                send(inst.at(idx).msgList.at(i).msg, "out", inst.at(idx).msgList.at(i).port);
        }
        inst.at(idx).msgList.clear();
}
void Stp::dispatchALL ( )

Definition at line 43 of file stp.cc.

Referenced by handleSelfMessage().

                      {
        for (unsigned int i = 0; i < inst.size(); i++) {
                dispatch(i);
        }
}
void Stp::finish ( ) [protected, virtual]

Definition at line 217 of file stp.cc.

                 {
        cancelAndDelete(tick);
}
bool Stp::forwarding ( unsigned int  port,
unsigned int  vlan 
)

Definition at line 33 of file stp.cc.

Referenced by ANSASwitchCore::dispatch(), and ANSASwitchCore::relay().

                                                         {
        Enter_Method_Silent();
        for (unsigned int i = 0; i < instReg.size(); i++) {
                if (instReg.at(i) == vlan) {
                        return inst.at(i).forwarding(port);
                }
        }
        return false;
}
int Stp::getInstanceIndex ( unsigned int  _inst)

Definition at line 57 of file stp.cc.

Referenced by setBridgePriority(), setForwardDelay(), setHelloTime(), setLinkCost(), setMaxAge(), and setPortPriority().

                                            {
        for (unsigned int i = 0; i < instReg.size(); i++) {
                        if (instReg.at(i) == _inst) {
                                return i;
                        }
                }
        return -1;
}
void Stp::handleBPDU ( STPBPDU bpdu) [protected]

Definition at line 233 of file stp.cc.

Referenced by handleMessage().

                                   {
        unsigned int _vlan = bpdu->getVlan();

        for (unsigned int i = 0; i < instReg.size(); i++) {
                if (instReg.at(i) == _vlan) {
                        inst.at(i).handleBPDU(bpdu);
                        dispatch(i);
                        return;
                }
        }
        delete bpdu;

}
void Stp::handleMessage ( cMessage *  msg) [protected, virtual]

Definition at line 196 of file stp.cc.

{
        cMessage * tmp = msg;

        if (!msg->isSelfMessage()) {
                if (dynamic_cast<STPBPDU *>(tmp)){ // Configuration BPDU
                        STPBPDU * bpdu = (STPBPDU *) tmp;
                        handleBPDU(bpdu);
                } else if (dynamic_cast<STPTCN *>(tmp)){ // Topology Change Notification
                        STPTCN * tcn = (STPTCN *) tmp;
                        handleTCN(tcn);
                } else { // Rubbish
                        delete msg;
                }
        } else {
                handleSelfMessage(msg);
        }


}
void Stp::handleSelfMessage ( cMessage *  msg) [protected]

Definition at line 221 of file stp.cc.

Referenced by handleMessage().

                                          {
        if (msg == tick) {
                for (unsigned int i = 0; i < inst.size(); i++) {
                        inst.at(i).handleTick();
                }
                scheduleAt(simTime()+1, tick);
        } else {
                delete msg;
        }
        dispatchALL();
}
void Stp::handleTCN ( STPTCN tcn) [protected]

Definition at line 247 of file stp.cc.

Referenced by handleMessage().

                                {
        unsigned int _vlan = tcn->getVlan();

        for (unsigned int i = 0; i < instReg.size(); i++) {
                if (instReg.at(i) == _vlan) {
                        inst.at(i).handleTCN(tcn);
                        dispatch(i);
                        return;
                }
        }
        delete tcn;
}
void Stp::initialize ( int  stage) [protected, virtual]

Definition at line 145 of file stp.cc.

{
        if (stage == 0) {

                portCount = gateSize("out");

                tick = new cMessage("STP_TICK", 0);

                /* connection to MAC Table for faster aging */
                cModule * tmp_macTable = getParentModule()->getSubmodule("MACTable");
                addrTable = check_and_cast<MACTable *>(tmp_macTable);

                WATCH(bridgeAddress);
        }
        else if (stage == 1) {
                /* obtain a Bridge Address from Core and initialize instances*/
                cModule * tmp_core = getParentModule()->getSubmodule("core");
                ANSASwitchCore * core = check_and_cast<ANSASwitchCore *>(tmp_core);
                bridgeAddress = core->getBridgeAddress();

                /* obtain a VLAN list for STP instances creation */
                cModule * tmp_vlantable = getParentModule()->getSubmodule("VLANTable");
                VLANTable * vlantable = check_and_cast<VLANTable *>(tmp_vlantable);
                instReg = vlantable->getVLANList();


                /* call init on all instances */
                for (unsigned int i = 0; i < instReg.size(); i++) {
                        stpi tmp(instReg.at(i), portCount, bridgeAddress, addrTable);
                        inst.push_back(tmp);
                }

                const char *filename = par("configFile");
                const char *switchID = par("switchID");

                if (*filename == '\0' || *switchID == '\0') {
                        EV << "Warning: " << this->getParentModule()->getName() << ": Could not config, config filename or switchID is not set, using Default." << std::endl;
                } else {
                        stpXMLparser config(this);
                        config.parse(filename, switchID);
                }



                WATCH_VECTOR(inst);
                WATCH_VECTOR(instReg);

                scheduleAt(simTime()+1, tick);
        }
}
bool Stp::learning ( unsigned int  port,
unsigned int  vlan 
)

Definition at line 23 of file stp.cc.

Referenced by ANSASwitchCore::learn().

                                                       {
        Enter_Method_Silent();
        for (unsigned int i = 0; i < instReg.size(); i++) {
                if (instReg.at(i) == vlan) {
                        return inst.at(i).learning(port);
                }
        }
        return false;
}
virtual int Stp::numInitStages ( ) const [inline, protected, virtual]

Definition at line 56 of file stp.h.

{return 2;}
void Stp::setBridgePriority ( unsigned int  _inst,
unsigned int  _bridgePriority 
)

Definition at line 66 of file stp.cc.

Referenced by stpXMLparser::parseSTP().

                                                                            {
        int idx = getInstanceIndex(_inst);
        if (idx == -1) {
                return;
        }

        inst.at(idx).bridgePriority = _bridgePriority;

}
void Stp::setForwardDelay ( unsigned int  _inst,
unsigned int  _fwdDelay 
)

Definition at line 117 of file stp.cc.

Referenced by stpXMLparser::parseSTP().

                                                                    {
        int idx = getInstanceIndex(_inst);
        if (idx == -1) {
                return;
        }
        inst.at(idx).fwdDelay = _fwdDelay;

}
void Stp::setHelloTime ( unsigned int  _inst,
unsigned int  _helloTime 
)

Definition at line 134 of file stp.cc.

Referenced by stpXMLparser::parseSTP().

                                                                 {
        int idx = getInstanceIndex(_inst);
        if (idx == -1) {
                return;
        }
        inst.at(idx).helloTime = _helloTime;
}
void Stp::setLinkCost ( unsigned int  _inst,
std::vector< unsigned int > &  _portList,
std::vector< unsigned int > &  _costList 
)

Definition at line 101 of file stp.cc.

                                                                                                                {
        int idx = getInstanceIndex(_inst);
        if (idx == -1) {
                return;
        }

        if (_portList.size() != _costList.size()) {
                return;
        }

        for (unsigned int i = 0; i < _portList.size(); i++) {
                setLinkCost(idx, _portList.at(i), _costList.at(i));
        }

}
void Stp::setLinkCost ( unsigned int  _idx,
unsigned int  _port,
unsigned int  _cost 
) [protected]

Definition at line 80 of file stp.cc.

                                                                               {
        inst.at(_idx).portTable.at(_port).linkCost = _cost;
}
void Stp::setMaxAge ( unsigned int  _inst,
unsigned int  _maxAge 
)

Definition at line 126 of file stp.cc.

Referenced by stpXMLparser::parseSTP().

                                                            {
        int idx = getInstanceIndex(_inst);
        if (idx == -1) {
                return;
        }
        inst.at(idx).maxAge = _maxAge;
}
void Stp::setPortPriority ( unsigned int  _inst,
std::vector< unsigned int > &  _portList,
std::vector< unsigned int > &  _priList 
)

Definition at line 85 of file stp.cc.

Referenced by stpXMLparser::parseSTP().

                                                                                                                   {
        int idx = getInstanceIndex(_inst);
        if (idx == -1) {
                return;
        }

        if (_portList.size() != _priList.size()) {
                return;
        }

        for (unsigned int i = 0; i < _portList.size(); i++) {
                setPortPriority(idx, _portList.at(i), _priList.at(i));
        }

}
void Stp::setPortPriority ( unsigned int  _idx,
unsigned int  _port,
unsigned int  _priority 
) [protected]

Definition at line 77 of file stp.cc.

                                                                                       {
        inst.at(_idx).portTable.at(_port).priority = _priority;
}

Member Data Documentation

MACTable* Stp::addrTable [protected]

Definition at line 77 of file stp.h.

Referenced by initialize().

Definition at line 68 of file stp.h.

Referenced by initialize().

std::vector<unsigned int> Stp::instReg [protected]

Definition at line 71 of file stp.h.

Referenced by forwarding(), getInstanceIndex(), handleBPDU(), handleTCN(), initialize(), and learning().

unsigned int Stp::portCount [protected]

Definition at line 67 of file stp.h.

Referenced by initialize().

cMessage* Stp::tick [protected]

Definition at line 75 of file stp.h.

Referenced by finish(), handleSelfMessage(), and initialize().


The documentation for this class was generated from the following files: