|
|
| 283 |
iter->first->Close (); |
283 |
iter->first->Close (); |
| 284 |
} |
284 |
} |
| 285 |
m_socketAddresses.clear (); |
285 |
m_socketAddresses.clear (); |
|
|
286 |
for (std::map<Ptr<Socket>, Ipv4InterfaceAddress>::iterator iter = |
| 287 |
m_socketSubnetBroadcastAddresses.begin (); iter != m_socketSubnetBroadcastAddresses.end (); iter++) |
| 288 |
{ |
| 289 |
iter->first->Close (); |
| 290 |
} |
| 291 |
m_socketSubnetBroadcastAddresses.clear (); |
| 286 |
Ipv4RoutingProtocol::DoDispose (); |
292 |
Ipv4RoutingProtocol::DoDispose (); |
| 287 |
} |
293 |
} |
| 288 |
|
294 |
|
|
|
| 613 |
UdpSocketFactory::GetTypeId ()); |
619 |
UdpSocketFactory::GetTypeId ()); |
| 614 |
NS_ASSERT (socket != 0); |
620 |
NS_ASSERT (socket != 0); |
| 615 |
socket->SetRecvCallback (MakeCallback (&RoutingProtocol::RecvAodv, this)); |
621 |
socket->SetRecvCallback (MakeCallback (&RoutingProtocol::RecvAodv, this)); |
|
|
622 |
socket->Bind (InetSocketAddress (iface.GetLocal (), AODV_PORT)); |
| 616 |
socket->BindToNetDevice (l3->GetNetDevice (i)); |
623 |
socket->BindToNetDevice (l3->GetNetDevice (i)); |
| 617 |
socket->Bind (InetSocketAddress (Ipv4Address::GetAny (), AODV_PORT)); |
|
|
| 618 |
socket->SetAllowBroadcast (true); |
624 |
socket->SetAllowBroadcast (true); |
| 619 |
socket->SetAttribute ("IpTtl", UintegerValue (1)); |
625 |
socket->SetAttribute ("IpTtl", UintegerValue (1)); |
| 620 |
m_socketAddresses.insert (std::make_pair (socket, iface)); |
626 |
m_socketAddresses.insert (std::make_pair (socket, iface)); |
| 621 |
|
627 |
|
|
|
628 |
// create also a subnet broadcast socket |
| 629 |
socket = Socket::CreateSocket (GetObject<Node> (), |
| 630 |
UdpSocketFactory::GetTypeId ()); |
| 631 |
NS_ASSERT (socket != 0); |
| 632 |
socket->SetRecvCallback (MakeCallback (&RoutingProtocol::RecvAodv, this)); |
| 633 |
socket->Bind (InetSocketAddress (iface.GetBroadcast (), AODV_PORT)); |
| 634 |
socket->BindToNetDevice (l3->GetNetDevice (i)); |
| 635 |
socket->SetAllowBroadcast (true); |
| 636 |
socket->SetAttribute ("IpTtl", UintegerValue (1)); |
| 637 |
m_socketSubnetBroadcastAddresses.insert (std::make_pair (socket, iface)); |
| 638 |
|
| 622 |
// Add local broadcast record to the routing table |
639 |
// Add local broadcast record to the routing table |
| 623 |
Ptr<NetDevice> dev = m_ipv4->GetNetDevice (m_ipv4->GetInterfaceForAddress (iface.GetLocal ())); |
640 |
Ptr<NetDevice> dev = m_ipv4->GetNetDevice (m_ipv4->GetInterfaceForAddress (iface.GetLocal ())); |
| 624 |
RoutingTableEntry rt (/*device=*/ dev, /*dst=*/ iface.GetBroadcast (), /*know seqno=*/ true, /*seqno=*/ 0, /*iface=*/ iface, |
641 |
RoutingTableEntry rt (/*device=*/ dev, /*dst=*/ iface.GetBroadcast (), /*know seqno=*/ true, /*seqno=*/ 0, /*iface=*/ iface, |
| 625 |
/*hops=*/ 1, /*next hop=*/ iface.GetBroadcast (), /*lifetime=*/ Simulator::GetMaximumSimulationTime ()); |
642 |
/*hops=*/ 1, /*next hop=*/ iface.GetBroadcast (), /*lifetime=*/ Simulator::GetMaximumSimulationTime ()); |
| 626 |
m_routingTable.AddRoute (rt); |
643 |
m_routingTable.AddRoute (rt); |
| 627 |
|
644 |
|
|
|
645 |
if (l3->GetInterface (i)->GetArpCache ()) |
| 646 |
{ |
| 647 |
m_nb.AddArpCache (l3->GetInterface (i)->GetArpCache ()); |
| 648 |
} |
| 649 |
|
| 628 |
// Allow neighbor manager use this interface for layer 2 feedback if possible |
650 |
// Allow neighbor manager use this interface for layer 2 feedback if possible |
| 629 |
Ptr<WifiNetDevice> wifi = dev->GetObject<WifiNetDevice> (); |
651 |
Ptr<WifiNetDevice> wifi = dev->GetObject<WifiNetDevice> (); |
| 630 |
if (wifi == 0) |
652 |
if (wifi == 0) |
|
|
| 634 |
return; |
656 |
return; |
| 635 |
|
657 |
|
| 636 |
mac->TraceConnectWithoutContext ("TxErrHeader", m_nb.GetTxErrorCallback ()); |
658 |
mac->TraceConnectWithoutContext ("TxErrHeader", m_nb.GetTxErrorCallback ()); |
| 637 |
m_nb.AddArpCache (l3->GetInterface (i)->GetArpCache ()); |
|
|
| 638 |
} |
659 |
} |
| 639 |
|
660 |
|
| 640 |
void |
661 |
void |
|
|
| 662 |
NS_ASSERT (socket); |
683 |
NS_ASSERT (socket); |
| 663 |
socket->Close (); |
684 |
socket->Close (); |
| 664 |
m_socketAddresses.erase (socket); |
685 |
m_socketAddresses.erase (socket); |
|
|
686 |
|
| 687 |
// Close socket |
| 688 |
socket = FindSubnetBroadcastSocketWithInterfaceAddress (m_ipv4->GetAddress (i, 0)); |
| 689 |
NS_ASSERT (socket); |
| 690 |
socket->Close (); |
| 691 |
m_socketSubnetBroadcastAddresses.erase (socket); |
| 692 |
|
| 665 |
if (m_socketAddresses.empty ()) |
693 |
if (m_socketAddresses.empty ()) |
| 666 |
{ |
694 |
{ |
| 667 |
NS_LOG_LOGIC ("No aodv interfaces"); |
695 |
NS_LOG_LOGIC ("No aodv interfaces"); |
|
|
| 693 |
UdpSocketFactory::GetTypeId ()); |
721 |
UdpSocketFactory::GetTypeId ()); |
| 694 |
NS_ASSERT (socket != 0); |
722 |
NS_ASSERT (socket != 0); |
| 695 |
socket->SetRecvCallback (MakeCallback (&RoutingProtocol::RecvAodv,this)); |
723 |
socket->SetRecvCallback (MakeCallback (&RoutingProtocol::RecvAodv,this)); |
|
|
724 |
socket->Bind (InetSocketAddress (iface.GetLocal (), AODV_PORT)); |
| 696 |
socket->BindToNetDevice (l3->GetNetDevice (i)); |
725 |
socket->BindToNetDevice (l3->GetNetDevice (i)); |
| 697 |
// Bind to any IP address so that broadcasts can be received |
|
|
| 698 |
socket->Bind (InetSocketAddress (Ipv4Address::GetAny (), AODV_PORT)); |
| 699 |
socket->SetAllowBroadcast (true); |
726 |
socket->SetAllowBroadcast (true); |
| 700 |
m_socketAddresses.insert (std::make_pair (socket, iface)); |
727 |
m_socketAddresses.insert (std::make_pair (socket, iface)); |
| 701 |
|
728 |
|
|
|
729 |
// create also a subnet directed broadcast socket |
| 730 |
socket = Socket::CreateSocket (GetObject<Node> (), |
| 731 |
UdpSocketFactory::GetTypeId ()); |
| 732 |
NS_ASSERT (socket != 0); |
| 733 |
socket->SetRecvCallback (MakeCallback (&RoutingProtocol::RecvAodv, this)); |
| 734 |
socket->Bind (InetSocketAddress (iface.GetBroadcast (), AODV_PORT)); |
| 735 |
socket->BindToNetDevice (l3->GetNetDevice (i)); |
| 736 |
socket->SetAllowBroadcast (true); |
| 737 |
socket->SetAttribute ("IpTtl", UintegerValue (1)); |
| 738 |
m_socketSubnetBroadcastAddresses.insert (std::make_pair (socket, iface)); |
| 739 |
|
| 702 |
// Add local broadcast record to the routing table |
740 |
// Add local broadcast record to the routing table |
| 703 |
Ptr<NetDevice> dev = m_ipv4->GetNetDevice ( |
741 |
Ptr<NetDevice> dev = m_ipv4->GetNetDevice ( |
| 704 |
m_ipv4->GetInterfaceForAddress (iface.GetLocal ())); |
742 |
m_ipv4->GetInterfaceForAddress (iface.GetLocal ())); |
|
|
| 722 |
if (socket) |
760 |
if (socket) |
| 723 |
{ |
761 |
{ |
| 724 |
m_routingTable.DeleteAllRoutesFromInterface (address); |
762 |
m_routingTable.DeleteAllRoutesFromInterface (address); |
|
|
763 |
socket->Close (); |
| 725 |
m_socketAddresses.erase (socket); |
764 |
m_socketAddresses.erase (socket); |
|
|
765 |
|
| 766 |
Ptr<Socket> unicastSocket = FindSubnetBroadcastSocketWithInterfaceAddress (address); |
| 767 |
if (unicastSocket) |
| 768 |
{ |
| 769 |
unicastSocket->Close (); |
| 770 |
m_socketAddresses.erase (unicastSocket); |
| 771 |
} |
| 772 |
|
| 726 |
Ptr<Ipv4L3Protocol> l3 = m_ipv4->GetObject<Ipv4L3Protocol> (); |
773 |
Ptr<Ipv4L3Protocol> l3 = m_ipv4->GetObject<Ipv4L3Protocol> (); |
| 727 |
if (l3->GetNAddresses (i)) |
774 |
if (l3->GetNAddresses (i)) |
| 728 |
{ |
775 |
{ |
|
|
| 733 |
NS_ASSERT (socket != 0); |
780 |
NS_ASSERT (socket != 0); |
| 734 |
socket->SetRecvCallback (MakeCallback (&RoutingProtocol::RecvAodv, this)); |
781 |
socket->SetRecvCallback (MakeCallback (&RoutingProtocol::RecvAodv, this)); |
| 735 |
// Bind to any IP address so that broadcasts can be received |
782 |
// Bind to any IP address so that broadcasts can be received |
| 736 |
socket->Bind (InetSocketAddress (Ipv4Address::GetAny (), AODV_PORT)); |
783 |
socket->Bind (InetSocketAddress (iface.GetLocal (), AODV_PORT)); |
|
|
784 |
socket->BindToNetDevice (l3->GetNetDevice (i)); |
| 737 |
socket->SetAllowBroadcast (true); |
785 |
socket->SetAllowBroadcast (true); |
|
|
786 |
socket->SetAttribute ("IpTtl", UintegerValue (1)); |
| 738 |
m_socketAddresses.insert (std::make_pair (socket, iface)); |
787 |
m_socketAddresses.insert (std::make_pair (socket, iface)); |
| 739 |
|
788 |
|
|
|
789 |
// create also a unicast socket |
| 790 |
socket = Socket::CreateSocket (GetObject<Node> (), |
| 791 |
UdpSocketFactory::GetTypeId ()); |
| 792 |
NS_ASSERT (socket != 0); |
| 793 |
socket->SetRecvCallback (MakeCallback (&RoutingProtocol::RecvAodv, this)); |
| 794 |
socket->Bind (InetSocketAddress (iface.GetBroadcast (), AODV_PORT)); |
| 795 |
socket->BindToNetDevice (l3->GetNetDevice (i)); |
| 796 |
socket->SetAllowBroadcast (true); |
| 797 |
socket->SetAttribute ("IpTtl", UintegerValue (1)); |
| 798 |
m_socketSubnetBroadcastAddresses.insert (std::make_pair (socket, iface)); |
| 799 |
|
| 740 |
// Add local broadcast record to the routing table |
800 |
// Add local broadcast record to the routing table |
| 741 |
Ptr<NetDevice> dev = m_ipv4->GetNetDevice (m_ipv4->GetInterfaceForAddress (iface.GetLocal ())); |
801 |
Ptr<NetDevice> dev = m_ipv4->GetNetDevice (m_ipv4->GetInterfaceForAddress (iface.GetLocal ())); |
| 742 |
RoutingTableEntry rt (/*device=*/ dev, /*dst=*/ iface.GetBroadcast (), /*know seqno=*/ true, /*seqno=*/ 0, /*iface=*/ iface, |
802 |
RoutingTableEntry rt (/*device=*/ dev, /*dst=*/ iface.GetBroadcast (), /*know seqno=*/ true, /*seqno=*/ 0, /*iface=*/ iface, |
|
|
| 937 |
Ptr<Packet> packet = socket->RecvFrom (sourceAddress); |
997 |
Ptr<Packet> packet = socket->RecvFrom (sourceAddress); |
| 938 |
InetSocketAddress inetSourceAddr = InetSocketAddress::ConvertFrom (sourceAddress); |
998 |
InetSocketAddress inetSourceAddr = InetSocketAddress::ConvertFrom (sourceAddress); |
| 939 |
Ipv4Address sender = inetSourceAddr.GetIpv4 (); |
999 |
Ipv4Address sender = inetSourceAddr.GetIpv4 (); |
| 940 |
Ipv4Address receiver = m_socketAddresses[socket].GetLocal (); |
1000 |
Ipv4Address receiver; |
|
|
1001 |
|
| 1002 |
if (m_socketAddresses.find (socket) != m_socketAddresses.end ()) |
| 1003 |
{ |
| 1004 |
receiver = m_socketAddresses[socket].GetLocal (); |
| 1005 |
} |
| 1006 |
else if(m_socketSubnetBroadcastAddresses.find (socket) != m_socketSubnetBroadcastAddresses.end ()) |
| 1007 |
{ |
| 1008 |
receiver = m_socketSubnetBroadcastAddresses[socket].GetLocal (); |
| 1009 |
} |
| 1010 |
else |
| 1011 |
{ |
| 1012 |
NS_ASSERT_MSG (false, "Received a packet from an unknown socket"); |
| 1013 |
} |
| 941 |
NS_LOG_DEBUG ("AODV node " << this << " received a AODV packet from " << sender << " to " << receiver); |
1014 |
NS_LOG_DEBUG ("AODV node " << this << " received a AODV packet from " << sender << " to " << receiver); |
| 942 |
|
1015 |
|
| 943 |
UpdateRouteToNeighbor (sender, receiver); |
1016 |
UpdateRouteToNeighbor (sender, receiver); |
|
|
| 1832 |
return socket; |
1905 |
return socket; |
| 1833 |
} |
1906 |
} |
| 1834 |
|
1907 |
|
|
|
1908 |
Ptr<Socket> |
| 1909 |
RoutingProtocol::FindSubnetBroadcastSocketWithInterfaceAddress (Ipv4InterfaceAddress addr ) const |
| 1910 |
{ |
| 1911 |
NS_LOG_FUNCTION (this << addr); |
| 1912 |
for (std::map<Ptr<Socket>, Ipv4InterfaceAddress>::const_iterator j = |
| 1913 |
m_socketSubnetBroadcastAddresses.begin (); j != m_socketSubnetBroadcastAddresses.end (); ++j) |
| 1914 |
{ |
| 1915 |
Ptr<Socket> socket = j->first; |
| 1916 |
Ipv4InterfaceAddress iface = j->second; |
| 1917 |
if (iface == addr) |
| 1918 |
return socket; |
| 1919 |
} |
| 1920 |
Ptr<Socket> socket; |
| 1921 |
return socket; |
| 1835 |
} |
1922 |
} |
|
|
1923 |
|
| 1836 |
} |
1924 |
} |
|
|
1925 |
} |