Remove old traffic generator stuff

This commit is contained in:
2026-03-18 08:40:42 +01:00
parent 7c929cae0f
commit 64949975cf
8 changed files with 6 additions and 226 deletions

View File

@@ -12,13 +12,9 @@ endif()
build_lib( build_lib(
LIBNAME traffic-generator LIBNAME traffic-generator
SOURCE_FILES model/traffic-generator.cc SOURCE_FILES model/ethernet-generator.cc
model/ethernet-generator.cc
model/myCustomApp.cc
helper/traffic-generator-helper.cc helper/traffic-generator-helper.cc
HEADER_FILES model/traffic-generator.h HEADER_FILES model/ethernet-generator.h
model/ethernet-generator.h
model/myCustomApp.h
helper/traffic-generator-helper.h helper/traffic-generator-helper.h
LIBRARIES_TO_LINK ${libcore} LIBRARIES_TO_LINK ${libcore}
${libethernet} ${libethernet}

View File

@@ -1,8 +1,6 @@
#ifndef TRAFFIC_GENERATOR_HELPER_H #ifndef TRAFFIC_GENERATOR_HELPER_H
#define TRAFFIC_GENERATOR_HELPER_H #define TRAFFIC_GENERATOR_HELPER_H
#include "ns3/traffic-generator.h"
namespace ns3 namespace ns3
{ {

View File

@@ -81,7 +81,7 @@ EthernetGenerator::GetTypeId()
"Trace source indicating a packet was given to the netDevice" "Trace source indicating a packet was given to the netDevice"
"by the application", "by the application",
MakeTraceSourceAccessor(&EthernetGenerator::m_pktSentTrace), MakeTraceSourceAccessor(&EthernetGenerator::m_pktSentTrace),
"ns3::EthernetGenerator::PacketVlanTraceCallback"); "ns3::Packet::TracedCallback");
return tid; return tid;
} }
@@ -160,7 +160,7 @@ EthernetGenerator::Send()
else{ else{
m_net->Send(p, m_destAddress, 0xEDE1, m_vid, m_pcp, m_dei); m_net->Send(p, m_destAddress, 0xEDE1, m_vid, m_pcp, m_dei);
} }
m_pktSentTrace(p, m_vid); m_pktSentTrace(p);
} }
} // Namespace ns3 } // Namespace ns3

View File

@@ -34,7 +34,6 @@ class EthernetGenerator : public Application
void Setup(Ptr<EthernetNetDevice> net); void Setup(Ptr<EthernetNetDevice> net);
typedef TracedCallback<Ptr<const Packet>, uint16_t> PacketVlanTraceCallback;
protected: protected:
void DoDispose() override; void DoDispose() override;
@@ -66,7 +65,7 @@ class EthernetGenerator : public Application
EventId m_sendEvent; //!< Event to send the next packet EventId m_sendEvent; //!< Event to send the next packet
Ptr<EthernetNetDevice> m_net; Ptr<EthernetNetDevice> m_net;
PacketVlanTraceCallback m_pktSentTrace; TracedCallback<Ptr<const Packet>> m_pktSentTrace;
static const uint16_t MIN_PAYLOAD_SIZE = 42; //Min payload size with VLAN static const uint16_t MIN_PAYLOAD_SIZE = 42; //Min payload size with VLAN
}; };

View File

@@ -1,119 +0,0 @@
#include "myCustomApp.h"
#include "ns3/log.h"
#include "ns3/simulator.h"
#include "ns3/socket-factory.h"
#include "ns3/socket.h"
#include "ns3/uinteger.h"
#include "ns3/names.h"
#include "ns3/point-to-point-net-device.h"
#include <cstdio>
#include <cstdlib>
namespace ns3
{
NS_LOG_COMPONENT_DEFINE("myCustomApp");
NS_OBJECT_ENSURE_REGISTERED(myCustomApp);
TypeId
myCustomApp::GetTypeId()
{
static TypeId tid =
TypeId("ns3::myCustomApp")
.SetParent<Application>()
.SetGroupName("Applications")
.AddConstructor<myCustomApp>();
return tid;
}
myCustomApp::myCustomApp()
{
NS_LOG_FUNCTION(this);
m_sent = 0;
m_totalTx = 0;
m_totalRx = 0;
m_sendEvent = EventId();
}
myCustomApp::~myCustomApp()
{
NS_LOG_FUNCTION(this);
}
void
myCustomApp::Setup(Ptr<PointToPointNetDevice> net, int t)
{
m_net = net;
Packet::EnablePrinting();
m_sendEvent = Simulator::Schedule(Seconds(t), &myCustomApp::Send, this);
m_net->SetReceiveCallback(MakeCallback(&myCustomApp::RxPacket, this));
}
bool
myCustomApp::RxPacket(Ptr<NetDevice> dev, Ptr<const Packet> pkt, uint16_t mode, const Address& sender)
{
m_totalRx = m_totalRx + pkt->GetSize();
NS_LOG_INFO((Simulator::Now()).As(Time::S) << " \t" << Names::FindName(m_net->GetNode()) << "/" << Names::FindName(m_net) <<" : Pkt rcvd ! " << pkt->ToString());
return true;
}
void
myCustomApp::DoDispose()
{
NS_LOG_FUNCTION(this);
Application::DoDispose();
}
void
myCustomApp::StartApplication()
{
NS_LOG_FUNCTION(this);
}
void
myCustomApp::StopApplication()
{
NS_LOG_FUNCTION(this);
Simulator::Cancel(m_sendEvent);
NS_LOG_INFO("\tNb bytes rcvd :" << GetTotalRx());
}
void
myCustomApp::Send()
{
NS_LOG_FUNCTION(this);
NS_ASSERT(m_sendEvent.IsExpired());
uint8_t txBuffer[] = "\"Can you tell me where my country lies?\" \\ said the unifaun to his "
"true love's eyes. \\ \"It lies with me!\" cried the Queen of Maybe \\ - "
"for her merchandise, he traded in his prize.";
size_t txBufferSize = sizeof(txBuffer);
Ptr<Packet> p = Create<Packet>(txBuffer, txBufferSize);
NS_LOG_INFO((Simulator::Now()).As(Time::S) << " \t" << Names::FindName(m_net->GetNode()) << "/" << Names::FindName(m_net) <<" : Pkt sent ! " << p->ToString());
m_net->Send(p, m_net->GetBroadcast(), 0x800);
m_sendEvent = Simulator::Schedule(Seconds(2), &myCustomApp::Send, this);
}
uint64_t
myCustomApp::GetTotalTx() const
{
return m_totalTx;
}
uint64_t
myCustomApp::GetTotalRx() const
{
return m_totalRx;
}
} // Namespace ns3

View File

@@ -1,66 +0,0 @@
#ifndef MY_CUSTOM_APP_H
#define MY_CUSTOM_APP_H
#include "ns3/application.h"
#include "ns3/event-id.h"
#include "ns3/ptr.h"
#include <ns3/traced-callback.h>
#include "ns3/point-to-point-net-device.h"
namespace ns3
{
class Socket;
class Packet;
class myCustomApp : public Application
{
public:
/**
* \brief Get the type ID.
* \return the object TypeId
*/
static TypeId GetTypeId();
myCustomApp();
~myCustomApp() override;
/**
* \return the total bytes sent by this app
*/
uint64_t GetTotalTx() const;
uint64_t GetTotalRx() const;
void Setup(Ptr<PointToPointNetDevice> net, int t);
bool RxPacket(Ptr<NetDevice> dev, Ptr<const Packet> pkt, uint16_t mode, const Address& sender);
protected:
void DoDispose() override;
private:
void StartApplication() override;
void StopApplication() override;
/**
* \brief Send a packet
*/
void Send();
uint32_t m_count; //!< Maximum number of packets the application will send
Time m_interval; //!< Packet inter-send time
uint32_t m_size; //!< Size of the sent packet (including the SeqTsHeader)
uint32_t m_sent; //!< Counter for sent packets
uint64_t m_totalRx; //!< Total bytes sent
uint64_t m_totalTx; //!< Total bytes rcvd
Address m_peerAddress; //!< Remote peer address
uint16_t m_peerPort; //!< Remote peer port
EventId m_sendEvent; //!< Event to send the next packet
Ptr<PointToPointNetDevice> m_net;
};
} // namespace ns3
#endif

View File

@@ -1,8 +0,0 @@
#include "traffic-generator.h"
namespace ns3
{
/* ... */
}

View File

@@ -1,20 +0,0 @@
#ifndef TRAFFIC_GENERATOR_H
#define TRAFFIC_GENERATOR_H
// Add a doxygen group for this module.
// If you have more than one file, this should be in only one of them.
/**
* \defgroup traffic-generator Description of the traffic-generator
*/
namespace ns3
{
// Each class should be documented using Doxygen,
// and have an \ingroup traffic-generator directive
/* ... */
}
#endif /* TRAFFIC_GENERATOR_H */