sonic-net / DASH

Disaggregated APIs for SONiC Hosts
Apache License 2.0
80 stars 89 forks source link

[sai-gen] Add type hints for SAI generation scripts. #489

Closed r12f closed 8 months ago

r12f commented 8 months ago

Add type hints to make the code more maintainable since it will be even less likely to go wrong.

As previous refactoring changes, no updates on generated files:

image

kcudnik commented 8 months ago

Please fix build errors

r12f commented 8 months ago

ok, the tests are passed now. :D @kcudnik , this change is now ready for review.

r12f commented 8 months ago

thanks Chris!

but in a way that's going backwards to making it "understand" dash code!

and yep, this is something I am working on right now for counters. Basically, to generate the counter attributes, we have to add unused parameters into table action parameters, which is really weird to understand. a more proper way is actually to parse the p4 bmv2 program and find the counter writes to build the relationship.

i am working on 2 PRs, one add SAICounter annotation to make the counter in use. another one to parse the P4 program and build the relationships. this will makes more sense than the heuristics we had, such as the naming patterns, or the number of fields that an action has and etc.

r12f commented 8 months ago

adding one example as reference:

#ifdef TARGET_BMV2_V1MODEL
    counter(MAX_METER_BUCKETS, CounterType.bytes) meter_bucket_inbound;
    counter(MAX_METER_BUCKETS, CounterType.bytes) meter_bucket_outbound;
#endif // TARGET_BMV2_V1MODEL
    action meter_bucket_action(
            @SaiVal[type="sai_uint64_t", isreadonly="true"] bit<64> outbound_bytes_counter,
            @SaiVal[type="sai_uint64_t", isreadonly="true"] bit<64> inbound_bytes_counter,
            @SaiVal[type="sai_uint32_t", skipattr="true"] bit<32> meter_bucket_index) {
        // read only counters for SAI api generation only
        meta.meter_bucket_index = meter_bucket_index;
    }