### Install nwdiag via CLI Source: https://github.com/blockdiag/nwdiag/blob/master/README.rst Use easy_install or pip to install the nwdiag package. ```bash $ sudo easy_install nwdiag ``` ```bash $ sudo pip nwdiag ``` -------------------------------- ### Configure diagram setup options Source: https://context7.com/blockdiag/nwdiag/llms.txt Use these setup functions to define global output formats, antialiasing, and font paths for nwdiag, rackdiag, and packetdiag. ```python nwdiag_setup( format='PNG', antialias=True, fontpath='/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', outputdir='/tmp/diagrams', ) rackdiag_setup( format='SVG', antialias=False, ) packetdiag_setup( format='PNG', antialias=True, ) ``` -------------------------------- ### Programmatic Docutils Directive Setup Source: https://context7.com/blockdiag/nwdiag/llms.txt Sets up docutils directives programmatically for custom document processing pipelines, importing setup functions from each module. ```python from docutils.core import publish_doctree from nwdiag.utils.rst.directives import setup as nwdiag_setup from rackdiag.utils.rst.directives import setup as rackdiag_setup from packetdiag.utils.rst.directives import setup as packetdiag_setup ``` -------------------------------- ### Basic Network Definition Syntax Source: https://context7.com/blockdiag/nwdiag/llms.txt Example of defining networks and nodes with IP addresses. ```text nwdiag { network dmz { address = "210.x.x.x/24" web01 [address = "210.x.x.1"]; web02 [address = "210.x.x.2"]; } network internal { address = "172.x.x.x/24"; web01 [address = "172.x.x.1"]; web02 [address = "172.x.x.2"]; db01; db02; } } ``` -------------------------------- ### CLI Usage for rackdiag Source: https://context7.com/blockdiag/nwdiag/llms.txt Commands for generating server rack layout diagrams. ```bash # Basic usage rackdiag rack.diag # Output as SVG rackdiag -Tsvg rack.diag -o rack.svg # Generate rack diagram with custom dimensions rackdiag --size=400x800 rack.diag -o large_rack.png ``` -------------------------------- ### Configure Global Network Diagram Attributes Source: https://context7.com/blockdiag/nwdiag/llms.txt Set global defaults for fonts, colors, and layout behavior for the entire diagram. ```nwdiag nwdiag { // Global attributes default_fontsize = 14; default_node_color = lightblue; default_group_color = "#EEEEEE"; default_network_color = "#AADDFF"; default_text_color = "#333333"; // Disable external connector on top network external_connector = none; network internal { address = "10.0.0.0/8" server1; server2; } } ``` -------------------------------- ### Render Diagram to PNG Source: https://context7.com/blockdiag/nwdiag/llms.txt Draws and saves a network diagram to a PNG file. Requires nwdiag.drawer.DiagramDraw and antialias option for smoother rendering. ```python from nwdiag.drawer import DiagramDraw draw = DiagramDraw('PNG', diagram, filename='output.png', antialias=True) draw.draw() draw.save() ``` -------------------------------- ### Rack Diagram Syntax - Basic Rack Layout Source: https://context7.com/blockdiag/nwdiag/llms.txt Define server rack layouts specifying unit positions and equipment using numbered slots. Each item can span multiple rack units. ```APIDOC ## Rack Diagram Syntax - Basic Rack Layout ### Description Define server rack layouts specifying unit positions and equipment using numbered slots. Each item can span multiple rack units. ### Method N/A ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ```rackdiag rackdiag { // Set rack height 16U; // Equipment at specific positions with heights 1: UPS [4U]; 5: Network Switch; 6: Network Switch; 7: Patch Panel; 8: Server 1 [2U]; 10: Server 2 [2U]; 12: Storage Array [4U]; } ``` ``` -------------------------------- ### Build Rack Diagram from String Source: https://context7.com/blockdiag/nwdiag/llms.txt Parses a rack diagram definition from a string and builds the diagram object. Requires rackdiag.parser and rackdiag.builder.ScreenNodeBuilder. ```python from rackdiag import parser from rackdiag.builder import ScreenNodeBuilder rack_text = """ rackdiag { 16U; 1: UPS [4U]; 5: Switch; 6: Server 1 [2U]; 8: Server 2 [2U]; 10: Storage [4U]; } """ tree = parser.parse_string(rack_text) diagram = ScreenNodeBuilder.build(tree) ``` -------------------------------- ### Define network topology in simple.diag Source: https://github.com/blockdiag/nwdiag/blob/master/README.rst A sample specification file defining nodes and networks using dot-like syntax. ```text nwdiag { network dmz { address = "210.x.x.x/24" web01 [address = "210.x.x.1"]; web02 [address = "210.x.x.2"]; } network internal { address = "172.x.x.x/24"; web01 [address = "172.x.x.1"]; web02 [address = "172.x.x.2"]; db01; db02; } } ``` -------------------------------- ### Rack Diagram Syntax - Multiple Racks and Ascending Order Source: https://context7.com/blockdiag/nwdiag/llms.txt Define multiple rack cabinets and use ascending numbering (bottom-to-top) instead of the default descending order. ```APIDOC ## Rack Diagram Syntax - Multiple Racks and Ascending Order ### Description Define multiple rack cabinets and use ascending numbering (bottom-to-top) instead of the default descending order. ### Method N/A ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ```rackdiag rackdiag { // First rack - default descending (top-to-bottom) rack { description = "Rack A"; 16U; 1: Router; 2: Switch; 3: Server 1 [2U]; } // Second rack - ascending (bottom-to-top) rack { description = "Rack B"; 16U; ascending; 1: UPS [4U]; 5: Server 2 [2U]; 7: Server 3 [2U]; } } ``` ``` -------------------------------- ### Render Rack Diagram to PNG Source: https://context7.com/blockdiag/nwdiag/llms.txt Draws and saves a rack diagram to a PNG file. Requires rackdiag.drawer.DiagramDraw. ```python from rackdiag.drawer import DiagramDraw draw = DiagramDraw('PNG', diagram, filename='rack.png') draw.draw() draw.save() ``` -------------------------------- ### Rack Diagram Syntax - Auto-Numbering and Attributes Source: https://context7.com/blockdiag/nwdiag/llms.txt Use auto-numbering with `*` or `-` and add attributes like amperage and weight for detailed equipment specifications in rack diagrams. ```APIDOC ## Rack Diagram Syntax - Auto-Numbering and Attributes ### Description Use auto-numbering with `*` or `-` and add attributes like amperage and weight for detailed equipment specifications. ### Method N/A ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ```rackdiag rackdiag { 16U; description = "Primary Data Center Rack"; // Auto-numbered items using * or - 1: PDU [16U, 30A]; * UPS [4U, 20A, 50kg]; * Server [2U, 5A, 15kg]; * Server [2U, 5A, 15kg]; * Server [2U, 5A, 15kg]; * Storage [4U, 8A, 40kg]; // N/A renders as gray/empty space 15: N/A; } ``` ``` -------------------------------- ### Define Basic Rack Layout Source: https://context7.com/blockdiag/nwdiag/llms.txt Specify rack height and place equipment at specific unit positions. ```rackdiag rackdiag { // Set rack height 16U; // Equipment at specific positions with heights 1: UPS [4U]; 5: Network Switch; 6: Network Switch; 7: Patch Panel; 8: Server 1 [2U]; 10: Server 2 [2U]; 12: Storage Array [4U]; } ``` -------------------------------- ### Render Diagram to PDF Source: https://context7.com/blockdiag/nwdiag/llms.txt Draws and saves a network diagram to a PDF file. Requires nwdiag.drawer.DiagramDraw and the reportlab library. ```python from nwdiag.drawer import DiagramDraw draw = DiagramDraw('PDF', diagram, filename='output.pdf') draw.draw() draw.save() ``` -------------------------------- ### Peer-to-Peer Connection Syntax Source: https://context7.com/blockdiag/nwdiag/llms.txt Defining direct connections between nodes using the -- operator. ```text nwdiag { // Direct peer connection A -- B; // Node with custom shape A [shape = ellipse]; // Regular network segment network backbone { B; C; D; } // Multiple peer connections C -- E; D -- F; } ``` -------------------------------- ### Generate network diagram image Source: https://github.com/blockdiag/nwdiag/blob/master/README.rst Execute the nwdiag command to process the specification file and verify the output. ```bash $ nwdiag simple.diag $ ls simple.png simple.png ``` -------------------------------- ### Define Multiple Racks and Ordering Source: https://context7.com/blockdiag/nwdiag/llms.txt Create multiple rack cabinets and toggle between descending and ascending unit numbering. ```rackdiag rackdiag { // First rack - default descending (top-to-bottom) rack { description = "Rack A"; 16U; 1: Router; 2: Switch; 3: Server 1 [2U]; } // Second rack - ascending (bottom-to-top) rack { description = "Rack B"; 16U; ascending; 1: UPS [4U]; 5: Server 2 [2U]; 7: Server 3 [2U]; } } ``` -------------------------------- ### Multi-Homed Host Syntax Source: https://context7.com/blockdiag/nwdiag/llms.txt Defining nodes that connect to multiple network segments. ```text nwdiag { network frontend { address = "192.168.1.0/24" loadbalancer [address = "192.168.1.1"]; web01 [address = "192.168.1.10"]; web02 [address = "192.168.1.11"]; } network backend { address = "192.168.2.0/24" web01 [address = "192.168.2.10"]; web02 [address = "192.168.2.11"]; database [address = "192.168.2.100"]; } network storage { address = "10.0.0.0/24" database [address = "10.0.0.1"]; nas [address = "10.0.0.2"]; } } ``` -------------------------------- ### Parse Network Diagram from File Source: https://context7.com/blockdiag/nwdiag/llms.txt Parses a network diagram definition from a specified file. ```python tree = parser.parse_file("network.diag") ``` -------------------------------- ### Build Diagram from String Source: https://context7.com/blockdiag/nwdiag/llms.txt Parses a network diagram definition from a string and builds the diagram object. Requires nwdiag.parser and nwdiag.builder.ScreenNodeBuilder. ```python from nwdiag import parser from nwdiag.builder import ScreenNodeBuilder diagram_text = """ nwdiag { network frontend { web01; web02; } network backend { web01; web02; db01; } } """ tree = parser.parse_string(diagram_text) diagram = ScreenNodeBuilder.build(tree) ``` -------------------------------- ### Node Grouping Syntax Source: https://context7.com/blockdiag/nwdiag/llms.txt Organizing nodes into visual groups with custom colors. ```text nwdiag { network Sample_front { address = "192.168.10.0/24"; group web { color = "#FFCCCC"; web01 [address = ".1"]; web02 [address = ".2"]; } } network Sample_back { address = "192.168.20.0/24"; web01 [address = ".1"]; web02 [address = ".2"]; db01 [address = ".101"]; db02 [address = ".102"]; group db { color = "#CCCCFF"; db01; db02; } } } ``` -------------------------------- ### Rack Diagram Syntax - Multiple Items Per Level Source: https://context7.com/blockdiag/nwdiag/llms.txt Place multiple items side-by-side at the same rack unit level for representing items that share horizontal space. ```APIDOC ## Rack Diagram Syntax - Multiple Items Per Level ### Description Place multiple items side-by-side at the same rack unit level for representing items that share horizontal space. ### Method N/A ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ```rackdiag rackdiag { 12U; 1: UPS 1 [3U]; 1: UPS 2 [3U]; 4: Server 1; 4: Server 2 [2U]; 5: Server 3 [2U]; 6: Server 4 [2U]; 6: Server 5 [2U]; 6: Server 6 [2U]; 8: Server 7 [3U]; 9: Server 8; 9: Server 9; } ``` ``` -------------------------------- ### Render Diagram to SVG Source: https://context7.com/blockdiag/nwdiag/llms.txt Draws and saves a network diagram to an SVG file. Requires nwdiag.drawer.DiagramDraw. ```python from nwdiag.drawer import DiagramDraw draw = DiagramDraw('SVG', diagram, filename='output.svg') draw.draw() draw.save() ``` -------------------------------- ### Render Packet Diagram to PNG Source: https://context7.com/blockdiag/nwdiag/llms.txt Draws and saves a packet header diagram to a PNG file. Requires packetdiag.drawer.DiagramDraw. ```python from packetdiag.drawer import DiagramDraw draw = DiagramDraw('PNG', diagram, filename='tcp_header.png') draw.draw() draw.save() ``` -------------------------------- ### Configure Rack Auto-Numbering and Attributes Source: https://context7.com/blockdiag/nwdiag/llms.txt Use auto-numbering for equipment and include technical specifications like amperage and weight. ```rackdiag rackdiag { 16U; description = "Primary Data Center Rack"; // Auto-numbered items using * or - 1: PDU [16U, 30A]; * UPS [4U, 20A, 50kg]; * Server [2U, 5A, 15kg]; * Server [2U, 5A, 15kg]; * Server [2U, 5A, 15kg]; * Storage [4U, 8A, 40kg]; // N/A renders as gray/empty space 15: N/A; } ``` -------------------------------- ### Process RST content with embedded diagrams Source: https://context7.com/blockdiag/nwdiag/llms.txt Demonstrates how to parse RST content containing nwdiag directives into a doctree. ```python rst_content = """ Network Overview ================ .. nwdiag:: nwdiag { network { server1; server2; } } """ doctree = publish_doctree(rst_content) ``` -------------------------------- ### Build Packet Diagram from String Source: https://context7.com/blockdiag/nwdiag/llms.txt Parses a packet header diagram definition from a string and builds the diagram object. Requires packetdiag.parser and packetdiag.builder.ScreenNodeBuilder. ```python from packetdiag import parser from packetdiag.builder import ScreenNodeBuilder packet_text = """ packetdiag { colwidth = 32; 0-15: Source Port; 16-31: Destination Port; 32-63: Sequence Number; 64-95: Acknowledgment Number; } """ tree = parser.parse_string(packet_text) diagram = ScreenNodeBuilder.build(tree) ``` -------------------------------- ### CLI Usage for nwdiag Source: https://context7.com/blockdiag/nwdiag/llms.txt Commands for generating network diagrams from .diag files with various output formats and configurations. ```bash # Basic usage - generates PNG by default nwdiag network.diag # Output as SVG format nwdiag -Tsvg network.diag -o network.svg # Output as PDF format (requires reportlab) nwdiag -Tpdf network.diag -o network.pdf # Specify custom font nwdiag --font=/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf network.diag # Enable antialiasing for smoother output nwdiag -a network.diag # Read diagram from stdin cat network.diag | nwdiag -o output.png - # Show version nwdiag --version ``` -------------------------------- ### Using Diagram Directives in reStructuredText Source: https://context7.com/blockdiag/nwdiag/llms.txt Demonstrates how to embed nwdiag, rackdiag, and packetdiag diagrams directly within reStructuredText documents using their respective directives. ```rst .. In your .rst document Network Topology ================ .. nwdiag:: nwdiag { network dmz { web01; web02; } network internal { web01; web02; db01; } } Server Rack Layout ================== .. rackdiag:: rackdiag { 16U; 1: Switch; 2: Server [2U]; } TCP Header Format ================= .. packetdiag:: packetdiag { colwidth = 32; 0-15: Source Port; 16-31: Destination Port; } ``` -------------------------------- ### Network Diagram Syntax - Diagram Attributes Source: https://context7.com/blockdiag/nwdiag/llms.txt Set global diagram attributes for default styles, colors, and layout options in network diagrams. ```APIDOC ## Network Diagram Syntax - Diagram Attributes ### Description Set global diagram attributes for default styles, colors, and layout options. ### Method N/A ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ```nwdiag nwdiag { // Global attributes default_fontsize = 14; default_node_color = lightblue; default_group_color = "#EEEEEE"; default_network_color = "#AADDFF"; default_text_color = "#333333"; // Disable external connector on top network external_connector = none; network internal { address = "10.0.0.0/8" server1; server2; } } ``` ``` -------------------------------- ### Access Diagram Structure and Layout Source: https://context7.com/blockdiag/nwdiag/llms.txt Accesses the built diagram object to retrieve network and node information, as well as overall diagram dimensions. Assumes a 'diagram' object has been built. ```python print(f"Networks: {len(diagram.networks)}") for network in diagram.networks: print(f" {network.id}: {[n.id for n in network.nodes]}") print(f"Nodes: {len(diagram.nodes)}") for node in diagram.nodes: print(f" {node.id}: networks={[n.id for n in node.networks]}") print(f"Diagram size: {diagram.colwidth}x{diagram.colheight}") ``` -------------------------------- ### Sphinx Configuration for Diagram Directives Source: https://context7.com/blockdiag/nwdiag/llms.txt Configures Sphinx to use nwdiag, rackdiag, and packetdiag directives by adding them to the extensions list and setting relevant options in conf.py. ```python # In Sphinx conf.py extensions = [ 'sphinxcontrib.nwdiag', 'sphinxcontrib.rackdiag', 'sphinxcontrib.packetdiag', ] # Configure options nwdiag_fontpath = '/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf' nwdiag_html_image_format = 'SVG' nwdiag_antialias = True ``` -------------------------------- ### CLI Usage for packetdiag Source: https://context7.com/blockdiag/nwdiag/llms.txt Commands for generating packet or protocol header diagrams. ```bash # Basic usage packetdiag packet.diag # Output as SVG for web embedding packetdiag -Tsvg packet.diag -o packet.svg ``` -------------------------------- ### Access Rack Diagram Structure Source: https://context7.com/blockdiag/nwdiag/llms.txt Accesses the built rack diagram object to retrieve information about racks and the items within them. Assumes a 'diagram' object has been built. ```python for rack in diagram.racks: print(f"Rack height: {rack.colheight}U") for item in rack.nodes: print(f" Unit {item.number}: {item.label} [{item.colheight}U]") ``` -------------------------------- ### Parse Diagram Definitions with Python Source: https://context7.com/blockdiag/nwdiag/llms.txt Use the parser module to convert diagram text into a tree structure for programmatic access. ```python from nwdiag import parser # Parse diagram from string diagram_text = """ nwdiag { network dmz { address = "210.x.x.x/24" web01 [address = "210.x.x.1"]; web02 [address = "210.x.x.2"]; } } """ tree = parser.parse_string(diagram_text) print(f"Diagram ID: {tree.id}") print(f"Statements: {len(tree.stmts)}") ``` -------------------------------- ### Packet Diagram Syntax - Protocol Header Definition Source: https://context7.com/blockdiag/nwdiag/llms.txt Define packet/protocol headers showing bit-level field layouts. Fields are specified with bit ranges and labels. ```APIDOC ## Packet Diagram Syntax - Protocol Header Definition ### Description Define packet/protocol headers showing bit-level field layouts. Fields are specified with bit ranges and labels. ### Method N/A ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ```packetdiag packetdiag { colwidth = 32; node_height = 72; 0-15: Source Port; 16-31: Destination Port; 32-63: Sequence Number; 64-95: Acknowledgment Number; 96-99: Data Offset; 100-105: Reserved; 106: URG [rotate = 270]; 107: ACK [rotate = 270]; 108: PSH [rotate = 270]; 109: RST [rotate = 270]; 110: SYN [rotate = 270]; 111: FIN [rotate = 270]; 112-127: Window; 128-143: Checksum; 144-159: Urgent Pointer; 160-191: (Options and Padding); 192-223: data [colheight = 3]; } ``` ``` -------------------------------- ### Packet Diagram Syntax - Custom Field Attributes Source: https://context7.com/blockdiag/nwdiag/llms.txt Customize packet field appearance with colors, rotation, and height spanning for complex protocol visualizations. ```APIDOC ## Packet Diagram Syntax - Custom Field Attributes ### Description Customize packet field appearance with colors, rotation, and height spanning for complex protocol visualizations. ### Method N/A ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ```packetdiag packetdiag { colwidth = 16; // Field spanning multiple bits 0-7: Version [color = lightblue]; 8-15: Header Length [color = lightgreen]; // Single-bit flags with rotation 16: Reserved [rotate = 270]; 17: DF [rotate = 270, color = pink]; 18: MF [rotate = 270, color = pink]; 19-31: Fragment Offset; // Multi-row field 32-63: Source Address [colheight = 2, color = lightyellow]; 64-95: Destination Address [colheight = 2, color = lightyellow]; } ``` ``` -------------------------------- ### Network Diagram Syntax - Node Attributes Source: https://context7.com/blockdiag/nwdiag/llms.txt Customize node appearance in network diagrams using attributes like color, shape, label, and style. ```APIDOC ## Network Diagram Syntax - Node Attributes ### Description Customize node appearance with various attributes including color, shape, label, icon, and style options. ### Method N/A ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ```nwdiag nwdiag { network lan { address = "192.168.0.0/24" // Custom colors server1 [address = "192.168.0.1", color = "pink"]; server2 [address = "192.168.0.2", color = "#FF8888"]; // Custom shape router [address = "192.168.0.254", shape = box]; // Custom label different from node id fw [address = "192.168.0.253", label = "Firewall"]; // Style options backup [address = "192.168.0.100", style = dashed]; } } ``` ``` -------------------------------- ### Python API - Parser Module Source: https://context7.com/blockdiag/nwdiag/llms.txt The parser module converts diagram text into a parse tree structure. Use `parse_string()` for text input or `parse_file()` for file paths. ```APIDOC ## Python API - Parser Module ### Description The parser module converts diagram text into a parse tree structure. Use `parse_string()` for text input or `parse_file()` for file paths. ### Method N/A ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```python from nwdiag import parser # Parse diagram from string diagram_text = """ nwdiag { network dmz { address = "210.x.x.x/24" web01 [address = "210.x.x.1"]; web02 [address = "210.x.x.2"]; } } """ tree = parser.parse_string(diagram_text) print(f"Diagram ID: {tree.id}") print(f"Statements: {len(tree.stmts)}") ``` ### Response #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### Place Multiple Items Per Rack Level Source: https://context7.com/blockdiag/nwdiag/llms.txt Represent items sharing horizontal space by placing them at the same rack unit level. ```rackdiag rackdiag { 12U; 1: UPS 1 [3U]; 1: UPS 2 [3U]; 4: Server 1; 4: Server 2 [2U]; 5: Server 3 [2U]; 6: Server 4 [2U]; 6: Server 5 [2U]; 6: Server 6 [2U]; 8: Server 7 [3U]; 9: Server 8; 9: Server 9; } ``` -------------------------------- ### Define Packet Protocol Headers Source: https://context7.com/blockdiag/nwdiag/llms.txt Map bit-level field layouts for protocol headers using bit ranges and labels. ```packetdiag packetdiag { colwidth = 32; node_height = 72; 0-15: Source Port; 16-31: Destination Port; 32-63: Sequence Number; 64-95: Acknowledgment Number; 96-99: Data Offset; 100-105: Reserved; 106: URG [rotate = 270]; 107: ACK [rotate = 270]; 108: PSH [rotate = 270]; 109: RST [rotate = 270]; 110: SYN [rotate = 270]; 111: FIN [rotate = 270]; 112-127: Window; 128-143: Checksum; 144-159: Urgent Pointer; 160-191: (Options and Padding); 192-223: data [colheight = 3]; } ``` -------------------------------- ### Access Packet Diagram Field Information Source: https://context7.com/blockdiag/nwdiag/llms.txt Accesses the built packet diagram object to retrieve information about each field, including its bit range and label. Assumes a 'diagram' object has been built. ```python for field in diagram.fields: print(f"Bits {field.number}-{field.number + field.colwidth - 1}: {field.label}") ``` -------------------------------- ### Access Parsed Network Elements Source: https://context7.com/blockdiag/nwdiag/llms.txt Iterate through parsed statements to access network and node information. Requires a parsed tree object. ```python for stmt in tree.stmts: if isinstance(stmt, parser.Network): print(f"Network: {stmt.id}") for node_stmt in stmt.stmts: if isinstance(node_stmt, parser.Node): print(f" Node: {node_stmt.id}, Attrs: {node_stmt.attrs}") ``` -------------------------------- ### Apply Custom Packet Field Attributes Source: https://context7.com/blockdiag/nwdiag/llms.txt Enhance packet visualizations with field-specific colors, rotation, and multi-row spanning. ```packetdiag packetdiag { colwidth = 16; // Field spanning multiple bits 0-7: Version [color = lightblue]; 8-15: Header Length [color = lightgreen]; // Single-bit flags with rotation 16: Reserved [rotate = 270]; 17: DF [rotate = 270, color = pink]; 18: MF [rotate = 270, color = pink]; 19-31: Fragment Offset; // Multi-row field 32-63: Source Address [colheight = 2, color = lightyellow]; 64-95: Destination Address [colheight = 2, color = lightyellow]; } ``` -------------------------------- ### Define Network Diagram Node Attributes Source: https://context7.com/blockdiag/nwdiag/llms.txt Customize individual node appearance using attributes like color, shape, label, and style within a network definition. ```nwdiag nwdiag { network lan { address = "192.168.0.0/24" // Custom colors server1 [address = "192.168.0.1", color = "pink"]; server2 [address = "192.168.0.2", color = "#FF8888"]; // Custom shape router [address = "192.168.0.254", shape = box]; // Custom label different from node id fw [address = "192.168.0.253", label = "Firewall"]; // Style options backup [address = "192.168.0.100", style = dashed]; } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.