00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _PROPHET_RIB_TLV_H_
00018 #define _PROPHET_RIB_TLV_H_
00019
00020 #include "PointerList.h"
00021 #include "Node.h"
00022 #include "BaseTLV.h"
00023
00024 namespace prophet
00025 {
00026
00027 class RIBTLV : public BaseTLV
00028 {
00029 public:
00030
00031 typedef RIBNodeList::iterator iterator;
00032 typedef RIBNodeList::const_iterator const_iterator;
00033
00038 typedef enum {
00039 RELAY_NODE = 1 << 0,
00040 CUSTODY_NODE = 1 << 1,
00041 INTERNET_GW_NODE = 1 << 2
00042 } rib_header_flag_t;
00043
00053 struct RIBTLVHeader {
00054 u_int8_t type;
00055
00068 u_int8_t flags;
00073 u_int16_t length;
00074 u_int16_t rib_string_count;
00075 u_int16_t unused__;
00076 } __attribute__((packed));
00077
00082 struct RIBEntry {
00086 u_int16_t string_id;
00093 u_int8_t pvalue;
00106 u_int8_t flags;
00107 } __attribute__((packed));
00108
00109 static const size_t RIBTLVHeaderSize = sizeof(struct RIBTLVHeader);
00110
00111 static const size_t RIBEntrySize = sizeof(struct RIBEntry);
00112
00116 RIBTLV(const RIBNodeList& nodes,
00117 bool relay,
00118 bool custody,
00119 bool internet=false);
00120
00124 virtual ~RIBTLV() {}
00125
00129 size_t serialize(u_char* bp, size_t len) const;
00130
00132 const RIBNodeList& nodes() const { return nodes_; }
00133 bool relay() const { return relay_; }
00134 bool custody() const { return custody_; }
00135 bool internet() const { return internet_; }
00137
00138 protected:
00139 friend class TLVFactory<RIBTLV>;
00140
00144 RIBTLV();
00145
00149 static void decode_flags(u_int8_t flags, bool* relay,
00150 bool* custody, bool* internet);
00151
00156 size_t write_rib_entry(u_int16_t sid, double pvalue, bool relay,
00157 bool custody, bool internet,
00158 u_char* bp, size_t len) const;
00159
00164 size_t read_rib_entry(u_int16_t* sid, double* pvalue,
00165 bool* relay, bool* custody, bool* internet,
00166 const u_char* bp, size_t len);
00167
00171 bool deserialize(const u_char* bp, size_t len);
00172
00173 RIBNodeList nodes_;
00174 bool relay_;
00175
00176 bool custody_;
00177 bool internet_;
00178
00179 };
00180
00181 };
00182
00183 #endif // _PROPHET_RIB_TLV_H_