[Click] using RatedSource to send packets
Yogesh Mundada
yogesh.mundada at gmail.com
Wed Sep 1 12:37:29 EDT 2010
I wanted to use RatedSource to bombard the same packet. I used scapy
to generate this packet and then to create a Click config file
dynamically. Here is a python function to do so (Hope that it will be
useful to you in some way):
class PacketGeneratorWithDynamicPacket(Node):
def generate_click_config(self, pkt_rate, total_pkts, interface,
dut_type = 'switch', udp_payload_size = 1):
"""
Generate the packet yourself using scapy and then use Click to
send it at a specific rate
"""
dst_mac_addr = ((dut_type == 'switch') and
[self.sink_mac_addr] or [self.dut_my_interface_mac_addr])[0]
src_mac_addr = self.mac_addr
dst_ip_addr = self.sink_ip_addr
src_ip_addr = self.ip_addr
src_port = self.port
dst_port = self.dst_port
# Raw data is varied to change packet size
pkt = scapy.Ether(dst=dst_mac_addr, src=src_mac_addr, type=0x800) \
/scapy.IP(len=30,id=42807,flags="DF",ttl=64,proto="udp",src=src_ip_addr,dst=dst_ip_addr)
\
/scapy.UDP(sport=src_port,dport=dst_port) \
/scapy.Raw(load='%s' % ('Y' * udp_payload_size))
pkt_str = binascii.b2a_hex((str(pkt)))
print "Packet size is %d\n" % (len(pkt_str)/2)
click_config = """
src :: RatedSource(DATA \<
%s
>, RATE %s, LIMIT %s);
src_iface :: ToDevice(%s);
src -> src_iface;
"""
self.click_config_fname = '/tmp/click_%d.config' % (pkt_rate)
final_conf = click_config % (pkt_str,
str(pkt_rate),str(total_pkts), interface)
self.execute('echo "%s" > %s' % (final_conf,self.click_config_fname))
More information about the click
mailing list