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

Refactor control API #255

Closed
wants to merge 16 commits into from
Closed

Refactor control API #255

wants to merge 16 commits into from

Conversation

ashutshkumr
Copy link
Contributor

@ashutshkumr ashutshkumr commented Jul 21, 2022

Check documentation here.

What has changed (and why) ?

  • Refactored all control APIs into three major categories - control state, control action and control patch
    • Previously we had too many API endpoints for controlling states/actions - resulting in different function calls at SDK level for slightly related operations
    • There was no clear distinction between intent of exposed APIs - i.e. lack of organization
    • We know already that there are lots more to come, and hence it helps to keep the top level API less polluted/noisy
  • Grouped capture, states and metrics under one category called Monitor.
    • Its meaning resembles that of telemetry, but encompasses things like captured packets which traditionally doesn't fit the openconfig's interpretation of telemetry.
    • result is no longer an appropriate terminology because they more closely imply "one-off output" instead of "ever changing output".

What's pending ?

  • result keyword is mentioned in a lot of places, and hence would like to replace them (only in select places) if we're ok with new terminology - aka monitor
  • Need to discuss if we should expose warnings as an additional output for metrics/states. As of today, there's no way to return warning in those scenarios.

Backwards Compatibility

  • This change essentially breaks backwards compatibility because it will affect all control APIs, deprecating which might take longer than expected and might further add to the confusion (e.g. we'll end up having two ways of doing too many things for a long time)
  • From SDK perspective, breakage shall be on a function call-level, and hence shall only require changes in otg helper library

Examples

  • Before

     api := gosnappi.NewApi()
    
     c := api.NewConfig()
    
     // set config
     api.SetConfig(c)
    
     // start protocols
     ps := gosnappi.NewProtocolState()
     ps.SetState(gosnappi.ProtocolStateState.START)
     api.SetProtocolState(ps)
    
     // wait for protocol metrics to be ok ...
    
     // start transmit
     ts := gosnappi.NewTransmitState()
     ts.SetState(gosnappi.TransmitStateState.START)
     api.SetTransmitState(ts)
    
     // wait for flow metrics to be ok ...
    
     // withdraw some routes
     rs := gosnappi.NewRouteState()
     rs.SetNames([]string{"rr1"})
     rs.SetState(gosnappi.RouteStateState.WITHDRAW)
     api.SetRouteState(rs)
  • After

     api := gosnappi.NewApi()
    
     c := api.NewConfig()
    
     // set config
     api.SetConfig(c)
    
     // start protocols
     ps := gosnappi.NewControlState()
     ps.Protocol().SetState(gosnappi.ProtocolStateState.START)
     api.SetControlState(ps)
    
     // wait for protocol metrics to be ok ...
    
     // start transmit
     ts := gosnappi.NewControlState()
     ts.FlowTransmit().SetState(gosnappi.TransmitStateState.START)
     api.SetControlState(ts)
    
     // wait for flow metrics to be ok ...
    
     // withdraw some routes
     rs := gosnappi.NewControlState()
     rs.Route().
     	SetNames([]string{"rr1"}).
     	SetState(gosnappi.RouteStateState.WITHDRAW)
     api.SetControlState(rs)

@ashutshkumr ashutshkumr changed the title Refactor for control API Refactor control API Jul 25, 2022
@ashutshkumr ashutshkumr requested a review from SuryyaKrJana July 25, 2022 11:07
control/patch.yaml Outdated Show resolved Hide resolved
control/state.yaml Outdated Show resolved Hide resolved
control/state.yaml Show resolved Hide resolved
Copy link

@winstonliu1111 winstonliu1111 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we update the modeling guide as well so it is clear what should go into state/action/patch ??

schemas:
Control.Patch:
description: >-
Request for triggering action on resources in traffic generator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

description needs change? this is not triggering action on resources?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed, changed.

Copy link
Contributor

@SuryyaKrJana SuryyaKrJana left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look ok to me.

@anjan-keysight
Copy link
Contributor

Looks good to me.

@ashutshkumr ashutshkumr reopened this Aug 2, 2022
api/api.yaml Outdated Show resolved Hide resolved
version: ^0.0.0

components:
schemas:
LacpMember.State:
Lacp.State:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if every protocol should also have a set of choices in the heirarchy , since in future we might need to add additional triggers in any protocol (e.g. LACP ) based on end-user requirements. Or we can also choose to have separate choices at top level when the name should probably remain LacpMember to distinguish against future additional triggers,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per the most recent discussion, every protocol shall have its own set of choices, if the need arises to add more triggers for a given protocol.

We probably should avoid adding top level choices unless it's a separate protocol altogether. Let me know if you plan to suggest a change here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dont we need to then add a choice under Lacp , with a single choice available now ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should make it a choice under LACP from the beginning, to make it explicit. Also, new choices might have a different set of arguments to trigger the event.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@apratimmukherjee @PrasenjitAdhikary kindly review again - I've made the suggested changes.

The list of configured flows for which given property will be updated.
type: array
items:
$ref: '../flow/flow.yaml#/components/schemas/Flow'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though this is not related to this PR , I could not follow the exact semantics for patch_config . Lets assume at one time we can update only 1 resource e.g flows. We have 5 flows. Since property names is an array , I assume this means the same set of properties will be updated for all specified flows (e.g. only rate or only size or both i.e. array size possibly cant be more than 2 and values should not be duplicate for properties array. After this , I got confused since looks to me that user has to specify entire flow once again . Should user not be allowed to update only rate or size per flow (specified by flowname) and other properties should be hidden in this API . And validation should be done that specified sub-fields match fields chosen in 'property' array. i.e. should the updatable properties have a dedicated different structure such as flow_patch_attribs etc. Or did I miss the intent of the patch API for flows.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason there's no dedicated data structure for updating flow properties like size and rate is because from SDK UX POV, it's easier for users to work with.

c = api.config()
f1 = c.flows.add(name='f1')
f1.size.fixed = 256
f1.rate.pps = 500
f2 = c.flows.add(name='f2')
f2.size.fixed = 256
f2.rate.pps = 500

# set config for the first time
api.set_config(c)

# update rate for flow1
f1.rate.pps = 1000

cp = api.control_patch()
cp.flows.property_names = ["rate"]
cp.flows.flows = [f1]
api.set_control_patch(cp)

# fetch newly updated config
cpatched = api.get_config()

# fetched config shall be equivalent to what user already has
assert c == cpatched

Copy link
Contributor

@apratimmukherjee apratimmukherjee Aug 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like we should probably be explicit that only the values set in specified fields ( one of rate or size for flows ) will be patched with current config only for specified flows. The values of all remaining fields in the provided flows will be ignored ( or validated that no other fields are changed ?) . I assume if no changes are done for corresponding attribute , then no separate warning is expected to be provided.

Copy link
Contributor

@ajbalogh ajbalogh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm


components:
schemas:
Control.Patch:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unlike any other control API, this action changes the configuration (which will also reflect in get_config). Need to reflect that in the description, to avoid any ambiguity.
On second thought, if the API should be moved under the configuration group - and renamed to update_config - since the other two APIs in the group are also related to configuration and it will be obvious that the configuration would be modified and reflected in get_config?

Copy link
Contributor

@apratimmukherjee apratimmukherjee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

Copy link
Contributor

@PrasenjitAdhikary PrasenjitAdhikary left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

type: array
items:
type: string
x-constraint:
- '/components/schemas/Port/properties/name'
state:
description: >-
The LACP Member admin state.
The LACP member admin state.
'up' will start transmission of LACPDUs on selected member ports.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed the descriptions with Subrata/Sourav since I was under the impression that this is no longer accurate.
Can you please change the 'up' and 'down' description to below ( as received from Subrata ) which is more accurate than what was added initially:
'up' will turn on ‘sync’ flag of LACPDUs transmitted from selected member ports.
'down' will turn off ‘sync’ flag of LACPDUs transmitted from selected member ports.

@ashutshkumr
Copy link
Contributor Author

Replaced by #305

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants