RecvReply changed to respond properly to receive RREP with origin address != receiver address, but == local address of another interface
This commit is contained in:
@@ -178,7 +178,7 @@ Ipv4Interface::SetForwarding (bool val)
|
||||
void
|
||||
Ipv4Interface::Send (Ptr<Packet> p, Ipv4Address dest)
|
||||
{
|
||||
NS_LOG_FUNCTION (dest << *p);
|
||||
NS_LOG_UNCOND (dest << *p);
|
||||
if (!IsUp())
|
||||
{
|
||||
return;
|
||||
@@ -188,6 +188,7 @@ Ipv4Interface::Send (Ptr<Packet> p, Ipv4Address dest)
|
||||
{
|
||||
// XXX additional checks needed here (such as whether multicast
|
||||
// goes to loopback)?
|
||||
NS_LOG_UNCOND ("Ipv4Interface::Send loopback");
|
||||
m_device->Send (p, m_device->GetBroadcast (),
|
||||
Ipv4L3Protocol::PROT_NUMBER);
|
||||
return;
|
||||
@@ -197,6 +198,7 @@ Ipv4Interface::Send (Ptr<Packet> p, Ipv4Address dest)
|
||||
{
|
||||
if (dest == (*i).GetLocal ())
|
||||
{
|
||||
NS_LOG_UNCOND ("to local");
|
||||
Ptr<Ipv4L3Protocol> ipv4 = m_node->GetObject<Ipv4L3Protocol> ();
|
||||
|
||||
ipv4->Receive (m_device, p, Ipv4L3Protocol::PROT_NUMBER,
|
||||
@@ -209,19 +211,19 @@ Ipv4Interface::Send (Ptr<Packet> p, Ipv4Address dest)
|
||||
}
|
||||
if (m_device->NeedsArp ())
|
||||
{
|
||||
NS_LOG_LOGIC ("Needs ARP" << " " << dest);
|
||||
NS_LOG_UNCOND ("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_UNCOND ("All-network Broadcast");
|
||||
hardwareDestination = m_device->GetBroadcast ();
|
||||
found = true;
|
||||
}
|
||||
else if (dest.IsMulticast ())
|
||||
{
|
||||
NS_LOG_LOGIC ("IsMulticast");
|
||||
NS_LOG_UNCOND ("IsMulticast");
|
||||
NS_ASSERT_MSG(m_device->IsMulticast (),
|
||||
"ArpIpv4Interface::SendTo (): Sending multicast packet over "
|
||||
"non-multicast device");
|
||||
@@ -235,7 +237,7 @@ Ipv4Interface::Send (Ptr<Packet> p, Ipv4Address dest)
|
||||
{
|
||||
if (dest.IsSubnetDirectedBroadcast ((*i).GetMask ()))
|
||||
{
|
||||
NS_LOG_LOGIC ("Subnetwork Broadcast");
|
||||
NS_LOG_UNCOND ("Subnetwork Broadcast hardwareDestination " << hardwareDestination);
|
||||
hardwareDestination = m_device->GetBroadcast ();
|
||||
found = true;
|
||||
break;
|
||||
@@ -243,21 +245,21 @@ Ipv4Interface::Send (Ptr<Packet> p, Ipv4Address dest)
|
||||
}
|
||||
if (!found)
|
||||
{
|
||||
NS_LOG_LOGIC ("ARP Lookup");
|
||||
NS_LOG_UNCOND ("ARP Lookup");
|
||||
found = arp->Lookup (p, dest, m_device, m_cache, &hardwareDestination);
|
||||
}
|
||||
}
|
||||
|
||||
if (found)
|
||||
{
|
||||
NS_LOG_LOGIC ("Address Resolved. Send.");
|
||||
NS_LOG_UNCOND ("Address Resolved. Send.");
|
||||
m_device ->Send (p, hardwareDestination,
|
||||
Ipv4L3Protocol::PROT_NUMBER);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
NS_LOG_LOGIC ("Doesn't need ARP");
|
||||
NS_LOG_UNCOND ("Doesn't need ARP");
|
||||
m_device->Send (p, m_device->GetBroadcast (),
|
||||
Ipv4L3Protocol::PROT_NUMBER);
|
||||
}
|
||||
|
||||
@@ -390,9 +390,9 @@ void
|
||||
Ipv4L3Protocol::Receive( Ptr<NetDevice> device, Ptr<const Packet> p, uint16_t protocol, const Address &from,
|
||||
const Address &to, NetDevice::PacketType packetType)
|
||||
{
|
||||
NS_LOG_FUNCTION (this << &device << p << protocol << from);
|
||||
NS_LOG_UNCOND ("Ipv4L3Protocol::Receive" << &device << p << protocol << from);
|
||||
|
||||
NS_LOG_LOGIC ("Packet from " << from << " received on node " <<
|
||||
NS_LOG_UNCOND ("Packet from " << from << " received on node " <<
|
||||
m_node->GetId ());
|
||||
|
||||
uint32_t interface = 0;
|
||||
@@ -430,6 +430,7 @@ Ipv4L3Protocol::Receive( Ptr<NetDevice> device, Ptr<const Packet> p, uint16_t pr
|
||||
|
||||
if (!ipHeader.IsChecksumOk ())
|
||||
{
|
||||
NS_LOG_UNCOND("bad check sum");
|
||||
m_dropTrace (packet);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -194,14 +194,15 @@ RawSocketImpl::SendTo (Ptr<Packet> packet, uint32_t flags, const Address &toAddr
|
||||
}
|
||||
|
||||
void
|
||||
RawSocketImpl::SendByInterface (Ptr<Packet> packet, Ptr<const Ipv4Route> route)
|
||||
RawSocketImpl::SendByInterface (Ptr<Packet> p, Ptr<const Ipv4Route> route)
|
||||
{
|
||||
NS_ASSERT(m_node != 0);
|
||||
Ipv4Header ipv4Header;
|
||||
Ptr<Packet> packet = p->Copy();
|
||||
packet->PeekHeader(ipv4Header);
|
||||
Ipv4Address source = ipv4Header.GetSource ();
|
||||
Ipv4Address destination = ipv4Header.GetDestination ();
|
||||
NS_LOG_UNCOND ("RawSocketImpl::SendByInterface to " << destination);
|
||||
NS_LOG_UNCOND ("RawSocketImpl::SendByInterface to " << destination << " from " << source);
|
||||
|
||||
// Handle a few cases:
|
||||
// 1) packet is destined to limited broadcast address
|
||||
@@ -224,8 +225,9 @@ RawSocketImpl::SendByInterface (Ptr<Packet> packet, Ptr<const Ipv4Route> route)
|
||||
}
|
||||
|
||||
// 2) check: packet is destined to a subnet-directed broadcast address
|
||||
uint32_t ifaceIndex = 0;
|
||||
bool result = false;
|
||||
uint32_t ifaceIndex = 0;
|
||||
NS_LOG_UNCOND("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;
|
||||
@@ -234,19 +236,14 @@ RawSocketImpl::SendByInterface (Ptr<Packet> packet, Ptr<const Ipv4Route> route)
|
||||
Ipv4InterfaceAddress ifAddr = m_ipv4->GetAddress (ifaceIndex, j);
|
||||
NS_LOG_UNCOND ("Testing address " << ifAddr.GetLocal () << " with mask " << ifAddr.GetMask ());
|
||||
if (destination.IsSubnetDirectedBroadcast (ifAddr.GetMask ()) &&
|
||||
destination.CombineMask (ifAddr.GetMask ()) == ifAddr.GetLocal ().CombineMask (ifAddr.GetMask ()) )
|
||||
{
|
||||
NS_LOG_UNCOND ("RawSocketImpl::Send case 2: subnet directed bcast to " << ifAddr.GetLocal ());
|
||||
if (ifAddr.GetLocal() != loopback)
|
||||
(destination.CombineMask (ifAddr.GetMask ()) == ifAddr.GetLocal ().CombineMask (ifAddr.GetMask ())) )
|
||||
if ( (ifAddr.GetLocal() != loopback)/* && (ifAddr.GetLocal() != source)*/)
|
||||
{
|
||||
Ptr<Packet> copy = packet->Copy();
|
||||
copy->RemoveHeader(ipv4Header);
|
||||
ipv4Header.SetSource(ifAddr.GetLocal());
|
||||
copy->AddHeader(ipv4Header);
|
||||
outInterface->Send (copy, destination);
|
||||
NS_LOG_UNCOND ("Send case 2: subnet directed bcast to " << ifAddr.GetLocal ());
|
||||
Ptr<Packet> packetCopy = packet->Copy ();
|
||||
outInterface->Send (packetCopy, destination);
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(result) return;
|
||||
@@ -268,7 +265,7 @@ RawSocketImpl::SendByInterface (Ptr<Packet> packet, Ptr<const Ipv4Route> route)
|
||||
if (outInterface->IsUp ())
|
||||
{
|
||||
NS_LOG_UNCOND ("Send to gateway " << route->GetGateway ());
|
||||
outInterface->Send (packet, route->GetGateway ());
|
||||
outInterface->Send (p, route->GetGateway ());
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -304,14 +301,14 @@ RawSocketImpl::GetRxAvailable (void) const
|
||||
Ptr<Packet>
|
||||
RawSocketImpl::Recv (uint32_t maxSize, uint32_t flags)
|
||||
{
|
||||
NS_LOG_FUNCTION (this << maxSize << flags);
|
||||
NS_LOG_UNCOND ("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_FUNCTION (this << " maxSize " << maxSize << " flags " << flags << " address " <<fromAddress);
|
||||
NS_LOG_UNCOND ("RawSocketImpl::RecvFrom" << " maxSize " << maxSize << " flags " << flags << " address " <<fromAddress);
|
||||
if (m_recv.empty ())
|
||||
{
|
||||
return 0;
|
||||
|
||||
@@ -45,7 +45,6 @@ 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);
|
||||
|
||||
@@ -764,7 +764,7 @@ RoutingProtocol::SendReply (RreqHeader const & rreqHeader, RoutingTableEntry con
|
||||
TypeHeader tHeader (AODVTYPE_RREP);
|
||||
packet->AddHeader (tHeader);
|
||||
BuildPacket (/*packet*/packet, /*source port*/AODV_PORT, /*destination port*/AODV_PORT, /*source address*/toOrigin.GetInterface ().GetLocal(),
|
||||
/*destination address*/toOrigin.GetNextHop(), /*id*/0 , /*TTL*/ toOrigin.GetHop()); //TODO TTL
|
||||
/*destination address*/toOrigin.GetNextHop(), /*id*/0 , /*TTL*/ /*toOrigin.GetHop()*/ 35); //TODO TTL
|
||||
Ptr<Socket> socket = FindSocketWithInterfaceAddress(toOrigin.GetInterface ().GetLocal ());
|
||||
socket->SendTo (packet, 0, InetSocketAddress (toOrigin.GetNextHop(), AODV_PORT));
|
||||
}
|
||||
@@ -818,7 +818,7 @@ RoutingProtocol::SendReplyAck(Ipv4Address neighbor)
|
||||
RoutingTableEntry toNeighbor;
|
||||
m_routingTable.LookupRoute(neighbor, toNeighbor);
|
||||
BuildPacket (/*packet*/packet, /*source port*/AODV_PORT, /*destination port*/AODV_PORT, /*source address*/toNeighbor.GetInterface ().GetLocal (),
|
||||
/*destination address*/neighbor, /*id*/0 , /*TTL*/ 1);
|
||||
/*destination address*/neighbor, /*id*/0 , /*TTL*/ 35); // TODO TTL
|
||||
Ptr<Socket> socket = FindSocketWithInterfaceAddress(toNeighbor.GetInterface ().GetLocal ());
|
||||
socket->SendTo (packet, 0, InetSocketAddress (neighbor, AODV_PORT));
|
||||
}
|
||||
@@ -893,7 +893,8 @@ RoutingProtocol::RecvReply (Ptr<Packet> p, Ipv4Address receiver, Ipv4Address sen
|
||||
}
|
||||
// Acknowledge receipt of the RREP by sending a RREP-ACK message back
|
||||
if(rrepHeader.GetAckRequired()) SendReplyAck(sender);
|
||||
if (receiver == rrepHeader.GetOrigin ())
|
||||
NS_LOG_LOGIC ("receiver " << receiver << " origin " << rrepHeader.GetOrigin ());
|
||||
if ( FindSocketWithInterfaceAddress (rrepHeader.GetOrigin ()) != 0 )
|
||||
{
|
||||
if (toDst.GetFlag () == RTF_IN_SEARCH)
|
||||
m_routingTable.Update (rrepHeader.GetDst (), newEntry);
|
||||
@@ -1132,6 +1133,7 @@ RoutingProtocol::SendHello ()
|
||||
void
|
||||
RoutingProtocol::SendPacketFromQueue (Ipv4Address dst, Ptr<Ipv4Route> route)
|
||||
{
|
||||
NS_LOG_FUNCTION(this);
|
||||
QueueEntry queueEntry;
|
||||
while (m_queue.Dequeue (dst, queueEntry))
|
||||
{
|
||||
|
||||
@@ -249,7 +249,6 @@ RoutingTable::MarkLinkAsUinidirectional (Ipv4Address neighbor, Time blacklistTim
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
RoutingTable::Print(std::ostream &os) const
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user