Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
U
UERANSIM
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
Libraries
UERANSIM
Commits
003d7e9d
Commit
003d7e9d
authored
Nov 25, 2021
by
Louis Royer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allows to use IPv6 addresses for UE to gNB link
parent
d571ed87
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
112 additions
and
16 deletions
+112
-16
src/gnb.cpp
src/gnb.cpp
+1
-1
src/lib/udp/server.cpp
src/lib/udp/server.cpp
+27
-8
src/lib/udp/server.hpp
src/lib/udp/server.hpp
+4
-3
src/utils/io.cpp
src/utils/io.cpp
+30
-0
src/utils/io.hpp
src/utils/io.hpp
+2
-0
src/utils/network.cpp
src/utils/network.cpp
+24
-2
src/utils/network.hpp
src/utils/network.hpp
+5
-2
src/utils/yaml_utils.cpp
src/utils/yaml_utils.cpp
+18
-0
src/utils/yaml_utils.hpp
src/utils/yaml_utils.hpp
+1
-0
No files found.
src/gnb.cpp
View file @
003d7e9d
...
...
@@ -48,7 +48,7 @@ static nr::gnb::GnbConfig *ReadConfigYaml()
result
->
gnbIdLength
=
yaml
::
GetInt32
(
config
,
"idLength"
,
22
,
32
);
result
->
tac
=
yaml
::
GetInt32
(
config
,
"tac"
,
0
,
0xFFFFFF
);
result
->
portalIp
=
yaml
::
GetIp
4
(
config
,
"linkIp"
);
result
->
portalIp
=
yaml
::
GetIp
(
config
,
"linkIp"
);
result
->
ngapIp
=
yaml
::
GetIp4
(
config
,
"ngapIp"
);
result
->
gtpIp
=
yaml
::
GetIp4
(
config
,
"gtpIp"
);
...
...
src/lib/udp/server.cpp
View file @
003d7e9d
...
...
@@ -9,31 +9,50 @@
#include "server.hpp"
#include <cstring>
#include <utils/common.hpp>
namespace
udp
{
UdpServer
::
UdpServer
()
:
socket
{
Socket
::
CreateUdp4
()
}
UdpServer
::
UdpServer
()
:
sockets
{
}
{
sockets
.
push_back
(
Socket
::
CreateUdp6
());
sockets
.
push_back
(
Socket
::
CreateUdp4
());
}
UdpServer
::
UdpServer
(
const
std
::
string
&
address
,
uint16_t
port
)
:
socket
{
Socket
::
CreateAndBindUdp
({
address
,
port
})
}
UdpServer
::
UdpServer
(
const
std
::
string
&
address
,
uint16_t
port
)
:
sockets
{
}
{
sockets
.
push_back
(
Socket
::
CreateAndBindUdp
({
address
,
port
}));
}
int
UdpServer
::
Receive
(
uint8_t
*
buffer
,
size_t
bufferSize
,
int
timeoutMs
,
InetAddress
&
outPeerAddress
)
const
int
UdpServer
::
Receive
(
uint8_t
*
buffer
,
size_t
bufferSize
,
int
timeoutMs
,
InetAddress
&
outPeerAddress
)
{
return
socket
.
receive
(
buffer
,
bufferSize
,
timeoutMs
,
outPeerAddress
);
// Use the first socket ready for receiving data
// Warning: this may lead to starvation since there is no round robin implemented yet in `Socket::Select`
std
::
vector
<
Socket
>
ws
;
return
Socket
::
Select
(
sockets
,
ws
,
timeoutMs
).
receive
(
buffer
,
bufferSize
,
0
,
outPeerAddress
);
}
void
UdpServer
::
Send
(
const
InetAddress
&
address
,
const
uint8_t
*
buffer
,
size_t
bufferSize
)
const
int
UdpServer
::
Send
(
const
InetAddress
&
address
,
const
uint8_t
*
buffer
,
size_t
bufferSize
)
const
{
socket
.
send
(
address
,
buffer
,
bufferSize
);
int
version
=
address
.
getIpVersion
();
// invalid family
if
(
!
version
)
return
-
1
;
// send on first socket matching ip version
for
(
const
Socket
&
s
:
sockets
)
{
if
(
s
.
getIpVersion
()
==
version
)
return
s
.
send
(
address
,
buffer
,
bufferSize
);
}
// no socket found
return
-
1
;
}
UdpServer
::~
UdpServer
()
{
socket
.
close
();
for
(
Socket
&
s
:
sockets
)
s
.
close
();
}
}
// namespace udp
src/lib/udp/server.hpp
View file @
003d7e9d
...
...
@@ -9,6 +9,7 @@
#pragma once
#include <string>
#include <unistd.h>
#include <utils/network.hpp>
...
...
@@ -18,15 +19,15 @@ namespace udp
class
UdpServer
{
private:
Socket
socket
;
std
::
vector
<
Socket
>
sockets
;
public:
UdpServer
();
UdpServer
(
const
std
::
string
&
address
,
uint16_t
port
);
~
UdpServer
();
int
Receive
(
uint8_t
*
buffer
,
size_t
bufferSize
,
int
timeoutMs
,
InetAddress
&
outPeerAddress
)
const
;
void
Send
(
const
InetAddress
&
address
,
const
uint8_t
*
buffer
,
size_t
bufferSize
)
const
;
int
Receive
(
uint8_t
*
buffer
,
size_t
bufferSize
,
int
timeoutMs
,
InetAddress
&
outPeerAddress
);
int
Send
(
const
InetAddress
&
address
,
const
uint8_t
*
buffer
,
size_t
bufferSize
)
const
;
};
}
// namespace udp
src/utils/io.cpp
View file @
003d7e9d
...
...
@@ -219,6 +219,36 @@ std::string GetIp4OfInterface(const std::string &ifName)
return
std
::
string
{
str
};
}
std
::
string
GetIp6OfInterface
(
const
std
::
string
&
ifName
)
{
std
::
string
res
;
struct
ifreq
ifr
=
{};
int
fd
=
socket
(
AF_INET6
,
SOCK_DGRAM
,
0
);
if
(
fd
<=
0
)
return
""
;
ifr
.
ifr_addr
.
sa_family
=
AF_INET6
;
strncpy
(
ifr
.
ifr_name
,
ifName
.
c_str
(),
IFNAMSIZ
-
1
);
if
(
ioctl
(
fd
,
SIOCGIFADDR
,
&
ifr
))
{
close
(
fd
);
return
""
;
}
close
(
fd
);
auto
address
=
((
struct
sockaddr_in
*
)
&
ifr
.
ifr_addr
)
->
sin_addr
;
char
str
[
INET6_ADDRSTRLEN
]
=
{
0
};
if
(
inet_ntop
(
AF_INET6
,
&
address
,
str
,
INET6_ADDRSTRLEN
)
==
nullptr
)
return
""
;
return
std
::
string
{
str
};
}
std
::
string
GetHostByName
(
const
std
::
string
&
name
)
{
struct
addrinfo
hints
=
{};
...
...
src/utils/io.hpp
View file @
003d7e9d
...
...
@@ -42,6 +42,8 @@ void AppendPath(std::string &source, const std::string &target);
std
::
string
GetIp4OfInterface
(
const
std
::
string
&
ifName
);
std
::
string
GetIp6OfInterface
(
const
std
::
string
&
ifName
);
std
::
string
GetHostByName
(
const
std
::
string
&
name
);
}
// namespace io
src/utils/network.cpp
View file @
003d7e9d
...
...
@@ -78,7 +78,7 @@ InetAddress::InetAddress(const std::string &address, uint16_t port) : storage{},
if
(
s
!=
0
)
throw
LibError
(
"Bad Inet address: "
+
address
,
errno
);
if
(
result
->
ai_family
!=
AF_INET
&&
result
->
ai_family
=
=
AF_INET6
)
if
(
result
->
ai_family
!=
AF_INET
&&
result
->
ai_family
!
=
AF_INET6
)
{
freeaddrinfo
(
result
);
throw
std
::
runtime_error
(
"Bad Inet address: "
+
address
);
...
...
@@ -89,6 +89,16 @@ InetAddress::InetAddress(const std::string &address, uint16_t port) : storage{},
freeaddrinfo
(
result
);
}
int
InetAddress
::
getIpVersion
()
const
{
if
(
storage
.
ss_family
==
AF_INET
)
return
4
;
else
if
(
storage
.
ss_family
==
AF_INET6
)
return
6
;
else
return
0
;
}
InetAddress
::
InetAddress
(
const
OctetString
&
address
,
uint16_t
port
)
:
InetAddress
(
OctetStringToIpString
(
address
),
port
)
{
}
...
...
@@ -111,6 +121,7 @@ uint16_t InetAddress::getPort() const
Socket
::
Socket
(
int
domain
,
int
type
,
int
protocol
)
{
int
sd
=
socket
(
domain
,
type
,
protocol
);
socketDomain
=
domain
;
if
(
sd
<
0
)
throw
LibError
(
"Socket could not be created:"
,
errno
);
this
->
fd
=
sd
;
...
...
@@ -185,7 +196,7 @@ int Socket::receive(uint8_t *buffer, size_t bufferSize, int timeoutMs, InetAddre
return
0
;
}
void
Socket
::
send
(
const
InetAddress
&
address
,
const
uint8_t
*
buffer
,
size_t
size
)
const
int
Socket
::
send
(
const
InetAddress
&
address
,
const
uint8_t
*
buffer
,
size_t
size
)
const
{
ssize_t
rc
=
sendto
(
fd
,
buffer
,
size
,
MSG_DONTWAIT
,
address
.
getSockAddr
(),
address
.
getSockLen
());
if
(
rc
==
-
1
)
...
...
@@ -194,6 +205,7 @@ void Socket::send(const InetAddress &address, const uint8_t *buffer, size_t size
if
(
err
!=
EAGAIN
)
throw
LibError
(
"sendto failed: "
,
errno
);
}
return
rc
;
}
bool
Socket
::
hasFd
()
const
...
...
@@ -297,3 +309,13 @@ InetAddress Socket::getAddress() const
return
InetAddress
(
storage
,
len
);
}
int
Socket
::
getIpVersion
()
const
{
if
(
socketDomain
==
AF_INET6
)
return
6
;
else
if
(
socketDomain
==
AF_INET
)
return
4
;
else
return
0
;
}
src/utils/network.hpp
View file @
003d7e9d
...
...
@@ -38,6 +38,7 @@ struct InetAddress
return
len
;
}
[[
nodiscard
]]
int
getIpVersion
()
const
;
[[
nodiscard
]]
uint16_t
getPort
()
const
;
};
...
...
@@ -45,6 +46,7 @@ class Socket
{
private:
int
fd
;
int
socketDomain
;
public:
Socket
();
...
...
@@ -53,10 +55,11 @@ class Socket
public:
void
bind
(
const
InetAddress
&
address
)
const
;
int
receive
(
uint8_t
*
buffer
,
size_t
bufferSize
,
int
timeoutMs
,
InetAddress
&
outAddress
)
const
;
void
send
(
const
InetAddress
&
address
,
const
uint8_t
*
buffer
,
size_t
size
)
const
;
int
send
(
const
InetAddress
&
address
,
const
uint8_t
*
buffer
,
size_t
size
)
const
;
void
close
();
[[
nodiscard
]]
bool
hasFd
()
const
;
[[
nodiscard
]]
InetAddress
getAddress
()
const
;
[[
nodiscard
]]
int
getIpVersion
()
const
;
/* Socket options */
void
setReuseAddress
()
const
;
...
...
src/utils/yaml_utils.cpp
View file @
003d7e9d
...
...
@@ -158,6 +158,24 @@ std::string GetIp4(const YAML::Node &node, const std::string &name)
return
ipFromIf
;
}
std
::
string
GetIp
(
const
YAML
::
Node
&
node
,
const
std
::
string
&
name
)
{
std
::
string
s
=
GetString
(
node
,
name
);
int
version
=
utils
::
GetIpVersion
(
s
);
if
(
version
==
6
||
version
==
4
)
return
s
;
auto
ip4FromIf
=
io
::
GetIp4OfInterface
(
s
);
if
(
!
ip4FromIf
.
empty
())
return
ip4FromIf
;
auto
ip6FromIf
=
io
::
GetIp6OfInterface
(
s
);
if
(
!
ip6FromIf
.
empty
())
return
ip6FromIf
;
FieldError
(
name
,
"must be a valid IP address or a valid network interface with an IP address"
);
}
void
AssertHasBool
(
const
YAML
::
Node
&
node
,
const
std
::
string
&
name
)
{
AssertHasField
(
node
,
name
);
...
...
src/utils/yaml_utils.hpp
View file @
003d7e9d
...
...
@@ -42,6 +42,7 @@ std::string GetString(const YAML::Node &node, const std::string &name, std::opti
std
::
optional
<
int
>
maxLength
);
std
::
string
GetIp4
(
const
YAML
::
Node
&
node
,
const
std
::
string
&
name
);
std
::
string
GetIp
(
const
YAML
::
Node
&
node
,
const
std
::
string
&
name
);
bool
GetBool
(
const
YAML
::
Node
&
node
,
const
std
::
string
&
name
);
...
...
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