Skip to content

Commit

Permalink
pktio TDI p4lang side changes (#122)
Browse files Browse the repository at this point in the history
* pktio p4lang changes

* pktio p4lang changes

* pktio tdi p4lang side changes

* pktio TDI p4lang side changes

* pktio TDI p4lang side changes

* pktio TDI p4lang side changes
  • Loading branch information
abhaysi2 authored Feb 28, 2023
1 parent 9096ab3 commit 761c4e6
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 1 deletion.
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,
/** Get entry handle from key. */
TDI_TABLE_API_TYPE_NOTIFICATION = 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
88 changes: 88 additions & 0 deletions include/tdi/common/tdi_notifications.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Copyright(c) 2023 Intel Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this software except as stipulated in the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/** @file tdi_table_notifications.hpp
*
* @brief Contains TDI Table Notifications APIs
*/
#ifndef _TDI_TABLE_NOTIFICATIONS_HPP
#define _TDI_TABLE_NOTIFICATIONS_HPP

#include <cstring>
#include <functional>
#include <map>
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>

#include <tdi/common/tdi_defs.h>
#include <tdi/common/tdi_table_key.hpp>
#include <tdi/common/tdi_session.hpp>
#include <tdi/common/tdi_table_data.hpp>

namespace tdi {

class Table;

/**
* @brief Contains Parmaters info of Notification
* get and set the value with a field_id
*/
class NotificationOutParams {
public:
virtual ~NotificationOutParams() = default;
NotificationOutParams(const Table* table, const tdi_id_t &tdi_id_type)
: table_(table), notification_id_(tdi_id_type){};

virtual tdi_status_t setValue(const tdi_id_t & /*field_id*/,
const uint64_t & /*value*/) const {
return TDI_NOT_SUPPORTED;
};
virtual tdi_status_t getValue(const tdi_id_t & /*field_id*/,
uint64_t * /*value*/) const {
return TDI_NOT_SUPPORTED;
};

virtual tdi_status_t setValue(const tdi_id_t & /*field_id*/,
const std::vector<uint8_t> & /*value*/) const {
return TDI_NOT_SUPPORTED;
};
virtual tdi_status_t getValue(const tdi_id_t & /*field_id*/,
std::vector<uint8_t> * /*value*/) const {
return TDI_NOT_SUPPORTED;
};

virtual tdi_status_t getValue(const tdi_id_t & /*field_id*/,
uint8_t*const* /*value*/,
size_t * /*size*/) const {
return TDI_NOT_SUPPORTED;
};

private:
const Table* table_;
tdi_id_t notification_id_;
};

/**
* @brief Contains TDI Notification callback function
*/
typedef std::function<void(std::unique_ptr<tdi::TableKey> key,
std::unique_ptr<tdi::TableData> data,
std::unique_ptr<tdi::NotificationOutParams> params,
void *cookie)> tdiNotificationCallback;
} // tdi

#endif // _TDI_TABLE_NOTIFICATIONS_HPP
9 changes: 9 additions & 0 deletions include/tdi/common/tdi_table.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <tdi/common/tdi_defs.h>
#include <tdi/common/tdi_attributes.hpp>
#include <tdi/common/tdi_json_parser/tdi_table_info.hpp>
#include <tdi/common/tdi_notifications.hpp>
#include <tdi/common/tdi_operations.hpp>
#include <tdi/common/tdi_session.hpp>
#include <tdi/common/tdi_table_data.hpp>
Expand Down Expand Up @@ -652,6 +653,14 @@ class Table {

const TdiInfo *tdiInfoGet() const { return tdi_info_; };

virtual tdi_status_t notificationRegister(tdi::Target &target,
const tdi_id_t &notification_id,
tdiNotificationCallback &callback,
void *cookie);

virtual tdi_status_t notificationDeregister(tdi::Target &target,
const tdi_id_t &notification_id) const;

protected:
// Targets can choose to use any ctor to create tables. The 2nd one
// assists with setting table APIs during runtime rather than
Expand Down
15 changes: 15 additions & 0 deletions src/tdi_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/
#include <algorithm>
#include <tdi/common/tdi_notifications.hpp>
#include <tdi/common/tdi_table.hpp>

// local includes
Expand Down Expand Up @@ -348,6 +349,20 @@ tdi_status_t Table::tableAttributesGet(
return TDI_NOT_SUPPORTED;
}

tdi_status_t Table::notificationRegister(tdi::Target &,//target,
const tdi_id_t &,//notification_id,
tdiNotificationCallback &,//callback,
void * /*cookie*/) {
LOG_ERROR("%s:%d Not supported", __func__, __LINE__);
return TDI_NOT_SUPPORTED;
}

tdi_status_t Table::notificationDeregister(tdi::Target &,//target,
const tdi_id_t & /*notification_id*/) const{
LOG_ERROR("%s:%d Not supported", __func__, __LINE__);
return TDI_NOT_SUPPORTED;
}

tdi_status_t Table::operationsAllocate(
const tdi_operations_type_e &op_type,
std::unique_ptr<TableOperations> *table_ops) const {
Expand Down

0 comments on commit 761c4e6

Please sign in to comment.