gNMI over gRPC: Capabilities, Get, Set, and Subscribe, Packet by Packet
This walkthrough uses captures from the late Nick Russo's free packet-capture library, preserved by the Internet Archive. They are in the gRPC archive, grpc_pcap.zip, under grpc_pcap/: grpc_gnmi_capabilities.pcapng, grpc_gnmi_get.pcapng, grpc_gnmi_set_update.pcapng, grpc_gnmi_set_replace.pcapng, grpc_gnmi_set_delete.pcapng, grpc_gnmi_subscribe.pcapng, and grpc_gnmi_unimplemented.pcapng. The archive also holds the gnmi.proto file needed to decode them. The rest of the library is listed on his job aid page. We decoded the captures with VisualEther, which turns a Wireshark PCAP into a sequence diagram with a plain-English caption on every message.
Network engineers have long configured routers by typing CLI commands and monitored them by polling SNMP counters every few minutes. Model-driven management replaces both with structured data. Every setting and counter has a place in a YANG data model, and a program reads it, changes it, or streams it by path. gNMI is one of the main protocols for doing that, and it runs over gRPC, Google's remote-procedure-call framework, on top of HTTP/2.
That stack is easy to use from a Python library and hard to see from the outside. When a gNMI client reports an error, gets an empty reply, or waits for telemetry that never comes, the answer is in the packets. These captures were made in cleartext, so every layer decodes:
- Capabilities. The client asks what the router supports: a 51 kB answer listing 767 YANG models.
- Get. One read of the router's VRF configuration, answered in 164 ms.
- Set. The same value sent as an update and as a replace, then the path deleted. Only the list it sits in differs.
- Subscribe. A telemetry stream sampling every 10 seconds, until the client cancels it.
- An error. An HTTP 200 that is really a failure:
grpc-status 12,unknown service gnmi.gNMI.
Each capture is drawn as an annotated sequence diagram. Each participant gets a lane, each message is an arrow numbered as in Wireshark, and each carries a caption saying what it does. Every diagram comes as an interactive viewer, an HTML page, and a printable PDF. In the viewer and the HTML page, clicking any message opens its full Wireshark field tree.
💡 Read the walkthrough and a diagram side by side: open the interactive diagram in a split-screen window, or open the HTML version in a new tab and snap the two windows side by side. Each section below links its own diagram.
What is gNMI?
gNMI (gRPC Network Management Interface) is a protocol from the OpenConfig project for reading, changing, and streaming the state of network devices. Its specification defines one gRPC service, gnmi.gNMI, with four methods (section 3):
| RPC | gRPC call type | Request | Response | In these captures |
|---|---|---|---|---|
| Capabilities | Unary: one request, one response | CapabilityRequest (empty) | CapabilityResponse: gNMI version, encodings, models | 51 kB answer, 261 ms after the request |
| Get | Unary | GetRequest: paths, data type, encoding | GetResponse: one Notification per path | 982-byte answer in 164 ms |
| Set | Unary | SetRequest: delete, replace, and update lists | SetResponse: one UpdateResult per operation | 598 to 644 ms |
| Subscribe | Bidirectional streaming | SubscribeRequest: a SubscriptionList | A stream of SubscribeResponses | First sample after 10.1 s, then every 10 s |
A few terms that run through every capture:
- gRPC. A framework for calling a function on another machine. The client calls
Get(request); gRPC carries the request over HTTP/2 and brings back the response. - HTTP/2. The binary version of HTTP (RFC 9113). One TCP connection carries many independent streams, each a request and its response, cut into frames.
- protobuf (Protocol Buffers). gRPC's message encoding: compact binary, defined by a
.protofile. Wireshark needs that file, here Nick'sgnmi.proto, to name the fields. - YANG. The language data models are written in. A model such as
openconfig-interfacesdefines a tree of containers, lists, and leaves; a gNMI path names a node in that tree. - OpenConfig. Vendor-neutral YANG models written by network operators. Routers also ship their own native models, such as Cisco's
Cisco-IOS-XR-*, and gNMI carries either.
The router is called the target in gNMI. In captures 1 to 4 it is the IOS-XR router in Cisco's public DevNet sandbox, at 10.10.20.50, serving gRPC in cleartext on TCP 5740. The client is a Python script using grpc-python 1.32.0.
How does gNMI use gRPC and HTTP/2?
Every gNMI call in these captures has the same shape. The gRPC rules are in PROTOCOL-HTTP2.md:
- HTTP/2 starts without negotiation. In cleartext, the client assumes the server speaks HTTP/2 ("prior knowledge," RFC 9113 section 3.3) and opens with a 24-byte connection preface and a
SETTINGSframe. This client also raises its receive window to 4 MiB and sends aPING, which gRPC uses to measure the round trip. - Each call is a POST on a new stream. The client uses odd stream numbers (RFC 9113 section 5.1.1), starting at 1. The
HEADERSframe carries:method POST,:path /gnmi.gNMI/Get,content-type: application/grpc, andte: trailers. The path is the whole method name: packagegnmi, servicegNMI, methodGet. - Each message has a 5-byte prefix. The
DATAframe holds a 1-byte compressed flag, a 4-byte length, then the protobuf message. A 39-byteGetRequestmakes a 44-byte DATA frame. - The result comes last, in trailers. The response is
HEADERSwith:status 200, then the data, then a secondHEADERSframe, the trailers, withgrpc-statusandgrpc-message. PROTOCOL-HTTP2.md requires the status in trailers "even if the status code is OK."
Point 4 is the one that catches people. HTTP 200 only says the HTTP/2 stream worked. Whether the gNMI call worked is in grpc-status, where 0 means OK. Capture 5 shows an HTTP 200 with a failure inside.
🔓 The credentials are in cleartext. The client sends username: admin and password: Cisco123 as ordinary request headers, which gRPC calls metadata. These are the public DevNet sandbox defaults, so we show them as they appear in the diagrams. On a real network anyone on the path could read them. That is why the gNMI specification (section 3.1) requires TLS and says neither side may fall back to an unencrypted session. It requires a username and password in the metadata, but doesn't name the keys; username and password are the common convention.
The diagrams show each TCP segment as one arrow, with every HTTP/2 frame it carries listed beneath it. Segments that carry only a piece of a large message are left out.
Capture 1: Capabilities, what the router supports
A client normally starts by asking what the target supports. The CapabilityRequest has no fields, so its DATA frame is just the 5-byte prefix with length 0: the method name in :path is the whole request.
The answer is the largest message in these captures. The target sends response headers one round trip after the request, then a 51,218-byte CapabilityResponse. The target's own SETTINGS were empty, which leaves its frame size at the RFC 9113 default of 16,384 bytes, so the response goes out as three full 16,384-byte DATA frames and one of 2,071. The trailers close the stream with grpc-status: 0, 261 ms after the request. The response says (gNMI specification section 3.2.2):
gNMI_version: 0.4.0. The gNMI version the target implements. Version 0.4.0, from June 2017, is the one that introduced today's path encoding.supported_encodings:JSON_IETFandASCII.JSON_IETFis JSON as YANG defines it in RFC 7951. There is noPROTO, and no plainJSON, although the specification says both ends must supportJSON(section 2.3.1).- 767
supported_models. Each is a YANG module's name, organization, and version: 694 Cisco native models, 68 OpenConfig models, and 5 IETF models. They includeopenconfig-interfaces1.0.2,openconfig-bgp3.0.1, and the two Cisco models the next captures use.
A client picks its paths and encoding from this list before it sends a Get, Set, or Subscribe.
Capture 2: Get, one read
The client reads the router's VRF configuration. This capture's diagram carries the fullest explanation of the HTTP/2 frames, so it is the one to open first.
The request. The 39-byte GetRequest has three fields that matter:
path: a single path element,Cisco-IOS-XR-infra-rsi-cfg:vrfs. That is thevrfscontainer of Cisco's native IOS-XR VRF model, written as YANG module name and top node.encoding:JSON_IETF.type: absent. A protobuf encoder leaves out a field set to its default, and the default here isALL. With no type, the specification says the target must return configuration, state, and operational data (section 3.3.1).
The full request as Wireshark decodes it, HEADERS and DATA together:
frame : Frame 8: Packet, 419 bytes on wire (3352 bits), 419 bytes captured (3352 bits) on interface utun2, id 0
Interface id : 0 (utun2)
null : Null/Loopback
ip : Internet Protocol Version 4, Src: 192.168.45.1, Dst: 10.10.20.50
Differentiated Services Field : 0x02 (DSCP: CS0, ECN: ECT(0))
010. .... = Flags : 0x2, Don't fragment
tcp : Transmission Control Protocol, Src Port: 58176, Dst Port: 5740, Seq: 100, Ack: 36, Len: 363
Conversation completeness : Complete, WITH_DATA (31)
Flags : 0x018 (PSH, ACK)
Options : (12 bytes), No-Operation (NOP), No-Operation (NOP), Timestamps
TCP Option - No-Operation (NOP)
TCP Option - No-Operation (NOP)
TCP Option - Timestamps : TSval 1362243465, TSecr 3405997052
Timestamps
SEQ/ACK analysis
http2 : HyperText Transfer Protocol 2
Stream : SETTINGS, Stream ID: 0, Length 0
Flags : 0x01, ACK
http2 : HyperText Transfer Protocol 2
Stream : HEADERS, Stream ID: 1, Length 266, POST /gnmi.gNMI/Get
Flags : 0x04, End Headers
Header : :scheme: http
Header : :method: POST
Header : :authority: 10.10.20.50:5740
Header : :path: /gnmi.gNMI/Get
Header : username: admin
Header : password: Cisco123
Header : te: trailers
Header : content-type: application/grpc
Header : user-agent: grpc-python/1.32.0 grpc-c/12.0.0 (osx; chttp2)
Header : grpc-accept-encoding: identity,deflate,gzip
Header : accept-encoding: identity,gzip
http2 : HyperText Transfer Protocol 2
Stream : WINDOW_UPDATE, Stream ID: 1, Length 4
Flags : 0x00
http2 : HyperText Transfer Protocol 2
Stream : DATA, Stream ID: 1, Length 44
Flags : 0x01, End Stream
grpc : GRPC Message: /gnmi.gNMI/Get, Request
protobuf : Protocol Buffers: /gnmi.gNMI/Get,request (Message: gnmi.GetRequest)
Field(2) : path
path : (35 bytes) (Message: gnmi.Path)
Field(3) : elem
elem : (33 bytes) (Message: gnmi.PathElem)
Field(1) : name =
Value : 436973636f2d494f532d58522d696e6672612d7273692d6366673a76726673
Field(5) : encoding =
Value : 04
http2 : HyperText Transfer Protocol 2
Stream : WINDOW_UPDATE, Stream ID: 0, Length 4
Flags : 0x00
The response. 164 ms after the request, about one round trip plus 83 ms of work on the target, the whole answer arrives in one TCP segment: response headers, a 982-byte GetResponse, and trailers with grpc-status: 0. The GetResponse holds one Notification:
- a
timestampof1600628241779344365, in nanoseconds since 1970 (section 2.2.1): 18:57:21.779 UTC on September 20, 2020; - one
Updateat pathvrfs, whose 921-bytejson_ietf_valholds VRFsAandBwith their BGP route targets.
The response also carries an error field, which can mislead a reader into thinking the Get failed. It is a zero-length gnmi.Error, a field that gnmi.proto marks deprecated. Errors now go in the trailers (section 2.5), and the trailers say grpc-status: 0.
Where the time went. The answer came 327 ms after the SYN: one round trip for TCP, one for the HTTP/2 settings, one for the request, and 83 ms at the target. A client that keeps its gRPC channel open pays the first two only once.
What do gNMI Set update, replace, and delete do?
A SetRequest has three lists: delete (paths), replace (path and value), and update (path and value). The library has three Set captures made a minute or two apart against the same vrfs container. The update and replace captures send the same 472-byte JSON value, VRF C with route targets 3:3, byte for byte; only the list it sits in differs. The delete capture sends the path alone. The diagram draws the replace; the other two differ only in that one field and in the result.
SetRequest list | What the target does (section 3.4.4) | op in the SetResponse | Request to response |
|---|---|---|---|
update | Merges: changes only what the value names. VRF C is added; A and B stay. | UPDATE (3) | 598 ms |
replace | Makes the node match the value: anything not in it is deleted or reset to its default. VRFs A and B go. | REPLACE (2) | 644 ms |
delete | Removes the node and everything under it. | DELETE (1) | 636 ms |
The difference between update and replace is the one to remember. Sending the same value with replace instead of update wipes every list entry you left out, so a replace on the wrong container can remove configuration you meant to keep.
One transaction. A single SetRequest can mix all three lists. The target processes deletes, then replaces, then updates, and applies them all or none (sections 3.4 and 3.4.3).
The response. The 55-byte SetResponse has one UpdateResult per operation, giving the path and the op, plus a timestamp for the change. The response also carries empty deprecated error fields, like the Get's. The trailers carry grpc-status: 0. All three runs succeeded.
Why a Set is slower. A Get took 164 ms; each Set took about 600 ms, with the same round-trip time to the sandbox. The extra half second is the target applying the change to its configuration. The capture can't show what happens inside the router, only the wait. The replace capture's file runs to 2.12 s only because of a stray SSH segment from another sandbox host at the end; the RPC ends at 956 ms.
How does gNMI streaming telemetry work?
Streaming telemetry replaces SNMP polling: instead of the client asking every few minutes, the router pushes data on a schedule or whenever it changes. In gNMI that is the Subscribe RPC, the only bidirectional-streaming method. Either side can send messages for as long as the call stays open.
The request. The 108-byte SubscribeRequest carries a SubscriptionList:
- List mode:
STREAM. The field is absent, andSTREAMis the default (section 3.5.1.2): keep the call open and keep sending. The alternatives areONCE, one snapshot and then close, andPOLL, a snapshot each time the client asks. - Subscription mode:
SAMPLE, every10000000000ns. The interval is in nanoseconds, so this is 10 seconds.SAMPLEsends every value each interval, changed or not;ON_CHANGEsends only changes. - Path: IOS-XR's own telemetry state,
Cisco-IOS-XR-telemetry-model-driven-oper:telemetry-model-driven/destinations/destination. The client packs it into a single path element. The specification says each element should be one node of the tree (section 2.2.2), so this breaks its convention; IOS-XR accepts it and splits it into three elements in its replies. - Encoding:
PROTO. Values come back typed (string_val,uint_val,bool_val) instead of as JSON. The Capabilities answer didn't listPROTO, yet the target accepts it here. The specification's rule on unsupported encodings covers Get and Set, not Subscribe.
The client then sends an empty DATA frame with END_STREAM. That closes only the client's direction: this script has no more requests to send. The subscription stays up.
Ten seconds of nothing. The target's response headers arrive 10.13 s after the request, together with the first sample. IOS-XR took the first sample one interval after the subscription started, not at once; its own data shows the collection starting ten seconds after the request. The specification doesn't say when the first SAMPLE update must go out. A client that gives up, or reports "no telemetry," in the first interval may simply be impatient.
The first sample and sync_response. The first SubscribeResponse is 4,929 bytes: one Notification with a timestamp, a prefix shared by all its updates, and 63 Updates. A second, 2-byte SubscribeResponse follows in the same TCP segment with only sync_response: true. It marks the end of the initial set of values, which the specification requires once per subscription (section 3.5.2.3). A client that waits until it is in sync before acting waits for this message.
The stream reports on itself. The path asked for the router's telemetry destinations, and the only destination is this subscription, GNMI_1001. Its counters tick up with each sample: total-collections goes 0, 1, 2, 3, and total-num-of-bytes-sent goes 0, 4,929, 9,868, 14,807, the exact running total of the SubscribeResponse sizes. The target's timestamps run 10.003, 10.004, and 10.003 s apart.
How it ends. A STREAM subscription never ends on its own. At 45.16 s the client cancels the call by resetting stream 1 with RST_STREAM error code CANCEL (8). That is how the gNMI specification says to end a subscription (section 3.5), and gRPC maps it to call cancellation. No trailers follow, so the client's library reports status CANCELLED locally. The TCP teardown after it is messy, ending with a client RST and a run of retransmitted FINs from the target, but that is cleanup on a connection the client had already abandoned.
What is the difference between gNMI Get and Subscribe?
Both read data by path, and both return Notification messages with the same timestamp, prefix, and Update structure. The difference is time:
| Get | Subscribe | |
|---|---|---|
| gRPC call type | Unary | Bidirectional streaming |
| Answers | Once, then the call ends | Repeatedly, until someone cancels |
| Initial snapshot marker | None needed | sync_response: true |
| Typical use | Read configuration, check a value | Monitor counters, state, and events |
| In these captures | Answer in 164 ms | First sample after 10.1 s, then every 10 s |
Subscribe with list mode ONCE sits between the two: one snapshot, a sync_response, and the target closes the call.
What does "unknown service gnmi.gNMI" mean?
This capture is from the same client a day earlier, against a different IOS-XR router reached over the internet on TCP 57400. That router's gRPC server is clearly running: it answers Cisco's own gRPC configuration service in other captures from the same library. The client sends a normal GetRequest for openconfig-interfaces.
14.3 ms later, one HEADERS frame with END_STREAM answers and ends the call:
frame : Frame 17: Packet, 133 bytes on wire (1064 bits), 133 bytes captured (1064 bits) on interface en0, id 0
Interface id : 0 (en0)
eth : Ethernet II, Src: 48:5d:36:c9:c9:6b, Dst: c8:e0:eb:13:de:6d
Destination : c8:e0:eb:13:de:6d
Source : 48:5d:36:c9:c9:6b
ip : Internet Protocol Version 4, Src: 18.206.119.175, Dst: 192.168.1.151
Differentiated Services Field : 0x00 (DSCP: CS0, ECN: Not-ECT)
010. .... = Flags : 0x2, Don't fragment
tcp : Transmission Control Protocol, Src Port: 57400, Dst Port: 61190, Seq: 49, Ack: 456, Len: 67
Conversation completeness : Complete, WITH_DATA (31)
Flags : 0x018 (PSH, ACK)
Options : (12 bytes), No-Operation (NOP), No-Operation (NOP), Timestamps
TCP Option - No-Operation (NOP)
TCP Option - No-Operation (NOP)
TCP Option - Timestamps : TSval 251414286, TSecr 1309840497
Timestamps
SEQ/ACK analysis
http2 : HyperText Transfer Protocol 2
Stream : HEADERS, Stream ID: 1, Length 58, 200 OK
Flags : 0x05, End Headers, End Stream
Header : :status: 200 OK
Header : content-type: application/grpc
Header : grpc-status: 12
Header : grpc-message: unknown service gnmi.gNMI
This is a gRPC Trailers-Only response: the status line and the trailers in one header block, with no body. PROTOCOL-HTTP2.md allows it "for calls that produce an immediate error." It reads:
:status: 200. HTTP worked.grpc-status: 12, which isUNIMPLEMENTED. The gRPC call failed.grpc-message: unknown service gnmi.gNMI.
The router's gRPC server parsed the request, but has no service named gnmi.gNMI registered, so the call never reached a gNMI handler. The gRPC status code table lists "Method not found at server" as UNIMPLEMENTED. grpc-go writes exactly "unknown service" when the service is missing and "unknown method" when the service exists but the method doesn't.
When you see this error, check:
- Is gNMI enabled on the device? On many platforms, the gRPC server and the gNMI service are separate settings.
- Is the client on the right port? A device can run several gRPC servers, and only some may serve gNMI.
- Does the software release support gNMI at all?
Whichever it is, the fix is on the target, not in the request. And a client that logs only "HTTP 200" here has hidden the failure: always check grpc-status.
Can one connection carry many gNMI calls?
Yes, and that is the point of HTTP/2 streams. Nick's captures each open a new TCP connection for one call. In a capture of our own against a lab gNMI target, one TCP connection carries 16 calls: four Capabilities requests in a single TCP segment, on streams 1, 3, 5, and 7, then four Gets, four Sets, and four Subscribes, each on its own stream.
Each call is matched to its response by stream number, so responses can come back in any order. The TCP handshake and the HTTP/2 settings exchange happen once. In the Get capture those two cost two round trips, about half the time to the answer; a long-lived client pays them once for all its calls.
gNMI vs NETCONF
NETCONF is the older model-driven protocol, standardized by the IETF in 2006 and revised as RFC 6241 in 2011. Both carry YANG-modeled data; they differ in how:
| gNMI | NETCONF | |
|---|---|---|
| Transport | gRPC over HTTP/2, TLS required | SSH required (RFC 6241 section 2.3) |
| Encoding | protobuf messages, values in JSON_IETF or PROTO | XML |
| Read | Get | <get>, <get-config> |
| Write | Set with update, replace, delete | <edit-config> with merge, replace, create, delete, remove |
| Candidate configuration and commit | Not in the core specification; each SetRequest is one transaction | Candidate datastore and <commit> (section 8.3) |
| Streaming telemetry | Built in: Subscribe | A separate mechanism (YANG-Push) |
In practice gNMI is the usual choice for streaming telemetry, and many operators use NETCONF or gNMI for configuration depending on what their devices and tools support. OpenConfig has added a commit-confirmed extension to gNMI for operators who want NETCONF-style rollback.
Troubleshooting a gNMI client
Capture on the client, or on a port mirror, and decode the gRPC TCP port as HTTP/2. Production gNMI uses TLS, so you need the session keys first. Then:
- No connection? Look for the TCP SYN and SYN-ACK. No SYN-ACK points to a firewall or the wrong port.
- Connection, but no HTTP/2? A client speaking cleartext to a TLS port, or the reverse, never gets a
SETTINGSframe back. - HTTP 200, but an error? Read
grpc-statusandgrpc-messagein the trailers or the Trailers-Only header block. 12 with "unknown service" means gNMI isn't served there; 16 means bad credentials; 3 means an invalid argument, such as a bad path. - A response with an
errorfield? If it is empty andgrpc-statusis 0, the call succeeded. The field is deprecated. - No telemetry? Check how long you waited against
sample_interval, and look for theSubscribeResponseandsync_response. These captures waited 10 seconds for the first sample. - A Set that removed too much? Check whether the request used
replacewhereupdatewas meant.
Wireshark needs the .proto files to name protobuf fields. Point its protobuf search path at the folder holding gnmi.proto, gnmi_ext.proto, and everything they import, and turn on the options that load all files and show fields as Wireshark fields. Nick's gnmi.proto imports any.proto and descriptor.proto by bare name, so those two must sit in the same folder.
Frequently asked questions
What port does gNMI use? There is no single standard port. These captures use TCP 5740 (the DevNet sandbox) and TCP 57400 (a Cisco IOS-XR default); 9339 is also common. Check the device configuration.
Does gNMI work without TLS? The specification says no: TLS is required, and fallback to cleartext is forbidden. Lab devices such as the DevNet sandbox often allow cleartext anyway, which is what made these captures readable.
Is a gNMI path the same as an XPath? Close, but not the same. A gNMI path is a list of elements, each with a name and optional keys, such as destination[destination-id=GNMI_1001]. Tools often print it in an XPath-like form.
What is origin in a gNMI path? It says which schema the path belongs to. An empty origin defaults to openconfig (section 2.7.1). The Subscribe responses here set it to the Cisco module Cisco-IOS-XR-telemetry-model-driven-oper.
Why did my Subscribe get no data for a while? In SAMPLE mode, the target may wait one interval before the first sample, as IOS-XR did here. With ON_CHANGE, after the initial snapshot, nothing arrives until something changes.
How does a gNMI client stop a subscription? It cancels the RPC (on the wire, RST_STREAM with code CANCEL) or closes the whole connection.
What is the difference between gRPC and gNMI? gRPC is the general framework for remote calls. gNMI is one service defined on top of it, with four methods for network management. A device can run gRPC without serving gNMI, which is what capture 5 shows.
Takeaways
- gNMI is four gRPC methods. Capabilities, Get, and Set are unary; Subscribe streams in both directions.
- Each call is an HTTP/2 POST on its own stream.
:pathnames the method, and each message has a 5-byte prefix. - The result is in the trailers, not the HTTP status. HTTP 200 with
grpc-status 12is a failure. An empty deprecatederrorfield withgrpc-status 0is a success. replacedeletes what it doesn't mention;updatemerges. The same value in the wrong list can remove configuration.- Telemetry may not start for one interval. IOS-XR sent its first 10-second sample after 10 seconds, then
sync_response. - "unknown service gnmi.gNMI" is a target-side problem. The gRPC server is up, but gNMI isn't served on that port.
- Production gNMI needs TLS. Here the credentials crossed the wire in cleartext.
For another protocol that pushes data from devices, see How MQTT Works over TCP, WebSockets, and TLS.