Skip to content

Commit

Permalink
Add support for bonding device, clean-up middleware device ownership (#…
Browse files Browse the repository at this point in the history
…75)

* Add basic scaffolding for bond device

* Remove local IP/route/netmask from Device

* Implement bond device behavior

* Don't register bound devices with ENA raw processor

* Fix SSL client/server constructor arguments

* Add bond::Device::allocate()

* Specify a logger when allocating the next ENA device

* Middleware devices enforce ownership of their inner devices

* Clean-up OFED intialization in uspace Poller

* Fix TX/RX descriptor count adjustment

* Fix poll result calculation in bonding device
  • Loading branch information
xguerin authored Oct 17, 2023
1 parent eae7527 commit 1661fed
Show file tree
Hide file tree
Showing 56 changed files with 1,833 additions and 1,465 deletions.
11 changes: 5 additions & 6 deletions apps/lat_ofed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,20 @@ try {
/*
* Create an OFED device.
*/
ofed::Device* device = nullptr;
Device::Ref device;
if (opts.hasInterface()) {
device = new ofed::Device(logger, opts.interface(), 1024);
device = ofed::Device::allocate(logger, opts.interface(), 1024);
} else {
device = new ofed::Device(logger, 1024);
device = ofed::Device::allocate(logger, 1024);
}
/*
* Call the main function.
*/
int res = opts.isSender() ? Client::run(opts, *device)
: Server::run(opts, *device);
int res = opts.isSender() ? Client::run(opts, std::move(device))
: Server::run(opts, std::move(device));
/*
* Clean-up.
*/
delete device;
return res;
} catch (std::exception const& e) {
std::cerr << e.what() << std::endl;
Expand Down
14 changes: 7 additions & 7 deletions apps/lat_pipe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <tclap/CmdLine.h>

using namespace tulips;
using namespace transport;
using namespace apps::tcplatency;

int
Expand All @@ -26,25 +27,24 @@ try {
/*
* Create the tunnel device.
*/
transport::npipe::Device* device;
Device::Ref device;
if (opts.isSender()) {
device = new transport::npipe::ClientDevice(
device = transport::npipe::ClientDevice::allocate(
logger, opts.linkAddress(), opts.source(), opts.mask(), opts.route(),
"server.fifo", "client.fifo");
} else {
device = new transport::npipe::ServerDevice(
device = transport::npipe::ServerDevice::allocate(
logger, opts.linkAddress(), opts.source(), opts.mask(), opts.route(),
"client.fifo", "server.fifo");
}
/*
* Call the main function.
*/
int res = opts.isSender() ? Client::run(opts, *device)
: Server::run(opts, *device);
int res = opts.isSender() ? Client::run(opts, std::move(device))
: Server::run(opts, std::move(device));
/*
* Clean-up and return.
* Done.
*/
delete device;
return res;
} catch (std::exception const& e) {
std::cerr << e.what() << std::endl;
Expand Down
27 changes: 12 additions & 15 deletions apps/raw_ofed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,23 +115,23 @@ main_raw(const bool sender, const size_t ival, const bool pcap, const bool wait,
/*
* Create the console logger.
*/
auto logger = system::ConsoleLogger(system::Logger::Level::Trace);
auto log = system::ConsoleLogger(system::Logger::Level::Trace);
/*
* Create an OFED device
*/
ofed::Device ofed_device(logger, ifn, 32);
transport::pcap::Device* pcap_device = nullptr;
Device* device = &ofed_device;
Device::Ref dev;
auto ofed = ofed::Device::allocate(log, ifn, 32);
/*
* Open the pcap device
*/
if (pcap) {
if (sender) {
pcap_device = new transport::pcap::Device(logger, ofed_device, "client");
dev = transport::pcap::Device::allocate(log, std::move(ofed), "client");
} else {
pcap_device = new transport::pcap::Device(logger, ofed_device, "server");
dev = transport::pcap::Device::allocate(log, std::move(ofed), "server");
}
device = pcap_device;
} else {
dev = std::move(ofed);
}
/*
* Process the CPU ID.
Expand All @@ -143,8 +143,8 @@ main_raw(const bool sender, const size_t ival, const bool pcap, const bool wait,
* Processor
*/
RawProcessor proc;
ethernet::Producer eth_prod(logger, *device, device->address());
ethernet::Processor eth_proc(logger, device->address());
ethernet::Producer eth_prod(log, *dev, dev->address());
ethernet::Processor eth_proc(log, dev->address());
eth_prod.setType(sizeof(counter)).setDestinationAddress(dst);
eth_proc.setRawProcessor(proc);
proc.setEthernetProducer(eth_prod).setEthernetProcessor(eth_proc);
Expand All @@ -169,7 +169,7 @@ main_raw(const bool sender, const size_t ival, const bool pcap, const bool wait,
show_latency = false;
std::cout << "Latency = " << proc.averageLatency() << "ns" << std::endl;
}
wait ? device->wait(eth_proc, 1000000) : device->poll(eth_proc);
wait ? dev->wait(eth_proc, 1000000) : dev->poll(eth_proc);
if (usdly != 0) {
usleep(usdly);
}
Expand All @@ -192,18 +192,15 @@ main_raw(const bool sender, const size_t ival, const bool pcap, const bool wait,
show_latency = false;
std::cout << "Latency = " << proc.averageLatency() << "ns" << std::endl;
}
wait ? device->wait(eth_proc, 1000000) : device->poll(eth_proc);
wait ? dev->wait(eth_proc, 1000000) : dev->poll(eth_proc);
if (usdly > 0) {
usleep(usdly);
}
}
}
/*
* Delete the PCAP device.
* Done.
*/
if (pcap) {
delete pcap_device;
}
return 0;
}

Expand Down
16 changes: 15 additions & 1 deletion include/tulips/api/Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,26 @@ class Client final
using api::interface::Client::ApplicationLayerProtocol;
using interface::Client::Timestamp;

/*
* Allocator.
*/

static Ref allocate(system::Logger& log, Delegate& dlg,
transport::Device& device, const size_t nconn,
stack::ipv4::Address const& ip,
stack::ipv4::Address const& gw,
stack::ipv4::Address const& nm)
{
return std::make_unique<Client>(log, dlg, device, nconn, ip, gw, nm);
}

/*
* Constructor and destructor.
*/

Client(system::Logger& log, Delegate& dlg, transport::Device& device,
const size_t nconn);
const size_t nconn, stack::ipv4::Address const& ip,
stack::ipv4::Address const& gw, stack::ipv4::Address const& nm);
~Client() override = default;

/*
Expand Down
37 changes: 35 additions & 2 deletions include/tulips/api/Interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,35 @@ struct Delegate
class Client : public transport::Processor
{
public:
/**
* Default ID.
*/
static constexpr stack::tcpv4::Connection::ID DEFAULT_ID = -1;

/**
* Application layer protocol.
*/
enum class ApplicationLayerProtocol : uint8_t
{
None = 0,
HTTP_1_1 = 1,
HTTP_2 = 2,
};

/**
* Client ID alias.
*/
using ID = stack::tcpv4::Connection::ID;

/**
* Client delegate alias.
*/
using Delegate = interface::Delegate<ID>;

static constexpr ID DEFAULT_ID = -1;
/**
* Client reference alias.
*/
using Ref = std::unique_ptr<Client>;

/**
* @return whether or not the client has live connections.
Expand Down Expand Up @@ -267,10 +285,25 @@ class Client : public transport::Processor
class Server : public transport::Processor
{
public:
/**
* Default ID.
*/
static constexpr stack::tcpv4::Connection::ID DEFAULT_ID = -1;

/**
* Server ID alias.
*/
using ID = stack::tcpv4::Connection::ID;

/**
* Server delegate alias.
*/
using Delegate = interface::Delegate<ID>;

static constexpr ID DEFAULT_ID = -1;
/**
* Server reference alias.
*/
using Ref = std::unique_ptr<Server>;

/**
* Instruct the server to listen to a particular TCP port.
Expand Down
16 changes: 15 additions & 1 deletion include/tulips/api/Server.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,25 @@ class Server
*/
using interface::Server::Timestamp;

/*
* Allocator.
*/

static Ref allocate(system::Logger& log, Delegate& dlg,
transport::Device& device, const size_t nconn,
stack::ipv4::Address const& ip,
stack::ipv4::Address const& gw,
stack::ipv4::Address const& nm)
{
return std::make_unique<Server>(log, dlg, device, nconn, ip, gw, nm);
}

/**
* Constructor and destructor.
*/
Server(system::Logger& log, Delegate& delegate, transport::Device& device,
const size_t nconn);
const size_t nconn, stack::ipv4::Address const& ip,
stack::ipv4::Address const& gw, stack::ipv4::Address const& nm);

/**
* Device interface.
Expand Down
4 changes: 2 additions & 2 deletions include/tulips/apps/TCPLatency.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ namespace tulips::apps::tcplatency {

namespace Client {

int run(Options const& options, transport::Device& base_device);
int run(Options const& options, transport::Device::Ref dev);

}

namespace Server {

int run(Options const& options, transport::Device& base_device);
int run(Options const& options, transport::Device::Ref dev);

}

Expand Down
40 changes: 37 additions & 3 deletions include/tulips/ssl/Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,50 @@ class Client final
using api::interface::Client::ApplicationLayerProtocol;
using api::interface::Client::Timestamp;

/*
* Allocators.
*/

static Ref allocate(system::Logger& log,
api::interface::Client::Delegate& delegate,
transport::Device& device, const size_t nconn,
stack::ipv4::Address const& ip,
stack::ipv4::Address const& gw,
stack::ipv4::Address const& nm, const Protocol type,
const bool save_keys)
{
return std::make_unique<Client>(log, delegate, device, nconn, ip, gw, nm,
type, save_keys);
}

static Ref allocate(system::Logger& log,
api::interface::Client::Delegate& delegate,
transport::Device& device, const size_t nconn,
stack::ipv4::Address const& ip,
stack::ipv4::Address const& gw,
stack::ipv4::Address const& nm, const Protocol type,
std::string_view cert, std::string_view key)
{
return std::make_unique<Client>(log, delegate, device, nconn, ip, gw, nm,
type, cert, key);
}

/*
* Constructors and destructor.
*/

Client(system::Logger& log, api::interface::Client::Delegate& delegate,
transport::Device& device, const Protocol type, const size_t nconn,
transport::Device& device, const size_t nconn,
stack::ipv4::Address const& ip, stack::ipv4::Address const& gw,
stack::ipv4::Address const& nm, const Protocol type,
const bool save_keys);

Client(system::Logger& log, api::interface::Client::Delegate& delegate,
transport::Device& device, const Protocol type, std::string_view cert,
std::string_view key, const size_t nconn);
transport::Device& device, const size_t nconn,
stack::ipv4::Address const& ip, stack::ipv4::Address const& gw,
stack::ipv4::Address const& nm, const Protocol type,
std::string_view cert, std::string_view key);

~Client() override;

/*
Expand Down
35 changes: 28 additions & 7 deletions include/tulips/ssl/Server.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,41 @@ class Server
, public api::interface::Server::Delegate
{
public:
/**
/*
* Type alias import.
*/

using api::interface::Server::Timestamp;

/**
/*
* Allocator.
*/

static Ref allocate(system::Logger& log,
api::interface::Server::Delegate& delegate,
transport::Device& device, const size_t nconn,
stack::ipv4::Address const& ip,
stack::ipv4::Address const& gw,
stack::ipv4::Address const& nm, const ssl::Protocol type,
std::string_view cert, std::string_view key)
{
return std::make_unique<Server>(log, delegate, device, nconn, ip, gw, nm,
type, cert, key);
}

/*
* Constructor and destructor.
*/

Server(system::Logger& log, api::interface::Server::Delegate& delegate,
transport::Device& device, const ssl::Protocol type,
std::string_view cert, std::string_view key, const size_t nconn);
transport::Device& device, const size_t nconn,
stack::ipv4::Address const& ip, stack::ipv4::Address const& gw,
stack::ipv4::Address const& nm, const ssl::Protocol type,
std::string_view cert, std::string_view key);

~Server() override;

/**
/*
* Device interface.
*/

Expand All @@ -42,7 +63,7 @@ class Server
return m_server->sent(len, data);
}

/**
/*
* Server interface.
*/

Expand Down Expand Up @@ -73,7 +94,7 @@ class Server
m_server->unlisten(port);
}

/**
/*
* Server delegate.
*/

Expand Down
Loading

0 comments on commit 1661fed

Please sign in to comment.