Skip to content

Commit

Permalink
add interface enable/disable command
Browse files Browse the repository at this point in the history
  • Loading branch information
GIC-de committed Nov 24, 2022
1 parent 2dbc92d commit 72f8371
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 18 deletions.
2 changes: 2 additions & 0 deletions code/bngblaster/src/bbl_ctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ struct action actions[] = {
{"access-interfaces", bbl_access_ctrl_interfaces, true},
{"network-interfaces", bbl_network_ctrl_interfaces, true},
{"a10nsp-interfaces", bbl_a10nsp_ctrl_interfaces, true},
{"interface-enable", bbl_interface_ctrl_enable, false},
{"interface-disable", bbl_interface_ctrl_disable, false},
{"terminate", bbl_session_ctrl_terminate, false},
{"sessions-pending", bbl_session_ctrl_pending, true},
{"session-counters", bbl_session_ctrl_counters, true},
Expand Down
51 changes: 51 additions & 0 deletions code/bngblaster/src/bbl_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,57 @@ bbl_interface_get(char *interface_name)
return NULL;
}

static int
bbl_interface_ctrl_enable_disable(int fd, json_t *arguments, bool enable)
{
const char *s;
bbl_interface_s *interface;

/* Unpack further arguments */
if(json_unpack(arguments, "{s:s}", "interface", &s) != 0) {
return bbl_ctrl_status(fd, "error", 400, "missing argument interface");
}

CIRCLEQ_FOREACH(interface, &g_ctx->interface_qhead, interface_qnode) {
if(strcmp(interface->name, s) == 0) {
if(interface->type == LAG_INTERFACE) {
return bbl_ctrl_status(fd, "error", 400, "invalid interface");
}
if(enable) {
if(interface->state == INTERFACE_DISABLED) {
if(interface->lag_member && interface->lag_member->lacp_state) {
interface->state = INTERFACE_DOWN;
} else {
interface->state = INTERFACE_UP;
}
LOG(INFO, "Interface (%s) enabled\n", interface->name);
}
} else {
if(interface->state != INTERFACE_DISABLED) {
bbl_lag_member_lacp_reset(interface);
interface->state = INTERFACE_DISABLED;
LOG(INFO, "Interface (%s) disabled\n", interface->name);
}
}
return bbl_ctrl_status(fd, "ok", 200, NULL);
}
}

return bbl_ctrl_status(fd, "warning", 404, "interface not found");
}

int
bbl_interface_ctrl_enable(int fd, uint32_t session_id __attribute__((unused)), json_t *arguments)
{
return bbl_interface_ctrl_enable_disable(fd, arguments, true);
}

int
bbl_interface_ctrl_disable(int fd, uint32_t session_id __attribute__((unused)), json_t *arguments)
{
return bbl_interface_ctrl_enable_disable(fd, arguments, false);
}

int
bbl_interface_ctrl(int fd, uint32_t session_id __attribute__((unused)), json_t *arguments __attribute__((unused)))
{
Expand Down
6 changes: 6 additions & 0 deletions code/bngblaster/src/bbl_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ bbl_interface_init();
bbl_interface_s *
bbl_interface_get(char *interface_name);

int
bbl_interface_ctrl_enable(int fd, uint32_t session_id __attribute__((unused)), json_t *arguments);

int
bbl_interface_ctrl_disable(int fd, uint32_t session_id __attribute__((unused)), json_t *arguments);

int
bbl_interface_ctrl(int fd, uint32_t session_id __attribute__((unused)), json_t *arguments __attribute__((unused)));

Expand Down
49 changes: 35 additions & 14 deletions code/bngblaster/src/bbl_lag.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,20 +131,22 @@ bbl_lag_select(bbl_lag_s *lag)

CIRCLEQ_FOREACH(member, &lag->lag_member_qhead, lag_member_qnode) {
member->primary = false;
if(member->lacp_state == LACP_CURRENT &&
member->partner_state & LACP_STATE_FLAG_COLLECTING) {
if(active_count >= LAG_MEMBER_ACTIVE_MAX ||
active_count >= lag->config->lacp_max_active_links) {
bbl_lag_member_update_state(member, INTERFACE_STANDBY);
} else {
if(active_count == 0) {
member->primary = true;
if(member->interface->state != INTERFACE_DISABLED) {
if(member->lacp_state == LACP_CURRENT &&
member->partner_state & LACP_STATE_FLAG_COLLECTING) {
if(active_count >= LAG_MEMBER_ACTIVE_MAX ||
active_count >= lag->config->lacp_max_active_links) {
bbl_lag_member_update_state(member, INTERFACE_STANDBY);
} else {
if(active_count == 0) {
member->primary = true;
}
lag->active_list[active_count++] = member;
bbl_lag_member_update_state(member, INTERFACE_UP);
}
lag->active_list[active_count++] = member;
bbl_lag_member_update_state(member, INTERFACE_UP);
} else {
bbl_lag_member_update_state(member, INTERFACE_DOWN);
}
} else {
bbl_lag_member_update_state(member, INTERFACE_DOWN);
}
}

Expand Down Expand Up @@ -262,8 +264,27 @@ bbl_lag_interface_add(bbl_interface_s *interface, bbl_link_config_s *link_config
}

void
bbl_lag_rx_lacp(bbl_interface_s *interface,
bbl_ethernet_header_s *eth)
bbl_lag_member_lacp_reset(bbl_interface_s *interface)
{
bbl_lag_member_s *member = interface->lag_member;

if(member && member->lacp_state) {
member->lacp_state = LACP_DEFAULTED;
member->actor_state |= (LACP_STATE_FLAG_EXPIRED|LACP_STATE_FLAG_DEFAULTED);
memset(member->partner_system_id, 0x0, ETH_ADDR_LEN);
member->partner_system_priority = 0;
member->partner_key = 0;
member->partner_port_priority = 0;
member->partner_port_id = 0;
member->partner_state = 0;
LOG(LAG, "LAG (%s) LACP defaulted on interface %s\n",
member->lag->interface->name, interface->name);
bbl_lag_select(member->lag);
}
}

void
bbl_lag_rx_lacp(bbl_interface_s *interface, bbl_ethernet_header_s *eth)
{
bbl_lag_member_s *member = interface->lag_member;
bbl_lacp_s *lacp = (bbl_lacp_s*)eth->next;
Expand Down
6 changes: 4 additions & 2 deletions code/bngblaster/src/bbl_lag.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ bool
bbl_lag_interface_add(bbl_interface_s *interface, bbl_link_config_s *link_config);

void
bbl_lag_rx_lacp(bbl_interface_s *interface,
bbl_ethernet_header_s *eth);
bbl_lag_member_lacp_reset(bbl_interface_s *interface);

void
bbl_lag_rx_lacp(bbl_interface_s *interface, bbl_ethernet_header_s *eth);

int
bbl_lag_ctrl_info(int fd, uint32_t session_id __attribute__((unused)), json_t *arguments);
Expand Down
4 changes: 4 additions & 0 deletions code/bngblaster/src/bbl_tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -1489,6 +1489,10 @@ bbl_tx(bbl_interface_s *interface, uint8_t *buf, uint16_t *len)
bbl_session_s *session;
bbl_l2tp_queue_s *l2tpq;

if(interface->state == INTERFACE_DISABLED) {
return EMPTY;
}

/* Interface packets like LACP or LLDP. */
if(interface->send_requests) {
return bbl_tx_encode_interface_packet(interface, buf, len);
Expand Down
12 changes: 10 additions & 2 deletions docsrc/sources/api/interfaces.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
- Mandatory Arguments
- Optional Arguments
* - `interfaces`
- List all interfaces with index
- List all interfaces with index
-
-
* - `access-interfaces`
Expand All @@ -24,4 +24,12 @@
* - `lag-info`
- List all link aggregation (LAG) interfaces
-
-
-
* - `interface-enable`
- Enable interface
- `interface`
-
* - `interface-disable`
- Disable interface
- `interface`
-

0 comments on commit 72f8371

Please sign in to comment.