-
Notifications
You must be signed in to change notification settings - Fork 829
[cli] Add sample_rate and truncate_size to mirror session CLI #4459
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
base: master
Are you sure you want to change the base?
Changes from all commits
a2c3e10
8a7a9b5
0469bac
1b601cc
819a8c9
9c9fe39
9b0d02c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -125,6 +125,25 @@ | |
|
|
||
| asic_type = None | ||
|
|
||
|
|
||
| SAMPLE_RATE_MIN = 256 | ||
| SAMPLE_RATE_MAX = 8388608 | ||
| TRUNCATE_SIZE_MIN = 64 | ||
| TRUNCATE_SIZE_MAX = 9216 | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error message There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Still open — same concern as the other thread. Error message doesn't mention 0 is accepted. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same nit — error message doesn't mention 0 is valid. Non-blocking. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above — the reframed help text ("Omit for full mirror" / "Omit for no truncation") makes the error message consistent. No longer need to mention 0. Resolved. |
||
|
|
||
| def validate_sample_rate(ctx, param, value): | ||
|
Janetxxx marked this conversation as resolved.
|
||
| if value != 0 and (value < SAMPLE_RATE_MIN or value > SAMPLE_RATE_MAX): | ||
| raise click.BadParameter(f"must be {SAMPLE_RATE_MIN}..{SAMPLE_RATE_MAX}") | ||
| return value | ||
|
|
||
|
|
||
| def validate_truncate_size(ctx, param, value): | ||
| if value != 0 and (value < TRUNCATE_SIZE_MIN or value > TRUNCATE_SIZE_MAX): | ||
| raise click.BadParameter(f"must be {TRUNCATE_SIZE_MIN}..{TRUNCATE_SIZE_MAX}") | ||
| return value | ||
|
|
||
|
|
||
| DSCP_RANGE = click.IntRange(min=0, max=63) | ||
| TTL_RANGE = click.IntRange(min=0, max=255) | ||
| QUEUE_RANGE = click.IntRange(min=0, max=255) | ||
|
|
@@ -3190,12 +3209,20 @@ def erspan(ctx): | |
| @click.argument('src_port', metavar='[src_port]', required=False) | ||
| @click.argument('direction', metavar='[direction]', required=False) | ||
| @click.option('--policer') | ||
| def erspan_add(session_name, src_ip, dst_ip, dscp, ttl, gre_type, queue, policer, src_port, direction): | ||
| @click.option('--sample_rate', type=int, default=0, callback=validate_sample_rate, | ||
| help='Sampling rate (1-in-N). Valid range: 256..8388608. Omit for full mirror.') | ||
| @click.option('--truncate_size', type=int, default=0, callback=validate_truncate_size, | ||
| help='Truncation size in bytes. Valid range: 64..9216. Omit for no truncation.') | ||
| def erspan_add(session_name, src_ip, dst_ip, dscp, ttl, gre_type, queue, policer, src_port, direction, | ||
| sample_rate, truncate_size): | ||
| """ Add ERSPAN mirror session """ | ||
| add_erspan(session_name, src_ip, dst_ip, dscp, ttl, gre_type, queue, policer, src_port, direction) | ||
| add_erspan(session_name, src_ip, dst_ip, dscp, ttl, gre_type, | ||
| queue, policer, src_port, direction, | ||
| sample_rate, truncate_size) | ||
|
|
||
|
|
||
| def gather_session_info(session_info, policer, queue, src_port, direction): | ||
| def gather_session_info(session_info, policer, queue, src_port, direction, | ||
| sample_rate=0, truncate_size=0): | ||
| if policer: | ||
| session_info['policer'] = policer | ||
|
|
||
|
|
@@ -3208,9 +3235,18 @@ def gather_session_info(session_info, policer, queue, src_port, direction): | |
| direction = "both" | ||
|
Janetxxx marked this conversation as resolved.
|
||
| session_info['direction'] = direction.upper() | ||
|
|
||
| if sample_rate: | ||
| session_info['sample_rate'] = str(sample_rate) | ||
|
|
||
| if truncate_size: | ||
| session_info['truncate_size'] = str(truncate_size) | ||
|
|
||
| return session_info | ||
|
|
||
| def add_erspan(session_name, src_ip, dst_ip, dscp, ttl, gre_type, queue, policer, src_port=None, direction=None): | ||
|
|
||
| def add_erspan(session_name, src_ip, dst_ip, dscp, ttl, gre_type, queue, | ||
| policer, src_port=None, direction=None, | ||
| sample_rate=0, truncate_size=0): | ||
| session_info = { | ||
| "type" : "ERSPAN", | ||
| "src_ip": src_ip, | ||
|
|
@@ -3222,7 +3258,8 @@ def add_erspan(session_name, src_ip, dst_ip, dscp, ttl, gre_type, queue, policer | |
| if gre_type is not None: | ||
| session_info['gre_type'] = gre_type | ||
|
|
||
| session_info = gather_session_info(session_info, policer, queue, src_port, direction) | ||
| session_info = gather_session_info(session_info, policer, queue, src_port, direction, | ||
| sample_rate, truncate_size) | ||
| raw_src_port = session_info.get('src_port') | ||
| ctx = click.get_current_context() | ||
|
|
||
|
|
@@ -3333,6 +3370,7 @@ def span_add(session_name, dst_port, src_port, direction, queue, policer): | |
| """ Add SPAN mirror session """ | ||
| add_span(session_name, dst_port, src_port, direction, queue, policer) | ||
|
|
||
|
|
||
| def add_span(session_name, dst_port, src_port, direction, queue, policer): | ||
| # Save original dst_port for namespace detection (before alias conversion) | ||
| original_dst_port = dst_port | ||
|
|
@@ -3435,7 +3473,7 @@ def remove(session_name): | |
| else: | ||
| per_npu_configdb = {} | ||
| for front_asic_namespaces in namespaces['front_ns']: | ||
| per_npu_configdb[front_asic_namespaces] = ValidatedConfigDBConnector(ConfigDBConnector(use_unix_socket_path=True, namespace=front_asic_namespaces)) | ||
| per_npu_configdb[front_asic_namespaces] = ValidatedConfigDBConnector(ConfigDBConnector(use_unix_socket_path=True, namespace=front_asic_namespaces)) # noqa: E501 | ||
| per_npu_configdb[front_asic_namespaces].connect() | ||
| if per_npu_configdb[front_asic_namespaces].get_entry("MIRROR_SESSION", session_name): | ||
| try: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor nit: The error message
must be 256..8388608doesn't mention that 0 is also a valid value (disabled). A user seeing this error might not realize 0 is accepted. Consider:must be 0 (disabled) or 256..8388608. Same forvalidate_truncate_size. Low priority — not blocking.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still a valid nit. The error message says
must be 256..8388608but doesn't mention 0 is also accepted. Low priority, but would improve UX.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still open. Error messages still say
must be 256..8388608/must be 64..9216without mentioning 0 is valid. Low priority nit but would improve UX.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still valid nit — error message omits that 0 is accepted. Non-blocking, but would be a nice UX improvement in a follow-up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed by new design direction. Help text now says "Omit for full mirror" instead of "0 = disabled", so the error message
must be 256..8388608is consistent — users are not expected to explicitly pass 0. The magic numbers are now constants too. Looks good.