- def log(cls, s, v=1):
- if cls.verbose >= v:
- print "LOG: " + LPURPLE + s + END
-
- ## Class method to execute api commands.
- # Based on set level of verbosity print the output of the api command in
- # the terminal.
- # @param cls The class pointer.
- # @param s String variable to store api command string.
- @classmethod
- def api(cls, s):
- p = subprocess.Popen(cls.vpp_api_test_cmdline,
- stdout=subprocess.PIPE,
- stdin=subprocess.PIPE,
- stderr=subprocess.PIPE)
- if cls.verbose > 0:
- print "API: " + RED + s + END
- p.stdin.write(s)
- out = p.communicate()[0]
- out = out.replace("vat# ", "", 2)
- if cls.verbose > 0:
- if len(out) > 1:
- print YELLOW + out + END
- ## @var p
- # Object variable to store file descriptor of vpp_api_test subprocess
- # with open pipes to the standard output, inputs and error streams.
- ## @var out
- # Tuple variable to store standard output of vpp_api_test subprocess
- # where the string "vat# " is replaced by empty string later.
-
- ## Class method to execute cli commands.
- # Based on set level of verbosity of the log and verbosity defined by
- # environmental variable execute the cli command and print the output in
- # the terminal.
- # CLI command is executed via vpp API test tool (exec + cli_command)
- # @param cls The class pointer.
- # @param v Integer variable to store required level of verbosity.
- # @param s String variable to store cli command string.
- @classmethod
- def cli(cls, v, s):
- if cls.verbose < v:
- return
- p = subprocess.Popen(cls.vpp_api_test_cmdline,
- stdout=subprocess.PIPE,
- stdin=subprocess.PIPE,
- stderr=subprocess.PIPE)
- if cls.verbose > 0:
- print "CLI: " + RED + s + END
- p.stdin.write('exec ' + s)
- out = p.communicate()[0]
- out = out.replace("vat# ", "", 2)
- if cls.verbose > 0:
- if len(out) > 1:
- print YELLOW + out + END
- ## @var p
- # Object variable to store file descriptor of vpp_api_test subprocess
- # with open pipes to the standard output, inputs and error streams.
- ## @var out
- # Tuple variable to store standard output of vpp_api_test subprocess
- # where the string "vat# " is replaced by empty string later.
-
- ## Class method to create incoming packet stream for the packet-generator
- # interface.
- # Delete old /tmp/pgX_in.pcap file if exists and create the empty one and
- # fill it with provided packets and add it to pg_streams list.
- # @param cls The class pointer.
- # @param i Integer variable to store the index of the packet-generator
- # interface to create packet stream for.
- # @param pkts List variable to store packets to be added to the stream.
- @classmethod
- def pg_add_stream(cls, i, pkts):
- os.system("rm -f /tmp/pg%u_in.pcap" % i)
- wrpcap("/tmp/pg%u_in.pcap" % i, pkts)
- # no equivalent API command
- cls.cli(0, "packet-generator new pcap /tmp/pg%u_in.pcap source pg%u"
- " name pcap%u" % (i, i, i))
- cls.pg_streams.append('pcap%u' % i)
-
- ## Class method to enable packet capturing for the packet-generator
- # interface.
- # Delete old /tmp/pgX_out.pcap file if exists and set the packet-generator
- # to capture outgoing packets to /tmp/pgX_out.pcap file.
- # @param cls The class pointer.
- # @param args List variable to store the indexes of the packet-generator
- # interfaces to start packet capturing for.