Skip to content
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

Fix and improve D scripts for new message formats #171

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ default-members = [
"decode",
"messages",
]

resolver = "2"
21 changes: 10 additions & 11 deletions dtrace/trace-messages.d
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@

xcvr-ctl$target:::message-sent
{
peer = json(copyinstr(arg0), "ok");
msg = json(copyinstr(arg1), "ok");
vers = json(msg, "version");
body = json(msg, "body");
peer = json(copyinstr(arg0), "ok");
header = json(copyinstr(arg1), "ok");
msg = json(copyinstr(arg2), "ok");
printf("Sent message to %s\n", peer);
printf(" version: %s\n", vers);
printf(" body: %s\n", body);
printf(" header: %s\n", header);
printf(" msg: %s\n", msg);
}

xcvr-ctl$target:::message-received
{
peer = json(copyinstr(arg0), "ok");
msg = json(copyinstr(arg1), "ok");
vers = json(msg, "version");
peer = json(copyinstr(arg0), "ok");
header = json(copyinstr(arg1), "ok");
msg = json(copyinstr(arg2), "ok");
body = json(msg, "body");
printf("Recv message from %s\n", peer);
printf(" version: %s\n", vers);
printf(" body: %s\n", body);
printf(" header: %s\n", header);
printf(" msg: %s\n", msg);
}
197 changes: 134 additions & 63 deletions dtrace/trace-packets.d
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/sbin/dtrace -CZqs

#pragma D option bufsize=16k

/*
* Constants used to pick out parts of SP responses.
*
Expand All @@ -13,90 +15,159 @@
* - 1 u64 for the message ID
* - 1 u8 for the message kind variant ID
*
* For 10 bytes total.
* For 10 octets total.
*
* Message has:
*
* - 1 u8 for the version
* - 1 u8 for the MessageBody variant ID
*
* For 2 bytes total
* For 2 octets total
*
* For an SpResponse::Status:
* For the MessageBody::SpResponse, which we support printing on receipt, the
* contents are:
*
* - 1 u8 for the variant ID
* - 1 u8 for the variant ID (e.g., SpResponse::Read)
* - 2 u64s for the successful and failed module IDs.
*
* For 17 bytes total.
*
* So the data should start at:
*
* 10 + 2 + 17 = 29 octets into the message.
* For 17 octets total.
*/
#define HEADER_VERSION_OFFSET 0
#define HEADER_VERSION_OFFSET (0)
#define HEADER_MESSAGE_ID_OFFSET (1)
#define HEADER_MESSAGE_KIND_OFFSET (9)
#define HEADER_MESSAGE_KIND_OFFSET (HEADER_MESSAGE_ID_OFFSET + 8)
#define MESSAGE_VERSION_OFFSET (HEADER_MESSAGE_KIND_OFFSET + 1)
#define MESSAGE_BODY_VARIANT_OFFSET (MESSAGE_VERSION_OFFSET + 1)
#define SP_RESPONSE_VARIANT_OFFSET (MESSAGE_BODY_VARIANT_OFFSET + 1)
#define MODULE_ID_OFFSET (SP_RESPONSE_VARIANT_OFFSET + 1)
#define STATUS_DATA_OFFSET (MODULE_ID_OFFSET + 16)
#define SUCCESS_MODULE_ID_OFFSET (SP_RESPONSE_VARIANT_OFFSET + 1)
#define FAILED_MODULE_ID_OFFSET (SUCCESS_MODULE_ID_OFFSET + 8)

/*
* Definitions of the `MessageKind` enum
*/
#define MESSAGE_KIND_ERROR (0)
#define MESSAGE_KIND_HOST_REQUEST (1)
#define MESSAGE_KIND_SP_RESPONSE (2)

#define MESSAGE_KIND_SP_RESPONSE 2
#define SP_RESPONSE_STATUS 2
#define SP_RESPONSE_EXTENDED_STATUS 6
#define SP_RESPONSE_ACK 3
/*
* Definitions of the `SpResponse` enum discriminant.
*/
#define SP_RESPONSE_READ (0)
#define SP_RESPONSE_WRITE (1)
#define SP_RESPONSE_STATUS (2)
#define SP_RESPONSE_ACK (3)
#define SP_RESPONSE_EXTENDED_STATUS (6)

xcvr-ctl$target:::packet-sent
{
peer = json(copyinstr(arg0), "ok");
n_bytes = arg1;
buf = (char*)copyin(arg2, n_bytes);
vers = *(uint8_t*) buf;
message_id = *(uint64_t*) (buf + HEADER_MESSAGE_ID_OFFSET);
message_kind = *(uint8_t*) (buf + HEADER_MESSAGE_KIND_OFFSET);

printf("Sent payload to %s\n", peer);
printf(" n_bytes: %d\n", n_bytes);
printf(" version: %d\n", vers);
printf(" msg id: %d\n", message_id);
printf(" msg kind: %d\n", message_kind);
this->peer = json(copyinstr(arg0), "ok");
this->n_bytes = arg1;
this->buf = (char*)copyin(arg2, this->n_bytes);
this->vers = *(uint8_t*) this->buf;
this->message_id = *(uint64_t*) (this->buf + HEADER_MESSAGE_ID_OFFSET);
this->message_kind = *(uint8_t*) (this->buf + HEADER_MESSAGE_KIND_OFFSET);

printf("Sent payload to %s\n", this->peer);
printf(" n_bytes: %d\n", this->n_bytes);
printf(" version: %d\n", this->vers);
printf(" msg id: %d\n", this->message_id);

this->message_kind_str = "Unknown";
if (this->message_kind == MESSAGE_KIND_ERROR) {
this->message_kind_str = "Error";
} else if (this->message_kind == MESSAGE_KIND_HOST_REQUEST) {
this->message_kind_str = "HostRequest";
} else if (this->message_kind == MESSAGE_KIND_SP_RESPONSE) {
this->message_kind_str = "SpResponse";
}
printf(" msg kind: %s (%d)\n", this->message_kind_str, this->message_kind);
}

/* "First" action on receiving a packet. Copy in the main metadata. */
xcvr-ctl$target:::packet-received
{
this->peer = json(copyinstr(arg0), "ok");
this->n_bytes = arg1;

/* Pointer to the packet payload itself. */
this->buf = (char*) copyin(arg2, this->n_bytes);
this->vers = this->buf[0];
this->message_id = *(uint64_t*) (this->buf + HEADER_MESSAGE_ID_OFFSET);
this->message_kind = this->buf[HEADER_MESSAGE_KIND_OFFSET];
printf("Recv payload from: %s\n", this->peer);
printf(" Raw packet:\n");
tracemem(this->buf, 128, this->n_bytes);
printf(" n_bytes: %d\n", this->n_bytes);
printf(" version: %d\n", this->vers);
printf(" msg id: %d\n", this->message_id);
}

/* Print the MessageKinds */
xcvr-ctl$target:::packet-received
/this->message_kind == MESSAGE_KIND_ERROR/
{
printf(" msg kind: Error (%d)\n", this->message_kind);
}

xcvr-ctl$target:::packet-received
/this->message_kind == MESSAGE_KIND_HOST_REQUEST/
{
printf(" msg kind: HostRequest (%d)\n", this->message_kind);
}

xcvr-ctl$target:::packet-received
/this->message_kind == MESSAGE_KIND_SP_RESPONSE/
{
printf(" msg kind: SpResponse (%d)\n", this->message_kind);
this->message_body_variant = this->buf[MESSAGE_BODY_VARIANT_OFFSET];
}

/* Print the SP response kind, note these are printed in order. */
xcvr-ctl$target:::packet-received
/this->message_kind == MESSAGE_KIND_SP_RESPONSE &&
this->message_body_variant == SP_RESPONSE_STATUS/
{
printf("MessageBody: Status (%d)\n", this->message_body_variant);
}

xcvr-ctl$target:::packet-received
/this->message_kind == MESSAGE_KIND_SP_RESPONSE &&
this->message_body_variant == SP_RESPONSE_READ/
{
printf("MessageBody: Read (%d)\n", this->message_body_variant);
}

xcvr-ctl$target:::packet-received
/this->message_kind == MESSAGE_KIND_SP_RESPONSE &&
this->message_body_variant == SP_RESPONSE_WRITE/
{
printf("MessageBody: Write (%d)\n", this->message_body_variant);
}

xcvr-ctl$target:::packet-received
/this->message_kind == MESSAGE_KIND_SP_RESPONSE &&
this->message_body_variant == SP_RESPONSE_ACK/
{
printf("MessageBody: Ack (%d)\n", this->message_body_variant);
}

xcvr-ctl$target:::packet-received
/this->message_kind == MESSAGE_KIND_SP_RESPONSE &&
this->message_body_variant == SP_RESPONSE_EXTENDED_STATUS/
{
printf("MessageBody: ExtendedStatus (%d)\n", this->message_body_variant);
}

/* Then print the module IDs and remaining data. */
xcvr-ctl$target:::packet-received
/this->message_kind == MESSAGE_KIND_SP_RESPONSE/
{
peer = json(copyinstr(arg0), "ok");
n_bytes = arg1;

/* Pointer to the packet payload itself. */
buf = (char*) copyin(arg2, n_bytes);

vers = buf[0];
message_id = *(uint64_t*) (buf + HEADER_MESSAGE_ID_OFFSET);
message_kind = buf[HEADER_MESSAGE_KIND_OFFSET];

printf("Recv payload from: %s\n", peer);
printf(" n_bytes: %d\n", n_bytes);
printf(" version: %d\n", vers);
printf(" msg id: %d\n", message_id);
printf(" msg kind: %d\n", message_kind);

/* Print SpResponse data, for certain kinds of messages */
if (message_kind == MESSAGE_KIND_SP_RESPONSE) {
message_body_variant = buf[MESSAGE_BODY_VARIANT_OFFSET];
if (message_body_variant == MESSAGE_KIND_SP_RESPONSE) {
sp_response_variant = buf[SP_RESPONSE_VARIANT_OFFSET];
if ((sp_response_variant == SP_RESPONSE_STATUS) ||
(sp_response_variant == SP_RESPONSE_EXTENDED_STATUS) ||
(sp_response_variant == SP_RESPONSE_ACK))
{
printf(" module IDs:\n");
tracemem(buf + MODULE_ID_OFFSET, 16);
n_octets = n_bytes - STATUS_DATA_OFFSET;
data = (buf + STATUS_DATA_OFFSET);
printf(" data (up to %d octets): ", n_octets);
tracemem(data, 128, n_octets);
}
}
}
this->success_modules = *(uint64_t*)(this->buf + SUCCESS_MODULE_ID_OFFSET);
this->failed_modules = *(uint64_t*)(this->buf + FAILED_MODULE_ID_OFFSET);
printf(" successful module IDs: 0x%08x\n", this->success_modules);
printf(" failed module IDs: 0x%08x\n", this->failed_modules);
this->n_octets = this->n_bytes - FAILED_MODULE_ID_OFFSET;
this->data = (this->buf + FAILED_MODULE_ID_OFFSET);
printf(" remaining data (up to %d octets):\n", this->n_octets);
tracemem(this->data, 128, this->n_octets);
printf("\n");
}