INET Framework for OMNeT++/OMNEST
inet::bgp::Bgp Class Reference

#include <Bgp.h>

Inheritance diagram for inet::bgp::Bgp:
inet::LifecycleUnsupported inet::ILifecycle

Public Member Functions

 Bgp ()
 
virtual ~Bgp ()
 
- Public Member Functions inherited from inet::LifecycleUnsupported
virtual bool handleOperationStage (LifecycleOperation *operation, IDoneCallback *doneCallback) override
 Perform one stage of a lifecycle operation. More...
 
- Public Member Functions inherited from inet::ILifecycle
virtual ~ILifecycle ()
 

Protected Member Functions

virtual int numInitStages () const override
 
virtual void initialize (int stage) override
 
virtual void handleMessage (cMessage *msg) override
 
void createBgpRouter ()
 
void handleTimer (cMessage *timer)
 
virtual void finish () override
 

Private Attributes

ModuleRefByPar< IIpv4RoutingTablert
 
ModuleRefByPar< IInterfaceTableift
 
bool isUp = false
 
BgpRouterbgpRouter = nullptr
 
cMessage * startupTimer = nullptr
 

Constructor & Destructor Documentation

◆ Bgp()

inet::bgp::Bgp::Bgp ( )
20 {
21 }

◆ ~Bgp()

inet::bgp::Bgp::~Bgp ( )
virtual
24 {
25  cancelAndDelete(startupTimer);
26  delete bgpRouter;
27 }

Member Function Documentation

◆ createBgpRouter()

void inet::bgp::Bgp::createBgpRouter ( )
protected
84 {
85  bgpRouter = new BgpRouter(this, ift, rt);
86 
87  // read BGP configuration
88  cXMLElement *bgpConfig = par("bgpConfig");
89  BgpConfigReader configReader(this, ift);
90  configReader.loadConfigFromXML(bgpConfig, bgpRouter);
91 
94 }

Referenced by handleMessage(), and initialize().

◆ finish()

void inet::bgp::Bgp::finish ( )
overrideprotectedvirtual
54 {
55  if (!isUp) {
56  EV_ERROR << "Protocol is turned off. \n";
57  return;
58  }
59 
61 }

◆ handleMessage()

void inet::bgp::Bgp::handleMessage ( cMessage *  msg)
overrideprotectedvirtual
64 {
65  if (!isUp) {
66  if (msg->isSelfMessage())
67  throw cRuntimeError("Model error: self msg '%s' received when protocol is down", msg->getName());
68  EV_ERROR << "Protocol is turned off, dropping '" << msg->getName() << "' message\n";
69  delete msg;
70  return;
71  }
72 
73  if (msg == startupTimer)
75  else if (msg->isSelfMessage()) // BGP level
76  handleTimer(msg);
77  else if (!strcmp(msg->getArrivalGate()->getName(), "socketIn")) // TCP level
79  else
80  delete msg;
81 }

◆ handleTimer()

void inet::bgp::Bgp::handleTimer ( cMessage *  timer)
protected
97 {
98  BgpSession *pSession = (BgpSession *)timer->getContextPointer();
99  if (pSession) {
100  switch (timer->getKind()) {
101  case START_EVENT_KIND:
102  EV_INFO << "Processing Start Event" << std::endl;
103  pSession->getFSM()->ManualStart();
104  break;
105 
106  case CONNECT_RETRY_KIND:
107  EV_INFO << "Expiring Connect Retry Timer" << std::endl;
108  pSession->getFSM()->ConnectRetryTimer_Expires();
109  break;
110 
111  case HOLD_TIME_KIND:
112  EV_INFO << "Expiring Hold Timer" << std::endl;
113  pSession->getFSM()->HoldTimer_Expires();
114  break;
115 
116  case KEEP_ALIVE_KIND:
117  EV_INFO << "Expiring Keep Alive timer" << std::endl;
118  pSession->getFSM()->KeepaliveTimer_Expires();
119  break;
120 
121  default:
122  throw cRuntimeError("Invalid timer kind %d", timer->getKind());
123  }
124  }
125 }

Referenced by handleMessage().

◆ initialize()

void inet::bgp::Bgp::initialize ( int  stage)
overrideprotectedvirtual
30 {
31  cSimpleModule::initialize(stage);
32 
33  if (stage == INITSTAGE_LOCAL) {
34  ift.reference(this, "interfaceTableModule", true);
35  rt.reference(this, "routingTableModule", true);
36 
37  startupTimer = new cMessage("BGP-startup");
38  }
39  else if (stage == INITSTAGE_ROUTING_PROTOCOLS) { // interfaces and static routes are already initialized
40  cModule *node = findContainingNode(this);
41  NodeStatus *nodeStatus = node ? check_and_cast_nullable<NodeStatus *>(node->getSubmodule("status")) : nullptr;
42  isUp = !nodeStatus || nodeStatus->getState() == NodeStatus::UP;
43  if (isUp) {
44  simtime_t startupTime = par("startupTime");
45  if (startupTime == 0)
47  else
48  scheduleAfter(startupTime, startupTimer);
49  }
50  }
51 }

◆ numInitStages()

virtual int inet::bgp::Bgp::numInitStages ( ) const
inlineoverrideprotectedvirtual
35 { return NUM_INIT_STAGES; }

Member Data Documentation

◆ bgpRouter

BgpRouter* inet::bgp::Bgp::bgpRouter = nullptr
private

◆ ift

ModuleRefByPar<IInterfaceTable> inet::bgp::Bgp::ift
private

Referenced by createBgpRouter(), and initialize().

◆ isUp

bool inet::bgp::Bgp::isUp = false
private

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

◆ rt

ModuleRefByPar<IIpv4RoutingTable> inet::bgp::Bgp::rt
private

Referenced by createBgpRouter(), and initialize().

◆ startupTimer

cMessage* inet::bgp::Bgp::startupTimer = nullptr
private

Referenced by handleMessage(), initialize(), and ~Bgp().


The documentation for this class was generated from the following files:
inet::findContainingNode
cModule * findContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:31
inet::bgp::Bgp::startupTimer
cMessage * startupTimer
Definition: Bgp.h:28
inet::bgp::CONNECT_RETRY_KIND
const unsigned char CONNECT_RETRY_KIND
Definition: BgpCommon.h:24
inet::bgp::BgpRouter::printSessionSummary
void printSessionSummary()
Definition: BgpRouter.cc:35
inet::bgp::KEEP_ALIVE_KIND
const unsigned char KEEP_ALIVE_KIND
Definition: BgpCommon.h:26
inet::bgp::Bgp::ift
ModuleRefByPar< IInterfaceTable > ift
Definition: Bgp.h:25
inet::bgp::BgpRouter::addWatches
void addWatches()
Definition: BgpRouter.cc:56
inet::INITSTAGE_LOCAL
INET_API InitStage INITSTAGE_LOCAL
Initialization of local state that don't use or affect other modules includes:
inet::bgp::BgpRouter::recordStatistics
void recordStatistics()
Definition: BgpRouter.cc:64
NUM_INIT_STAGES
#define NUM_INIT_STAGES
Definition: InitStageRegistry.h:73
inet::bgp::Bgp::isUp
bool isUp
Definition: Bgp.h:26
inet::bgp::Bgp::handleTimer
void handleTimer(cMessage *timer)
Definition: Bgp.cc:96
inet::bgp::Bgp::bgpRouter
BgpRouter * bgpRouter
Definition: Bgp.h:27
inet::bgp::Bgp::createBgpRouter
void createBgpRouter()
Definition: Bgp.cc:83
inet::bgp::BgpRouter::processMessageFromTCP
void processMessageFromTCP(cMessage *msg)
Definition: BgpRouter.cc:279
inet::NodeStatus::UP
@ UP
Definition: NodeStatus.h:28
inet::bgp::HOLD_TIME_KIND
const unsigned char HOLD_TIME_KIND
Definition: BgpCommon.h:25
inet::bgp::Bgp::rt
ModuleRefByPar< IIpv4RoutingTable > rt
Definition: Bgp.h:24
inet::INITSTAGE_ROUTING_PROTOCOLS
INET_API InitStage INITSTAGE_ROUTING_PROTOCOLS
Initialization of routing protocols.
inet::bgp::START_EVENT_KIND
const unsigned char START_EVENT_KIND
Definition: BgpCommon.h:23