-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add injectable ICD Check-In BackOff strategy
- Loading branch information
1 parent
6fbe28b
commit 1459034
Showing
11 changed files
with
267 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* | ||
* Copyright (c) 2024 Project CHIP Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <app/icd/server/ICDCheckInBackOffStrategy.h> | ||
#include <lib/core/ClusterEnums.h> | ||
|
||
namespace chip { | ||
namespace app { | ||
|
||
/** | ||
* @brief Default ICD Check-In BackOff Strategy. | ||
* The default strategy is based on the two types of controllers | ||
* - kPermanent : Always send a Check-In message | ||
* - kEphemeral : Never send a Check-In message | ||
* | ||
* This implementation represents a no back off strategy. | ||
*/ | ||
class DefaultICDCheckInBackOffStrategy : public ICDCheckInBackOffStrategy | ||
{ | ||
public: | ||
DefaultICDCheckInBackOffStrategy() = default; | ||
~DefaultICDCheckInBackOffStrategy() = default; | ||
|
||
/** | ||
* @brief Function checks if the entry is a permanent or ephemeral client. | ||
* If the client is permanent, we should send a Check-In message. | ||
* If the cliet is ephemerakl, we should not send a Check-In message. | ||
* | ||
* @param entry Entry for which we are deciding if we need to send a Check-In message or not. | ||
* @return true If the client is permanent, return true. | ||
* @return false If the client is not permanent, ephemeral or invalid, return false. | ||
*/ | ||
bool ShouldSendCheckInMessage(const ICDMonitoringEntry & entry) | ||
{ | ||
return (entry.clientType == Clusters::IcdManagement::ClientTypeEnum::kPermanent); | ||
} | ||
|
||
/** | ||
* @brief The default Check-In BackOff fundamentally implements a no back off strategy. | ||
* As such, we don't need to execute anything to force the maximum Check-In BackOff. | ||
* | ||
*/ | ||
CHIP_ERROR ForceMaximumCheckInBackoff() { return CHIP_NO_ERROR; } | ||
}; | ||
|
||
} // namespace app | ||
} // namespace chip |
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) 2024 Project CHIP Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#pragma once | ||
|
||
#include <app/icd/server/ICDMonitoringTable.h> | ||
#include <lib/core/CHIPError.h> | ||
|
||
namespace chip { | ||
namespace app { | ||
|
||
/** | ||
* @brief This class defines the necessary interface a ICD Check-In BackOff strategy needs to implment to be consummed by the | ||
* ICDManager class. The strategy is injected with the init server params when initializing the device Server class. | ||
*/ | ||
class ICDCheckInBackOffStrategy | ||
{ | ||
public: | ||
virtual ~ICDCheckInBackOffStrategy() = default; | ||
|
||
/** | ||
* @brief Function is used by the ICDManager to determine if a Check-In message should be sent to the given entry based on the | ||
* Check-In BackOff strategy. | ||
* | ||
* There are no requirements on how the Check-In BackOff strategy should behave. | ||
* The only specified requirement is the maximum time between to Check-In message, MaximumCheckInBackOff. | ||
* All strategies must respect this requirement. | ||
* | ||
* @param entry ICDMonitoringEntry for which we are about to send a Check-In message to. | ||
* | ||
* @return true ICDCheckInBackOffStrategy determines that we SHOULD send a Check-In message to the given entry | ||
* @return falseI CDCheckInBackOffStrategy determines that we SHOULD NOT send a Check-In message to the given entry | ||
*/ | ||
virtual bool ShouldSendCheckInMessage(const ICDMonitoringEntry & entry) = 0; | ||
|
||
/** | ||
* @brief Function is used within the test event trigger to force the maximum BackOff state of the ICD Check-In BackOff | ||
* strategy. This enables to validate the strategy and to certify it respects the MaximumCheckInBackOff interval during | ||
* certification. | ||
* | ||
* Function sets the maxmimum BackOff state for all clients registered with the ICD | ||
* | ||
* @return CHIP_ERROR Any error returned during the forcing of the maximum BackOff state | ||
*/ | ||
virtual CHIP_ERROR ForceMaximumCheckInBackoff() = 0; | ||
}; | ||
|
||
} // namespace app | ||
} // namespace chip |
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
57 changes: 57 additions & 0 deletions
57
src/app/icd/server/tests/TestDefaultICDCheckInBackOffStrategy.cpp
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,57 @@ | ||
/* | ||
* | ||
* Copyright (c) 2024 Project CHIP Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <pw_unit_test/framework.h> | ||
|
||
#include <app/icd/server/DefaultICDCheckInBackOffStrategy.h> | ||
#include <app/icd/server/ICDMonitoringTable.h> | ||
#include <crypto/DefaultSessionKeystore.h> | ||
#include <lib/core/ClusterEnums.h> | ||
#include <lib/core/DataModelTypes.h> | ||
#include <lib/core/NodeId.h> | ||
|
||
using namespace chip; | ||
using namespace chip::app; | ||
using namespace chip::app::Clusters::IcdManagement; | ||
|
||
using TestSessionKeystoreImpl = Crypto::DefaultSessionKeystore; | ||
|
||
namespace { | ||
|
||
TEST(TestDefaultICDCheckInBackOffStrategy, TestShouldSendCheckInMessagePermanentClient) | ||
{ | ||
TestSessionKeystoreImpl keystore; | ||
ICDMonitoringEntry entry(&keystore); | ||
|
||
entry.clientType = ClientTypeEnum::kPermanent; | ||
|
||
DefaultICDCheckInBackOffStrategy strategy; | ||
EXPECT_TRUE(strategy.ShouldSendCheckInMessage(entry)); | ||
} | ||
|
||
TEST(TestDefaultICDCheckInBackOffStrategy, TestShouldSendCheckInMessageEphemeralClient) | ||
{ | ||
TestSessionKeystoreImpl keystore; | ||
ICDMonitoringEntry entry(&keystore); | ||
|
||
entry.clientType = ClientTypeEnum::kEphemeral; | ||
|
||
DefaultICDCheckInBackOffStrategy strategy; | ||
EXPECT_FALSE(strategy.ShouldSendCheckInMessage(entry)); | ||
} | ||
|
||
} // namespace |
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
Oops, something went wrong.