A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
socket.h
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2006 Georgia Tech Research Corporation
4
* 2007 INRIA
5
*
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License version 2 as
8
* published by the Free Software Foundation;
9
*
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
14
*
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
*
19
* Authors: George F. Riley<riley@ece.gatech.edu>
20
* Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
21
*/
22
23
#ifndef NS3_SOCKET_H
24
#define NS3_SOCKET_H
25
26
#include "ns3/callback.h"
27
#include "ns3/ptr.h"
28
#include "ns3/tag.h"
29
#include "ns3/object.h"
30
#include "ns3/net-device.h"
31
#include "
address.h
"
32
#include <stdint.h>
33
34
namespace
ns3 {
35
36
37
class
Node;
38
class
Packet;
39
64
class
Socket
:
public
Object
65
{
66
public
:
67
static
TypeId
GetTypeId
(
void
);
68
69
Socket
(
void
);
70
virtual
~Socket
(
void
);
71
72
enum
SocketErrno
{
73
ERROR_NOTERROR
,
74
ERROR_ISCONN
,
75
ERROR_NOTCONN
,
76
ERROR_MSGSIZE
,
77
ERROR_AGAIN
,
78
ERROR_SHUTDOWN
,
79
ERROR_OPNOTSUPP
,
80
ERROR_AFNOSUPPORT
,
81
ERROR_INVAL
,
82
ERROR_BADF
,
83
ERROR_NOROUTETOHOST
,
84
ERROR_NODEV
,
85
ERROR_ADDRNOTAVAIL
,
86
ERROR_ADDRINUSE
,
87
SOCKET_ERRNO_LAST
88
};
89
90
enum
SocketType
{
91
NS3_SOCK_STREAM
,
92
NS3_SOCK_SEQPACKET
,
93
NS3_SOCK_DGRAM
,
94
NS3_SOCK_RAW
95
};
96
106
static
Ptr<Socket>
CreateSocket
(
Ptr<Node>
node,
TypeId
tid);
112
virtual
enum
Socket::SocketErrno
GetErrno
(
void
)
const
= 0;
116
virtual
enum
Socket::SocketType
GetSocketType
(
void
)
const
= 0;
120
virtual
Ptr<Node>
GetNode
(
void
)
const
= 0;
133
void
SetConnectCallback
(
Callback
<
void
,
Ptr<Socket>
> connectionSucceeded,
134
Callback
<
void
,
Ptr<Socket>
> connectionFailed);
150
void
SetCloseCallbacks
(
Callback
<
void
,
Ptr<Socket>
> normalClose,
151
Callback
<
void
,
Ptr<Socket>
> errorClose);
169
void
SetAcceptCallback
(
Callback
<
bool
,
Ptr<Socket>
,
170
const
Address
&> connectionRequest,
171
Callback
<
void
,
Ptr<Socket>
,
172
const
Address
&> newConnectionCreated);
180
void
SetDataSentCallback
(
Callback
<
void
,
Ptr<Socket>
,
181
uint32_t> dataSent);
196
void
SetSendCallback
(
Callback
<
void
,
Ptr<Socket>
, uint32_t> sendCb);
204
void
SetRecvCallback
(
Callback
<
void
,
Ptr<Socket>
>);
210
virtual
int
Bind
(
const
Address
&address) = 0;
211
217
virtual
int
Bind
() = 0;
218
224
virtual
int
Bind6
() = 0;
225
233
virtual
int
Close
(
void
) = 0;
234
241
virtual
int
ShutdownSend
(
void
) = 0;
242
249
virtual
int
ShutdownRecv
(
void
) = 0;
250
255
virtual
int
Connect
(
const
Address
&address) = 0;
256
261
virtual
int
Listen
(
void
) = 0;
262
273
virtual
uint32_t
GetTxAvailable
(
void
)
const
= 0;
274
320
virtual
int
Send
(
Ptr<Packet>
p, uint32_t flags) = 0;
321
335
virtual
int
SendTo
(
Ptr<Packet>
p, uint32_t flags,
336
const
Address
&toAddress) = 0;
337
343
virtual
uint32_t
GetRxAvailable
(
void
)
const
= 0;
344
396
virtual
Ptr<Packet>
Recv
(uint32_t maxSize, uint32_t flags) = 0;
397
417
virtual
Ptr<Packet>
RecvFrom
(uint32_t maxSize, uint32_t flags,
418
Address
&fromAddress) = 0;
419
421
// The remainder of these public methods are overloaded methods //
422
// or variants of Send() and Recv(), and they are non-virtual //
424
434
int
Send
(
Ptr<Packet>
p);
435
448
int
Send
(
const
uint8_t* buf, uint32_t size, uint32_t flags);
449
450
467
int
SendTo
(
const
uint8_t* buf, uint32_t size, uint32_t flags,
468
const
Address
&address);
469
479
Ptr<Packet>
Recv
(
void
);
480
495
int
Recv
(uint8_t* buf, uint32_t size, uint32_t flags);
496
510
Ptr<Packet>
RecvFrom
(
Address
&fromAddress);
511
529
int
RecvFrom
(uint8_t* buf, uint32_t size, uint32_t flags,
530
Address
&fromAddress);
535
virtual
int
GetSockName
(
Address
&address)
const
= 0;
536
556
virtual
void
BindToNetDevice
(
Ptr<NetDevice>
netdevice);
557
567
Ptr<NetDevice>
GetBoundNetDevice
();
568
569
581
virtual
bool
SetAllowBroadcast
(
bool
allowBroadcast) = 0;
582
591
virtual
bool
GetAllowBroadcast
()
const
= 0;
592
605
void
SetRecvPktInfo
(
bool
flag);
606
612
bool
IsRecvPktInfo
()
const
;
613
614
protected
:
615
void
NotifyConnectionSucceeded
(
void
);
616
void
NotifyConnectionFailed
(
void
);
617
void
NotifyNormalClose
(
void
);
618
void
NotifyErrorClose
(
void
);
619
bool
NotifyConnectionRequest
(
const
Address
&from);
620
void
NotifyNewConnectionCreated
(
Ptr<Socket>
socket,
const
Address
&from);
621
void
NotifyDataSent
(uint32_t size);
622
void
NotifySend
(uint32_t spaceAvailable);
623
void
NotifyDataRecv
(
void
);
624
virtual
void
DoDispose
(
void
);
625
Ptr<NetDevice>
m_boundnetdevice
;
626
bool
m_recvPktInfo
;
627
private
:
628
Callback<void, Ptr<Socket>
>
m_connectionSucceeded
;
629
Callback<void, Ptr<Socket>
>
m_connectionFailed
;
630
Callback<void, Ptr<Socket>
>
m_normalClose
;
631
Callback<void, Ptr<Socket>
>
m_errorClose
;
632
Callback<bool, Ptr<Socket>
,
const
Address
&>
m_connectionRequest
;
633
Callback<void, Ptr<Socket>
,
const
Address
&>
m_newConnectionCreated
;
634
Callback<void, Ptr<Socket>
, uint32_t>
m_dataSent
;
635
Callback<void, Ptr<Socket>
, uint32_t >
m_sendCb
;
636
Callback<void, Ptr<Socket>
>
m_receivedData
;
637
638
};
639
644
class
SocketAddressTag
:
public
Tag
645
{
646
public
:
647
SocketAddressTag
();
648
void
SetAddress
(
Address
addr);
649
Address
GetAddress
(
void
)
const
;
650
651
static
TypeId
GetTypeId
(
void
);
652
virtual
TypeId
GetInstanceTypeId
(
void
)
const
;
653
virtual
uint32_t
GetSerializedSize
(
void
)
const
;
654
virtual
void
Serialize
(
TagBuffer
i)
const
;
655
virtual
void
Deserialize
(
TagBuffer
i);
656
virtual
void
Print
(std::ostream &os)
const
;
657
658
private
:
659
Address
m_address
;
660
};
661
666
class
SocketIpTtlTag
:
public
Tag
667
{
668
public
:
669
SocketIpTtlTag
();
670
void
SetTtl
(uint8_t ttl);
671
uint8_t
GetTtl
(
void
)
const
;
672
673
static
TypeId
GetTypeId
(
void
);
674
virtual
TypeId
GetInstanceTypeId
(
void
)
const
;
675
virtual
uint32_t
GetSerializedSize
(
void
)
const
;
676
virtual
void
Serialize
(
TagBuffer
i)
const
;
677
virtual
void
Deserialize
(
TagBuffer
i);
678
virtual
void
Print
(std::ostream &os)
const
;
679
680
private
:
681
uint8_t
m_ttl
;
682
};
683
684
689
class
SocketSetDontFragmentTag
:
public
Tag
690
{
691
public
:
692
SocketSetDontFragmentTag
();
693
void
Enable
(
void
);
694
void
Disable
(
void
);
695
bool
IsEnabled
(
void
)
const
;
696
697
static
TypeId
GetTypeId
(
void
);
698
virtual
TypeId
GetInstanceTypeId
(
void
)
const
;
699
virtual
uint32_t
GetSerializedSize
(
void
)
const
;
700
virtual
void
Serialize
(
TagBuffer
i)
const
;
701
virtual
void
Deserialize
(
TagBuffer
i);
702
virtual
void
Print
(std::ostream &os)
const
;
703
private
:
704
bool
m_dontFragment
;
705
};
706
707
}
// namespace ns3
708
709
#endif
/* NS3_SOCKET_H */
src
network
model
socket.h
Generated on Tue Oct 9 2012 16:45:43 for ns-3 by
1.8.1.2