Pavlin Radoslavov | 726c637 | 2013-03-20 02:34:42 -0700 | [diff] [blame^] | 1 | #! /usr/bin/env python |
| 2 | # -*- Mode: python; py-indent-offset: 4; tab-width: 8; indent-tabs-mode: t; -*- |
| 3 | |
| 4 | import copy |
| 5 | import pprint |
| 6 | import os |
| 7 | import sys |
| 8 | import subprocess |
| 9 | import json |
| 10 | import argparse |
| 11 | import io |
| 12 | import time |
| 13 | |
| 14 | ## Global Var ## |
| 15 | |
| 16 | DEBUG=0 |
| 17 | pp = pprint.PrettyPrinter(indent=4) |
| 18 | |
| 19 | ## Worker Functions ## |
| 20 | def log_error(txt): |
| 21 | print '%s' % (txt) |
| 22 | |
| 23 | def debug(txt): |
| 24 | if DEBUG: |
| 25 | print '%s' % (txt) |
| 26 | |
| 27 | |
| 28 | if __name__ == "__main__": |
| 29 | usage_msg = "Usage: %s <begin-flow-id> <end-flow-id>\n" % (sys.argv[0]) |
| 30 | |
| 31 | # app.debug = False; |
| 32 | |
| 33 | # Usage info |
| 34 | if len(sys.argv) > 1 and (sys.argv[1] == "-h" or sys.argv[1] == "--help"): |
| 35 | print(usage_msg) |
| 36 | exit(0) |
| 37 | |
| 38 | # Check arguments |
| 39 | if len(sys.argv) < 3: |
| 40 | log_error(usage_msg) |
| 41 | exit(1) |
| 42 | |
| 43 | # Extract the arguments |
| 44 | begin_flow_id = int(sys.argv[1], 0) |
| 45 | end_flow_id = int(sys.argv[2], 0) |
| 46 | if begin_flow_id > end_flow_id: |
| 47 | log_error(usage_msg) |
| 48 | exit(1) |
| 49 | |
| 50 | # |
| 51 | # Do the work |
| 52 | # |
| 53 | # We generate a number of flows between same source and destination |
| 54 | # DPID and ports. |
| 55 | # |
| 56 | # NOTE: Currently, up to 65536 flows are supported. |
| 57 | # More flows can be supported by iterating by, say, iterating over some of |
| 58 | # the other bytes of the autogenereated source/destination MAC addresses. |
| 59 | # |
| 60 | flow_id = begin_flow_id |
| 61 | idx = 0 |
| 62 | while flow_id <= end_flow_id: |
| 63 | mac3 = idx / 255 |
| 64 | mac4 = idx % 255 |
| 65 | str_mac3 = "%0.2x" % mac3 |
| 66 | str_mac4 = "%0.2x" % mac4 |
| 67 | src_mac = "00:00:" + str_mac3 + ":" + str_mac4 + ":00:00"; |
| 68 | dst_mac = "00:01:" + str_mac3 + ":" + str_mac4 + ":00:00"; |
| 69 | 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) |
| 70 | flow_id = flow_id + 1 |
| 71 | idx = idx + 1 |