SST  15.1.0
StructuralSimulationToolkit
coreTest_PortModule.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_CORETEST_PORTMODULE_H
13 #define SST_CORE_CORETEST_PORTMODULE_H
14 
15 #include "sst/core/component.h"
16 #include "sst/core/event.h"
17 #include "sst/core/subcomponent.h"
18 
19 namespace SST::CoreTestPortModule {
20 
21 class PortSubComponent;
22 
23 // Event passed between test components. The variable modified can
24 // be set to true as a test of modifying events in PortModules.
25 class PortModuleEvent : public Event
26 {
27 public:
28  bool modified = false;
29  bool last = false;
30 
31  void serialize_order(SST::Core::Serialization::serializer& ser) override
32  {
33  Event::serialize_order(ser);
34  SST_SER(modified);
35  SST_SER(last);
36  }
37 
38  ImplementSerializable(SST::CoreTestPortModule::PortModuleEvent);
39 };
40 
41 // Event that is created by a PortModule to notify the receiving
42 // component that the event was dropped
43 class PortModuleAckEvent : public Event
44 {
45 public:
46  void serialize_order(SST::Core::Serialization::serializer& ser) override { Event::serialize_order(ser); }
47 
48  ImplementSerializable(SST::CoreTestPortModule::PortModuleAckEvent);
49 };
50 
51 
53 {
54 public:
55  SST_ELI_REGISTER_PORTMODULE(
57  "coreTestElement",
58  "portmodules.test",
59  SST_ELI_ELEMENT_VERSION(0, 1, 0),
60  "PortModule used for testing port module functionality")
61 
62  SST_ELI_DOCUMENT_PARAMS(
63  { "modify", "Set to true to have PortModule mark event as modfied. NOTE: only 1 of modify, drop or replace can be set to true.", "false" },
64  { "drop", "Set to true to have PortModule drop events. NOTE: only 1 of modify, drop, or replace can be set to true.", "false" },
65  { "replace", "Set to true to have PortModule drop events and deliver an Ack event instead. NOTE: only 1 of modify, drop or replace can be set to true.", "false" },
66  { "install_on_send", "Controls whether the PortModule is installed on the send or receive side. Set to true to register on send and false to register on recieve.", "false" },
67  )
68 
69  SST_ELI_DOCUMENT_STATISTICS(
70  { "events_intercepted", "How many events were intercepted by the module", "count", 4 },
71  { "not_enabled", "A statistic that isn't enabled in tests to ensure that stat level is respected", "none", 7 }
72  )
73 
74  SST_ELI_IS_CHECKPOINTABLE()
75 
76  explicit TestPortModule(Params& params);
77 
78  // For serialization only
79  TestPortModule() = default;
80  ~TestPortModule() {}
81 
82  void eventSent(uintptr_t key, Event*& ev) override;
83  void interceptHandler(uintptr_t key, Event*& data, bool& cancel) override;
84 
85  bool installOnReceive() override { return !install_on_send_; }
86  bool installOnSend() override { return install_on_send_; }
87 
88 private:
89  bool install_on_send_ = false;
90  bool modify_ = false;
91  bool drop_ = false;
92  bool replace_ = false;
93 
94  Statistic<uint64_t>* count_ = nullptr;
95  Statistic<uint64_t>* no_stat_ = nullptr;
96 
97  void serialize_order(SST::Core::Serialization::serializer& ser) override
98  {
99  SST::PortModule::serialize_order(ser);
100  SST_SER(install_on_send_);
101  SST_SER(modify_);
102  SST_SER(drop_);
103  SST_SER(replace_);
104  SST_SER(count_);
105  SST_SER(no_stat_);
106  }
107  ImplementSerializable(SST::CoreTestPortModule::TestPortModule)
108 };
109 
111 {
112 public:
113  // REGISTER THIS COMPONENT INTO THE ELEMENT LIBRARY
114  SST_ELI_REGISTER_COMPONENT(
116  "coreTestElement",
117  "coreTestPortModuleComponent",
118  SST_ELI_ELEMENT_VERSION(1,0,0),
119  "Component to test PortModule functionality",
120  COMPONENT_CATEGORY_UNCATEGORIZED
121  )
122 
123  SST_ELI_DOCUMENT_PORTS(
124  {"left", "Link to the left. Will only receive on left port. If nothing is attached to the left port, the component will send sendcount events.", { "" } },
125  {"right", "Link to the right. Will only send on right port. If nothing is connect to the right port, the component will check the types of the events recieved.", { "" } }
126  )
127 
128  SST_ELI_DOCUMENT_PARAMS(
129  { "sendcount", "Events to send if send is set to true", "20"},
130  { "use_subcomponent", "Set to true to use a subcomponent to hook up the ports", "false"},
131  { "repeat_last", "When set to true, will keep sending \"last\" events until the simulation terminates. This is to support test of the RandomDropPortModule which doesn't check event types or values so will not automatically pass through the event marked last.", "false" },
132  )
133 
134  SST_ELI_DOCUMENT_STATISTICS(
135  { "handle_modified_event", "How many modified events were handled", "events", 1 },
136  { "handle_ack_event", "How many ack events were handled", "events", 1 },
137  { "handle_unmodified_event", "How many unmodified events were handled", "events", 1 },
138  )
139 
140  // Optional since there is nothing to document
141  SST_ELI_DOCUMENT_SUBCOMPONENT_SLOTS(
142  {"port_slot", "Slot for loading subcomponent to test shared ports", "" }
143  )
144 
145  SST_ELI_IS_CHECKPOINTABLE()
146 
147  coreTestPortModuleComponent(SST::ComponentId_t id, SST::Params& params);
148 
149  void serialize_order(SST::Core::Serialization::serializer& ser) override
150  {
151  SST::Component::serialize_order(ser);
152  SST_SER(sendcount_);
153  SST_SER(sub_);
154  SST_SER(repeat_last_);
155  SST_SER(left_);
156  SST_SER(right_);
157  SST_SER(stat_mod_event_);
158  SST_SER(stat_unmod_event_);
159  SST_SER(stat_ack_event_);
160  }
162 
163 private:
164  int sendcount_ = 20;
165  bool repeat_last_ = false;
166 
167  Statistic<uint32_t>* stat_mod_event_;
168  Statistic<uint32_t>* stat_ack_event_;
169  Statistic<uint32_t>* stat_unmod_event_;
170 
171  Link* left_;
172  Link* right_;
173 
174  PortSubComponent* sub_ = nullptr;
175 
176  coreTestPortModuleComponent() = default; // for serialization only
177  coreTestPortModuleComponent(const coreTestPortModuleComponent&) = delete; // do not implement
178  coreTestPortModuleComponent& operator=(const coreTestPortModuleComponent&) = delete; // do not implement
179 
180  bool tick(SST::Cycle_t);
181  void handleEvent(SST::Event* ev);
182  void handleEventLast(SST::Event* ev);
183 };
184 
186 {
187 public:
188  SST_ELI_REGISTER_SUBCOMPONENT_API(SST::CoreTestPortModule::PortSubComponent)
189 
190  SST_ELI_REGISTER_SUBCOMPONENT(
192  "coreTestElement",
193  "PortSubComponent",
194  SST_ELI_ELEMENT_VERSION(1,0,0),
195  "Subcomponent used to test putting PortModules on shared ports",
197  )
198 
199  SST_ELI_IS_CHECKPOINTABLE()
200 
201  PortSubComponent(ComponentId_t id, Params& params);
202  PortSubComponent() = default; // For serialization
203  ~PortSubComponent() {}
204 
205  Link* getLeft() { return left_; }
206  Link* getRight() { return right_; }
207 
208 private:
209  Link* left_;
210  Link* right_;
211 
212  void dummy_handler(SST::Event* UNUSED(ev)) {}
213 
214  void serialize_order(SST::Core::Serialization::serializer& ser) override
215  {
216  SST::SubComponent::serialize_order(ser);
217  SST_SER(left_);
218  SST_SER(right_);
219  }
220  ImplementSerializable(SST::CoreTestPortModule::PortSubComponent)
221 };
222 
223 } // namespace SST::CoreTestPortModule
224 
225 #endif // SST_CORE_CORETEST_PORTMODULE_H
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition: serializer.h:42
Definition: coreTest_PortModule.h:25
Main component object for the simulation.
Definition: component.h:30
Definition: coreTest_PortModule.h:185
bool installOnReceive() override
Called to determine if the PortModule should be installed on receives.
Definition: coreTest_PortModule.h:85
Definition: coreTest_PortModule.h:52
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: coreTest_PortModule.cc:48
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: coreTest_PortModule.cc:82
Definition: coreTest_PortModule.h:110
Definition: coreTest_PortModule.h:43
Parameter store.
Definition: params.h:63
Definition: coreTest_PortModule.h:19
Base class for Events - Items sent across links to communicate between components.
Definition: event.h:40
bool installOnSend() override
Called to determine if the PortModule should be installed on sends.
Definition: coreTest_PortModule.h:86
PortModules are modules that can be attached to the send and/or receive side of ports.
Definition: portModule.h:50
SubComponent is a class loadable through the factory which allows dynamic functionality to be added t...
Definition: subcomponent.h:28