A Discrete-Event Network Simulator
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2007 Emmanuelle Laprise, INRIA
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
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  * Authors: Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>,
19  * Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
20  */
21 #ifndef PACKET_SOCKET_H
22 #define PACKET_SOCKET_H
24 #include <stdint.h>
25 #include <queue>
26 #include "ns3/callback.h"
27 #include "ns3/traced-callback.h"
28 #include "ns3/ptr.h"
29 #include "ns3/socket.h"
30 #include "ns3/net-device.h"
32 namespace ns3 {
34 class Node;
35 class Packet;
36 class NetDevice;
37 class PacketSocketAddress;
78 class PacketSocket : public Socket
79 {
80 public:
81  static TypeId GetTypeId (void);
83  PacketSocket ();
84  virtual ~PacketSocket ();
86  void SetNode (Ptr<Node> node);
88  virtual enum SocketErrno GetErrno (void) const;
89  virtual enum SocketType GetSocketType (void) const;
90  virtual Ptr<Node> GetNode (void) const;
91  virtual int Bind (void);
92  virtual int Bind6 (void);
93  virtual int Bind (const Address & address);
94  virtual int Close (void);
95  virtual int ShutdownSend (void);
96  virtual int ShutdownRecv (void);
97  virtual int Connect (const Address &address);
98  virtual int Listen (void);
99  virtual uint32_t GetTxAvailable (void) const;
100  virtual int Send (Ptr<Packet> p, uint32_t flags);
101  virtual int SendTo (Ptr<Packet> p, uint32_t flags, const Address &toAddress);
102  virtual uint32_t GetRxAvailable (void) const;
103  virtual Ptr<Packet> Recv (uint32_t maxSize, uint32_t flags);
104  virtual Ptr<Packet> RecvFrom (uint32_t maxSize, uint32_t flags,
105  Address &fromAddress);
106  virtual int GetSockName (Address &address) const;
107  virtual bool SetAllowBroadcast (bool allowBroadcast);
108  virtual bool GetAllowBroadcast () const;
110 private:
111  void ForwardUp (Ptr<NetDevice> device, Ptr<const Packet> packet,
112  uint16_t protocol, const Address &from, const Address &to,
113  NetDevice::PacketType packetType);
114  int DoBind (const PacketSocketAddress &address);
115  uint32_t GetMinMtu (PacketSocketAddress ad) const;
116  virtual void DoDispose (void);
118  enum State {
120  STATE_BOUND, // open and bound
121  STATE_CONNECTED, // open, bound and connected
123  };
124  Ptr<Node> m_node;
125  enum SocketErrno m_errno;
126  bool m_shutdownSend;
127  bool m_shutdownRecv;
128  enum State m_state;
129  uint16_t m_protocol;
130  bool m_isSingleDevice;
131  uint32_t m_device;
132  Address m_destAddr;
134  std::queue<Ptr<Packet> > m_deliveryQueue;
135  uint32_t m_rxAvailable;
137  TracedCallback<Ptr<const Packet> > m_dropTrace;
139  // Socket options (attributes)
140  uint32_t m_rcvBufSize;
142 };
148 class PacketSocketTag : public Tag
149 {
150 public:
154  PacketSocketTag ();
169  void SetDestAddress(Address a);
174  Address GetDestAddress (void) const;
176  static TypeId GetTypeId (void);
177  virtual TypeId GetInstanceTypeId (void) const;
178  virtual uint32_t GetSerializedSize (void) const;
179  virtual void Serialize (TagBuffer i) const;
180  virtual void Deserialize (TagBuffer i);
181  virtual void Print (std::ostream &os) const;
183 private:
184  std::string m_deviceName;
185  NetDevice::PacketType m_packetType;
186  Address m_destAddr;
187 };
192 class DeviceNameTag : public Tag
193 {
194 public:
198  DeviceNameTag ();
203  void SetDeviceName (std::string n);
208  std::string GetDeviceName (void) const;
209  static TypeId GetTypeId (void);
210  virtual TypeId GetInstanceTypeId (void) const;
211  virtual uint32_t GetSerializedSize (void) const;
212  virtual void Serialize (TagBuffer i) const;
213  virtual void Deserialize (TagBuffer i);
214  virtual void Print (std::ostream &os) const;
216 private:
217  std::string m_deviceName;
218 };
220 } // namespace ns3
222 #endif /* PACKET_SOCKET_H */
virtual enum SocketErrno GetErrno(void) const
Address GetDestAddress(void) const
Ptr< Packet > Recv(void)
Read a single packet from the socket.
Definition: socket.cc:174
forward calls to a chain of CallbackAn ns3::TracedCallback has almost exactly the same API as a norma...
std::queue< Ptr< Packet > > m_deliveryQueue
Default destination address.
an address for a packet socket
virtual Ptr< Packet > RecvFrom(uint32_t maxSize, uint32_t flags, Address &fromAddress)
Read a single packet from the socket and retrieve the sender address.
virtual void DoDispose(void)
A PacketSocket is a link between an application and a net device.
Definition: packet-socket.h:78
virtual uint32_t GetSerializedSize(void) const
void SetPacketType(NetDevice::PacketType t)
virtual int Bind(void)
Allocate a local IPv4 endpoint for this socket.
virtual void Print(std::ostream &os) const
virtual int GetSockName(Address &address) const
a polymophic address class
Definition: address.h:86
virtual TypeId GetInstanceTypeId(void) const
virtual void Serialize(TagBuffer i) const
A low-level Socket API based loosely on the BSD Socket API.A few things to keep in mind about this ty...
Definition: socket.h:66
virtual bool SetAllowBroadcast(bool allowBroadcast)
Configure whether broadcast datagram transmissions are allowed.
void SetDestAddress(Address a)
virtual int ShutdownRecv(void)
virtual void Deserialize(TagBuffer i)
virtual uint32_t GetSerializedSize(void) const
virtual Ptr< Node > GetNode(void) const
virtual int Listen(void)
Listen for incoming connections.
virtual uint32_t GetRxAvailable(void) const
tag a set of bytes in a packet
Definition: tag.h:36
virtual int Send(Ptr< Packet > p, uint32_t flags)
Send data (or dummy data) to the remote host.
virtual int SendTo(Ptr< Packet > p, uint32_t flags, const Address &toAddress)
Send data to a specified peer.
This class implements a tag that carries the ns3 device name from where a packet is coming...
virtual bool GetAllowBroadcast() const
Query whether broadcast datagram transmissions are allowed.
virtual void Deserialize(TagBuffer i)
virtual int Close(void)
Close a socket.
read and write tag data
Definition: tag-buffer.h:51
virtual uint32_t GetTxAvailable(void) const
Returns the number of bytes which can be sent in a single call to Send.
virtual void Serialize(TagBuffer i) const
NetDevice::PacketType GetPacketType(void) const
virtual void Print(std::ostream &os) const
virtual TypeId GetInstanceTypeId(void) const
virtual int Connect(const Address &address)
Initiate a connection to a remote host.
virtual int Bind6(void)
Allocate a local IPv6 endpoint for this socket.
std::string GetDeviceName(void) const
This class implements a tag that carries the dest address of a packet and the packet type...
virtual int ShutdownSend(void)
a unique identifier for an interface.
Definition: type-id.h:44
virtual enum SocketType GetSocketType(void) const
void SetDeviceName(std::string n)