21#include "flow/error/error.hpp"
29 "@todo Investigate why this is required. As of this writing I do not recall off-hand.");
48 m_service_ports(S_NUM_SERVICE_PORTS),
49 m_ephemeral_ports(S_NUM_EPHEMERAL_PORTS),
50 m_ephemeral_and_recent_ephemeral_ports(S_NUM_EPHEMERAL_PORTS),
108 FLOW_LOG_INFO(
"Flow service port [" << port <<
"] reserved.");
118 if (port_bit_idx != Bit_set::npos)
143 FLOW_LOG_INFO(
"Ran out of non-recently used and available NetFlow ports; "
144 "reserving oldest recently used available NetFlow port [" << port <<
"].");
167 FLOW_LOG_INFO(
"NetFlow ephemeral port [" << port <<
"] reserved.");
195 FLOW_LOG_INFO(
"NetFlow service port [" << port <<
"] returned.");
249 FLOW_LOG_INFO(
"NetFlow ephemeral port [" << port <<
"] returned.");
263 using boost::random::uniform_int_distribution;
266 uniform_int_distribution<size_t> range(0, ports.size() - 1);
270 if (!ports.test(port_bit_idx))
272 port_bit_idx = ports.find_next(port_bit_idx);
274 if (port_bit_idx == Bit_set::npos)
276 port_bit_idx = ports.find_first();
Interface that the user should implement, passing the implementing Logger into logging classes (Flow'...
static const size_t S_NUM_EPHEMERAL_PORTS
Total number of "ephemeral" ports (ones reserved at random with reserve_ephemeral_port()).
static const size_t S_MAX_RECENT_EPHEMERAL_PORTS
The maximum size of m_recent_ephemeral_ports.
flow_port_t reserve_port(flow_port_t port, Error_code *err_code)
Reserve the specified service port, or reserve_ephemeral_port() if the specified port is S_PORT_ANY.
Bit_set m_service_ports
Current service port set.
flow_port_t reserve_ephemeral_port(Error_code *err_code)
Reserve a randomly chosen available ephemeral port.
static const flow_port_t S_FIRST_SERVICE_PORT
The port number of the lowest service port.
boost::dynamic_bitset<> Bit_set
Short-hand for bit set of arbitary length, representing a port set (each bit is a port; 1 open,...
void return_port(flow_port_t port, Error_code *err_code)
Return a previously reserved port (of any type).
static const flow_port_t S_FIRST_EPHEMERAL_PORT
The port number of the lowest ephemeral port.
Bit_set m_ephemeral_and_recent_ephemeral_ports
Set representing the union of the set of current reserved ephemeral ports and the set of the last up-...
static bool is_service_port(flow_port_t port)
Returns true if and only if the given port is a service port (as opposed to ephemeral or S_PORT_ANY).
Port_space(log::Logger *logger)
Constructs the Port_space with all ports available.
size_t find_available_port_bit_idx(const Bit_set &ports)
Helper method that, given a reference to a bit set representing available ports (1 available,...
static const size_t S_NUM_SERVICE_PORTS
Total number of "service" ports (ones that can be reserved by number with reserve_port()).
std::queue< flow_port_t > m_recent_ephemeral_ports
A FIFO of recently used but currently available ephemeral ports.
Random_generator m_rnd_generator
Random number generator for picking ports.
Bit_set m_ephemeral_ports
Current ephemeral port set; indexing analogous to m_service_ports but starting at S_FIRST_EPHEMERAL_P...
static const size_t S_NUM_PORTS
Total number of ports in the port space, including S_PORT_ANY.
util::Rnd_gen_uniform_range_base::Random_generator Random_generator
Random number generator.
uint32_t flow_port_sans_overflow_t
A type same as flow_port_t but larger, useful when doing arithmetic that might hit overflow in corner...
#define FLOW_ERROR_EMIT_ERROR(ARG_val)
Sets *err_code to ARG_val and logs a warning about the error using FLOW_LOG_WARNING().
#define FLOW_LOG_INFO(ARG_stream_fragment)
Logs an INFO message into flow::log::Logger *get_logger() with flow::log::Component get_log_component...
#define FLOW_LOG_TRACE(ARG_stream_fragment)
Logs a TRACE message into flow::log::Logger *get_logger() with flow::log::Component get_log_component...
@ S_INTERNAL_ERROR_PORT_NOT_TAKEN
Internal error: Tried to return Flow port which had not been reserved.
@ S_OUT_OF_PORTS
No more ephemeral Flow ports available.
@ S_PORT_TAKEN
Flow port already reserved.
@ S_INVALID_SERVICE_PORT_NUMBER
Flow port number is not in the valid service port number range.
Flow module containing the API and implementation of the Flow network protocol, a TCP-inspired stream...
uint16_t flow_port_t
Logical Flow port type (analogous to a UDP/TCP port in spirit but in no way relevant to UDP/TCP).
const flow_port_t S_PORT_ANY
Special Flow port value used to indicate "invalid port" or "please pick a random available ephemeral ...
bool in_closed_open_range(T const &min_val, T const &val, T const &max_val)
Returns true if and only if the given value is within the given range, given as a [low,...
boost::chrono::microseconds time_since_posix_epoch()
Get the current POSIX (Unix) time as a duration from the Epoch time point.
boost::system::error_code Error_code
Short-hand for a boost.system error code (which basically encapsulates an integer/enum error code and...
Flow_log_component
The flow::log::Component payload enumeration comprising various log components used by Flow's own int...