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_HELLO_TLV_H_ 00018 #define _PROPHET_HELLO_TLV_H_ 00019 00020 #include <string> 00021 #include "BaseTLV.h" 00022 00023 namespace prophet 00024 { 00025 00026 class HelloTLV : public BaseTLV 00027 { 00028 public: 00046 struct HelloTLVHeader { 00047 u_int8_t type; 00048 u_int8_t unused__:5; 00058 u_int8_t HF:3; 00063 u_int16_t length; 00071 u_int8_t timer; 00079 u_int8_t name_length; 00085 u_char sender_name[0]; 00086 } __attribute__((packed)); 00087 00088 static const size_t HelloTLVHeaderSize = sizeof(struct HelloTLVHeader); 00089 00094 typedef enum { 00095 HF_UNKNOWN = 0x0, 00096 SYN = 0x1, 00097 SYNACK = 0x2, 00098 ACK = 0x3, 00099 RSTACK = 0x4 00100 } hello_hf_t; 00101 00102 static const char* 00103 hf_to_str(hello_hf_t hf) 00104 { 00105 switch(hf) { 00106 case SYN: return "SYN"; 00107 case SYNACK: return "SYNACK"; 00108 case ACK: return "ACK"; 00109 case RSTACK: return "RSTACK"; 00110 case HF_UNKNOWN: 00111 default: return "Unrecognized prophet HF code"; 00112 } 00113 } 00114 00118 HelloTLV(hello_hf_t hf, 00119 u_int8_t timer, 00120 const std::string& sender); 00121 00125 virtual ~HelloTLV() {} 00126 00130 size_t serialize(u_char* bp, size_t len) const; 00131 00133 hello_hf_t hf() const { return hf_; } 00134 const char* hf_str() const { return hf_to_str(hf_); } 00135 u_int8_t timer() const { return timer_; } 00136 std::string sender() const { return sender_; } 00138 00139 protected: 00140 friend class TLVFactory<HelloTLV>; 00141 00145 HelloTLV(); 00146 00150 bool deserialize(const u_char* bp, size_t len); 00151 00152 hello_hf_t hf_; 00153 u_int8_t timer_; 00154 std::string sender_; 00155 }; // class HelloTLV 00156 00157 }; // namespace prophet 00158 00159 #endif // _PROPHET_HELLO_TLV_H_