A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
loopback-net-device.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008 INRIA
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
7 */
8#ifndef LOOPBACK_NET_DEVICE_H
9#define LOOPBACK_NET_DEVICE_H
10
11#include "ns3/mac48-address.h"
12#include "ns3/net-device.h"
13
14#include <stdint.h>
15#include <string>
16
17namespace ns3
18{
19
20class Node;
21
22/**
23 * \ingroup netdevice
24 * \ingroup internet
25 *
26 * \brief Virtual network interface that loops back any data sent to it to
27 * be immediately received on the same interface.
28 *
29 * This NetDevice is automatically added to any node as soon as the Internet
30 * stack is initialized.
31 */
33{
34 public:
35 /**
36 * \brief Get the type ID.
37 * \return the object TypeId
38 */
39 static TypeId GetTypeId();
41
42 // inherited from NetDevice base class.
43 void SetIfIndex(const uint32_t index) override;
44 uint32_t GetIfIndex() const override;
45 Ptr<Channel> GetChannel() const override;
46 void SetAddress(Address address) override;
47 Address GetAddress() const override;
48 bool SetMtu(const uint16_t mtu) override;
49 uint16_t GetMtu() const override;
50 bool IsLinkUp() const override;
51 void AddLinkChangeCallback(Callback<void> callback) override;
52 bool IsBroadcast() const override;
53 Address GetBroadcast() const override;
54 bool IsMulticast() const override;
55 Address GetMulticast(Ipv4Address multicastGroup) const override;
56 bool IsPointToPoint() const override;
57 bool IsBridge() const override;
58 bool Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber) override;
59 bool SendFrom(Ptr<Packet> packet,
60 const Address& source,
61 const Address& dest,
62 uint16_t protocolNumber) override;
63 Ptr<Node> GetNode() const override;
64 void SetNode(Ptr<Node> node) override;
65 bool NeedsArp() const override;
67
68 Address GetMulticast(Ipv6Address addr) const override;
69
71 bool SupportsSendFrom() const override;
72
73 protected:
74 void DoDispose() override;
75
76 private:
77 /**
78 * Receive a packet from tge Loopback NetDevice.
79 *
80 * \param packet a reference to the received packet
81 * \param protocol the protocol
82 * \param to destination address
83 * \param from source address
84 */
85 void Receive(Ptr<Packet> packet, uint16_t protocol, Mac48Address to, Mac48Address from);
86
87 /**
88 * The callback used to notify higher layers that a packet has been received.
89 */
91
92 /**
93 * The callback used to notify higher layers that a packet has been received in promiscuous
94 * mode.
95 */
97
98 Ptr<Node> m_node; //!< the node this NetDevice is associated with
99 uint16_t m_mtu; //!< device MTU
100 uint32_t m_ifIndex; //!< interface index
101 Mac48Address m_address; //!< NetDevice MAC address
102};
103
104} // namespace ns3
105
106#endif /* LOOPBACK_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.
Virtual network interface that loops back any data sent to it to be immediately received on the same ...
static TypeId GetTypeId()
Get the type ID.
bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber) override
void DoDispose() override
Destructor implementation.
uint32_t m_ifIndex
interface index
bool IsMulticast() const override
void Receive(Ptr< Packet > packet, uint16_t protocol, Mac48Address to, Mac48Address from)
Receive a packet from tge Loopback NetDevice.
bool IsBridge() const override
Return true if the net device is acting as a bridge.
bool NeedsArp() const override
Ptr< Node > GetNode() const override
uint16_t GetMtu() const override
Address GetMulticast(Ipv4Address multicastGroup) const override
Make and return a MAC multicast address using the provided multicast group.
Ptr< Node > m_node
the node this NetDevice is associated with
bool IsBroadcast() const override
void SetIfIndex(const uint32_t index) override
bool IsLinkUp() const override
bool IsPointToPoint() const override
Return true if the net device is on a point-to-point link.
Mac48Address m_address
NetDevice MAC address.
uint32_t GetIfIndex() const override
NetDevice::ReceiveCallback m_rxCallback
The callback used to notify higher layers that a packet has been received.
void SetReceiveCallback(NetDevice::ReceiveCallback cb) override
void AddLinkChangeCallback(Callback< void > callback) override
Address GetAddress() const override
bool SupportsSendFrom() const override
NetDevice::PromiscReceiveCallback m_promiscCallback
The callback used to notify higher layers that a packet has been received in promiscuous mode.
void SetAddress(Address address) override
Set the address of this interface.
bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber) override
void SetPromiscReceiveCallback(PromiscReceiveCallback cb) override
Ptr< Channel > GetChannel() const override
bool SetMtu(const uint16_t mtu) override
Address GetBroadcast() const override
void SetNode(Ptr< Node > node) override
an EUI-48 address
Network layer to device interface.
Definition net-device.h:87
Smart pointer class similar to boost::intrusive_ptr.
a unique identifier for an interface.
Definition type-id.h:48
Every class exported by the ns3 library is enclosed in the ns3 namespace.