Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICMP Client #298

Merged
merged 2 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
21 changes: 11 additions & 10 deletions code/bngblaster/src/bbl_access.c
Original file line number Diff line number Diff line change
Expand Up @@ -567,12 +567,16 @@ 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) {
session->stats.icmp_tx++;
session->access_interface->stats.icmp_tx++;
return true;
}
} else {
return bbl_icmp_client_rx(session, NULL, eth, ipv4, icmp);
}
}
return false;
Expand Down Expand Up @@ -648,10 +652,7 @@ bbl_access_rx_ipv4(bbl_access_interface_s *interface,
case PROTOCOL_IPV4_ICMP:
session->stats.icmp_rx++;
interface->stats.icmp_rx++;
if(bbl_access_rx_icmp(session, eth, ipv4)) {
session->stats.icmp_tx++;
interface->stats.icmp_tx++;
}
bbl_access_rx_icmp(session, eth, ipv4);
return;
case PROTOCOL_IPV4_UDP:
udp = (bbl_udp_s*)ipv4->next;
Expand Down
160 changes: 157 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,124 @@ 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", "network-interface",
"autostart", "start-delay",
"count", "results",
"interval", "size", "ttl",
"df", "tos",
"source-address",
"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);
}
if(json_unpack(icmp, "{s:s}", "network-interface", &s) == 0) {
if(icmp_client_config->icmp_client_group_id) {
fprintf(stderr, "JSON config error: At most one icmp-client-group-id or network-interface must be specified for icmp-clients.\n");
return false;
}
icmp_client_config->network_interface = strdup(s);
} else if (!icmp_client_config->icmp_client_group_id) {
fprintf(stderr, "JSON config error: Missing value for icmp-client, either icmp-client-group-id or network-interface is required\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", "tos", 0, 255);
if(value) {
icmp_client_config->tos = json_number_value(value);
}

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

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->dst)) {
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;
}
if(json_unpack(icmp, "{s:s}", "source-address", &s) == 0) {
if(!inet_pton(AF_INET, s, &icmp_client_config->src)) {
fprintf(stderr, "JSON config error: Invalid value for icmp-client->source-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 +3002,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 +3019,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 +4219,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
5 changes: 4 additions & 1 deletion code/bngblaster/src/bbl_ctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const char *schema_all_args[] = {
"result-code", "error-code", "error-message",
"disconnect-code", "disconnect-protocol",
"disconnect-direction", "disconnect-message",
"ldp-instance-id", "tcp-flags", "debug",
"ldp-instance-id", "tcp-flags", "debug", "detail",
"verified-only", "bidirectional-verified-only",
NULL
};
Expand Down 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
4 changes: 4 additions & 0 deletions code/bngblaster/src/bbl_ctx.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ typedef struct bbl_ctx_
bool tcp;
bool dpdk;

bbl_icmp_client_s *icmp_clients;
bgp_session_s *bgp_sessions;
bgp_raw_update_s *bgp_raw_updates;
isis_instance_s *isis_instances;
Expand Down Expand Up @@ -197,6 +198,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
Loading