forked from isc-projects/kea
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[5647] CalloutHandle is now associated with the DHCP packet object.
When the packet goes out of scope the callout handle is destroyed.
- Loading branch information
1 parent
092b634
commit faf336d
Showing
10 changed files
with
152 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC") | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
#include <hooks/callout_handle_associate.h> | ||
#include <hooks/hooks_manager.h> | ||
|
||
namespace isc { | ||
namespace hooks { | ||
|
||
CalloutHandleAssociate::CalloutHandleAssociate() | ||
: callout_handle_() { | ||
} | ||
|
||
CalloutHandlePtr | ||
CalloutHandleAssociate::getCalloutHandle() { | ||
if (!callout_handle_) { | ||
callout_handle_ = HooksManager::createCalloutHandle(); | ||
} | ||
|
||
return (callout_handle_); | ||
} | ||
|
||
} // end of namespace isc::hooks | ||
} // end of namespace isc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC") | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
#ifndef CALLOUT_HANDLE_ASSOCIATE_H | ||
#define CALLOUT_HANDLE_ASSOCIATE_H | ||
|
||
#include <hooks/callout_handle.h> | ||
|
||
namespace isc { | ||
namespace hooks { | ||
|
||
/// @brief Base class for classes which need to be associated with | ||
/// a @c CalloutHandle object. | ||
/// | ||
/// The @c CalloutHandle is an object used to pass various parameters | ||
/// between Kea and the callouts. The Kea servers usually invoke | ||
/// multiple different callouts for a single packet such as DHCP | ||
/// packet, control command etc. Therefore, it is required to | ||
/// associate this packet with an instance of the callout handle, so | ||
/// this instance can be used for all callouts invoked for this | ||
/// packet. | ||
/// | ||
/// Previously this association was made by the @c CalloutHandleStore | ||
/// class. However, with the introduction of parallel processing | ||
/// of packets (DHCP packets parking) it became awkward to use. | ||
/// Attempts to extend this class to hold a map of associations | ||
/// failed because of no easy way to garbage collect unused handles. | ||
/// | ||
/// The easiest way to deal with this is to provide ownership of the | ||
/// @c CalloutHandle to the object with which it is associated. The | ||
/// class of this object needs to derive from this class. When the | ||
/// object (e.g. DHCP packet) goes out of scope and is destroyed | ||
/// this instance is destroyed as well. | ||
class CalloutHandleAssociate { | ||
public: | ||
|
||
/// @brief Constructor. | ||
CalloutHandleAssociate(); | ||
|
||
/// @brief Returns callout handle. | ||
/// | ||
/// The callout handle is created if it doesn't exist. Subsequent | ||
/// calls to this method always return the same handle. | ||
/// | ||
/// @return Pointer to the callout handle. | ||
CalloutHandlePtr getCalloutHandle(); | ||
|
||
protected: | ||
|
||
/// @brief Callout handle stored. | ||
CalloutHandlePtr callout_handle_; | ||
|
||
|
||
}; | ||
|
||
} // end of isc::hooks | ||
} // end of isc | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC") | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
#include <config.h> | ||
|
||
#include <hooks/callout_handle.h> | ||
#include <hooks/callout_handle_associate.h> | ||
#include <gtest/gtest.h> | ||
|
||
using namespace isc::hooks; | ||
|
||
namespace { | ||
|
||
// This test verifies that the callout handle can be created and | ||
// retrieved from the CalloutHandleAssociate. | ||
TEST(CalloutHandleAssociate, getCalloutHandle) { | ||
CalloutHandleAssociate associate; | ||
// The handle should be initialized and returned. | ||
CalloutHandlePtr callout_handle = associate.getCalloutHandle(); | ||
ASSERT_TRUE(callout_handle); | ||
|
||
// When calling the second time, the same handle should be returned. | ||
CalloutHandlePtr callout_handle2 = associate.getCalloutHandle(); | ||
EXPECT_TRUE(callout_handle == callout_handle2); | ||
|
||
// A different associate should produce a different handle. | ||
CalloutHandleAssociate associate2; | ||
callout_handle2 = associate2.getCalloutHandle(); | ||
EXPECT_FALSE(callout_handle == callout_handle2); | ||
} | ||
|
||
} // end of anonymous namespace |