| 1 | > **Warning** |
| 2 | > |
| 3 | > ## THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. |
| 4 | > |
| 5 | > ## Please edit the corresponding file in [/packages/mermaid/src/docs/syntax/packet.md](../../packages/mermaid/src/docs/syntax/packet.md). |
| 6 | |
| 7 | # Packet Diagram (v11.0.0+) |
| 8 | |
| 9 | ## Introduction |
| 10 | |
| 11 | A packet diagram is a visual representation used to illustrate the structure and contents of a network packet. Network packets are the fundamental units of data transferred over a network. |
| 12 | |
| 13 | ## Usage |
| 14 | |
| 15 | This diagram type is particularly useful for developers, network engineers, educators, and students who require a clear and concise way to represent the structure of network packets. |
| 16 | |
| 17 | ## Syntax |
| 18 | |
| 19 | ``` |
| 20 | packet |
| 21 | start: "Block name" %% Single-bit block |
| 22 | start-end: "Block name" %% Multi-bit blocks |
| 23 | ... More Fields ... |
| 24 | ``` |
| 25 | |
| 26 | ### Bits Syntax (v11.7.0+) |
| 27 | |
| 28 | Using start and end bit counts can be difficult, especially when modifying a design. For this we add a bit count field, which starts from the end of the previous field automagically. Use `+<count>` to set the number of bits, thus: |
| 29 | |
| 30 | ``` |
| 31 | packet |
| 32 | +1: "Block name" %% Single-bit block |
| 33 | +8: "Block name" %% 8-bit block |
| 34 | 9-15: "Manually set start and end, it's fine to mix and match" |
| 35 | ... More Fields ... |
| 36 | ``` |
| 37 | |
| 38 | ## Examples |
| 39 | |
| 40 | ```mermaid-example |
| 41 | --- |
| 42 | title: "TCP Packet" |
| 43 | --- |
| 44 | packet |
| 45 | 0-15: "Source Port" |
| 46 | 16-31: "Destination Port" |
| 47 | 32-63: "Sequence Number" |
| 48 | 64-95: "Acknowledgment Number" |
| 49 | 96-99: "Data Offset" |
| 50 | 100-105: "Reserved" |
| 51 | 106: "URG" |
| 52 | 107: "ACK" |
| 53 | 108: "PSH" |
| 54 | 109: "RST" |
| 55 | 110: "SYN" |
| 56 | 111: "FIN" |
| 57 | 112-127: "Window" |
| 58 | 128-143: "Checksum" |
| 59 | 144-159: "Urgent Pointer" |
| 60 | 160-191: "(Options and Padding)" |
| 61 | 192-255: "Data (variable length)" |
| 62 | ``` |
| 63 | |
| 64 | ```mermaid |
| 65 | --- |
| 66 | title: "TCP Packet" |
| 67 | --- |
| 68 | packet |
| 69 | 0-15: "Source Port" |
| 70 | 16-31: "Destination Port" |
| 71 | 32-63: "Sequence Number" |
| 72 | 64-95: "Acknowledgment Number" |
| 73 | 96-99: "Data Offset" |
| 74 | 100-105: "Reserved" |
| 75 | 106: "URG" |
| 76 | 107: "ACK" |
| 77 | 108: "PSH" |
| 78 | 109: "RST" |
| 79 | 110: "SYN" |
| 80 | 111: "FIN" |
| 81 | 112-127: "Window" |
| 82 | 128-143: "Checksum" |
| 83 | 144-159: "Urgent Pointer" |
| 84 | 160-191: "(Options and Padding)" |
| 85 | 192-255: "Data (variable length)" |
| 86 | ``` |
| 87 | |
| 88 | ```mermaid-example |
| 89 | packet |
| 90 | title UDP Packet |
| 91 | +16: "Source Port" |
| 92 | +16: "Destination Port" |
| 93 | 32-47: "Length" |
| 94 | 48-63: "Checksum" |
| 95 | 64-95: "Data (variable length)" |
| 96 | ``` |
| 97 | |
| 98 | ```mermaid |
| 99 | packet |
| 100 | title UDP Packet |
| 101 | +16: "Source Port" |
| 102 | +16: "Destination Port" |
| 103 | 32-47: "Length" |
| 104 | 48-63: "Checksum" |
| 105 | 64-95: "Data (variable length)" |
| 106 | ``` |
| 107 | |
| 108 | ## Details of Syntax |
| 109 | |
| 110 | - **Ranges**: Each line after the title represents a different field in the packet. The range (e.g., `0-15`) indicates the bit positions in the packet. |
| 111 | - **Field Description**: A brief description of what the field represents, enclosed in quotes. |
| 112 | |
| 113 | ## Configuration |
| 114 | |
| 115 | Please refer to the [configuration](/config/schema-docs/config-defs-packet-diagram-config.html) guide for details. |
| 116 | |
| 117 | <!-- |
| 118 | |
| 119 | Theme variables are not currently working due to a mermaid bug. The passed values are not being propagated into styles function. |
| 120 | |
| 121 | ## Theme Variables |
| 122 | |
| 123 | | Property | Description | Default Value | |
| 124 | | ---------------- | -------------------------- | ------------- | |
| 125 | | byteFontSize | Font size of the bytes | '10px' | |
| 126 | | startByteColor | Color of the starting byte | 'black' | |
| 127 | | endByteColor | Color of the ending byte | 'black' | |
| 128 | | labelColor | Color of the labels | 'black' | |
| 129 | | labelFontSize | Font size of the labels | '12px' | |
| 130 | | titleColor | Color of the title | 'black' | |
| 131 | | titleFontSize | Font size of the title | '14px' | |
| 132 | | blockStrokeColor | Color of the block stroke | 'black' | |
| 133 | | blockStrokeWidth | Width of the block stroke | '1' | |
| 134 | | blockFillColor | Fill color of the block | '#efefef' | |
| 135 | |
| 136 | ## Example on config and theme |
| 137 | |
| 138 | ```mermaid-example |
| 139 | --- |
| 140 | config: |
| 141 | packet: |
| 142 | showBits: true |
| 143 | themeVariables: |
| 144 | packet: |
| 145 | startByteColor: red |
| 146 | --- |
| 147 | packet |
| 148 | 0-15: "Source Port" |
| 149 | 16-31: "Destination Port" |
| 150 | 32-63: "Sequence Number" |
| 151 | ``` |
| 152 | |
| 153 | --> |
| 154 | |