Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
oai-upf-6g
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenXG
oai-upf-6g
Commits
aa2a83ae
Commit
aa2a83ae
authored
Aug 06, 2024
by
Franck Messaoudi
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop' into upf-merging-qos-and-n4-interoperability-brahcnes
parents
f9ae57a1
5954b5c6
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
78 additions
and
97 deletions
+78
-97
src/upf_app/CMakeLists.txt
src/upf_app/CMakeLists.txt
+1
-14
src/upf_app/CmdRunner.cpp
src/upf_app/CmdRunner.cpp
+24
-0
src/upf_app/CmdRunner.hpp
src/upf_app/CmdRunner.hpp
+14
-0
src/upf_app/SessionProgramManager.cpp
src/upf_app/SessionProgramManager.cpp
+7
-13
src/upf_app/helpers/NextHopFinder.cpp
src/upf_app/helpers/NextHopFinder.cpp
+24
-62
src/upf_app/helpers/NextHopFinder.hpp
src/upf_app/helpers/NextHopFinder.hpp
+8
-8
No files found.
src/upf_app/CMakeLists.txt
View file @
aa2a83ae
...
...
@@ -48,6 +48,7 @@ add_library(UPF_XDP STATIC
Configuration.cpp
SignalHandler.cpp
helpers/NextHopFinder.cpp
SessionProgramManager.cpp
SessionManager.cpp
SessionPrograms.cpp
...
...
@@ -83,20 +84,6 @@ target_include_directories(UPF_XDP PUBLIC
add_dependencies
(
UPF_XDP upf_ebpf_xdp_all
)
# configure_file (
# ${PROJECT_SOURCE_DIR}/cmake/Configuration.h.in
# ${PROJECT_SOURCE_DIR}/src/Configuration.h
# )
# configure_file (
# ${PROJECT_SOURCE_DIR}/cmake/Configuration.cpp.in
# ${PROJECT_SOURCE_DIR}/src/Configuration.cpp
# )
# Targets:
# * <prefix>/lib/upf_bpf.a
# * header location after install: <prefix>/include/*.h
# * headers can be included by C++ code `#include <*/*.h>`
install
(
TARGETS UPF_XDP
EXPORT
"
${
TARGETS_EXPORT_NAME
}
"
...
...
src/upf_app/CmdRunner.cpp
0 → 100644
View file @
aa2a83ae
#include "CmdRunner.hpp"
#include <array>
#include <memory>
#include <stdexcept>
#include <cstdio> // For popen and pclose
// CmdRunner::CmdRunner() {}
//------------------------------------------------------------------------
std
::
string
CmdRunner
::
exec
(
const
std
::
string
&
cmd
)
{
std
::
array
<
char
,
256
>
buffer
;
std
::
string
result
;
std
::
shared_ptr
<
FILE
>
pipe
(
popen
(
cmd
.
c_str
(),
"r"
),
pclose
);
if
(
!
pipe
)
{
throw
std
::
runtime_error
(
"popen() failed!"
);
}
while
(
fgets
(
buffer
.
data
(),
buffer
.
size
(),
pipe
.
get
())
!=
nullptr
)
{
result
+=
buffer
.
data
();
}
return
result
;
}
src/upf_app/CmdRunner.hpp
0 → 100644
View file @
aa2a83ae
#ifndef CMDRUNNER_HPP
#define CMDRUNNER_HPP
#include <string>
class
CmdRunner
{
public:
// CmdRunner();
// Function to execute a shell command and return the output
static
std
::
string
exec
(
const
std
::
string
&
cmd
);
};
#endif // CMDRUNNER_HPP
\ No newline at end of file
src/upf_app/SessionProgramManager.cpp
View file @
aa2a83ae
...
...
@@ -82,11 +82,10 @@ void SessionProgramManager::addFarProgram(
/*---------------------------------------------------------------------------------------------------------------*/
uint32_t
SessionProgramManager
::
getRemoteIP
(
uint32_t
upfIP
,
uint32_t
remoteIP
)
{
NextHopFinder
finder
;
uint32_t
ipnexthop
=
0
;
if
(
not
finder
.
sameSubnet
(
upfIP
,
remoteIP
))
{
if
(
not
NextHopFinder
::
sameSubnet
(
upfIP
,
remoteIP
))
{
Logger
::
upf_app
().
debug
(
"Not in the same subnet"
);
ipnexthop
=
finder
.
retrieveNextHopIP
(
remoteIP
);
ipnexthop
=
NextHopFinder
::
retrieveNextHopIP
(
remoteIP
);
}
else
{
Logger
::
upf_app
().
debug
(
"The same subnet"
);
ipnexthop
=
remoteIP
;
...
...
@@ -219,12 +218,11 @@ void SessionProgramManager::storeFARInFARMap(
void SessionProgramManager::updateARPTableForN6(
std::shared_ptr<FARProgram> pFARProgram, uint32_t dnIP, uint32_t upfn6IP) {
try {
NextHopFinder finder;
// uint32_t remoteN6 = getRemoteIP(upfn6IP, dnIP);
uint32_t ipnexremoteN6hop = (is_little_endian()) ?
htole32(getRemoteIP(upfn6IP, dnIP)) :
getRemoteIP(upfn6IP, dnIP);
auto remoteN6MAC
= finder.
retrieveNextHopMAC(ipnexremoteN6hop);
auto remoteN6MAC
= NextHopFinder::
retrieveNextHopMAC(ipnexremoteN6hop);
struct s_arp_mapping map_table;
memset(&map_table, 0, sizeof(struct s_arp_mapping));
...
...
@@ -276,14 +274,12 @@ void SessionProgramManager::updateARPTableForN3(
std::shared_ptr<FARProgram> pFARProgram, uint32_t gNodeBIP,
uint32_t upfn3IP, uint64_t seid) {
try {
NextHopFinder finder;
// uint32_t remoteN3 = getRemoteIP(upfn3IP, gNodeBIP);
uint32_t ipnexremoteN3hop = (is_little_endian()) ?
htole32(getRemoteIP(upfn3IP, gNodeBIP)) :
getRemoteIP(upfn3IP, gNodeBIP);
auto remoteN3MAC
= finder.
retrieveNextHopMAC(ipnexremoteN3hop);
auto remoteN3MAC
= NextHopFinder::
retrieveNextHopMAC(ipnexremoteN3hop);
struct s_arp_mapping map_table;
memset(&map_table, 0, sizeof(struct s_arp_mapping));
...
...
@@ -536,10 +532,9 @@ void SessionProgramManager::createPipeline(
// std::thread arpUpdateThread1([this, pFARProgram, seid, gNodeBIP, dnIP,
// upfn3IP, upfn6IP]() {
// try {
// NextHopFinder finder;
// uint32_t remoteN6 = getRemoteIP(upfn6IP, dnIP);
// auto remoteN6MAC =
finder.
retrieveNextHopMAC(remoteN6);
// auto remoteN6MAC =
NextHopFinder::
retrieveNextHopMAC(remoteN6);
// uint32_t ipnexremoteN6hop =
// (is_little_endian()) ? htole32(remoteN6) : remoteN6;
...
...
@@ -547,7 +542,7 @@ void SessionProgramManager::createPipeline(
// ipnexremoteN6hop, remoteN6MAC->ether_addr_octet, BPF_ANY);
// uint32_t remoteN3 = getRemoteIP(upfn3IP, gNodeBIP);
// auto remoteN3MAC =
finder.
retrieveNextHopMAC(remoteN3);
// auto remoteN3MAC =
NextHopFinder::
retrieveNextHopMAC(remoteN3);
// uint32_t ipnexremoteN3hop =
// (is_little_endian()) ? htole32(remoteN3) : remoteN3;
...
...
@@ -584,9 +579,8 @@ void SessionProgramManager::createPipeline(
// std::thread arpUpdateThread2([this, pFARProgram, dnIP, upfn6IP]() {
// try {
// // updateArpTableMap(pFARProgram, upfn6IP, ipnexthop);
// NextHopFinder finder;
// uint32_t remoteN6 = getRemoteIP(upfn6IP, dnIP);
// auto remoteN6MAC =
finder.
retrieveNextHopMAC(remoteN6);
// auto remoteN6MAC =
NextHopFinder::
retrieveNextHopMAC(remoteN6);
// uint32_t ipnexremoteN6hop =
// (is_little_endian()) ? htole32(remoteN6) : remoteN6;
...
...
src/upf_app/helpers/NextHopFinder.cpp
View file @
aa2a83ae
#include "NextHopFinder.hpp"
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include <types.h>
#include <arpa/inet.h>
#include <netinet/ether.h>
#include <iostream>
#include <stdexcept>
#include <arpa/inet.h>
#define COMMAND_MAX_LENGTH 256
#define OUTPUT_MAX_LENGTH 256
#include "CmdRunner.hpp"
/*---------------------------------------------------------------------------------------------------------------*/
NextHopFinder
::
NextHopFinder
()
{}
//
NextHopFinder::NextHopFinder() {}
/*---------------------------------------------------------------------------------------------------------------*/
int
NextHopFinder
::
calculateSubnetMask
(
uint32_t
ip
)
{
...
...
@@ -44,73 +31,48 @@ int NextHopFinder::sameSubnet(uint32_t ip1, uint32_t ip2) {
}
/*---------------------------------------------------------------------------------------------------------------*/
u_int32_t
NextHopFinder
::
retrieveNextHopIP
(
uint32_t
destination_ip
)
{
char
command
[
COMMAND_MAX_LENGTH
];
struct
in_addr
addr
;
addr
.
s_addr
=
destination_ip
;
char
*
ipAddress
=
inet_ntoa
(
addr
);
uint32_t
NextHopFinder
::
retrieveNextHopIP
(
uint32_t
ipDest
)
{
std
::
string
cmd
=
{};
struct
in_addr
addr
=
{.
s_addr
=
ipDest
};
char
*
ipAddress
=
inet_ntoa
(
addr
);
if
(
ipAddress
==
nullptr
)
{
Logger
::
upf_app
().
error
(
"The Next Hop IPv4 WAS NOT Retrieved"
);
throw
std
::
runtime_error
(
"The Next Hop IPv4 WAS NOT Retrieved"
);
if
(
ipAddress
)
{
cmd
=
fmt
::
format
(
"ip route get {} | awk '{print $3}'"
,
ipAddress
);
}
sprintf
(
command
,
"ip route get %s | awk '{print $3}'"
,
ipAddress
);
u_int32_t
next_hop_ip
=
htonl
(
inet_addr
(
executeCommand
(
command
).
c_str
()));
uint32_t
nextHopIp
=
htonl
(
inet_addr
(
CmdRunner
::
exec
(
cmd
).
c_str
()));
if
(
!
next
_hop_i
p
)
{
if
(
!
next
HopI
p
)
{
Logger
::
upf_app
().
error
(
"The Next Hop IPv4 WAS NOT Retrieved"
);
throw
std
::
runtime_error
(
"The Next Hop IPv4 WAS NOT Retrieved"
);
}
return
next
_hop_i
p
;
return
next
HopI
p
;
}
/*---------------------------------------------------------------------------------------------------------------*/
ether_addr
*
NextHopFinder
::
retrieveNextHopMAC
(
uint32_t
next_hop_ip
)
{
char
command
[
COMMAND_MAX_LENGTH
];
ether_addr
*
NextHopFinder
::
retrieveNextHopMAC
(
uint32_t
nextHopIp
)
{
std
::
string
cmd
=
{};
struct
in_addr
addr
=
{.
s_addr
=
nextHopIp
};
char
*
ipAddress
=
inet_ntoa
(
addr
);
std
::
string
nextHopMac
=
{};
struct
in_addr
addr
;
addr
.
s_addr
=
next_hop_ip
;
char
*
ipAddress
=
inet_ntoa
(
addr
);
if
(
ipAddress
==
nullptr
)
{
Logger
::
upf_app
().
error
(
"The Next Hop IPv4 WAS NOT Retrieved"
);
throw
std
::
runtime_error
(
"The Next Hop IPv4 WAS NOT Retrieved"
);
if
(
ipAddress
)
{
cmd
=
fmt
::
format
(
"sudo arping -c 1 {} | awk '/from/ {{print $4}}'"
,
ipAddress
);
}
sprintf
(
command
,
"sudo arping -c 1 %s | awk '/from/ {print $4}'"
,
ipAddress
);
// Logger::upf_app().debug("Next Hop SRC IP = %s", ipAddress);
Logger
::
upf_app
().
debug
(
"Next Hop <SRC IP, MAC Address> = <%s, %s>"
,
ipAddress
,
executeCommand
(
command
).
c_str
());
ether_addr
*
next_hop_mac
=
{};
next_hop_mac
=
ether_aton
(
executeCommand
(
command
).
c_str
());
nextHopMac
=
CmdRunner
::
exec
(
cmd
);
if
(
next
_hop_mac
==
nullptr
)
{
if
(
next
HopMac
.
empty
()
)
{
Logger
::
upf_app
().
error
(
"The Next Hop MAC WAS NOT Retrieved"
);
throw
std
::
runtime_error
(
"The Next Hop MAC WAS NOT Retrieved"
);
}
return
next_hop_mac
;
}
/*---------------------------------------------------------------------------------------------------------------*/
std
::
string
NextHopFinder
::
executeCommand
(
const
std
::
string
&
command
)
{
char
output
[
OUTPUT_MAX_LENGTH
];
FILE
*
fp
=
popen
(
command
.
c_str
(),
"r"
);
if
(
fp
==
nullptr
)
{
Logger
::
upf_app
().
error
(
"Failed to Run the Command: %s
\n
"
,
command
.
c_str
());
return
""
;
}
Logger
::
upf_app
().
debug
(
"Next Hop <SRC IP, MAC Address> = <%s, %s>"
,
ipAddress
,
nextHopMac
);
fgets
(
output
,
OUTPUT_MAX_LENGTH
,
fp
);
pclose
(
fp
);
return
output
;
return
ether_aton
(
nextHopMac
.
c_str
());
}
/*---------------------------------------------------------------------------------------------------------------*/
src/upf_app/helpers/NextHopFinder.hpp
View file @
aa2a83ae
...
...
@@ -2,21 +2,21 @@
#define NEXT_HOP_FINDER_HPP
#include <string>
#include <memory>
//
#include <memory>
#include <netinet/ether.h>
#include "logger.hpp"
class
NextHopFinder
{
public:
NextHopFinder
();
uint32_t
retrieveNextHopIP
(
uint32_t
destination_ip_
);
ether_addr
*
retrieveNextHopMAC
(
uint32_t
next_hop_ip_
);
int
calculateSubnetMask
(
uint32_t
ip
);
int
sameSubnet
(
uint32_t
ip1
,
uint32_t
ip2
);
//
NextHopFinder();
static
uint32_t
retrieveNextHopIP
(
uint32_t
destination_ip_
);
static
ether_addr
*
retrieveNextHopMAC
(
uint32_t
next_hop_ip_
);
static
int
calculateSubnetMask
(
uint32_t
ip
);
static
int
sameSubnet
(
uint32_t
ip1
,
uint32_t
ip2
);
private:
std
::
string
executeCommand
(
const
std
::
string
&
command
);
//
private:
//
std::string executeCommand(const std::string& command);
};
#endif // NEXT_HOP_FINDER_HPP
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment