Revised OpenFlow Library  v0.6.0dev
 All Classes Files Functions Variables Friends Groups Pages
clldpattr.h
1 /*
2  * clldpattr.h
3  *
4  * Created on: 26.02.2014
5  * Author: andi
6  */
7 
8 #ifndef CLLDPATTR_H_
9 #define CLLDPATTR_H_
10 
11 #include <string.h>
12 
13 #include <string>
14 
15 #include "rofl/common/cmemory.h"
16 #include "rofl/common/croflexception.h"
17 #include "rofl/common/logging.h"
18 
19 namespace rofl {
20 namespace protocol {
21 namespace lldp {
22 
23 class eLLDPException : public RoflException {};
24 class eLLDPNotFound : public eLLDPException {};
25 class eLLDPInval : public eLLDPException {};
26 
27 
28 #ifndef ETH_ALEN
29 #define ETH_ALEN 6
30 #endif
31 
32 /*
33  * LLDP common TLV header
34  */
36  uint16_t tlen; // type:7 + length:9
37  uint8_t body[0];
38 } __attribute__((packed));
39 
40 
41 // Ethernet + LLDP common header
42 struct lldp_hdr_t {
43  uint8_t eth_dst[ETH_ALEN];
44  uint8_t eth_src[ETH_ALEN];
45  uint16_t eth_type; // = 0x88-CC
46  struct lldp_tlv_hdr_t body[0];
47 } __attribute__((packed));
48 
49 // LLDP TLV ID header (chassis-id, port-id)
51  struct lldp_tlv_hdr_t hdr;
52  uint8_t subtype;
53  uint8_t body[0];
54 } __attribute__((packed));
55 
56 
57 // LLDP TLV SYSTEM CAPS header
59  struct lldp_tlv_hdr_t hdr;
60  uint8_t chassis_id;
61  uint16_t available_caps;
62  uint16_t enabled_caps;
63 } __attribute__((packed));
64 
65 
66 // LLDP TLV TTL header
68  struct lldp_tlv_hdr_t hdr;
69  uint16_t ttl;
70 } __attribute__((packed));
71 
72 
73 /* LLDP TLV types */
74 enum lldp_tlv_type {
75  LLDPTT_END = 0,
76  LLDPTT_CHASSIS_ID = 1,
77  LLDPTT_PORT_ID = 2,
78  LLDPTT_TTL = 3,
79  LLDPTT_PORT_DESC = 4,
80  LLDPTT_SYSTEM_NAME = 5,
81  LLDPTT_SYSTEM_DESC = 6,
82  LLDPTT_SYSTEM_CAPS = 7,
83  LLDPTT_MGMT_ADDR = 8,
84 };
85 
86 /* LLDP chassis ID TLV subtypes */
87 enum lldp_tlv_chassis_id_subtype {
88  LLDPCHIDST_RESERVED = 0,
89  LLDPCHIDST_CHASSIS = 1,
90  LLDPCHIDST_IFALIAS = 2,
91  LLDPCHIDST_PORT = 3,
92  LLDPCHIDST_MAC_ADDR = 4,
93  LLDPCHIDST_NET_ADDR = 5,
94  LLDPCHIDST_IFNAME = 6,
95  LLDPCHIDST_LOCAL = 7,
96 };
97 
98 /* LLDP port ID TLV subtypes */
99 enum lldp_tlv_port_id_subtype {
100  LLDPPRTIDST_RESERVED = 0,
101  LLDPPRTIDST_IFALIAS = 1,
102  LLDPPRTIDST_PORT = 2,
103  LLDPPRTIDST_MAC_ADDR = 3,
104  LLDPPRTIDST_NET_ADDR = 4,
105  LLDPPRTIDST_IFNAME = 5,
106  LLDPPRTIDST_AGENT_CIRCUIT_ID = 6,
107  LLDPPRTIDST_LOCAL = 7,
108 };
109 
110 /* LLDP system capabilities */
111 enum lldp_sys_caps {
112  LLDP_SYSCAPS_OTHER = 0,
113  LLDP_SYSCAPS_REPEATER = 1,
114  LLDP_SYSCAPS_BRIDGE = 2,
115  LLDP_SYSCAPS_WLANAP = 3,
116  LLDP_SYSCAPS_ROUTER = 4,
117  LLDP_SYSCAPS_PHONE = 5,
118  LLDP_SYSCAPS_DOCSIS = 6,
119  LLDP_SYSCAPS_STA_ONLY = 7,
120 };
121 
122 
123 
124 
129 {
130 protected:
131 
132  rofl::cmemory hdr; // LLDP header
133  rofl::cmemory body; // LLDP payload
134 
135 public:
136 
140  clldpattr(
141  size_t bodylen = 0);
142 
146  clldpattr(
147  clldpattr const& attr);
148 
152  clldpattr&
153  operator= (clldpattr const& attr);
154 
158  bool
159  operator== (clldpattr const& attr);
160 
164  virtual
165  ~clldpattr();
166 
167 public:
168 
172  virtual size_t
173  length() const;
174 
178  virtual void
179  pack(uint8_t *buf = NULL, size_t buflen = 0);
180 
184  virtual void
185  unpack(uint8_t *buf, size_t buflen);
186 
187 public:
188 
192  virtual uint8_t
193  get_type() const;
194 
198  virtual void
199  set_type(uint8_t type);
200 
204  virtual uint16_t
205  get_length() const;
206 
210  virtual void
211  set_length(uint16_t len);
212 
216  virtual rofl::cmemory const&
217  get_body() const { return body; };
218 
222  virtual rofl::cmemory&
223  set_body() { return body; };
224 
225 public:
226 
230  friend std::ostream&
231  operator<< (std::ostream& os, clldpattr const& attr) {
232  os << rofl::indent(0) << "<clldpattr type:" << (int)attr.get_type()
233  << " len:" << (int)attr.get_length()
234  << " mem-len:" << (int)attr.length()
235  << " >" << std::endl;
236  return os;
237  };
238 };
239 
240 
241 
247 {
248 public:
249 
253  clldpattr_end();
254 
259  clldpattr const& attr) : clldpattr(attr) {};
260 
265  clldpattr_end const& attr);
266 
271  operator= (clldpattr_end const& attr);
272 
276  virtual
277  ~clldpattr_end();
278 
279 
280 public:
281 
285  friend std::ostream&
286  operator<< (std::ostream& os, clldpattr_end const& attr) {
287  os << dynamic_cast<clldpattr const&>( attr );
288  os << rofl::indent(2) << "<clldpattr_end >" << std::endl;
289  return os;
290  };
291 };
292 
293 
294 
295 
301 {
302  uint8_t sub_type;
303 
304 public:
305 
309  clldpattr_id(
310  uint8_t type,
311  uint8_t sub_type = 0,
312  size_t len = sizeof(struct lldp_tlv_id_hdr_t));
313 
317  clldpattr_id(
318  clldpattr const& attr) : clldpattr(attr), sub_type(0) {};
319 
323  clldpattr_id(
324  clldpattr_id const& attr);
325 
329  clldpattr_id&
330  operator= (clldpattr_id const& attr);
331 
335  virtual
336  ~clldpattr_id();
337 
338 public:
339 
343  virtual size_t
344  length() const;
345 
349  virtual void
350  pack(uint8_t *buf = NULL, size_t buflen = 0);
351 
355  virtual void
356  unpack(uint8_t *buf, size_t buflen);
357 
358 public:
359 
363  virtual uint8_t const&
364  get_sub_type() const { return sub_type; };
365 
369  virtual uint8_t&
370  set_sub_type() { return sub_type; };
371 
375  virtual std::string
376  get_string() const;
377 
381  virtual void
382  set_string(std::string const str);
383 
384 
385 public:
386 
390  friend std::ostream&
391  operator<< (std::ostream& os, clldpattr_id const& attr) {
392  os << dynamic_cast<clldpattr const&>( attr );
393  switch (attr.get_type()) {
394  case LLDPTT_CHASSIS_ID: {
395  os << rofl::indent(2) << "<clldpattr_chassis_id sub-type:" << (int)attr.get_sub_type() << " >" << std::endl;
396  } break;
397  case LLDPTT_PORT_ID: {
398  os << rofl::indent(2) << "<clldpattr_port_id sub-type:" << (int)attr.get_sub_type() << " >" << std::endl;
399  } break;
400  default: {
401  os << rofl::indent(2) << "<clldpattr_id type:" << (int)attr.get_type() << " sub-type:" << (int)attr.get_sub_type() << " >" << std::endl;
402  };
403  }
404  rofl::indent i(4);
405  os << attr.get_body();
406  return os;
407  };
408 };
409 
410 
411 
412 
418 {
419  uint16_t ttl;
420 
421 public:
422 
427  size_t len = sizeof(struct lldp_tlv_ttl_hdr_t));
428 
433  clldpattr const& attr) : clldpattr(attr), ttl(0) {};
434 
439  clldpattr_ttl const& attr);
440 
445  operator= (clldpattr_ttl const& attr);
446 
450  virtual
451  ~clldpattr_ttl();
452 
453 public:
454 
458  virtual size_t
459  length() const;
460 
464  virtual void
465  pack(uint8_t *buf = NULL, size_t buflen = 0);
466 
470  virtual void
471  unpack(uint8_t *buf, size_t buflen);
472 
473 public:
474 
478  virtual uint16_t const&
479  get_ttl() const { return ttl; };
480 
484  virtual uint16_t&
485  set_ttl() { return ttl; };
486 
487 public:
488 
492  friend std::ostream&
493  operator<< (std::ostream& os, clldpattr_ttl const& attr) {
494  os << dynamic_cast<clldpattr const&>( attr );
495  os << rofl::indent(2) << "<clldpattr_ttl ttl:0x" << std::hex << (int)attr.get_ttl() << std::dec << " >" << std::endl;
496  return os;
497  };
498 };
499 
500 
506 {
507 public:
508 
513  uint8_t type,
514  size_t len = sizeof(struct lldp_tlv_hdr_t));
515 
520  clldpattr const& attr) : clldpattr(attr) {
521  //lldp_desc_generic = somem();
522  };
523 
528  clldpattr_desc const& attr);
529 
534  operator= (clldpattr_desc const& attr);
535 
539  virtual
540  ~clldpattr_desc();
541 
542 
543 public:
544 
548  virtual std::string
549  get_desc() const;
550 
554  virtual void
555  set_desc(std::string const& desc);
556 
557 public:
558 
562  friend std::ostream&
563  operator<< (std::ostream& os, clldpattr_desc const& attr) {
564  os << dynamic_cast<clldpattr const&>( attr );
565  switch (attr.get_type()) {
566  case rofl::protocol::lldp::LLDPTT_PORT_DESC: {
567  os << rofl::indent(2) << "<clldpattr_port_desc desc:" << attr.get_desc() << " >";
568  } break;
569  case rofl::protocol::lldp::LLDPTT_SYSTEM_NAME: {
570  os << rofl::indent(2) << "<clldpattr_system_name desc:" << attr.get_desc() << " >";
571  } break;
572  case rofl::protocol::lldp::LLDPTT_SYSTEM_DESC: {
573  os << rofl::indent(2) << "<clldpattr_system_desc desc:" << attr.get_desc() << " >";
574  } break;
575  default: {
576  os << rofl::indent(2) << "<clldpattr_desc type:" << (int)attr.get_type() << " desc:" << attr.get_desc() << " >";
577  };
578  }
579  rofl::indent i(4);
580  os << attr.get_body();
581  return os;
582  };
583 };
584 
585 
586 
587 
588 
589 
590 
591 
592 
593 
594 
600 {
601  uint8_t chassis_id;
602  uint16_t available_caps;
603  uint16_t enabled_caps;
604 
605 public:
606 
611  size_t len = sizeof(struct lldp_tlv_sys_caps_hdr_t));
612 
617  clldpattr const& attr) : clldpattr(attr), chassis_id(0), available_caps(0), enabled_caps(0) {};
618 
623  clldpattr_system_caps const& attr);
624 
629  operator= (clldpattr_system_caps const& attr);
630 
634  virtual
636 
637 public:
638 
642  virtual size_t
643  length() const;
644 
648  virtual void
649  pack(uint8_t *buf = NULL, size_t buflen = 0);
650 
654  virtual void
655  unpack(uint8_t *buf, size_t buflen);
656 
657 public:
658 
662  virtual uint8_t const&
663  get_chassis_id() const { return chassis_id; };
664 
668  virtual uint8_t&
669  set_chassis_id() { return chassis_id; };
670 
674  virtual uint16_t const&
675  get_available_caps() const { return available_caps; };
676 
680  virtual uint16_t&
681  set_available_caps() { return available_caps; };
682 
686  virtual uint16_t const&
687  get_enabled_caps() const { return enabled_caps; };
688 
692  virtual uint16_t&
693  set_enabled_caps() { return enabled_caps; };
694 
695 
696 public:
697 
701  friend std::ostream&
702  operator<< (std::ostream& os, clldpattr_system_caps const& attr) {
703  os << dynamic_cast<clldpattr const&>( attr );
704  os << rofl::indent(2) << "<clldpattr_sys_caps >" << std::endl;
705  os << rofl::indent(4) << "<chassis-id: " << (int)attr.get_chassis_id() << " >" << std::endl;
706  os << rofl::indent(4) << "<available-caps: 0x" << std::hex << (int)attr.get_available_caps() << std::dec << " >" << std::endl;
707  os << rofl::indent(4) << "<enabled-caps: 0x" << std::hex << (int)attr.get_enabled_caps() << std::dec << " >" << std::endl;
708  return os;
709  };
710 };
711 
712 // TODO: mgmt-addr
713 
714 }; // end of namespace lldp
715 }; // end of namespace protocol
716 }; // end of namespace rofl
717 
718 #endif /* CLLDPATTR_H_ */
Definition: clldpattr.h:24
Definition: clldpattr.h:128
Definition: clldpattr.h:25
Definition: clldpattr.h:42
Definition: clldpattr.h:35
Definition: clldpattr.h:504
Definition: clldpattr.h:416
Definition: clldpattr.h:245
Definition: clldpattr.h:299
C++ abstraction for malloc'ed memory areas.
Definition: cmemory.h:44
Definition: logging.h:76
Definition: clldpattr.h:50
Definition: clldpattr.h:23
Definition: croflexception.h:27