Skip to content

Commit

Permalink
Fix sonic-net#158 - libsai delete operation failure and log msg. THe …
Browse files Browse the repository at this point in the history
…test for error code was backwards and log message used same write updateType string for all operations. I fixed the compare and used a dynamic enum print method.
  • Loading branch information
chrispsommers committed Jul 21, 2022
1 parent ec3b721 commit af248c3
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 6 deletions.
2 changes: 1 addition & 1 deletion dash-pipeline/SAI/templates/saiapi.cpp.j2
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ sai_status_t sai_remove_{{ table.name }}(
{% endfor %}

retCode = MutateTableEntry(matchActionEntry, p4::v1::Update_Type_DELETE);
if (grpc::StatusCode::OK != retCode) {
if (grpc::StatusCode::OK == retCode) {
delete matchActionEntry;
return 0;
}
Expand Down
11 changes: 9 additions & 2 deletions dash-pipeline/SAI/templates/utils.cpp.j2
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <atomic>
#include <limits>
#include <stdint.h>
#include <string.h>
#include <PI/pi.h>
#include <grpcpp/grpcpp.h>
#include "p4/v1/p4runtime.grpc.pb.h"
Expand Down Expand Up @@ -129,7 +130,13 @@ int GetDeviceId() {
return deviceId;
}

string updateTypeStr(p4::v1::Update_Type updateType) {
const google::protobuf::EnumDescriptor *descriptor = p4::v1::Update_Type_descriptor();
return descriptor->FindValueByNumber(updateType)->name();
}

grpc::StatusCode MutateTableEntry(p4::v1::TableEntry *entry, p4::v1::Update_Type updateType) {

p4::v1::WriteRequest request;
request.set_device_id(GetDeviceId());
auto update = request.add_updates();
Expand All @@ -141,11 +148,11 @@ grpc::StatusCode MutateTableEntry(p4::v1::TableEntry *entry, p4::v1::Update_Type
grpc::ClientContext context;
grpc::Status status = stub->Write(&context, request, &rep);
if (status.ok()) {
LOG("GRPC call Write::add_one_entry OK: ");
LOG("GRPC call Write::" << updateTypeStr(updateType) << " OK" << std::endl);
}
else {
LOG("GRPC ERROR["<< status.error_code() <<"]: " << status.error_message() << ", " << status.error_details());
LOG("GRPC call Write::add_one_entry ERROR: " << std::endl << entry->ShortDebugString());
LOG("GRPC call Write::" << updateTypeStr(updateType) << " ERROR: " << std::endl << entry->ShortDebugString());
}
//MILIND?? What is this? reference release? memory release?
entity->release_table_entry();
Expand Down
2 changes: 1 addition & 1 deletion dash-pipeline/tests/init_switch/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
all:init_switch
init_switch: init_switch.cpp
init_switch: init_switch.cpp /SAI/lib/libsai.so
echo "building $@ ..."
g++ \
-I /SAI/lib \
Expand Down
2 changes: 1 addition & 1 deletion dash-pipeline/tests/vnet_out/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
all:vnet_out
vnet_out: vnet_out.cpp
vnet_out: vnet_out.cpp /SAI/lib/libsai.so
echo "building $@ ..."
g++ \
-I /SAI/SAI/inc \
Expand Down
29 changes: 28 additions & 1 deletion dash-pipeline/tests/vnet_out/vnet_out.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,22 @@ extern sai_status_t sai_create_direction_lookup_entry(
_In_ const sai_direction_lookup_entry_t *direction_lookup_entry,
_In_ uint32_t attr_count,
_In_ const sai_attribute_t *attr_list);
extern sai_status_t sai_remove_direction_lookup_entry(
_In_ const sai_direction_lookup_entry_t *direction_lookup_entry);

extern sai_status_t sai_create_eni_ether_address_map_entry(
_In_ const sai_eni_ether_address_map_entry_t *outbound_eni_lookup_from_vm_entry,
_In_ uint32_t attr_count,
_In_ const sai_attribute_t *attr_list);
extern sai_status_t sai_remove_eni_ether_address_map_entry(
_In_ const sai_eni_ether_address_map_entry_t *outbound_eni_lookup_from_vm_entry);

extern sai_status_t sai_create_outbound_eni_to_vni_entry(
_In_ const sai_outbound_eni_to_vni_entry_t *outbound_eni_to_vni_entry,
_In_ uint32_t attr_count,
_In_ const sai_attribute_t *attr_list);
extern sai_status_t sai_remove_outbound_eni_to_vni_entry(
_In_ const sai_outbound_eni_to_vni_entry_t *outbound_eni_to_vni_entry);

extern sai_dash_api_t sai_dash_api_impl;

Expand Down Expand Up @@ -83,9 +89,30 @@ int main(int argc, char **argv)
std::cout << "Failed to create ENI To VNI" << std::endl;
return 1;
}

attrs.clear();

// Delete everything in reverse order
status = sai_remove_outbound_eni_to_vni_entry(&e2v);
if (status != SAI_STATUS_SUCCESS)
{
std::cout << "Failed to remove ENI To VNI" << std::endl;
return 1;
}

status = sai_remove_eni_ether_address_map_entry(&eam);
if (status != SAI_STATUS_SUCCESS)
{
std::cout << "Failed to remove ENI Lookup From VM" << std::endl;
return 1;
}

status = sai_remove_direction_lookup_entry(&dle);
if (status != SAI_STATUS_SUCCESS)
{
std::cout << "Failed to remove Direction Lookup Entry" << std::endl;
return 1;
}


std::cout << "Done." << std::endl;

Expand Down

0 comments on commit af248c3

Please sign in to comment.