Kea 3.1.1
blq_msg.h
Go to the documentation of this file.
1// Copyright (C) 2022-2025 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#ifndef BLQ_MSG_H
8#define BLQ_MSG_H
9
10#include <config.h>
11#include <dhcp/pkt.h>
12#include <tcp/tcp_stream_msg.h>
13
14namespace isc {
15namespace lease_query {
16
18typedef uint32_t Xid;
19
24class BlqMsg {
25public:
30 : pkt_(pkt) {
31 if (!pkt) {
32 isc_throw(BadValue, "BlqMsg::pkt cannot be empty");
33 }
34 }
35
37 virtual ~BlqMsg() {
38 }
39
41 Xid getXid() const {
42 return (pkt_->getTransid());
43 }
44
48 void setXid(const Xid& xid) {
49 pkt_->setTransid(xid);
50 }
51
54 return (pkt_);
55 }
56
58 void pack() {
59 // We need the wire form of the query, so pack it.
60 pkt_->pack();
61 auto buffer = pkt_->getBuffer();
62
63 // Prepend the length of the request.
64 uint16_t size = static_cast<uint16_t>(buffer.getLength());
65 wire_data_.reserve(size + 2);
66 wire_data_.push_back(static_cast<uint8_t>((size & 0xff00U) >> 8));
67 wire_data_.push_back(static_cast<uint8_t>(size & 0x00ffU));
68
69 // Add on the packet data.
70 auto const& data = buffer.getVector();
71 wire_data_.insert(wire_data_.end(), data.cbegin(), data.cend());
72 }
73
75 size_t getWireSize() const {
76 return (wire_data_.size());
77 }
78
81 return (wire_data_);
82 }
83
84protected:
87
90};
91
93typedef boost::shared_ptr<BlqMsg> BlqMsgPtr;
94
96class BlqQuery : public BlqMsg {
97public:
102 : BlqMsg(query) {
103 }
104
106 virtual ~BlqQuery() {
107 }
108
111 return (getPkt());
112 }
113};
114
116typedef boost::shared_ptr<BlqQuery> BlqQueryPtr;
117
119typedef std::list<BlqQueryPtr> BlqQueryList;
120
124class BlqResponse : public BlqMsg {
125public:
130 : BlqMsg(response) {
131 }
132
134 virtual ~BlqResponse() {};
135
138 return (getPkt());
139 }
140};
141
143typedef boost::shared_ptr<BlqResponse> BlqResponsePtr;
144
146typedef std::list<BlqResponsePtr> BlqResponseList;
147
148} // end of namespace isc::lease_query
149} // end of namespace isc
150
151#endif // BLQ_MSG_H
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
virtual ~BlqMsg()
Destructor.
Definition blq_msg.h:37
size_t getWireSize() const
Returns size of the packed wire data.
Definition blq_msg.h:75
void setXid(const Xid &xid)
Sets the transaction id.
Definition blq_msg.h:48
BlqMsg(dhcp::PktPtr pkt)
Constructor.
Definition blq_msg.h:29
tcp::WireData wire_data_
Holds the TCP stream wire form of the query.
Definition blq_msg.h:89
dhcp::PktPtr pkt_
The DHCP(4/6) packet containing the query.
Definition blq_msg.h:86
dhcp::PktPtr getPkt() const
Returns a pointer to the DHCPx packet.
Definition blq_msg.h:53
void pack()
Packs the packet into wire form ready for TCP transmission.
Definition blq_msg.h:58
Xid getXid() const
Returns the transaction id.
Definition blq_msg.h:41
tcp::WireData & getWireData()
Returns a reference to the wire data.
Definition blq_msg.h:80
dhcp::PktPtr getQuery()
Returns the DHCPx query packet.
Definition blq_msg.h:110
BlqQuery(dhcp::PktPtr query)
Constructor.
Definition blq_msg.h:101
virtual ~BlqQuery()
Destructor.
Definition blq_msg.h:106
dhcp::PktPtr getResponse()
Returns the DHCPx response packet.
Definition blq_msg.h:137
BlqResponse(dhcp::PktPtr response)
Constructor.
Definition blq_msg.h:129
virtual ~BlqResponse()
Destructor.
Definition blq_msg.h:134
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< isc::dhcp::Pkt > PktPtr
A pointer to either Pkt4 or Pkt6 packet.
Definition pkt.h:999
std::list< BlqQueryPtr > BlqQueryList
Contains a list of BlqQuery pointers.
Definition blq_msg.h:119
boost::shared_ptr< BlqResponse > BlqResponsePtr
Defines a shared pointer to an BlqResponse.
Definition blq_msg.h:143
uint32_t Xid
Defines a Bulk LeaseQuery transaction id.
Definition blq_msg.h:18
std::list< BlqResponsePtr > BlqResponseList
Contains a list of BlqResponse pointers.
Definition blq_msg.h:146
boost::shared_ptr< BlqQuery > BlqQueryPtr
Defines a shared pointer to an BlqQuery.
Definition blq_msg.h:116
boost::shared_ptr< BlqMsg > BlqMsgPtr
Defines a shared pointer to an BlqMsg.
Definition blq_msg.h:93
std::vector< uint8_t > WireData
Defines a data structure for storing raw bytes of data on the wire.
Defines the logger used by the top-level component of kea-lfc.