Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
GNS3_unikernel_testbed
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
NGUYEN Do Duc Anh
GNS3_unikernel_testbed
Commits
517bbb88
Commit
517bbb88
authored
4 months ago
by
NGUYEN Do Duc Anh
Browse files
Options
Downloads
Patches
Plain Diff
update inter node with ebpf + fix opp
parent
1b504a3b
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
ubuntu_base/opportunistic_node.py
+13
-15
13 additions, 15 deletions
ubuntu_base/opportunistic_node.py
ubuntu_intermediate/intermediate_node.py
+40
-19
40 additions, 19 deletions
ubuntu_intermediate/intermediate_node.py
with
53 additions
and
34 deletions
ubuntu_base/opportunistic_node.py
+
13
−
15
View file @
517bbb88
...
...
@@ -103,7 +103,13 @@ def modify_node_id(file_path, new_value):
file
.
writelines
(
lines
)
def
start_ebpf_on_interface
(
inter_num
,
b
,
fn
):
def
start_process_from_queue
():
file_path
=
if_utils
.
DIR
+
'
/ubuntu_base/op_ebpf.c
'
# Replace with your C file path
modify_node_id
(
file_path
,
if_utils
.
my_id
)
b
=
BPF
(
src_file
=
f
"
op_ebpf.c
"
)
fn
=
b
.
load_func
(
"
op_ebpf
"
,
BPF
.
XDP
)
for
inter_num
in
range
(
if_utils
.
MIN_INTER_NUMBER
,
if_utils
.
MAX_INTER_NUMBER
):
inter_name
=
if_utils
.
PHYSICAL_INTERFACE
[
inter_num
]
b
.
attach_xdp
(
inter_name
,
fn
,
0
)
print
(
"
Attach the ebpf program at
"
,
inter_name
)
...
...
@@ -123,20 +129,12 @@ def start_ebpf_on_interface(inter_num, b, fn):
time
.
sleep
(
1
)
except
KeyError
:
continue
except
KeyboardInterrupt
:
except
Exception
:
print
(
"
Interrupted
"
)
b
.
remove_xdp
(
inter_name
,
0
)
def
start_process_from_queue
():
file_path
=
if_utils
.
DIR
+
'
/ubuntu_base/op_ebpf.c
'
# Replace with your C file path
modify_node_id
(
file_path
,
if_utils
.
my_id
)
b
=
BPF
(
src_file
=
f
"
op_ebpf.c
"
)
fn
=
b
.
load_func
(
"
op_ebpf
"
,
BPF
.
XDP
)
for
inter_num
in
range
(
if_utils
.
MIN_INTER_NUMBER
,
if_utils
.
MAX_INTER_NUMBER
):
threading
.
Thread
(
target
=
start_ebpf_on_interface
,
args
=
[
inter_num
,
b
,
fn
]).
start
()
inter_name
=
if_utils
.
PHYSICAL_INTERFACE
[
inter_num
]
b
.
remove_xdp
(
inter_name
,
0
)
if
__name__
==
"
__main__
"
:
...
...
This diff is collapsed.
Click to expand it.
ubuntu_intermediate/intermediate_node.py
+
40
−
19
View file @
517bbb88
# import os
# import sys
import
subprocess
#
import subprocess
# sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
# from netfilterqueue import NetfilterQueue
# import ubuntu_base.opportunistic_utils import *
import
ctypes
#
import ctypes
import
threading
from
bcc
import
BPF
# from bcc.utils import printb
DIR
=
"
/home/intermediate/Desktop/gns3_unikernel_testbed
"
...
...
@@ -31,20 +35,37 @@ DIR = "/home/intermediate/Desktop/gns3_unikernel_testbed"
def
main
():
rule_check
=
"
sudo iptables -C FORWARD -i br0 -j NFQUEUE --queue-num 1
"
try
:
subprocess
.
run
(
rule_check
,
shell
=
True
,
check
=
True
)
print
(
"
Rule already exists, no need to add it.
"
)
except
subprocess
.
CalledProcessError
:
subprocess
.
run
(
f
"
sudo
{
DIR
}
/ubuntu_intermediate/./initiate.sh
"
,
shell
=
True
,
check
=
True
)
print
(
"
./initiate is executed
"
)
b
=
BPF
(
src_file
=
f
"
inter_op_ebpf.c
"
)
fn
=
b
.
load_func
(
"
inter_op_ebpf
"
,
BPF
.
XDP
)
for
inter_num
in
range
(
3
,
13
):
inter_name
=
f
"
ens
{
inter_num
+
1
}
"
b
.
attach_xdp
(
inter_name
,
fn
,
0
)
print
(
"
Attach the ebpf program at
"
,
inter_name
)
try
:
rule_1
=
"
sudo iptables -I FORWARD -i br0 -j NFQUEUE --queue-num 1
"
subprocess
.
run
(
rule_1
,
shell
=
True
,
check
=
True
)
print
(
"
Rule added successfully.
"
)
except
subprocess
.
CalledProcessError
as
e
:
print
(
f
"
Failed to add the rule:
{
e
}
"
)
b
.
trace_print
()
except
Exception
:
print
(
"
Interrupted
"
)
for
inter_num
in
range
(
3
,
13
):
inter_name
=
f
"
ens
{
inter_num
+
1
}
"
b
.
remove_xdp
(
inter_name
,
0
)
# rule_check = "sudo iptables -C FORWARD -i br0 -j NFQUEUE --queue-num 1"
# try:
# subprocess.run(rule_check, shell=True, check=True)
# print("Rule already exists, no need to add it.")
# except subprocess.CalledProcessError:
# subprocess.run(f"sudo {DIR}/ubuntu_intermediate/./initiate.sh", shell=True, check=True)
# print("./initiate is executed")
# try:
# rule_1 = "sudo iptables -I FORWARD -i br0 -j NFQUEUE --queue-num 1"
# subprocess.run(rule_1, shell=True, check=True)
# print("Rule added successfully.")
# except subprocess.CalledProcessError as e:
# print(f"Failed to add the rule: {e}")
# q = NetfilterQueue()
# q.bind(1, process_packet) # Bind to queue number 1
...
...
@@ -55,9 +76,9 @@ def main():
# except KeyboardInterrupt:
# print("Stopping packet listener")
lib
=
ctypes
.
CDLL
(
DIR
+
"
/ubuntu_intermediate/./inter_c_library.so
"
)
lib
.
start_process_from_queue
.
restype
=
None
# The function returns void
threading
.
Thread
(
target
=
lib
.
start_process_from_queue
).
start
()
#
lib = ctypes.CDLL(DIR + "/ubuntu_intermediate/./inter_c_library.so")
#
lib.start_process_from_queue.restype = None # The function returns void
#
threading.Thread(target=lib.start_process_from_queue).start()
if
__name__
==
"
__main__
"
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment