<jupyter_start><jupyter_text>Preparation of the environment TASK 17 (OPTIONAL)Enable logging at the debug level:<jupyter_code>from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"
import logging
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
logging.debug("test")<jupyter_output><empty_output><jupyter_text>TASK 18Import the Cisco gNMI package and its client module:<jupyter_code>from cisco_gnmi import ClientBuilder<jupyter_output><empty_output><jupyter_text>Connectivity to the deviceTASK 19<jupyter_code>builder = ClientBuilder('198.18.134.72:57777')
builder.set_os('IOS XR')
builder.set_secure_from_target()
builder.set_ssl_target_override()
builder.set_call_authentication('cisco', 'cisco')

client = builder.construct()<jupyter_output><empty_output><jupyter_text>Configuration of model-driven telemetry streaming (dynamic, dial-in) Configure the IOS XR device for model-driven telemetry streaming using the **gNMI dial-in** mechanism. In this case, the MDT receiver (i.e., the host that runs the Jupyter notebook - `198.18.134.50`) will contact the device (**dial-in**) and exchange SYN -- SYN-ACK -- ACK with the device while establishing the connection.If the connection is successfully created, the device will start streaming telemetry data towards the collection point.The collection will stop when the receiver cancels the subscription (e.g., _Interrupt the kernel_ of the Jupyter notebook) or when the session terminates (e.g., when polling once).Here, we subscribe to updates of the operational state (`Cisco-IOS-XR-infra-statsd-oper`) of the management interface (`[interface-name="MgmtEth0/RP0/CPU0/0"]`). Specifically, we are looking for generic counters regarding this interface :- (multicast / broadcast) packets received / sent- bytes received / sent- output / input drops- output / input queue drops- CRC errors- ...Notice that the subscription method (`subscribe_xpaths()`) has a few parameters:- `xpath_subscriptions`: the xpath(s) to use for subscription- `request_mode`: whether to stream continuously, once, or to poll data. Can be one of: STREAM, ONCE, POLL- `sub_mode`: whether to sample regularly the data, or to stream the data only when a change is happening. Can be one of: TARGET_DEFINED, ON_CHANGE, SAMPLE- `encoding`: the encoding format of the returned data. Can be one of: JSON, BYTES, PROTO, ASCII, JSON_IETF- `sample_interval`: the time interval at which samples of data should be streamed [ns]- `suppress_redundant`: whether to avoid sending duplicate data- `heartbeat_interval`: the enforced time interval after which data should be sent when `suppress_redundant` is in use [ns]In this example, we expect to receive data regularly, every 60 seconds.TASK 20Create the subscription:<jupyter_code># Subscribe
subscribe_reply = client.subscribe_xpaths(xpath_subscriptions='Cisco-IOS-XR-infra-statsd-oper:infra-statistics/interfaces/interface[interface-name="MgmtEth0/RP0/CPU0/0"]/generic-counters',
                                          request_mode='STREAM',
                                          sub_mode='SAMPLE',
                                          encoding='PROTO',
                                          sample_interval=60000000000, # Every 60 seconds
                                          suppress_redundant=False,
                                          heartbeat_interval=None
)

# Print the MDT data
for m in subscribe_reply:
    print(m)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08447488584474885, 'fraction_numerical': 0.01598173515981735, 'mean_word_length': 4.043165467625899, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '261872', 'license': 'Apache-2.0', 'n_tokens_mistral': 1005, 'n_tokens_neox': 933, 'n_words': 331, 'path': 'cisco-gNMI-dynamic-subscription.ipynb', 'repo_name': 'bigevilbeard/xr-gnmi-lab', 'size': '3504'}