examples/names.cc
changeset 4151 682a4cae7a5f
parent 4144 c59fdf82869b
child 4152 99e350f3f7b4
equal deleted inserted replaced
4150:682eb88ed29e 4151:682a4cae7a5f
    50   n.Create (4);
    50   n.Create (4);
    51 
    51 
    52   //
    52   //
    53   // We're going to use the zeroth node in the container as the client, and
    53   // We're going to use the zeroth node in the container as the client, and
    54   // the first node as the server.  Add some "human readable" names for these
    54   // the first node as the server.  Add some "human readable" names for these
    55   // nodes.  The first parameter specifies the root of the "/Names" name space
    55   // nodes.  The names below will go into the name system as "/Names/client"
    56   // as the destination, so these will go into the name system as "/Names/client"
    56   // and "/Names/server", but note that the Add function assumes that if you
    57   // and "/Names/server".  
    57   // omit the leading "/Names/" the remaining string is assumed to be rooted
       
    58   // in the "/Names" namespace. The following calls,
    58   //
    59   //
    59   Names::Add ("/Names/client", n.Get (0));
    60   //  Names::Add ("client", n.Get (0));
       
    61   //  Names::Add ("/Names/client", n.Get (0));
       
    62   //
       
    63   // will produce identical results.
       
    64   //
       
    65   Names::Add ("client", n.Get (0));
    60   Names::Add ("/Names/server", n.Get (1));
    66   Names::Add ("/Names/server", n.Get (1));
    61 
    67 
    62   InternetStackHelper internet;
    68   InternetStackHelper internet;
    63   internet.Install (n);
    69   internet.Install (n);
    64 
    70 
    69   NetDeviceContainer d = csma.Install (n);
    75   NetDeviceContainer d = csma.Install (n);
    70 
    76 
    71   //
    77   //
    72   // Add some human readable names for the devices we'll be interested in.
    78   // Add some human readable names for the devices we'll be interested in.
    73   // We add the names to the name space "under" the nodes we created above.
    79   // We add the names to the name space "under" the nodes we created above.
    74   // This has the effect of making "/Names/client/eth0" and "/Names/server/eth0"
    80   // This has the effect of making "/Names/client/eth0" and "/Names/server/eth0".
    75   // Note that the first part of the path must reference a previously named object,
    81   // In this case, we again omit the "/Names/" prefix on one call to illustrate
    76   // and we have, in fact, already named objects "/Names/client" and
    82   // the shortcut.
    77   // "/Names/server"
       
    78   //
    83   //
    79   Names::Add ("/Names/client/eth0", d.Get (0));
    84   Names::Add ("/Names/client/eth0", d.Get (0));
    80   Names::Add ("/Names/server/eth0", d.Get (1));
    85   Names::Add ("server/eth0", d.Get (1));
    81 
    86 
    82   //
    87   //
    83   // You can use the object names that you've assigned in calls to the Config
    88   // You can use the object names that you've assigned in calls to the Config
    84   // system to set Object Attributes.  For example, you can set the Mtu 
    89   // system to set Object Attributes.  For example, you can set the Mtu 
    85   // Attribute of a Csma devices using the object naming service.
    90   // Attribute of a Csma devices using the object naming service.
   125   apps.Start (Seconds (2.0));
   130   apps.Start (Seconds (2.0));
   126   apps.Stop (Seconds (10.0));
   131   apps.Stop (Seconds (10.0));
   127 
   132 
   128   //
   133   //
   129   // Use the Config system to connect a trace source using the object name
   134   // Use the Config system to connect a trace source using the object name
   130   // service to specify the path.
   135   // service to specify the path.  Note that in this case, the "/Names"
       
   136   // prefix is always required since the _Config_ system always expects to 
       
   137   // see a fully qualified path name 
   131   //
   138   //
   132   Config::Connect ("/Names/client/eth0/Rx", MakeCallback (&RxEvent));
   139   Config::Connect ("/Names/client/eth0/Rx", MakeCallback (&RxEvent));
   133 
   140 
   134   Simulator::Run ();
   141   Simulator::Run ();
   135   Simulator::Destroy ();
   142   Simulator::Destroy ();