Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * Copyright (c) 2013 Mohammed J.F. Alenazi | 3 * Copyright (c) 2013 Mohammed J.F. Alenazi |
4 * | 4 * |
5 * This program is free software; you can redistribute it and/or modify | 5 * This program is free software; you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 2 as | 6 * it under the terms of the GNU General Public License version 2 as |
7 * published by the Free Software Foundation; | 7 * published by the Free Software Foundation; |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with this program; if not, write to the Free Software | 15 * along with this program; if not, write to the Free Software |
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
17 * | 17 * |
18 * Author: Mohammed J.F. Alenazi <malenazi@ittc.ku.edu> | 18 * Author: Mohammed J.F. Alenazi <malenazi@ittc.ku.edu> |
19 * | 19 * |
20 * James P.G. Sterbenz <jpgs@ittc.ku.edu>, director | 20 * James P.G. Sterbenz <jpgs@ittc.ku.edu>, director |
21 * ResiliNets Research Group http://wiki.ittc.ku.edu/resilinets | 21 * ResiliNets Research Group http://wiki.ittc.ku.edu/resilinets |
22 * Information and Telecommunication Technology Center (ITTC) | 22 * Information and Telecommunication Technology Center (ITTC) |
23 * and Department of Electrical Engineering and Computer Science | 23 * and Department of Electrical Engineering and Computer Science |
24 * The University of Kansas Lawrence, KS USA. | 24 * The University of Kansas Lawrence, KS USA. |
25 * | 25 * |
26 * Work supported by King Saud University and the ITTC at The University of Kans as. | 26 * Work supported by King Saud University and |
27 * the ITTC at The University of Kansas. | |
27 */ | 28 */ |
29 | |
30 #ifndef EPIDEMIC_ROUTING_PROTOCOL_H | |
31 #define EPIDEMIC_ROUTING_PROTOCOL_H | |
28 | 32 |
29 #include "epidemic-packet-queue.h" | 33 #include "epidemic-packet-queue.h" |
30 #include "epidemic-packet.h" | 34 #include "epidemic-packet.h" |
31 #include "ns3/random-variable-stream.h" | 35 #include "ns3/random-variable-stream.h" |
32 #include "epidemic-tag.h" | 36 #include "epidemic-tag.h" |
33 #include <vector> | 37 #include <vector> |
34 #include "ns3/boolean.h" | 38 #include "ns3/boolean.h" |
35 #include "ns3/config.h" | 39 #include "ns3/config.h" |
36 #include "ns3/node.h" | 40 #include "ns3/node.h" |
37 #include "ns3/ipv4-routing-protocol.h" | 41 #include "ns3/ipv4-routing-protocol.h" |
38 #include "ns3/inet-socket-address.h" | 42 #include "ns3/inet-socket-address.h" |
39 #include "ns3/ipv4-interface.h" | 43 #include "ns3/ipv4-interface.h" |
40 #include "ns3/ipv4-l3-protocol.h" | 44 #include "ns3/ipv4-l3-protocol.h" |
41 #include "ns3/output-stream-wrapper.h" | 45 #include "ns3/output-stream-wrapper.h" |
42 #include "ns3/timer.h" | 46 #include "ns3/timer.h" |
43 #include <iostream> | 47 #include <iostream> |
44 #include <algorithm> | 48 #include <algorithm> |
45 #include <functional> | 49 #include <functional> |
46 #include "ns3/ipv4-route.h" | 50 #include "ns3/ipv4-route.h" |
47 #include "ns3/socket.h" | 51 #include "ns3/socket.h" |
48 #include "ns3/log.h" | 52 #include "ns3/log.h" |
49 | 53 |
50 #ifndef EPIDEMIC_ROUTING_PROTOCOL_H | 54 /** |
51 #define EPIDEMIC_ROUTING_PROTOCOL_H | 55 * \defgroup epidemic Epidemic Routing |
Peter Barnes
2014/09/23 22:54:31
Include guard has to go before any includes.
mjf.alenazi
2014/11/25 19:51:55
Done.
| |
56 * | |
57 * This section documents the API of the ns-3 epidemic module. For a | |
58 * generic functional description, please refer to the ns-3 model | |
59 * library document. | |
60 */ | |
61 | |
52 | 62 |
53 namespace ns3 { | 63 namespace ns3 { |
54 namespace Epidemic { | 64 namespace Epidemic { |
55 /** | 65 /** |
56 * \ingroup epidemic | 66 * \ingroup epidemic |
57 * \brief Epidemic routing protocol | 67 * \brief Epidemic routing protocol |
58 * This implementation is based on the paper titled 'Epidemic Routing for | 68 * This implementation is based on the paper titled 'Epidemic Routing for |
59 * Partially-Connected Ad Hoc Networks' | 69 * Partially-Connected Ad Hoc Networks' |
60 * In the original paper, the implementation was on top of | 70 * In the original paper, the implementation was on top of |
61 * the Internet MANET Encapsulation Protocol (IMEP) layer, which | 71 * the Internet MANET Encapsulation Protocol (IMEP) layer, which |
62 * is responsible for notifying the epidemic agent when a new node | 72 * is responsible for notifying the epidemic agent when a new node |
63 * comes into radio range. However, since IMEP is not implemented in ns-3 | 73 * comes into radio range. However, since IMEP is not implemented in ns-3 |
64 * , a beacon mechanism is added to the implementation. | 74 * , a beacon mechanism is added to the implementation. |
65 * Some functions are adapted from the implementation AODV. | 75 * Some functions are adapted from the implementation AODV. |
66 * Transport Port for MANET routing protocols ports | |
67 * Based on \RFC{5498} | |
68 */ | 76 */ |
69 class RoutingProtocol : public Ipv4RoutingProtocol | 77 class RoutingProtocol : public Ipv4RoutingProtocol |
Peter Barnes
2015/04/28 23:42:33
@Tommaso: I encouraged relying on the Epidemic na
mjf.alenazi
2017/05/13 23:57:15
Acknowledged.
| |
70 { | 78 { |
71 public: | 79 public: |
72 /// Get TypeID class method | 80 /** |
81 * Get the registered TypeId for this class. | |
82 * \return The object TypeId. | |
83 */ | |
73 static TypeId GetTypeId (void); | 84 static TypeId GetTypeId (void); |
74 | 85 |
75 /// Transport Port for MANET routing protocols ports, based on \RFC{5498} | 86 /// Transport Port for MANET routing protocols ports, based on \RFC{5498} |
76 static const uint32_t EPIDEMIC_PORT = 269; | 87 static const uint32_t EPIDEMIC_PORT = 269; |
77 /// c-tor | 88 /// c-tor |
78 RoutingProtocol (); | 89 RoutingProtocol (); |
90 /** Dummy destructor, see DoDispose. */ | |
79 virtual ~RoutingProtocol (); | 91 virtual ~RoutingProtocol (); |
92 /** Destructor implementation */ | |
80 virtual void DoDispose (); | 93 virtual void DoDispose (); |
81 // Inherited methods: | 94 // Inherited methods: |
82 Ptr<Ipv4Route> RouteOutput (Ptr<Packet> p, const Ipv4Header &header, Ptr<NetDe vice> oif, Socket::SocketErrno &sockerr); | 95 Ptr<Ipv4Route> RouteOutput (Ptr<Packet> p, const Ipv4Header &header, |
83 bool RouteInput (Ptr<const Packet> p, const Ipv4Header &header, Ptr<const NetD evice> idev, UnicastForwardCallback ucb, | 96 Ptr<NetDevice> oif, Socket::SocketErrno &sockerr); |
84 MulticastForwardCallback mcb, LocalDeliverCallback lcb, Error Callback ecb); | 97 bool RouteInput (Ptr<const Packet> p, const Ipv4Header &header, |
98 Ptr<const NetDevice> idev, UnicastForwardCallback ucb, | |
99 MulticastForwardCallback mcb, | |
100 LocalDeliverCallback lcb, ErrorCallback ecb); | |
85 virtual void PrintRoutingTable (Ptr<OutputStreamWrapper> stream) const; | 101 virtual void PrintRoutingTable (Ptr<OutputStreamWrapper> stream) const; |
86 virtual void NotifyInterfaceUp (uint32_t interface); | 102 virtual void NotifyInterfaceUp (uint32_t interface); |
87 virtual void NotifyInterfaceDown (uint32_t interface); | 103 virtual void NotifyInterfaceDown (uint32_t interface); |
88 virtual void NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress addres s); | 104 virtual void NotifyAddAddress (uint32_t interface, |
89 virtual void NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress add ress); | 105 Ipv4InterfaceAddress address); |
106 virtual void NotifyRemoveAddress (uint32_t interface, | |
107 Ipv4InterfaceAddress address); | |
90 virtual void SetIpv4 (Ptr<Ipv4> ipv4); | 108 virtual void SetIpv4 (Ptr<Ipv4> ipv4); |
91 | 109 |
92 private: | 110 private: |
93 /// Main IP address for the current node | 111 /// Main IP address for the current node |
94 Ipv4Address m_mainAddress; | 112 Ipv4Address m_mainAddress; |
95 /// Number of times a packet is resent | 113 /// Number of times a packet is resent |
96 uint32_t m_hopCount; | 114 uint32_t m_hopCount; |
97 /// Maximum number of packets a queue can hold | 115 /// Maximum number of packets a queue can hold |
98 uint32_t m_maxQueueLen; | 116 uint32_t m_maxQueueLen; |
99 /// Time in seconds after which the packet will expire in the queue | 117 /// Time in seconds after which the packet will expire in the queue |
100 Time m_queueEntryExpireTime; | 118 Time m_queueEntryExpireTime; |
101 /// Time in seconds for sending periodic beacon packets | 119 /// Time in seconds for sending periodic beacon packets |
102 Time m_beaconInterval; | 120 Time m_beaconInterval; |
103 /// Upper bound of the uniform distribution random time added to avoid collisi ons. Measured in milliseconds | 121 /// Time in seconds for host recent period, in which hosts can not |
122 // re-exchange summary vectors | |
123 Time m_hostRecentPeriod; | |
124 /// Upper bound of the uniform distribution random time added | |
125 // to avoid collisions. Measured in milliseconds | |
104 uint32_t m_beaconMaxJitterMs; | 126 uint32_t m_beaconMaxJitterMs; |
105 /// Local counter for data packets | 127 /// Local counter for data packets |
106 uint16_t m_dataPacketCounter; | 128 uint16_t m_dataPacketCounter; |
107 /// A pointer to the Ipv4 for the current node | 129 /// A pointer to the Ipv4 for the current node |
108 Ptr<Ipv4> m_ipv4; | 130 Ptr<Ipv4> m_ipv4; |
109 /// A map between opened sockets and IP addresses | 131 /// A map between opened sockets and IP addresses |
110 std::map<Ptr<Socket>, Ipv4InterfaceAddress> m_socketAddresses; | 132 std::map<Ptr<Socket>, Ipv4InterfaceAddress> m_socketAddresses; |
111 /// queue associated with a node | 133 /// queue associated with a node |
112 PacketQueue m_queue; | 134 PacketQueue m_queue; |
113 /// timer for sending beacons | 135 /// timer for sending beacons |
114 Timer m_beaconTimer; | 136 Timer m_beaconTimer; |
115 /// uniform random variable to be added to beacon intervals to avoid collision s | 137 /// uniform random variable to be added to beacon intervals |
138 // to avoid collisions | |
116 Ptr<UniformRandomVariable> m_beaconJitter; | 139 Ptr<UniformRandomVariable> m_beaconJitter; |
140 /// Type to connect a host address to recent contact time value | |
141 typedef std::map<Ipv4Address, Time> HostContactMap; | |
142 /// Pair representing host address and time value | |
143 typedef HostContactMap::value_type HostContactMapPair; | |
144 /// Hash table to store recent contact time for nodes | |
145 HostContactMap m_hostContactTime; | |
117 | 146 |
118 | 147 |
119 | 148 |
120 /// Start protocol operation | 149 /// Start protocol operation |
150 /// Invoked by SetIpv4() | |
121 void Start (); | 151 void Start (); |
122 /// Captures Epidemic packet | 152 /// Captures incomming Epidemic packet via /p socket |
Peter Barnes
2015/04/28 23:42:33
"incoming"
mjf.alenazi
2017/05/13 23:57:16
Done.
| |
123 void RecvEpidemic (Ptr<Socket> socket); | 153 void RecvEpidemic (Ptr<Socket> socket); |
Peter Barnes
2015/04/28 23:42:33
Explicitly document arguments:
* \param socket
mjf.alenazi
2017/05/13 23:57:16
Done.
| |
124 /// Sends Disjoint packet given a vector containing the other nodes Packet IDs and its IP address | 154 /** |
125 void SendDisjointPackets (EpidemicSummaryVectorHeader packet_SMV,Ipv4Address d est); | 155 * \brief Sends disjoint packets given a vector containing |
156 * the other nodes Packet IDs and its IP address | |
157 * \param packet_SMV vector containing the other nodes Packet IDs | |
158 * \param dest destination address | |
159 */ | |
160 void SendDisjointPackets ( | |
161 SummaryVectorHeader packet_SMV, Ipv4Address dest); | |
126 /// Function to send beacons periodically | 162 /// Function to send beacons periodically |
127 void SendBeacons (); | 163 void SendBeacons (); |
128 /// Find the output device for a given IP address | 164 /// \returns the output device for a given IP address \p dst |
129 uint32_t FindOutputDeviceForAddress ( Ipv4Address dst); | 165 uint32_t FindOutputDeviceForAddress ( Ipv4Address dst); |
Peter Barnes
2015/04/28 23:42:33
Explicitly document arguments:
* \param dst …
| |
130 /// Find the loopback device for current node | 166 /// \returns the loopback device for current node |
131 uint32_t FindLoopbackDevice (); | 167 uint32_t FindLoopbackDevice (); |
132 /// Send a packet to a given IP address | 168 /// Send a packet to a given IP address \p addr |
133 void SendPacket (Ptr<Packet> p,InetSocketAddress addr); | 169 void SendPacket (Ptr<Packet> p,InetSocketAddress addr); |
Peter Barnes
2015/04/28 23:42:33
Explicitly document arguments:
* \param p …
*
| |
134 /// Check if an address belongs to the current node | 170 /// \returns true if an address belongs to the current node |
135 bool IsMyOwnAddress (Ipv4Address src); | 171 bool IsMyOwnAddress (Ipv4Address src); |
Peter Barnes
2015/04/28 23:42:33
Explicitly document arguments:
* \param src …
mjf.alenazi
2017/05/13 23:57:16
Done.
| |
136 /// Broadcast a given packet | 172 /// Broadcast a given packet \p p |
137 void BroadcastPacket (Ptr<Packet> p); | 173 void BroadcastPacket (Ptr<Packet> p); |
Peter Barnes
2015/04/28 23:42:33
Explicitly document arguments:
* \param p …
mjf.alenazi
2017/05/13 23:57:16
Done.
| |
138 /** | 174 /** |
139 * \brief Send summary vector | 175 * \brief Send summary vector |
140 * \param dest destination address | 176 * \param dest destination address |
141 * \param firstNode check the anti-entropy session in the Epidemic paper | 177 * \param firstNode check the anti-entropy session in the Epidemic paper |
142 * True send a summary vector with reply header | 178 * \c true send a summary vector with reply header |
143 * False send a summary vector with reply back header | 179 * \c false send a summary vector with reply back header |
144 */ | 180 */ |
145 void SendSummaryVector (Ipv4Address dest,bool firstNode); | 181 void SendSummaryVector (Ipv4Address dest,bool firstNode); |
146 /// Find socket with local interface address iface | 182 /// \returns socket with local interface address \p iface |
147 Ptr<Socket> FindSocketWithInterfaceAddress (Ipv4InterfaceAddress iface) const; | 183 Ptr<Socket> FindSocketWithInterfaceAddress ( |
Peter Barnes
2015/04/28 23:42:33
Explicitly document arguments:
* \param iface .
mjf.alenazi
2017/05/13 23:57:16
Done.
| |
148 /// Send a a packet from a queue | 184 Ipv4InterfaceAddress iface) const; |
185 /// Send a a packet from a queue via \p queueEntry to address \p dst | |
149 void SendPacketFromQueue (Ipv4Address dst,QueueEntry queueEntry); | 186 void SendPacketFromQueue (Ipv4Address dst,QueueEntry queueEntry); |
Peter Barnes
2015/04/28 23:42:33
Explicitly document arguments:
* \param dst …
mjf.alenazi
2017/05/13 23:57:16
Done.
| |
187 /// \returns true if \p hostID has been contacted recently | |
188 bool IsHostContactedRecently (Ipv4Address hostID); | |
Peter Barnes
2015/04/28 23:42:33
Explicitly document arguments:
* \param hostId
mjf.alenazi
2017/05/13 23:57:16
Done.
| |
150 | 189 |
151 | 190 |
152 }; | 191 }; |
153 } //end namespace epidemic | 192 } //end namespace epidemic |
154 } //end namespace ns3 | 193 } //end namespace ns3 |
155 #endif | 194 #endif |
LEFT | RIGHT |