def createEgressStatView(self, trafficItemObj, egressTrackingPort, offsetBit, bitWidth, egressStatViewName='EgressStatView', ingressTrackingFilterName=None): """ Description Create egress statistic view for egress stats. """ egressTrackingOffsetFilter = 'Custom: ({0}bits at offset {1})'.format(int(bitWidth), int(offsetBit)) trafficItemName = self.getTrafficItemName(trafficItemObj) # Get EgressStats # Create Egress Stats self.ixnObj.logInfo('Creating new statview for egress stats...') response = self.ixnObj.post(self.ixnObj.sessionUrl+'/statistics/view', data={'caption': egressStatViewName, 'treeViewNodeName': 'Egress Custom Views', 'type': 'layer23TrafficFlow', 'visible': True}) egressStatView = response.json()['links'][0]['href'] self.ixnObj.logInfo('egressStatView Object: %s' % egressStatView) # /api/v1/sessions/1/ixnetwork/statistics/view/12 self.ixnObj.logInfo('Creating layer23TrafficFlowFilter') # Dynamically get the PortFilterId response = self.ixnObj.get(self.ixnObj.httpHeader+egressStatView+'/availablePortFilter') portFilterId = [] for eachPortFilterId in response.json(): #192.168.70.10/Card2/Port1 self.ixnObj.logInfo('\tAvailable PortFilterId: %s' % eachPortFilterId['name'], timestamp=False) if eachPortFilterId['name'] == egressTrackingPort: self.ixnObj.logInfo('\tLocated egressTrackingPort: %s' % egressTrackingPort, timestamp=False) portFilterId.append(eachPortFilterId['links'][0]['href']) break if portFilterId == []: raise IxNetRestApiException('No port filter ID found') self.ixnObj.logInfo('PortFilterId: %s' % portFilterId) # Dynamically get the Traffic Item Filter ID response = self.ixnObj.get(self.ixnObj.httpHeader+egressStatView+'/availableTrafficItemFilter') availableTrafficItemFilterId = [] for eachTrafficItemFilterId in response.json(): if eachTrafficItemFilterId['name'] == trafficItemName: availableTrafficItemFilterId.append(eachTrafficItemFilterId['links'][0]['href']) break if availableTrafficItemFilterId == []: raise IxNetRestApiException('No traffic item filter ID found.') self.ixnObj.logInfo('availableTrafficItemFilterId: %s' % availableTrafficItemFilterId, timestamp=False) # /api/v1/sessions/1/ixnetwork/statistics/view/12 self.ixnObj.logInfo('egressStatView: %s' % egressStatView, timestamp=False) layer23TrafficFlowFilter = self.ixnObj.httpHeader+egressStatView+'/layer23TrafficFlowFilter' self.ixnObj.logInfo('layer23TrafficFlowFilter: %s' % layer23TrafficFlowFilter, timestamp=False) response = self.ixnObj.patch(layer23TrafficFlowFilter, data={'egressLatencyBinDisplayOption': 'showEgressRows', 'trafficItemFilterId': availableTrafficItemFilterId[0], 'portFilterIds': portFilterId, 'trafficItemFilterIds': availableTrafficItemFilterId}) # Get the egress tracking filter egressTrackingFilter = None ingressTrackingFilter = None response = self.ixnObj.get(self.ixnObj.httpHeader+egressStatView+'/availableTrackingFilter') self.ixnObj.logInfo('Available tracking filters for both ingress and egress...', timestamp=False) for eachTrackingFilter in response.json(): self.ixnObj.logInfo('\tFilter Name: {0}: {1}'.format(eachTrackingFilter['id'], eachTrackingFilter['name']), timestamp=False) if bool(re.match('Custom: *\([0-9]+ bits at offset [0-9]+\)', eachTrackingFilter['name'])): egressTrackingFilter = eachTrackingFilter['links'][0]['href'] if ingressTrackingFilterName is not None: if eachTrackingFilter['name'] == ingressTrackingFilterName: ingressTrackingFilter = eachTrackingFilter['links'][0]['href'] if egressTrackingFilter is None: raise IxNetRestApiException('Failed to locate your defined custom offsets: {0}'.format(egressTrackingOffsetFilter)) # /api/v1/sessions/1/ixnetwork/statistics/view/23/availableTrackingFilter/3 self.ixnObj.logInfo('Located egressTrackingFilter: %s' % egressTrackingFilter, timestamp=False) enumerationFilter = layer23TrafficFlowFilter+'/enumerationFilter' response = self.ixnObj.post(enumerationFilter, data={'sortDirection': 'ascending', 'trackingFilterId': egressTrackingFilter}) if ingressTrackingFilterName is not None: self.ixnObj.logInfo('Located ingressTrackingFilter: %s' % egressTrackingFilter, timestamp=False) response = self.ixnObj.post(enumerationFilter, data={'sortDirection': 'ascending', 'trackingFilterId': ingressTrackingFilter}) # Must enable one or more egress statistic counters in order to enable the # egress tracking stat view object next. # Enabling: ::ixNet::OBJ-/statistics/view:"EgressStats"/statistic:"Tx Frames" # Enabling: ::ixNet::OBJ-/statistics/view:"EgressStats"/statistic:"Rx Frames" # Enabling: ::ixNet::OBJ-/statistics/view:"EgressStats"/statistic:"Frames Delta" # Enabling: ::ixNet::OBJ-/statistics/view:"EgressStats"/statistic:"Loss %" response = self.ixnObj.get(self.ixnObj.httpHeader+egressStatView+'/statistic') for eachEgressStatCounter in response.json(): eachStatCounterObject = eachEgressStatCounter['links'][0]['href'] eachStatCounterName = eachEgressStatCounter['caption'] self.ixnObj.logInfo('\tEnabling egress stat counter: %s' % eachStatCounterName, timestamp=False) self.ixnObj.patch(self.ixnObj.httpHeader+eachStatCounterObject, data={'enabled': True}) self.ixnObj.patch(self.ixnObj.httpHeader+egressStatView, data={'enabled': True}) self.ixnObj.logInfo('createEgressCustomStatView: Done') return egressStatView