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