blob: 6d959967af48fbb725c0960aa8b50f3bde1ca4eb [file] [log] [blame]
Ting Xuce4b6452022-04-24 06:14:25 +00001.. _packetforge_doc:
2
3Packetforge for generic flow
4============================
5
6Packetforge is a tool to support generic flow. Since the input format of
7generic flow is hard to read and create, packetforge can help to create
8generic flow rules using a format of naming protocols (like Scapy) or json
9profile. Packetforge is built based on a parsegraph, users can modify the
10graph nodes and edges if needed.
11
12Command examples
13----------------
14
15::
16
17 $ python flow_create.py --add -p "mac()/ipv4(src=1.1.1.1,dst=2.2.2.2)/udp()"
18 -a "redirect-to-queue 3" -i 1
19
20 $ python flow_create.py --add
21 --pattern "mac()/ipv4(src=1.1.1.1,dst=2.2.2.2)/udp()"
22 --actions "redirect-to-queue 3" --interface 1
23
24 $ python flow_create.py --del -i 1 -I 0
25
26 $ python flow_create.py --del --interface 1 --flow-index 0
27
28Naming format input. There are two operations, add and delete flow rules.
29For add, it needs three parameters. Pattern is similar to Scapy protocols.
30Actions is the same as vnet/flow command. Interface is the device to which
31we want to add the flow rule. For delete, flow index is the index of the
32flow rule we want to delete. We can get the index number when we add the
33flow or use command to show the existed flow entry in CLI.
34
35::
36
37 $ python flow_create.py --add -f "./flow_rule_examples/mac_ipv4.json" -i 1
38
39 $ python flow_create.py --add --file "./flow_rule_examples/mac_ipv4.json"
40 --interface 1
41
42 $ python flow_create.py --add -f "./flow_rule_examples/mac_ipv4.json"
43 -a "redirect-to-queue 3" -i 1
44
45Json profile format input. This command takes a json profile as parameter.
46In the json profile, there will be protocols and their fields and values.
47Users can define spec and mask for each field. Actions can be added in the
48profile directly, otherwise "-a" option should be added in the command to
49specify actions. The example can be found in parsegraph/samples folder.
50Users can create their own json files according to examples and Spec.
51
52::
53
Ting Xuf34420f2023-03-16 01:22:33 +000054 $ python flow_create.py --show -p "mac()/ipv4(src=1.1.1.1,dst=2.2.2.2)/udp()"
55
56 $ python flow_parse.py --show -p "mac()/ipv4(src=1.1.1.1,dst=2.2.2.2)/udp()"
57
58These commands can show the forging result of spec and mask only, without invoving
59VPP. No need to configure actions and interfaces. Users can get the binary string
60of spec and mask from a flow pattern if needed. flow_parse.py can be used without
61VAPI installed.
62
63::
64
Ting Xuce4b6452022-04-24 06:14:25 +000065 $ show flow entry
66
67It is a vnet/flow command, used in VPP CLI. It can show the added flow rules
68after using the above commands. Users can get the flow index with this command
69and use it to delete the flow rule.
70
71ParseGraph
72----------
73
74Packetforge is built based on a ParseGraph. The ParseGraph is constructed
75with nodes and edges. Nodes are protocols, including information about
76protocol's name, fields and default values. Edges are the relationship
77between two protocols, including some actions needed when connecting two
78protocols. For example, change the mac header ethertype to 0x0800 when
79connecting mac and ipv4. More details are in the Spec in parsegraph folder.
80Users can build the ParseGraph following the spec by themselves, like
81adding a new protocol. If NIC supports the new protocol, the rule can be
82created. Otherwise, it will return error.