A Discrete-Event Network Simulator
API
mock-net-device.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2020 Universita' di Firenze, Italy
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: Tommaso Pecorella <tommaso.pecorella@unifi.it>
19  */
20 #ifndef MOCK_NET_DEVICE_H
21 #define MOCK_NET_DEVICE_H
22 
23 #include <stdint.h>
24 #include <string>
25 
26 #include "ns3/traced-callback.h"
27 #include "ns3/net-device.h"
28 
29 namespace ns3 {
30 
31 class Node;
32 
47 class MockNetDevice : public NetDevice
48 {
49 public:
54  static TypeId GetTypeId (void);
55  MockNetDevice ();
56 
69  void Receive (Ptr<Packet> packet, uint16_t protocol, Address to, Address from, NetDevice::PacketType packetType);
70 
71  // inherited from NetDevice base class.
72  virtual void SetIfIndex (const uint32_t index);
73  virtual uint32_t GetIfIndex (void) const;
74  virtual Ptr<Channel> GetChannel (void) const;
75  virtual void SetAddress (Address address);
76  virtual Address GetAddress (void) const;
77  virtual bool SetMtu (const uint16_t mtu);
78  virtual uint16_t GetMtu (void) const;
79  virtual bool IsLinkUp (void) const;
80  virtual void AddLinkChangeCallback (Callback<void> callback);
81  virtual bool IsBroadcast (void) const;
82  virtual Address GetBroadcast (void) const;
83  virtual bool IsMulticast (void) const;
84  virtual Address GetMulticast (Ipv4Address multicastGroup) const;
85  virtual Address GetMulticast (Ipv6Address addr) const;
86  virtual bool IsPointToPoint (void) const;
87  virtual bool IsBridge (void) const;
88  virtual bool Send (Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber);
89  virtual bool SendFrom (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber);
90  virtual Ptr<Node> GetNode (void) const;
91  virtual void SetNode (Ptr<Node> node);
92  virtual bool NeedsArp (void) const;
95  virtual bool SupportsSendFrom (void) const;
96 
107 
108 protected:
109  virtual void DoDispose (void);
110 
111 private:
112 
117  uint16_t m_mtu;
118  uint32_t m_ifIndex;
120 
121  bool m_linkUp;
123 
128 };
129 
130 } // namespace ns3
131 
132 #endif /* MOCK_NET_DEVICE_H */
ns3::TypeId
a unique identifier for an interface.
Definition: type-id.h:59
ns3::MockNetDevice::NeedsArp
virtual bool NeedsArp(void) const
Definition: mock-net-device.cc:298
ns3::MockNetDevice::IsMulticast
virtual bool IsMulticast(void) const
Definition: mock-net-device.cc:185
ns3::Callback< void >
ns3::MockNetDevice::m_ifIndex
uint32_t m_ifIndex
Interface index.
Definition: mock-net-device.h:118
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::MockNetDevice::IsBroadcast
virtual bool IsBroadcast(void) const
Definition: mock-net-device.cc:146
ns3::MockNetDevice::m_linkUp
bool m_linkUp
Flag indicating whether or not the link is up.
Definition: mock-net-device.h:121
ns3::MockNetDevice::MockNetDevice
MockNetDevice()
Definition: mock-net-device.cc:55
ns3::MockNetDevice::GetMtu
virtual uint16_t GetMtu(void) const
Definition: mock-net-device.cc:125
ns3::Ipv4Address
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
ns3::Ipv6Address
Describes an IPv6 address.
Definition: ipv6-address.h:50
ns3::MockNetDevice::m_mtu
uint16_t m_mtu
MTU.
Definition: mock-net-device.h:117
ns3::MockNetDevice::SetIfIndex
virtual void SetIfIndex(const uint32_t index)
Definition: mock-net-device.cc:82
ns3::MockNetDevice::m_pointToPointMode
bool m_pointToPointMode
Enabling this will disable Broadcast and Arp.
Definition: mock-net-device.h:122
ns3::MockNetDevice::IsPointToPoint
virtual bool IsPointToPoint(void) const
Return true if the net device is on a point-to-point link.
Definition: mock-net-device.cc:241
ns3::MockNetDevice::m_linkChangeCallbacks
TracedCallback m_linkChangeCallbacks
List of callbacks to fire if the link changes state (up or down).
Definition: mock-net-device.h:127
ns3::MockNetDevice::GetAddress
virtual Address GetAddress(void) const
Definition: mock-net-device.cc:110
ns3::Ptr< Packet >
ns3::MockNetDevice::SetMtu
virtual bool SetMtu(const uint16_t mtu)
Definition: mock-net-device.cc:117
ns3::MockNetDevice::m_promiscCallback
NetDevice::PromiscReceiveCallback m_promiscCallback
Promiscuous receive callback.
Definition: mock-net-device.h:114
ns3::MockNetDevice::GetChannel
virtual Ptr< Channel > GetChannel(void) const
Definition: mock-net-device.cc:96
ns3::Address
a polymophic address class
Definition: address.h:91
ns3::MockNetDevice::Receive
void Receive(Ptr< Packet > packet, uint16_t protocol, Address to, Address from, NetDevice::PacketType packetType)
Pretend that a packet has been received from a connected Channel.
Definition: mock-net-device.cc:65
ns3::MockNetDevice::Send
virtual bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber)
Definition: mock-net-device.cc:259
ns3::MockNetDevice::SetAddress
virtual void SetAddress(Address address)
Set the address of this interface.
Definition: mock-net-device.cc:103
first.address
address
Definition: first.py:44
ns3::MockNetDevice::AddLinkChangeCallback
virtual void AddLinkChangeCallback(Callback< void > callback)
Definition: mock-net-device.cc:139
ns3::MockNetDevice::GetNode
virtual Ptr< Node > GetNode(void) const
Definition: mock-net-device.cc:285
ns3::MockNetDevice
This device assumes 48-bit mac addressing; there is also the possibility to add an ErrorModel if you ...
Definition: mock-net-device.h:48
ns3::MockNetDevice::m_rxCallback
NetDevice::ReceiveCallback m_rxCallback
Receive callback.
Definition: mock-net-device.h:113
ns3::MockNetDevice::SupportsSendFrom
virtual bool SupportsSendFrom(void) const
Definition: mock-net-device.cc:334
ns3::MockNetDevice::m_address
Address m_address
MAC address.
Definition: mock-net-device.h:119
ns3::MockNetDevice::SendFrom
virtual bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber)
Definition: mock-net-device.cc:267
ns3::MockNetDevice::SetNode
virtual void SetNode(Ptr< Node > node)
Definition: mock-net-device.cc:291
ns3::MockNetDevice::GetMulticast
virtual Address GetMulticast(Ipv4Address multicastGroup) const
Make and return a MAC multicast address using the provided multicast group.
Definition: mock-net-device.cc:205
ns3::MockNetDevice::SetPromiscReceiveCallback
virtual void SetPromiscReceiveCallback(PromiscReceiveCallback cb)
Definition: mock-net-device.cc:327
ns3::MockNetDevice::IsLinkUp
virtual bool IsLinkUp(void) const
Definition: mock-net-device.cc:132
ns3::MockNetDevice::m_node
Ptr< Node > m_node
Node this netDevice is associated to.
Definition: mock-net-device.h:116
ns3::NetDevice::PacketType
PacketType
Packet types are used as they are in Linux.
Definition: net-device.h:297
ns3::TracedCallback
Forward calls to a chain of Callback.
Definition: traced-callback.h:53
ns3::MockNetDevice::SetSendCallback
void SetSendCallback(PromiscReceiveCallback cb)
Add a callback to be invoked when the MockNetDevice has a packet to "send".
Definition: mock-net-device.cc:341
ns3::MockNetDevice::IsBridge
virtual bool IsBridge(void) const
Return true if the net device is acting as a bridge.
Definition: mock-net-device.cc:252
ns3::MockNetDevice::GetBroadcast
virtual Address GetBroadcast(void) const
Definition: mock-net-device.cc:166
ns3::MockNetDevice::SetReceiveCallback
virtual void SetReceiveCallback(NetDevice::ReceiveCallback cb)
Definition: mock-net-device.cc:309
ns3::MockNetDevice::m_sendCallback
NetDevice::PromiscReceiveCallback m_sendCallback
Send callback.
Definition: mock-net-device.h:115
ns3::MockNetDevice::GetIfIndex
virtual uint32_t GetIfIndex(void) const
Definition: mock-net-device.cc:89
ns3::NetDevice
Network layer to device interface.
Definition: net-device.h:96
ns3::MockNetDevice::DoDispose
virtual void DoDispose(void)
Destructor implementation.
Definition: mock-net-device.cc:316
ns3::MockNetDevice::GetTypeId
static TypeId GetTypeId(void)
Get the type ID.
Definition: mock-net-device.cc:40