A Discrete-Event Network Simulator
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
15#include <limits>
16
17namespace ns3
18{
19
20/**
21 * @ingroup applications
22 * @brief Base class for sink applications.
23 *
24 * This class can be used as a base class for sink applications.
25 * A sink application is an application that is primarily used to only receive or echo packets.
26 *
27 * The main purpose of this base class application public API is to hold attributes for the local
28 * (IPv4 or IPv6) address and port to bind to.
29 *
30 * There are three ways that the port value can be configured. First, and most typically, through
31 * the use of a socket address (InetSocketAddress or Inet6SocketAddress) that is configured as the
32 * Local address to bind to. Second, through direct configuration of the Port attribute. Third,
33 * through the use of an optional constructor argument. If multiple of these port configuration
34 * methods are used, it is up to subclass definition which one takes precedence; in the existing
35 * subclasses in this directory, the port value configured in the Local socket address (if a socket
36 * address is configured there) will take precedence.
37 */
39{
40 public:
41 /**
42 * @brief Get the type ID.
43 * @return the object TypeId
44 */
45 static TypeId GetTypeId();
46
47 /**
48 * Constructor
49 *
50 * @param defaultPort the default port number
51 */
52 SinkApplication(uint16_t defaultPort = 0);
53 ~SinkApplication() override;
54
55 static constexpr uint32_t INVALID_PORT{std::numeric_limits<uint32_t>::max()}; //!< invalid port
56
57 protected:
58 Address m_local; //!< Local address to bind to (address and port)
59 uint32_t m_port; //!< Local port to bind to
60
61 private:
62 /**
63 * @brief set the local address
64 * @param addr local address
65 */
66 virtual void SetLocal(const Address& addr);
67
68 /**
69 * @brief get the local address
70 * @return the local address
71 */
72 Address GetLocal() const;
73
74 /**
75 * @brief set the server port
76 * @param port server port
77 */
78 virtual void SetPort(uint32_t port);
79
80 /**
81 * @brief get the server port
82 * @return the server port
83 */
84 uint32_t GetPort() const;
85};
86
87} // namespace ns3
88
89#endif /* SINK_APPLICATION_H */
a polymophic address class
Definition address.h:90
The base class for all ns3 applications.
Definition application.h:51
Base class for sink applications.
static constexpr uint32_t INVALID_PORT
invalid port
virtual void SetLocal(const Address &addr)
set the local address
SinkApplication(uint16_t defaultPort=0)
Constructor.
Address GetLocal() const
get the local address
uint32_t GetPort() const
get the server port
static TypeId GetTypeId()
Get the type ID.
Address m_local
Local address to bind to (address and port)
uint32_t m_port
Local port to bind to.
virtual void SetPort(uint32_t port)
set the server port
a unique identifier for an interface.
Definition type-id.h:48
uint16_t port
Definition dsdv-manet.cc:33
Every class exported by the ns3 library is enclosed in the ns3 namespace.