Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding StarOS parser Commands #856

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 111 additions & 0 deletions src/genie/libs/parser/staros/show session disconnect-reasons.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import re
from genie.metaparser import MetaParser
from genie.metaparser.util.schemaengine import Any, Schema

class ShowSesDisReaSchema(MetaParser):
"""Schema for show session disconnect-reasons"""

schema = {
'dis_rea_table': {
'TOTAL_DISCONNECTS': str,
Any(): {
'NUM_DISC': str,
'PERCENTAGE': str,
},
}
}

class ShowSessionDiss(ShowSesDisReaSchema):
"""Parser for show session disconnect-reasons"""

cli_command = 'show session disconnect-reasons'

"""
[local]COR-ASR5K-1# show session disconnect-reasons
Monday January 29 14:48:31 ART 2024
Session Disconnect Statistics

Total Disconnects: 12345249830

Disconnect Reason Num Disc Percentage
----------------------------------------------------- ---------- ----------
Admin-disconnect 898190 0.00728
Remote-disconnect 11802373713 95.60255
Local-disconnect 3653063 0.02959
Idle-Inactivity-timeout 414551522 3.35798
Session-setup-timeout 384617 0.00312
internal-error 2 0.00000
path-failure 117515 0.00095
Gtp-unknown-pdp-addr-or-pdp-type 28400654 0.23005
static-ip-validation-failed 5 0.00000
ggsn-aaa-auth-req-failed 2 0.00000
Long-duration-timeout 11185805 0.09061
failed-update-handoff 1212400 0.00982
call-internal-reject 29 0.00000
failed-auth-with-charging-svc 11891 0.00010
ims-authorization-failed 779951 0.00632
Auth-failed 24576425 0.19908
Gtp-context-replacement 3179378 0.02575
ims-authorization-revoked 5270 0.00004
ims-auth-decision-invalid 1 0.00000
dt-ggsn-tun-reestablish-failed 6064313 0.04912
No-response 3459270 0.02802
unknown-apn 2 0.00000
gtpc-path-failure 343664 0.00278
gtpu-path-failure 923654 0.00748
disconnect-from-policy-server 10969 0.00009
gtpu-err-ind 8389798 0.06796
apn-denied-no-subscription 3 0.00000
Sgw-context-replacement 3358732 0.02721
ggsn-no-rsp-from-sgsn 10433802 0.08452
invalid-qci 1 0.00000
4Gto3G-context-replacement 615958 0.00499
3Gto4G-context-replacement 10801712 0.08750
Local-fallback-timeout 1 0.00000
srvcc-ps-to-cs-handover 2 0.00000
pgw-transaction-timeout 1 0.00000
path-failure-s5 189532 0.00154
path-failure-s11 570060 0.00462
gtpu-path-failure-s5u 17299 0.00014
gtpu-path-failure-s1u 1561 0.00001
gtpu-err-ind-s5u 13387 0.00011
disconnect-from-charging-server 8725676 0.07068
"""

def cli(self, output=None):
if output is None:
out = self.device.execute(self.cli_command)
else:
out = output

# initial return dictionary
session_dict = {}
result_dict = {}

# initial regexp pattern
p0= re.compile(r'Total\s\Disconnects:(?P<total_disconnects_title>\s\d+)')
p1 = re.compile(r'((?P<disconnect_reason>[\w\-*]+)\s+(?P<num_disc>\d+)\s+(?P<percentage>\d+\.\d{5}))')

for line in out.splitlines():
line = line.strip()

m = p0.match(line)
if m:
if 'dis_rea_table' not in session_dict:
result_dict = session_dict.setdefault('dis_rea_table',{})
total_dis = m.groupdict()['total_disconnects_title']

result_dict['TOTAL_DISCONNECTS'] = total_dis

m = p1.match(line)
if m:
if 'dis_rea_table' not in session_dict:
result_dict = session_dict.setdefault('dis_rea_table',{})
disconnect = m.groupdict()['disconnect_reason']
number_disconnected = m.groupdict()['num_disc']
per = m.groupdict()['percentage']
result_dict[disconnect] = {}
result_dict[disconnect]['NUM_DISC'] = number_disconnected
result_dict[disconnect]['PERCENTAGE'] = per

return session_dict
Original file line number Diff line number Diff line change
@@ -0,0 +1,260 @@
"""starOS implementation of show_active-charging_charging-action_all.py

"""
import re
from genie.metaparser import MetaParser
from genie.metaparser.util.schemaengine import Any, Optional

class ShowActiveChargingSchema(MetaParser):
"""Schema for show active-charging charging-action all"""

schema = {
'charging-action': {
Any():{
Optional('Content ID'): int,
Optional('EGCDRs'): str,
Optional('Limit For Uplink Bandwidth'): str,
Optional('Peak Data Rate Uplink'): str,
Optional('Peak Burst Size Uplink'): str,
Optional('Limit For Downlink Bandwidth'): str,
Optional('Peak Data Rate Downlink'): str,
Optional('Peak Burst Size Downlink'): str,
Optional('Credit-Control'): str,
Optional('Xheader-Insert'): str,
Optional('Encryption Type'): str,
Optional('Encryption Key'): str,
Optional('Redirect URL'): str,
Optional('Discard'): str,
},
}
}


class ShowActiveCharging(ShowActiveChargingSchema):
"""Parser for show active-charging charging-action all"""

cli_command = 'show active-charging charging-action all'

"""
Charging Action Name: namecg
Content ID: 100
Service ID: 0
EDRs: Disabled
EGCDRs: Enabled
Rf: Disabled
UDRs: Enabled
Flow Idle Timeout: 300 (secs)
Limit For Flow Type: Disabled
Bandwidth ID: 0
Limit For Uplink Bandwidth: Enabled
Peak Data Rate : 512000 bits/second
Peak Burst Size: 48000 bytes
Violate Action : Discard
Limit For Downlink Bandwidth: Enabled
Peak Data Rate : 512000 bits/second
Peak Burst Size: 48000 bytes
Violate Action : Discard
Throttle-Suppress Timeout: n/a
QoS Renegotiate Traffic-Class: Disabled
QoS Class Identifier: Not Configured
IP Type of Service: Not Configured
Tethering Block Feature: Not Configured
IP-TTL Value: n/a
Content Filtering: Enabled
Service Chain: Not Configured
UP Service Chain: Not Configured
Credit-Control: Enabled
Xheader-Insert: Xheadername
Encryption Type: rc4md5
Encryption Key : Funa82FaCH1s3fev
Message Type: Request
Flow Action:
Redirect URL: Disabled
Redirect URL from OCS: Disabled
Redirect to Video Server: Disabled
Clear Quota Retry Timer: Disabled
Conditional Redirect: Disabled
Discard: Disabled
Terminate-Flow: Disabled
Terminate-Session: Disabled
Rulebase Change: Disabled
Billing Action:
Event Data Record: Disabled
GGSN charging Data Record: Enabled
Rf Accounting: Disabled
User Data Record: Enabled
Radius Accounting Record: Disabled
Charge Volume: ip bytes
PCO-Custom1 value: n/a
Flow-Mapping Idle Timeout: 300 (secs)
DNS Proxy Bypass: Disabled
Discard on Readdressing Failure: Disabled
"""

def cli(self, output=None):
if output is None:
out = self.device.execute(self.cli_command)
else:
out = output

# initial return dictionary
cca_dict = {}
result_dict = {}

# Define regular expression patterns
p0 = re.compile(r'Charging Action Name:\s+(?P<name>\S+)')
p1 = re.compile(r'Content ID:\s+(?P<content_id>\d+)')
p2 = re.compile(r'EGCDRs:\s+(?P<egcdrs>\S+)')
p3 = re.compile(r'Limit For Uplink Bandwidth:\s+(?P<enabled_ul>\S+)')
p4 = re.compile(r'Peak Data Rate\s+:\s+(?P<peak_data_rate_ul>\S+\s+bits/second)')
p5 = re.compile(r'Peak Burst Size:\s+(?P<peak_burst_size_ul>\S+\s+bytes)')
p6 = re.compile(r'Limit For Downlink Bandwidth:\s+(?P<enabled_dl>\w+)')
p7 = re.compile(r'Peak Data Rate\s+:\s+(?P<peak_data_rate_dl>\S+\s+bits/second)')
p8 = re.compile(r'Peak Burst Size:\s+(?P<peak_burst_size_dl>\S+\s+bytes)')
p9 = re.compile(r'Credit-Control:\s+(?P<credit_control>\S+)')
p10 = re.compile(r'Xheader-Insert:\s+(?P<xheader_insert>\S+)')
p11 = re.compile(r'Encryption Type:\s+(?P<encryption_type>\S+)')
p12 = re.compile(r'Encryption Key\s+:\s+(?P<encryption_key>\S+)')
p13 = re.compile(r'Redirect URL: (?P<redirect_url>\S+)')
p14 = re.compile(r'Discard: (?P<discard>\S+)')

# Split output by lines and iterate
for line in out.splitlines():
line = line.strip()

# Charging Action Name
m = p0.match(line)
if m:
if 'charging-action' not in cca_dict:
result_dict = cca_dict.setdefault('charging-action', {})
charging_action = m.groupdict()['name']
result_dict[charging_action] = {}
continue

# Content ID
m = p1.match(line)
if m:
if 'charging-action' not in cca_dict:
result_dict = cca_dict.setdefault('charging-action', {})
content_id = m.groupdict()['content_id']
result_dict[charging_action]["Content ID"] = int(content_id)
continue

# EGCDRs
m = p2.match(line)
if m:
if 'charging-action' not in cca_dict:
result_dict = cca_dict.setdefault('charging-action', {})
egcdrs = m.groupdict()['egcdrs']
result_dict[charging_action]["EGCDRs"] = egcdrs
continue

# Limit For Uplink Bandwidth
m = p3.match(line)
if m:
if 'charging-action' not in cca_dict:
result_dict = cca_dict.setdefault('charging-action', {})
limit_for_uplink = m.groupdict()['enabled_ul']
result_dict[charging_action]["Limit For Uplink Bandwidth"] = limit_for_uplink
continue

# Peak Data Rate Uplink
m = p4.match(line)
if m:
if 'charging-action' not in cca_dict:
result_dict = cca_dict.setdefault('charging-action', {})
peak_data_rate_ul = m.groupdict()['peak_data_rate_ul']
result_dict[charging_action]["Peak Data Rate Uplink"] = peak_data_rate_ul
continue

# Peak Burst Size Uplink
m = p5.match(line)
if m:
if 'charging-action' not in cca_dict:
result_dict = cca_dict.setdefault('charging-action', {})
peak_burst_size_ul = m.groupdict()['peak_burst_size_ul']
result_dict[charging_action]["Peak Burst Size Uplink"] = peak_burst_size_ul
continue

# Limit For Downlink Bandwidth
m = p6.match(line)
if m:
if 'charging-action' not in cca_dict:
result_dict = cca_dict.setdefault('charging-action', {})
limit_for_downlink = m.groupdict()['enabled_dl']
result_dict[charging_action]["Limit For Downlink Bandwidth"] = limit_for_downlink
continue

# Peak Data Rate Downlink
m = p7.match(line)
if m:
if 'charging-action' not in cca_dict:
result_dict = cca_dict.setdefault('charging-action', {})
peak_data_rate_dl = m.groupdict()['peak_data_rate_dl']
result_dict[charging_action]["Peak Data Rate Downlink"] = peak_data_rate_dl
continue

# Peak Burst Size Downlink
m = p8.match(line)
if m:
if 'charging-action' not in cca_dict:
result_dict = cca_dict.setdefault('charging-action', {})
peak_burst_size_dl = m.groupdict()['peak_burst_size_dl']
result_dict[charging_action]["Peak Burst Size Downlink"] = peak_burst_size_dl
continue

# Credit-Control
m = p9.match(line)
if m:
if 'charging-action' not in cca_dict:
result_dict = cca_dict.setdefault('charging-action', {})
credit_control = m.groupdict()['credit_control']
result_dict[charging_action]["Credit-Control"] = credit_control
continue

# Xheader-Insert
m = p10.match(line)
if m:
if 'charging-action' not in cca_dict:
result_dict = cca_dict.setdefault('charging-action', {})
xheader_insert = m.groupdict()['xheader_insert']
result_dict[charging_action]["Xheader-Insert"] = xheader_insert
continue

# Encryption Type
m = p11.match(line)
if m:
if 'charging-action' not in cca_dict:
result_dict = cca_dict.setdefault('charging-action', {})
encryption_type = m.groupdict()['encryption_type']
result_dict[charging_action]["Encryption Type"] = encryption_type
continue

# Encryption Key
m = p12.match(line)
if m:
if 'charging-action' not in cca_dict:
result_dict = cca_dict.setdefault('charging-action', {})
encryption_key = m.groupdict()['encryption_key']
result_dict[charging_action]["Encryption Key"] = encryption_key
continue

# Redirect URL
m = p13.match(line)
if m:
if 'charging-action' not in cca_dict:
result_dict = cca_dict.setdefault('charging-action', {})
redirect_url = m.groupdict()['redirect_url']
result_dict[charging_action]["Redirect URL"] = redirect_url
continue

# Discard
m = p14.match(line)
if m:
if 'charging-action' not in cca_dict:
result_dict = cca_dict.setdefault('charging-action', {})
discard = m.groupdict()['discard']
result_dict[charging_action]["Discard"] = discard
continue

return cca_dict
Loading