blob: 78297c5216f9a4396a329042165911227f159316 [file] [log] [blame]
Dan Talaycof75360a2010-02-05 22:22:54 -08001#!/usr/bin/env python2.5
2"""This script reads struct from OpenFlow header file and output query
3
4(C) Copyright Stanford University
5Author ykk
6Date October 2009
7"""
8import sys
9import getopt
10import openflow
11
12def usage():
13 """Display usage
14 """
15 print "Usage "+sys.argv[0]+" <options> struct_name\n"+\
16 "Options:\n"+\
17 "-h/--help\n\tPrint this usage guide\n"+\
18 "-c/--cstruct\n\tPrint C struct\n"+\
19 "-n/--name\n\tPrint names of struct\n"+\
20 "-s/--size\n\tPrint size of struct\n"+\
21 ""
22
23#Parse options and arguments
24try:
25 opts, args = getopt.getopt(sys.argv[1:], "hcsn",
26 ["help","cstruct","size","names"])
27except getopt.GetoptError:
28 usage()
29 sys.exit(2)
30
31#Check there is only struct name
32if not (len(args) == 1):
33 usage()
34 sys.exit(2)
35
36#Parse options
37##Print C struct
38printc = False
39##Print names
40printname = False
41##Print size
42printsize = False
43for opt,arg in opts:
44 if (opt in ("-h","--help")):
45 usage()
46 sys.exit(0)
47 elif (opt in ("-s","--size")):
48 printsize = True
49 elif (opt in ("-c","--cstruct")):
50 printc = True
51 elif (opt in ("-n","--names")):
52 printname = True
53 else:
54 assert (False,"Unhandled option :"+opt)
55
56pyopenflow = openflow.messages()
57cstruct = pyopenflow.structs[args[0].strip()]
58pattern = pyopenflow.get_pattern(cstruct)
59
60#Print C struct
61if (printc):
62 print cstruct
63
64#Print pattern
65print "Python pattern = "+str(pattern)
66
67#Print name
68if (printname):
69 print cstruct.get_names()
70
71#Print size
72if (printsize):
73 print "Size = "+str(pyopenflow.get_size(pattern))
74