# HG changeset patch # Parent f77377f7222367334e6cfce4a0e26e56df302166 # User Tommaso Pecorella # Date 1384896923 -3600 Bug 938 - missing Doxygen in ns-3 (internet model) diff --git a/src/internet/model/arp-cache.h b/src/internet/model/arp-cache.h --- a/src/internet/model/arp-cache.h +++ b/src/internet/model/arp-cache.h @@ -49,34 +49,78 @@ class ArpCache : public Object { private: + /** + * \brief Copy constructor + * + * Defined and unimplemented to avoid misuse + */ ArpCache (ArpCache const &); + /** + * \brief Copy constructor + * + * Defined and unimplemented to avoid misuse + * \returns + */ ArpCache& operator= (ArpCache const &); public: + /** + * \brief Get the type ID. + * \return the object TypeId + */ static TypeId GetTypeId (void); class Entry; ArpCache (); ~ArpCache (); /** + * \brief Set the NetDevice and Ipv4Interface associated with the ArpCache + * * \param device The hardware NetDevice associated with this ARP chache * \param interface the Ipv4Interface associated with this ARP chache */ void SetDevice (Ptr device, Ptr interface); /** + * \brief Returns the NetDevice that this ARP cache is associated with * \return The NetDevice that this ARP cache is associated with */ Ptr GetDevice (void) const; /** + * \brief Returns the Ipv4Interface that this ARP cache is associated with * \return the Ipv4Interface that this ARP cache is associated with */ Ptr GetInterface (void) const; + /** + * \brief Set the time the entry will be in ALIVE state (unless refreshed) + * \param aliveTimeout the Alive state timeout + */ void SetAliveTimeout (Time aliveTimeout); + /** + * \brief Set the time the entry will be in DEAD state before being removed + * \param deadTimeout the Dead state timeout + */ void SetDeadTimeout (Time deadTimeout); + /** + * \brief Set the time the entry will be in WAIT_REPLY state + * \param waitReplyTimeout the WAIT_REPLY state timeout + */ void SetWaitReplyTimeout (Time waitReplyTimeout); + + /** + * \brief Get the time the entry will be in ALIVE state (unless refreshed) + * \returns the Alive state timeout + */ Time GetAliveTimeout (void) const; + /** + * \brief Get the time the entry will be in DEAD state before being removed + * \returns the Dead state timeout + */ Time GetDeadTimeout (void) const; + /** + * \brief Get the time the entry will be in WAIT_REPLY state + * \returns the WAIT_REPLY state timeout + */ Time GetWaitReplyTimeout (void) const; /** @@ -190,46 +234,65 @@ void ClearRetries (void); private: + /** + * \brief ARP cache entry states + */ enum ArpCacheEntryState_e { ALIVE, WAIT_REPLY, DEAD }; + /** + * \brief Update the entry when seeing a packet + */ void UpdateSeen (void); + + /** + * \brief Returns the entry timeout + * \returns the entry timeout + */ Time GetTimeout (void) const; - ArpCache *m_arp; - ArpCacheEntryState_e m_state; - Time m_lastSeen; - Address m_macAddress; - Ipv4Address m_ipv4Address; - std::list > m_pending; - uint32_t m_retries; + + ArpCache *m_arp; //!< pointer to the ARP cache owning the entry + ArpCacheEntryState_e m_state; //!< state of the entry + Time m_lastSeen; //!< last moment a packet from that address has been seen + Address m_macAddress; //!< entry's MAC address + Ipv4Address m_ipv4Address; //!< entry's IP address + std::list > m_pending; //!< list of pending packets for the entry's IP + uint32_t m_retries; //!< rerty counter }; private: + /** + * \brief ARP Cache container + */ typedef sgi::hash_map Cache; + /** + * \brief ARP Cache container iterator + */ typedef sgi::hash_map::iterator CacheI; virtual void DoDispose (void); - Ptr m_device; - Ptr m_interface; - Time m_aliveTimeout; - Time m_deadTimeout; - Time m_waitReplyTimeout; - EventId m_waitReplyTimer; - Callback, Ipv4Address> m_arpRequestCallback; - uint32_t m_maxRetries; + Ptr m_device; //!< NetDevice associated with the cache + Ptr m_interface; //!< Ipv4Interface associated with the cache + Time m_aliveTimeout; //!< cache alive state timeout + Time m_deadTimeout; //!< cache dead state timeout + Time m_waitReplyTimeout; //!< cache reply state timeout + EventId m_waitReplyTimer; //!< cache alive state timer + Callback, Ipv4Address> m_arpRequestCallback; //!< reply timeout callback + uint32_t m_maxRetries; //!< max retries for a resolution + /** * This function is an event handler for the event that the * ArpCache wants to check whether it must retry any Arp requests. * If there are no Arp requests pending, this event is not scheduled. */ void HandleWaitReplyTimeout (void); - uint32_t m_pendingQueueSize; - Cache m_arpCache; - TracedCallback > m_dropTrace; + uint32_t m_pendingQueueSize; //!< number of packets waiting for a resolution + Cache m_arpCache; //!< the ARP cache + TracedCallback > m_dropTrace; //!< trace for packets dropped by the ARP cache queue }; diff --git a/src/internet/model/arp-header.h b/src/internet/model/arp-header.h --- a/src/internet/model/arp-header.h +++ b/src/internet/model/arp-header.h @@ -34,21 +34,69 @@ class ArpHeader : public Header { public: + /** + * \brief Set the ARP request parameters + * \param sourceHardwareAddress the source hardware address + * \param sourceProtocolAddress the source IP address + * \param destinationHardwareAddress the destination hardware address (usually the broadcast address) + * \param destinationProtocolAddress the destination IP address + */ void SetRequest (Address sourceHardwareAddress, Ipv4Address sourceProtocolAddress, Address destinationHardwareAddress, Ipv4Address destinationProtocolAddress); + /** + * \brief Set the ARP reply parameters + * \param sourceHardwareAddress the source hardware address + * \param sourceProtocolAddress the source IP address + * \param destinationHardwareAddress the destination hardware address (usually the broadcast address) + * \param destinationProtocolAddress the destination IP address + */ void SetReply (Address sourceHardwareAddress, Ipv4Address sourceProtocolAddress, Address destinationHardwareAddress, Ipv4Address destinationProtocolAddress); + + /** + * \brief Check if the ARP is a request + * \returns true if it is a request + */ bool IsRequest (void) const; + + /** + * \brief Check if the ARP is a reply + * \returns true if it is a reply + */ bool IsReply (void) const; + + /** + * \brief Returns the source hardware address + * \returns the source hardware address + */ Address GetSourceHardwareAddress (void); + + /** + * \brief Returns the destination hardware address + * \returns the destination hardware address + */ Address GetDestinationHardwareAddress (void); + + /** + * \brief Returns the source IP address + * \returns the source IP address + */ Ipv4Address GetSourceIpv4Address (void); + + /** + * \brief Returns the destination IP address + * \returns the destination IP address + */ Ipv4Address GetDestinationIpv4Address (void); + /** + * \brief Get the type ID. + * \return the object TypeId + */ static TypeId GetTypeId (void); virtual TypeId GetInstanceTypeId (void) const; virtual void Print (std::ostream &os) const; @@ -56,15 +104,18 @@ virtual void Serialize (Buffer::Iterator start) const; virtual uint32_t Deserialize (Buffer::Iterator start); + /** + * \brief Enumeration listing the possible ARP types + */ enum ArpType_e { ARP_TYPE_REQUEST = 1, ARP_TYPE_REPLY = 2 }; - uint16_t m_type; - Address m_macSource; - Address m_macDest; - Ipv4Address m_ipv4Source; - Ipv4Address m_ipv4Dest; + uint16_t m_type; //!< type of the ICMP (ARP_TYPE_REQUEST) + Address m_macSource; //!< hardware source address + Address m_macDest; //!< hardware destination address + Ipv4Address m_ipv4Source; //!< IP source address + Ipv4Address m_ipv4Dest; //!< IP destination address }; } // namespace ns3 diff --git a/src/internet/model/arp-l3-protocol.h b/src/internet/model/arp-l3-protocol.h --- a/src/internet/model/arp-l3-protocol.h +++ b/src/internet/model/arp-l3-protocol.h @@ -49,29 +49,49 @@ class ArpL3Protocol : public Object { public: + /** + * \brief Get the type ID. + * \return the object TypeId + */ static TypeId GetTypeId (void); - static const uint16_t PROT_NUMBER; + static const uint16_t PROT_NUMBER; //!< ARP protocol number (0x0806) ArpL3Protocol (); virtual ~ArpL3Protocol (); + /** + * \brief Set the node the ARP L3 protocol is associated with + * \param node the node + */ void SetNode (Ptr node); + /** + * \brief Create an ARP cache for the device/interface + * \param device the NetDevice + * \param interface the Ipv4Interface + * \returns a smart pointer to the ARP cache + */ Ptr CreateCache (Ptr device, Ptr interface); /** * \brief Receive a packet + * \param device the source NetDevice + * \param p the packet + * \param protocol the protocol + * \param from the source address + * \param to the destination address + * \param packetType type of packet (i.e., unicast, multicast, etc.) */ void Receive (Ptr device, Ptr p, uint16_t protocol, const Address &from, const Address &to, NetDevice::PacketType packetType); /** * \brief Perform an ARP lookup - * \param p - * \param destination - * \param device - * \param cache - * \param hardwareDestination - * \return + * \param p the packet + * \param destination destination IP address + * \param device outgoing device + * \param cache ARP cache + * \param hardwareDestination filled with the destination MAC address (if the entry exists) + * \return true if there is a matching ARP Entry */ bool Lookup (Ptr p, Ipv4Address destination, Ptr device, @@ -96,16 +116,49 @@ */ virtual void NotifyNewAggregate (); private: - typedef std::list > CacheList; + typedef std::list > CacheList; //!< container of the ARP caches + /** + * \brief Copy constructor + * + * Defined and unimplemented to avoid misuse + * \param o + */ ArpL3Protocol (const ArpL3Protocol &o); + /** + * \brief Copy constructor + * + * Defined and unimplemented to avoid misuse + * \param o + * \returns + */ ArpL3Protocol &operator = (const ArpL3Protocol &o); + + /** + * \brief Finds the cache associated with a NetDevice + * \param device the NetDevice + * \returns the ARP cache, or null if no cache is found + */ Ptr FindCache (Ptr device); + + /** + * \brief Send an ARP request to an host + * \param cache the ARP cache to use + * \param to the destination IP + */ void SendArpRequest (Ptrcache, Ipv4Address to); + /** + * \brief Send an ARP reply to an host + * \param cache the ARP cache to use + * \param myIp the source IP address + * \param toIp the destination IP + * \param toMac the destination MAC address + */ void SendArpReply (Ptr cache, Ipv4Address myIp, Ipv4Address toIp, Address toMac); - CacheList m_cacheList; - Ptr m_node; - TracedCallback > m_dropTrace; - Ptr m_requestJitter; + + CacheList m_cacheList; //!< ARP cache container + Ptr m_node; //!< node the ARP L3 protocol is associated with + TracedCallback > m_dropTrace; //!< trace for packets dropped by ARP + Ptr m_requestJitter; //!< jitter to de-sync ARP requests }; diff --git a/src/internet/model/candidate-queue.cc b/src/internet/model/candidate-queue.cc --- a/src/internet/model/candidate-queue.cc +++ b/src/internet/model/candidate-queue.cc @@ -27,6 +27,13 @@ namespace ns3 { +/** + * \brief Stream insertion operator. + * + * \param os the reference to the output stream + * \param t the SPFVertex type + * \returns the reference to the output stream + */ std::ostream& operator<< (std::ostream& os, const SPFVertex::VertexType& t) { diff --git a/src/internet/model/candidate-queue.h b/src/internet/model/candidate-queue.h --- a/src/internet/model/candidate-queue.h +++ b/src/internet/model/candidate-queue.h @@ -176,6 +176,7 @@ * prevent the compiler from slipping in incorrect versions that don't * properly deal with deep copies. * \param sr object to assign + * \return copied object */ CandidateQueue& operator= (CandidateQueue& sr); /** @@ -185,13 +186,22 @@ * defined by this method. If v1 should be popped before v2, this * method return true; false otherwise * + * \param v1 first operand + * \param v2 second operand * \return True if v1 should be popped before v2; false otherwise */ static bool CompareSPFVertex (const SPFVertex* v1, const SPFVertex* v2); - typedef std::list CandidateList_t; - CandidateList_t m_candidates; + typedef std::list CandidateList_t; //!< container of SPFVertex pointers + CandidateList_t m_candidates; //!< SPFVertex candidates + /** + * \brief Stream insertion operator. + * + * \param os the reference to the output stream + * \param q the CandidateQueue + * \returns the reference to the output stream + */ friend std::ostream& operator<< (std::ostream& os, const CandidateQueue& q); }; diff --git a/src/internet/model/global-route-manager-impl.cc b/src/internet/model/global-route-manager-impl.cc --- a/src/internet/model/global-route-manager-impl.cc +++ b/src/internet/model/global-route-manager-impl.cc @@ -44,6 +44,13 @@ namespace ns3 { +/** + * \brief Stream insertion operator. + * + * \param os the reference to the output stream + * \param exit the exit node + * \returns the reference to the output stream + */ std::ostream& operator<< (std::ostream& os, const SPFVertex::NodeExit_t& exit) { diff --git a/src/internet/model/global-route-manager-impl.h b/src/internet/model/global-route-manager-impl.h --- a/src/internet/model/global-route-manager-impl.h +++ b/src/internet/model/global-route-manager-impl.h @@ -34,7 +34,7 @@ namespace ns3 { -const uint32_t SPF_INFINITY = 0xffffffff; +const uint32_t SPF_INFINITY = 0xffffffff; //!< "infinite" distance between nodes class CandidateQueue; class Ipv4GlobalRouting; @@ -298,7 +298,9 @@ * network represented by "this" SPFVertex. */ void SetRootExitDirection (Ipv4Address nextHop, int32_t id = SPF_INFINITY); - typedef std::pair NodeExit_t; + + typedef std::pair NodeExit_t; //!< IPv4 / interface container for exit nodes. + /** * @brief Set the IP address and outgoing interface index that should be used * to begin forwarding packets from the root SPFVertex to "this" SPFVertex. @@ -532,22 +534,27 @@ */ bool IsVertexProcessed (void) const; + /** + * @brief Clear the value of the VertexProcessed flag + * + * Flag to note whether vertex has been processed in stage two of + * SPF computation + */ void ClearVertexProcessed (void); private: - VertexType m_vertexType; - Ipv4Address m_vertexId; - GlobalRoutingLSA* m_lsa; - uint32_t m_distanceFromRoot; - int32_t m_rootOif; - Ipv4Address m_nextHop; - typedef std::list< NodeExit_t > ListOfNodeExit_t; - /// store the multiple root's exits for supporting ECMP - ListOfNodeExit_t m_ecmpRootExits; - typedef std::list ListOfSPFVertex_t; - ListOfSPFVertex_t m_parents; - ListOfSPFVertex_t m_children; - bool m_vertexProcessed; + VertexType m_vertexType; //!< Vertex type + Ipv4Address m_vertexId; //!< Vertex ID + GlobalRoutingLSA* m_lsa; //!< Link State Advertisement + uint32_t m_distanceFromRoot; //!< Distance from root node + int32_t m_rootOif; //!< root Output Interface + Ipv4Address m_nextHop; //!< next hop + typedef std::list< NodeExit_t > ListOfNodeExit_t; //!< container of Exit nodes + ListOfNodeExit_t m_ecmpRootExits; //!< store the multiple root's exits for supporting ECMP + typedef std::list ListOfSPFVertex_t; //!< container of SPFVertexes + ListOfSPFVertex_t m_parents; //!< parent list + ListOfSPFVertex_t m_children; //!< Children list + bool m_vertexProcessed; //!< Flag to note whether vertex has been processed in stage two of SPF computation /** * @brief The SPFVertex copy construction is disallowed. There's no need for @@ -561,8 +568,13 @@ */ SPFVertex& operator= (SPFVertex& v); - //friend std::ostream& operator<< (std::ostream& os, const ListOfIf_t& ifs); - //friend std::ostream& operator<< (std::ostream& os, const ListOfAddr_t& addrs); + /** + * \brief Stream insertion operator. + * + * \param os the reference to the output stream + * \param vs a list of SPFVertexes + * \returns the reference to the output stream + */ friend std::ostream& operator<< (std::ostream& os, const SPFVertex::ListOfSPFVertex_t& vs); }; @@ -662,16 +674,35 @@ */ void Initialize (); + /** + * @brief Look up the External Link State Advertisement associated with the given + * index. + * @internal + * + * The external database map is searched for the given index and corresponding + * GlobalRoutingLSA is returned. + * + * @see GlobalRoutingLSA + * @param index the index associated with the LSA. + * @returns A pointer to the Link State Advertisement. + */ GlobalRoutingLSA* GetExtLSA (uint32_t index) const; + /** + * @brief Get the number of External Link State Advertisements. + * @internal + * + * @see GlobalRoutingLSA + * @returns the number of External Link State Advertisements. + */ uint32_t GetNumExtLSAs () const; private: - typedef std::map LSDBMap_t; - typedef std::pair LSDBPair_t; + typedef std::map LSDBMap_t; //!< container of IPv4 addresses / Link State Advertisements + typedef std::pair LSDBPair_t; //!< pair of IPv4 addresses / Link State Advertisements - LSDBMap_t m_database; - std::vector m_extdatabase; + LSDBMap_t m_database; //!< database of IPv4 addresses / Link State Advertisements + std::vector m_extdatabase; //!< database of External Link State Advertisements /** * @brief GlobalRouteManagerLSDB copy construction is disallowed. There's no @@ -736,6 +767,7 @@ /** * @brief Debugging routine; call the core SPF from the unit tests * @internal + * @param root the root node to start calculations */ void DebugSPFCalculate (Ipv4Address root); @@ -754,22 +786,184 @@ */ GlobalRouteManagerImpl& operator= (GlobalRouteManagerImpl& srmi); - SPFVertex* m_spfroot; - GlobalRouteManagerLSDB* m_lsdb; + SPFVertex* m_spfroot; //!< the root node + GlobalRouteManagerLSDB* m_lsdb; //!< the Link State DataBase (LSDB) of the Global Route Manager + + /** + * \brief Test if a node is a stub, from an OSPF sense. + * + * If there is only one link of type 1 or 2, then a default route + * can safely be added to the next-hop router and SPF does not need + * to be run + * + * \param root the root node + * \returns true if the node is a stub + */ bool CheckForStubNode (Ipv4Address root); + + /** + * \brief Calculate the shortest path first (SPF) tree + * + * Equivalent to quagga ospf_spf_calculate + * \param root the root node + */ void SPFCalculate (Ipv4Address root); + + /** + * \brief Process Stub nodes + * + * Processing logic from RFC 2328, page 166 and quagga ospf_spf_process_stubs () + * stub link records will exist for point-to-point interfaces and for + * broadcast interfaces for which no neighboring router can be found + * + * \param v vertex to be processed + */ void SPFProcessStubs (SPFVertex* v); + + /** + * \brief Process Autonomous Systems (AS) External LSA + * + * \param v vertex to be processed + * \param extlsa external LSA + */ void ProcessASExternals (SPFVertex* v, GlobalRoutingLSA* extlsa); - void SPFNext (SPFVertex*, CandidateQueue&); + + /** + * \brief Examine the links in v's LSA and update the list of candidates with any + * vertices not already on the list + * + * \internal + * + * This method is derived from quagga ospf_spf_next (). See RFC2328 Section + * 16.1 (2) for further details. + * + * We're passed a parameter \a v that is a vertex which is already in the SPF + * tree. A vertex represents a router node. We also get a reference to the + * SPF candidate queue, which is a priority queue containing the shortest paths + * to the networks we know about. + * + * We examine the links in v's LSA and update the list of candidates with any + * vertices not already on the list. If a lower-cost path is found to a + * vertex already on the candidate list, store the new (lower) cost. + * + * \param v the vertex + * \param candidate the SPF candidate queue + */ + void SPFNext (SPFVertex* v, CandidateQueue& candidate); + + /** + * \brief Calculate nexthop from root through V (parent) to vertex W (destination) + * with given distance from root->W. + * + * This method is derived from quagga ospf_nexthop_calculation() 16.1.1. + * For now, this is greatly simplified from the quagga code + * + * \param v the parent + * \param w the destination + * \param l the link record + * \param distance the target distance + * \returns 1 on success + */ int SPFNexthopCalculation (SPFVertex* v, SPFVertex* w, GlobalRoutingLinkRecord* l, uint32_t distance); + + /** + * \brief Adds a vertex to the list of children *in* each of its parents + * + * Derived from quagga ospf_vertex_add_parents () + * + * This is a somewhat oddly named method (blame quagga). Although you might + * expect it to add a parent *to* something, it actually adds a vertex + * to the list of children *in* each of its parents. + * + * Given a pointer to a vertex, it links back to the vertex's parent that it + * already has set and adds itself to that vertex's list of children. + * + * \param v the vertex + */ void SPFVertexAddParent (SPFVertex* v); + + /** + * \brief Search for a link between two vertexes. + * + * This method is derived from quagga ospf_get_next_link () + * + * First search the Global Router Link Records of vertex \a v for one + * representing a point-to point link to vertex \a w. + * + * What is done depends on prev_link. Contrary to appearances, prev_link just + * acts as a flag here. If prev_link is NULL, we return the first Global + * Router Link Record we find that describes a point-to-point link from \a v + * to \a w. If prev_link is not NULL, we return a Global Router Link Record + * representing a possible *second* link from \a v to \a w. + * + * \param v first vertex + * \param w second vertex + * \param prev_link the previous link in the list + * \returns the link's record + */ GlobalRoutingLinkRecord* SPFGetNextLink (SPFVertex* v, SPFVertex* w, GlobalRoutingLinkRecord* prev_link); + + /** + * \brief Add a host route to the routing tables + * + * + * This method is derived from quagga ospf_intra_add_router () + * + * This is where we are actually going to add the host routes to the routing + * tables of the individual nodes. + * + * The vertex passed as a parameter has just been added to the SPF tree. + * This vertex must have a valid m_root_oid, corresponding to the outgoing + * interface on the root router of the tree that is the first hop on the path + * to the vertex. The vertex must also have a next hop address, corresponding + * to the next hop on the path to the vertex. The vertex has an m_lsa field + * that has some number of link records. For each point to point link record, + * the m_linkData is the local IP address of the link. This corresponds to + * a destination IP address, reachable from the root, to which we add a host + * route. + * + * \param v the vertex + * + */ void SPFIntraAddRouter (SPFVertex* v); + + /** + * \brief Add a transit to the routing tables + * + * \param v the vertex + */ void SPFIntraAddTransit (SPFVertex* v); + + /** + * \brief Add a stub to the routing tables + * + * \param l the global routing link record + * \param v the vertex + */ void SPFIntraAddStub (GlobalRoutingLinkRecord *l, SPFVertex* v); + + /** + * \brief Add an external route to the routing tables + * + * \param extlsa the external LSA + * \param v the vertex + */ void SPFAddASExternal (GlobalRoutingLSA *extlsa, SPFVertex *v); + + /** + * \brief Return the interface number corresponding to a given IP address and mask + * + * This is a wrapper around GetInterfaceForPrefix(), but we first + * have to find the right node pointer to pass to that function. + * If no such interface is found, return -1 (note: unit test framework + * for routing assumes -1 to be a legal return value) + * + * \param a the target IP address + * \param amask the target subnet mask + * \return the outgoing interface number + */ int32_t FindOutgoingInterfaceId (Ipv4Address a, Ipv4Mask amask = Ipv4Mask ("255.255.255.255")); }; diff --git a/src/internet/model/global-router-interface.h b/src/internet/model/global-router-interface.h --- a/src/internet/model/global-router-interface.h +++ b/src/internet/model/global-router-interface.h @@ -559,9 +559,16 @@ * proper position in the tree. */ SPFStatus m_status; - uint32_t m_node_id; + uint32_t m_node_id; //!< node ID }; +/** + * \brief Stream insertion operator. + * + * \param os the reference to the output stream + * \param lsa the LSA + * \returns the reference to the output stream + */ std::ostream& operator<< (std::ostream& os, GlobalRoutingLSA& lsa); /** @@ -576,11 +583,10 @@ class GlobalRouter : public Object { public: -/** - * @brief The Interface ID of the Global Router interface. - * - * @see Object::GetObject () - */ + /** + * \brief Get the type ID. + * \return the object TypeId + */ static TypeId GetTypeId (void); /** @@ -588,8 +594,16 @@ */ GlobalRouter (); + /** + * \brief Set the specific Global Routing Protocol to be used + * \param routing the routing protocol + */ + void SetRoutingProtocol (Ptr routing); - void SetRoutingProtocol (Ptr routing); + /** + * \brief Get the specific Global Routing Protocol used + * \returns the routing protocol + */ Ptr GetRoutingProtocol (void); /** @@ -709,31 +723,129 @@ private: virtual ~GlobalRouter (); + + /** + * \brief Clear list of LSAs + */ void ClearLSAs (void); + /** + * \brief Link through the given channel and find the net device that's on the other end. + * + * This only makes sense with a point-to-point channel. + * + * \param nd outgoing NetDevice + * \param ch channel + * \returns the NetDevice on the other end + */ Ptr GetAdjacent (Ptr nd, Ptr ch) const; + + /** + * \brief Given a node and a net device, find an IPV4 interface index that corresponds + * to that net device. + * + * This function may fail for various reasons. If a node + * does not have an internet stack (for example if it is a bridge) we won't have + * an IPv4 at all. If the node does have a stack, but the net device in question + * is bridged, there will not be an interface associated directly with the device. + * + * \param node the node + * \param nd outgoing NetDevice + * \param index the IPV4 interface index + * \returns true on success + */ bool FindInterfaceForDevice (Ptr node, Ptr nd, uint32_t &index) const; + + /** + * \brief Finds a designated router + * + * Given a local net device, we need to walk the channel to which the net device is + * attached and look for nodes with GlobalRouter interfaces on them (one of them + * will be us). Of these, the router with the lowest IP address on the net device + * connecting to the channel becomes the designated router for the link. + * + * \param ndLocal local NetDevice to scan + * \param allowRecursion Recursively look for routers down bridge port + * \returns the IP address of the designated router + */ Ipv4Address FindDesignatedRouterForLink (Ptr ndLocal, bool allowRecursion) const; + + /** + * \brief Checks for the presence of another router on the NetDevice + * + * Given a node and an attached net device, take a look off in the channel to + * which the net device is attached and look for a node on the other side + * that has a GlobalRouter interface aggregated. Life gets more complicated + * when there is a bridged net device on the other side. + * + * \param nd NetDevice to scan + * \param allowRecursion Recursively look for routers down bridge port + * \returns true if a router is found + */ bool AnotherRouterOnLink (Ptr nd, bool allowRecursion) const; + + /** + * \brief Process a generic broadcast link + * + * \param nd the NetDevice + * \param pLSA the Global LSA + * \param c the returned NetDevice container + */ void ProcessBroadcastLink (Ptr nd, GlobalRoutingLSA *pLSA, NetDeviceContainer &c); + + /** + * \brief Process a single broadcast link + * + * \param nd the NetDevice + * \param pLSA the Global LSA + * \param c the returned NetDevice container + */ void ProcessSingleBroadcastLink (Ptr nd, GlobalRoutingLSA *pLSA, NetDeviceContainer &c); + + /** + * \brief Process a bridged broadcast link + * + * \param nd the NetDevice + * \param pLSA the Global LSA + * \param c the returned NetDevice container + */ void ProcessBridgedBroadcastLink (Ptr nd, GlobalRoutingLSA *pLSA, NetDeviceContainer &c); + /** + * \brief Process a point to point link + * + * \param ndLocal the NetDevice + * \param pLSA the Global LSA + */ void ProcessPointToPointLink (Ptr ndLocal, GlobalRoutingLSA *pLSA); + + /** + * \brief Build one NetworkLSA for each net device talking to a network that we are the + * designated router for. + * + * \param c the devices. + */ void BuildNetworkLSAs (NetDeviceContainer c); + + /** + * \brief Decide whether or not a given net device is being bridged by a BridgeNetDevice. + * + * \param nd the NetDevice + * \returns the BridgeNetDevice smart pointer or null if not found + */ Ptr NetDeviceIsBridged (Ptr nd) const; - typedef std::list ListOfLSAs_t; - ListOfLSAs_t m_LSAs; + typedef std::list ListOfLSAs_t; //!< container for the GlobalRoutingLSAs + ListOfLSAs_t m_LSAs; //!< database of GlobalRoutingLSAs - Ipv4Address m_routerId; - Ptr m_routingProtocol; + Ipv4Address m_routerId; //!< router ID (its IPv4 address) + Ptr m_routingProtocol; //!< the Ipv4GlobalRouting in use - typedef std::list InjectedRoutes; - typedef std::list::const_iterator InjectedRoutesCI; - typedef std::list::iterator InjectedRoutesI; - InjectedRoutes m_injectedRoutes; // Routes we are exporting + typedef std::list InjectedRoutes; //!< container of Ipv4RoutingTableEntry + typedef std::list::const_iterator InjectedRoutesCI; //!< Const Iterator to container of Ipv4RoutingTableEntry + typedef std::list::iterator InjectedRoutesI; //!< Iterator to container of Ipv4RoutingTableEntry + InjectedRoutes m_injectedRoutes; //!< Routes we are exporting // inherited from Object virtual void DoDispose (void); diff --git a/src/internet/model/icmpv4-l4-protocol.h b/src/internet/model/icmpv4-l4-protocol.h --- a/src/internet/model/icmpv4-l4-protocol.h +++ b/src/internet/model/icmpv4-l4-protocol.h @@ -14,22 +14,40 @@ class Icmpv4L4Protocol : public IpL4Protocol { public: + /** + * \brief Get the type ID. + * \return the object TypeId + */ static TypeId GetTypeId (void); - static const uint8_t PROT_NUMBER; + static const uint8_t PROT_NUMBER; //!< ICMP protocol number (0x1) Icmpv4L4Protocol (); virtual ~Icmpv4L4Protocol (); + /** + * \brief Set the node the protocol is associated with. + * \param node the node + */ void SetNode (Ptr node); + /** + * Get the protocol number + * \returns the protocol number + */ static uint16_t GetStaticProtocolNumber (void); + + /** + * Get the protocol number + * \returns the protocol number + */ virtual int GetProtocolNumber (void) const; /** * \brief Receive method. * \param p the packet * \param header the IPv4 header - * \param interface the interface from which the packet is coming + * \param incomingInterface the interface from which the packet is coming + * \returns the receive status */ virtual enum IpL4Protocol::RxStatus Receive (Ptr p, Ipv4Header const &header, @@ -39,14 +57,33 @@ * \brief Receive method. * \param p the packet * \param header the IPv6 header - * \param interface the interface from which the packet is coming + * \param incomingInterface the interface from which the packet is coming + * \returns the receive status */ virtual enum IpL4Protocol::RxStatus Receive (Ptr p, Ipv6Header const &header, Ptr incomingInterface); + /** + * \brief Send a Destination Unreachable - Fragmentation needed ICMP error + * \param header the original IP header + * \param orgData the original packet + * \param nextHopMtu the next hop MTU + */ void SendDestUnreachFragNeeded (Ipv4Header header, Ptr orgData, uint16_t nextHopMtu); + + /** + * \brief Send a Time Exceeded ICMP error + * \param header the original IP header + * \param orgData the original packet + */ void SendTimeExceededTtl (Ipv4Header header, Ptr orgData); + + /** + * \brief Send a Time Exceeded ICMP error + * \param header the original IP header + * \param orgData the original packet + */ void SendDestUnreachPort (Ipv4Header header, Ptr orgData); // From IpL4Protocol @@ -62,30 +99,86 @@ */ virtual void NotifyNewAggregate (); private: + /** + * \brief Handles an incoming ICMP Echo packet + * \param p the packet + * \param header the IP header + * \param source the source address + * \param destination the destination address + */ void HandleEcho (Ptr p, Icmpv4Header header, Ipv4Address source, Ipv4Address destination); + /** + * \brief Handles an incoming ICMP Destination Unreachable packet + * \param p the packet + * \param header the IP header + * \param source the source address + * \param destination the destination address + */ void HandleDestUnreach (Ptr p, Icmpv4Header header, Ipv4Address source, Ipv4Address destination); + /** + * \brief Handles an incoming ICMP Time Exceeded packet + * \param p the packet + * \param icmp the ICMP header + * \param source the source address + * \param destination the destination address + */ void HandleTimeExceeded (Ptr p, Icmpv4Header icmp, Ipv4Address source, Ipv4Address destination); + /** + * \brief Send an ICMP Destination Unreachable packet + * + * \param header the original IP header + * \param orgData the original packet + * \param code the ICMP code + * \param nextHopMtu the next hop MTU + */ void SendDestUnreach (Ipv4Header header, Ptr orgData, uint8_t code, uint16_t nextHopMtu); + /** + * \brief Send a generic ICMP packet + * + * \param packet the packet + * \param dest the destination + * \param type the ICMP type + * \param code the ICMP code + */ void SendMessage (Ptr packet, Ipv4Address dest, uint8_t type, uint8_t code); + /** + * \brief Send a generic ICMP packet + * + * \param packet the packet + * \param source the source + * \param dest the destination + * \param type the ICMP type + * \param code the ICMP code + * \param route the route to be used + */ void SendMessage (Ptr packet, Ipv4Address source, Ipv4Address dest, uint8_t type, uint8_t code, Ptr route); + /** + * \brief Forward the message to an L4 protocol + * + * \param source the source + * \param icmp the ICMP header + * \param info info data (e.g., the target MTU) + * \param ipHeader the IP header carried by ICMP + * \param payload payload chunk carried by ICMP + */ void Forward (Ipv4Address source, Icmpv4Header icmp, uint32_t info, Ipv4Header ipHeader, const uint8_t payload[8]); virtual void DoDispose (void); - Ptr m_node; - IpL4Protocol::DownTargetCallback m_downTarget; + Ptr m_node; //!< the node this protocol is associated with + IpL4Protocol::DownTargetCallback m_downTarget; //!< callback to Ipv4::Send }; } // namespace ns3 diff --git a/src/internet/model/icmpv4.h b/src/internet/model/icmpv4.h --- a/src/internet/model/icmpv4.h +++ b/src/internet/model/icmpv4.h @@ -40,16 +40,42 @@ TIME_EXCEEDED = 11 }; + /** + * Enables ICMP Checksum calculation + */ void EnableChecksum (void); + + /** + * Set ICMP type + * \param type the ICMP type + */ void SetType (uint8_t type); + + /** + * Set ICMP code + * \param code the ICMP code + */ void SetCode (uint8_t code); + /** + * Get ICMP type + * \returns the ICMP type + */ uint8_t GetType (void) const; + /** + * Get ICMP code + * \returns the ICMP code + */ uint8_t GetCode (void) const; + /** + * \brief Get the type ID. + * \return the object TypeId + */ static TypeId GetTypeId (void); Icmpv4Header (); virtual ~Icmpv4Header (); + virtual TypeId GetInstanceTypeId (void) const; virtual uint32_t GetSerializedSize (void) const; virtual void Serialize (Buffer::Iterator start) const; @@ -57,23 +83,56 @@ virtual void Print (std::ostream &os) const; private: - uint8_t m_type; - uint8_t m_code; - bool m_calcChecksum; + uint8_t m_type; //!< ICMP type + uint8_t m_code; //!< ICMP code + bool m_calcChecksum; //!< true if checksum is calculated }; class Icmpv4Echo : public Header { public: + /** + * \brief Set the Echo identifier + * \param id the identifier + */ void SetIdentifier (uint16_t id); + /** + * \brief Set the Echo sequence number + * \param seq the sequence number + */ void SetSequenceNumber (uint16_t seq); + /** + * \brief Set the Echo data + * \param data the data + */ void SetData (Ptr data); + /** + * \brief Get the Echo identifier + * \returns the identifier + */ uint16_t GetIdentifier (void) const; + /** + * \brief Get the Echo sequence number + * \returns the sequence number + */ uint16_t GetSequenceNumber (void) const; + /** + * \brief Get the Echo data size + * \returns the data size + */ uint32_t GetDataSize (void) const; + /** + * \brief Get the Echo data + * \param payload the data (filled) + * \returns the data length + */ uint32_t GetData (uint8_t payload[]) const; + /** + * Get ICMP type + * \returns the ICMP type + */ static TypeId GetTypeId (void); Icmpv4Echo (); virtual ~Icmpv4Echo (); @@ -83,10 +142,10 @@ virtual uint32_t Deserialize (Buffer::Iterator start); virtual void Print (std::ostream &os) const; private: - uint16_t m_identifier; - uint16_t m_sequence; - uint8_t *m_data; - uint32_t m_dataSize; + uint16_t m_identifier; //!< identifier + uint16_t m_sequence; //!< sequence number + uint8_t *m_data; //!< data + uint32_t m_dataSize; //!< data size }; class Icmpv4DestinationUnreachable : public Header @@ -100,17 +159,46 @@ FRAG_NEEDED = 4, SOURCE_ROUTE_FAILED = 5 }; + + /** + * Get ICMP type + * \returns the ICMP type + */ static TypeId GetTypeId (void); Icmpv4DestinationUnreachable (); virtual ~Icmpv4DestinationUnreachable (); + /** + * \brief Set the next hop MTU + * \param mtu the MTU + */ void SetNextHopMtu (uint16_t mtu); + /** + * \brief Get the next hop MTU + * \returns the MTU + */ uint16_t GetNextHopMtu (void) const; + /** + * \brief Set the ICMP carried data + * \param data the data + */ void SetData (Ptr data); + /** + * \brief Set the ICMP carried IPv4 header + * \param header the header + */ void SetHeader (Ipv4Header header); + /** + * \brief Get the ICMP carried data + * \param payload the data (filled) + */ void GetData (uint8_t payload[8]) const; + /** + * \brief Get the ICMP carried IPv4 header + * \returns the header + */ Ipv4Header GetHeader (void) const; private: @@ -120,9 +208,9 @@ virtual uint32_t Deserialize (Buffer::Iterator start); virtual void Print (std::ostream &os) const; private: - uint16_t m_nextHopMtu; - Ipv4Header m_header; - uint8_t m_data[8]; + uint16_t m_nextHopMtu; //!< next hop MTU + Ipv4Header m_header; //!< carried IPv4 header + uint8_t m_data[8]; //!< carried data }; @@ -134,12 +222,32 @@ FRAGMENT_REASSEMBLY = 1 }; + /** + * \brief Get the ICMP carried data + * \param data the data + */ void SetData (Ptr data); + /** + * \brief Set the ICMP carried IPv4 header + * \param header the header + */ void SetHeader (Ipv4Header header); + /** + * \brief Get the ICMP carried data + * \param payload the data (filled) + */ void GetData (uint8_t payload[8]) const; + /** + * \brief Get the ICMP carried IPv4 header + * \returns the header + */ Ipv4Header GetHeader (void) const; + /** + * Get ICMP type + * \returns the ICMP type + */ static TypeId GetTypeId (void); Icmpv4TimeExceeded (); virtual ~Icmpv4TimeExceeded (); @@ -150,8 +258,8 @@ virtual void Print (std::ostream &os) const; private: - Ipv4Header m_header; - uint8_t m_data[8]; + Ipv4Header m_header; //!< carried IPv4 header + uint8_t m_data[8]; //!< carried data }; } // namespace ns3 diff --git a/src/internet/model/icmpv6-l4-protocol.h b/src/internet/model/icmpv6-l4-protocol.h --- a/src/internet/model/icmpv6-l4-protocol.h +++ b/src/internet/model/icmpv6-l4-protocol.h @@ -338,6 +338,7 @@ * \param p the packet * \param header the IPv4 header * \param interface the interface from which the packet is coming + * \returns the receive status */ virtual enum IpL4Protocol::RxStatus Receive (Ptr p, Ipv4Header const &header, @@ -348,6 +349,7 @@ * \param p the packet * \param header the IPv6 header * \param interface the interface from which the packet is coming + * \returns the receive status */ virtual enum IpL4Protocol::RxStatus Receive (Ptr p, Ipv6Header const &header, @@ -363,11 +365,14 @@ /** * \brief Lookup in the ND cache for the IPv6 address + * + * \note Unlike other Lookup method, it does not send NS request! + * * \param dst destination address * \param device device * \param cache the neighbor cache * \param hardwareDestination hardware address - * \note Unlike other Lookup method, it does not send NS request! + * \return true if the address is in the ND cache, the hardwareDestination is updated. */ bool Lookup (Ipv6Address dst, Ptr device, Ptr cache, Address* hardwareDestination); @@ -423,7 +428,7 @@ virtual void DoDispose (); private: - typedef std::list > CacheList; + typedef std::list > CacheList; //!< container of NdiscCaches /** * \brief The node. @@ -559,6 +564,7 @@ /** * \brief Get the cache corresponding to the device. * \param device the device + * \returns the NdiscCache associated with the device */ Ptr FindCache (Ptr device); @@ -569,7 +575,7 @@ virtual IpL4Protocol::DownTargetCallback GetDownTarget (void) const; virtual IpL4Protocol::DownTargetCallback6 GetDownTarget6 (void) const; - IpL4Protocol::DownTargetCallback6 m_downTarget; + IpL4Protocol::DownTargetCallback6 m_downTarget; //!< callback to Ipv6::Send }; diff --git a/src/internet/model/ip-l4-protocol.h b/src/internet/model/ip-l4-protocol.h --- a/src/internet/model/ip-l4-protocol.h +++ b/src/internet/model/ip-l4-protocol.h @@ -47,6 +47,9 @@ class IpL4Protocol : public Object { public: + /** + * \brief Rx status codes + */ enum RxStatus { RX_OK, RX_CSUM_FAILED, @@ -54,6 +57,10 @@ RX_ENDPOINT_UNREACH }; + /** + * \brief Get the type ID. + * \return the object TypeId + */ static TypeId GetTypeId (void); virtual ~IpL4Protocol (); @@ -64,30 +71,29 @@ virtual int GetProtocolNumber (void) const = 0; /** + * \brief Called from lower-level layers to send the packet up in the stack. * \param p packet to forward up * \param header IPv4 Header information * \param incomingInterface the Ipv4Interface on which the packet arrived - * - * Called from lower-level layers to send the packet up - * in the stack. + * \returns Rx status code */ virtual enum RxStatus Receive (Ptr p, Ipv4Header const &header, Ptr incomingInterface) = 0; /** + * \brief Called from lower-level layers to send the packet up in the stack. * \param p packet to forward up * \param header IPv6 Header information * \param incomingInterface the Ipv6Interface on which the packet arrived - * - * Called from lower-level layers to send the packet up - * in the stack. + * \returns Rx status code */ virtual enum RxStatus Receive (Ptr p, Ipv6Header const &header, Ptr incomingInterface) = 0; /** + * \brief Called from lower-level layers to send the ICMP packet up in the stack. * \param icmpSource the source address of the icmp message * \param icmpTtl the ttl of the icmp message * \param icmpType the 'type' field of the icmp message @@ -98,7 +104,7 @@ * the icmp message * \param payloadDestination the destination address of the packet which * triggered the icmp message. - * \param payload the first 8 bytes of the udp header of the packet + * \param payload the first 8 bytes of the packet payload * which triggered the icmp message. */ virtual void ReceiveIcmp (Ipv4Address icmpSource, uint8_t icmpTtl, @@ -108,6 +114,7 @@ /** + * \brief Called from lower-level layers to send the ICMPv6 packet up in the stack. * \param icmpSource the source address of the icmp message * \param icmpTtl the ttl of the icmp message * \param icmpType the 'type' field of the icmp message @@ -118,7 +125,7 @@ * the icmp message * \param payloadDestination the destination address of the packet which * triggered the icmp message. - * \param payload the first 8 bytes of the udp header of the packet + * \param payload the first 8 bytes of the packet payload * which triggered the icmp message. */ virtual void ReceiveIcmp (Ipv6Address icmpSource, uint8_t icmpTtl, @@ -126,12 +133,18 @@ Ipv6Address payloadSource, Ipv6Address payloadDestination, const uint8_t payload[8]); + /** + * \brief callback to send packets over IPv4 + */ typedef Callback, Ipv4Address, Ipv4Address, uint8_t, Ptr > DownTargetCallback; + /** + * \brief callback to send packets over IPv6 + */ typedef Callback, Ipv6Address, Ipv6Address, uint8_t, Ptr > DownTargetCallback6; /** * This method allows a caller to set the current down target callback - * set for this L4 protocol + * set for this L4 protocol (IPv4 case) * * \param cb current Callback for the L4 protocol */ @@ -139,7 +152,7 @@ /** * This method allows a caller to set the current down target callback - * set for this L4 protocol + * set for this L4 protocol (IPv6 case) * * \param cb current Callback for the L4 protocol */ @@ -147,7 +160,7 @@ /** * This method allows a caller to get the current down target callback - * set for this L4 protocol, for + * set for this L4 protocol (IPv4 case) * * \return current Callback for the L4 protocol */ @@ -155,7 +168,7 @@ /** * This method allows a caller to get the current down target callback - * set for this L4 protocol, for + * set for this L4 protocol (IPv6 case) * * \return current Callback for the L4 protocol */ diff --git a/src/internet/model/ipv4-address-generator.cc b/src/internet/model/ipv4-address-generator.cc --- a/src/internet/model/ipv4-address-generator.cc +++ b/src/internet/model/ipv4-address-generator.cc @@ -27,53 +27,160 @@ namespace ns3 { +/** + * \internal + * \ingroup address + * + * \brief Implementation class of Ipv4AddressGenerator + * This generator assigns addresses sequentially from a provided + * network address; used in topology code. It also keeps track of all + * addresses assigned to perform duplicate detection. + */ class Ipv4AddressGeneratorImpl { public: Ipv4AddressGeneratorImpl (); virtual ~Ipv4AddressGeneratorImpl (); + /** + * \internal + * \brief Initialise the base network, mask and address for the generator + * + * The first call to NextAddress() or GetAddress() will return the + * value passed in. + * + * \param net The network for the base Ipv4Address + * \param mask The network mask of the base Ipv4Address + * \param addr The base address used for initialization + */ void Init (const Ipv4Address net, const Ipv4Mask mask, const Ipv4Address addr); + /** + * \internal + * \brief Get the current network of the given Ipv4Mask + * + * Does not change the internal state; this just peeks at the current + * network + * + * \param mask The Ipv4Mask for the current network + * \returns the IPv4 address of the current network + */ Ipv4Address GetNetwork (const Ipv4Mask mask) const; + + /** + * \internal + * \brief Get the next network according to the given Ipv4Mask + * + * This operation is a pre-increment, meaning that the internal state + * is changed before returning the new network address. + * + * This also resets the address to the base address that was + * used for initialization. + * + * \param mask The Ipv4Mask used to set the next network + * \returns the IPv4 address of the next network + */ Ipv4Address NextNetwork (const Ipv4Mask mask); + /** + * \internal + * \brief Set the address for the given mask + * + * \param addr The address to set for the current mask + * \param mask The Ipv4Mask whose address is to be set + */ void InitAddress (const Ipv4Address addr, const Ipv4Mask mask); - Ipv4Address GetAddress (const Ipv4Mask mask) const; + + /** + * \internal + * \brief Allocate the next Ipv4Address for the configured network and mask + * + * This operation is a post-increment, meaning that the first address + * allocated will be the one that was initially configured. + * + * \param mask The Ipv4Mask for the current network + * \returns the IPv4 address + */ Ipv4Address NextAddress (const Ipv4Mask mask); + /** + * \internal + * \brief Get the Ipv4Address that will be allocated upon NextAddress () + * + * Does not change the internal state; just is used to peek the next + * address that will be allocated upon NextAddress () + * + * \param mask The Ipv4Mask for the current network + * \returns the IPv4 address + */ + Ipv4Address GetAddress (const Ipv4Mask mask) const; + + /** + * \internal + * \brief Reset the networks and Ipv4Address to zero + */ void Reset (void); + + /** + * \internal + * \brief Add the Ipv4Address to the list of IPv4 entries + * + * Typically, this is used by external address allocators that want + * to make use of this class's ability to track duplicates. AddAllocated + * is always called internally for any address generated by NextAddress () + * + * \param addr The Ipv4Address to be added to the list of Ipv4 entries + * \returns true on success + */ bool AddAllocated (const Ipv4Address addr); + /** + * \internal + * \brief Used to turn off fatal errors and assertions, for testing + */ void TestMode (void); private: - static const uint32_t N_BITS = 32; - static const uint32_t MOST_SIGNIFICANT_BIT = 0x80000000; + static const uint32_t N_BITS = 32; //!< /internal the number of bits in the address + static const uint32_t MOST_SIGNIFICANT_BIT = 0x80000000; //!< /internal MSB set to 1 + /** + * \internal + * \brief Create an index number for the network mask + * \param mask the mask to index + * \returns an index + */ uint32_t MaskToIndex (Ipv4Mask mask) const; + /** + * \internal + * \brief This class holds the state for a given network + */ class NetworkState { public: - uint32_t mask; - uint32_t shift; - uint32_t network; - uint32_t addr; - uint32_t addrMax; + uint32_t mask; //!< /internal the network mask + uint32_t shift; //!< /internal a shift + uint32_t network; //!< /internal the network + uint32_t addr; //!< /internal the address + uint32_t addrMax; //!< /internal the maximum address }; - NetworkState m_netTable[N_BITS]; + NetworkState m_netTable[N_BITS]; //!< /internal the available networks + /** + * \internal + * \brief This class holds the allocated addresses + */ class Entry { public: - uint32_t addrLow; - uint32_t addrHigh; + uint32_t addrLow; //!< /internal the lowest allocated address + uint32_t addrHigh; //!< /internal the highest allocated address }; - std::list m_entries; - bool m_test; + std::list m_entries; //!< /internal contained of allocated addresses + bool m_test; //!< /internal test mode (if true) }; Ipv4AddressGeneratorImpl::Ipv4AddressGeneratorImpl () diff --git a/src/internet/model/ipv4-address-generator.h b/src/internet/model/ipv4-address-generator.h --- a/src/internet/model/ipv4-address-generator.h +++ b/src/internet/model/ipv4-address-generator.h @@ -28,22 +28,103 @@ * * \brief This generator assigns addresses sequentially from a provided * network address; used in topology code. + * + * \note BEWARE: this class acts as a Singleton. + * In other terms, two different instances of Ipv4AddressGenerator will + * pick IPv4 numbers from the same pool. Changing the network in one of them + * will also change the network in the other instances. + * */ class Ipv4AddressGenerator { public: + /** + * \brief Initialise the base network, mask and address for the generator + * + * The first call to NextAddress() or GetAddress() will return the + * value passed in. + * + * \param net The network for the base Ipv4Address + * \param mask The network mask of the base Ipv4Address + * \param addr The base address used for initialization + */ static void Init (const Ipv4Address net, const Ipv4Mask mask, const Ipv4Address addr = "0.0.0.1"); + /** + * \brief Get the next network according to the given Ipv4Mask + * + * This operation is a pre-increment, meaning that the internal state + * is changed before returning the new network address. + * + * This also resets the address to the base address that was + * used for initialization. + * + * \param mask The Ipv4Mask used to set the next network + * \returns the IPv4 address of the next network + */ static Ipv4Address NextNetwork (const Ipv4Mask mask); + + /** + * \brief Get the current network of the given Ipv4Mask + * + * Does not change the internal state; this just peeks at the current + * network + * + * \param mask The Ipv4Mask for the current network + * \returns the IPv4 address of the current network + */ static Ipv4Address GetNetwork (const Ipv4Mask mask); + /** + * \brief Set the address for the given mask + * + * \param addr The address to set for the current mask + * \param mask The Ipv4Mask whose address is to be set + */ static void InitAddress (const Ipv4Address addr, const Ipv4Mask mask); + + /** + * \brief Allocate the next Ipv4Address for the configured network and mask + * + * This operation is a post-increment, meaning that the first address + * allocated will be the one that was initially configured. + * + * \param mask The Ipv4Mask for the current network + * \returns the IPv4 address + */ static Ipv4Address NextAddress (const Ipv4Mask mask); + + /** + * \brief Get the Ipv4Address that will be allocated upon NextAddress () + * + * Does not change the internal state; just is used to peek the next + * address that will be allocated upon NextAddress () + * + * \param mask The Ipv4Mask for the current network + * \returns the IPv4 address + */ static Ipv4Address GetAddress (const Ipv4Mask mask); + /** + * \brief Reset the networks and Ipv4Address to zero + */ static void Reset (void); + + /** + * \brief Add the Ipv4Address to the list of IPv4 entries + * + * Typically, this is used by external address allocators that want + * to make use of this class's ability to track duplicates. AddAllocated + * is always called internally for any address generated by NextAddress () + * + * \param addr The Ipv4Address to be added to the list of Ipv4 entries + * \returns true on success + */ static bool AddAllocated (const Ipv4Address addr); + /** + * \brief Used to turn off fatal errors and assertions, for testing + */ static void TestMode (void); }; diff --git a/src/internet/model/ipv4-end-point-demux.h b/src/internet/model/ipv4-end-point-demux.h --- a/src/internet/model/ipv4-end-point-demux.h +++ b/src/internet/model/ipv4-end-point-demux.h @@ -42,43 +42,141 @@ class Ipv4EndPointDemux { public: + /** + * \brief Container of the IPv4 endpoints. + */ typedef std::list EndPoints; + + /** + * \brief Iterator to the container of the IPv4 endpoints. + */ typedef std::list::iterator EndPointsI; Ipv4EndPointDemux (); ~Ipv4EndPointDemux (); + /** + * \brief Get the entire list of end points registered. + * \return list of Ipv4EndPoint + */ EndPoints GetAllEndPoints (void); + + /** + * \brief Lookup for port local. + * \param port port to test + * \return true if a port local is in EndPoints, false otherwise + */ bool LookupPortLocal (uint16_t port); + + /** + * \brief Lookup for address and port. + * \param addr address to test + * \param port port to test + * \return true if there is a match in EndPoints, false otherwise + */ bool LookupLocal (Ipv4Address addr, uint16_t port); + + /** + * \brief lookup for a match with all the parameters. + * \param daddr destination address to test + * \param dport destination port to test + * \param saddr source address to test + * \param sport source port to test + * \param incomingInterface the incoming interface + * \return list of IPv4EndPoints (could be 0 element) + */ EndPoints Lookup (Ipv4Address daddr, uint16_t dport, Ipv4Address saddr, uint16_t sport, Ptr incomingInterface); + /** + * \brief simple lookup for a match with all the parameters. + * \param daddr destination address to test + * \param dport destination port to test + * \param saddr source address to test + * \param sport source port to test + * \return IPv4EndPoint (0 if not found) + */ Ipv4EndPoint *SimpleLookup (Ipv4Address daddr, uint16_t dport, Ipv4Address saddr, uint16_t sport); + /** + * \brief Allocate a Ipv4EndPoint. + * \return an empty Ipv4EndPoint instance + */ Ipv4EndPoint *Allocate (void); + + /** + * \brief Allocate a Ipv4EndPoint. + * \param address IPv4 address + * \return an Ipv4EndPoint instance + */ Ipv4EndPoint *Allocate (Ipv4Address address); + + /** + * \brief Allocate a Ipv4EndPoint. + * \param port local port + * \return an Ipv4EndPoint instance + */ Ipv4EndPoint *Allocate (uint16_t port); + + /** + * \brief Allocate a Ipv4EndPoint. + * \param address local address + * \param port local port + * \return an Ipv4EndPoint instance + */ Ipv4EndPoint *Allocate (Ipv4Address address, uint16_t port); + + /** + * \brief Allocate a Ipv4EndPoint. + * \param localAddress local address + * \param localPort local port + * \param peerAddress peer address + * \param peerPort peer port + * \return an Ipv4EndPoint instance + */ Ipv4EndPoint *Allocate (Ipv4Address localAddress, uint16_t localPort, Ipv4Address peerAddress, uint16_t peerPort); + /** + * \brief Remove a end point. + * \param endPoint the end point to remove + */ void DeAllocate (Ipv4EndPoint *endPoint); private: + + /** + * \brief Allocate an ephemeral port. + * \returns the ephemeral port + */ uint16_t AllocateEphemeralPort (void); + /** + * \brief The ephemeral port. + */ uint16_t m_ephemeral; + + /** + * \brief The last ephemeral port. + */ uint16_t m_portLast; + + /** + * \brief The first ephemeral port. + */ uint16_t m_portFirst; + + /** + * \brief A list of IPv4 end points. + */ EndPoints m_endPoints; }; diff --git a/src/internet/model/ipv4-end-point.h b/src/internet/model/ipv4-end-point.h --- a/src/internet/model/ipv4-end-point.h +++ b/src/internet/model/ipv4-end-point.h @@ -46,48 +46,188 @@ class Ipv4EndPoint { public: + /** + * \brief Constructor. + * \param address the IPv4 address + * \param port the port + */ Ipv4EndPoint (Ipv4Address address, uint16_t port); ~Ipv4EndPoint (); + /** + * \brief Get the local address. + * \return the local address + */ Ipv4Address GetLocalAddress (void); + + /** + * \brief Set the local address. + * \param address the address to set + */ void SetLocalAddress (Ipv4Address address); + + /** + * \brief Get the local port. + * \return the local port + */ uint16_t GetLocalPort (void); + + /** + * \brief Get the peer address. + * \return the peer address + */ Ipv4Address GetPeerAddress (void); + + /** + * \brief Get the peer port. + * \return the peer port + */ uint16_t GetPeerPort (void); + /** + * \brief Set the peer informations (address and port). + * \param address peer address + * \param port peer port + */ void SetPeer (Ipv4Address address, uint16_t port); + /** + * \brief Bind a socket to specific device. + * + * This method corresponds to using setsockopt() SO_BINDTODEVICE + * of real network or BSD sockets. If set on a socket, this option will + * force packets to leave the bound device regardless of the device that + * IP routing would naturally choose. In the receive direction, only + * packets received from the bound interface will be delivered. + * + * This option has no particular relationship to binding sockets to + * an address via Socket::Bind (). It is possible to bind sockets to a + * specific IP address on the bound interface by calling both + * Socket::Bind (address) and Socket::BindToNetDevice (device), but it + * is also possible to bind to mismatching device and address, even if + * the socket can not receive any packets as a result. + * + * \param netdevice Pointer to Netdevice of desired interface + */ void BindToNetDevice (Ptr netdevice); + + /** + * \brief Returns socket's bound netdevice, if any. + * + * This method corresponds to using getsockopt() SO_BINDTODEVICE + * of real network or BSD sockets. + * + * + * \returns Pointer to interface. + */ Ptr GetBoundNetDevice (void); // Called from socket implementations to get notified about important events. + /** + * \brief Set the reception callback. + * \param callback callback function + */ void SetRxCallback (Callback, Ipv4Header, uint16_t, Ptr > callback); + /** + * \brief Set the ICMP callback. + * \param callback callback function + */ void SetIcmpCallback (Callback callback); + /** + * \brief Set the default destroy callback. + * \param callback callback function + */ void SetDestroyCallback (Callback callback); - // Called from an L4Protocol implementation to notify an endpoint of a - // packet reception. + /** + * \brief Forward the packet to the upper level. + * + * Called from an L4Protocol implementation to notify an endpoint of a + * packet reception. + * \param p the packet + * \param header the packet header + * \param sport source port + * \param incomingInterface incoming interface + */ void ForwardUp (Ptr p, const Ipv4Header& header, uint16_t sport, Ptr incomingInterface); - // Called from an L4Protocol implementation to notify an endpoint of - // an icmp message reception. + + /** + * \brief Forward the ICMP packet to the upper level. + * + * Called from an L4Protocol implementation to notify an endpoint of + * an icmp message reception. + * + * \param icmpSource source IP address + * \param icmpTtl time-to-live + * \param icmpType ICMP type + * \param icmpCode ICMP code + * \param icmpInfo ICMP info + */ void ForwardIcmp (Ipv4Address icmpSource, uint8_t icmpTtl, uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo); private: + /** + * \brief ForwardUp wrapper. + * \param p packet + * \param header the packet header + * \param sport source port + * \param incomingInterface incoming interface + */ void DoForwardUp (Ptr p, const Ipv4Header& header, uint16_t sport, Ptr incomingInterface); - void DoForwardIcmp (Ipv4Address icmpSource, uint8_t icmpTtl, + /** + * \brief ForwardIcmp wrapper. + * \param icmpSource source IP address + * \param icmpTtl time-to-live + * \param icmpType ICMP type + * \param icmpCode ICMP code + * \param icmpInfo ICMP info + */ + void DoForwardIcmp (Ipv4Address icmpSource, uint8_t icmpTtl, uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo); + + /** + * \brief The local address. + */ Ipv4Address m_localAddr; + + /** + * \brief The local port. + */ uint16_t m_localPort; + + /** + * \brief The peer address. + */ Ipv4Address m_peerAddr; + + /** + * \brief The peer port. + */ uint16_t m_peerPort; + + /** + * \brief The NetDevice the EndPoint is bound to (if any). + */ Ptr m_boundnetdevice; + + /** + * \brief The RX callback. + */ Callback, Ipv4Header, uint16_t, Ptr > m_rxCallback; + + /** + * \brief The ICMPv6 callback. + */ Callback m_icmpCallback; + + /** + * \brief The destroy callback. + */ Callback m_destroyCallback; }; diff --git a/src/internet/model/ipv4-global-routing.h b/src/internet/model/ipv4-global-routing.h --- a/src/internet/model/ipv4-global-routing.h +++ b/src/internet/model/ipv4-global-routing.h @@ -69,15 +69,19 @@ class Ipv4GlobalRouting : public Ipv4RoutingProtocol { public: + /** + * \brief Get the type ID. + * \return the object TypeId + */ static TypeId GetTypeId (void); -/** - * \brief Construct an empty Ipv4GlobalRouting routing protocol, - * - * The Ipv4GlobalRouting class supports host and network unicast routes. - * This method initializes the lists containing these routes to empty. - * - * \see Ipv4GlobalRouting - */ + /** + * \brief Construct an empty Ipv4GlobalRouting routing protocol, + * + * The Ipv4GlobalRouting class supports host and network unicast routes. + * This method initializes the lists containing these routes to empty. + * + * \see Ipv4GlobalRouting + */ Ipv4GlobalRouting (); virtual ~Ipv4GlobalRouting (); @@ -94,131 +98,132 @@ virtual void SetIpv4 (Ptr ipv4); virtual void PrintRoutingTable (Ptr stream) const; -/** - * \brief Add a host route to the global routing table. - * - * \param dest The Ipv4Address destination for this route. - * \param nextHop The Ipv4Address of the next hop in the route. - * \param interface The network interface index used to send packets to the - * destination. - * - * \see Ipv4Address - */ + /** + * \brief Add a host route to the global routing table. + * + * \param dest The Ipv4Address destination for this route. + * \param nextHop The Ipv4Address of the next hop in the route. + * \param interface The network interface index used to send packets to the + * destination. + * + * \see Ipv4Address + */ void AddHostRouteTo (Ipv4Address dest, Ipv4Address nextHop, uint32_t interface); -/** - * \brief Add a host route to the global routing table. - * - * \param dest The Ipv4Address destination for this route. - * \param interface The network interface index used to send packets to the - * destination. - * - * \see Ipv4Address - */ + /** + * \brief Add a host route to the global routing table. + * + * \param dest The Ipv4Address destination for this route. + * \param interface The network interface index used to send packets to the + * destination. + * + * \see Ipv4Address + */ void AddHostRouteTo (Ipv4Address dest, uint32_t interface); -/** - * \brief Add a network route to the global routing table. - * - * \param network The Ipv4Address network for this route. - * \param networkMask The Ipv4Mask to extract the network. - * \param nextHop The next hop in the route to the destination network. - * \param interface The network interface index used to send packets to the - * destination. - * - * \see Ipv4Address - */ + /** + * \brief Add a network route to the global routing table. + * + * \param network The Ipv4Address network for this route. + * \param networkMask The Ipv4Mask to extract the network. + * \param nextHop The next hop in the route to the destination network. + * \param interface The network interface index used to send packets to the + * destination. + * + * \see Ipv4Address + */ void AddNetworkRouteTo (Ipv4Address network, Ipv4Mask networkMask, Ipv4Address nextHop, uint32_t interface); -/** - * \brief Add a network route to the global routing table. - * - * \param network The Ipv4Address network for this route. - * \param networkMask The Ipv4Mask to extract the network. - * \param interface The network interface index used to send packets to the - * destination. - * - * \see Ipv4Address - */ + /** + * \brief Add a network route to the global routing table. + * + * \param network The Ipv4Address network for this route. + * \param networkMask The Ipv4Mask to extract the network. + * \param interface The network interface index used to send packets to the + * destination. + * + * \see Ipv4Address + */ void AddNetworkRouteTo (Ipv4Address network, Ipv4Mask networkMask, uint32_t interface); -/** - * \brief Add an external route to the global routing table. - * - * \param network The Ipv4Address network for this route. - * \param networkMask The Ipv4Mask to extract the network. - * \param nextHop The next hop Ipv4Address - * \param interface The network interface index used to send packets to the - * destination. - */ + /** + * \brief Add an external route to the global routing table. + * + * \param network The Ipv4Address network for this route. + * \param networkMask The Ipv4Mask to extract the network. + * \param nextHop The next hop Ipv4Address + * \param interface The network interface index used to send packets to the + * destination. + */ void AddASExternalRouteTo (Ipv4Address network, Ipv4Mask networkMask, Ipv4Address nextHop, uint32_t interface); -/** - * \brief Get the number of individual unicast routes that have been added - * to the routing table. - * - * \warning The default route counts as one of the routes. - */ + /** + * \brief Get the number of individual unicast routes that have been added + * to the routing table. + * + * \warning The default route counts as one of the routes. + * \returns the number of routes + */ uint32_t GetNRoutes (void) const; -/** - * \brief Get a route from the global unicast routing table. - * - * Externally, the unicast global routing table appears simply as a table with - * n entries. The one subtlety of note is that if a default route has been set - * it will appear as the zeroth entry in the table. This means that if you - * add only a default route, the table will have one entry that can be accessed - * either by explicitly calling GetDefaultRoute () or by calling GetRoute (0). - * - * Similarly, if the default route has been set, calling RemoveRoute (0) will - * remove the default route. - * - * \param i The index (into the routing table) of the route to retrieve. If - * the default route has been set, it will occupy index zero. - * \return If route is set, a pointer to that Ipv4RoutingTableEntry is returned, otherwise - * a zero pointer is returned. - * - * \see Ipv4RoutingTableEntry - * \see Ipv4GlobalRouting::RemoveRoute - */ + /** + * \brief Get a route from the global unicast routing table. + * + * Externally, the unicast global routing table appears simply as a table with + * n entries. The one subtlety of note is that if a default route has been set + * it will appear as the zeroth entry in the table. This means that if you + * add only a default route, the table will have one entry that can be accessed + * either by explicitly calling GetDefaultRoute () or by calling GetRoute (0). + * + * Similarly, if the default route has been set, calling RemoveRoute (0) will + * remove the default route. + * + * \param i The index (into the routing table) of the route to retrieve. If + * the default route has been set, it will occupy index zero. + * \return If route is set, a pointer to that Ipv4RoutingTableEntry is returned, otherwise + * a zero pointer is returned. + * + * \see Ipv4RoutingTableEntry + * \see Ipv4GlobalRouting::RemoveRoute + */ Ipv4RoutingTableEntry *GetRoute (uint32_t i) const; -/** - * \brief Remove a route from the global unicast routing table. - * - * Externally, the unicast global routing table appears simply as a table with - * n entries. The one subtlety of note is that if a default route has been set - * it will appear as the zeroth entry in the table. This means that if the - * default route has been set, calling RemoveRoute (0) will remove the - * default route. - * - * \param i The index (into the routing table) of the route to remove. If - * the default route has been set, it will occupy index zero. - * - * \see Ipv4RoutingTableEntry - * \see Ipv4GlobalRouting::GetRoute - * \see Ipv4GlobalRouting::AddRoute - */ + /** + * \brief Remove a route from the global unicast routing table. + * + * Externally, the unicast global routing table appears simply as a table with + * n entries. The one subtlety of note is that if a default route has been set + * it will appear as the zeroth entry in the table. This means that if the + * default route has been set, calling RemoveRoute (0) will remove the + * default route. + * + * \param i The index (into the routing table) of the route to remove. If + * the default route has been set, it will occupy index zero. + * + * \see Ipv4RoutingTableEntry + * \see Ipv4GlobalRouting::GetRoute + * \see Ipv4GlobalRouting::AddRoute + */ void RemoveRoute (uint32_t i); - /** - * Assign a fixed random variable stream number to the random variables - * used by this model. Return the number of streams (possibly zero) that - * have been assigned. - * - * \param stream first stream index to use - * \return the number of stream indices assigned by this model - */ + /** + * Assign a fixed random variable stream number to the random variables + * used by this model. Return the number of streams (possibly zero) that + * have been assigned. + * + * \param stream first stream index to use + * \return the number of stream indices assigned by this model + */ int64_t AssignStreams (int64_t stream); protected: @@ -232,23 +237,34 @@ /// A uniform random number generator for randomly routing packets among ECMP Ptr m_rand; + /// container of Ipv4RoutingTableEntry (routes to hosts) typedef std::list HostRoutes; + /// const iterator of container of Ipv4RoutingTableEntry (routes to hosts) typedef std::list::const_iterator HostRoutesCI; + /// iterator of container of Ipv4RoutingTableEntry (routes to hosts) typedef std::list::iterator HostRoutesI; + + /// container of Ipv4RoutingTableEntry (routes to networks) typedef std::list NetworkRoutes; + /// const iterator of container of Ipv4RoutingTableEntry (routes to networks) typedef std::list::const_iterator NetworkRoutesCI; + /// iterator of container of Ipv4RoutingTableEntry (routes to networks) typedef std::list::iterator NetworkRoutesI; + + /// container of Ipv4RoutingTableEntry (routes to external AS) typedef std::list ASExternalRoutes; + /// const iterator of container of Ipv4RoutingTableEntry (routes to external AS) typedef std::list::const_iterator ASExternalRoutesCI; + /// iterator of container of Ipv4RoutingTableEntry (routes to external AS) typedef std::list::iterator ASExternalRoutesI; Ptr LookupGlobal (Ipv4Address dest, Ptr oif = 0); - HostRoutes m_hostRoutes; - NetworkRoutes m_networkRoutes; - ASExternalRoutes m_ASexternalRoutes; // External routes imported + HostRoutes m_hostRoutes; //!< Routes to hosts + NetworkRoutes m_networkRoutes; //!< Routes to networks + ASExternalRoutes m_ASexternalRoutes; //!< External routes imported - Ptr m_ipv4; + Ptr m_ipv4; //!< associated IPv4 instance }; } // Namespace ns3 diff --git a/src/internet/model/ipv4-header.h b/src/internet/model/ipv4-header.h --- a/src/internet/model/ipv4-header.h +++ b/src/internet/model/ipv4-header.h @@ -172,6 +172,7 @@ */ DscpType GetDscp (void) const; /** + * \param dscp the dscp * \returns std::string of DSCPType */ std::string DscpTypeToString (DscpType dscp) const; @@ -180,6 +181,7 @@ */ EcnType GetEcn (void) const; /** + * \param ecn the ECNType * \returns std::string of ECNType */ std::string EcnTypeToString (EcnType ecn) const; @@ -220,6 +222,10 @@ */ bool IsChecksumOk (void) const; + /** + * \brief Get the type ID. + * \return the object TypeId + */ static TypeId GetTypeId (void); virtual TypeId GetInstanceTypeId (void) const; virtual void Print (std::ostream &os) const; @@ -228,25 +234,26 @@ virtual uint32_t Deserialize (Buffer::Iterator start); private: + /// flags related to IP fragmentation enum FlagsE { DONT_FRAGMENT = (1<<0), MORE_FRAGMENTS = (1<<1) }; - bool m_calcChecksum; + bool m_calcChecksum; //!< true if the checksum must be calculated - uint16_t m_payloadSize; - uint16_t m_identification; - uint32_t m_tos : 8; //Also used as DSCP + ECN value - uint32_t m_ttl : 8; - uint32_t m_protocol : 8; - uint32_t m_flags : 3; - uint16_t m_fragmentOffset; - Ipv4Address m_source; - Ipv4Address m_destination; - uint16_t m_checksum; - bool m_goodChecksum; - uint16_t m_headerSize; + uint16_t m_payloadSize; //!< payload size + uint16_t m_identification; //!< identification + uint32_t m_tos : 8; //!< TOS, also used as DSCP + ECN value + uint32_t m_ttl : 8; //!< TTL + uint32_t m_protocol : 8; //!< Protocol + uint32_t m_flags : 3; //!< flags + uint16_t m_fragmentOffset; //!< Fragment offset + Ipv4Address m_source; //!< source address + Ipv4Address m_destination; //!< destination address + uint16_t m_checksum; //!< checksum + bool m_goodChecksum; //!< true if checksum is correct + uint16_t m_headerSize; //!< IP header size }; } // namespace ns3 diff --git a/src/internet/model/ipv4-interface-address.h b/src/internet/model/ipv4-interface-address.h --- a/src/internet/model/ipv4-interface-address.h +++ b/src/internet/model/ipv4-interface-address.h @@ -42,6 +42,10 @@ class Ipv4InterfaceAddress { public: + /** + * \enum InterfaceAddressScope_e + * \brief Address scope. + */ enum InterfaceAddressScope_e { HOST, LINK, @@ -49,39 +53,116 @@ }; Ipv4InterfaceAddress (); - // Configure m_local, m_mask, and m_broadcast from the below constructor + + /** + * \brief Configure local address, mask and broadcast address + * \param local the local address + * \param mask the network mask + */ Ipv4InterfaceAddress (Ipv4Address local, Ipv4Mask mask); + /** + * Copy constructor + * \param o the object to copy + */ Ipv4InterfaceAddress (const Ipv4InterfaceAddress &o); + /** + * \brief Set local address + * \param local the address + */ void SetLocal (Ipv4Address local); + /** + * \brief Get the local address + * \returns the local address + */ Ipv4Address GetLocal (void) const; + /** + * \brief Set the network mask + * \param mask the network mask + */ void SetMask (Ipv4Mask mask); + /** + * \brief Get the network mask + * \returns the network mask + */ Ipv4Mask GetMask (void) const; + /** + * \brief Set the broadcast address + * \param broadcast the broadcast address + */ void SetBroadcast (Ipv4Address broadcast); + /** + * \brief Get the broadcast address + * \returns the broadcast address + */ Ipv4Address GetBroadcast (void) const; + /** + * \brief Set the scope. + * \param scope the scope of address + */ void SetScope (Ipv4InterfaceAddress::InterfaceAddressScope_e scope); + + /** + * \brief Get address scope. + * \return scope + */ Ipv4InterfaceAddress::InterfaceAddressScope_e GetScope (void) const; + /** + * \brief Check if the address is a secondary address + * + * Secondary address is used for multihoming + * \returns true if the address is secondary + */ bool IsSecondary (void) const; + + /** + * \brief Make the address secondary (used for multihoming) + */ void SetSecondary (void); + /** + * \brief Make the address primary + */ void SetPrimary (void); private: - Ipv4Address m_local; // Interface address + Ipv4Address m_local; //!< Interface address // Note: m_peer may be added in future when necessary - // Ipv4Address m_peer; // Peer destination address (in Linux: m_address) - Ipv4Mask m_mask; // Network mask - Ipv4Address m_broadcast; // Broadcast address + // Ipv4Address m_peer; // Peer destination address (in Linux: m_address) + Ipv4Mask m_mask; //!< Network mask + Ipv4Address m_broadcast; //!< Broadcast address - InterfaceAddressScope_e m_scope; - bool m_secondary; // For use in multihoming + InterfaceAddressScope_e m_scope; //!< Address scope + bool m_secondary; //!< For use in multihoming + /** + * \brief Equal to operator. + * + * \param a the first operand + * \param b the first operand + * \returns true if the operands are equal + */ friend bool operator == (Ipv4InterfaceAddress const &a, Ipv4InterfaceAddress const &b); + + /** + * \brief Not equal to operator. + * + * \param a the first operand + * \param b the first operand + * \returns true if the operands are not equal + */ friend bool operator != (Ipv4InterfaceAddress const &a, Ipv4InterfaceAddress const &b); }; +/** + * \brief Stream insertion operator. + * + * \param os the reference to the output stream + * \param addr the Ipv4InterfaceAddress + * \returns the reference to the output stream + */ std::ostream& operator<< (std::ostream& os, const Ipv4InterfaceAddress &addr); inline bool operator == (const Ipv4InterfaceAddress &a, const Ipv4InterfaceAddress &b) diff --git a/src/internet/model/ipv4-interface.h b/src/internet/model/ipv4-interface.h --- a/src/internet/model/ipv4-interface.h +++ b/src/internet/model/ipv4-interface.h @@ -43,20 +43,36 @@ * specific information (addresses) about an interface. * * By default, Ipv4 interface are created in the "down" state - * no IP addresses. Before becoming useable, the user must + * no IP addresses. Before becoming usable, the user must * add an address of some type and invoke Setup on them. */ class Ipv4Interface : public Object { public: + /** + * \brief Get the type ID + * \return type ID + */ static TypeId GetTypeId (void); Ipv4Interface (); virtual ~Ipv4Interface(); + /** + * \brief Set node associated with interface. + * \param node node + */ void SetNode (Ptr node); + /** + * \brief Set the NetDevice. + * \param device NetDevice + */ void SetDevice (Ptr device); - void SetArpCache (Ptr); + /** + * \brief Set ARP cache used by this interface + * \param arpCache the ARP cache + */ + void SetArpCache (Ptr arpCache); /** * \returns the underlying NetDevice. This method cannot return zero. @@ -164,18 +180,36 @@ protected: virtual void DoDispose (void); private: + /** + * \brief Initialize interface. + */ void DoSetup (void); + + + /** + * \brief Container for the Ipv4InterfaceAddresses. + */ typedef std::list Ipv4InterfaceAddressList; + + /** + * \brief Container Iterator for the Ipv4InterfaceAddresses. + */ typedef std::list::const_iterator Ipv4InterfaceAddressListCI; + + /** + * \brief Const Container Iterator for the Ipv4InterfaceAddresses. + */ typedef std::list::iterator Ipv4InterfaceAddressListI; - bool m_ifup; - bool m_forwarding; // IN_DEV_FORWARD - uint16_t m_metric; - Ipv4InterfaceAddressList m_ifaddrs; - Ptr m_node; - Ptr m_device; - Ptr m_cache; + + + bool m_ifup; //!< The state of this interface + bool m_forwarding; //!< Forwarding state. + uint16_t m_metric; //!< Interface metric + Ipv4InterfaceAddressList m_ifaddrs; //!< Address list + Ptr m_node; //!< The associated node + Ptr m_device; //!< The associated NetDevice + Ptr m_cache; //!< ARP cache }; } // namespace ns3 diff --git a/src/internet/model/ipv4-l3-protocol.cc b/src/internet/model/ipv4-l3-protocol.cc --- a/src/internet/model/ipv4-l3-protocol.cc +++ b/src/internet/model/ipv4-l3-protocol.cc @@ -688,9 +688,9 @@ } } -/// \todo when should we set ip_id? check whether we are incrementing -/// m_identification on packets that may later be dropped in this stack -/// and whether that deviates from Linux +// \todo when should we set ip_id? check whether we are incrementing +// m_identification on packets that may later be dropped in this stack +// and whether that deviates from Linux Ipv4Header Ipv4L3Protocol::BuildHeader ( Ipv4Address source, diff --git a/src/internet/model/ipv4-l3-protocol.h b/src/internet/model/ipv4-l3-protocol.h --- a/src/internet/model/ipv4-l3-protocol.h +++ b/src/internet/model/ipv4-l3-protocol.h @@ -77,8 +77,12 @@ class Ipv4L3Protocol : public Ipv4 { public: + /** + * \brief Get the type ID. + * \return the object TypeId + */ static TypeId GetTypeId (void); - static const uint16_t PROT_NUMBER; + static const uint16_t PROT_NUMBER; //!< Protocol number (0x0800) Ipv4L3Protocol(); virtual ~Ipv4L3Protocol (); @@ -97,6 +101,10 @@ DROP_FRAGMENT_TIMEOUT /**< Fragment timeout exceeded */ }; + /** + * \brief Set node associated with this stack. + * \param node node to set + */ void SetNode (Ptr node); // functions defined in base class Ipv4 @@ -182,6 +190,11 @@ void SendWithHeader (Ptr packet, Ipv4Header ipHeader, Ptr route); uint32_t AddInterface (Ptr device); + /** + * \brief Get an interface. + * \param i interface index + * \return IPv4 interface pointer + */ Ptr GetInterface (uint32_t i) const; uint32_t GetNInterfaces (void) const; @@ -220,7 +233,20 @@ virtual void NotifyNewAggregate (); private: friend class Ipv4L3ProtocolTestCase; + + /** + * \brief Copy constructor. + * + * Defined but not implemented to avoid misuse + */ Ipv4L3Protocol(const Ipv4L3Protocol &); + + /** + * \brief Copy constructor. + * + * Defined but not implemented to avoid misuse + * \returns the copied object + */ Ipv4L3Protocol &operator = (const Ipv4L3Protocol &); // class Ipv4 attributes @@ -229,6 +255,17 @@ virtual void SetWeakEsModel (bool model); virtual bool GetWeakEsModel (void) const; + /** + * \brief Construct an IPv4 header. + * \param source source IPv4 address + * \param destination destination IPv4 address + * \param protocol L4 protocol + * \param payloadSize payload size + * \param ttl Time to Live + * \param tos Type of Service + * \param mayFragment true if the packet can be fragmented + * \return newly created IPv4 header + */ Ipv4Header BuildHeader ( Ipv4Address source, Ipv4Address destination, @@ -238,25 +275,65 @@ uint8_t tos, bool mayFragment); + /** + * \brief Send packet with route. + * \param route route + * \param packet packet to send + * \param ipHeader IPv4 header to add to the packet + */ void SendRealOut (Ptr route, Ptr packet, Ipv4Header const &ipHeader); + /** + * \brief Forward a packet. + * \param rtentry route + * \param p packet to forward + * \param header IPv4 header to add to the packet + */ void IpForward (Ptr rtentry, Ptr p, const Ipv4Header &header); + /** + * \brief Forward a multicast packet. + * \param mrtentry route + * \param p packet to forward + * \param header IPv6 header to add to the packet + */ void IpMulticastForward (Ptr mrtentry, Ptr p, const Ipv4Header &header); + /** + * \brief Deliver a packet. + * \param p packet delivered + * \param ip IPv4 header + * \param iif input interface packet was received + */ void LocalDeliver (Ptr p, Ipv4Header const&ip, uint32_t iif); + + /** + * \brief Fallback when no route is found. + * \param p packet + * \param ipHeader IPv4 header + * \param sockErrno error number + */ void RouteInputError (Ptr p, const Ipv4Header & ipHeader, Socket::SocketErrno sockErrno); + /** + * \brief Add an IPv4 interface to the stack. + * \param interface interface to add + * \return index of newly added interface + */ uint32_t AddIpv4Interface (Ptr interface); + + /** + * \brief Setup loopback interface. + */ void SetupLoopback (void); /** @@ -264,6 +341,13 @@ * \return Icmpv4L4Protocol pointer */ Ptr GetIcmp (void) const; + + /** + * \brief Check if an IPv4 address is unicast. + * \param ad address + * \param interfaceMask the network mask + * \return true if the address is unicast + */ bool IsUnicast (Ipv4Address ad, Ipv4Mask interfaceMask) const; /** @@ -277,7 +361,7 @@ /** * \brief Process a packet fragment * \param packet the packet - * \param fragmentSize the size of the fragment + * \param ipHeader the IP header * \param iif Input Interface * \return true is the fragment completed the packet */ @@ -291,32 +375,47 @@ */ void HandleFragmentsTimeout ( std::pair key, Ipv4Header & ipHeader, uint32_t iif); + /** + * \brief Container of the IPv4 Interfaces. + */ typedef std::vector > Ipv4InterfaceList; + /** + * \brief Container of the IPv4 Raw Sockets. + */ typedef std::list > SocketList; - typedef std::list > L4List_t; + /** + * \brief Container of the IPv4 L4 instances. + */ + typedef std::list > L4List_t; - bool m_ipForward; - bool m_weakEsModel; - L4List_t m_protocols; - Ipv4InterfaceList m_interfaces; - uint8_t m_defaultTos; - uint8_t m_defaultTtl; - uint16_t m_identification; - Ptr m_node; + bool m_ipForward; //!< Forwarding packets (i.e. router mode) state. + bool m_weakEsModel; //!< Weak ES model state + L4List_t m_protocols; //!< List of transport protocol. + Ipv4InterfaceList m_interfaces; //!< List of IPv4 interfaces. + uint8_t m_defaultTos; //!< Default TOS + uint8_t m_defaultTtl; //!< Default TTL + uint16_t m_identification; //!< Identification + Ptr m_node; //!< Node attached to stack. + /// Trace of sent packets TracedCallback, uint32_t> m_sendOutgoingTrace; + /// Trace of unicast forwarded packets TracedCallback, uint32_t> m_unicastForwardTrace; + /// Trace of locally delivered packets TracedCallback, uint32_t> m_localDeliverTrace; // The following two traces pass a packet with an IP header + /// Trace of transmitted packets TracedCallback, Ptr, uint32_t> m_txTrace; + /// Trace of received packets TracedCallback, Ptr, uint32_t> m_rxTrace; // (ifindex not valid if reason is DROP_NO_ROUTE) + /// Trace of dropped packets TracedCallback, DropReason, Ptr, uint32_t> m_dropTrace; - Ptr m_routingProtocol; + Ptr m_routingProtocol; //!< Routing protocol associated with the stack - SocketList m_sockets; + SocketList m_sockets; //!< List of IPv4 raw sockets. /** * \class Fragments @@ -374,15 +473,14 @@ }; + /// Container of fragments, stored as pairs(src+dst addr, src+dst port) / fragment typedef std::map< std::pair, Ptr > MapFragments_t; + /// Container of fragment timeout event, stored as pairs(src+dst addr, src+dst port) / EventId typedef std::map< std::pair, EventId > MapFragmentsTimers_t; - /** - * \brief The hash of fragmented packets. - */ - MapFragments_t m_fragments; - Time m_fragmentExpirationTimeout; - MapFragmentsTimers_t m_fragmentsTimers; + MapFragments_t m_fragments; //!< Fragmented packets. + Time m_fragmentExpirationTimeout; //!< Expiration timeout + MapFragmentsTimers_t m_fragmentsTimers; //!< Expiration events. }; diff --git a/src/internet/model/ipv4-list-routing.h b/src/internet/model/ipv4-list-routing.h --- a/src/internet/model/ipv4-list-routing.h +++ b/src/internet/model/ipv4-list-routing.h @@ -45,6 +45,10 @@ class Ipv4ListRouting : public Ipv4RoutingProtocol { public: + /** + * \brief Get the type ID of this class. + * \return type ID + */ static TypeId GetTypeId (void); Ipv4ListRouting (); @@ -92,11 +96,25 @@ void DoDispose (void); void DoInitialize (void); private: + /** + * \brief Container identifying an IPv4 Routing Protocol entry in the list. + */ typedef std::pair > Ipv4RoutingProtocolEntry; + /** + * \brief Container of the IPv4 Routing Protocols. + */ typedef std::list Ipv4RoutingProtocolList; - Ipv4RoutingProtocolList m_routingProtocols; + Ipv4RoutingProtocolList m_routingProtocols; //!< List of routing protocols. + + /** + * \brief Compare two routing protocols. + * \param a first object to compare + * \param b second object to compare + * \return true if they are the same, false otherwise + */ static bool Compare (const Ipv4RoutingProtocolEntry& a, const Ipv4RoutingProtocolEntry& b); - Ptr m_ipv4; + Ptr m_ipv4; //!< Ipv4 this protocol is associated with. + }; diff --git a/src/internet/model/ipv4-packet-info-tag.h b/src/internet/model/ipv4-packet-info-tag.h --- a/src/internet/model/ipv4-packet-info-tag.h +++ b/src/internet/model/ipv4-packet-info-tag.h @@ -43,23 +43,67 @@ { public: Ipv4PacketInfoTag (); - // Implemented, but not used in the stack yet + + /** + * \brief Set the tag's address + * + * \param addr the address + */ void SetAddress (Ipv4Address addr); - // Implemented, but not used in the stack yet + + /** + * \brief Get the tag's address + * + * \returns the address + */ Ipv4Address GetAddress (void) const; - // This corresponds to "ipi_spec_dst" in struct in_pktinfo. - // Implemented, but not used in the stack yet + /** + * \brief Set the tag's \a local address + * + * This corresponds to "ipi_spec_dst" in struct in_pktinfo. + * Implemented, but not used in the stack yet + * \param addr the address + */ void SetLocalAddress (Ipv4Address addr); - // This corresponds to "ipi_spec_dst" in struct in_pktinfo. - // Implemented, but not used in the stack yet + /** + * \brief Get the tag's \a local address + * + * This corresponds to "ipi_spec_dst" in struct in_pktinfo. + * Implemented, but not used in the stack yet + * \returns the address + */ Ipv4Address GetLocalAddress (void) const; + + /** + * \brief Set the tag's receiving interface + * + * \param ifindex the interface index + */ void SetRecvIf (uint32_t ifindex); + /** + * \brief Get the tag's receiving interface + * + * \returns the interface index + */ uint32_t GetRecvIf (void) const; - // Implemented, but not used in the stack yet + + /** + * \brief Set the tag's Time to Live + * Implemented, but not used in the stack yet + * \param ttl the TTL + */ void SetTtl (uint8_t ttl); - // Implemented, but not used in the stack yet + /** + * \brief Get the tag's Time to Live + * Implemented, but not used in the stack yet + * \returns the TTL + */ uint8_t GetTtl (void) const; + /** + * \brief Get the type ID. + * \return the object TypeId + */ static TypeId GetTypeId (void); virtual TypeId GetInstanceTypeId (void) const; virtual uint32_t GetSerializedSize (void) const; @@ -77,12 +121,12 @@ // address */ // }; - Ipv4Address m_addr; - Ipv4Address m_spec_dst; - uint32_t m_ifindex; + Ipv4Address m_addr; //!< Header destination address + Ipv4Address m_spec_dst; //!< Local address + uint32_t m_ifindex; //!< interface index - // Uset for IP_RECVTTL, though not implemented yet. - uint8_t m_ttl; + // Used for IP_RECVTTL, though not implemented yet. + uint8_t m_ttl; //!< Time to Live }; } // namespace ns3 diff --git a/src/internet/model/ipv4-packet-probe.h b/src/internet/model/ipv4-packet-probe.h --- a/src/internet/model/ipv4-packet-probe.h +++ b/src/internet/model/ipv4-packet-probe.h @@ -47,6 +47,10 @@ class Ipv4PacketProbe : public Probe { public: + /** + * \brief Get the type ID. + * \return the object TypeId + */ static TypeId GetTypeId (); Ipv4PacketProbe (); virtual ~Ipv4PacketProbe (); @@ -102,7 +106,9 @@ */ void TraceSink (Ptr packet, Ptr ipv4, uint32_t interface); + /// Traced Callback: the packet, the Ipv4 object and the interface. TracedCallback, Ptr, uint32_t> m_output; + /// Traced Callback: the previous packet's size and the actual packet's size. TracedCallback m_outputBytes; /// The traced packet. diff --git a/src/internet/model/ipv4-raw-socket-factory-impl.h b/src/internet/model/ipv4-raw-socket-factory-impl.h --- a/src/internet/model/ipv4-raw-socket-factory-impl.h +++ b/src/internet/model/ipv4-raw-socket-factory-impl.h @@ -25,6 +25,12 @@ namespace ns3 { +/** + * \ingroup socket + * + * \class Ipv4RawSocketFactoryImpl + * \brief Implementation of IPv4 raw socket factory. + */ class Ipv4RawSocketFactoryImpl : public Ipv4RawSocketFactory { public: diff --git a/src/internet/model/ipv4-raw-socket-factory.h b/src/internet/model/ipv4-raw-socket-factory.h --- a/src/internet/model/ipv4-raw-socket-factory.h +++ b/src/internet/model/ipv4-raw-socket-factory.h @@ -37,6 +37,10 @@ class Ipv4RawSocketFactory : public SocketFactory { public: + /** + * \brief Get the type ID. + * \return the object TypeId + */ static TypeId GetTypeId (void); }; diff --git a/src/internet/model/ipv4-raw-socket-impl.h b/src/internet/model/ipv4-raw-socket-impl.h --- a/src/internet/model/ipv4-raw-socket-impl.h +++ b/src/internet/model/ipv4-raw-socket-impl.h @@ -13,17 +13,41 @@ class NetDevice; class Node; +/** + * \class Ipv4RawSocketImpl + * \brief IPv4 raw socket. + * \ingroup socket + * + * A RAW Socket typically is used to access specific IP layers not usually + * available through L4 sockets, e.g., ICMP. The implementer should take + * particular care to define the Ipv4RawSocketImpl Attributes, and in + * particular the Protocol attribute. + */ class Ipv4RawSocketImpl : public Socket { public: + /** + * \brief Get the type ID of this class. + * \return type ID + */ static TypeId GetTypeId (void); Ipv4RawSocketImpl (); + /** + * \brief Set the node associated with this socket. + * \param node node to set + */ void SetNode (Ptr node); - virtual enum Socket::SocketErrno GetErrno (void) const; + virtual enum Socket::SocketErrno GetErrno () const; + + /** + * \brief Get socket type (NS3_SOCK_RAW) + * \return socket type + */ virtual enum Socket::SocketType GetSocketType (void) const; + virtual Ptr GetNode (void) const; virtual int Bind (const Address &address); virtual int Bind (); @@ -43,7 +67,20 @@ virtual Ptr RecvFrom (uint32_t maxSize, uint32_t flags, Address &fromAddress); + + /** + * \brief Set protocol field. + * \param protocol protocol to set + */ void SetProtocol (uint16_t protocol); + + /** + * \brief Forward up to receive method. + * \param p packet + * \param ipHeader IPv4 header + * \param incomingInterface incoming interface + * \return true if forwarded, false otherwise + */ bool ForwardUp (Ptr p, Ipv4Header ipHeader, Ptr incomingInterface); virtual bool SetAllowBroadcast (bool allowBroadcast); virtual bool GetAllowBroadcast () const; @@ -51,22 +88,26 @@ private: virtual void DoDispose (void); + /** + * \struct Data + * \brief IPv4 raw data and additional information. + */ struct Data { - Ptr packet; - Ipv4Address fromIp; - uint16_t fromProtocol; + Ptr packet; /**< Packet data */ + Ipv4Address fromIp; /**< Source address */ + uint16_t fromProtocol; /**< Protocol used */ }; - enum Socket::SocketErrno m_err; - Ptr m_node; - Ipv4Address m_src; - Ipv4Address m_dst; - uint16_t m_protocol; - std::list m_recv; - bool m_shutdownSend; - bool m_shutdownRecv; - uint32_t m_icmpFilter; - bool m_iphdrincl; + enum Socket::SocketErrno m_err; //!< Last error number. + Ptr m_node; //!< Node + Ipv4Address m_src; //!< Source address. + Ipv4Address m_dst; //!< Destination address. + uint16_t m_protocol; //!< Protocol. + std::list m_recv; //!< Packet waiting to be processed. + bool m_shutdownSend; //!< Flag to shutdown send capability. + bool m_shutdownRecv; //!< Flag to shutdown receive capability. + uint32_t m_icmpFilter; //!< ICMPv4 filter specification + bool m_iphdrincl; //!< Include IP Header information (a.k.a setsockopt (IP_HDRINCL)) }; } // namespace ns3 diff --git a/src/internet/model/ipv4-route.h b/src/internet/model/ipv4-route.h --- a/src/internet/model/ipv4-route.h +++ b/src/internet/model/ipv4-route.h @@ -89,15 +89,22 @@ #endif private: - Ipv4Address m_dest; - Ipv4Address m_source; - Ipv4Address m_gateway; - Ptr m_outputDevice; + Ipv4Address m_dest; //!< Destination address. + Ipv4Address m_source; //!< Source address. + Ipv4Address m_gateway; //!< Gateway address. + Ptr m_outputDevice; //!< Output device. #ifdef NOTYET uint32_t m_inputIfIndex; #endif }; +/** + * \brief Stream insertion operator. + * + * \param os the reference to the output stream + * \param route the Ipv4 route + * \returns the reference to the output stream + */ std::ostream& operator<< (std::ostream& os, Ipv4Route const& route); /** @@ -154,14 +161,14 @@ */ std::map GetOutputTtlMap () const; - static const uint32_t MAX_INTERFACES = 16; // Maximum number of multicast interfaces on a router - static const uint32_t MAX_TTL = 255; // Maximum time-to-live (TTL) + static const uint32_t MAX_INTERFACES = 16; //!< Maximum number of multicast interfaces on a router + static const uint32_t MAX_TTL = 255; //!< Maximum time-to-live (TTL) private: - Ipv4Address m_group; // Group - Ipv4Address m_origin; // Source of packet - uint32_t m_parent; // Source interface - std::map m_ttls; + Ipv4Address m_group; //!< Group + Ipv4Address m_origin; //!< Source of packet + uint32_t m_parent; //!< Source interface + std::map m_ttls; //!< Time to Live container }; } // namespace ns3 diff --git a/src/internet/model/ipv4-routing-table-entry.h b/src/internet/model/ipv4-routing-table-entry.h --- a/src/internet/model/ipv4-routing-table-entry.h +++ b/src/internet/model/ipv4-routing-table-entry.h @@ -135,25 +135,56 @@ uint32_t interface); private: + /** + * \brief Constructor. + * \param network network address + * \param mask network mask + * \param gateway the gateway + * \param interface the interface index + */ Ipv4RoutingTableEntry (Ipv4Address network, Ipv4Mask mask, Ipv4Address gateway, uint32_t interface); + /** + * \brief Constructor. + * \param dest destination address + * \param mask network mask + * \param interface the interface index + */ Ipv4RoutingTableEntry (Ipv4Address dest, Ipv4Mask mask, uint32_t interface); + /** + * \brief Constructor. + * \param dest destination address + * \param gateway the gateway + * \param interface the interface index + */ Ipv4RoutingTableEntry (Ipv4Address dest, Ipv4Address gateway, uint32_t interface); + /** + * \brief Constructor. + * \param dest destination address + * \param interface the interface index + */ Ipv4RoutingTableEntry (Ipv4Address dest, uint32_t interface); - Ipv4Address m_dest; - Ipv4Mask m_destNetworkMask; - Ipv4Address m_gateway; - uint32_t m_interface; + Ipv4Address m_dest; //!< destination address + Ipv4Mask m_destNetworkMask; //!< destination network mask + Ipv4Address m_gateway; //!< gateway + uint32_t m_interface; //!< output interface }; +/** + * \brief Stream insertion operator. + * + * \param os the reference to the output stream + * \param route the Ipv4 routing table entry + * \returns the reference to the output stream + */ std::ostream& operator<< (std::ostream& os, Ipv4RoutingTableEntry const& route); /** @@ -215,15 +246,29 @@ std::vector outputInterfaces); private: + /** + * \brief Constructor. + * \param origin source address + * \param group destination address + * \param inputInterface input interface + * \param outputInterfaces output interfaces + */ Ipv4MulticastRoutingTableEntry (Ipv4Address origin, Ipv4Address group, uint32_t inputInterface, std::vector outputInterfaces); - Ipv4Address m_origin; - Ipv4Address m_group; - uint32_t m_inputInterface; - std::vector m_outputInterfaces; + Ipv4Address m_origin; //!< source address + Ipv4Address m_group; //!< destination address + uint32_t m_inputInterface; //!< input interface + std::vector m_outputInterfaces; //!< output interfaces }; +/** + * \brief Stream insertion operator. + * + * \param os the reference to the output stream + * \param route the Ipv4 multicast routing table entry + * \returns the reference to the output stream + */ std::ostream& operator<< (std::ostream& os, Ipv4MulticastRoutingTableEntry const& route); } // namespace ns3 diff --git a/src/internet/model/ipv4-static-routing.h b/src/internet/model/ipv4-static-routing.h --- a/src/internet/model/ipv4-static-routing.h +++ b/src/internet/model/ipv4-static-routing.h @@ -69,6 +69,10 @@ class Ipv4StaticRouting : public Ipv4RoutingProtocol { public: + /** + * \brief The interface Id associated with this class. + * \return type identifier + */ static TypeId GetTypeId (void); Ipv4StaticRouting (); @@ -177,6 +181,7 @@ * to the routing table. * * \warning The default route counts as one of the routes. + * \return number of entries */ uint32_t GetNRoutes (void) const; @@ -308,6 +313,7 @@ * to the routing table. * * \warning The default multicast route counts as one of the routes. + * \return number of entries */ uint32_t GetNMulticastRoutes (void) const; @@ -375,23 +381,63 @@ virtual void DoDispose (void); private: + /// Container for the network routes typedef std::list > NetworkRoutes; + + /// Const Iterator for container for the network routes typedef std::list >::const_iterator NetworkRoutesCI; + + /// Iterator for container for the network routes typedef std::list >::iterator NetworkRoutesI; + /// Container for the multicast routes typedef std::list MulticastRoutes; + + /// Const Iterator for container for the multicast routes typedef std::list::const_iterator MulticastRoutesCI; + + /// Iterator for container for the multicast routes typedef std::list::iterator MulticastRoutesI; + /** + * \brief Lookup in the forwarding table for destination. + * \param dest destination address + * \param oif output interface if any (put 0 otherwise) + * \return Ipv4Route to route the packet to reach dest address + */ Ptr LookupStatic (Ipv4Address dest, Ptr oif = 0); + + /** + * \brief Lookup in the multicast forwarding table for destination. + * \param origin source address + * \param group group multicast address + * \param interface interface index + * \return Ipv4MulticastRoute to route the packet to reach dest address + */ Ptr LookupStatic (Ipv4Address origin, Ipv4Address group, uint32_t interface); + /** + * \brief Choose the source address to use with destination address. + * \param interface interface index + * \param dest IPv4 destination address + * \return IPv4 source address to use + */ Ipv4Address SourceAddressSelection (uint32_t interface, Ipv4Address dest); + /** + * \brief the forwarding table for network. + */ NetworkRoutes m_networkRoutes; + + /** + * \brief the forwarding table for multicast. + */ MulticastRoutes m_multicastRoutes; + /** + * \brief Ipv4 reference. + */ Ptr m_ipv4; }; diff --git a/src/internet/model/ipv4.h b/src/internet/model/ipv4.h --- a/src/internet/model/ipv4.h +++ b/src/internet/model/ipv4.h @@ -75,6 +75,10 @@ class Ipv4 : public Object { public: + /** + * \brief Get the type ID. + * \return the object TypeId + */ static TypeId GetTypeId (void); Ipv4 (); virtual ~Ipv4 (); @@ -167,6 +171,7 @@ * * \param address The IP address being considered * \param iif The incoming Ipv4 interface index + * \returns true if the address is associated with the interface index * * This method can be used to determine whether a received packet has * an acceptable address for local delivery on the host. The address @@ -378,13 +383,35 @@ virtual void DeleteRawSocket (Ptr socket) = 0; - static const uint32_t IF_ANY = 0xffffffff; + static const uint32_t IF_ANY = 0xffffffff; //!< interface wildcard, meaning any interface private: // Indirect the Ipv4 attributes through private pure virtual methods + + /** + * \brief Set or unset the IP forwarding state + * \param forward the forwarding state + */ virtual void SetIpForward (bool forward) = 0; + /** + * \brief Get the IP forwarding state + * \returns true if IP is in forwarding state + */ virtual bool GetIpForward (void) const = 0; + + /** + * \brief Set or unset the Weak Es Model + * + * RFC1122 term for whether host accepts datagram with a dest. address on another interface + * \param model true for Weak Es Model + */ virtual void SetWeakEsModel (bool model) = 0; + /** + * \brief Get the Weak Es Model status + * + * RFC1122 term for whether host accepts datagram with a dest. address on another interface + * \returns true for Weak Es Model activated + */ virtual bool GetWeakEsModel (void) const = 0; }; diff --git a/src/internet/model/ipv6-address-generator.h b/src/internet/model/ipv6-address-generator.h --- a/src/internet/model/ipv6-address-generator.h +++ b/src/internet/model/ipv6-address-generator.h @@ -51,7 +51,7 @@ * but can also be a pseudo-random value (\RFC{3041}). This implementation * does not generate EUI-64-based interface IDs. * - * BEWARE: this class acts as a Singleton. + * \note BEWARE: this class acts as a Singleton. * In other terms, two different instances of Ipv6AddressGenerator will * pick IPv6 numbers from the same pool. Changing the network in one of them * will also change the network in the other instances. diff --git a/src/internet/model/ipv6-end-point-demux.h b/src/internet/model/ipv6-end-point-demux.h --- a/src/internet/model/ipv6-end-point-demux.h +++ b/src/internet/model/ipv6-end-point-demux.h @@ -47,14 +47,7 @@ */ typedef std::list::iterator EndPointsI; - /** - * \brief Constructor. - */ Ipv6EndPointDemux (); - - /** - * \brief Destructor. - */ ~Ipv6EndPointDemux (); /** @@ -79,7 +72,7 @@ * \param src source address to test * \param sport source port to test * \param incomingInterface the incoming interface - * \return list en IPv6EndPoints (could be 0 element) + * \return list of IPv6EndPoints (could be 0 element) */ EndPoints Lookup (Ipv6Address dst, uint16_t dport, Ipv6Address src, uint16_t sport, Ptr incomingInterface); diff --git a/src/internet/model/ipv6-end-point.h b/src/internet/model/ipv6-end-point.h --- a/src/internet/model/ipv6-end-point.h +++ b/src/internet/model/ipv6-end-point.h @@ -35,8 +35,14 @@ class Packet; /** - * \class Ipv6EndPoint - * \brief An IPv6 end point, four tuples identification. + * \brief A representation of an internet IPv6 endpoint/connection + * + * This class provides an internet four-tuple (source and destination ports + * and addresses). These are used in the ns3::Ipv6EndPointDemux as targets + * of lookups. The class also has a callback for notification to higher + * layers that a packet from a lower layer was received. In the ns3 + * internet-stack, these notifications are automatically registered to be + * received by the corresponding socket. */ class Ipv6EndPoint { @@ -48,9 +54,6 @@ */ Ipv6EndPoint (Ipv6Address addr, uint16_t port); - /** - * \brief Destructor. - */ ~Ipv6EndPoint (); /** @@ -113,7 +116,6 @@ * the socket can not receive any packets as a result. * * \param netdevice Pointer to Netdevice of desired interface - * \returns nothing */ void BindToNetDevice (Ptr netdevice); @@ -148,6 +150,10 @@ /** * \brief Forward the packet to the upper level. + * + * Called from an L4Protocol implementation to notify an endpoint of a + * packet reception. + * * \param p the packet * \param header the packet header * \param port source port @@ -155,8 +161,11 @@ void ForwardUp (Ptr p, Ipv6Header header, uint16_t port); /** - * \brief Function called from an L4Protocol implementation - * to notify an endpoint of an icmp message reception. + * \brief Forward the ICMP packet to the upper level. + * + * Called from an L4Protocol implementation to notify an endpoint of + * an icmp message reception. + * * \param src source IPv6 address * \param ttl time-to-live * \param type ICMPv6 type diff --git a/src/internet/model/ipv6-interface-address.h b/src/internet/model/ipv6-interface-address.h --- a/src/internet/model/ipv6-interface-address.h +++ b/src/internet/model/ipv6-interface-address.h @@ -53,7 +53,7 @@ /** * \enum Scope_e - * \brief Scope of address. + * \brief Address scope. */ enum Scope_e { diff --git a/src/internet/model/ipv6-interface.h b/src/internet/model/ipv6-interface.h --- a/src/internet/model/ipv6-interface.h +++ b/src/internet/model/ipv6-interface.h @@ -42,7 +42,7 @@ * \brief The IPv6 representation of a network interface * * By default IPv6 interfaces are created in the "down" state - * with IP "fe80::1" and a /64 prefix. Before becoming useable, + * with IP "fe80::1" and a /64 prefix. Before becoming usable, * the user must invoke SetUp on them once the final IPv6 address * and mask has been set. */ @@ -268,7 +268,7 @@ typedef std::list::iterator Ipv6InterfaceAddressListI; /** - * \brief Const Container Itareator for the Ipv6InterfaceAddresses. + * \brief Const Container Iterator for the Ipv6InterfaceAddresses. */ typedef std::list::const_iterator Ipv6InterfaceAddressListCI; diff --git a/src/internet/model/ipv6-l3-protocol.h b/src/internet/model/ipv6-l3-protocol.h --- a/src/internet/model/ipv6-l3-protocol.h +++ b/src/internet/model/ipv6-l3-protocol.h @@ -94,7 +94,7 @@ virtual ~Ipv6L3Protocol (); /** - * \brief Set node for this stack. + * \brief Set node associated with this stack. * \param node node to set */ void SetNode (Ptr node); @@ -427,16 +427,18 @@ /** * \brief Copy constructor. - * \param o object to copy + * + * Defined but not implemented to avoid misuse */ - Ipv6L3Protocol (const Ipv6L3Protocol& o); + Ipv6L3Protocol (const Ipv6L3Protocol&); /** * \brief Copy constructor. - * \param o object to copy + * + * Defined but not implemented to avoid misuse * \returns the copied object */ - Ipv6L3Protocol &operator = (const Ipv6L3Protocol& o); + Ipv6L3Protocol &operator = (const Ipv6L3Protocol&); /** * \brief Construct an IPv6 header. @@ -469,7 +471,7 @@ void IpForward (Ptr idev, Ptr rtentry, Ptr p, const Ipv6Header& header); /** - * \brief Forward a packet in multicast. + * \brief Forward a multicast packet. * \param idev Pointer to ingress network device * \param mrtentry route * \param p packet to forward diff --git a/src/internet/model/ipv6-list-routing.h b/src/internet/model/ipv6-list-routing.h --- a/src/internet/model/ipv6-list-routing.h +++ b/src/internet/model/ipv6-list-routing.h @@ -136,15 +136,8 @@ */ static bool Compare (const Ipv6RoutingProtocolEntry& a, const Ipv6RoutingProtocolEntry& b); - /** - * \brief List of routing protocols. - */ - Ipv6RoutingProtocolList m_routingProtocols; - - /** - * \brief Ipv6 reference. - */ - Ptr m_ipv6; + Ipv6RoutingProtocolList m_routingProtocols; //!< List of routing protocols. + Ptr m_ipv6; //!< Ipv6 this protocol is associated with. }; } // namespace ns3 diff --git a/src/internet/model/ipv6-raw-socket-factory-impl.h b/src/internet/model/ipv6-raw-socket-factory-impl.h --- a/src/internet/model/ipv6-raw-socket-factory-impl.h +++ b/src/internet/model/ipv6-raw-socket-factory-impl.h @@ -27,6 +27,8 @@ { /** + * \ingroup socket + * * \class Ipv6RawSocketFactoryImpl * \brief Implementation of IPv6 raw socket factory. */ diff --git a/src/internet/model/ipv6-raw-socket-impl.h b/src/internet/model/ipv6-raw-socket-impl.h --- a/src/internet/model/ipv6-raw-socket-impl.h +++ b/src/internet/model/ipv6-raw-socket-impl.h @@ -36,6 +36,7 @@ /** * \class Ipv6RawSocketImpl * \brief IPv6 raw socket. + * \ingroup socket * * A RAW Socket typically is used to access specific IP layers not usually * available through L4 sockets, e.g., ICMP. The implementer should take @@ -70,26 +71,15 @@ */ static TypeId GetTypeId (); - /** - * \brief Constructor. - */ Ipv6RawSocketImpl (); - - /** - * \brief Destructor. - */ virtual ~Ipv6RawSocketImpl (); /** - * \brief Set the node. + * \brief Set the node associated with this socket. * \param node node to set */ void SetNode (Ptr node); - /** - * \brief Get last error number. - * \return error number - */ virtual enum Socket::SocketErrno GetErrno () const; /** @@ -98,108 +88,24 @@ */ virtual enum Socket::SocketType GetSocketType () const; - /** - * \brief Get node. - * \return node associated with this raw socket. - */ virtual Ptr GetNode () const; - /** - * \brief Bind the socket to address. - * \param address bind to this address - * \return 0 if success, -1 otherwise - */ virtual int Bind (const Address& address); - - /** - * \brief Bind socket. - * \return 0 if success, -1 otherwise - */ virtual int Bind (); virtual int Bind6 (); - /** - * \brief Get socket address. - * \param address socket address if method success - * \return 0 if success, -1 otherwise - */ virtual int GetSockName (Address& address) const; - /** - * \brief Close the socket. - * \return 0 if success, -1 otherwise - */ virtual int Close (); - - /** - * \brief Shutdown send capability. - * \return 0 if success, -1 otherwise - */ virtual int ShutdownSend (); - - /** - * \brief Shutdown receive capability. - * \return 0 if success, -1 otherwise - */ virtual int ShutdownRecv (); - - /** - * \brief Connect to address. - * \param address address - * \return 0 if success, -1 otherwise - */ virtual int Connect (const Address& address); - - /** - * \brief Listen. - * \return 0 if success, -1 otherwise - */ virtual int Listen (); - - /** - * \brief Get TX size available. - * \return TX size - */ virtual uint32_t GetTxAvailable () const; - - /** - * \brief Get RX size available. - * \return RX size - */ virtual uint32_t GetRxAvailable () const; - - /** - * \brief Send a packet. - * \param p packet to send - * \param flags additionnal flags - * \return 0 if success, -1 otherwise - */ virtual int Send (Ptr p, uint32_t flags); - - /** - * \brief Send a packet. - * \param p packet to send - * \param flags additionnal flags - * \param toAddress destination address - * \return 0 if success, -1 otherwise - */ virtual int SendTo (Ptr p, uint32_t flags, const Address& toAddress); - - /** - * \brief Receive packet. - * \param maxSize maximum size - * \param flags additionnal flags - * \return packet received - */ virtual Ptr Recv (uint32_t maxSize, uint32_t flags); - - /** - * \brief Receive packet. - * \param maxSize maximum size - * \param flags additionnal flags - * \param fromAddress source address - * \return packet received - */ virtual Ptr RecvFrom (uint32_t maxSize, uint32_t flags, Address& fromAddress); /** diff --git a/src/internet/model/ipv6-routing-table-entry.h b/src/internet/model/ipv6-routing-table-entry.h --- a/src/internet/model/ipv6-routing-table-entry.h +++ b/src/internet/model/ipv6-routing-table-entry.h @@ -261,12 +261,12 @@ }; /** -* \brief Stream insertion operator. -* -* \param os the reference to the output stream -* \param route the Ipv6 routing table entry -* \returns the reference to the output stream -*/ + * \brief Stream insertion operator. + * + * \param os the reference to the output stream + * \param route the Ipv6 routing table entry + * \returns the reference to the output stream + */ std::ostream& operator<< (std::ostream& os, Ipv6RoutingTableEntry const& route); /** @@ -372,12 +372,12 @@ }; /** -* \brief Stream insertion operator. -* -* \param os the reference to the output stream -* \param route the Ipv6 multicast routing table entry -* \returns the reference to the output stream -*/ + * \brief Stream insertion operator. + * + * \param os the reference to the output stream + * \param route the Ipv6 multicast routing table entry + * \returns the reference to the output stream + */ std::ostream& operator<< (std::ostream& os, Ipv6MulticastRoutingTableEntry const& route); } /* namespace ns3 */ diff --git a/src/internet/model/ipv6-static-routing.h b/src/internet/model/ipv6-static-routing.h --- a/src/internet/model/ipv6-static-routing.h +++ b/src/internet/model/ipv6-static-routing.h @@ -48,9 +48,22 @@ /** * \ingroup ipv6StaticRouting * \class Ipv6StaticRouting - * \brief Static routing protocol for IP version 6 stack. + * + * \brief Static routing protocol for IP version 6 stacks. + * + * This class provides a basic set of methods for inserting static + * unicast and multicast routes into the Ipv6 routing system. + * This particular protocol is designed to be inserted into an + * Ipv6ListRouting protocol but can be used also as a standalone + * protocol. + * + * The Ipv6StaticRouting class inherits from the abstract base class + * Ipv6RoutingProtocol that defines the interface methods that a routing + * protocol must support. + * * \see Ipv6RoutingProtocol * \see Ipv6ListRouting + * \see Ipv6ListRouting::AddRoutingProtocol */ class Ipv6StaticRouting : public Ipv6RoutingProtocol { @@ -61,14 +74,7 @@ */ static TypeId GetTypeId (); - /** - * \brief Constructor. - */ Ipv6StaticRouting (); - - /** - * \brief Destructor. - */ virtual ~Ipv6StaticRouting (); /** diff --git a/src/internet/model/loopback-net-device.h b/src/internet/model/loopback-net-device.h --- a/src/internet/model/loopback-net-device.h +++ b/src/internet/model/loopback-net-device.h @@ -38,6 +38,10 @@ class LoopbackNetDevice : public NetDevice { public: + /** + * \brief Get the type ID. + * \return the object TypeId + */ static TypeId GetTypeId (void); LoopbackNetDevice (); @@ -72,13 +76,30 @@ protected: virtual void DoDispose (void); private: + /** + * Receive a packet from tge Loopback NetDevice. + * + * \param packet a reference to the received packet + * \param protocol the protocol + * \param to destination address + * \param from source address + */ void Receive (Ptr packet, uint16_t protocol, Mac48Address to, Mac48Address from); + + /** + * The callback used to notify higher layers that a packet has been received. + */ NetDevice::ReceiveCallback m_rxCallback; + + /** + * The callback used to notify higher layers that a packet has been received in promiscuous mode. + */ NetDevice::PromiscReceiveCallback m_promiscCallback; - Ptr m_node; - uint16_t m_mtu; - uint32_t m_ifIndex; - Mac48Address m_address; + + Ptr m_node; //!< the node this NetDevice is associated with + uint16_t m_mtu; //!< device MTU + uint32_t m_ifIndex; //!< interface index + Mac48Address m_address; //!< NetDevice MAC address }; } // namespace ns3 diff --git a/src/internet/model/ndisc-cache.h b/src/internet/model/ndisc-cache.h --- a/src/internet/model/ndisc-cache.h +++ b/src/internet/model/ndisc-cache.h @@ -412,20 +412,29 @@ }; private: + /** + * \brief Neighbor Discovery Cache container + */ typedef sgi::hash_map Cache; + /** + * \brief Neighbor Discovery Cache container iterator + */ typedef sgi::hash_map::iterator CacheI; /** * \brief Copy constructor. - * \param a cache to copy + * + * Not implemented to avoid misuse */ - NdiscCache (NdiscCache const &a); + NdiscCache (NdiscCache const &); /** - * \brief Equal operator. - * \param a cache to copy + * \brief Copy constructor. + * + * Not implemented to avoid misuse + * \returns */ - NdiscCache& operator= (NdiscCache const &a); + NdiscCache& operator= (NdiscCache const &); /** * \brief Dispose this object. diff --git a/src/internet/model/nsc-sysctl.cc b/src/internet/model/nsc-sysctl.cc --- a/src/internet/model/nsc-sysctl.cc +++ b/src/internet/model/nsc-sysctl.cc @@ -23,9 +23,19 @@ namespace ns3 { +/** + * \ingroup nsctcp + * + * This object represent the underlying nsc stack attributes and + * provide a ns-3-like system to access them though sysctls + */ class NscStackStringAccessor : public AttributeAccessor { public: + /** + * \brief Constructor + * \param name name of the attribute + */ NscStackStringAccessor (std::string name) : m_name (name) {} virtual bool Set (ObjectBase * object, const AttributeValue &val) const; @@ -33,7 +43,7 @@ virtual bool HasGetter (void) const; virtual bool HasSetter (void) const; private: - std::string m_name; + std::string m_name; //!< name of the attribute }; bool NscStackStringAccessor::HasGetter (void) const diff --git a/src/internet/model/nsc-sysctl.h b/src/internet/model/nsc-sysctl.h --- a/src/internet/model/nsc-sysctl.h +++ b/src/internet/model/nsc-sysctl.h @@ -25,20 +25,42 @@ namespace ns3 { -// This object represents the underlying nsc stack, -// which is aggregated to a Node object, and which provides access to the -// sysctls of the nsc stack through attributes. +/** + * \ingroup nsctcp + * + * This object represents the underlying nsc stack, + * which is aggregated to a Node object, and which provides access to the + * sysctls of the nsc stack through attributes. + */ class Ns3NscStack : public Object { public: + /** + * \brief Get the type ID. + * \return the object TypeId + */ static TypeId GetTypeId (void); virtual TypeId GetInstanceTypeId (void) const; + /** + * \brief Set the underlying stack + * \param stack the stack + */ void SetStack (INetStack *stack) { m_stack = stack; } private: friend class NscStackStringAccessor; + /** + * \brief Set an attribute + * \param name the attribute name + * \param value the attribute value + */ void Set (std::string name, std::string value); + /** + * \brief Get an attribute + * \param name the attribute name + * \returns the attribute value + */ std::string Get (std::string name) const; - INetStack *m_stack; + INetStack *m_stack; //!< the underlying stack }; } // namespace ns3 diff --git a/src/internet/model/nsc-tcp-l4-protocol.cc b/src/internet/model/nsc-tcp-l4-protocol.cc --- a/src/internet/model/nsc-tcp-l4-protocol.cc +++ b/src/internet/model/nsc-tcp-l4-protocol.cc @@ -55,16 +55,45 @@ /* see http://www.iana.org/assignments/protocol-numbers */ const uint8_t NscTcpL4Protocol::PROT_NUMBER = 6; +/** + * \ingroup nsctcp + * \brief Nsc interface implementation class. + */ class NscInterfaceImpl : public ISendCallback, public IInterruptCallback { public: + /** + * Constructor + * \param prot the NSC TCP protocol + */ NscInterfaceImpl (Ptr prot); private: + /** + * \brief Invoked by NSCs 'ethernet driver' to re-inject a packet into ns-3. + * + * A packet is an octet soup consisting of an IP Header, TCP Header + * and user payload, if any + * + * \param data the data + * \param datalen the data length + */ virtual void send_callback (const void *data, int datalen); + /** + * \brief Called by the NSC stack whenever something of interest has happened + * + * Examples: when data arrives on a socket, a listen socket + * has a new connection pending, etc. + */ virtual void wakeup (); + /** + * \brief Called by the Linux stack RNG initialization + * + * Its also used by the cradle code to add a timestamp to + * printk/printf/debug output. + */ virtual void gettime (unsigned int *, unsigned int *); private: - Ptr m_prot; + Ptr m_prot; //!< the NSC TCP protocol }; NscInterfaceImpl::NscInterfaceImpl (Ptr prot) @@ -113,9 +142,16 @@ return tid; } +/** + * \brief External Random number generator + * + * \todo make it random... + * + * \returns a random number + */ int external_rand () { - return 1; /// \todo + return 1; } NscTcpL4Protocol::NscTcpL4Protocol () @@ -385,7 +421,7 @@ void NscTcpL4Protocol::wakeup () { - /// \todo + // \todo // this should schedule a timer to read from all tcp sockets now... this is // an indication that data might be waiting on the socket @@ -451,7 +487,7 @@ // IP address of the subnet but this was found to fail for // some use cases in /30 subnets. - /// \todo \bugid{1398} NSC's limitation to single-interface nodes + // \todo \bugid{1398} NSC's limitation to single-interface nodes m_nscStack->add_default_gateway (addrOss.str ().c_str ()); } } diff --git a/src/internet/model/nsc-tcp-l4-protocol.h b/src/internet/model/nsc-tcp-l4-protocol.h --- a/src/internet/model/nsc-tcp-l4-protocol.h +++ b/src/internet/model/nsc-tcp-l4-protocol.h @@ -45,18 +45,39 @@ */ class NscTcpL4Protocol : public IpL4Protocol { public: - static const uint8_t PROT_NUMBER; + static const uint8_t PROT_NUMBER; //!< protocol number (0x6) + /** + * \brief Get the type ID. + * \return the object TypeId + */ static TypeId GetTypeId (void); - /** - * \brief Constructor - */ + NscTcpL4Protocol (); virtual ~NscTcpL4Protocol (); + /** + * Set node associated with this stack + * \param node the node + */ void SetNode (Ptr node); + + /** + * Set the NSC library to be used + * \param lib the library path + */ void SetNscLibrary (const std::string &lib); + + /** + * Get the NSC library being used + * \returns the library path + */ std::string GetNscLibrary (void) const; virtual int GetProtocolNumber (void) const; + + /** + * Get the NSC version + * \returns the NSC version + */ virtual int GetVersion (void) const; /** @@ -65,27 +86,54 @@ */ Ptr CreateSocket (void); + /** + * \brief Allocate an IPv4 Endpoint + * \return the Endpoint + */ Ipv4EndPoint *Allocate (void); + /** + * \brief Allocate an IPv4 Endpoint + * \param address address to use + * \return the Endpoint + */ Ipv4EndPoint *Allocate (Ipv4Address address); + /** + * \brief Allocate an IPv4 Endpoint + * \param port port to use + * \return the Endpoint + */ Ipv4EndPoint *Allocate (uint16_t port); + /** + * \brief Allocate an IPv4 Endpoint + * \param address address to use + * \param port port to use + * \return the Endpoint + */ Ipv4EndPoint *Allocate (Ipv4Address address, uint16_t port); + /** + * \brief Allocate an IPv4 Endpoint + * \param localAddress local address to use + * \param localPort local port to use + * \param peerAddress remote address to use + * \param peerPort remote port to use + * \return the Endpoint + */ Ipv4EndPoint *Allocate (Ipv4Address localAddress, uint16_t localPort, Ipv4Address peerAddress, uint16_t peerPort); + + /** + * \brief Remove an IPv4 Endpoint. + * \param endPoint the end point to remove + */ void DeAllocate (Ipv4EndPoint *endPoint); - /** - * \brief Receive a packet up the protocol stack - * \param p The Packet to dump the contents into - * \param header IPv4 Header information - * \param incomingInterface The Ipv4Interface it was received on - */ virtual IpL4Protocol::RxStatus Receive (Ptr p, - Ipv4Header const &header, - Ptr incomingInterface); + Ipv4Header const &header, + Ptr incomingInterface); virtual IpL4Protocol::RxStatus Receive (Ptr p, - Ipv6Header const &header, - Ptr interface); + Ipv6Header const &header, + Ptr interface); // From IpL4Protocol virtual void SetDownTarget (IpL4Protocol::DownTargetCallback cb); @@ -97,38 +145,73 @@ virtual void DoDispose (void); virtual void NotifyNewAggregate (); private: + /** + * \brief Copy constructor + * + * Defined and not implemented to avoid misuse + */ NscTcpL4Protocol (NscTcpL4Protocol const &); + /** + * \brief Copy constructor + * + * Defined and not implemented to avoid misuse + * \returns + */ NscTcpL4Protocol& operator= (NscTcpL4Protocol const &); // NSC callbacks. // NSC invokes these hooks to interact with the simulator. // In any case, these methods are only to be called by NSC. - // - // send_callback is invoked by NSCs 'ethernet driver' to re-inject - // a packet (i.e. an octet soup consisting of an IP Header, TCP Header - // and user payload, if any), into ns-3. + + /** + * \brief Invoked by NSCs 'ethernet driver' to re-inject a packet into ns-3. + * + * A packet is an octet soup consisting of an IP Header, TCP Header + * and user payload, if any + * + * \param data the data + * \param datalen the data length + */ void send_callback (const void *data, int datalen); - // This is called by the NSC stack whenever something of interest - // has happened, e.g. when data arrives on a socket, a listen socket - // has a new connection pending, etc. + /** + * \brief Called by the NSC stack whenever something of interest has happened + * + * Examples: when data arrives on a socket, a listen socket + * has a new connection pending, etc. + */ void wakeup (); - // This is called by the Linux stack RNG initialization. - // Its also used by the cradle code to add a timestamp to - // printk/printf/debug output. + /** + * \brief Called by the Linux stack RNG initialization + * + * Its also used by the cradle code to add a timestamp to + * printk/printf/debug output. + * \param sec seconds + * \param usec microseconds + */ void gettime (unsigned int *sec, unsigned int *usec); + /** + * \brief Add an interface + * + * Actually NSC only supports one interface per node (\bugid{1398}) + */ void AddInterface (void); + + /** + * \brief Provide a "soft" interrupt to NSC + */ void SoftInterrupt (void); friend class NscInterfaceImpl; friend class NscTcpSocketImpl; - Ptr m_node; - Ipv4EndPointDemux *m_endPoints; - INetStack* m_nscStack; - NscInterfaceImpl *m_nscInterface; - void *m_dlopenHandle; - std::string m_nscLibrary; - Timer m_softTimer; - std::vector > m_sockets; - IpL4Protocol::DownTargetCallback m_downTarget; + + Ptr m_node; //!< the node this stack is associated with + Ipv4EndPointDemux *m_endPoints; //!< A list of IPv4 end points. + INetStack* m_nscStack; //!< the NSC stack. + NscInterfaceImpl *m_nscInterface; //!< the NSC Interface. + void *m_dlopenHandle; //!< dynamic library handle. + std::string m_nscLibrary; //!< path to the NSC library. + Timer m_softTimer; //!< Soft interrupt timer + std::vector > m_sockets; //!< list of sockets + IpL4Protocol::DownTargetCallback m_downTarget; //!< Callback to send packets over IPv4 }; } // namespace ns3 diff --git a/src/internet/model/nsc-tcp-socket-factory-impl.h b/src/internet/model/nsc-tcp-socket-factory-impl.h --- a/src/internet/model/nsc-tcp-socket-factory-impl.h +++ b/src/internet/model/nsc-tcp-socket-factory-impl.h @@ -47,6 +47,10 @@ NscTcpSocketFactoryImpl (); virtual ~NscTcpSocketFactoryImpl (); + /** + * \brief Set the associated TCP L4 protocol. + * \param tcp the TCP L4 protocol + */ void SetTcp (Ptr tcp); virtual Ptr CreateSocket (void); @@ -54,7 +58,7 @@ protected: virtual void DoDispose (void); private: - Ptr m_tcp; + Ptr m_tcp; //!< the associated TCP L4 protocol }; } // namespace ns3 diff --git a/src/internet/model/nsc-tcp-socket-impl.h b/src/internet/model/nsc-tcp-socket-impl.h --- a/src/internet/model/nsc-tcp-socket-impl.h +++ b/src/internet/model/nsc-tcp-socket-impl.h @@ -53,15 +53,34 @@ class NscTcpSocketImpl : public TcpSocket { public: + /** + * \brief Get the type ID. + * \return the object TypeId + */ static TypeId GetTypeId (void); /** * Create an unbound tcp socket. */ NscTcpSocketImpl (); + + /** + * Clone a TCP socket, for use upon receiving a connection request in LISTEN state + * + * \param sock the original Tcp Socket + */ NscTcpSocketImpl (const NscTcpSocketImpl& sock); virtual ~NscTcpSocketImpl (); + /** + * \brief Set the associated node. + * \param node the node + */ void SetNode (Ptr node); + + /** + * \brief Set the associated TCP L4 protocol. + * \param tcp the TCP L4 protocol + */ void SetTcp (Ptr tcp); virtual enum SocketErrno GetErrno (void) const; @@ -87,22 +106,68 @@ virtual bool GetAllowBroadcast () const; private: + /** + * \brief Called by NscTcpSocketImpl::ForwardUp() + * + * Actually performs the ForwardUp operations + */ void NSCWakeup (void); friend class Tcp; // invoked by Tcp class + /** + * Finish the binding process + * \returns 0 on success, -1 on failure + */ int FinishBind (void); + /** + * \brief Called by the L3 protocol when it received a packet to pass on to TCP. + * + * \param p the incoming packet + * \param header the packet's IPv4 header + * \param port the incoming port + * \param incomingInterface the incoming interface + */ void ForwardUp (Ptr p, Ipv4Header header, uint16_t port, Ptr incomingInterface); + /** + * \brief Kill this socket by zeroing its attributes (IPv4) + * + * This is a callback function configured to m_endpoint in + * SetupCallback(), invoked when the endpoint is destroyed. + */ void Destroy (void); //methods for state + /** + * \brief Send all the pending data + * \returns true on success + */ bool SendPendingData (void); + /** + * \brief Read all the pending data + * \returns true on success + */ bool ReadPendingData (void); + /** + * \brief Accept an incoming connection + * \returns true on success + */ bool Accept (void); + /** + * \brief Complete the Fork operations (after a connection has been accepted) + */ void CompleteFork (void); + + /** + * \brief Called when a connection is in Established state + */ void ConnectionSucceeded (); // Manage data tx/rx - /// \todo This should be virtual and overridden + // \todo This should be virtual and overridden + /** + * \brief Copy self + * \returns a copy of self + */ Ptr Copy (); // attribute related @@ -112,7 +177,15 @@ virtual uint32_t GetRcvBufSize (void) const; virtual void SetSegSize (uint32_t size); virtual uint32_t GetSegSize (void) const; + /** + * \brief Set the Advertised Window size + * \param window the window size + */ virtual void SetAdvWin (uint32_t window); + /** + * \brief Get the Advertised Window size + * \returns the window size + */ virtual uint32_t GetAdvWin (void) const; virtual void SetSSThresh (uint32_t threshold); virtual uint32_t GetSSThresh (void) const; @@ -131,57 +204,62 @@ virtual void SetPersistTimeout (Time timeout); virtual Time GetPersistTimeout (void) const; + /** + * \brief Translate between a NSC error and a ns-3 error code + * \param err NSC error + * \returns ns-3 error code + */ enum Socket::SocketErrno GetNativeNs3Errno (int err) const; - uint32_t m_delAckMaxCount; - Time m_delAckTimeout; - bool m_noDelay; + uint32_t m_delAckMaxCount; //!< Number of packet to fire an ACK before delay timeout + Time m_delAckTimeout; //!< Time to delay an ACK + bool m_noDelay; //!< Disable ACk delay - Ipv4EndPoint *m_endPoint; - Ptr m_node; - Ptr m_tcp; - Ipv4Address m_remoteAddress; - uint16_t m_remotePort; + Ipv4EndPoint *m_endPoint; //!< the IPv4 endpoint + Ptr m_node; //!< the associated node + Ptr m_tcp; //!< the associated TCP L4 protocol + Ipv4Address m_remoteAddress; //!< peer IP address + uint16_t m_remotePort; //!< peer port //these two are so that the socket/endpoint cloning works - Ipv4Address m_localAddress; - uint16_t m_localPort; - InetSocketAddress m_peerAddress; - enum SocketErrno m_errno; - bool m_shutdownSend; - bool m_shutdownRecv; - bool m_connected; + Ipv4Address m_localAddress; //!< local address + uint16_t m_localPort; //!< local port + InetSocketAddress m_peerAddress; //!< peer IP and port + enum SocketErrno m_errno; //!< last error number + bool m_shutdownSend; //!< Send no longer allowed + bool m_shutdownRecv; //!< Receive no longer allowed + bool m_connected; //!< Connection established //manage the state information - TracedValue m_state; - bool m_closeOnEmpty; + TracedValue m_state; //!< state information + bool m_closeOnEmpty; //!< true if socket will close when buffer is empty //needed to queue data when in SYN_SENT state - std::queue > m_txBuffer; - uint32_t m_txBufferSize; + std::queue > m_txBuffer; //!< transmission buffer + uint32_t m_txBufferSize; //!< transmission buffer size // Window management - uint32_t m_segmentSize; //SegmentSize - uint32_t m_rxWindowSize; - uint32_t m_advertisedWindowSize; //Window to advertise - TracedValue m_cWnd; //Congestion window - uint32_t m_ssThresh; //Slow Start Threshold - uint32_t m_initialCWnd; //Initial cWnd value + uint32_t m_segmentSize; //!< SegmentSize + uint32_t m_rxWindowSize; //!< Receive window size + uint32_t m_advertisedWindowSize; //!< Window to advertise + TracedValue m_cWnd; //!< Congestion window + uint32_t m_ssThresh; //!< Slow Start Threshold + uint32_t m_initialCWnd; //!< Initial cWnd value // Round trip time estimation - Time m_lastMeasuredRtt; + Time m_lastMeasuredRtt; //!< Last measured RTT // Timer-related members - Time m_cnTimeout; - uint32_t m_cnCount; - Time m_persistTimeout; + Time m_cnTimeout; //!< Timeout for connection retry + uint32_t m_cnCount; //!< Count of remaining connection retries + Time m_persistTimeout; //!< Time between sending 1-byte probes // Temporary queue for delivering data to application - std::queue > m_deliveryQueue; - uint32_t m_rxAvailable; - INetStreamSocket* m_nscTcpSocket; + std::queue > m_deliveryQueue; //!< receive buffer + uint32_t m_rxAvailable; //!< receive buffer available size + INetStreamSocket* m_nscTcpSocket; //!< the real NSC TCP socket // Attributes - uint32_t m_sndBufSize; // buffer limit for the outgoing queue - uint32_t m_rcvBufSize; // maximum receive socket buffer size + uint32_t m_sndBufSize; //!< buffer limit for the outgoing queue + uint32_t m_rcvBufSize; //!< maximum receive socket buffer size }; } // namespace ns3 diff --git a/src/internet/model/pending-data.h b/src/internet/model/pending-data.h --- a/src/internet/model/pending-data.h +++ b/src/internet/model/pending-data.h @@ -41,17 +41,54 @@ class PendingData { public: PendingData (); + /** + * Constructor + * \param s size + * \param d data + * \param msg message size + * \param resp response size + */ PendingData (uint32_t s, uint8_t* d = NULL, uint32_t msg = 0, uint32_t resp = 0); - PendingData (const std::string&); // Construct from string - PendingData (uint8_t*, uint32_t&, Packet*); // Construct from serialized buffer - PendingData (const PendingData&); // Copy constructor + /** + * Constructor from string + * \param s string + */ + PendingData (const std::string& s); // Construct from string + // not implemented ? + // PendingData (uint8_t*, uint32_t&, Packet*); // Construct from serialized buffer + /** + * Copy constructor + * \param o object to copy + */ + PendingData (const PendingData& o); // Copy constructor virtual ~PendingData (); // Destructor + + /** + * Returns the size of the pending data + * \returns size of pending data + */ uint32_t Size () const { return size; } // Serialization - uint8_t* Serialize (uint8_t*, uint32_t&); // Serialize to a buffer - uint8_t* Construct (uint8_t*, uint32_t&); // Construct from buffer - virtual void Clear (); // Remove all associated data - virtual void Add (uint32_t s, const uint8_t* d = 0); // Add some data to end + // not implemented ? + // uint8_t* Serialize (uint8_t*, uint32_t&); // Serialize to a buffer + // not implemented ? + // uint8_t* Construct (uint8_t*, uint32_t&); // Construct from buffer + + /** + * \brief Remove all associated data + */ + virtual void Clear (); + + /** + * \brief Add some data to end + * \param s the data size. + * \param d the data to store. + */ + virtual void Add (uint32_t s, const uint8_t* d = 0); // + /** + * \brief Add some data to end + * \param p packet containing the data. + */ virtual void Add (Ptr p); /** * This method returns the number of bytes in the PendingData buffer @@ -89,9 +126,24 @@ * \return seqOffset-seqFront */ virtual uint32_t OffsetFromSeq (const SequenceNumber32& seqFront, const SequenceNumber32& seqOffset); - virtual Ptr CopyFromOffset (uint32_t, uint32_t); // Size, offset, ret packet - // Copy data, size, offset specified by sequence difference - virtual Ptr CopyFromSeq (uint32_t, const SequenceNumber32&, const SequenceNumber32&); + + /** + * \brief Copy data starting from a give offset + * \param s size of data to copy + * \param o offset + * \returns a packet containing the requested data + */ + virtual Ptr CopyFromOffset (uint32_t s, uint32_t o); // Size, offset, ret packet + /** + * \brief Copy data starting from a give offset + * \param s size of data to copy + * \param f Front sequence + * \param o Offset sequence + * + * \see PendingData::OffsetFromSeq() + * \returns a packet containing the requested data + */ + virtual Ptr CopyFromSeq (uint32_t s, const SequenceNumber32& f, const SequenceNumber32& o); /** * Permits object to clear any pending data between seqFront and * seqOffset - 1). Callers should check the return value to determine @@ -102,15 +154,35 @@ * \return number of bytes from the front that were removed from the buffer */ virtual uint32_t RemoveToSeq (const SequenceNumber32& seqFront, const SequenceNumber32& seqOffset); - PendingData* Copy () const; // Create a copy of this header - PendingData* CopyS (uint32_t); // Copy with new size - PendingData* CopySD (uint32_t, uint8_t*); // Copy with new size, new data + + /** + * \brief Create a copy of self + * \returns copy of pending data + */ + PendingData* Copy () const; + /** + * \brief Create a copy of self with new size + * + * Assumes no associated data + * \param s new size + * \returns copy of pending data + */ + PendingData* CopyS (uint32_t s); // Copy + /** + * \brief Create a copy of self with new size, new data + * + * Assumes no associated data + * \param s new size + * \param d new data + * \returns copy of pending data + */ + PendingData* CopySD (uint32_t s, uint8_t* d); public: - uint32_t size; // Number of data bytes - std::vector > data; // Corresponding data (may be null) + uint32_t size; //!< Number of data bytes + std::vector > data; //!< Corresponding data (may be null) // The next two fields allow simulated applications to exchange some info - uint32_t msgSize; // Total size of message - uint32_t responseSize; // Size of response requested + uint32_t msgSize; //!< Total size of message + uint32_t responseSize; //!< Size of response requested }; } //namepsace ns3 diff --git a/src/internet/model/rtt-estimator.h b/src/internet/model/rtt-estimator.h --- a/src/internet/model/rtt-estimator.h +++ b/src/internet/model/rtt-estimator.h @@ -39,15 +39,26 @@ */ class RttHistory { public: + /** + * \brief Constructor - builds an RttHistory with the given parameters + * \param s First sequence number in packet sent + * \param c Number of bytes sent + * \param t Time this one was sent + */ RttHistory (SequenceNumber32 s, uint32_t c, Time t); + /** + * \brief Copy constructor + * \param h the object to copy + */ RttHistory (const RttHistory& h); // Copy constructor public: - SequenceNumber32 seq; // First sequence number in packet sent - uint32_t count; // Number of bytes sent - Time time; // Time this one was sent - bool retx; // True if this has been retransmitted + SequenceNumber32 seq; //!< First sequence number in packet sent + uint32_t count; //!< Number of bytes sent + Time time; //!< Time this one was sent + bool retx; //!< True if this has been retransmitted }; +/// Container for RttHistory objects typedef std::deque RttHistory_t; /** @@ -57,10 +68,18 @@ */ class RttEstimator : public Object { public: + /** + * \brief Get the type ID. + * \return the object TypeId + */ static TypeId GetTypeId (void); RttEstimator(); - RttEstimator (const RttEstimator&); + /** + * \brief Copy constructor + * \param r the object to copy + */ + RttEstimator (const RttEstimator& r); virtual ~RttEstimator(); @@ -97,6 +116,10 @@ */ virtual Time RetransmitTimeout () = 0; + /** + * \brief Copy object + * \returns a copy of itself + */ virtual Ptr Copy () const = 0; /** @@ -139,16 +162,16 @@ Time GetCurrentEstimate (void) const; private: - SequenceNumber32 m_next; // Next expected sequence to be sent - RttHistory_t m_history; // List of sent packet - uint16_t m_maxMultiplier; - Time m_initialEstimatedRtt; + SequenceNumber32 m_next; //!< Next expected sequence to be sent + RttHistory_t m_history; //!< List of sent packet + uint16_t m_maxMultiplier; //!< Maximum RTO Multiplier + Time m_initialEstimatedRtt; //!< Initial RTT estimation protected: - Time m_currentEstimatedRtt; // Current estimate - Time m_minRto; // minimum value of the timeout - uint32_t m_nSamples; // Number of samples - uint16_t m_multiplier; // RTO Multiplier + Time m_currentEstimatedRtt; //!< Current estimate + Time m_minRto; //!< minimum value of the timeout + uint32_t m_nSamples; //!< Number of samples + uint16_t m_multiplier; //!< RTO Multiplier }; /** @@ -163,11 +186,19 @@ */ class RttMeanDeviation : public RttEstimator { public: + /** + * \brief Get the type ID. + * \return the object TypeId + */ static TypeId GetTypeId (void); RttMeanDeviation (); - RttMeanDeviation (const RttMeanDeviation&); + /** + * \brief Copy constructor + * \param r the object to copy + */ + RttMeanDeviation (const RttMeanDeviation& r); virtual TypeId GetInstanceTypeId (void) const; @@ -186,7 +217,7 @@ Ptr Copy () const; /** - * \brief Resets sthe estimator. + * \brief Resets the estimator. */ void Reset (); @@ -197,8 +228,8 @@ void Gain (double g); private: - double m_gain; // Filter gain - Time m_variance; // Current variance + double m_gain; //!< Filter gain + Time m_variance; //!< Current variance }; } // namespace ns3 diff --git a/src/internet/model/sim_interface.h b/src/internet/model/sim_interface.h --- a/src/internet/model/sim_interface.h +++ b/src/internet/model/sim_interface.h @@ -24,49 +24,122 @@ #define NSC_VERSION 0x000500 +/** + * \ingroup nsctcp + * \brief Struct interface to NSC stack + */ struct INetStack { virtual ~INetStack() {} + /** + * \brief Initialize the stack + * \param hz timer_interrupt frequency + */ virtual void init (int hz) = 0; + /** + * \brief Deliver complete packet to the NSC network stack + * \param if_id interface ID + * \param data data + * \param datalen data length + */ virtual void if_receive_packet (int if_id, const void *data, int datalen) = 0; - + /** + * \brief Send complete packet to the NSC network stack + * \param data data + * \param datalen data length + */ virtual void if_send_packet (const void *data, int datalen) = 0; + /** + * \brief Signal the completion of send procedure to the NSC network stack + * \param if_id interface ID + */ virtual void if_send_finish (int if_id) = 0; + /** + * \brief Attach an interface to the stack + * \param addr address + * \param mask network mask + * \param mtu MTU + */ virtual void if_attach (const char *addr, const char *mask, int mtu) = 0; + /** + * \brief Add a default gateway to the interface + * \param addr gateway address + */ virtual void add_default_gateway (const char *addr) = 0; - /** Purely for debugging/diagnostic purposes. This returns the internal id - * of the stack instance. + /** + * \brief Returns the internal id of the stack instance. + * + * Purely for debugging/diagnostic purposes. + * \return internal stack id */ virtual int get_id () = 0; - /** Should return a short one-word name of the stack. Eg. Linux 2.4.x -> + /** + * \brief Return a short one-word name of the stack + * + * Should return a short one-word name of the stack. Eg. Linux 2.4.x -> * linux24, FreeBSD 5.x -> freebsd5. This can be used to identify output - * from a stack, for example a packet trace file. */ + * from a stack, for example a packet trace file. + * \return short one-word name of the stack + */ virtual const char *get_name () = 0; - /** This is used so the simulator can call the stack timer_interrupt function + /** + * \brief Get the timer_interrupt frequency + * + * This is used so the simulator can call the stack timer_interrupt function * the correct amount of times per second. For example, lwip has a hz of 10, * which it returns here to say that it's timer_interrupt should be called * 10 times a second. FreeBSD uses 100, as does Linux 2.4, while Linux 2.6 * uses 1000. (This is often configurable in the kernel in question, also.) + * + * \return frequency */ virtual int get_hz () = 0; + /** + * \brief The stack timer_interrupt function + */ virtual void timer_interrupt () = 0; + + /** + * \brief Increment the time ticks + */ virtual void increment_ticks () = 0; + /** + * \brief Set the buffer size + */ virtual void buffer_size (int size) = 0; + /** + * \brief Create a new UDP socket + */ virtual struct INetDatagramSocket *new_udp_socket () { return NULL; } + /** + * \brief Create a new TCP socket + */ virtual struct INetStreamSocket *new_tcp_socket () { return NULL; } + /** + * \brief Create a new SCTP socket + */ virtual struct INetStreamSocket *new_sctp_socket () { return NULL; } // The following I've made optional to implement for now. Eases // integration of new features. + /** + * \brief use sysctl to modify system parameters + * \param sysctl_name name of the parameter to modify + * \param oldval old value + * \param oldlenp old value length + * \param newval new value + * \param newlen new value length + * \returns + */ virtual int sysctl (const char *sysctl_name, void *oldval, size_t *oldlenp, void *newval, size_t newlen) { @@ -77,6 +150,12 @@ // to convert the string-value to something that the stack can handle. // The idea here is that this is a front-end to the sysctl(2) call, // much like the sysctl(8) program. + /** + * \brief Set system parameters using sysctl + * \param name name of the parameter to modify + * \param value new value + * \returns + */ virtual int sysctl_set (const char *name, const char *value) { return -1; @@ -85,45 +164,81 @@ // same as above, cradle code is expected to convert the sysctl value // into a string. // returns length of the string in value, i.e. retval > len: 'output truncated'. + /** + * \brief Get system parameters using sysctl + * \param name name of the parameter to modify + * \param value value + * \param len value length + * \returns length of the string in value, i.e. retval > len: 'output truncated'. + */ virtual int sysctl_get (const char *name, char *value, size_t len) { return -1; } - // this tells the cradle code to put the name of sysctl number 'idx' - // into name[]. - // The idea is that this can be used to get a list of all available sysctls: - // char buf[256] - // for (i=0; sysctl_getnum(i, buf, sizeof(buf)) > 0 ;i++) - // puts(buf); - // returns -1 if idx is out of range and the length of the sysctl name otherwise. + /** + * \brief Tell the cradle code to put the name of sysctl number 'idx' into name[]. + * + * The idea is that this can be used to get a list of all available sysctls: + * \verbatim + char buf[256] + for (i=0; sysctl_getnum(i, buf, sizeof(buf)) > 0 ;i++) + puts(buf); + \endverbatim + * + * \param idx index + * \param name sysctl name + * \param len sysctl length + * \returns -1 if idx is out of range and the length of the sysctl name otherwise. + */ virtual int sysctl_getnum (size_t idx, char *name, size_t len) { return -1; } + /** + * \brief Show the NSC configuration + */ virtual void show_config () { ; } - /* Optional functions used to get and set variables for this stack */ + /** + * \brief Optional function to get variables for this stack + * \param var the variable + * \param result the result + * \param result_len result length + * \returns true on success + */ virtual bool get_var (const char *var, char *result, int result_len) { return false; } + /** + * \brief Optional function to set variables for this stack + * \param var the variable + * \param val the new value + * \returns true on success + */ virtual bool set_var (const char *var, const char *val) { return false; } - /** The level of debugging or diagnostic information to print out. This - * normally means kernel messages printed out during initialisation but - * may also include extra debugging messages that are part of NSC. */ + /** + * \brief Set the level of debugging or diagnostic information to print out. + * + * This normally means kernel messages printed out during initialisation but + * may also include extra debugging messages that are part of NSC. + * + * \param level debugging/diagnostic level + */ virtual void set_diagnostic (int level) {} - /** Simple interface to support sending any textual command to a stack + /** + * \brief Simple interface to support sending any textual command to a stack * * @returns 0 on success */ @@ -133,62 +248,173 @@ } }; +/** + * \ingroup nsctcp + * \brief Struct interface to NSC Stream (i.e., TCP) Sockets + */ struct INetStreamSocket { virtual ~INetStreamSocket() {} + /** + * \brief Connect to a remote peer + */ virtual void connect (const char *, int) = 0; + /** + * \brief Disconnect from a remote peer + */ virtual void disconnect () = 0; + /** + * \brief Put the socket in Listening state on a port + */ virtual void listen (int) = 0; + /** + * \brief Accept an incoming connection + */ virtual int accept (INetStreamSocket **) = 0; + /** + * \brief Send some data + * \param data the data + * \param datalen data length + * \return the number of data sent or -1 on error + */ virtual int send_data (const void *data, int datalen) = 0; + /** + * \brief Read some data + * \param buf the buffer to store the data + * \param buflen buffer length + * \return the number of data read or -1 on error + */ virtual int read_data (void *buf, int *buflen) = 0; - /* We need to pass the option name in as a string here. The reason for + /** + * \brief Set the socket options + * + * We need to pass the option name in as a string here. The reason for * this is that different operating systems you compile on will have - * different numbers defined for the constants SO_SNDBUF and so on. */ + * different numbers defined for the constants SO_SNDBUF and so on. + * + * \param optname name of the option + * \param val option value + * \param valsize size of the option value + * \returns + */ virtual int setsockopt (char *optname, void *val, size_t valsize) = 0; + /** + * \brief Print the socket state + */ virtual void print_state (FILE *) = 0; + /** + * \brief Check the connection state + * \returns true if socket is in connected state + */ virtual bool is_connected () = 0; + /** + * \brief Check the listening state + * \returns true if socket is in listening state + */ virtual bool is_listening () = 0; - + /** + * \brief Get the peer name + * + * \note not implemented + * + * \param sa sockaddr structure to fill + * \param salen sockaddr structure length + * \returns -1 on error (always returns -1) + */ virtual int getpeername (struct sockaddr *sa, size_t *salen) { return -1; } + /** + * \brief Get the socket local name + * + * \note not implemented + * + * \param sa sockaddr structure to fill + * \param salen sockaddr structure length + * \returns -1 on error (always returns -1) + */ virtual int getsockname (struct sockaddr *sa, size_t *salen) { return -1; } - /* Optional functions used to get and set variables for this TCP - * connection. */ + /** + * \brief Optional function used to get variables for this TCP connection. + * + * \note not implemented + * + * \param var variable requested + * \param result result result + * \param result_len result length + * \return always false + */ virtual bool get_var (const char *var, char *result, int result_len) { return false; } - + /** + * \brief Optional function used to set variables for this TCP connection. + * + * \note not implemented + * + * \param var variable to set + * \param val value to set + * \return always false + */ virtual bool set_var (const char *var, const char *val) { return false; } }; +/** + * \ingroup nsctcp + * \brief Struct interface to NSC Datagram (i.e., UDP) Sockets + */ struct INetDatagramSocket { virtual ~INetDatagramSocket() {} + /** + * \brief Set the destination address and port + */ virtual void set_destination (const char *, int) = 0; + /** + * \brief Send a datagram + * \param data the data + * \param datalen data length + */ virtual void send_data (const void *data, int datalen) = 0; }; + +/** + * \ingroup nsctcp + * \brief Struct interface to NSC send capabilities + */ struct ISendCallback { virtual ~ISendCallback() {} + /** + * \brief Invoked by NSCs 'ethernet driver' to re-inject a packet into ns-3. + */ virtual void send_callback (const void *data, int datalen) = 0; }; +/** + * \ingroup nsctcp + * \brief Struct interface to NSC soft interrupt capabilities + */ struct IInterruptCallback { virtual ~IInterruptCallback() {} + /** + * \brief Called by the NSC stack whenever something of interest has happened + */ virtual void wakeup () = 0; + /** + * \brief Get the actual time + */ virtual void gettime (unsigned int *, unsigned int *) = 0; }; diff --git a/src/internet/model/tcp-header.h b/src/internet/model/tcp-header.h --- a/src/internet/model/tcp-header.h +++ b/src/internet/model/tcp-header.h @@ -175,9 +175,16 @@ Address destination, uint8_t protocol); + /** + * \brief TCP flag field values + */ typedef enum { NONE = 0, FIN = 1, SYN = 2, RST = 4, PSH = 8, ACK = 16, URG = 32, ECE = 64, CWR = 128} Flags_t; + /** + * \brief Get the type ID. + * \return the object TypeId + */ static TypeId GetTypeId (void); virtual TypeId GetInstanceTypeId (void) const; virtual void Print (std::ostream &os) const; @@ -192,22 +199,27 @@ bool IsChecksumOk (void) const; private: + /** + * \brief Calculate the header checksum + * \param size packet size + * \returns the checksum + */ uint16_t CalculateHeaderChecksum (uint16_t size) const; - uint16_t m_sourcePort; - uint16_t m_destinationPort; - SequenceNumber32 m_sequenceNumber; - SequenceNumber32 m_ackNumber; - uint8_t m_length; // really a uint4_t - uint8_t m_flags; // really a uint6_t - uint16_t m_windowSize; - uint16_t m_urgentPointer; + uint16_t m_sourcePort; //!< Source port + uint16_t m_destinationPort; //!< Destination port + SequenceNumber32 m_sequenceNumber; //!< Sequence number + SequenceNumber32 m_ackNumber; //!< ACK number + uint8_t m_length; //!< Length (really a uint4_t) + uint8_t m_flags; //!< Flags (really a uint6_t) + uint16_t m_windowSize; //!< Window size + uint16_t m_urgentPointer; //!< Urgent pointer - Address m_source; - Address m_destination; - uint8_t m_protocol; + Address m_source; //!< Source IP address + Address m_destination; //!< Destination IP address + uint8_t m_protocol; //!< Protocol number - bool m_calcChecksum; - bool m_goodChecksum; + bool m_calcChecksum; //!< Flag to calculate checksum + bool m_goodChecksum; //!< Flag to indicate that checksum is correct }; } // namespace ns3 diff --git a/src/internet/model/tcp-l4-protocol.h b/src/internet/model/tcp-l4-protocol.h --- a/src/internet/model/tcp-l4-protocol.h +++ b/src/internet/model/tcp-l4-protocol.h @@ -55,43 +55,123 @@ class TcpL4Protocol : public IpL4Protocol { public: + /** + * \brief Get the type ID. + * \return the object TypeId + */ static TypeId GetTypeId (void); - static const uint8_t PROT_NUMBER; - /** - * \brief Constructor - */ + static const uint8_t PROT_NUMBER; //!< protocol number (0x6) + TcpL4Protocol (); virtual ~TcpL4Protocol (); + /** + * Set node associated with this stack + * \param node the node + */ void SetNode (Ptr node); virtual int GetProtocolNumber (void) const; /** + * \brief Create a TCP socket * \return A smart Socket pointer to a TcpSocket allocated by this instance * of the TCP protocol */ Ptr CreateSocket (void); + /** + * \brief Create a TCP socket + * \return A smart Socket pointer to a TcpSocket allocated by this instance + * of the TCP protocol + * + * \warning using a socketTypeId other than TCP is a bad idea. + * + * \param socketTypeId the socket TypeId + */ Ptr CreateSocket (TypeId socketTypeId); + /** + * \brief Allocate an IPv4 Endpoint + * \return the Endpoint + */ Ipv4EndPoint *Allocate (void); + /** + * \brief Allocate an IPv4 Endpoint + * \param address address to use + * \return the Endpoint + */ Ipv4EndPoint *Allocate (Ipv4Address address); + /** + * \brief Allocate an IPv4 Endpoint + * \param port port to use + * \return the Endpoint + */ Ipv4EndPoint *Allocate (uint16_t port); + /** + * \brief Allocate an IPv4 Endpoint + * \param address address to use + * \param port port to use + * \return the Endpoint + */ Ipv4EndPoint *Allocate (Ipv4Address address, uint16_t port); + /** + * \brief Allocate an IPv4 Endpoint + * \param localAddress local address to use + * \param localPort local port to use + * \param peerAddress remote address to use + * \param peerPort remote port to use + * \return the Endpoint + */ Ipv4EndPoint *Allocate (Ipv4Address localAddress, uint16_t localPort, Ipv4Address peerAddress, uint16_t peerPort); + /** + * \brief Allocate an IPv6 Endpoint + * \return the Endpoint + */ Ipv6EndPoint *Allocate6 (void); + /** + * \brief Allocate an IPv6 Endpoint + * \param address address to use + * \return the Endpoint + */ Ipv6EndPoint *Allocate6 (Ipv6Address address); + /** + * \brief Allocate an IPv6 Endpoint + * \param port port to use + * \return the Endpoint + */ Ipv6EndPoint *Allocate6 (uint16_t port); + /** + * \brief Allocate an IPv6 Endpoint + * \param address address to use + * \param port port to use + * \return the Endpoint + */ Ipv6EndPoint *Allocate6 (Ipv6Address address, uint16_t port); + /** + * \brief Allocate an IPv6 Endpoint + * \param localAddress local address to use + * \param localPort local port to use + * \param peerAddress remote address to use + * \param peerPort remote port to use + * \return the Endpoint + */ Ipv6EndPoint *Allocate6 (Ipv6Address localAddress, uint16_t localPort, Ipv6Address peerAddress, uint16_t peerPort); + /** + * \brief Remove an IPv4 Endpoint. + * \param endPoint the end point to remove + */ void DeAllocate (Ipv4EndPoint *endPoint); + /** + * \brief Remove an IPv6 Endpoint. + * \param endPoint the end point to remove + */ void DeAllocate (Ipv6EndPoint *endPoint); /** - * \brief Send a packet via TCP + * \brief Send a packet via TCP (IPv4) * \param packet The packet to send * \param saddr The source Ipv4Address * \param daddr The destination Ipv4Address @@ -102,33 +182,27 @@ void Send (Ptr packet, Ipv4Address saddr, Ipv4Address daddr, uint16_t sport, uint16_t dport, Ptr oif = 0); + /** + * \brief Send a packet via TCP (IPv6) + * \param packet The packet to send + * \param saddr The source Ipv4Address + * \param daddr The destination Ipv4Address + * \param sport The source port number + * \param dport The destination port number + * \param oif The output interface bound. Defaults to null (unspecified). + */ void Send (Ptr packet, Ipv6Address saddr, Ipv6Address daddr, uint16_t sport, uint16_t dport, Ptr oif = 0); - /** - * \brief Receive a packet up the protocol stack - * \param p The Packet to dump the contents into - * \param header IPv4 Header information - * \param incomingInterface The Ipv4Interface it was received on - */ + + virtual enum IpL4Protocol::RxStatus Receive (Ptr p, - Ipv4Header const &header, - Ptr incomingInterface); + Ipv4Header const &header, + Ptr incomingInterface); virtual enum IpL4Protocol::RxStatus Receive (Ptr p, - Ipv6Header const &header, - Ptr interface); + Ipv6Header const &header, + Ptr incomingInterface); - /** - * \brief Receive an ICMP packet - * \param icmpSource The IP address of the source of the packet. - * \param icmpTtl The time to live from the IP header - * \param icmpType The type of the message from the ICMP header - * \param icmpCode The message code from the ICMP header - * \param icmpInfo 32-bit integer carrying informational value of varying semantics. - * \param payloadSource The IP source address from the IP header of the packet - * \param payloadDestination The IP destination address from the IP header of the packet - * \param payload Payload of the ICMP packet - */ virtual void ReceiveIcmp (Ipv4Address icmpSource, uint8_t icmpTtl, uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo, Ipv4Address payloadSource,Ipv4Address payloadDestination, @@ -153,23 +227,35 @@ */ virtual void NotifyNewAggregate (); private: - Ptr m_node; - Ipv4EndPointDemux *m_endPoints; - Ipv6EndPointDemux *m_endPoints6; - TypeId m_rttTypeId; - TypeId m_socketTypeId; + Ptr m_node; //!< the node this stack is associated with + Ipv4EndPointDemux *m_endPoints; //!< A list of IPv4 end points. + Ipv6EndPointDemux *m_endPoints6; //!< A list of IPv6 end points. + TypeId m_rttTypeId; //!< The RTT Estimator TypeId + TypeId m_socketTypeId; //!< The socket TypeId private: friend class TcpSocketBase; void SendPacket (Ptr, const TcpHeader &, Ipv4Address, Ipv4Address, Ptr oif = 0); void SendPacket (Ptr, const TcpHeader &, Ipv6Address, Ipv6Address, Ptr oif = 0); - TcpL4Protocol (const TcpL4Protocol &o); - TcpL4Protocol &operator = (const TcpL4Protocol &o); - std::vector > m_sockets; - IpL4Protocol::DownTargetCallback m_downTarget; - IpL4Protocol::DownTargetCallback6 m_downTarget6; + /** + * \brief Copy constructor + * + * Defined and not implemented to avoid misuse + */ + TcpL4Protocol (const TcpL4Protocol &); + /** + * \brief Copy constructor + * + * Defined and not implemented to avoid misuse + * \returns + */ + TcpL4Protocol &operator = (const TcpL4Protocol &); + + std::vector > m_sockets; //!< list of sockets + IpL4Protocol::DownTargetCallback m_downTarget; //!< Callback to send packets over IPv4 + IpL4Protocol::DownTargetCallback6 m_downTarget6; //!< Callback to send packets over IPv6 }; } // namespace ns3 diff --git a/src/internet/model/tcp-newreno.cc b/src/internet/model/tcp-newreno.cc --- a/src/internet/model/tcp-newreno.cc +++ b/src/internet/model/tcp-newreno.cc @@ -81,7 +81,7 @@ { } -/** We initialize m_cWnd from this function, after attributes initialized */ +/* We initialize m_cWnd from this function, after attributes initialized */ int TcpNewReno::Listen (void) { @@ -90,7 +90,7 @@ return TcpSocketBase::Listen (); } -/** We initialize m_cWnd from this function, after attributes initialized */ +/* We initialize m_cWnd from this function, after attributes initialized */ int TcpNewReno::Connect (const Address & address) { @@ -99,7 +99,7 @@ return TcpSocketBase::Connect (address); } -/** Limit the size of in-flight data by cwnd and receiver's rxwin */ +/* Limit the size of in-flight data by cwnd and receiver's rxwin */ uint32_t TcpNewReno::Window (void) { @@ -113,7 +113,7 @@ return CopyObject (this); } -/** New ACK (up to seqnum seq) received. Increase cwnd and call TcpSocketBase::NewAck() */ +/* New ACK (up to seqnum seq) received. Increase cwnd and call TcpSocketBase::NewAck() */ void TcpNewReno::NewAck (const SequenceNumber32& seq) { @@ -158,7 +158,7 @@ TcpSocketBase::NewAck (seq); } -/** Cut cwnd and enter fast recovery mode upon triple dupack */ +/* Cut cwnd and enter fast recovery mode upon triple dupack */ void TcpNewReno::DupAck (const TcpHeader& t, uint32_t count) { @@ -187,7 +187,7 @@ }; } -/** Retransmit timeout */ +/* Retransmit timeout */ void TcpNewReno::Retransmit (void) { diff --git a/src/internet/model/tcp-newreno.h b/src/internet/model/tcp-newreno.h --- a/src/internet/model/tcp-newreno.h +++ b/src/internet/model/tcp-newreno.h @@ -36,11 +36,19 @@ class TcpNewReno : public TcpSocketBase { public: + /** + * \brief Get the type ID. + * \return the object TypeId + */ static TypeId GetTypeId (void); /** * Create an unbound tcp socket. */ TcpNewReno (void); + /** + * \brief Copy constructor + * \param sock the object to copy + */ TcpNewReno (const TcpNewReno& sock); virtual ~TcpNewReno (void); @@ -62,16 +70,19 @@ virtual void SetInitialCwnd (uint32_t cwnd); virtual uint32_t GetInitialCwnd (void) const; private: - void InitializeCwnd (void); // set m_cWnd when connection starts + /** + * \brief Set the congestion window when connection starts + */ + void InitializeCwnd (void); protected: - TracedValue m_cWnd; //< Congestion window - uint32_t m_ssThresh; //< Slow Start Threshold - uint32_t m_initialCWnd; //< Initial cWnd value - SequenceNumber32 m_recover; //< Previous highest Tx seqnum for fast recovery - uint32_t m_retxThresh; //< Fast Retransmit threshold - bool m_inFastRec; //< currently in fast recovery - bool m_limitedTx; //< perform limited transmit + TracedValue m_cWnd; //!< Congestion window + uint32_t m_ssThresh; //!< Slow Start Threshold + uint32_t m_initialCWnd; //!< Initial cWnd value + SequenceNumber32 m_recover; //!< Previous highest Tx seqnum for fast recovery + uint32_t m_retxThresh; //!< Fast Retransmit threshold + bool m_inFastRec; //!< currently in fast recovery + bool m_limitedTx; //!< perform limited transmit }; } // namespace ns3 diff --git a/src/internet/model/tcp-reno.cc b/src/internet/model/tcp-reno.cc --- a/src/internet/model/tcp-reno.cc +++ b/src/internet/model/tcp-reno.cc @@ -73,7 +73,7 @@ { } -/** We initialize m_cWnd from this function, after attributes initialized */ +/* We initialize m_cWnd from this function, after attributes initialized */ int TcpReno::Listen (void) { @@ -82,7 +82,7 @@ return TcpSocketBase::Listen (); } -/** We initialize m_cWnd from this function, after attributes initialized */ +/* We initialize m_cWnd from this function, after attributes initialized */ int TcpReno::Connect (const Address & address) { @@ -91,7 +91,7 @@ return TcpSocketBase::Connect (address); } -/** Limit the size of in-flight data by cwnd and receiver's rxwin */ +/* Limit the size of in-flight data by cwnd and receiver's rxwin */ uint32_t TcpReno::Window (void) { @@ -105,7 +105,7 @@ return CopyObject (this); } -/** New ACK (up to seqnum seq) received. Increase cwnd and call TcpSocketBase::NewAck() */ +/* New ACK (up to seqnum seq) received. Increase cwnd and call TcpSocketBase::NewAck() */ void TcpReno::NewAck (const SequenceNumber32& seq) { diff --git a/src/internet/model/tcp-reno.h b/src/internet/model/tcp-reno.h --- a/src/internet/model/tcp-reno.h +++ b/src/internet/model/tcp-reno.h @@ -38,11 +38,19 @@ class TcpReno : public TcpSocketBase { public: + /** + * \brief Get the type ID. + * \return the object TypeId + */ static TypeId GetTypeId (void); /** * Create an unbound tcp socket. */ TcpReno (void); + /** + * \brief Copy constructor + * \param sock the object to copy + */ TcpReno (const TcpReno& sock); virtual ~TcpReno (void); @@ -64,14 +72,17 @@ virtual void SetInitialCwnd (uint32_t cwnd); virtual uint32_t GetInitialCwnd (void) const; private: - void InitializeCwnd (void); // set m_cWnd when connection starts + /** + * \brief Set the congestion window when connection starts + */ + void InitializeCwnd (void); protected: - TracedValue m_cWnd; //< Congestion window - uint32_t m_ssThresh; //< Slow Start Threshold - uint32_t m_initialCWnd; //< Initial cWnd value - uint32_t m_retxThresh; //< Fast Retransmit threshold - bool m_inFastRec; //< currently in fast recovery + TracedValue m_cWnd; //!< Congestion window + uint32_t m_ssThresh; //!< Slow Start Threshold + uint32_t m_initialCWnd; //!< Initial cWnd value + uint32_t m_retxThresh; //!< Fast Retransmit threshold + bool m_inFastRec; //!< currently in fast recovery }; } // namespace ns3 diff --git a/src/internet/model/tcp-rfc793.h b/src/internet/model/tcp-rfc793.h --- a/src/internet/model/tcp-rfc793.h +++ b/src/internet/model/tcp-rfc793.h @@ -39,11 +39,19 @@ class TcpRfc793 : public TcpSocketBase { public: + /** + * \brief Get the type ID. + * \return the object TypeId + */ static TypeId GetTypeId (void); /** * Create an unbound tcp socket. */ TcpRfc793 (void); + /** + * \brief Copy constructor + * \param sock the object to copy + */ TcpRfc793 (const TcpRfc793& sock); virtual ~TcpRfc793 (void); diff --git a/src/internet/model/tcp-rx-buffer.h b/src/internet/model/tcp-rx-buffer.h --- a/src/internet/model/tcp-rx-buffer.h +++ b/src/internet/model/tcp-rx-buffer.h @@ -40,20 +40,67 @@ class TcpRxBuffer : public Object { public: + /** + * \brief Get the type ID. + * \return the object TypeId + */ static TypeId GetTypeId (void); + /** + * \brief Constructor + * \param n initial Sequence number to be received + */ TcpRxBuffer (uint32_t n = 0); virtual ~TcpRxBuffer (); // Accessors + /** + * \brief Get Next Rx Sequence number + * \returns Next Rx Sequence number + */ SequenceNumber32 NextRxSequence (void) const; + /** + * \brief Get the lowest sequence number that this TcpRxBuffer cannot accept + * \returns the lowest sequence number that this TcpRxBuffer cannot accept + */ SequenceNumber32 MaxRxSequence (void) const; + /** + * \brief Increment the Next Sequence number + */ void IncNextRxSequence (void); + /** + * \brief Set the Next Sequence number + * \param s the Sequence number + */ void SetNextRxSequence (const SequenceNumber32& s); + /** + * \brief Set the FIN Sequence number (i.e., the one closing the connection) + * \param s the Sequence number + */ void SetFinSequence (const SequenceNumber32& s); + /** + * \brief Get the Maximum buffer size + * \returns the Maximum buffer size + */ uint32_t MaxBufferSize (void) const; + /** + * \brief Set the Maximum buffer size + * \param s the Maximum buffer size + */ void SetMaxBufferSize (uint32_t s); + /** + * \brief Get the actual buffer occupancy + * \returns buffer occupancy (in bytes) + */ uint32_t Size (void) const; + /** + * \brief Get the actual number of bytes available to be read + * \returns size of available data (in bytes) + */ uint32_t Available () const; + /** + * \brief Check if the buffer did receive all the data (and the connection is closed) + * \returns true if all data have been received + */ bool Finished (void); /** @@ -63,6 +110,8 @@ * removing data from the buffer that overlaps the tail of the inputted * packet * + * \param p packet + * \param tcph packet's TCP header * \return True when success, false otherwise. */ bool Add (Ptr p, TcpHeader const& tcph); @@ -70,18 +119,21 @@ /** * Extract data from the head of the buffer as indicated by nextRxSeq. * The extracted data is going to be forwarded to the application. + * + * \param maxSize maximum number of bytes to extract + * \returns a packet */ Ptr Extract (uint32_t maxSize); public: + /// container for data stored in the buffer typedef std::map >::iterator BufIterator; - TracedValue m_nextRxSeq; //< Seqnum of the first missing byte in data (RCV.NXT) - SequenceNumber32 m_finSeq; //< Seqnum of the FIN packet - bool m_gotFin; //< Did I received FIN packet? - uint32_t m_size; //< Number of total data bytes in the buffer, not necessarily contiguous - uint32_t m_maxBuffer; //< Upper bound of the number of data bytes in buffer (RCV.WND) - uint32_t m_availBytes; //< Number of bytes available to read, i.e. contiguous block at head - std::map > m_data; - //< Corresponding data (may be null) + TracedValue m_nextRxSeq; //!< Seqnum of the first missing byte in data (RCV.NXT) + SequenceNumber32 m_finSeq; //!< Seqnum of the FIN packet + bool m_gotFin; //!< Did I received FIN packet? + uint32_t m_size; //!< Number of total data bytes in the buffer, not necessarily contiguous + uint32_t m_maxBuffer; //!< Upper bound of the number of data bytes in buffer (RCV.WND) + uint32_t m_availBytes; //!< Number of bytes available to read, i.e. contiguous block at head + std::map > m_data; //!< Corresponding data (may be null) }; } //namepsace ns3 diff --git a/src/internet/model/tcp-socket-base.h b/src/internet/model/tcp-socket-base.h --- a/src/internet/model/tcp-socket-base.h +++ b/src/internet/model/tcp-socket-base.h @@ -209,7 +209,7 @@ * \brief Called by the L3 protocol when it received a packet to pass on to TCP. * * \param packet the incoming packet - * \param header the apcket's IPv4 header + * \param header the packet's IPv4 header * \param port the incoming port * \param incomingInterface the incoming interface */ @@ -219,7 +219,7 @@ * \brief Called by the L3 protocol when it received a packet to pass on to TCP. * * \param packet the incoming packet - * \param header the apcket's IPv6 header + * \param header the packet's IPv6 header * \param port the incoming port */ void ForwardUp6 (Ptr packet, Ipv6Header header, uint16_t port); @@ -228,7 +228,7 @@ * \brief Called by TcpSocketBase::ForwardUp(). * * \param packet the incoming packet - * \param header the apcket's IPv4 header + * \param header the packet's IPv4 header * \param port the incoming port * \param incomingInterface the incoming interface */ @@ -238,7 +238,7 @@ * \brief Called by TcpSocketBase::ForwardUp6(). * * \param packet the incoming packet - * \param header the apcket's IPv6 header + * \param header the packet's IPv6 header * \param port the incoming port */ virtual void DoForwardUp (Ptr packet, Ipv6Header header, uint16_t port); diff --git a/src/internet/model/tcp-tahoe.cc b/src/internet/model/tcp-tahoe.cc --- a/src/internet/model/tcp-tahoe.cc +++ b/src/internet/model/tcp-tahoe.cc @@ -72,7 +72,7 @@ { } -/** We initialize m_cWnd from this function, after attributes initialized */ +/* We initialize m_cWnd from this function, after attributes initialized */ int TcpTahoe::Listen (void) { @@ -81,7 +81,7 @@ return TcpSocketBase::Listen (); } -/** We initialize m_cWnd from this function, after attributes initialized */ +/* We initialize m_cWnd from this function, after attributes initialized */ int TcpTahoe::Connect (const Address & address) { @@ -90,7 +90,7 @@ return TcpSocketBase::Connect (address); } -/** Limit the size of in-flight data by cwnd and receiver's rxwin */ +/* Limit the size of in-flight data by cwnd and receiver's rxwin */ uint32_t TcpTahoe::Window (void) { @@ -104,7 +104,7 @@ return CopyObject (this); } -/** New ACK (up to seqnum seq) received. Increase cwnd and call TcpSocketBase::NewAck() */ +/* New ACK (up to seqnum seq) received. Increase cwnd and call TcpSocketBase::NewAck() */ void TcpTahoe::NewAck (SequenceNumber32 const& seq) { @@ -128,7 +128,7 @@ TcpSocketBase::NewAck (seq); // Complete newAck processing } -/** Cut down ssthresh upon triple dupack */ +/* Cut down ssthresh upon triple dupack */ void TcpTahoe::DupAck (const TcpHeader& t, uint32_t count) { @@ -148,7 +148,7 @@ } } -/** Retransmit timeout */ +/* Retransmit timeout */ void TcpTahoe::Retransmit (void) { NS_LOG_FUNCTION (this); diff --git a/src/internet/model/tcp-tahoe.h b/src/internet/model/tcp-tahoe.h --- a/src/internet/model/tcp-tahoe.h +++ b/src/internet/model/tcp-tahoe.h @@ -42,11 +42,19 @@ class TcpTahoe : public TcpSocketBase { public: + /** + * \brief Get the type ID. + * \return the object TypeId + */ static TypeId GetTypeId (void); /** * Create an unbound tcp socket. */ TcpTahoe (void); + /** + * \brief Copy constructor + * \param sock the object to copy + */ TcpTahoe (const TcpTahoe& sock); virtual ~TcpTahoe (void); @@ -68,13 +76,16 @@ virtual void SetInitialCwnd (uint32_t cwnd); virtual uint32_t GetInitialCwnd (void) const; private: - void InitializeCwnd (void); // set m_cWnd when connection starts + /** + * \brief Set the congestion window when connection starts + */ + void InitializeCwnd (void); protected: - TracedValue m_cWnd; //< Congestion window - uint32_t m_ssThresh; //< Slow Start Threshold - uint32_t m_initialCWnd; //< Initial cWnd value - uint32_t m_retxThresh; //< Fast Retransmit threshold + TracedValue m_cWnd; //!< Congestion window + uint32_t m_ssThresh; //!< Slow Start Threshold + uint32_t m_initialCWnd; //!< Initial cWnd value + uint32_t m_retxThresh; //!< Fast Retransmit threshold }; } // namespace ns3 diff --git a/src/internet/model/tcp-tx-buffer.h b/src/internet/model/tcp-tx-buffer.h --- a/src/internet/model/tcp-tx-buffer.h +++ b/src/internet/model/tcp-tx-buffer.h @@ -40,7 +40,15 @@ class TcpTxBuffer : public Object { public: + /** + * \brief Get the type ID. + * \return the object TypeId + */ static TypeId GetTypeId (void); + /** + * \brief Constructor + * \param n initial Sequence number to be transmitted + */ TcpTxBuffer (uint32_t n = 0); virtual ~TcpTxBuffer (void); @@ -48,31 +56,37 @@ /** * Returns the first byte's sequence number + * \returns the first byte's sequence number */ SequenceNumber32 HeadSequence (void) const; /** * Returns the last byte's sequence number + 1 + * \returns the last byte's sequence number + 1 */ SequenceNumber32 TailSequence (void) const; /** * Returns total number of bytes in this Tx buffer + * \returns total number of bytes in this Tx buffer */ uint32_t Size (void) const; /** * Returns the Tx window size + * \returns the Tx window size (in bytes) */ uint32_t MaxBufferSize (void) const; /** * Set the Tx window size + * \param n Tx window size (in bytes) */ void SetMaxBufferSize (uint32_t n); /** * Returns the available capacity in this Tx window + * \returns available capacity in this Tx window */ uint32_t Available (void) const; @@ -86,17 +100,23 @@ /** * Returns the number of bytes from the buffer in the range [seq, tailSequence) + * \param seq initial sequence number + * \returns the number of bytes from the buffer in the range */ uint32_t SizeFromSequence (const SequenceNumber32& seq) const; /** * Copy data of size numBytes into a packet, data from the range [seq, seq+numBytes) + * \param numBytes number of bytes to copy + * \param seq start sequence number to extract + * \returns a packet */ Ptr CopyFromSequence (uint32_t numBytes, const SequenceNumber32& seq); /** * Set the m_firstByteSeq to seq. Supposed to be called only when the * connection is just set up and we did not send any data out yet. + * \param seq The sequence number of the head byte */ void SetHeadSequence (const SequenceNumber32& seq); @@ -108,12 +128,13 @@ void DiscardUpTo (const SequenceNumber32& seq); private: + /// container for data stored in the buffer typedef std::list >::iterator BufIterator; - TracedValue m_firstByteSeq; //< Sequence number of the first byte in data (SND.UNA) - uint32_t m_size; //< Number of data bytes - uint32_t m_maxBuffer; //< Max number of data bytes in buffer (SND.WND) - std::list > m_data; //< Corresponding data (may be null) + TracedValue m_firstByteSeq; //!< Sequence number of the first byte in data (SND.UNA) + uint32_t m_size; //!< Number of data bytes + uint32_t m_maxBuffer; //!< Max number of data bytes in buffer (SND.WND) + std::list > m_data; //!< Corresponding data (may be null) }; } // namepsace ns3 diff --git a/src/internet/model/tcp-westwood.h b/src/internet/model/tcp-westwood.h --- a/src/internet/model/tcp-westwood.h +++ b/src/internet/model/tcp-westwood.h @@ -62,18 +62,32 @@ class TcpWestwood : public TcpSocketBase { public: + /** + * \brief Get the type ID. + * \return the object TypeId + */ static TypeId GetTypeId (void); TcpWestwood (void); + /** + * \brief Copy constructor + * \param sock the object to copy + */ TcpWestwood (const TcpWestwood& sock); virtual ~TcpWestwood (void); + /** + * \brief Protocol variant (Westwood or Westwood+) + */ enum ProtocolType { WESTWOOD, WESTWOODPLUS }; + /** + * \brief Filter type (None or Tustin) + */ enum FilterType { NONE, @@ -85,17 +99,11 @@ virtual int Listen (void); protected: - /** - * Limit the size of outstanding data based on the cwnd and the receiver's advertised window - * - * \return the max. possible number of unacked bytes - */ - virtual uint32_t Window (void); - - /** - * Call CopyObject to clone me - */ - virtual Ptr Fork (void); + virtual uint32_t Window (void); // Return the max possible number of unacked bytes + virtual Ptr Fork (void); // Call CopyObject to clone me + virtual void NewAck (SequenceNumber32 const& seq); // Inc cwnd and call NewAck() of parent + virtual void DupAck (const TcpHeader& t, uint32_t count); // Treat 3 dupack as timeout + virtual void Retransmit (void); // Retransmit time out /** * Process the newly received ACK @@ -106,58 +114,17 @@ virtual void ReceivedAck (Ptr packet, const TcpHeader& tcpHeader); /** - * Adjust the cwnd based on the current congestion control phase, - * and then call the TcpSocketBase::NewAck() to complete the processing - * - * \param seq the acknowledgment number - */ - virtual void NewAck (SequenceNumber32 const& seq); - - /** - * Adjust the cwnd using the currently estimated bandwidth, - * retransmit the missing packet, and enter fast recovery if 3 DUPACKs are received - * - * \param header the TCP header of the ACK packet - * \param count the number of DUPACKs - */ - virtual void DupAck (const TcpHeader& header, uint32_t count); - - /** - * Upon an RTO event, adjust the cwnd using the currently estimated bandwidth, - * retransmit the missing packet, and exit fast recovery - */ - virtual void Retransmit (void); - - /** * Estimate the RTT, record the minimum value, * and run a clock on the RTT to trigger Westwood+ bandwidth sampling + * \param header the packet header */ virtual void EstimateRtt (const TcpHeader& header); // Implementing ns3::TcpSocket -- Attribute get/set - /** - * \param size the segment size to be used in a connection - */ - virtual void SetSegSize (uint32_t size); - - /** - * \param the slow-start threshold - */ - virtual void SetSSThresh (uint32_t threshold); - - /** - * \return the slow-start threshold - */ + virtual void SetSegSize (uint32_t size); + virtual void SetSSThresh (uint32_t threshold); virtual uint32_t GetSSThresh (void) const; - - /** - * \param cwnd the initial cwnd - */ - virtual void SetInitialCwnd (uint32_t cwnd); - - /** - * \return the initial cwnd - */ + virtual void SetInitialCwnd (uint32_t cwnd); virtual uint32_t GetInitialCwnd (void) const; private: @@ -196,24 +163,24 @@ void Filtering (void); protected: - TracedValue m_cWnd; //< Congestion window - uint32_t m_ssThresh; //< Slow Start Threshold - uint32_t m_initialCWnd; //< Initial cWnd value - bool m_inFastRec; //< Currently in fast recovery if TRUE + TracedValue m_cWnd; //!< Congestion window + uint32_t m_ssThresh; //!< Slow Start Threshold + uint32_t m_initialCWnd; //!< Initial cWnd value + bool m_inFastRec; //!< Currently in fast recovery if TRUE - TracedValue m_currentBW; //< Current value of the estimated BW - double m_lastSampleBW; //< Last bandwidth sample - double m_lastBW; //< Last bandwidth sample after being filtered - Time m_minRtt; //< Minimum RTT - double m_lastAck; //< The time last ACK was received - SequenceNumber32 m_prevAckNo; //< Previously received ACK number - int m_accountedFor; //< The number of received DUPACKs - enum ProtocolType m_pType; //< 0 for Westwood, 1 for Westwood+ - enum FilterType m_fType; //< 0 for none, 1 for Tustin + TracedValue m_currentBW; //!< Current value of the estimated BW + double m_lastSampleBW; //!< Last bandwidth sample + double m_lastBW; //!< Last bandwidth sample after being filtered + Time m_minRtt; //!< Minimum RTT + double m_lastAck; //!< The time last ACK was received + SequenceNumber32 m_prevAckNo; //!< Previously received ACK number + int m_accountedFor; //!< The number of received DUPACKs + enum ProtocolType m_pType; //!< 0 for Westwood, 1 for Westwood+ + enum FilterType m_fType; //!< 0 for none, 1 for Tustin - int m_ackedSegments; //< The number of segments ACKed between RTTs - bool m_IsCount; //< Start keeping track of m_ackedSegments for Westwood+ if TRUE - EventId m_bwEstimateEvent; //< The BW estimation event for Westwood+ + int m_ackedSegments; //!< The number of segments ACKed between RTTs + bool m_IsCount; //!< Start keeping track of m_ackedSegments for Westwood+ if TRUE + EventId m_bwEstimateEvent; //!< The BW estimation event for Westwood+ }; diff --git a/src/internet/model/udp-header.h b/src/internet/model/udp-header.h --- a/src/internet/model/udp-header.h +++ b/src/internet/model/udp-header.h @@ -114,6 +114,10 @@ Ipv6Address destination, uint8_t protocol); + /** + * \brief Get the type ID. + * \return the object TypeId + */ static TypeId GetTypeId (void); virtual TypeId GetInstanceTypeId (void) const; virtual void Print (std::ostream &os) const; @@ -128,16 +132,21 @@ bool IsChecksumOk (void) const; private: + /** + * \brief Calculate the header checksum + * \param size packet size + * \returns the checksum + */ uint16_t CalculateHeaderChecksum (uint16_t size) const; - uint16_t m_sourcePort; - uint16_t m_destinationPort; - uint16_t m_payloadSize; + uint16_t m_sourcePort; //!< Source port + uint16_t m_destinationPort; //!< Destination port + uint16_t m_payloadSize; //!< Payload size - Address m_source; - Address m_destination; - uint8_t m_protocol; - bool m_calcChecksum; - bool m_goodChecksum; + Address m_source; //!< Source IP address + Address m_destination; //!< Destination IP address + uint8_t m_protocol; //!< Protocol number + bool m_calcChecksum; //!< Flag to calculate checksum + bool m_goodChecksum; //!< Flag to indicate that checksum is correct }; } // namespace ns3 diff --git a/src/internet/model/udp-l4-protocol.h b/src/internet/model/udp-l4-protocol.h --- a/src/internet/model/udp-l4-protocol.h +++ b/src/internet/model/udp-l4-protocol.h @@ -47,12 +47,20 @@ */ class UdpL4Protocol : public IpL4Protocol { public: + /** + * \brief Get the type ID. + * \return the object TypeId + */ static TypeId GetTypeId (void); - static const uint8_t PROT_NUMBER; + static const uint8_t PROT_NUMBER; //!< protocol number (0x11) UdpL4Protocol (); virtual ~UdpL4Protocol (); + /** + * Set node associated with this stack + * \param node the node + */ void SetNode (Ptr node); virtual int GetProtocolNumber (void) const; @@ -63,25 +71,90 @@ */ Ptr CreateSocket (void); + /** + * \brief Allocate an IPv4 Endpoint + * \return the Endpoint + */ Ipv4EndPoint *Allocate (void); + /** + * \brief Allocate an IPv4 Endpoint + * \param address address to use + * \return the Endpoint + */ Ipv4EndPoint *Allocate (Ipv4Address address); + /** + * \brief Allocate an IPv4 Endpoint + * \param port port to use + * \return the Endpoint + */ Ipv4EndPoint *Allocate (uint16_t port); + /** + * \brief Allocate an IPv4 Endpoint + * \param address address to use + * \param port port to use + * \return the Endpoint + */ Ipv4EndPoint *Allocate (Ipv4Address address, uint16_t port); + /** + * \brief Allocate an IPv4 Endpoint + * \param localAddress local address to use + * \param localPort local port to use + * \param peerAddress remote address to use + * \param peerPort remote port to use + * \return the Endpoint + */ Ipv4EndPoint *Allocate (Ipv4Address localAddress, uint16_t localPort, Ipv4Address peerAddress, uint16_t peerPort); + + /** + * \brief Allocate an IPv6 Endpoint + * \return the Endpoint + */ Ipv6EndPoint *Allocate6 (void); + /** + * \brief Allocate an IPv6 Endpoint + * \param address address to use + * \return the Endpoint + */ Ipv6EndPoint *Allocate6 (Ipv6Address address); + /** + * \brief Allocate an IPv6 Endpoint + * \param port port to use + * \return the Endpoint + */ Ipv6EndPoint *Allocate6 (uint16_t port); + /** + * \brief Allocate an IPv6 Endpoint + * \param address address to use + * \param port port to use + * \return the Endpoint + */ Ipv6EndPoint *Allocate6 (Ipv6Address address, uint16_t port); + /** + * \brief Allocate an IPv6 Endpoint + * \param localAddress local address to use + * \param localPort local port to use + * \param peerAddress remote address to use + * \param peerPort remote port to use + * \return the Endpoint + */ Ipv6EndPoint *Allocate6 (Ipv6Address localAddress, uint16_t localPort, - Ipv6Address peerAddress, uint16_t peerPort); + Ipv6Address peerAddress, uint16_t peerPort); + /** + * \brief Remove an IPv4 Endpoint. + * \param endPoint the end point to remove + */ void DeAllocate (Ipv4EndPoint *endPoint); + /** + * \brief Remove an IPv6 Endpoint. + * \param endPoint the end point to remove + */ void DeAllocate (Ipv6EndPoint *endPoint); // called by UdpSocket. /** - * \brief Send a packet via UDP + * \brief Send a packet via UDP (IPv4) * \param packet The packet to send * \param saddr The source Ipv4Address * \param daddr The destination Ipv4Address @@ -91,40 +164,50 @@ void Send (Ptr packet, Ipv4Address saddr, Ipv4Address daddr, uint16_t sport, uint16_t dport); + /** + * \brief Send a packet via UDP (IPv4) + * \param packet The packet to send + * \param saddr The source Ipv4Address + * \param daddr The destination Ipv4Address + * \param sport The source port number + * \param dport The destination port number + * \param route The route + */ void Send (Ptr packet, Ipv4Address saddr, Ipv4Address daddr, uint16_t sport, uint16_t dport, Ptr route); + /** + * \brief Send a packet via UDP (IPv6) + * \param packet The packet to send + * \param saddr The source Ipv4Address + * \param daddr The destination Ipv4Address + * \param sport The source port number + * \param dport The destination port number + */ void Send (Ptr packet, Ipv6Address saddr, Ipv6Address daddr, uint16_t sport, uint16_t dport); + /** + * \brief Send a packet via UDP (IPv6) + * \param packet The packet to send + * \param saddr The source Ipv4Address + * \param daddr The destination Ipv4Address + * \param sport The source port number + * \param dport The destination port number + * \param route The route + */ void Send (Ptr packet, Ipv6Address saddr, Ipv6Address daddr, uint16_t sport, uint16_t dport, Ptr route); - /** - * \brief Receive a packet up the protocol stack - * \param p The Packet to dump the contents into - * \param header IPv4 Header information - * \param interface the interface from which the packet is coming. - */ + // inherited from Ipv4L4Protocol virtual enum IpL4Protocol::RxStatus Receive (Ptr p, - Ipv4Header const &header, - Ptr interface); + Ipv4Header const &header, + Ptr interface); virtual enum IpL4Protocol::RxStatus Receive (Ptr p, - Ipv6Header const &header, - Ptr interface); + Ipv6Header const &header, + Ptr interface); - /** - * \brief Receive an ICMP packet - * \param icmpSource The IP address of the source of the packet. - * \param icmpTtl The time to live from the IP header - * \param icmpType The type of the message from the ICMP header - * \param icmpCode The message code from the ICMP header - * \param icmpInfo 32-bit integer carrying informational value of varying semantics. - * \param payloadSource The IP source address from the IP header of the packet - * \param payloadDestination The IP destination address from the IP header of the packet - * \param payload Payload of the ICMP packet - */ virtual void ReceiveIcmp (Ipv4Address icmpSource, uint8_t icmpTtl, uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo, Ipv4Address payloadSource,Ipv4Address payloadDestination, @@ -149,14 +232,28 @@ */ virtual void NotifyNewAggregate (); private: - Ptr m_node; - Ipv4EndPointDemux *m_endPoints; - Ipv6EndPointDemux *m_endPoints6; - UdpL4Protocol (const UdpL4Protocol &o); - UdpL4Protocol &operator = (const UdpL4Protocol &o); - std::vector > m_sockets; - IpL4Protocol::DownTargetCallback m_downTarget; - IpL4Protocol::DownTargetCallback6 m_downTarget6; + Ptr m_node; //!< the node this stack is associated with + Ipv4EndPointDemux *m_endPoints; //!< A list of IPv4 end points. + Ipv6EndPointDemux *m_endPoints6; //!< A list of IPv6 end points. + + /** + * \brief Copy constructor + * + * Defined and not implemented to avoid misuse + */ + UdpL4Protocol (const UdpL4Protocol &); + /** + * \brief Copy constructor + * + * Defined and not implemented to avoid misuse + * \returns + */ + UdpL4Protocol &operator = (const UdpL4Protocol &); + + std::vector > m_sockets; //!< list of sockets + IpL4Protocol::DownTargetCallback m_downTarget; //!< Callback to send packets over IPv4 + IpL4Protocol::DownTargetCallback6 m_downTarget6; //!< Callback to send packets over IPv6 + }; } // namespace ns3 diff --git a/src/internet/model/udp-socket-factory-impl.h b/src/internet/model/udp-socket-factory-impl.h --- a/src/internet/model/udp-socket-factory-impl.h +++ b/src/internet/model/udp-socket-factory-impl.h @@ -57,6 +57,10 @@ UdpSocketFactoryImpl (); virtual ~UdpSocketFactoryImpl (); + /** + * \brief Set the associated UDP L4 protocol. + * \param udp the UDP L4 protocol + */ void SetUdp (Ptr udp); /** @@ -71,7 +75,7 @@ protected: virtual void DoDispose (void); private: - Ptr m_udp; + Ptr m_udp; //!< the associated UDP L4 protocol }; } // namespace ns3 diff --git a/src/internet/model/udp-socket-factory.h b/src/internet/model/udp-socket-factory.h --- a/src/internet/model/udp-socket-factory.h +++ b/src/internet/model/udp-socket-factory.h @@ -40,6 +40,10 @@ class UdpSocketFactory : public SocketFactory { public: + /** + * \brief Get the type ID. + * \return the object TypeId + */ static TypeId GetTypeId (void); }; diff --git a/src/internet/model/udp-socket-impl.cc b/src/internet/model/udp-socket-impl.cc --- a/src/internet/model/udp-socket-impl.cc +++ b/src/internet/model/udp-socket-impl.cc @@ -45,7 +45,10 @@ NS_OBJECT_ENSURE_REGISTERED (UdpSocketImpl) ; -static const uint32_t MAX_IPV4_UDP_DATAGRAM_SIZE = 65507; +// The correct maximum UDP message size is 65507, as determined by the following formula: +// 0xffff - (sizeof(IP Header) + sizeof(UDP Header)) = 65535-(20+8) = 65507 +// \todo MAX_IPV4_UDP_DATAGRAM_SIZE is correct only for IPv4 +static const uint32_t MAX_IPV4_UDP_DATAGRAM_SIZE = 65507; //!< Maximum UDP datagram size // Add attributes generic to all UdpSockets to base class UdpSocket TypeId @@ -736,9 +739,9 @@ } -// maximum message size for UDP broadcast is limited by MTU +// maximum message size for UDP broadcast is limited by MTU // size of underlying link; we are not checking that now. -/// \todo Check MTU size of underlying link +// \todo Check MTU size of underlying link uint32_t UdpSocketImpl::GetTxAvailable (void) const { diff --git a/src/internet/model/udp-socket-impl.h b/src/internet/model/udp-socket-impl.h --- a/src/internet/model/udp-socket-impl.h +++ b/src/internet/model/udp-socket-impl.h @@ -50,6 +50,10 @@ class UdpSocketImpl : public UdpSocket { public: + /** + * \brief Get the type ID. + * \return the object TypeId + */ static TypeId GetTypeId (void); /** * Create an unbound udp socket. @@ -57,7 +61,15 @@ UdpSocketImpl (); virtual ~UdpSocketImpl (); + /** + * \brief Set the associated node. + * \param node the node + */ void SetNode (Ptr node); + /** + * \brief Set the associated UDP L4 protocol. + * \param udp the UDP L4 protocol + */ void SetUdp (Ptr udp); virtual enum SocketErrno GetErrno (void) const; @@ -101,48 +113,127 @@ friend class UdpSocketFactory; // invoked by Udp class + + /** + * Finish the binding process + * \returns 0 on success, -1 on failure + */ int FinishBind (void); - void ForwardUp (Ptr p, Ipv4Header header, uint16_t port, - Ptr incomingInterface); - void ForwardUp6 (Ptr p, Ipv6Header header, uint16_t port); + + /** + * \brief Called by the L3 protocol when it received a packet to pass on to TCP. + * + * \param packet the incoming packet + * \param header the packet's IPv4 header + * \param port the incoming port + * \param incomingInterface the incoming interface + */ + void ForwardUp (Ptr packet, Ipv4Header header, uint16_t port, Ptr incomingInterface); + + /** + * \brief Called by the L3 protocol when it received a packet to pass on to TCP. + * + * \param packet the incoming packet + * \param header the packet's IPv6 header + * \param port the incoming port + */ + void ForwardUp6 (Ptr packet, Ipv6Header header, uint16_t port); + + /** + * \brief Kill this socket by zeroing its attributes (IPv4) + * + * This is a callback function configured to m_endpoint in + * SetupCallback(), invoked when the endpoint is destroyed. + */ void Destroy (void); + + /** + * \brief Kill this socket by zeroing its attributes (IPv6) + * + * This is a callback function configured to m_endpoint in + * SetupCallback(), invoked when the endpoint is destroyed. + */ void Destroy6 (void); + + /** + * \brief Send a packet + * \param p packet + * \returns 0 on success, -1 on failure + */ int DoSend (Ptr p); + /** + * \brief Send a packet to a specific destination + * \param p packet + * \param daddr destination address + * \returns 0 on success, -1 on failure + */ int DoSendTo (Ptr p, const Address &daddr); + /** + * \brief Send a packet to a specific destination and port (IPv4) + * \param p packet + * \param daddr destination address + * \param dport destination port + * \returns 0 on success, -1 on failure + */ int DoSendTo (Ptr p, Ipv4Address daddr, uint16_t dport); + /** + * \brief Send a packet to a specific destination and port (IPv6) + * \param p packet + * \param daddr destination address + * \param dport destination port + * \returns 0 on success, -1 on failure + */ int DoSendTo (Ptr p, Ipv6Address daddr, uint16_t dport); - void ForwardIcmp (Ipv4Address icmpSource, uint8_t icmpTtl, - uint8_t icmpType, uint8_t icmpCode, - uint32_t icmpInfo); - void ForwardIcmp6 (Ipv6Address icmpSource, uint8_t icmpTtl, - uint8_t icmpType, uint8_t icmpCode, - uint32_t icmpInfo); - Ipv4EndPoint *m_endPoint; - Ipv6EndPoint *m_endPoint6; - Ptr m_node; - Ptr m_udp; - Address m_defaultAddress; - uint16_t m_defaultPort; - TracedCallback > m_dropTrace; + /** + * \brief Called by the L3 protocol when it received an ICMP packet to pass on to TCP. + * + * \param icmpSource the ICMP source address + * \param icmpTtl the ICMP Time to Live + * \param icmpType the ICMP Type + * \param icmpCode the ICMP Code + * \param icmpInfo the ICMP Info + */ + void ForwardIcmp (Ipv4Address icmpSource, uint8_t icmpTtl, uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo); - enum SocketErrno m_errno; - bool m_shutdownSend; - bool m_shutdownRecv; - bool m_connected; - bool m_allowBroadcast; + /** + * \brief Called by the L3 protocol when it received an ICMPv6 packet to pass on to TCP. + * + * \param icmpSource the ICMP source address + * \param icmpTtl the ICMP Time to Live + * \param icmpType the ICMP Type + * \param icmpCode the ICMP Code + * \param icmpInfo the ICMP Info + */ + void ForwardIcmp6 (Ipv6Address icmpSource, uint8_t icmpTtl, uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo); - std::queue > m_deliveryQueue; - uint32_t m_rxAvailable; + // Connections to other layers of TCP/IP + Ipv4EndPoint* m_endPoint; //!< the IPv4 endpoint + Ipv6EndPoint* m_endPoint6; //!< the IPv6 endpoint + Ptr m_node; //!< the associated node + Ptr m_udp; //!< the associated UDP L4 protocol + Callback m_icmpCallback; //!< ICMP callback + Callback m_icmpCallback6; //!< ICMPv6 callback + + Address m_defaultAddress; //!< Default address + uint16_t m_defaultPort; //!< Default port + TracedCallback > m_dropTrace; //!< Trace for dropped packets + + enum SocketErrno m_errno; //!< Socket error code + bool m_shutdownSend; //!< Send no longer allowed + bool m_shutdownRecv; //!< Receive no longer allowed + bool m_connected; //!< Connection established + bool m_allowBroadcast; //!< Allow send broadcast packets + + std::queue > m_deliveryQueue; //!< Queue for incoming packets + uint32_t m_rxAvailable; //!< Number of available bytes to be received // Socket attributes - uint32_t m_rcvBufSize; - uint8_t m_ipMulticastTtl; - int32_t m_ipMulticastIf; - bool m_ipMulticastLoop; - bool m_mtuDiscover; - Callback m_icmpCallback; - Callback m_icmpCallback6; + uint32_t m_rcvBufSize; //!< Receive buffer size + uint8_t m_ipMulticastTtl; //!< Multicast TTL + int32_t m_ipMulticastIf; //!< Multicast Interface + bool m_ipMulticastLoop; //!< Allow multicast loop + bool m_mtuDiscover; //!< Allow MTU discovery }; } // namespace ns3 diff --git a/src/internet/model/udp-socket.h b/src/internet/model/udp-socket.h --- a/src/internet/model/udp-socket.h +++ b/src/internet/model/udp-socket.h @@ -46,6 +46,11 @@ class UdpSocket : public Socket { public: + /** + * Get the type ID. + * \brief Get the type ID. + * \return the object TypeId + */ static TypeId GetTypeId (void); UdpSocket (void); @@ -99,15 +104,67 @@ private: // Indirect the attribute setting and getting through private virtual methods + /** + * \brief Set the receiving buffer size + * \param size the buffer size + */ virtual void SetRcvBufSize (uint32_t size) = 0; + /** + * \brief Get the receiving buffer size + * \returns the buffer size + */ virtual uint32_t GetRcvBufSize (void) const = 0; + /** + * \brief Set the IP multicast TTL + * \param ipTtl the IP multicast TTL + */ virtual void SetIpMulticastTtl (uint8_t ipTtl) = 0; + /** + * \brief Get the IP multicast TTL + * \returns the IP multicast TTL + */ virtual uint8_t GetIpMulticastTtl (void) const = 0; + /** + * \brief Set the IP multicast interface + * \param ipIf the IP multicast interface + */ virtual void SetIpMulticastIf (int32_t ipIf) = 0; + /** + * \brief Get the IP multicast interface + * \returns the IP multicast interface + */ virtual int32_t GetIpMulticastIf (void) const = 0; + /** + * \brief Set the IP multicast loop capability + * + * This means that the socket will receive the packets + * sent by itself on a multicast address. + * Equivalent to setsockopt IP_MULTICAST_LOOP + * + * \param loop the IP multicast loop capability + */ virtual void SetIpMulticastLoop (bool loop) = 0; + /** + * \brief Get the IP multicast loop capability + * + * This means that the socket will receive the packets + * sent by itself on a multicast address. + * Equivalent to setsockopt IP_MULTICAST_LOOP + * + * \returns the IP multicast loop capability + */ virtual bool GetIpMulticastLoop (void) const = 0; + /** + * \brief Set the MTU discover capability + * + * \param discover the MTU discover capability + */ virtual void SetMtuDiscover (bool discover) = 0; + /** + * \brief Get the MTU discover capability + * + * \returns the MTU discover capability + */ virtual bool GetMtuDiscover (void) const = 0; }; diff --git a/src/network/model/socket.h b/src/network/model/socket.h --- a/src/network/model/socket.h +++ b/src/network/model/socket.h @@ -119,6 +119,8 @@ */ static Ptr CreateSocket (Ptr node, TypeId tid); /** + * \brief Get last error number. + * * \return the errno associated to the last call which failed in this * socket. Each socket's errno is initialized to zero * when the socket is created. @@ -129,7 +131,8 @@ */ virtual enum Socket::SocketType GetSocketType (void) const = 0; /** - * \returns the node this socket is associated with. + * \brief Return the node this socket is associated with. + * \returns the node */ virtual Ptr GetNode (void) const = 0; /** @@ -551,6 +554,7 @@ int RecvFrom (uint8_t* buf, uint32_t size, uint32_t flags, Address &fromAddress); /** + * \brief Get socket address. * \param address the address name this socket is associated with. * \returns 0 if success, -1 otherwise */