From bdf0896c2a7e272dcc79596ecfd76954aad55929 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Mon, 23 Jun 2008 14:15:41 -0700 Subject: [PATCH] add helper code --- doc/howtos/howtos-net-device.h | 69 ++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/doc/howtos/howtos-net-device.h b/doc/howtos/howtos-net-device.h index acd1568fc..00bb016e1 100644 --- a/doc/howtos/howtos-net-device.h +++ b/doc/howtos/howtos-net-device.h @@ -90,4 +90,73 @@ SimpleNetDevice::SetAddress (Mac48Address address) } \endcode +Building a topology with such a device is then a matter of +instanciating a set of SimpleNetDevice objects connected on a shared +SimpleChannel: +\code +NodeContainer nodes; +nodes.Create (10); +Ptr channel = CreateObject (); +for (uint32_t i = 0; i < nodes.GetN (); ++i) + { + CreateSimpleDevice (nodes.Get (i), channel); + } +\endcode + +With the following CreateSimpleDevice function: +\code +static Ptr +CreateSimpleDevice (Ptr node, Ptr channel) +{ + Ptr device = CreateObject (); + device->SetAddress (Mac48Address:Allocate ()); + device->SetChannel (channel); + node->AddDevice (device); + return device; +} +\endcode + +Of course, ultimately, you need to provide a helper class for this new device and channel +to save each user from having to re-implement their own CreateSimpleDevice helper +function: + +\code +class SimpleHelper +{ +public: + NetDeviceContainer Install (NodeContainer nodes, Ptr channel); + NetDeviceContainer Install (NodeContainer nodes); +}; +\endcode + +with the following straightforward implementation, inspired by the CreateSimpleDevice +function defined above: + +\code +NetDeviceContainer +SimpleHelper::Install (NodeContainer nodes, Ptr channel) +{ + NetDeviceContainer devices; + for (NodeContainer::Iterator i = nodes.Begin (); i != nodes.End (); ++i) + { + Ptr dev = CreateObject (); + dev->SetAddress (Mac48Address::Allocate ()); + dev->SetChannel (channel); + (*i)->AddDevice (dev); + devices.Add (dev); + } + return devices; +} +NetDeviceContainer +SimpleHelper::Install (NodeContainer nodes) +{ + return Install (nodes, CreateObject ()); +} +\endcode + +Of course, at some point, this device helper class should also contain a couple of +ascii and pcap tracing helper functions but, since the default SimpleNetDevice +class we used as an example here does not report any trace event, it would +be of little use. + */