1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 /* 3 * Copyright (c) 2008 INRIA 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> 19 */ 20 #ifndef LOOPBACK_NET_DEVICE_H 21 #define LOOPBACK_NET_DEVICE_H 22 23 #include "ns3/net-device.h" 24 #include "ns3/mac48-address.h" 25 #include <stdint.h> 26 #include <string> 27 28 namespace ns3 { 29 30 class Node; 31 32 /** 33 * \ingroup netdevice 34 * \ingroup internet 35 * 36 * \brief Virtual network interface that loops back any data sent to it to 37 * be immediately received on the same interface. 38 * 39 * This NetDevice is automatically added to any node as soon as the Internet 40 * stack is initialized. 41 */ 42 class LoopbackNetDevice : public NetDevice 43 { 44 public: 45 /** 46 * \brief Get the type ID. 47 * \return the object TypeId 48 */ 49 static TypeId GetTypeId (void); 50 LoopbackNetDevice (); 51 52 // inherited from NetDevice base class. 53 virtual void SetIfIndex (const uint32_t index); 54 virtual uint32_t GetIfIndex (void) const; 55 virtual Ptr<Channel> GetChannel (void) const; 56 virtual void SetAddress (Address address); 57 virtual Address GetAddress (void) const; 58 virtual bool SetMtu (const uint16_t mtu); 59 virtual uint16_t GetMtu (void) const; 60 virtual bool IsLinkUp (void) const; 61 virtual void AddLinkChangeCallback (Callback<void> callback); 62 virtual bool IsBroadcast (void) const; 63 virtual Address GetBroadcast (void) const; 64 virtual bool IsMulticast (void) const; 65 virtual Address GetMulticast (Ipv4Address multicastGroup) const; 66 virtual bool IsPointToPoint (void) const; 67 virtual bool IsBridge (void) const; 68 virtual bool Send (Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber); 69 virtual bool SendFrom (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber); 70 virtual Ptr<Node> GetNode (void) const; 71 virtual void SetNode (Ptr<Node> node); 72 virtual bool NeedsArp (void) const; 73 virtual void SetReceiveCallback (NetDevice::ReceiveCallback cb); 74 75 virtual Address GetMulticast (Ipv6Address addr) const; 76 77 virtual void SetPromiscReceiveCallback (PromiscReceiveCallback cb); 78 virtual bool SupportsSendFrom (void) const; 79 80 protected: 81 virtual void DoDispose (void); 82 private: 83 /** 84 * Receive a packet from tge Loopback NetDevice. 85 * 86 * \param packet a reference to the received packet 87 * \param protocol the protocol 88 * \param to destination address 89 * \param from source address 90 */ 91 void Receive (Ptr<Packet> packet, uint16_t protocol, Mac48Address to, Mac48Address from); 92 93 /** 94 * The callback used to notify higher layers that a packet has been received. 95 */ 96 NetDevice::ReceiveCallback m_rxCallback; 97 98 /** 99 * The callback used to notify higher layers that a packet has been received in promiscuous mode. 100 */ 101 NetDevice::PromiscReceiveCallback m_promiscCallback; 102 103 Ptr<Node> m_node; //!< the node this NetDevice is associated with 104 uint16_t m_mtu; //!< device MTU 105 uint32_t m_ifIndex; //!< interface index 106 Mac48Address m_address; //!< NetDevice MAC address 107 }; 108 109 } // namespace ns3 110 111 #endif /* LOOPBACK_NET_DEVICE_H */ 112