OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
StateMachine Class Reference

#include <state_machine.h>

Inheritance diagram for StateMachine:
Collaboration diagram for StateMachine:

Classes

struct  EventContainer
 

Public Types

enum  State {
  IDLE = 0, ACTIVE = 1, CONNECT = 2, OPENSENT = 3,
  OPENCONFIRM = 4, ESTABLISHED = 5
}
 
typedef boost::function< void(void)> EventCB
 

Public Member Functions

 StateMachine (BgpPeer *peer)
 
virtual ~StateMachine ()
 
void Initialize ()
 
void Shutdown (int subcode)
 
void SetAdminState (bool down, int subcode)
 
bool IsQueueEmpty () const
 
template<typename Ev , int code>
void OnIdle (const Ev &event)
 
template<typename Ev >
void OnIdleCease (const Ev &event)
 
template<typename Ev , int code>
void OnIdleError (const Ev &event)
 
void OnIdleNotification (const fsm::EvBgpNotification &event)
 
int GetConnectTime () const
 
virtual void StartConnectTimer (int seconds)
 
void CancelConnectTimer ()
 
bool ConnectTimerRunning ()
 
virtual void StartOpenTimer (int seconds)
 
void CancelOpenTimer ()
 
bool OpenTimerRunning ()
 
int GetConfiguredHoldTime () const
 
virtual void StartHoldTimer ()
 
void CancelHoldTimer ()
 
bool HoldTimerRunning ()
 
virtual void StartIdleHoldTimer ()
 
void CancelIdleHoldTimer ()
 
bool IdleHoldTimerRunning ()
 
void StartSession ()
 
virtual void DeleteSession (BgpSession *session)
 
void AssignSession (bool active)
 
virtual void OnSessionEvent (TcpSession *session, TcpSession::Event event)
 
bool PassiveOpen (BgpSession *session)
 
void OnMessage (BgpSession *session, BgpProto::BgpMessage *msg, size_t msgsize=0)
 
void OnMessageError (BgpSession *session, const ParseErrorContext *context)
 
void SendNotification (BgpSession *session, int code, int subcode=0, const std::string &data=std::string())
 
bool ProcessNotificationEvent (BgpSession *session)
 
void SetDataCollectionKey (BgpPeerInfo *peer_info) const
 
const std::string & StateName () const
 
const std::string & LastStateName () const
 
BgpPeerpeer ()
 
BgpSessionactive_session ()
 
void set_active_session (BgpSession *session)
 
BgpSessionpassive_session ()
 
void set_passive_session (BgpSession *session)
 
int connect_attempts () const
 
void connect_attempts_inc ()
 
void connect_attempts_clear ()
 
int hold_time () const
 
void reset_hold_time ()
 
void set_hold_time (int hold_time)
 
virtual int keepalive_time_msecs () const
 
int idle_hold_time () const
 
void reset_idle_hold_time ()
 
void set_idle_hold_time (int idle_hold_time)
 
void set_state (State state)
 
State get_state () const
 
const std::string last_state_change_at () const
 
const uint64_t last_state_change_usecs_at () const
 
void set_last_event (const std::string &event)
 
const std::string & last_event () const
 
void set_last_notification_in (int code, int subcode, const std::string &reason)
 
void set_last_notification_out (int code, int subcode, const std::string &reason)
 
const std::string last_notification_out_error () const
 
const std::string last_notification_in_error () const
 
void reset_last_info ()
 
void LogEvent (std::string event_name, std::string msg, SandeshLevel::type log_level=SandeshLevel::SYS_DEBUG)
 
bool HoldTimerExpired ()
 
virtual bool IsCloseGraceful () const
 
virtual bool IsRouterTypeBGPaaS () const
 
virtual bool IsPeerCloseInProgress () const
 

Static Public Attributes

static const int kOpenTime = 15
 
static const int kConnectInterval = 30
 
static const int kHoldTime = 90
 
static const int kOpenSentHoldTime = 240
 
static const int kIdleHoldTime
 
static const int kMaxIdleHoldTime = 100 * 1000
 
static const int kJitter = 10
 

Protected Member Functions

virtual void OnNotificationMessage (BgpSession *session, BgpProto::BgpMessage *msg)
 
virtual const int GetIdleHoldTimeMSecs () const
 

Private Member Functions

bool ConnectTimerExpired ()
 
void FireConnectTimer ()
 
bool OpenTimerExpired ()
 
void FireOpenTimer ()
 
void FireHoldTimer ()
 
bool IdleHoldTimerExpired ()
 
void FireIdleHoldTimer ()
 
void TimerErrorHanlder (std::string name, std::string error)
 
void DeleteAllTimers ()
 
void BGPPeerInfoSend (const BgpPeerInfoData &peer_info)
 
template<typename Ev >
bool Enqueue (const Ev &event)
 
bool DequeueEvent (EventContainer ec)
 
void DequeueEventDone (bool done)
 
void UpdateFlapCount ()
 
void PeerClose (int code, int subcode)
 
 DISALLOW_COPY_AND_ASSIGN (StateMachine)
 

Private Attributes

WorkQueue< EventContainerwork_queue_
 
BgpPeerpeer_
 
BgpSessionactive_session_
 
BgpSessionpassive_session_
 
Timerconnect_timer_
 
Timeropen_timer_
 
Timerhold_timer_
 
Timeridle_hold_timer_
 
int hold_time_
 
int idle_hold_time_
 
int attempts_
 
unsigned int seed_
 
bool deleted_
 
State state_
 
State last_state_
 
std::string last_event_
 
uint64_t last_event_at_
 
uint64_t last_state_change_at_
 
std::pair< int, int > last_notification_in_
 
std::string last_notification_in_error_
 
uint64_t last_notification_in_at_
 
std::pair< int, int > last_notification_out_
 
std::string last_notification_out_error_
 
uint64_t last_notification_out_at_
 

Friends

class StateMachineTest
 
class StateMachineUnitTest
 

Detailed Description

Definition at line 75 of file state_machine.h.

Member Typedef Documentation

typedef boost::function<void(void)> StateMachine::EventCB

Definition at line 77 of file state_machine.h.

Member Enumeration Documentation

Enumerator
IDLE 
ACTIVE 
CONNECT 
OPENSENT 
OPENCONFIRM 
ESTABLISHED 

Definition at line 87 of file state_machine.h.

Constructor & Destructor Documentation

StateMachine::StateMachine ( BgpPeer peer)
explicit

Definition at line 1080 of file state_machine.cc.

Here is the call graph for this function:

StateMachine::~StateMachine ( )
virtual

Definition at line 1124 of file state_machine.cc.

Here is the call graph for this function:

Member Function Documentation

BgpSession * StateMachine::active_session ( )

Definition at line 1360 of file state_machine.cc.

void StateMachine::AssignSession ( bool  active)

Definition at line 1340 of file state_machine.cc.

Here is the call graph for this function:

void StateMachine::BGPPeerInfoSend ( const BgpPeerInfoData &  peer_info)
private

Definition at line 1720 of file state_machine.cc.

void StateMachine::CancelConnectTimer ( )

Definition at line 1226 of file state_machine.cc.

Here is the call graph for this function:

void StateMachine::CancelHoldTimer ( )

Definition at line 1277 of file state_machine.cc.

Here is the call graph for this function:

void StateMachine::CancelIdleHoldTimer ( )

Definition at line 1259 of file state_machine.cc.

Here is the call graph for this function:

void StateMachine::CancelOpenTimer ( )

Definition at line 1241 of file state_machine.cc.

Here is the call graph for this function:

int StateMachine::connect_attempts ( ) const
inline

Definition at line 152 of file state_machine.h.

void StateMachine::connect_attempts_clear ( )
inline

Definition at line 154 of file state_machine.h.

void StateMachine::connect_attempts_inc ( )
inline

Definition at line 153 of file state_machine.h.

bool StateMachine::ConnectTimerExpired ( )
private

Definition at line 1405 of file state_machine.cc.

Here is the call graph for this function:

bool StateMachine::ConnectTimerRunning ( )

Definition at line 1230 of file state_machine.cc.

Here is the call graph for this function:

void StateMachine::DeleteAllTimers ( )
private

Definition at line 1113 of file state_machine.cc.

Here is the call graph for this function:

void StateMachine::DeleteSession ( BgpSession session)
virtual

Definition at line 1327 of file state_machine.cc.

Here is the call graph for this function:

bool StateMachine::DequeueEvent ( StateMachine::EventContainer  ec)
private

Definition at line 1645 of file state_machine.cc.

Here is the call graph for this function:

void StateMachine::DequeueEventDone ( bool  done)
private

Definition at line 1667 of file state_machine.cc.

Here is the call graph for this function:

StateMachine::DISALLOW_COPY_AND_ASSIGN ( StateMachine  )
private
template<typename Ev >
bool StateMachine::Enqueue ( const Ev &  event)
private

Definition at line 1623 of file state_machine.cc.

Here is the call graph for this function:

void StateMachine::FireConnectTimer ( )
private

Definition at line 1287 of file state_machine.cc.

Here is the call graph for this function:

void StateMachine::FireHoldTimer ( )
private

Definition at line 1295 of file state_machine.cc.

Here is the call graph for this function:

void StateMachine::FireIdleHoldTimer ( )
private

Definition at line 1299 of file state_machine.cc.

Here is the call graph for this function:

void StateMachine::FireOpenTimer ( )
private

Definition at line 1291 of file state_machine.cc.

Here is the call graph for this function:

State StateMachine::get_state ( ) const
inline

Definition at line 168 of file state_machine.h.

int StateMachine::GetConfiguredHoldTime ( ) const

Definition at line 1690 of file state_machine.cc.

Here is the call graph for this function:

int StateMachine::GetConnectTime ( ) const

Definition at line 1209 of file state_machine.cc.

virtual const int StateMachine::GetIdleHoldTimeMSecs ( ) const
inlineprotectedvirtual

Definition at line 191 of file state_machine.h.

int StateMachine::hold_time ( ) const
inline

Definition at line 156 of file state_machine.h.

bool StateMachine::HoldTimerExpired ( )

Definition at line 1415 of file state_machine.cc.

Here is the call graph for this function:

bool StateMachine::HoldTimerRunning ( )

Definition at line 1281 of file state_machine.cc.

Here is the call graph for this function:

int StateMachine::idle_hold_time ( ) const
inline

Definition at line 161 of file state_machine.h.

bool StateMachine::IdleHoldTimerExpired ( )
private

Definition at line 1428 of file state_machine.cc.

Here is the call graph for this function:

bool StateMachine::IdleHoldTimerRunning ( )

Definition at line 1263 of file state_machine.cc.

Here is the call graph for this function:

void StateMachine::Initialize ( )

Definition at line 1130 of file state_machine.cc.

Here is the call graph for this function:

bool StateMachine::IsCloseGraceful ( ) const
virtual

Definition at line 1433 of file state_machine.cc.

Here is the call graph for this function:

bool StateMachine::IsPeerCloseInProgress ( ) const
virtual

Definition at line 1134 of file state_machine.cc.

Here is the call graph for this function:

bool StateMachine::IsQueueEmpty ( ) const

Definition at line 1159 of file state_machine.cc.

Here is the call graph for this function:

bool StateMachine::IsRouterTypeBGPaaS ( ) const
virtual

Definition at line 1437 of file state_machine.cc.

Here is the call graph for this function:

virtual int StateMachine::keepalive_time_msecs ( ) const
inlinevirtual

Definition at line 159 of file state_machine.h.

const std::string& StateMachine::last_event ( ) const
inline

Definition at line 172 of file state_machine.h.

const std::string StateMachine::last_notification_in_error ( ) const

Definition at line 1675 of file state_machine.cc.

Here is the call graph for this function:

const std::string StateMachine::last_notification_out_error ( ) const

Definition at line 1681 of file state_machine.cc.

Here is the call graph for this function:

const std::string StateMachine::last_state_change_at ( ) const

Definition at line 1586 of file state_machine.cc.

Here is the call graph for this function:

const uint64_t StateMachine::last_state_change_usecs_at ( ) const

Definition at line 1590 of file state_machine.cc.

const string & StateMachine::LastStateName ( ) const

Definition at line 1582 of file state_machine.cc.

void StateMachine::LogEvent ( std::string  event_name,
std::string  msg,
SandeshLevel::type  log_level = SandeshLevel::SYS_DEBUG 
)

Definition at line 1634 of file state_machine.cc.

Here is the call graph for this function:

template<typename Ev , int code>
void StateMachine::OnIdle ( const Ev &  event)

Definition at line 1179 of file state_machine.cc.

Here is the call graph for this function:

template<typename Ev >
void StateMachine::OnIdleCease ( const Ev &  event)

Definition at line 1185 of file state_machine.cc.

Here is the call graph for this function:

template<typename Ev , int code>
void StateMachine::OnIdleError ( const Ev &  event)

Definition at line 1196 of file state_machine.cc.

Here is the call graph for this function:

void StateMachine::OnIdleNotification ( const fsm::EvBgpNotification event)

Definition at line 1203 of file state_machine.cc.

Here is the call graph for this function:

void StateMachine::OnMessage ( BgpSession session,
BgpProto::BgpMessage msg,
size_t  msgsize = 0 
)

Definition at line 1490 of file state_machine.cc.

Here is the call graph for this function:

void StateMachine::OnMessageError ( BgpSession session,
const ParseErrorContext context 
)

Definition at line 1548 of file state_machine.cc.

Here is the call graph for this function:

void StateMachine::OnNotificationMessage ( BgpSession session,
BgpProto::BgpMessage msg 
)
protectedvirtual

Definition at line 1478 of file state_machine.cc.

Here is the call graph for this function:

void StateMachine::OnSessionEvent ( TcpSession session,
TcpSession::Event  event 
)
virtual

Definition at line 1445 of file state_machine.cc.

Here is the call graph for this function:

bool StateMachine::OpenTimerExpired ( )
private

Definition at line 1410 of file state_machine.cc.

Here is the call graph for this function:

bool StateMachine::OpenTimerRunning ( )

Definition at line 1245 of file state_machine.cc.

Here is the call graph for this function:

BgpSession * StateMachine::passive_session ( )

Definition at line 1364 of file state_machine.cc.

bool StateMachine::PassiveOpen ( BgpSession session)

Definition at line 1469 of file state_machine.cc.

Here is the call graph for this function:

BgpPeer* StateMachine::peer ( )
inline

Definition at line 146 of file state_machine.h.

void StateMachine::PeerClose ( int  code,
int  subcode 
)
private

Definition at line 1170 of file state_machine.cc.

Here is the call graph for this function:

bool StateMachine::ProcessNotificationEvent ( BgpSession session)

Definition at line 1387 of file state_machine.cc.

Here is the call graph for this function:

void StateMachine::reset_hold_time ( )

Definition at line 1797 of file state_machine.cc.

Here is the call graph for this function:

void StateMachine::reset_idle_hold_time ( )
inline

Definition at line 162 of file state_machine.h.

void StateMachine::reset_last_info ( )

Definition at line 1806 of file state_machine.cc.

Here is the call graph for this function:

void StateMachine::SendNotification ( BgpSession session,
int  code,
int  subcode = 0,
const std::string &  data = std::string() 
)

Definition at line 1368 of file state_machine.cc.

Here is the call graph for this function:

void StateMachine::set_active_session ( BgpSession session)

Definition at line 1350 of file state_machine.cc.

Here is the call graph for this function:

void StateMachine::set_hold_time ( int  hold_time)

Definition at line 1788 of file state_machine.cc.

Here is the call graph for this function:

void StateMachine::set_idle_hold_time ( int  idle_hold_time)
inline

Definition at line 163 of file state_machine.h.

Here is the call graph for this function:

void StateMachine::set_last_event ( const std::string &  event)

Definition at line 1725 of file state_machine.cc.

Here is the call graph for this function:

void StateMachine::set_last_notification_in ( int  code,
int  subcode,
const std::string &  reason 
)

Definition at line 1758 of file state_machine.cc.

Here is the call graph for this function:

void StateMachine::set_last_notification_out ( int  code,
int  subcode,
const std::string &  reason 
)

Definition at line 1744 of file state_machine.cc.

Here is the call graph for this function:

void StateMachine::set_passive_session ( BgpSession session)

Definition at line 1355 of file state_machine.cc.

Here is the call graph for this function:

void StateMachine::set_state ( State  state)

Definition at line 1772 of file state_machine.cc.

Here is the call graph for this function:

void StateMachine::SetAdminState ( bool  down,
int  subcode 
)

Definition at line 1146 of file state_machine.cc.

Here is the call graph for this function:

void StateMachine::SetDataCollectionKey ( BgpPeerInfo *  peer_info) const

Definition at line 1671 of file state_machine.cc.

Here is the call graph for this function:

void StateMachine::Shutdown ( int  subcode)

Definition at line 1138 of file state_machine.cc.

Here is the call graph for this function:

void StateMachine::StartConnectTimer ( int  seconds)
virtual

Definition at line 1214 of file state_machine.cc.

Here is the call graph for this function:

void StateMachine::StartHoldTimer ( )
virtual

Definition at line 1267 of file state_machine.cc.

Here is the call graph for this function:

void StateMachine::StartIdleHoldTimer ( )
virtual

Definition at line 1249 of file state_machine.cc.

Here is the call graph for this function:

void StateMachine::StartOpenTimer ( int  seconds)
virtual

Definition at line 1234 of file state_machine.cc.

Here is the call graph for this function:

void StateMachine::StartSession ( )

Definition at line 1308 of file state_machine.cc.

Here is the call graph for this function:

const string & StateMachine::StateName ( ) const

Definition at line 1578 of file state_machine.cc.

void StateMachine::TimerErrorHanlder ( std::string  name,
std::string  error 
)
inlineprivate

Definition at line 210 of file state_machine.h.

void StateMachine::UpdateFlapCount ( )
private

Definition at line 1163 of file state_machine.cc.

Here is the call graph for this function:

Friends And Related Function Documentation

friend class StateMachineTest
friend

Definition at line 194 of file state_machine.h.

friend class StateMachineUnitTest
friend

Definition at line 195 of file state_machine.h.

Member Data Documentation

BgpSession* StateMachine::active_session_
private

Definition at line 222 of file state_machine.h.

int StateMachine::attempts_
private

Definition at line 230 of file state_machine.h.

Timer* StateMachine::connect_timer_
private

Definition at line 224 of file state_machine.h.

bool StateMachine::deleted_
private

Definition at line 232 of file state_machine.h.

int StateMachine::hold_time_
private

Definition at line 228 of file state_machine.h.

Timer* StateMachine::hold_timer_
private

Definition at line 226 of file state_machine.h.

int StateMachine::idle_hold_time_
private

Definition at line 229 of file state_machine.h.

Timer* StateMachine::idle_hold_timer_
private

Definition at line 227 of file state_machine.h.

const int StateMachine::kConnectInterval = 30
static

Definition at line 80 of file state_machine.h.

const int StateMachine::kHoldTime = 90
static

Definition at line 81 of file state_machine.h.

const int StateMachine::kIdleHoldTime
static
Initial value:
=
getenv("CONTRAIL_BGP_IDLE_HOLD_TIME_MSECS") ?
strtol(getenv("CONTRAIL_BGP_IDLE_HOLD_TIME_MSECS"), NULL, 0) : 5000

Definition at line 83 of file state_machine.h.

const int StateMachine::kJitter = 10
static

Definition at line 85 of file state_machine.h.

const int StateMachine::kMaxIdleHoldTime = 100 * 1000
static

Definition at line 84 of file state_machine.h.

const int StateMachine::kOpenSentHoldTime = 240
static

Definition at line 82 of file state_machine.h.

const int StateMachine::kOpenTime = 15
static

Definition at line 79 of file state_machine.h.

std::string StateMachine::last_event_
private

Definition at line 235 of file state_machine.h.

uint64_t StateMachine::last_event_at_
private

Definition at line 236 of file state_machine.h.

std::pair<int, int> StateMachine::last_notification_in_
private

Definition at line 238 of file state_machine.h.

uint64_t StateMachine::last_notification_in_at_
private

Definition at line 240 of file state_machine.h.

std::string StateMachine::last_notification_in_error_
private

Definition at line 239 of file state_machine.h.

std::pair<int, int> StateMachine::last_notification_out_
private

Definition at line 241 of file state_machine.h.

uint64_t StateMachine::last_notification_out_at_
private

Definition at line 243 of file state_machine.h.

std::string StateMachine::last_notification_out_error_
private

Definition at line 242 of file state_machine.h.

State StateMachine::last_state_
private

Definition at line 234 of file state_machine.h.

uint64_t StateMachine::last_state_change_at_
private

Definition at line 237 of file state_machine.h.

Timer* StateMachine::open_timer_
private

Definition at line 225 of file state_machine.h.

BgpSession* StateMachine::passive_session_
private

Definition at line 223 of file state_machine.h.

BgpPeer* StateMachine::peer_
private

Definition at line 221 of file state_machine.h.

unsigned int StateMachine::seed_
private

Definition at line 231 of file state_machine.h.

State StateMachine::state_
private

Definition at line 233 of file state_machine.h.

WorkQueue<EventContainer> StateMachine::work_queue_
private

Definition at line 220 of file state_machine.h.


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