00001 #ifndef _TOPOPACKET_H__
00002 #define _TOPOPACKET_H__
00003
00004 #include <sys/types.h>
00005
00006 #include <gea/Time.h>
00007
00008 #include <awds/AwdsRouting.h>
00009 #include <awds/Flood.h>
00010
00011
00012
00013 namespace awds {
00014
00018 struct TopoPacketNeighItr {
00019 char *ptr;
00020 public:
00021
00022 bool operator ==(const TopoPacketNeighItr& other) const { return ptr == other.ptr; }
00023 bool operator !=(const TopoPacketNeighItr& other) const { return !(*this == other); }
00024 TopoPacketNeighItr& operator++() { ptr += awds::NodeId::size + 2; return *this; }
00025 NodeId operator *() const { NodeId ret; ret.fromArray(ptr); return ret; }
00026 };
00027
00038 class TopoPacket :
00039 public Flood
00040 {
00041
00042 public:
00043
00044 static const size_t OffsetValidity = FloodHeaderEnd;
00045 static const size_t OffsetNumLinks = OffsetValidity + sizeof(u_int32_t);
00046 static const size_t OffsetLinks = OffsetNumLinks + 1;
00047
00048
00049
00050 TopoPacket(BasePacket&p) : Flood(p) {
00051 setFloodType(FloodTypeTopo);
00052 }
00053
00058 void setNeigh(AwdsRouting *awdsRouting);
00059
00063 int getNumLinks() const {
00064 return (int)(unsigned)(unsigned char)packet.buffer[OffsetNumLinks];
00065 }
00066
00069 gea::Duration getValidity() const {
00070 u_int32_t v = fromArray<u_int32_t>(&packet.buffer[OffsetValidity]);
00071 return gea::Duration(v,1000);
00072 }
00073
00074
00077 void setValidity(long d) {
00078 u_int32_t v = d;
00079 toArray<u_int32_t>(v,&packet.buffer[OffsetValidity]);
00080 }
00083 void print();
00084
00085 };
00086
00087 }
00088
00089 #endif //TOPOPACKET_H__
00090
00091
00092
00093
00094
00095