-
Notifications
You must be signed in to change notification settings - Fork 427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable support for MQTT stitcher in stirling #1918
Open
ChinmayaSharma-hue
wants to merge
8
commits into
pixie-io:main
Choose a base branch
from
ChinmayaSharma-hue:mqtt-stitcher
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
040752e
Added MQTT Stitcher and corresponding tests
ChinmayaSharma-hue 55f70c7
Fixed Lint Errors
ChinmayaSharma-hue 37b1db2
Comment additions, bug fixes and handling of duplicate requests
ChinmayaSharma-hue 5d9c5e4
State handling in parsing and stitcher test refactoring
ChinmayaSharma-hue 1c6d0b5
Avoiding excess insertion into protocol state and handling of AUTH pa…
ChinmayaSharma-hue c61f88d
Removal of AUTH key mapping entry from MapRequestToResponse
ChinmayaSharma-hue a876583
Fixed lint errors and parse test error.
ChinmayaSharma-hue 1a8b466
Added initializer for global field in StateWrapper in stitcher test
ChinmayaSharma-hue File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ namespace stirling { | |
namespace protocols { | ||
namespace mqtt { | ||
|
||
// MatchKey layout, || control_packet_type (4 bits) | dup (1 bit) | qos (2 bits) | retain (1 bit) || | ||
typedef uint8_t MatchKey; | ||
ddelnano marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
constexpr MatchKey UnmatchedResp = 0xff; | ||
|
@@ -64,12 +65,10 @@ std::map<MatchKey, MatchKey> MapRequestToResponse = { | |
{0xa0, 0xb0}, | ||
// PINGREQ to PINGRESP | ||
{0xc0, 0xd0}, | ||
// AUTH to AUTH | ||
{0xf0, 0xf0}, | ||
// DISCONNECT to Dummy response | ||
{0xe0, UnmatchedResp}, | ||
// AUTH to Dummy response | ||
{0xf0, UnmatchedResp}}; | ||
|
||
std::set<std::tuple<uint32_t, uint32_t>> UnansweredPublish; | ||
{0xe0, UnmatchedResp}}; | ||
|
||
// Possible to have the server sending PUBLISH with same packet identifier as client PUBLISH before | ||
// it sends PUBACK, causing server PUBLISH to be put into response deque instead of request deque. | ||
|
@@ -82,7 +81,7 @@ MatchKey getMatchKey(mqtt::Message& frame) { | |
|
||
RecordsWithErrorCount<Record> StitchFrames( | ||
absl::flat_hash_map<packet_id_t, std::deque<Message>>* req_frames, | ||
absl::flat_hash_map<packet_id_t, std::deque<Message>>* resp_frames) { | ||
absl::flat_hash_map<packet_id_t, std::deque<Message>>* resp_frames, mqtt::StateWrapper* state) { | ||
std::vector<Record> entries; | ||
int error_count = 0; | ||
|
||
|
@@ -104,19 +103,24 @@ RecordsWithErrorCount<Record> StitchFrames( | |
// finding the closest appropriate response from response deque in terms of timestamp and type | ||
// for each request in the request deque | ||
for (mqtt::Message& req_frame : req_deque) { | ||
// if the request is a PUBLISH (QOS 1 or QOS 2) with dup false, entry needs to be made in | ||
// UnansweredPublish | ||
if (req_frame.control_packet_type == 3 && req_frame.header_fields["qos"] != 0 && | ||
!req_frame.dup) { | ||
UnansweredPublish.insert(std::tuple<uint32_t, uint32_t>( | ||
req_frame.header_fields["packet_identifier"], req_frame.header_fields["qos"])); | ||
} | ||
// if the request is a duplicate PUBLISH, find out if the original PUBLISH has been matched | ||
if (req_frame.control_packet_type == 3 && req_frame.header_fields["qos"] != 0 && | ||
req_frame.dup) { | ||
if (UnansweredPublish.find(std::tuple<uint32_t, uint32_t>( | ||
req_frame.header_fields["packet_identifier"], req_frame.header_fields["qos"])) == | ||
UnansweredPublish.end()) { | ||
const MqttControlPacketType control_packet_type = | ||
magic_enum::enum_cast<MqttControlPacketType>(req_frame.control_packet_type).value(); | ||
// If the frame is PUBLISH, and there are duplicates in the deque, then mark the frame as | ||
// consumed and match the latest duplicate with its response (if the response exists in the | ||
// response deque) | ||
if (control_packet_type == MqttControlPacketType::PUBLISH) { | ||
std::tuple<uint32_t, uint32_t> unique_publish_identifier = std::tuple<uint32_t, uint32_t>( | ||
req_frame.header_fields["packet_identifier"], req_frame.header_fields["qos"]); | ||
if (req_frame.type == message_type_t::kRequest && | ||
state->send[unique_publish_identifier] > 0) { | ||
state->send[unique_publish_identifier] -= 1; | ||
req_frame.consumed = true; | ||
continue; | ||
} | ||
|
||
if (req_frame.type == message_type_t::kResponse && | ||
state->recv[unique_publish_identifier] > 0) { | ||
state->recv[unique_publish_identifier] -= 1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Related to my earlier comment about avoiding excess inserts into |
||
req_frame.consumed = true; | ||
continue; | ||
} | ||
|
@@ -165,17 +169,6 @@ RecordsWithErrorCount<Record> StitchFrames( | |
} | ||
mqtt::Message& resp_frame = *response_frame_iter; | ||
|
||
// if the response is PUBACK/PUBREC, then remove the associated (packet_identifier, qos) tuple | ||
// from the UnansweredPublish set | ||
if (resp_frame.control_packet_type == 4) { | ||
UnansweredPublish.erase( | ||
std::tuple<uint64_t, uint64_t>(resp_frame.header_fields["packet_identifier"], 1)); | ||
} | ||
if (resp_frame.control_packet_type == 5) { | ||
UnansweredPublish.erase( | ||
std::tuple<uint64_t, uint64_t>(resp_frame.header_fields["packet_identifier"], 2)); | ||
} | ||
|
||
req_frame.consumed = true; | ||
resp_frame.consumed = true; | ||
entries.push_back({std::move(req_frame), std::move(resp_frame)}); | ||
|
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it necessary to store a key in the state for
PUBLISH
'es that don't have any dups?The
::operator[]
method will insert into the map if the key doesn't exist. So I believe the+=
operator will work as expected without the non dup branch.