SST 16.0.0
Structural Simulation Toolkit
randomDrop.h
1// Copyright 2009-2026 NTESS. Under the terms
2// of Contract DE-NA0003525 with NTESS, the U.S.
3// Government retains certain rights in this software.
4//
5// Copyright (c) 2009-2026, NTESS
6// All rights reserved.
7//
8// This file is part of the SST software package. For license
9// information, see the LICENSE file in the top level directory of the
10// distribution.
11
12#ifndef SST_CORE_IMPL_PORTMODULE_RANDOMDROP_H
13#define SST_CORE_IMPL_PORTMODULE_RANDOMDROP_H
14
15#include "sst/core/eli/elementinfo.h"
16#include "sst/core/portModule.h"
17#include "sst/core/rng/marsaglia.h"
18
19#include <cstdint>
20#include <string>
21
22namespace SST::IMPL::PortModule {
23
24class RandomDrop : public SST::PortModule
25{
26public:
27 SST_ELI_REGISTER_PORTMODULE(
28 RandomDrop,
29 "sst",
30 "portmodules.random_drop",
31 SST_ELI_ELEMENT_VERSION(0, 1, 0),
32 "Port module that will randomly drop events based on specified probability"
33 )
34
35 SST_ELI_DOCUMENT_PARAMS(
36 { "drop_prob", "Probability to drop event", "0.01" },
37 { "drop_on_send", "Controls whether to drop packets during the send versus the default of on the receive", "false" },
38 { "rngseed", "Set a seed for the random number generator used to control drops", "7" },
39 { "verbose", "Debugging output", "false"}
40 )
41
42 SST_ELI_DOCUMENT_STATISTICS(
43 { "dropped", "Counts number of events that are dropped", "events", 1},
44 { "observed", "Counts number of events that are observed, including any dropped", "events", 1}
45 )
46
47 explicit RandomDrop(Params& params);
48
49 // For serialization only
50 RandomDrop() = default;
51 ~RandomDrop();
52
53 uintptr_t registerLinkAttachTool(const AttachPointMetaData& mdata) override;
54 void eventSent(uintptr_t key, Event*& ev) override;
55
56 uintptr_t registerHandlerIntercept(const AttachPointMetaData& mdata) override;
57 void interceptHandler(uintptr_t key, Event*& data, bool& cancel) override;
58
59 /**
60 Called to determine if the PortModule should be installed on
61 receives
62
63 @return true if PortModule should be installed on receives
64 */
65 bool installOnReceive() override { return !drop_on_send_; }
66
67 /**
68 Called to determine if the PortModule should be installed on
69 sends. NOTE: Install PortModules on sends will have a
70 noticeable impact on performance, consider architecting things
71 so that you can intercept on receives.
72
73 @return true if PortModule should be installed on sends
74 */
75 bool installOnSend() override { return drop_on_send_; }
76
77
78protected:
79 void serialize_order(SST::Core::Serialization::serializer& ser) override;
80 ImplementSerializable(SST::IMPL::PortModule::RandomDrop);
81
82private:
83 double drop_prob_ = 0.01;
84 bool verbose_ = false;
85 bool drop_on_send_ = false;
87
88 // String will store information about component and port names if
89 // verbose is turned on.
90 std::string* print_info_ = nullptr;
91
92 Statistic<uint64_t>* stat_dropped_ = nullptr;
93 Statistic<uint64_t>* stat_observed_ = nullptr;
94};
95
96} // namespace SST::IMPL::PortModule
97
98#endif // SST_CORE_IMPL_PORTMODULE_RANDOMDROP_H
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition serializer.h:43
Base class for Events - Items sent across links to communicate between components.
Definition event.h:41
Definition randomDrop.h:25
bool installOnSend() override
Called to determine if the PortModule should be installed on sends.
Definition randomDrop.h:75
void eventSent(uintptr_t key, Event *&ev) override
Function that will be called when an event is sent on a link with registered PortModules.
Definition randomDrop.cc:54
uintptr_t registerLinkAttachTool(const AttachPointMetaData &mdata) override
Function that will be called when a PortModule is registered on sends (i.e.
Definition randomDrop.cc:43
void interceptHandler(uintptr_t key, Event *&data, bool &cancel) override
Function that will be called before the event handler to let the attach point intercept the data.
Definition randomDrop.cc:81
bool installOnReceive() override
Called to determine if the PortModule should be installed on receives.
Definition randomDrop.h:65
uintptr_t registerHandlerIntercept(const AttachPointMetaData &mdata) override
Function that will be called when a handler is registered with recieves (i.e.
Definition randomDrop.cc:70
Parameter store.
Definition params.h:65
PortModules are modules that can be attached to the send and/or receive side of ports.
Definition portModule.h:54
Implements a random number generator using the Marsaglia method.
Definition marsaglia.h:41
Forms the template defined base class for statistics gathering within SST.
Definition statbase.h:369
Struct used as a base class for all AttachPoint metadata passed to registration functions.
Definition sst_types.h:201