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,232 @@
#include "gPTP-packet.h"
#include "ns3/log.h"
#include "ns3/object.h"
#include "ns3/packet.h"
namespace ns3
{
NS_LOG_COMPONENT_DEFINE("GPTPPacket");
NS_OBJECT_ENSURE_REGISTERED(PdelayPayload);
TypeId
PdelayPayload::GetTypeId()
{
static TypeId tid =
TypeId("ns3::PdelayPayload")
.SetParent<Object>()
.SetGroupName("tsn")
.AddConstructor<PdelayPayload>();
return tid;
}
PdelayPayload::PdelayPayload()
{
NS_LOG_FUNCTION(this);
m_pkt = Create<Packet>(20);
}
PdelayPayload::PdelayPayload(uint64_t timestampSecond, uint32_t timestampNanoSecond, uint64_t clockIdentity, uint16_t portIdentity)
{
NS_LOG_FUNCTION(this);
uint8_t txBuffer[20] = {};
txBuffer[0] = (timestampSecond & 0xFF0000000000) >> 40;
txBuffer[1] = (timestampSecond & 0x00FF00000000) >> 32;
txBuffer[2] = (timestampSecond & 0x0000FF000000) >> 24;
txBuffer[3] = (timestampSecond & 0x000000FF0000) >> 16;
txBuffer[4] = (timestampSecond & 0x00000000FF00) >> 8;
txBuffer[5] = (timestampSecond & 0x0000000000FF);
txBuffer[6] = (timestampNanoSecond & 0xFF000000) >> 24;
txBuffer[7] = (timestampNanoSecond & 0x00FF0000) >> 16;
txBuffer[8] = (timestampNanoSecond & 0x0000FF00) >> 8;
txBuffer[9] = (timestampNanoSecond & 0x000000FF);
txBuffer[10] = (clockIdentity & 0xFF00000000000000) >> 56;
txBuffer[11] = (clockIdentity & 0x00FF000000000000) >> 48;
txBuffer[12] = (clockIdentity & 0x0000FF0000000000) >> 40;
txBuffer[13] = (clockIdentity & 0x000000FF00000000) >> 32;
txBuffer[14] = (clockIdentity & 0x00000000FF000000) >> 24;
txBuffer[15] = (clockIdentity & 0x0000000000FF0000) >> 16;
txBuffer[16] = (clockIdentity & 0x000000000000FF00) >> 8;
txBuffer[17] = (clockIdentity & 0x00000000000000FF);
txBuffer[18] = (portIdentity & 0xFF00) >> 8;
txBuffer[19] = (portIdentity & 0x00FF);
size_t txBufferSize = sizeof(txBuffer);
m_pkt = Create<Packet>(txBuffer, txBufferSize);
}
PdelayPayload::~PdelayPayload()
{
NS_LOG_FUNCTION(this);
}
Ptr<Packet>
PdelayPayload::GetPkt()
{
NS_LOG_FUNCTION(this);
return m_pkt;
}
NS_OBJECT_ENSURE_REGISTERED(SyncPayload);
TypeId
SyncPayload::GetTypeId()
{
static TypeId tid =
TypeId("ns3::SyncPayload")
.SetParent<Object>()
.SetGroupName("tsn")
.AddConstructor<SyncPayload>();
return tid;
}
SyncPayload::SyncPayload()
{
NS_LOG_FUNCTION(this);
m_pkt = Create<Packet>(10);
}
SyncPayload::SyncPayload(uint64_t timestampSecond, uint32_t timestampNanoSecond)
{
NS_LOG_FUNCTION(this);
uint8_t txBuffer[10] = {};
txBuffer[0] = (timestampSecond & 0xFF0000000000) >> 40;
txBuffer[1] = (timestampSecond & 0x00FF00000000) >> 32;
txBuffer[2] = (timestampSecond & 0x0000FF000000) >> 24;
txBuffer[3] = (timestampSecond & 0x000000FF0000) >> 16;
txBuffer[4] = (timestampSecond & 0x00000000FF00) >> 8;
txBuffer[5] = (timestampSecond & 0x0000000000FF);
txBuffer[6] = (timestampNanoSecond & 0xFF000000) >> 24;
txBuffer[7] = (timestampNanoSecond & 0x00FF0000) >> 16;
txBuffer[8] = (timestampNanoSecond & 0x0000FF00) >> 8;
txBuffer[9] = (timestampNanoSecond & 0x000000FF);
size_t txBufferSize = sizeof(txBuffer);
m_pkt = Create<Packet>(txBuffer, txBufferSize);
}
SyncPayload::~SyncPayload()
{
NS_LOG_FUNCTION(this);
}
Ptr<Packet>
SyncPayload::GetPkt()
{
NS_LOG_FUNCTION(this);
return m_pkt;
}
NS_OBJECT_ENSURE_REGISTERED(FollowUpPayload);
TypeId
FollowUpPayload::GetTypeId()
{
static TypeId tid =
TypeId("ns3::FollowUpPayload")
.SetParent<Object>()
.SetGroupName("tsn")
.AddConstructor<FollowUpPayload>();
return tid;
}
FollowUpPayload::FollowUpPayload()
{
NS_LOG_FUNCTION(this);
m_pkt = Create<Packet>(42);
}
FollowUpPayload::FollowUpPayload(uint64_t timestampSecond,
uint32_t timestampNanoSecond,
uint32_t cumulativeScaledRateRatio,
uint16_t gmTimeBaseIndicator,
uint32_t lastGmPhaseChange0,
uint32_t lastGmPhaseChange1,
uint32_t lastGmPhaseChange2,
uint32_t scaledLastGmFreqChange)
{
NS_LOG_FUNCTION(this);
uint8_t txBuffer[42] = {};
txBuffer[0] = (timestampSecond & 0xFF0000000000) >> 40;
txBuffer[1] = (timestampSecond & 0x00FF00000000) >> 32;
txBuffer[2] = (timestampSecond & 0x0000FF000000) >> 24;
txBuffer[3] = (timestampSecond & 0x000000FF0000) >> 16;
txBuffer[4] = (timestampSecond & 0x00000000FF00) >> 8;
txBuffer[5] = (timestampSecond & 0x0000000000FF);
txBuffer[6] = (timestampNanoSecond & 0xFF000000) >> 24;
txBuffer[7] = (timestampNanoSecond & 0x00FF0000) >> 16;
txBuffer[8] = (timestampNanoSecond & 0x0000FF00) >> 8;
txBuffer[9] = (timestampNanoSecond & 0x000000FF);
txBuffer[10] = (m_tlvType & 0xFF00);
txBuffer[11] = (m_tlvType & 0x00FF);
txBuffer[12] = (m_lenghtField & 0xFF00);
txBuffer[13] = (m_lenghtField & 0x00FF);
txBuffer[14] = (m_organizationId & 0xFF0000);
txBuffer[15] = (m_organizationId & 0x00FF00);
txBuffer[16] = (m_organizationId & 0x0000FF);
txBuffer[17] = (m_organizationSubType & 0xFF0000);
txBuffer[18] = (m_organizationSubType & 0x00FF00);
txBuffer[19] = (m_organizationSubType & 0x0000FF);
txBuffer[20] = (cumulativeScaledRateRatio & 0xFF000000);
txBuffer[21] = (cumulativeScaledRateRatio & 0x00FF0000);
txBuffer[22] = (cumulativeScaledRateRatio & 0x0000FF00);
txBuffer[23] = (cumulativeScaledRateRatio & 0x000000FF);
txBuffer[24] = (gmTimeBaseIndicator & 0xFF00);
txBuffer[25] = (gmTimeBaseIndicator & 0x00FF);
txBuffer[26] = (lastGmPhaseChange0 & 0xFF000000);
txBuffer[27] = (lastGmPhaseChange0 & 0x00FF0000);
txBuffer[28] = (lastGmPhaseChange0 & 0x0000FF00);
txBuffer[29] = (lastGmPhaseChange0 & 0x000000FF);
txBuffer[30] = (lastGmPhaseChange1 & 0xFF000000);
txBuffer[31] = (lastGmPhaseChange1 & 0x00FF0000);
txBuffer[32] = (lastGmPhaseChange1 & 0x0000FF00);
txBuffer[33] = (lastGmPhaseChange1 & 0x000000FF);
txBuffer[34] = (lastGmPhaseChange2 & 0xFF000000);
txBuffer[35] = (lastGmPhaseChange2 & 0x00FF0000);
txBuffer[36] = (lastGmPhaseChange2 & 0x0000FF00);
txBuffer[37] = (lastGmPhaseChange2 & 0x000000FF);
txBuffer[38] = (scaledLastGmFreqChange & 0xFF000000);
txBuffer[39] = (scaledLastGmFreqChange & 0x00FF0000);
txBuffer[40] = (scaledLastGmFreqChange & 0x0000FF00);
txBuffer[41] = (scaledLastGmFreqChange & 0x000000FF);
size_t txBufferSize = sizeof(txBuffer);
m_pkt = Create<Packet>(txBuffer, txBufferSize);
}
FollowUpPayload::~FollowUpPayload()
{
NS_LOG_FUNCTION(this);
}
Ptr<Packet>
FollowUpPayload::GetPkt()
{
NS_LOG_FUNCTION(this);
return m_pkt;
}
}