00001 #ifndef _FLOOD_H__
00002 #define _FLOOD_H__
00003
00004 #include <awds/SrcPacket.h>
00005 #include <awds/FloodTypes.h>
00006
00007
00008
00009 namespace awds {
00010
00024 class Flood : public SrcPacket {
00025
00026
00027 public:
00028 static const size_t OffsetLastHop = SrcPacketEnd;
00029 static const size_t OffsetTTL = OffsetLastHop + NodeId::size;
00030 static const size_t OffsetFloodType = OffsetTTL + 1;
00031 static const size_t FloodHeaderEnd = OffsetFloodType + 1;
00032
00033 Flood(BasePacket& p) : SrcPacket(p) {
00034 packet.setType(PacketTypeFlood);
00035 }
00036
00041 int getTTL() {
00042 return (int)(unsigned)(unsigned char)packet.buffer[OffsetTTL];
00043 }
00048 void setTTL(int ttl) {
00049 packet.buffer[OffsetTTL] = (char)(unsigned char)(ttl % 0x0100);
00050 }
00051
00054 void decrTTL() {
00055 packet.buffer[OffsetTTL]--;
00056 }
00057
00060 void incTTL() {
00061 packet.buffer[OffsetTTL]++;
00062 }
00063
00068 NodeId getLastHop() const {
00069 NodeId ret;
00070 ret.fromArray(&packet.buffer[OffsetLastHop]);
00071 return ret;
00072 }
00073
00078 void setLastHop(const NodeId& id) {
00079 id.toArray(&packet.buffer[OffsetLastHop]);
00080 }
00081
00082
00083 int getFloodType() {
00084 return (int)packet.buffer[OffsetFloodType];
00085
00086 }
00087
00088 void setFloodType(int ft) {
00089 packet.buffer[OffsetFloodType] = (char)(ft % 0x0100);
00090 }
00091
00092 };
00093
00094 }
00095
00096
00097
00098
00099
00100 #endif //FLOOD_H__
00101
00102
00103
00104
00105
00106