SST 15.0
Structural Simulation Toolkit
randomDrop.h
1// Copyright 2009-2025 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-2025, 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/threadsafe.h"
18#include "sst/core/timeVortex.h"
19
20#include <sst/core/rng/marsaglia.h>
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 propability"
33 )
34
35 SST_ELI_DOCUMENT_PARAMS(
36 { "drop_prob", "Probability to drop event", "0.01" },
37 { "drop_on_send", "Controls whether to drop packetes 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 explicit RandomDrop(Params& params);
43
44 // For serialization only
45 RandomDrop() = default;
46 ~RandomDrop();
47
48 uintptr_t registerLinkAttachTool(const AttachPointMetaData& mdata) override;
49 void eventSent(uintptr_t key, Event*& ev) override;
50
51 uintptr_t registerHandlerIntercept(const AttachPointMetaData& mdata) override;
52 void interceptHandler(uintptr_t key, Event*& data, bool& cancel) override;
53
54 /**
55 Called to determine if the PortModule should be installed on
56 receives
57
58 @return true if PortModule should be installed on receives
59 */
60 bool installOnReceive() override { return !drop_on_send_; }
61
62 /**
63 Called to determine if the PortModule should be installed on
64 sends. NOTE: Install PortModules on sends will have a
65 noticeable impact on performance, consider architecting things
66 so that you can intercept on receives.
67
68 @return true if PortModule should be installed on sends
69 */
70 bool installOnSend() override { return drop_on_send_; }
71
72
73protected:
74 void serialize_order(SST::Core::Serialization::serializer& ser) override;
75 ImplementSerializable(SST::IMPL::PortModule::RandomDrop);
76
77private:
78 double drop_prob_ = 0.01;
79 bool verbose_ = false;
80 bool drop_on_send_ = false;
82
83 // String will store information about component and port names if
84 // verbose is turned on.
85 std::string* print_info_ = nullptr;
86};
87
88} // namespace SST::IMPL::PortModule
89
90#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:45
Base class for Events - Items sent across links to communicate between components.
Definition event.h:35
Definition randomDrop.h:25
bool installOnSend() override
Called to determine if the PortModule should be installed on sends.
Definition randomDrop.h:70
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:51
uintptr_t registerLinkAttachTool(const AttachPointMetaData &mdata) override
Function that will be called when a PortModule is registered on sends (i.e.
Definition randomDrop.cc:40
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:77
bool installOnReceive() override
Called to determine if the PortModule should be installed on receives.
Definition randomDrop.h:60
uintptr_t registerHandlerIntercept(const AttachPointMetaData &mdata) override
Function that will be called when a handler is registered with recieves (i.e.
Definition randomDrop.cc:66
Parameter store.
Definition params.h:58
PortModules are modules that can be attached to the send and/or receive side of ports.
Definition portModule.h:46
Implements a random number generator using the Marsaglia method.
Definition marsaglia.h:40
Struct used as a base class for all AttachPoint metadata passed to registration functions.
Definition sst_types.h:73