ns-3 Direct Code Execution
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
linux-socket-impl.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2012 NICT
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Hajime Tazaki <tazaki@nict.go.jp>
19  */
20 #ifndef UDP_SOCKET_IMPL_H
21 #define UDP_SOCKET_IMPL_H
22 
23 #include "ns3/socket.h"
24 #include "ns3/event-id.h"
25 #include <sys/socket.h>
26 
27 namespace ns3 {
28 
29 class Node;
30 class Packet;
31 class Task;
32 class LinuxSocketFd;
33 
34 class LinuxSocketImpl : public Socket
35 {
36 public:
37  static TypeId GetTypeId (void);
41  LinuxSocketImpl ();
42  virtual ~LinuxSocketImpl ();
43  void CreateSocket ();
44 
45  virtual enum SocketErrno GetErrno (void) const;
46  virtual enum SocketType GetSocketType (void) const;
47  virtual void SetNode (Ptr<Node> node);
48  virtual Ptr<Node> GetNode (void) const;
49  virtual int Bind (void);
50  virtual int Bind6 (void);
51  virtual int Bind (const Address &address);
52  virtual int Close (void);
53  virtual int ShutdownSend (void);
54  virtual int ShutdownRecv (void);
55  virtual int Connect (const Address &address);
56  virtual int Listen (void);
57  virtual uint32_t GetTxAvailable (void) const;
58  virtual int Send (Ptr<Packet> p, uint32_t flags);
59  virtual int SendTo (Ptr<Packet> p, uint32_t flags, const Address &address);
60  virtual uint32_t GetRxAvailable (void) const;
61  virtual Ptr<Packet> Recv (uint32_t maxSize, uint32_t flags);
62  virtual Ptr<Packet> RecvFrom (uint32_t maxSize, uint32_t flags,
63  Address &fromAddress);
64  virtual int GetSockName (Address &address) const;
65  virtual int MulticastJoinGroup (uint32_t interfaceIndex, const Address &groupAddress);
66  virtual int MulticastLeaveGroup (uint32_t interfaceIndex, const Address &groupAddress);
67  virtual void BindToNetDevice (Ptr<NetDevice> netdevice);
68  virtual bool SetAllowBroadcast (bool allowBroadcast);
69  virtual bool GetAllowBroadcast () const;
70  void Poll ();
71 
72  Address PosixAddressToNs3Address (const struct sockaddr *my_addr, socklen_t addrlen);
73  int Ns3AddressToPosixAddress (const Address& nsaddr,
74  struct sockaddr *addr, socklen_t *addrlen);
75 
76  typedef Callback<int,const Address&,struct sockaddr *,socklen_t *> Ns3ToPosixConverter;
77  typedef Callback<Address,const struct sockaddr *,socklen_t> PosixToNs3Converter;
78 
81 
86 
87 private:
88  // Attributes set through UdpSocket base class
89  virtual void SetRcvBufSize (uint32_t size);
90  virtual uint32_t GetRcvBufSize (void) const;
91  virtual void SetIpTtl (uint8_t ipTtl);
92  virtual uint8_t GetIpTtl (void) const;
93  virtual void SetIpMulticastTtl (uint8_t ipTtl);
94  virtual uint8_t GetIpMulticastTtl (void) const;
95  virtual void SetIpMulticastIf (int32_t ipIf);
96  virtual int32_t GetIpMulticastIf (void) const;
97  virtual void SetIpMulticastLoop (bool loop);
98  virtual bool GetIpMulticastLoop (void) const;
99  virtual void SetMtuDiscover (bool discover);
100  virtual bool GetMtuDiscover (void) const;
101  uint16_t EnterFakeTask ();
102  void LeaveFakeTask (uint16_t pid);
103  void ScheduleTask (EventImpl *event);
104  static void ScheduleTaskTrampoline (void *context);
105 
106  enum SocketErrno m_errno;
107  Ptr<Node> m_node;
108  uint16_t m_family;
109  uint16_t m_socktype;
110  uint16_t m_protocol;
113  uint16_t m_pid;
114  EventId m_poll;
115 
116 };
117 
118 } // namespace ns3
119 
120 #endif /* UDP_SOCKET_IMPL_H */