114 lines
3.7 KiB
C++
114 lines
3.7 KiB
C++
#include "stream-identification-function-active-dest-mac-vlan.h"
|
|
|
|
#include "ns3/log.h"
|
|
#include "ns3/uinteger.h"
|
|
#include "ns3/mac48-address.h"
|
|
#include "ns3/packet.h"
|
|
#include "ns3/ethernet-trailer.h"
|
|
|
|
|
|
#include "stream-identification-function.h"
|
|
#include "ns3/ethernet-header2.h"
|
|
|
|
namespace ns3
|
|
{
|
|
|
|
NS_LOG_COMPONENT_DEFINE("ActiveDestMacVlanStreamIdentificationFunction");
|
|
|
|
NS_OBJECT_ENSURE_REGISTERED(ActiveDestMacVlanStreamIdentificationFunction);
|
|
|
|
TypeId
|
|
ActiveDestMacVlanStreamIdentificationFunction::GetTypeId()
|
|
{
|
|
static TypeId tid =
|
|
TypeId("ns3::ActiveDestMacVlanStreamIdentificationFunction")
|
|
.SetParent<StreamIdentificationFunction>()
|
|
.SetGroupName("tsn")
|
|
.AddConstructor<ActiveDestMacVlanStreamIdentificationFunction>()
|
|
.AddAttribute("Address",
|
|
"Destination Mac Address",
|
|
AddressValue(Mac48Address("ff:ff:ff:ff:ff:ff")),
|
|
MakeAddressAccessor(&ActiveDestMacVlanStreamIdentificationFunction::m_destAddress),
|
|
MakeAddressChecker())
|
|
.AddAttribute("VlanID",
|
|
"Vlan ID",
|
|
UintegerValue(0),
|
|
MakeUintegerAccessor(&ActiveDestMacVlanStreamIdentificationFunction::m_vid),
|
|
MakeUintegerChecker<uint16_t>())
|
|
.AddAttribute("UpdateVlanID",
|
|
"Update Vlan ID",
|
|
UintegerValue(0),
|
|
MakeUintegerAccessor(&ActiveDestMacVlanStreamIdentificationFunction::m_updateVid),
|
|
MakeUintegerChecker<uint16_t>())
|
|
.AddAttribute("UpdateAddress",
|
|
"Update Destination Mac Address",
|
|
AddressValue(Mac48Address("ff:ff:ff:ff:ff:ff")),
|
|
MakeAddressAccessor(&ActiveDestMacVlanStreamIdentificationFunction::m_updateDestAddress),
|
|
MakeAddressChecker())
|
|
.AddAttribute("UpdatePCP",
|
|
"Update PCP",
|
|
UintegerValue(0),
|
|
MakeUintegerAccessor(&ActiveDestMacVlanStreamIdentificationFunction::m_updatePcp),
|
|
MakeUintegerChecker<uint8_t>());
|
|
return tid;
|
|
}
|
|
|
|
|
|
ActiveDestMacVlanStreamIdentificationFunction::ActiveDestMacVlanStreamIdentificationFunction()
|
|
{
|
|
NS_LOG_FUNCTION(this);
|
|
}
|
|
|
|
ActiveDestMacVlanStreamIdentificationFunction::~ActiveDestMacVlanStreamIdentificationFunction()
|
|
{
|
|
NS_LOG_FUNCTION(this);
|
|
}
|
|
|
|
bool
|
|
ActiveDestMacVlanStreamIdentificationFunction::Match(Ptr<Packet> p)
|
|
{
|
|
NS_LOG_FUNCTION(this);
|
|
|
|
Ptr<Packet> pcopy = p->Copy();
|
|
|
|
EthernetHeader2 header;
|
|
pcopy->RemoveHeader(header);
|
|
|
|
if(m_destAddress==header.GetDest() && m_vid==header.GetVid())
|
|
{
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
void
|
|
ActiveDestMacVlanStreamIdentificationFunction::GetActiveUpdate(Ptr<Packet> p)
|
|
{
|
|
NS_LOG_FUNCTION(this);
|
|
|
|
//Update the pkt
|
|
//Remove old header and trailer
|
|
EthernetHeader2 oldHeader;
|
|
p->RemoveHeader(oldHeader);
|
|
EthernetTrailer oldTrailer;
|
|
p->RemoveTrailer(oldTrailer);
|
|
|
|
//Add new header and trailer
|
|
EthernetHeader2 header;
|
|
header.SetDest(Mac48Address::ConvertFrom(m_updateDestAddress));
|
|
header.SetSrc(oldHeader.GetSrc());
|
|
header.SetEthertype(oldHeader.GetEthertype());
|
|
header.SetVlanTag(m_updatePcp, oldHeader.GetDei(), m_updateVid);
|
|
header.SetRedundancyTag(oldHeader.RemoveRedundancyTag());
|
|
p->AddHeader(header);
|
|
|
|
EthernetTrailer trailer;
|
|
trailer.EnableFcs(true);
|
|
trailer.CalcFcs(p);
|
|
p->AddTrailer(trailer);
|
|
|
|
}
|
|
|
|
}
|