/home/aherms/Code/git/awds-routing/src/awds/TopoPacket.h

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         // definitions  of packet layout.
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(double(v) * 0.001);
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     }; // end of class TopoPacket
00086 
00087 } // end of namespace awds
00088 
00089 #endif //TOPOPACKET_H__
00090 /* This stuff is for emacs
00091  * Local variables:
00092  * mode:c++
00093  * c-basic-offset: 4
00094  * End:
00095  */

Generated on Tue Dec 11 17:58:48 2007 for AWDS by  doxygen 1.5.3-20071008