Revised OpenFlow Library  v0.6.0dev
 All Classes Files Functions Variables Friends Groups Pages
gtp_actions.h
1 /*
2  * gtp_actions.h
3  *
4  * Created on: 02.08.2013
5  * Author: andreas
6  */
7 
8 #ifndef GTP_ACTIONS_H_
9 #define GTP_ACTIONS_H_
10 
11 #include <inttypes.h>
12 #include <iostream>
13 
14 #include <rofl/common/logging.h>
15 #include <rofl/common/cmemory.h>
16 
17 namespace rofl {
18 namespace openflow {
19 namespace experimental {
20 namespace gtp {
21 
22 enum gtp_exp_id_t {
23  GTP_EXP_ID = 0x5555a781,
24 };
25 
26 enum gtp_action_type_t {
27  GTP_ACTION_PUSH_GTP,
28  GTP_ACTION_POP_GTP,
29 };
30 
32  uint16_t exptype;
33  uint16_t explen;
34  uint8_t data[0];
35 } __attribute__((packed));
36 
38  uint16_t exptype;
39  uint16_t explen;
40  uint16_t ethertype;
41 } __attribute__((packed));
42 
44  uint16_t exptype;
45  uint16_t explen;
46  uint16_t ethertype;
47 } __attribute__((packed));
48 
49 
50 
52 public:
53 
58  uint16_t exptype = 0,
59  size_t bodylen = sizeof(struct ofp_exp_gtp_action_body_hdr)) :
60  rofl::cmemory(bodylen) {
61  set_exp_type(exptype);
62  set_exp_len(bodylen);
63  };
64 
69 
74  const cofaction_exp_body_gtp& body) { *this = body; };
75 
80  operator= (
81  const cofaction_exp_body_gtp& body) {
82  if (this == &body)
83  return *this;
85  return *this;
86  };
87 
92  const rofl::cmemory& body) { *this = body; };
93 
98  operator= (
99  const rofl::cmemory& body) {
100  if (this == &body)
101  return *this;
103  return *this;
104  };
105 
106 public:
107 
111  uint16_t
112  get_exp_type() const {
113  if (rofl::cmemory::memlen() < sizeof(struct ofp_exp_gtp_action_body_hdr))
114  throw eInval();
115  return be16toh(((struct ofp_exp_gtp_action_body_hdr*)rofl::cmemory::somem())->exptype);
116  };
117 
121  void
122  set_exp_type(uint16_t exptype) {
123  if (rofl::cmemory::memlen() < sizeof(struct ofp_exp_gtp_action_body_hdr))
124  throw eInval();
125  ((struct ofp_exp_gtp_action_body_hdr*)rofl::cmemory::somem())->exptype = htobe16(exptype);
126  };
127 
131  uint16_t
132  get_exp_len() const {
133  if (rofl::cmemory::memlen() < sizeof(struct ofp_exp_gtp_action_body_hdr))
134  throw eInval();
135  return be16toh(((struct ofp_exp_gtp_action_body_hdr*)rofl::cmemory::somem())->explen);
136  };
137 
141  void
142  set_exp_len(uint16_t explen) {
143  if (rofl::cmemory::memlen() < sizeof(struct ofp_exp_gtp_action_body_hdr))
144  throw eInval();
145  ((struct ofp_exp_gtp_action_body_hdr*)rofl::cmemory::somem())->explen = htobe16(explen);
146  };
147 
148 public:
149 
150  friend std::ostream&
151  operator<< (std::ostream& os, const cofaction_exp_body_gtp& body) {
152  os << rofl::indent(0) << "<cofaction_exp_body_gtp exp-type: 0x" <<
153  std::hex << (unsigned int)body.get_exp_type() << std::dec
154  << ">" << std::endl;
155  rofl::indent i(2);
156  os << dynamic_cast<const rofl::cmemory&>( body );
157  return os;
158  };
159 };
160 
161 
162 
164 public:
165 
170  uint16_t ethertype = 0) :
172  GTP_ACTION_PUSH_GTP,
173  sizeof(struct ofp_exp_gtp_action_body_push_gtp)) {
174  set_ether_type(ethertype);
175  };
176 
181 
186  const cofaction_exp_body_push_gtp& action) { *this = action; };
187 
192  operator= (
193  const cofaction_exp_body_push_gtp& body) {
194  if (this == &body)
195  return *this;
197  return *this;
198  };
199 
204  const rofl::cmemory& body) { *this = body; };
205 
210  operator= (
211  const rofl::cmemory& action) {
212  if (this == &action)
213  return *this;
215  return *this;
216  };
217 
218 public:
219 
223  uint16_t
224  get_ether_type() const {
226  throw eInval();
227  return be16toh(((struct ofp_exp_gtp_action_body_push_gtp*)rofl::cmemory::somem())->ethertype);
228  };
229 
233  void
234  set_ether_type(uint16_t ethertype) {
236  throw eInval();
237  ((struct ofp_exp_gtp_action_body_push_gtp*)rofl::cmemory::somem())->ethertype = htobe16(ethertype);
238  };
239 
240 public:
241 
242  friend std::ostream&
243  operator<< (std::ostream& os, const cofaction_exp_body_push_gtp& action) {
244  os << rofl::indent(0) << "<cofaction_push_gtp ether-type: 0x" <<
245  std::hex << (unsigned int)action.get_ether_type() << std::dec
246  << ">" << std::endl;
247  rofl::indent i(2);
248  os << dynamic_cast<const rofl::cmemory&>( action );
249  return os;
250  };
251 
252 };
253 
254 
255 
256 
258 public:
259 
264  uint16_t ethertype = 0) :
266  GTP_ACTION_POP_GTP,
267  sizeof(struct ofp_exp_gtp_action_body_pop_gtp)) {
268  set_ether_type(ethertype);
269  };
270 
275 
280  const cofaction_exp_body_pop_gtp& action) { *this = action; };
281 
286  operator= (
287  const cofaction_exp_body_pop_gtp& body) {
288  if (this == &body)
289  return *this;
291  return *this;
292  };
293 
298  const rofl::cmemory& body) { *this = body; };
299 
304  operator= (
305  const rofl::cmemory& action) {
306  if (this == &action)
307  return *this;
309  return *this;
310  };
311 
312 public:
313 
317  uint16_t
318  get_ether_type() const {
320  throw eInval();
321  return be16toh(((struct ofp_exp_gtp_action_body_pop_gtp*)rofl::cmemory::somem())->ethertype);
322  };
323 
327  void
328  set_ether_type(uint16_t ethertype) {
330  throw eInval();
331  ((struct ofp_exp_gtp_action_body_pop_gtp*)rofl::cmemory::somem())->ethertype = htobe16(ethertype);
332  };
333 
334 public:
335 
336  friend std::ostream&
337  operator<< (std::ostream& os, const cofaction_exp_body_pop_gtp& action) {
338  os << rofl::indent(0) << "<cofaction_pop_gtp ether-type: 0x" <<
339  std::hex << (unsigned int)action.get_ether_type() << std::dec
340  << ">" << std::endl;
341  rofl::indent i(2);
342  os << dynamic_cast<const rofl::cmemory&>( action );
343  return os;
344  };
345 
346 };
347 
348 
349 }; // end of namespace gtp
350 }; // end of namespace experimental
351 }; // end of namespace openflow
352 }; // end of namespace rofl
353 
354 #endif /* GTP_ACTIONS_H_ */
size_t memlen() const
Returns length of allocated memory area.
Definition: cmemory.cc:109
uint8_t * somem() const
Returns pointer to start of allocated memory area.
Definition: cmemory.cc:101
Definition: croflexception.h:65
C++ abstraction for malloc'ed memory areas.
Definition: cmemory.h:44
cmemory & operator=(cmemory const &m)
Assignment operator.
Definition: cmemory.cc:85
Definition: logging.h:76