Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PSA eBPF: Commands: Clone Command #20

Merged
merged 2 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions src/p4rrot/psa_ebpf/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from p4rrot.standard_fields import *
from p4rrot.generator_tools import *
from p4rrot.checks import *
from p4rrot.core.commands import *
import random

class AssignRandomValue(Command):
Expand Down Expand Up @@ -85,3 +86,58 @@ def get_generated_code(self):

def execute(self, test_env):
pass


class Clone(Command):
def __init__(self, keys, table_name=None, action_name=None, env=None):
self.keys = keys
self.env = env
if table_name is None:
self.table_name = "clone_table" + UID.get()
else:
self.table_name=table_name

if action_name is None:
self.action_name = "setter_action_" + UID.get()
else:
self.action_name = action_name


def check(self):
pass

def get_generated_code(self):
gc = GeneratedCode()
decl = gc.get_decl()
decl.writeln(f"action {self.action_name}(CloneSessionId_t clone_session) {{")
decl.increase_indent()
decl.writeln("ostd.clone_session_id = clone_session;")
decl.writeln("ostd.clone = true;")
decl.decrease_indent()
decl.writeln("}")


apply = gc.get_apply()
match = []
for key in self.keys:
match.append(self.env.get_varinfo(key))
actions = [self.action_name, "NoAction"]

try:
key = [
{"name": part_key["handle"], "match_type": "exact"} for part_key in match
]
except TypeError:
key = [
{"name": part_key.get_handle(), "match_type": "exact"} for part_key in match
]
size = 256
const_entries = []
default_action = "NoAction"
eval_table = Table(
self.table_name, actions, key, size, const_entries, default_action
)
gc.concat(eval_table.get_generated_code())
apply.writeln("{}.apply();".format(self.table_name))

return gc
4 changes: 4 additions & 0 deletions tests/psa_ebpf/clone/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.p4
*.bc
*.c
*.o
39 changes: 39 additions & 0 deletions tests/psa_ebpf/clone/codegen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import sys
sys.path.append('../../../src/')

from p4rrot.generator_tools import *
from p4rrot.known_types import *
from p4rrot.standard_fields import *
from p4rrot.core.commands import *
from p4rrot.tcp_fields import *
from p4rrot.psa_ebpf.commands import *



UID.reset()
fp = FlowProcessor(
istruct = [],
ostruct = [],
standard_fields = [UdpDstPort]
)



(
fp
.add(Clone([UdpDstPort.handle], table_name="clone_table", action_name="assign_clone"))
)



fs = FlowSelector(
'IPV4_UDP',
[(UdpDstPort,5555)],
fp
)


solution = Solution()
solution.add_flow_processor(fp)
solution.add_flow_selector(fs)
solution.get_generated_code().dump('template')
Loading