Bug 671 add packet-info-tag.cc for IP_PKTINFO/IPV6_PKTINFO

This commit is contained in:
Hajime Tazaki committed 2010-07-13 13:00:55 +09:00
1 parent 06440be530
commit b907576cdf
29 files changed
+892 -65

No files matched your search

+284
View File
@@ -0,0 +1,284 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2010 Hajime Tazaki
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Authors: Hajime Tazaki <tazaki@sfc.wide.ad.jp>
*/
#include <stdint.h>
#include "ns3/ipv4-address.h"
#include "ns3/test.h"
#include "ipv4-packet-info-tag.h"
namespace ns3 {
Ipv4PacketInfoTag::Ipv4PacketInfoTag ()
: m_addr (Ipv4Address ()),
m_spec_dst (Ipv4Address ()),
m_ifindex (0),
m_ttl (0)
{
}
void
Ipv4PacketInfoTag::SetAddress (Ipv4Address addr)
{
m_addr = addr;
}
Ipv4Address
Ipv4PacketInfoTag::GetAddress (void) const
{
return m_addr;
}
void
Ipv4PacketInfoTag::SetLocalAddress (Ipv4Address addr)
{
m_spec_dst = addr;
}
Ipv4Address
Ipv4PacketInfoTag::GetLocalAddress (void) const
{
return m_spec_dst;
}
void
Ipv4PacketInfoTag::SetRecvIf (uint32_t ifindex)
{
m_ifindex = ifindex;
}
uint32_t
Ipv4PacketInfoTag::GetRecvIf (void) const
{
return m_ifindex;
}
void
Ipv4PacketInfoTag::SetTtl (uint8_t ttl)
{
m_ttl = ttl;
}
uint8_t
Ipv4PacketInfoTag::GetTtl (void) const
{
return m_ttl;
}
TypeId
Ipv4PacketInfoTag::GetTypeId (void)
{
static TypeId tid = TypeId ("ns3::Ipv4PacketInfoTag")
.SetParent<Tag> ()
.AddConstructor<Ipv4PacketInfoTag> ()
;
return tid;
}
TypeId
Ipv4PacketInfoTag::GetInstanceTypeId (void) const
{
return GetTypeId ();
}
uint32_t
Ipv4PacketInfoTag::GetSerializedSize (void) const
{
return 4 + 4
+ sizeof (uint32_t)
+ sizeof (uint8_t);
}
void
Ipv4PacketInfoTag::Serialize (TagBuffer i) const
{
uint8_t buf[4];
m_addr.Serialize (buf);
i.Write (buf, 4);
m_spec_dst.Serialize (buf);
i.Write (buf, 4);
i.WriteU32 (m_ifindex);
i.WriteU8 (m_ttl);
}
void
Ipv4PacketInfoTag::Deserialize (TagBuffer i)
{
uint8_t buf[4];
i.Read (buf, 4);
m_addr.Deserialize (buf);
i.Read (buf, 4);
m_spec_dst.Deserialize (buf);
m_ifindex = i.ReadU32 ();
m_ttl = i.ReadU8 ();
}
void
Ipv4PacketInfoTag::Print (std::ostream &os) const
{
os << "Ipv4 PKTINFO [DestAddr: " << m_addr;
os << ", Local Address:" << m_spec_dst;
os << ", RecvIf:" << (uint32_t) m_ifindex;
os << ", TTL:" << (uint32_t) m_ttl;
os << "] ";
}
}//namespace ns3
//-----------------------------------------------------------------------------
// Unit tests
//-----------------------------------------------------------------------------
#include "ns3/log.h"
#include "ns3/abort.h"
#include "ns3/attribute.h"
#include "ns3/object-factory.h"
#include "ns3/internet-stack-helper.h"
#include "ns3/ipv4-address-helper.h"
#include "ns3/csma-helper.h"
#include "ns3/node-container.h"
#include "ns3/object-factory.h"
#include "ns3/socket-factory.h"
#include "ns3/udp-socket-factory.h"
#include "ns3/udp-socket.h"
#include "ns3/ipv4-raw-socket-factory.h"
#include "ns3/inet-socket-address.h"
#include "ns3/simulator.h"
namespace ns3 {
class Ipv4PacketInfoTagTest: public TestCase
{
public:
Ipv4PacketInfoTagTest ();
private:
virtual bool DoRun (void);
void RxCb (Ptr<Socket> socket);
void DoSendData (Ptr<Socket> socket, std::string to);
};
Ipv4PacketInfoTagTest::Ipv4PacketInfoTagTest ()
: TestCase ("Ipv4PacketInfoTagTest")
{}
void
Ipv4PacketInfoTagTest::RxCb (Ptr<Socket> socket)
{
uint32_t availableData;
Ptr<Packet> m_receivedPacket;
availableData = socket->GetRxAvailable ();
m_receivedPacket = socket->Recv (std::numeric_limits<uint32_t>::max(), 0);
NS_ASSERT (availableData == m_receivedPacket->GetSize ());
Ipv4PacketInfoTag tag;
bool found;
found = m_receivedPacket->RemovePacketTag (tag);
NS_ASSERT (found);
tag.Print (std::cout);
}
void
Ipv4PacketInfoTagTest::DoSendData (Ptr<Socket> socket, std::string to)
{
Address realTo = InetSocketAddress (Ipv4Address (to.c_str()), 200);
if (DynamicCast<UdpSocket> (socket) != 0)
{
NS_TEST_EXPECT_MSG_EQ (socket->SendTo (Create<Packet> (123), 0, realTo),
123, "XXX");
}
// Should only Ipv4RawSock
else
{
socket->SendTo (Create<Packet> (123), 0, realTo);
}
}
bool
Ipv4PacketInfoTagTest::DoRun (void)
{
NodeContainer n;
n.Create (2);
InternetStackHelper internet;
internet.Install (n);
CsmaHelper csma;
NetDeviceContainer d = csma.Install (n);
Ipv4AddressHelper ipv4;
ipv4.SetBase ("10.1.1.0", "255.255.255.0");
Ipv4InterfaceContainer i = ipv4.Assign (d);
// IPv4 test
Ptr<SocketFactory> factory = n.Get (0)->GetObject<SocketFactory> (UdpSocketFactory::GetTypeId ());
Ptr<Socket> socket = factory->CreateSocket ();
InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (), 200);
socket->Bind (local);
socket->SetRecvPktInfo (true);
socket->SetRecvCallback (MakeCallback (&ns3::Ipv4PacketInfoTagTest::RxCb, this));
// receive on loopback
Simulator::ScheduleWithContext (socket->GetNode ()->GetId (), Seconds (0),
&Ipv4PacketInfoTagTest::DoSendData, this, socket, "127.0.0.1");
Simulator::Run ();
// send from node1 and recved via csma
Ptr<SocketFactory> factory2 = n.Get (1)->GetObject<SocketFactory> (UdpSocketFactory::GetTypeId ());
Ptr<Socket> socket2 = factory2->CreateSocket ();
Simulator::ScheduleWithContext (socket2->GetNode ()->GetId (), Seconds (0),
&Ipv4PacketInfoTagTest::DoSendData, this, socket, "10.1.1.1");
Simulator::Run ();
// ipv4 w rawsocket
factory = n.Get (0)->GetObject<SocketFactory> (Ipv4RawSocketFactory::GetTypeId ());
socket = factory->CreateSocket ();
local = InetSocketAddress (Ipv4Address::GetAny (), 0);
socket->Bind (local);
socket->SetRecvPktInfo (true);
socket->SetRecvCallback (MakeCallback (&ns3::Ipv4PacketInfoTagTest::RxCb, this));
// receive on loopback
Simulator::ScheduleWithContext (socket->GetNode ()->GetId (), Seconds (0),
&Ipv4PacketInfoTagTest::DoSendData, this, socket, "127.0.0.1");
Simulator::Run ();
// send from node1 and recved via csma
factory2 = n.Get (1)->GetObject<SocketFactory> (Ipv4RawSocketFactory::GetTypeId ());
socket2 = factory2->CreateSocket ();
Simulator::ScheduleWithContext (socket2->GetNode ()->GetId (), Seconds (0),
&Ipv4PacketInfoTagTest::DoSendData, this, socket, "10.1.1.1");
Simulator::Run ();
return 0;
}
static class Ipv4PacketInfoTagTestSuite : public TestSuite
{
public:
Ipv4PacketInfoTagTestSuite ();
private:
} g_packetinfotagTests;
Ipv4PacketInfoTagTestSuite::Ipv4PacketInfoTagTestSuite ()
: TestSuite ("ipv4-packet-info-tag", UNIT)
{
AddTestCase (new Ipv4PacketInfoTagTest ());
}
}
+89
View File
@@ -0,0 +1,89 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2010 Hajime Tazaki
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Authors: Hajime Tazaki <tazaki@sfc.wide.ad.jp>
*/
#ifndef __IPV4_PACKET_INFO_TAG_H__
#define __IPV4_PACKET_INFO_TAG_H__
#include "ns3/tag.h"
namespace ns3 {
class Node;
class Packet;
/**
* \brief This class implements Linux struct pktinfo
* in order to deliver ancillary information to the socket interface.
* This is used with socket option such as IP_PKTINFO, IP_RECVTTL,
* IP_RECVTOS. See linux manpage ip(7).
*
* This tag in the send direction is presently not enabled but we
* would accept a patch along those lines in the future.
*/
class Ipv4PacketInfoTag : public Tag
{
public:
Ipv4PacketInfoTag ();
// Implemented, but not used in the stack yet
void SetAddress (Ipv4Address addr);
// Implemented, but not used in the stack yet
Ipv4Address GetAddress (void) const;
// This corresponds to "ipi_spec_dst" in struct in_pktinfo.
// Implemented, but not used in the stack yet
void SetLocalAddress (Ipv4Address addr);
// This corresponds to "ipi_spec_dst" in struct in_pktinfo.
// Implemented, but not used in the stack yet
Ipv4Address GetLocalAddress (void) const;
void SetRecvIf (uint32_t ifindex);
uint32_t GetRecvIf (void) const;
// Implemented, but not used in the stack yet
void SetTtl (uint8_t ttl);
// Implemented, but not used in the stack yet
uint8_t GetTtl (void) const;
static TypeId GetTypeId (void);
virtual TypeId GetInstanceTypeId (void) const;
virtual uint32_t GetSerializedSize (void) const;
virtual void Serialize (TagBuffer i) const;
virtual void Deserialize (TagBuffer i);
virtual void Print (std::ostream &os) const;
private:
// Linux IP_PKTINFO ip(7) implementation
//
// struct in_pktinfo {
// unsigned int ipi_ifindex; /* Interface index */
// struct in_addr ipi_spec_dst; /* Local address */
// struct in_addr ipi_addr; /* Header Destination
// address */
// };
Ipv4Address m_addr;
Ipv4Address m_spec_dst;
uint32_t m_ifindex;
// Uset for IP_RECVTTL, though not implemented yet.
uint8_t m_ttl;
};
} //namespace ns3
#endif /* __IPV4_PACKET_INFO_TAG_H__ */
+294
View File
@@ -0,0 +1,294 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2010 Hajime Tazaki
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Authors: Hajime Tazaki <tazaki@sfc.wide.ad.jp>
*/
#include <stdint.h>
#include "ns3/ipv6-address.h"
#include "ns3/test.h"
#include "ipv6-packet-info-tag.h"
namespace ns3 {
Ipv6PacketInfoTag::Ipv6PacketInfoTag ()
: m_addr (Ipv6Address ()),
m_ifindex (0),
m_hoplimit (0),
m_tclass (0)
{
}
void
Ipv6PacketInfoTag::SetAddress (Ipv6Address addr)
{
m_addr = addr;
}
Ipv6Address
Ipv6PacketInfoTag::GetAddress (void) const
{
return m_addr;
}
void
Ipv6PacketInfoTag::SetRecvIf (uint32_t ifindex)
{
m_ifindex = ifindex;
}
uint32_t
Ipv6PacketInfoTag::GetRecvIf (void) const
{
return m_ifindex;
}
void
Ipv6PacketInfoTag::SetHoplimit (uint8_t ttl)
{
m_hoplimit = ttl;
}
uint8_t
Ipv6PacketInfoTag::GetHoplimit (void) const
{
return m_hoplimit;
}
void
Ipv6PacketInfoTag::SetTrafficClass (uint8_t tclass)
{
m_tclass = tclass;
}
uint8_t
Ipv6PacketInfoTag::GetTrafficClass (void) const
{
return m_tclass;
}
TypeId
Ipv6PacketInfoTag::GetTypeId (void)
{
static TypeId tid = TypeId ("ns3::Ipv6PacketInfoTag")
.SetParent<Tag> ()
.AddConstructor<Ipv6PacketInfoTag> ()
;
return tid;
}
TypeId
Ipv6PacketInfoTag::GetInstanceTypeId (void) const
{
return GetTypeId ();
}
uint32_t
Ipv6PacketInfoTag::GetSerializedSize (void) const
{
return 16
+ sizeof (uint8_t)
+ sizeof (uint8_t)
+ sizeof (uint8_t);
}
void
Ipv6PacketInfoTag::Serialize (TagBuffer i) const
{
uint8_t buf[16];
m_addr.Serialize (buf);
i.Write (buf, 16);
i.WriteU8 (m_ifindex);
i.WriteU8 (m_hoplimit);
i.WriteU8 (m_tclass);
}
void
Ipv6PacketInfoTag::Deserialize (TagBuffer i)
{
uint8_t buf[16];
i.Read (buf, 16);
m_addr.Deserialize (buf);
m_ifindex = i.ReadU8 ();
m_hoplimit = i.ReadU8 ();
m_tclass = i.ReadU8 ();
}
void
Ipv6PacketInfoTag::Print (std::ostream &os) const
{
os << "Ipv6 PKTINFO [DestAddr: " << m_addr;
os << ", RecvIf:" << (uint32_t) m_ifindex;
os << ", TTL:" << (uint32_t) m_hoplimit;
os << ", TClass:" << (uint32_t) m_tclass;
os << "] ";
}
}//namespace ns3
//-----------------------------------------------------------------------------
// Unit tests
//-----------------------------------------------------------------------------
#include "ns3/log.h"
#include "ns3/abort.h"
#include "ns3/attribute.h"
#include "ns3/object-factory.h"
#include "ns3/internet-stack-helper.h"
#include "ns3/ipv6-address-helper.h"
#include "ns3/csma-helper.h"
#include "ns3/node-container.h"
#include "ns3/object-factory.h"
#include "ns3/socket-factory.h"
#include "ns3/udp-socket-factory.h"
#include "ns3/udp-socket.h"
#include "ns3/ipv6-raw-socket-factory.h"
#include "ns3/inet6-socket-address.h"
#include "ns3/simulator.h"
#include "ns3/uinteger.h"
namespace ns3 {
class Ipv6PacketInfoTagTest: public TestCase
{
public:
Ipv6PacketInfoTagTest ();
private:
virtual bool DoRun (void);
void RxCb (Ptr<Socket> socket);
void DoSendData (Ptr<Socket> socket, std::string to);
};
Ipv6PacketInfoTagTest::Ipv6PacketInfoTagTest ()
: TestCase ("Ipv6PacketInfoTagTest")
{}
void
Ipv6PacketInfoTagTest::RxCb (Ptr<Socket> socket)
{
uint32_t availableData;
Ptr<Packet> m_receivedPacket;
availableData = socket->GetRxAvailable ();
m_receivedPacket = socket->Recv (std::numeric_limits<uint32_t>::max(), 0);
NS_ASSERT (availableData == m_receivedPacket->GetSize ());
Ipv6PacketInfoTag tag;
bool found;
found = m_receivedPacket->RemovePacketTag (tag);
NS_ASSERT (found);
tag.Print (std::cout);
std::cout << std::endl;
}
void
Ipv6PacketInfoTagTest::DoSendData (Ptr<Socket> socket, std::string to)
{
Address realTo = Inet6SocketAddress (Ipv6Address (to.c_str()), 200);
if (DynamicCast<UdpSocket> (socket) != 0)
{
NS_TEST_EXPECT_MSG_EQ (socket->SendTo (Create<Packet> (123), 0, realTo),
123, "XXX");
}
// Should only Ipv6RawSock
else
{
socket->SendTo (Create<Packet> (123), 0, realTo);
}
}
bool
Ipv6PacketInfoTagTest::DoRun (void)
{
NodeContainer n;
n.Create (2);
InternetStackHelper internet;
internet.Install (n);
CsmaHelper csma;
NetDeviceContainer d = csma.Install (n);
Ipv6AddressHelper ipv6;
ipv6.NewNetwork(Ipv6Address("2000:1000:0:2000::"), Ipv6Prefix(64));
Ipv6InterfaceContainer i = ipv6.Assign (d);
// ipv6 w rawsocket
Ptr<SocketFactory> factory = n.Get (0)->GetObject<SocketFactory> (Ipv6RawSocketFactory::GetTypeId ());
Ptr<Socket> socket = factory->CreateSocket ();
Inet6SocketAddress local = Inet6SocketAddress (Ipv6Address::GetAny (), 0);
socket->SetAttribute ("Protocol", UintegerValue (Ipv6Header::IPV6_ICMPV6));
socket->Bind (local);
socket->SetRecvPktInfo (true);
socket->SetRecvCallback (MakeCallback (&ns3::Ipv6PacketInfoTagTest::RxCb, this));
// receive on loopback
Simulator::ScheduleWithContext (socket->GetNode ()->GetId (), Seconds (0),
&Ipv6PacketInfoTagTest::DoSendData, this, socket, "::1");
Simulator::Run ();
// send from node1 and recved via csma
Ptr<SocketFactory> factory2 = n.Get (1)->GetObject<SocketFactory> (Ipv6RawSocketFactory::GetTypeId ());
Ptr<Socket> socket2 = factory2->CreateSocket ();
std::stringstream dst;
dst << i.GetAddress (0, 0);
Simulator::ScheduleWithContext (socket2->GetNode ()->GetId (), Seconds (0),
&Ipv6PacketInfoTagTest::DoSendData, this, socket,
dst.str ());
Simulator::Run ();
#ifdef UDP6_SUPPORTED
// IPv6 test
factory = n.Get (0)->GetObject<SocketFactory> (UdpSocketFactory::GetTypeId ());
socket = factory->CreateSocket ();
local = Inet6SocketAddress (Ipv6Address::GetAny (), 200);
socket->Bind (local);
socket->SetRecvPktInfo (true);
socket->SetRecvCallback (MakeCallback (&ns3::Ipv6PacketInfoTagTest::RxCb, this));
// receive on loopback
Simulator::ScheduleWithContext (socket->GetNode ()->GetId (), Seconds (0),
&Ipv6PacketInfoTagTest::DoSendData, this, socket, "::1");
Simulator::Run ();
// send from node1 and recved via csma
factory2 = n.Get (1)->GetObject<SocketFactory> (UdpSocketFactory::GetTypeId ());
socket2 = factory2->CreateSocket ();
Simulator::ScheduleWithContext (socket2->GetNode ()->GetId (), Seconds (0),
&Ipv6PacketInfoTagTest::DoSendData, this, socket, "10.1.1.1");
Simulator::Run ();
#endif // UDP6_SUPPORTED
// IPv6 test
return 0;
}
static class Ipv6PacketInfoTagTestSuite : public TestSuite
{
public:
Ipv6PacketInfoTagTestSuite ();
private:
} g_packetinfotagTests;
Ipv6PacketInfoTagTestSuite::Ipv6PacketInfoTagTestSuite ()
: TestSuite ("ipv6-packet-info-tag", UNIT)
{
AddTestCase (new Ipv6PacketInfoTagTest ());
}
}
+94
View File
@@ -0,0 +1,94 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2010 Hajime Tazaki
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Authors: Hajime Tazaki <tazaki@sfc.wide.ad.jp>
*/
#ifndef __IPV6_PACKET_INFO_TAG_H__
#define __IPV6_PACKET_INFO_TAG_H__
#include "ns3/tag.h"
namespace ns3 {
class Node;
class Packet;
/**
* \brief This class implements a tag that carries socket ancillary
* data to the socket interface. This is used like
* socket option of IP_PKTINFO/IPV6_PKTINFO in RFC 3542
* See: http://tools.ietf.org/html/rfc3542
*
* This tag in the send direction is presently not enabled but we
* would accept a patch along those lines in the future. To include
* the nexthop in the send direction would increase the size of the
* tag beyond 20 bytes, so in that case, we recommend that an
* additional tag be used to carry the IPv6 next hop address.
*/
class Ipv6PacketInfoTag : public Tag
{
public:
Ipv6PacketInfoTag ();
// Implemented, but not used in the stack yet
void SetAddress (Ipv6Address addr);
// Implemented, but not used in the stack yet
Ipv6Address GetAddress (void) const;
void SetRecvIf (uint32_t ifindex);
uint32_t GetRecvIf (void) const;
// Implemented, but not used in the stack yet
void SetHoplimit (uint8_t ttl);
// Implemented, but not used in the stack yet
uint8_t GetHoplimit (void) const;
// Implemented, but not used in the stack yet
void SetTrafficClass (uint8_t tclass);
// Implemented, but not used in the stack yet
uint8_t GetTrafficClass (void) const;
static TypeId GetTypeId (void);
virtual TypeId GetInstanceTypeId (void) const;
virtual uint32_t GetSerializedSize (void) const;
virtual void Serialize (TagBuffer i) const;
virtual void Deserialize (TagBuffer i);
virtual void Print (std::ostream &os) const;
private:
/*
* RFC 3542 includes
* for outgoing packet,
* 1. the source IPv6 address,
* 2. the outgoing interface index,
* 3. the outgoing hop limit,
* 4. the next hop address, and
* 5. the outgoing traffic class value.
*
* for incoming packet,
* 1. the destination IPv6 address,
* 2. the arriving interface index,
* 3. the arriving hop limit, and
* 4. the arriving traffic class value.
*/
Ipv6Address m_addr;
uint8_t m_ifindex;
uint8_t m_hoplimit;
uint8_t m_tclass;
};
} //namespace ns3
#endif /* __IPV6_PACKET_INFO_TAG_H__ */
+8
View File
@@ -34,6 +34,7 @@ namespace ns3 {
Socket::Socket (void)
{
m_boundnetdevice = 0;
m_recvpktinfo = false;
NS_LOG_FUNCTION_NOARGS ();
}
@@ -324,6 +325,13 @@ Socket::GetBoundNetDevice ()
return m_boundnetdevice;
}
void
Socket::SetRecvPktInfo (bool flag)
{
NS_LOG_FUNCTION_NOARGS ();
m_recvpktinfo = flag;
}
/***************************************************************
* Socket Tags
***************************************************************/
+11
View File
@@ -570,6 +570,16 @@ public:
*/
virtual bool GetAllowBroadcast () const = 0;
/**
* \brief Enable/Disable receive packet information to socket.
*
* For IP_PKTINFO/IP6_PKTINFO. This method is only usable for
* Raw socket and Datagram Socket. Not supported for Stream socket.
*
* \param Enable/Disable receive information
* \returns nothing
*/
void SetRecvPktInfo (bool flag);
protected:
void NotifyConnectionSucceeded (void);
@@ -583,6 +593,7 @@ protected:
void NotifyDataRecv (void);
virtual void DoDispose (void);
Ptr<NetDevice> m_boundnetdevice;
bool m_recvpktinfo;
private:
Callback<void, Ptr<Socket> > m_connectionSucceeded;
Callback<void, Ptr<Socket> > m_connectionFailed;
+4
View File
@@ -51,6 +51,8 @@ def build(bld):
'radiotap-header.cc',
'spectrum-phy.cc',
'spectrum-channel.cc',
'ipv4-packet-info-tag.cc',
'ipv6-packet-info-tag.cc',
]
headers = bld.new_task_gen('ns3header')
@@ -103,4 +105,6 @@ def build(bld):
'spectrum-phy.h',
'spectrum-channel.h',
'phy-mac.h',
'ipv4-packet-info-tag.h',
'ipv6-packet-info-tag.h',
]