raw socket killed
This commit is contained in:
@@ -178,7 +178,7 @@ Ipv4Interface::SetForwarding (bool val)
|
||||
void
|
||||
Ipv4Interface::Send (Ptr<Packet> p, Ipv4Address dest)
|
||||
{
|
||||
NS_LOG_LOGIC (dest << *p);
|
||||
NS_LOG_FUNCTION (dest << *p);
|
||||
if (!IsUp())
|
||||
{
|
||||
return;
|
||||
@@ -188,7 +188,6 @@ Ipv4Interface::Send (Ptr<Packet> p, Ipv4Address dest)
|
||||
{
|
||||
// XXX additional checks needed here (such as whether multicast
|
||||
// goes to loopback)?
|
||||
NS_LOG_LOGIC ("Ipv4Interface::Send loopback");
|
||||
m_device->Send (p, m_device->GetBroadcast (),
|
||||
Ipv4L3Protocol::PROT_NUMBER);
|
||||
return;
|
||||
@@ -198,7 +197,6 @@ Ipv4Interface::Send (Ptr<Packet> p, Ipv4Address dest)
|
||||
{
|
||||
if (dest == (*i).GetLocal ())
|
||||
{
|
||||
NS_LOG_LOGIC ("to local");
|
||||
Ptr<Ipv4L3Protocol> ipv4 = m_node->GetObject<Ipv4L3Protocol> ();
|
||||
|
||||
ipv4->Receive (m_device, p, Ipv4L3Protocol::PROT_NUMBER,
|
||||
@@ -211,19 +209,19 @@ Ipv4Interface::Send (Ptr<Packet> p, Ipv4Address dest)
|
||||
}
|
||||
if (m_device->NeedsArp ())
|
||||
{
|
||||
NS_LOG_LOGIC ("Needs ARP" << " " << dest);
|
||||
NS_LOG_LOGIC ("Needs ARP" << " " << dest);
|
||||
Ptr<ArpL3Protocol> arp = m_node->GetObject<ArpL3Protocol> ();
|
||||
Address hardwareDestination;
|
||||
bool found = false;
|
||||
if (dest.IsBroadcast ())
|
||||
{
|
||||
NS_LOG_LOGIC ("All-network Broadcast");
|
||||
NS_LOG_LOGIC ("All-network Broadcast");
|
||||
hardwareDestination = m_device->GetBroadcast ();
|
||||
found = true;
|
||||
}
|
||||
else if (dest.IsMulticast ())
|
||||
{
|
||||
NS_LOG_LOGIC ("IsMulticast");
|
||||
NS_LOG_LOGIC ("IsMulticast");
|
||||
NS_ASSERT_MSG(m_device->IsMulticast (),
|
||||
"ArpIpv4Interface::SendTo (): Sending multicast packet over "
|
||||
"non-multicast device");
|
||||
@@ -237,7 +235,7 @@ Ipv4Interface::Send (Ptr<Packet> p, Ipv4Address dest)
|
||||
{
|
||||
if (dest.IsSubnetDirectedBroadcast ((*i).GetMask ()))
|
||||
{
|
||||
NS_LOG_LOGIC ("Subnetwork Broadcast hardwareDestination " << hardwareDestination);
|
||||
NS_LOG_LOGIC ("Subnetwork Broadcast");
|
||||
hardwareDestination = m_device->GetBroadcast ();
|
||||
found = true;
|
||||
break;
|
||||
@@ -245,21 +243,21 @@ Ipv4Interface::Send (Ptr<Packet> p, Ipv4Address dest)
|
||||
}
|
||||
if (!found)
|
||||
{
|
||||
NS_LOG_LOGIC ("ARP Lookup");
|
||||
NS_LOG_LOGIC ("ARP Lookup");
|
||||
found = arp->Lookup (p, dest, m_device, m_cache, &hardwareDestination);
|
||||
}
|
||||
}
|
||||
|
||||
if (found)
|
||||
{
|
||||
NS_LOG_LOGIC ("Address Resolved. Send.");
|
||||
NS_LOG_LOGIC ("Address Resolved. Send.");
|
||||
m_device ->Send (p, hardwareDestination,
|
||||
Ipv4L3Protocol::PROT_NUMBER);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
NS_LOG_LOGIC ("Doesn't need ARP");
|
||||
NS_LOG_LOGIC ("Doesn't need ARP");
|
||||
m_device->Send (p, m_device->GetBroadcast (),
|
||||
Ipv4L3Protocol::PROT_NUMBER);
|
||||
}
|
||||
|
||||
@@ -40,9 +40,6 @@
|
||||
#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");
|
||||
|
||||
@@ -128,35 +125,7 @@ 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->SetProtocol(17); // UdpL4Protocol::PROT_NUMBER
|
||||
socket->SetNode (m_node);
|
||||
m_rawSocket.push_back (socket);
|
||||
return socket;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Ipv4L3Protocol::DeleteRawSocket2 (Ptr<Socket> socket)
|
||||
{
|
||||
NS_LOG_FUNCTION (this << socket);
|
||||
for (RawSocketList::iterator i = m_rawSocket.begin (); i != m_rawSocket.end (); ++i)
|
||||
{
|
||||
if ((*i) == socket)
|
||||
{
|
||||
m_rawSocket.erase (i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
Ipv4L3Protocol::DeleteRawSocket (Ptr<Socket> socket)
|
||||
{
|
||||
NS_LOG_FUNCTION (this << socket);
|
||||
@@ -170,7 +139,6 @@ Ipv4L3Protocol::DeleteRawSocket (Ptr<Socket> socket)
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* This method is called by AddAgregate and completes the aggregation
|
||||
* by setting the node in the ipv4 stack
|
||||
@@ -392,7 +360,7 @@ Ipv4L3Protocol::Receive( Ptr<NetDevice> device, Ptr<const Packet> p, uint16_t pr
|
||||
{
|
||||
NS_LOG_FUNCTION (this << &device << p << protocol << from);
|
||||
|
||||
NS_LOG_LOGIC ("Packet from " << from << " received on node " <<
|
||||
NS_LOG_LOGIC ("Packet from " << from << " received on node " <<
|
||||
m_node->GetId ());
|
||||
|
||||
uint32_t interface = 0;
|
||||
@@ -430,22 +398,13 @@ Ipv4L3Protocol::Receive( Ptr<NetDevice> device, Ptr<const Packet> p, uint16_t pr
|
||||
|
||||
if (!ipHeader.IsChecksumOk ())
|
||||
{
|
||||
NS_LOG_LOGIC("bad check sum");
|
||||
m_dropTrace (packet);
|
||||
return;
|
||||
}
|
||||
|
||||
for (RawSocketList::iterator i = m_rawSocket.begin (); i != m_rawSocket.end (); ++i)
|
||||
{
|
||||
NS_LOG_LOGIC ("Forwarding to raw socket");
|
||||
Ptr<RawSocketImpl> socket = *i;
|
||||
if(socket->ForwardUp (p, device))
|
||||
return;
|
||||
}
|
||||
|
||||
for (SocketList::iterator i = m_sockets.begin (); i != m_sockets.end (); ++i)
|
||||
{
|
||||
NS_LOG_LOGIC ("Forwarding to ip_raw socket");
|
||||
NS_LOG_LOGIC ("Forwarding to raw socket");
|
||||
Ptr<Ipv4RawSocketImpl> socket = *i;
|
||||
socket->ForwardUp (packet, ipHeader, device);
|
||||
}
|
||||
|
||||
@@ -31,7 +31,6 @@
|
||||
#include "ns3/ipv4-header.h"
|
||||
#include "ns3/ipv4-routing-protocol.h"
|
||||
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
class Packet;
|
||||
@@ -44,7 +43,6 @@ class Ipv4Route;
|
||||
class Node;
|
||||
class Socket;
|
||||
class Ipv4RawSocketImpl;
|
||||
class RawSocketImpl;
|
||||
class Ipv4L4Protocol;
|
||||
class Ipv4L4Protocol;
|
||||
class Icmpv4L4Protocol;
|
||||
@@ -73,10 +71,7 @@ public:
|
||||
Ptr<Ipv4RoutingProtocol> GetRoutingProtocol (void) const;
|
||||
|
||||
Ptr<Socket> CreateRawSocket (void);
|
||||
Ptr<Socket> CreateRawSocket2 (void);
|
||||
void DeleteRawSocket (Ptr<Socket> socket);
|
||||
void DeleteRawSocket2 (Ptr<Socket> socket);
|
||||
|
||||
|
||||
/**
|
||||
* \param protocol a template for the protocol to add to this L4 Demux.
|
||||
@@ -211,7 +206,6 @@ 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;
|
||||
@@ -228,7 +222,6 @@ private:
|
||||
Ptr<Ipv4RoutingProtocol> m_routingProtocol;
|
||||
|
||||
SocketList m_sockets;
|
||||
RawSocketList m_rawSocket;
|
||||
};
|
||||
|
||||
} // Namespace ns3
|
||||
|
||||
@@ -244,35 +244,36 @@ Ipv4RawSocketImpl::ForwardUp (Ptr<const Packet> p, Ipv4Header ipHeader, Ptr<NetD
|
||||
{
|
||||
NS_LOG_FUNCTION (this << *p << ipHeader << device);
|
||||
if (m_shutdownRecv)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
{
|
||||
return false;
|
||||
}
|
||||
NS_LOG_LOGIC ("src = " << m_src << " dst = " << m_dst);
|
||||
if ((m_src == Ipv4Address::GetAny () || ipHeader.GetDestination () == m_src) &&
|
||||
(m_dst == Ipv4Address::GetAny () || ipHeader.GetSource () == m_dst) &&
|
||||
ipHeader.GetProtocol () == m_protocol)
|
||||
{
|
||||
Ptr<Packet> copy = p->Copy ();
|
||||
if (m_protocol == 1)
|
||||
{
|
||||
Icmpv4Header icmpHeader;
|
||||
copy->PeekHeader (icmpHeader);
|
||||
uint8_t type = icmpHeader.GetType ();
|
||||
if (type < 32 && ((1 << type) & m_icmpFilter))
|
||||
{
|
||||
// filter out icmp packet.
|
||||
return false;
|
||||
}
|
||||
Ptr<Packet> copy = p->Copy ();
|
||||
if (m_protocol == 1)
|
||||
{
|
||||
Icmpv4Header icmpHeader;
|
||||
copy->PeekHeader (icmpHeader);
|
||||
uint8_t type = icmpHeader.GetType ();
|
||||
if (type < 32 &&
|
||||
((1 << type) & m_icmpFilter))
|
||||
{
|
||||
// filter out icmp packet.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
copy->AddHeader (ipHeader);
|
||||
struct Data data;
|
||||
data.packet = copy;
|
||||
data.fromIp = ipHeader.GetSource ();
|
||||
data.fromProtocol = ipHeader.GetProtocol ();
|
||||
m_recv.push_back (data);
|
||||
NotifyDataRecv ();
|
||||
return true;
|
||||
}
|
||||
copy->AddHeader (ipHeader);
|
||||
struct Data data;
|
||||
data.packet = copy;
|
||||
data.fromIp = ipHeader.GetSource ();
|
||||
data.fromProtocol = ipHeader.GetProtocol ();
|
||||
m_recv.push_back (data);
|
||||
NotifyDataRecv ();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
#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
|
||||
@@ -1,26 +0,0 @@
|
||||
#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,388 +0,0 @@
|
||||
#include "raw-socket-impl.h"
|
||||
#include "ipv4-l3-protocol.h"
|
||||
#include "icmpv4.h"
|
||||
#include "ns3/inet-socket-address.h"
|
||||
#include "ns3/node.h"
|
||||
#include "ns3/packet.h"
|
||||
#include "ns3/uinteger.h"
|
||||
#include "ns3/log.h"
|
||||
#include "ipv4-interface.h"
|
||||
#include "udp-header.h"
|
||||
|
||||
NS_LOG_COMPONENT_DEFINE ("RawSocketImpl");
|
||||
|
||||
namespace ns3
|
||||
{
|
||||
|
||||
NS_OBJECT_ENSURE_REGISTERED (RawSocketImpl);
|
||||
|
||||
TypeId
|
||||
RawSocketImpl::GetTypeId (void)
|
||||
{
|
||||
static TypeId tid = TypeId ("ns3::RawSocketImpl") .SetParent<Socket> () .AddAttribute ("Protocol", "Protocol number to match.", UintegerValue (0),
|
||||
MakeUintegerAccessor (&RawSocketImpl::m_protocol), MakeUintegerChecker<uint16_t> ()) .AddAttribute ("IcmpFilter",
|
||||
"Any icmp header whose type field matches a bit in this filter is dropped.", UintegerValue (0), MakeUintegerAccessor (
|
||||
&RawSocketImpl::m_icmpFilter), MakeUintegerChecker<uint32_t> ());
|
||||
return tid;
|
||||
}
|
||||
|
||||
RawSocketImpl::RawSocketImpl ()
|
||||
{
|
||||
NS_LOG_FUNCTION (this);
|
||||
m_err = Socket::ERROR_NOTERROR;
|
||||
m_node = 0;
|
||||
m_src = Ipv4Address::GetAny ();
|
||||
m_dst = Ipv4Address::GetAny ();
|
||||
m_protocol = 0;
|
||||
m_shutdownSend = false;
|
||||
m_shutdownRecv = false;
|
||||
}
|
||||
|
||||
void
|
||||
RawSocketImpl::SetNode (Ptr<Node> node)
|
||||
{
|
||||
m_node = node;
|
||||
m_ipv4 = m_node->GetObject<Ipv4L3Protocol> ();
|
||||
NS_ASSERT(m_ipv4 != 0);
|
||||
for(uint32_t i = 0; i < m_ipv4->GetNInterfaces(); ++i)
|
||||
{
|
||||
m_interfaces.push_back (m_ipv4->GetInterface(i));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
RawSocketImpl::DoDispose (void)
|
||||
{
|
||||
NS_LOG_FUNCTION (this);
|
||||
m_node = 0;
|
||||
Socket::DoDispose ();
|
||||
}
|
||||
|
||||
enum Socket::SocketErrno
|
||||
RawSocketImpl::GetErrno (void) const
|
||||
{
|
||||
NS_LOG_FUNCTION (this);
|
||||
return m_err;
|
||||
}
|
||||
Ptr<Node>
|
||||
RawSocketImpl::GetNode (void) const
|
||||
{
|
||||
NS_LOG_FUNCTION (this);
|
||||
return m_node;
|
||||
}
|
||||
int
|
||||
RawSocketImpl::Bind (const Address &address)
|
||||
{
|
||||
NS_LOG_FUNCTION (this << address);
|
||||
if (!InetSocketAddress::IsMatchingType (address))
|
||||
{
|
||||
m_err = Socket::ERROR_INVAL;
|
||||
return -1;
|
||||
}
|
||||
InetSocketAddress ad = InetSocketAddress::ConvertFrom (address);
|
||||
m_src = ad.GetIpv4 ();
|
||||
m_sport = ad.GetPort();
|
||||
return 0;
|
||||
}
|
||||
int
|
||||
RawSocketImpl::Bind (void)
|
||||
{
|
||||
NS_LOG_FUNCTION (this);
|
||||
m_src = Ipv4Address::GetAny ();
|
||||
m_sport = 0;
|
||||
return 0;
|
||||
}
|
||||
int
|
||||
RawSocketImpl::GetSockName (Address &address) const
|
||||
{
|
||||
address = InetSocketAddress (m_src, 0);
|
||||
return 0;
|
||||
}
|
||||
int
|
||||
RawSocketImpl::Close (void)
|
||||
{
|
||||
NS_LOG_FUNCTION (this);
|
||||
Ptr<Ipv4L3Protocol> ipv4 = m_node->GetObject<Ipv4L3Protocol> ();
|
||||
if (ipv4 != 0)
|
||||
{
|
||||
ipv4->DeleteRawSocket (this);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int
|
||||
RawSocketImpl::ShutdownSend (void)
|
||||
{
|
||||
NS_LOG_FUNCTION (this);
|
||||
m_shutdownSend = true;
|
||||
return 0;
|
||||
}
|
||||
int
|
||||
RawSocketImpl::ShutdownRecv (void)
|
||||
{
|
||||
NS_LOG_FUNCTION (this);
|
||||
m_shutdownRecv = true;
|
||||
return 0;
|
||||
}
|
||||
int
|
||||
RawSocketImpl::Connect (const Address &address)
|
||||
{
|
||||
NS_LOG_FUNCTION (this << address);
|
||||
if (!InetSocketAddress::IsMatchingType (address))
|
||||
{
|
||||
m_err = Socket::ERROR_INVAL;
|
||||
return -1;
|
||||
}
|
||||
InetSocketAddress ad = InetSocketAddress::ConvertFrom (address);
|
||||
m_dst = ad.GetIpv4 ();
|
||||
return 0;
|
||||
}
|
||||
int
|
||||
RawSocketImpl::Listen (void)
|
||||
{
|
||||
NS_LOG_FUNCTION (this);
|
||||
m_err = Socket::ERROR_OPNOTSUPP;
|
||||
return -1;
|
||||
}
|
||||
uint32_t
|
||||
RawSocketImpl::GetTxAvailable (void) const
|
||||
{
|
||||
NS_LOG_FUNCTION (this);
|
||||
return 0xffffffff;
|
||||
}
|
||||
int
|
||||
RawSocketImpl::Send (Ptr<Packet> p, uint32_t flags)
|
||||
{
|
||||
NS_LOG_FUNCTION (this << " packet " << p << flags);
|
||||
InetSocketAddress to = InetSocketAddress (m_dst, m_protocol);
|
||||
return SendTo (p, flags, to);
|
||||
}
|
||||
int
|
||||
RawSocketImpl::SendTo (Ptr<Packet> packet, uint32_t flags, const Address &toAddress)
|
||||
{
|
||||
|
||||
if (!InetSocketAddress::IsMatchingType (toAddress))
|
||||
{
|
||||
m_err = Socket::ERROR_INVAL;
|
||||
return -1;
|
||||
}
|
||||
if (m_shutdownSend)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
if (m_ipv4->GetRoutingProtocol ())
|
||||
{
|
||||
Ipv4Header header;
|
||||
Ptr<Packet> copy = packet->Copy();
|
||||
copy->RemoveHeader (header);
|
||||
NS_LOG_LOGIC ("RawSocketImpl::SendTo packet uid " << packet->GetUid() << " address " << header.GetDestination());
|
||||
SocketErrno errno_ = ERROR_NOTERROR;//do not use errno as it is the standard C last error number
|
||||
Ptr<Ipv4Route> route;
|
||||
uint32_t oif = 0; //specify non-zero if bound to a source address
|
||||
route = m_ipv4->GetRoutingProtocol ()->RouteOutput (copy, header, oif, errno_);
|
||||
if (route != 0)
|
||||
{
|
||||
NS_LOG_LOGIC ("Route exists");
|
||||
SendByInterface(packet, route);
|
||||
}
|
||||
else
|
||||
{
|
||||
NS_LOG_LOGIC ("dropped because no outgoing route.");
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
RawSocketImpl::SendByInterface (Ptr<Packet> p, Ptr<const Ipv4Route> route)
|
||||
{
|
||||
NS_ASSERT(m_node != 0);
|
||||
Ipv4Header ipv4Header;
|
||||
Ptr<Packet> packet = p->Copy();
|
||||
packet->RemoveHeader(ipv4Header);
|
||||
Ipv4Address source = ipv4Header.GetSource ();
|
||||
Ipv4Address destination = ipv4Header.GetDestination ();
|
||||
NS_LOG_LOGIC ("RawSocketImpl::SendByInterface to " << destination << " from " << source);
|
||||
|
||||
// Handle a few cases:
|
||||
// 1) packet is destined to limited broadcast address
|
||||
// 2) packet is destined to a subnet-directed broadcast address
|
||||
// 3) packet is not broadcast, and is passed in with a route entry
|
||||
const Ipv4Address loopback ("127.0.0.1");
|
||||
// 1) packet is destined to limited broadcast address
|
||||
if (destination.IsBroadcast ())
|
||||
{
|
||||
NS_LOG_LOGIC ("RawSocketImpl::Send case 1: limited broadcast");
|
||||
for (std::list< Ptr<Ipv4Interface> >::iterator ifaceIter = m_interfaces.begin (); ifaceIter != m_interfaces.end (); ifaceIter++)
|
||||
{
|
||||
Ptr<Ipv4Interface> outInterface = *ifaceIter;
|
||||
Ptr<Packet> packetCopy = p->Copy ();
|
||||
|
||||
NS_ASSERT (packet->GetSize () <= outInterface->GetDevice()->GetMtu ());
|
||||
outInterface->Send (packetCopy, destination);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// 2) check: packet is destined to a subnet-directed broadcast address
|
||||
bool result = false;
|
||||
uint32_t ifaceIndex = 0;
|
||||
NS_LOG_LOGIC("number of interfaces " << m_interfaces.size ());
|
||||
for (std::list< Ptr<Ipv4Interface> >::iterator ifaceIter = m_interfaces.begin (); ifaceIter != m_interfaces.end (); ifaceIter++, ifaceIndex++)
|
||||
{
|
||||
Ptr<Ipv4Interface> outInterface = *ifaceIter;
|
||||
for (uint32_t j = 0; j < m_ipv4->GetNAddresses (ifaceIndex); j++)
|
||||
{
|
||||
Ipv4InterfaceAddress ifAddr = m_ipv4->GetAddress (ifaceIndex, j);
|
||||
NS_LOG_LOGIC ("Testing address " << ifAddr.GetLocal () << " with mask " << ifAddr.GetMask ());
|
||||
if (destination.IsSubnetDirectedBroadcast (ifAddr.GetMask ()) &&
|
||||
(destination.CombineMask (ifAddr.GetMask ()) == ifAddr.GetLocal ().CombineMask (ifAddr.GetMask ())) )
|
||||
//if (ifAddr.GetLocal() == source)
|
||||
{
|
||||
NS_LOG_LOGIC ("Send case 2: subnet directed bcast to " << ifAddr.GetLocal ());
|
||||
Ptr<Packet> packetCopy = p->Copy ();
|
||||
outInterface->Send (packetCopy, destination);
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(result) return;
|
||||
|
||||
// 3) packet is not broadcast, and is passed in with a route entry
|
||||
// with a valid Ipv4Address as the gateway
|
||||
if (route && route->GetGateway () != Ipv4Address ())
|
||||
{
|
||||
NS_LOG_LOGIC ("RawSocketImpl::Send case 3: passed in with route");
|
||||
Ptr<NetDevice> outDev = route->GetOutputDevice ();
|
||||
int32_t interface = m_ipv4->GetInterfaceForDevice (outDev);
|
||||
NS_ASSERT (interface >= 0);
|
||||
Ptr<Ipv4Interface> outInterface = m_ipv4->GetInterface (interface);
|
||||
NS_LOG_LOGIC ("Send via NetDevice ifIndex " << outDev->GetIfIndex () << " ipv4InterfaceIndex " << interface);
|
||||
|
||||
NS_ASSERT (p->GetSize () <= outInterface->GetDevice ()->GetMtu ());
|
||||
if (!route->GetGateway ().IsEqual (Ipv4Address ("0.0.0.0")))
|
||||
{
|
||||
if (outInterface->IsUp ())
|
||||
{
|
||||
NS_LOG_LOGIC ("Send to gateway " << route->GetGateway ());
|
||||
Ptr<Packet> packetCopy = p->Copy ();
|
||||
outInterface->Send (packetCopy, route->GetGateway ());
|
||||
}
|
||||
else
|
||||
{
|
||||
NS_LOG_LOGIC ("Dropping-- outgoing interface is down: " << route->GetGateway ());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (outInterface->IsUp ())
|
||||
{
|
||||
Ptr<Packet> packetCopy = p->Copy ();
|
||||
NS_LOG_LOGIC ("Send to destination " << destination);
|
||||
outInterface->Send (packetCopy, destination);
|
||||
}
|
||||
else
|
||||
{
|
||||
NS_LOG_LOGIC ("Dropping-- outgoing interface is down: " << destination);
|
||||
}
|
||||
} return;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t
|
||||
RawSocketImpl::GetRxAvailable (void) const
|
||||
{
|
||||
NS_LOG_FUNCTION (this);
|
||||
uint32_t rx = 0;
|
||||
for (std::list<Data>::const_iterator i = m_recv.begin (); i != m_recv.end (); ++i)
|
||||
{
|
||||
rx += (i->packet)->GetSize ();
|
||||
}
|
||||
return rx;
|
||||
}
|
||||
Ptr<Packet>
|
||||
RawSocketImpl::Recv (uint32_t maxSize, uint32_t flags)
|
||||
{
|
||||
NS_LOG_LOGIC ("RawSocketImpl::Recv" << maxSize << flags);
|
||||
Address tmp;
|
||||
return RecvFrom (maxSize, flags, tmp);
|
||||
}
|
||||
Ptr<Packet>
|
||||
RawSocketImpl::RecvFrom (uint32_t maxSize, uint32_t flags, Address &fromAddress)
|
||||
{
|
||||
NS_LOG_LOGIC ("RawSocketImpl::RecvFrom" << " maxSize " << maxSize << " flags " << flags << " address " <<fromAddress);
|
||||
if (m_recv.empty ())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
struct Data data = m_recv.front ();
|
||||
m_recv.pop_front ();
|
||||
if (data.packet->GetSize () > maxSize)
|
||||
{
|
||||
Ptr<Packet> first = data.packet->CreateFragment (0, maxSize);
|
||||
data.packet->RemoveAtStart (maxSize);
|
||||
m_recv.push_front (data);
|
||||
return first;
|
||||
}
|
||||
|
||||
InetSocketAddress inet = InetSocketAddress (data.fromIp, data.fromProtocol);
|
||||
fromAddress = inet;
|
||||
return data.packet;
|
||||
}
|
||||
|
||||
void
|
||||
RawSocketImpl::SetProtocol (uint16_t protocol)
|
||||
{
|
||||
NS_LOG_FUNCTION (this << protocol);
|
||||
m_protocol = protocol;
|
||||
}
|
||||
|
||||
bool
|
||||
RawSocketImpl::ForwardUp (Ptr<const Packet> p, Ptr<NetDevice> device)
|
||||
{
|
||||
if (m_shutdownRecv)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
Ptr<Packet> copy = p->Copy ();
|
||||
Ipv4Header ipHeader;
|
||||
copy->RemoveHeader(ipHeader);
|
||||
for (std::list< Ptr<Ipv4Interface> >::const_iterator ifaceIter = m_interfaces.begin (); ifaceIter != m_interfaces.end (); ifaceIter++)
|
||||
{
|
||||
for (uint32_t i = 0; i < (*ifaceIter)->GetNAddresses(); ++i)
|
||||
{
|
||||
if ((*ifaceIter)->GetAddress(i).GetLocal() == ipHeader.GetSource())
|
||||
return true;
|
||||
}
|
||||
}
|
||||
UdpHeader udpHeader;
|
||||
copy->RemoveHeader(udpHeader);
|
||||
NS_LOG_LOGIC ("src = " << m_src << " dst = " << m_dst);
|
||||
if ( m_sport == udpHeader.GetDestinationPort () && ipHeader.GetProtocol () == m_protocol)
|
||||
{
|
||||
|
||||
if (m_protocol == 1)
|
||||
{
|
||||
Icmpv4Header icmpHeader;
|
||||
copy->PeekHeader (icmpHeader);
|
||||
uint8_t type = icmpHeader.GetType ();
|
||||
if (type < 32 && ((1 << type) & m_icmpFilter))
|
||||
{
|
||||
// filter out icmp packet.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Ptr<Packet> packet = p->Copy();
|
||||
struct Data data;
|
||||
data.packet = packet;
|
||||
data.fromIp = ipHeader.GetSource ();
|
||||
data.fromProtocol = ipHeader.GetProtocol ();
|
||||
m_recv.push_back (data);
|
||||
NotifyDataRecv ();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace ns3
|
||||
@@ -1,71 +0,0 @@
|
||||
#ifndef RAW_SOCKET_IMPL_H
|
||||
#define RAW_SOCKET_IMPL_H
|
||||
|
||||
#include "ns3/socket.h"
|
||||
#include "ns3/ipv4-header.h"
|
||||
#include "ns3/ipv4-route.h"
|
||||
#include "ipv4-l3-protocol.h"
|
||||
#include <list>
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
class NetDevice;
|
||||
class Node;
|
||||
|
||||
class RawSocketImpl : public Socket
|
||||
{
|
||||
public:
|
||||
static TypeId GetTypeId (void);
|
||||
|
||||
RawSocketImpl ();
|
||||
|
||||
void SetNode (Ptr<Node> node);
|
||||
|
||||
virtual enum Socket::SocketErrno GetErrno (void) const;
|
||||
virtual Ptr<Node> GetNode (void) const;
|
||||
virtual int Bind (const Address &address);
|
||||
virtual int Bind ();
|
||||
virtual int GetSockName (Address &address) const;
|
||||
virtual int Close (void);
|
||||
virtual int ShutdownSend (void);
|
||||
virtual int ShutdownRecv (void);
|
||||
virtual int Connect (const Address &address);
|
||||
virtual int Listen (void);
|
||||
virtual uint32_t GetTxAvailable (void) const;
|
||||
virtual int Send (Ptr<Packet> p, uint32_t flags);
|
||||
virtual int SendTo (Ptr<Packet> p, uint32_t flags,const Address &toAddress);
|
||||
void SendByInterface (Ptr<Packet> packet, Ptr<const Ipv4Route> route);
|
||||
virtual uint32_t GetRxAvailable (void) const;
|
||||
virtual Ptr<Packet> Recv (uint32_t maxSize, uint32_t flags);
|
||||
virtual Ptr<Packet> RecvFrom (uint32_t maxSize, uint32_t flags,
|
||||
Address &fromAddress);
|
||||
|
||||
void SetProtocol (uint16_t protocol);
|
||||
bool ForwardUp (Ptr<const Packet> p, Ptr<NetDevice> device);
|
||||
private:
|
||||
virtual void DoDispose (void);
|
||||
|
||||
|
||||
struct Data {
|
||||
Ptr<Packet> packet;
|
||||
Ipv4Address fromIp;
|
||||
uint16_t fromProtocol;
|
||||
};
|
||||
|
||||
enum Socket::SocketErrno m_err;
|
||||
Ptr<Node> m_node;
|
||||
Ipv4Address m_src;
|
||||
uint16_t m_sport;
|
||||
Ipv4Address m_dst;
|
||||
uint16_t m_protocol;
|
||||
std::list<struct Data> m_recv;
|
||||
bool m_shutdownSend;
|
||||
bool m_shutdownRecv;
|
||||
uint32_t m_icmpFilter;
|
||||
std::list< Ptr<Ipv4Interface> > m_interfaces;
|
||||
Ptr<Ipv4L3Protocol> m_ipv4;
|
||||
};
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
#endif /* RAW_SOCKET_IMPL_H */
|
||||
@@ -94,8 +94,6 @@ 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',
|
||||
'icmpv4.cc',
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
#include "ns3/nstime.h"
|
||||
#include "ns3/net-device.h"
|
||||
|
||||
#include "ns3/raw-socket-factory.h"
|
||||
#include "ns3/udp-socket-factory.h"
|
||||
#include "src/internet-stack/udp-l4-protocol.h"
|
||||
#include <algorithm>
|
||||
|
||||
@@ -260,8 +260,8 @@ RoutingProtocol::RouteInput (Ptr<const Packet> p, const Ipv4Header &header, Ptr<
|
||||
Ptr<Packet> packet = p->Copy();
|
||||
lcb (p, header, iif);
|
||||
Ptr<Ipv4Route> route;
|
||||
NS_LOG_LOGIC ("Forward broadcast");
|
||||
ucb (route, packet, header);
|
||||
// NS_LOG_LOGIC ("Forward broadcast");
|
||||
// ucb (route, packet, header);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -370,8 +370,7 @@ RoutingProtocol::NotifyInterfaceUp (uint32_t i )
|
||||
if (iface.GetLocal () == Ipv4Address ("127.0.0.1"))
|
||||
return;
|
||||
// Create a socket to listen only on this interface
|
||||
l3 = m_ipv4->GetObject<Ipv4L3Protocol> ();
|
||||
Ptr<Socket> socket = l3->CreateRawSocket2();
|
||||
Ptr<Socket> socket = Socket::CreateSocket (GetObject<Node> (), UdpSocketFactory::GetTypeId());
|
||||
NS_ASSERT (socket != 0);
|
||||
socket->SetRecvCallback (MakeCallback (&RoutingProtocol::RecvAodv, this));
|
||||
socket->Bind(InetSocketAddress (iface.GetLocal(), AODV_PORT));
|
||||
@@ -420,8 +419,7 @@ RoutingProtocol::NotifyAddAddress (uint32_t i, Ipv4InterfaceAddress address )
|
||||
if (iface.GetLocal () == Ipv4Address ("127.0.0.1"))
|
||||
return;
|
||||
// Create a socket to listen only on this interface
|
||||
Ptr<Ipv4L3Protocol> l3 = m_ipv4->GetObject<Ipv4L3Protocol> ();
|
||||
Ptr<Socket> socket = l3->CreateRawSocket2 ();
|
||||
Ptr<Socket> socket = Socket::CreateSocket (GetObject<Node> (), UdpSocketFactory::GetTypeId());
|
||||
NS_ASSERT (socket != 0);
|
||||
socket->SetRecvCallback (MakeCallback (&RoutingProtocol::RecvAodv, this));
|
||||
socket->Bind (InetSocketAddress (iface.GetLocal (), AODV_PORT));
|
||||
@@ -456,8 +454,7 @@ RoutingProtocol::NotifyRemoveAddress (uint32_t i, Ipv4InterfaceAddress address )
|
||||
{
|
||||
Ipv4InterfaceAddress iface = interface->GetAddress (0);
|
||||
// Create a socket to listen only on this interface
|
||||
Ptr<Ipv4L3Protocol> l3 = m_ipv4->GetObject<Ipv4L3Protocol> ();
|
||||
Ptr<Socket> socket = l3->CreateRawSocket2 ();
|
||||
Ptr<Socket> socket = Socket::CreateSocket (GetObject<Node> (), UdpSocketFactory::GetTypeId());
|
||||
NS_ASSERT (socket != 0);
|
||||
socket->SetRecvCallback (MakeCallback (&RoutingProtocol::RecvAodv, this));
|
||||
socket->Bind (InetSocketAddress (iface.GetLocal (), AODV_PORT));
|
||||
@@ -549,7 +546,7 @@ RoutingProtocol::SendRequest (Ipv4Address dst)
|
||||
packet->AddHeader (rreqHeader);
|
||||
TypeHeader tHeader (AODVTYPE_RREQ);
|
||||
packet->AddHeader (tHeader);
|
||||
SendPacketViaRawSocket (/*packet*/packet, /*pair<Ptr<Socket> , Ipv4InterfaceAddress>*/ *j, /*dst*/iface.GetBroadcast (), /*TTL*/ NetDiameter, /*id*/0);
|
||||
socket->Send(packet);
|
||||
}
|
||||
ScheduleRreqRetry (dst);
|
||||
if (EnableHello)
|
||||
@@ -583,17 +580,9 @@ RoutingProtocol::RecvAodv (Ptr<Socket> socket )
|
||||
NS_LOG_FUNCTION (this);
|
||||
Address sourceAddress;
|
||||
Ptr<Packet> packet = socket->RecvFrom (sourceAddress);
|
||||
|
||||
Ipv4Header ipv4Header;
|
||||
packet->RemoveHeader (ipv4Header);
|
||||
|
||||
UdpHeader udpHeader;
|
||||
packet->RemoveHeader (udpHeader);
|
||||
NS_ASSERT (udpHeader.GetDestinationPort () == AODV_PORT);
|
||||
NS_ASSERT (udpHeader.GetSourcePort () == AODV_PORT);
|
||||
|
||||
InetSocketAddress inetSourceAddr = InetSocketAddress::ConvertFrom (sourceAddress);
|
||||
Ipv4Address sender = inetSourceAddr.GetIpv4 ();
|
||||
Ipv4Address receiver = m_socketAddresses[socket].GetLocal ();
|
||||
Ipv4Address sender = ipv4Header.GetSource ();
|
||||
NS_LOG_DEBUG ("AODV node " << this << " received a AODV packet from " << sender << " to " << receiver);
|
||||
|
||||
UpdateRouteToNeighbor (sender, receiver);
|
||||
@@ -608,12 +597,12 @@ RoutingProtocol::RecvAodv (Ptr<Socket> socket )
|
||||
{
|
||||
case AODVTYPE_RREQ:
|
||||
{
|
||||
RecvRequest (packet, receiver, sender, ipv4Header);
|
||||
RecvRequest (packet, receiver, sender);
|
||||
break;
|
||||
}
|
||||
case AODVTYPE_RREP:
|
||||
{
|
||||
RecvReply (packet, receiver, sender, ipv4Header);
|
||||
RecvReply (packet, receiver, sender);
|
||||
break;
|
||||
}
|
||||
case AODVTYPE_RERR:
|
||||
@@ -668,7 +657,7 @@ RoutingProtocol::UpdateRouteToNeighbor (Ipv4Address sender, Ipv4Address receiver
|
||||
}
|
||||
|
||||
void
|
||||
RoutingProtocol::RecvRequest (Ptr<Packet> p, Ipv4Address receiver, Ipv4Address src, Ipv4Header ipv4Header )
|
||||
RoutingProtocol::RecvRequest (Ptr<Packet> p, Ipv4Address receiver, Ipv4Address src)
|
||||
{
|
||||
NS_LOG_FUNCTION (this);
|
||||
RreqHeader rreqHeader;
|
||||
@@ -753,7 +742,7 @@ RoutingProtocol::RecvRequest (Ptr<Packet> p, Ipv4Address receiver, Ipv4Address s
|
||||
*/
|
||||
RoutingTableEntry toDst;
|
||||
Ipv4Address dst = rreqHeader.GetDst ();
|
||||
NS_LOG_LOGIC (receiver << " recieve RREQ to destination " << dst << " with ttl " << (uint16_t) ipv4Header.GetTtl ());
|
||||
NS_LOG_LOGIC (receiver << " recieve RREQ to destination " << dst);
|
||||
if (m_routingTable.LookupRoute (dst, toDst))
|
||||
{
|
||||
/*
|
||||
@@ -775,23 +764,15 @@ RoutingProtocol::RecvRequest (Ptr<Packet> p, Ipv4Address receiver, Ipv4Address s
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* If a node does not generate a RREP the incoming IP header has TTL larger than 1, the node updates
|
||||
* and broadcasts the RREQ on each of its configured interfaces.
|
||||
*/
|
||||
if (ipv4Header.GetTtl () < 2)
|
||||
return;
|
||||
|
||||
for (std::map<Ptr<Socket> , Ipv4InterfaceAddress>::const_iterator j = m_socketAddresses.begin (); j != m_socketAddresses.end (); ++j)
|
||||
{
|
||||
Ptr<Socket> socket = j->first;
|
||||
Ipv4InterfaceAddress iface = j->second;
|
||||
Ptr<Packet> packet = p->Copy ();
|
||||
Ptr<Packet> packet = Create<Packet> ();
|
||||
packet->AddHeader (rreqHeader);
|
||||
TypeHeader tHeader (AODVTYPE_RREQ);
|
||||
packet->AddHeader (tHeader);
|
||||
SendPacketViaRawSocket (/*packet*/packet, /*pair<Ptr<Socket> , Ipv4InterfaceAddress>*/ *j, /*dst*/iface.GetBroadcast (),
|
||||
/*TTL*/ ipv4Header.GetTtl () - 1, /*id*/ipv4Header.GetIdentification ());
|
||||
socket->Send (packet);
|
||||
}
|
||||
|
||||
if (EnableHello)
|
||||
@@ -819,8 +800,7 @@ RoutingProtocol::SendReply (RreqHeader const & rreqHeader, RoutingTableEntry con
|
||||
packet->AddHeader (tHeader);
|
||||
Ptr<Socket> socket = FindSocketWithInterfaceAddress (toOrigin.GetInterface ());
|
||||
NS_ASSERT (socket);
|
||||
SendPacketViaRawSocket (/*packet*/packet, /*pair<Ptr<Socket> , Ipv4InterfaceAddress>*/ std::make_pair(socket, toOrigin.GetInterface ()),
|
||||
/*dst*/toOrigin.GetNextHop (), /*TTL*/ toOrigin.GetHop (), /*id*/0);
|
||||
socket->SendTo (packet, 0, InetSocketAddress (toOrigin.GetNextHop (), AODV_PORT));
|
||||
}
|
||||
|
||||
void
|
||||
@@ -853,8 +833,7 @@ RoutingProtocol::SendReplyByIntermediateNode (RoutingTableEntry & toDst, Routing
|
||||
Ptr<Socket> socket = FindSocketWithInterfaceAddress (toOrigin.GetInterface ());
|
||||
m_routingTable.Print(std::cout);
|
||||
NS_ASSERT (socket);
|
||||
SendPacketViaRawSocket (/*packet*/packet, /*pair<Ptr<Socket> , Ipv4InterfaceAddress>*/ std::make_pair(socket, toOrigin.GetInterface ()),
|
||||
/*dst*/toOrigin.GetNextHop (), /*TTL*/ toOrigin.GetHop (), /*id*/0);
|
||||
socket->SendTo (packet, 0, InetSocketAddress (toOrigin.GetNextHop (), AODV_PORT));
|
||||
|
||||
// Generating gratuitous RREPs
|
||||
if (gratRep)
|
||||
@@ -868,8 +847,7 @@ RoutingProtocol::SendReplyByIntermediateNode (RoutingTableEntry & toDst, Routing
|
||||
Ptr<Socket> socket = FindSocketWithInterfaceAddress (toDst.GetInterface ());
|
||||
NS_ASSERT (socket);
|
||||
NS_LOG_LOGIC ("Send gratuitous RREP " << packet->GetUid());
|
||||
SendPacketViaRawSocket (/*packet*/packetToDst, /*pair<Ptr<Socket> , Ipv4InterfaceAddress>*/ std::make_pair(socket, toDst.GetInterface ()),
|
||||
/*dst*/toDst.GetNextHop (), /*TTL*/ toDst.GetHop (), /*id*/0);
|
||||
socket->SendTo (packetToDst, 0, InetSocketAddress (toDst.GetNextHop (), AODV_PORT));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -886,12 +864,11 @@ RoutingProtocol::SendReplyAck (Ipv4Address neighbor )
|
||||
m_routingTable.LookupRoute (neighbor, toNeighbor);
|
||||
Ptr<Socket> socket = FindSocketWithInterfaceAddress (toNeighbor.GetInterface ());
|
||||
NS_ASSERT (socket);
|
||||
SendPacketViaRawSocket (/*packet*/packet, /*pair<Ptr<Socket> , Ipv4InterfaceAddress>*/ std::make_pair(socket, toNeighbor.GetInterface ()),
|
||||
/*dst*/neighbor, /*TTL*/ 1, /*id*/0);
|
||||
socket->SendTo (packet, 0, InetSocketAddress (neighbor, AODV_PORT));
|
||||
}
|
||||
|
||||
void
|
||||
RoutingProtocol::RecvReply (Ptr<Packet> p, Ipv4Address receiver, Ipv4Address sender, Ipv4Header ipv4Header )
|
||||
RoutingProtocol::RecvReply (Ptr<Packet> p, Ipv4Address receiver, Ipv4Address sender)
|
||||
{
|
||||
NS_LOG_FUNCTION(this << " src " << sender);
|
||||
RrepHeader rrepHeader;
|
||||
@@ -1012,12 +989,11 @@ RoutingProtocol::RecvReply (Ptr<Packet> p, Ipv4Address receiver, Ipv4Address sen
|
||||
packet->AddHeader (tHeader);
|
||||
Ptr<Socket> socket = FindSocketWithInterfaceAddress (toOrigin.GetInterface ());
|
||||
NS_ASSERT (socket);
|
||||
SendPacketViaRawSocket (/*packet*/packet, /*pair<Ptr<Socket> , Ipv4InterfaceAddress>*/ std::make_pair(socket, toOrigin.GetInterface ()),
|
||||
/*dst*/toOrigin.GetNextHop (), /*TTL*/ ipv4Header.GetTtl () - 1, /*id*/0);
|
||||
socket->SendTo (packet, 0, InetSocketAddress (toOrigin.GetNextHop (), AODV_PORT));
|
||||
}
|
||||
|
||||
void
|
||||
RoutingProtocol::RecvReplyAck (Ipv4Address neighbor )
|
||||
RoutingProtocol::RecvReplyAck (Ipv4Address neighbor)
|
||||
{
|
||||
NS_LOG_LOGIC(this);
|
||||
// TODO
|
||||
@@ -1063,11 +1039,6 @@ RoutingProtocol::RecvError (Ptr<Packet> p, Ipv4Address src )
|
||||
NS_LOG_FUNCTION (this << " from " << src);
|
||||
RerrHeader rerrHeader;
|
||||
p->RemoveHeader (rerrHeader);
|
||||
bool noDelete = rerrHeader.GetNoDelete ();
|
||||
if (noDelete)
|
||||
{
|
||||
NS_LOG_LOGIC ("Receive RERR with no delete flag.");
|
||||
}
|
||||
std::map<Ipv4Address, uint32_t> dstWithNextHopSrc;
|
||||
std::map<Ipv4Address, uint32_t> unreachable;
|
||||
m_routingTable.GetListOfDestinationWithNextHop (src, dstWithNextHopSrc);
|
||||
@@ -1114,8 +1085,7 @@ RoutingProtocol::RecvError (Ptr<Packet> p, Ipv4Address src )
|
||||
rerrHeader.Print(std::cout);
|
||||
SendRerrMessage (packet, precursors);
|
||||
}
|
||||
if (!noDelete)
|
||||
m_routingTable.InvalidateRoutesWithDst (unreachable);
|
||||
m_routingTable.InvalidateRoutesWithDst (unreachable);
|
||||
NS_LOG_LOGIC ("After receive RERR");
|
||||
m_routingTable.Print (std::cout);
|
||||
}
|
||||
@@ -1169,7 +1139,6 @@ RoutingProtocol::HelloTimerExpire ()
|
||||
// TODO select random time for the next hello
|
||||
htimer.Cancel ();
|
||||
Time t = Scalar(0.01)*MilliSeconds(UniformVariable().GetValue (0.0, 100.0));
|
||||
NS_LOG_LOGIC ("delay = " << t.GetMicroSeconds ());
|
||||
htimer.Schedule (HelloInterval - t);
|
||||
}
|
||||
|
||||
@@ -1195,37 +1164,16 @@ RoutingProtocol::SendHello ()
|
||||
Ptr<Socket> socket = j->first;
|
||||
Ipv4InterfaceAddress iface = j->second;
|
||||
RrepHeader helloHeader (/*prefix size=*/0, /*hops=*/0, /*dst=*/iface.GetLocal (), /*dst seqno=*/m_seqNo,
|
||||
/*origin=*/iface.GetLocal (),/*lifetime=*/Scalar (AllowedHelloLoss) * HelloInterval);
|
||||
/*origin=*/iface.GetLocal (),/*lifetime=*/Scalar (AllowedHelloLoss) * HelloInterval);
|
||||
Ptr<Packet> packet = Create<Packet> ();
|
||||
packet->AddHeader (helloHeader);
|
||||
TypeHeader tHeader (AODVTYPE_RREP);
|
||||
packet->AddHeader (tHeader);
|
||||
SendPacketViaRawSocket (/*packet*/packet, /*pair<Ptr<Socket> , Ipv4InterfaceAddress>*/ *j,
|
||||
/*dst*/iface.GetBroadcast (), /*TTL*/ 1, /*id*/0);
|
||||
socket->Send (packet);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
RoutingProtocol::SendPacketViaRawSocket (Ptr<Packet> packet, std::pair<Ptr<Socket> , Ipv4InterfaceAddress> socketAddress, Ipv4Address dst,
|
||||
uint16_t ttl, uint16_t id )
|
||||
{
|
||||
UdpHeader udpHeader;
|
||||
udpHeader.SetDestinationPort (AODV_PORT);
|
||||
udpHeader.SetSourcePort (AODV_PORT);
|
||||
packet->AddHeader (udpHeader);
|
||||
|
||||
Ipv4Header ipv4Header;
|
||||
ipv4Header.SetSource (socketAddress.second.GetLocal ());
|
||||
ipv4Header.SetDestination (dst);
|
||||
ipv4Header.SetIdentification (id);
|
||||
ipv4Header.EnableChecksum ();
|
||||
ipv4Header.SetProtocol (UdpL4Protocol::PROT_NUMBER);
|
||||
ipv4Header.SetTtl (ttl);
|
||||
ipv4Header.SetPayloadSize (packet->GetSize ());
|
||||
packet->AddHeader (ipv4Header);
|
||||
NS_LOG_LOGIC ("Send packet " << packet->GetUid() << " from " << socketAddress.second.GetLocal () << " to " << dst);
|
||||
socketAddress.first->SendTo (packet, 0, InetSocketAddress (dst, AODV_PORT));
|
||||
}
|
||||
|
||||
void
|
||||
RoutingProtocol::SendPacketFromQueue (Ipv4Address dst, Ptr<Ipv4Route> route )
|
||||
@@ -1321,8 +1269,7 @@ RoutingProtocol::SendRerrWhenNoRouteToForward (Ipv4Address dst, uint32_t dstSeqN
|
||||
Ptr<Socket> socket = FindSocketWithInterfaceAddress (toOrigin.GetInterface ());
|
||||
NS_ASSERT (socket);
|
||||
NS_LOG_LOGIC ("unicast RERR to the source of the data transmission");
|
||||
SendPacketViaRawSocket (/*packet*/packet, /*pair<Ptr<Socket> , Ipv4InterfaceAddress>*/ std::make_pair(socket, toOrigin.GetInterface ()),
|
||||
/*dst*/toOrigin.GetNextHop (), /*TTL*/ 1, /*id*/0);
|
||||
socket->SendTo(packet, 0, InetSocketAddress (toOrigin.GetNextHop (), AODV_PORT));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1334,8 +1281,7 @@ RoutingProtocol::SendRerrWhenNoRouteToForward (Ipv4Address dst, uint32_t dstSeqN
|
||||
Ipv4InterfaceAddress iface = i->second;
|
||||
NS_ASSERT (socket);
|
||||
NS_LOG_LOGIC ("broadcast RERR meassage from interface " << iface.GetLocal());
|
||||
SendPacketViaRawSocket (/*packet*/packet, /*pair<Ptr<Socket> , Ipv4InterfaceAddress>*/ std::make_pair(socket, iface),
|
||||
/*dst*/iface.GetBroadcast (), /*TTL*/1, /*id*/0);
|
||||
socket->Send (packet);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1358,8 +1304,7 @@ RoutingProtocol::SendRerrMessage (Ptr<Packet> packet, std::vector<Ipv4Address> p
|
||||
Ptr<Socket> socket = FindSocketWithInterfaceAddress (toPrecursor.GetInterface ());
|
||||
NS_ASSERT (socket);
|
||||
NS_LOG_LOGIC ("one precursor => unicast RERR to " << toPrecursor.GetDestination() << " from " << toPrecursor.GetInterface ().GetLocal ());
|
||||
SendPacketViaRawSocket (/*packet*/packet, /*pair<Ptr<Socket> , Ipv4InterfaceAddress>*/ std::make_pair(socket, toPrecursor.GetInterface ()),
|
||||
/*dst*/precursors.front (), /*TTL*/ 1, /*id*/0);
|
||||
socket->SendTo(packet, 0, InetSocketAddress (precursors.front (), AODV_PORT));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1386,8 +1331,7 @@ RoutingProtocol::SendRerrMessage (Ptr<Packet> packet, std::vector<Ipv4Address> p
|
||||
Ptr<Socket> socket = FindSocketWithInterfaceAddress (*i);
|
||||
NS_ASSERT (socket);
|
||||
NS_LOG_LOGIC ("broadcast RERR meassage from interface " << i->GetLocal());
|
||||
SendPacketViaRawSocket (/*packet*/packet, /*pair<Ptr<Socket> , Ipv4InterfaceAddress>*/ std::make_pair(socket, *i),
|
||||
/*dst*/m_socketAddresses[socket].GetBroadcast (), /*TTL*/ 1, /*id*/0);
|
||||
socket->Send (packet);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -178,9 +178,9 @@ private:
|
||||
/// Receive and process control packet
|
||||
void RecvAodv (Ptr<Socket> socket);
|
||||
/// Receive RREQ
|
||||
void RecvRequest (Ptr<Packet> p, Ipv4Address receiver, Ipv4Address src, Ipv4Header ipv4Header);
|
||||
void RecvRequest (Ptr<Packet> p, Ipv4Address receiver, Ipv4Address src);
|
||||
/// Receive RREP
|
||||
void RecvReply (Ptr<Packet> p, Ipv4Address my ,Ipv4Address src, Ipv4Header ipv4Header);
|
||||
void RecvReply (Ptr<Packet> p, Ipv4Address my ,Ipv4Address src);
|
||||
/// Receive RREP_ACK
|
||||
void RecvReplyAck(Ipv4Address neighbor);
|
||||
/// Receive RERR from node with address src
|
||||
@@ -218,10 +218,6 @@ private:
|
||||
* \param origin - originating node IP address
|
||||
*/
|
||||
void SendRerrWhenNoRouteToForward (Ipv4Address dst, uint32_t dstSeqNo, Ipv4Address origin);
|
||||
/**
|
||||
* Add UDP, IP headers to packet and send it via raw socket
|
||||
*/
|
||||
void SendPacketViaRawSocket (Ptr<Packet> packet, std::pair<Ptr<Socket> , Ipv4InterfaceAddress> socketAddress, Ipv4Address dst, uint16_t ttl, uint16_t id);
|
||||
//\}
|
||||
|
||||
/// Notify that packet is dropped for some reason
|
||||
|
||||
Reference in New Issue
Block a user