00001 /* 00002 * Copyright 2007 Baylor University 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef _PROPHET_RIBD_TLV_H 00018 #define _PROPHET_RIBD_TLV_H 00019 00020 #include "BaseTLV.h" 00021 #include "Dictionary.h" 00022 00023 namespace prophet 00024 { 00025 00026 class RIBDTLV : public BaseTLV 00027 { 00028 public: 00039 struct RIBDTLVHeader { 00040 u_int8_t type; 00041 u_int8_t flags; 00042 00046 u_int16_t length; 00047 u_int16_t entry_count; 00048 u_int16_t unused__; 00049 } __attribute__((packed)); 00050 00055 struct RoutingAddressString { 00063 u_int16_t string_id; 00064 u_int8_t length; 00065 u_int8_t unused__; 00066 u_char ra_string[0]; 00067 } __attribute__((packed)); 00068 00069 static const size_t RIBDTLVHeaderSize = sizeof(struct RIBDTLVHeader); 00070 00071 static const size_t RoutingAddressStringSize = 00072 sizeof(struct RoutingAddressString); 00073 00077 RIBDTLV(const Dictionary& ribd); 00078 00082 virtual ~RIBDTLV() {} 00083 00087 size_t serialize(u_char* bp, size_t len) const; 00088 00092 const Dictionary& ribd(const std::string& sender, 00093 const std::string& receiver); 00094 00095 protected: 00096 friend class TLVFactory<RIBDTLV>; 00097 00101 RIBDTLV(); 00102 00107 size_t write_ras_entry(u_int16_t sid, const std::string& dest_id, 00108 u_char* bp, size_t len) const; 00109 00114 size_t read_ras_entry(u_int16_t* sid, std::string& dest_id, 00115 const u_char* bp, size_t len); 00116 00120 bool deserialize(const u_char* bp, size_t len); 00121 00122 Dictionary ribd_; 00123 00124 00125 }; // class RIBDTLV 00126 00127 }; // namespace prophet 00128 00129 #endif // _PROPHET_RIBD_TLV_H