A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
sink-application.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2024 DERONNE SOFTWARE ENGINEERING
3
*
4
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
* Author: Sébastien Deronne <sebastien.deronne@gmail.com>
7
*/
8
9
#ifndef SINK_APPLICATION_H
10
#define SINK_APPLICATION_H
11
12
#include "ns3/address.h"
13
#include "ns3/application.h"
14
#include "ns3/traced-callback.h"
15
16
#include <limits>
17
18
namespace
ns3
19
{
20
21
class
Packet
;
22
class
Address
;
23
class
Socket
;
24
25
/**
26
* @ingroup applications
27
* @brief Base class for sink applications.
28
*
29
* This class can be used as a base class for sink applications.
30
* A sink application is an application that is primarily used to only receive or echo packets.
31
*
32
* The main purpose of this base class application public API is to hold attributes for the local
33
* (IPv4 or IPv6) address and port to bind to.
34
*
35
* There are three ways that the port value can be configured. First, and most typically, through
36
* the use of a socket address (InetSocketAddress or Inet6SocketAddress) that is configured as the
37
* Local address to bind to. Second, through direct configuration of the Port attribute. Third,
38
* through the use of an optional constructor argument. If multiple of these port configuration
39
* methods are used, it is up to subclass definition which one takes precedence; in the existing
40
* subclasses in this directory, the port value configured in the Local socket address (if a socket
41
* address is configured there) will take precedence.
42
*/
43
class
SinkApplication
:
public
Application
44
{
45
public
:
46
/**
47
* @brief Get the type ID.
48
* @return the object TypeId
49
*/
50
static
TypeId
GetTypeId
();
51
52
/**
53
* Constructor
54
*
55
* @param defaultPort the default port number
56
*/
57
SinkApplication
(uint16_t defaultPort = 0);
58
~SinkApplication
()
override
;
59
60
static
constexpr
uint32_t
INVALID_PORT
{std::numeric_limits<uint32_t>::max()};
//!< invalid port
61
62
protected
:
63
void
DoDispose
()
override
;
64
65
/**
66
* @brief Close all the sockets
67
* @return true if all sockets closed successfully, false otherwise
68
*/
69
bool
CloseAllSockets
();
70
71
/// Callbacks for tracing the packet Rx events
72
ns3::TracedCallback<Ptr<const Packet>
>
m_rxTraceWithoutAddress
;
73
74
/// Traced Callback: received packets, source address.
75
TracedCallback<Ptr<const Packet>
,
const
Address
&>
m_rxTrace
;
76
77
Ptr<Socket>
m_socket
;
//!< Socket (IPv4 or IPv6, depending on local address)
78
Ptr<Socket>
m_socket6
;
//!< IPv6 Socket (used if only port is specified)
79
80
TypeId
m_protocolTid
;
//!< Protocol TypeId value
81
82
Address
m_local
;
//!< Local address to bind to (address and port)
83
uint32_t
m_port
;
//!< Local port to bind to
84
85
private
:
86
void
StartApplication
()
override
;
87
void
StopApplication
()
override
;
88
89
/**
90
* @brief set the local address
91
* @param addr local address
92
*/
93
virtual
void
SetLocal
(
const
Address
& addr);
94
95
/**
96
* @brief get the local address
97
* @return the local address
98
*/
99
Address
GetLocal
()
const
;
100
101
/**
102
* @brief set the server port
103
* @param port server port
104
*/
105
virtual
void
SetPort
(
uint32_t
port
);
106
107
/**
108
* @brief get the server port
109
* @return the server port
110
*/
111
uint32_t
GetPort
()
const
;
112
113
/**
114
* @brief Close the socket
115
* @param socket the socket to close
116
* @return true if the socket closed successfully, false otherwise
117
*/
118
bool
CloseSocket
(
Ptr<Socket>
socket);
119
120
/**
121
* @brief Application specific startup code for child subclasses
122
*/
123
virtual
void
DoStartApplication
();
124
125
/**
126
* @brief Application specific shutdown code for child subclasses
127
*/
128
virtual
void
DoStopApplication
();
129
};
130
131
}
// namespace ns3
132
133
#endif
/* SINK_APPLICATION_H */
ns3::Address
a polymophic address class
Definition
address.h:90
ns3::Application::Application
Application()
Definition
application.cc:49
ns3::Packet
network packets
Definition
packet.h:228
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition
ptr.h:67
ns3::SinkApplication::INVALID_PORT
static constexpr uint32_t INVALID_PORT
invalid port
Definition
sink-application.h:60
ns3::SinkApplication::SetLocal
virtual void SetLocal(const Address &addr)
set the local address
Definition
sink-application.cc:74
ns3::SinkApplication::m_rxTraceWithoutAddress
ns3::TracedCallback< Ptr< const Packet > > m_rxTraceWithoutAddress
Callbacks for tracing the packet Rx events.
Definition
sink-application.h:72
ns3::SinkApplication::m_socket6
Ptr< Socket > m_socket6
IPv6 Socket (used if only port is specified).
Definition
sink-application.h:78
ns3::SinkApplication::StopApplication
void StopApplication() override
Application specific shutdown code.
Definition
sink-application.cc:122
ns3::SinkApplication::DoDispose
void DoDispose() override
Destructor implementation.
Definition
sink-application.cc:65
ns3::SinkApplication::m_protocolTid
TypeId m_protocolTid
Protocol TypeId value.
Definition
sink-application.h:80
ns3::SinkApplication::SinkApplication
SinkApplication(uint16_t defaultPort=0)
Constructor.
Definition
sink-application.cc:53
ns3::SinkApplication::DoStartApplication
virtual void DoStartApplication()
Application specific startup code for child subclasses.
Definition
sink-application.cc:157
ns3::SinkApplication::GetLocal
Address GetLocal() const
get the local address
Definition
sink-application.cc:81
ns3::SinkApplication::~SinkApplication
~SinkApplication() override
Definition
sink-application.cc:59
ns3::SinkApplication::GetPort
uint32_t GetPort() const
get the server port
Definition
sink-application.cc:98
ns3::SinkApplication::DoStopApplication
virtual void DoStopApplication()
Application specific shutdown code for child subclasses.
Definition
sink-application.cc:163
ns3::SinkApplication::StartApplication
void StartApplication() override
Application specific startup code.
Definition
sink-application.cc:104
ns3::SinkApplication::GetTypeId
static TypeId GetTypeId()
Get the type ID.
Definition
sink-application.cc:23
ns3::SinkApplication::m_local
Address m_local
Local address to bind to (address and port).
Definition
sink-application.h:82
ns3::SinkApplication::m_socket
Ptr< Socket > m_socket
Socket (IPv4 or IPv6, depending on local address).
Definition
sink-application.h:77
ns3::SinkApplication::CloseSocket
bool CloseSocket(Ptr< Socket > socket)
Close the socket.
Definition
sink-application.cc:139
ns3::SinkApplication::m_port
uint32_t m_port
Local port to bind to.
Definition
sink-application.h:83
ns3::SinkApplication::SetPort
virtual void SetPort(uint32_t port)
set the server port
Definition
sink-application.cc:87
ns3::SinkApplication::CloseAllSockets
bool CloseAllSockets()
Close all the sockets.
Definition
sink-application.cc:130
ns3::SinkApplication::m_rxTrace
TracedCallback< Ptr< const Packet >, const Address & > m_rxTrace
Traced Callback: received packets, source address.
Definition
sink-application.h:75
ns3::Socket
A low-level Socket API based loosely on the BSD Socket API.
Definition
socket.h:57
ns3::TracedCallback
Forward calls to a chain of Callback.
Definition
traced-callback.h:43
ns3::TypeId
a unique identifier for an interface.
Definition
type-id.h:49
uint32_t
port
uint16_t port
Definition
dsdv-manet.cc:33
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
applications
model
sink-application.h
Generated on
for ns-3 by
1.15.0