]>
The Tcpdump Group git mirrors - tcpdump/blob - print-arista.c
1 // Copyright (c) 2018 Arista Networks, Inc. All rights reserved.
3 /* \summary: EtherType protocol for Arista Networks printer */
7 #include "netdissect-stdinc.h"
9 #include "netdissect.h"
16 The Arista timestamp header consists of the following fields:
17 1. The Arista ethertype (0xd28b)
18 2. A 2-byte subtype field; 0x01 indicates the timestamp header
19 3. A 2-byte version field, described below.
20 4. A 48-bit or 64-bit timestamp field, depending on the contents of the version field
22 This header is then followed by the original ethertype and the remainder of the original packet.
25 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
26 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
28 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
30 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +
32 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
33 | ethertype 0xd28b | subtype 0x1 |
34 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
36 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +
38 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
40 The two-byte version value is split into 3 fields:
41 1. The timescale in use. Currently assigned values include:
44 2. The timestamp format and length. Currently assigned values include:
52 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
53 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
54 | timescale | format|hw info|
55 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
58 See also: https://www.arista.com/assets/data/pdf/Whitepapers/Overview_Arista_Timestamps.pdf
62 #define ARISTA_SUBTYPE_TIMESTAMP 0x0001
63 static const struct tok subtype_str
[] = {
64 { ARISTA_SUBTYPE_TIMESTAMP
, "Timestamp" },
68 static const struct tok ts_timescale_str
[] = {
74 #define FORMAT_64BIT 0x1
75 #define FORMAT_48BIT 0x2
76 static const struct tok ts_format_str
[] = {
77 { FORMAT_64BIT
, "64-bit" },
78 { FORMAT_48BIT
, "48-bit" },
82 static const struct tok hw_info_str
[] = {
88 #define MAX_VALID_NS 999999999U
89 #define BOGUS_NS_STR "(bogus ns!)"
92 arista_print_date_hms_time(netdissect_options
*ndo
, const uint32_t seconds
,
93 const uint32_t nanoseconds
)
95 const time_t ts
= seconds
;
96 char buf
[sizeof("-yyyyyyyyyy-mm-dd hh:mm:ss")];
99 nd_format_time(buf
, sizeof(buf
), "%Y-%m-%d %H:%M:%S",
100 gmtime(&ts
)), nanoseconds
);
101 if (nanoseconds
> MAX_VALID_NS
)
102 ND_PRINT(" " BOGUS_NS_STR
);
106 arista_ethertype_print(netdissect_options
*ndo
, const u_char
*bp
, u_int len _U_
)
109 u_short bytesConsumed
= 0;
111 ndo
->ndo_protocol
= "arista";
113 subTypeId
= GET_BE_U_2(bp
);
117 ND_PRINT("SubType %s (0x%04x), ",
118 tok2str(subtype_str
, "Unknown", subTypeId
),
121 // TapAgg Header Timestamping
122 if (subTypeId
== ARISTA_SUBTYPE_TIMESTAMP
) {
124 uint32_t nanoseconds
;
125 uint8_t ts_timescale
= GET_U_1(bp
);
128 ND_PRINT("Timescale %s (%u), ",
129 tok2str(ts_timescale_str
, "Unknown", ts_timescale
),
132 uint8_t ts_format
= GET_U_1(bp
) >> 4;
133 uint8_t hw_info
= GET_U_1(bp
) & 0x0f;
137 // Timestamp has 32-bit lsb in nanosec and remaining msb in sec
138 ND_PRINT("Format %s (%u), HwInfo %s (%u), Timestamp ",
139 tok2str(ts_format_str
, "Unknown", ts_format
),
141 tok2str(hw_info_str
, "Unknown", hw_info
),
145 seconds
= GET_BE_U_4(bp
);
146 nanoseconds
= GET_BE_U_4(bp
+ 4);
147 arista_print_date_hms_time(ndo
, seconds
, nanoseconds
);
151 seconds
= GET_BE_U_2(bp
);
152 nanoseconds
= GET_BE_U_4(bp
+ 2);
153 ND_PRINT("%u.%09u", seconds
, nanoseconds
);
154 if (nanoseconds
> MAX_VALID_NS
)
155 ND_PRINT(" " BOGUS_NS_STR
);
165 return bytesConsumed
;