bus network
This commit is contained in:
65
tutorial/bus-network.cc
Normal file
65
tutorial/bus-network.cc
Normal file
@@ -0,0 +1,65 @@
|
||||
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2007 University of Washington
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#include "ns3/mac48-address.h"
|
||||
#include "ns3/csma-net-device.h"
|
||||
#include "ns3/csma-topology.h"
|
||||
#include "ns3/csma-ipv4-topology.h"
|
||||
|
||||
#include "bus-network.h"
|
||||
#include "ipv4-address-generator.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
BusNetwork::BusNetwork (
|
||||
Ipv4Mask mask,
|
||||
Ipv4Address network,
|
||||
Ipv4Address startAddress,
|
||||
DataRate bps,
|
||||
Time delay,
|
||||
uint32_t n)
|
||||
{
|
||||
Ipv4AddressGenerator::SeedNetwork (mask, network);
|
||||
Ipv4AddressGenerator::SeedAddress (mask, startAddress);
|
||||
|
||||
m_channel = CsmaTopology::CreateCsmaChannel (bps, delay);
|
||||
|
||||
for (uint32_t i = 0; i < n; ++i)
|
||||
{
|
||||
Ptr<Node> node = Create<InternetNode> ();
|
||||
uint32_t nd = CsmaIpv4Topology::AddIpv4CsmaNetDevice (node, m_channel,
|
||||
Mac48Address::Allocate ());
|
||||
Ipv4Address address = Ipv4AddressGenerator::AllocateAddress (mask,
|
||||
network);
|
||||
CsmaIpv4Topology::AddIpv4Address (node, nd, address, mask);
|
||||
m_nodes.push_back (node);
|
||||
}
|
||||
}
|
||||
|
||||
BusNetwork::~BusNetwork ()
|
||||
{
|
||||
m_nodes.erase (m_nodes.begin (), m_nodes.end ());
|
||||
}
|
||||
|
||||
Ptr<Node>
|
||||
BusNetwork::GetNode (uint32_t n)
|
||||
{
|
||||
return m_nodes[n];
|
||||
}
|
||||
|
||||
}; // namespace ns3
|
||||
53
tutorial/bus-network.h
Normal file
53
tutorial/bus-network.h
Normal file
@@ -0,0 +1,53 @@
|
||||
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2007 University of Washington
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef BUS_NETWORK_H
|
||||
#define BUS_NETWORK_H
|
||||
|
||||
#include <list>
|
||||
#include "ns3/ptr.h"
|
||||
#include "ns3/node.h"
|
||||
#include "ns3/ipv4-address.h"
|
||||
#include "ns3/data-rate.h"
|
||||
#include "ns3/csma-channel.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
class BusNetwork
|
||||
{
|
||||
public:
|
||||
BusNetwork (
|
||||
Ipv4Mask mask,
|
||||
Ipv4Address network,
|
||||
Ipv4Address startAddress,
|
||||
DataRate bps,
|
||||
Time delay,
|
||||
uint32_t n);
|
||||
|
||||
virtual ~BusNetwork ();
|
||||
|
||||
Ptr<Node> GetNode (uint32_t n);
|
||||
|
||||
private:
|
||||
std::vector<Ptr<Node> > m_nodes;
|
||||
Ptr<CsmaChannel> m_channel;
|
||||
};
|
||||
|
||||
}; // namespace ns3
|
||||
|
||||
#endif /* BUS_NETWORK_H */
|
||||
63
tutorial/tutorial-bus-network.cc
Normal file
63
tutorial/tutorial-bus-network.cc
Normal file
@@ -0,0 +1,63 @@
|
||||
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#include "ns3/log.h"
|
||||
#include "ns3/ipv4-address.h"
|
||||
#include "ns3/udp-echo-client.h"
|
||||
#include "ns3/udp-echo-server.h"
|
||||
#include "ns3/simulator.h"
|
||||
#include "ns3/nstime.h"
|
||||
#include "ns3/ascii-trace.h"
|
||||
|
||||
#include "bus-network.h"
|
||||
|
||||
NS_LOG_COMPONENT_DEFINE ("BusNetworkSimulation");
|
||||
|
||||
using namespace ns3;
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
LogComponentEnable ("BusNetworkSimulation", LOG_LEVEL_ALL);
|
||||
LogComponentEnable ("BusNetwork", LOG_LEVEL_ALL);
|
||||
|
||||
NS_LOG_INFO ("Bus Network Simulation");
|
||||
|
||||
BusNetwork busNetwork (Ipv4Mask ("255.255.0.0"), Ipv4Address ("10.1.0.0"),
|
||||
Ipv4Address ("0.0.0.0"), DataRate(10000000), MilliSeconds(20), 10);
|
||||
|
||||
uint32_t port = 7;
|
||||
|
||||
Ptr<Node> n0 = busNetwork.GetNode (0);
|
||||
Ptr<UdpEchoClient> client = Create<UdpEchoClient> (n0, "10.1.0.1", port,
|
||||
1, Seconds(1.), 1024);
|
||||
|
||||
Ptr<Node> n1 = busNetwork.GetNode (1);
|
||||
Ptr<UdpEchoServer> server = Create<UdpEchoServer> (n1, port);
|
||||
|
||||
server->Start(Seconds(1.));
|
||||
client->Start(Seconds(2.));
|
||||
|
||||
server->Stop (Seconds(10.));
|
||||
client->Stop (Seconds(10.));
|
||||
|
||||
AsciiTrace asciitrace ("tutorial.tr");
|
||||
asciitrace.TraceAllQueues ();
|
||||
asciitrace.TraceAllNetDeviceRx ();
|
||||
|
||||
Simulator::Run ();
|
||||
Simulator::Destroy ();
|
||||
}
|
||||
@@ -36,3 +36,9 @@ def build(bld):
|
||||
obj = bld.create_ns3_program('testipv4',
|
||||
['core'])
|
||||
obj.source = ['testipv4.cc', 'ipv4-address-generator.cc']
|
||||
|
||||
obj = bld.create_ns3_program('tutorial-bus-network',
|
||||
['core'])
|
||||
obj.source = ['tutorial-bus-network.cc',
|
||||
'bus-network.cc',
|
||||
'ipv4-address-generator.cc']
|
||||
|
||||
Reference in New Issue
Block a user