OLD | NEW |
(Empty) | |
| 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 /* |
| 3 * Copyright (c) 2017 University of Padova |
| 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: Davide Magrin <magrinda@dei.unipd.it> |
| 19 */ |
| 20 |
| 21 #ifndef LORA_NET_DEVICE_H |
| 22 #define LORA_NET_DEVICE_H |
| 23 |
| 24 #include "ns3/net-device.h" |
| 25 #include "ns3/lora-channel.h" |
| 26 #include "ns3/lora-phy.h" |
| 27 #include "ns3/lora-mac.h" |
| 28 |
| 29 namespace ns3 { |
| 30 |
| 31 class LoraChannel; |
| 32 class LoraPhy; |
| 33 class LoraMac; |
| 34 |
| 35 /** |
| 36 * Hold together all LoRa related objects. |
| 37 * |
| 38 * This class holds together pointers to LoraChannel, LoraPhy and LoraMac, |
| 39 * exposing methods through which Application instances can send packets. The |
| 40 * Application only needs to craft its packets, the NetDevice will take care of |
| 41 * calling the LoraMac's Send method with the appropriate parameters. |
| 42 */ |
| 43 class LoraNetDevice : public NetDevice |
| 44 { |
| 45 public: |
| 46 static TypeId GetTypeId (void); |
| 47 |
| 48 // Constructor and destructor |
| 49 LoraNetDevice (); |
| 50 virtual ~LoraNetDevice (); |
| 51 |
| 52 /** |
| 53 * Set which LoraMac instance is linked to this device. |
| 54 * |
| 55 * \param mac the mac layer to use. |
| 56 */ |
| 57 void SetMac (Ptr<LoraMac> mac); |
| 58 |
| 59 /** |
| 60 * Set which LoraPhy instance is linked to this device. |
| 61 * |
| 62 * \param phy the phy layer to use. |
| 63 */ |
| 64 void SetPhy (Ptr<LoraPhy> phy); |
| 65 |
| 66 /** |
| 67 * Get the LoraMac instance that is linked to this NetDevice. |
| 68 * |
| 69 * \return the mac we are currently using. |
| 70 */ |
| 71 Ptr<LoraMac> GetMac (void) const; |
| 72 |
| 73 /** |
| 74 * Get the LoraPhy instance that is linked to this NetDevice. |
| 75 * |
| 76 * \return the phy we are currently using. |
| 77 */ |
| 78 Ptr<LoraPhy> GetPhy (void) const; |
| 79 |
| 80 /** |
| 81 * Send a packet through the LoRaWAN stack. |
| 82 * |
| 83 * \param packet The packet to send. |
| 84 */ |
| 85 void Send (Ptr<Packet> packet); |
| 86 |
| 87 /** |
| 88 * Callback the Mac layer calls whenever a packet arrives and needs to be |
| 89 * forwarded up the stack. |
| 90 * |
| 91 * \param packet The packet that was received. |
| 92 */ |
| 93 void Receive (Ptr<Packet> packet); |
| 94 |
| 95 // From class NetDevice. Some of these have little meaning for a LoRaWAN |
| 96 // network device (since, for instance, IP is not used in the standard) |
| 97 virtual void SetReceiveCallback (NetDevice::ReceiveCallback cb); |
| 98 virtual Ptr<Channel> GetChannel (void) const; |
| 99 virtual void SetNode (Ptr<Node> node); |
| 100 virtual Ptr<Node> GetNode (void) const; |
| 101 |
| 102 virtual void SetIfIndex (const uint32_t index); |
| 103 virtual uint32_t GetIfIndex (void) const; |
| 104 virtual void SetAddress (Address address); |
| 105 virtual Address GetAddress (void) const; |
| 106 virtual bool SetMtu (const uint16_t mtu); |
| 107 virtual uint16_t GetMtu (void) const; |
| 108 virtual bool IsLinkUp (void) const; |
| 109 virtual void AddLinkChangeCallback (Callback<void> callback); |
| 110 virtual bool IsBroadcast (void) const; |
| 111 virtual Address GetBroadcast (void) const; |
| 112 virtual bool IsMulticast (void) const; |
| 113 virtual Address GetMulticast (Ipv4Address multicastGroup) const; |
| 114 virtual Address GetMulticast (Ipv6Address addr) const; |
| 115 virtual bool IsBridge (void) const; |
| 116 virtual bool IsPointToPoint (void) const; |
| 117 virtual bool Send (Ptr<Packet> packet, const Address& dest, uint16_t protocolN
umber); |
| 118 virtual bool SendFrom (Ptr<Packet> packet, const Address& source, const Addres
s& dest, uint16_t protocolNumber); |
| 119 virtual bool NeedsArp (void) const; |
| 120 virtual void SetPromiscReceiveCallback (PromiscReceiveCallback cb); |
| 121 virtual bool SupportsSendFrom (void) const; |
| 122 |
| 123 protected: |
| 124 |
| 125 /** |
| 126 * Receive a packet from the lower layer and pass the |
| 127 * packet up the stack. |
| 128 * |
| 129 * \param packet The packet we need to forward. |
| 130 * \param from The from address. |
| 131 * \param to The to address. |
| 132 */ |
| 133 void ForwardUp (Ptr<Packet> packet, Mac48Address from, Mac48Address to); |
| 134 |
| 135 private: |
| 136 |
| 137 /** |
| 138 * Return the LoraChannel this device is connected to. |
| 139 */ |
| 140 Ptr<LoraChannel> DoGetChannel (void) const; |
| 141 |
| 142 /** |
| 143 * Complete the configuration of this LoRa device by connecting all lower |
| 144 * components (PHY, MAC, Channel) together. |
| 145 */ |
| 146 void CompleteConfig (void); |
| 147 |
| 148 // Member variables |
| 149 Ptr<Node> m_node; //!< The Node this NetDevice is connected to. |
| 150 Ptr<LoraPhy> m_phy; //!< The LoraPhy this NetDevice is connected to. |
| 151 Ptr<LoraMac> m_mac; //!< The LoraMac this NetDevice is connected to. |
| 152 bool m_configComplete; //!< Whether the configuration was already completed. |
| 153 |
| 154 /** |
| 155 * Upper layer callback used for notification of new data packet arrivals. |
| 156 */ |
| 157 NetDevice::ReceiveCallback m_receiveCallback; |
| 158 }; |
| 159 |
| 160 } //namespace ns3 |
| 161 |
| 162 #endif /* LORA_NET_DEVICE_H */ |
OLD | NEW |