Skip to content

Commit

Permalink
enhance session-start command #78
Browse files Browse the repository at this point in the history
  • Loading branch information
GIC-de committed Apr 21, 2022
1 parent d17363c commit b99490e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
19 changes: 16 additions & 3 deletions code/bngblaster/src/bbl_ctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ bbl_ctrl_session_info(int fd, bbl_ctx_s *ctx, uint32_t session_id, json_t* argum
if(session) {
session_json = bbl_session_json(session);
if(!session_json) {
bbl_ctrl_status(fd, "error", 500, "internal error");
return bbl_ctrl_status(fd, "error", 500, "internal error");
}

root = json_pack("{ss si so*}",
Expand All @@ -446,14 +446,27 @@ ssize_t
bbl_ctrl_session_start(int fd, bbl_ctx_s *ctx, uint32_t session_id, json_t* arguments __attribute__((unused))) {
bbl_session_s *session;

if(g_teardown) {
return bbl_ctrl_status(fd, "error", 405, "teardown");
}

if(session_id == 0) {
/* session-id is mandatory */
return bbl_ctrl_status(fd, "error", 405, "missing session-id");
return bbl_ctrl_status(fd, "error", 400, "missing session-id");
}

session = bbl_session_get(ctx, session_id);
if(session) {
if(session->session_state != BBL_IDLE ||
if(session->session_state == BBL_TERMINATED &&
session->reconnect_delay == 0) {
ctx->sessions_flapped++;
session->stats.flapped++;
session->session_state = BBL_IDLE;
bbl_session_reset(session);
if(ctx->sessions_terminated) {
ctx->sessions_terminated--;
}
} else if(session->session_state != BBL_IDLE ||
CIRCLEQ_NEXT(session, session_idle_qnode) ||
CIRCLEQ_PREV(session, session_idle_qnode)) {
return bbl_ctrl_status(fd, "error", 405, "wrong session state");
Expand Down
2 changes: 1 addition & 1 deletion code/bngblaster/src/bbl_session.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ bbl_session_get(bbl_ctx_s *ctx, uint32_t session_id)
return ctx->session_list[session_id-1];
}

static void
void
bbl_session_reset(bbl_session_s *session) {
/* Reset session for reconnect */
memset(&session->server_mac, 0xff, ETH_ADDR_LEN); /* init with broadcast MAC */
Expand Down
3 changes: 3 additions & 0 deletions code/bngblaster/src/bbl_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,9 @@ session_state_string(uint32_t state);
bbl_session_s *
bbl_session_get(bbl_ctx_s *ctx, uint32_t session_id);

void
bbl_session_reset(bbl_session_s *session);

void
bbl_session_update_state(bbl_ctx_s *ctx, bbl_session_s *session, session_state_t state);

Expand Down

0 comments on commit b99490e

Please sign in to comment.