Ocean
Loading...
Searching...
No Matches
MaintenanceUDPConnector.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#ifndef FACEBOOK_NETWORK_MAINTENANCE_UDP_CONNECTOR_H
9#define FACEBOOK_NETWORK_MAINTENANCE_UDP_CONNECTOR_H
10
14
16#include "ocean/base/Thread.h"
18
19#include <queue>
20
21namespace Ocean
22{
23
24namespace Network
25{
26
27/**
28 * This class implements a network connector between two maintenance managers using the UDP protocol.
29 * The connector allows to transmit maintenance data from one manager to another manager by application of a network.<br>
30 * This connector can be either a sender or a receiver (not both concurrently) depending on the configuration.<br>
31 * The sender extracts maintenance data from the local maintenance manager and sends this data to the remote connector (configured as receiver).<br>
32 * The receiver receives maintenance data from a remote connector (configured as sender) and places this data into the local maintenance manager.<br>
33 * @see configurateAsSender(), configurateAsReceiver(), MaintenanceTCPConnector.
34 * @ingroup network
35 */
36class OCEAN_NETWORK_EXPORT MaintenanceUDPConnector :
38 protected Thread
39{
40 protected:
41
42 /**
43 * Definition of a vector holding bytes.
44 */
45 typedef std::vector<uint8_t> Buffer;
46
47 /**
48 * Definition of a buffer queue.
49 */
50 typedef std::queue<Buffer> BufferQueue;
51
52 public:
53
54 /**
55 * Creates a new maintenance connector object.
56 */
58
59 /**
60 * Destructs a maintenance connector object.
61 */
63
64 /**
65 * Returns whether this connector is configured as sender.
66 * @return True, if so
67 * @see configurateAsSender(), isReceiver().
68 */
69 inline bool isSender() const;
70
71 /**
72 * Returns whether this connector is configured as receiver.
73 * @return True, if so
74 * @see configurateAsReceiver(), isSender().
75 */
76 inline bool isReceiver() const;
77
78 /**
79 * Configures this connector as sender.
80 * @param targetAddress The address of the remote host to which the maintenance data will be sent
81 * @param targetPort The port of the remote host to which the maintenance data will be sent
82 * @see configurateAsReceiver().
83 */
84 void configurateAsSender(const Address4& targetAddress, Port& targetPort);
85
86 /**
87 * Configures this connector as receiver.
88 * @param port The local port of this receiver connector
89 */
90 void configurateAsReceiver(const Port& port);
91
92 protected:
93
94 /**
95 * Internal thread run function.
96 */
97 void threadRun() override;
98
99 /**
100 * UDP data receive event function.
101 * @param senderAddress The address of the sender from which the data has been sent
102 * @param senderPort The port of the sender from which the data has been sent
103 * @param buffer The buffer which has been sent
104 * @param bufferSize the size of the buffer
105 * @param messageId The id of the received data provided by the UDP client
106 */
107 void onReceiveUDPMessage(const Address4& senderAddress, const Port& senderPort, const void* buffer, const size_t bufferSize, const PackagedUDPServer::MessageId messageId);
108
109 protected:
110
111 /// The lock of this connector.
112 mutable Lock lock_;
113
114 /// The target address if this connector is a sender.
116
117 /// The target port if this connector is a sender.
119
120 /// The source port if this connector is a receiver.
122
123 /// The UDP client of this connector, used if this connector is a sender.
125
126 /// The UDP server of this connector, used if this connector is a receiver.
128
129 /// The queue of maintenance data.
131};
132
134{
135 const ScopedLock scopedLock(lock_);
136
138
140}
141
143{
144 const ScopedLock scopedLock(lock_);
145
147
148 return serverSourcePort_.isValid();
149}
150
151}
152
153}
154
155#endif // FACEBOOK_NETWORK_MAINTENANCE_UDP_CONNECTOR_H
This class implements a recursive lock object.
Definition Lock.h:31
This class is the base class for all maintenance connectors.
Definition Maintenance.h:49
This class wraps an address number with 32 bits.
Definition Address4.h:26
bool isValid() const
Returns whether this address hold a valid address.
Definition Address4.h:154
This class implements a network connector between two maintenance managers using the UDP protocol.
Definition MaintenanceUDPConnector.h:39
Port serverSourcePort_
The source port if this connector is a receiver.
Definition MaintenanceUDPConnector.h:121
std::vector< uint8_t > Buffer
Definition of a vector holding bytes.
Definition MaintenanceUDPConnector.h:45
Address4 clientTargetAddress_
The target address if this connector is a sender.
Definition MaintenanceUDPConnector.h:115
PackagedUDPServer udpServer
The UDP server of this connector, used if this connector is a receiver.
Definition MaintenanceUDPConnector.h:127
void configurateAsReceiver(const Port &port)
Configures this connector as receiver.
Lock lock_
The lock of this connector.
Definition MaintenanceUDPConnector.h:112
void onReceiveUDPMessage(const Address4 &senderAddress, const Port &senderPort, const void *buffer, const size_t bufferSize, const PackagedUDPServer::MessageId messageId)
UDP data receive event function.
std::queue< Buffer > BufferQueue
Definition of a buffer queue.
Definition MaintenanceUDPConnector.h:50
PackagedUDPClient udpClient
The UDP client of this connector, used if this connector is a sender.
Definition MaintenanceUDPConnector.h:124
void configurateAsSender(const Address4 &targetAddress, Port &targetPort)
Configures this connector as sender.
bool isReceiver() const
Returns whether this connector is configured as receiver.
Definition MaintenanceUDPConnector.h:142
~MaintenanceUDPConnector() override
Destructs a maintenance connector object.
BufferQueue bufferQueue_
The queue of maintenance data.
Definition MaintenanceUDPConnector.h:130
MaintenanceUDPConnector()
Creates a new maintenance connector object.
void threadRun() override
Internal thread run function.
Port clientTargetPort_
The target port if this connector is a sender.
Definition MaintenanceUDPConnector.h:118
bool isSender() const
Returns whether this connector is configured as sender.
Definition MaintenanceUDPConnector.h:133
uint32_t MessageId
Definition of a message id.
Definition PackagedSocket.h:192
This class implements a UDP client able to send larger messages as normally restricted by the UDP pro...
Definition PackagedUDPClient.h:25
This class implements a packaged UDP server.
Definition PackagedUDPServer.h:25
This class wraps a port number with 16 bits.
Definition Port.h:26
bool isValid() const
Returns whether this port hold a non-zero value.
Definition Port.h:131
This class implements a scoped lock object for recursive lock objects.
Definition Lock.h:135
This class implements a thread.
Definition Thread.h:115
The namespace covering the entire Ocean framework.
Definition Accessor.h:15