tutorial/point-to-point-ipv4-topology.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Wed, 02 Jan 2008 09:09:24 +0100
changeset 2230 9f13ac3291e0
parent 1848 5dfaf1619279
child 2231 a5b898c1ee2c
permissions -rw-r--r--
add CreateObject<> to instanciate subclasses of the Object base class. Replaces Create<>.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1848
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     2
/*
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     3
 * This program is free software; you can redistribute it and/or modify
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     4
 * it under the terms of the GNU General Public License version 2 as
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     5
 * published by the Free Software Foundation;
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     6
 *
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     7
 * This program is distributed in the hope that it will be useful,
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    10
 * GNU General Public License for more details.
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    11
 *
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    12
 * You should have received a copy of the GNU General Public License
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    13
 * along with this program; if not, write to the Free Software
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    15
 */
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    16
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    17
#include "ns3/assert.h"
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    18
#include "ns3/log.h"
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    19
#include "ns3/nstime.h"
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    20
#include "ns3/internet-node.h"
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    21
#include "ns3/ipv4-address.h"
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    22
#include "ns3/ipv4.h"
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    23
#include "ns3/queue.h"
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    24
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    25
#include "ns3/point-to-point-channel.h"
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    26
#include "ns3/point-to-point-net-device.h"
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    27
#include "point-to-point-ipv4-topology.h"
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    28
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    29
namespace ns3 {
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    30
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    31
  Ptr<PointToPointChannel>
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    32
PointToPointIpv4Topology::CreateChannel (
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    33
  const DataRate& bps,
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    34
  const Time& delay)
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    35
{
2230
9f13ac3291e0 add CreateObject<> to instanciate subclasses of the Object base class. Replaces Create<>.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1848
diff changeset
    36
  return CreateObject<PointToPointChannel> (bps, delay);
1848
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    37
}
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    38
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    39
  uint32_t
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    40
PointToPointIpv4Topology::AddNetDevice (
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    41
  Ptr<Node> node,
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    42
  Ptr<PointToPointChannel> channel)
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    43
{
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    44
  NS_ASSERT (channel->GetNDevices () <= 1);
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    45
2230
9f13ac3291e0 add CreateObject<> to instanciate subclasses of the Object base class. Replaces Create<>.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1848
diff changeset
    46
  Ptr<PointToPointNetDevice> nd = CreateObject<PointToPointNetDevice> (node);
1848
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    47
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    48
  Ptr<Queue> q = Queue::CreateDefault ();
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    49
  nd->AddQueue(q);
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    50
  nd->Attach (channel);
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    51
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    52
  return nd->GetIfIndex ();
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    53
}
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    54
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    55
  uint32_t
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    56
PointToPointIpv4Topology::AddAddress (
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    57
  Ptr<Node> node,
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    58
  uint32_t netDeviceNumber,
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    59
  Ipv4Address address,
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    60
  Ipv4Mask mask)
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    61
{
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    62
  Ptr<NetDevice> nd = node->GetDevice(netDeviceNumber);
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    63
  Ptr<Ipv4> ipv4 = node->QueryInterface<Ipv4> (Ipv4::iid);
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    64
  uint32_t ifIndex = ipv4->AddInterface (nd);
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    65
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    66
  ipv4->SetAddress (ifIndex, address);
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    67
  ipv4->SetNetworkMask (ifIndex, mask);
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    68
  ipv4->SetUp (ifIndex);
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    69
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    70
  return ifIndex;
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    71
}
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    72
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    73
} // namespace ns3