internet: (fixes #111) Rip and RipNg don't receive unicast packets.
This commit is contained in:
@@ -147,8 +147,12 @@ void Rip::DoInitialize ()
|
||||
socket->BindToNetDevice (m_ipv4->GetNetDevice (i));
|
||||
int ret = socket->Bind (local);
|
||||
NS_ASSERT_MSG (ret == 0, "Bind unsuccessful");
|
||||
|
||||
socket->SetRecvCallback (MakeCallback (&Rip::Receive, this));
|
||||
socket->SetIpRecvTtl (true);
|
||||
m_sendSocketList[socket] = i;
|
||||
socket->SetRecvPktInfo (true);
|
||||
|
||||
m_unicastSocketList[socket] = i;
|
||||
}
|
||||
else if (m_ipv4->GetAddress (i, j).GetScope() == Ipv4InterfaceAddress::GLOBAL)
|
||||
{
|
||||
@@ -157,17 +161,17 @@ void Rip::DoInitialize ()
|
||||
}
|
||||
}
|
||||
|
||||
if (!m_recvSocket)
|
||||
if (!m_multicastRecvSocket)
|
||||
{
|
||||
NS_LOG_LOGIC ("RIP: adding receiving socket");
|
||||
TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory");
|
||||
Ptr<Node> theNode = GetObject<Node> ();
|
||||
m_recvSocket = Socket::CreateSocket (theNode, tid);
|
||||
m_multicastRecvSocket = Socket::CreateSocket (theNode, tid);
|
||||
InetSocketAddress local = InetSocketAddress (RIP_ALL_NODE, RIP_PORT);
|
||||
m_recvSocket->Bind (local);
|
||||
m_recvSocket->SetRecvCallback (MakeCallback (&Rip::Receive, this));
|
||||
m_recvSocket->SetIpRecvTtl (true);
|
||||
m_recvSocket->SetRecvPktInfo (true);
|
||||
m_multicastRecvSocket->Bind (local);
|
||||
m_multicastRecvSocket->SetRecvCallback (MakeCallback (&Rip::Receive, this));
|
||||
m_multicastRecvSocket->SetIpRecvTtl (true);
|
||||
m_multicastRecvSocket->SetRecvPktInfo (true);
|
||||
}
|
||||
|
||||
|
||||
@@ -316,7 +320,7 @@ void Rip::NotifyInterfaceUp (uint32_t i)
|
||||
|
||||
|
||||
bool sendSocketFound = false;
|
||||
for (SocketListI iter = m_sendSocketList.begin (); iter != m_sendSocketList.end (); iter++ )
|
||||
for (SocketListI iter = m_unicastSocketList.begin (); iter != m_unicastSocketList.end (); iter++ )
|
||||
{
|
||||
if (iter->second == i)
|
||||
{
|
||||
@@ -345,26 +349,28 @@ void Rip::NotifyInterfaceUp (uint32_t i)
|
||||
InetSocketAddress local = InetSocketAddress (address.GetLocal (), RIP_PORT);
|
||||
socket->BindToNetDevice (m_ipv4->GetNetDevice (i));
|
||||
socket->Bind (local);
|
||||
socket->SetRecvCallback (MakeCallback (&Rip::Receive, this));
|
||||
socket->SetIpRecvTtl (true);
|
||||
m_sendSocketList[socket] = i;
|
||||
}
|
||||
socket->SetRecvPktInfo (true);
|
||||
m_unicastSocketList[socket] = i;
|
||||
}
|
||||
if (address.GetScope () == Ipv4InterfaceAddress::GLOBAL)
|
||||
{
|
||||
SendTriggeredRouteUpdate ();
|
||||
}
|
||||
}
|
||||
|
||||
if (!m_recvSocket)
|
||||
if (!m_multicastRecvSocket)
|
||||
{
|
||||
NS_LOG_LOGIC ("RIP: adding receiving socket");
|
||||
TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory");
|
||||
Ptr<Node> theNode = GetObject<Node> ();
|
||||
m_recvSocket = Socket::CreateSocket (theNode, tid);
|
||||
m_multicastRecvSocket = Socket::CreateSocket (theNode, tid);
|
||||
InetSocketAddress local = InetSocketAddress (RIP_ALL_NODE, RIP_PORT);
|
||||
m_recvSocket->Bind (local);
|
||||
m_recvSocket->SetRecvCallback (MakeCallback (&Rip::Receive, this));
|
||||
m_recvSocket->SetIpRecvTtl (true);
|
||||
m_recvSocket->SetRecvPktInfo (true);
|
||||
m_multicastRecvSocket->Bind (local);
|
||||
m_multicastRecvSocket->SetRecvCallback (MakeCallback (&Rip::Receive, this));
|
||||
m_multicastRecvSocket->SetIpRecvTtl (true);
|
||||
m_multicastRecvSocket->SetRecvPktInfo (true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -381,14 +387,14 @@ void Rip::NotifyInterfaceDown (uint32_t interface)
|
||||
}
|
||||
}
|
||||
|
||||
for (SocketListI iter = m_sendSocketList.begin (); iter != m_sendSocketList.end (); iter++ )
|
||||
for (SocketListI iter = m_unicastSocketList.begin (); iter != m_unicastSocketList.end (); iter++ )
|
||||
{
|
||||
NS_LOG_INFO ("Checking socket for interface " << interface);
|
||||
if (iter->second == interface)
|
||||
{
|
||||
NS_LOG_INFO ("Removed socket for interface " << interface);
|
||||
iter->first->Close ();
|
||||
m_sendSocketList.erase (iter);
|
||||
m_unicastSocketList.erase (iter);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -555,14 +561,14 @@ void Rip::DoDispose ()
|
||||
m_nextTriggeredUpdate = EventId ();
|
||||
m_nextUnsolicitedUpdate = EventId ();
|
||||
|
||||
for (SocketListI iter = m_sendSocketList.begin (); iter != m_sendSocketList.end (); iter++ )
|
||||
for (SocketListI iter = m_unicastSocketList.begin (); iter != m_unicastSocketList.end (); iter++ )
|
||||
{
|
||||
iter->first->Close ();
|
||||
}
|
||||
m_sendSocketList.clear ();
|
||||
m_unicastSocketList.clear ();
|
||||
|
||||
m_recvSocket->Close ();
|
||||
m_recvSocket = 0;
|
||||
m_multicastRecvSocket->Close ();
|
||||
m_multicastRecvSocket = 0;
|
||||
|
||||
m_ipv4 = 0;
|
||||
|
||||
@@ -714,11 +720,20 @@ void Rip::Receive (Ptr<Socket> socket)
|
||||
Address sender;
|
||||
Ptr<Packet> packet = socket->RecvFrom (sender);
|
||||
InetSocketAddress senderAddr = InetSocketAddress::ConvertFrom (sender);
|
||||
NS_LOG_INFO ("Received " << *packet << " from " << senderAddr);
|
||||
NS_LOG_INFO ("Received " << *packet << " from " << senderAddr.GetIpv4 () << ":" << senderAddr.GetPort ());
|
||||
|
||||
Ipv4Address senderAddress = senderAddr.GetIpv4 ();
|
||||
uint16_t senderPort = senderAddr.GetPort ();
|
||||
|
||||
if (socket == m_multicastRecvSocket)
|
||||
{
|
||||
NS_LOG_LOGIC ("Received a packet from the multicast socket");
|
||||
}
|
||||
else
|
||||
{
|
||||
NS_LOG_LOGIC ("Received a packet from one of the unicast sockets");
|
||||
}
|
||||
|
||||
Ipv4PacketInfoTag interfaceInfo;
|
||||
if (!packet->RemovePacketTag (interfaceInfo))
|
||||
{
|
||||
@@ -748,10 +763,12 @@ void Rip::Receive (Ptr<Socket> socket)
|
||||
|
||||
if (hdr.GetCommand () == RipHeader::RESPONSE)
|
||||
{
|
||||
NS_LOG_LOGIC ("The message is a Response from " << senderAddr.GetIpv4 () << ":" << senderAddr.GetPort ());
|
||||
HandleResponses (hdr, senderAddress, ipInterfaceIndex, hopLimit);
|
||||
}
|
||||
else if (hdr.GetCommand () == RipHeader::REQUEST)
|
||||
{
|
||||
NS_LOG_LOGIC ("The message is a Request from " << senderAddr.GetIpv4 () << ":" << senderAddr.GetPort ());
|
||||
HandleRequests (hdr, senderAddress, senderPort, ipInterfaceIndex, hopLimit);
|
||||
}
|
||||
else
|
||||
@@ -785,7 +802,7 @@ void Rip::HandleRequests (RipHeader requestHdr, Ipv4Address senderAddress, uint1
|
||||
// we use one of the sending sockets, as they're bound to the right interface
|
||||
// and the local address might be used on different interfaces.
|
||||
Ptr<Socket> sendingSocket;
|
||||
for (SocketListI iter = m_sendSocketList.begin (); iter != m_sendSocketList.end (); iter++ )
|
||||
for (SocketListI iter = m_unicastSocketList.begin (); iter != m_unicastSocketList.end (); iter++ )
|
||||
{
|
||||
if (iter->second == incomingInterface)
|
||||
{
|
||||
@@ -918,7 +935,7 @@ void Rip::HandleRequests (RipHeader requestHdr, Ipv4Address senderAddress, uint1
|
||||
}
|
||||
p->AddHeader (hdr);
|
||||
NS_LOG_DEBUG ("SendTo: " << *p);
|
||||
m_recvSocket->SendTo (p, 0, InetSocketAddress (senderAddress, senderPort));
|
||||
m_multicastRecvSocket->SendTo (p, 0, InetSocketAddress (senderAddress, senderPort));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1067,7 +1084,7 @@ void Rip::DoSendRouteUpdate (bool periodic)
|
||||
{
|
||||
NS_LOG_FUNCTION (this << (periodic ? " periodic" : " triggered"));
|
||||
|
||||
for (SocketListI iter = m_sendSocketList.begin (); iter != m_sendSocketList.end (); iter++ )
|
||||
for (SocketListI iter = m_unicastSocketList.begin (); iter != m_unicastSocketList.end (); iter++ )
|
||||
{
|
||||
uint32_t interface = iter->second;
|
||||
|
||||
@@ -1254,7 +1271,7 @@ void Rip::SendRouteRequest ()
|
||||
hdr.AddRte (rte);
|
||||
p->AddHeader (hdr);
|
||||
|
||||
for (SocketListI iter = m_sendSocketList.begin (); iter != m_sendSocketList.end (); iter++ )
|
||||
for (SocketListI iter = m_unicastSocketList.begin (); iter != m_unicastSocketList.end (); iter++ )
|
||||
{
|
||||
uint32_t interface = iter->second;
|
||||
|
||||
|
||||
@@ -389,8 +389,8 @@ private:
|
||||
/// Socket list type const iterator
|
||||
typedef std::map<Ptr<Socket>, uint32_t>::const_iterator SocketListCI;
|
||||
|
||||
SocketList m_sendSocketList; //!< list of sockets for sending (socket, interface index)
|
||||
Ptr<Socket> m_recvSocket; //!< receive socket
|
||||
SocketList m_unicastSocketList; //!< list of sockets for unicast messages (socket, interface index)
|
||||
Ptr<Socket> m_multicastRecvSocket; //!< multicast receive socket
|
||||
|
||||
EventId m_nextUnsolicitedUpdate; //!< Next Unsolicited Update event
|
||||
EventId m_nextTriggeredUpdate; //!< Next Triggered Update event
|
||||
|
||||
@@ -141,9 +141,10 @@ void RipNg::DoInitialize ()
|
||||
socket->BindToNetDevice (m_ipv6->GetNetDevice (i));
|
||||
int ret = socket->Bind (local);
|
||||
NS_ASSERT_MSG (ret == 0, "Bind unsuccessful");
|
||||
socket->ShutdownRecv ();
|
||||
socket->SetRecvCallback (MakeCallback (&RipNg::Receive, this));
|
||||
socket->SetIpv6RecvHopLimit (true);
|
||||
m_sendSocketList[socket] = i;
|
||||
socket->SetRecvPktInfo (true);
|
||||
m_unicastSocketList[socket] = i;
|
||||
}
|
||||
else if (m_ipv6->GetAddress (i, j).GetScope() == Ipv6InterfaceAddress::GLOBAL)
|
||||
{
|
||||
@@ -152,17 +153,17 @@ void RipNg::DoInitialize ()
|
||||
}
|
||||
}
|
||||
|
||||
if (!m_recvSocket)
|
||||
if (!m_multicastRecvSocket)
|
||||
{
|
||||
NS_LOG_LOGIC ("RIPng: adding receiving socket");
|
||||
TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory");
|
||||
Ptr<Node> theNode = GetObject<Node> ();
|
||||
m_recvSocket = Socket::CreateSocket (theNode, tid);
|
||||
m_multicastRecvSocket = Socket::CreateSocket (theNode, tid);
|
||||
Inet6SocketAddress local = Inet6SocketAddress (RIPNG_ALL_NODE, RIPNG_PORT);
|
||||
m_recvSocket->Bind (local);
|
||||
m_recvSocket->SetRecvCallback (MakeCallback (&RipNg::Receive, this));
|
||||
m_recvSocket->SetIpv6RecvHopLimit (true);
|
||||
m_recvSocket->SetRecvPktInfo (true);
|
||||
m_multicastRecvSocket->Bind (local);
|
||||
m_multicastRecvSocket->SetRecvCallback (MakeCallback (&RipNg::Receive, this));
|
||||
m_multicastRecvSocket->SetIpv6RecvHopLimit (true);
|
||||
m_multicastRecvSocket->SetRecvPktInfo (true);
|
||||
}
|
||||
|
||||
|
||||
@@ -287,7 +288,7 @@ void RipNg::NotifyInterfaceUp (uint32_t i)
|
||||
|
||||
|
||||
bool sendSocketFound = false;
|
||||
for (SocketListI iter = m_sendSocketList.begin (); iter != m_sendSocketList.end (); iter++ )
|
||||
for (SocketListI iter = m_unicastSocketList.begin (); iter != m_unicastSocketList.end (); iter++ )
|
||||
{
|
||||
if (iter->second == i)
|
||||
{
|
||||
@@ -316,9 +317,10 @@ void RipNg::NotifyInterfaceUp (uint32_t i)
|
||||
Inet6SocketAddress local = Inet6SocketAddress (address.GetAddress (), RIPNG_PORT);
|
||||
socket->BindToNetDevice (m_ipv6->GetNetDevice (i));
|
||||
socket->Bind (local);
|
||||
socket->ShutdownRecv ();
|
||||
socket->SetRecvCallback (MakeCallback (&RipNg::Receive, this));
|
||||
socket->SetIpv6RecvHopLimit (true);
|
||||
m_sendSocketList[socket] = i;
|
||||
socket->SetRecvPktInfo (true);
|
||||
m_unicastSocketList[socket] = i;
|
||||
}
|
||||
else if (address.GetScope() == Ipv6InterfaceAddress::GLOBAL)
|
||||
{
|
||||
@@ -326,17 +328,17 @@ void RipNg::NotifyInterfaceUp (uint32_t i)
|
||||
}
|
||||
}
|
||||
|
||||
if (!m_recvSocket)
|
||||
if (!m_multicastRecvSocket)
|
||||
{
|
||||
NS_LOG_LOGIC ("RIPng: adding receiving socket");
|
||||
TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory");
|
||||
Ptr<Node> theNode = GetObject<Node> ();
|
||||
m_recvSocket = Socket::CreateSocket (theNode, tid);
|
||||
m_multicastRecvSocket = Socket::CreateSocket (theNode, tid);
|
||||
Inet6SocketAddress local = Inet6SocketAddress (RIPNG_ALL_NODE, RIPNG_PORT);
|
||||
m_recvSocket->Bind (local);
|
||||
m_recvSocket->SetRecvCallback (MakeCallback (&RipNg::Receive, this));
|
||||
m_recvSocket->SetIpv6RecvHopLimit (true);
|
||||
m_recvSocket->SetRecvPktInfo (true);
|
||||
m_multicastRecvSocket->Bind (local);
|
||||
m_multicastRecvSocket->SetRecvCallback (MakeCallback (&RipNg::Receive, this));
|
||||
m_multicastRecvSocket->SetIpv6RecvHopLimit (true);
|
||||
m_multicastRecvSocket->SetRecvPktInfo (true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -353,14 +355,14 @@ void RipNg::NotifyInterfaceDown (uint32_t interface)
|
||||
}
|
||||
}
|
||||
|
||||
for (SocketListI iter = m_sendSocketList.begin (); iter != m_sendSocketList.end (); iter++ )
|
||||
for (SocketListI iter = m_unicastSocketList.begin (); iter != m_unicastSocketList.end (); iter++ )
|
||||
{
|
||||
NS_LOG_INFO ("Checking socket for interface " << interface);
|
||||
if (iter->second == interface)
|
||||
{
|
||||
NS_LOG_INFO ("Removed socket for interface " << interface);
|
||||
iter->first->Close ();
|
||||
m_sendSocketList.erase (iter);
|
||||
m_unicastSocketList.erase (iter);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -538,14 +540,14 @@ void RipNg::DoDispose ()
|
||||
m_nextTriggeredUpdate = EventId ();
|
||||
m_nextUnsolicitedUpdate = EventId ();
|
||||
|
||||
for (SocketListI iter = m_sendSocketList.begin (); iter != m_sendSocketList.end (); iter++ )
|
||||
for (SocketListI iter = m_unicastSocketList.begin (); iter != m_unicastSocketList.end (); iter++ )
|
||||
{
|
||||
iter->first->Close ();
|
||||
}
|
||||
m_sendSocketList.clear ();
|
||||
m_unicastSocketList.clear ();
|
||||
|
||||
m_recvSocket->Close ();
|
||||
m_recvSocket = 0;
|
||||
m_multicastRecvSocket->Close ();
|
||||
m_multicastRecvSocket = 0;
|
||||
|
||||
m_ipv6 = 0;
|
||||
|
||||
@@ -777,7 +779,7 @@ void RipNg::HandleRequests (RipNgHeader requestHdr, Ipv6Address senderAddress, u
|
||||
// we use one of the sending sockets, as they're bound to the right interface
|
||||
// and the local address might be used on different interfaces.
|
||||
Ptr<Socket> sendingSocket;
|
||||
for (SocketListI iter = m_sendSocketList.begin (); iter != m_sendSocketList.end (); iter++ )
|
||||
for (SocketListI iter = m_unicastSocketList.begin (); iter != m_unicastSocketList.end (); iter++ )
|
||||
{
|
||||
if (iter->second == incomingInterface)
|
||||
{
|
||||
@@ -857,7 +859,7 @@ void RipNg::HandleRequests (RipNgHeader requestHdr, Ipv6Address senderAddress, u
|
||||
Ptr<Socket> sendingSocket;
|
||||
if (senderAddress.IsLinkLocal ())
|
||||
{
|
||||
for (SocketListI iter = m_sendSocketList.begin (); iter != m_sendSocketList.end (); iter++ )
|
||||
for (SocketListI iter = m_unicastSocketList.begin (); iter != m_unicastSocketList.end (); iter++ )
|
||||
{
|
||||
if (iter->second == incomingInterface)
|
||||
{
|
||||
@@ -867,7 +869,7 @@ void RipNg::HandleRequests (RipNgHeader requestHdr, Ipv6Address senderAddress, u
|
||||
}
|
||||
else
|
||||
{
|
||||
sendingSocket = m_recvSocket;
|
||||
sendingSocket = m_multicastRecvSocket;
|
||||
}
|
||||
|
||||
Ptr<Packet> p = Create<Packet> ();
|
||||
@@ -1078,7 +1080,7 @@ void RipNg::DoSendRouteUpdate (bool periodic)
|
||||
{
|
||||
NS_LOG_FUNCTION (this << (periodic ? " periodic" : " triggered"));
|
||||
|
||||
for (SocketListI iter = m_sendSocketList.begin (); iter != m_sendSocketList.end (); iter++ )
|
||||
for (SocketListI iter = m_unicastSocketList.begin (); iter != m_unicastSocketList.end (); iter++ )
|
||||
{
|
||||
uint32_t interface = iter->second;
|
||||
|
||||
@@ -1254,7 +1256,7 @@ void RipNg::SendRouteRequest ()
|
||||
hdr.AddRte (rte);
|
||||
p->AddHeader (hdr);
|
||||
|
||||
for (SocketListI iter = m_sendSocketList.begin (); iter != m_sendSocketList.end (); iter++ )
|
||||
for (SocketListI iter = m_unicastSocketList.begin (); iter != m_unicastSocketList.end (); iter++ )
|
||||
{
|
||||
uint32_t interface = iter->second;
|
||||
|
||||
|
||||
@@ -395,8 +395,8 @@ private:
|
||||
/// Socket list type const iterator
|
||||
typedef std::map<Ptr<Socket>, uint32_t>::const_iterator SocketListCI;
|
||||
|
||||
SocketList m_sendSocketList; //!< list of sockets for sending (socket, interface index)
|
||||
Ptr<Socket> m_recvSocket; //!< receive socket
|
||||
SocketList m_unicastSocketList; //!< list of sockets for unicast messages (socket, interface index)
|
||||
Ptr<Socket> m_multicastRecvSocket; //!< multicast receive socket
|
||||
|
||||
EventId m_nextUnsolicitedUpdate; //!< Next Unsolicited Update event
|
||||
EventId m_nextTriggeredUpdate; //!< Next Triggered Update event
|
||||
|
||||
Reference in New Issue
Block a user