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
6699b76d
Commit
6699b76d
authored
Dec 07, 2021
by
aligungr
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
IPv6 support
parent
3a9c992b
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
25 additions
and
27 deletions
+25
-27
src/lib/udp/server.cpp
src/lib/udp/server.cpp
+14
-12
src/lib/udp/server.hpp
src/lib/udp/server.hpp
+1
-1
src/utils/network.cpp
src/utils/network.cpp
+8
-10
src/utils/network.hpp
src/utils/network.hpp
+2
-2
src/utils/yaml_utils.cpp
src/utils/yaml_utils.cpp
+0
-2
No files found.
src/lib/udp/server.cpp
View file @
6699b76d
...
@@ -14,13 +14,13 @@
...
@@ -14,13 +14,13 @@
namespace
udp
namespace
udp
{
{
UdpServer
::
UdpServer
()
:
sockets
{}
UdpServer
::
UdpServer
()
:
sockets
{}
{
{
sockets
.
push_back
(
Socket
::
CreateUdp6
());
sockets
.
push_back
(
Socket
::
CreateUdp6
());
sockets
.
push_back
(
Socket
::
CreateUdp4
());
sockets
.
push_back
(
Socket
::
CreateUdp4
());
}
}
UdpServer
::
UdpServer
(
const
std
::
string
&
address
,
uint16_t
port
)
:
sockets
{}
UdpServer
::
UdpServer
(
const
std
::
string
&
address
,
uint16_t
port
)
:
sockets
{}
{
{
sockets
.
push_back
(
Socket
::
CreateAndBindUdp
({
address
,
port
}));
sockets
.
push_back
(
Socket
::
CreateAndBindUdp
({
address
,
port
}));
}
}
...
@@ -32,25 +32,27 @@ int UdpServer::Receive(uint8_t *buffer, size_t bufferSize, int timeoutMs, InetAd
...
@@ -32,25 +32,27 @@ int UdpServer::Receive(uint8_t *buffer, size_t bufferSize, int timeoutMs, InetAd
return
Socket
::
Select
(
sockets
,
ws
,
timeoutMs
).
receive
(
buffer
,
bufferSize
,
0
,
outPeerAddress
);
return
Socket
::
Select
(
sockets
,
ws
,
timeoutMs
).
receive
(
buffer
,
bufferSize
,
0
,
outPeerAddress
);
}
}
int
UdpServer
::
Send
(
const
InetAddress
&
address
,
const
uint8_t
*
buffer
,
size_t
bufferSize
)
const
void
UdpServer
::
Send
(
const
InetAddress
&
address
,
const
uint8_t
*
buffer
,
size_t
bufferSize
)
const
{
{
int
version
=
address
.
getIpVersion
();
int
version
=
address
.
getIpVersion
();
// invalid family
if
(
version
!=
4
&&
version
!=
6
)
if
(
!
version
)
throw
std
::
runtime_error
{
"UdpServer::Send failure: Invalid IP version on"
};
return
-
1
;
// send on first socket matching ip version
for
(
const
Socket
&
s
:
sockets
)
for
(
const
Socket
&
s
:
sockets
)
{
{
if
(
s
.
getIpVersion
()
==
version
)
if
(
s
.
getIpVersion
()
==
version
)
return
s
.
send
(
address
,
buffer
,
bufferSize
);
{
s
.
send
(
address
,
buffer
,
bufferSize
);
return
;
}
}
// no socket found
}
return
-
1
;
throw
std
::
runtime_error
{
"UdpServer::Send failure: No socket found"
};
}
}
UdpServer
::~
UdpServer
()
UdpServer
::~
UdpServer
()
{
{
for
(
Socket
&
s
:
sockets
)
for
(
auto
&
s
:
sockets
)
s
.
close
();
s
.
close
();
}
}
...
...
src/lib/udp/server.hpp
View file @
6699b76d
...
@@ -27,7 +27,7 @@ class UdpServer
...
@@ -27,7 +27,7 @@ class UdpServer
~
UdpServer
();
~
UdpServer
();
int
Receive
(
uint8_t
*
buffer
,
size_t
bufferSize
,
int
timeoutMs
,
InetAddress
&
outPeerAddress
);
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
;
void
Send
(
const
InetAddress
&
address
,
const
uint8_t
*
buffer
,
size_t
bufferSize
)
const
;
};
};
}
// namespace udp
}
// namespace udp
src/utils/network.cpp
View file @
6699b76d
...
@@ -122,10 +122,10 @@ uint16_t InetAddress::getPort() const
...
@@ -122,10 +122,10 @@ uint16_t InetAddress::getPort() const
Socket
::
Socket
(
int
domain
,
int
type
,
int
protocol
)
Socket
::
Socket
(
int
domain
,
int
type
,
int
protocol
)
{
{
int
sd
=
socket
(
domain
,
type
,
protocol
);
int
sd
=
socket
(
domain
,
type
,
protocol
);
socketDomain
=
domain
;
if
(
sd
<
0
)
if
(
sd
<
0
)
throw
LibError
(
"Socket could not be created:"
,
errno
);
throw
LibError
(
"Socket could not be created:"
,
errno
);
this
->
fd
=
sd
;
this
->
fd
=
sd
;
this
->
domain
=
domain
;
}
}
Socket
Socket
::
CreateUdp4
()
Socket
Socket
::
CreateUdp4
()
...
@@ -148,7 +148,7 @@ Socket Socket::CreateTcp6()
...
@@ -148,7 +148,7 @@ Socket Socket::CreateTcp6()
return
{
AF_INET6
,
SOCK_STREAM
,
IPPROTO_TCP
};
return
{
AF_INET6
,
SOCK_STREAM
,
IPPROTO_TCP
};
}
}
Socket
::
Socket
()
:
fd
(
-
1
)
Socket
::
Socket
()
:
fd
(
-
1
)
,
domain
(
0
)
{
{
}
}
...
@@ -197,7 +197,7 @@ int Socket::receive(uint8_t *buffer, size_t bufferSize, int timeoutMs, InetAddre
...
@@ -197,7 +197,7 @@ int Socket::receive(uint8_t *buffer, size_t bufferSize, int timeoutMs, InetAddre
return
0
;
return
0
;
}
}
int
Socket
::
send
(
const
InetAddress
&
address
,
const
uint8_t
*
buffer
,
size_t
size
)
const
void
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
());
ssize_t
rc
=
sendto
(
fd
,
buffer
,
size
,
MSG_DONTWAIT
,
address
.
getSockAddr
(),
address
.
getSockLen
());
if
(
rc
==
-
1
)
if
(
rc
==
-
1
)
...
@@ -206,7 +206,6 @@ int Socket::send(const InetAddress &address, const uint8_t *buffer, size_t size)
...
@@ -206,7 +206,6 @@ int Socket::send(const InetAddress &address, const uint8_t *buffer, size_t size)
if
(
err
!=
EAGAIN
)
if
(
err
!=
EAGAIN
)
throw
LibError
(
"sendto failed: "
,
errno
);
throw
LibError
(
"sendto failed: "
,
errno
);
}
}
return
rc
;
}
}
bool
Socket
::
hasFd
()
const
bool
Socket
::
hasFd
()
const
...
@@ -280,12 +279,12 @@ Socket Socket::Select(const std::vector<Socket> &readSockets, const std::vector<
...
@@ -280,12 +279,12 @@ Socket Socket::Select(const std::vector<Socket> &readSockets, const std::vector<
if
(
!
rs
.
empty
())
if
(
!
rs
.
empty
())
{
{
std
::
uniform_int_distribution
<
int
>
drs
(
0
,
rs
.
size
()
-
1
);
std
::
uniform_int_distribution
<
int
>
drs
(
0
,
rs
.
size
()
-
1
);
return
rs
[
drs
(
generator
)];
return
rs
[
drs
(
generator
)];
}
}
if
(
!
ws
.
empty
())
if
(
!
ws
.
empty
())
{
{
std
::
uniform_int_distribution
<
int
>
dws
(
0
,
ws
.
size
()
-
1
);
std
::
uniform_int_distribution
<
int
>
dws
(
0
,
ws
.
size
()
-
1
);
return
rs
[
dws
(
generator
)];
return
rs
[
dws
(
generator
)];
}
}
return
{};
return
{};
...
@@ -323,10 +322,9 @@ InetAddress Socket::getAddress() const
...
@@ -323,10 +322,9 @@ InetAddress Socket::getAddress() const
int
Socket
::
getIpVersion
()
const
int
Socket
::
getIpVersion
()
const
{
{
if
(
socketD
omain
==
AF_INET6
)
if
(
d
omain
==
AF_INET6
)
return
6
;
return
6
;
else
if
(
socketD
omain
==
AF_INET
)
if
(
d
omain
==
AF_INET
)
return
4
;
return
4
;
else
return
0
;
return
0
;
}
}
src/utils/network.hpp
View file @
6699b76d
...
@@ -46,7 +46,7 @@ class Socket
...
@@ -46,7 +46,7 @@ class Socket
{
{
private:
private:
int
fd
;
int
fd
;
int
socketD
omain
;
int
d
omain
;
public:
public:
Socket
();
Socket
();
...
@@ -55,7 +55,7 @@ class Socket
...
@@ -55,7 +55,7 @@ class Socket
public:
public:
void
bind
(
const
InetAddress
&
address
)
const
;
void
bind
(
const
InetAddress
&
address
)
const
;
int
receive
(
uint8_t
*
buffer
,
size_t
bufferSize
,
int
timeoutMs
,
InetAddress
&
outAddress
)
const
;
int
receive
(
uint8_t
*
buffer
,
size_t
bufferSize
,
int
timeoutMs
,
InetAddress
&
outAddress
)
const
;
int
send
(
const
InetAddress
&
address
,
const
uint8_t
*
buffer
,
size_t
size
)
const
;
void
send
(
const
InetAddress
&
address
,
const
uint8_t
*
buffer
,
size_t
size
)
const
;
void
close
();
void
close
();
[[
nodiscard
]]
bool
hasFd
()
const
;
[[
nodiscard
]]
bool
hasFd
()
const
;
[[
nodiscard
]]
InetAddress
getAddress
()
const
;
[[
nodiscard
]]
InetAddress
getAddress
()
const
;
...
...
src/utils/yaml_utils.cpp
View file @
6699b76d
...
@@ -158,7 +158,6 @@ std::string GetIp4(const YAML::Node &node, const std::string &name)
...
@@ -158,7 +158,6 @@ std::string GetIp4(const YAML::Node &node, const std::string &name)
return
ipFromIf
;
return
ipFromIf
;
}
}
std
::
string
GetIp
(
const
YAML
::
Node
&
node
,
const
std
::
string
&
name
)
std
::
string
GetIp
(
const
YAML
::
Node
&
node
,
const
std
::
string
&
name
)
{
{
std
::
string
s
=
GetString
(
node
,
name
);
std
::
string
s
=
GetString
(
node
,
name
);
...
@@ -173,7 +172,6 @@ std::string GetIp(const YAML::Node &node, const std::string & name)
...
@@ -173,7 +172,6 @@ std::string GetIp(const YAML::Node &node, const std::string & name)
if
(
!
ip6FromIf
.
empty
())
if
(
!
ip6FromIf
.
empty
())
return
ip6FromIf
;
return
ip6FromIf
;
FieldError
(
name
,
"must be a valid IP address or a valid network interface with an IP address"
);
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
)
void
AssertHasBool
(
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