83 lines
2.5 KiB
C++
83 lines
2.5 KiB
C++
|
|
#include "ns3/core-module.h"
|
||
|
|
#include "ns3/applications-module.h"
|
||
|
|
#include "ns3/command-line.h"
|
||
|
|
#include "ns3/simulator.h"
|
||
|
|
#include "ns3/node.h"
|
||
|
|
#include "ns3/drop-tail-queue.h"
|
||
|
|
|
||
|
|
#include "ns3/ethernet-net-device.h"
|
||
|
|
#include "ns3/ethernet-channel.h"
|
||
|
|
#include "ns3/ethernet-generator.h"
|
||
|
|
#include "ns3/ethernet-header2.h"
|
||
|
|
|
||
|
|
/**
|
||
|
|
* \file
|
||
|
|
*
|
||
|
|
* Example of the use of ethernet-generator.cc on a network composed of two
|
||
|
|
* ethernet end-stations
|
||
|
|
* ES1 ====== ES2
|
||
|
|
*/
|
||
|
|
|
||
|
|
using namespace ns3;
|
||
|
|
|
||
|
|
int
|
||
|
|
main(int argc, char* argv[])
|
||
|
|
{
|
||
|
|
//Enable logging
|
||
|
|
LogComponentEnable("EthernetGenerator", LOG_LEVEL_INFO);
|
||
|
|
CommandLine cmd(__FILE__);
|
||
|
|
cmd.Parse(argc, argv);
|
||
|
|
|
||
|
|
//Create two nodes
|
||
|
|
Ptr<Node> n0 = CreateObject<Node>();
|
||
|
|
Names::Add("ES1", n0);
|
||
|
|
Ptr<Node> n1 = CreateObject<Node>();
|
||
|
|
Names::Add("ES2", n1);
|
||
|
|
|
||
|
|
//Create and add a netDevice to each node
|
||
|
|
Ptr<EthernetNetDevice> net0 = CreateObject<EthernetNetDevice>();
|
||
|
|
n0->AddDevice(net0);
|
||
|
|
Names::Add("ES1#01", net0);
|
||
|
|
Ptr<EthernetNetDevice> net1 = CreateObject<EthernetNetDevice>();
|
||
|
|
n1->AddDevice(net1);
|
||
|
|
Names::Add("ES2#01", net1);
|
||
|
|
|
||
|
|
//Create a Ethernet Channel and attach it two the two netDevices
|
||
|
|
Ptr<EthernetChannel> channel = CreateObject<EthernetChannel>();
|
||
|
|
net0->Attach(channel);
|
||
|
|
net1->Attach(channel);
|
||
|
|
|
||
|
|
//Allocate a Mac address and create two FIFO (for the output port)
|
||
|
|
//for each netDevice.
|
||
|
|
net0->SetAddress(Mac48Address::Allocate());
|
||
|
|
net0->SetQueue(CreateObject<DropTailQueue<Packet>>());
|
||
|
|
net0->SetQueue(CreateObject<DropTailQueue<Packet>>());
|
||
|
|
|
||
|
|
net1->SetAddress(Mac48Address::Allocate());
|
||
|
|
net1->SetQueue(CreateObject<DropTailQueue<Packet>>());
|
||
|
|
net1->SetQueue(CreateObject<DropTailQueue<Packet>>());
|
||
|
|
|
||
|
|
//Application description
|
||
|
|
Ptr<EthernetGenerator> app0 = CreateObject<EthernetGenerator>();
|
||
|
|
app0->Setup(net0);
|
||
|
|
app0->SetAttribute("Address", AddressValue(net1->GetAddress()));
|
||
|
|
app0->SetAttribute("BurstSize", UintegerValue(2));
|
||
|
|
app0->SetAttribute("PayloadSize", UintegerValue(1400));
|
||
|
|
app0->SetAttribute("Period", TimeValue(Seconds(5)));
|
||
|
|
app0->SetAttribute("InterFrame", TimeValue(MilliSeconds(200)));
|
||
|
|
app0->SetAttribute("Offset", TimeValue(MilliSeconds(100)));
|
||
|
|
app0->SetAttribute("VlanID", UintegerValue(100));
|
||
|
|
app0->SetAttribute("PCP", UintegerValue(0));
|
||
|
|
|
||
|
|
n0->AddApplication(app0);
|
||
|
|
app0->SetStartTime(Seconds(0));
|
||
|
|
app0->SetStopTime(Seconds(10));
|
||
|
|
|
||
|
|
//Execute the simulation
|
||
|
|
Simulator::Stop(Seconds(10));
|
||
|
|
Simulator::Run();
|
||
|
|
Simulator::Destroy();
|
||
|
|
|
||
|
|
return 0;
|
||
|
|
}
|