Update README and add contrib dir

This commit is contained in:
2025-12-01 15:56:02 +01:00
parent 1b80de2153
commit cd9ba93d58
150 changed files with 25563 additions and 0 deletions

View File

@@ -0,0 +1,153 @@
#include "ethernet-generator.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/ethernet-net-device.h"
#include <cstdio>
#include <cstdlib>
namespace ns3
{
NS_LOG_COMPONENT_DEFINE("EthernetGenerator");
NS_OBJECT_ENSURE_REGISTERED(EthernetGenerator);
TypeId
EthernetGenerator::GetTypeId()
{
static TypeId tid =
TypeId("ns3::EthernetGenerator")
.SetParent<Application>()
.SetGroupName("Applications")
.AddConstructor<EthernetGenerator>()
.AddAttribute("Address",
"Destination Mac Address",
AddressValue(Mac48Address("ff:ff:ff:ff:ff:ff")),
MakeAddressAccessor(&EthernetGenerator::m_destAddress),
MakeAddressChecker())
.AddAttribute("PayloadSize",
"Payload Size in bytes",
UintegerValue(100),
MakeUintegerAccessor(&EthernetGenerator::m_payload_size),
MakeUintegerChecker<uint16_t>())
.AddAttribute("BurstSize",
"Burst size",
UintegerValue(1),
MakeUintegerAccessor(&EthernetGenerator::m_burst_size),
MakeUintegerChecker<uint16_t>())
.AddAttribute("Period",
"Period between burst",
TimeValue(Seconds(1)),
MakeTimeAccessor(&EthernetGenerator::m_period),
MakeTimeChecker())
.AddAttribute("InterFrame",
"Period between two packet of a burst",
TimeValue(Seconds(0)),
MakeTimeAccessor(&EthernetGenerator::m_interframe),
MakeTimeChecker())
.AddAttribute("Offset",
"Time offset between application start and first packet emission",
TimeValue(Seconds(0)),
MakeTimeAccessor(&EthernetGenerator::m_offset),
MakeTimeChecker())
.AddAttribute("VlanID",
"Vlan ID",
UintegerValue(65535),
MakeUintegerAccessor(&EthernetGenerator::m_vid),
MakeUintegerChecker<uint16_t>())
.AddAttribute("PCP",
"PCP field",
UintegerValue(0),
MakeUintegerAccessor(&EthernetGenerator::m_pcp),
MakeUintegerChecker<uint8_t>())
.AddAttribute("DEI",
"DEI bit",
UintegerValue(0),
MakeUintegerAccessor(&EthernetGenerator::m_dei),
MakeUintegerChecker<uint8_t>())
.AddTraceSource("PktSent",
"Trace source indicating a packet was given to the netDevice"
"by the application",
MakeTraceSourceAccessor(&EthernetGenerator::m_pktSentTrace),
"ns3::EthernetGenerator::PacketVlanTraceCallback");
return tid;
}
EthernetGenerator::EthernetGenerator()
{
NS_LOG_FUNCTION(this);
m_net = nullptr;
}
EthernetGenerator::~EthernetGenerator()
{
NS_LOG_FUNCTION(this);
}
void
EthernetGenerator::Setup(Ptr<EthernetNetDevice> net)
{
m_net = net;
}
void
EthernetGenerator::DoDispose()
{
NS_LOG_FUNCTION(this);
Application::DoDispose();
}
void
EthernetGenerator::StartApplication()
{
NS_LOG_FUNCTION(this);
if (m_vid==65535 && m_payload_size < MIN_PAYLOAD_SIZE + 4){
m_payload_size = MIN_PAYLOAD_SIZE + 4;
}
else if(m_payload_size < MIN_PAYLOAD_SIZE){
m_payload_size = MIN_PAYLOAD_SIZE;
}
m_sendEvent = Simulator::Schedule(m_offset, &EthernetGenerator::SendBurst, this);
}
void
EthernetGenerator::StopApplication()
{
NS_LOG_FUNCTION(this);
Simulator::Cancel(m_sendEvent);
}
void
EthernetGenerator::SendBurst()
{
NS_LOG_FUNCTION(this);
for (int i = 0; i < m_burst_size; i++) {
Simulator::Schedule(m_interframe*i, &EthernetGenerator::Send, this);
}
m_sendEvent = Simulator::Schedule(m_period, &EthernetGenerator::SendBurst, this);
}
void
EthernetGenerator::Send()
{
NS_LOG_FUNCTION(this);
Ptr<Packet> p = Create<Packet>(m_payload_size);
//NS_LOG_INFO((Simulator::Now()).As(Time::S) << " \t" << Names::FindName(m_net->GetNode()) << "/" << Names::FindName(m_net) <<" : Pkt #" << p->GetUid() <<"(vid="<< m_vid <<") given to the netDevice ! " << p->ToString());
if (m_vid==65535){
m_net->Send(p, m_destAddress, 0xEDE1);
}
else{
m_net->Send(p, m_destAddress, 0xEDE1, m_vid, m_pcp, m_dei);
}
m_pktSentTrace(p, m_vid);
}
} // Namespace ns3

View File

@@ -0,0 +1,72 @@
#ifndef ETHERNET_GENERATOR_H
#define ETHERNET_GENERATOR_H
#include "ns3/application.h"
#include "ns3/event-id.h"
#include "ns3/ptr.h"
#include <ns3/traced-callback.h>
#include "ns3/ethernet-net-device.h"
namespace ns3
{
class Socket;
class Packet;
class EthernetGenerator : public Application
{
public:
/**
* \brief Get the type ID.
* \return the object TypeId
*/
static TypeId GetTypeId();
EthernetGenerator();
~EthernetGenerator() override;
/**
* \return the total bytes sent by this app
*/
void Setup(Ptr<EthernetNetDevice> net);
typedef TracedCallback<Ptr<const Packet>, uint16_t> PacketVlanTraceCallback;
protected:
void DoDispose() override;
private:
void StartApplication() override;
void StopApplication() override;
/**
* \brief Send a packet
*/
void SendBurst();
void Send();
Address m_destAddress;
int m_payload_size;
int m_burst_size;
Time m_period;
Time m_interframe;
Time m_offset;
uint16_t m_vid;
uint8_t m_pcp;
uint8_t m_dei;
EventId m_sendEvent; //!< Event to send the next packet
Ptr<EthernetNetDevice> m_net;
PacketVlanTraceCallback m_pktSentTrace;
static const uint16_t MIN_PAYLOAD_SIZE = 42; //Min payload size with VLAN
};
} // namespace ns3
#endif

View File

@@ -0,0 +1,119 @@
#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

@@ -0,0 +1,66 @@
#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

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

View File

@@ -0,0 +1,20 @@
#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 */