1 # Copyright 2015 Spirent Communications.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
16 Code to integrate Spirent TestCenter with the vsperf test framework.
18 Provides a model for Spirent TestCenter as a test tool for implementing
19 various performance tests of a virtual switch.
22 from __future__ import print_function
24 from tools.pkt_gen import trafficgen
25 from core.results.results_constants import ResultsConstants
29 from conf import settings
32 class TestCenter(trafficgen.ITrafficGenerator):
48 def send_burst_traffic(self, traffic=None, numpkts=100, duration=20, framerate=100):
54 def send_cont_traffic(self, traffic=None, duration=30, framerate=0,
61 def send_rfc2544_throughput(self, traffic=None, trials=3, duration=20,
62 lossrate=0.0, multistream=False):
64 Send traffic per RFC2544 throughput test specifications.
68 args = [settings.getValue("TRAFFICGEN_STC_PYTHON2_PATH"),
69 os.path.join(settings.getValue("TRAFFICGEN_STC_TESTCENTER_PATH"),
70 settings.getValue("TRAFFICGEN_STC_RFC2544_TPUT_TEST_FILE_NAME")),
72 settings.getValue("TRAFFICGEN_STC_LAB_SERVER_ADDR"),
73 "--license_server_addr",
74 settings.getValue("TRAFFICGEN_STC_LICENSE_SERVER_ADDR"),
75 "--east_chassis_addr",
76 settings.getValue("TRAFFICGEN_STC_EAST_CHASSIS_ADDR"),
78 settings.getValue("TRAFFICGEN_STC_EAST_SLOT_NUM"),
80 settings.getValue("TRAFFICGEN_STC_EAST_PORT_NUM"),
81 "--west_chassis_addr",
82 settings.getValue("TRAFFICGEN_STC_WEST_CHASSIS_ADDR"),
84 settings.getValue("TRAFFICGEN_STC_WEST_SLOT_NUM"),
86 settings.getValue("TRAFFICGEN_STC_WEST_PORT_NUM"),
87 "--test_session_name",
88 settings.getValue("TRAFFICGEN_STC_TEST_SESSION_NAME"),
90 settings.getValue("TRAFFICGEN_STC_RESULTS_DIR"),
91 "--csv_results_file_prefix",
92 settings.getValue("TRAFFICGEN_STC_CSV_RESULTS_FILE_PREFIX"),
94 settings.getValue("TRAFFICGEN_STC_NUMBER_OF_TRIALS"),
95 "--trial_duration_sec",
96 settings.getValue("TRAFFICGEN_STC_TRIAL_DURATION_SEC"),
98 settings.getValue("TRAFFICGEN_STC_TRAFFIC_PATTERN"),
100 settings.getValue("TRAFFICGEN_STC_SEARCH_MODE"),
102 settings.getValue("TRAFFICGEN_STC_LEARNING_MODE"),
103 "--rate_lower_limit_pct",
104 settings.getValue("TRAFFICGEN_STC_RATE_LOWER_LIMIT_PCT"),
105 "--rate_upper_limit_pct",
106 settings.getValue("TRAFFICGEN_STC_RATE_UPPER_LIMIT_PCT"),
107 "--rate_initial_pct",
108 settings.getValue("TRAFFICGEN_STC_RATE_INITIAL_PCT"),
110 settings.getValue("TRAFFICGEN_STC_RATE_STEP_PCT"),
112 settings.getValue("TRAFFICGEN_STC_RESOLUTION_PCT"),
114 settings.getValue("TRAFFICGEN_STC_FRAME_SIZE"),
115 "--acceptable_frame_loss_pct",
116 settings.getValue("TRAFFICGEN_STC_ACCEPTABLE_FRAME_LOSS_PCT"),
118 settings.getValue("TRAFFICGEN_STC_EAST_INTF_ADDR"),
119 "--east_intf_gateway_addr",
120 settings.getValue("TRAFFICGEN_STC_EAST_INTF_GATEWAY_ADDR"),
122 settings.getValue("TRAFFICGEN_STC_WEST_INTF_ADDR"),
123 "--west_intf_gateway_addr",
124 settings.getValue("TRAFFICGEN_STC_WEST_INTF_GATEWAY_ADDR")]
125 if settings.getValue("TRAFFICGEN_STC_VERBOSE") is "True":
126 args.append("--verbose")
128 print("Arguments used to call test: %s" % args)
130 subprocess.check_call(args)
132 file = os.path.join(settings.getValue("TRAFFICGEN_STC_RESULTS_DIR"),
133 settings.getValue("TRAFFICGEN_STC_CSV_RESULTS_FILE_PREFIX") + ".csv")
135 print("file: %s" % file)
139 with open(file, "r") as csvfile:
140 csvreader = csv.DictReader(csvfile)
141 for row in csvreader:
142 print("Row: %s" % row)
143 result[ResultsConstants.TX_RATE_FPS] = 0.0
144 result[ResultsConstants.THROUGHPUT_RX_FPS] = 0.0
145 result[ResultsConstants.TX_RATE_MBPS] = 0.0
146 result[ResultsConstants.THROUGHPUT_RX_MBPS] = 0.0
147 result[ResultsConstants.TX_RATE_PERCENT] = float(row["OfferedLoad(%)"])
148 result[ResultsConstants.THROUGHPUT_RX_PERCENT] = float(row["Throughput(%)"])
149 result[ResultsConstants.MIN_LATENCY_NS] = float(row["MinimumLatency(us)"]) * 1000
150 result[ResultsConstants.MAX_LATENCY_NS] = float(row["MaximumLatency(us)"]) * 1000
151 result[ResultsConstants.AVG_LATENCY_NS] = float(row["AverageLatency(us)"]) * 1000
154 if __name__ == '__main__':
159 'dstip': '90.90.90.90',
163 with TestCenter() as dev:
164 print(dev.send_rfc2544_throughput(traffic=TRAFFIC))