When the client sends packet to the server, the tag was attached to
the packet, and it is implemented as follows:
******************************************************
void WebClient::HttpGet(std::string url)
{
double current;
//cout<<url<<endl;
std::string request = std::string("GET ").append(url).append(" HTTP/
1.1\r\n\r\n");
const uint8_t* data = reinterpret_cast<const
uint8_t*>(request.data());
cout<<"sending..."<<endl;
//m_socket->Send(data, request.length(), 0);
Ptr<Packet> p=Create<Packet>(data,request.length());
HttpPacketTag tag;
tag.SetSimpleValue (0x1);
uint8_t jjj=tag.GetSimpleValue();
std::cout<<jjj<<std::endl;
p->AddPacketTag (tag);
Ptr<Packet> aCopy = p->Copy ();
// read the tag from the packet copy
HttpPacketTag tagCopy;
aCopy->PeekPacketTag (tagCopy);
uint8_t jj=tagCopy.GetSimpleValue();
std::cout<<jj<<std::endl;
m_socket->Send(p);
m_socket->SetRecvCallback (MakeCallback(&WebClient::HandleRead,
this));
Time next(Seconds(interval));
Simulator::ScheduleWithContext(m_socket->GetNode()-
>GetId(),next,&WebClient::HttpGet,this, url);
}
}
************************************************************
When the server received packet from a client, it process the tag as
follows:
void WebServer::Sched()
{
Ptr<Packet> p;
std::string url;
Ipv4Header ipv4;
//TcpHeader tcpheader;
Ipv4Address ip;
//uint16_t port;
HttpPacketTag tag;
//MyHeader myheader;
uint8_t PF;
if (!m_serverQueue.IsEmpty())
{
if(p=m_serverQueue.Dequeue())
{
p->PeekPacketTag (tag);
PF=tag.GetSimpleValue();
std::cout<<jj<<std::endl;
//p->RemoveHeader(myheader);
//PF=myheader.GetData();
p->PeekHeader(ipv4);
ip=ipv4.GetSource();
//p->PeekPacketTag (tag);
//PF=tag.GetSimpleValue();
//std::cout<<PF<<std::endl;
const char* data = reinterpret_cast<const char*>(p->PeekData());
//m_data.append(data,p->GetSize());
url.append(data,p->GetSize());
if (url.length() > 0)
{
ParseHttp(ip.Get(),url,PF);
}
}
}
//cout<<"the length of the queue is
"<<m_serverQueue.GetNPackets()<<endl;
Time next(Seconds(1/static_cast<double> (m_serveRate)));
Simulator::Schedule(next,&WebServer::Sched, this);
std::cout<<Simulator::Now()<<std::endl;
}
The above is the code related to tag.
Moreover, i have another problem about Ipv4Header. When the client
sends packets to a server, it created a packet as: Ptr<Packet>
p=Create<Packet>(), then send out: socket->send(p). Here i do not add
Ipv4Header, yet i can obtain Ipv4Header with PeekHeader(Ipv4Header) at
the server,why?
Thanks Suresh.