From: Ales Musil <[email protected]>

Allow sample to accept obs_point_id as register instead of integer
literal value.

Signed-off-by: Ales Musil <[email protected]>
---
V6:
- Removed Dumitru's ack.
V5:
- Added Dumitru's ack
---
 include/ovn/actions.h | 16 +++++++++-------
 lib/actions.c         | 12 ++++++++----
 tests/ovn.at          | 13 ++++++++++++-
 3 files changed, 29 insertions(+), 12 deletions(-)

diff --git a/include/ovn/actions.h b/include/ovn/actions.h
index 88cf4de79f..c8dd66ed83 100644
--- a/include/ovn/actions.h
+++ b/include/ovn/actions.h
@@ -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. */
diff --git a/lib/actions.c b/lib/actions.c
index 37676ef81b..586c64af36 100644
--- a/lib/actions.c
+++ b/lib/actions.c
@@ -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, ");");
 }
@@ -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;
     }
@@ -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)) {
diff --git a/tests/ovn.at b/tests/ovn.at
index 0f401ab96a..f1fc29503f 100644
--- a/tests/ovn.at
+++ b/tests/ovn.at
@@ -2333,11 +2333,19 @@ 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.
@@ -2345,6 +2353,9 @@ 
sample(probability=0,collector_set=200,obs_domain=300,obs_point=foo);
 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)
-- 
2.45.2

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to