Packet::EnablePrinting ();
MyHeader sourceHeader;
sourceHeader.SetData (m_header);
p = Create<Packet> (m_size);
p->AddHeader (sourceHeader);
p->Print (std::cout);
std::cout << std::endl;
and in the receiver application side
MyHeader destinationheader;
packet->RemoveHeader (destinationheader);
destinationheader.Print(std::cout);
std::cout << std::endl;
uint16_t data= destinationheader.GetData ();
The problem is i send for example data=2
when I print the destinationheader i got data=2
But with the GetData() method i got 12.
data=2
At time 1718.01s participant received 1024 bytes from 10.1.1.1 port 49153 as 12
What is the problem?
Regards
void
AppRequestor::Send (void)
{
NS_LOG_FUNCTION (this);
NS_ASSERT (m_sendEvent.IsExpired ());
double d = AppRequestor::distance(m_node1);
if (d<=10) {
Packet::EnablePrinting ();
MyHeader sourceHeader;
sourceHeader.SetData (m_header);
Ptr<Packet> p;
//Add the new header to this packet
if (m_dataSize)
{
//
// If m_dataSize is non-zero, we have a data buffer of the same size that we
// are expected to copy and send. This state of affairs is created if one of
// the Fill functions is called. In this case, m_size must have been set
// to agree with m_dataSize
//
NS_ASSERT_MSG (m_dataSize == m_size, "AppRequestor::Send(): m_size and m_dataSize inconsistent");
NS_ASSERT_MSG (m_data, "AppRequestor::Send(): m_dataSize but no m_data");
p = Create<Packet> (m_data, m_dataSize);
p->AddHeader (sourceHeader);
p->Print (std::cout);
std::cout << std::endl;
}
else
{
//
// If m_dataSize is zero, the client has indicated that it doesn't care
// about the data itself either by specifying the data size by setting
// the corresponding attribute or by not calling a SetFill function. In
// this case, we don't worry about it either. But we do allow m_size
// to have a value different from the (zero) m_dataSize.
//
p = Create<Packet> (m_size);
p->AddHeader (sourceHeader);
p->Print (std::cout);
std::cout << std::endl;
}
// call to the trace sinks before the packet is actually sent,
// so that tags added to the packet can be sent as well
m_txTrace (p);
m_socket->Send (p);
++m_sent;
if (Ipv4Address::IsMatchingType (m_peerAddress))
{
NS_LOG_INFO ("At time " << Simulator::Now ().GetSeconds () << "s requestor sent " << m_size << " bytes to " <<
Ipv4Address::ConvertFrom (m_peerAddress) << " port " << m_peerPort);
}
}
if (m_sent < m_count)
{
ScheduleTransmit (m_interval);
}
}
When Receive:
void
AppParticipant::HandleRead (Ptr<Socket> socket)
{
NS_LOG_FUNCTION (this << socket);
Ptr<Packet> packet= Create<Packet> (m_size);
Address from;
//Ptr<Packet> packet = socket->RecvFrom (from);
while ((packet = socket->RecvFrom (from)))
{
if (InetSocketAddress::IsMatchingType (from))
{
MyHeader destinationheader;
packet->RemoveHeader (destinationheader);
destinationheader.Print(std::cout);
std::cout << std::endl;
uint16_t data= destinationheader.GetData ();
NS_LOG_INFO ("At time " << Simulator::Now ().GetSeconds () << "s participant received " << packet->GetSize () << " bytes from " <<
InetSocketAddress::ConvertFrom (from).GetIpv4 () << " port " <<
InetSocketAddress::ConvertFrom (from).GetPort () << " as " << std::cout << data << std::endl);
}
packet->RemoveAllPacketTags ();
packet->RemoveAllByteTags ();
NS_LOG_LOGIC ("Responding");
socket->SendTo (packet, 0, from);
if (InetSocketAddress::IsMatchingType (from))
{
NS_LOG_INFO ("At time " << Simulator::Now ().GetSeconds () << "s participant sent " << packet->GetSize () << " bytes to " <<
InetSocketAddress::ConvertFrom (from).GetIpv4 () << " port " <<
InetSocketAddress::ConvertFrom (from).GetPort ());
}
}
}
There is :