A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ipv4-end-point.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2005 INRIA
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
7 */
8
9#include "ipv4-end-point.h"
10
11#include "ns3/log.h"
12#include "ns3/packet.h"
13#include "ns3/simulator.h"
14
15namespace ns3
16{
17
18NS_LOG_COMPONENT_DEFINE("Ipv4EndPoint");
19
21 : m_localAddr(address),
22 m_localPort(port),
23 m_peerAddr(Ipv4Address::GetAny()),
24 m_peerPort(0),
25 m_rxEnabled(true)
26{
27 NS_LOG_FUNCTION(this << address << port);
28}
29
31{
32 NS_LOG_FUNCTION(this);
34 {
36 }
37 m_rxCallback.Nullify();
38 m_icmpCallback.Nullify();
40}
41
44{
45 NS_LOG_FUNCTION(this);
46 return m_localAddr;
47}
48
49void
51{
52 NS_LOG_FUNCTION(this << address);
53 m_localAddr = address;
54}
55
56uint16_t
58{
59 NS_LOG_FUNCTION(this);
60 return m_localPort;
61}
62
65{
66 NS_LOG_FUNCTION(this);
67 return m_peerAddr;
68}
69
70uint16_t
72{
73 NS_LOG_FUNCTION(this);
74 return m_peerPort;
75}
76
77void
79{
80 NS_LOG_FUNCTION(this << address << port);
81 m_peerAddr = address;
83}
84
85void
87{
88 NS_LOG_FUNCTION(this << netdevice);
89 m_boundnetdevice = netdevice;
90}
91
98
99void
101 Callback<void, Ptr<Packet>, Ipv4Header, uint16_t, Ptr<Ipv4Interface>> callback)
102{
103 NS_LOG_FUNCTION(this << &callback);
104 m_rxCallback = callback;
105}
106
107void
114
115void
117{
118 NS_LOG_FUNCTION(this << &callback);
119 m_destroyCallback = callback;
120}
121
122void
124 const Ipv4Header& header,
125 uint16_t sport,
126 Ptr<Ipv4Interface> incomingInterface)
127{
128 NS_LOG_FUNCTION(this << p << &header << sport << incomingInterface);
129
130 if (!m_rxCallback.IsNull())
131 {
132 m_rxCallback(p, header, sport, incomingInterface);
133 }
134}
135
136void
138 uint8_t icmpTtl,
139 uint8_t icmpType,
140 uint8_t icmpCode,
141 uint32_t icmpInfo)
142{
143 NS_LOG_FUNCTION(this << icmpSource << (uint32_t)icmpTtl << (uint32_t)icmpType
144 << (uint32_t)icmpCode << icmpInfo);
145 if (!m_icmpCallback.IsNull())
146 {
147 m_icmpCallback(icmpSource, icmpTtl, icmpType, icmpCode, icmpInfo);
148 }
149}
150
151void
153{
154 m_rxEnabled = enabled;
155}
156
157bool
159{
160 return m_rxEnabled;
161}
162
163} // namespace ns3
Callback template class.
Definition callback.h:422
void Nullify()
Discard the implementation, set it to null.
Definition callback.h:561
bool IsNull() const
Check for null implementation.
Definition callback.h:555
Ipv4 addresses are stored in host order in this class.
bool m_rxEnabled
true if the endpoint can receive packets.
void BindToNetDevice(Ptr< NetDevice > netdevice)
Bind a socket to specific device.
Callback< void, Ipv4Address, uint8_t, uint8_t, uint8_t, uint32_t > m_icmpCallback
The ICMPv6 callback.
void SetDestroyCallback(Callback< void > callback)
Set the default destroy callback.
Ipv4Address GetLocalAddress() const
Get the local address.
void SetLocalAddress(Ipv4Address address)
Set the local address.
uint16_t GetPeerPort() const
Get the peer port.
void ForwardUp(Ptr< Packet > p, const Ipv4Header &header, uint16_t sport, Ptr< Ipv4Interface > incomingInterface)
Forward the packet to the upper level.
void ForwardIcmp(Ipv4Address icmpSource, uint8_t icmpTtl, uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo)
Forward the ICMP packet to the upper level.
uint16_t m_localPort
The local port.
Ptr< NetDevice > GetBoundNetDevice() const
Returns socket's bound netdevice, if any.
Ipv4EndPoint(Ipv4Address address, uint16_t port)
Constructor.
uint16_t GetLocalPort() const
Get the local port.
bool IsRxEnabled() const
Checks if the endpoint can receive packets.
void SetRxEnabled(bool enabled)
Enable or Disable the endpoint Rx capability.
Ipv4Address GetPeerAddress() const
Get the peer address.
Ipv4Address m_peerAddr
The peer address.
uint16_t m_peerPort
The peer port.
Ptr< NetDevice > m_boundnetdevice
The NetDevice the EndPoint is bound to (if any).
void SetIcmpCallback(Callback< void, Ipv4Address, uint8_t, uint8_t, uint8_t, uint32_t > callback)
Set the ICMP callback.
void SetPeer(Ipv4Address address, uint16_t port)
Set the peer information (address and port).
void SetRxCallback(Callback< void, Ptr< Packet >, Ipv4Header, uint16_t, Ptr< Ipv4Interface > > callback)
Set the reception callback.
Ipv4Address m_localAddr
The local address.
Callback< void > m_destroyCallback
The destroy callback.
Callback< void, Ptr< Packet >, Ipv4Header, uint16_t, Ptr< Ipv4Interface > > m_rxCallback
The RX callback.
Packet header for IPv4.
Definition ipv4-header.h:23
Smart pointer class similar to boost::intrusive_ptr.
uint16_t port
Definition dsdv-manet.cc:33
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Every class exported by the ns3 library is enclosed in the ns3 namespace.