Left: | ||
Right: |
OLD | NEW |
---|---|
(Empty) | |
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | |
2 /* | |
3 * Copyright (c) 2013 Mohammed J.F. Alenazi | |
4 * | |
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 | |
7 * published by the Free Software Foundation; | |
8 * | |
9 * This program is distributed in the hope that it will be useful, | |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 * GNU General Public License for more details. | |
13 * | |
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 | |
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
17 * | |
18 * Author: Mohammed J.F. Alenazi <malenazi@ittc.ku.edu> | |
19 * | |
20 * James P.G. Sterbenz <jpgs@ittc.ku.edu>, director | |
21 * ResiliNets Research Group http://wiki.ittc.ku.edu/resilinets | |
22 * Information and Telecommunication Technology Center (ITTC) | |
23 * and Department of Electrical Engineering and Computer Science | |
24 * The University of Kansas Lawrence, KS USA. | |
25 * | |
26 * Work supported by King Saud University and the ITTC at The University of Kans as. | |
27 */ | |
28 | |
29 #include "epidemic-packet-queue.h" | |
30 #include "epidemic-packet.h" | |
31 #include "ns3/random-variable-stream.h" | |
32 #include "epidemic-tag.h" | |
33 #include <vector> | |
34 #include "ns3/boolean.h" | |
35 #include "ns3/config.h" | |
36 #include "ns3/node.h" | |
37 #include "ns3/ipv4-routing-protocol.h" | |
38 #include "ns3/inet-socket-address.h" | |
39 #include "ns3/ipv4-interface.h" | |
40 #include "ns3/ipv4-l3-protocol.h" | |
41 #include "ns3/output-stream-wrapper.h" | |
42 #include "ns3/timer.h" | |
43 #include <iostream> | |
44 #include <algorithm> | |
45 #include <functional> | |
46 #include "ns3/ipv4-route.h" | |
47 #include "ns3/socket.h" | |
48 #include "ns3/log.h" | |
49 | |
50 | |
51 namespace ns3 { | |
52 namespace Epidemic { | |
53 /** | |
54 * \ingroup epidemic | |
55 * \brief Epidemic routing protocol | |
56 * This implementation is based on the paper titled 'Epidemic Routing for | |
57 * Partially-Connected Ad Hoc Networks' | |
58 * In the original paper, the implementation was on top of | |
59 * the Internet MANET Encapsulation Protocol (IMEP) layer, which | |
60 * is responsible for notifying the epidemic agent when a new node | |
61 * comes into radio range. However, since IMEP is not implemented in ns-3 | |
62 * , a beacon mechanism is added to the implementation. | |
63 * Some functions are adapted from the implementation AODV. | |
64 * Transport Port for MANET routing protocols ports | |
65 * Based on \RFC{5498} | |
66 */ | |
67 class RoutingProtocol : public Ipv4RoutingProtocol | |
68 { | |
69 public: | |
70 /// Get TypeID class method | |
71 static TypeId GetTypeId (void); | |
72 | |
73 /// Transport Port for MANET routing protocols ports, based on \RFC{5498} | |
74 static const uint32_t EPIDEMIC_PORT = 269; | |
75 /// c-tor | |
76 RoutingProtocol (); | |
77 virtual ~RoutingProtocol (); | |
78 virtual void DoDispose (); | |
79 // Inherited methods: | |
80 Ptr<Ipv4Route> RouteOutput (Ptr<Packet> p, const Ipv4Header &header, Ptr<NetDe vice> oif, Socket::SocketErrno &sockerr); | |
81 bool RouteInput (Ptr<const Packet> p, const Ipv4Header &header, Ptr<const NetD evice> idev, UnicastForwardCallback ucb, | |
82 MulticastForwardCallback mcb, LocalDeliverCallback lcb, Error Callback ecb); | |
83 virtual void PrintRoutingTable (Ptr<OutputStreamWrapper> stream) const; | |
84 virtual void NotifyInterfaceUp (uint32_t interface); | |
85 virtual void NotifyInterfaceDown (uint32_t interface); | |
86 virtual void NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress addres s); | |
87 virtual void NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress add ress); | |
88 virtual void SetIpv4 (Ptr<Ipv4> ipv4); | |
89 | |
90 private: | |
91 /// Main IP address for the current node | |
92 Ipv4Address m_mainAddress; | |
93 /// Number of times a packet is resent | |
94 uint32_t m_hopCount; | |
95 /// Maximum number of packets a queue can hold | |
96 uint32_t m_maxQueueLen; | |
97 /// Time in seconds after which the packet will expire in the queue | |
98 Time m_queueEntryExpireTime; | |
99 /// Time in seconds for sending periodic beacon packets | |
100 Time m_beaconInterval; | |
101 /// Upper bound of the uniform distribution random time added to avoid collisi ons. Measured in milliseconds | |
Peter Barnes
2014/09/12 20:33:50
Suggest m_beaconMaxJitterMs
mjf.alenazi
2014/09/18 00:34:26
Done.
| |
102 uint32_t m_beaconRandomness; | |
103 /// Local counter for data packets | |
104 uint16_t m_dataPacketCounter; | |
105 /// A pointer to the Ipv4 for the current node | |
106 Ptr<Ipv4> m_ipv4; | |
107 /// A map between opened sockets and IP addresses | |
108 std::map<Ptr<Socket>, Ipv4InterfaceAddress> m_socketAddresses; | |
109 /// queue associated with a node | |
110 PacketQueue m_queue; | |
111 /// timer for sending beacons | |
112 Timer m_beaconTimer; | |
113 /// unifrom random variable to be added to beacon intervals to avoid collision s | |
Peter Barnes
2014/09/12 20:33:50
"uniform"
Suggest m_beaconJitter
mjf.alenazi
2014/09/18 00:34:26
Done.
| |
114 Ptr<UniformRandomVariable> m_beaconRandomnessDistro; | |
115 | |
116 | |
117 | |
118 /// Start protocol operation | |
119 void Start (); | |
120 /// Captures Epidemic packet | |
121 void RecvEpidemic (Ptr<Socket> socket); | |
122 /// Sends Disjoint packet given a vector containing the other nodes Packet IDs and its IP address | |
123 void SendDisjointPackets (EpidemicSummaryVectorHeader packet_SMV,Ipv4Address d est); | |
124 /// Function to send beacons periodically | |
125 void SendBeacons (); | |
126 /// Find the output device for a given IP address | |
127 uint32_t FindOutputDeviceForAddress ( Ipv4Address dst); | |
128 /// Find the loopback device for current node | |
129 uint32_t FindLoopbackDevice (); | |
130 /// Send a packet to a given IP address | |
131 void SendPacket (Ptr<Packet> p,InetSocketAddress addr); | |
132 /// Check if an address belongs to the current node | |
133 bool IsMyOwnAddress (Ipv4Address src); | |
134 /// Broadcast a given packet | |
135 void BroadcastPacket (Ptr<Packet> p); | |
136 /** | |
137 * \brief Send summary vector | |
138 * \param dest destination address | |
139 * \param firstNode check the anti-entropy session in the Epidemic paper | |
140 * True send a summary vector with reply header | |
141 * False send a summary vector with reply back header | |
142 */ | |
143 void SendSummaryVector (Ipv4Address dest,bool firstNode); | |
144 /// Find socket with local interface address iface | |
145 Ptr<Socket> FindSocketWithInterfaceAddress (Ipv4InterfaceAddress iface) const; | |
146 /// Send a a packet from a queue | |
147 void SendPacketFromQueue (Ipv4Address dst,QueueEntry queueEntry); | |
148 | |
149 | |
150 }; | |
151 } //end namespace epidemic | |
152 } //end namespace ns3 | |
OLD | NEW |