Skip to content

1.2.2 JNPL BNF Grammar

Mark Bednarczyk edited this page Nov 14, 2024 · 1 revision

Certainly! Refining the JNet Packet Language (JNPL) by defining explicit data types and adjusting the syntax for protocol definitions will significantly enhance the language's clarity, maintainability, and scalability. Below, I provide a comprehensive update incorporating your requirements:

  1. Defining Data Types for JNPL
  2. Updated Protocol Definition Syntax
  3. Formalizing the Updated Grammar in JNPL
  4. Comprehensive JNPL Script Example with Enhanced Syntax
  5. Additional Syntax Examples and Use Cases
  6. Best Practices for JNPL Script Design
  7. Developing Tooling Support
  8. Engaging with the Community
  9. Testing and Validation
  10. Final Recommendations

1. Defining Data Types for JNPL

Establishing clear data types is crucial for maintaining consistency and ensuring that scripts are both readable and less error-prone. Below are the data types tailored for JNPL:

a. Byte Stream

  • Description: Represents an array of bytes.
  • Syntax: reference[offset:length]
  • Defaults: If offset is omitted, it defaults to 0. If length is omitted, it defaults to the remaining bytes from offset.
  • Examples:
    • Packet[0:10] - Bytes 0 to 9 of Packet.
    • Packet[:10] - Bytes 0 to 9 of Packet (offset defaults to 0).
    • Packet[10:] - Bytes 10 to the end of Packet (length defaults to remaining bytes).

b. Offset

  • Description: Specifies the byte or bit offset within a byte stream.
  • Type: Integer
  • Usage: Used to indicate the starting position for data extraction or manipulation.
  • Example:
    • Offset: Packet.L3Offset >> 2

c. Length

  • Description: Specifies the number of bytes or bits to process.
  • Type: Integer
  • Usage: Indicates the size of the data segment to extract or manipulate.
  • Example:
    • Length: Packet.L3Len >> 2

d. Range

  • Description: Combines offset and length to define a specific segment within a byte stream.
  • Syntax: offset:length
  • Type: Derived from Offset and Length
  • Usage: Used for defining segments like Payload.
  • Example:
    • Payload: 12:64 - Starts at byte 12 and spans 64 bytes.

e. Set

  • Description: Represents a collection of discrete values.
  • Syntax: A,B,C,...
  • Type: Enumeration
  • Usage: Used for conditions and selections.
  • Example:
    • Layer3.Type in [IPv4, IPv6]

2. Updated Protocol Definition Syntax

To enhance readability and maintainability, the conditional logic is moved inside the protocol blocks. Additionally, adopting dot notation (.) for field access improves clarity, reserving bracket notation ([]) for arrays and expressions.

a. Syntax Adjustments

  • Implicit Type Definitions: Use : instead of = to define implicit types without using the define statement.

    • Before: Offset = Packet.L3Offset >> 2
    • After: Offset: Packet.L3Offset >> 2
  • Dot Notation for Field Access: Access fields using . instead of [], except when accessing array elements or performing logical evaluations.

    • Example: MPLS.TopLabel == 100

b. Updated Protocol Block Example

Here is the updated IP protocol block serving as a template for other protocol blocks:

define IP protocol {
    Offset: Packet.L3Offset >> 2
    Length: Packet.L3Len >> 2
    Payload: Packet.length - (Offset + Length)

    fields: { Src, Dst, TTL, Protocol }

    // Define IPv4 Sub-Protocol
    define IPv4 protocol {
        condition: Packet.L3Type == IPv4
        fields: { Src = 12:4, Dst = 16:4, Flags = 6, TTL = 8, Protocol = 9 }
    }

    // Define IPv6 Sub-Protocol
    define IPv6 protocol {
        condition: Packet.L3Type == IPv6
        fields: { Src = 7:16, Dst = 23:6, FlowLabel = 1, TTL = 6, Protocol = 5 }
    }
}

Key Points:

  • Implicit Definitions: Offset, Length, and Payload are implicitly defined with their respective types.
  • Dot Notation: Fields like Packet.L3Type are accessed using dot notation.
  • Range Type for Payload: Payload is defined using the range type, calculated based on Offset and Length.
  • Curly Braces {} for Field Definitions: Enhances readability by clearly grouping field assignments.

3. Formalizing the Updated Grammar in JNPL

To accommodate the new data types and syntax adjustments, the grammar needs to be updated. Below is the Extended Backus-Naur Form (EBNF) representation reflecting these changes:

<JNPL> ::= <Statement>+

<Statement> ::= <DefineProtocolBlock>
              | <DefineHashMode>
              | <DefineConstant>
              | <DefineFilter>
              | <DefineAction>
              | <OtherStatements>

<DefineProtocolBlock> ::= 'protocol' '{' <ProtocolBlock>+ '}'

<ProtocolBlock> ::= 'define' <Identifier> 'protocol' '{' <ProtocolOptions> <SubProtocol>+ '}'

<SubProtocol> ::= 'define' <Identifier> 'protocol' '{' <SubProtocolOptions> '}'

<ProtocolOptions> ::= <ProtocolOption>+

<ProtocolOption> ::= 'Offset:' <Expression>
                  | 'Length:' <Expression>
                  | 'Payload:' <Expression>
                  | 'fields:' '{' <FieldList> '}'

<SubProtocolOptions> ::= <SubProtocolOption>+

<SubProtocolOption> ::= 'condition:' <Condition>
                        | 'fields:' '{' <FieldAssignments> '}'

<FieldList> ::= <FieldName> { ',' <FieldName> }

<FieldAssignments> ::= <FieldAssignment> { ',' <FieldAssignment> }

<FieldAssignment> ::= <FieldName> '=' <OffsetLength>

<Condition> ::= <Expression>

<DefineHashMode> ::= 'define' <Identifier> 'HashMode' '{' <HashModeOption>+ '}'

<HashModeOption> ::= 'Priority' '=' <Integer>
                   | 'Encapsulation' '=' <EncapsulationList>
                   | 'Layer3Type' '=' <Layer3TypeList>
                   | 'Layer4Type' '=' <Layer4TypeList>
                   | 'InnerLayer3Type' '=' <InnerLayer3TypeList>
                   | 'InnerLayer4Type' '=' <InnerLayer4TypeList>
                   | 'TupleSwap' '=' <TrueFalse>
                   | 'MaskNo' '=' <Integer>
                   | 'Port' '=' <PortNumberSpec>
                   | 'Algorithm' '=' <HashAlgorithm>
                   | 'Key' '=' <HexString>
                   | 'Tag' '=' <Identifier>

<EncapsulationList> ::= <EncapsulationValue> { ',' <EncapsulationValue> }
<EncapsulationValue> ::= 'VLAN' | 'MPLS'

<Layer3TypeList> ::= <Layer3TypeValue> { ',' <Layer3TypeValue> }
<Layer3TypeValue> ::= 'IPv4' | 'IPv6' | 'IP' | 'Other'

<Layer4TypeList> ::= <Layer4TypeValue> { ',' <Layer4TypeValue> }
<Layer4TypeValue> ::= 'TCP' | 'UDP' | 'ICMP' | 'GREv0' | 'SCTP' | 'Other'

<InnerLayer3TypeList> ::= <InnerLayer3TypeValue> { ',' <InnerLayer3TypeValue> }
<InnerLayer3TypeValue> ::= 'IPv4' | 'IPv6' | 'IP' | 'Other'

<InnerLayer4TypeList> ::= <InnerLayer4TypeValue> { ',' <InnerLayer4TypeValue> }
<InnerLayer4TypeValue> ::= 'TCP' | 'UDP' | 'SCTP' | 'Other'

<HashAlgorithm> ::= 'CRC32' | 'SHA256' | 'NTH10' | 'TOEPLITZ' | 'HashRoundRobin'

<HexString> ::= '0x' <HexDigits>
<HexDigits> ::= <HexDigit>+

<HexDigit> ::= '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'
             | 'A' | 'B' | 'C' | 'D' | 'E' | 'F'
             | 'a' | 'b' | 'c' | 'd' | 'e' | 'f'

<PortNumberSpec> ::= '"' <AnyCharacterExceptDoubleQuote>* '"'

<Identifier> ::= <Letter> { <Letter> | <Digit> | '_' }

<Letter> ::= 'A'..'Z' | 'a'..'z'

<Integer> ::= <Digit>+

<Digit> ::= '0'..'9'

<String> ::= '"' { <AnyCharacterExceptDoubleQuote> } '"'

<TrueFalse> ::= 'true' | 'false'

Key Enhancements:

  • Colon (:) for Implicit Definitions: Replaces the equal sign (=) to define implicit types without using define.
  • Dot Notation: Incorporated into expressions within conditions and field access.
  • Curly Braces {} for Grouping: Enhances readability by clearly grouping field assignments and options.
  • Reserved Bracket Notation ([]): Remains reserved for arrays and logical evaluations.

4. Comprehensive JNPL Script Example with Enhanced Syntax

Integrating the new data types and syntax adjustments, here is an updated and comprehensive JNPL script:

priority = 10

define TopLabel 0
define BottomLabel -1

// Supported Protocols and Fields
protocol {
    // Define IP Protocol Block
    define IP protocol {
        Offset: Packet.L3Offset >> 2
        Length: Packet.L3Len >> 2
        Payload: Packet.length - (Offset + Length)

        fields: { Src, Dst, TTL, Protocol }

        // Define IPv4 Sub-Protocol
        define IPv4 protocol {
            condition: Packet.L3Type == IPv4
            fields: { Src = 12:4, Dst = 16:4, Flags = 6, TTL = 8, Protocol = 9 }
        }

        // Define IPv6 Sub-Protocol
        define IPv6 protocol {
            condition: Packet.L3Type == IPv6
            fields: { Src = 7:16, Dst = 23:6, FlowLabel = 1, TTL = 6, Protocol = 5 }
        }
    }

    // Define TRANSPORT Protocol Block
    define TRANSPORT protocol {
        Offset: Packet.L4Offset >> 2
        Length: Packet.L4Len >> 2
        Payload: Packet.length - (Offset + Length)

        fields: { SrcPort, DstPort, Length, Checksum }

        // Define TCP Sub-Protocol
        define TCP protocol {
            condition: Packet.L4Type == TCP
            fields: { SrcPort = 0:2, DstPort = 2:2, Flags = 12:2, Seq = 4:4, Ack = 8:4, Checksum = 16:2 }
        }

        // Define UDP Sub-Protocol
        define UDP protocol {
            condition: Packet.L4Type == UDP
            fields: { SrcPort = 0:2, DstPort = 2:2, Length = 4:2, Checksum = 6:2 }
        }

        // Define SCTP Sub-Protocol
        define SCTP protocol {
            condition: Packet.L4Type == SCTP
            fields: { SrcPort = 0:2, DstPort = 2:2, Tag = 4:4, Checksum = 8:4 }
        }

        // Add more transport protocols as needed
    }

    // Add more protocol blocks as needed (e.g., APPLICATION, DATA)
}

// Define Constants
define TCP 17
define UDP 8
define IPv4 1
define IPv6 2

// HashMode Definitions using define/block Style
define Hash5Tuple HashMode {
    Priority = 5
    Encapsulation = VLAN,MPLS
    Algorithm = CRC32
    Key = 0xABCDEF
    Tag = VlanTag
}

define Hash3TupleGTPv1v2Sorted HashMode {
    Priority = 10
    Encapsulation = VLAN
    Layer3Type = IPv4,IPv6
    Layer4Type = TCP,UDP
    Algorithm = SHA256
}

// Filter Definition for VLAN Traffic
define VLAN_TRAFFIC filter {
    Frame[4:2] == IPv4
    MPLS.TopLabel == 100 AND MPLS.BottomLabel == 200
    VLAN[0].Id == 100 AND VLAN[1].Id == 200 AND VLAN.Count >= 2 AND VLAN.Payload == 3
    Layer3.Type in [IPv4, IPv6]
    Layer4.Type == TCP
    Port == 4
}

// Action Definition for VLAN Traffic using Hash5Tuple
action HandleVLANTraffic {
    filter VLAN_TRAFFIC == true

    log "SYN packet from 192.168.1.1 detected"
    distribute = (0..3) based on Hash5Tuple

    slice = 12:64
}

// Additional Action Definition using Hash3TupleGTPv1v2Sorted
action DistributeWithHash3Tuple {
    filter SomeOtherFilter == true

    log "Distributing traffic based on Hash3TupleGTPv1v2Sorted"
    distribute = (0..3) based on Hash3TupleGTPv1v2Sorted

    slice = 20:128
}

Highlights of the Updated Script:

  • Implicit Type Definitions: Offset, Length, and Payload are defined using :, indicating their data types without explicit define statements.
  • Dot Notation Usage: Fields like Packet.L3Type and MPLS.TopLabel are accessed using dot notation, enhancing readability.
  • Curly Braces for Fields: Field assignments are enclosed within {} for clarity.
  • Range Type for Payload: Payload is defined as a range (offset:length), calculated based on Offset and Length.
  • Consistent Formatting: Proper indentation and alignment of blocks improve overall readability.

5. Additional Syntax Examples and Use Cases

To further illustrate the versatility and functionality of the updated syntax and data types, here are additional examples covering various scenarios:

a. Defining an Application Layer Protocol

protocol {
    // Define APPLICATION Protocol Block
    define APPLICATION protocol {
        Offset: Packet.L5Offset >> 2
        Length: Packet.L5Len >> 2
        Payload: Packet.length - (Offset + Length)

        fields: { AppSrc, AppDst, AppType }

        // Define HTTP Sub-Protocol
        define HTTP protocol {
            condition: Packet.L5Type == HTTP
            fields: { AppSrc = 0:2, AppDst = 2:2, Method = 4:4, StatusCode = 8:4 }
        }

        // Define HTTPS Sub-Protocol
        define HTTPS protocol {
            condition: Packet.L5Type == HTTPS
            fields: { AppSrc = 0:2, AppDst = 2:2, Method = 4:4, StatusCode = 8:4 }
        }

        // Add more application protocols as needed
    }
}

Usage:

  • Enables actions and filters based on application layer protocols like HTTP and HTTPS.
  • Facilitates detailed packet inspection and processing at the application layer.

b. Defining a Data Protocol

protocol {
    // Define DATA Protocol Block
    define DATA protocol {
        Offset: Packet.DataOffset >> 2
        Length: Packet.DataLen >> 2
        Payload: Packet.length - (Offset + Length)

        fields: { DataSrc, DataDst, DataType }

        // Define DNS Sub-Protocol
        define DNS protocol {
            condition: Packet.DataType == DNS
            fields: { QueryID = 0:2, Flags = 2:2, QDCount = 4:2, ANCount = 6:2 }
        }

        // Define FTP Sub-Protocol
        define FTP protocol {
            condition: Packet.DataType == FTP
            fields: { Command = 0:2, ResponseCode = 2:2, SessionID = 4:4 }
        }

        // Add more data protocols as needed
    }
}

Usage:

  • Allows for detailed processing of data-specific protocols like DNS and FTP.
  • Enhances the ability to create granular filters and actions based on data payloads.

c. Defining a New HashMode with Extended Options

define HashExtendedVLAN HashMode {
    Priority = 8
    Encapsulation = VLAN,MPLS
    Layer3Type = IPv4
    Layer4Type = UDP
    InnerLayer3Type = IPv6
    InnerLayer4Type = SCTP
    TupleSwap = true
    MaskNo = 2
    Port = "GTPv1-U"
    Algorithm = NTH10
    Key = 0xDEADBEEF
    Tag = ExtendedVlanTag
}

Purpose:

  • Demonstrates a hash mode with advanced configurations, including tuple swapping, masking, specific port specifications, and cryptographic keys.
  • Enables complex distribution logic tailored to specific network scenarios.

d. Action Definition Utilizing the Extended HashMode

action DistributeWithExtendedHash {
    filter ExtendedVLANFilter == true

    log "Distributing traffic using Extended VLAN HashMode"
    distribute = (0..3) based on HashExtendedVLAN

    slice = 25:100
}

Purpose:

  • Applies the HashExtendedVLAN hash mode to distribute traffic based on intricate criteria.
  • Facilitates precise and secure traffic distribution across designated buffers.

6. Best Practices for JNPL Script Design

Adhering to best practices ensures that your JNPL scripts remain efficient, readable, and maintainable. Here are some recommendations:

a. Modular Script Design

Organize your JNPL scripts into modular sections, each handling specific aspects of packet processing. This enhances readability and facilitates easier debugging and updates.

Example Structure:

// HashMode Definitions
define HashModes {
    define Hash5Tuple HashMode { ... }
    define Hash3TupleGTPv1v2Sorted HashMode { ... }
    define RoundRobin HashMode { ... }
    // Additional HashModes
}

// Protocol Definitions
protocol {
    define IP protocol { ... }
    define TRANSPORT protocol { ... }
    define APPLICATION protocol { ... }
    // Additional Protocols
}

// Filter Definitions
define Filters {
    define VLAN_TRAFFIC filter { ... }
    define HighPriorityTraffic filter { ... }
    // Additional Filters
}

// Action Definitions
define Actions {
    action HandleVLANTraffic { ... }
    action DistributeWithHash3Tuple { ... }
    action DistributeRoundRobin { ... }
    // Additional Actions
}

b. Consistent Naming Conventions

Use clear and consistent naming conventions for filters, actions, and hash modes to make scripts self-explanatory.

Example:

  • Filters:

    • VLAN_TRAFFIC
    • HighPriorityTraffic
    • DropBlacklisted
  • Actions:

    • HandleVLANTraffic
    • DistributeWithHash3Tuple
    • DropBlacklistedTraffic
  • HashModes:

    • Hash5Tuple
    • Hash3TupleGTPv1v2Sorted
    • RoundRobin

c. Comprehensive Commenting

Include comments to explain complex logic or important decisions within the scripts. This aids future maintenance and helps other users understand the script's intent.

Example:

// Filter for VLAN traffic with specific MPLS labels and VLAN IDs
define VLAN_TRAFFIC filter {
    Frame[4:2] == IPv4
    MPLS.TopLabel == 100 AND MPLS.BottomLabel == 200
    VLAN[0].Id == 100 AND VLAN[1].Id == 200 AND VLAN.Count >= 2 AND VLAN.Payload == 3
    Layer3.Type in [IPv4, IPv6]
    Layer4.Type == TCP
    Port == 4
}

d. Priority Management

Carefully assign priority levels to ensure that critical rules are processed before less important ones. Avoid overlapping filters with conflicting actions unless intentional.

Example:

// Highest priority: Drop traffic from blacklisted IPs
define DropBlacklisted filter {
    IP.Src in blacklisted_ips
}

define ActionDropBlacklisted action {
    log "Blocked traffic from blacklisted IP"
    drop
}

action DropBlacklisted {
    priority = 0
}

// High priority: Handle VLAN traffic
define HandleVLANTraffic filter {
    VLAN_TRAFFIC == true
}

define ActionHandleVLANTraffic action {
    log "SYN packet from 192.168.1.1 detected"
    distribute = (0..3) based on Hash5Tuple
    slice = 12:64
}

action HandleVLANTraffic {
    priority = 10
}

// Default handling with lowest priority
define DefaultHandling filter {
    true
}

define ActionDefaultHandling action {
    log "Default handling for all other traffic"
    assign to_module "default_processor"
}

action DefaultHandling {
    priority = 64
}

e. Error Handling and Validation

Ensure that your scripts handle potential errors gracefully and validate conditions effectively.

Example:

action HandleVLANTraffic {
    filter VLAN_TRAFFIC == true

    if (Packet.Payload.length < 64) {
        log "Payload too short, dropping packet"
        drop
    } else {
        log "SYN packet from 192.168.1.1 detected"
        distribute = (0..3) based on Hash5Tuple
        slice = 12:64
    }
}

f. Utilize Reusable Components

Define reusable filters, actions, and hash modes to avoid redundancy and promote consistency across scripts.

Example:

define CommonFilters {
    define DropBlacklisted filter { ... }
    define HighPriorityTraffic filter { ... }
    // Additional Common Filters
}

define CommonActions {
    define ActionDropBlacklisted action { ... }
    define ActionHandleHighPriority action { ... }
    // Additional Common Actions
}

define CommonHashModes {
    define Hash5Tuple HashMode { ... }
    define RoundRobin HashMode { ... }
    // Additional Common HashModes
}

7. Developing Tooling Support

To maximize the usability of JNPL, especially with the enhanced define/protocol and define HashMode structures, consider developing or integrating the following tools:

a. Syntax Highlighting for Code Editors

Creating syntax highlighting for JNPL in popular code editors like Visual Studio Code or Sublime Text can significantly enhance the user experience.

Example for Visual Studio Code:

  1. Define a TextMate Grammar:

    • Create a jnpl.tmLanguage.json file outlining the syntax rules for JNPL.
    • Include patterns for define, protocol, HashMode, filters, actions, and comments.
  2. Sample jnpl.tmLanguage.json:

    {
        "name": "JNPL",
        "fileTypes": ["jnpl"],
        "patterns": [
            {
                "name": "keyword.control.define.jnpl",
                "match": "\\bdefine\\b"
            },
            {
                "name": "entity.name.function.protocol.jnpl",
                "match": "\\bprotocol\\b"
            },
            {
                "name": "entity.name.function.hashmode.jnpl",
                "match": "\\bHashMode\\b"
            },
            {
                "name": "keyword.operator.assignment.jnpl",
                "match": ":="
            },
            {
                "name": "string.quoted.double.jnpl",
                "begin": "\"",
                "end": "\""
            },
            {
                "name": "comment.line.double-slash.jnpl",
                "begin": "//",
                "end": "$"
            },
            {
                "name": "constant.numeric.jnpl",
                "match": "\\b0x[0-9A-Fa-f]+\\b"
            },
            {
                "name": "constant.numeric.jnpl",
                "match": "\\b\\d+\\b"
            },
            {
                "name": "entity.name.type.protocol.jnpl",
                "match": "\\bprotocol\\b"
            },
            {
                "name": "keyword.other.filter.jnpl",
                "match": "\\bfilter\\b"
            },
            {
                "name": "keyword.other.action.jnpl",
                "match": "\\baction\\b"
            },
            {
                "name": "keyword.control.condition.jnpl",
                "match": "\\bcondition:\\b"
            },
            {
                "name": "keyword.control.fields.jnpl",
                "match": "\\bfields:\\b"
            }
        ],
        "scopeName": "source.jnpl"
    }
  3. Package the Extension:

    • Bundle the grammar file within a VS Code extension.
    • Add necessary configuration files like package.json.
    • Publish the extension to the VS Code Marketplace.
  4. Usage:

    • Users can install the extension and select JNPL as the language mode to enable syntax highlighting.

b. Linters and Formatters

Develop linters to validate JNPL scripts against the defined grammar and best practices, and formatters to ensure consistent code style.

Features:

  • Syntax Validation: Ensure that all define/protocol, HashMode, filters, and actions adhere to the grammar.
  • Best Practices Enforcement: Check for consistent naming conventions, proper priority assignments, and modular script structures.
  • Automatic Formatting: Provide tools to auto-format scripts for improved readability.

Example Implementation:

  • Linting Rules:

    • Unique Definitions: Ensure that each HashMode and protocol is uniquely defined.
    • Required Fields: Verify that mandatory fields (e.g., Priority, Algorithm in HashMode) are present.
    • Field Assignments: Check that field assignments follow the correct format (e.g., SrcPort = 0:2).
  • Formatting Tool:

    • Align key-value pairs.
    • Standardize indentation (e.g., 4 spaces per level).
    • Ensure consistent casing for keywords and identifiers.

c. Documentation Generators

Automate the creation of comprehensive documentation based on JNPL scripts, including:

  • API Documentation: Detailed descriptions of available commands, protocols, filters, actions, and hash modes.
  • Examples and Tutorials: Step-by-step guides demonstrating various use cases.
  • Reference Manuals: Exhaustive listings of all language constructs and their specifications.

Tools:

  • Doxygen: Adapt Doxygen or similar tools to parse JNPL scripts and generate HTML or PDF documentation.
  • Custom Scripts: Develop custom scripts to extract documentation comments and organize them into structured formats.

Example:

  • Doxygen Configuration:
    • Define custom patterns to recognize JNPL-specific syntax.
    • Annotate scripts with documentation comments using a consistent style (e.g., // @description).

8. Engaging with the Community

Building a supportive community around JNPL can accelerate its adoption and improvement. Here are some strategies:

a. Open-Source Repository

Host JNPL on a platform like GitHub to facilitate collaboration, issue tracking, and contributions.

Steps:

  1. Create a Repository:

    • Initialize a GitHub repository named JNPL or similar.
    • Include a README.md with an overview, installation instructions, and basic usage examples.
  2. Organize the Repository:

    • /docs: Comprehensive documentation.
    • /examples: Sample JNPL scripts demonstrating various features.
    • /grammar: Formal grammar specifications and tooling scripts.
    • /tools: Scripts for linting, formatting, and other utilities.
  3. License and Contribution Guidelines:

    • Choose an appropriate open-source license (e.g., MIT, Apache 2.0).
    • Provide clear CONTRIBUTING.md guidelines to encourage and streamline community contributions.

b. Forums and Discussion Boards

Establish platforms for users to ask questions, share scripts, and discuss enhancements.

Options:

  • GitHub Discussions: Utilize GitHub’s built-in discussions feature for Q&A and community engagement.
  • Dedicated Forum: Create a forum using platforms like Discourse or Reddit.
  • Chat Channels: Set up real-time communication channels on Slack, Discord, or IRC.

c. Tutorials and Webinars

Host tutorials, webinars, and workshops to educate users about JNPL’s capabilities and best practices.

Content Ideas:

  • Introduction to JNPL: Basic concepts and getting started.
  • Advanced Filtering and Actions: Deep dives into complex use cases.
  • HashMode Customization: Tutorials on defining and utilizing custom hash modes.
  • Performance Optimization: Strategies for writing efficient JNPL scripts.

9. Testing and Validation

Implement comprehensive testing strategies to ensure the reliability and performance of JNPL scripts.

a. Unit Testing

Develop unit tests for individual components like filters, actions, and hash modes to ensure they function as intended.

Example:

// Test Case: Verify that VLAN_TRAFFIC filter correctly identifies matching packets
test VLAN_TRAFFIC_Filter {
    input_packet = {
        Frame[4:2] = IPv4
        MPLS.TopLabel = 100
        MPLS.BottomLabel = 200
        VLAN[0].Id = 100
        VLAN[1].Id = 200
        VLAN.Count = 2
        VLAN.Payload = 3
        Layer3.Type = IPv4
        Layer4.Type = TCP
        Port = 4
    }

    expected_result = true

    assert filter(VLAN_TRAFFIC, input_packet) == expected_result
}

b. Integration Testing

Ensure that different parts of the script work seamlessly together, such as hash modes influencing distribution correctly.

Example:

// Integration Test: Ensure that packets are distributed based on Hash5Tuple
test DistributeBasedOnHash5Tuple {
    input_packet = {
        Frame[4:2] = IPv4
        MPLS.TopLabel = 100
        MPLS.BottomLabel = 200
        VLAN[0].Id = 100
        VLAN[1].Id = 200
        VLAN.Count = 2
        VLAN.Payload = 3
        Layer3.Type = IPv4
        Layer4.Type = TCP
        Port = 4
    }

    action_result = execute_action(HandleVLANTraffic, input_packet)

    assert action_result.distribute_buffers == [0, 1, 2, 3]
    assert action_result.hash_value % 4 == 0 // Example condition
}

c. Performance Testing

Benchmark the performance of JNPL scripts, especially in high-throughput environments, to identify and address bottlenecks.

Tools:

  • Benchmark Scripts: Create scripts that simulate high volumes of packet processing.
  • Profiling Tools: Utilize profiling tools to measure execution time and resource usage.

Example:

# Run performance benchmark
./jnpl_processor --script test_script.jnpl --input high_volume_packets.pcap

10. Final Recommendations

  1. Iterative Development:

    • Continuously refine the JNPL syntax and features based on user feedback and evolving requirements.
  2. Comprehensive Documentation:

    • Maintain up-to-date and detailed documentation, covering all aspects of JNPL, including the new define/protocol and define HashMode configurations.
  3. Tooling Support:

    • Prioritize the development of essential tools like syntax highlighters, linters, and formatters to enhance the user experience.
  4. Community Engagement:

    • Foster an active and supportive community to drive adoption, gather feedback, and encourage contributions.
  5. Performance Optimization:

    • Regularly profile and optimize the JNPL interpreter or compiler to ensure efficient packet processing, especially under heavy loads.
  6. Security Considerations:

    • Implement robust input validation and sandboxing mechanisms to prevent malicious scripts from compromising the system.
  7. Extensibility:

    • Design JNPL to be easily extensible, allowing for the addition of new protocols, actions, and hash modes without disrupting existing scripts.

Conclusion

By defining explicit data types, moving conditional logic into protocol blocks, and adopting dot notation for field access, your JNPL syntax becomes more organized, readable, and aligned with common programming practices. This structured approach not only enhances the clarity and maintainability of your scripts but also facilitates scalability as new protocols and hash modes are introduced.

Next Steps:

  • Implement the Updated Syntax: Start using the refined define/protocol and define HashMode structures in your JNPL scripts to test and validate the changes.
  • Develop Tooling: Begin working on syntax highlighting, linters, and other tools to support the new syntax.
  • Expand Documentation: Update your documentation to reflect the changes and provide clear guidance on using define/protocol and define HashMode.
  • Engage the Community: Share the updated syntax with your user base to gather feedback and encourage collaboration.

If you need further assistance with specific aspects of JNPL development, such as detailed grammar specifications, parser implementation, additional syntax examples, or tooling support, feel free to reach out! I'm here to help you make JNPL as robust and user-friendly as possible.

Clone this wiki locally