Skip to content

Commit

Permalink
Support create_ports and fix bug in generated code (#355)
Browse files Browse the repository at this point in the history
* Support create_ports and fix bug in generated code

* feedback
  • Loading branch information
DanG100 authored Feb 8, 2024
1 parent 8b665aa commit f6f155e
Show file tree
Hide file tree
Showing 18 changed files with 170 additions and 13 deletions.
2 changes: 1 addition & 1 deletion dataplane/apigen/apigen.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func parse(headers []string, includePaths ...string) (*cc.AST, error) {
const (
saiPath = "bazel-lemming/external/com_github_opencomputeproject_sai"
ccOutDir = "dataplane/standalone/sai"
protoOutDir = "dataplane/proto"
protoOutDir = "dataplane/proto/sai"
)

func generate() error {
Expand Down
5 changes: 4 additions & 1 deletion dataplane/apigen/ccgen/ccgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -652,8 +652,11 @@ return msg;
LOG(ERROR) << status.error_message();
return SAI_STATUS_FAILURE;
}
if (object_count != resp.resps().size()) {
return SAI_STATUS_FAILURE;
}
for (uint32_t i = 0; i < object_count; i++) {
{{ if .OidVar -}} {{ .OidVar }} = object_id[i] = resp.resps(i).oid(); {{ end }}
{{ if .OidVar -}} object_id[i] = resp.resps(i).oid(); {{ end }}
object_statuses[i] = SAI_STATUS_SUCCESS;
}
Expand Down
13 changes: 13 additions & 0 deletions dataplane/saiserver/ports.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,19 @@ func (port *port) CreatePort(ctx context.Context, req *saipb.CreatePortRequest)
}, nil
}

// CreatePorts creates multiple ports.
func (port *port) CreatePorts(ctx context.Context, re *saipb.CreatePortsRequest) (*saipb.CreatePortsResponse, error) {
resp := &saipb.CreatePortsResponse{}
for _, req := range re.GetReqs() {
res, err := attrmgr.InvokeAndSave(ctx, port.mgr, port.CreatePort, req)
if err != nil {
return nil, err
}
resp.Resps = append(resp.Resps, res)
}
return resp, nil
}

func (port *port) createCPUPort(ctx context.Context) (uint64, error) {
id := port.mgr.NextID()

Expand Down
99 changes: 99 additions & 0 deletions dataplane/saiserver/ports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,105 @@ func TestCreatePort(t *testing.T) {
}
}

func TestCreatePorts(t *testing.T) {
tests := []struct {
desc string
req *saipb.CreatePortsRequest
getInterfaceErr error
want *saipb.CreatePortsResponse
wantAttr *saipb.PortAttribute
wantErr string
}{{
desc: "success",
req: &saipb.CreatePortsRequest{
Reqs: []*saipb.CreatePortRequest{{}},
},
want: &saipb.CreatePortsResponse{
Resps: []*saipb.CreatePortResponse{{Oid: 1}},
},
wantAttr: &saipb.PortAttribute{
OperStatus: saipb.PortOperStatus_PORT_OPER_STATUS_UP.Enum(),
QosNumberOfQueues: proto.Uint32(0),
QosQueueList: []uint64{},
QosNumberOfSchedulerGroups: proto.Uint32(0),
QosSchedulerGroupList: []uint64{},
IngressPriorityGroupList: []uint64{},
FloodStormControlPolicerId: proto.Uint64(0),
BroadcastStormControlPolicerId: proto.Uint64(0),
MulticastStormControlPolicerId: proto.Uint64(0),
IngressAcl: proto.Uint64(0),
EgressAcl: proto.Uint64(0),
IngressMacsecAcl: proto.Uint64(0),
EgressMacsecAcl: proto.Uint64(0),
MacsecPortList: []uint64{},
IngressMirrorSession: []uint64{},
EgressMirrorSession: []uint64{},
IngressSamplepacketEnable: proto.Uint64(0),
EgressSamplepacketEnable: proto.Uint64(0),
IngressSampleMirrorSession: []uint64{},
EgressSampleMirrorSession: []uint64{},
PolicerId: proto.Uint64(0),
QosDot1PToTcMap: proto.Uint64(0),
QosDot1PToColorMap: proto.Uint64(0),
QosDscpToTcMap: proto.Uint64(0),
QosDscpToColorMap: proto.Uint64(0),
QosTcToQueueMap: proto.Uint64(0),
QosTcAndColorToDot1PMap: proto.Uint64(0),
QosTcAndColorToDscpMap: proto.Uint64(0),
QosTcToPriorityGroupMap: proto.Uint64(0),
QosPfcPriorityToPriorityGroupMap: proto.Uint64(0),
QosPfcPriorityToQueueMap: proto.Uint64(0),
QosSchedulerProfileId: proto.Uint64(0),
QosIngressBufferProfileList: []uint64{},
QosEgressBufferProfileList: []uint64{},
EgressBlockPortList: []uint64{},
PortPoolList: []uint64{},
IsolationGroup: proto.Uint64(0),
TamObject: []uint64{},
PortSerdesId: proto.Uint64(0),
QosMplsExpToTcMap: proto.Uint64(0),
QosMplsExpToColorMap: proto.Uint64(0),
QosTcAndColorToMplsExpMap: proto.Uint64(0),
SystemPort: proto.Uint64(0),
QosDscpToForwardingClassMap: proto.Uint64(0),
QosMplsExpToForwardingClassMap: proto.Uint64(0),
IpsecPort: proto.Uint64(0),
SupportedSpeed: []uint32{1000, 10000, 40000},
OperSpeed: proto.Uint32(40000),
SupportedFecMode: []saipb.PortFecMode{saipb.PortFecMode_PORT_FEC_MODE_NONE},
NumberOfIngressPriorityGroups: proto.Uint32(0),
QosMaximumHeadroomSize: proto.Uint32(0),
AdminState: proto.Bool(true),
AutoNegMode: proto.Bool(true),
Mtu: proto.Uint32(1514),
},
}}
for _, tt := range tests {
t.Run(tt.desc, func(t *testing.T) {
dplane := &fakeSwitchDataplane{}
c, mgr, stopFn := newTestPort(t, dplane)
defer stopFn()
got, gotErr := c.CreatePorts(context.TODO(), tt.req)
if diff := errdiff.Check(gotErr, tt.wantErr); diff != "" {
t.Fatalf("CreatePort() unexpected err: %s", diff)
}
if gotErr != nil {
return
}
if d := cmp.Diff(got, tt.want, protocmp.Transform()); d != "" {
t.Errorf("CreatePorts() failed: diff(-got,+want)\n:%s", d)
}
attr := &saipb.PortAttribute{}
if err := mgr.PopulateAllAttributes("1", attr); err != nil {
t.Fatal(err)
}
if d := cmp.Diff(attr, tt.wantAttr, protocmp.Transform()); d != "" {
t.Errorf("CreatePorts() failed: diff(-got,+want)\n:%s", d)
}
})
}
}

func TestSetPortAttribute(t *testing.T) {
tests := []struct {
desc string
Expand Down
6 changes: 3 additions & 3 deletions dataplane/standalone/sai/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ class PortStateReactor
sai_port_state_change_notification_fn callback) {
this->callback = callback;
lemming::dataplane::sai::PortStateChangeNotificationRequest req;
stub->experimental_async()->PortStateChangeNotification(&context, &req, this);
stub->experimental_async()->PortStateChangeNotification(&context, &req,
this);
StartRead(&resp);
StartCall();
}
Expand All @@ -235,7 +236,7 @@ class PortStateReactor
lemming::dataplane::sai::PortStateChangeNotificationResponse resp;
sai_port_state_change_notification_fn callback;
};
#else
#else
class PortStateReactor
: public grpc::ClientReadReactor<
lemming::dataplane::sai::PortStateChangeNotificationResponse> {
Expand Down Expand Up @@ -272,5 +273,4 @@ class PortStateReactor
};
#endif


#endif // DATAPLANE_STANDALONE_SAI_COMMON_H_
3 changes: 3 additions & 0 deletions dataplane/standalone/sai/fdb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ sai_status_t l_create_fdb_entries(uint32_t object_count,
LOG(ERROR) << status.error_message();
return SAI_STATUS_FAILURE;
}
if (object_count != resp.resps().size()) {
return SAI_STATUS_FAILURE;
}
for (uint32_t i = 0; i < object_count; i++) {
object_statuses[i] = SAI_STATUS_SUCCESS;
}
Expand Down
5 changes: 4 additions & 1 deletion dataplane/standalone/sai/lag.cc
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,11 @@ sai_status_t l_create_lag_members(sai_object_id_t switch_id,
LOG(ERROR) << status.error_message();
return SAI_STATUS_FAILURE;
}
if (object_count != resp.resps().size()) {
return SAI_STATUS_FAILURE;
}
for (uint32_t i = 0; i < object_count; i++) {
switch_id = object_id[i] = resp.resps(i).oid();
object_id[i] = resp.resps(i).oid();
object_statuses[i] = SAI_STATUS_SUCCESS;
}

Expand Down
3 changes: 3 additions & 0 deletions dataplane/standalone/sai/mpls.cc
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,9 @@ sai_status_t l_create_inseg_entries(uint32_t object_count,
LOG(ERROR) << status.error_message();
return SAI_STATUS_FAILURE;
}
if (object_count != resp.resps().size()) {
return SAI_STATUS_FAILURE;
}
for (uint32_t i = 0; i < object_count; i++) {
object_statuses[i] = SAI_STATUS_SUCCESS;
}
Expand Down
3 changes: 3 additions & 0 deletions dataplane/standalone/sai/nat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,9 @@ sai_status_t l_create_nat_entries(uint32_t object_count,
LOG(ERROR) << status.error_message();
return SAI_STATUS_FAILURE;
}
if (object_count != resp.resps().size()) {
return SAI_STATUS_FAILURE;
}
for (uint32_t i = 0; i < object_count; i++) {
object_statuses[i] = SAI_STATUS_SUCCESS;
}
Expand Down
3 changes: 3 additions & 0 deletions dataplane/standalone/sai/neighbor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,9 @@ sai_status_t l_create_neighbor_entries(
LOG(ERROR) << status.error_message();
return SAI_STATUS_FAILURE;
}
if (object_count != resp.resps().size()) {
return SAI_STATUS_FAILURE;
}
for (uint32_t i = 0; i < object_count; i++) {
object_statuses[i] = SAI_STATUS_SUCCESS;
}
Expand Down
5 changes: 4 additions & 1 deletion dataplane/standalone/sai/next_hop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,11 @@ sai_status_t l_create_next_hops(sai_object_id_t switch_id,
LOG(ERROR) << status.error_message();
return SAI_STATUS_FAILURE;
}
if (object_count != resp.resps().size()) {
return SAI_STATUS_FAILURE;
}
for (uint32_t i = 0; i < object_count; i++) {
switch_id = object_id[i] = resp.resps(i).oid();
object_id[i] = resp.resps(i).oid();
object_statuses[i] = SAI_STATUS_SUCCESS;
}

Expand Down
5 changes: 4 additions & 1 deletion dataplane/standalone/sai/next_hop_group.cc
Original file line number Diff line number Diff line change
Expand Up @@ -419,8 +419,11 @@ sai_status_t l_create_next_hop_group_members(sai_object_id_t switch_id,
LOG(ERROR) << status.error_message();
return SAI_STATUS_FAILURE;
}
if (object_count != resp.resps().size()) {
return SAI_STATUS_FAILURE;
}
for (uint32_t i = 0; i < object_count; i++) {
switch_id = object_id[i] = resp.resps(i).oid();
object_id[i] = resp.resps(i).oid();
object_statuses[i] = SAI_STATUS_SUCCESS;
}

Expand Down
5 changes: 4 additions & 1 deletion dataplane/standalone/sai/port.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1844,8 +1844,11 @@ sai_status_t l_create_ports(sai_object_id_t switch_id, uint32_t object_count,
LOG(ERROR) << status.error_message();
return SAI_STATUS_FAILURE;
}
if (object_count != resp.resps().size()) {
return SAI_STATUS_FAILURE;
}
for (uint32_t i = 0; i < object_count; i++) {
switch_id = object_id[i] = resp.resps(i).oid();
object_id[i] = resp.resps(i).oid();
object_statuses[i] = SAI_STATUS_SUCCESS;
}

Expand Down
3 changes: 3 additions & 0 deletions dataplane/standalone/sai/route.cc
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ sai_status_t l_create_route_entries(uint32_t object_count,
LOG(ERROR) << status.error_message();
return SAI_STATUS_FAILURE;
}
if (object_count != resp.resps().size()) {
return SAI_STATUS_FAILURE;
}
for (uint32_t i = 0; i < object_count; i++) {
object_statuses[i] = SAI_STATUS_SUCCESS;
}
Expand Down
8 changes: 7 additions & 1 deletion dataplane/standalone/sai/srv6.cc
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,11 @@ sai_status_t l_create_srv6_sidlists(sai_object_id_t switch_id,
LOG(ERROR) << status.error_message();
return SAI_STATUS_FAILURE;
}
if (object_count != resp.resps().size()) {
return SAI_STATUS_FAILURE;
}
for (uint32_t i = 0; i < object_count; i++) {
switch_id = object_id[i] = resp.resps(i).oid();
object_id[i] = resp.resps(i).oid();
object_statuses[i] = SAI_STATUS_SUCCESS;
}

Expand Down Expand Up @@ -374,6 +377,9 @@ sai_status_t l_create_my_sid_entries(uint32_t object_count,
LOG(ERROR) << status.error_message();
return SAI_STATUS_FAILURE;
}
if (object_count != resp.resps().size()) {
return SAI_STATUS_FAILURE;
}
for (uint32_t i = 0; i < object_count; i++) {
object_statuses[i] = SAI_STATUS_SUCCESS;
}
Expand Down
5 changes: 4 additions & 1 deletion dataplane/standalone/sai/stp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,11 @@ sai_status_t l_create_stp_ports(sai_object_id_t switch_id,
LOG(ERROR) << status.error_message();
return SAI_STATUS_FAILURE;
}
if (object_count != resp.resps().size()) {
return SAI_STATUS_FAILURE;
}
for (uint32_t i = 0; i < object_count; i++) {
switch_id = object_id[i] = resp.resps(i).oid();
object_id[i] = resp.resps(i).oid();
object_statuses[i] = SAI_STATUS_SUCCESS;
}

Expand Down
5 changes: 4 additions & 1 deletion dataplane/standalone/sai/tunnel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -960,8 +960,11 @@ sai_status_t l_create_tunnels(sai_object_id_t switch_id, uint32_t object_count,
LOG(ERROR) << status.error_message();
return SAI_STATUS_FAILURE;
}
if (object_count != resp.resps().size()) {
return SAI_STATUS_FAILURE;
}
for (uint32_t i = 0; i < object_count; i++) {
switch_id = object_id[i] = resp.resps(i).oid();
object_id[i] = resp.resps(i).oid();
object_statuses[i] = SAI_STATUS_SUCCESS;
}

Expand Down
5 changes: 4 additions & 1 deletion dataplane/standalone/sai/vlan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -509,8 +509,11 @@ sai_status_t l_create_vlan_members(sai_object_id_t switch_id,
LOG(ERROR) << status.error_message();
return SAI_STATUS_FAILURE;
}
if (object_count != resp.resps().size()) {
return SAI_STATUS_FAILURE;
}
for (uint32_t i = 0; i < object_count; i++) {
switch_id = object_id[i] = resp.resps(i).oid();
object_id[i] = resp.resps(i).oid();
object_statuses[i] = SAI_STATUS_SUCCESS;
}

Expand Down

0 comments on commit f6f155e

Please sign in to comment.