blob: 3d6131832cb1d51828d87fb9a723a3bc6e761475 [file] [log] [blame]
Pavlin Radoslavov6b180162013-04-02 06:16:48 +00001#! /usr/bin/env python
2# -*- Mode: python; py-indent-offset: 4; tab-width: 8; indent-tabs-mode: t; -*-
3
4#
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
17import 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)
31DOMAINS_N = 7
32NODES_N = 25
33
34## Worker Functions ##
35def log_error(txt):
36 print '%s' % (txt)
37
38def debug(txt):
39 if DEBUG:
40 print '%s' % (txt)
41
42
43if __name__ == "__main__":
44 usage_msg = "Generate a number of flows by using a pre-defined template.\n"
45 usage_msg = usage_msg + "\n"
46 usage_msg = usage_msg + "NOTE: This script is work-in-progress. Currently all flows are within same\n"
47 usage_msg = usage_msg + "pair of switch ports and contain auto-generated MAC-based matching conditions.\n"
48 usage_msg = usage_msg + "\n"
49 usage_msg = usage_msg + "Usage: %s <begin-flow-id>\n" % (sys.argv[0])
50 usage_msg = usage_msg + "\n"
51 usage_msg = usage_msg + " The output should be saved to a file, and the flows should be installed\n"
52 usage_msg = usage_msg + " by using the command './add_flow.py -f filename'\n"
53
54
55 # app.debug = False
56
57 # Usage info
58 if len(sys.argv) > 1 and (sys.argv[1] == "-h" or sys.argv[1] == "--help"):
59 print(usage_msg)
60 exit(0)
61
62 # Check arguments
63 if len(sys.argv) < 2:
64 log_error(usage_msg)
65 exit(1)
66
67 # Extract the arguments
68 begin_flow_id = int(sys.argv[1], 0)
69
70 #
71 # Do the work
72 #
73 # NOTE: Currently, up to 65536 flows are supported.
74 # More flows can be supported by iterating by, say, iterating over some of
75 # the other bytes of the autogenereated source/destination MAC addresses.
76 #
77 # We iterate over each pair of domains. E.g.:
78 # (2,3) (2,4) (2,5) ... (2,8) (3,2) (3,4) ... (3,8) (4,2) ... (8,7)
79 # Within each domain we iterate over the corresponding pairs of node IDs:
80 # (2,2) (3,3) (4,4) (5,5) ... (25, 25)
81 #
82 flow_id = begin_flow_id
83 idx = 0
84 src_domain_id = 2
85 while src_domain_id < DOMAINS_N + 2:
86 dst_domain_id = 2
87 while dst_domain_id < DOMAINS_N + 2:
88 if src_domain_id == dst_domain_id:
89 dst_domain_id = dst_domain_id + 1
90 continue
91 node_id = 2
92 while node_id < NODES_N:
93 # The matching MAC addresses
94 mac2 = idx / 255
95 mac3 = idx % 255
96 str_mac2 = "%0.2x" % mac2
97 str_mac3 = "%0.2x" % mac3
98 src_mac = "00:01:" + str_mac2 + ":" + str_mac3 + ":00:00"
99 dst_mac = "00:02:" + str_mac2 + ":" + str_mac3 + ":00:00"
100 # The src/dst node DPID
101 src_node_dpid = "%0.2x" % node_id
102 dst_node_dpid = "%0.2x" % node_id
103 src_domain_dpid = "%0.2x" % src_domain_id
104 dst_domain_dpid = "%0.2x" % dst_domain_id
105 src_dpid = "00:00:00:00:00:00:" + src_domain_dpid + ":" + src_node_dpid
106 dst_dpid = "00:00:00:00:00:00:" + dst_domain_dpid + ":" + dst_node_dpid
107 # The flow from source to destination
108 print "%s FOOBAR %s 1 %s 1 matchSrcMac %s matchDstMac %s" % (flow_id, src_dpid, dst_dpid, src_mac, dst_mac)
109 flow_id = flow_id + 1
110 idx = idx + 1
111 node_id = node_id + 1
112 dst_domain_id = dst_domain_id + 1
113 src_domain_id = src_domain_id + 1