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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Tommaso Pecorella <tommaso.pecorella@unifi.it>
7 */
8#ifndef MOCK_NET_DEVICE_H
9#define MOCK_NET_DEVICE_H
10
11#include "ns3/net-device.h"
12#include "ns3/traced-callback.h"
13
14#include <stdint.h>
15#include <string>
16
17namespace ns3
18{
19
20class Node;
21
22/**
23 * \ingroup netdevice
24 *
25 * This device assumes 48-bit mac addressing; there is also the possibility to
26 * add an ErrorModel if you want to force losses on the device.
27 *
28 * The device can be installed on a node through the MockNetDeviceHelper.
29 * In case of manual creation, the user is responsible for assigning an unique
30 * address to the device.
31 *
32 * By default the device is in Broadcast mode, with infinite bandwidth.
33 *
34 * \brief simple net device for simple things and testing
35 */
37{
38 public:
39 /**
40 * \brief Get the type ID.
41 * \return the object TypeId
42 */
43 static TypeId GetTypeId();
45
46 /**
47 * Pretend that a packet has been received from a connected Channel.
48 *
49 * Note that no analysis is performed on the addresses, and the
50 * packet is forwarded to the callbacks according to the packetType.
51 *
52 * \param packet Packet received on the channel
53 * \param protocol protocol number
54 * \param to address packet should be sent to
55 * \param from address packet was sent from
56 * \param packetType type of the packet (e.g., NetDevice::PACKET_HOST,
57 * NetDevice::PACKET_OTHERHOST, etc.)
58 */
59 void Receive(Ptr<Packet> packet,
60 uint16_t protocol,
61 Address to,
62 Address from,
63 NetDevice::PacketType packetType);
64
65 // inherited from NetDevice base class.
66 void SetIfIndex(const uint32_t index) override;
67 uint32_t GetIfIndex() const override;
68 Ptr<Channel> GetChannel() const override;
69 void SetAddress(Address address) override;
70 Address GetAddress() const override;
71 bool SetMtu(const uint16_t mtu) override;
72 uint16_t GetMtu() const override;
73 bool IsLinkUp() const override;
74 void AddLinkChangeCallback(Callback<void> callback) override;
75 bool IsBroadcast() const override;
76 Address GetBroadcast() const override;
77 bool IsMulticast() const override;
78 Address GetMulticast(Ipv4Address multicastGroup) const override;
79 Address GetMulticast(Ipv6Address addr) const override;
80 bool IsPointToPoint() const override;
81 bool IsBridge() const override;
82 bool Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber) override;
83 bool SendFrom(Ptr<Packet> packet,
84 const Address& source,
85 const Address& dest,
86 uint16_t protocolNumber) override;
87 Ptr<Node> GetNode() const override;
88 void SetNode(Ptr<Node> node) override;
89 bool NeedsArp() const override;
92 bool SupportsSendFrom() const override;
93
94 /**
95 *
96 * Add a callback to be invoked when the MockNetDevice has a packet to "send".
97 *
98 * In the callback the PacketType is always set to NetDevice::PACKET_HOST.
99 *
100 * \param cb callback to invoke whenever the MockNetDevice has one packet to "send".
101 *
102 */
104
105 protected:
106 void DoDispose() override;
107
108 private:
110 NetDevice::PromiscReceiveCallback m_promiscCallback; //!< Promiscuous receive callback
112 Ptr<Node> m_node; //!< Node this netDevice is associated to
113 uint16_t m_mtu; //!< MTU
114 uint32_t m_ifIndex; //!< Interface index
115 Address m_address; //!< MAC address
116
117 bool m_linkUp; //!< Flag indicating whether or not the link is up
118 bool m_pointToPointMode; //!< Enabling this will disable Broadcast and Arp.
119
120 /**
121 * List of callbacks to fire if the link changes state (up or down).
122 */
124};
125
126} // namespace ns3
127
128#endif /* MOCK_NET_DEVICE_H */
a polymophic address class
Definition address.h:90
Callback template class.
Definition callback.h:422
Ipv4 addresses are stored in host order in this class.
Describes an IPv6 address.
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:87
PacketType
Packet types are used as they are in Linux.
Definition net-device.h:289
Smart pointer class similar to boost::intrusive_ptr.
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition type-id.h:48
Every class exported by the ns3 library is enclosed in the ns3 namespace.