Revised OpenFlow Library  v0.6.0dev
 All Classes Files Functions Variables Friends Groups Pages
csegmsg.h
1 /*
2  * csegmsg.h
3  *
4  * Created on: 13.03.2014
5  * Author: andreas
6  */
7 
8 #ifndef CSEGMSG_H_
9 #define CSEGMSG_H_
10 
11 #include <inttypes.h>
12 
13 #include <iostream>
14 
15 #include "rofl/common/cclock.h"
16 #include "rofl/common/logging.h"
17 #include "rofl/common/croflexception.h"
18 #include "rofl/common/openflow/messages/cofmsg_stats.h"
19 #include "rofl/common/openflow/messages/cofmsg_desc_stats.h"
20 #include "rofl/common/openflow/messages/cofmsg_flow_stats.h"
21 #include "rofl/common/openflow/messages/cofmsg_aggr_stats.h"
22 #include "rofl/common/openflow/messages/cofmsg_table_stats.h"
23 #include "rofl/common/openflow/messages/cofmsg_port_stats.h"
24 #include "rofl/common/openflow/messages/cofmsg_queue_stats.h"
25 #include "rofl/common/openflow/messages/cofmsg_group_stats.h"
26 #include "rofl/common/openflow/messages/cofmsg_group_desc_stats.h"
27 #include "rofl/common/openflow/messages/cofmsg_group_features_stats.h"
28 #include "rofl/common/openflow/messages/cofmsg_meter_stats.h"
29 #include "rofl/common/openflow/messages/cofmsg_meter_config_stats.h"
30 #include "rofl/common/openflow/messages/cofmsg_meter_features_stats.h"
31 #include "rofl/common/openflow/messages/cofmsg_table_features_stats.h"
32 #include "rofl/common/openflow/messages/cofmsg_port_desc_stats.h"
33 
34 namespace rofl {
35 
39 
40 class csegmsg {
41 
42  cclock expires_at; // time this cmultipart message will expire
43  uint32_t xid; // transaction id used by this multipart message
44  rofl::openflow::cofmsg_stats* msg; // stitched multipart message, allocated on heap
45 
46  static time_t const DEFAULT_EXPIRATION_DELTA_SEC = 8;
47  static time_t const DEFAULT_EXPIRATION_DELTA_NSEC = 0;
48 
49 public:
50 
54  csegmsg();
55 
59  csegmsg(uint32_t xid);
60 
64  virtual
65  ~csegmsg();
66 
70  csegmsg(csegmsg const& segmsg);
71 
75  csegmsg&
76  operator= (csegmsg const& segmsg);
77 
78 public:
79 
83  bool
84  has_expired() const;
85 
89  void
90  set_expiration_in(
91  time_t delta_sec = 0, time_t delta_nsec = 0);
92 
96  uint32_t
97  get_xid() const { return xid; };
98 
103  get_msg() const {
104  if (0 == msg)
105  throw eInval();
106  return *msg;
107  };
108 
109 
110 public:
111 
115  void
117 
123 
124 private:
125 
129  void
130  clone(rofl::openflow::cofmsg_stats const& msg);
131 
132 public:
133 
134  friend std::ostream&
135  operator<< (std::ostream& os, csegmsg const& msg) {
136  os << rofl::indent(0) << "<csegmsg" << " >" << std::endl;
137  os << rofl::indent(2) << "<expires: >" << std::endl;
138  { rofl::indent i(4); os << msg.expires_at; }
139  os << rofl::indent(2) << "<xid: 0x" << std::hex << (int)msg.xid << std::dec << " >" << std::endl;
140  rofl::indent i(2);
141  switch (msg.msg->get_version()) {
142  case rofl::openflow13::OFP_VERSION: {
143 
144  switch (msg.msg->get_type()) {
145  case rofl::openflow13::OFPT_MULTIPART_REQUEST: {
146 
147  switch (msg.msg->get_stats_type()) {
148  case rofl::openflow13::OFPMP_DESC: {
149  os << dynamic_cast<rofl::openflow::cofmsg_desc_stats_request const&>( *(msg.msg) );
150  } break;
151  case rofl::openflow13::OFPMP_FLOW: {
152  os << dynamic_cast<rofl::openflow::cofmsg_flow_stats_request const&>( *(msg.msg) );
153  } break;
154  case rofl::openflow13::OFPMP_AGGREGATE: {
155  os << dynamic_cast<rofl::openflow::cofmsg_aggr_stats_request const&>( *(msg.msg) );
156  } break;
157  case rofl::openflow13::OFPMP_TABLE: {
158  os << dynamic_cast<rofl::openflow::cofmsg_table_stats_request const&>( *(msg.msg) );
159  } break;
160  case rofl::openflow13::OFPMP_PORT_STATS: {
161  os << dynamic_cast<rofl::openflow::cofmsg_port_stats_request const&>( *(msg.msg) );
162  } break;
163  case rofl::openflow13::OFPMP_QUEUE: {
164  os << dynamic_cast<rofl::openflow::cofmsg_queue_stats_request const&>( *(msg.msg) );
165  } break;
166  case rofl::openflow13::OFPMP_GROUP: {
167  os << dynamic_cast<rofl::openflow::cofmsg_group_stats_request const&>( *(msg.msg) );
168  } break;
169  case rofl::openflow13::OFPMP_GROUP_DESC: {
170  os << dynamic_cast<rofl::openflow::cofmsg_group_desc_stats_request const&>( *(msg.msg) );
171  } break;
172  case rofl::openflow13::OFPMP_GROUP_FEATURES: {
173  os << dynamic_cast<rofl::openflow::cofmsg_group_features_stats_request const&>( *(msg.msg) );
174  } break;
175  // TODO: meters
176  case rofl::openflow13::OFPMP_TABLE_FEATURES: {
177  os << dynamic_cast<rofl::openflow::cofmsg_table_features_stats_request const&>( *(msg.msg) );
178  } break;
179  case rofl::openflow13::OFPMP_PORT_DESC: {
180  os << dynamic_cast<rofl::openflow::cofmsg_port_desc_stats_request const&>( *(msg.msg) );
181  } break;
182  default: {
183  os << *(msg.msg);
184  };
185  }
186 
187  } break;
188  case rofl::openflow13::OFPT_MULTIPART_REPLY: {
189 
190  switch (msg.msg->get_stats_type()) {
191  case rofl::openflow13::OFPMP_DESC: {
192  os << dynamic_cast<rofl::openflow::cofmsg_desc_stats_reply const&>( *(msg.msg) );
193  } break;
194  case rofl::openflow13::OFPMP_FLOW: {
195  os << dynamic_cast<rofl::openflow::cofmsg_flow_stats_reply const&>( *(msg.msg) );
196  } break;
197  case rofl::openflow13::OFPMP_AGGREGATE: {
198  os << dynamic_cast<rofl::openflow::cofmsg_aggr_stats_reply const&>( *(msg.msg) );
199  } break;
200  case rofl::openflow13::OFPMP_TABLE: {
201  os << dynamic_cast<rofl::openflow::cofmsg_table_stats_reply const&>( *(msg.msg) );
202  } break;
203  case rofl::openflow13::OFPMP_PORT_STATS: {
204  os << dynamic_cast<rofl::openflow::cofmsg_port_stats_reply const&>( *(msg.msg) );
205  } break;
206  case rofl::openflow13::OFPMP_QUEUE: {
207  os << dynamic_cast<rofl::openflow::cofmsg_queue_stats_reply const&>( *(msg.msg) );
208  } break;
209  case rofl::openflow13::OFPMP_GROUP: {
210  os << dynamic_cast<rofl::openflow::cofmsg_group_stats_reply const&>( *(msg.msg) );
211  } break;
212  case rofl::openflow13::OFPMP_GROUP_DESC: {
213  os << dynamic_cast<rofl::openflow::cofmsg_group_desc_stats_reply const&>( *(msg.msg) );
214  } break;
215  case rofl::openflow13::OFPMP_GROUP_FEATURES: {
216  os << dynamic_cast<rofl::openflow::cofmsg_group_features_stats_reply const&>( *(msg.msg) );
217  } break;
218  // TODO: meters
219  case rofl::openflow13::OFPMP_TABLE_FEATURES: {
220  os << dynamic_cast<rofl::openflow::cofmsg_table_features_stats_reply const&>( *(msg.msg) );
221  } break;
222  case rofl::openflow13::OFPMP_PORT_DESC: {
223  os << dynamic_cast<rofl::openflow::cofmsg_port_desc_stats_reply const&>( *(msg.msg) );
224  } break;
225  default: {
226  os << *(msg.msg);
227  };
228  }
229 
230  } break;
231  default: {
232  // oops, do nothing here
233  };
234  }
235 
236  } break;
237  }
238  return os;
239  };
240 };
241 
242 }; // end of namespace rofl
243 
244 #endif /* CMULTIPART_H_ */
Definition: csegmsg.h:37
Definition: cclock.h:25
Definition: croflexception.h:65
Definition: cofmsg_stats.h:19
Definition: csegmsg.h:36
Definition: csegmsg.h:38
Definition: logging.h:76
Definition: csegmsg.h:40
Definition: croflexception.h:27
rofl::openflow::cofmsg_stats * retrieve_and_detach_msg()
Returns pointer to this->msg and sets this->msg to NULL. The object resides on heap and must be destr...
Definition: csegmsg.cc:373
void store_and_merge_msg(rofl::openflow::cofmsg_stats const &msg)
Merges payload from msg within this->msg. Checks stats sub-type first.
Definition: csegmsg.cc:206