A Discrete-Event Network Simulator
API
packet-socket.h
Go to the documentation of this file.
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
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 * 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
23
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"
31
32namespace ns3 {
33
34class Node;
35class Packet;
36class NetDevice;
37class PacketSocketAddress;
38
93class PacketSocket : public Socket
94{
95public:
100 static TypeId GetTypeId (void);
101
102 PacketSocket ();
103 virtual ~PacketSocket ();
104
109 void SetNode (Ptr<Node> node);
110
111 virtual enum SocketErrno GetErrno (void) const;
112 virtual enum SocketType GetSocketType (void) const;
113 virtual Ptr<Node> GetNode (void) const;
121 virtual int Bind (void);
129 virtual int Bind6 (void);
137 virtual int Bind (const Address & address);
138 virtual int Close (void);
139 virtual int ShutdownSend (void);
140 virtual int ShutdownRecv (void);
141 virtual int Connect (const Address &address);
142 virtual int Listen (void);
143 virtual uint32_t GetTxAvailable (void) const;
144 virtual int Send (Ptr<Packet> p, uint32_t flags);
145 virtual int SendTo (Ptr<Packet> p, uint32_t flags, const Address &toAddress);
146 virtual uint32_t GetRxAvailable (void) const;
147 virtual Ptr<Packet> Recv (uint32_t maxSize, uint32_t flags);
148 virtual Ptr<Packet> RecvFrom (uint32_t maxSize, uint32_t flags,
149 Address &fromAddress);
150 virtual int GetSockName (Address &address) const;
151 virtual int GetPeerName (Address &address) const;
152 virtual bool SetAllowBroadcast (bool allowBroadcast);
153 virtual bool GetAllowBroadcast () const;
154
155private:
166 void ForwardUp (Ptr<NetDevice> device, Ptr<const Packet> packet,
167 uint16_t protocol, const Address &from, const Address &to,
168 NetDevice::PacketType packetType);
176
183 virtual void DoDispose (void);
184
188 enum State {
190 STATE_BOUND, // open and bound
191 STATE_CONNECTED, // open, bound and connected
193 };
194
196 mutable enum SocketErrno m_errno;
200 uint16_t m_protocol;
204
205 std::queue<std::pair<Ptr<Packet>, Address> > m_deliveryQueue;
207
210
211 // Socket options (attributes)
213
214};
215
219class PacketSocketTag : public Tag
220{
221public:
240 void SetDestAddress(Address a);
245 Address GetDestAddress (void) const;
246
251 static TypeId GetTypeId (void);
252 virtual TypeId GetInstanceTypeId (void) const;
253 virtual uint32_t GetSerializedSize (void) const;
254 virtual void Serialize (TagBuffer i) const;
255 virtual void Deserialize (TagBuffer i);
256 virtual void Print (std::ostream &os) const;
257
258private:
261};
265class DeviceNameTag : public Tag
266{
267public:
271 DeviceNameTag ();
276 void SetDeviceName (std::string n);
281 std::string GetDeviceName (void) const;
286 static TypeId GetTypeId (void);
287 virtual TypeId GetInstanceTypeId (void) const;
288 virtual uint32_t GetSerializedSize (void) const;
289 virtual void Serialize (TagBuffer i) const;
290 virtual void Deserialize (TagBuffer i);
291 virtual void Print (std::ostream &os) const;
292
293private:
294 std::string m_deviceName;
295};
296
297} // namespace ns3
298
299#endif /* PACKET_SOCKET_H */
300
301
a polymophic address class
Definition: address.h:91
This class implements a tag that carries the ns3 device name from where a packet is coming.
DeviceNameTag()
Create an empty DeviceNameTag.
virtual uint32_t GetSerializedSize(void) const
virtual void Serialize(TagBuffer i) const
virtual void Deserialize(TagBuffer i)
std::string m_deviceName
Device name.
static TypeId GetTypeId(void)
Get the type ID.
void SetDeviceName(std::string n)
Set the device name.
virtual void Print(std::ostream &os) const
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
std::string GetDeviceName(void) const
Get the device name from where the corresponding packet is coming.
PacketType
Packet types are used as they are in Linux.
Definition: net-device.h:297
an address for a packet socket
A PacketSocket is a link between an application and a net device.
Definition: packet-socket.h:94
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 int GetSockName(Address &address) const
Get socket address.
virtual bool SetAllowBroadcast(bool allowBroadcast)
Configure whether broadcast datagram transmissions are allowed.
virtual void DoDispose(void)
Destructor implementation.
virtual int Bind(void)
Bind the socket to the NetDevice and register the protocol handler.
Ptr< Node > m_node
the associated node
virtual int Send(Ptr< Packet > p, uint32_t flags)
Send data (or dummy data) to the remote host.
Address m_destAddr
Default destination address.
virtual int Listen(void)
Listen for incoming connections.
virtual int Connect(const Address &address)
Initiate a connection to a remote host.
State
States of the socket.
uint32_t m_rxAvailable
Rx queue size [Bytes].
virtual uint32_t GetTxAvailable(void) const
Returns the number of bytes which can be sent in a single call to Send.
virtual uint32_t GetRxAvailable(void) const
Return number of bytes which can be returned from one or multiple calls to Recv.
std::queue< std::pair< Ptr< Packet >, Address > > m_deliveryQueue
Rx queue.
virtual int ShutdownSend(void)
virtual Ptr< Node > GetNode(void) const
Return the node this socket is associated with.
int DoBind(const PacketSocketAddress &address)
Bind the socket to the NetDevice and register the protocol handler specified in the address.
virtual int ShutdownRecv(void)
virtual int SendTo(Ptr< Packet > p, uint32_t flags, const Address &toAddress)
Send data to a specified peer.
uint32_t m_rcvBufSize
Rx buffer size [Bytes].
virtual int Bind6(void)
Bind the socket to the NetDevice and register the protocol handler.
void ForwardUp(Ptr< NetDevice > device, Ptr< const Packet > packet, uint16_t protocol, const Address &from, const Address &to, NetDevice::PacketType packetType)
Called by the L3 protocol when it received a packet to pass on to TCP.
virtual enum SocketErrno GetErrno(void) const
Get last error number.
bool m_isSingleDevice
Is bound to a single netDevice.
virtual enum SocketType GetSocketType(void) const
virtual bool GetAllowBroadcast() const
Query whether broadcast datagram transmissions are allowed.
uint32_t GetMinMtu(PacketSocketAddress ad) const
Get the minimum MTU supported by the NetDevices bound to a specific address.
static TypeId GetTypeId(void)
Get the type ID.
uint16_t m_protocol
Socket protocol.
enum SocketErrno m_errno
Socket error code.
void SetNode(Ptr< Node > node)
Set the associated node.
virtual ~PacketSocket()
virtual int GetPeerName(Address &address) const
Get the peer address of a connected socket.
virtual int Close(void)
Close a socket.
bool m_shutdownSend
Send no longer allowed.
uint32_t m_device
index of the bound NetDevice
enum State m_state
Socket state.
TracedCallback< Ptr< const Packet > > m_dropTrace
Traced callback: dropped packets.
bool m_shutdownRecv
Receive no longer allowed.
This class implements a tag that carries the dest address of a packet and the packet type.
virtual void Print(std::ostream &os) const
Address m_destAddr
Destination address.
virtual void Serialize(TagBuffer i) const
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
NetDevice::PacketType GetPacketType(void) const
Get the packet type.
NetDevice::PacketType m_packetType
Packet type.
PacketSocketTag()
Create an empty PacketSocketTag.
static TypeId GetTypeId(void)
Get the type ID.
virtual uint32_t GetSerializedSize(void) const
void SetPacketType(NetDevice::PacketType t)
Set the packet type.
Address GetDestAddress(void) const
Get the destination address of the corresponding packet.
virtual void Deserialize(TagBuffer i)
void SetDestAddress(Address a)
Set the destination address of the corresponding packet.
A low-level Socket API based loosely on the BSD Socket API.
Definition: socket.h:67
SocketType
Enumeration of the possible socket types.
Definition: socket.h:104
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition: socket.h:82
Ptr< Packet > Recv(void)
Read a single packet from the socket.
Definition: socket.cc:175
read and write tag data
Definition: tag-buffer.h:52
tag a set of bytes in a packet
Definition: tag.h:37
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition: type-id.h:59
address
Definition: first.py:44
Every class exported by the ns3 library is enclosed in the ns3 namespace.