#ifndef MKNODE_H #define MKNODE_H #include #include #include #include "include/commmodel.hpp" #include "MKPacket.h" #include "MKLib.h" /*! \brief Represents a node in the MESH. */ class MKNode { public: friend class MKNodeTests; /*! \brief Constructs a new MKNode with with a mac address and ip address \param mac_addr The mac address for this node. \param ip_addr The ip address for this node. \pre mac_addr must not be NULL. \pre ip_addr must not be NULL. */ MKNode(mac_t mac_addr, ip4_t ip_addr); ~MKNode(); /*! Represents a link to a one-hop neighbor. */ struct MKNeighbor { /*! \brief Constructs a new MKNeighbor that refers to a particular node. \param node The the neighbor node. \pre node must not be NULL. */ MKNeighbor(const MKNode *node); ~MKNeighbor(); /*! MKNode that represents MKNeighbor */ const MKNode *node; /*! Time to send a sample packet from MKNode to MKNeighbor and back to MKNode. */ latency_t latency; /*! Signal strength of MKNeighbor as measured by MKNode. */ signal_strength_t signal; /*! Weight (aka, metric) from MKNode to MKNeighbor. */ weight_t weight; /*! Throughput in kb/s from MKNode to MKNeighbor. */ throughput_t throughput; /*! Amount of time measured in microseconds that MKNode has not receieved a packet from MKNeighbor. */ inactive_t inactive; }; /** A MKRoute is like a MKNeighbor except possibly over multiple hops */ struct MKRoute { MKRoute(const MKNode *dest); ~MKRoute(); const MKNode *node; latency_t latency; void clearHops(); void addNextHop(MKNode *); inline std::vector getHops() { return std::vector(hops); } int length() { return hops.size(); } throughput_t throughput(); private: std::vector hops; }; /*! \brief Returns a string containing the mac address and ip address of this node. \return A string of the form "[MKNode $mac @ $ip4]" where $mac is the mac address and $ip4 is the ip4 address. */ operator std::string() const; /*! \brief Returns a new node that represents this node. \details A new node will be allocated; it is the caller's responsibility to free this memory. \return A new node that represents this node. */ node *asCommNode() const; /*! \brief Adds a neighbor node along with the link info between this node and the neighbor node. \details The link info represents this node's connection with the neighbor node. \param node The neighbor node to add. \param link The link info between this node and the neighbor nodde. \pre node is not null and has Mac + IP set. \pre link must not be NULL. */ void addNeighbor(const MKNode *node, NeighborInfo *link); /*! \brief get neighbor information */ MKNeighbor *nbr(mac_t target); /*! \brief Get route information */ MKRoute *route(mac_t target); /*! \brief add a new route */ MKRoute *addRoute(MKNode *target); /*! \brief Clears the route cache */ void clearRoutes(); /*! \brief Clears this node's neighbors. */ void clearNeighbors(); /*! \brief Returns this node's IP address. \return This node's IP address. */ inline ip4_t getIP4() const { return ip4; } inline mac_t getMAC() const { return mac; } /*! \brief Returns a copy of this node's list of neighbors. \details The nodes shall be ordered in the returned vector in the same order that they where added. \return n copy of this node's list of neighbors. */ std::vector getNeighbors() const; /*! \brief Sets this node's ip address. \param ip The new ip address for this node. \pre ip must be > 0. */ inline void setIP(ip4_t ip) { ip4 = ip; } protected: /*! This node's mac address. */ const mac_t mac; /*! This node's ip address */ ip4_t ip4; /*! This node's list of neighbors */ std::map neighbors; /*! Known route information */ std::map routes; }; #endif