Custom Protocol Traffic

The commands to start P4FlowForge with Custom traffic are:

#First start the receiver
receiver.py --protocol custom --custom <json_file>

#Start the generator
generator.py --time <time> --mean <messages_per_second> --interface <output_interface> --protocol custom --custom <json_file>

Make sure to use the same JSON format for both receiver and generator.

A P4 code is available at https://github.com/dnredson/TrafficForge/blob/main/standard.p4arrow-up-right to test a custom protocol described by this JSON file format:

{
    "nome": "MeuProtocoloDinamico",
    "campos": [
        {"nome": "field1", "tipo": "IntField", "default": 123},
        {"nome": "field2", "tipo": "StrField", "default": ""},
        {"nome": "timestamp", "tipo": "IntField", "default": 0}
    ]
}

This protocol can be easily adapted to P4 with the header

//HEADER
header meuProtocolo_t {
    bit<32>   field1;
    bit<64>   field2; 
    bit<32>   timestamp;
}

//PARSER
state meuProtocolo {
        packet.extract(hdr.meuProtocolo);
        transition accept;
}

P4FlowForge uses the types described on Scapy to create a custom protocol. The fields compatible are:

IntField: Represents an integer field in a packet. It allows you to specify a field that holds integer values.

StrField: Represents a string field in a packet. It will enable you to specify a field that holds string values.

ByteField: Represents a single byte field in a packet. It's typically used for fields that store byte-sized values.

ShortField: Represents a short integer field in a packet. It's used for fields that store 16-bit integer values.

LongField: Represents a long integer field in a packet. It's used for fields that store 64-bit integer values.

IPField: Represents an IP address field in a packet. It allows you to specify a field that holds IP address values.

MACField: Represents a MAC address field in a packet. It allows you to specify a field that holds MAC address values.

EnumField: Represents an enumerated field in a packet. It allows you to specify a field that can only take on certain predefined values, typically from an enumerated list.

Last updated