7#ifndef RADIUS_ACCOUNTING_H
8#define RADIUS_ACCOUNTING_H
14#include <boost/multi_index_container.hpp>
15#include <boost/multi_index/member.hpp>
16#include <boost/multi_index/ordered_index.hpp>
17#include <boost/date_time/gregorian/gregorian_types.hpp>
18#include <boost/date_time/posix_time/posix_time_types.hpp>
56 const boost::posix_time::ptime& timestamp)
74typedef boost::multi_index_container<
80 boost::multi_index::indexed_by<
83 boost::multi_index::ordered_unique<
84 boost::multi_index::tag<TMAddressIndexTag>,
85 boost::multi_index::member<
LeaseTS,
91 boost::multi_index::ordered_non_unique<
92 boost::multi_index::tag<TMTimestampIndexTag>,
93 boost::multi_index::member<
LeaseTS,
94 const boost::posix_time::ptime,
167 static size_t counter_;
170 static std::mutex mutex_;
195 void init(
const std::string& filename);
270 boost::posix_time::ptime
The IOAddress class represents an IP addresses (version agnostic)
const asiolink::IOAddress addr_
Lease address.
const boost::posix_time::ptime timestamp_
Create timestamp.
LeaseTS(const asiolink::IOAddress &addr, const boost::posix_time::ptime ×tamp)
Constructor.
RadiusAcctHandlerPtr buildAcct6(const data::ConstElementPtr &arguments, Event event)
Build RadiusAcct handler for Accounting-Request.
TMContainer container_
The Create timestamp container which holds session history.
RadiusAcctHandlerPtr buildAcct4(const data::ConstElementPtr &arguments, Event event)
Build RadiusAcct handler for Accounting-Request.
void eraseCreateTimestamp(const asiolink::IOAddress &addr)
Erase create-timestamp entry to session history.
CSVFilePtr file_
Pointer to the CSVFile.
void init(const std::string &filename)
Initialize.
bool loadFromFile()
Load create-timestamp entries from file.
static void runAsync(RadiusAcctHandlerPtr handler)
Run asynchronously.
std::mutex mutex_
Mutex to protect access to container_ and file_.
RadiusAccounting()
Constructor.
void storeToFile()
Store create-timestamp entries to a file.
size_t record_count_
New record counter.
RadiusAcctHandlerPtr buildAcct(const dhcp::Lease4Ptr &lease, Event event)
Build RadiusAcct handler for Accounting-Request - IPv4.
static void terminate(RadiusAcctEnv env, int result)
Termination callback.
const boost::posix_time::ptime epoch_
Epoch to avoid too long values.
boost::posix_time::ptime getCreateTimestamp(const asiolink::IOAddress &addr, bool generate)
Get lease create-timestamp entry from session history.
std::string filename_
Create timestamps file name.
virtual ~RadiusAccounting()=default
Destructor.
Class of Radius accounting environments.
RadiusAcctEnv(std::string session_id, Event event, uint32_t subnet_id, AttributesPtr send_attrs)
Constructor.
std::string session_id_
Session Id.
bool finished_
Termination flag.
AttributesPtr send_attrs_
Attributes to send.
uint32_t subnet_id_
Subnet Id (aka client/NAS port).
RadiusAcctHandler(RadiusAcctEnv env, const CallbackAcct &callback)
Constructor.
static size_t getCounter()
Get instance counter.
RadiusAcctEnv env_
Environment.
void start()
Start communication.
virtual ~RadiusAcctHandler()
Destructor.
RadiusAsyncAcctPtr acct_
Pointer to the communication class.
RadiusService(const std::string &name)
Constructor.
boost::shared_ptr< const Element > ConstElementPtr
boost::shared_ptr< Lease6 > Lease6Ptr
Pointer to a Lease6 structure.
boost::shared_ptr< Lease4 > Lease4Ptr
Pointer to a Lease4 structure.
boost::shared_ptr< RadiusAcctHandler > RadiusAcctHandlerPtr
Type of pointers to Radius accounting communication handler.
TMContainer::index< TMAddressIndexTag >::type TMContainerAddressIndex
First index type in the TMContainer.
boost::shared_ptr< Attributes > AttributesPtr
Shared pointers to attribute collection.
boost::multi_index_container< LeaseTS, boost::multi_index::indexed_by< boost::multi_index::ordered_unique< boost::multi_index::tag< TMAddressIndexTag >, boost::multi_index::member< LeaseTS, const asiolink::IOAddress, &LeaseTS::addr_ > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< TMTimestampIndexTag >, boost::multi_index::member< LeaseTS, const boost::posix_time::ptime, &LeaseTS::timestamp_ > > > > TMContainer
Create timestamp container.
std::function< void(int)> CallbackAcct
Type of callback for accounting termination.
TMContainer::index< TMTimestampIndexTag >::type TMContainerTimestampIndex
Second index type in the TMContainer.
Event
Type of accounting events.
boost::shared_ptr< util::CSVFile > CSVFilePtr
Type of pointers to CSV file.
boost::shared_ptr< RadiusAsyncAcct > RadiusAsyncAcctPtr
Pointer to asynchronous accounting.
string eventToText(Event event)
Translate an event to text.
Defines the logger used by the top-level component of kea-lfc.
Tag for the index for searching by address.
Tag for the index for searching by timestamp.