[Click] Basic question about IP header fields.
Beyers Cronje
bcronje at gmail.com
Thu Oct 25 17:19:50 EDT 2007
Hi,
See [click]/include/click/ipflowid.hh , the IPFlowID class has a hashcode()
function. Then use Click's HashMap [click]/include/click/hashmap.hh to keep
state of the flows. Grep for HashMap and/or IPFlowID under [click]/elements
to find examples on how it's used.
Beyers
On 10/25/07, Josh Butler <J.R.Butler-05 at student.lboro.ac.uk> wrote:
>
> Hi,
>
> Thanks again, another problem solved. But another one begins. Those
> elements I've created are dead simple, I want to do something a bit more
> complicated. I'm planning on creating an element that creates a flow id for
> packets based on their source and destination addresses and ports.
> Apparently I need to take each of those fields and do an XOR (^) on them to
> get a hash value that I can use as a flow ID - does that sound right? My
> first issue is that I can't manipulate the IP addresses as I would the other
> header fields. So doing this is not as straight forward as I though it would
> be. How can I do this?
>
> I then need to store this flow ID in an array, so that any subsequent
> packets with the same ID are identifiable. But I can't really approach this
> until I know how to create the hash value first, so any help on that would
> be much appreciated.
>
> Regards
> Josh
>
> ----- Original Message -----
> *From:* Beyers Cronje <bcronje at gmail.com>
> *To:* tuna_armadillo at hotmail.com
> *Cc:* click at amsterdam.lcs.mit.edu
> *Sent:* Tuesday, October 23, 2007 3:50 AM
> *Subject:* Re: [Click] Basic question about IP header fields.
>
> Hi Josh,
>
> The ip_len field is in network byte order, assuming you are running on an
> Intel platform you need to convert it to host byte order using
> ntohs(iph->ip_len)
>
> Google on these terms: ntohs, ntohl, endianness, network byte order, host
> byte order
>
> See http://en.wikipedia.org/wiki/Endianness for an overview.
>
> Beyers
>
>
> On 10/23/07, Nikki <tuna_armadillo at hotmail.com> wrote:
> >
> > Hi guys,
> >
> > Firstly, many many thanks for the help, its been great - I've only just
> > got round to putting it into practice now I've got most of the theory
> > out of the way, but the code you gave me has worked a treat. I think I
> > need to read up on pointers a bit more to fully understand it, but I
> > think I see what its doing.
> >
> > So anyway, on to my new question. I tried messing around with the code,
> > in my new element and it now looks like this:
> >
> > const click_ip *iph = p->ip_header(); // Get pointer to IP Header
> >
> > if (!iph){ // Make sure it's a valid header
> > p->kill();
> > return;
> > }
> > else if (iph->ip_len <= 1000){ // Check Total Length field
> > output(0).push(p);
> > }
> > else{
> > output(1).push(p);
> > }
> >
> > I want to split packets through different outputs depending on packet
> > size, but the code above just pushes everything through output 1. I'm
> > using FromDump in my config script, and am using a dump with packets of
> > varying sizes, from 40 to 1420 bytes - but they all come out of output
> > 1, not output 0. Where am I going wrong?
> >
> > Thanks,
> > Josh
> >
> >
> > On Tue, 2007-09-11 at 01:02 +0200, Beyers Cronje wrote:
> > > Josh,
> > >
> > > And so I inadvertently demonstrated one of the classic beginner
> > > mistakes to watch out for :) Always either push/pull, kill or store
> > > the packet for later use...
> > >
> > >
> > > On 9/11/07, Eddie Kohler <kohler at cs.ucla.edu> wrote:
> > > Thanks, Beyers -- but I'd either "assert(iph)" or "if (!iph) {
> >
> > > p->kill(); return; }", to avoid leaking memory.
> > > E
> > >
> > >
> > > Beyers Cronje wrote:
> > > > Hi Josh,
> > > >
> > > > You need to get a pointer to the IP Header. A simple
> > > example:
> > > >
> > > > const click_ip *iph = p->ip_header(); // Get pointer to IP
> > > Header
> > > > if (!iph) // Make sure it's a valid header
> > > > return;
> > > >
> > > > if (iph->ip_tos <= n) // Check TOS field
> > > > output(0).push(p);
> > > > else
> > > > output(1).push(p)
> > > >
> > > > The above example expects IP packets. So you'll have to
> > > filter on IP packets
> > > > and also set the IP header annotations i.e.:
> > > >
> > > > FromDevice(eth0) -> Classifier(12/0800) -> MarkIPHeader(14)
> > > -> YourElement;
> > > >
> > > > Classifier to filter IP packets, and MarkIPHeader to set
> > > annotations. You
> > > > can also use CheckIPHeader instead of MarkIPHeader.
> > > >
> > > > Hope this helps.
> > > >
> > > > Beyers
> > > >
> > > > On 9/10/07, Josh Butler <tuna_armadillo at hotmail.com> wrote:
> > > >> Hi,
> > > >>
> > > >> This is my first question and probably won't be my last.
> > > I've been doing a
> > > >> project involving Click for a while, but owing to my very
> > > basic programming
> > > >> skills have struggled quite a lot, though I've enjoyed
> > > messing about with
> > > >> click in the process - I've been writing a bit of an
> > > idiot's guide as I've
> > > >> gone along!
> > > >>
> > > >> I've got my head round creating the router configuration
> > > scripts by
> > > >> combining elements and am now looking to go inside the
> > > elements and make
> > > >> some changes. I've chosen the tee element as one of the
> > > easier elements to
> > > >> look at and modify, and have a good understanding of what
> > > it does in push
> > > >> mode.
> > > >>
> > > >> I now want to modify this element in a very basic way,
> > > using a simple if
> > > >> statement if possible so that I can push packets through
> > > either the
> > > >> element's first or second output port depending on some
> > > criteria such as the
> > > >> type of service field within the IP header. Here's what I
> > > mean in
> > > >> pseudocode, if that's the correct term;
> > > >>
> > > >> if (type_of_service_field <= n){
> > > >> output(0).push(p);
> > > >> }
> > > >> else {
> > > >> output(1).push(p);
> > > >> }
> > > >>
> > > >> I've looked through all the material on the click site and
> > > can't find a
> > > >> simple answer to the question of how to access the
> > > different fields within
> > > >> the IP header. Maybe I'm being stupid, but a bit of help
> > > would be awesome.
> > > >>
> > > >> Thanks,
> > > >> Josh
> > > >>
> > > >>
> > >
> > _________________________________________________________________
> > > >> 100's of Music vouchers to be won with MSN Music
> > > >> https://www.musicmashup.co.uk
> > > >> _______________________________________________
> > > >> click mailing list
> > > >> click at amsterdam.lcs.mit.edu
> > > >> https://amsterdam.lcs.mit.edu/mailman/listinfo/click
> > > >>
> > > > _______________________________________________
> > > > click mailing list
> > > > click at amsterdam.lcs.mit.edu
> > > > https://amsterdam.lcs.mit.edu/mailman/listinfo/click
> > >
> >
> >
> >
>
More information about the click
mailing list