polycube icon indicating copy to clipboard operation
polycube copied to clipboard

CLI: current library is not preserving order or JSON elements in all the cases

Open acloudiator opened this issue 7 years ago • 1 comments

We should preserve the order in the JSON that is received from polycubed in order to print the elements to the user in the same list they are defined in the data model.

In order to do that we modified the https://github.com/Jeffail/gabs library in order to use https://github.com/cevaris/ordered_map instead of standard maps, it is working for some cases but not for all of them. For example, when an array of objects is received, the order is not preserved. https://github.com/polycube-network/polycube/blob/1f3dbfe9e01c415865425241be0939c7988cc4e5/src/polycubectl/vendor/github.com/Jeffail/gabs2/gabs.go#L192.

There is not an easy solution for it, the major challenge is that the JSON unmarshalling provided by golang is based on the standard map that is not ordered, so there will be always a case where the order is lost.

I think a possible solution would be to create (probably not from scratch) our own JSON unmarshalling routine, unfortunately, it doesn't appear to be that easy work. -Mauricio

acloudiator avatar Dec 18 '18 19:12 acloudiator

One use case that makes this issue evident, is the session table show command in pcn-iptables. The out-of-order show makes the session table more difficult to read.

direction  dnatip  dnatport  dport  dst        id    l4proto  sequence  snatip  snatport  sport  src        state        ttl
forward    notset  0         0      8.8.8.8    6805  ICMP     512       notset  0         17901  10.0.2.15  ESTABLISHED  1555334600
reverse    notset  0         0      10.0.2.15  6805  ICMP     512       notset  0         17901  8.8.8.8    ESTABLISHED  1555334600

mbertrone avatar Apr 15 '19 13:04 mbertrone