|
269 |
RoutingProtocol::RouteOutput (Ptr<Packet> p, const Ipv4Header &header, |
269 |
RoutingProtocol::RouteOutput (Ptr<Packet> p, const Ipv4Header &header, |
270 |
Ptr<NetDevice> oif, Socket::SocketErrno &sockerr) |
270 |
Ptr<NetDevice> oif, Socket::SocketErrno &sockerr) |
271 |
{ |
271 |
{ |
272 |
NS_LOG_FUNCTION (this << header.GetDestination ()); |
272 |
NS_LOG_FUNCTION (this << header << (oif? oif->GetIfIndex () : 0)); |
273 |
if (! p) |
273 |
if (! p) |
274 |
{ |
274 |
{ |
275 |
return LoopbackRoute (header); // later |
275 |
return LoopbackRoute (header); // later |
|
370 |
{ |
370 |
{ |
371 |
Ipv4InterfaceAddress iface = j->second; |
371 |
Ipv4InterfaceAddress iface = j->second; |
372 |
if (m_ipv4->GetInterfaceForAddress (iface.GetLocal ()) == iif) |
372 |
if (m_ipv4->GetInterfaceForAddress (iface.GetLocal ()) == iif) |
373 |
if (dst == iface.GetBroadcast ()) |
373 |
if (dst == iface.GetBroadcast () || dst.IsBroadcast ()) |
374 |
{ |
374 |
{ |
375 |
if (!EnableBroadcast) |
|
|
376 |
{ |
377 |
return true; |
378 |
} |
379 |
if (m_dpd.IsDuplicate (p, header)) |
375 |
if (m_dpd.IsDuplicate (p, header)) |
380 |
{ |
376 |
{ |
381 |
NS_LOG_DEBUG ("Duplicated packet " << p->GetUid () << " from " << origin << ". Drop."); |
377 |
NS_LOG_DEBUG ("Duplicated packet " << p->GetUid () << " from " << origin << ". Drop."); |
|
385 |
NS_LOG_LOGIC ("Broadcast local delivery to " << iface.GetLocal ()); |
381 |
NS_LOG_LOGIC ("Broadcast local delivery to " << iface.GetLocal ()); |
386 |
Ptr<Packet> packet = p->Copy (); |
382 |
Ptr<Packet> packet = p->Copy (); |
387 |
lcb (p, header, iif); |
383 |
lcb (p, header, iif); |
|
|
384 |
if (!EnableBroadcast) |
385 |
{ |
386 |
return true; |
387 |
} |
388 |
if (header.GetTtl () > 1) |
388 |
if (header.GetTtl () > 1) |
389 |
{ |
389 |
{ |
390 |
NS_LOG_LOGIC ("Forward broadcast. TTL " << (uint16_t) header.GetTtl ()); |
390 |
NS_LOG_LOGIC ("Forward broadcast. TTL " << (uint16_t) header.GetTtl ()); |
|
528 |
UdpSocketFactory::GetTypeId ()); |
528 |
UdpSocketFactory::GetTypeId ()); |
529 |
NS_ASSERT (socket != 0); |
529 |
NS_ASSERT (socket != 0); |
530 |
socket->SetRecvCallback (MakeCallback (&RoutingProtocol::RecvAodv, this)); |
530 |
socket->SetRecvCallback (MakeCallback (&RoutingProtocol::RecvAodv, this)); |
531 |
socket->Bind (InetSocketAddress (iface.GetLocal (), AODV_PORT)); |
531 |
socket->BindToNetDevice (l3->GetNetDevice (i)); |
532 |
socket->Connect (InetSocketAddress (iface.GetBroadcast (), AODV_PORT)); |
532 |
socket->Bind (InetSocketAddress (Ipv4Address::GetAny (), AODV_PORT)); |
|
|
533 |
socket->SetAllowBroadcast (true); |
533 |
socket->SetAttribute ("IpTtl", UintegerValue (1)); |
534 |
socket->SetAttribute ("IpTtl", UintegerValue (1)); |
534 |
m_socketAddresses.insert (std::make_pair (socket, iface)); |
535 |
m_socketAddresses.insert (std::make_pair (socket, iface)); |
535 |
|
536 |
|
|
607 |
UdpSocketFactory::GetTypeId ()); |
608 |
UdpSocketFactory::GetTypeId ()); |
608 |
NS_ASSERT (socket != 0); |
609 |
NS_ASSERT (socket != 0); |
609 |
socket->SetRecvCallback (MakeCallback (&RoutingProtocol::RecvAodv,this)); |
610 |
socket->SetRecvCallback (MakeCallback (&RoutingProtocol::RecvAodv,this)); |
610 |
socket->Bind (InetSocketAddress (iface.GetLocal (), AODV_PORT)); |
611 |
socket->BindToNetDevice (l3->GetNetDevice (i)); |
611 |
socket->Connect (InetSocketAddress (iface.GetBroadcast (), AODV_PORT)); |
612 |
// Bind to any IP address so that broadcasts can be received |
|
|
613 |
socket->Bind (InetSocketAddress (Ipv4Address::GetAny(), AODV_PORT)); |
614 |
socket->SetAllowBroadcast (true); |
612 |
m_socketAddresses.insert (std::make_pair (socket, iface)); |
615 |
m_socketAddresses.insert (std::make_pair (socket, iface)); |
613 |
|
616 |
|
614 |
// Add local broadcast record to the routing table |
617 |
// Add local broadcast record to the routing table |
|
644 |
UdpSocketFactory::GetTypeId ()); |
647 |
UdpSocketFactory::GetTypeId ()); |
645 |
NS_ASSERT (socket != 0); |
648 |
NS_ASSERT (socket != 0); |
646 |
socket->SetRecvCallback (MakeCallback (&RoutingProtocol::RecvAodv, this)); |
649 |
socket->SetRecvCallback (MakeCallback (&RoutingProtocol::RecvAodv, this)); |
647 |
socket->Bind (InetSocketAddress (iface.GetLocal (), AODV_PORT)); |
650 |
// Bind to any IP address so that broadcasts can be received |
648 |
socket->Connect (InetSocketAddress (iface.GetBroadcast (), AODV_PORT)); |
651 |
socket->Bind (InetSocketAddress (Ipv4Address::GetAny(), AODV_PORT)); |
|
|
652 |
socket->SetAllowBroadcast (true); |
649 |
m_socketAddresses.insert (std::make_pair (socket, iface)); |
653 |
m_socketAddresses.insert (std::make_pair (socket, iface)); |
650 |
|
654 |
|
651 |
// Add local broadcast record to the routing table |
655 |
// Add local broadcast record to the routing table |
|
692 |
NS_ASSERT (m_lo != 0); |
696 |
NS_ASSERT (m_lo != 0); |
693 |
Ptr<Ipv4Route> rt = Create<Ipv4Route> (); |
697 |
Ptr<Ipv4Route> rt = Create<Ipv4Route> (); |
694 |
rt->SetDestination (hdr.GetDestination ()); |
698 |
rt->SetDestination (hdr.GetDestination ()); |
695 |
rt->SetSource (hdr.GetSource ()); |
699 |
rt->SetSource (Ipv4Address ("127.0.0.1")); |
696 |
rt->SetGateway (Ipv4Address ("127.0.0.1")); |
700 |
rt->SetGateway (Ipv4Address ("127.0.0.1")); |
697 |
rt->SetOutputDevice (m_lo); |
701 |
rt->SetOutputDevice (m_lo); |
698 |
return rt; |
702 |
return rt; |
|
762 |
packet->AddHeader (rreqHeader); |
766 |
packet->AddHeader (rreqHeader); |
763 |
TypeHeader tHeader (AODVTYPE_RREQ); |
767 |
TypeHeader tHeader (AODVTYPE_RREQ); |
764 |
packet->AddHeader (tHeader); |
768 |
packet->AddHeader (tHeader); |
765 |
socket->Send (packet); |
769 |
// Send to all-hosts broadcast if on /32 addr, subnet-directed otherwise |
|
|
770 |
Ipv4Address destination; |
771 |
if (iface.GetMask () == Ipv4Mask::GetOnes ()) |
772 |
{ |
773 |
destination = Ipv4Address ("255.255.255.255"); |
774 |
} |
775 |
else |
776 |
{ |
777 |
destination = iface.GetBroadcast (); |
778 |
} |
779 |
socket->SendTo (packet, 0, InetSocketAddress (destination, AODV_PORT)); |
766 |
} |
780 |
} |
767 |
ScheduleRreqRetry (dst); |
781 |
ScheduleRreqRetry (dst); |
768 |
if (EnableHello) |
782 |
if (EnableHello) |
|
989 |
packet->AddHeader (rreqHeader); |
1003 |
packet->AddHeader (rreqHeader); |
990 |
TypeHeader tHeader (AODVTYPE_RREQ); |
1004 |
TypeHeader tHeader (AODVTYPE_RREQ); |
991 |
packet->AddHeader (tHeader); |
1005 |
packet->AddHeader (tHeader); |
992 |
socket->Send (packet); |
1006 |
// Send to all-hosts broadcast if on /32 addr, subnet-directed otherwise |
|
|
1007 |
Ipv4Address destination; |
1008 |
if (iface.GetMask () == Ipv4Mask::GetOnes ()) |
1009 |
{ |
1010 |
destination = Ipv4Address ("255.255.255.255"); |
1011 |
} |
1012 |
else |
1013 |
{ |
1014 |
destination = iface.GetBroadcast (); |
1015 |
} |
1016 |
socket->SendTo (packet, 0, InetSocketAddress (destination, AODV_PORT)); |
993 |
} |
1017 |
} |
994 |
|
1018 |
|
995 |
if (EnableHello) |
1019 |
if (EnableHello) |
|
1401 |
packet->AddHeader (helloHeader); |
1425 |
packet->AddHeader (helloHeader); |
1402 |
TypeHeader tHeader (AODVTYPE_RREP); |
1426 |
TypeHeader tHeader (AODVTYPE_RREP); |
1403 |
packet->AddHeader (tHeader); |
1427 |
packet->AddHeader (tHeader); |
1404 |
socket->Send (packet); |
1428 |
// Send to all-hosts broadcast if on /32 addr, subnet-directed otherwise |
|
|
1429 |
Ipv4Address destination; |
1430 |
if (iface.GetMask () == Ipv4Mask::GetOnes ()) |
1431 |
{ |
1432 |
destination = Ipv4Address ("255.255.255.255"); |
1433 |
} |
1434 |
else |
1435 |
{ |
1436 |
destination = iface.GetBroadcast (); |
1437 |
} |
1438 |
socket->SendTo (packet, 0, InetSocketAddress (destination, AODV_PORT)); |
1405 |
} |
1439 |
} |
1406 |
} |
1440 |
} |
1407 |
|
1441 |
|
|
1504 |
Ipv4InterfaceAddress iface = i->second; |
1538 |
Ipv4InterfaceAddress iface = i->second; |
1505 |
NS_ASSERT (socket); |
1539 |
NS_ASSERT (socket); |
1506 |
NS_LOG_LOGIC ("Broadcast RERR message from interface " << iface.GetLocal()); |
1540 |
NS_LOG_LOGIC ("Broadcast RERR message from interface " << iface.GetLocal()); |
1507 |
socket->Send (packet); |
1541 |
// Send to all-hosts broadcast if on /32 addr, subnet-directed otherwise |
|
|
1542 |
Ipv4Address destination; |
1543 |
if (iface.GetMask () == Ipv4Mask::GetOnes ()) |
1544 |
{ |
1545 |
destination = Ipv4Address ("255.255.255.255"); |
1546 |
} |
1547 |
else |
1548 |
{ |
1549 |
destination = iface.GetBroadcast (); |
1550 |
} |
1551 |
socket->SendTo (packet, 0, InetSocketAddress (destination, AODV_PORT)); |
1508 |
} |
1552 |
} |
1509 |
} |
1553 |
} |
1510 |
} |
1554 |
} |
|
1550 |
Ptr<Socket> socket = FindSocketWithInterfaceAddress (*i); |
1594 |
Ptr<Socket> socket = FindSocketWithInterfaceAddress (*i); |
1551 |
NS_ASSERT (socket); |
1595 |
NS_ASSERT (socket); |
1552 |
NS_LOG_LOGIC ("Broadcast RERR message from interface " << i->GetLocal()); |
1596 |
NS_LOG_LOGIC ("Broadcast RERR message from interface " << i->GetLocal()); |
1553 |
socket->Send (packet); |
1597 |
// Send to all-hosts broadcast if on /32 addr, subnet-directed otherwise |
|
|
1598 |
Ipv4Address destination; |
1599 |
if (i->GetMask () == Ipv4Mask::GetOnes ()) |
1600 |
{ |
1601 |
destination = Ipv4Address ("255.255.255.255"); |
1602 |
} |
1603 |
else |
1604 |
{ |
1605 |
destination = i->GetBroadcast (); |
1606 |
} |
1607 |
socket->SendTo (packet, 0, InetSocketAddress (destination, AODV_PORT)); |
1554 |
} |
1608 |
} |
1555 |
} |
1609 |
} |
1556 |
|
1610 |
|