Skip to content

Commit

Permalink
remove unnecessary access methods
Browse files Browse the repository at this point in the history
  • Loading branch information
tatry committed May 23, 2022
1 parent 4e435a4 commit 2bbdab1
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 159 deletions.
33 changes: 11 additions & 22 deletions CLI/action_selector.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,9 @@
static int parse_dst_action_selector(int *argc, char ***argv, psabpf_context_t *psabpf_ctx,
psabpf_action_selector_context_t *ctx, bool is_last)
{
if (is_keyword(**argv, "id")) {
NEXT_ARGP_RET();
fprintf(stderr, "id: Action Selector access not supported\n");
return ENOTSUP;
} else if (is_keyword(**argv, "name")) {
NEXT_ARGP_RET();
fprintf(stderr, "name: Action Selector access not supported yet\n");
return ENOTSUP;
} else {
int error_code = psabpf_action_selector_ctx_name(psabpf_ctx, ctx, **argv);
if (error_code != NO_ERROR)
return error_code;
}
int error_code = psabpf_action_selector_ctx_name(psabpf_ctx, ctx, **argv);
if (error_code != NO_ERROR)
return error_code;

if (is_last) {
NEXT_ARGP();
Expand Down Expand Up @@ -505,19 +495,18 @@ int do_action_selector_help(int argc, char **argv)
(void) argc; (void) argv;

fprintf(stderr,
"Usage: %1$s action-selector add_member pipe ID ACTION_SELECTOR ACTION [data ACTION_PARAMS]\n"
" %1$s action-selector delete_member pipe ID ACTION_SELECTOR MEMBER_REF\n"
" %1$s action-selector update_member pipe ID ACTION_SELECTOR MEMBER_REF ACTION [data ACTION_PARAMS]\n"
"Usage: %1$s action-selector add_member pipe ID ACTION_SELECTOR_NAME ACTION [data ACTION_PARAMS]\n"
" %1$s action-selector delete_member pipe ID ACTION_SELECTOR_NAME MEMBER_REF\n"
" %1$s action-selector update_member pipe ID ACTION_SELECTOR_NAME MEMBER_REF ACTION [data ACTION_PARAMS]\n"
""
" %1$s action-selector create_group pipe ID ACTION_SELECTOR\n"
" %1$s action-selector delete_group pipe ID ACTION_SELECTOR GROUP_REF\n"
" %1$s action-selector create_group pipe ID ACTION_SELECTOR_NAME\n"
" %1$s action-selector delete_group pipe ID ACTION_SELECTOR_NAME GROUP_REF\n"
""
" %1$s action-selector add_to_group pipe ID ACTION_SELECTOR MEMBER_REF to GROUP_REF\n"
" %1$s action-selector delete_from_group pipe ID ACTION_SELECTOR MEMBER_REF from GROUP_REF\n"
" %1$s action-selector add_to_group pipe ID ACTION_SELECTOR_NAME MEMBER_REF to GROUP_REF\n"
" %1$s action-selector delete_from_group pipe ID ACTION_SELECTOR_NAME MEMBER_REF from GROUP_REF\n"
""
" %1$s action-selector default_group_action pipe ID ACTION_SELECTOR ACTION [data ACTION_PARAMS]\n"
" %1$s action-selector default_group_action pipe ID ACTION_SELECTOR_NAME ACTION [data ACTION_PARAMS]\n"
"\n"
" ACTION_SELECTOR := { id ACTION_SELECTOR_ID | name FILE | ACTION_SELECTOR_FILE }\n"
" ACTION := { id ACTION_ID | ACTION_NAME }\n"
" ACTION_PARAMS := { DATA }\n"
"",
Expand Down
28 changes: 9 additions & 19 deletions CLI/counter.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,19 @@ static int parse_dst_counter(int *argc, char ***argv, const char **counter_name,
return EINVAL;
}

if (is_keyword(**argv, "id")) {
NEXT_ARGP_RET();
fprintf(stderr, "id: counter access not supported\n");
return ENOTSUP;
} else if (is_keyword(**argv, "name")) {
NEXT_ARGP_RET();
fprintf(stderr, "name: counter access not supported yet\n");
return ENOTSUP;
} else {
if (counter_name != NULL)
*counter_name = **argv;
int error_code = psabpf_counter_ctx_name(psabpf_ctx, ctx, **argv);
if (error_code != NO_ERROR)
return error_code;
}
if (counter_name != NULL)
*counter_name = **argv;
int error_code = psabpf_counter_ctx_name(psabpf_ctx, ctx, **argv);
if (error_code != NO_ERROR)
return error_code;

NEXT_ARGP();
return NO_ERROR;
}

static int parse_counter_key(int *argc, char ***argv, psabpf_counter_entry_t *entry)
{
/* TODO: replace 'key' keyword with 'index' */
if (!is_keyword(**argv, "key"))
return NO_ERROR; /* key is optional */
NEXT_ARGP_RET();
Expand Down Expand Up @@ -411,11 +402,10 @@ int do_counter_help(int argc, char **argv)
{
(void) argc; (void) argv;
fprintf(stderr,
"Usage: %1$s counter get pipe ID COUNTER [key DATA]\n"
" %1$s counter set pipe ID COUNTER [key DATA] value COUNTER_VALUE\n"
" %1$s counter reset pipe ID COUNTER [key DATA]\n"
"Usage: %1$s counter get pipe ID COUNTER_NAME [key DATA]\n"
" %1$s counter set pipe ID COUNTER_NAME [key DATA] value COUNTER_VALUE\n"
" %1$s counter reset pipe ID COUNTER_NAME [key DATA]\n"
"\n"
" COUNTER := { id COUNTER_ID | name COUNTER | COUNTER_FILE }\n"
" COUNTER_VALUE := { BYTES | PACKETS | BYTES:PACKETS }\n"
"",
program_name);
Expand Down
27 changes: 8 additions & 19 deletions CLI/digest.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,14 @@ static int parse_digest(int *argc, char ***argv, psabpf_context_t *psabpf_ctx,
fprintf(stderr, "too few parameters\n");
return EPERM;
}
if (is_keyword(**argv, "id")) {
NEXT_ARGP_RET();
fprintf(stderr, "id: digest access not supported\n");
return ENOTSUP;
} else if (is_keyword(**argv, "name")) {
NEXT_ARGP_RET();
fprintf(stderr, "name: digest access not supported yet\n");
return ENOTSUP;
} else {
int error_code = psabpf_digest_ctx_name(psabpf_ctx, ctx, **argv);
if (error_code != NO_ERROR) {
fprintf(stderr, "failed to open digest %s: %s\n", **argv, strerror(error_code));
return error_code;
}
*instance_name = **argv;

int error_code = psabpf_digest_ctx_name(psabpf_ctx, ctx, **argv);
if (error_code != NO_ERROR) {
fprintf(stderr, "failed to open digest %s: %s\n", **argv, strerror(error_code));
return error_code;
}
*instance_name = **argv;

NEXT_ARGP();

return NO_ERROR;
Expand Down Expand Up @@ -174,10 +166,7 @@ int do_digest_help(int argc, char **argv)
{
(void) argc; (void) argv;
fprintf(stderr,
"Usage: %1$s digest get pipe ID DIGEST\n"
"\n"
" DIGEST := { id DIGEST_ID | name FILE | DIGEST_FILE }\n"
"",
"Usage: %1$s digest get pipe ID DIGEST_NAME\n",
program_name);
return 0;
}
23 changes: 6 additions & 17 deletions CLI/meter.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,9 @@ int convert_str_to_meter_value(const char *str, psabpf_meter_value_t *value) {
int parse_dst_meter(int *argc, char ***argv, psabpf_context_t *psabpf_ctx,
psabpf_meter_ctx_t *ctx)
{
if (is_keyword(**argv, "id")) {
NEXT_ARGP_RET();
fprintf(stderr, "id: meter access not supported\n");
return ENOTSUP;
} else if (is_keyword(**argv, "name")) {
NEXT_ARGP_RET();
fprintf(stderr, "name: meter access not supported yet\n");
return ENOTSUP;
} else {
int error_code = psabpf_meter_ctx_name(ctx, psabpf_ctx, **argv);
if (error_code != NO_ERROR)
return error_code;
}
int error_code = psabpf_meter_ctx_name(ctx, psabpf_ctx, **argv);
if (error_code != NO_ERROR)
return error_code;

NEXT_ARGP_RET();

Expand Down Expand Up @@ -230,11 +220,10 @@ int do_meter_help(int argc, char **argv) {
(void) argc; (void) argv;

fprintf(stderr,
"Usage: %1$s meter get pipe ID METER index INDEX\n"
" %1$s meter update pipe ID METER index INDEX PIR:PBS CIR:CBS\n"
" %1$s meter reset pipe ID METER index INDEX\n"
"Usage: %1$s meter get pipe ID METER_NAME index INDEX\n"
" %1$s meter update pipe ID METER_NAME index INDEX PIR:PBS CIR:CBS\n"
" %1$s meter reset pipe ID METER_NAME index INDEX\n"
"\n"
" METER := { id METER_ID | name FILE | METER_FILE }\n"
" INDEX := { DATA }\n"
" PIR := { DATA }\n"
" PBS := { DATA }\n"
Expand Down
25 changes: 7 additions & 18 deletions CLI/register.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,11 @@ static int parse_dst_register(int *argc, char ***argv, const char **register_nam
return EINVAL;
}

if (is_keyword(**argv, "id")) {
NEXT_ARGP_RET();
fprintf(stderr, "id: register access not supported\n");
return ENOTSUP;
} else if (is_keyword(**argv, "name")) {
NEXT_ARGP_RET();
fprintf(stderr, "name: register access not supported yet\n");
return ENOTSUP;
} else {
if (register_name != NULL)
*register_name = **argv;
int error_code = psabpf_register_ctx_name(psabpf_ctx, ctx, **argv);
if (error_code != NO_ERROR)
return error_code;
}
if (register_name != NULL)
*register_name = **argv;
int error_code = psabpf_register_ctx_name(psabpf_ctx, ctx, **argv);
if (error_code != NO_ERROR)
return error_code;

NEXT_ARGP();
return NO_ERROR;
Expand Down Expand Up @@ -303,10 +293,9 @@ int do_register_help(int argc, char **argv)
{
(void) argc; (void) argv;
fprintf(stderr,
"Usage: %1$s register get pipe ID REGISTER [index DATA]\n"
" %1$s register set pipe ID REGISTER index DATA value REGISTER_VALUE\n"
"Usage: %1$s register get pipe ID REGISTER_NAME [index DATA]\n"
" %1$s register set pipe ID REGISTER_NAME index DATA value REGISTER_VALUE\n"
"\n"
" REGISTER := { id REGISTER_ID | name REGISTER | REGISTER_FILE }\n"
" REGISTER_VALUE := { DATA }\n"
"",
program_name);
Expand Down
37 changes: 13 additions & 24 deletions CLI/table.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,11 @@
static int parse_dst_table(int *argc, char ***argv, psabpf_context_t *psabpf_ctx,
psabpf_table_entry_ctx_t *ctx, const char **table_name, bool can_be_last)
{
if (is_keyword(**argv, "id")) {
NEXT_ARGP_RET();
fprintf(stderr, "id: table access not supported\n");
return ENOTSUP;
} else if (is_keyword(**argv, "name")) {
NEXT_ARGP_RET();
fprintf(stderr, "name: table access not supported yet\n");
return ENOTSUP;
} else {
if (table_name != NULL)
*table_name = **argv;
int error_code = psabpf_table_entry_ctx_tblname(psabpf_ctx, ctx, **argv);
if (error_code != NO_ERROR)
return error_code;
}
if (table_name != NULL)
*table_name = **argv;
int error_code = psabpf_table_entry_ctx_tblname(psabpf_ctx, ctx, **argv);
if (error_code != NO_ERROR)
return error_code;

if (can_be_last) {
NEXT_ARGP();
Expand Down Expand Up @@ -920,19 +910,18 @@ int do_table_help(int argc, char **argv)
(void) argc; (void) argv;

fprintf(stderr,
"Usage: %1$s table add pipe ID TABLE ACTION key MATCH_KEY [data ACTION_PARAMS] [priority PRIORITY]\n"
" %1$s table add pipe ID TABLE ref key MATCH_KEY data ACTION_REFS [priority PRIORITY]\n"
" %1$s table update pipe ID TABLE ACTION key MATCH_KEY [data ACTION_PARAMS] [priority PRIORITY]\n"
" %1$s table delete pipe ID TABLE [key MATCH_KEY]\n"
" %1$s table default set pipe ID TABLE ACTION [data ACTION_PARAMS]\n"
"Usage: %1$s table add pipe ID TABLE_NAME ACTION key MATCH_KEY [data ACTION_PARAMS] [priority PRIORITY]\n"
" %1$s table add pipe ID TABLE_NAME ref key MATCH_KEY data ACTION_REFS [priority PRIORITY]\n"
" %1$s table update pipe ID TABLE_NAME ACTION key MATCH_KEY [data ACTION_PARAMS] [priority PRIORITY]\n"
" %1$s table delete pipe ID TABLE_NAME [key MATCH_KEY]\n"
" %1$s table default set pipe ID TABLE_NAME ACTION [data ACTION_PARAMS]\n"
/* Support for this one might be preserved, but makes no sense, because indirect tables
* has no default entry. In other words we do not forbid this syntax explicitly.
* " %1$s table default pipe ID TABLE ref data ACTION_REFS\n" */
" %1$s table get pipe ID TABLE [ref] [key MATCH_KEY]\n"
* " %1$s table default pipe ID TABLE_NAME ref data ACTION_REFS\n" */
" %1$s table get pipe ID TABLE_NAME [ref] [key MATCH_KEY]\n"
"Unimplemented commands:\n"
" %1$s table default get pipe ID TABLE\n"
" %1$s table default get pipe ID TABLE_NAME\n"
"\n"
" TABLE := { id TABLE_ID | name FILE | TABLE_FILE }\n"
" ACTION := { id ACTION_ID | ACTION_NAME }\n"
" ACTION_REFS := { MEMBER_REF | group GROUP_REF } \n"
" MATCH_KEY := { EXACT_KEY | LPM_KEY | RANGE_KEY | TERNARY_KEY | none }\n"
Expand Down
65 changes: 26 additions & 39 deletions docs/command reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,13 @@ psabpf-ctl del-port pipe id ID dev DEV
# Tables
```shell
psabpf-ctl table add pipe ID TABLE ACTION key MATCH_KEY [data ACTION_PARAMS] [priority PRIORITY]
psabpf-ctl table add pipe ID TABLE ref key MATCH_KEY data ACTION_REFS [priority PRIORITY]
psabpf-ctl table update pipe ID TABLE ACTION key MATCH_KEY [data ACTION_PARAMS] [priority PRIORITY]
psabpf-ctl table delete pipe ID TABLE [key MATCH_KEY]
psabpf-ctl table default set pipe ID TABLE ACTION [data ACTION_PARAMS]
psabpf-ctl table get pipe ID TABLE [ref] [key MATCH_KEY]

TABLE := { id TABLE_ID | name FILE | TABLE_FILE }
psabpf-ctl table add pipe ID TABLE_NAME ACTION key MATCH_KEY [data ACTION_PARAMS] [priority PRIORITY]
psabpf-ctl table add pipe ID TABLE_NAME ref key MATCH_KEY data ACTION_REFS [priority PRIORITY]
psabpf-ctl table update pipe ID TABLE_NAME ACTION key MATCH_KEY [data ACTION_PARAMS] [priority PRIORITY]
psabpf-ctl table delete pipe ID TABLE_NAME [key MATCH_KEY]
psabpf-ctl table default set pipe ID TABLE_NAME ACTION [data ACTION_PARAMS]
psabpf-ctl table get pipe ID TABLE_NAME [ref] [key MATCH_KEY]

ACTION := { id ACTION_ID | ACTION_NAME }
ACTION_REFS := { MEMBER_REF | group GROUP_REF }
MATCH_KEY := { EXACT_KEY | LPM_KEY | RANGE_KEY | TERNARY_KEY | none }
Expand All @@ -77,7 +76,7 @@ METER_VALUE := { PIR:PBS CIR:CBS }
Commands to implement:
```shell
psabpf-ctl table default get pipe ID TABLE
psabpf-ctl table default get pipe ID TABLE_NAME
```
`ref` keyword means that table has an implementation, `ActionProfile` or `ActionSelector`, and then behave according to
Expand All @@ -86,28 +85,26 @@ this situation.
# Action Selectors
```shell
psabpf-ctl action-selector add_member pipe ID ACTION_SELECTOR ACTION [data ACTION_PARAMS]
psabpf-ctl action-selector delete_member pipe ID ACTION_SELECTOR MEMBER_REF
psabpf-ctl action-selector update_member pipe ID ACTION_SELECTOR MEMBER_REF ACTION [data ACTION_PARAMS]
psabpf-ctl action-selector create_group pipe ID ACTION_SELECTOR
psabpf-ctl action-selector delete_group pipe ID ACTION_SELECTOR GROUP_REF
psabpf-ctl action-selector add_to_group pipe ID ACTION_SELECTOR MEMBER_REF to GROUP_REF
psabpf-ctl action-selector delete_from_group pipe ID ACTION_SELECTOR MEMBER_REF from GROUP_REF
psabpf-ctl action-selector default_group_action pipe ID ACTION_SELECTOR ACTION [data ACTION_PARAMS]

ACTION_SELECTOR := { id ACTION_SELECTOR_ID | name FILE | ACTION_SELECTOR_FILE }
psabpf-ctl action-selector add_member pipe ID ACTION_SELECTOR_NAME ACTION [data ACTION_PARAMS]
psabpf-ctl action-selector delete_member pipe ID ACTION_SELECTOR_NAME MEMBER_REF
psabpf-ctl action-selector update_member pipe ID ACTION_SELECTOR_NAME MEMBER_REF ACTION [data ACTION_PARAMS]
psabpf-ctl action-selector create_group pipe ID ACTION_SELECTOR_NAME
psabpf-ctl action-selector delete_group pipe ID ACTION_SELECTOR_NAME GROUP_REF
psabpf-ctl action-selector add_to_group pipe ID ACTION_SELECTOR_NAME MEMBER_REF to GROUP_REF
psabpf-ctl action-selector delete_from_group pipe ID ACTION_SELECTOR_NAME MEMBER_REF from GROUP_REF
psabpf-ctl action-selector default_group_action pipe ID ACTION_SELECTOR_NAME ACTION [data ACTION_PARAMS]

ACTION := { id ACTION_ID | ACTION_NAME }
ACTION_PARAMS := { DATA }
```
# Meters
```shell
psabpf-ctl meter get pipe ID METER index INDEX
psabpf-ctl meter update pipe ID METER index INDEX PIR:PBS CIR:CBS
psabpf-ctl meter reset pipe ID METER index INDEX
psabpf-ctl meter get pipe ID METER_NAME index INDEX
psabpf-ctl meter update pipe ID METER_NAME index INDEX PIR:PBS CIR:CBS
psabpf-ctl meter reset pipe ID METER_NAME index INDEX

METER := { id METER_ID | name FILE | METER_FILE }
INDEX := { DATA }
PIR := { DATA }
PBS := { DATA }
Expand All @@ -118,34 +115,24 @@ CBS := { DATA }
# Digests
```shell
psabpf-ctl digest get pipe ID DIGEST

DIGEST := { id DIGEST_ID | name FILE | DIGEST_FILE }
psabpf-ctl digest get pipe ID DIGEST_NAME
```
# Counters
```shell
psabpf-ctl counter get pipe ID COUNTER [key DATA]
psabpf-ctl counter set pipe ID COUNTER [key DATA] value COUNTER_VALUE
psabpf-ctl counter reset pipe ID COUNTER [key DATA]
psabpf-ctl counter get pipe ID COUNTER_NAME [key DATA]
psabpf-ctl counter set pipe ID COUNTER_NAME [key DATA] value COUNTER_VALUE
psabpf-ctl counter reset pipe ID COUNTER_NAME [key DATA]

COUNTER := { id COUNTER_ID | name COUNTER | COUNTER_FILE }
COUNTER_VALUE := { BYTES | PACKETS | BYTES:PACKETS }
```
# Registers
```shell
psabpf-ctl register get pipe ID REGISTER [index DATA]
psabpf-ctl register set pipe ID REGISTER index DATA value REGISTER_VALUE
psabpf-ctl register get pipe ID REGISTER_NAME [index DATA]
psabpf-ctl register set pipe ID REGISTER_NAME index DATA value REGISTER_VALUE

REGISTER := { id REGISTER_ID | name REGISTER | REGISTER_FILE }
REGISTER_VALUE := { DATA }
```
Commands to implement:
```shell
psabpf-ctl register set pipe ID REGISTER index DATA value REGISTER_VALUE
psabpf-ctl register reset pipe ID REGISTER index DATA
```
2 changes: 1 addition & 1 deletion lib/psabpf_pipeline.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ static int join_tuple_to_map_if_tuple(psabpf_context_t *ctx, const char *tuple_n
const char *ternary_tbl_name_lst_char_ptr = strstr(tuple_name, suffix);

if (ternary_tbl_name_lst_char_ptr) {
char tuples_map_name[256];
char tuples_map_name[268];
int ternary_map_name_length = (int)(ternary_tbl_name_lst_char_ptr - tuple_name);
char map_name[256];
strncpy(map_name, tuple_name, ternary_map_name_length);
Expand Down

0 comments on commit 2bbdab1

Please sign in to comment.