Skip to content

Commit

Permalink
Add python CLI byte stream support for table key (ipv6). (#125)
Browse files Browse the repository at this point in the history
* Add python CLI byte stream support for table key (ipv6).

* Changed the logic from byte_stream to check the is_ptr is set or not.
1. Initialized the KeyFieldInfo and check the width is > 64, set the
   is_ptr to True in file src/tdi_json_parser/tdi_info_parser.cpp.
2. Fixed invalid check for is_ptr==True and field size is less than and equal to 8 bytes
   and log error as Please don't use byte arrays in include/tdi/common/tdi_utils.hpp.
3. Reverted back the is_ptr check only.3. Reverted back the is_ptr check
   only.3. Reverted back the is_ptr check only.

* Change back the error message to indicated use byte array.

* Need to change the comment line according the latest error log.
  • Loading branch information
weiqiand authored Mar 2, 2023
1 parent 761c4e6 commit fe1308c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
4 changes: 3 additions & 1 deletion include/tdi/common/tdi_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,9 @@ static inline tdi_status_t keyFieldSafeGet(
);
return TDI_INVALID_ARG;
}
if ((*key_field)->isPtrGet() && field_value->size_ < 64) {
/* If field size less than or equal to 8 and is_ptr is true,
* should use byte arrays */
if ((*key_field)->isPtrGet() && field_value->size_ <= 8) {
LOG_ERROR(
"%s:%d Field size is greater than 64 bits. Please use byte arrays in "
"the KeyFieldValue for field %d",
Expand Down
2 changes: 1 addition & 1 deletion src/tdi_json_parser/tdi_info_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ std::unique_ptr<KeyFieldInfo> TdiInfoParser::parseKeyField(
default_fl_value,
default_str_value,
checkIsFieldSlice(table_key_cjson),
false,
width>64,
false);
if (tmp == nullptr) {
LOG_ERROR("%s:%d Error forming key_field %d",
Expand Down
5 changes: 5 additions & 0 deletions tdi_python/tdiTable.py
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,7 @@ def _init_key(self):
return sts
for field_id in field_ids:
field_name = c_char_p()
logging.debug("field_id={} field_name={}".format(field_id, field_name))
sts = self._cintf.get_driver().tdi_key_field_name_get(self._info_handle, field_id, byref(field_name))
if not sts == 0:
print("CLI Error: get key field name for {} failed. [{}]".format(self.name, self._cintf.err_str(sts)))
Expand Down Expand Up @@ -931,6 +932,9 @@ def _set_key_fields(self, content, key_handle):
sts = -1
if name not in content.keys():
continue
logging.debug("info:info.type {}, info.data_type {} \n"
"info.is_ptr {}".format(self.key_match_type_cls.key_match_type_str(info.type),
self.data_type_cls.data_type_str(info.data_type), info.is_ptr))
if self.key_match_type_cls.key_match_type_str(info.type) == "EXACT":
if self.data_type_cls.data_type_str(info.data_type) == "STRING":
value = c_char_p(content[name].encode('ascii'))
Expand All @@ -940,6 +944,7 @@ def _set_key_fields(self, content, key_handle):
sts = self._cintf.get_driver().tdi_key_field_set_value(key_handle, info.id, value)
else:
value, bytes_ = self.fill_c_byte_arr(content[name], info.size)
logging.debug("value={} bytes_ {}".format(bytes(value).hex(),bytes_))
sts = self._cintf.get_driver().tdi_key_field_set_value_ptr(key_handle, info.id, value, bytes_)
elif self.key_match_type_cls.key_match_type_str(info.type) == "TERNARY":
if not info.is_ptr:
Expand Down

0 comments on commit fe1308c

Please sign in to comment.