MCPcopy Create free account
hub / github.com/FDio/vpp / Forge

Function Forge

extras/packetforge/packetforge.py:24–76  ·  view source on GitHub ↗
(pattern, actions, file_flag, show_result_only)

Source from the content-addressed store, hash-verified

22
23
24def Forge(pattern, actions, file_flag, show_result_only):
25 pg = ParseGraph.Create(parsegraph_path)
26 if pg == None:
27 print("error: create parsegraph failed")
28 return None
29
30 if not file_flag:
31 token = ParsePattern(pattern)
32 if token == None:
33 return None
34 else:
35 if not os.path.exists(pattern):
36 print("error: file not exist '%s' " % (pattern))
37 return
38 f = open(pattern, "r", encoding="utf-8")
39 token = json.load(f)
40 if "actions" in token:
41 actions = token["actions"]
42
43 path = Path.Create(token)
44 if path == None:
45 print("error: path not exit")
46 return None
47
48 result = pg.Forge(path)
49 if result == None:
50 print("error: result not available")
51 return None
52
53 spec, mask = GetBinary(result.ToJSON())
54
55 # create generic flow
56 my_flow = {
57 "flow": {
58 "generic": {
59 "pattern": {"spec": bytes(spec.encode()), "mask": bytes(mask.encode())}
60 }
61 },
62 }
63
64 if show_result_only:
65 return my_flow
66
67 my_flow.update(
68 {
69 "type": VppEnum.vl_api_flow_type_v2_t.FLOW_TYPE_GENERIC_V2,
70 }
71 )
72
73 # update actions entry
74 my_flow = GetAction(actions, my_flow)
75
76 return my_flow
77
78
79def GetAction(actions, flow):

Callers

nothing calls this directly

Calls 9

printFunction · 0.85
ParsePatternFunction · 0.85
GetBinaryFunction · 0.85
GetActionFunction · 0.85
ForgeMethod · 0.80
ToJSONMethod · 0.80
CreateMethod · 0.45
encodeMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected