FastUDPFlows with fixed port addresses

YWG youngwk at yahoo.com
Fri Jul 6 20:52:32 EDT 2001


Hi,

Currently, the FastUDPFlows element creates UDP/IP packets with
source/destination port addresses that are randomly generated. I would
like to modify this element to produce packets with preassigned port
addresses.

The significant changes I made are ;
1. Adding a new parameter port_addr to change_ports() such that I assign
the port_addr directly into the udp source and destination port address
instead of having them being generated randomly.

2. Created a new variable _start_portaddr which contains the port
address of the packets of the first flow. Subsequent flows will get port
addresses that are obtained by incrementing _start_portaddr by 1. For
example, if the _start_portaddr==1000, then packets of the 1st flow
should get port addresses 1000 and the packets of the second flow 1001
and so on.

My problem is that, for example when I use _start_portaddr==1000, the
actual port address of the packets belonging to the first flow is 59395.
The 2nd and 3rd flows' port addresses are 59651 and 59907. Why are the
port addresses of each flow incremented by 256 and not by 1? Why is the
Actual_port_addr==(_start_portaddr*256)%(0xFFFF) and not
Actual_port_addr==_start_portaddr?

Regards
Wei Kuan


Below shows some of the code changes I made. The initialization stuff
are not included.
---------------------------------------------------------------------------

void
FastUDPFlowsPort::change_ports(int flow, unsigned short port_addr)
{
  click_ip *ip = reinterpret_cast<click_ip
*>(_flows[flow].packet->data()+14);
  click_udp *udp = reinterpret_cast<click_udp *>(ip + 1);

  udp->uh_sport = port_addr;
  udp->uh_dport = port_addr;
  udp->uh_sum = 0;
  unsigned short len = _len-14-sizeof(click_ip);
  if (_cksum) {
    unsigned csum = ~in_cksum((unsigned char *)udp, len) & 0xFFFF;
    udp->uh_sum = csum_tcpudp_magic(_sipaddr.s_addr, _dipaddr.s_addr,
        len, IP_PROTO_UDP, csum);
  } else
    udp->uh_sum = 0;
}

Packet *
FastUDPFlowsPort::get_packet()
{
#if 0
  int flow = _last_flow;
  _last_flow = _last_flow+1;
  if (_last_flow >= _nflows) _last_flow = 0;
#else
  int flow = (random() >> 2) % _nflows;
#endif

  if (_flows[flow].flow_count == _flowsize) {
    change_ports(flow,_assigned_portaddr);

  //Put code for  round-robin manipulation of _assigned_portaddr;
  // _nflows = number of flows. _stop_portaddr=_start_portaddr +
_nflows-1
  // _stop_portaddr was created by me

  _assigned_portaddr++;
  if (_assigned_portaddr > _stop_portaddr ){
    _assigned_portaddr=_start_portaddr;
  }

    _flows[flow].flow_count = 0;
  }
  _flows[flow].flow_count++;
  atomic_inc(&(_flows[flow].skb)->users);
  return reinterpret_cast<Packet *>(_flows[flow].skb);
}




More information about the click mailing list