Questions about element programming....

Brecht Vermeulen brecht.vermeulen at rug.ac.be
Wed Mar 20 00:36:09 EST 2002


Hi Juan,

> 
> 1. In the programming manual it says that every element have to implement notify_ninputs y notify_noutputs to create it respectives inputs y outputs, but in FtpPortMapper they are no such functions. Why?
> 

I've read in the manual :
 - Method on Element: virtual void notify_ninputs (int NINPUTS)
 - Method on Element: virtual void notify_noutputs (int NOUTPUTS)
     The NINPUTS and NOUTPUTS arguments specify how many input and
     output ports were used in the configuration. For example, if
     NINPUTS is 5, then input ports 0 through 4 were used.(1)
 
     These methods' default implementations do nothing.

so there's a default implementation and you only have to use these
functions if you want to be notified how many ports are used, as far as
I see. I think you will mostly use these if your element has a variable
number of ports and you want to know how many ports are connected.
Is it stated somewhere in the manual that you *have* to implement them ?

> 2. How can I distinguish between an IPv4 packet and a IPv6 packet? I want to have an input for ipv4 packets and another for ipv6 packets, but I'm not sure how to do that.
> 3.How can I know from wich input the packet comes from? (a way to know if a packet is IPv4/IPv6)

well, e.g. in elements/ethernet/arpquerier.cc :
void
ARPQuerier::push(int port, Packet *p)
{
  if (port == 0)
    handle_ip(p);
  else {
    handle_response(p);
    p->kill();
  }
}

so you get the port in the push call.


For pull:
- Method on Element: virtual Packet * pull (int PORT)
     Called when a downstream element makes a pull request of this
     element's output port PORT. This element is expected to process
     the request however it likes and to return a packet.

so, question 2 is also solved I think if you let the IPv4 and IPv6
packets enter on different ports.

regards,
Brecht



More information about the click mailing list