From 5b95df87d62d6f57f505a2a7f61dec6cbe5cb34a Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Wed, 6 May 2020 07:57:30 -0700 Subject: [PATCH] core: Extend object-names example (check for regressions, non-log output) --- examples/naming/object-names.cc | 44 ++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/examples/naming/object-names.cc b/examples/naming/object-names.cc index ce21c68f3..649184277 100644 --- a/examples/naming/object-names.cc +++ b/examples/naming/object-names.cc @@ -21,6 +21,8 @@ // ================= // LAN // +// This program demonstrates some basic use of the Object names capability +// #include "ns3/core-module.h" #include "ns3/csma-module.h" @@ -31,18 +33,19 @@ using namespace ns3; NS_LOG_COMPONENT_DEFINE ("ObjectNamesExample"); +uint32_t bytesReceived = 0; + void RxEvent (std::string context, Ptr packet) { - NS_LOG_INFO (context << " packet " << packet); + std::cout << Simulator::Now ().GetSeconds () << "s " << context << " packet size " << packet->GetSize () << std::endl; + bytesReceived += packet->GetSize (); } int main (int argc, char *argv[]) { -#if 1 - LogComponentEnable ("ObjectNamesExample", LOG_LEVEL_INFO); -#endif + bool outputValidated = true; CommandLine cmd (__FILE__); cmd.Parse (argc, argv); @@ -103,8 +106,23 @@ main (int argc, char *argv[]) // in this case, the "/Names" prefix is always required since the _Config_ // system always expects to see a fully qualified path name. // + + Ptr csmaNetDevice = d.Get (0)->GetObject (); + UintegerValue val; + csmaNetDevice->GetAttribute ("Mtu", val); + std::cout << "MTU on device 0 before configuration is " << val.Get () << std::endl; + Config::Set ("/Names/client/eth0/Mtu", UintegerValue (1234)); + // Check the attribute again + csmaNetDevice->GetAttribute ("Mtu", val); + std::cout << "MTU on device 0 after configuration is " << val.Get () << std::endl; + + if (val.Get () != 1234) + { + outputValidated = false; + } + // // You can mix and match names and Attributes in calls to the Config system. // For example, if "eth0" is a named object, you can get to its parent through @@ -178,6 +196,24 @@ main (int argc, char *argv[]) // csma.EnablePcap ("client-device.pcap", d.Get (0), false, true); + std::cout << "Running simulation..." << std::endl; Simulator::Run (); Simulator::Destroy (); + + // Expected to see ARP exchange and one packet + // 64 bytes (minimum Ethernet frame size) x 2, plus (1024 + 8 + 20 + 18) + if (bytesReceived != (64 + 64 + 1070)) + { + outputValidated = false; + } + + if (outputValidated) + { + exit (0); + } + else + { + std::cerr << "Program internal checking failed; exiting with error" << std::endl; + exit (1); + } }