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
00019 class Beacon : public SrcPacket {
00020
00021 public:
00022
00023 static const size_t OffsetPeriod = SrcPacketEnd;
00024 static const size_t OffsetNumNoMpr = OffsetPeriod + 2;
00025 static const size_t OffsetNumMpr = OffsetNumNoMpr + 1;
00026 static const size_t OffsetLNeigh = OffsetNumMpr + 1;
00027
00028
00029 Beacon(BasePacket& p) : SrcPacket(p) {
00030 packet.setType(PacketTypeBeacon);
00031 }
00032
00033 gea::Duration getPeriod() const;
00034 void setPeriod(const gea::Duration& d);
00035
00036 int getNumNoMpr() {
00037 return (int)packet.buffer[OffsetNumNoMpr];
00038 }
00039
00040 void setNumNoMpr(int n) {
00041 packet.buffer[OffsetNumNoMpr] = (char)n;
00042
00043 }
00044
00045 int getNumMpr() {
00046 return (int)packet.buffer[OffsetNumMpr];
00047 }
00048
00049 void setNumMpr(int n) {
00050 packet.buffer[OffsetNumMpr] = (char)n;
00051 }
00052
00053 void setNeigh(class AwdsRouting *awdsRouting, gea::AbsTime t);
00054
00055 void add2Hop(class AwdsRouting *awdsRouting);
00056 void remove2Hop(class AwdsRouting *awdsRouting);
00057
00058 bool hasNoMpr(const NodeId& id);
00059
00060 bool hasMpr(const NodeId& id);
00061 bool hasNeigh(const NodeId& id);
00062
00063 bool tryRemoveFromMpr(AwdsRouting *awdsRouting);
00064
00065 private:
00066
00069 bool hasNeighBinsearch(int a, int b, const NodeId& id);
00070
00071 };
00072 }
00073
00074 #endif //BEACON_H__
00075
00076
00077
00078
00079
00080