283 lines
7.3 KiB
C++
283 lines
7.3 KiB
C++
#include "gPTP-header.h"
|
|
|
|
#include "ns3/buffer.h"
|
|
#include "ns3/abort.h"
|
|
#include "ns3/assert.h"
|
|
#include "ns3/header.h"
|
|
#include "ns3/log.h"
|
|
|
|
#include <iomanip>
|
|
#include <iostream>
|
|
|
|
#include <bitset>
|
|
|
|
namespace ns3
|
|
{
|
|
|
|
NS_LOG_COMPONENT_DEFINE("GPTPHeader");
|
|
|
|
NS_OBJECT_ENSURE_REGISTERED(GptpHeader);
|
|
|
|
GptpHeader::GptpHeader()
|
|
{
|
|
NS_LOG_FUNCTION_NOARGS();
|
|
}
|
|
|
|
GptpHeader::~GptpHeader()
|
|
{
|
|
NS_LOG_FUNCTION_NOARGS();
|
|
}
|
|
|
|
TypeId
|
|
GptpHeader::GetTypeId()
|
|
{
|
|
NS_LOG_FUNCTION_NOARGS();
|
|
static TypeId tid = TypeId("ns3::GptpHeader")
|
|
.SetParent<Header>()
|
|
.SetGroupName("Tsn")
|
|
.AddConstructor<GptpHeader>();
|
|
return tid;
|
|
}
|
|
|
|
TypeId
|
|
GptpHeader::GetInstanceTypeId() const
|
|
{
|
|
NS_LOG_FUNCTION_NOARGS();
|
|
return GetTypeId();
|
|
}
|
|
|
|
void
|
|
GptpHeader::Print(std::ostream& os) const
|
|
{
|
|
NS_LOG_FUNCTION(this);
|
|
std::string proto;
|
|
|
|
os <<"GPTP print ==> TODO";
|
|
}
|
|
|
|
uint32_t
|
|
GptpHeader::GetSerializedSize() const
|
|
{
|
|
NS_LOG_FUNCTION_NOARGS();
|
|
return 34;
|
|
}
|
|
|
|
void
|
|
GptpHeader::Serialize(Buffer::Iterator start) const
|
|
{
|
|
NS_LOG_FUNCTION(this);
|
|
uint8_t flag1 = ((0 << 7) |
|
|
(m_ptpProfifilSpecific2Flag << 6) |
|
|
(m_ptpProfifilSpecific1Flag << 5) |
|
|
(0 << 4) |
|
|
(0 << 3) |
|
|
(m_unicastFlag << 2) |
|
|
(m_twoStepFlag << 1) |
|
|
(m_alternateMasterFlag << 0));
|
|
uint8_t flag2 = ((0 << 7) |
|
|
(0 << 6) |
|
|
(m_frequencyTraceable << 5) |
|
|
(m_timeTraceable << 4) |
|
|
(m_ptpTimescale << 3) |
|
|
(m_currentUtcOffsetValid << 2) |
|
|
(m_leap59 << 1) |
|
|
(m_leap61 << 0));
|
|
|
|
Buffer::Iterator i = start;
|
|
i.WriteU8((m_majorSdoId << 4) | m_messageType);
|
|
i.WriteU8((m_minorVersionPTP << 4) | m_versionPTP);
|
|
i.WriteHtonU16(m_messageLenght);
|
|
i.WriteU8(m_domainNumber);
|
|
i.WriteU8(m_minorSdoId);
|
|
i.WriteU8(flag1);
|
|
i.WriteU8(flag2);
|
|
i.WriteHtonU64(m_correctionField);
|
|
i.WriteHtonU32(m_messageTypeSpecific);
|
|
i.WriteHtonU64(m_clockIndentity);
|
|
i.WriteHtonU16(m_portIdentity);
|
|
i.WriteHtonU16(m_sequenceId);
|
|
i.WriteU8(m_controlField);
|
|
i.WriteU8(m_logMessageInterval);
|
|
|
|
// for (int j=0; j<(int)m_QTagList.size() ; j++)
|
|
// {
|
|
// i.WriteHtonU16(m_QTagList[j].TPID);
|
|
// if(m_QTagList[j].Type == VLAN)
|
|
// {
|
|
// i.WriteHtonU16(m_QTagList[j].TCI);
|
|
// }
|
|
// else if(m_QTagList[j].Type == REDUNDANCY)
|
|
// {
|
|
// i.WriteHtonU32(m_QTagList[j].TCI);
|
|
// }
|
|
// }
|
|
// i.WriteHtonU16(m_ethertype);
|
|
}
|
|
|
|
uint32_t
|
|
GptpHeader::Deserialize(Buffer::Iterator start)
|
|
{
|
|
NS_LOG_FUNCTION(this);
|
|
|
|
Buffer::Iterator i = start;
|
|
uint8_t tmp = i.ReadU8();
|
|
m_majorSdoId = (tmp & 0b11110000) >> 4;
|
|
m_messageType = tmp & 0b00001111;
|
|
tmp = i.ReadU8();
|
|
m_minorVersionPTP = (tmp & 0b11110000) >> 4;
|
|
m_versionPTP = tmp & 0b00001111;
|
|
m_messageLenght = i.ReadNtohU16();
|
|
m_domainNumber = i.ReadU8();
|
|
m_minorSdoId = i.ReadU8();
|
|
uint16_t flags = i.ReadNtohU16();
|
|
m_alternateMasterFlag = (flags & 0b0000000100000000) >> 8;
|
|
m_twoStepFlag = (flags & 0b0000001000000000) >> 9;
|
|
m_unicastFlag = (flags & 0b0000010000000000) >> 10;
|
|
m_ptpProfifilSpecific1Flag = (flags & 0b0010000000000000) >> 13;
|
|
m_ptpProfifilSpecific2Flag = (flags & 0b0100000000000000) >> 14;
|
|
m_leap61 = (flags & 0b0000000000000001) >> 0;
|
|
m_leap59 = (flags & 0b0000000000000010) >> 1;
|
|
m_currentUtcOffsetValid = (flags & 0b0000000000000100) >> 2;
|
|
m_ptpTimescale = (flags & 0b0000000000001000) >> 3;
|
|
m_timeTraceable = (flags & 0b0000000000010000) >> 4;
|
|
m_frequencyTraceable = (flags & 0b0000000000100000) >> 5;
|
|
m_correctionField = i.ReadNtohU64();
|
|
m_messageTypeSpecific = i.ReadNtohU32();
|
|
m_clockIndentity = i.ReadNtohU64();
|
|
m_portIdentity = i.ReadNtohU16();
|
|
m_sequenceId = i.ReadNtohU16();
|
|
m_controlField = i.ReadU8();
|
|
m_logMessageInterval = i.ReadU8();
|
|
|
|
// NS_LOG_INFO("m_majorSdoId " << (uint16_t)m_majorSdoId);
|
|
// NS_LOG_INFO("m_messageType " << (uint16_t)m_messageType);
|
|
// NS_LOG_INFO("m_minorVersionPTP " << (uint16_t)m_minorVersionPTP);
|
|
// NS_LOG_INFO("m_versionPTP " << (uint16_t)m_versionPTP);
|
|
// NS_LOG_INFO("m_messageLenght " << (uint16_t)m_messageLenght);
|
|
// NS_LOG_INFO("m_domainNumber " << (uint16_t)m_domainNumber);
|
|
// NS_LOG_INFO("m_minorSdoId " << (uint16_t)m_minorSdoId);
|
|
// NS_LOG_INFO("m_alternateMasterFlag " << (uint16_t)m_alternateMasterFlag);
|
|
// NS_LOG_INFO("m_twoStepFlag " << (uint16_t)m_twoStepFlag);
|
|
// NS_LOG_INFO("m_unicastFlag " << (uint16_t)m_unicastFlag);
|
|
// NS_LOG_INFO("m_ptpProfifilSpecific1Flag " << (uint16_t)m_ptpProfifilSpecific1Flag);
|
|
// NS_LOG_INFO("m_ptpProfifilSpecific2Flag " << (uint16_t)m_ptpProfifilSpecific2Flag);
|
|
// NS_LOG_INFO("m_leap61 " << (uint16_t)m_leap61);
|
|
// NS_LOG_INFO("m_leap59 " << (uint16_t)m_leap59);
|
|
// NS_LOG_INFO("m_currentUtcOffsetValid " << (uint16_t)m_currentUtcOffsetValid);
|
|
// NS_LOG_INFO("m_ptpTimescale " << (uint16_t)m_ptpTimescale);
|
|
// NS_LOG_INFO("m_timeTraceable " << (uint16_t)m_timeTraceable);
|
|
// NS_LOG_INFO("m_frequencyTraceable " << (uint16_t)m_frequencyTraceable);
|
|
// NS_LOG_INFO("m_correctionField " << m_correctionField);
|
|
// NS_LOG_INFO("m_clockIndentity " << m_clockIndentity);
|
|
// NS_LOG_INFO("m_portIdentity " << m_portIdentity);
|
|
// NS_LOG_INFO("m_sequenceId " << m_sequenceId);
|
|
// NS_LOG_INFO("m_controlField " << (uint16_t)m_controlField);
|
|
// NS_LOG_INFO("m_logMessageInterval " << (uint16_t)m_logMessageInterval);
|
|
|
|
return GetSerializedSize();
|
|
}
|
|
|
|
void
|
|
GptpHeader::SetMessageType(uint8_t messageType)
|
|
{
|
|
m_messageType = messageType;
|
|
}
|
|
|
|
void
|
|
GptpHeader::SetMessageLenght(uint8_t messageLenght)
|
|
{
|
|
m_messageLenght = messageLenght;
|
|
}
|
|
|
|
void
|
|
GptpHeader::SetDomainNumber(uint8_t domainNumber)
|
|
{
|
|
m_domainNumber = domainNumber;
|
|
}
|
|
|
|
void
|
|
GptpHeader::SetTwoStepFlag(bool twoStepFlag)
|
|
{
|
|
m_twoStepFlag = twoStepFlag;
|
|
}
|
|
|
|
void
|
|
GptpHeader::SetCorrectionField(uint64_t correctionField)
|
|
{
|
|
m_correctionField = correctionField;
|
|
}
|
|
|
|
void
|
|
GptpHeader::SetClockIdentity(uint64_t clockIdentity)
|
|
{
|
|
m_clockIndentity = clockIdentity;
|
|
}
|
|
void
|
|
GptpHeader::SetPortIdentity(uint16_t portIdentity)
|
|
{
|
|
m_portIdentity = portIdentity;
|
|
}
|
|
|
|
void
|
|
GptpHeader::SetSequenceId(uint16_t sequenceId)
|
|
{
|
|
m_sequenceId = sequenceId;
|
|
}
|
|
|
|
void
|
|
GptpHeader::SetLogMessageInterval(uint8_t logMessageInterval)
|
|
{
|
|
m_logMessageInterval = logMessageInterval;
|
|
}
|
|
|
|
uint8_t
|
|
GptpHeader::GetMessageType()
|
|
{
|
|
return m_messageType;
|
|
}
|
|
|
|
uint8_t
|
|
GptpHeader::GetDomainNumber()
|
|
{
|
|
return m_domainNumber;
|
|
}
|
|
|
|
bool
|
|
GptpHeader::GetTwoStepFlag()
|
|
{
|
|
return m_twoStepFlag;
|
|
}
|
|
|
|
uint64_t
|
|
GptpHeader::GetCorrectionField()
|
|
{
|
|
return m_correctionField;
|
|
}
|
|
uint64_t
|
|
GptpHeader::GetClockIdentity()
|
|
{
|
|
return m_clockIndentity;
|
|
}
|
|
|
|
uint16_t
|
|
GptpHeader::GetPortIdentity()
|
|
{
|
|
return m_portIdentity;
|
|
}
|
|
|
|
uint16_t
|
|
GptpHeader::GetSequenceId()
|
|
{
|
|
return m_sequenceId;
|
|
}
|
|
|
|
uint8_t
|
|
GptpHeader::GetLogMessageInterval()
|
|
{
|
|
return m_logMessageInterval;
|
|
}
|
|
|
|
|
|
|
|
}
|