From f6734e27dcf879f08a775609bf59f943975a3729 Mon Sep 17 00:00:00 2001 From: Raj Joshi Date: Wed, 9 Jun 2021 02:43:37 +0800 Subject: [PATCH] added aging support for fetch_rtt_mul_ws table --- control_plane/algo/algo.cpp | 2 +- control_plane/bfrt/bfrt.cpp | 49 ++++++++++++++++++++++++++++++++++--- control_plane/bfrt/bfrt.hpp | 19 +++++++++++--- p4src/adjust_rwnd.p4 | 1 + 4 files changed, 64 insertions(+), 7 deletions(-) diff --git a/control_plane/algo/algo.cpp b/control_plane/algo/algo.cpp index 8f22fef..24c8197 100644 --- a/control_plane/algo/algo.cpp +++ b/control_plane/algo/algo.cpp @@ -37,7 +37,7 @@ bf_status_t inNetworkCCAlgo(std::fstream &outfile, bool &algo_running){ while(algo_running){ status = bfrt.get_queuing_info(egressPort, currentAvgQdepth, currentWorkingCopy); - printf("%i\n",currentRwnd); + printf("Current Rwnd: %i\n",currentRwnd); if(currentAvgQdepth > upperQdepthThreshold){ // multiplicative decrement currentRwnd = max_rwnd(minimumRwnd, currentRwnd / rwndDecrement); status = bfrt.set_rwnd(egressPort, currentRwnd); diff --git a/control_plane/bfrt/bfrt.cpp b/control_plane/bfrt/bfrt.cpp index 4c31d27..f85dac5 100644 --- a/control_plane/bfrt/bfrt.cpp +++ b/control_plane/bfrt/bfrt.cpp @@ -139,6 +139,7 @@ void Bfruntime::init(){ void Bfruntime::initBfRtTablesRegisters(){ bf_status_t status; + bfrt::BfRtIdleTmoExpiryCb idle_time_callback = fetch_rtt_mul_and_ws_aging_cb_wrapper; /* // Register working_copy status = bf_rt_info->bfrtTableFromNameGet("SwitchEgressControl.working_copy", &working_copy); @@ -194,8 +195,12 @@ void Bfruntime::initBfRtTablesRegisters(){ fflush(stdout); status = fetch_rtt_mul_and_ws->dataFieldIdGet("ws", set_rtt_mul_and_ws_action_id, &set_rtt_mul_and_ws_action_field_ws_id); CHECK_BF_STATUS(status); + status = fetch_rtt_mul_and_ws->dataFieldIdGet("$ENTRY_TTL", set_rtt_mul_and_ws_action_id, &set_rtt_mul_and_ws_action_field_entry_ttl_id); + CHECK_BF_STATUS(status); printf("WS datafield ID is %u\n", set_rtt_mul_and_ws_action_field_ws_id); fflush(stdout); + + // Allocate and reset key objects status = fetch_rtt_mul_and_ws->keyAllocate(&fetch_rtt_mul_and_ws_key1); CHECK_BF_STATUS(status); @@ -215,6 +220,13 @@ void Bfruntime::initBfRtTablesRegisters(){ status = fetch_rtt_mul_and_ws->dataReset(set_rtt_mul_and_ws_action_id, fetch_rtt_mul_and_ws_data2.get()); CHECK_BF_STATUS(status); + status = fetch_rtt_mul_and_ws->attributeAllocate(bfrt::TableAttributesType::IDLE_TABLE_RUNTIME, bfrt::TableAttributesIdleTableMode::NOTIFY_MODE, &fetch_rtt_mul_and_ws_attributes); + CHECK_BF_STATUS(status); + status = fetch_rtt_mul_and_ws_attributes->idleTableNotifyModeSet(true, idle_time_callback, Bfruntime::fetch_rtt_mul_and_ws_key_ttl_query_interval, Bfruntime::fetch_rtt_mul_and_ws_key_max_ttl, Bfruntime::fetch_rtt_mul_and_ws_key_min_ttl, Bfruntime::fetch_rtt_mul_and_ws_key_cookie); + CHECK_BF_STATUS(status); + status = fetch_rtt_mul_and_ws->tableAttributesSet(*session, dev_tgt, *fetch_rtt_mul_and_ws_attributes); + CHECK_BF_STATUS(status); + // set consistent initial currentWorkingCopy in CP and DP this->currentWorkingCopy = 0; this->set_working_copy(this->currentWorkingCopy); @@ -430,7 +442,7 @@ bf_status_t Bfruntime::get_queuing_info(port_t egressPort, uint64_t &avgQdepth, bf_status_t Bfruntime::add_rtt_ws_entry_pair(const rtt_ws_entry_pair_info_t &info){ bf_status_t status; - + // Prepare key1 status = fetch_rtt_mul_and_ws_key1->setValue(fetch_rtt_mul_and_ws_key_ipv4_src_id, static_cast(info.srcIP)); CHECK_BF_STATUS(status); @@ -447,7 +459,8 @@ bf_status_t Bfruntime::add_rtt_ws_entry_pair(const rtt_ws_entry_pair_info_t &inf CHECK_BF_STATUS(status); status = fetch_rtt_mul_and_ws_data1->setValue(set_rtt_mul_and_ws_action_field_ws_id, static_cast(info.srcWS)); CHECK_BF_STATUS(status); - + status = fetch_rtt_mul_and_ws_data1->setValue(set_rtt_mul_and_ws_action_field_entry_ttl_id, static_cast(Bfruntime::fetch_rtt_mul_and_ws_common_timeout)); + CHECK_BF_STATUS(status); // Prepare key2 status = fetch_rtt_mul_and_ws_key2->setValue(fetch_rtt_mul_and_ws_key_ipv4_src_id, static_cast(info.dstIP)); @@ -464,7 +477,9 @@ bf_status_t Bfruntime::add_rtt_ws_entry_pair(const rtt_ws_entry_pair_info_t &inf CHECK_BF_STATUS(status); status = fetch_rtt_mul_and_ws_data2->setValue(set_rtt_mul_and_ws_action_field_ws_id, static_cast(info.dstWS)); CHECK_BF_STATUS(status); - + status = fetch_rtt_mul_and_ws_data2->setValue(set_rtt_mul_and_ws_action_field_entry_ttl_id, static_cast(Bfruntime::fetch_rtt_mul_and_ws_common_timeout)); + CHECK_BF_STATUS(status); + // status = pcpp_session->beginBatch();CHECK_BF_STATUS(status); status = fetch_rtt_mul_and_ws->tableEntryAdd(*pcpp_session, dev_tgt, *fetch_rtt_mul_and_ws_key1, *fetch_rtt_mul_and_ws_data1); @@ -477,3 +492,31 @@ bf_status_t Bfruntime::add_rtt_ws_entry_pair(const rtt_ws_entry_pair_info_t &inf return status; } + +void Bfruntime::fetch_rtt_mul_and_ws_aging_cb(const bf_rt_target_t &dev_tgt, const bfrt::BfRtTableKey *table_key, void *cookie){ + bf_status_t status; + uint64_t srcIP; + uint64_t dstIP; + uint64_t srcPort; + uint64_t dstPort; + + status = table_key->getValue(fetch_rtt_mul_and_ws_key_ipv4_dst_id, &dstIP); CHECK_BF_STATUS(status); + status = table_key->getValue(fetch_rtt_mul_and_ws_key_ipv4_src_id, &srcIP); CHECK_BF_STATUS(status); + status = table_key->getValue(fetch_rtt_mul_and_ws_key_tcp_dst_port_id, &srcPort); CHECK_BF_STATUS(status); + status = table_key->getValue(fetch_rtt_mul_and_ws_key_tcp_src_port_id, &dstPort); CHECK_BF_STATUS(status); + (void) cookie; + + printf("Aging out entry.\n", srcIP, dstIP, srcPort, dstPort); + + try{ + status = fetch_rtt_mul_and_ws->tableEntryDel(*pcpp_session, dev_tgt, *table_key); CHECK_BF_STATUS(status); + }catch(...){ + printf("WARNING: Could not find the matching entry"); + } + status = this->pcpp_session->sessionCompleteOperations(); CHECK_BF_STATUS(status); +} + +void fetch_rtt_mul_and_ws_aging_cb_wrapper(const bf_rt_target_t &dev_tgt, const bfrt::BfRtTableKey *key, void *cookie){ + Bfruntime &bfrt = Bfruntime::getInstance(); + bfrt.fetch_rtt_mul_and_ws_aging_cb(dev_tgt, key, cookie); +} diff --git a/control_plane/bfrt/bfrt.hpp b/control_plane/bfrt/bfrt.hpp index 5d7fdd2..430a673 100644 --- a/control_plane/bfrt/bfrt.hpp +++ b/control_plane/bfrt/bfrt.hpp @@ -29,6 +29,8 @@ struct rtt_ws_entry_pair_info_t { rtt_t rtt_mul; }; +void fetch_rtt_mul_and_ws_aging_cb_wrapper(const bf_rt_target_t &dev_tgt, const bfrt::BfRtTableKey *key, void *cookie); + class Bfruntime { private: @@ -59,6 +61,8 @@ class Bfruntime { std::unique_ptr fetch_rtt_mul_and_ws_key2; std::unique_ptr fetch_rtt_mul_and_ws_data1; std::unique_ptr fetch_rtt_mul_and_ws_data2; + std::unique_ptr fetch_rtt_mul_and_ws_attributes; + bf_rt_id_t fetch_rtt_mul_and_ws_key_ipv4_src_id = 0; bf_rt_id_t fetch_rtt_mul_and_ws_key_ipv4_dst_id = 0; bf_rt_id_t fetch_rtt_mul_and_ws_key_tcp_src_port_id = 0; @@ -66,10 +70,15 @@ class Bfruntime { bf_rt_id_t set_rtt_mul_and_ws_action_id = 0; bf_rt_id_t set_rtt_mul_and_ws_action_field_rtt_mul_id = 0; bf_rt_id_t set_rtt_mul_and_ws_action_field_ws_id = 0; + bf_rt_id_t set_rtt_mul_and_ws_action_field_entry_ttl_id = 0; + const uint32_t fetch_rtt_mul_and_ws_key_ttl_query_interval = 250; + const uint32_t fetch_rtt_mul_and_ws_key_max_ttl = 5000; + const uint32_t fetch_rtt_mul_and_ws_key_min_ttl = 1000; + const uint32_t fetch_rtt_mul_and_ws_common_timeout = 1000; + const void * fetch_rtt_mul_and_ws_key_cookie; working_copy_t currentWorkingCopy = 0; - /* Private constructor and destructor to avoid them being called by clients. @@ -92,8 +101,10 @@ class Bfruntime { // Swaps the working copy (of qdepth sum/count registers) bf_status_t update_working_copy(working_copy_t ¤tWorkingCopy); - + /******************/ + /* Public Section */ + /******************/ public: /* Provides access to the unique instance of the singleton */ @@ -106,11 +117,13 @@ class Bfruntime { bf_status_t get_queuing_info(port_t egressPort, uint64_t &avgQdepth, working_copy_t ¤tWorkingCopy); bf_status_t add_rtt_ws_entry_pair(const rtt_ws_entry_pair_info_t &rtt_ws_entry_pair_info); + // static void fetch_rtt_mul_and_ws_aging_cb(const bf_rt_target_t &dev_tgt, const bfrt::BfRtTableKey *table_key, void *cookie); + + void fetch_rtt_mul_and_ws_aging_cb(const bf_rt_target_t &dev_tgt, const bfrt::BfRtTableKey *table_key, void *cookie); /* Singleton should not be clonable or assignable */ Bfruntime(Bfruntime &other) = delete; void operator=(const Bfruntime &) = delete; - }; diff --git a/p4src/adjust_rwnd.p4 b/p4src/adjust_rwnd.p4 index cfdcd9f..fd62d0e 100644 --- a/p4src/adjust_rwnd.p4 +++ b/p4src/adjust_rwnd.p4 @@ -46,6 +46,7 @@ control adjustRWND(inout header_t hdr, inout ingress_metadata_t ig_meta){ } default_action = miss_rtt_ws_lookup; size = 65536; + idle_timeout = true; } action set_log_rwnd(bit<16> result) {