A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
udp-server.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007,2008,2009 INRIA, UDCAST
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Amine Ismail <amine.ismail@sophia.inria.fr>
7 * <amine.ismail@udcast.com>
8 *
9 */
10
11#ifndef UDP_SERVER_H
12#define UDP_SERVER_H
13
14#include "packet-loss-counter.h"
15#include "sink-application.h"
16
17#include "ns3/event-id.h"
18#include "ns3/ptr.h"
19#include "ns3/traced-callback.h"
20
21namespace ns3
22{
23/**
24 * @ingroup applications
25 * @defgroup udpclientserver UdpClientServer
26 */
27
28/**
29 * @ingroup udpclientserver
30 *
31 * @brief A UDP server, receives UDP packets from a remote host.
32 *
33 * UDP packets carry a 32bits sequence number followed by a 64bits time
34 * stamp in their payloads. The application uses the sequence number
35 * to determine if a packet is lost, and the time stamp to compute the delay.
36 */
38{
39 public:
40 static constexpr uint16_t DEFAULT_PORT{100}; //!< default port
41
42 /**
43 * @brief Get the type ID.
44 * @return the object TypeId
45 */
46 static TypeId GetTypeId();
47
48 UdpServer();
49 ~UdpServer() override;
50
51 /**
52 * @brief Returns the number of lost packets
53 * @return the number of lost packets
54 */
55 uint32_t GetLost() const;
56
57 /**
58 * @brief Returns the number of received packets
59 * @return the number of received packets
60 */
61 uint64_t GetReceived() const;
62
63 /**
64 * @brief Returns the size of the window used for checking loss.
65 * @return the size of the window used for checking loss.
66 */
67 uint16_t GetPacketWindowSize() const;
68
69 /**
70 * @brief Set the size of the window used for checking loss. This value should
71 * be a multiple of 8
72 * @param size the size of the window used for checking loss. This value should
73 * be a multiple of 8
74 */
75 void SetPacketWindowSize(uint16_t size);
76
77 private:
78 void StartApplication() override;
79 void StopApplication() override;
80
81 /**
82 * @brief Handle a packet reception.
83 *
84 * This function is called by lower layers.
85 *
86 * @param socket the socket the packet was received to.
87 */
88 void HandleRead(Ptr<Socket> socket);
89
90 Ptr<Socket> m_socket; //!< Socket
91 Ptr<Socket> m_socket6; //!< IPv6 Socket (used if only port is specified)
92 uint64_t m_received; //!< Number of received packets
93 PacketLossCounter m_lossCounter; //!< Lost packet counter
94
95 /// Callbacks for tracing the packet Rx events
97
98 /// Callbacks for tracing the packet Rx events, includes source and destination addresses
100};
101
102} // namespace ns3
103
104#endif /* UDP_SERVER_H */
a polymophic address class
Definition address.h:90
A class to count the number of lost packets.
Smart pointer class similar to boost::intrusive_ptr.
Base class for sink applications.
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition type-id.h:48
A UDP server, receives UDP packets from a remote host.
Definition udp-server.h:38
Ptr< Socket > m_socket6
IPv6 Socket (used if only port is specified)
Definition udp-server.h:91
TracedCallback< Ptr< const Packet > > m_rxTrace
Callbacks for tracing the packet Rx events.
Definition udp-server.h:96
~UdpServer() override
Definition udp-server.cc:69
uint64_t GetReceived() const
Returns the number of received packets.
Definition udp-server.cc:96
void StartApplication() override
Application specific startup code.
Ptr< Socket > m_socket
Socket.
Definition udp-server.h:90
void HandleRead(Ptr< Socket > socket)
Handle a packet reception.
static TypeId GetTypeId()
Get the type ID.
Definition udp-server.cc:34
PacketLossCounter m_lossCounter
Lost packet counter.
Definition udp-server.h:93
static constexpr uint16_t DEFAULT_PORT
default port
Definition udp-server.h:40
void SetPacketWindowSize(uint16_t size)
Set the size of the window used for checking loss.
Definition udp-server.cc:82
TracedCallback< Ptr< const Packet >, const Address &, const Address & > m_rxTraceWithAddresses
Callbacks for tracing the packet Rx events, includes source and destination addresses.
Definition udp-server.h:99
uint32_t GetLost() const
Returns the number of lost packets.
Definition udp-server.cc:89
uint64_t m_received
Number of received packets.
Definition udp-server.h:92
uint16_t GetPacketWindowSize() const
Returns the size of the window used for checking loss.
Definition udp-server.cc:75
void StopApplication() override
Application specific shutdown code.
Every class exported by the ns3 library is enclosed in the ns3 namespace.