summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYuichi Ito <ito.yuichi0@gmail.com>2014-05-27 10:06:18 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2014-05-27 20:24:28 +0900
commit525a4a11ee06c8aa2d05f77619df8a33a2914ffb (patch)
tree3fcabc359aa3678c31be3270ec13493649306a60
parentaf5267b4abbc41ac4d9facd8ad6ffad23b789aaf (diff)
sw test tool: Enable sending packets using random values
The switch test tool is now enabled to send packets using random values as follows: "tests":[ { "ingress":{ "packets":{ "data":[ "ethernet(dst=netaddr.EUI(randint(0, 2 ** 48 - 1)), ethertype=2048)", "ipv4(proto=6, src=netaddr.IPAddress(randint(0, 2 ** 32 - 1)))", "tcp(dst_port=randint(0, 2 ** 16 - 1))", "str('\\x11' * (1500 - 54))" ], "pktps":1000, "duration_time":30 } }, "egress":{ "throughput":[ { "OFPMatch":{ "oxm_fields":[ { "OXMTlv":{ "field":"in_port", "value":2 } } ] }, "kbps":1500 } ] } } ] When ingress.packets.data includes 'randint', the switch test tool will send each packet using random values. Signed-off-by: Yuichi Ito <ito.yuichi0@gmail.com> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--ryu/tests/switch/tester.py30
1 files changed, 23 insertions, 7 deletions
diff --git a/ryu/tests/switch/tester.py b/ryu/tests/switch/tester.py
index eacd3fb0..02463106 100644
--- a/ryu/tests/switch/tester.py
+++ b/ryu/tests/switch/tester.py
@@ -18,11 +18,13 @@ import inspect
import json
import logging
import math
+import netaddr
import os
import signal
import sys
import time
import traceback
+from random import randint
from ryu import cfg
@@ -724,20 +726,24 @@ class OfTester(app_manager.RyuApp):
def _continuous_packet_send(self, pkt):
assert self.ingress_event is None
- pkt_data = pkt[KEY_PACKETS][KEY_DATA]
+ pkt_text = pkt[KEY_PACKETS]['packet_text']
+ pkt_bin = pkt[KEY_PACKETS]['packet_binary']
pktps = pkt[KEY_PACKETS][KEY_PKTPS]
duration_time = pkt[KEY_PACKETS][KEY_DURATION_TIME]
+ randomize = pkt[KEY_PACKETS]['randomize']
- self.logger.debug("send_packet:[%s]", packet.Packet(pkt_data))
+ self.logger.debug("send_packet:[%s]", packet.Packet(pkt_bin))
self.logger.debug("pktps:[%d]", pktps)
self.logger.debug("duration_time:[%d]", duration_time)
- arg = {'pkt_data': pkt_data,
+ arg = {'packet_text': pkt_text,
+ 'packet_binary': pkt_bin,
'thread_counter': 0,
'dot_span': int(CONTINUOUS_PROGRESS_SPAN /
CONTINUOUS_THREAD_INTVL),
'packet_counter': float(0),
- 'packet_counter_inc': pktps * CONTINUOUS_THREAD_INTVL}
+ 'packet_counter_inc': pktps * CONTINUOUS_THREAD_INTVL,
+ 'randomize': randomize}
try:
self.ingress_event = hub.Event()
@@ -774,8 +780,14 @@ class OfTester(app_manager.RyuApp):
self.ingress_threads.append(tid)
hub.sleep(0)
for _ in range(count):
+ if arg['randomize']:
+ msg = eval('/'.join(arg['packet_text']))
+ msg.serialize()
+ data = msg.data
+ else:
+ data = arg['packet_binary']
try:
- self.tester_sw.send_packet_out(arg['pkt_data'])
+ self.tester_sw.send_packet_out(data)
except Exception as err:
self.thread_msg = err
self.ingress_event.set()
@@ -1270,12 +1282,16 @@ class Test(stringify.StringifyMixin):
test_pkt[KEY_INGRESS] = __test_pkt_from_json(test[KEY_INGRESS])
elif isinstance(test[KEY_INGRESS], dict):
test_pkt[KEY_PACKETS] = {
- KEY_DATA: __test_pkt_from_json(
+ 'packet_text': test[KEY_INGRESS][KEY_PACKETS][KEY_DATA],
+ 'packet_binary': __test_pkt_from_json(
test[KEY_INGRESS][KEY_PACKETS][KEY_DATA]),
KEY_DURATION_TIME: test[KEY_INGRESS][KEY_PACKETS].get(
KEY_DURATION_TIME, DEFAULT_DURATION_TIME),
KEY_PKTPS: test[KEY_INGRESS][KEY_PACKETS].get(
- KEY_PKTPS, DEFAULT_PKTPS)}
+ KEY_PKTPS, DEFAULT_PKTPS),
+ 'randomize': True in [
+ line.find('randint') != -1
+ for line in test[KEY_INGRESS][KEY_PACKETS][KEY_DATA]]}
else:
raise ValueError('invalid format: "%s" field' % KEY_INGRESS)
# parse 'egress' or 'PACKET_IN' or 'table-miss'