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

Provide API to reset table entry to its default state #123

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions include/tdi/common/c_frontend/tdi_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,23 @@ tdi_status_t tdi_table_entry_del(const tdi_table_hdl *table_hdl,
const tdi_flags_hdl *flags,
const tdi_table_key_hdl *key);

/**
* @brief Reset an entry of the table
*
* @param[in] table_hdl Table object
* @param[in] session Session Object
* @param[in] dev_tgt Device target
* @param[in] flags Call flags
* @param[in] key Entry Key
*
* @return Status of the API call
*/
tdi_status_t tdi_table_entry_reset(const tdi_table_hdl *table_hdl,
const tdi_session_hdl *session,
const tdi_target_hdl *dev_tgt,
const tdi_flags_hdl *flags,
const tdi_table_key_hdl *key);

/**
* @brief Clear a table. Delete all entries. This API also resets default
* entry if present and is not const default. If table has always present
Expand Down
4 changes: 3 additions & 1 deletion include/tdi/common/tdi_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,10 @@ enum tdi_table_api_type_e {
TDI_TABLE_API_TYPE_KEY_GET = 15,
/** Get entry handle from key. */
TDI_TABLE_API_TYPE_HANDLE_GET = 16,
/** Reset. Reset an entry to its default state*/
TDI_TABLE_API_TYPE_RESET = 17,
/** Invalid not supported API. */
TDI_TABLE_API_TYPE_INVALID_API = 17
TDI_TABLE_API_TYPE_INVALID_API = 18
};
// The same name can be used with or without enum keyword. Advantage of being
// compatible with C++
Expand Down
15 changes: 15 additions & 0 deletions include/tdi/common/tdi_table.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,21 @@ class Table {
const tdi::Flags &flags,
const tdi::TableKey &key) const;

/**
* @brief Delete an entry of the table
*
* @param[in] session Session Object
* @param[in] dev_tgt Device target
* @param[in] flags Call flags
* @param[in] key Entry Key
*
* @return Status of the API call
*/
virtual tdi_status_t entryReset(const tdi::Session &session,
const tdi::Target &dev_tgt,
const tdi::Flags &flags,
const tdi::TableKey &key) const;

/**
* @brief Clear a table. Delete all entries. This API also resets default
* entry if present and is not const default. If table has always present
Expand Down
12 changes: 12 additions & 0 deletions src/c_frontend/tdi_table_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,18 @@ tdi_status_t tdi_table_entry_del(const tdi_table_hdl *table_hdl,
*reinterpret_cast<const tdi::TableKey *>(key));
}

tdi_status_t tdi_table_entry_reset(const tdi_table_hdl *table_hdl,
const tdi_session_hdl *session,
const tdi_target_hdl *target,
const tdi_flags_hdl *flags,
const tdi_table_key_hdl *key) {
auto table = reinterpret_cast<const tdi::Table *>(table_hdl);
return table->entryReset(*reinterpret_cast<const tdi::Session *>(session),
*reinterpret_cast<const tdi::Target *>(target),
*reinterpret_cast<const tdi::Flags *>(flags),
*reinterpret_cast<const tdi::TableKey *>(key));
}

tdi_status_t tdi_table_clear(const tdi_table_hdl *table_hdl,
const tdi_session_hdl *session,
const tdi_target_hdl *target,
Expand Down
11 changes: 11 additions & 0 deletions src/tdi_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ tdi_status_t Table::entryDel(const Session & /*session*/,
return TDI_NOT_SUPPORTED;
}

tdi_status_t Table::entryReset(const Session & /*session*/,
const Target & /*dev_tgt*/,
const Flags & /*flags*/,
const TableKey & /*key*/) const {
LOG_ERROR("%s:%d %s ERROR : Table entry Reset not supported",
__func__,
__LINE__,
tableInfoGet()->nameGet().c_str());
return TDI_NOT_SUPPORTED;
}

tdi_status_t Table::clear(const Session & /*session*/,
const Target & /*dev_tgt*/,
const Flags & /*flags*/) const {
Expand Down
35 changes: 34 additions & 1 deletion tdi_python/tdiTable.py
Original file line number Diff line number Diff line change
Expand Up @@ -1506,7 +1506,40 @@ def del_entry(self, key_content, entry_handle=None):
if sts != 0:
raise TdiTableError("Error: table_entry_delete failed on table {}. [{}]".format(self.name, self._cintf.err_str(sts)), self, sts)

def get_entry(self, key_content, from_hw=False, print_entry=True, key_handle=None, entry_handle=None, dev_tgt=None):
def reset_entry(self, key_content, entry_handle=None):
if entry_handle != None and "get_by_handle" not in self.supported_commands:
raise TdiTableError("{} Error: reseting entry by handle not supported.".format(self.name), self, -1)

key_handle = None
#entry_tgt = byref(self._cintf.BfDevTgt(0, 0, 0, 0))
entry_tgt = self._cintf.get_dev_tgt()
if entry_handle != None:
key_handle = self._cintf.handle_type()
sts = self._cintf.get_driver().tdi_table_key_allocate(self._handle, byref(key_handle))
if sts != 0:
raise TdiTableError("CLI Error: table key allocate failed. [{}].".format(self._cintf.err_str(sts)), self, sts)
sts = self._cintf.tdi_table_entry_key_get(self._handle,
self._cintf.get_session(),
self._cintf.get_dev_tgt(),
entry_handle,
entry_tgt,
key_handle)
if sts != 0:
raise TdiTableError("Error: table_entry_reset failed on table {}. [{}]".format(self.name, self._cintf.err_str(sts)), self, sts)
else:
key_handle = self._make_call_keys(key_content)
if key_handle == -1:
return -1
entry_tgt = self._cintf.get_dev_tgt()
sts = self._cintf.tdi_table_entry_reset(self._handle,
self._cintf.get_session(),
entry_tgt,
key_handle)
self._cintf.get_driver().tdi_table_key_deallocate(key_handle)
if sts != 0:
raise TdiTableError("Error: table_entry_reset failed on table {}. [{}]".format(self.name, self._cintf.err_str(sts)), self, sts)

def get_entry(self, key_content, from_hw=False, print_entry=True, key_handle=None, entry_handle=None):
is_key_set = False if key_handle==None else True
if dev_tgt == None:
dev_tgt = self._cintf.get_dev_tgt()
Expand Down
5 changes: 5 additions & 0 deletions tdi_python/tdicli.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ def tdi_table_entry_del(tbl_hdl, session, dev_tgt, key):
return self._driver.tdi_table_entry_del(tbl_hdl, session, dev_tgt, flags, key)
setattr(self, 'tdi_table_entry_del', tdi_table_entry_del)

def tdi_table_entry_reset(tbl_hdl, session, dev_tgt, key):
flags = self.get_flags()
return self._driver.tdi_table_entry_reset(tbl_hdl, session, dev_tgt, flags, key)
setattr(self, 'tdi_table_entry_reset', tdi_table_entry_reset)

def tdi_table_entry_add(tbl_hdl, session, dev_tgt, flags, key, data):
return self._driver.tdi_table_entry_add(tbl_hdl, session, dev_tgt, flags, key, data)
setattr(self, 'tdi_table_entry_add', tdi_table_entry_add)
Expand Down