packet tag problem

853 views
Skip to first unread message

chanpaul

unread,
Apr 20, 2011, 9:51:48 AM4/20/11
to ns-3-users
Hi everyone, i met a problem with packet tag.
A-----------switch--------------B
A sends packets to B, and attach some tag to all packets from A(e.g.,
0x1). When PeekPacketTag at B, i found that the content of the tag is
changed. Can the packet tag be transmited through the network? Can
anyone help me?

Lalith Suresh

unread,
Apr 20, 2011, 11:58:36 AM4/20/11
to ns-3-...@googlegroups.com
Are you sure you've implemented the serialise/deserialise methods of the tag correctly?
 

--
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To post to this group, send email to ns-3-...@googlegroups.com.
To unsubscribe from this group, send email to ns-3-users+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/ns-3-users?hl=en.




--
Lalith Suresh
Department of Computer Science and Engineering
Instituto Superior Técnico
www.lalith.in

chanpaul

unread,
Apr 21, 2011, 9:47:44 AM4/21/11
to ns-3-users
I modified the example in sample/main-packet-tag.cc, and do nothing to
the serized/deserized function in main-packet-tag.cc

On 4月20日, 下午11时58分, Lalith Suresh <suresh.lal...@gmail.com> wrote:
> *Instituto Superior Técnico*www.lalith.in

Lalith Suresh

unread,
Apr 21, 2011, 11:22:43 AM4/21/11
to ns-3-...@googlegroups.com


2011/4/21 chanpaul <wangj...@gmail.com>

I modified the example in sample/main-packet-tag.cc, and do nothing to
the serized/deserized function in main-packet-tag.cc

If you've changed the fields in the tag, then you need to change the serialise/deserialise methods accordingly.



--
Lalith Suresh
Instituto Superior Técnico
www.lalith.in

chanpaul

unread,
Apr 21, 2011, 9:52:06 PM4/21/11
to ns-3-users
I did not change the tag fields, and my tag definition is as follows:
*******************************************************************
#include "ns3/log.h"
#include "ns3/tag.h"
#include "ns3/packet.h"
#include "ns3/uinteger.h"
#include <iostream>
#include "http-packet-tag.h"
NS_LOG_COMPONENT_DEFINE ("HttpPacketTag");
namespace ns3 {
NS_OBJECT_ENSURE_REGISTERED (HttpPacketTag);

HttpPacketTag::HttpPacketTag()
{
NS_LOG_FUNCTION_NOARGS ();
}
HttpPacketTag::~HttpPacketTag()
{
NS_LOG_FUNCTION_NOARGS ();
}

TypeId
HttpPacketTag::GetTypeId (void)
{
static TypeId tid = TypeId ("ns3::HttpPacketTag")
.SetParent<Tag> ()
.AddConstructor<HttpPacketTag> ()
.AddAttribute ("SimpleValue",
"A simple value",
EmptyAttributeValue (),
MakeUintegerAccessor
(&HttpPacketTag::GetSimpleValue),
MakeUintegerChecker<uint8_t> ())
;
return tid;
}
TypeId
HttpPacketTag::GetInstanceTypeId (void) const
{
return GetTypeId ();
}
uint32_t
HttpPacketTag::GetSerializedSize (void) const
{
return 1;
}
void
HttpPacketTag::Serialize (TagBuffer i) const
{
i.WriteU8 (m_simpleValue);
}
void
HttpPacketTag::Deserialize (TagBuffer i)
{
m_simpleValue = i.ReadU8 ();
}
void
HttpPacketTag::Print (std::ostream &os) const
{
os << "v=" << (uint32_t)m_simpleValue;
}
void
HttpPacketTag::SetSimpleValue (uint8_t value)
{
m_simpleValue = value;
}
uint8_t
HttpPacketTag::GetSimpleValue (void) const
{
return m_simpleValue;
}
}

*******************************************************************


On 4月21日, 下午11时22分, Lalith Suresh <suresh.lal...@gmail.com> wrote:
> 2011/4/21 chanpaul <wangjin...@gmail.com>
> *Instituto Superior Técnico*www.lalith.in

chanpaul

unread,
Apr 21, 2011, 11:00:31 PM4/21/11
to ns-3-users
I just looked up the ns3 manual, and found that
"Add a tag to this packet. This method calls the
* Tag::GetSerializedSize and, then, Tag::Serialize.
*
* Note that this method is const, that is, it does not
* modify the state of this packet, which is fairly
* un-intuitive." (http://www.nsnam.org/docs/manual/html/
packets.html#id1)
It means that AddPacketTag can not modify the packet, thus the packet
tag can not be sended through the network, is it right?

On 4月22日, 上午9时52分, chanpaul <wangjin...@gmail.com> wrote:
> I did not change thetagfields, and mytagdefinition is as follows:
> > If you've changed the fields in thetag, then you need to change the
> > serialise/deserialise methods accordingly.
>
> > > On 4月20日, 下午11时58分, Lalith Suresh <suresh.lal...@gmail.com> wrote:
> > > > On Wed, Apr 20, 2011 at 2:51 PM, chanpaul <wangjin...@gmail.com> wrote:
> > > > > Hi everyone, i met a problem withpackettag.
> > > > > A-----------switch--------------B
> > > > > A sends packets to B, and attach sometagto all packets from A(e.g.,
> > > > > 0x1). When PeekPacketTag at B, i found that the content of thetagis
> > > > > changed. Can thepackettagbe transmited through the network? Can

Lalith Suresh

unread,
Apr 22, 2011, 7:47:33 AM4/22/11
to ns-3-...@googlegroups.com


2011/4/22 chanpaul <wangj...@gmail.com>

I just looked up the ns3 manual, and found that
"Add a tag to this packet. This method calls the
 * Tag::GetSerializedSize and, then, Tag::Serialize.
 *
 * Note that this method is const, that is, it does not
 * modify the state of this packet, which is fairly
 * un-intuitive." (http://www.nsnam.org/docs/manual/html/
packets.html#id1)
It means that AddPacketTag can not modify the packet, thus the packet
tag can not be sended through the network, is it right?

Well, Tags are just pieces of information you attach to the packet without really modifying the packet itself. It's a simulator only mechanism and *does not work* with real world networks (which I guess you're not trying). The code snippet you've attached looks correct at a quick glance, so I'll need to see how you're using the tag to be able to tell what's wrong.



--
Lalith Suresh
Instituto Superior Técnico
www.lalith.in

chanpaul

unread,
Apr 22, 2011, 9:24:48 AM4/22/11
to ns-3-users
Our project is mainly to detect DDoS attackers.I simulate some DDoS
attackers mixed with normal clients. In order to evaluate our
detection algorithm, i need to mark these nodes with packet tag, and
"0" indicates attacker, and "1" indicates normal clients. Combining
this information and the detection results, i can obtain the detection
ratio, false positives, etc.

On 4月22日, 下午7时47分, Lalith Suresh <suresh.lal...@gmail.com> wrote:
> 2011/4/22 chanpaul <wangjin...@gmail.com>
> *Instituto Superior Técnico*www.lalith.in

Lalith Suresh

unread,
Apr 22, 2011, 1:08:56 PM4/22/11
to ns-3-...@googlegroups.com


2011/4/22 chanpaul <wangj...@gmail.com>

Our project is mainly to detect DDoS attackers.I simulate some DDoS
attackers mixed with normal clients. In order to evaluate our
detection algorithm, i need to mark these nodes with packet tag, and
"0" indicates attacker, and "1" indicates normal clients. Combining
this information and the detection results, i can obtain the detection
ratio, false positives, etc.

Yes, but I meant that I'd like to see the sections of the code where you're handling tags to be able to tell what's wrong. :)



--
Lalith Suresh
Instituto Superior Técnico
www.lalith.in

chanpaul

unread,
Apr 22, 2011, 10:07:02 PM4/22/11
to ns-3-users
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.

Sakshi

unread,
Apr 30, 2014, 2:11:04 AM4/30/14
to ns-3-...@googlegroups.com
Hi Chanpaul,

I am facing the same problem.

https://groups.google.com/forum/#!topic/ns-3-users/jqh3Iv7RqJI

Pl. reply.

Thank you,
Reply all
Reply to author
Forward
0 new messages