Closed nskalis closed 1 year ago
The request is sent as proto encoded bytes not json.
If you want to print the request in json format run the same command with --format protojson
:
gnmic --address x.x.x.x:57400 --username xxx --password xxx --insecure \
get \
--path /state/system/platform \
--encoding json \
--print-request \
--format protojson
Thank you. Then
nokia/sros
as a grpc server doesn't implement/respect fully the specification https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md see Content-Type → "content-type" "application/grpc" [("+proto" / "+json" / {custom})]
In other words, the below attempt returns 0
bytes and a HTTP 200 OK
status.
echo -en '\x00\x00\x00\x00S{"path": [{"elem": [{"name": "state"}, {"name": "system"}, {"name": "platform"}]}]}' | curl --silent --noproxy '*' --insecure --http2 --http2-prior-knowledge --header "Content-Type: application/grpc+json" --header "TE: trailers" --header "Username: xxx" --header "Password: xxx" --data-binary @- --output - http://x.x.x.x:57400/gnmi.gNMI/Get
Following the same approach with other well-known grpc servers, I get the expected json
reply.
Assuming you're working for or you're in close relationship with Nokia, can you possibly advise if the http header content-type
is honoured as per spec by the router?
Unfortunately, I believe the case is that nokia/sros
doesn't support the content-type
header as per the grpc specification.
< HTTP/2 200
< content-type: application/grpc
< grpc-status: 13
< grpc-message: Unable to parse request
Hi @nskalis it is not clear what you're trying to do... Nokia SR OS supports gNMI service (as per gNMI specification) and therefore gNMI clients (such as gnmic and others) can interact with it.
grpc
is a slim extension of http2
. The official page of grpc
outlines the rules around it.
What I wish to achieve is:
grpc
generated code, but a http/2 POST
requestjson
insteadIt is the simplest approach that works (in any context) with "normal" (as per spec) grpc servers.
What the gNMI
specification dictates is only the structure of the body (of the http/2 request).
For now, I think I have to encode the body of the request based on the standard method outlined here https://googleapis.dev/python/protobuf/latest/google/protobuf/json_format.html for example, in protobuf
.
What the gNMI specification dictates is only the structure of the body (of the http/2 request).
gNMI spec defines the service as a protobuf-based service
https://github.com/openconfig/reference/blob/ff092419eced6c2cf01bb747151091d684e2fc85/rpc/gnmi/gnmi-specification.md?plain=1#L85-L91 https://github.com/openconfig/gnmi/blob/master/proto/gnmi/gnmi.proto
Depends on the way you look at it; or, only a parameter (url
) in a http request.
cURL
: echo -en '\x00\x00\x00\x00\x00' | curl --silent --noproxy '*' --insecure --http2 --http2-prior-knowledge --header "Content-Type: application/grpc+json" --header "TE: trailers" --header "Username: xxx" --header "Password: xxx" --data-binary @- --output - http://x.x.x.x:57400/gnmi.gNMI/Capabilities
. It succeeds.gnmic CLI
: /usr/local/sbin/gnmic --address x.x.x.x:57400 --username xxx --password xxx --insecure capabilities
If you use tcpdump
for both approaches above, they are one and the same.
So, what gnmic CLI
does is 1 command away in cURL
, and 2 lines away in any http/2
client (because nokia/sros
grpc server seems not to honour the http header content-type
subtypes) and the body
of the request has to be encoded in protobuf
.
Let me organise the .proto
files, and I'll let you know the outcome (if interested) in 2-3 weeks as I am working part-time on it.
Works with protobuf
encoding too. I'll request this feature from the vendor through the official channels. Thank you for being able to print out the request through gnmic
.
Hi, and thank you for making
gnmic
available.I have a question to ask you; if I issue a
GET
request for exampleThe
--print-request
flag prints the following out:The body of the request is not actually encoded as
json
based ontcpdump
(but inprotobuf
), the response is decoded injson
.Would you be so kind to advise how the actual
json
document in the request looks like? In other words, what thejson_format
(fromprotobuf
) would print out?I tried and failed with
{"path": [{"elem": [{"name": "state"}, {"name": "system"}, {"name": "platform"}]}], "type": "ALL", "encoding": "JSON"
{"path": [{"elem": {"name": "state"}}, {"elem": {"name": "system"}}, {"elem": {"name": "platform"}}], "type": "ALL", "encoding": "JSON"}