Skip to content

Commit ff4fb88

Browse files
committed
common: Added seq NED function that generate integers incrementally.
This can be used in a packet source packetInterval parameter, for example, to generate packets according to a specific schedule.
1 parent 672f396 commit ff4fb88

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

src/inet/common/NedFunctions.cc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,25 @@ Define_NED_Function2(nedf_getId,
311311
"ned",
312312
"Returns the id of the module or channel in context.")
313313

314+
cNEDValue nedf_seq(cComponent *context, cNEDValue argv[], int argc)
315+
{
316+
static int handle = cSimulationOrSharedDataManager::registerSharedVariableName("inet::NedFunctions::seq");
317+
auto& seqs = getSimulationOrSharedDataManager()->getSharedVariable<std::map<std::string, int>>(handle);
318+
auto key = argv[0].stringValue();
319+
auto it = seqs.find(key);
320+
if (it == seqs.end())
321+
seqs[key] = 0;
322+
else
323+
seqs[key]++;
324+
return cNEDValue(seqs[key]);
325+
}
326+
327+
Define_NED_Function2(nedf_seq,
328+
"int seq(string id)",
329+
"misc",
330+
"Returns the next integer (starting from 0) associated to the first argument which must be a string."
331+
);
332+
314333
} // namespace utils
315334

316335
} // namespace inet

0 commit comments

Comments
 (0)