in simulation/src/sixlowpan/model/sixlowpan-header.cc [977:1086]
void SixLowPanIphc::Serialize (Buffer::Iterator start) const
{
Buffer::Iterator i = start;
i.WriteHtonU16 (m_baseFormat);
if ( GetCid () )
{
i.WriteU8 (m_srcdstContextId);
}
// Traffic Class and Flow Label
switch ( GetTf () )
{
uint8_t temp;
case TF_FULL:
temp = (m_ecn << 6) | m_dscp;
i.WriteU8 (temp);
temp = m_flowLabel >> 16;
i.WriteU8 (temp);
temp = (m_flowLabel >> 8) & 0xff;
i.WriteU8 (temp);
temp = m_flowLabel & 0xff;
i.WriteU8 (temp);
break;
case TF_DSCP_ELIDED:
temp = (m_ecn << 6) | (m_flowLabel >> 16 );
i.WriteU8 (temp);
temp = (m_flowLabel >> 8) & 0xff;
i.WriteU8 (temp);
temp = m_flowLabel & 0xff;
i.WriteU8 (temp);
break;
case TF_FL_ELIDED:
temp = (m_ecn << 6) | m_dscp;
i.WriteU8 (temp);
break;
default:
break;
}
// Next Header
if ( GetNh () == false )
{
i.WriteU8 (m_nextHeader);
}
// Hop Limit
if ( GetHlim () == HLIM_INLINE )
{
i.WriteU8 (m_hopLimit);
}
// Source Address
switch (GetSam () )
{
case HC_INLINE:
if ( GetSac () == false )
{
i.Write (m_srcInlinePart, 16);
}
break;
case HC_COMPR_64:
i.Write (m_srcInlinePart, 8);
break;
case HC_COMPR_16:
i.Write (m_srcInlinePart, 2);
break;
case HC_COMPR_0:
default:
break;
}
// Destination Address
if ( GetM () == false)
{
// unicast
switch (GetDam () )
{
case HC_INLINE:
i.Write (m_dstInlinePart, 16);
break;
case HC_COMPR_64:
i.Write (m_dstInlinePart, 8);
break;
case HC_COMPR_16:
i.Write (m_dstInlinePart, 2);
break;
case HC_COMPR_0:
default:
break;
}
}
else
{
// multicast
switch (GetDam () )
{
case HC_INLINE:
i.Write (m_dstInlinePart, 16);
break;
case HC_COMPR_64:
i.Write (m_dstInlinePart, 6);
break;
case HC_COMPR_16:
i.Write (m_dstInlinePart, 4);
break;
case HC_COMPR_0:
i.Write (m_dstInlinePart, 1);
break;
default:
break;
}
}
}