Commit 8c8f4dd4 authored by Thomas Markwalder's avatar Thomas Markwalder
Browse files

[#42, !103] General clean up

parent eddf6e3d
This diff is collapsed.
......@@ -296,13 +296,8 @@ void IfaceMgr::stopDHCPReceiver() {
}
receiver_error_ = "no error";
/* if(getPacketQueue4())*/ {
getPacketQueue4()->clear();
}
/* if (getPacketQueue6()) */ {
getPacketQueue4()->clear();
}
getPacketQueue4()->clear();
getPacketQueue4()->clear();
}
......
......@@ -1035,9 +1035,9 @@ public:
/// @brief DHCPv4 receiver packet queue.
///
/// Incoming packets are read by the receiver thread and
/// added to this queue. @c receive4() dequeues and
/// returns them.
PacketQueue4Ptr getPacketQueue4() {
/// added to this queue. @c receive4() dequeues and
/// returns them.
PacketQueue4Ptr getPacketQueue4() {
return (PacketQueueMgr4::instance().getPacketQueue());
}
......@@ -1060,8 +1060,7 @@ public:
///
/// @throw Unexpected if the thread already exists.
void startDHCPReceiver(const uint16_t family);
/// @brief Stops the DHCP packet receiver.
/// @brief Stops the DHCP packet receiver.
///
/// Stops the receiver and delete the dedicated thread.
void stopDHCPReceiver();
......@@ -1186,7 +1185,7 @@ private:
/// Loops forever reading DHCPv4 packets from the interface sockets
/// and adds them to the packet queue. It monitors the "terminate"
/// watch socket, and exits if it is marked ready. This is method
/// is used as the worker function in the thread created by @c
/// is used as the worker function in the thread created by @c
/// startDHCP4Receiver(). It currently uses select() to monitor
/// socket readiness. If the select errors out (other than EINTR),
/// it marks the "error" watch socket as ready.
......@@ -1195,11 +1194,11 @@ private:
/// @brief Receives a single DHCPv4 packet from an interface socket
///
/// Called by @c receiveDHPC4Packets when a socket fd is flagged as
/// ready. It uses the DHCPv4 packet filter to receive a single packet
/// from the given interface socket, adds it to the packet queue, and
/// ready. It uses the DHCPv4 packet filter to receive a single packet
/// from the given interface socket, adds it to the packet queue, and
/// marks the "receive" watch socket ready. If an error occurs during
/// the read, the "error" watch socket is marked ready.
///
///
/// @param iface interface
/// @param socket_info structure holding socket information
void receiveDHCP4Packet(Iface& iface, const SocketInfo& socket_info);
......@@ -1209,7 +1208,7 @@ private:
/// Loops forever reading DHCPv6 packets from the interface sockets
/// and adds them to the packet queue. It monitors the "terminate"
/// watch socket, and exits if it is marked ready. This is method
/// is used as the worker function in the thread created by @c
/// is used as the worker function in the thread created by @c
/// startDHCP6Receiver(). It currently uses select() to monitor
/// socket readiness. If the select errors out (other than EINTR),
/// it marks the "error" watch socket as ready.
......@@ -1218,11 +1217,11 @@ private:
/// @brief Receives a single DHCPv6 packet from an interface socket
///
/// Called by @c receiveDHPC6Packets when a socket fd is flagged as
/// ready. It uses the DHCPv6 packet filter to receive a single packet
/// from the given interface socket, adds it to the packet queue, and
/// ready. It uses the DHCPv6 packet filter to receive a single packet
/// from the given interface socket, adds it to the packet queue, and
/// marks the "receive" watch socket ready. If an error occurs during
/// the read, the "error" watch socket is marked ready.
///
///
/// @param iface interface
/// @param socket_info structure holding socket information
void receiveDHCP6Packet(const SocketInfo& socket_info);
......@@ -1256,7 +1255,7 @@ private:
std::string receiver_error_;
/// @brief DHCP packet receive error watch socket.
/// Marked as ready when the DHCP packet receiver experiences
/// Marked as ready when the DHCP packet receiver experiences
/// an I/O error.
isc::util::WatchSocket error_watch_;
......
......@@ -36,17 +36,22 @@ enum class QueueEnd {
};
/// @brief Interface for managing a queue of inbound DHCP packets
template<typename PacketTypePtr>
///
/// This class serves as the abstract interface for packet queue
/// implementations which may be used by @c IfaceMgr to store
/// inbound packets until they are a dequeued for processing.
///
template<typename PacketTypePtr>
class PacketQueue {
public:
/// @brief Constructor
///
/// @param queue_type name of this queue's implementation type.
/// @param queue_type name of this queue's implementation type.
/// Typically this is assigned by the factory that creates the
/// queue. It is the logical name used to register queue
/// implementations.
PacketQueue(const std::string& queue_type)
PacketQueue(const std::string& queue_type)
: queue_type_(queue_type) {}
/// Virtual destructor
......@@ -56,9 +61,9 @@ public:
///
/// Calls @c dropPacket to determine if the packet should be queued
/// or dropped. If it should be queued it is added to the end of the
/// specified by the "to" parameter.
/// specified by the "to" parameter.
///
/// @param packet packet to enqueue
/// @param packet packet to enqueue
/// @param source socket the packet came from - this can be
/// @param to end of the queue from which to remove packet(s).
/// Defaults to BACK.
......@@ -92,7 +97,7 @@ public:
/// This function is called at the beginning of @enqueuePacket and
/// provides an opportunity to examine the packet and its source
/// and decide whether it should be dropped or added to the queue.
/// Derivations are expected to provide implementations based on
/// Derivations are expected to provide implementations based on
/// their own requirements. Bear in mind that the packet has NOT
/// been unpacked at this point. The default implementation simply
/// returns false.
......@@ -102,7 +107,7 @@ public:
///
/// @return true if the packet should be dropped, false if it should be
/// kept.
virtual bool dropPacket(PacketTypePtr /* packet */,
virtual bool dropPacket(PacketTypePtr /* packet */,
const SocketInfo& /* source */) {
return (false);
}
......@@ -112,8 +117,8 @@ public:
/// This function is called at the beginning of @c dequeuPacket and
/// provides an opportunity to examine and discard packets from
/// the queue prior to dequeuing the next packet to be
/// processed. Derivations are expected to provide implementations
/// based on their own requirements. The default implemenation is to
/// processed. Derivations are expected to provide implementations
/// based on their own requirements. The default implemenation is to
/// to simply returns without skipping any packets.
///
/// @param from end of the queue from which packets should discarded
......@@ -121,7 +126,7 @@ public:
///
/// @return The number of packets discarded.
virtual int eatPackets(const QueueEnd& /* from */) {
return (0);
return (0);
}
/// @brief Pushes a packet onto the queue
......@@ -140,9 +145,9 @@ public:
/// @brief Gets the packet currently at one end of the queue
///
/// Returns a pointer the packet at the specified end of the
/// queue without dequeuing it.
/// queue without dequeuing it.
///
/// @return A pointer to packet, or an empty pointer if the
/// @return A pointer to packet, or an empty pointer if the
/// queue is empty.
virtual const PacketTypePtr peek(const QueueEnd& from=QueueEnd::FRONT) const = 0;
......@@ -156,12 +161,26 @@ public:
/// @brief Discards all packets currently in the buffer.
virtual void clear() = 0;
/// @brief Fetches operational information about the current state of the queue
///
/// Creates and returns an ElementPtr containing a single entry,
/// "queue-type". Derivations are expected to call this method first
/// and then add their own values. Since implementations may vary
/// widely on data of interest, this is structured as an ElementPtr
/// for broad latitude.
///
/// @return an ElementPtr containing elements for values of interest
virtual data::ElementPtr getInfo() {
data::ElementPtr info = data::Element::createMap();
info->set("queue-type", data::Element::create(queue_type_));
return(info);
}
/// @brief Fetches a JSON string representation of queue operational info
///
/// This method calls @c getInfo() and then converts that into JSON text.
///
/// @return string of JSON text
virtual std::string getInfoStr() {
data::ElementPtr info = getInfo();
std::ostringstream os;
......@@ -169,25 +188,30 @@ public:
return (os.str());
}
/// @brief
/// @return Fetches the logical name of the type of this queue.
std::string getQueueType() {
return (queue_type_);
};
private:
/// @brief Name of the this queue's implementation type.
/// @brief Logcial name of the this queue's implementation type.
std::string queue_type_;
};
/// @brief Defines pointer to the DHCPv4 queue interface used at the application level.
/// @brief Defines pointer to the DHCPv4 queue interface used at the application level.
/// This is the type understood by IfaceMgr and the type that should be returned by
/// DHCPv4 packet queue factories.
typedef boost::shared_ptr<PacketQueue<Pkt4Ptr>> PacketQueue4Ptr;
/// @brief Defines pointer to the DHCPv6 queue interface used at the application level.
/// @brief Defines pointer to the DHCPv6 queue interface used at the application level.
/// This is the type understood by IfaceMgr and the type that should be returned by
/// DHCPv6 packet queue factories.
typedef boost::shared_ptr<PacketQueue<Pkt6Ptr>> PacketQueue6Ptr;
/// @brief Provides an abstract ring-buffer implementation of the PacketQueue interface.
template<typename PacketTypePtr>
template<typename PacketTypePtr>
class PacketQueueRing : public PacketQueue<PacketTypePtr> {
public:
static const size_t MIN_RING_CAPACITY = 5;
......@@ -196,7 +220,7 @@ public:
///
/// @param queue_capacity maximum number of packets the queue can hold
PacketQueueRing(const std::string& queue_type, size_t capacity)
: PacketQueue<PacketTypePtr>(queue_type) {
: PacketQueue<PacketTypePtr>(queue_type) {
queue_.set_capacity(capacity);
}
......@@ -241,9 +265,9 @@ public:
/// @brief Gets the packet currently at one end of the queue
///
/// Returns a pointer the packet at the specified end of the
/// queue without dequeuing it.
/// queue without dequeuing it.
///
/// @return A pointer to packet, or an empty pointer if the
/// @return A pointer to packet, or an empty pointer if the
/// queue is empty.
virtual const PacketTypePtr peek(const QueueEnd& from=QueueEnd::FRONT) const {
PacketTypePtr packet;
......@@ -257,7 +281,7 @@ public:
/// @brief Returns True if the queue is empty.
virtual bool empty() const {
return(queue_.empty());
}
}
/// @brief Returns the maximum number of packets allowed in the buffer.
virtual size_t getCapacity() const {
......@@ -272,8 +296,8 @@ public:
/// @throw BadValue if capacity is too low.
virtual void setCapacity(size_t capacity) {
if (capacity < MIN_RING_CAPACITY) {
isc_throw(BadValue, "Queue capacity of " << capacity
<< " is invalid. It must be at least "
isc_throw(BadValue, "Queue capacity of " << capacity
<< " is invalid. It must be at least "
<< MIN_RING_CAPACITY);
}
......@@ -291,6 +315,7 @@ public:
queue_.clear();
}
/// @brief Fetches pertinent information
virtual data::ElementPtr getInfo() {
data::ElementPtr info = PacketQueue<PacketTypePtr>::getInfo();
info->set("capacity", data::Element::create(static_cast<int64_t>(getCapacity())));
......@@ -305,44 +330,42 @@ private:
};
/// @brief Default DHCPv4 packet queue buffer implementation
/// @brief DHCPv4 packet queue buffer implementation
///
/// This implementation does not (currently) add any drop
/// or packet skip logic, it operates as a verbatim ring
/// queue for DHCPv4 packets.
///
class PacketQueueRing4 : public PacketQueueRing<Pkt4Ptr> {
public:
static const size_t DEFAULT_RING_CAPACITY = 500;
/// @brief Constructor
///
/// @param capacity maximum number of packets the queue can hold
PacketQueueRing4(const std::string& queue_type, size_t capacity=DEFAULT_RING_CAPACITY)
PacketQueueRing4(const std::string& queue_type, size_t capacity)
: PacketQueueRing(queue_type, capacity) {
};
/// @brief virtual Destructor
virtual ~PacketQueueRing4(){}
virtual void useDefaults(){
setCapacity(DEFAULT_RING_CAPACITY);
}
};
/// @brief Default DHCPv6 packet queue buffer implementation
/// @brief DHCPv6 packet queue buffer implementation
///
/// This implementation does not (currently) add any drop
/// or packet skip logic, it operates as a verbatim ring
/// queue for DHCPv6 packets.
///
class PacketQueueRing6 : public PacketQueueRing<Pkt6Ptr> {
public:
static const size_t DEFAULT_RING_CAPACITY = 500;
/// @brief Constructor
///
/// @param capacity maximum number of packets the queue can hold
PacketQueueRing6(const std::string& queue_type, size_t capacity=DEFAULT_RING_CAPACITY)
PacketQueueRing6(const std::string& queue_type, size_t capacity)
: PacketQueueRing(queue_type, capacity) {
};
/// @brief virtual Destructor
virtual ~PacketQueueRing6(){}
virtual void useDefaults() {
setCapacity(DEFAULT_RING_CAPACITY);
}
};
......
......@@ -21,7 +21,7 @@ namespace dhcp {
/// @brief Invalid Queue type exception
///
/// Thrown when a packet queue manager doesn't recognize the type of the queue.
/// Thrown when a packet queue manager doesn't recognize the type of the queue.
class InvalidQueueType : public Exception {
public:
InvalidQueueType(const char* file, size_t line, const char* what) :
......@@ -30,43 +30,11 @@ public:
/// @brief Packet Queue Managers (PQM).
///
/// @todo TKM rewrite this...
/// Each Kea server supporting Configuration Backend feature implements
/// a "manager" class which holds information about supported and
/// configured backends and provides access to the backends. This is
/// similar to @c HostMgr and @c LeaseMgr singletons being used by the
/// DHCP servers.
///
/// The Config Backend Managers are typically implemented as singletons
/// which can be accessed from any place within the server code. This
/// includes server configuration, data fetching during normal server
/// operation and data management, including processing of control
/// commands implemented within hooks libraries.
///
/// The @c BaseConfigBackendMgr is a base class for all PQMs implemented
/// for respective Kea servers. It includes mechanisms to register config
/// backend factory functions and to create instances of the backends using
/// those factory functions as a result of server configuration. The mechanism
/// of factory functions registration is useful in cases when the config
/// backend is implemented within the hook library. Such hook library
/// registers factory function in its @c load function and the server
/// simply calls this function to create the instance of this backend when
/// instructed to do so via configuration. Similar mechanism exists in
/// DHCP @c HostMgr.
///
/// Unlike @c HostMgr, the PQMs do not directly expose API to fetch and
/// manipulate the data in the database. This is done via, so called,
/// Configuration Backends Pools. See @c BaseConfigBackendPool for
/// details. The @c BaseConfigBackendMgr is provided with the pool type
/// via class template parameter. Respective PQM implementations
/// use their own pools, which provide APIs appropriate for those
/// implementations.
/// Base class to manage the registry of packet queue implemenations
/// and the creation of and access to the current packet queue.
///
/// @tparam ConfgBackendPoolType Type of the configuration backend pool
/// to be used by the manager. It must derive from @c BaseConfigBackendPool
/// template class.
/// @tparam PacktQueueTypePtr Base type of packet queues managed by
/// the manager (e.g. PacketQueue4Ptr, PacketQueue6Ptr).
template<typename PacketQueueTypePtr>
class PacketQueueMgr {
public:
......@@ -128,10 +96,6 @@ public:
// If it's there remove it
if (index != factories_.end()) {
factories_.erase(index);
// @todo What do we do here, if we only have one queue?
// I think we don't care, as we should be reloading/reconfiging...
// It may be that PQM doesn't retain the instance at all?
// pool_->delAllBackends(db_type);
return (true);
}
......@@ -152,7 +116,7 @@ public:
/// replaced unless the new queue is successfully created.
///
/// @throw InvalidQueueParameter if parameters is not map that contains
/// "queue-type", InvalidQueueType if the queue type requested is not
/// "queue-type", InvalidQueueType if the queue type requested is not
/// supported.
/// @throw Unexpected if the backend factory function returned NULL.
void createPacketQueue(data::ConstElementPtr parameters) {
......
......@@ -17,8 +17,8 @@ namespace dhcp {
/// @brief Packet Queue Manager for DHPCv4 servers.
///
/// Implements the "manager" class which holds information about the
/// supported and packet queues and provides management of the current
/// queue instance.
/// supported DHCPv4 packet queue implementations and provides management
/// of the current queue instance.
///
/// It is implemented as a singleton that can be accessed from any place
/// within the server code. This includes server configuration, data
......@@ -46,8 +46,8 @@ public:
/// @brief Returns a sole instance of the @c PacketQueueMgr4.
///
/// This method is used to retrieve the instance of the of the
/// @c PacketQueueMgr4 created by the @c create method. If the
/// This method is used to retrieve the instance of the of the
/// @c PacketQueueMgr4 created by the @c create method. If the
/// instance doesn't exist yet, it is created using the @c create
/// method.
static PacketQueueMgr4& instance();
......@@ -55,10 +55,11 @@ public:
private:
/// @brief Private constructor.
///
/// @todo probably will add the open source/default impl(s)
/// It registers a default factory for DHCPv4 queues and creates
/// an default DHCPv4 packet queue.
PacketQueueMgr4();
/// @brief Returns a pointer to the currently used instance of the
/// @brief Returns a pointer to the currently instance of the
/// @c PacketQueueMgr4.
static boost::scoped_ptr<PacketQueueMgr4>& getPacketQueueMgr4Ptr();
};
......
......@@ -17,8 +17,8 @@ namespace dhcp {
/// @brief Packet Queue Manager for DHPCv6 servers.
///
/// Implements the "manager" class which holds information about the
/// supported and packet queues and provides management of the current
/// queue instance.
/// supported DHCPv6 packet queue implementations and provides management
/// of the current queue instance.
///
/// It is implemented as a singleton that can be accessed from any place
/// within the server code. This includes server configuration, data
......@@ -56,7 +56,8 @@ public:
private:
/// @brief Private constructor.
///
/// @todo probably will add the open source/default impl(s)
/// It registers a default factory for DHCPv6 queues and creates
/// an default DHCPv6 packet queue.
PacketQueueMgr6();
/// @brief Returns a pointer to the currently used instance of the
......
......@@ -18,6 +18,9 @@ namespace dhcp {
///
/// This parser parses the "queue-control" parameter which holds the
/// the configurable parameters that tailor DHCP packet queue behavior.
/// Currently "queue-control" is treated as a map of arbitrary values,
/// with only one required value, "queue-type". This was done to
/// provide latitude for differing queue implementations.
///
/// This parser is used in both DHCPv4 and DHCPv6. Derived parsers
/// are not needed.
......
......@@ -361,7 +361,7 @@ public:
}
/// @brief Returns queue control information
/// @return pointer to a queue control information
/// @return pointer to the queue control information
const isc::data::ConstElementPtr getQueueControlInfo() const {
return (queue_control_);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment