SST/macro
packet_flow.h
Go to the documentation of this file.
1 #ifndef PACKETFLOW_H
2 #define PACKETFLOW_H
3 
8 #include <sprockit/debug.h>
9 
11 DeclareDebugSlot(packet_flow_queue)
12 DeclareDebugSlot(packet_flow_config)
13 
14 namespace sstmac {
15 namespace hw {
16 
18 {
19  public:
20  virtual int initial_credits() const = 0;
21 };
22 
23 class packet_flow_interface
24 {
25  public:
26  typedef enum {
27  credit,
28  payload
29  } type_t;
30 
31  public:
32  type_t
33  type() const {
34  return type_;
35  }
36 
37  int
38  vc() const {
39  return vc_;
40  }
41 
42  void
43  set_vc(int vc) {
44  vc_ = vc;
45  }
46 
47  void
48  serialize_order(serializer& ser);
49 
50  static const long infinity = -1;
51 
52  static const int unassigned_vc = -1;
53 
54  protected:
55  packet_flow_interface(int vc, type_t ty)
56  : vc_(vc), type_(ty)
57  {
58  }
59 
60  packet_flow_interface(type_t ty) :
61  type_(ty), vc_(unassigned_vc)
62  {
63  }
64 
65  packet_flow_interface()
66  : vc_(unassigned_vc) {
67  }
68 
69  protected:
70  int vc_;
71  type_t type_;
72 
73 };
74 
75 /**
76  @class packet_flow
77  Encapsulates a group of machine packets traveling together on the
78  same path between endpoints. This is usually one fraction of
79  a larger message.
80  */
81 class packet_flow_payload :
82  public packet_flow_interface,
83  public packet
84  //public serializable_type<packet_flow_payload>
85 {
86  public:
87  static const double uninitialized_bw;
88 
89  //ImplementSerializable(packet_flow_payload)
90 
91  public:
92  packet_flow_payload(
93  message* parent,
94  int num_bytes,
95  long offset);
96 
97  packet_flow_payload(){} //for serialization
98 
99  virtual ~packet_flow_payload() {}
100 
101  type_t
102  type() const {
103  return payload;
104  }
105 
106  /**
107  Needed because of routable_message ambiguity.
108  */
109  int
110  vc() const {
111  return vc_;
112  }
113 
114  virtual int
115  next_vc() const = 0;
116 
117  virtual int
118  next_port() const = 0;
119 
120  void
121  update_vc() {
122  int new_vc = next_vc();
123  if (new_vc == routing::uninitialized){
124  vc_ = 0;
125  } else {
126  vc_ = new_vc;
127  }
128  }
129 
130  /**
131  @return The total number of bytes in the complete message
132  summed over all trains
133  */
134  long
135  num_bytes_total() const {
136  return orig_->byte_length();
137  }
138 
139  /**
140  @return The number of bytes in this packet_flow, NOT
141  the total number of bytes in the parent message.
142  See #num_bytes_total
143  */
144  int
145  num_bytes() const {
146  return num_bytes_;
147  }
148 
149  timestamp
150  arrival() const {
151  return arrival_;
152  }
153 
154  void
155  set_arrival(double time) {
156  arrival_ = time;
157  }
158 
159  void
160  init_bw(double bw) {
161  bw_ = bw_ == uninitialized_bw ? bw : bw_;
162  }
163 
164  void
165  set_max_bw(double bw){
166  init_bw(bw);
167  bw_ = std::min(bw_, bw);
168  }
169 
170  /**
171  @return The bandwidth in number of bytes per second
172  */
173  double
174  bw() const {
175  return bw_;
176  }
177 
178  /**
179  @param The bandwidth in number of bytes per second
180  */
181  void
182  set_bw(double bw) {
183  bw_ = bw;
184  }
185 
186  double
187  max_incoming_bw() const {
188  return max_in_bw_;
189  }
190 
191  void
192  set_max_incoming_bw(double bw) {
193  max_in_bw_ = bw;
194  }
195 
196  double
197  ser_delay() const {
198  return num_bytes_ / bw_;
199  }
200 
201  void
202  set_inport(int port) {
203  inport_ = port;
204  }
205 
206  int
207  inport() const {
208  return inport_;
209  }
210 
211  std::string
212  to_string() const;
213 
214  void
215  serialize_order(serializer& ser);
216 
217  protected:
218  int inport_;
219 
220  double bw_;
221 
222  double max_in_bw_;
223 
224  timestamp arrival_;
225 
226 };
227 
228 class packet_flow_credit :
229  public event,
230  public packet_flow_interface,
231  public serializable_type<packet_flow_credit>
232 {
233 
234  public:
235  ImplementSerializable(packet_flow_credit)
236 
237  public:
238  packet_flow_credit(){} //for serialization
239 
240  packet_flow_credit(
241  int port,
242  int vc,
243  long num_credits)
244  : port_(port),
245  num_credits_(num_credits),
246  packet_flow_interface(vc, credit) {
247  }
248 
249  type_t
250  type() const {
251  return credit;
252  }
253 
254  int
255  port() const {
256  return port_;
257  }
258 
259  virtual bool
260  is_credit() const {
261  return true;
262  }
263 
264  virtual bool
265  is_chunk() const {
266  return true;
267  }
268 
269  long
270  num_credits() const {
271  return num_credits_;
272  }
273 
274  std::string
275  to_string() const;
276 
277  void
278  serialize_order(serializer& ser);
279 
280  protected:
281  int num_credits_;
282  int port_;
283 
284 
285 };
286 
287 }
288 }
289 
290 
291 #endif // PACKETFLOW_H
292 
#define ImplementSerializable(obj)
Definition: serializable.h:77
SUMI = Simulator unified messagine interface It is also the name for a solid ink in Japanese - i...
#define DeclareDebugSlot(name)
Macro used for declaring a debug slot in a header file.
Definition: debug.h:244
static const int uninitialized
Definition: routing_enum.h:8