A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
packet-socket-client.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2014 Universita' di Firenze
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Tommaso Pecorella <tommaso.pecorella@unifi.it>
7 */
8
9#ifndef PACKET_SOCKET_CLIENT_H
10#define PACKET_SOCKET_CLIENT_H
11
13
14#include "ns3/application.h"
15#include "ns3/event-id.h"
16#include "ns3/ptr.h"
17#include "ns3/traced-callback.h"
18
19namespace ns3
20{
21
22class Socket;
23class Packet;
24
25/**
26 * \ingroup socket
27 *
28 * \brief A simple client.
29 *
30 * Sends packets using PacketSocket. It does not require (or use) IP.
31 *
32 * Packets are sent as soon as PacketSocketClient::Start is called.
33 * The application has the same requirements as the PacketSocket for
34 * what concerns the underlying NetDevice and the Address scheme.
35 * It is meant to be used in ns-3 tests.
36 *
37 * The application will send `MaxPackets' packets, one every `Interval'
38 * time. Packet size (`PacketSize') can be configured.
39 * Provides a "Tx" Traced Callback (transmitted packets, source address).
40 *
41 * Note: packets larger than the NetDevice MTU will not be sent.
42 */
44{
45 public:
46 /**
47 * \brief Get the type ID.
48 * \return the object TypeId
49 */
50 static TypeId GetTypeId();
51
53
54 ~PacketSocketClient() override;
55
56 /**
57 * \brief set the remote address and protocol to be used
58 * \param addr remote address
59 */
61
62 /**
63 * \brief Query the priority value of this socket
64 * \return The priority value
65 */
66 uint8_t GetPriority() const;
67
68 protected:
69 void DoDispose() override;
70
71 private:
72 void StartApplication() override;
73 void StopApplication() override;
74
75 /**
76 * \brief Manually set the socket priority
77 * \param priority The socket priority (in the range 0..6)
78 */
79 void SetPriority(uint8_t priority);
80
81 /**
82 * \brief Send a packet
83 *
84 * Either <i>Interval</i> and <i>MaxPackets</i> may be zero, but not both. If <i>Interval</i>
85 * is zero, the PacketSocketClient will send <i>MaxPackets</i> packets without any delay into
86 * the socket. If <i>MaxPackets</i> is zero, then the PacketSocketClient will send every
87 * <i>Interval</i> until the application is stopped.
88 */
89 void Send();
90
91 uint32_t m_maxPackets; //!< Maximum number of packets the application will send
92 Time m_interval; //!< Packet inter-send time
93 uint32_t m_size; //!< Size of the sent packet
94 uint8_t m_priority; //!< Priority of the sent packets
95
96 uint32_t m_sent; //!< Counter for sent packets
97 Ptr<Socket> m_socket; //!< Socket
98 PacketSocketAddress m_peerAddress; //!< Remote peer address
99 bool m_peerAddressSet; //!< Sanity check
100 EventId m_sendEvent; //!< Event to send the next packet
101
102 /// Traced Callback: sent packets, source address.
104};
105
106} // namespace ns3
107
108#endif /* PACKET_SOCKET_CLIENT_H */
a polymophic address class
Definition address.h:90
The base class for all ns3 applications.
Definition application.h:51
An identifier for simulation events.
Definition event-id.h:45
an address for a packet socket
uint32_t m_sent
Counter for sent packets.
void StopApplication() override
Application specific shutdown code.
TracedCallback< Ptr< const Packet >, const Address & > m_txTrace
Traced Callback: sent packets, source address.
Ptr< Socket > m_socket
Socket.
void DoDispose() override
Destructor implementation.
uint8_t GetPriority() const
Query the priority value of this socket.
EventId m_sendEvent
Event to send the next packet.
uint32_t m_maxPackets
Maximum number of packets the application will send.
void SetPriority(uint8_t priority)
Manually set the socket priority.
static TypeId GetTypeId()
Get the type ID.
bool m_peerAddressSet
Sanity check.
void SetRemote(PacketSocketAddress addr)
set the remote address and protocol to be used
uint32_t m_size
Size of the sent packet.
uint8_t m_priority
Priority of the sent packets.
void StartApplication() override
Application specific startup code.
PacketSocketAddress m_peerAddress
Remote peer address.
Time m_interval
Packet inter-send time.
Smart pointer class similar to boost::intrusive_ptr.
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition type-id.h:48
Every class exported by the ns3 library is enclosed in the ns3 namespace.