blob: 9b89282e153d3c3761d23c41cb93d60b7b5e1136 [file] [log] [blame]
Ting Xuf34420f2023-03-16 01:22:33 +00001# Copyright (c) 2022 Intel and/or its affiliates.
2# Licensed under the Apache License, Version 2.0 (the "License");
3# you may not use this file except in compliance with the License.
4# You may obtain a copy of the License at:
5#
6# http://www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS,
10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11# See the License for the specific language governing permissions and
12# limitations under the License.
13
14import sys, getopt
15import packetforge
16
17
18def Main(argv):
19 file_flag = False
20 operation = None
21 try:
22 opts, args = getopt.getopt(
23 argv,
24 "hf:p:a:i:I:",
25 [
26 "help",
27 "show",
28 "file=",
29 "pattern=",
30 ],
31 )
32 except getopt.GetoptError:
33 print("flow_parse.py --show -f <file> -p <pattern>")
34 sys.exit()
35 for opt, arg in opts:
36 if opt == "-h":
37 print("flow_parse.py --show -f <file> -p <pattern>")
38 sys.exit()
39 elif opt == "--show":
40 operation = "show"
41 elif opt in ("-f", "--file"):
42 json_file = arg
43 file_flag = True
44 elif opt in ("-p", "--pattern") and not file_flag:
45 pattern = arg
46
47 if operation == None:
48 print("Error: Please choose the operation: show")
49 sys.exit()
50
51 if not file_flag:
52 result = packetforge.Forge(pattern, None, False, True)
53 else:
54 result = packetforge.Forge(json_file, None, True, True)
55
56 return result
57
58
59if __name__ == "__main__":
60 # Parse the arguments
61 my_flow = Main(sys.argv[1:])
62
63 print(my_flow)
64
65# command example:
66# python flow_parse.py --show -p "mac()/ipv4(src=1.1.1.1,dst=2.2.2.2)/udp()"