View | Details | Raw Unified | Return to bug 1911
Collapse All | Expand All

(-)a/src/aodv/model/aodv-routing-protocol.cc (-5 / +95 lines)
 Lines 283-288    Link Here 
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_socketUnicastAddresses.begin (); iter != m_socketUnicastAddresses.end (); iter++)
288
    {
289
      iter->first->Close ();
290
    }
291
  m_socketUnicastAddresses.clear ();
286
  Ipv4RoutingProtocol::DoDispose ();
292
  Ipv4RoutingProtocol::DoDispose ();
287
}
293
}
288
294
 Lines 613-630    Link Here 
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));
616
  socket->Bind (InetSocketAddress (Ipv4Address::GetAny (), AODV_PORT));
622
  socket->Bind (InetSocketAddress (iface.GetBroadcast (), AODV_PORT));
617
  socket->BindToNetDevice (l3->GetNetDevice (i));
623
  socket->BindToNetDevice (l3->GetNetDevice (i));
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 unicast 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.GetLocal (), AODV_PORT));
634
  socket->BindToNetDevice (l3->GetNetDevice (i));
635
  socket->SetAllowBroadcast (true);
636
  socket->SetAttribute ("IpTtl", UintegerValue (1));
637
  m_socketUnicastAddresses.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)
 Lines 634-640    Link Here 
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
 Lines 662-667    Link Here 
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 = FindUnicastSocketWithInterfaceAddress (m_ipv4->GetAddress (i, 0));
689
  NS_ASSERT (socket);
690
  socket->Close ();
691
  m_socketUnicastAddresses.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");
 Lines 694-704    Link Here 
694
          NS_ASSERT (socket != 0);
722
          NS_ASSERT (socket != 0);
695
          socket->SetRecvCallback (MakeCallback (&RoutingProtocol::RecvAodv,this));
723
          socket->SetRecvCallback (MakeCallback (&RoutingProtocol::RecvAodv,this));
696
          // Bind to any IP address so that broadcasts can be received
724
          // Bind to any IP address so that broadcasts can be received
697
          socket->Bind (InetSocketAddress (Ipv4Address::GetAny (), AODV_PORT));
725
          socket->Bind (InetSocketAddress (iface.GetBroadcast (), AODV_PORT));
698
          socket->BindToNetDevice (l3->GetNetDevice (i));
726
          socket->BindToNetDevice (l3->GetNetDevice (i));
699
          socket->SetAllowBroadcast (true);
727
          socket->SetAllowBroadcast (true);
700
          m_socketAddresses.insert (std::make_pair (socket, iface));
728
          m_socketAddresses.insert (std::make_pair (socket, iface));
701
729
730
          // create also a unicast socket
731
          socket = Socket::CreateSocket (GetObject<Node> (),
732
                                                       UdpSocketFactory::GetTypeId ());
733
          NS_ASSERT (socket != 0);
734
          socket->SetRecvCallback (MakeCallback (&RoutingProtocol::RecvAodv, this));
735
          socket->Bind (InetSocketAddress (iface.GetLocal (), AODV_PORT));
736
          socket->BindToNetDevice (l3->GetNetDevice (i));
737
          socket->SetAllowBroadcast (true);
738
          socket->SetAttribute ("IpTtl", UintegerValue (1));
739
          m_socketUnicastAddresses.insert (std::make_pair (socket, iface));
740
702
          // Add local broadcast record to the routing table
741
          // Add local broadcast record to the routing table
703
          Ptr<NetDevice> dev = m_ipv4->GetNetDevice (
742
          Ptr<NetDevice> dev = m_ipv4->GetNetDevice (
704
              m_ipv4->GetInterfaceForAddress (iface.GetLocal ()));
743
              m_ipv4->GetInterfaceForAddress (iface.GetLocal ()));
 Lines 722-728    Link Here 
722
  if (socket)
761
  if (socket)
723
    {
762
    {
724
      m_routingTable.DeleteAllRoutesFromInterface (address);
763
      m_routingTable.DeleteAllRoutesFromInterface (address);
764
      socket->Close ();
725
      m_socketAddresses.erase (socket);
765
      m_socketAddresses.erase (socket);
766
767
      Ptr<Socket> unicastSocket = FindUnicastSocketWithInterfaceAddress (address);
768
      if (unicastSocket)
769
        {
770
          unicastSocket->Close ();
771
          m_socketAddresses.erase (unicastSocket);
772
        }
773
726
      Ptr<Ipv4L3Protocol> l3 = m_ipv4->GetObject<Ipv4L3Protocol> ();
774
      Ptr<Ipv4L3Protocol> l3 = m_ipv4->GetObject<Ipv4L3Protocol> ();
727
      if (l3->GetNAddresses (i))
775
      if (l3->GetNAddresses (i))
728
        {
776
        {
 Lines 733-742    Link Here 
733
          NS_ASSERT (socket != 0);
781
          NS_ASSERT (socket != 0);
734
          socket->SetRecvCallback (MakeCallback (&RoutingProtocol::RecvAodv, this));
782
          socket->SetRecvCallback (MakeCallback (&RoutingProtocol::RecvAodv, this));
735
          // Bind to any IP address so that broadcasts can be received
783
          // Bind to any IP address so that broadcasts can be received
736
          socket->Bind (InetSocketAddress (Ipv4Address::GetAny (), AODV_PORT));
784
          socket->Bind (InetSocketAddress (iface.GetBroadcast (), AODV_PORT));
785
          socket->BindToNetDevice (l3->GetNetDevice (i));
737
          socket->SetAllowBroadcast (true);
786
          socket->SetAllowBroadcast (true);
787
          socket->SetAttribute ("IpTtl", UintegerValue (1));
738
          m_socketAddresses.insert (std::make_pair (socket, iface));
788
          m_socketAddresses.insert (std::make_pair (socket, iface));
739
789
790
          // create also a unicast socket
791
          socket = Socket::CreateSocket (GetObject<Node> (),
792
                                                       UdpSocketFactory::GetTypeId ());
793
          NS_ASSERT (socket != 0);
794
          socket->SetRecvCallback (MakeCallback (&RoutingProtocol::RecvAodv, this));
795
          socket->Bind (InetSocketAddress (iface.GetLocal (), AODV_PORT));
796
          socket->BindToNetDevice (l3->GetNetDevice (i));
797
          socket->SetAllowBroadcast (true);
798
          socket->SetAttribute ("IpTtl", UintegerValue (1));
799
          m_socketUnicastAddresses.insert (std::make_pair (socket, iface));
800
740
          // Add local broadcast record to the routing table
801
          // Add local broadcast record to the routing table
741
          Ptr<NetDevice> dev = m_ipv4->GetNetDevice (m_ipv4->GetInterfaceForAddress (iface.GetLocal ()));
802
          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,
803
          RoutingTableEntry rt (/*device=*/ dev, /*dst=*/ iface.GetBroadcast (), /*know seqno=*/ true, /*seqno=*/ 0, /*iface=*/ iface,
 Lines 937-943    Link Here 
937
  Ptr<Packet> packet = socket->RecvFrom (sourceAddress);
998
  Ptr<Packet> packet = socket->RecvFrom (sourceAddress);
938
  InetSocketAddress inetSourceAddr = InetSocketAddress::ConvertFrom (sourceAddress);
999
  InetSocketAddress inetSourceAddr = InetSocketAddress::ConvertFrom (sourceAddress);
939
  Ipv4Address sender = inetSourceAddr.GetIpv4 ();
1000
  Ipv4Address sender = inetSourceAddr.GetIpv4 ();
940
  Ipv4Address receiver = m_socketAddresses[socket].GetLocal ();
1001
  Ipv4Address receiver;
1002
1003
  if (m_socketAddresses.find (socket) != m_socketAddresses.end ())
1004
    {
1005
      receiver = m_socketAddresses[socket].GetLocal ();
1006
    }
1007
  else if(m_socketUnicastAddresses.find (socket) != m_socketUnicastAddresses.end ())
1008
    {
1009
      receiver = m_socketUnicastAddresses[socket].GetLocal ();
1010
    }
1011
  else
1012
    {
1013
      NS_ASSERT_MSG (false, "Received a packet from an unknown socket");
1014
    }
941
  NS_LOG_DEBUG ("AODV node " << this << " received a AODV packet from " << sender << " to " << receiver);
1015
  NS_LOG_DEBUG ("AODV node " << this << " received a AODV packet from " << sender << " to " << receiver);
942
1016
943
  UpdateRouteToNeighbor (sender, receiver);
1017
  UpdateRouteToNeighbor (sender, receiver);
 Lines 1832-1836    Link Here 
1832
  return socket;
1906
  return socket;
1833
}
1907
}
1834
1908
1909
Ptr<Socket>
1910
RoutingProtocol::FindUnicastSocketWithInterfaceAddress (Ipv4InterfaceAddress addr ) const
1911
{
1912
  NS_LOG_FUNCTION (this << addr);
1913
  for (std::map<Ptr<Socket>, Ipv4InterfaceAddress>::const_iterator j =
1914
         m_socketUnicastAddresses.begin (); j != m_socketUnicastAddresses.end (); ++j)
1915
    {
1916
      Ptr<Socket> socket = j->first;
1917
      Ipv4InterfaceAddress iface = j->second;
1918
      if (iface == addr)
1919
        return socket;
1920
    }
1921
  Ptr<Socket> socket;
1922
  return socket;
1835
}
1923
}
1924
1836
}
1925
}
1926
}
(-)a/src/aodv/model/aodv-routing-protocol.h (-2 / +6 lines)
 Lines 140-147    Link Here 
140
140
141
  /// IP protocol
141
  /// IP protocol
142
  Ptr<Ipv4> m_ipv4;
142
  Ptr<Ipv4> m_ipv4;
143
  /// Raw socket per each IP interface, map socket -> iface address (IP + mask)
143
  /// Raw subnet directed broadcasts socket per each IP interface, map socket -> iface address (IP + mask)
144
  std::map< Ptr<Socket>, Ipv4InterfaceAddress > m_socketAddresses;
144
  std::map< Ptr<Socket>, Ipv4InterfaceAddress > m_socketAddresses;
145
  /// Raw unicast socket per each IP interface, map socket -> iface address (IP + mask)
146
  std::map< Ptr<Socket>, Ipv4InterfaceAddress > m_socketUnicastAddresses;
145
  /// Loopback device used to defer RREQ until packet will be fully formed
147
  /// Loopback device used to defer RREQ until packet will be fully formed
146
  Ptr<NetDevice> m_lo; 
148
  Ptr<NetDevice> m_lo; 
147
149
 Lines 191-198    Link Here 
191
  void UpdateRouteToNeighbor (Ipv4Address sender, Ipv4Address receiver);
193
  void UpdateRouteToNeighbor (Ipv4Address sender, Ipv4Address receiver);
192
  /// Check that packet is send from own interface
194
  /// Check that packet is send from own interface
193
  bool IsMyOwnAddress (Ipv4Address src);
195
  bool IsMyOwnAddress (Ipv4Address src);
194
  /// Find socket with local interface address iface
196
  /// Find subnet broadcast socket with local interface address iface
195
  Ptr<Socket> FindSocketWithInterfaceAddress (Ipv4InterfaceAddress iface) const;
197
  Ptr<Socket> FindSocketWithInterfaceAddress (Ipv4InterfaceAddress iface) const;
198
  /// Find unicast socket with local interface address iface
199
  Ptr<Socket> FindUnicastSocketWithInterfaceAddress (Ipv4InterfaceAddress iface) const;
196
  /// Process hello message
200
  /// Process hello message
197
  void ProcessHello (RrepHeader const & rrepHeader, Ipv4Address receiverIfaceAddr);
201
  void ProcessHello (RrepHeader const & rrepHeader, Ipv4Address receiverIfaceAddr);
198
  /// Create loopback route for given header
202
  /// Create loopback route for given header

Return to bug 1911