avoid excessive calls to GetObject during topology construction
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Tue Jul 07 21:18:01 2009 +0200 (7 months ago)
changeset 46898aaa5e83939e
parent 4688 010500125723
child 4690 98aac83e4416
avoid excessive calls to GetObject during topology construction
src/internet-stack/arp-l3-protocol.cc
src/internet-stack/icmpv4-l4-protocol.cc
src/internet-stack/ipv4-l3-protocol.cc
src/internet-stack/nsc-tcp-l4-protocol.cc
src/internet-stack/tcp-l4-protocol.cc
src/internet-stack/udp-l4-protocol.cc
     1.1 --- a/src/internet-stack/arp-l3-protocol.cc	Tue Jul 07 16:18:55 2009 +0200
     1.2 +++ b/src/internet-stack/arp-l3-protocol.cc	Tue Jul 07 21:18:01 2009 +0200
     1.3 @@ -81,12 +81,15 @@
     1.4  void
     1.5  ArpL3Protocol::NotifyNewAggregate ()
     1.6  {
     1.7 -  Ptr<Node>node = this->GetObject<Node> ();
     1.8 -  //verify that it's a valid node and that
     1.9 -  //the node was not set before
    1.10 -  if (node!= 0 && m_node == 0)
    1.11 +  if (m_node == 0)
    1.12      {
    1.13 -      this->SetNode (node);
    1.14 +      Ptr<Node>node = this->GetObject<Node> ();
    1.15 +      //verify that it's a valid node and that
    1.16 +      //the node was not set before
    1.17 +      if (node != 0)
    1.18 +        {
    1.19 +          this->SetNode (node);
    1.20 +        }
    1.21      }
    1.22    Object::NotifyNewAggregate ();
    1.23  }
     2.1 --- a/src/internet-stack/icmpv4-l4-protocol.cc	Tue Jul 07 16:18:55 2009 +0200
     2.2 +++ b/src/internet-stack/icmpv4-l4-protocol.cc	Tue Jul 07 21:18:01 2009 +0200
     2.3 @@ -50,15 +50,20 @@
     2.4  void
     2.5  Icmpv4L4Protocol::NotifyNewAggregate ()
     2.6  {
     2.7 -  bool is_not_initialized = (m_node == 0);
     2.8 -  Ptr<Node>node = this->GetObject<Node> ();
     2.9 -  Ptr<Ipv4L3Protocol> ipv4 = this->GetObject<Ipv4L3Protocol> ();
    2.10 -  if (is_not_initialized && node!= 0 && ipv4 != 0)
    2.11 +  if (m_node == 0)
    2.12      {
    2.13 -      this->SetNode (node);
    2.14 -      ipv4->Insert (this);
    2.15 -      Ptr<Ipv4RawSocketFactoryImpl> rawFactory = CreateObject<Ipv4RawSocketFactoryImpl> ();
    2.16 -      ipv4->AggregateObject (rawFactory);
    2.17 +      Ptr<Node> node = this->GetObject<Node> ();
    2.18 +      if (node != 0)
    2.19 +	{
    2.20 +	  Ptr<Ipv4L3Protocol> ipv4 = this->GetObject<Ipv4L3Protocol> ();
    2.21 +	  if (ipv4 != 0)
    2.22 +	    {
    2.23 +	      this->SetNode (node);
    2.24 +	      ipv4->Insert (this);
    2.25 +	      Ptr<Ipv4RawSocketFactoryImpl> rawFactory = CreateObject<Ipv4RawSocketFactoryImpl> ();
    2.26 +	      ipv4->AggregateObject (rawFactory);
    2.27 +	    }
    2.28 +	}
    2.29      }
    2.30    Object::NotifyNewAggregate ();
    2.31  }
     3.1 --- a/src/internet-stack/ipv4-l3-protocol.cc	Tue Jul 07 16:18:55 2009 +0200
     3.2 +++ b/src/internet-stack/ipv4-l3-protocol.cc	Tue Jul 07 21:18:01 2009 +0200
     3.3 @@ -146,12 +146,15 @@
     3.4  void
     3.5  Ipv4L3Protocol::NotifyNewAggregate ()
     3.6  {
     3.7 -  Ptr<Node>node = this->GetObject<Node>();
     3.8 -  // verify that it's a valid node and that
     3.9 -  // the node has not been set before
    3.10 -  if (node!= 0 && m_node == 0)
    3.11 +  if (m_node == 0)
    3.12      {
    3.13 -      this->SetNode (node);
    3.14 +      Ptr<Node>node = this->GetObject<Node>();
    3.15 +      // verify that it's a valid node and that
    3.16 +      // the node has not been set before
    3.17 +      if (node != 0)
    3.18 +        {
    3.19 +          this->SetNode (node);
    3.20 +        }
    3.21      }
    3.22    Object::NotifyNewAggregate ();
    3.23  }
     4.1 --- a/src/internet-stack/nsc-tcp-l4-protocol.cc	Tue Jul 07 16:18:55 2009 +0200
     4.2 +++ b/src/internet-stack/nsc-tcp-l4-protocol.cc	Tue Jul 07 21:18:01 2009 +0200
     4.3 @@ -164,16 +164,21 @@
     4.4  void
     4.5  NscTcpL4Protocol::NotifyNewAggregate ()
     4.6  { 
     4.7 -  bool is_not_initialized = (m_node == 0);
     4.8 -  Ptr<Node>node = this->GetObject<Node> ();
     4.9 -  Ptr<Ipv4L3Protocol> ipv4 = this->GetObject<Ipv4L3Protocol> ();
    4.10 -  if (is_not_initialized && node!= 0 && ipv4 != 0)
    4.11 +  if (m_node == 0)
    4.12      {
    4.13 -      this->SetNode (node);
    4.14 -      ipv4->Insert (this);
    4.15 -      Ptr<NscTcpSocketFactoryImpl> tcpFactory = CreateObject<NscTcpSocketFactoryImpl> ();
    4.16 -      tcpFactory->SetTcp (this);
    4.17 -      node->AggregateObject (tcpFactory);
    4.18 +      Ptr<Node>node = this->GetObject<Node> ();
    4.19 +      if (node != 0)
    4.20 +        {
    4.21 +          Ptr<Ipv4L3Protocol> ipv4 = this->GetObject<Ipv4L3Protocol> ();
    4.22 +          if (ipv4 != 0)
    4.23 +            {
    4.24 +              this->SetNode (node);
    4.25 +              ipv4->Insert (this);
    4.26 +              Ptr<NscTcpSocketFactoryImpl> tcpFactory = CreateObject<NscTcpSocketFactoryImpl> ();
    4.27 +              tcpFactory->SetTcp (this);
    4.28 +              node->AggregateObject (tcpFactory);
    4.29 +            }
    4.30 +        }
    4.31      }
    4.32    Object::NotifyNewAggregate ();
    4.33  }
     5.1 --- a/src/internet-stack/tcp-l4-protocol.cc	Tue Jul 07 16:18:55 2009 +0200
     5.2 +++ b/src/internet-stack/tcp-l4-protocol.cc	Tue Jul 07 21:18:01 2009 +0200
     5.3 @@ -366,16 +366,21 @@
     5.4  void
     5.5  TcpL4Protocol::NotifyNewAggregate ()
     5.6  {
     5.7 -  bool is_not_initialized = (m_node == 0);
     5.8 -  Ptr<Node>node = this->GetObject<Node> ();
     5.9 -  Ptr<Ipv4L3Protocol> ipv4 = this->GetObject<Ipv4L3Protocol> ();
    5.10 -  if (is_not_initialized && node!= 0 && ipv4 != 0)
    5.11 +  if (m_node == 0)
    5.12      {
    5.13 -      this->SetNode (node);
    5.14 -      ipv4->Insert (this);
    5.15 -      Ptr<TcpSocketFactoryImpl> tcpFactory = CreateObject<TcpSocketFactoryImpl> ();
    5.16 -      tcpFactory->SetTcp (this);
    5.17 -      node->AggregateObject (tcpFactory);
    5.18 +      Ptr<Node> node = this->GetObject<Node> ();
    5.19 +      if (node != 0)
    5.20 +        {
    5.21 +          Ptr<Ipv4L3Protocol> ipv4 = this->GetObject<Ipv4L3Protocol> ();
    5.22 +          if (ipv4 != 0)
    5.23 +            {
    5.24 +              this->SetNode (node);
    5.25 +              ipv4->Insert (this);
    5.26 +              Ptr<TcpSocketFactoryImpl> tcpFactory = CreateObject<TcpSocketFactoryImpl> ();
    5.27 +              tcpFactory->SetTcp (this);
    5.28 +              node->AggregateObject (tcpFactory);
    5.29 +            }
    5.30 +        }
    5.31      }
    5.32    Object::NotifyNewAggregate ();
    5.33  }
     6.1 --- a/src/internet-stack/udp-l4-protocol.cc	Tue Jul 07 16:18:55 2009 +0200
     6.2 +++ b/src/internet-stack/udp-l4-protocol.cc	Tue Jul 07 21:18:01 2009 +0200
     6.3 @@ -77,16 +77,21 @@
     6.4  void
     6.5  UdpL4Protocol::NotifyNewAggregate ()
     6.6  {  
     6.7 -  bool is_not_initialized = (m_node == 0);
     6.8 -  Ptr<Node>node = this->GetObject<Node> ();
     6.9 -  Ptr<Ipv4L3Protocol> ipv4 = this->GetObject<Ipv4L3Protocol> ();
    6.10 -  if (is_not_initialized && node!= 0 && ipv4 != 0)
    6.11 +  if (m_node == 0)
    6.12      {
    6.13 -      this->SetNode (node);
    6.14 -      ipv4->Insert (this);
    6.15 -      Ptr<UdpSocketFactoryImpl> udpFactory = CreateObject<UdpSocketFactoryImpl> ();
    6.16 -      udpFactory->SetUdp (this);
    6.17 -      node->AggregateObject (udpFactory);
    6.18 +      Ptr<Node> node = this->GetObject<Node> ();
    6.19 +      if (node != 0)
    6.20 +        {
    6.21 +          Ptr<Ipv4L3Protocol> ipv4 = this->GetObject<Ipv4L3Protocol> ();
    6.22 +          if (ipv4 != 0)
    6.23 +            {
    6.24 +              this->SetNode (node);
    6.25 +              ipv4->Insert (this);
    6.26 +              Ptr<UdpSocketFactoryImpl> udpFactory = CreateObject<UdpSocketFactoryImpl> ();
    6.27 +              udpFactory->SetUdp (this);
    6.28 +              node->AggregateObject (udpFactory);
    6.29 +            }
    6.30 +        }
    6.31      }
    6.32    Object::NotifyNewAggregate ();
    6.33  }