Skip to content
This repository has been archived by the owner on Oct 28, 2022. It is now read-only.

Issue with JSON formatting when Requested-path ! = Response-prefix #598

Open
yashikakn opened this issue May 12, 2022 · 1 comment
Open

Comments

@yashikakn
Copy link

When trying to retrieve ip-addresses data using GNMI subscribe request, I see the ip addresses data is received from the DUT (please refer to attached file <json.encoding.raw>) but looks like the tool has some issue with JSON formatting when Requested-path ! = Response-prefix.
(file <json.encoding.formatted>)

Here, requested path is :/interfaces/interface[name=lo0]/subinterfaces/subinterface[index=0]/

Same works with –encoding proto. Please refer to attached files < proto.encoding.raw, proto.encoding.formatted>

Sample outputs:

  1. With encoding 'json'
    gnmic -a 10.92.196.149:50051 sub --path "/interfaces/interface[name="lo0"]/subinterfaces/subinterface[index=0]" -u root -p Embe1mpls --insecure --encoding json --mode once{
    "source": "10.92.196.149:50051",
    "subscription-name": "default-1652375785",
    "timestamp": 1652375789566454228,
    "time": "2022-05-12T10:16:29.566454228-07:00",
    "prefix": "interfaces/interface[name=lo0]/subinterfaces/subinterface[index=0]",
    "updates": [
    {
    "Path": "state/index",
    "values": {
    "state/index": 0
    }
    },
    {
    "Path": "state/description",
    "values": {
    "state/description": ""
    }
    },
    {
    "Path": "state/enabled",
    "values": {
    "state/enabled": 1
    }
    },
    {
    "Path": "state/name",
    "values": {
    "state/name": "lo0.0"
    }
    },
    {
    "Path": "state/ifindex",
    "values": {
    "state/ifindex": 16
    }
    },
    {
    "Path": "state/admin-status",
    "values": {
    "state/admin-status": "UP"
    }
    },
    {
    "Path": "state/oper-status",
    "values": {
    "state/oper-status": "UP"
    }
    },
    {
    "Path": "state/last-change",
    "values": {
    "state/last-change": 0
    }
    },
    {
    "Path": "state/logical",
    "values": {
    "state/logical": 1
    }
    }
    ]
    }
    {
    "source": "10.92.196.149:50051",
    "subscription-name": "default-1652375785",
    "timestamp": 1652375789570389796,
    "time": "2022-05-12T10:16:29.570389796-07:00",
    "prefix": "interfaces/interface[name=lo0]/subinterfaces/subinterface[index=0]",
    "updates": [
    {
    "Path": "ipv4/state/enabled",
    "values": {
    "ipv4/state/enabled": 1
    }
    },
    {
    "Path": "ipv4/state/mtu",
    "values": {
    "ipv4/state/mtu": 65535
    }
    }
    ]
    }
    {
    "source": "10.92.196.149:50051",
    "subscription-name": "default-1652375785",
    "timestamp": 1652375789572884485,
    "time": "2022-05-12T10:16:29.572884485-07:00",
    "prefix": "interfaces/interface[name=lo0]/subinterfaces/subinterface[index=0]",
    "updates": [
    {
    "Path": "ipv6/state/enabled",
    "values": {
    "ipv6/state/enabled": 1
    }
    },
    {
    "Path": "ipv6/state/mtu",
    "values": {
    "ipv6/state/mtu": 4294967295
    }
    }
    ]
    }

  2. With encoding 'proto':
    gnmic -a 10.92.196.149:50051 sub --path "/interfaces/interface[name="lo0"]/subinterfaces/subinterface[index=0]" -u root -p Embe1mpls --insecure --encoding proto --mode once
    {
    "source": "10.92.196.149:50051",
    "subscription-name": "default-1652375806",
    "timestamp": 1652375809449870735,
    "time": "2022-05-12T10:16:49.449870735-07:00",
    "prefix": "interfaces/interface[name=lo0]/subinterfaces/subinterface[index=0]",
    "updates": [
    {
    "Path": "state/index",
    "values": {
    "state/index": 0
    }
    },
    {
    "Path": "state/description",
    "values": {
    "state/description": ""
    }
    },
    {
    "Path": "state/enabled",
    "values": {
    "state/enabled": true
    }
    },
    {
    "Path": "state/name",
    "values": {
    "state/name": "lo0.0"
    }
    },
    {
    "Path": "state/ifindex",
    "values": {
    "state/ifindex": 16
    }
    },
    {
    "Path": "state/admin-status",
    "values": {
    "state/admin-status": "UP"
    }
    },
    {
    "Path": "state/oper-status",
    "values": {
    "state/oper-status": "UP"
    }
    },
    {
    "Path": "state/last-change",
    "values": {
    "state/last-change": 0
    }
    },
    {
    "Path": "state/logical",
    "values": {
    "state/logical": true
    }
    }
    ]
    }
    {
    "source": "10.92.196.149:50051",
    "subscription-name": "default-1652375806",
    "timestamp": 1652375809450004641,
    "time": "2022-05-12T10:16:49.450004641-07:00",
    "prefix": "interfaces/interface[name=lo0]/subinterfaces/subinterface[index=0]/ipv4/addresses/address[ip=10.255.2.76]",
    "updates": [
    {
    "Path": "state/ip",
    "values": {
    "state/ip": "10.255.2.76"
    }
    },
    {
    "Path": "state/prefix-length",
    "values": {
    "state/prefix-length": 32
    }
    },
    {
    "Path": "state/origin",
    "values": {
    "state/origin": "STATIC"
    }
    }
    ]
    }
    {
    "source": "10.92.196.149:50051",
    "subscription-name": "default-1652375806",
    "timestamp": 1652375809450139391,
    "time": "2022-05-12T10:16:49.450139391-07:00",
    "prefix": "interfaces/interface[name=lo0]/subinterfaces/subinterface[index=0]/ipv4/addresses/address[ip=127.0.0.1]",
    "updates": [
    {
    "Path": "state/ip",
    "values": {
    "state/ip": "127.0.0.1"
    }
    },
    {
    "Path": "state/prefix-length",
    "values": {
    "state/prefix-length": 32
    }
    },
    {
    "Path": "state/origin",
    "values": {
    "state/origin": "STATIC"
    }
    }
    ]
    }
    {
    "source": "10.92.196.149:50051",
    "subscription-name": "default-1652375806",
    "timestamp": 1652375809450262600,
    "time": "2022-05-12T10:16:49.4502626-07:00",
    "prefix": "interfaces/interface[name=lo0]/subinterfaces/subinterface[index=0]/ipv4/addresses/address[ip=127.0.0.64]",
    "updates": [
    {
    "Path": "state/ip",
    "values": {
    "state/ip": "127.0.0.64"
    }
    },
    {
    "Path": "state/prefix-length",
    "values": {
    "state/prefix-length": 32
    }
    },
    {
    "Path": "state/origin",
    "values": {
    "state/origin": "STATIC"
    }
    }
    ]
    }
    {
    "source": "10.92.196.149:50051",
    "subscription-name": "default-1652375806",
    "timestamp": 1652375809452684011,
    "time": "2022-05-12T10:16:49.452684011-07:00",
    "prefix": "interfaces/interface[name=lo0]/subinterfaces/subinterface[index=0]",
    "updates": [
    {
    "Path": "ipv4/state/enabled",
    "values": {
    "ipv4/state/enabled": true
    }
    },
    {
    "Path": "ipv4/state/mtu",
    "values": {
    "ipv4/state/mtu": 65535
    }
    }
    ]
    }
    {
    "source": "10.92.196.149:50051",
    "subscription-name": "default-1652375806",
    "timestamp": 1652375809452796022,
    "time": "2022-05-12T10:16:49.452796022-07:00",
    "prefix": "interfaces/interface[name=lo0]/subinterfaces/subinterface[index=0]/ipv6/addresses/address[ip=abcd::10:255:2:76]",
    "updates": [
    {
    "Path": "state/ip",
    "values": {
    "state/ip": "abcd::10:255:2:76"
    }
    },
    {
    "Path": "state/prefix-length",
    "values": {
    "state/prefix-length": 128
    }
    },
    {
    "Path": "state/origin",
    "values": {
    "state/origin": "STATIC"
    }
    },
    {
    "Path": "state/status",
    "values": {
    "state/status": "PREFERRED"
    }
    }
    ]
    }
    {
    "source": "10.92.196.149:50051",
    "subscription-name": "default-1652375806",
    "timestamp": 1652375809452936008,
    "time": "2022-05-12T10:16:49.452936008-07:00",
    "prefix": "interfaces/interface[name=lo0]/subinterfaces/subinterface[index=0]/ipv6/addresses/address[ip=fe80::2c5:2cf0:3:f03d]",
    "updates": [
    {
    "Path": "state/ip",
    "values": {
    "state/ip": "fe80::2c5:2cf0:3:f03d"
    }
    },
    {
    "Path": "state/prefix-length",
    "values": {
    "state/prefix-length": 128
    }
    },
    {
    "Path": "state/origin",
    "values": {
    "state/origin": "RANDOM"
    }
    },
    {
    "Path": "state/status",
    "values": {
    "state/status": "PREFERRED"
    }
    }
    ]
    }
    {
    "source": "10.92.196.149:50051",
    "subscription-name": "default-1652375806",
    "timestamp": 1652375809455088976,
    "time": "2022-05-12T10:16:49.455088976-07:00",
    "prefix": "interfaces/interface[name=lo0]/subinterfaces/subinterface[index=0]",
    "updates": [
    {
    "Path": "ipv6/state/enabled",
    "values": {
    "ipv6/state/enabled": true
    }
    },
    {
    "Path": "ipv6/state/mtu",
    "values": {
    "ipv6/state/mtu": 4294967295
    }
    }
    ]
    }

json.encoding.raw.txt
json.encoding.formatted.txt
proto.encoding.formatted.txt
proto.encoding.raw.txt

@karimra
Copy link
Owner

karimra commented May 14, 2022

Hi, took me some time to dig into this but it looks like the whole message marshaling into json is failing because the value of state/prefix-length is not a valid json string.
Whatever gnmi server you are querying is returning a single space as a json value for state/prefix-length

update:  {
  timestamp:  1651733127911788946
  prefix:  {
    elem:  {
      name:  "interfaces"
    }
    elem:  {
      name:  "interface"
      key:  {
        key:  "name"
        value:  "lo0"
      }
    }
    elem:  {
      name:  "subinterfaces"
    }
    elem:  {
      name:  "subinterface"
      key:  {
        key:  "index"
        value:  "0"
      }
    }
    elem:  {
      name:  "ipv4"
    }
    elem:  {
      name:  "addresses"
    }
    elem:  {
      name:  "address"
      key:  {
        key:  "ip"
        value:  "128.220.11.66"
      }
    }
  }
  update:  {
    path:  {
      elem:  {
        name:  "state"
      }
      elem:  {
        name:  "ip"
      }
    }
    val:  {
      json_val:  "\"128.220.11.66\""
    }
  }
  update:  {
    path:  {
      elem:  {
        name:  "state"
      }
      elem:  {
        name:  "prefix-length"
      }
    }
    val:  {
      json_val:  " " <---- # This is the culprit
    }
  }
  update:  {
    path:  {
      elem:  {
        name:  "state"
      }
      elem:  {
        name:  "origin"
      }
    }
    val:  {
      json_val:  "\"STATIC\""
    }
  }
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants