MKCommModel
|
00001 #ifndef MKNODE_H 00002 #define MKNODE_H 00003 00004 #include <vector> 00005 #include <sys/types.h> 00006 #include <map> 00007 00008 #include "include/commmodel.hpp" 00009 #include "MKPacket.h" 00010 #include "MKLib.h" 00011 00013 class MKNode { 00014 public: 00015 00016 friend class MKNodeTests; 00017 00025 MKNode(mac_t mac_addr, ip4_t ip_addr); 00026 ~MKNode(); 00027 00029 struct MKNeighbor { 00030 00036 MKNeighbor(const MKNode *node); 00037 ~MKNeighbor(); 00038 00040 const MKNode *node; 00041 00043 latency_t latency; 00044 00046 signal_strength_t signal; 00047 00049 weight_t weight; 00050 00052 throughput_t throughput; 00053 00055 inactive_t inactive; 00056 }; 00057 00059 struct MKRoute { 00060 00061 MKRoute(const MKNode *dest); 00062 ~MKRoute(); 00063 00064 const MKNode *node; 00065 00066 latency_t latency; 00067 00068 void clearHops(); 00069 void addNextHop(MKNode *); 00070 inline std::vector<MKNode *> getHops() { return std::vector<MKNode *>(hops); } 00071 int length() { return hops.size(); } 00072 throughput_t throughput(); 00073 00074 private: 00075 std::vector<MKNode *> hops; 00076 }; 00077 00082 operator std::string() const; 00083 00089 node *asCommNode() const; 00090 00099 void addNeighbor(const MKNode *node, NeighborInfo *link); 00100 00104 MKNeighbor *nbr(mac_t target); 00105 00109 MKRoute *route(mac_t target); 00110 00114 MKRoute *addRoute(MKNode *target); 00115 00119 void clearRoutes(); 00120 00124 void clearNeighbors(); 00125 00130 inline ip4_t getIP4() const { return ip4; } 00131 00132 inline mac_t getMAC() const { return mac; } 00133 00140 std::vector<const MKNode *> getNeighbors() const; 00141 00147 inline void setIP(ip4_t ip) { ip4 = ip; } 00148 00149 protected: 00150 00152 const mac_t mac; 00153 00155 ip4_t ip4; 00157 std::map<MacAddr, MKNeighbor *> neighbors; 00159 std::map<MacAddr, MKRoute *> routes; 00160 00161 }; 00162 00163 #endif