Skip to content

Commit

Permalink
actions: Add support for sample with register.
Browse files Browse the repository at this point in the history
Allow sample to accept obs_point_id as register instead of integer
literal value.

Signed-off-by: Ales Musil <[email protected]>
  • Loading branch information
almusil authored and dceara committed Jul 31, 2024
1 parent b3d67b5 commit 9169ea1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
16 changes: 9 additions & 7 deletions include/ovn/actions.h
Original file line number Diff line number Diff line change
Expand Up @@ -498,13 +498,15 @@ struct ovnact_lookup_fdb {
/* OVNACT_SAMPLE */
struct ovnact_sample {
struct ovnact ovnact;
uint16_t probability; /* probability over UINT16_MAX. */
uint8_t obs_domain_id; /* most significant byte of the
observation domain id. The other 24 bits
will come from the datapath's tunnel key. */
uint32_t collector_set_id; /* colector_set_id. */
uint32_t obs_point_id; /* observation point id. */
bool use_cookie; /* use cookie as obs_point_id */
uint16_t probability; /* probability over UINT16_MAX. */
uint8_t obs_domain_id; /* most significant byte of the
observation domain id. The other
24 bits will come from the
datapath's tunnel key. */
uint32_t collector_set_id; /* colector_set_id. */
struct expr_field obs_point_id_src; /* observation point id source reg */
uint32_t obs_point_id; /* observation point id */
bool use_cookie; /* use cookie as obs_point_id */
};

/* OVNACT_COMMIT_ECMP_NH. */
Expand Down
12 changes: 8 additions & 4 deletions lib/actions.c
Original file line number Diff line number Diff line change
Expand Up @@ -4523,10 +4523,13 @@ format_SAMPLE(const struct ovnact_sample *sample, struct ds *s)

ds_put_format(s, ",collector_set=%"PRIu32, sample->collector_set_id);
ds_put_format(s, ",obs_domain=%"PRIu8, sample->obs_domain_id);
ds_put_cstr(s, ",obs_point=");
if (sample->use_cookie) {
ds_put_cstr(s, ",obs_point=$cookie");
ds_put_cstr(s, "$cookie");
} else if (sample->obs_point_id_src.symbol) {
expr_field_format(&sample->obs_point_id_src, s);
} else {
ds_put_format(s, ",obs_point=%"PRIu32, sample->obs_point_id);
ds_put_format(s, "%"PRIu32, sample->obs_point_id);
}
ds_put_format(s, ");");
}
Expand All @@ -4551,6 +4554,8 @@ encode_SAMPLE(const struct ovnact_sample *sample,

if (sample->use_cookie) {
os->obs_point_imm = ep->lflow_uuid.parts[0];
} else if (sample->obs_point_id_src.symbol) {
os->obs_point_src = expr_resolve_field(&sample->obs_point_id_src);
} else {
os->obs_point_imm = sample->obs_point_id;
}
Expand Down Expand Up @@ -4584,8 +4589,7 @@ parse_sample_arg(struct action_context *ctx, struct ovnact_sample *sample)
sample->obs_point_id = ntohll(ctx->lexer->token.value.integer);
lexer_get(ctx->lexer);
} else {
lexer_syntax_error(ctx->lexer,
"malformed sample observation_point_id");
action_parse_field(ctx, 32, false, &sample->obs_point_id_src);
}
} else if (lexer_match_id(ctx->lexer, "obs_domain")) {
if (!lexer_force_match(ctx->lexer, LEX_T_EQUALS)) {
Expand Down
13 changes: 12 additions & 1 deletion tests/ovn.at
Original file line number Diff line number Diff line change
Expand Up @@ -2333,18 +2333,29 @@ sample(probability=10);
sample(probability=100,collector_set=999,obs_domain=0,obs_point=1000);
encodes as drop

sample(probability=10, obs_point=reg3);
formats as sample(probability=10,collector_set=0,obs_domain=0,obs_point=reg3);
encodes as sample(probability=10,collector_set_id=0,obs_domain_id=11259375,obs_point_id=NXM_NX_XXREG0[[0..31]])

sample(probability=10, obs_point=ct_label.obs_point_id);
formats as sample(probability=10,collector_set=0,obs_domain=0,obs_point=ct_label.obs_point_id);
encodes as sample(probability=10,collector_set_id=0,obs_domain_id=11259375,obs_point_id=NXM_NX_CT_LABEL[[96..127]])

sample(probability=0,collector_set=200,obs_domain=0,obs_point=1000);
probability must be greater than zero

sample(probability=0,collector_set=200,obs_domain=0,obs_point=foo);
Syntax error at `foo' malformed sample observation_point_id.
Syntax error at `foo' expecting field name.

sample(probability=0,collector_set=200,obs_domain=300,obs_point=foo);
Syntax error at `300' obs_domain must be 8-bit long.

sample(probability=10,foo=bar,obs_domain=0,obs_point=1000);
Syntax error at `foo' unknown argument.

sample(probability=10, obs_point=ct_label);
Cannot use 128-bit field ct_label[[0..127]] where 32-bit field is required.

# mac_cache_use
mac_cache_use;
encodes as resubmit(,OFTABLE_MAC_CACHE_USE)
Expand Down

0 comments on commit 9169ea1

Please sign in to comment.