@@ -303,31 +303,56 @@ def pa_addFlowSpace(args, cmd):
303303 help = "Define list of queues permitted on this flowspace." )
304304 parser .add_option ("-f" , "--forced-queue" , default = None , dest = "fqueue" , type = "int" ,
305305 help = "Force a queue id upon output action." )
306-
307306 return parser .parse_args (args )
308307
309308def do_addFlowSpace (gopts , opts , args ):
310309 if len (args ) != 5 :
311310 print "add-flowpace : Requires 5 arguments; only %d given" % len (args )
312311 print "add-flowspace: <flowspace-name> <dpid> <priority> <match> <slice-perm>"
312+ print "If range is specified for vlan, the format for add-flowspace is as below:(Currently only vlan ranges are supported)"
313+ print "add-flowspace <flowspace-name> <dpid> <priority> <dl_vlan=1-10> <slice-perm>"
313314 sys .exit ()
314315 passwd = getPassword (gopts )
315- match = makeMatch (args [3 ])
316- req = { "name" : args [0 ], "dpid" : args [1 ], "priority" : int (args [2 ]), "match" : match }
317- if opts .queues is not None :
318- req ['queues' ] = opts .queues
319- if opts .fqueue is not None :
320- req ['force-enqueue' ] = opts .fqueue
321- actions = args [4 ].split (',' )
322- acts = []
323- for action in actions :
324- parts = action .split ('=' )
325- act = { 'slice-name' : parts [0 ], "permission" : parts [1 ] }
326- acts .append (act )
327- req ['slice-action' ] = acts
328- ret = connect (gopts , "add-flowspace" , passwd , data = [req ])
329- if ret :
330- print "FlowSpace %s was added with request id %s." % (args [0 ], ret )
316+ if (args [3 ].find ('-' ) != - 1 ):
317+ #Get the ranges
318+ ranges = getRange (args [3 ])
319+ if ((int (ranges [0 ]) < 1 ) or (int (ranges [0 ]) > 4095 ) or (int (ranges [1 ]) < 1 ) or (int (ranges [1 ]) > 4095 )):
320+ print "The vlan range should be within 1 and 4095"
321+ sys .exit ()
322+ for r in range ((int (ranges [0 ])), (int (ranges [1 ])+ 1 )):
323+ match = makeMatchWithRanges (args [3 ],r )
324+ req = { "name" : args [0 ], "dpid" : args [1 ], "priority" : int (args [2 ]), "match" : match }
325+ if opts .queues is not None :
326+ req ['queues' ] = opts .queues
327+ if opts .fqueue is not None :
328+ req ['force-enqueue' ] = opts .fqueue
329+ actions = args [4 ].split (',' )
330+ acts = []
331+ for action in actions :
332+ parts = action .split ('=' )
333+ act = { 'slice-name' : parts [0 ], "permission" : parts [1 ] }
334+ acts .append (act )
335+ req ['slice-action' ] = acts
336+ ret = connect (gopts , "add-flowspace" , passwd , data = [req ])
337+ if ret :
338+ print "FlowSpace %s was added with request id %s." % (args [0 ], ret )
339+ else :
340+ match = makeMatch (args [3 ])
341+ req = { "name" : args [0 ], "dpid" : args [1 ], "priority" : int (args [2 ]), "match" : match }
342+ if opts .queues is not None :
343+ req ['queues' ] = opts .queues
344+ if opts .fqueue is not None :
345+ req ['force-enqueue' ] = opts .fqueue
346+ actions = args [4 ].split (',' )
347+ acts = []
348+ for action in actions :
349+ parts = action .split ('=' )
350+ act = { 'slice-name' : parts [0 ], "permission" : parts [1 ] }
351+ acts .append (act )
352+ req ['slice-action' ] = acts
353+ ret = connect (gopts , "add-flowspace" , passwd , data = [req ])
354+ if ret :
355+ print "FlowSpace %s was added with request id %s." % (args [0 ], ret )
331356
332357def pa_updateFlowSpace (args , cmd ):
333358 usage = "%s [options] <flowspace-name>" % USAGE .format (cmd )
@@ -717,7 +742,8 @@ def makeMatch(matchStr):
717742 for item in matchItems :
718743 it = item .split ('=' )
719744 if len (it ) != 2 :
720- print "Match items must be of the form <key>=<val>"
745+ print it
746+ print "Match items must be of the form =, not %s" % it
721747 sys .exit ()
722748 try :
723749 (mstr , func ) = MATCHSTRS [it [0 ].lower ()]
@@ -726,8 +752,44 @@ def makeMatch(matchStr):
726752 print "Unknown match item %s" % it [0 ]
727753 sys .exit ()
728754 return match
729-
730755
756+ def makeMatchWithRanges (matchStr ,rng ):
757+ if matchStr == 'any' or matchStr == 'all' :
758+ return {}
759+ matchItems = matchStr .split (',' )
760+ match = {}
761+ for item in matchItems :
762+ it = item .split ('=' )
763+ if len (it ) != 2 :
764+ print it
765+ print "Match items must be of the form <key>=<val>"
766+ sys .exit ()
767+ try :
768+ if it [0 ].lower () != 'dl_vlan' :
769+ (mstr , func ) = MATCHSTRS [it [0 ].lower ()]
770+ match [mstr ] = func (it [1 ])
771+ else :
772+ match ['dl_vlan' ] = rng
773+ except KeyError , e :
774+ print "Unknown match item %s" % it [0 ]
775+ sys .exit ()
776+ return match
777+
778+ def getRange (matchStr ):
779+ matchItems = matchStr .split (',' )
780+ match = {}
781+ ranges = []
782+ for item in matchItems :
783+ it = item .split ('=' )
784+ if len (it ) != 2 :
785+ print "Match items must be of the form <key>=<val>"
786+ sys .exit ()
787+ if it [0 ].lower () == 'dl_vlan' :
788+ ranges = it [1 ].split ('-' )
789+ if len (ranges ) != 2 :
790+ print "The vlan range should be given in the form <from>-<to>, for eg. dl_vlan=10-100"
791+ return ranges
792+
731793def connect (opts , cmd , passwd , data = None ):
732794 try :
733795 url = getUrl (opts )
@@ -923,6 +985,9 @@ def print_help(option, opt, value, parser):
923985 "replaced with the queue id given in the forced queue option. Note: The forced queue "
924986 "should be defined in the queue option and all these queue ids should be defined with "
925987 "the appropriate port on the switch."
988+ "A range can be specified only for the dl_vlan match field."
989+ "To specify the range for dl_vlan match field, the add-flowspace api has to be used as in the below example:"
990+ "Eg. ./fvctl.py add-flowspace flow1 all 1000 dl_vlan=1-10 slice1=6"
926991 "See the fvctl man page for information "
927992 "on the format of <dpid>, <match>, and <slice-perm>."
928993 )),
0 commit comments