This commit is contained in:
Gustavo J. A. M. Carneiro
2007-10-09 13:25:30 +01:00
36 changed files with 171 additions and 35 deletions

View File

@@ -62,7 +62,7 @@ int main (int argc, char* argv[])
//utilize the loops variable to show that it can be read from the command line
if(loops>0)
{
cout<<"You requested "<<loops<<" iterations of a loop";
std::cerr<<"You requested "<<loops<<" iterations of a loop";
for(uint32_t i=0;i<loops;++i)
cout<<"iteration "<<i;
}

View File

@@ -43,6 +43,7 @@ PacketMetadata::DataFreeList::~DataFreeList ()
{
PacketMetadata::Deallocate (*i);
}
PacketMetadata::m_enable = false;
}
void
@@ -643,6 +644,11 @@ PacketMetadata::Create (uint32_t size)
void
PacketMetadata::Recycle (struct PacketMetadata::Data *data)
{
if (!m_enable)
{
PacketMetadata::Deallocate (data);
return;
}
NS_LOG_LOGIC ("recycle size="<<data->m_size<<", list="<<m_freeList.size ());
NS_ASSERT (data->m_count == 0);
if (m_freeList.size () > 1000 ||

View File

@@ -190,7 +190,9 @@ private:
public:
~DataFreeList ();
};
friend DataFreeList::~DataFreeList ();
PacketMetadata ();
void DoAddHeader (uint32_t uid, uint32_t size);
void DoRemoveHeader (uint32_t uid, uint32_t size);

View File

@@ -20,6 +20,7 @@
*/
#include "command-line.h"
#include "ns3/debug.h"
#include <unistd.h>
namespace ns3 {
@@ -109,8 +110,15 @@ CommandLine::Parse (int argc, char *argv[])
std::string name, value;
if (cur == std::string::npos)
{
if (argc == 1)
{
// invalid argument. ignore it.
continue;
}
argv++;
argc--;
name = param;
value = "";
value = *argv;
}
else
{
@@ -124,7 +132,12 @@ CommandLine::Parse (int argc, char *argv[])
DefaultValueBase *item = *i;
if (item->GetName () == name)
{
item->ParseValue (value);
if (!item->ParseValue (value))
{
std::cerr << "Warning: failed to parse command line argument `"
<< name << "' of type '" << item->GetType ()
<< "' with value `" << value << "'." << std::endl;
}
continue;
}
}
@@ -144,3 +157,83 @@ CommandLine::Parse (int argc, char *argv[])
}
}//namespace ns3
#ifdef RUN_SELF_TESTS
#include "test.h"
#include <iostream>
#include <sstream>
namespace ns3 {
class CommandLineTest : public Test
{
public:
CommandLineTest () : Test ("CommandLine") {}
virtual bool RunTests (void)
{
bool result = true;
// redirect stderr temporarily (else warnings appear during unit testing, which is not nice)
std::ostringstream nullout;
std::streambuf *origcerr = std::cerr.rdbuf (nullout.rdbuf ());
{
char *argv[] = {"run-tests", "--loops", "bad-value", NULL};
int argc = sizeof (argv) / sizeof (argv[0]) - 1;
uint32_t loops = 123;
CommandLine::AddArgValue ("loops","a test of the command line", loops);
CommandLine::Parse (argc, argv);
NS_TEST_ASSERT_EQUAL (loops, 123);
}
{
char *argv[] = {"run-tests", "--loops=bad-value", NULL};
int argc = sizeof (argv) / sizeof (argv[0]) - 1;
uint32_t loops = 123;
CommandLine::AddArgValue ("loops","a test of the command line", loops);
CommandLine::Parse (argc, argv);
NS_TEST_ASSERT_EQUAL (loops, 123);
}
{
char *argv[] = {"run-tests", "--loops", "456", NULL};
int argc = sizeof (argv) / sizeof (argv[0]) - 1;
uint32_t loops = 123;
CommandLine::AddArgValue ("loops","a test of the command line", loops);
CommandLine::Parse (argc, argv);
NS_TEST_ASSERT_EQUAL (loops, 456);
}
{
char *argv[] = {"run-tests", "--loops=456", NULL};
int argc = sizeof (argv) / sizeof (argv[0]) - 1;
uint32_t loops = 123;
CommandLine::AddArgValue ("loops","a test of the command line", loops);
CommandLine::Parse (argc, argv);
NS_TEST_ASSERT_EQUAL (loops, 456);
}
// unredirect cerr
std::cerr.rdbuf (origcerr);
return result;
}
};
static CommandLineTest g_commandLineTests;
}//namespace ns3
#endif /* RUN_SELF_TESTS */

View File

@@ -123,14 +123,18 @@ CommandLine::UserDefaultValue<T>::DoParseValue (const std::string &value)
iss.str (value);
T v;
iss >> v;
*m_valuePtr = v;
return !iss.bad () && !iss.fail ();
bool ok = (!iss.bad () && !iss.fail ());
if (ok)
{
*m_valuePtr = v;
}
return ok;
}
template <typename T>
std::string
CommandLine::UserDefaultValue<T>::DoGetType (void) const
{
return "";
return TypeNameGet<T> ();
}
template <typename T>
std::string

View File

@@ -97,6 +97,21 @@ class DefaultValueList
static Iterator End (void);
static void Remove (const std::string &name);
static void Add (DefaultValueBase *defaultValue);
template <typename T>
static const T* Get (const std::string &name)
{
for (Iterator iter = Begin (); iter != End (); iter++)
{
const DefaultValueBase *value = *iter;
if (value->GetName () == name)
{
return dynamic_cast<const T*> (value);
}
}
return NULL;
}
private:
typedef std::list<DefaultValueBase *> List;
static List *GetList (void);

View File

@@ -352,6 +352,11 @@ operator != (Ptr<T1> const &lhs, Ptr<T2> const &rhs)
return PeekPointer (lhs) != PeekPointer (rhs);
}
template <typename T>
bool operator < (const Ptr<T> &lhs, const Ptr<T> &rhs)
{
return PeekPointer<T> (lhs) < PeekPointer<T> (rhs);
}
template <typename T1, typename T2>
Ptr<T1>

View File

@@ -1,7 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2005 INRIA
* 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

View File

@@ -1,7 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2005 INRIA
* 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

View File

@@ -1,7 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2005 INRIA
* 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

View File

@@ -1,7 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2005,2006 INRIA
* 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

View File

@@ -1,7 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2006 INRIA
* 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

View File

@@ -1,7 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2006 INRIA
* 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

View File

@@ -1,7 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2006 INRIA
* 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

View File

@@ -1,7 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2006 INRIA
* 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

View File

@@ -1,7 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2006 INRIA
* 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

View File

@@ -1,7 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2006 INRIA
* 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

View File

@@ -1,7 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2005,2006 INRIA
* 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

View File

@@ -1,7 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2006 INRIA
* 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

View File

@@ -1,7 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2006 INRIA
* 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

View File

@@ -2,7 +2,6 @@
/*
* Copyright (c) 2006 INRIA
* Copyright (c) 2005 Mathieu Lacage
* 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
@@ -20,7 +19,7 @@
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
*
* This code started as a c++ translation of a java-based code written in 2005
* to implement a heap sort. Which explains the Copyright Mathieu Lacage at the
* to implement a heap sort. Which explains the "Copyright Mathieu Lacage" at the
* top of this file.
*
* What is smart about this code ?

View File

@@ -1,7 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2005 INRIA
* 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

View File

@@ -1,7 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2005 INRIA
* 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

View File

@@ -1,7 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2005 INRIA
* 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

View File

@@ -1,7 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2006 INRIA
* 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

View File

@@ -1,7 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2006 INRIA
* 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

View File

@@ -1,7 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2006 INRIA
* 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

View File

@@ -1,7 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2005 INRIA
* 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

View File

@@ -1,7 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2007 INRIA
* 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

View File

@@ -1,7 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2005,2006 INRIA
* 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

View File

@@ -1,7 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2005 INRIA
* 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

View File

@@ -1,7 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2007 INRIA
* 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

View File

@@ -1,7 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2007 INRIA
* 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

View File

@@ -2,7 +2,6 @@
/*
* Copyright (c) 2005,2006 INRIA
* Copyright (c) 2007 Emmanuelle Laprise
* 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

View File

@@ -1,3 +1,22 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2005,2007 INRIA
*
* 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
*/
#include "timer.h"
#include "simulator.h"
#include "simulation-singleton.h"

View File

@@ -1,3 +1,22 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2005,2007 INRIA
*
* 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
*/
#ifndef TIMER_H
#define TIMER_H