Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ to install different dependencies.
required to run some of the generated binaries uner valgrind
- valgrind, as some tests use it to check for memory errors
- Boost library, for some of the C++ tests: we currently require
`boost/optional.hpp` and `boost/functional/hash.hpp`
`boost/functional/hash.hpp`

### Installing dependencies from package repositories

Expand Down
2 changes: 1 addition & 1 deletion proto/frontend/src/action_prof_mgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ class ActionProfAccessManual : public ActionProfAccessBase {
bool get_member_info(const Id &group_id, const Id &member_id,
int *weight, WatchPort *watch_port) const;

// would be nice to be able to use boost::optional for the retrieve functions;
// would be nice to be able to use std::optional for the retrieve functions;
// we cannot return a pointer (that would be null if the key couldn't be
// found) because some other thread may come in and remove the corresponding
// group / member, thus invalidating the pointer.
Expand Down
2 changes: 1 addition & 1 deletion proto/frontend/src/table_info_store.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class TableInfoStore {
uint64_t controller_metadata{0};
std::string metadata;
int64_t idle_timeout_ns{0};
// wish I could use boost::optional here
// wish I could use std::optional here
bool is_oneshot{false};
pi_indirect_handle_t oneshot_group_handle{0};
};
Expand Down
3 changes: 1 addition & 2 deletions proto/tests/matchers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,7 @@ TableEntryMatcher_Base::add_direct_counter(pi_p4_id_t counter_id,
CounterDataMatcher(data, check_bytes, check_packets));
}

void
TableEntryMatcher_Base::set_ttl(boost::optional<int64_t> ttl_ns) {
void TableEntryMatcher_Base::set_ttl(std::optional<int64_t> ttl_ns) {
ttl = ttl_ns;
}

Expand Down
12 changes: 5 additions & 7 deletions proto/tests/matchers.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,13 @@
#include <gmock/gmock.h>

#include <iosfwd>
#include <optional>
#include <string>
#include <unordered_map>

#include <boost/optional.hpp>

#include "p4/v1/p4runtime.pb.h"

#include "PI/pi.h"
#include "PI/pi_clone.h"
#include "p4/v1/p4runtime.pb.h"

namespace pi {
namespace proto {
Expand Down Expand Up @@ -224,8 +222,8 @@ class TableEntryMatcher_Base {
const p4::v1::CounterData &data,
bool check_bytes, bool check_packets);

// boost:none means to TTL expected in the entry properties
void set_ttl(boost::optional<int64_t> ttl_ns);
// std::nullopt means to TTL expected in the entry properties
void set_ttl(std::optional<int64_t> ttl_ns);

protected:
TableEntryMatcher_Base();
Expand All @@ -235,7 +233,7 @@ class TableEntryMatcher_Base {

std::unordered_map<pi_p4_id_t, MeterSpecMatcher> meters;
std::unordered_map<pi_p4_id_t, CounterDataMatcher> counters;
boost::optional<int64_t> ttl;
std::optional<int64_t> ttl;
};

class TableEntryMatcher_Direct
Expand Down
13 changes: 6 additions & 7 deletions proto/tests/mock_switch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,14 @@

#include <algorithm> // std::copy, std::for_each, std::count
#include <map>
#include <optional>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility> // std::move
#include <vector>

#include <boost/functional/hash.hpp>
#include <boost/optional.hpp>

#include "PI/frontends/cpp/tables.h"
#include "PI/frontends/proto/device_mgr.h"
#include "PI/int/pi_int.h"
Expand All @@ -44,6 +42,7 @@
#include "PI/target/pi_imp.h"
#include "PI/target/pi_learn_imp.h"
#include "PI/target/pi_tables_imp.h"
#include "boost/functional/hash.hpp"

namespace pi {
namespace proto {
Expand Down Expand Up @@ -800,7 +799,7 @@ class DummyPRE {
pi_mc_node_handle_t node_handle) {
auto it = mc_nodes.find(node_handle);
if (it == mc_nodes.end()) return PI_STATUS_TARGET_ERROR;
if (it->second.attached_to.is_initialized()) return PI_STATUS_TARGET_ERROR;
if (it->second.attached_to) return PI_STATUS_TARGET_ERROR;
it->second.attached_to = grp_handle;
return PI_STATUS_SUCCESS;
}
Expand All @@ -810,8 +809,8 @@ class DummyPRE {
(void)grp_handle;
auto it = mc_nodes.find(node_handle);
if (it == mc_nodes.end()) return PI_STATUS_TARGET_ERROR;
if (!it->second.attached_to.is_initialized()) return PI_STATUS_TARGET_ERROR;
it->second.attached_to = boost::none;
if (!it->second.attached_to) return PI_STATUS_TARGET_ERROR;
it->second.attached_to = std::nullopt;
return PI_STATUS_SUCCESS;
}

Expand All @@ -833,7 +832,7 @@ class DummyPRE {
pi_mc_node_handle_t node_handle;
pi_mc_rid_t rid;
std::vector<pi_mc_port_t> eg_ports;
boost::optional<pi_mc_grp_handle_t> attached_to;
std::optional<pi_mc_grp_handle_t> attached_to;

McNode(pi_mc_node_handle_t node_handle,
pi_mc_rid_t rid,
Expand Down
19 changes: 8 additions & 11 deletions proto/tests/server/test_gnmi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
*/

#include <grpcpp/grpcpp.h>

#include <gtest/gtest.h>

#include <chrono>
Expand All @@ -30,17 +29,15 @@
#include <map>
#include <memory>
#include <mutex>
#include <optional>
#include <ostream>
#include <string>
#include <thread>
#include <unordered_map>
#include <vector>

#include <boost/optional.hpp>

#include "gnmi/gnmi.grpc.pb.h"

#include "gnmi.h"
#include "gnmi/gnmi.grpc.pb.h"

using grpc::Server;
using grpc::ServerBuilder;
Expand Down Expand Up @@ -191,9 +188,9 @@ std::ostream &operator <<(std::ostream &os, const Event &e) {
return os;
}

std::ostream &operator <<(std::ostream &os, const boost::optional<Event> &e) {
if (e.is_initialized())
os << e.get();
std::ostream& operator<<(std::ostream& os, const std::optional<Event>& e) {
if (e)
os << e.value();
else
os << "NONE";
return os;
Expand Down Expand Up @@ -559,11 +556,11 @@ class TestGNMISysrepo : public TestGNMI {
return event_queue.empty();
}

boost::optional<Event> wait_for_event(const std::string &xpath) {
std::optional<Event> wait_for_event(const std::string& xpath) {
Event event;
event.xpath = xpath;
if (!event_queue.pop_back(&event, std::chrono::milliseconds(500)))
return boost::none;
return std::nullopt;
return event;
}

Expand Down Expand Up @@ -623,7 +620,7 @@ class TestGNMISysrepo : public TestGNMI {
auto xpath = gNMI_path_to_XPath(notification.prefix(), update.path());
if (xpath == expected_xpath) return update.val().string_val();
}
return ""; // use boost::optional instead ?
return ""; // use std::optional instead ?
}

static constexpr char iface_type[] = "iana-if-type:ethernetCsmacd";
Expand Down
9 changes: 4 additions & 5 deletions proto/tests/stream_receiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@
#include <chrono>
#include <condition_variable>
#include <mutex>
#include <optional>
#include <queue>

#include <boost/optional.hpp>

#include "p4/v1/p4runtime.pb.h"

namespace p4v1 = ::p4::v1;
Expand Down Expand Up @@ -102,8 +101,8 @@ class StreamReceiver {
}

template <typename Rep, typename Period>
boost::optional<T> get(const std::chrono::duration<Rep, Period> &timeout) {
using Clock = std::chrono::steady_clock;
std::optional<T> get(const std::chrono::duration<Rep, Period>& timeout) {
using Clock = std::chrono::steady_clock;
Lock lock(mutex);
// using wait_until and not wait_for to account for spurious awakenings.
if (cvar.wait_until(lock, Clock::now() + timeout,
Expand All @@ -112,7 +111,7 @@ class StreamReceiver {
msgs.pop();
return msg;
}
return boost::none;
return std::nullopt;
}

private:
Expand Down
Loading
Loading