Skip to content

Commit

Permalink
add session-start command rtbrick#78
Browse files Browse the repository at this point in the history
  • Loading branch information
GIC-de committed Apr 21, 2022
1 parent b7e52c1 commit 22aee59
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 2 deletions.
5 changes: 5 additions & 0 deletions code/bngblaster/src/bbl_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -1316,6 +1316,10 @@ json_parse_config(json_t *root, bbl_ctx_s *ctx) {
if (json_is_number(value)) {
ctx->config.sessions_start_delay = json_number_value(value);
}
value = json_object_get(section, "autostart");
if (json_is_boolean(value)) {
ctx->config.sessions_autostart = json_boolean_value(value);
}
}

/* IPoE Configuration */
Expand Down Expand Up @@ -2191,6 +2195,7 @@ bbl_config_init_defaults (bbl_ctx_s *ctx) {
ctx->config.sessions_max_outstanding = 800;
ctx->config.sessions_start_rate = 400;
ctx->config.sessions_stop_rate = 400;
ctx->config.sessions_autostart = true;
ctx->config.pppoe_discovery_timeout = 5;
ctx->config.pppoe_discovery_retry = 10;
ctx->config.ppp_mru = 1492;
Expand Down
24 changes: 24 additions & 0 deletions code/bngblaster/src/bbl_ctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,29 @@ bbl_ctrl_session_info(int fd, bbl_ctx_s *ctx, uint32_t session_id, json_t* argum
}
}

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(session_id == 0) {
/* session-id is mandatory */
return bbl_ctrl_status(fd, "error", 405, "missing session-id");
}

session = bbl_session_get(ctx, session_id);
if(session) {
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");
}
CIRCLEQ_INSERT_TAIL(&ctx->sessions_idle_qhead, session, session_idle_qnode);
return bbl_ctrl_status(fd, "ok", 200, NULL);
} else {
return bbl_ctrl_status(fd, "warning", 404, "session not found");
}
}

static json_t *
bbl_ctrl_interfaces_json(bbl_interface_s *interace, const char *type) {
return json_pack("{ss si ss si si si si si si si si}",
Expand Down Expand Up @@ -1338,6 +1361,7 @@ struct action actions[] = {
{"ip6cp-close", bbl_ctrl_session_ip6cp_close},
{"session-counters", bbl_ctrl_session_counters},
{"session-info", bbl_ctrl_session_info},
{"session-start", bbl_ctrl_session_start},
{"session-traffic", bbl_ctrl_session_traffic_stats},
{"session-traffic-enabled", bbl_ctrl_session_traffic_start},
{"session-traffic-start", bbl_ctrl_session_traffic_start},
Expand Down
3 changes: 2 additions & 1 deletion code/bngblaster/src/bbl_ctx.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ typedef struct bbl_ctx_
uint16_t sessions_start_rate;
uint16_t sessions_stop_rate;
uint16_t sessions_start_delay;

bool sessions_autostart;

bool iterate_outer_vlan;

/* Static */
Expand Down
4 changes: 3 additions & 1 deletion code/bngblaster/src/bbl_session.c
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,9 @@ bbl_sessions_init(bbl_ctx_s *ctx)
session->interface = access_config->access_if;
session->network_interface = bbl_get_network_interface(ctx, access_config->network_interface);
session->session_state = BBL_IDLE;
CIRCLEQ_INSERT_TAIL(&ctx->sessions_idle_qhead, session, session_idle_qnode);
if(ctx->config.sessions_autostart) {
CIRCLEQ_INSERT_TAIL(&ctx->sessions_idle_qhead, session, session_idle_qnode);
}
ctx->sessions++;
if(session->access_type == ACCESS_TYPE_PPPOE) {
ctx->sessions_pppoe++;
Expand Down
4 changes: 4 additions & 0 deletions docsrc/sources/api/sessions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
- Terminate session
-
- `session-id`, `reconnect-delay`
* - `session-start`
- Start session manually
- `session-id`
-

The argument ``reconnect-delay`` is only applicable in combination with ``session-id``
and reconnect enabled in configuration. This argument allows to delay the session
Expand Down
3 changes: 3 additions & 0 deletions docsrc/sources/configuration/sessions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
* - `start-delay`
- Wait N seconds after all interface are resolved before starting sessions
- 0
* - `autostart`
- Start sessions automatically
- true

Per default sessions are created by iteration over inner VLAN range first and
outer VLAN second. Which can be changed by ``iterate-vlan-outer`` to iterate
Expand Down

0 comments on commit 22aee59

Please sign in to comment.