Example #1
0
    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
Example #2
0
    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
Example #3
0
    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
Example #4
0
    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
Example #5
0
    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
Example #6
0
def main():
    grc.debug("In Function {0}".format(inspect.stack()[0][3]))

    prep()

    start()

    cleanup()
Example #7
0
    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
Example #8
0
    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
Example #9
0
    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")
Example #10
0
    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
Example #11
0
 def __del__(self):
     grc.debug("Finalized {0} class".format(self.__class__))
     grc.comCls.__del__(self)
Example #12
0
def cleanup():
    grc.debug("In Function {0}".format(inspect.stack()[0][3]))
Example #13
0
 def help_duration(self):
     grc.debug("In Function {0}".format(inspect.stack()[0][3]))
     print ("     Packet generation duration     ")
     print ("          duration <val>            ")
Example #14
0
 def help_receiver(self):
     grc.debug("In Function {0}".format(inspect.stack()[0][3]))
     print ("     Receiver subcommands     ")
Example #15
0
def start():
    grc.debug("In Function {0}".format(inspect.stack()[0][3]))

    cpg_cli=cpackgen_cli()
    cpg_cli.cmdloop()
Example #16
0
 def help_parameter(self):
     grc.debug("In Function {0}".format(inspect.stack()[0][3]))
     print ("     Generator Parameters     ")
Example #17
0
    def do_receiver(self, args):
        grc.debug("In Function {0}".format(inspect.stack()[0][3]))

        rcv_cli=rcv.receiver_cli()
        rcv_cli.cmdloop()
Example #18
0
 def __init__(self):
     grc.debug("Initialized {0} class".format(self.__class__))
     cli_fmwk.VCCli.__init__(self, intro="cpackgen cli",
                             prompt="(cpackgen)")
Example #19
0
    def do_generator(self, args):
        grc.debug("In Function {0}".format(inspect.stack()[0][3]))

        gen_cli=gen.generator_cli()
        gen_cli.cmdloop()
Example #20
0
 def help_save(self):
     grc.debug("In Function {0}".format(inspect.stack()[0][3]))
     print ("      Save captured packets     ")
Example #21
0
 def help_count(self):
     grc.debug("In Function {0}".format(inspect.stack()[0][3]))
     print ("     Packet count     ")
     print ("          count max <val> ")
Example #22
0
 def help_custom(self):
     grc.debug("In Function {0}".format(inspect.stack()[0][3]))
     print ("     Custom packet definition subcommands         ")
Example #23
0
 def __init__(self):
     grc.debug("Initialized {0} class".format(self.__class__))
     grc.comCls.__init__(self, "Generator subcommands",
                         'cpackgen:Generator)', 'generator')
Example #24
0
 def help_l7(self):
     grc.debug("In Function {0}".format(inspect.stack()[0][3]))
     print ("     Layer 7 packet definition subcommands         ")
Example #25
0
 def help_filter(self):
     grc.debug("In Function {0}".format(inspect.stack()[0][3]))
     print ("     Receiver Filters     ")
Example #26
0
 def help_generator(self):
     grc.debug("In Function {0}".format(inspect.stack()[0][3]))
     print ("     Generator subcommands     ")
Example #27
0
 def do_save(self, args):
     grc.debug("In Function {0}".format(inspect.stack()[0][3]))
     grc.jdump('save', self.p_ref.stdin)
Example #28
0
 def help_packet(self):
     grc.debug("In Function {0}".format(inspect.stack()[0][3]))
     print ("     Generator Packet definitions     ")
Example #29
0
 def __init__(self):
     grc.debug("Initialized {0} class".format(self.__class__))
     grc.comCls.__init__(self, "Receiver subcommands",
                         'cpackgen:Receiver)', 'receiver')
Example #30
0
 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