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
48{
49 public:
54 static TypeId GetTypeId();
56
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
115
116 protected:
117 void DoDispose() override;
118
119 private:
124 uint16_t m_mtu;
127
128 bool m_linkUp;
130
135};
136
137} // namespace ns3
138
139#endif /* MOCK_NET_DEVICE_H */
a polymophic address class
Definition: address.h:100
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:78
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.