def addTrafficItemPacketStack(self, configElementObj, protocolStackNameToAdd, stackNumber, action='append'): """ Description To either append or insert a protocol stack to an existing packet. You must know the exact name of the protocolTemplate to add by calling showProtocolTemplates() API and get the exact name as a value for the parameter protocolStackNameToAdd. You must also know where to add the new packet header stack. Use showTrafficItemPacketStack() to see your current stack numbers. This API returns the protocol stack object handle so you could use it to config its settings. Parameters configElementObj: /api/v1/sessions/1/ixnetwork/traffic/trafficItem/{id}/configElement/{id} action: append: To add after the specified stackNumber insert: To add before the specified stackNumber protocolStackNameToAdd: The name of the protocol stack to add. To get a list of options, use API showProtocolTemplates(). Some common ones: MPLS, IPv4, TCP, UDP, VLAN, IGMPv1, IGMPv2, DHCP, VXLAN stackNumber: The stack number to append or insert into. Use showTrafficItemPacketStack() to view the packet header stack in order to know which stack number to insert your new stack before or after the stack number. Example: addTrafficItemPacketStack(configElement, protocolStackNameToAdd='UDP', stackNumber=3, action='append', apiKey=apiKey, verifySslCert=False Returns: /api/v1/sessions/1/ixnetwork/traffic/trafficItem/{id}/configElement/{id}/stack/{id} """ if action == 'append': action = 'appendprotocol' if action == 'insert': action = 'insertprotocol' # /api/v1/sessions/1 match = re.match('http.*(/api.*sessions/[0-9]).*', self.ixnObj.sessionUrl) if match: apiHeader = match.group(1) # /api/v1/sessions/1/ixnetwork/traffic/trafficItem/1/configElement/1 arg1 = configElementObj+'/stack/' + str(stackNumber) # Display a list of the current packet stack response = self.ixnObj.get(self.ixnObj.httpHeader+configElementObj+'/stack') for (index, eachHeader) in enumerate(response.json()): self.ixnObj.logInfo('{0}: {1}'.format(index+1, eachHeader['displayName']), timestamp=False) # Get a list of all the protocol templates: response = self.ixnObj.get(self.ixnObj.sessionUrl+'/traffic/protocolTemplate?skip=0&take=end') protocolTemplateId = None for eachProtocol in response.json()['data']: if bool(re.match('^%s$' % protocolStackNameToAdd, eachProtocol['displayName'].strip(), re.I)): # /api/v1/sessions/1/traffic/protocolTemplate/30 protocolTemplateId = eachProtocol['links'][0]['href'] if protocolTemplateId == None: raise IxNetRestApiException('No such protocolTemplate name found: {0}'.format(protocolStackNameToAdd)) self.ixnObj.logInfo('protocolTemplateId: %s' % protocolTemplateId, timestamp=False) data = {'arg1': arg1, 'arg2': protocolTemplateId} response = self.ixnObj.post(self.ixnObj.httpHeader+configElementObj+'/stack/operations/%s' % action, data=data) self.ixnObj.waitForComplete(response, self.ixnObj.httpHeader+configElementObj+'/stack/operations/appendprotocol/'+response.json()['id']) # /api/v1/sessions/1/ixnetwork/traffic/trafficItem/1/configElement/1/stack/4 self.ixnObj.logInfo('addTrafficItemPacketStack: Returning: %s' % response.json()['result'], timestamp=False) return response.json()['result']