Skip to content

Commit

Permalink
ICMP client (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
GIC-de committed Dec 17, 2024
1 parent 3727a8b commit 50aae54
Show file tree
Hide file tree
Showing 14 changed files with 726 additions and 15 deletions.
1 change: 1 addition & 0 deletions code/bngblaster/src/bbl.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ struct keyval_ log_names[] = {
{ INFO, "info" },
{ PCAP, "pcap" },
{ IP, "ip" },
{ ICMP, "icmp" },
{ LOSS, "loss" },
{ L2TP, "l2tp" },
{ DHCP, "dhcp" },
Expand Down
1 change: 1 addition & 0 deletions code/bngblaster/src/bbl.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include "bbl_li.h"
#include "bbl_cfm.h"
#include "bbl_tcp.h"
#include "bbl_icmp_client.h"
#include "bbl_http_client.h"
#include "bbl_http_server.h"
#include "bbl_fragment.h"
Expand Down
14 changes: 8 additions & 6 deletions code/bngblaster/src/bbl_access.c
Original file line number Diff line number Diff line change
Expand Up @@ -567,12 +567,14 @@ static bool
bbl_access_rx_icmp(bbl_session_s *session, bbl_ethernet_header_s *eth, bbl_ipv4_s *ipv4)
{
bbl_icmp_s *icmp = (bbl_icmp_s*)ipv4->next;
if(session->ip_address &&
session->ip_address == ipv4->dst &&
icmp->type == ICMP_TYPE_ECHO_REQUEST) {
/* Send ICMP reply... */
if(bbl_access_icmp_reply(session, eth, ipv4, icmp) == BBL_TXQ_OK) {
return true;
if(session->ip_address && session->ip_address == ipv4->dst) {
if(icmp->type == ICMP_TYPE_ECHO_REQUEST) {
/* Send ICMP reply... */
if(bbl_access_icmp_reply(session, eth, ipv4, icmp) == BBL_TXQ_OK) {
return true;
}
} else {
return bbl_icmp_client_rx(session, eth, ipv4, icmp);
}
}
return false;
Expand Down
136 changes: 133 additions & 3 deletions code/bngblaster/src/bbl_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -894,8 +894,9 @@ json_parse_access_interface(json_t *access_interface, bbl_access_config_s *acces
"access-line-profile-id", "ipcp", "dhcp",
"ipv4", "ip6cp", "dhcpv6",
"dhcpv6-ldra", "ipv6", "igmp-autostart",
"igmp-version", "session-traffic-autostart", "session-group-id",
"stream-group-id", "http-client-group-id",
"igmp-version", "session-traffic-autostart",
"session-group-id", "stream-group-id",
"http-client-group-id", "icmp-client-group-id",
"cfm-cc", "cfm-level", "cfm-ma-id", "cfm-ma-name"
};
if(!schema_validate(access_interface, "access", schema,
Expand Down Expand Up @@ -1224,6 +1225,12 @@ json_parse_access_interface(json_t *access_interface, bbl_access_config_s *acces
access_config->tcp = true;
}

value = json_object_get(access_interface, "icmp-client-group-id");
JSON_OBJ_GET_NUMBER(access_interface, value, "access", "icmp-client-group-id", 0, 65535);
if(value) {
access_config->icmp_client_group_id = json_number_value(value);
}

JSON_OBJ_GET_BOOL(access_interface, value, "access", "cfm-cc");
if(value) {
access_config->cfm_cc = json_boolean_value(value);
Expand Down Expand Up @@ -2718,6 +2725,100 @@ json_parse_config_streams(json_t *root)
return true;
}

static bool
json_parse_icmp_client_config(json_t *icmp, bbl_icmp_client_config_s *icmp_client_config)
{
json_t *value = NULL;
const char *s = NULL;

const char *schema[] = {
"icmp-client-group-id",
"autostart", "start-delay",
"count", "results",
"interval", "size", "ttl",
"destination-address"
};

if(!schema_validate(icmp, "icmp-client", schema,
sizeof(schema)/sizeof(schema[0]))) {
return false;
}

JSON_OBJ_GET_NUMBER(icmp, value, "icmp-client", "icmp-client-group-id", 1, 65535);
if(value) {
icmp_client_config->icmp_client_group_id = json_number_value(value);
} else {
fprintf(stderr, "JSON config error: Missing value for icmp-client->icmp-client-group-id\n");
return false;
}

JSON_OBJ_GET_BOOL(icmp, value, "icmp-client", "autostart");
if(value) {
icmp_client_config->autostart = json_boolean_value(value);
} else {
icmp_client_config->autostart = true;
}

JSON_OBJ_GET_NUMBER(icmp, value, "icmp-client", "start-delay", 0, 65535);
if(value) {
icmp_client_config->start_delay = json_number_value(value);
}

JSON_OBJ_GET_NUMBER(icmp, value, "icmp-client", "count", 0, 65535);
if(value) {
icmp_client_config->count = json_number_value(value);
}

JSON_OBJ_GET_NUMBER(icmp, value, "icmp-client", "size", 0, 65507);
if(value) {
icmp_client_config->size = json_number_value(value);
} else {
icmp_client_config->size = 8;
}

JSON_OBJ_GET_NUMBER(icmp, value, "icmp-client", "ttl", 1, 255);
if(value) {
icmp_client_config->ttl = json_number_value(value);
} else {
icmp_client_config->ttl = 64;
}

JSON_OBJ_GET_NUMBER(icmp, value, "icmp-client", "results", 0, 65535);
if(value) {
icmp_client_config->results = json_number_value(value);
} else {
icmp_client_config->results = icmp_client_config->count;
}
if(!icmp_client_config->results) icmp_client_config->results = 3;

value = json_object_get(icmp, "interval");
if(value) {
icmp_client_config->interval = json_number_value(value);
if(icmp_client_config->interval <= 0) {
fprintf(stderr, "JSON config error: Invalid value for stream->pps\n");
return false;
}
icmp_client_config->interval_sec = icmp_client_config->interval;
icmp_client_config->interval_nsec = (icmp_client_config->interval - icmp_client_config->interval_sec) * SEC;
} else {
icmp_client_config->interval = 1.0;
icmp_client_config->interval_sec = 1;
}

if(json_unpack(icmp, "{s:s}", "destination-address", &s) == 0) {
if(!inet_pton(AF_INET, s, &icmp_client_config->destination)) {
fprintf(stderr, "JSON config error: Invalid value for icmp-client->destination-address\n");
return false;
}
} else {
fprintf(stderr, "JSON config error: Missing value for icmp-client->destination-address\n");
return false;
}

return true;
}


static bool
json_parse_http_client_config(json_t *http, bbl_http_client_config_s *http_client_config)
{
Expand Down Expand Up @@ -2877,6 +2978,7 @@ json_parse_config(json_t *root)
ospf_config_s *ospf_config = NULL;
ldp_config_s *ldp_config = NULL;

bbl_icmp_client_config_s *icmp_client_config = NULL;
bbl_http_client_config_s *http_client_config = NULL;
bbl_http_server_config_s *http_server_config = NULL;

Expand All @@ -2893,7 +2995,7 @@ json_parse_config(json_t *root)
"isis", "ospf",
"bgp", "bgp-raw-update-files",
"ldp", "ldp-raw-update-files",
"l2tp-server",
"l2tp-server", "icmp-client",
"http-client", "http-server"
};
if(!schema_validate(root, "root", root_schema,
Expand Down Expand Up @@ -4093,6 +4195,34 @@ json_parse_config(json_t *root)
fprintf(stderr, "JSON config error: List expected in L2TP server configuration but dictionary found\n");
}

/* ICMP Client Configuration */
sub = json_object_get(root, "icmp-client");
if(json_is_array(sub)) {
/* Config is provided as array (multiple ICMP clients) */
size = json_array_size(sub);
for(i = 0; i < size; i++) {
if(!icmp_client_config) {
g_ctx->config.icmp_client_config = calloc(1, sizeof(bbl_icmp_client_config_s));
icmp_client_config = g_ctx->config.icmp_client_config;
} else {
icmp_client_config->next = calloc(1, sizeof(bbl_icmp_client_config_s));
icmp_client_config = icmp_client_config->next;
}
if(!json_parse_icmp_client_config(json_array_get(sub, i), icmp_client_config)) {
return false;
}
}
} else if(json_is_object(sub)) {
/* Config is provided as object (single ICMP client) */
icmp_client_config = calloc(1, sizeof(bbl_icmp_client_config_s));
if(!g_ctx->config.icmp_client_config) {
g_ctx->config.icmp_client_config = icmp_client_config;
}
if(!json_parse_icmp_client_config(sub, icmp_client_config)) {
return false;
}
}

/* HTTP Client Configuration */
sub = json_object_get(root, "http-client");
if(json_is_array(sub)) {
Expand Down
1 change: 1 addition & 0 deletions code/bngblaster/src/bbl_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ typedef struct bbl_access_config_
uint16_t stream_group_id;
uint16_t session_group_id;
uint16_t http_client_group_id;
uint16_t icmp_client_group_id;

uint16_t access_outer_vlan;
uint16_t access_outer_vlan_min;
Expand Down
3 changes: 3 additions & 0 deletions code/bngblaster/src/bbl_ctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ struct action actions[] = {
{"monkey-start", bbl_ctrl_monkey_start, schema_all_args, false},
{"monkey-stop", bbl_ctrl_monkey_stop, schema_all_args, false},
{"lag-info", bbl_lag_ctrl_info, schema_all_args, true},
{"icmp-clients", bbl_icmp_client_ctrl, schema_all_args, true},
{"icmp-clients-start", bbl_icmp_client_ctrl_start, schema_all_args, false},
{"icmp-clients-stop", bbl_icmp_client_ctrl_stop, schema_all_args, false},
{"http-clients", bbl_http_client_ctrl, schema_all_args, true},
{"http-clients-start", bbl_http_client_ctrl_start, schema_all_args, false},
{"http-clients-stop", bbl_http_client_ctrl_stop, schema_all_args, false},
Expand Down
3 changes: 3 additions & 0 deletions code/bngblaster/src/bbl_ctx.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ typedef struct bbl_ctx_
/* LDP Instances */
ldp_config_s *ldp_config;

/* ICMP Client Instances */
bbl_icmp_client_config_s *icmp_client_config;

/* HTTP Client/Server Instances */
bbl_http_client_config_s *http_client_config;
bbl_http_server_config_s *http_server_config;
Expand Down
2 changes: 2 additions & 0 deletions code/bngblaster/src/bbl_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ typedef struct bbl_stream_group_ bbl_stream_group_s;
typedef struct bbl_stream_ bbl_stream_s;
typedef struct bbl_tcp_ctx_ bbl_tcp_ctx_s;
typedef struct bbl_ctrl_thread_ bbl_ctrl_thread_s;
typedef struct bbl_icmp_client_config_ bbl_icmp_client_config_s;
typedef struct bbl_icmp_client_ bbl_icmp_client_s;
typedef struct bbl_http_client_config_ bbl_http_client_config_s;
typedef struct bbl_http_client_ bbl_http_client_s;
typedef struct bbl_http_server_config_ bbl_http_server_config_s;
Expand Down
6 changes: 0 additions & 6 deletions code/bngblaster/src/bbl_http_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ typedef struct bbl_http_client_
bool
bbl_http_client_session_init(bbl_session_s *session);

bool
bbl_http_server_init(bbl_network_interface_s *network_interface);

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

Expand All @@ -84,7 +81,4 @@ bbl_http_client_ctrl_start(int fd, uint32_t session_id, json_t *arguments __attr
int
bbl_http_client_ctrl_stop(int fd, uint32_t session_id, json_t *arguments __attribute__((unused)));

bool
bbl_http_server_init(bbl_network_interface_s *network_interface);

#endif
Loading

0 comments on commit 50aae54

Please sign in to comment.