00001 #ifndef _BEACON_H__
00002 #define _BEACON_H__
00003
00004
00005 #include <cassert>
00006
00007 #include <gea/Time.h>
00008
00009 #include <awds/SrcPacket.h>
00010 #include <awds/NodeId.h>
00011 #include <awds/BasePacket.h>
00012
00013
00014 namespace awds {
00015
00022 class Beacon : public SrcPacket {
00023
00024 public:
00025
00026
00027 static const size_t OffsetPeriod = SrcPacketEnd;
00028 static const size_t OffsetNumNoMpr = OffsetPeriod + 2;
00029 static const size_t OffsetNumMpr = OffsetNumNoMpr + 1;
00030 static const size_t OffsetLNeigh = OffsetNumMpr + 1;
00031
00032 Beacon(BasePacket& p) : SrcPacket(p) {
00033 packet.setType(PacketTypeBeacon);
00034 }
00035
00036 gea::Duration getPeriod() const;
00037 void setPeriod(const gea::Duration& d);
00038
00039
00040 int getNumNoMpr() {
00041 return (int)packet.buffer[OffsetNumNoMpr];
00042 }
00043
00044 void setNumNoMpr(int n) {
00045 packet.buffer[OffsetNumNoMpr] = (char)n;
00046
00047 }
00048
00049 int getNumMpr() {
00050 return (int)packet.buffer[OffsetNumMpr];
00051 }
00052
00053 void setNumMpr(int n) {
00054 packet.buffer[OffsetNumMpr] = (char)n;
00055 }
00056
00057 void setNeigh(class AwdsRouting *awdsRouting, gea::AbsTime t);
00058
00059 void add2Hop(class AwdsRouting *awdsRouting);
00060 void remove2Hop(class AwdsRouting *awdsRouting);
00061
00062 bool hasNoMpr(const NodeId& id);
00063
00064 bool hasMpr(const NodeId& id);
00065 bool hasNeigh(const NodeId& id);
00066
00067 bool tryRemoveFromMpr(AwdsRouting *awdsRouting);
00068
00069 private:
00070
00073 bool hasNeighBinsearch(int a, int b, const NodeId& id);
00074
00075 };
00076 }
00077
00078 #endif //BEACON_H__
00079
00080
00081
00082
00083
00084