SST 15.0
Structural Simulation Toolkit
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
19namespace SST::CoreTestPortModule {
20
22
23// Event passed between test components. The variable modified can
24// be set to true as a test of modifying events in PortModules.
25class PortModuleEvent : public Event
26{
27public:
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
43class PortModuleAckEvent : public Event
44{
45public:
46 void serialize_order(SST::Core::Serialization::serializer& ser) override { Event::serialize_order(ser); }
47
49};
50
51
52class TestPortModule : public SST::PortModule
53{
54public:
55 SST_ELI_REGISTER_PORTMODULE(
56 TestPortModule,
57 "coreTestElement",
58 "portmodules.test",
59 SST_ELI_ELEMENT_VERSION(0, 1, 0),
60 "PortModule used for testing port module functionality")
61
62 // TODO Need stats
63
64 SST_ELI_DOCUMENT_PARAMS(
65 { "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" },
66 { "drop", "Set to true to have PortModule drop events. NOTE: only 1 of modify, drop, or replace can be set to true.", "false" },
67 { "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" },
68 { "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" },
69 )
70
71 explicit TestPortModule(Params& params);
72
73 // For serialization only
74 TestPortModule() = default;
75 ~TestPortModule() {}
76
77 void eventSent(uintptr_t key, Event*& ev) override;
78 void interceptHandler(uintptr_t key, Event*& data, bool& cancel) override;
79
80 bool installOnReceive() override { return !install_on_send_; }
81 bool installOnSend() override { return install_on_send_; }
82
83private:
84 bool install_on_send_ = false;
85 bool modify_ = false;
86 bool drop_ = false;
87 bool replace_ = false;
88
89 void serialize_order(SST::Core::Serialization::serializer& ser) override
90 {
91 SST::PortModule::serialize_order(ser);
92 SST_SER(install_on_send_);
93 SST_SER(modify_);
94 SST_SER(drop_);
95 SST_SER(replace_);
96 }
97 ImplementSerializable(SST::CoreTestPortModule::TestPortModule)
98};
99
100class coreTestPortModuleComponent : public SST::Component
101{
102public:
103 // REGISTER THIS COMPONENT INTO THE ELEMENT LIBRARY
104 SST_ELI_REGISTER_COMPONENT(
105 coreTestPortModuleComponent,
106 "coreTestElement",
107 "coreTestPortModuleComponent",
108 SST_ELI_ELEMENT_VERSION(1,0,0),
109 "Component to test PortModule functionality",
110 COMPONENT_CATEGORY_UNCATEGORIZED
111 )
112
113 SST_ELI_DOCUMENT_PORTS(
114 {"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.", { "" } },
115 {"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.", { "" } }
116 )
117
118 SST_ELI_DOCUMENT_PARAMS(
119 { "sendcount", "Events to send if send is set to true", "20"},
120 { "use_subcomponent", "Set to true to use a subcomponent to hook up the ports", "false"},
121 { "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" },
122 )
123
124 // Optional since there is nothing to document
125 SST_ELI_DOCUMENT_SUBCOMPONENT_SLOTS(
126 {"port_slot", "SLot for loading subcomponent to test shared ports", "" }
127 )
128
129 coreTestPortModuleComponent(SST::ComponentId_t id, SST::Params& params);
130
131 void serialize_order(SST::Core::Serialization::serializer& ser) override
132 {
133 SST::Component::serialize_order(ser);
134 SST_SER(sendcount_);
135 SST_SER(sub_);
136 SST_SER(repeat_last_);
137 SST_SER(left_);
138 SST_SER(right_);
139 }
141
142private:
143 int sendcount_ = 20;
144 bool repeat_last_ = false;
145
146 Link* left_;
147 Link* right_;
148
149 PortSubComponent* sub_ = nullptr;
150
151 coreTestPortModuleComponent() = default; // for serialization only
152 coreTestPortModuleComponent(const coreTestPortModuleComponent&) = delete; // do not implement
153 coreTestPortModuleComponent& operator=(const coreTestPortModuleComponent&) = delete; // do not implement
154
155 bool tick(SST::Cycle_t);
156 void handleEvent(SST::Event* ev);
157 void handleEventLast(SST::Event* ev);
158};
159
160class PortSubComponent : public SST::SubComponent
161{
162public:
163 SST_ELI_REGISTER_SUBCOMPONENT_API(SST::CoreTestPortModule::PortSubComponent)
164
165 SST_ELI_REGISTER_SUBCOMPONENT(
166 PortSubComponent,
167 "coreTestElement",
168 "PortSubComponent",
169 SST_ELI_ELEMENT_VERSION(1,0,0),
170 "Subcomponent used to test putting PortModules on shared ports",
172 )
173
174 PortSubComponent(ComponentId_t id, Params& params);
175 PortSubComponent() = default; // For serialization
176 ~PortSubComponent() {}
177
178 Link* getLeft() { return left_; }
179 Link* getRight() { return right_; }
180
181private:
182 Link* left_;
183 Link* right_;
184
185 void dummy_handler(SST::Event* UNUSED(ev)) {}
186
187 void serialize_order(SST::Core::Serialization::serializer& ser) override
188 {
189 SST::SubComponent::serialize_order(ser);
190 SST_SER(left_);
191 SST_SER(right_);
192 }
193 ImplementSerializable(SST::CoreTestPortModule::PortSubComponent)
194};
195
196} // namespace SST::CoreTestPortModule
197
198#endif // SST_CORE_CORETEST_PORTMODULE_H
Main component object for the simulation.
Definition component.h:31
Definition coreTest_PortModule.h:44
Definition coreTest_PortModule.h:26
Definition coreTest_PortModule.h:161
Definition coreTest_PortModule.h:53
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:43
bool installOnSend() override
Called to determine if the PortModule should be installed on sends.
Definition coreTest_PortModule.h:81
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:75
bool installOnReceive() override
Called to determine if the PortModule should be installed on receives.
Definition coreTest_PortModule.h:80
Definition coreTest_PortModule.h:101
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
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
SubComponent is a class loadable through the factory which allows dynamic functionality to be added t...
Definition subcomponent.h:29