def configTrafficItem(self, mode=None, obj=None, trafficItem=None, endpoints=None, configElements=None): """ Description Create or modify a Traffic Item. When creating a new Traffic Item, this API will return 3 object handles: trafficItemObj, endpointSetObjList and configElementObjList NOTE: Each Traffic Item could create multiple endpoints and for each endpoint. you could provide a list of configElements for each endpoint. The endpoints and configElements must be in a list. - Each endpointSet allows you to configure the highLevelStream, which overrides configElements. - If you set bi-directional to True, then there will be two highLevelStreams that you could configure. - Including highLevelStream is optional. Set highLevelStream to None to use configElements. Parameters mode: craete|modify obj: For "mode=modify" only. Provide the object to modify: trafficItemObj|configElementObj|endpointObj trafficItem: Traffic Item kwargs. endpoints: [list]: A list: [{name: sources:[], destionations:[], highLevelStreams: None, (add more endpoints)... ] Scroll down to see example. configElements: [list]: Config Element kwargs. Each item in this list is aligned to the sequential order of your endpoint list. If mode is create: The required parameters are: mode, trafficItem, endpoints and configElements If mode is modify: The required parameters are: mode, obj, and one of the objects to modify (trafficIemObj, endpointObj or configElementObj). You need to provide the right object handle. To modify trafficItem: Ex: /api/v1/sessions/1/ixnetwork/traffic/trafficItem/ To modify endpointSet: Ex: /api/v1/sessions/1/ixnetwork/traffic/trafficItem/1/endpointSet/ To modify configElements = configElement object handlex Ex: /api/v1/sessions/1/ixnetwork/traffic/trafficItem/1/configElement/ Look at sample script l2l3RestNgpy.py Traffic Item Parameters trafficType options: raw, ipv4, ipv4, ethernetVlan, frameRelay, atm, fcoe, fc, hdlc, ppp srcDestMesh: Defaults to one-to-one Options: manyToMany or fullMesh routeMesh: fullMesh or oneToOne allowSelfDestined: True or False trackBy: [list]: trackingenabled0, ethernetIiSourceaddress0, ethernetIiDestinationaddress0, ethernetIiPfcQueue0, vlanVlanId0, vlanVlanUserPriority0, ipv4SourceIp0, sourceDestValuePair0, sourceDestEndpointPair0, ipv4Precedence0, ipv4SourceIp0, flowGroup0, frameSize0 ConfigElement Parameters transmissionType: - continuous|fixedFrameCount|fixedDuration - custom (for burstPacketCount) frameCount: (For continuous and fixedFrameCount traffic) burstPacketCount: (For bursty traffic) frameSizeType: fixed|random frameSize: The packet size. frameRate: The rate to transmit packets frameRateType: bitsPerSecond|framesPerSecond|interPacketGap|percentLineRate frameRateBitRateUnitsType: bitsPerSec|bytesPerSec|kbitsPerSec|kbytesPerSec|mbitsPerSec|mbytesPerSec duration: Set fixedDuration portDistribution: applyRateToAll|splitRateEvenly. Default=applyRateToAll streamDistribution: splitRateEvenly|applyRateToAll. Default=splitRateEvently trackBy: : Some options: flowGroup0, vlanVlanId0, ethernetIiDestinationaddress0, ethernetIiSourceaddress0, sourcePort0, sourceDestPortPair0, ipv4DestIp0, ipv4SourceIp0, ipv4Precedence0, ethernetIiPfcQueue0, frameSize0 If frameSizeType == random incrementFrom: Frame size increment from. incrementTo: Frame size increment to. For bursty packet count, transmissionType = 'custom', burstPacketCount = 50000, Endpoints Parameters A list of topology, deviceGroup or protocol objects sources: Object in a list. destinations: Object in a lsit. Example: ['/api/v1/sessions/1/ixnetwork/topology/8'] or a list ['.../topology/1', '.../topology/3'] ['.../topology/1/deviceGroup/1', '.../topology/2/deviceGroup/1/ethernet/1/ipv4/1'] USAGE EXAMPLE: To modify: trafficObj.configTrafficItem(mode='modify', obj='/api/v1/sessions/1/ixnetwork/traffic/trafficItem/1/configElement/1', configElements={'transmissionType': 'continuous'}) trafficObj.configTrafficItem(mode='modify', obj='/api/v1/sessions/1/ixnetwork/traffic/trafficItem/1', trafficItem={'trackBy': ['frameSize0', 'ipv4SourceIp0']}) To create new Traffic Item: configTrafficItem(mode='create', trafficItem = { 'name':'Topo1 to Topo2', 'trafficType':'ipv4', 'biDirectional':True, 'srcDestMesh':'one-to-one', 'routeMesh':'oneToOne', 'allowSelfDestined':False, 'trackBy': ['flowGroup0', 'vlanVlanId0']}, endpoints = [{'name':'Flow-Group-1', 'sources': [topologyObj1], 'destinations': [topologyObj2], 'highLevelStreamElements': None}], configElements = [{'transmissionType': 'fixedFrameCount', 'frameCount': 50000, 'frameRate': 88, 'frameRateType': 'percentLineRate', 'frameSize': 128, 'portDistribution': 'applyRateToAll', 'streamDistribution': 'splitRateEvenly' }] ) To create a new Traffic Item and configure the highLevelStream: trafficObj.configTrafficItem(mode='create', trafficItem = {'name':'Topo3 to Topo4', 'trafficType':'ipv4', 'biDirectional':True, 'srcDestMesh':'one-to-one', 'routeMesh':'oneToOne', 'allowSelfDestined':False, 'trackBy': ['flowGroup0', 'vlanVlanId0']}, endpoints = [{'name':'Flow-Group-1', 'sources': [topologyObj1], 'destinations': [topologyObj2], 'highLevelStreamElements': [ { 'transmissionType': 'fixedFrameCount', 'frameCount': 10000, 'frameRate': 18, 'frameRateType': 'percentLineRate', 'frameSize': 128}, { 'transmissionType': 'fixedFrameCount', 'frameCount': 20000, 'frameRate': 28, 'frameRateType': 'percentLineRate', 'frameSize': 228} ] }], configElements = None) Return: trafficItemObj, endpointSetObjList, configElementObjList """ if mode == 'create': trafficItemUrl = self.ixnObj.sessionUrl+'/traffic/trafficItem' if mode == 'modify' and obj is None: raise IxNetRestApiException('Modifying Traffic Item requires a Traffic Item object') if mode == 'create' and trafficItem is None: raise IxNetRestApiException('Creating Traffic Item requires trafficItem kwargs') if mode == None: raise IxNetRestApiException('configTrafficItem Error: Must include mode: config or modify') # Don't configure config elements if user is configuring highLevelStreams isHighLevelStreamTrue = False # Create a new Traffic Item if mode == 'create' and trafficItem != None: if 'trackBy' in trafficItem: trackBy = trafficItem['trackBy'] del trafficItem['trackBy'] self.ixnObj.logInfo('configTrafficItem: %s : %s' % (trafficItemUrl, trafficItem), timestamp=False) response = self.ixnObj.post(trafficItemUrl, data=trafficItem) trafficItemObj = response.json()['links'][0]['href'] if mode == 'modify' and trafficItem != None: trafficItemObj = obj if 'trackBy' in trafficItem: trackBy = trafficItem['trackBy'] del trafficItem['trackBy'] self.ixnObj.patch(self.ixnObj.httpHeader+trafficItemObj, data=trafficItem) # Create Endpoints if mode == 'create' and endpoints != None: if type(endpoints) != list: raise IxNetRestApiException('configTrafficItem error: Provide endpoints in a list') endpointSetObjList = [] if 'trafficItemObj' not in locals(): # Expect the user to pass in the endpoint object handle correctly and parse # out the traffic item object handle. trafficItemObj = self.ixnObj.sessionUrl.split('/endpointSet')[0] # endpoints = [{'name':'Flow-Group-1', 'sources': [topologyObj1], 'destinations': [topologyObj2], 'highLevelStreamElements': None}] for endPoint in endpoints: endpointSrcDst = {} # {'name':'Flow-Group-1', 'sources': [topologyObj1], 'destinations': [topologyObj2]} if 'name' in endPoint: endpointSrcDst['name'] = endPoint['name'] if 'sources' in endPoint: endpointSrcDst['sources'] = endPoint['sources'] if 'destinations' in endPoint: endpointSrcDst['destinations'] = endPoint['destinations'] if 'multicastDestinations' in endPoint: endpointSrcDst['multicastDestinations'] = endPoint['multicastDestinations'] if 'multicastReceivers' in endPoint: endpointSrcDst['multicastReceivers'] = endPoint['multicastReceivers'] if 'scalableDestinations' in endPoint: endpointSrcDst['scalableDestinations'] = endPoint['scalableDestinations'] if 'scalableSources' in endPoint: endpointSrcDst['scalableSources'] = endPoint['scalableSources'] response = self.ixnObj.post(self.ixnObj.httpHeader+trafficItemObj+'/endpointSet', data=endpointSrcDst) if 'highLevelStreamElements' in endPoint: highLevelStream = endPoint['highLevelStreamElements'] # JSON doesn't support None. In case user passed in {} instead of None. if highLevelStream == {}: highLevelStream = None else: highLevelStream = None # Get the RETURNED endpointSet/# object endpointSetObj = response.json()['links'][0]['href'] response = self.ixnObj.get(self.ixnObj.httpHeader+endpointSetObj) # This endpontSet ID is used for getting the corresponding Config Element ID # in case there are multiple endpoint sets created. endpointSetId = response.json()['id'] endpointSetObjList.append(endpointSetObj) # An endpoint flow group could have two highLevelStream if bi-directional is enabled.x if highLevelStream != None: isHighLevelStreamTrue = True configElementObjList = None ;# Don't configure config elements if user is configuring highLevelStreams streamNum = 1 for eachHighLevelStream in highLevelStream: self.configConfigElements(self.ixnObj.httpHeader+trafficItemObj+'/highLevelStream/'+str(streamNum), eachHighLevelStream) streamNum += 1 if mode == 'modify' and endpoints != None: endpointSrcDst = {} if 'name' in endpoints: endpointSrcDst['name'] = endpoints['name'] if 'sources' in endpoints: endpointSrcDst['sources'] = endpoints['sources'] if 'destinations' in endpoints: endpointSrcDst['destinations'] = endpoints['destinations'] endpointSetObj = obj self.ixnObj.patch(self.ixnObj.httpHeader+endpointSetObj, data=endpointSrcDst) if isHighLevelStreamTrue == False and configElements != None: if mode == 'create' and type(configElements) != list: raise IxNetRestApiException('configTrafficItem error: Provide configElements in a list') if mode == 'modify': configElementObj = obj self.configConfigElements(self.ixnObj.httpHeader+configElementObj, configElements) if mode == 'create': endpointResponse = self.ixnObj.get(self.ixnObj.httpHeader+trafficItemObj+'/endpointSet') index = 0 configElementCounter = 1 configElementObjList = [] for eachEndpoint in endpointResponse.json(): configElementObj = trafficItemObj+'/configElement/'+str(configElementCounter) configElementObjList.append(configElementObj) self.configConfigElements(self.ixnObj.httpHeader+configElementObj, configElements[index]) if len(endpointSetObjList) == len(configElements): index += 1 configElementCounter += 1 if configElements is None: configElementObjList = [] # Cannot configure tracking until endpoints are created. This is why # tracking config is at the end here. if mode in ['create', 'modify'] and 'trackBy' in locals(): self.ixnObj.logInfo('Config Traffic Item statistic trackings', timestamp=False) self.ixnObj.patch(self.ixnObj.httpHeader+trafficItemObj+'/tracking', data={'trackBy': trackBy}) # API server needs some time to complete processing the highlevel stream configuration before entering regenerate. if mode == 'create' and trafficItem != None: return [trafficItemObj, endpointSetObjList, configElementObjList]