Skip to content

Commit

Permalink
[ovsp4rt] Implement journaling api and client
Browse files Browse the repository at this point in the history
- Created JournalClient, a subclass of Client that is
  instrumented to record interactions between OVS and
  the P4Runtime server.

- Created a variant of the public API that uses
  JournalClient objects.

Signed-off-by: Derek Foster <justffoulkes@gmail.com>
  • Loading branch information
ffoulkes committed Dec 24, 2024
1 parent 8020335 commit 5c66dab
Show file tree
Hide file tree
Showing 6 changed files with 234 additions and 4 deletions.
16 changes: 14 additions & 2 deletions ovs-p4rt/sidecar/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,23 @@ endif()
add_library(ovs_sidecar_o OBJECT
${OVSP4RT_INCLUDE_DIR}/ovsp4rt/ovs-p4rt.h
ovsp4rt.cc
ovsp4rt_c_api.cc
ovsp4rt_cc_api.h
ovsp4rt_private.h
)

if(BUILD_CLIENT)
if(BUILD_JOURNAL)
target_sources(ovs_sidecar_o PRIVATE
ovsp4rt_cc_api.h
ovsp4rt_journal_api.cc
)
else()
target_sources(ovs_sidecar_o PRIVATE
ovsp4rt_c_api.cc
ovsp4rt_cc_api.h
)
endif()
endif()

if(DPDK_TARGET)
add_subdirectory(dpdk)
elseif(ES2K_TARGET)
Expand Down
8 changes: 8 additions & 0 deletions ovs-p4rt/sidecar/client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@ add_library(ovsp4rt_client_o OBJECT
ovsp4rt_client_interface.h
)

if(BUILD_JOURNAL)
target_sources(ovsp4rt_client_o PRIVATE
ovsp4rt_journal_client.cc
ovsp4rt_journal_client.h
)
endif()

target_include_directories(ovsp4rt_client_o PUBLIC
${OVSP4RT_INCLUDE_DIR}
${SIDECAR_SOURCE_DIR}
${STRATUM_SOURCE_DIR}
)
Expand Down
2 changes: 0 additions & 2 deletions ovs-p4rt/sidecar/client/ovsp4rt_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

#include <stdint.h>

#include <string>

#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "ovsp4rt_client_interface.h"
Expand Down
30 changes: 30 additions & 0 deletions ovs-p4rt/sidecar/client/ovsp4rt_journal_client.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2024 Intel Corporation
// SPDX-License-Identifier: Apache-2.0

#include "ovsp4rt_journal_client.h"

namespace ovsp4rt {

absl::StatusOr<::p4::v1::ReadResponse> JournalClient::sendReadRequest(
const p4::v1::ReadRequest& request) {
#if 0
_journal.recordReadRequest(request);
auto response = Client::sendReadRequest(request);
_journal.recordReadResponse(response);
#else
return Client::sendReadRequest(request);
#endif
}

absl::Status JournalClient::sendWriteRequest(
const p4::v1::WriteRequest& request) {
#if 0
_journal.recordWriteRequest(request);
auto response = Client::sendWriteRequest(request);
_journal.recordWriteResponse(response);
#else
return Client::sendWriteRequest(request);
#endif
}

} // namespace ovsp4rt
37 changes: 37 additions & 0 deletions ovs-p4rt/sidecar/client/ovsp4rt_journal_client.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2024 Intel Corporation
// SPDX-License-Identifier: Apache-2.0

#ifndef OVSP4RT_JOURNAL_CLIENT_H_
#define OVSP4RT_JOURNAL_CLIENT_H_

#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "client/ovsp4rt_client.h"
#include "journal/ovsp4rt_journal.h"
#include "p4/v1/p4runtime.pb.h"

namespace ovsp4rt {

class JournalClient : public Client {
public:
JournalClient() {}
virtual ~JournalClient() = default;

// Sends a Read Table Entry request to the P4Runtime server.
absl::StatusOr<p4::v1::ReadResponse> sendReadRequest(
const p4::v1::ReadRequest& request) override;

// Sends a Write Table Entry request to the P4Runtime server.
absl::Status sendWriteRequest(const p4::v1::WriteRequest& request) override;

// Returns a reference to the Journal object.
Journal& journal() { return journal_; }

private:
// Journal object.
Journal journal_;
};

} // namespace ovsp4rt

#endif // OVSP4RT_JOURNAL_CLIENT_H_
145 changes: 145 additions & 0 deletions ovs-p4rt/sidecar/ovsp4rt_journal_api.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
// Copyright 2022-2024 Intel Corporation
// SPDX-License-Identifier: Apache-2.0

// Implements the C API using the JournalClient class.

#include "client/ovsp4rt_journal_client.h"
#include "ovsp4rt/ovs-p4rt.h"
#include "ovsp4rt_cc_api.h"

//----------------------------------------------------------------------
// ovsp4rt_config_fdb_entry (DPDK, ES2K)
//----------------------------------------------------------------------
void ovsp4rt_config_fdb_entry(struct mac_learning_info learn_info,
bool insert_entry, const char* grpc_addr) {
using namespace ovsp4rt;

JournalClient client;
client.journal().recordInput(__func__, learn_info, insert_entry);

ConfigFdbEntry(client, learn_info, insert_entry, grpc_addr);
}

//----------------------------------------------------------------------
// ovsp4rt_config_tunnel_entry (DPDK, ES2K)
//----------------------------------------------------------------------
void ovsp4rt_config_tunnel_entry(struct tunnel_info tunnel_info,
bool insert_entry, const char* grpc_addr) {
using namespace ovsp4rt;

JournalClient client;
client.journal().recordInput(__func__, tunnel_info, insert_entry);

ConfigTunnelEntry(client, tunnel_info, insert_entry, grpc_addr);
}

//----------------------------------------------------------------------
// ovsp4rt_str_to_tunnel_type (DPDK, ES2K)
//
// It is unclear whether this function belongs here or in a separate
// file.
//----------------------------------------------------------------------
enum ovs_tunnel_type ovsp4rt_str_to_tunnel_type(const char* tnl_type) {
if (tnl_type) {
if (strcmp(tnl_type, "vxlan") == 0) {
return OVS_TUNNEL_VXLAN;
} else if (strcmp(tnl_type, "geneve") == 0) {
return OVS_TUNNEL_GENEVE;
}
}
return OVS_TUNNEL_UNKNOWN;
}

#if defined(DPDK_TARGET)

//----------------------------------------------------------------------
// Unimplemented functions (DPDK)
//----------------------------------------------------------------------
void ovsp4rt_config_rx_tunnel_src_entry(struct tunnel_info tunnel_info,
bool insert_entry,
const char* grpc_addr) {}

void ovsp4rt_config_vlan_entry(uint16_t vlan_id, bool insert_entry,
const char* grpc_addr) {}

void ovsp4rt_config_tunnel_src_port_entry(struct src_port_info tnl_sp,
bool insert_entry,
const char* grpc_addr) {}

void ovsp4rt_config_src_port_entry(struct src_port_info vsi_sp,
bool insert_entry, const char* grpc_addr) {}

void ovsp4rt_config_ip_mac_map_entry(struct ip_mac_map_info ip_info,
bool insert_entry, const char* grpc_addr) {
}

#elif defined(ES2K_TARGET)

//----------------------------------------------------------------------
// ovsp4rt_config_ip_mac_map_entry (ES2K)
//----------------------------------------------------------------------
void ovsp4rt_config_ip_mac_map_entry(struct ip_mac_map_info ip_info,
bool insert_entry, const char* grpc_addr) {
using namespace ovsp4rt;

JournalClient client;
client.journal().recordInput(_func__, ip_info, insert_entry);

ConfigIpMacMapEntry(client, ip_info, insert_entry, grpc_addr);
}

//----------------------------------------------------------------------
// ovsp4rt_config_rx_tunnel_src_entry (ES2K)
//----------------------------------------------------------------------
void ovsp4rt_config_rx_tunnel_src_entry(struct tunnel_info tunnel_info,
bool insert_entry,
const char* grpc_addr) {
using namespace ovsp4rt;

JournalClient client;
client.journal().recordInput(__func__, tunnel_info, insert_entry);

ConfigRxTunnelSrcEntry(client, tunnel_info, insert_entry, grpc_addr);
}

//----------------------------------------------------------------------
// ovsp4rt_config_src_port_entry (ES2K)
//----------------------------------------------------------------------
void ovsp4rt_config_src_port_entry(struct src_port_info vsi_sp,
bool insert_entry, const char* grpc_addr) {
using namespace ovsp4rt;

JournalClient client;
client.journal().recordInput(__func__, vsi_sp, insert_entry);

ConfigSrcPortEntry(client, vsi_sp, insert_entry, grpc_addr);
}

//----------------------------------------------------------------------
// ovsp4rt_config_tunnel_src_port_entry (ES2K)
//----------------------------------------------------------------------
void ovsp4rt_config_tunnel_src_port_entry(struct src_port_info tnl_sp,
bool insert_entry,
const char* grpc_addr) {
using namespace ovsp4rt;

JournalClient client;
client.journal().recordInput(__func__, tnl_sp, insert_entry);

ConfigTunnelSrcPortEntry(client, tnl_sp, insert_entry, grpc_addr);
}

//----------------------------------------------------------------------
// ovsp4rt_config_vlan_entry (ES2K)
//----------------------------------------------------------------------
void ovsp4rt_config_vlan_entry(uint16_t vlan_id, bool insert_entry,
const char* grpc_addr) {
using namespace ovsp4rt;

JournalClient client;
client.journal().recordInput(__func__, tnl_sp, insert_entry);

ConfigVlanEntry(client, vlan_id, insert_entry, grpc_addr);
}

#endif // ES2K_TARGET

0 comments on commit 5c66dab

Please sign in to comment.