def do_ipv4(self, args): grc.debug("In Function {0}".format(inspect.stack()[0][3])) grc.debug("IPv4 define args {0}".format(args)) j={} arg_lst=args.split() if len(arg_lst) < 2: self.help_ipv4() return arg_d = dict(zip(arg_lst[::2], [arg_lst[i] for i in range(1, len(arg_lst), 2)])) j['sip']=struct.unpack("@i", socket.inet_pton(socket.AF_INET, arg_d['sip']))[0] j['dip']=struct.unpack("@i", socket.inet_pton(socket.AF_INET, arg_d['dip']))[0] if 'ttl' in arg_d: j['ttl']=int(arg_d['ttl']) if 'protocol' in arg_d: j['protocol']=int(arg_d['protocol']) if 'payload' in arg_d: j['payload']=arg_d['payload'] if 'dscp' in arg_d: j['dscp']=int(arg_d['dscp']) self.l3_dict['ipv4']=j
def do_rate(self, args): grc.debug("In Function {0}".format(inspect.stack()[0][3])) r_list=args.split() if len(r_list) < 2: self.help_rate() return if r_list[0]=='pps': if not r_list[1]: self.help_rate() return self.param_dict['rate_pps']=int(r_list[1]) elif r_list[0]=='bps': if not r_list[1]: self.help_rate() return bps=int(r_list[1]) if r_list[2]: if r_list[2]=='KBps': bps=bps*1024*8 if r_list[2]=='MBps': bps=bps*1024*1024*8 if r_list[2]=='GBps': bps=bps*1024*1024*1024*8 self.param_dict['rate_bps']=bps else: self.help_rate() return
def do_payload(self, args): grc.debug("In Function {0}".format(inspect.stack()[0][3])) grc.debug("Payload define args {0}".format(args)) j={} arg_lst=args.split() if len(arg_lst) < 2: self.help_payload() return arg_d = dict(zip(arg_lst[::2], [arg_lst[i] for i in range(1, len(arg_lst), 2)])) if 'increment' == arg_d['value']: j['value_type']=1 if 'step' in arg_d: j['step']=int(arg_d['step']) elif 'random' == arg_d['value']: j['value_type']=2 else: j['value']=arg_d['value'] j['value_type']=0 if 'size' in arg_d: j['size']=int(arg_d['size']) self.l7_dict['payload']=j
def do_l7(self, args): grc.debug("In Function {0}".format(inspect.stack()[0][3])) l_dict={} p_cli=pkt.l7_cli(l_dict) p_cli.cmdloop() self.pkt_dict['l7']=l_dict
def do_custom(self, args): grc.debug("In Function {0}".format(inspect.stack()[0][3])) l_dict={} p_cli=pkt.customPkt_cli(l_dict) p_cli.cmdloop() self.pkt_dict['custom']=l_dict
def main(): grc.debug("In Function {0}".format(inspect.stack()[0][3])) prep() start() cleanup()
def do_udp(self, args): grc.debug("In Function {0}".format(inspect.stack()[0][3])) grc.debug("UDP define args {0}".format(args)) j={} arg_lst=args.split() if len(arg_lst) < 2: self.help_udp() return arg_d = dict(zip(arg_lst[::2], [arg_lst[i] for i in range(1, len(arg_lst), 2)])) j['sport']=int(arg_d['sport']) j['dport']=int(arg_d['dport']) self.l4_dict['udp']=j
def do_duration(self, args): grc.debug("In Function {0}".format(inspect.stack()[0][3])) r_list=args.split() if len(r_list) < 2: self.help_duration() return if r_list[0]=='max': if not r_list[1]: self.help_duration() return self.param_dict['duration_max']=int(r_list[1]) else: self.help_duration() return
def do_packet(self, args): grc.debug("In Function {0}".format(inspect.stack()[0][3])) pkt_dict={} p_cli=genPkt_cli(pkt_dict) p_cli.cmdloop() j_dict={} j_dict['generator_packet']=pkt_dict #Send the packet definitions to generator process grc.jdump(j_dict, self.p_ref.stdin) self.p_ref.poll() if self.p_ref.returncode != None: grc.error("Generator process terminated") else: grc.debug("Generator process still active")
def do_ethernet(self, args): grc.debug("In Function {0}".format(inspect.stack()[0][3])) grc.debug("Ethernet define args {0}".format(args)) j={} arg_lst=args.split() if len(arg_lst) < 3: self.help_ethernet() return arg_d = dict(zip(arg_lst[::2], [arg_lst[i] for i in range(1, len(arg_lst), 2)])) j['smac']=arg_d['smac'] j['dmac']=arg_d['dmac'] if 'ethertype' in arg_d: j['ethertype']=int(arg_d['ethertype'], 16) if 'payload' in arg_d: j['payload']=arg_d['payload'] self.l2_dict['ethernet']=j
def __del__(self): grc.debug("Finalized {0} class".format(self.__class__)) grc.comCls.__del__(self)
def cleanup(): grc.debug("In Function {0}".format(inspect.stack()[0][3]))
def help_duration(self): grc.debug("In Function {0}".format(inspect.stack()[0][3])) print (" Packet generation duration ") print (" duration <val> ")
def help_receiver(self): grc.debug("In Function {0}".format(inspect.stack()[0][3])) print (" Receiver subcommands ")
def start(): grc.debug("In Function {0}".format(inspect.stack()[0][3])) cpg_cli=cpackgen_cli() cpg_cli.cmdloop()
def help_parameter(self): grc.debug("In Function {0}".format(inspect.stack()[0][3])) print (" Generator Parameters ")
def do_receiver(self, args): grc.debug("In Function {0}".format(inspect.stack()[0][3])) rcv_cli=rcv.receiver_cli() rcv_cli.cmdloop()
def __init__(self): grc.debug("Initialized {0} class".format(self.__class__)) cli_fmwk.VCCli.__init__(self, intro="cpackgen cli", prompt="(cpackgen)")
def do_generator(self, args): grc.debug("In Function {0}".format(inspect.stack()[0][3])) gen_cli=gen.generator_cli() gen_cli.cmdloop()
def help_save(self): grc.debug("In Function {0}".format(inspect.stack()[0][3])) print (" Save captured packets ")
def help_count(self): grc.debug("In Function {0}".format(inspect.stack()[0][3])) print (" Packet count ") print (" count max <val> ")
def help_custom(self): grc.debug("In Function {0}".format(inspect.stack()[0][3])) print (" Custom packet definition subcommands ")
def __init__(self): grc.debug("Initialized {0} class".format(self.__class__)) grc.comCls.__init__(self, "Generator subcommands", 'cpackgen:Generator)', 'generator')
def help_l7(self): grc.debug("In Function {0}".format(inspect.stack()[0][3])) print (" Layer 7 packet definition subcommands ")
def help_filter(self): grc.debug("In Function {0}".format(inspect.stack()[0][3])) print (" Receiver Filters ")
def help_generator(self): grc.debug("In Function {0}".format(inspect.stack()[0][3])) print (" Generator subcommands ")
def do_save(self, args): grc.debug("In Function {0}".format(inspect.stack()[0][3])) grc.jdump('save', self.p_ref.stdin)
def help_packet(self): grc.debug("In Function {0}".format(inspect.stack()[0][3])) print (" Generator Packet definitions ")
def __init__(self): grc.debug("Initialized {0} class".format(self.__class__)) grc.comCls.__init__(self, "Receiver subcommands", 'cpackgen:Receiver)', 'receiver')
def __init__(self, d): grc.debug("Initialized {0} class".format(self.__class__)) cli_fmwk.VCCli.__init__(self, intro="Generator packet definitions cli", prompt="(cpackgen:Generator:Packet)") self.pkt_dict=d