|
|
| 92 |
* \param tid The TypeId of the socket to create |
92 |
* \param tid The TypeId of the socket to create |
| 93 |
*/ |
93 |
*/ |
| 94 |
static Ptr<Socket> CreateSocket (Ptr<Node> node, TypeId tid); |
94 |
static Ptr<Socket> CreateSocket (Ptr<Node> node, TypeId tid); |
| 95 |
|
|
|
| 96 |
/** |
95 |
/** |
| 97 |
* \return the errno associated to the last call which failed in this |
96 |
* \return the errno associated to the last call which failed in this |
| 98 |
* socket. Each socket's errno is initialized to zero |
97 |
* socket. Each socket's errno is initialized to zero |
| 99 |
* when the socket is created. |
98 |
* when the socket is created. |
| 100 |
*/ |
99 |
*/ |
| 101 |
virtual enum Socket::SocketErrno GetErrno (void) const = 0; |
100 |
virtual enum Socket::SocketErrno GetErrno (void) const = 0; |
| 102 |
|
|
|
| 103 |
/** |
101 |
/** |
| 104 |
* \returns the node this socket is associated with. |
102 |
* \returns the node this socket is associated with. |
| 105 |
*/ |
103 |
*/ |
| 106 |
virtual Ptr<Node> GetNode (void) const = 0; |
104 |
virtual Ptr<Node> GetNode (void) const = 0; |
| 107 |
|
105 |
|
| 108 |
void SetCloseUnblocksCallback (Callback<void, Ptr<Socket> > closeUnblocks); |
|
|
| 109 |
|
| 110 |
/** |
106 |
/** |
| 111 |
* \param closeCompleted Callback invoked when the close operation is |
107 |
* \param closeCompleted Callback invoked when the close operation is |
| 112 |
* completed. |
108 |
* completed. |
| 113 |
*/ |
109 |
*/ |
| 114 |
void SetCloseCallback (Callback<void, Ptr<Socket> > closeCompleted); |
110 |
void SetCloseCallback (Callback<void, Ptr<Socket> > closeCompleted); |
| 115 |
|
|
|
| 116 |
/** |
111 |
/** |
| 117 |
* \param connectionSucceeded this callback is invoked when the |
112 |
* \param connectionSucceeded this callback is invoked when the |
| 118 |
* connection request initiated by the user is successfully |
113 |
* connection request initiated by the user is successfully |
|
|
| 165 |
* user should check this return value to confirm that the |
160 |
* user should check this return value to confirm that the |
| 166 |
* callback is supported. |
161 |
* callback is supported. |
| 167 |
*/ |
162 |
*/ |
| 168 |
virtual bool SetDataSentCallback (Callback<void, Ptr<Socket>, uint32_t> dataSent); |
163 |
virtual bool SetDataSentCallback (Callback<void, Ptr<Socket>, |
|
|
164 |
uint32_t> dataSent); |
| 169 |
/** |
165 |
/** |
| 170 |
* \brief Notify application when space in transmit buffer is added |
166 |
* \brief Notify application when space in transmit buffer is added |
| 171 |
* |
167 |
* |
|
|
| 242 |
virtual int Listen (uint32_t queueLimit) = 0; |
238 |
virtual int Listen (uint32_t queueLimit) = 0; |
| 243 |
|
239 |
|
| 244 |
/** |
240 |
/** |
|
|
241 |
* \brief Returns the number of bytes which can be sent in a single call |
| 242 |
* to Send. |
| 243 |
* |
| 244 |
* For datagram sockets, this returns the number of bytes that |
| 245 |
* can be passed atomically through the underlying protocol. |
| 246 |
* |
| 247 |
* For stream sockets, this returns the available space in bytes |
| 248 |
* left in the transmit buffer. |
| 249 |
*/ |
| 250 |
virtual uint32_t GetTxAvailable (void) const = 0; |
| 251 |
|
| 252 |
/** |
| 245 |
* \brief Send data (or dummy data) to the remote host |
253 |
* \brief Send data (or dummy data) to the remote host |
| 246 |
* |
254 |
* |
| 247 |
* This function matches closely in semantics to the send() function |
255 |
* This function matches closely in semantics to the send() function |
| 248 |
* call in the standard C library (libc): |
256 |
* call in the standard C library (libc): |
| 249 |
* ssize_t send (int s, const void *msg, size_t len, int flags); |
257 |
* ssize_t send (int s, const void *msg, size_t len, int flags); |
| 250 |
* except that the function call is asynchronous. |
258 |
* except that the send I/O is asynchronous. This is the |
|
|
259 |
* primary Send method at this low-level API and must be implemented |
| 260 |
* by subclasses. |
| 251 |
* |
261 |
* |
| 252 |
* In a typical blocking sockets model, this call would block upon |
262 |
* In a typical blocking sockets model, this call would block upon |
| 253 |
* lack of space to hold the message to be sent. In ns-3 at this |
263 |
* lack of space to hold the message to be sent. In ns-3 at this |
|
|
| 272 |
* split the Packet (based on information obtained from |
282 |
* split the Packet (based on information obtained from |
| 273 |
* GetTxAvailable) and reattempt to send the data. |
283 |
* GetTxAvailable) and reattempt to send the data. |
| 274 |
* |
284 |
* |
|
|
285 |
* The flags argument is formed by or'ing one or more of the values: |
| 286 |
* MSG_OOB process out-of-band data |
| 287 |
* MSG_DONTROUTE bypass routing, use direct interface |
| 288 |
* These flags are _unsupported_ as of ns-3.1. |
| 289 |
* |
| 275 |
* \param p ns3::Packet to send |
290 |
* \param p ns3::Packet to send |
|
|
291 |
* \param flags Socket control flags |
| 276 |
* \returns the number of bytes accepted for transmission if no error |
292 |
* \returns the number of bytes accepted for transmission if no error |
| 277 |
* occurs, and -1 otherwise. |
293 |
* occurs, and -1 otherwise. |
|
|
294 |
* |
| 295 |
* \see SetSendCallback |
| 278 |
*/ |
296 |
*/ |
| 279 |
virtual int Send (Ptr<Packet> p) = 0; |
297 |
virtual int Send (Ptr<Packet> p, uint32_t flags) = 0; |
| 280 |
|
298 |
|
| 281 |
/** |
299 |
/** |
| 282 |
* \brief Returns the number of bytes which can be sent in a single call |
300 |
* \brief Send data to a specified peer. |
| 283 |
* to Send. |
301 |
* |
|
|
302 |
* This method has similar semantics to Send () but subclasses may |
| 303 |
* want to provide checks on socket state, so the implementation is |
| 304 |
* pushed to subclasses. |
| 305 |
* |
| 306 |
* \param p packet to send |
| 307 |
* \param flags Socket control flags |
| 308 |
* \param toAddress IP Address of remote host |
| 309 |
* \returns -1 in case of error or the number of bytes copied in the |
| 310 |
* internal buffer and accepted for transmission. |
| 311 |
*/ |
| 312 |
virtual int SendTo (Ptr<Packet> p, uint32_t flags, |
| 313 |
const Address &toAddress) = 0; |
| 314 |
|
| 315 |
/** |
| 316 |
* Return number of bytes which can be returned from one or |
| 317 |
* multiple calls to Recv. |
| 318 |
* Must be possible to call this method from the Recv callback. |
| 319 |
*/ |
| 320 |
virtual uint32_t GetRxAvailable (void) const = 0; |
| 321 |
|
| 322 |
/** |
| 323 |
* \brief Read data from the socket |
| 324 |
* |
| 325 |
* This function matches closely in semantics to the recv() function |
| 326 |
* call in the standard C library (libc): |
| 327 |
* ssize_t recv (int s, void *buf, size_t len, int flags); |
| 328 |
* except that the receive I/O is asynchronous. This is the |
| 329 |
* primary Recv method at this low-level API and must be implemented |
| 330 |
* by subclasses. |
| 284 |
* |
331 |
* |
| 285 |
* For datagram sockets, this returns the number of bytes that |
332 |
* This method is normally used only on a connected socket. |
| 286 |
* can be passed atomically through the underlying protocol. |
333 |
* In a typical blocking sockets model, this call would block until |
|
|
334 |
* at least one byte is returned or the connection closes. |
| 335 |
* In ns-3 at this API, the call returns immediately in such a case |
| 336 |
* and returns 0 if nothing is available to be read. |
| 337 |
* However, an application can set a callback, ns3::SetRecvCallback, |
| 338 |
* to be notified of data being available to be read |
| 339 |
* (when it conceptually unblocks); this is an asynchronous |
| 340 |
* I/O model for recv(). |
| 341 |
* |
| 342 |
* This variant of Recv() uses class ns3::Packet to encapsulate |
| 343 |
* data, rather than providing a raw pointer and length field. |
| 344 |
* This allows an ns-3 application to attach tags if desired (such |
| 345 |
* as a flow ID) and may allow the simulator to avoid some data |
| 346 |
* copies. Despite the appearance of receiving Packets on a stream |
| 347 |
* socket, just think of it as a fancy byte buffer with streaming |
| 348 |
* semantics. |
| 287 |
* |
349 |
* |
| 288 |
* For stream sockets, this returns the available space in bytes |
350 |
* The semantics depend on the type of socket. For a datagram socket, |
| 289 |
* left in the transmit buffer. |
351 |
* each Recv() returns the data from at most one Send(), and order |
|
|
352 |
* is not necessarily preserved. For a stream socket, the bytes |
| 353 |
* are delivered in order, and on-the-wire packet boundaries are |
| 354 |
* not preserved. |
| 355 |
* |
| 356 |
* The flags argument is formed by or'ing one or more of the values: |
| 357 |
* MSG_OOB process out-of-band data |
| 358 |
* MSG_PEEK peek at incoming message |
| 359 |
* These flags are _unsupported_ as of ns-3.1. |
| 360 |
* |
| 361 |
* Some variants of Recv() are supported as additional API, |
| 362 |
* including RecvFrom(), overloaded Recv() without arguments, |
| 363 |
* and variants that use raw character buffers. |
| 364 |
* |
| 365 |
* \param maxSize reader will accept packet up to maxSize |
| 366 |
* \param flags Socket control flags |
| 367 |
* \returns Ptr<Packet> of the next in-sequence packet. Returns |
| 368 |
* 0 if the socket cannot return a next in-sequence packet conforming |
| 369 |
* to the maxSize and flags. |
| 370 |
* |
| 371 |
* \see SetRecvCallback |
| 290 |
*/ |
372 |
*/ |
| 291 |
virtual uint32_t GetTxAvailable (void) const = 0; |
373 |
virtual Ptr<Packet> Recv (uint32_t maxSize, uint32_t flags) = 0; |
|
|
374 |
|
| 375 |
/** |
| 376 |
* \brief Read a single packet from the socket and retrieve the sender |
| 377 |
* address. |
| 378 |
* |
| 379 |
* Calls Recv(maxSize, flags) with maxSize |
| 380 |
* implicitly set to maximum sized integer, and flags set to zero. |
| 381 |
* |
| 382 |
* This method has similar semantics to Recv () but subclasses may |
| 383 |
* want to provide checks on socket state, so the implementation is |
| 384 |
* pushed to subclasses. |
| 385 |
* |
| 386 |
* \param maxSize reader will accept packet up to maxSize |
| 387 |
* \param flags Socket control flags |
| 388 |
* \param fromAddress output parameter that will return the |
| 389 |
* address of the sender of the received packet, if any. Remains |
| 390 |
* untouched if no packet is received. |
| 391 |
* \returns Ptr<Packet> of the next in-sequence packet. Returns |
| 392 |
* 0 if the socket cannot return a next in-sequence packet. |
| 393 |
*/ |
| 394 |
virtual Ptr<Packet> RecvFrom (uint32_t maxSize, uint32_t flags, |
| 395 |
Address &fromAddress) = 0; |
| 292 |
|
396 |
|
|
|
397 |
///////////////////////////////////////////////////////////////////// |
| 398 |
// The remainder of these public methods are overloaded methods // |
| 399 |
// or variants of Send() and Recv(), and they are non-virtual // |
| 400 |
///////////////////////////////////////////////////////////////////// |
| 401 |
|
| 293 |
/** |
402 |
/** |
| 294 |
* \brief Send data (or dummy data) to the remote host |
403 |
* \brief Send data (or dummy data) to the remote host |
| 295 |
* \param buf A pointer to a raw byte buffer of some data to send. If this |
|
|
| 296 |
* is 0, we send dummy data whose size is specified by the second parameter |
| 297 |
* \param size the number of bytes to copy from the buffer |
| 298 |
* |
404 |
* |
| 299 |
* This is provided so as to have an API which is closer in appearance |
405 |
* Overloaded version of Send(..., flags) with flags set to zero. |
| 300 |
* to that of real network or BSD sockets. |
406 |
* |
|
|
407 |
* \param p ns3::Packet to send |
| 408 |
* \returns the number of bytes accepted for transmission if no error |
| 409 |
* occurs, and -1 otherwise. |
| 301 |
*/ |
410 |
*/ |
| 302 |
int Send (const uint8_t* buf, uint32_t size); |
411 |
int Send (Ptr<Packet> p); |
| 303 |
|
412 |
|
| 304 |
/** |
413 |
/** |
| 305 |
* \brief Send data to a specified peer. |
414 |
* \brief Send data (or dummy data) to the remote host |
| 306 |
* \param p packet to send |
415 |
* |
| 307 |
* \param address IP Address of remote host |
416 |
* This method is provided so as to have an API which is closer in |
| 308 |
* \returns -1 in case of error or the number of bytes copied in the |
417 |
* appearance to that of real network or BSD sockets. |
| 309 |
* internal buffer and accepted for transmission. |
418 |
* |
|
|
419 |
* \param buf A pointer to a raw byte buffer of some data to send. If |
| 420 |
* this buffer is 0, we send dummy data whose size is specified by the |
| 421 |
* second parameter |
| 422 |
* \param size the number of bytes to copy from the buffer |
| 423 |
* \param flags Socket control flags |
| 310 |
*/ |
424 |
*/ |
| 311 |
virtual int SendTo (Ptr<Packet> p, const Address &address) = 0; |
425 |
int Send (const uint8_t* buf, uint32_t size, uint32_t flags); |
|
|
426 |
|
| 312 |
|
427 |
|
| 313 |
/** |
428 |
/** |
| 314 |
* \brief Send data to a specified peer. |
429 |
* \brief Send data to a specified peer. |
| 315 |
* \param buf A pointer to a raw byte buffer of some data to send. If this |
430 |
* |
| 316 |
* is 0, we send dummy data whose size is specified by the third parameter |
431 |
* This method is provided so as to have an API which is closer in |
|
|
432 |
* appearance to that of real network or BSD sockets. |
| 433 |
* |
| 434 |
* \param buf A pointer to a raw byte buffer of some data to send. |
| 435 |
* If this is 0, we send dummy data whose size is specified by the |
| 436 |
* third parameter |
| 317 |
* \param size the number of bytes to copy from the buffer |
437 |
* \param size the number of bytes to copy from the buffer |
|
|
438 |
* \param flags Socket control flags |
| 318 |
* \param address IP Address of remote host |
439 |
* \param address IP Address of remote host |
| 319 |
* \returns -1 in case of error or the number of bytes copied in the |
440 |
* \returns -1 in case of error or the number of bytes copied in the |
| 320 |
* internal buffer and accepted for transmission. |
441 |
* internal buffer and accepted for transmission. |
| 321 |
* |
442 |
* |
| 322 |
* This is provided so as to have an API which is closer in appearance |
|
|
| 323 |
* to that of real network or BSD sockets. |
| 324 |
*/ |
443 |
*/ |
| 325 |
int SendTo (const uint8_t* buf, uint32_t size, const Address &address); |
444 |
int SendTo (const uint8_t* buf, uint32_t size, uint32_t flags, |
|
|
445 |
const Address &address); |
| 326 |
|
446 |
|
| 327 |
/** |
447 |
/** |
| 328 |
* \brief Read a single packet from the socket |
448 |
* \brief Read a single packet from the socket |
| 329 |
* \param maxSize reader will accept packet up to maxSize |
|
|
| 330 |
* \param flags Socket recv flags |
| 331 |
* \returns Ptr<Packet> of the next in-sequence packet. Returns |
| 332 |
* 0 if the socket cannot return a next in-sequence packet conforming |
| 333 |
* to the maxSize and flags. |
| 334 |
*/ |
| 335 |
virtual Ptr<Packet> Recv (uint32_t maxSize, uint32_t flags) = 0; |
| 336 |
/** |
| 337 |
* \brief Read a single packet from the socket |
| 338 |
* |
449 |
* |
| 339 |
* Overloaded version of Recv(maxSize, flags) with maxSize |
450 |
* Overloaded version of Recv(maxSize, flags) with maxSize |
| 340 |
* implicitly set to maximum sized integer, and flags set to zero. |
451 |
* implicitly set to maximum sized integer, and flags set to zero. |
| 341 |
* |
452 |
* |
| 342 |
* \returns Ptr<Packet> of the next in-sequence packet. Returns |
453 |
* \returns Ptr<Packet> of the next in-sequence packet. Returns |
| 343 |
* 0 if the socket cannot return a next in-sequence packet. |
454 |
* 0 if the socket cannot return a next in-sequence packet. |
| 344 |
*/ |
455 |
*/ |
| 345 |
Ptr<Packet> Recv (void); |
456 |
Ptr<Packet> Recv (void); |
|
|
457 |
|
| 346 |
/** |
458 |
/** |
| 347 |
* \brief Recv data (or dummy data) from the remote host |
459 |
* \brief Recv data (or dummy data) from the remote host |
| 348 |
* \param buf A pointer to a raw byte buffer to write the data to. |
460 |
* |
|
|
461 |
* This method is provided so as to have an API which is closer in |
| 462 |
* appearance to that of real network or BSD sockets. |
| 463 |
* |
| 349 |
* If the underlying packet was carring null (fake) data, this buffer |
464 |
* If the underlying packet was carring null (fake) data, this buffer |
| 350 |
* will be zeroed up to the length specified by the return value. |
465 |
* will be zeroed up to the length specified by the return value. |
|
|
466 |
* |
| 467 |
* \param buf A pointer to a raw byte buffer to write the data to. |
| 351 |
* \param size Number of bytes (at most) to copy to buf |
468 |
* \param size Number of bytes (at most) to copy to buf |
| 352 |
* \param flags any flags to pass to the socket |
469 |
* \param flags any flags to pass to the socket |
| 353 |
* \returns number of bytes copied into buf |
470 |
* \returns number of bytes copied into buf |
| 354 |
* |
|
|
| 355 |
* This is provided so as to have an API which is closer in appearance |
| 356 |
* to that of real network or BSD sockets. |
| 357 |
*/ |
471 |
*/ |
| 358 |
int Recv (uint8_t* buf, uint32_t size, uint32_t flags); |
472 |
int Recv (uint8_t* buf, uint32_t size, uint32_t flags); |
|
|
473 |
|
| 359 |
/** |
474 |
/** |
| 360 |
* Return number of bytes which can be returned from one or |
475 |
* \brief Read a single packet from the socket and retrieve the sender |
| 361 |
* multiple calls to Recv. |
476 |
* address. |
| 362 |
* Must be possible to call this method from the Recv callback. |
477 |
* |
|
|
478 |
* Calls RecvFrom (maxSize, flags, fromAddress) with maxSize |
| 479 |
* implicitly set to maximum sized integer, and flags set to zero. |
| 480 |
* |
| 481 |
* \param maxSize reader will accept packet up to maxSize |
| 482 |
* \param flags Socket control flags |
| 483 |
* \param fromAddress output parameter that will return the |
| 484 |
* address of the sender of the received packet, if any. Remains |
| 485 |
* untouched if no packet is received. |
| 486 |
* \returns Ptr<Packet> of the next in-sequence packet. Returns |
| 487 |
* 0 if the socket cannot return a next in-sequence packet. |
| 363 |
*/ |
488 |
*/ |
| 364 |
virtual uint32_t GetRxAvailable (void) const = 0; |
489 |
Ptr<Packet> RecvFrom (Address &fromAddress); |
|
|
490 |
|
| 491 |
/** |
| 492 |
* \brief Read a single packet from the socket and retrieve the sender |
| 493 |
* address. |
| 494 |
* |
| 495 |
* This method is provided so as to have an API which is closer in |
| 496 |
* appearance to that of real network or BSD sockets. |
| 497 |
* |
| 498 |
* \param buf A pointer to a raw byte buffer to write the data to. |
| 499 |
* If the underlying packet was carring null (fake) data, this buffer |
| 500 |
* will be zeroed up to the length specified by the return value. |
| 501 |
* \param size Number of bytes (at most) to copy to buf |
| 502 |
* \param flags any flags to pass to the socket |
| 503 |
* \param fromAddress output parameter that will return the |
| 504 |
* address of the sender of the received packet, if any. Remains |
| 505 |
* untouched if no packet is received. |
| 506 |
* \returns number of bytes copied into buf |
| 507 |
*/ |
| 508 |
int RecvFrom (uint8_t* buf, uint32_t size, uint32_t flags, |
| 509 |
Address &fromAddress); |
| 365 |
|
510 |
|
| 366 |
protected: |
511 |
protected: |
| 367 |
void NotifyCloseUnblocks (void); |
512 |
void NotifyCloseUnblocks (void); |
|
|
| 391 |
}; |
536 |
}; |
| 392 |
|
537 |
|
| 393 |
/** |
538 |
/** |
| 394 |
* \brief This class implements a tag that carries the source address |
539 |
* \brief This class implements a tag that carries an address |
| 395 |
* of a packet across the receiving socket interface. |
540 |
* of a packet across the socket interface. |
| 396 |
*/ |
541 |
*/ |
| 397 |
class SocketRxAddressTag : public Tag |
542 |
class SocketAddressTag : public Tag |
| 398 |
{ |
543 |
{ |
| 399 |
public: |
544 |
public: |
| 400 |
SocketRxAddressTag (); |
545 |
SocketAddressTag (); |
| 401 |
void SetAddress (Address addr); |
546 |
void SetAddress (Address addr); |
| 402 |
Address GetAddress (void) const; |
547 |
Address GetAddress (void) const; |
| 403 |
|
548 |
|