From e4dedb226f57cd4a10b268c006814316d6448724 Mon Sep 17 00:00:00 2001 From: "Gustavo J. A. M. Carneiro" Date: Mon, 30 Jul 2007 17:33:12 +0100 Subject: [PATCH] Add a simpler olsr::EnableAllNodes API as suggested by Mathieu. --- examples/simple-p2p-olsr.cc | 16 ++---------- src/routing/olsr/olsr.cc | 52 +++++++++++++++++++++++++++++++++++++ src/routing/olsr/olsr.h | 37 ++++++++++++++++++++++++++ src/routing/olsr/wscript | 2 ++ 4 files changed, 93 insertions(+), 14 deletions(-) create mode 100644 src/routing/olsr/olsr.cc create mode 100644 src/routing/olsr/olsr.h diff --git a/examples/simple-p2p-olsr.cc b/examples/simple-p2p-olsr.cc index 1050f9e42..731b49c32 100644 --- a/examples/simple-p2p-olsr.cc +++ b/examples/simple-p2p-olsr.cc @@ -65,7 +65,7 @@ #include "ns3/onoff-application.h" #include "ns3/debug.h" -#include "ns3/olsr-agent.h" +#include "ns3/olsr.h" using namespace ns3; @@ -138,20 +138,9 @@ int main (int argc, char *argv[]) // Run OLSR in each node. - ComponentManager::Create > - (OlsrAgent::cid, OlsrAgent::iid, n0)->Start (); - - ComponentManager::Create > - (OlsrAgent::cid, OlsrAgent::iid, n1)->Start (); - - ComponentManager::Create > - (OlsrAgent::cid, OlsrAgent::iid, n2)->Start (); - - ComponentManager::Create > - (OlsrAgent::cid, OlsrAgent::iid, n3)->Start (); + olsr::EnableAllNodes (); -#if 1 // Create the OnOff application to send UDP datagrams of size // 210 bytes at a rate of 448 Kb/s Ptr ooff = Create ( @@ -176,7 +165,6 @@ int main (int argc, char *argv[]) // Start the application ooff->Start(Seconds(1.1)); ooff->Stop (Seconds(10.0)); -#endif // Configure tracing of all enqueue, dequeue, and NetDevice receive events // Trace output will be sent to the simple-p2p.tr file diff --git a/src/routing/olsr/olsr.cc b/src/routing/olsr/olsr.cc new file mode 100644 index 000000000..298c65216 --- /dev/null +++ b/src/routing/olsr/olsr.cc @@ -0,0 +1,52 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2007 INESC Porto + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Gustavo J. A. M. Carneiro + */ + +#include "olsr-agent.h" +#include "olsr.h" + +namespace ns3 { namespace olsr { + + +void +EnableAllNodes (void) +{ + EnableNodes (NodeList::Begin (), NodeList::End ()); +} + +void +EnableNodes (NodeList::Iterator begin, NodeList::Iterator end) +{ + for (NodeList::Iterator i = begin; i != end; i++) + { + EnableNode (*i); + } +} + +void +EnableNode (Ptr node) +{ + ComponentManager::Create > + (OlsrAgent::cid, OlsrAgent::iid, node)->Start (); +} + + +}} // namespace ns3, olsr + diff --git a/src/routing/olsr/olsr.h b/src/routing/olsr/olsr.h new file mode 100644 index 000000000..914b4021e --- /dev/null +++ b/src/routing/olsr/olsr.h @@ -0,0 +1,37 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2007 INESC Porto + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Gustavo J. A. M. Carneiro + */ + +#ifndef OLSR_H +#define OLSR_H + +#include "ns3/node-list.h" + +namespace ns3 +{ + namespace olsr + { + void EnableAllNodes (void); + void EnableNodes (NodeList::Iterator begin, NodeList::Iterator end); + void EnableNode (Ptr node); + } +} + +#endif /* OLSR_H */ diff --git a/src/routing/olsr/wscript b/src/routing/olsr/wscript index 8b6b05a22..576af164f 100644 --- a/src/routing/olsr/wscript +++ b/src/routing/olsr/wscript @@ -12,9 +12,11 @@ def build(bld): 'routing-table.cc', 'olsr-agent.cc', 'olsr-agent-impl.cc', + 'olsr.cc', ] headers = bld.create_obj('ns3header') headers.source = [ 'olsr-agent.h', + 'olsr.h', ]