Skip to content

Commit

Permalink
feat(servergen): add template for remove (#510)
Browse files Browse the repository at this point in the history
* feat(servergen): add template for remove

* feat(servergen): add template for remove
  • Loading branch information
abhishek-7 authored Dec 19, 2024
1 parent 401ef16 commit 8e038da
Show file tree
Hide file tree
Showing 52 changed files with 2,332 additions and 23 deletions.
21 changes: 20 additions & 1 deletion dataplane/apigen/ccgen/servergen.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class {{ .ServiceName }} final : public lemming::dataplane::sai::{{ .ServiceName
#endif // {{ .IncludeGuard }}
`))
serverCCTmpl = template.Must(template.New("header").Parse(`// Copyright 2024 Google LLC
serverCCTmpl = template.Must(template.New("cc").Parse(`// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -179,6 +179,25 @@ class {{ .ServiceName }} final : public lemming::dataplane::sai::{{ .ServiceName
{{ range .Funcs }}
{{- if and .ProtoRPCName (not .IsStreaming) }}
grpc::Status {{ $.ServiceName }}::{{ .ProtoRPCName }}(grpc::ServerContext* context, const lemming::dataplane::sai::{{ .ProtoRequestType }}* req, lemming::dataplane::sai::{{ .ProtoResponseType }}* resp) {
LOG(INFO) << "Func: " << __PRETTY_FUNCTION__;
{{- if .UseCommonAPI }}
{{ if eq .Operation "remove" }}
{{ if .OidVar -}} auto status = api->{{ .Name }}(req->oid());
{{ else -}}
{{ if .EntryVar }}
auto entry = {{ .EntryConversionToFunc }}(req->entry());
auto status = api->{{.Name}}(&entry);
{{ end }}
{{end}}
{{ if or (ne (len .OidVar) 0) (ne (len .EntryVar) 0)}}
if(status != SAI_STATUS_SUCCESS) {
context->AddTrailingMetadata("status-code", "500");
context->AddTrailingMetadata("message","Internal server error");
return grpc::Status(grpc::StatusCode::INTERNAL, "Internal error occurred");
}
{{ end }}
{{ end }}
{{- end}}
return grpc::Status::OK;
}
Expand Down
46 changes: 24 additions & 22 deletions dataplane/apigen/typeinfo/typeinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,29 @@ type GenType struct {
}

type GenFunc struct {
ProtoRPCName string
ProtoRequestType string
ProtoResponseType string
ReturnType string
Name string
Args string
TypeName string
Operation string
Vars string
UseCommonAPI bool
AttrSwitch *AttrSwitch
Client string
OidVar string
OidPointer string
AttrType string
AttrEnumType string
SwitchScoped bool
EntryConversionFunc string
EntryVar string
ConvertFunc string
AttrConvertInsert string
IsStreaming bool
ProtoRPCName string
ProtoRequestType string
ProtoResponseType string
ReturnType string
Name string
Args string
TypeName string
Operation string
Vars string
UseCommonAPI bool
AttrSwitch *AttrSwitch
Client string
OidVar string
OidPointer string
AttrType string
AttrEnumType string
SwitchScoped bool
EntryConversionFunc string
EntryVar string
EntryConversionToFunc string
ConvertFunc string
AttrConvertInsert string
IsStreaming bool
}

type APITemplate struct {
Expand Down Expand Up @@ -242,6 +243,7 @@ func populateCCInfo(meta *saiast.FuncMetadata, apiName string, sai *saiast.SAIAP
entryType := strings.TrimPrefix(sai.Funcs[fn.Typ].Params[i].Typ, "const ")
if ua, ok := typeToUnionAccessor[entryType]; ok {
genFunc.EntryConversionFunc = ua.convertFromFunc
genFunc.EntryConversionToFunc = ua.convertToFunc
genFunc.EntryVar = sai.Funcs[fn.Typ].Params[i].Name
}
}
Expand Down
88 changes: 88 additions & 0 deletions dataplane/standalone/saiserver/acl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,138 +25,226 @@ grpc::Status Acl::CreateAclTable(
grpc::ServerContext* context,
const lemming::dataplane::sai::CreateAclTableRequest* req,
lemming::dataplane::sai::CreateAclTableResponse* resp) {
LOG(INFO) << "Func: " << __PRETTY_FUNCTION__;

return grpc::Status::OK;
}

grpc::Status Acl::RemoveAclTable(
grpc::ServerContext* context,
const lemming::dataplane::sai::RemoveAclTableRequest* req,
lemming::dataplane::sai::RemoveAclTableResponse* resp) {
LOG(INFO) << "Func: " << __PRETTY_FUNCTION__;

auto status = api->remove_acl_table(req->oid());

if (status != SAI_STATUS_SUCCESS) {
context->AddTrailingMetadata("status-code", "500");
context->AddTrailingMetadata("message", "Internal server error");
return grpc::Status(grpc::StatusCode::INTERNAL, "Internal error occurred");
}

return grpc::Status::OK;
}

grpc::Status Acl::GetAclTableAttribute(
grpc::ServerContext* context,
const lemming::dataplane::sai::GetAclTableAttributeRequest* req,
lemming::dataplane::sai::GetAclTableAttributeResponse* resp) {
LOG(INFO) << "Func: " << __PRETTY_FUNCTION__;

return grpc::Status::OK;
}

grpc::Status Acl::CreateAclEntry(
grpc::ServerContext* context,
const lemming::dataplane::sai::CreateAclEntryRequest* req,
lemming::dataplane::sai::CreateAclEntryResponse* resp) {
LOG(INFO) << "Func: " << __PRETTY_FUNCTION__;

return grpc::Status::OK;
}

grpc::Status Acl::RemoveAclEntry(
grpc::ServerContext* context,
const lemming::dataplane::sai::RemoveAclEntryRequest* req,
lemming::dataplane::sai::RemoveAclEntryResponse* resp) {
LOG(INFO) << "Func: " << __PRETTY_FUNCTION__;

auto status = api->remove_acl_entry(req->oid());

if (status != SAI_STATUS_SUCCESS) {
context->AddTrailingMetadata("status-code", "500");
context->AddTrailingMetadata("message", "Internal server error");
return grpc::Status(grpc::StatusCode::INTERNAL, "Internal error occurred");
}

return grpc::Status::OK;
}

grpc::Status Acl::SetAclEntryAttribute(
grpc::ServerContext* context,
const lemming::dataplane::sai::SetAclEntryAttributeRequest* req,
lemming::dataplane::sai::SetAclEntryAttributeResponse* resp) {
LOG(INFO) << "Func: " << __PRETTY_FUNCTION__;

return grpc::Status::OK;
}

grpc::Status Acl::GetAclEntryAttribute(
grpc::ServerContext* context,
const lemming::dataplane::sai::GetAclEntryAttributeRequest* req,
lemming::dataplane::sai::GetAclEntryAttributeResponse* resp) {
LOG(INFO) << "Func: " << __PRETTY_FUNCTION__;

return grpc::Status::OK;
}

grpc::Status Acl::CreateAclCounter(
grpc::ServerContext* context,
const lemming::dataplane::sai::CreateAclCounterRequest* req,
lemming::dataplane::sai::CreateAclCounterResponse* resp) {
LOG(INFO) << "Func: " << __PRETTY_FUNCTION__;

return grpc::Status::OK;
}

grpc::Status Acl::RemoveAclCounter(
grpc::ServerContext* context,
const lemming::dataplane::sai::RemoveAclCounterRequest* req,
lemming::dataplane::sai::RemoveAclCounterResponse* resp) {
LOG(INFO) << "Func: " << __PRETTY_FUNCTION__;

auto status = api->remove_acl_counter(req->oid());

if (status != SAI_STATUS_SUCCESS) {
context->AddTrailingMetadata("status-code", "500");
context->AddTrailingMetadata("message", "Internal server error");
return grpc::Status(grpc::StatusCode::INTERNAL, "Internal error occurred");
}

return grpc::Status::OK;
}

grpc::Status Acl::SetAclCounterAttribute(
grpc::ServerContext* context,
const lemming::dataplane::sai::SetAclCounterAttributeRequest* req,
lemming::dataplane::sai::SetAclCounterAttributeResponse* resp) {
LOG(INFO) << "Func: " << __PRETTY_FUNCTION__;

return grpc::Status::OK;
}

grpc::Status Acl::GetAclCounterAttribute(
grpc::ServerContext* context,
const lemming::dataplane::sai::GetAclCounterAttributeRequest* req,
lemming::dataplane::sai::GetAclCounterAttributeResponse* resp) {
LOG(INFO) << "Func: " << __PRETTY_FUNCTION__;

return grpc::Status::OK;
}

grpc::Status Acl::CreateAclRange(
grpc::ServerContext* context,
const lemming::dataplane::sai::CreateAclRangeRequest* req,
lemming::dataplane::sai::CreateAclRangeResponse* resp) {
LOG(INFO) << "Func: " << __PRETTY_FUNCTION__;

return grpc::Status::OK;
}

grpc::Status Acl::RemoveAclRange(
grpc::ServerContext* context,
const lemming::dataplane::sai::RemoveAclRangeRequest* req,
lemming::dataplane::sai::RemoveAclRangeResponse* resp) {
LOG(INFO) << "Func: " << __PRETTY_FUNCTION__;

auto status = api->remove_acl_range(req->oid());

if (status != SAI_STATUS_SUCCESS) {
context->AddTrailingMetadata("status-code", "500");
context->AddTrailingMetadata("message", "Internal server error");
return grpc::Status(grpc::StatusCode::INTERNAL, "Internal error occurred");
}

return grpc::Status::OK;
}

grpc::Status Acl::GetAclRangeAttribute(
grpc::ServerContext* context,
const lemming::dataplane::sai::GetAclRangeAttributeRequest* req,
lemming::dataplane::sai::GetAclRangeAttributeResponse* resp) {
LOG(INFO) << "Func: " << __PRETTY_FUNCTION__;

return grpc::Status::OK;
}

grpc::Status Acl::CreateAclTableGroup(
grpc::ServerContext* context,
const lemming::dataplane::sai::CreateAclTableGroupRequest* req,
lemming::dataplane::sai::CreateAclTableGroupResponse* resp) {
LOG(INFO) << "Func: " << __PRETTY_FUNCTION__;

return grpc::Status::OK;
}

grpc::Status Acl::RemoveAclTableGroup(
grpc::ServerContext* context,
const lemming::dataplane::sai::RemoveAclTableGroupRequest* req,
lemming::dataplane::sai::RemoveAclTableGroupResponse* resp) {
LOG(INFO) << "Func: " << __PRETTY_FUNCTION__;

auto status = api->remove_acl_table_group(req->oid());

if (status != SAI_STATUS_SUCCESS) {
context->AddTrailingMetadata("status-code", "500");
context->AddTrailingMetadata("message", "Internal server error");
return grpc::Status(grpc::StatusCode::INTERNAL, "Internal error occurred");
}

return grpc::Status::OK;
}

grpc::Status Acl::GetAclTableGroupAttribute(
grpc::ServerContext* context,
const lemming::dataplane::sai::GetAclTableGroupAttributeRequest* req,
lemming::dataplane::sai::GetAclTableGroupAttributeResponse* resp) {
LOG(INFO) << "Func: " << __PRETTY_FUNCTION__;

return grpc::Status::OK;
}

grpc::Status Acl::CreateAclTableGroupMember(
grpc::ServerContext* context,
const lemming::dataplane::sai::CreateAclTableGroupMemberRequest* req,
lemming::dataplane::sai::CreateAclTableGroupMemberResponse* resp) {
LOG(INFO) << "Func: " << __PRETTY_FUNCTION__;

return grpc::Status::OK;
}

grpc::Status Acl::RemoveAclTableGroupMember(
grpc::ServerContext* context,
const lemming::dataplane::sai::RemoveAclTableGroupMemberRequest* req,
lemming::dataplane::sai::RemoveAclTableGroupMemberResponse* resp) {
LOG(INFO) << "Func: " << __PRETTY_FUNCTION__;

auto status = api->remove_acl_table_group_member(req->oid());

if (status != SAI_STATUS_SUCCESS) {
context->AddTrailingMetadata("status-code", "500");
context->AddTrailingMetadata("message", "Internal server error");
return grpc::Status(grpc::StatusCode::INTERNAL, "Internal error occurred");
}

return grpc::Status::OK;
}

grpc::Status Acl::GetAclTableGroupMemberAttribute(
grpc::ServerContext* context,
const lemming::dataplane::sai::GetAclTableGroupMemberAttributeRequest* req,
lemming::dataplane::sai::GetAclTableGroupMemberAttributeResponse* resp) {
LOG(INFO) << "Func: " << __PRETTY_FUNCTION__;

return grpc::Status::OK;
}
18 changes: 18 additions & 0 deletions dataplane/standalone/saiserver/bfd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,33 +25,51 @@ grpc::Status Bfd::CreateBfdSession(
grpc::ServerContext* context,
const lemming::dataplane::sai::CreateBfdSessionRequest* req,
lemming::dataplane::sai::CreateBfdSessionResponse* resp) {
LOG(INFO) << "Func: " << __PRETTY_FUNCTION__;

return grpc::Status::OK;
}

grpc::Status Bfd::RemoveBfdSession(
grpc::ServerContext* context,
const lemming::dataplane::sai::RemoveBfdSessionRequest* req,
lemming::dataplane::sai::RemoveBfdSessionResponse* resp) {
LOG(INFO) << "Func: " << __PRETTY_FUNCTION__;

auto status = api->remove_bfd_session(req->oid());

if (status != SAI_STATUS_SUCCESS) {
context->AddTrailingMetadata("status-code", "500");
context->AddTrailingMetadata("message", "Internal server error");
return grpc::Status(grpc::StatusCode::INTERNAL, "Internal error occurred");
}

return grpc::Status::OK;
}

grpc::Status Bfd::SetBfdSessionAttribute(
grpc::ServerContext* context,
const lemming::dataplane::sai::SetBfdSessionAttributeRequest* req,
lemming::dataplane::sai::SetBfdSessionAttributeResponse* resp) {
LOG(INFO) << "Func: " << __PRETTY_FUNCTION__;

return grpc::Status::OK;
}

grpc::Status Bfd::GetBfdSessionAttribute(
grpc::ServerContext* context,
const lemming::dataplane::sai::GetBfdSessionAttributeRequest* req,
lemming::dataplane::sai::GetBfdSessionAttributeResponse* resp) {
LOG(INFO) << "Func: " << __PRETTY_FUNCTION__;

return grpc::Status::OK;
}

grpc::Status Bfd::GetBfdSessionStats(
grpc::ServerContext* context,
const lemming::dataplane::sai::GetBfdSessionStatsRequest* req,
lemming::dataplane::sai::GetBfdSessionStatsResponse* resp) {
LOG(INFO) << "Func: " << __PRETTY_FUNCTION__;

return grpc::Status::OK;
}
Loading

0 comments on commit 8e038da

Please sign in to comment.