avoid excessive calls to GetObject during topology construction
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Tue, 07 Jul 2009 21:18:01 +0200
changeset 4669 8aaa5e83939e
parent 4668 010500125723
child 4670 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
--- a/src/internet-stack/arp-l3-protocol.cc	Tue Jul 07 16:18:55 2009 +0200
+++ b/src/internet-stack/arp-l3-protocol.cc	Tue Jul 07 21:18:01 2009 +0200
@@ -81,12 +81,15 @@
 void
 ArpL3Protocol::NotifyNewAggregate ()
 {
-  Ptr<Node>node = this->GetObject<Node> ();
-  //verify that it's a valid node and that
-  //the node was not set before
-  if (node!= 0 && m_node == 0)
+  if (m_node == 0)
     {
-      this->SetNode (node);
+      Ptr<Node>node = this->GetObject<Node> ();
+      //verify that it's a valid node and that
+      //the node was not set before
+      if (node != 0)
+        {
+          this->SetNode (node);
+        }
     }
   Object::NotifyNewAggregate ();
 }
--- a/src/internet-stack/icmpv4-l4-protocol.cc	Tue Jul 07 16:18:55 2009 +0200
+++ b/src/internet-stack/icmpv4-l4-protocol.cc	Tue Jul 07 21:18:01 2009 +0200
@@ -50,15 +50,20 @@
 void
 Icmpv4L4Protocol::NotifyNewAggregate ()
 {
-  bool is_not_initialized = (m_node == 0);
-  Ptr<Node>node = this->GetObject<Node> ();
-  Ptr<Ipv4L3Protocol> ipv4 = this->GetObject<Ipv4L3Protocol> ();
-  if (is_not_initialized && node!= 0 && ipv4 != 0)
+  if (m_node == 0)
     {
-      this->SetNode (node);
-      ipv4->Insert (this);
-      Ptr<Ipv4RawSocketFactoryImpl> rawFactory = CreateObject<Ipv4RawSocketFactoryImpl> ();
-      ipv4->AggregateObject (rawFactory);
+      Ptr<Node> node = this->GetObject<Node> ();
+      if (node != 0)
+	{
+	  Ptr<Ipv4L3Protocol> ipv4 = this->GetObject<Ipv4L3Protocol> ();
+	  if (ipv4 != 0)
+	    {
+	      this->SetNode (node);
+	      ipv4->Insert (this);
+	      Ptr<Ipv4RawSocketFactoryImpl> rawFactory = CreateObject<Ipv4RawSocketFactoryImpl> ();
+	      ipv4->AggregateObject (rawFactory);
+	    }
+	}
     }
   Object::NotifyNewAggregate ();
 }
--- a/src/internet-stack/ipv4-l3-protocol.cc	Tue Jul 07 16:18:55 2009 +0200
+++ b/src/internet-stack/ipv4-l3-protocol.cc	Tue Jul 07 21:18:01 2009 +0200
@@ -146,12 +146,15 @@
 void
 Ipv4L3Protocol::NotifyNewAggregate ()
 {
-  Ptr<Node>node = this->GetObject<Node>();
-  // verify that it's a valid node and that
-  // the node has not been set before
-  if (node!= 0 && m_node == 0)
+  if (m_node == 0)
     {
-      this->SetNode (node);
+      Ptr<Node>node = this->GetObject<Node>();
+      // verify that it's a valid node and that
+      // the node has not been set before
+      if (node != 0)
+        {
+          this->SetNode (node);
+        }
     }
   Object::NotifyNewAggregate ();
 }
--- a/src/internet-stack/nsc-tcp-l4-protocol.cc	Tue Jul 07 16:18:55 2009 +0200
+++ b/src/internet-stack/nsc-tcp-l4-protocol.cc	Tue Jul 07 21:18:01 2009 +0200
@@ -164,16 +164,21 @@
 void
 NscTcpL4Protocol::NotifyNewAggregate ()
 { 
-  bool is_not_initialized = (m_node == 0);
-  Ptr<Node>node = this->GetObject<Node> ();
-  Ptr<Ipv4L3Protocol> ipv4 = this->GetObject<Ipv4L3Protocol> ();
-  if (is_not_initialized && node!= 0 && ipv4 != 0)
+  if (m_node == 0)
     {
-      this->SetNode (node);
-      ipv4->Insert (this);
-      Ptr<NscTcpSocketFactoryImpl> tcpFactory = CreateObject<NscTcpSocketFactoryImpl> ();
-      tcpFactory->SetTcp (this);
-      node->AggregateObject (tcpFactory);
+      Ptr<Node>node = this->GetObject<Node> ();
+      if (node != 0)
+        {
+          Ptr<Ipv4L3Protocol> ipv4 = this->GetObject<Ipv4L3Protocol> ();
+          if (ipv4 != 0)
+            {
+              this->SetNode (node);
+              ipv4->Insert (this);
+              Ptr<NscTcpSocketFactoryImpl> tcpFactory = CreateObject<NscTcpSocketFactoryImpl> ();
+              tcpFactory->SetTcp (this);
+              node->AggregateObject (tcpFactory);
+            }
+        }
     }
   Object::NotifyNewAggregate ();
 }
--- a/src/internet-stack/tcp-l4-protocol.cc	Tue Jul 07 16:18:55 2009 +0200
+++ b/src/internet-stack/tcp-l4-protocol.cc	Tue Jul 07 21:18:01 2009 +0200
@@ -366,16 +366,21 @@
 void
 TcpL4Protocol::NotifyNewAggregate ()
 {
-  bool is_not_initialized = (m_node == 0);
-  Ptr<Node>node = this->GetObject<Node> ();
-  Ptr<Ipv4L3Protocol> ipv4 = this->GetObject<Ipv4L3Protocol> ();
-  if (is_not_initialized && node!= 0 && ipv4 != 0)
+  if (m_node == 0)
     {
-      this->SetNode (node);
-      ipv4->Insert (this);
-      Ptr<TcpSocketFactoryImpl> tcpFactory = CreateObject<TcpSocketFactoryImpl> ();
-      tcpFactory->SetTcp (this);
-      node->AggregateObject (tcpFactory);
+      Ptr<Node> node = this->GetObject<Node> ();
+      if (node != 0)
+        {
+          Ptr<Ipv4L3Protocol> ipv4 = this->GetObject<Ipv4L3Protocol> ();
+          if (ipv4 != 0)
+            {
+              this->SetNode (node);
+              ipv4->Insert (this);
+              Ptr<TcpSocketFactoryImpl> tcpFactory = CreateObject<TcpSocketFactoryImpl> ();
+              tcpFactory->SetTcp (this);
+              node->AggregateObject (tcpFactory);
+            }
+        }
     }
   Object::NotifyNewAggregate ();
 }
--- a/src/internet-stack/udp-l4-protocol.cc	Tue Jul 07 16:18:55 2009 +0200
+++ b/src/internet-stack/udp-l4-protocol.cc	Tue Jul 07 21:18:01 2009 +0200
@@ -77,16 +77,21 @@
 void
 UdpL4Protocol::NotifyNewAggregate ()
 {  
-  bool is_not_initialized = (m_node == 0);
-  Ptr<Node>node = this->GetObject<Node> ();
-  Ptr<Ipv4L3Protocol> ipv4 = this->GetObject<Ipv4L3Protocol> ();
-  if (is_not_initialized && node!= 0 && ipv4 != 0)
+  if (m_node == 0)
     {
-      this->SetNode (node);
-      ipv4->Insert (this);
-      Ptr<UdpSocketFactoryImpl> udpFactory = CreateObject<UdpSocketFactoryImpl> ();
-      udpFactory->SetUdp (this);
-      node->AggregateObject (udpFactory);
+      Ptr<Node> node = this->GetObject<Node> ();
+      if (node != 0)
+        {
+          Ptr<Ipv4L3Protocol> ipv4 = this->GetObject<Ipv4L3Protocol> ();
+          if (ipv4 != 0)
+            {
+              this->SetNode (node);
+              ipv4->Insert (this);
+              Ptr<UdpSocketFactoryImpl> udpFactory = CreateObject<UdpSocketFactoryImpl> ();
+              udpFactory->SetUdp (this);
+              node->AggregateObject (udpFactory);
+            }
+        }
     }
   Object::NotifyNewAggregate ();
 }