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
28c8124e
Commit
28c8124e
authored
Sep 29, 2021
by
aligungr
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
RNG improvements and fix of initial ID conflict
parent
04a4dbbb
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
153 additions
and
26 deletions
+153
-26
src/lib/app/proc_table.cpp
src/lib/app/proc_table.cpp
+16
-1
src/ue/rls/task.cpp
src/ue/rls/task.cpp
+3
-2
src/ue/rrc/connection.cpp
src/ue/rrc/connection.cpp
+2
-1
src/utils/common.cpp
src/utils/common.cpp
+0
-21
src/utils/common.hpp
src/utils/common.hpp
+0
-1
src/utils/random.cpp
src/utils/random.cpp
+84
-0
src/utils/random.hpp
src/utils/random.hpp
+48
-0
No files found.
src/lib/app/proc_table.cpp
View file @
28c8124e
...
...
@@ -20,10 +20,25 @@
#include <utils/common.hpp>
#include <utils/constants.hpp>
#include <utils/io.hpp>
#include <utils/random.hpp>
namespace
app
{
static
std
::
string
RandomFileName
(
const
std
::
vector
<
std
::
string
>
&
nodes
,
int
cmdPort
)
{
std
::
string
s
;
for
(
auto
&
node
:
nodes
)
{
s
+=
node
;
s
+=
"|"
;
}
s
+=
std
::
to_string
(
cmdPort
);
Random
rnd
=
Random
::
Mixed
(
s
);
return
utils
::
IntToHex
(
rnd
.
nextL
())
+
utils
::
IntToHex
(
rnd
.
nextL
());
}
void
CreateProcTable
(
const
std
::
vector
<
std
::
string
>
&
nodes
,
int
cmdPort
)
{
try
...
...
@@ -33,7 +48,7 @@ void CreateProcTable(const std::vector<std::string> &nodes, int cmdPort)
std
::
string
filePath
;
while
(
true
)
{
std
::
string
fileName
=
utils
::
IntToHex
(
utils
::
Random64
())
+
utils
::
IntToHex
(
utils
::
Random64
()
);
std
::
string
fileName
=
RandomFileName
(
nodes
,
cmdPort
);
filePath
=
cons
::
PROC_TABLE_DIR
+
fileName
;
if
(
!
io
::
Exists
(
filePath
))
...
...
src/ue/rls/task.cpp
View file @
28c8124e
...
...
@@ -13,6 +13,7 @@
#include <ue/rrc/task.hpp>
#include <utils/common.hpp>
#include <utils/constants.hpp>
#include <utils/random.hpp>
namespace
nr
::
ue
{
...
...
@@ -22,7 +23,7 @@ UeRlsTask::UeRlsTask(TaskBase *base) : m_base{base}
m_logger
=
m_base
->
logBase
->
makeUniqueLogger
(
m_base
->
config
->
getLoggerPrefix
()
+
"rls"
);
m_shCtx
=
new
RlsSharedContext
();
m_shCtx
->
sti
=
utils
::
Random64
();
m_shCtx
->
sti
=
Random
::
Mixed
(
base
->
config
->
getNodeName
()).
nextL
();
m_udpTask
=
new
RlsUdpTask
(
base
,
m_shCtx
,
base
->
config
->
gnbSearchList
);
m_ctlTask
=
new
RlsControlTask
(
base
,
m_shCtx
);
...
...
@@ -108,7 +109,7 @@ void UeRlsTask::onLoop()
break
;
}
case
NmUeRrcToRls
:
:
RESET_STI
:
{
m_shCtx
->
sti
=
utils
::
Random64
();
m_shCtx
->
sti
=
Random
::
Mixed
(
m_base
->
config
->
getNodeName
()).
nextL
();
break
;
}
}
...
...
src/ue/rrc/connection.cpp
View file @
28c8124e
...
...
@@ -11,6 +11,7 @@
#include <lib/rrc/encode.hpp>
#include <ue/nas/task.hpp>
#include <ue/nts.hpp>
#include <utils/random.hpp>
#include <asn/rrc/ASN_RRC_RRCSetup-IEs.h>
#include <asn/rrc/ASN_RRC_RRCSetup.h>
...
...
@@ -58,7 +59,7 @@ void UeRrcTask::startConnectionEstablishment(OctetString &&nasPdu)
if
(
m_initialId
.
present
==
ASN_RRC_InitialUE_Identity_PR_NOTHING
)
{
m_initialId
.
present
=
ASN_RRC_InitialUE_Identity_PR_randomValue
;
asn
::
SetBitStringLong
<
39
>
(
static_cast
<
int64_t
>
(
utils
::
Random64
()
),
m_initialId
.
choice
.
randomValue
);
asn
::
SetBitStringLong
<
39
>
(
Random
::
Mixed
(
m_base
->
config
->
getNodeName
()).
nextL
(
),
m_initialId
.
choice
.
randomValue
);
}
m_initialNasPdu
=
std
::
move
(
nasPdu
);
...
...
src/utils/common.cpp
View file @
28c8124e
...
...
@@ -262,27 +262,6 @@ int utils::ParseInt(const char *str)
return
n
;
}
uint64_t
utils
::
Random64
()
{
static
bool
initiated
=
false
;
static
std
::
random_device
randomDevice
{};
static
std
::
mt19937_64
randomEngine
(
randomDevice
());
if
(
!
initiated
)
{
randomEngine
.
seed
(
std
::
chrono
::
high_resolution_clock
::
now
().
time_since_epoch
().
count
());
initiated
=
true
;
}
while
(
true
)
{
std
::
uniform_int_distribution
<
uint64_t
>
distribution
;
uint64_t
r
=
distribution
(
randomEngine
);
if
(
r
!=
0
)
return
r
;
}
}
void
utils
::
Sleep
(
int
ms
)
{
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
milliseconds
(
ms
));
...
...
src/utils/common.hpp
View file @
28c8124e
...
...
@@ -34,7 +34,6 @@ int ParseInt(const std::string &str);
int
ParseInt
(
const
char
*
str
);
bool
TryParseInt
(
const
std
::
string
&
str
,
int
&
output
);
bool
TryParseInt
(
const
char
*
str
,
int
&
output
);
uint64_t
Random64
();
void
Sleep
(
int
ms
);
bool
IsRoot
();
bool
IsNumeric
(
const
std
::
string
&
str
);
...
...
src/utils/random.cpp
0 → 100644
View file @
28c8124e
//
// This file is a part of UERANSIM open source project.
// Copyright (c) 2021 ALİ GÜNGÖR.
//
// The software and all associated files are licensed under GPL-3.0
// and subject to the terms and conditions defined in LICENSE file.
//
#include "random.hpp"
#include <atomic>
#include <chrono>
static
std
::
atomic
<
int64_t
>
s_counter
;
Random
::
Random
()
:
Random
(
std
::
chrono
::
high_resolution_clock
::
now
().
time_since_epoch
().
count
()
+
s_counter
++
)
{
}
Random
::
Random
(
int64_t
seed
)
:
m_seed
{
seed
}
{
}
int64_t
Random
::
nextL
()
{
m_seed
=
(
8253729LL
*
m_seed
+
2396403LL
);
m_seed
&=
0x7FFFFFFFFFFFFFFFLL
;
return
m_seed
;
}
int64_t
Random
::
nextL
(
int
end
)
{
return
nextL
()
%
static_cast
<
int64_t
>
(
end
);
}
int64_t
Random
::
nextL
(
int
start
,
int
end
)
{
return
nextL
(
end
-
start
)
+
start
;
}
uint64_t
Random
::
nextUL
()
{
return
static_cast
<
uint64_t
>
(
nextL
());
}
uint64_t
Random
::
nextUL
(
int
end
)
{
return
static_cast
<
uint64_t
>
(
nextL
(
end
));
}
uint64_t
Random
::
nextUL
(
int
start
,
int
end
)
{
return
static_cast
<
uint64_t
>
(
nextL
(
start
,
end
));
}
int32_t
Random
::
nextI
()
{
return
static_cast
<
int32_t
>
(
nextL
()
&
0x7FFFFFFFLL
);
}
int32_t
Random
::
nextI
(
int
end
)
{
return
static_cast
<
int32_t
>
(
nextL
(
end
)
&
0x7FFFFFFFLL
);
}
int32_t
Random
::
nextI
(
int
start
,
int
end
)
{
return
static_cast
<
int32_t
>
(
nextL
(
start
,
end
)
&
0x7FFFFFFFLL
);
}
uint32_t
Random
::
nextUI
()
{
return
static_cast
<
uint32_t
>
(
nextI
());
}
uint32_t
Random
::
nextUI
(
int
end
)
{
return
static_cast
<
uint32_t
>
(
nextI
(
end
));
}
uint32_t
Random
::
nextUI
(
int
start
,
int
end
)
{
return
static_cast
<
uint32_t
>
(
nextI
(
start
,
end
));
}
\ No newline at end of file
src/utils/random.hpp
0 → 100644
View file @
28c8124e
//
// This file is a part of UERANSIM open source project.
// Copyright (c) 2021 ALİ GÜNGÖR.
//
// The software and all associated files are licensed under GPL-3.0
// and subject to the terms and conditions defined in LICENSE file.
//
#pragma once
#include <cstdint>
#include <functional>
#include <string>
class
Random
{
private:
int64_t
m_seed
;
public:
Random
();
explicit
Random
(
int64_t
seed
);
int64_t
nextL
();
int64_t
nextL
(
int
end
);
int64_t
nextL
(
int
start
,
int
end
);
uint64_t
nextUL
();
uint64_t
nextUL
(
int
end
);
uint64_t
nextUL
(
int
start
,
int
end
);
int32_t
nextI
();
int32_t
nextI
(
int
end
);
int32_t
nextI
(
int
start
,
int
end
);
uint32_t
nextUI
();
uint32_t
nextUI
(
int
end
);
uint32_t
nextUI
(
int
start
,
int
end
);
template
<
typename
T
>
static
inline
Random
Mixed
(
const
T
&
v
)
{
auto
hash
=
static_cast
<
int64_t
>
(
std
::
hash
<
T
>
{}(
v
));
Random
r
;
r
.
m_seed
^=
hash
;
return
r
;
}
};
\ 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