Skip to content

Commit

Permalink
Add NETSIMULYZER_PRE_NS3_41_ENUM_VALUE option & pre ns-3.41 enum co…
Browse files Browse the repository at this point in the history
…mpatibility

See: #38
  • Loading branch information
bpe2 committed May 1, 2024
1 parent 02db71d commit 466e6bb
Show file tree
Hide file tree
Showing 10 changed files with 161 additions and 44 deletions.
32 changes: 32 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,38 @@
# cause risk of injury or damage to property. The software developed by NIST
# employees is not subject to copyright protection within the United States.

option(NETSIMULYZER_PRE_NS3_41_ENUM_VALUE "Force compatibility with ns-3 versions before ns-3.41" OFF)

# ns-3.41 is tagged at e5039092b3bb5d7942d973cc1016eaa60bdce51c
#
# Note: This doesn't handle squash merges, or some other
# way out there out of tree stuff
# See: `NETSIMULYZER_PRE_NS3_41_ENUM_VALUE` option for that
execute_process(COMMAND "git" "merge-base" "--is-ancestor" "e5039092b3bb5d7942d973cc1016eaa60bdce51c" "HEAD"
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
RESULT_VARIABLE NETSIMULYZER_USE_ENUM_COMPAT
)

# Handling for if `git` is not installed
# Hope this string is well defined...
if (${NETSIMULYZER_USE_ENUM_COMPAT} STREQUAL "no such file or directory")
# Huge hack for tar ball ns-3 installs
# If they don't have `grep` either,
# then I'm out of options
execute_process(COMMAND "grep" "-w" "EnumValue(int value)" "src/core/model/enum.h"
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
RESULT_VARIABLE NETSIMULYZER_USE_ENUM_COMPAT_GREP)
# `grep` returns `0` on match
if (${NETSIMULYZER_USE_ENUM_COMPAT_GREP} EQUAL 0)
set(NETSIMULYZER_USE_ENUM_COMPAT 1)
endif ()
endif ()

if (${NETSIMULYZER_PRE_NS3_41_ENUM_VALUE} OR ${NETSIMULYZER_USE_ENUM_COMPAT} EQUAL 1)
add_compile_definitions(NETSIMULYZER_PRE_NS3_41_ENUM_VALUE)
endif ()


build_lib(
LIBNAME netsimulyzer
SOURCE_FILES
Expand Down
22 changes: 20 additions & 2 deletions model/ecdf-sink.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,22 +85,29 @@ EcdfSink::GetTypeId(void)
.AddAttribute("Connection",
"Type of connection to form between points in the series",
EnumValue(XYSeries::ConnectionType::Line),
#ifndef NETSIMULYZER_PRE_NS3_41_ENUM_VALUE
MakeEnumAccessor<XYSeries::ConnectionType>(&EcdfSink::SetConnectionType,
&EcdfSink::GetConnectionType),
#else
MakeEnumAccessor(&EcdfSink::SetConnectionType,
&EcdfSink::GetConnectionType),
#endif
MakeEnumChecker(
XYSeries::ConnectionType::None, "None",
XYSeries::ConnectionType::Line, "Line",
XYSeries::ConnectionType::Spline, "Spline"))
// Keep clang-format off
.AddAttribute("FlushMode",
"When to write the changes to the graph",
EnumValue(EcdfSink::FlushMode::OnWrite),
#ifndef NETSIMULYZER_PRE_NS3_41_ENUM_VALUE
MakeEnumAccessor<EcdfSink::FlushMode>(&EcdfSink::SetFlushMode, &EcdfSink::GetFlushMode),
#else
MakeEnumAccessor(&EcdfSink::SetFlushMode, &EcdfSink::GetFlushMode),
#endif
MakeEnumChecker(
EcdfSink::FlushMode::OnWrite, "OnWrite",
EcdfSink::FlushMode::Interval, "Interval",
EcdfSink::FlushMode::Manual,"Manual"))
// clang-format on
.AddAttribute("Interval",
"The interval to update the plot. "
"Only used when the `FlushMode` attribute is set to `Interval`",
Expand Down Expand Up @@ -165,10 +172,17 @@ EcdfSink::SetFlushMode(EcdfSink::FlushMode mode)
XYSeries::ConnectionType
EcdfSink::GetConnectionType(void) const
{
#ifndef NETSIMULYZER_PRE_NS3_41_ENUM_VALUE
EnumValue<XYSeries::ConnectionType> connectionType;
m_series->GetAttribute("Connection", connectionType);

return connectionType.Get();
#else
EnumValue connectionType;
m_series->GetAttribute("Connection", connectionType);

return static_cast<XYSeries::ConnectionType>(connectionType.Get());
#endif
}

void
Expand Down Expand Up @@ -233,7 +247,11 @@ EcdfSink::Flush(void)
m_series->Clear();
double total = 0.0;

#ifndef NETSIMULYZER_PRE_NS3_41_ENUM_VALUE
EnumValue<XYSeries::ConnectionType> connectionMode;
#else
EnumValue connectionMode;
#endif
m_series->GetAttribute("Connection", connectionMode);

if (connectionMode.Get() == XYSeries::ConnectionType::None)
Expand Down
2 changes: 1 addition & 1 deletion model/ecdf-sink.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,6 @@ class EcdfSink : public Object
double m_totalPoints{0.0};
};

} // namespace ns3
} // namespace ns3::netsimulyzer

#endif // ECDF_SINK_H
25 changes: 24 additions & 1 deletion model/orchestrator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,19 @@ makeAxisAttributes(ns3::Ptr<ns3::netsimulyzer::ValueAxis> axis)
axis->GetAttribute("Maximum", max);
element["max"] = max.Get();

#ifndef NETSIMULYZER_PRE_NS3_41_ENUM_VALUE
ns3::EnumValue<ns3::netsimulyzer::ValueAxis::Scale> scaleMode;
#else
ns3::EnumValue scaleMode;
#endif
axis->GetAttribute("Scale", scaleMode);
element["scale"] = ScaleToString(scaleMode.Get());

#ifndef NETSIMULYZER_PRE_NS3_41_ENUM_VALUE
ns3::EnumValue<ns3::netsimulyzer::ValueAxis::BoundMode> boundMode;
#else
ns3::EnumValue boundMode;
#endif
axis->GetAttribute("BoundMode", boundMode);
element["bound-mode"] = BoundModeToString(boundMode.Get());

Expand Down Expand Up @@ -656,7 +664,11 @@ Orchestrator::SetupSimulation(void)
area->GetAttribute("Height", height);
element["height"] = height.Get();

#ifndef NETSIMULYZER_PRE_NS3_41_ENUM_VALUE
EnumValue<RectangularArea::DrawMode> fillMode;
#else
EnumValue fillMode;
#endif
area->GetAttribute("Fill", fillMode);

switch (fillMode.Get())
Expand All @@ -672,7 +684,11 @@ Orchestrator::SetupSimulation(void)
break;
}

#ifndef NETSIMULYZER_PRE_NS3_41_ENUM_VALUE
EnumValue<RectangularArea::DrawMode> borderMode;
#else
EnumValue borderMode;
#endif
area->GetAttribute("Border", borderMode);

switch (borderMode.Get())
Expand Down Expand Up @@ -1107,8 +1123,11 @@ Orchestrator::Commit(XYSeries& series)
series.GetAttribute("Visible", visible);
element["visible"] = visible.Get();

#ifndef NETSIMULYZER_PRE_NS3_41_ENUM_VALUE
EnumValue<XYSeries::ConnectionType> connection;
series.GetAttribute("Connection", connection);
#else
EnumValue connection;
#endif
switch (connection.Get())
{
case XYSeries::ConnectionType::None:
Expand Down Expand Up @@ -1140,7 +1159,11 @@ Orchestrator::Commit(XYSeries& series)
break;
}

#ifndef NETSIMULYZER_PRE_NS3_41_ENUM_VALUE
EnumValue<XYSeries::LabelMode> labelMode;
#else
EnumValue labelMode;
#endif
series.GetAttribute("LabelMode", labelMode);
switch (labelMode.Get())
{
Expand Down
8 changes: 8 additions & 0 deletions model/rectangular-area.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,20 @@ RectangularArea::GetTypeId(void)
.AddAttribute("Border",
"How to draw the border of the area",
EnumValue(DrawMode::Solid),
#ifndef NETSIMULYZER_PRE_NS3_41_ENUM_VALUE
MakeEnumAccessor<DrawMode>(&RectangularArea::m_borderMode),
#else
MakeEnumAccessor(&RectangularArea::m_borderMode),
#endif
MakeEnumChecker(DrawMode::Solid, "Solid", DrawMode::Hidden, "Hidden"))
.AddAttribute("Fill",
"How to draw the body of the area",
EnumValue(DrawMode::Hidden),
#ifndef NETSIMULYZER_PRE_NS3_41_ENUM_VALUE
MakeEnumAccessor<DrawMode>(&RectangularArea::m_fillMode),
#else
MakeEnumAccessor(&RectangularArea::m_fillMode),
#endif
MakeEnumChecker(DrawMode::Solid, "Solid", DrawMode::Hidden, "Hidden"))
.AddAttribute("Name",
"Name to represent this area in visualizer elements",
Expand Down
50 changes: 30 additions & 20 deletions model/state-transition-sink.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,39 +75,50 @@ StateTransitionSink::StateTransitionSink(Ptr<Orchestrator> orchestrator,
TypeId
StateTransitionSink::GetTypeId(void)
{
static TypeId tid = TypeId("ns3::netsimulyzer::StateTransitionSink")
.SetParent<ns3::Object>()
.SetGroupName("netsimulyzer")
.AddAttribute("Name",
"Set the names for sub-elements",
StringValue(),
MakeStringAccessor(&StateTransitionSink::SetNames),
MakeStringChecker())
.AddAttribute("Series",
"The series tracking the application state",
PointerValue(),
MakePointerAccessor(&StateTransitionSink::m_series),
MakePointerChecker<CategoryValueSeries>())
.AddAttribute("Log",
"The Log Stream that this helper writes to",
PointerValue(),
MakePointerAccessor(&StateTransitionSink::m_log),
MakePointerChecker<LogStream>())
// clang-format off
static TypeId tid =
TypeId("ns3::netsimulyzer::StateTransitionSink")
.SetParent<ns3::Object>()
.SetGroupName("netsimulyzer")
.AddAttribute("Name",
"Set the names for sub-elements",
StringValue(),
MakeStringAccessor(&StateTransitionSink::SetNames),
MakeStringChecker())
.AddAttribute("Series",
"The series tracking the application state",
PointerValue(),
MakePointerAccessor(&StateTransitionSink::m_series),
MakePointerChecker<CategoryValueSeries>())
.AddAttribute("Log",
"The Log Stream that this helper writes to",
PointerValue(),
MakePointerAccessor(&StateTransitionSink::m_log),
MakePointerChecker<LogStream>())
.AddAttribute("LoggingMode",
"Mode for connecting points within the series",
EnumValue(LoggingMode::StateChanges),
#ifndef NETSIMULYZER_PRE_NS3_41_ENUM_VALUE
MakeEnumAccessor<LoggingMode>(&StateTransitionSink::SetLoggingMode,
&StateTransitionSink::GetLoggingMode),
#else
MakeEnumAccessor(&StateTransitionSink::SetLoggingMode,
&StateTransitionSink::GetLoggingMode),
#endif

MakeEnumChecker(
LoggingMode::StateChanges, "StateChanges",
LoggingMode::All, "All",
LoggingMode::None, "None"))
.AddAttribute("TimeUnit",
"The unit of time to use for the X axis",
EnumValue(Time::S),
#ifndef NETSIMULYZER_PRE_NS3_41_ENUM_VALUE
MakeEnumAccessor<Time::Unit>(&StateTransitionSink::SetTimeUnit,
&StateTransitionSink::GetTimeUnit),
#else
MakeEnumAccessor(&StateTransitionSink::SetTimeUnit,
&StateTransitionSink::GetTimeUnit),
#endif
MakeEnumChecker(
Time::Unit::Y, "Year",
Time::Unit::D, "Day",
Expand All @@ -120,7 +131,6 @@ StateTransitionSink::GetTypeId(void)
Time::Unit::PS, "Picosecond",
Time::Unit::FS,"Femtosecond"));

// clang-format on
return tid;
}

Expand Down
41 changes: 25 additions & 16 deletions model/throughput-sink.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,25 +69,29 @@ ThroughputSink::ThroughputSink(Ptr<Orchestrator> orchestrator, const std::string
TypeId
ThroughputSink::GetTypeId(void)
{
static TypeId tid = TypeId("ns3::netsimulyzer::ThroughputSink")
.SetParent<ns3::Object>()
.SetGroupName("netsimulyzer")
.AddAttribute("XYSeries",
"The XY Series",
TypeId::ATTR_GET,
PointerValue(),
MakePointerAccessor(&ThroughputSink::GetSeries),
MakePointerChecker<XYSeries>())
.AddAttribute("Interval",
"Time between updates",
TimeValue(Seconds(1)),
MakeTimeAccessor(&ThroughputSink::SetInterval),
MakeTimeChecker())
// clang-format off
static TypeId tid =
TypeId("ns3::netsimulyzer::ThroughputSink")
.SetParent<ns3::Object>()
.SetGroupName("netsimulyzer")
.AddAttribute("XYSeries",
"The XY Series",
TypeId::ATTR_GET,
PointerValue(),
MakePointerAccessor(&ThroughputSink::GetSeries),
MakePointerChecker<XYSeries>())
.AddAttribute("Interval",
"Time between updates",
TimeValue(Seconds(1)),
MakeTimeAccessor(&ThroughputSink::SetInterval),
MakeTimeChecker())
.AddAttribute("Unit",
"The unit for the throughput plot",
EnumValue(ThroughputSink::Unit::KBit),
#ifndef NETSIMULYZER_PRE_NS3_41_ENUM_VALUE
MakeEnumAccessor<ThroughputSink::Unit>(&ThroughputSink::SetUnit),
#else
MakeEnumAccessor(&ThroughputSink::SetUnit),
#endif
MakeEnumChecker(
ThroughputSink::Bit, "b/s",
ThroughputSink::KBit, "kb/s",
Expand All @@ -100,8 +104,14 @@ ThroughputSink::GetTypeId(void)
.AddAttribute("TimeUnit",
"The unit of time to use for the X axis",
EnumValue(Time::S),

#ifndef NETSIMULYZER_PRE_NS3_41_ENUM_VALUE
MakeEnumAccessor<Time::Unit>(&ThroughputSink::SetTimeUnit,
&ThroughputSink::GetTimeUnit),
#else
MakeEnumAccessor(&ThroughputSink::SetTimeUnit,
&ThroughputSink::GetTimeUnit),
#endif
MakeEnumChecker(
Time::Unit::Y, "Year",
Time::Unit::D, "Day",
Expand All @@ -114,7 +124,6 @@ ThroughputSink::GetTypeId(void)
Time::Unit::PS, "Picosecond",
Time::Unit::FS, "Femtosecond"));

// clang-format on
return tid;
}

Expand Down
10 changes: 9 additions & 1 deletion model/value-axis.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,27 @@ ValueAxis::GetTypeId(void)
.AddAttribute("BoundMode",
"How the boundaries of the axis may move given a new value",
EnumValue(ValueAxis::BoundMode::HighestValue),
#ifndef NETSIMULYZER_PRE_NS3_41_ENUM_VALUE
MakeEnumAccessor<BoundMode>(&ValueAxis::m_boundMode),
#else
MakeEnumAccessor(&ValueAxis::m_boundMode),
#endif
// clang-format off
MakeEnumChecker(
BoundMode::Fixed, "Fixed",
BoundMode::HighestValue, "HighestValue"))
.AddAttribute("Scale",
"The method to scale between tick marks on the axis",
EnumValue(ValueAxis::Scale::Linear),
#ifndef NETSIMULYZER_PRE_NS3_41_ENUM_VALUE
MakeEnumAccessor<Scale>(&ValueAxis::m_scale),
#else
MakeEnumAccessor(&ValueAxis::m_scale),
#endif
MakeEnumChecker(
ValueAxis::Linear, "Linear",
ValueAxis::Logarithmic, "Logarithmic"));
// clang-format on
// clang-format on

return tid;
}
Expand Down
Loading

0 comments on commit 466e6bb

Please sign in to comment.