OLD | NEW |
(Empty) | |
| 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 /*· |
| 3 * Copyright (c) YEAR COPYRIGHTHOLDER |
| 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: Michal Paszta· |
| 19 */ |
| 20 |
| 21 #ifndef SMECN_ROUTING_PROTOCOL_H_ |
| 22 #define SMECN_ROUTING_PROTOCOL_H_ |
| 23 |
| 24 #include "smecn-rtable.h" |
| 25 #include "smecn-header.h" |
| 26 #include <ns3/timer.h> |
| 27 #include <ns3/node.h> |
| 28 #include <ns3/mobility-model.h> |
| 29 #include "ns3/ipv4-routing-protocol.h" |
| 30 #include "ns3/ipv4-interface.h" |
| 31 #include "ns3/ipv4-l3-protocol.h" |
| 32 #include "ns3/yans-wifi-phy.h" |
| 33 #include "ns3/propagation-loss-model.h" |
| 34 #include "ns3/rns.h" |
| 35 #include "ns3/random-variable-stream.h" |
| 36 |
| 37 namespace ns3 { |
| 38 namespace smecn { |
| 39 class BroadcastHeader; |
| 40 |
| 41 /** |
| 42 * \ingroup smecn |
| 43 * \brief SMECN routing protocol. |
| 44 *· |
| 45 * SMECN (Minimum Energy Communication Network) Protocol |
| 46 */ |
| 47 class RoutingProtocol : public Ipv4RoutingProtocol |
| 48 { |
| 49 public: |
| 50 static TypeId GetTypeId (void); |
| 51 static const uint32_t SMECN_PORT; |
| 52 |
| 53 /// Constructor |
| 54 RoutingProtocol (); |
| 55 |
| 56 /// Destructor |
| 57 ~RoutingProtocol (); |
| 58 virtual void DoDispose (); |
| 59 |
| 60 ///\name From Ipv4RoutingProtocol |
| 61 //\{ |
| 62 Ptr<Ipv4Route> RouteOutput (Ptr<Packet> p, const Ipv4Header &header, Ptr<NetDe
vice> oif, Socket::SocketErrno &sockerr); |
| 63 bool RouteInput (Ptr<const Packet> p, const Ipv4Header &header, Ptr<const NetD
evice> idev, |
| 64 UnicastForwardCallback ucb, MulticastForwardCallback mcb, |
| 65 LocalDeliverCallback lcb, ErrorCallback ecb); |
| 66 virtual void NotifyInterfaceUp (uint32_t interface); |
| 67 virtual void NotifyInterfaceDown (uint32_t interface); |
| 68 virtual void NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress addres
s); |
| 69 virtual void NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress add
ress); |
| 70 virtual void SetIpv4 (Ptr<Ipv4> ipv4); |
| 71 virtual void PrintRoutingTable (Ptr<OutputStreamWrapper> stream) const; |
| 72 //\} |
| 73 |
| 74 |
| 75 /** |
| 76 * @brief Sends a packet in the duty phase. |
| 77 * |
| 78 * @param packet pointer to the packet which should be sent |
| 79 * @param dst destination IP address |
| 80 */ |
| 81 void Send (Ptr<Packet> packet, Ipv4Address dst); |
| 82 |
| 83 /** |
| 84 * @brief broadcasts the reconfiguration message. |
| 85 * |
| 86 * @retval true if the broadcast was successfull |
| 87 * @retval otherwise |
| 88 */ |
| 89 bool SendReconfigurationBroadcast (void); |
| 90 |
| 91 /** |
| 92 * @brief Receive and interpret other node's reconfiguration broadcast. |
| 93 * |
| 94 * @param socket who did the message come from |
| 95 */ |
| 96 void ReceiveReconfigurationBroadcast (Ptr<Socket> socket); |
| 97 |
| 98 /** |
| 99 * @brief Calculate the current range of the node. |
| 100 * |
| 101 * There is currently no easy way to determine node's range. Therefore this |
| 102 * function applies a bisection method to solve the equation: |
| 103 * |
| 104 * CalcRxPower(double txPowerDbm, Ptr<MobilityModel> a, Ptr<MobilityModel> b) |
| 105 * = minimumPowerDbm |
| 106 * |
| 107 * for b and the distance from b to a is the range of the node. |
| 108 * |
| 109 * The CalcRxPower function is specific to the PropagationModel used by the |
| 110 * channel. The txPowerDbm value and the minimumPowerDbm value are specific to |
| 111 * the PHY used by the node. Current position is set to a(0,0). |
| 112 * |
| 113 * The function takes different b(xb,0) values and checks if the power of the |
| 114 * node is sufficient to reach it or not. Depending on the outcome, the xb |
| 115 * value is increased or decreased according to the bisection method until it |
| 116 * changes by less than "accuracy". |
| 117 * |
| 118 * @param accuracy how accurate should the range estimation be |
| 119 * @return up-to-date range of the node. |
| 120 */ |
| 121 double EstimateRange (double accuracy); |
| 122 |
| 123 void SetRanges(void); |
| 124 |
| 125 /// Create loopback route for given header |
| 126 Ptr<Ipv4Route> |
| 127 LoopbackRoute (const Ipv4Header & header, Ptr<NetDevice> oif) const; |
| 128 |
| 129 void PositionUpdate (void); |
| 130 |
| 131 void SetMobility (Ptr<MobilityModel> m); |
| 132 Ptr<MobilityModel> GetMobility (); |
| 133 void SetWifiPhy (Ptr<WifiPhy> wifiPhy); |
| 134 Ptr<WifiPhy> GetWifiPhy (void); |
| 135 void SetPropagationLossModel (Ptr<PropagationLossModel> p); |
| 136 Ptr<PropagationLossModel> GetPropagationLossModel(void); |
| 137 |
| 138 ///Handle RNS |
| 139 void SetRns(Ptr<rns::Rns<Ipv4Address> > rns) {m_rns = rns;} |
| 140 void UpdateFromRns(rns::Neighbor<Ipv4Address> n); |
| 141 void PrintPowersAndRanges(Ptr<OutputStreamWrapper> stream); |
| 142 |
| 143 private: |
| 144 |
| 145 /// Configure the protocol before it starts |
| 146 void Start (void); |
| 147 ///\name Protocol parameters. |
| 148 //\{ |
| 149 /// Time between configuration phases in [s] |
| 150 Time ReconfigurationInterval; |
| 151 /// Interval between reconfiguration broadcast and RT update in [ms]. Useful i
f nodes work synchronously. |
| 152 Time UpdateFromBroadcastInterval; |
| 153 /// How accurate should the automatic range estimation be [m]. |
| 154 double RangeEstimationAccuracy; |
| 155 /// Enables RNS usage |
| 156 bool EnableRns; |
| 157 /// Maximum Age |
| 158 uint32_t MaxAge; |
| 159 //\} |
| 160 |
| 161 Ipv4Address m_id; |
| 162 |
| 163 bool m_rrOpen; |
| 164 uint32_t m_powerLevels; |
| 165 double* m_radioRange; |
| 166 |
| 167 RoutingTable m_routingTable; |
| 168 |
| 169 /// Mobility model, used to obtain position. |
| 170 Ptr<MobilityModel> m_mobility; |
| 171 |
| 172 Ptr<rns::Rns<Ipv4Address> > m_rns; |
| 173 |
| 174 /// Yans Wifi Phy model, for communication cost estimation. |
| 175 Ptr<YansWifiPhy> m_yansWifiPhy; |
| 176 /// Propagation Loss Model of this network, for communication cost estimation. |
| 177 Ptr<PropagationLossModel> m_propagationLossModel; |
| 178 |
| 179 /// Pointer to Rns module (only with EnableRns set to true) |
| 180 // Ptr<Rns<Ipv4Address> > m_rns; |
| 181 |
| 182 /// IP protocol |
| 183 Ptr<Ipv4> m_ipv4; |
| 184 /// Raw socket per each IP interface, map socket -> iface address (IP + mask) |
| 185 std::map< Ptr<Socket>, Ipv4InterfaceAddress > m_socketAddresses; |
| 186 /// Loopback device |
| 187 Ptr<NetDevice> m_lo; |
| 188 |
| 189 /// Provides uniform random variables. |
| 190 Ptr<UniformRandomVariable> m_uniformRandomVariable; |
| 191 |
| 192 uint16_t m_prevPacketId; |
| 193 Ipv4Address m_prevPacketSource; |
| 194 |
| 195 /// Reconfiguration period timer |
| 196 Timer m_reconfigrationTimer; |
| 197 void ReconfigurationTimerExpire(); |
| 198 /// Update timer |
| 199 Timer m_updateTimer; |
| 200 void UpdateTimerExpire(); |
| 201 |
| 202 /// Checks if the given address is this device's own address |
| 203 bool IsMyOwnAddress(Ipv4Address addr); |
| 204 |
| 205 /// Find socket with Ip Address |
| 206 Ptr<Socket> FindSocketWithInterfaceAddress (Ipv4InterfaceAddress iface) const; |
| 207 |
| 208 bool Forwarding (Ptr<const Packet> p, const Ipv4Header & header, |
| 209 UnicastForwardCallback ucb, ErrorCallback ecb); |
| 210 |
| 211 /** |
| 212 * @brief Increase the current phy power level. |
| 213 * |
| 214 * @retval true If the power level could be increased. |
| 215 * @retval false If the power level is at its highest already. |
| 216 */ |
| 217 bool IncreasePower(void); |
| 218 /** |
| 219 * @brief Browse through the routing table and choose the optimal power lvl. |
| 220 * |
| 221 * Each entry has its own power level, that will be used during |
| 222 * communication. |
| 223 * This function sets the minimum possible power level found in the routing |
| 224 * table. This power level and range will be visible to external modules as |
| 225 * this node's settings. |
| 226 * |
| 227 * @return current power level |
| 228 */ |
| 229 uint8_t SetPower (void); |
| 230 }; |
| 231 |
| 232 |
| 233 } // namespace smecn |
| 234 } // namespace ns3 |
| 235 |
| 236 #endif /* SMECN_ROUTING_PROTOCOL_H_ */ |
OLD | NEW |