Raw socket nearly work
This commit is contained in:
@@ -40,6 +40,9 @@
|
||||
#include "icmpv4-l4-protocol.h"
|
||||
#include "ipv4-interface.h"
|
||||
#include "ipv4-raw-socket-impl.h"
|
||||
#include "raw-socket-impl.h"
|
||||
|
||||
|
||||
|
||||
NS_LOG_COMPONENT_DEFINE ("Ipv4L3Protocol");
|
||||
|
||||
@@ -125,6 +128,18 @@ Ipv4L3Protocol::CreateRawSocket (void)
|
||||
m_sockets.push_back (socket);
|
||||
return socket;
|
||||
}
|
||||
|
||||
Ptr<Socket>
|
||||
Ipv4L3Protocol::CreateRawSocket2 (void)
|
||||
{
|
||||
NS_LOG_FUNCTION (this);
|
||||
Ptr<RawSocketImpl> socket = CreateObject<RawSocketImpl> ();
|
||||
socket->SetNode (m_node);
|
||||
m_rawSocket.push_back (socket);
|
||||
return socket;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Ipv4L3Protocol::DeleteRawSocket (Ptr<Socket> socket)
|
||||
{
|
||||
|
||||
@@ -30,6 +30,8 @@
|
||||
#include "ns3/traced-callback.h"
|
||||
#include "ns3/ipv4-header.h"
|
||||
#include "ns3/ipv4-routing-protocol.h"
|
||||
#include "raw-socket-impl.h"
|
||||
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
@@ -71,6 +73,7 @@ public:
|
||||
Ptr<Ipv4RoutingProtocol> GetRoutingProtocol (void) const;
|
||||
|
||||
Ptr<Socket> CreateRawSocket (void);
|
||||
Ptr<Socket> CreateRawSocket2 (void);
|
||||
void DeleteRawSocket (Ptr<Socket> socket);
|
||||
|
||||
/**
|
||||
@@ -206,6 +209,7 @@ private:
|
||||
|
||||
typedef std::list<Ptr<Ipv4Interface> > Ipv4InterfaceList;
|
||||
typedef std::list<Ptr<Ipv4RawSocketImpl> > SocketList;
|
||||
typedef std::list<Ptr<RawSocketImpl> > RawSocketList;
|
||||
typedef std::list<Ptr<Ipv4L4Protocol> > L4List_t;
|
||||
|
||||
bool m_ipForward;
|
||||
@@ -222,6 +226,7 @@ private:
|
||||
Ptr<Ipv4RoutingProtocol> m_routingProtocol;
|
||||
|
||||
SocketList m_sockets;
|
||||
RawSocketList m_rawSocket;
|
||||
};
|
||||
|
||||
} // Namespace ns3
|
||||
|
||||
24
src/internet-stack/raw-socket-factory-impl.cc
Normal file
24
src/internet-stack/raw-socket-factory-impl.cc
Normal file
@@ -0,0 +1,24 @@
|
||||
#include "raw-socket-factory-impl.h"
|
||||
#include "raw-socket-impl.h"
|
||||
#include "ipv4-l3-protocol.h"
|
||||
#include "ns3/socket.h"
|
||||
#include "ns3/log.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
void
|
||||
RawSocketFactoryImpl::DoDispose (void)
|
||||
{
|
||||
m_ipv4 = 0;
|
||||
RawSocketFactory::DoDispose ();
|
||||
}
|
||||
|
||||
Ptr<Socket>
|
||||
RawSocketFactoryImpl::CreateSocket (void)
|
||||
{
|
||||
|
||||
Ptr<Socket> socket = m_ipv4->CreateRawSocket2 ();
|
||||
return socket;
|
||||
}
|
||||
|
||||
} // namespace ns3
|
||||
26
src/internet-stack/raw-socket-factory-impl.h
Normal file
26
src/internet-stack/raw-socket-factory-impl.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef RAW_SOCKET_FACTORY_IMPL_H
|
||||
#define RAW_SOCKET_FACTORY_IMPL_H
|
||||
|
||||
#include "ns3/raw-socket-factory.h"
|
||||
#include "ipv4-l3-protocol.h"
|
||||
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
class Ipv4L3Protocol;
|
||||
|
||||
class RawSocketFactoryImpl : public RawSocketFactory
|
||||
{
|
||||
protected:
|
||||
virtual void DoDispose (void);
|
||||
public:
|
||||
virtual Ptr<Socket> CreateSocket (void);
|
||||
private:
|
||||
Ptr<Ipv4L3Protocol> m_ipv4;
|
||||
|
||||
};
|
||||
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
#endif /* RAW_SOCKET_FACTORY_IMPL_H */
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef IPV4_RAW_SOCKET_IMPL_H
|
||||
#define IPV4_RAW_SOCKET_IMPL_H
|
||||
#ifndef RAW_SOCKET_IMPL_H
|
||||
#define RAW_SOCKET_IMPL_H
|
||||
|
||||
#include "ns3/socket.h"
|
||||
#include "ns3/ipv4-header.h"
|
||||
|
||||
@@ -94,6 +94,7 @@ def build(bld):
|
||||
'pending-data.cc',
|
||||
'sequence-number.cc',
|
||||
'rtt-estimator.cc',
|
||||
'raw-socket-factory-impl.cc',
|
||||
'raw-socket-impl.cc',
|
||||
'ipv4-raw-socket-factory-impl.cc',
|
||||
'ipv4-raw-socket-impl.cc',
|
||||
|
||||
35
src/node/raw-socket-factory.cc
Normal file
35
src/node/raw-socket-factory.cc
Normal file
@@ -0,0 +1,35 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2007 INRIA
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
|
||||
*/
|
||||
#include "raw-socket-factory.h"
|
||||
#include "ns3/uinteger.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
NS_OBJECT_ENSURE_REGISTERED (RawSocketFactory);
|
||||
|
||||
TypeId RawSocketFactory::GetTypeId (void)
|
||||
{
|
||||
static TypeId tid = TypeId ("ns3::RawSocketFactory")
|
||||
.SetParent<SocketFactory> ()
|
||||
;
|
||||
return tid;
|
||||
}
|
||||
|
||||
} // namespace ns3
|
||||
46
src/node/raw-socket-factory.h
Normal file
46
src/node/raw-socket-factory.h
Normal file
@@ -0,0 +1,46 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2007 INRIA
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
|
||||
*/
|
||||
#ifndef RAW_SOCKET_FACTORY_H
|
||||
#define RAW_SOCKET_FACTORY_H
|
||||
|
||||
#include "socket-factory.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
class Socket;
|
||||
|
||||
/**
|
||||
* \ingroup socket
|
||||
*
|
||||
* \brief API to create RAW socket instances
|
||||
*
|
||||
* This abstract class defines the API for RAW socket factory.
|
||||
*
|
||||
*/
|
||||
class RawSocketFactory : public SocketFactory
|
||||
{
|
||||
public:
|
||||
static TypeId GetTypeId (void);
|
||||
|
||||
};
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
#endif /* RAW_SOCKET_FACTORY_H */
|
||||
@@ -45,7 +45,10 @@ Ptr<Socket>
|
||||
Socket::CreateSocket (Ptr<Node> node, TypeId tid)
|
||||
{
|
||||
Ptr<Socket> s;
|
||||
NS_LOG_UNCOND(tid);
|
||||
NS_ASSERT(node != 0);
|
||||
Ptr<SocketFactory> socketFactory = node->GetObject<SocketFactory> (tid);
|
||||
NS_ASSERT(socketFactory != 0);
|
||||
s = socketFactory->CreateSocket ();
|
||||
NS_ASSERT (s != 0);
|
||||
return s;
|
||||
|
||||
@@ -30,6 +30,7 @@ def build(bld):
|
||||
'packet-socket.cc',
|
||||
'udp-socket.cc',
|
||||
'udp-socket-factory.cc',
|
||||
'raw-socket-factory.cc',
|
||||
'tcp-socket.cc',
|
||||
'tcp-socket-factory.cc',
|
||||
'ipv4.cc',
|
||||
@@ -71,6 +72,7 @@ def build(bld):
|
||||
'packet-socket-factory.h',
|
||||
'udp-socket.h',
|
||||
'udp-socket-factory.h',
|
||||
'raw-socket-factory.h',
|
||||
'tcp-socket.h',
|
||||
'tcp-socket-factory.h',
|
||||
'ipv4.h',
|
||||
|
||||
@@ -43,6 +43,11 @@
|
||||
#include "ns3/nstime.h"
|
||||
#include "ns3/net-device.h"
|
||||
|
||||
#include "ns3/raw-socket-factory.h"
|
||||
#include "ns3/ipv4-raw-socket-factory.h"
|
||||
|
||||
|
||||
|
||||
/// UDP Port for AODV control traffic
|
||||
#define AODV_PORT 654
|
||||
|
||||
@@ -66,6 +71,7 @@ RoutingProtocol::InsertBroadcastId (Ipv4Address id, uint32_t bid)
|
||||
bool
|
||||
RoutingProtocol::LookupBroadcastId (Ipv4Address id, uint32_t bid)
|
||||
{
|
||||
NS_LOG_FUNCTION(this);
|
||||
PurgeBroadcastId ();
|
||||
for (std::vector<BroadcastId>::const_iterator i = m_broadcastIdCache.begin (); i != m_broadcastIdCache.end (); ++i)
|
||||
if (i->src == id && i->id == bid)
|
||||
@@ -229,7 +235,9 @@ RoutingProtocol::Start ()
|
||||
continue;
|
||||
|
||||
// Create a socket to listen only on this interface
|
||||
Ptr<Socket> socket = Socket::CreateSocket (GetObject<Node> (), TypeId::LookupByName ("ns3::UdpSocketFactory"));
|
||||
Ptr<RawSocketImpl> socket = CreateObject<RawSocketImpl> ();
|
||||
socket->SetNode(GetObject<Node> ());
|
||||
//Ptr<Socket> socket = Socket::CreateSocket (GetObject<Node> (), RawSocketFactory::GetTypeId());
|
||||
NS_ASSERT (socket != 0);
|
||||
int status = socket->Bind (InetSocketAddress (iface.GetLocal (), AODV_PORT));
|
||||
NS_ASSERT (status != -1);
|
||||
@@ -436,6 +444,8 @@ RoutingProtocol::SendRequest (Ipv4Address dst, bool D, bool G)
|
||||
// Create RREQ header
|
||||
TypeHeader tHeader (AODVTYPE_RREQ);
|
||||
RreqHeader rreqHeader;
|
||||
Ipv4Header ipv4Header;
|
||||
ipv4Header.SetTtl (NET_DIAMETER);
|
||||
rreqHeader.SetDst (dst);
|
||||
|
||||
RoutingTableEntry rt;
|
||||
@@ -488,6 +498,9 @@ RoutingProtocol::SendRequest (Ipv4Address dst, bool D, bool G)
|
||||
rreqHeader.SetOrigin (iface.GetLocal ());
|
||||
InsertBroadcastId (iface.GetLocal (), m_broadcastID);
|
||||
|
||||
ipv4Header.SetSource (iface.GetLocal ());
|
||||
ipv4Header.SetDestination (iface.GetBroadcast());
|
||||
|
||||
packet->AddHeader (rreqHeader);
|
||||
packet->AddHeader (tHeader);
|
||||
socket->Send (packet);
|
||||
|
||||
Reference in New Issue
Block a user