def getProtocolSessionsStats(self, portName, protocol): """ Description Get a protocol session status for a specified protocol on a port Parameters portName: : Name of the Port to get the protocol session stats eg: "1/1/11" protocol: : Name of the protocol. eg: Examples getProtocolSessionsStats(portName='1/1/11', protocol='ospf') Return Protocol stats in dictionary format eg: {'ospf': {'Configured': 2, 'Up': 1}} """ protocolStats = {} vport = self.portMgmtObj.getVportObjectByName(portName) if vport == None: raise IxNetRestApiException('PortName {0} not connected to chassis'.format(portName)) node = '/router' if re.search('bgp', protocol, re.I): node = '/neighborRange' protocolResponse = self.ixnObj.get(vport + '/protocols/' + protocol) response = self.ixnObj.get(vport + '/protocols/' + protocol + node) if response.json() != []: if response.json()[0]['enabled'] == True and protocolResponse.json()['runningState'] == 'started': if re.search('ospf', protocol, re.I): protocolViewName = 'OSPF Aggregated Statistics' elif re.search('ospfV3', protocol, re.I): protocolViewName = 'OSPFv3 Aggregated Statistics' elif re.search('bgp', protocol, re.I): protocolViewName = 'BGP Aggregated Statistics' elif re.search('isis', protocol, re.I): protocolViewName = 'ISIS Aggregated Statistics' elif re.search('ripng', protocol, re.I): protocolViewName = 'RIPng Aggregated Statistics' elif re.search('bfd', protocol, re.I): protocolViewName = 'BFD Aggregated Statistics' elif re.search('rip', protocol, re.I): protocolViewName = 'RIP Aggregated Statistics' elif re.search('ldp', protocol, re.I): protocolViewName = 'LDP Aggregated Statistics' elif re.search('mplsoam', protocol, re.I): protocolViewName = 'MPLSOAM Aggregated Statistics' elif re.search('pim', protocol, re.I): protocolViewName = 'PIMSM Aggregated Statistics' else: raise IxNetRestApiException('No viewName defined') else: raise IxNetRestApiException('No {0} protocol running or enabled on port {1}'.format(protocol, portName)) else: raise IxNetRestApiException('No {0} protocol configured on port {1}'.format(protocol, portName)) stats = self.statObj.getStats(viewName=protocolViewName, displayStats=False) #totalPorts = len(stats.keys()); # Length stats.keys() represents total ports. self.ixnObj.logInfo('ProtocolViewName: {0}'.format(protocolViewName)) for session in stats.keys(): if re.search('OSPF', protocolViewName, re.I): sessionsUp = int(stats[session]['Full Nbrs.']) totalSessions = int(stats[session]['Sess. Configured']) elif re.search('BGP', protocolViewName, re.I): sessionsUp = int(stats[session]['Sess. Up']) totalSessions = int(stats[session]['Sess. Configured']) elif re.search('ISIS', protocolViewName, re.I): sessionsUp = int(stats[session]['L2 Sess. Up']) totalSessions = int(stats[session]['L2 Sess. Configured']) elif re.search('RIPng', protocolViewName, re.I) or re.search('BFD', protocolViewName, re.I): sessionsUp = int(stats[session]['Routers Running']) totalSessions = int(stats[session]['Routers Configured']) elif re.search('RIP', protocolViewName, re.I): sessionsUp = int(stats[session]['Request Packet Tx']) totalSessions = int(stats[session]['Routers Configured']) elif re.search('LACP', protocolViewName, re.I): sessionsUp = int(stats[session]['LAG Member Ports UP']) totalSessions = int(stats[session]['Total LAG Member Ports']) elif re.search('LDP', protocolViewName, re.I): sessionsUp = int(stats[session]['Targeted Sess. Up']) totalSessions = int(stats[session]['Targeted Sess. Configured']) elif re.search('MPLS', protocolViewName, re.I): sessionsUp = int(stats[session]['BFD Up-Sessions']) totalSessions = int(stats[session]['BFD Session Count']) elif re.search('PIM', protocolViewName, re.I): sessionsUp = int(stats[session]['Rtrs. Running']) totalSessions = int(stats[session]['Rtrs. Configured']) # totalSessionsNotStarted = int(stats[session]['Sessions Not Started']) else: raise IxNetRestApiException('No protocol viewName found') if stats[session]['Port Name'] == portName: self.ixnObj.logInfo('\n\tPortName: {0}\n\t TotalSessionsUp: {1}\n\t TotalSessionsConfigured: {2}'.format( stats[session]['Port Name'], sessionsUp, totalSessions), timestamp=False) protocolStats[protocol] = {'Configured': totalSessions, 'Up': sessionsUp} return protocolStats