A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
mock-net-device.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Universita' di Firenze, Italy
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Tommaso Pecorella <tommaso.pecorella@unifi.it>
18 */
19#ifndef MOCK_NET_DEVICE_H
20#define MOCK_NET_DEVICE_H
21
22#include "ns3/net-device.h"
23#include "ns3/traced-callback.h"
24
25#include <stdint.h>
26#include <string>
27
28namespace ns3
29{
30
31class Node;
32
33/**
34 * \ingroup netdevice
35 *
36 * This device assumes 48-bit mac addressing; there is also the possibility to
37 * add an ErrorModel if you want to force losses on the device.
38 *
39 * The device can be installed on a node through the MockNetDeviceHelper.
40 * In case of manual creation, the user is responsible for assigning an unique
41 * address to the device.
42 *
43 * By default the device is in Broadcast mode, with infinite bandwidth.
44 *
45 * \brief simple net device for simple things and testing
46 */
48{
49 public:
50 /**
51 * \brief Get the type ID.
52 * \return the object TypeId
53 */
54 static TypeId GetTypeId();
56
57 /**
58 * Pretend that a packet has been received from a connected Channel.
59 *
60 * Note that no analysis is performed on the addresses, and the
61 * packet is forwarded to the callbacks according to the packetType.
62 *
63 * \param packet Packet received on the channel
64 * \param protocol protocol number
65 * \param to address packet should be sent to
66 * \param from address packet was sent from
67 * \param packetType type of the packet (e.g., NetDevice::PACKET_HOST,
68 * NetDevice::PACKET_OTHERHOST, etc.)
69 */
70 void Receive(Ptr<Packet> packet,
71 uint16_t protocol,
72 Address to,
73 Address from,
74 NetDevice::PacketType packetType);
75
76 // inherited from NetDevice base class.
77 void SetIfIndex(const uint32_t index) override;
78 uint32_t GetIfIndex() const override;
79 Ptr<Channel> GetChannel() const override;
80 void SetAddress(Address address) override;
81 Address GetAddress() const override;
82 bool SetMtu(const uint16_t mtu) override;
83 uint16_t GetMtu() const override;
84 bool IsLinkUp() const override;
85 void AddLinkChangeCallback(Callback<void> callback) override;
86 bool IsBroadcast() const override;
87 Address GetBroadcast() const override;
88 bool IsMulticast() const override;
89 Address GetMulticast(Ipv4Address multicastGroup) const override;
90 Address GetMulticast(Ipv6Address addr) const override;
91 bool IsPointToPoint() const override;
92 bool IsBridge() const override;
93 bool Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber) override;
94 bool SendFrom(Ptr<Packet> packet,
95 const Address& source,
96 const Address& dest,
97 uint16_t protocolNumber) override;
98 Ptr<Node> GetNode() const override;
99 void SetNode(Ptr<Node> node) override;
100 bool NeedsArp() const override;
103 bool SupportsSendFrom() const override;
104
105 /**
106 *
107 * Add a callback to be invoked when the MockNetDevice has a packet to "send".
108 *
109 * In the callback the PacketType is always set to NetDevice::PACKET_HOST.
110 *
111 * \param cb callback to invoke whenever the MockNetDevice has one packet to "send".
112 *
113 */
115
116 protected:
117 void DoDispose() override;
118
119 private:
121 NetDevice::PromiscReceiveCallback m_promiscCallback; //!< Promiscuous receive callback
123 Ptr<Node> m_node; //!< Node this netDevice is associated to
124 uint16_t m_mtu; //!< MTU
125 uint32_t m_ifIndex; //!< Interface index
126 Address m_address; //!< MAC address
127
128 bool m_linkUp; //!< Flag indicating whether or not the link is up
129 bool m_pointToPointMode; //!< Enabling this will disable Broadcast and Arp.
130
131 /**
132 * List of callbacks to fire if the link changes state (up or down).
133 */
135};
136
137} // namespace ns3
138
139#endif /* MOCK_NET_DEVICE_H */
a polymophic address class
Definition: address.h:101
Callback template class.
Definition: callback.h:438
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
Describes an IPv6 address.
Definition: ipv6-address.h:49
This device assumes 48-bit mac addressing; there is also the possibility to add an ErrorModel if you ...
Ptr< Node > m_node
Node this netDevice is associated to.
void DoDispose() override
Destructor implementation.
uint32_t m_ifIndex
Interface index.
void AddLinkChangeCallback(Callback< void > callback) override
uint16_t GetMtu() const override
bool IsPointToPoint() const override
Return true if the net device is on a point-to-point link.
bool IsLinkUp() const override
void SetSendCallback(PromiscReceiveCallback cb)
Add a callback to be invoked when the MockNetDevice has a packet to "send".
bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber) override
bool IsMulticast() const override
void SetReceiveCallback(NetDevice::ReceiveCallback cb) override
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.
Ptr< Node > GetNode() const override
void SetIfIndex(const uint32_t index) override
static TypeId GetTypeId()
Get the type ID.
NetDevice::PromiscReceiveCallback m_sendCallback
Send callback.
bool SupportsSendFrom() const override
bool IsBridge() const override
Return true if the net device is acting as a bridge.
bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber) override
Address GetBroadcast() const override
bool IsBroadcast() const override
void SetNode(Ptr< Node > node) override
Address GetAddress() const override
TracedCallback m_linkChangeCallbacks
List of callbacks to fire if the link changes state (up or down).
bool m_pointToPointMode
Enabling this will disable Broadcast and Arp.
Ptr< Channel > GetChannel() const override
Address m_address
MAC address.
bool m_linkUp
Flag indicating whether or not the link is up.
void SetPromiscReceiveCallback(PromiscReceiveCallback cb) override
NetDevice::PromiscReceiveCallback m_promiscCallback
Promiscuous receive callback.
void SetAddress(Address address) override
Set the address of this interface.
bool NeedsArp() const override
uint32_t GetIfIndex() const override
bool SetMtu(const uint16_t mtu) override
Address GetMulticast(Ipv4Address multicastGroup) const override
Make and return a MAC multicast address using the provided multicast group.
NetDevice::ReceiveCallback m_rxCallback
Receive callback.
Network layer to device interface.
Definition: net-device.h:98
PacketType
Packet types are used as they are in Linux.
Definition: net-device.h:300
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition: type-id.h:59
Every class exported by the ns3 library is enclosed in the ns3 namespace.