packetforge: add packetforge for generic flow to extras
[vpp.git] / extras / packetforge / EdgeAction.py
1 # 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
14
15 class EdgeAction:
16     def __init__(self):
17         self.ToStartObject = None
18         self.ToExpression = None
19         self.FromStartObject = None
20         self.FromExpression = None
21
22     def Create(token):
23         if token == None:
24             return None
25
26         dststr = token["dst"]
27         srcstr = token["src"]
28
29         if srcstr == None or dststr == None:
30             return None
31
32         action = EdgeAction()
33
34         dststr = dststr.strip()
35         srcstr = srcstr.strip()
36
37         if dststr.startswith("start."):
38             action.ToStartObject = True
39             action.ToExpression = dststr[6:]
40         elif dststr.startswith("end."):
41             action.ToStartObject = False
42             action.ToExpression = dststr[4:]
43         else:
44             return None
45
46         if srcstr.startswith("start."):
47             action.FromStartObject = True
48             action.FromExpression = srcstr[6:]
49         elif srcstr.startswith("end."):
50             action.FromStartObject = False
51             action.FromExpression = srcstr[4:]
52         else:
53             action.FromExpression = srcstr
54
55         return action