Revised OpenFlow Library  v0.6.0dev
 All Classes Files Functions Variables Friends Groups Pages
pppoe_actions.h
1 #ifndef PPPOE_ACTIONS_H
2 #define PPPOE_ACTIONS_H 1
3 
4 #include <inttypes.h>
5 #include <iostream>
6 
7 #include <rofl/common/logging.h>
8 #include <rofl/common/cmemory.h>
9 
10 namespace rofl {
11 namespace openflow {
12 namespace experimental {
13 namespace pppoe {
14 
15 enum pppoe_exp_id_t {
16  PPPOE_EXP_ID = 0x5555a780,
17 };
18 
19 enum pppoe_action_type_t {
20  PPPOE_ACTION_PUSH_PPPOE,
21  PPPOE_ACTION_POP_PPPOE,
22 };
23 
25  uint16_t exptype;
26  uint16_t explen;
27  uint8_t data[0];
28 } __attribute__((packed));
29 
31  uint16_t exptype;
32  uint16_t explen;
33  uint16_t ethertype;
34 } __attribute__((packed));
35 
37  uint16_t exptype;
38  uint16_t explen;
39  uint16_t ethertype;
40 } __attribute__((packed));
41 
42 
43 
45 public:
46 
51  uint16_t exptype = 0,
52  size_t bodylen = sizeof(struct ofp_exp_pppoe_action_body_hdr)) :
53  rofl::cmemory(bodylen) {
54  set_exp_type(exptype);
55  set_exp_len(bodylen);
56  };
57 
62 
67  const cofaction_exp_body_pppoe& body) { *this = body; };
68 
73  operator= (
74  const cofaction_exp_body_pppoe& body) {
75  if (this == &body)
76  return *this;
78  return *this;
79  };
80 
85  const rofl::cmemory& body) { *this = body; };
86 
91  operator= (
92  const rofl::cmemory& body) {
93  if (this == &body)
94  return *this;
96  return *this;
97  };
98 
99 public:
100 
104  uint16_t
105  get_exp_type() const {
107  throw eInval();
108  return be16toh(((struct ofp_exp_pppoe_action_body_hdr*)rofl::cmemory::somem())->exptype);
109  };
110 
114  void
115  set_exp_type(uint16_t exptype) {
117  throw eInval();
118  ((struct ofp_exp_pppoe_action_body_hdr*)rofl::cmemory::somem())->exptype = htobe16(exptype);
119  };
120 
124  uint16_t
125  get_exp_len() const {
127  throw eInval();
128  return be16toh(((struct ofp_exp_pppoe_action_body_hdr*)rofl::cmemory::somem())->explen);
129  };
130 
134  void
135  set_exp_len(uint16_t explen) {
137  throw eInval();
138  ((struct ofp_exp_pppoe_action_body_hdr*)rofl::cmemory::somem())->explen = htobe16(explen);
139  };
140 
141 public:
142 
143  friend std::ostream&
144  operator<< (std::ostream& os, const cofaction_exp_body_pppoe& body) {
145  os << rofl::indent(0) << "<cofaction_exp_body_pppoe exp-type: 0x" <<
146  std::hex << (unsigned int)body.get_exp_type() << std::dec
147  << ">" << std::endl;
148  rofl::indent i(2);
149  os << dynamic_cast<const rofl::cmemory&>( body );
150  return os;
151  };
152 };
153 
154 
155 
157 public:
158 
163  uint16_t ethertype = 0) :
165  PPPOE_ACTION_PUSH_PPPOE,
166  sizeof(struct ofp_exp_pppoe_action_body_push_pppoe)) {
167  set_ether_type(ethertype);
168  };
169 
174 
179  const cofaction_exp_body_push_pppoe& action) { *this = action; };
180 
185  operator= (
186  const cofaction_exp_body_push_pppoe& body) {
187  if (this == &body)
188  return *this;
190  return *this;
191  };
192 
197  const rofl::cmemory& body) { *this = body; };
198 
203  operator= (
204  const rofl::cmemory& action) {
205  if (this == &action)
206  return *this;
208  return *this;
209  };
210 
211 public:
212 
216  uint16_t
217  get_ether_type() const {
219  throw eInval();
220  return be16toh(((struct ofp_exp_pppoe_action_body_push_pppoe*)rofl::cmemory::somem())->ethertype);
221  };
222 
226  void
227  set_ether_type(uint16_t ethertype) {
229  throw eInval();
230  ((struct ofp_exp_pppoe_action_body_push_pppoe*)rofl::cmemory::somem())->ethertype = htobe16(ethertype);
231  };
232 
233 public:
234 
235  friend std::ostream&
236  operator<< (std::ostream& os, const cofaction_exp_body_push_pppoe& action) {
237  os << rofl::indent(0) << "<cofaction_push_pppoe ether-type: 0x" <<
238  std::hex << (unsigned int)action.get_ether_type() << std::dec
239  << ">" << std::endl;
240  rofl::indent i(2);
241  os << dynamic_cast<const rofl::cmemory&>( action );
242  return os;
243  };
244 
245 };
246 
247 
248 
249 
251 public:
252 
257  uint16_t ethertype = 0) :
259  PPPOE_ACTION_POP_PPPOE,
260  sizeof(struct ofp_exp_pppoe_action_body_pop_pppoe)) {
261  set_ether_type(ethertype);
262  };
263 
268 
273  const cofaction_exp_body_pop_pppoe& action) { *this = action; };
274 
279  operator= (
280  const cofaction_exp_body_pop_pppoe& body) {
281  if (this == &body)
282  return *this;
284  return *this;
285  };
286 
291  const rofl::cmemory& body) { *this = body; };
292 
297  operator= (
298  const rofl::cmemory& action) {
299  if (this == &action)
300  return *this;
302  return *this;
303  };
304 
305 public:
306 
310  uint16_t
311  get_ether_type() const {
313  throw eInval();
314  return be16toh(((struct ofp_exp_pppoe_action_body_pop_pppoe*)rofl::cmemory::somem())->ethertype);
315  };
316 
320  void
321  set_ether_type(uint16_t ethertype) {
323  throw eInval();
324  ((struct ofp_exp_pppoe_action_body_pop_pppoe*)rofl::cmemory::somem())->ethertype = htobe16(ethertype);
325  };
326 
327 public:
328 
329  friend std::ostream&
330  operator<< (std::ostream& os, const cofaction_exp_body_pop_pppoe& action) {
331  os << rofl::indent(0) << "<cofaction_pop_pppoe ether-type: 0x" <<
332  std::hex << (unsigned int)action.get_ether_type() << std::dec
333  << ">" << std::endl;
334  rofl::indent i(2);
335  os << dynamic_cast<const rofl::cmemory&>( action );
336  return os;
337  };
338 
339 };
340 
341 
342 }; // end of namespace pppoe
343 }; // end of namespace experimental
344 }; // end of namespace openflow
345 }; // end of namespace rofl
346 
347 #endif
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