1 ##############################################################################
2 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
12 import vstf.common.decorator as deco
13 from vstf.common.utils import kill_by_name, my_popen
17 LOG = logging.getLogger(__name__)
22 self._send_processes = []
23 self._receive_processes = []
25 @deco.check("protocol", choices=['udp_bw'], defaults='udp_bw')
26 @deco.check("namespace", defaults=None)
29 @deco.check("size", defaults=64)
30 @deco.check("threads", defaults=1)
31 @deco.check("ratep", defaults=0)
32 def send_start(self, **kwargs):
33 cmd = self.format_send_start(**kwargs)
34 LOG.info("cmd:%s", cmd)
36 process = my_popen(cmd.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
37 self._send_processes.append(process)
43 error_str = "start netmap send success"
45 error_str = "start netmap send failed, %s" % (str(kwargs))
47 self._send_processes.remove(process)
51 def send_stop(self, **kwargs):
55 for process in self._send_processes:
58 error_str = "stop netmap send success"
59 results.append((ret, error_str))
60 self._send_processes = []
63 def format_send_start(self, **kwargs):
64 cmd = "pkt-gen -i %(src_iface)s -f tx -l %(pkt_size)s -p %(threads)s -D %(dst_mac)s -R %(ratep)s"
66 'src_iface': kwargs['src'][0]['iface'],
67 'dst_mac': kwargs['dst'][0]['mac'],
68 'pkt_size': kwargs['size'],
69 'threads': kwargs['threads'],
70 'ratep': kwargs['ratep']
76 def format_receive_start(self, **kwargs):
77 cmd = "pkt-gen -i %(iface)s -f rx"
79 'iface': kwargs['dst'][0]['iface']
84 @deco.check("protocol", choices=['udp_bw'], defaults='udp_bw')
85 @deco.check("namespace", defaults=None)
87 def receive_start(self, **kwargs):
89 cmd = self.format_receive_start(**kwargs)
90 LOG.info("cmd:%s", cmd)
92 process = my_popen(cmd.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
93 self._receive_processes.append(process)
99 error_str = "start netmap receive success"
101 error_str = "start netmap receive failed, %s" % (str(kwargs))
103 self._receive_processes.remove(process)
105 return ret, error_str
107 def receive_stop(self, **kwargs):
108 LOG.info("receive_stop")
110 for process in self._receive_processes:
113 self._receive_processes = []
114 error_str = "stop netmap receive success"
115 self._receive_processes = []
116 return ret, error_str
123 def force_clean(self):
124 LOG.info("%s %s start", self.__class__, self.force_clean.__name__)
125 kill_by_name('pkt-gen')
126 self._send_processes = []
127 self._receive_processes = []
134 "protocol": "udp_bw",
135 # "namespace": "receive",
140 ret = perf.receive_start(**receive)
141 LOG.info("*********receive_start***********")
144 # "namespace": "send",
145 "protocol": "udp_bw",
147 {"iface": "eth4", "mac": "90:e2:ba:20:1f:d8"}
150 {"mac": "90:e2:ba:20:1f:d9"}
156 print perf.send_start(**send)
157 print perf._send_processes
160 print perf.send_stop()
161 print perf.receive_stop()
164 if __name__ == "__main__":
165 from vstf.common.log import setup_logging
167 setup_logging(level=logging.DEBUG, log_file="/var/log/vstf/vstf-netmap.log", clevel=logging.INFO)