blob: 953fc03b8de66a6ddd0bd374f905642988527724 [file] [log] [blame]
Pavlin Radoslavov726c6372013-03-20 02:34:42 -07001#! /usr/bin/env python
2# -*- Mode: python; py-indent-offset: 4; tab-width: 8; indent-tabs-mode: t; -*-
3
Pavlin Radoslavovcb8cdfe2013-03-20 02:40:38 -07004#
5# A script for generating a number of flows.
6#
7# The output of the script should be saved to a file, and the flows from
8# that file should be added by the following command:
9#
10# web/add_flow.py -f filename
11#
12# NOTE: Currently, some of the parameters fo the flows are hard-coded,
13# and all flows are between same source and destination DPID and ports
14# (differentiated by different matchSrcMac and matchDstMac).
15#
16
Pavlin Radoslavov726c6372013-03-20 02:34:42 -070017import copy
18import pprint
19import os
20import sys
21import subprocess
22import json
23import argparse
24import io
25import time
26
27## Global Var ##
28
29DEBUG=0
30pp = pprint.PrettyPrinter(indent=4)
31
32## Worker Functions ##
33def log_error(txt):
34 print '%s' % (txt)
35
36def debug(txt):
37 if DEBUG:
38 print '%s' % (txt)
39
40
41if __name__ == "__main__":
42 usage_msg = "Usage: %s <begin-flow-id> <end-flow-id>\n" % (sys.argv[0])
43
44 # app.debug = False;
45
46 # Usage info
47 if len(sys.argv) > 1 and (sys.argv[1] == "-h" or sys.argv[1] == "--help"):
48 print(usage_msg)
49 exit(0)
50
51 # Check arguments
52 if len(sys.argv) < 3:
53 log_error(usage_msg)
54 exit(1)
55
56 # Extract the arguments
57 begin_flow_id = int(sys.argv[1], 0)
58 end_flow_id = int(sys.argv[2], 0)
59 if begin_flow_id > end_flow_id:
60 log_error(usage_msg)
61 exit(1)
62
63 #
64 # Do the work
65 #
Pavlin Radoslavov726c6372013-03-20 02:34:42 -070066 # NOTE: Currently, up to 65536 flows are supported.
67 # More flows can be supported by iterating by, say, iterating over some of
68 # the other bytes of the autogenereated source/destination MAC addresses.
69 #
70 flow_id = begin_flow_id
71 idx = 0
72 while flow_id <= end_flow_id:
73 mac3 = idx / 255
74 mac4 = idx % 255
75 str_mac3 = "%0.2x" % mac3
76 str_mac4 = "%0.2x" % mac4
77 src_mac = "00:00:" + str_mac3 + ":" + str_mac4 + ":00:00";
78 dst_mac = "00:01:" + str_mac3 + ":" + str_mac4 + ":00:00";
79 print "%s FOOBAR 00:00:00:00:00:00:01:01 1 00:00:00:00:00:00:01:0b 1 matchSrcMac %s matchDstMac %s" % (flow_id, src_mac, dst_mac)
80 flow_id = flow_id + 1
81 idx = idx + 1