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
8c217ae8
Commit
8c217ae8
authored
Feb 14, 2021
by
aligungr
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
JSON utility improvement
parent
dc9aaded
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
73 additions
and
89 deletions
+73
-89
src/gnb/app/cmd_handler.cpp
src/gnb/app/cmd_handler.cpp
+12
-25
src/gnb/types.cpp
src/gnb/types.cpp
+20
-19
src/gnb/types.hpp
src/gnb/types.hpp
+4
-5
src/ue/app/cmd_handler.cpp
src/ue/app/cmd_handler.cpp
+12
-16
src/ue/mm/base.cpp
src/ue/mm/base.cpp
+6
-6
src/ue/types.cpp
src/ue/types.cpp
+4
-4
src/ue/types.hpp
src/ue/types.hpp
+6
-5
src/utils/common_types.cpp
src/utils/common_types.cpp
+5
-5
src/utils/common_types.hpp
src/utils/common_types.hpp
+4
-4
No files found.
src/gnb/app/cmd_handler.cpp
View file @
8c217ae8
...
...
@@ -92,19 +92,18 @@ void GnbCmdHandler::HandleCmdImpl(TaskBase &base, NwGnbCliCommand &msg)
switch
(
msg
.
cmd
->
present
)
{
case
app
:
:
GnbCliCommand
::
STATUS
:
{
msg
.
sendResult
(
base
.
appTask
->
m_statusInfo
.
toString
());
msg
.
sendResult
(
ToJson
(
base
.
appTask
->
m_statusInfo
).
dumpYaml
());
break
;
}
case
app
:
:
GnbCliCommand
::
INFO
:
{
msg
.
sendResult
(
base
.
config
->
toString
());
msg
.
sendResult
(
ToJson
(
*
base
.
config
).
dumpYaml
());
break
;
}
case
app
:
:
GnbCliCommand
::
AMF_LIST
:
{
std
::
stringstream
ss
{}
;
Json
json
=
Json
::
Arr
({})
;
for
(
auto
&
amf
:
base
.
ngapTask
->
m_amfCtx
)
ss
<<
"- ID["
<<
amf
.
first
<<
"]
\n
"
;
utils
::
Trim
(
ss
);
msg
.
sendResult
(
ss
.
str
());
json
.
push
(
Json
::
Obj
({{
"id"
,
amf
.
first
}}));
msg
.
sendResult
(
json
.
dumpYaml
());
break
;
}
case
app
:
:
GnbCliCommand
::
AMF_INFO
:
{
...
...
@@ -113,33 +112,21 @@ void GnbCmdHandler::HandleCmdImpl(TaskBase &base, NwGnbCliCommand &msg)
else
{
auto
amf
=
base
.
ngapTask
->
m_amfCtx
[
msg
.
cmd
->
amfId
];
Printer
printer
{};
printer
.
appendKeyValue
({
{
"address"
,
amf
->
address
},
{
"port"
,
std
::
to_string
(
amf
->
port
)},
{
"name"
,
amf
->
amfName
},
{
"capacity"
,
std
::
to_string
(
amf
->
relativeCapacity
)},
{
"state"
,
EnumToString
(
amf
->
state
)},
});
printer
.
trim
();
msg
.
sendResult
(
printer
.
makeString
());
msg
.
sendResult
(
ToJson
(
*
amf
).
dumpYaml
());
}
break
;
}
case
app
:
:
GnbCliCommand
::
UE_LIST
:
{
Printer
printer
{}
;
Json
json
=
Json
::
Arr
({})
;
for
(
auto
&
ue
:
base
.
ngapTask
->
m_ueCtx
)
{
printer
.
appendKeyValueList
({
json
.
push
(
Json
::
Obj
({
{
"ue-name"
,
base
.
mrTask
->
m_ueMap
[
ue
.
first
].
name
},
{
"ran-ngap-id"
,
std
::
to_string
(
ue
.
second
->
ranUeNgapId
)},
{
"amf-ngap-id"
,
std
::
to_string
(
ue
.
second
->
amfUeNgapId
)},
});
printer
.
decrement
(
2
);
{
"ran-ngap-id"
,
ue
.
second
->
ranUeNgapId
},
{
"amf-ngap-id"
,
ue
.
second
->
amfUeNgapId
},
}));
}
printer
.
trim
();
msg
.
sendResult
(
printer
.
makeString
());
msg
.
sendResult
(
json
.
dumpYaml
());
break
;
}
case
app
:
:
GnbCliCommand
::
UE_COUNT
:
{
...
...
src/gnb/types.cpp
View file @
8c217ae8
...
...
@@ -14,31 +14,32 @@
namespace
nr
::
gnb
{
std
::
string
GnbStatusInfo
::
toString
()
const
Json
ToJson
(
const
GnbStatusInfo
&
v
)
{
Printer
printer
{};
printer
.
appendKeyValue
({{
"is-ngap-up"
,
this
->
isNgapUp
?
"true"
:
"false"
}});
printer
.
trim
();
return
printer
.
makeString
();
return
Json
::
Obj
({{
"is-ngap-up"
,
v
.
isNgapUp
}});
}
std
::
string
GnbConfig
::
toString
()
const
Json
ToJson
(
const
GnbConfig
&
v
)
{
Printer
printer
{};
printer
.
appendKeyValue
({
{
"nci"
,
std
::
to_string
(
this
->
nci
)},
{
"gnb-id"
,
std
::
to_string
(
this
->
getGnbId
())},
{
"cell-id"
,
std
::
to_string
(
this
->
getCellId
())},
{
"mcc"
,
std
::
to_string
(
this
->
plmn
.
mcc
)},
{
"mnc"
,
std
::
to_string
(
this
->
plmn
.
mnc
)},
{
"tac"
,
std
::
to_string
(
this
->
tac
)},
{
"name"
,
this
->
name
},
return
Json
::
Obj
({
{
"nci"
,
v
.
nci
},
{
"plmn"
,
ToJson
(
v
.
plmn
)},
{
"tac"
,
v
.
tac
},
{
"name"
,
v
.
name
},
});
printer
.
trim
();
return
printer
.
makeString
();
}
const
char
*
EnumToString
(
EAmfState
v
)
Json
ToJson
(
const
NgapAmfContext
&
v
)
{
return
Json
::
Obj
({
{
"name"
,
v
.
amfName
},
{
"capacity"
,
v
.
relativeCapacity
},
{
"state"
,
ToJson
(
v
.
state
).
str
()},
{
"address"
,
v
.
address
+
":"
+
std
::
to_string
(
v
.
port
)},
});
}
Json
ToJson
(
const
EAmfState
&
v
)
{
switch
(
v
)
{
...
...
@@ -49,7 +50,7 @@ const char *EnumToString(EAmfState v)
case
EAmfState
:
:
CONNECTED
:
return
"CONNECTED"
;
default:
return
"
<?>
"
;
return
"
?
"
;
}
}
...
...
src/gnb/types.hpp
View file @
8c217ae8
...
...
@@ -219,8 +219,6 @@ struct PduSessionResource
struct
GnbStatusInfo
{
bool
isNgapUp
;
[[
nodiscard
]]
std
::
string
toString
()
const
;
};
struct
GtpUeContext
...
...
@@ -278,8 +276,6 @@ struct GnbConfig
{
return
static_cast
<
int
>
(
nci
&
static_cast
<
uint64_t
>
((
1
<<
(
36
-
gnbIdLength
))
-
1
));
}
[[
nodiscard
]]
std
::
string
toString
()
const
;
};
struct
TaskBase
...
...
@@ -302,6 +298,9 @@ struct MrUeContext
std
::
string
name
;
};
const
char
*
EnumToString
(
EAmfState
v
);
Json
ToJson
(
const
GnbStatusInfo
&
v
);
Json
ToJson
(
const
GnbConfig
&
v
);
Json
ToJson
(
const
NgapAmfContext
&
v
);
Json
ToJson
(
const
EAmfState
&
v
);
}
// namespace nr::gnb
\ No newline at end of file
src/ue/app/cmd_handler.cpp
View file @
8c217ae8
...
...
@@ -83,27 +83,23 @@ void UeCmdHandler::HandleCmdImpl(TaskBase &base, NwUeCliCommand &msg)
switch
(
msg
.
cmd
->
present
)
{
case
app
:
:
UeCliCommand
::
STATUS
:
{
Printer
printer
{};
printer
.
appendKeyValue
({
{
"cm-state"
,
nr
::
ue
::
CmStateName
(
base
.
nasTask
->
mm
->
m_cmState
)},
{
"rm-state"
,
nr
::
ue
::
RmStateName
(
base
.
nasTask
->
mm
->
m_rmState
)},
{
"mm-state"
,
nr
::
ue
::
MmSubStateName
(
base
.
nasTask
->
mm
->
m_mmSubState
)},
{
"sim-inserted"
,
base
.
nasTask
->
mm
->
m_validSim
?
"true"
:
"false"
},
Json
json
=
Json
::
Obj
({
{
"cm-state"
,
ToJson
(
base
.
nasTask
->
mm
->
m_cmState
)},
{
"rm-state"
,
ToJson
(
base
.
nasTask
->
mm
->
m_rmState
)},
{
"mm-state"
,
ToJson
(
base
.
nasTask
->
mm
->
m_mmSubState
)},
{
"sim-inserted"
,
base
.
nasTask
->
mm
->
m_validSim
},
});
printer
.
trim
();
msg
.
sendResult
(
printer
.
makeString
());
msg
.
sendResult
(
json
.
dumpYaml
());
break
;
}
case
app
:
:
UeCliCommand
::
INFO
:
{
Printer
printer
{};
printer
.
appendKeyValue
({
{
"supi"
,
base
.
config
->
supi
.
has_value
()
?
base
.
config
->
supi
->
toString
()
:
""
},
{
"plmn"
,
base
.
config
->
plmn
.
toString
()},
{
"imei"
,
base
.
config
->
imei
.
has_value
()
?
*
base
.
config
->
imei
:
""
},
{
"imeisv"
,
base
.
config
->
imeiSv
.
has_value
()
?
*
base
.
config
->
imeiSv
:
""
},
Json
json
=
Json
::
Obj
({
{
"supi"
,
ToJson
(
base
.
config
->
supi
)},
{
"plmn"
,
ToJson
(
base
.
config
->
plmn
)},
{
"imei"
,
::
ToJson
(
base
.
config
->
imei
)},
{
"imeisv"
,
::
ToJson
(
base
.
config
->
imeiSv
)},
});
printer
.
trim
();
msg
.
sendResult
(
printer
.
makeString
());
msg
.
sendResult
(
json
.
dumpYaml
());
break
;
}
}
...
...
src/ue/mm/base.cpp
View file @
8c217ae8
...
...
@@ -115,13 +115,13 @@ void NasMm::switchMmState(EMmState state, EMmSubState subState)
if
(
m_base
->
nodeListener
)
{
m_base
->
nodeListener
->
onSwitch
(
app
::
NodeType
::
UE
,
m_base
->
config
->
getNodeName
(),
app
::
StateType
::
MM
,
MmSubStateName
(
oldSubState
),
MmSubStateName
(
subState
));
ToJson
(
oldSubState
).
str
(),
ToJson
(
subState
).
str
(
));
m_base
->
nodeListener
->
onSwitch
(
app
::
NodeType
::
UE
,
m_base
->
config
->
getNodeName
(),
app
::
StateType
::
MM_SUB
,
MmStateName
(
oldState
),
MmStateName
(
state
));
ToJson
(
oldState
).
str
(),
ToJson
(
state
).
str
(
));
}
if
(
state
!=
oldState
||
subState
!=
oldSubState
)
m_logger
->
info
(
"UE switches to state: %s"
,
MmSubStateName
(
subState
));
m_logger
->
info
(
"UE switches to state: %s"
,
ToJson
(
subState
).
str
().
c_str
(
));
triggerMmCycle
();
}
...
...
@@ -136,7 +136,7 @@ void NasMm::switchRmState(ERmState state)
if
(
m_base
->
nodeListener
)
{
m_base
->
nodeListener
->
onSwitch
(
app
::
NodeType
::
UE
,
m_base
->
config
->
getNodeName
(),
app
::
StateType
::
RM
,
RmStateName
(
oldState
),
RmStateName
(
m_rmState
));
ToJson
(
oldState
).
str
(),
ToJson
(
m_rmState
).
str
(
));
}
// No need to log it
...
...
@@ -155,11 +155,11 @@ void NasMm::switchCmState(ECmState state)
if
(
m_base
->
nodeListener
)
{
m_base
->
nodeListener
->
onSwitch
(
app
::
NodeType
::
UE
,
m_base
->
config
->
getNodeName
(),
app
::
StateType
::
CM
,
CmStateName
(
oldState
),
CmStateName
(
m_cmState
));
ToJson
(
oldState
).
str
(),
ToJson
(
m_cmState
).
str
(
));
}
if
(
state
!=
oldState
)
m_logger
->
info
(
"UE switches to state: %s"
,
CmStateName
(
state
));
m_logger
->
info
(
"UE switches to state: %s"
,
ToJson
(
state
).
str
().
c_str
(
));
triggerMmCycle
();
}
...
...
src/ue/types.cpp
View file @
8c217ae8
...
...
@@ -22,7 +22,7 @@ UeTimers::UeTimers()
{
}
const
char
*
CmStateName
(
ECmState
state
)
Json
ToJson
(
ECmState
state
)
{
switch
(
state
)
{
...
...
@@ -35,7 +35,7 @@ const char *CmStateName(ECmState state)
}
}
const
char
*
RmStateName
(
ERmState
state
)
Json
ToJson
(
ERmState
state
)
{
switch
(
state
)
{
...
...
@@ -48,7 +48,7 @@ const char *RmStateName(ERmState state)
}
}
const
char
*
MmStateName
(
EMmState
state
)
Json
ToJson
(
EMmState
state
)
{
switch
(
state
)
{
...
...
@@ -69,7 +69,7 @@ const char *MmStateName(EMmState state)
}
}
const
char
*
MmSubStateName
(
EMmSubState
state
)
Json
ToJson
(
EMmSubState
state
)
{
switch
(
state
)
{
...
...
src/ue/types.hpp
View file @
8c217ae8
...
...
@@ -12,6 +12,7 @@
#include <nas/nas.hpp>
#include <nas/timer.hpp>
#include <utils/common_types.hpp>
#include <utils/json.hpp>
#include <utils/logger.hpp>
#include <utils/nts.hpp>
#include <utils/octet_string.hpp>
...
...
@@ -71,7 +72,7 @@ struct UeConfig
[[
nodiscard
]]
std
::
string
getNodeName
()
const
{
if
(
supi
.
has_value
())
return
supi
->
toString
();
return
ToJson
(
supi
).
str
();
if
(
imei
.
has_value
())
return
"imei-"
+
*
imei
;
if
(
imeiSv
.
has_value
())
...
...
@@ -358,9 +359,9 @@ struct UeStatusInfo
std
::
optional
<
UePduSessionInfo
>
pduSessions
[
16
]{};
};
const
char
*
CmStateName
(
ECmState
state
);
const
char
*
RmStateName
(
ERmState
state
);
const
char
*
MmStateName
(
EMmState
state
);
const
char
*
MmSubStateName
(
EMmSubState
state
);
Json
ToJson
(
ECmState
state
);
Json
ToJson
(
ERmState
state
);
Json
ToJson
(
EMmState
state
);
Json
ToJson
(
EMmSubState
state
);
}
// namespace nr::ue
src/utils/common_types.cpp
View file @
8c217ae8
...
...
@@ -25,15 +25,15 @@ Supi Supi::Parse(const std::string &supi)
throw
std
::
runtime_error
(
"invalid SUPI value"
);
}
std
::
string
Supi
::
toString
()
const
Json
ToJson
(
const
Supi
&
v
)
{
return
type
+
"-"
+
value
;
return
v
.
type
+
"-"
+
v
.
value
;
}
std
::
string
Plmn
::
toString
()
const
Json
ToJson
(
const
Plmn
&
v
)
{
std
::
stringstream
ss
{};
ss
<<
std
::
setfill
(
'0'
)
<<
std
::
setw
(
3
)
<<
mcc
<<
"/"
;
ss
<<
std
::
setfill
(
'0'
)
<<
std
::
setw
(
isLongMnc
?
3
:
2
)
<<
mnc
;
ss
<<
std
::
setfill
(
'0'
)
<<
std
::
setw
(
3
)
<<
v
.
mcc
<<
"/"
;
ss
<<
std
::
setfill
(
'0'
)
<<
std
::
setw
(
v
.
isLongMnc
?
3
:
2
)
<<
v
.
mnc
;
return
ss
.
str
();
}
src/utils/common_types.hpp
View file @
8c217ae8
...
...
@@ -8,6 +8,7 @@
#pragma once
#include "json.hpp"
#include "octet.hpp"
#include <memory>
#include <optional>
...
...
@@ -27,8 +28,6 @@ struct Plmn
int
mcc
;
int
mnc
;
bool
isLongMnc
;
[[
nodiscard
]]
std
::
string
toString
()
const
;
};
struct
SliceSupport
...
...
@@ -117,6 +116,7 @@ struct Supi
}
static
Supi
Parse
(
const
std
::
string
&
supi
);
};
[[
nodiscard
]]
std
::
string
toString
()
const
;
};
\ No newline at end of file
Json
ToJson
(
const
Supi
&
v
);
Json
ToJson
(
const
Plmn
&
v
);
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