11#include "ns3/nstime.h"
12#include "ns3/q2nsviz-trace-writer.h"
13#include <initializer_list>
37template <
typename... Ts>
inline std::string
StrCat(Ts&&... parts) {
38 std::ostringstream _oss;
39 (void) std::initializer_list<int>{((_oss << std::forward<Ts>(parts)), 0)...};
44 return ns3::Simulator::Now().GetNanoSeconds();
54 <<
"\"type\":\"createNode\",\"t_ns\":0,"
55 <<
"\"label\":" <<
J(label) <<
",\"x\":" << xPct <<
",\"y\":" << yPct <<
"}";
60 const std::string& kind) {
63 <<
"\"type\":\"createChannel\",\"t_ns\":0,"
64 <<
"\"from\":" <<
J(from) <<
",\"to\":" <<
J(to) <<
",\"kind\":" <<
J(kind) <<
"}";
71inline void TraceCreateBit(
const std::string& node,
const std::string& bitLabel,
72 const std::string& kind,
const std::string& color) {
75 <<
"\"type\":\"createBit\",\"t_ns\":" <<
JTns() <<
",\"node\":" <<
J(node)
76 <<
",\"label\":" <<
J(bitLabel) <<
",\"kind\":" <<
J(kind) <<
",\"color\":" <<
J(color) <<
"}";
83 <<
"\"type\":\"setBitColor\",\"t_ns\":" <<
JTns() <<
",\"bit\":" <<
J(bitLabel)
84 <<
",\"color\":" <<
J(color) <<
"}";
91 <<
"\"type\":\"entangle\",\"t_ns\":" <<
JTns() <<
",\"bits\":[";
92 for (
size_t i = 0; i < bits.size(); ++i) {
103inline void TraceEntangle(
const std::vector<std::string>& bits, uint64_t duration_ns) {
104 std::ostringstream o;
106 <<
"\"type\":\"entangle\",\"t_ns\":" <<
JTns() <<
",\"duration_ns\":" << duration_ns
108 for (
size_t i = 0; i < bits.size(); ++i) {
116inline void TraceEntangle(
const std::vector<std::string>& bits, ns3::Time duration) {
122inline void TraceMeasure(
const std::string& bitLabel,
const std::string& base =
"Z") {
123 std::ostringstream o;
125 <<
"\"type\":\"measure\",\"t_ns\":" <<
JTns() <<
",\"bit\":" <<
J(bitLabel)
126 <<
",\"base\":" <<
J(base) <<
"}";
132inline void TraceMeasure(
const std::string& bitLabel, uint64_t duration_ns,
133 const std::string& base =
"Z") {
134 std::ostringstream o;
136 <<
"\"type\":\"measure\",\"t_ns\":" <<
JTns() <<
",\"duration_ns\":" << duration_ns
137 <<
",\"bit\":" <<
J(bitLabel) <<
",\"base\":" <<
J(base) <<
"}";
140inline void TraceMeasure(
const std::string& bitLabel, ns3::Time duration,
141 const std::string& base =
"Z") {
142 TraceMeasure(bitLabel, duration.GetNanoSeconds(), base);
147 const std::string& supportNode =
"") {
148 std::ostringstream o;
150 <<
"\"type\":\"graphMeasure\",\"t_ns\":" <<
JTns() <<
",\"bit\":" <<
J(bitLabel)
151 <<
",\"base\":" <<
J(base);
152 if (!supportNode.empty()) {
153 o <<
",\"supportNode\":" <<
J(supportNode);
162 const std::string& base =
"Z",
163 const std::string& supportNode =
"") {
164 std::ostringstream o;
166 <<
"\"type\":\"graphMeasure\",\"t_ns\":" <<
JTns() <<
",\"duration_ns\":" << duration_ns
167 <<
",\"bit\":" <<
J(bitLabel) <<
",\"base\":" <<
J(base);
168 if (!supportNode.empty()) {
169 o <<
",\"supportNode\":" <<
J(supportNode);
175 const std::string& base =
"Z",
176 const std::string& supportNode =
"") {
181 std::ostringstream o;
183 <<
"\"type\":\"removeBit\","
184 <<
"\"t_ns\":" << t_ns <<
",\"bit\":" <<
J(bitLabel) <<
"}";
192inline void TraceSendBit(
const std::string& bitLabel,
const std::string& from,
193 const std::string& to,
const std::string& kind, uint64_t t0_ns,
195 std::ostringstream o;
197 <<
"\"type\":\"sendBit\",\"t0_ns\":" << t0_ns <<
",\"t1_ns\":" << t1_ns
198 <<
",\"bit\":" <<
J(bitLabel) <<
",\"from\":" <<
J(from) <<
",\"to\":" <<
J(to)
199 <<
",\"kind\":" <<
J(kind) <<
"}";
202inline void TraceSendBit(
const std::string& bitLabel,
const std::string& from,
203 const std::string& to,
const std::string& kind, ns3::Time t0,
205 TraceSendBit(bitLabel, from, to, kind, t0.GetNanoSeconds(), t1.GetNanoSeconds());
208inline void TraceSendPacket(
const std::string& from,
const std::string& to, uint64_t t0_ns,
209 uint64_t t1_ns,
const std::string& label) {
210 std::ostringstream o;
212 <<
"\"type\":\"sendPacket\",\"t0_ns\":" << t0_ns <<
",\"t1_ns\":" << t1_ns
213 <<
",\"from\":" <<
J(from) <<
",\"to\":" <<
J(to) <<
",\"label\":" <<
J(label) <<
"}";
216inline void TraceSendPacket(
const std::string& from,
const std::string& to, ns3::Time t0,
217 ns3::Time t1,
const std::string& label) {
218 TraceSendPacket(from, to, t0.GetNanoSeconds(), t1.GetNanoSeconds(), label);
225 std::ostringstream o;
227 <<
"\"type\":\"traceText\",\"t_ns\":" <<
JTns() <<
",\"text\":" <<
J(text) <<
"}";
231inline void Trace(
const std::string& text) {
235template <
typename... Ts>
inline void Trace(Ts&&... parts) {
240 std::ostringstream o;
242 <<
"\"type\":\"traceText\",\"t_ns\":" <<
JTns() <<
",\"node\":" <<
J(node)
243 <<
",\"text\":" <<
J(text) <<
"}";
247inline void TraceNodeText(
const std::string& node,
const std::string& text) {
251template <
typename... Ts>
inline void TraceNodeText(
const std::string& node, Ts&&... parts) {
static TraceWriter & Instance()
void Write(const std::string &line)
std::string J(const std::string &s)
std::string StrCat(Ts &&... parts)
void Trace(const std::string &text)
void TraceNodeText(const std::string &node, const std::string &text)
void TraceEntangle(const std::vector< std::string > &bits)
void TraceRemoveBit(const std::string &bitLabel, uint64_t t_ns=NowNs())
void TraceSendPacket(const std::string &from, const std::string &to, uint64_t t0_ns, uint64_t t1_ns, const std::string &label)
void TraceCreateBit(const std::string &node, const std::string &bitLabel, const std::string &kind, const std::string &color)
void TraceMeasure(const std::string &bitLabel, const std::string &base="Z")
void TraceGraphMeasure(const std::string &bitLabel, const std::string &base="Z", const std::string &supportNode="")
void TraceCreateNode(const std::string &label, int xPct, int yPct)
void TraceCreateChannel(const std::string &from, const std::string &to, const std::string &kind)
void _TraceString(const std::string &text)
void TraceSendBit(const std::string &bitLabel, const std::string &from, const std::string &to, const std::string &kind, uint64_t t0_ns, uint64_t t1_ns)
void _TraceNodeTextString(const std::string &node, const std::string &text)
void TraceSetBitColor(const std::string &bitLabel, const std::string &color)