Skip to content

Commit

Permalink
Merge "Send PollRequest prior to reading PollResponse"
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuul authored and opencontrail-ci-admin committed Aug 9, 2016
2 parents 5a564e3 + 6d40fb5 commit bcc4200
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 37 deletions.
38 changes: 15 additions & 23 deletions src/ifmap/client/ifmap_state_machine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,6 @@ struct SsrcStart : sc::state<SsrcStart, IFMapStateMachine> {
> reactions;
SsrcStart(my_context ctx) : my_base(ctx) {
IFMapStateMachine *sm = &context<IFMapStateMachine>();
// Since we are restarting the SM, log all transitions.
sm->set_log_all_transitions(true);
sm->set_state(IFMapStateMachine::SSRCSTART);
sm->channel()->ReconnectPreparation();
}
Expand Down Expand Up @@ -629,6 +627,8 @@ struct PollResponseWait :
typedef mpl::list<
sc::custom_reaction<EvReadSuccess>,
sc::custom_reaction<EvReadFailed>,
sc::custom_reaction<EvWriteSuccess>,
sc::custom_reaction<EvWriteFailed>,
sc::custom_reaction<EvProcResponseSuccess>,
sc::custom_reaction<EvProcResponseFailed>,
sc::custom_reaction<EvConnectionResetReq>
Expand All @@ -642,16 +642,25 @@ struct PollResponseWait :
sc::result react(const EvReadSuccess &event) {
// the header of the response to 'poll' has been read successfully
IFMapStateMachine *sm = &context<IFMapStateMachine>();
sm->channel()->SendPollRequest();
int failure = sm->channel()->ReadPollResponse();
if (failure) {
return transit<SsrcStart>();
} else {
return transit<SendPoll>();
return discard_event();
}
}
sc::result react(const EvReadFailed &event) {
return transit<SsrcStart>();
}
sc::result react(const EvWriteSuccess &event) {
IFMapStateMachine *sm = &context<IFMapStateMachine>();
sm->channel()->PollResponseWait();
return discard_event();
}
sc::result react(const EvWriteFailed &event) {
return transit<SsrcStart>();
}
sc::result react(const EvProcResponseSuccess &event) {
IFMapStateMachine *sm = &context<IFMapStateMachine>();
sm->channel()->ProcResponse(event.error_, event.bytes_);
Expand Down Expand Up @@ -682,8 +691,7 @@ IFMapStateMachine::IFMapStateMachine(IFMapManager *manager,
channel_(NULL), state_(IDLE), last_state_(IDLE), last_state_change_at_(0),
last_event_at_(0), max_connect_wait_interval_ms_(kConnectWaitIntervalMs),
max_response_wait_interval_ms_(
config_options.peer_response_wait_time*1000), // ms
log_all_transitions_(true) {
config_options.peer_response_wait_time*1000) {
}

void IFMapStateMachine::Initialize() {
Expand Down Expand Up @@ -865,7 +873,7 @@ void IFMapStateMachine::ProcSubscribeResponse(
}
}

// current state: SendPoll
// current state: SendPoll or PollResponseWait
void IFMapStateMachine::ProcPollWrite(
const boost::system::error_code& error, size_t bytes_transferred) {
CHECK_CONCURRENCY_MAIN_THR();
Expand Down Expand Up @@ -945,25 +953,9 @@ bool IFMapStateMachine::DequeueEvent(
}

void IFMapStateMachine::LogSmTransition() {
switch (state_) {
case SENDPOLL:
case POLLRESPONSEWAIT:
// Log these states only once for each connection attempt. This helps
// since we will keep circling between them once the connection has
// been established and we dont need to print them for every new VM
// that comes up.
if (log_all_transitions()) {
IFMAP_SM_DEBUG(IFMapSmTransitionMessage, StateName(last_state_),
"===>", StateName(state_));
if (state_ == POLLRESPONSEWAIT) {
set_log_all_transitions(false);
}
}
break;
default:
if (state_ != POLLRESPONSEWAIT || state_ != last_state_) {
IFMAP_SM_DEBUG(IFMapSmTransitionMessage, StateName(last_state_), "===>",
StateName(state_));
break;
}
}

Expand Down
3 changes: 0 additions & 3 deletions src/ifmap/client/ifmap_state_machine.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,6 @@ class IFMapStateMachine :
size_t WorkQueueEnqueues() const { return work_queue_.NumEnqueues(); }
size_t WorkQueueDequeues() const { return work_queue_.NumDequeues(); }
size_t WorkQueueLength() const { return work_queue_.Length(); }
bool log_all_transitions() { return log_all_transitions_; }
void set_log_all_transitions(bool value) { log_all_transitions_ = value; }

private:
void EnqueueEvent(const sc::event_base &ev);
Expand Down Expand Up @@ -171,7 +169,6 @@ class IFMapStateMachine :
uint64_t last_event_at_;
int max_connect_wait_interval_ms_;
int max_response_wait_interval_ms_;
bool log_all_transitions_;
};

#endif /* __IFMAP_STATE_MACHINE_H__ */
40 changes: 29 additions & 11 deletions src/ifmap/client/test/ifmap_state_machine_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -221,22 +221,28 @@ TEST_F(IFMapStateMachineTest, ErrorlessRun) {
.WillOnce(InvokeWithoutArgs(boost::bind(
&IFMapStateMachine::ProcHandshakeResponse,
state_machine(), success_ec())));
// end the test after sending the second poll request
// end the test after sending the fourth poll request
EXPECT_CALL(*mock_channel(), SendPollRequest())
.Times(2)
.Times(4)
.WillOnce(InvokeWithoutArgs(boost::bind(
&IFMapStateMachine::ProcPollWrite,
state_machine(), success_ec(), kReturnBytes)))
.WillOnce(InvokeWithoutArgs(boost::bind(
&IFMapStateMachine::ProcPollWrite,
state_machine(), success_ec(), kReturnBytes)))
.WillOnce(InvokeWithoutArgs(boost::bind(
&IFMapStateMachine::ProcPollWrite,
state_machine(), success_ec(), kReturnBytes)))
// Just to end the test somewhere, return i.e. no action
.WillOnce(Return());
EXPECT_CALL(*mock_channel(), PollResponseWait())
.Times(1)
.WillOnce(InvokeWithoutArgs(boost::bind(
.Times(3)
.WillRepeatedly(InvokeWithoutArgs(boost::bind(
&IFMapStateMachine::ProcPollResponseRead,
state_machine(), success_ec(), kReturnBytes)));
EXPECT_CALL(*mock_channel(), ReadPollResponse())
.Times(1)
.WillOnce(Return(kOpSuccess));
.Times(3)
.WillRepeatedly(Return(kOpSuccess));

Start("10.1.2.3", "8443");
// Wait for the sequence of events to occur
Expand Down Expand Up @@ -302,9 +308,14 @@ TEST_F(IFMapStateMachineTest, ReadPollRespError) {
.WillRepeatedly(InvokeWithoutArgs(boost::bind(
&IFMapStateMachine::ProcHandshakeResponse,
state_machine(), success_ec())));
// end the test after sending the third poll request
// End the test after sending the third poll request.
// 2 calls happen in the first iteration when there's a read error.
// 1 call happens in the second iteration and causes test to end.
EXPECT_CALL(*mock_channel(), SendPollRequest())
.Times(2)
.Times(3)
.WillOnce(InvokeWithoutArgs(boost::bind(
&IFMapStateMachine::ProcPollWrite,
state_machine(), success_ec(), kReturnBytes)))
.WillOnce(InvokeWithoutArgs(boost::bind(
&IFMapStateMachine::ProcPollWrite,
state_machine(), success_ec(), kReturnBytes)))
Expand Down Expand Up @@ -423,10 +434,17 @@ TEST_F(IFMapStateMachineTest, MessageContentError) {
.WillRepeatedly(InvokeWithoutArgs(boost::bind(
&IFMapStateMachine::ProcHandshakeResponse,
state_machine(), success_ec())));
// End the test after sending the second poll request. Hence one more call
// than the other mock functions below
// End the test after sending the fourth poll request.
// 2 calls happen in the first iteration when there's a message error.
// 2 calls happen in the second iteration when there's no message error.
// Each iteration needs 1 call to PollResponseWait and ReadPollResponse.
// Hence SendPollRequest has two more calls than the other mock functions
// below.
EXPECT_CALL(*mock_channel(), SendPollRequest())
.Times(3)
.Times(4)
.WillOnce(InvokeWithoutArgs(boost::bind(
&IFMapStateMachine::ProcPollWrite,
state_machine(), success_ec(), kReturnBytes)))
.WillOnce(InvokeWithoutArgs(boost::bind(
&IFMapStateMachine::ProcPollWrite,
state_machine(), success_ec(), kReturnBytes)))
Expand Down

0 comments on commit bcc4200

Please sign in to comment.