implement properly the refcounting rules for the capability getters
parent
e5d10e4bf7
commit
77a1488dd2
|
@ -69,6 +69,7 @@ ArpIpv4Interface::SendTo (Packet p, Ipv4Address dest)
|
|||
{
|
||||
PeekDevice ()->Send (p, hardwareDestination, Ipv4::PROT_NUMBER);
|
||||
}
|
||||
arp->Unref ();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -84,7 +84,9 @@ Arp::FindCache (NetDevice *device)
|
|||
return *i;
|
||||
}
|
||||
}
|
||||
Ipv4Interface *interface = m_node->GetIpv4 ()->FindInterfaceForDevice (device);
|
||||
Ipv4 *ipv4 = m_node->GetIpv4 ();
|
||||
Ipv4Interface *interface = ipv4->FindInterfaceForDevice (device);
|
||||
ipv4->Unref ();
|
||||
ArpCache * cache = new ArpCache (device, interface);
|
||||
NS_ASSERT (device->IsBroadcast ());
|
||||
device->SetLinkChangeCallback (MakeCallback (&ArpCache::Flush, cache));
|
||||
|
|
|
@ -61,15 +61,24 @@ TraceResolver *
|
|||
InternetNode::CreateTraceResolver (TraceContext const &context)
|
||||
{
|
||||
CompositeTraceResolver *resolver = new CompositeTraceResolver (context);
|
||||
Ipv4 *ipv4 = GetIpv4 ();
|
||||
resolver->Add ("ipv4",
|
||||
MakeCallback (&Ipv4::CreateTraceResolver, GetIpv4 ()),
|
||||
MakeCallback (&Ipv4::CreateTraceResolver, ipv4),
|
||||
InternetNode::IPV4);
|
||||
ipv4->Unref ();
|
||||
|
||||
Arp *arp = GetArp ();
|
||||
resolver->Add ("arp",
|
||||
MakeCallback (&Arp::CreateTraceResolver, GetArp ()),
|
||||
MakeCallback (&Arp::CreateTraceResolver, arp),
|
||||
InternetNode::ARP);
|
||||
arp->Unref ();
|
||||
|
||||
Udp *udp = GetUdp ();
|
||||
resolver->Add ("udp",
|
||||
MakeCallback (&Udp::CreateTraceResolver, GetUdp ()),
|
||||
MakeCallback (&Udp::CreateTraceResolver, udp),
|
||||
InternetNode::UDP);
|
||||
udp->Unref ();
|
||||
|
||||
return resolver;
|
||||
}
|
||||
|
||||
|
@ -102,36 +111,45 @@ void InternetNode::Dispose()
|
|||
ApplicationList*
|
||||
InternetNode::GetApplicationList() const
|
||||
{
|
||||
m_applicationList->Ref ();
|
||||
return m_applicationList;
|
||||
}
|
||||
|
||||
L3Demux*
|
||||
InternetNode::GetL3Demux() const
|
||||
{
|
||||
m_l3Demux->Ref ();
|
||||
return m_l3Demux;
|
||||
}
|
||||
|
||||
Ipv4L4Demux*
|
||||
InternetNode::GetIpv4L4Demux() const
|
||||
{
|
||||
m_ipv4L4Demux->Ref ();
|
||||
return m_ipv4L4Demux;
|
||||
}
|
||||
|
||||
Ipv4 *
|
||||
InternetNode::GetIpv4 (void) const
|
||||
{
|
||||
return static_cast<Ipv4*> (m_l3Demux->Lookup (Ipv4::PROT_NUMBER));
|
||||
Ipv4 *ipv4 = static_cast<Ipv4*> (m_l3Demux->PeekProtocol (Ipv4::PROT_NUMBER));
|
||||
ipv4->Ref ();
|
||||
return ipv4;
|
||||
}
|
||||
Udp *
|
||||
InternetNode::GetUdp (void) const
|
||||
{
|
||||
return static_cast<Udp*> (m_ipv4L4Demux->Lookup (Udp::PROT_NUMBER));
|
||||
Udp *udp = static_cast<Udp*> (m_ipv4L4Demux->PeekProtocol (Udp::PROT_NUMBER));
|
||||
udp->Ref ();
|
||||
return udp;
|
||||
}
|
||||
|
||||
Arp *
|
||||
InternetNode::GetArp (void) const
|
||||
{
|
||||
return static_cast<Arp*> (m_l3Demux->Lookup (Arp::PROT_NUMBER));
|
||||
Arp *arp = static_cast<Arp*> (m_l3Demux->PeekProtocol (Arp::PROT_NUMBER));
|
||||
arp->Ref ();
|
||||
return arp;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -143,7 +161,7 @@ InternetNode::DoAddDevice (NetDevice *device) const
|
|||
bool
|
||||
InternetNode::ReceiveFromDevice (NetDevice *device, const Packet &p, uint16_t protocolNumber) const
|
||||
{
|
||||
L3Protocol *target = GetL3Demux()->Lookup(protocolNumber);
|
||||
L3Protocol *target = GetL3Demux()->PeekProtocol (protocolNumber);
|
||||
if (target != 0)
|
||||
{
|
||||
Packet packet = p;
|
||||
|
|
|
@ -91,7 +91,7 @@ Ipv4L4Demux::Insert(const Ipv4L4Protocol&protocol)
|
|||
return copy;
|
||||
}
|
||||
Ipv4L4Protocol*
|
||||
Ipv4L4Demux::Lookup(int protocolNumber)
|
||||
Ipv4L4Demux::PeekProtocol(int protocolNumber)
|
||||
{
|
||||
for (L4List_t::iterator i = m_protocols.begin(); i != m_protocols.end(); ++i)
|
||||
{
|
||||
|
|
|
@ -81,7 +81,7 @@ public:
|
|||
* to forward packets up the stack to the right protocol.
|
||||
* It is also called from InternetNode::GetUdp for example.
|
||||
*/
|
||||
Ipv4L4Protocol* Lookup(int protocolNumber);
|
||||
Ipv4L4Protocol* PeekProtocol(int protocolNumber);
|
||||
/**
|
||||
* \param protocol protocol to remove from this demux.
|
||||
*
|
||||
|
|
|
@ -47,7 +47,9 @@ Ipv4LoopbackInterface::DoCreateTraceResolver (TraceContext const &context)
|
|||
void
|
||||
Ipv4LoopbackInterface::SendTo (Packet packet, Ipv4Address dest)
|
||||
{
|
||||
m_node->GetIpv4 ()->Receive (packet, PeekDevice ());
|
||||
Ipv4 *ipv4 = m_node->GetIpv4 ();
|
||||
ipv4->Receive (packet, PeekDevice ());
|
||||
ipv4->Unref ();
|
||||
}
|
||||
|
||||
}//namespace ns3
|
||||
|
|
|
@ -518,7 +518,9 @@ Ipv4::Forwarding (Packet const &packet, Ipv4Header &ipHeader, NetDevice *device)
|
|||
void
|
||||
Ipv4::ForwardUp (Packet p, Ipv4Header const&ip)
|
||||
{
|
||||
Ipv4L4Protocol *protocol = m_node->GetIpv4L4Demux ()->Lookup (ip.GetProtocol ());
|
||||
Ipv4L4Demux *demux = m_node->GetIpv4L4Demux ();
|
||||
Ipv4L4Protocol *protocol = demux->PeekProtocol (ip.GetProtocol ());
|
||||
demux->Unref ();
|
||||
protocol->Receive (p, ip.GetSource (), ip.GetDestination ());
|
||||
}
|
||||
|
||||
|
|
|
@ -91,7 +91,8 @@ L3Protocol* L3Demux::Insert(const L3Protocol& l3p)
|
|||
return l;
|
||||
}
|
||||
|
||||
L3Protocol* L3Demux::Lookup(int p)
|
||||
L3Protocol*
|
||||
L3Demux::PeekProtocol (int p)
|
||||
{ // Look up a protocol by protocol number
|
||||
L3Map_t::iterator i = m_protocols.find(p);
|
||||
if (i == m_protocols.end()) return 0; // Not found
|
||||
|
|
|
@ -85,7 +85,7 @@ public:
|
|||
* to forward packets up the stack to the right protocol.
|
||||
* It is also called from InternetNode::GetIpv4 for example.
|
||||
*/
|
||||
ns3::L3Protocol* Lookup(int protocolNumber);
|
||||
ns3::L3Protocol* PeekProtocol (int protocolNumber);
|
||||
/**
|
||||
* \param protocol protocol to remove from this demux.
|
||||
*
|
||||
|
|
|
@ -172,7 +172,10 @@ void OnOffApplication::StartApplication() // Called at time specified by Star
|
|||
MakeCallback(&OnOffApplication::ConnectionFailed,
|
||||
this));
|
||||
#endif
|
||||
m_socket = PeekNode ()->GetUdp ()->CreateSocket ();
|
||||
|
||||
Udp *udp = PeekNode ()->GetUdp ();
|
||||
m_socket = udp->CreateSocket ();
|
||||
udp->Unref ();
|
||||
m_socket->Connect (m_peerIP, m_peerPort);
|
||||
}
|
||||
StopApplication(); // Insure no pending event
|
||||
|
|
|
@ -35,6 +35,7 @@ UdpSocket::UdpSocket (Node *node)
|
|||
m_connected (false)
|
||||
{
|
||||
NS_ASSERT (GetUdp () != 0);
|
||||
m_udp = m_node->GetUdp ();
|
||||
m_node->Ref ();
|
||||
}
|
||||
UdpSocket::~UdpSocket ()
|
||||
|
@ -57,6 +58,11 @@ UdpSocket::Destroy (void)
|
|||
m_node = 0;
|
||||
}
|
||||
m_endPoint = 0;
|
||||
if (m_udp != 0)
|
||||
{
|
||||
m_udp->Unref ();
|
||||
m_udp = 0;
|
||||
}
|
||||
}
|
||||
int
|
||||
UdpSocket::FinishBind (void)
|
||||
|
@ -73,25 +79,25 @@ UdpSocket::FinishBind (void)
|
|||
int
|
||||
UdpSocket::Bind (void)
|
||||
{
|
||||
m_endPoint = GetUdp ()->Allocate ();
|
||||
m_endPoint = m_udp->Allocate ();
|
||||
return FinishBind ();
|
||||
}
|
||||
int
|
||||
UdpSocket::Bind (Ipv4Address address)
|
||||
{
|
||||
m_endPoint = GetUdp ()->Allocate (address);
|
||||
m_endPoint = m_udp->Allocate (address);
|
||||
return FinishBind ();
|
||||
}
|
||||
int
|
||||
UdpSocket::Bind (uint16_t port)
|
||||
{
|
||||
m_endPoint = GetUdp ()->Allocate (port);
|
||||
m_endPoint = m_udp->Allocate (port);
|
||||
return FinishBind ();
|
||||
}
|
||||
int
|
||||
UdpSocket::Bind (Ipv4Address address, uint16_t port)
|
||||
{
|
||||
m_endPoint = GetUdp ()->Allocate (address, port);
|
||||
m_endPoint = m_udp->Allocate (address, port);
|
||||
return FinishBind ();
|
||||
}
|
||||
|
||||
|
@ -185,7 +191,7 @@ UdpSocket::DoSendPacketTo (const Packet &p, Ipv4Address daddr, uint16_t dport,
|
|||
m_errno = ESHUTDOWN;
|
||||
return -1;
|
||||
}
|
||||
GetUdp ()->Send (p, m_endPoint->GetLocalAddress (), daddr,
|
||||
m_udp->Send (p, m_endPoint->GetLocalAddress (), daddr,
|
||||
m_endPoint->GetLocalPort (), dport);
|
||||
if (!dataSent.IsNull ())
|
||||
{
|
||||
|
@ -245,11 +251,4 @@ UdpSocket::ForwardUp (const Packet &packet, Ipv4Address saddr, uint16_t sport)
|
|||
}
|
||||
}
|
||||
|
||||
Udp *
|
||||
UdpSocket::GetUdp (void) const
|
||||
{
|
||||
return m_node->GetUdp ();
|
||||
}
|
||||
|
||||
|
||||
}//namespace ns3
|
||||
|
|
|
@ -83,6 +83,7 @@ private:
|
|||
|
||||
Ipv4EndPoint *m_endPoint;
|
||||
Node *m_node;
|
||||
Udp *m_udp;
|
||||
Ipv4Address m_defaultAddress;
|
||||
uint16_t m_defaultPort;
|
||||
Callback<void,Socket*,uint32_t,const Ipv4Address &,uint16_t> m_dummyRxCallback;
|
||||
|
|
|
@ -146,6 +146,7 @@ Udp::Send (Packet packet,
|
|||
if (ipv4 != 0)
|
||||
{
|
||||
ipv4->Send (packet, saddr, daddr, PROT_NUMBER);
|
||||
ipv4->Unref ();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue