src/helper/olsr-helper.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Fri, 12 Jun 2009 13:44:19 -0700
changeset 4560 2f106fd728ab
parent 4472 e20a31541404
child 4616 a84f60b6cd12
permissions -rw-r--r--
Remove static routing dependencies in code
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2833
f3474fd850b2 add missing license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2702
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
f3474fd850b2 add missing license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2702
diff changeset
     2
/*
f3474fd850b2 add missing license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2702
diff changeset
     3
 * Copyright (c) 2008 INRIA
f3474fd850b2 add missing license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2702
diff changeset
     4
 *
f3474fd850b2 add missing license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2702
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
f3474fd850b2 add missing license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2702
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
f3474fd850b2 add missing license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2702
diff changeset
     7
 * published by the Free Software Foundation;
f3474fd850b2 add missing license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2702
diff changeset
     8
 *
f3474fd850b2 add missing license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2702
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
f3474fd850b2 add missing license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2702
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
f3474fd850b2 add missing license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2702
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
f3474fd850b2 add missing license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2702
diff changeset
    12
 * GNU General Public License for more details.
f3474fd850b2 add missing license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2702
diff changeset
    13
 *
f3474fd850b2 add missing license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2702
diff changeset
    14
 * You should have received a copy of the GNU General Public License
f3474fd850b2 add missing license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2702
diff changeset
    15
 * along with this program; if not, write to the Free Software
f3474fd850b2 add missing license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2702
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
f3474fd850b2 add missing license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2702
diff changeset
    17
 *
f3474fd850b2 add missing license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2702
diff changeset
    18
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
f3474fd850b2 add missing license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2702
diff changeset
    19
 */
2484
d5b05b706999 port Olsr code to attributes/helpers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    20
#include "olsr-helper.h"
4364
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4358
diff changeset
    21
#include "ns3/olsr-routing-protocol.h"
2484
d5b05b706999 port Olsr code to attributes/helpers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    22
#include "ns3/node-list.h"
4147
5d8530130930 rename object-names.{cc,h} to names.{cc,h} per convention
Craig Dowell <craigdo@ee.washington.edu>
parents: 4140
diff changeset
    23
#include "ns3/names.h"
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4364
diff changeset
    24
#include "ns3/ipv4-list-routing.h"
2484
d5b05b706999 port Olsr code to attributes/helpers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    25
d5b05b706999 port Olsr code to attributes/helpers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    26
namespace ns3 {
d5b05b706999 port Olsr code to attributes/helpers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    27
d5b05b706999 port Olsr code to attributes/helpers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    28
OlsrHelper::OlsrHelper ()
d5b05b706999 port Olsr code to attributes/helpers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    29
{
4364
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4358
diff changeset
    30
  m_agentFactory.SetTypeId ("ns3::olsr::RoutingProtocol");
2484
d5b05b706999 port Olsr code to attributes/helpers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    31
}
d5b05b706999 port Olsr code to attributes/helpers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    32
d5b05b706999 port Olsr code to attributes/helpers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    33
void 
d5b05b706999 port Olsr code to attributes/helpers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    34
OlsrHelper::SetAgent (std::string tid,
3786
9f384deadb46 replace \t with 8 spaces.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2997
diff changeset
    35
                      std::string n0, const AttributeValue &v0,
9f384deadb46 replace \t with 8 spaces.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2997
diff changeset
    36
                      std::string n1, const AttributeValue &v1,
9f384deadb46 replace \t with 8 spaces.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2997
diff changeset
    37
                      std::string n2, const AttributeValue &v2,
9f384deadb46 replace \t with 8 spaces.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2997
diff changeset
    38
                      std::string n3, const AttributeValue &v3,
9f384deadb46 replace \t with 8 spaces.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2997
diff changeset
    39
                      std::string n4, const AttributeValue &v4,
9f384deadb46 replace \t with 8 spaces.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2997
diff changeset
    40
                      std::string n5, const AttributeValue &v5,
9f384deadb46 replace \t with 8 spaces.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2997
diff changeset
    41
                      std::string n6, const AttributeValue &v6,
9f384deadb46 replace \t with 8 spaces.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2997
diff changeset
    42
                      std::string n7, const AttributeValue &v7)
2484
d5b05b706999 port Olsr code to attributes/helpers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    43
{
d5b05b706999 port Olsr code to attributes/helpers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    44
  m_agentFactory.SetTypeId (tid);
d5b05b706999 port Olsr code to attributes/helpers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    45
  m_agentFactory.Set (n0, v0);
d5b05b706999 port Olsr code to attributes/helpers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    46
  m_agentFactory.Set (n1, v1);
d5b05b706999 port Olsr code to attributes/helpers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    47
  m_agentFactory.Set (n2, v2);
d5b05b706999 port Olsr code to attributes/helpers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    48
  m_agentFactory.Set (n3, v3);
d5b05b706999 port Olsr code to attributes/helpers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    49
  m_agentFactory.Set (n4, v4);
d5b05b706999 port Olsr code to attributes/helpers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    50
  m_agentFactory.Set (n5, v5);
d5b05b706999 port Olsr code to attributes/helpers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    51
  m_agentFactory.Set (n6, v6);
d5b05b706999 port Olsr code to attributes/helpers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    52
  m_agentFactory.Set (n7, v7);
d5b05b706999 port Olsr code to attributes/helpers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    53
}
d5b05b706999 port Olsr code to attributes/helpers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    54
d5b05b706999 port Olsr code to attributes/helpers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    55
void 
2995
b72805b3ca69 Align helper API use of Install()
Tom Henderson <tomh@tomh.org>
parents: 2834
diff changeset
    56
OlsrHelper::Install (NodeContainer container)
2484
d5b05b706999 port Olsr code to attributes/helpers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    57
{
2702
6800982bef15 do not use templates.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2603
diff changeset
    58
  for (NodeContainer::Iterator i = container.Begin (); i != container.End (); ++i)
6800982bef15 do not use templates.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2603
diff changeset
    59
    {
6800982bef15 do not use templates.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2603
diff changeset
    60
      Ptr<Node> node = *i;
2995
b72805b3ca69 Align helper API use of Install()
Tom Henderson <tomh@tomh.org>
parents: 2834
diff changeset
    61
      Install (node);
2702
6800982bef15 do not use templates.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2603
diff changeset
    62
    }
2484
d5b05b706999 port Olsr code to attributes/helpers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    63
}
d5b05b706999 port Olsr code to attributes/helpers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    64
void 
2995
b72805b3ca69 Align helper API use of Install()
Tom Henderson <tomh@tomh.org>
parents: 2834
diff changeset
    65
OlsrHelper::Install (Ptr<Node> node)
2484
d5b05b706999 port Olsr code to attributes/helpers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    66
{
4364
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4358
diff changeset
    67
  if (node->GetObject<olsr::RoutingProtocol> () != 0)
2995
b72805b3ca69 Align helper API use of Install()
Tom Henderson <tomh@tomh.org>
parents: 2834
diff changeset
    68
    {
b72805b3ca69 Align helper API use of Install()
Tom Henderson <tomh@tomh.org>
parents: 2834
diff changeset
    69
      NS_FATAL_ERROR ("OlsrHelper::Install(): Aggregating "
4364
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4358
diff changeset
    70
         "an Olsr Agent to a node with an existing Olsr RoutingProtocol");
2995
b72805b3ca69 Align helper API use of Install()
Tom Henderson <tomh@tomh.org>
parents: 2834
diff changeset
    71
      return;
b72805b3ca69 Align helper API use of Install()
Tom Henderson <tomh@tomh.org>
parents: 2834
diff changeset
    72
    }
4364
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4358
diff changeset
    73
  Ptr<olsr::RoutingProtocol> agent = m_agentFactory.Create<olsr::RoutingProtocol> ();
4358
e63305078fe5 rework olsr
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4147
diff changeset
    74
  node->AggregateObject (agent);
e63305078fe5 rework olsr
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4147
diff changeset
    75
  Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4364
diff changeset
    76
  Ptr<Ipv4ListRouting> ipv4Routing = DynamicCast<Ipv4ListRouting> (ipv4->GetRoutingProtocol ());
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4364
diff changeset
    77
  NS_ASSERT (ipv4Routing);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4364
diff changeset
    78
  ipv4Routing->AddRoutingProtocol (agent, 10);
2565
d8730df76e9c start the OLSR agent
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2491
diff changeset
    79
  agent->Start ();
2484
d5b05b706999 port Olsr code to attributes/helpers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    80
}
d5b05b706999 port Olsr code to attributes/helpers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    81
void 
4140
6bbf05bf4826 Brute force all of the helpers to use object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3786
diff changeset
    82
OlsrHelper::Install (std::string nodeName)
6bbf05bf4826 Brute force all of the helpers to use object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3786
diff changeset
    83
{
6bbf05bf4826 Brute force all of the helpers to use object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3786
diff changeset
    84
  Ptr<Node> node = Names::Find<Node> (nodeName);
6bbf05bf4826 Brute force all of the helpers to use object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3786
diff changeset
    85
  Install (node);
6bbf05bf4826 Brute force all of the helpers to use object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3786
diff changeset
    86
}
6bbf05bf4826 Brute force all of the helpers to use object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3786
diff changeset
    87
void 
2995
b72805b3ca69 Align helper API use of Install()
Tom Henderson <tomh@tomh.org>
parents: 2834
diff changeset
    88
OlsrHelper::InstallAll (void)
2484
d5b05b706999 port Olsr code to attributes/helpers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    89
{
2995
b72805b3ca69 Align helper API use of Install()
Tom Henderson <tomh@tomh.org>
parents: 2834
diff changeset
    90
  Install (NodeContainer::GetGlobal ());
2484
d5b05b706999 port Olsr code to attributes/helpers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    91
}
d5b05b706999 port Olsr code to attributes/helpers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    92
d5b05b706999 port Olsr code to attributes/helpers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    93
} // namespace ns3