Skip to content

Commit 98b32cd

Browse files
author
LUNET\cowh4
committed
source code added
0 parents  commit 98b32cd

14 files changed

+2767
-0
lines changed

helper/vm-helper.cc

+119
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2+
/*
3+
* Copyright (c) 2008 INRIA
4+
*
5+
* This program is free software; you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License version 2 as
7+
* published by the Free Software Foundation;
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17+
*
18+
* Author: Mathieu Lacage <[email protected]>
19+
*/
20+
#include "vm-helper.h"
21+
#include "ns3/inet-socket-address.h"
22+
#include "ns3/packet-socket-address.h"
23+
#include "ns3/string.h"
24+
#include "ns3/data-rate.h"
25+
#include "ns3/uinteger.h"
26+
#include "ns3/names.h"
27+
#include "ns3/random-variable-stream.h"
28+
#include "ns3/vm.h"
29+
30+
namespace ns3 {
31+
32+
VmHelper::VmHelper (std::string protocol, Address address)
33+
{
34+
m_factory.SetTypeId ("ns3::VM");
35+
m_factory.Set ("Protocol", StringValue (protocol));
36+
m_factory.Set ("Remote", AddressValue (address));
37+
}
38+
39+
void
40+
VmHelper::SetAttribute (std::string name, const AttributeValue &value)
41+
{
42+
m_factory.Set (name, value);
43+
}
44+
45+
ApplicationContainer
46+
VmHelper::Install (Ptr<Node> node) const
47+
{
48+
return ApplicationContainer (InstallPriv (node));
49+
}
50+
51+
ApplicationContainer
52+
VmHelper::Install (std::string nodeName) const
53+
{
54+
Ptr<Node> node = Names::Find<Node> (nodeName);
55+
return ApplicationContainer (InstallPriv (node));
56+
}
57+
58+
ApplicationContainer
59+
VmHelper::Install (NodeContainer c) const
60+
{
61+
ApplicationContainer apps;
62+
for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
63+
{
64+
apps.Add (InstallPriv (*i));
65+
}
66+
67+
return apps;
68+
}
69+
70+
Ptr<Application>
71+
VmHelper::InstallPriv (Ptr<Node> node) const
72+
{
73+
Ptr<Application> app = m_factory.Create<Application> ();
74+
node->AddApplication (app);
75+
76+
return app;
77+
}
78+
79+
int64_t
80+
VmHelper::AssignStreams (NodeContainer c, int64_t stream)
81+
{
82+
int64_t currentStream = stream;
83+
Ptr<Node> node;
84+
for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
85+
{
86+
node = (*i);
87+
for (uint32_t j = 0; j < node->GetNApplications (); j++)
88+
{
89+
Ptr<VM> onoff = DynamicCast<VM> (node->GetApplication (j));
90+
if (onoff)
91+
{
92+
currentStream += onoff->AssignStreams (currentStream);
93+
}
94+
}
95+
}
96+
return (currentStream - stream);
97+
}
98+
99+
void
100+
VmHelper::SetConstantRate (DataRate dataRate, uint32_t packetSize)
101+
{
102+
m_factory.Set ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1000]"));
103+
m_factory.Set ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]"));
104+
m_factory.Set ("DataRate", DataRateValue (dataRate));
105+
m_factory.Set ("PacketSize", UintegerValue (packetSize));
106+
}
107+
108+
Ptr<VM>
109+
VmHelper::InstallOnServer (Ptr<Node> node) const
110+
{
111+
Ptr<VM> app = m_factory.Create<VM> ();
112+
node->AddApplication (app);
113+
114+
return app;
115+
}
116+
117+
118+
119+
} // namespace ns3

helper/vm-helper.h

+135
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2+
/*
3+
* Copyright (c) 2008 INRIA
4+
*
5+
* This program is free software; you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License version 2 as
7+
* published by the Free Software Foundation;
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17+
*
18+
* Author: Mathieu Lacage <[email protected]>
19+
*/
20+
#ifndef VM_HELPER_H
21+
#define VM_HELPER_H
22+
23+
#include <stdint.h>
24+
#include <string>
25+
#include "ns3/object-factory.h"
26+
#include "ns3/address.h"
27+
#include "ns3/attribute.h"
28+
#include "ns3/net-device.h"
29+
#include "ns3/node-container.h"
30+
#include "ns3/application-container.h"
31+
#include "ns3/vm.h"
32+
33+
namespace ns3 {
34+
35+
class DataRate;
36+
37+
/**
38+
* \brief A helper to make it easier to instantiate an ns3::OnOffApplication
39+
* on a set of nodes.
40+
*/
41+
class VmHelper
42+
{
43+
public:
44+
/**
45+
* Create an VmHelper to make it easier to work with OnOffApplications
46+
*
47+
* \param protocol the name of the protocol to use to send traffic
48+
* by the applications. This string identifies the socket
49+
* factory type used to create sockets for the applications.
50+
* A typical value would be ns3::UdpSocketFactory.
51+
* \param address the address of the remote node to send traffic
52+
* to.
53+
*/
54+
VmHelper (std::string protocol, Address address);
55+
56+
/**
57+
* Helper function used to set the underlying application attributes.
58+
*
59+
* \param name the name of the application attribute to set
60+
* \param value the value of the application attribute to set
61+
*/
62+
void SetAttribute (std::string name, const AttributeValue &value);
63+
64+
/**
65+
* Helper function to set a constant rate source. Equivalent to
66+
* setting the attributes OnTime to constant 1000 seconds, OffTime to
67+
* constant 0 seconds, and the DataRate and PacketSize set accordingly
68+
*
69+
* \param dataRate DataRate object for the sending rate
70+
* \param packetSize size in bytes of the packet payloads generated
71+
*/
72+
void SetConstantRate (DataRate dataRate, uint32_t packetSize = 512);
73+
74+
/**
75+
* Install an ns3::OnOffApplication on each node of the input container
76+
* configured with all the attributes set with SetAttribute.
77+
*
78+
* \param c NodeContainer of the set of nodes on which an OnOffApplication
79+
* will be installed.
80+
* \returns Container of Ptr to the applications installed.
81+
*/
82+
ApplicationContainer Install (NodeContainer c) const;
83+
84+
/**
85+
* Install an ns3::OnOffApplication on the node configured with all the
86+
* attributes set with SetAttribute.
87+
*
88+
* \param node The node on which an OnOffApplication will be installed.
89+
* \returns Container of Ptr to the applications installed.
90+
*/
91+
ApplicationContainer Install (Ptr<Node> node) const;
92+
93+
Ptr<VM> InstallOnServer (Ptr<Node> node) const;
94+
95+
/**
96+
* Install an ns3::OnOffApplication on the node configured with all the
97+
* attributes set with SetAttribute.
98+
*
99+
* \param nodeName The node on which an OnOffApplication will be installed.
100+
* \returns Container of Ptr to the applications installed.
101+
*/
102+
ApplicationContainer Install (std::string nodeName) const;
103+
104+
/**
105+
* Assign a fixed random variable stream number to the random variables
106+
* used by this model. Return the number of streams (possibly zero) that
107+
* have been assigned. The Install() method should have previously been
108+
* called by the user.
109+
*
110+
* \param stream first stream index to use
111+
* \param c NodeContainer of the set of nodes for which the OnOffApplication
112+
* should be modified to use a fixed stream
113+
* \return the number of stream indices assigned by this helper
114+
*/
115+
int64_t AssignStreams (NodeContainer c, int64_t stream);
116+
117+
private:
118+
/**
119+
* \internal
120+
* Install an ns3::OnOffApplication on the node configured with all the
121+
* attributes set with SetAttribute.
122+
*
123+
* \param node The node on which an OnOffApplication will be installed.
124+
* \returns Ptr to the application installed.
125+
*/
126+
Ptr<Application> InstallPriv (Ptr<Node> node) const;
127+
std::string m_protocol;
128+
Address m_remote;
129+
ObjectFactory m_factory;
130+
};
131+
132+
} // namespace ns3
133+
134+
#endif /* VM_HELPER_H */
135+

0 commit comments

Comments
 (0)