diff mbox series

[net-next,v1,2/2] netlink: specs: add partial specification for openvswitch

Message ID 20230316120142.94268-3-donald.hunter@gmail.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series ynl: add support for user headers and struct attrs | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 18 this patch: 18
netdev/cc_maintainers fail 2 maintainers not CCed: corbet@lwn.net linux-doc@vger.kernel.org
netdev/build_clang success Errors and warnings before: 18 this patch: 18
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 18 this patch: 18
netdev/checkpatch warning WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Donald Hunter March 16, 2023, 12:01 p.m. UTC
The openvswitch family has a user header, uses struct attrs and has
array values and demonstrates these features in the YNL CLI. These specs
are sufficient to create, delete and dump datapaths and to dump vports:

$ ./tools/net/ynl/cli.py \
    --schema Documentation/netlink/genetlink-legacy.yaml \
    --spec Documentation/netlink/specs/ovs_datapath.yaml \
    --do dp-new --json '{ "dp_ifindex": 0, "name": "demo", "upcall_pid": 0}'
None

$ ./tools/net/ynl/cli.py \
    --schema Documentation/netlink/genetlink-legacy.yaml \
    --spec Documentation/netlink/specs/ovs_datapath.yaml \
    --dump dp-get --json '{ "dp_ifindex": 0 }'
[{'dp_ifindex': 3,
  'masks_cache_size': 256,
  'megaflow_stats': {'cache_hits': 0,
                     'mask_hit': 0,
                     'masks': 0,
                     'pad1': 0,
                     'padding': 0},
  'name': 'test',
  'stats': {'flows': 0, 'hit': 0, 'lost': 0, 'missed': 0},
  'user_features': {'dispatch_upcall_per_cpu',
                    'tc_recirc_sharing',
                    'unaligned'}},
 {'dp_ifindex': 39,
  'masks_cache_size': 256,
  'megaflow_stats': {'cache_hits': 0,
                     'mask_hit': 0,
                     'masks': 0,
                     'pad1': 0,
                     'padding': 0},
  'name': 'demo',
  'stats': {'flows': 0, 'hit': 0, 'lost': 0, 'missed': 0},
  'user_features': set()}]

$ ./tools/net/ynl/cli.py \
    --schema Documentation/netlink/genetlink-legacy.yaml \
    --spec Documentation/netlink/specs/ovs_datapath.yaml \
    --do dp-del --json '{ "dp_ifindex": 0, "name": "demo"}'
None

$ ./tools/net/ynl/cli.py \
    --schema Documentation/netlink/genetlink-legacy.yaml \
    --spec Documentation/netlink/specs/ovs_vport.yaml \
    --dump vport-get --json '{ "dp_ifindex": 3 }'
[{'dp_ifindex': 3,
  'ifindex': 3,
  'name': 'test',
  'port_no': 0,
  'stats': {'rx_bytes': 0,
            'rx_dropped': 0,
            'rx_errors': 0,
            'rx_packets': 0,
            'tx_bytes': 0,
            'tx_dropped': 0,
            'tx_errors': 0,
            'tx_packets': 0},
  'type': 'internal',
  'upcall_pid': [0],
  'upcall_stats': {'fail': 0, 'success': 0}}]

Signed-off-by: Donald Hunter <donald.hunter@gmail.com>
---
 Documentation/netlink/specs/ovs_datapath.yaml | 154 ++++++++++++++++++
 Documentation/netlink/specs/ovs_vport.yaml    | 141 ++++++++++++++++
 2 files changed, 295 insertions(+)
 create mode 100644 Documentation/netlink/specs/ovs_datapath.yaml
 create mode 100644 Documentation/netlink/specs/ovs_vport.yaml

Comments

Jakub Kicinski March 18, 2023, 4:52 a.m. UTC | #1
On Thu, 16 Mar 2023 12:01:42 +0000 Donald Hunter wrote:
> +user-header: ovs_header

Let's place this attr inside 'operations'?

also s/_/-/ everywhere, we try to use - as a separator in the spec, 
the C codegen replaces it with underscores
Donald Hunter March 18, 2023, 4:54 p.m. UTC | #2
On Sat, 18 Mar 2023 at 04:52, Jakub Kicinski <kuba@kernel.org> wrote:
>
> On Thu, 16 Mar 2023 12:01:42 +0000 Donald Hunter wrote:
> > +user-header: ovs_header
>
> Let's place this attr inside 'operations'?

Ah, good point - can it vary per operation and should it be a property
of each command?

> also s/_/-/ everywhere, we try to use - as a separator in the spec,
> the C codegen replaces it with underscores

Ack, will do.
Jakub Kicinski March 19, 2023, 1:44 a.m. UTC | #3
On Sat, 18 Mar 2023 16:54:35 +0000 Donald Hunter wrote:
> > On Thu, 16 Mar 2023 12:01:42 +0000 Donald Hunter wrote:  
> > > +user-header: ovs_header  
> >
> > Let's place this attr inside 'operations'?  
> 
> Ah, good point - can it vary per operation and should it be a property
> of each command?

We should allow both. Have tools/net/ynl/lib/nlspec.py expose it as 
a property of an operation, but let the spec writers only specify 
it once if each command uses the same format.
diff mbox series

Patch

diff --git a/Documentation/netlink/specs/ovs_datapath.yaml b/Documentation/netlink/specs/ovs_datapath.yaml
new file mode 100644
index 000000000000..c420f78f7c25
--- /dev/null
+++ b/Documentation/netlink/specs/ovs_datapath.yaml
@@ -0,0 +1,154 @@ 
+# SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause)
+
+name: ovs_datapath
+version: 2
+protocol: genetlink-legacy
+
+doc:
+  OVS datapath configuration over generic netlink.
+
+definitions:
+  -
+    name: ovs_header
+    type: struct
+    members:
+      -
+        name: dp_ifindex
+        type: u32
+  -
+    name: user_features
+    type: flags
+    entries:
+      -
+        name: unaligned
+        doc: Allow last Netlink attribute to be unaligned
+      -
+        name: vport_pids
+        doc: Allow datapath to associate multiple Netlink PIDs to each vport
+      -
+        name: tc_recirc_sharing
+        doc: Allow tc offload recirc sharing
+      -
+        name: dispatch_upcall_per_cpu
+        doc: Allow per-cpu dispatch of upcalls
+  -
+    name: datapath_stats
+    type: struct
+    members:
+      -
+        name: hit
+        type: u64
+      -
+        name: missed
+        type: u64
+      -
+        name: lost
+        type: u64
+      -
+        name: flows
+        type: u64
+  -
+    name: megaflow_stats
+    type: struct
+    members:
+      -
+        name: mask_hit
+        type: u64
+      -
+        name: masks
+        type: u32
+      -
+        name: padding
+        type: u32
+      -
+        name: cache_hits
+        type: u64
+      -
+        name: pad1
+        type: u64
+
+user-header: ovs_header
+
+attribute-sets:
+  -
+    name: datapath
+    attributes:
+      -
+        name: name
+        type: string
+      -
+        name: upcall_pid
+        doc: upcall pid
+        type: u32
+      -
+        name: stats
+        type: struct
+        struct: datapath_stats
+      -
+        name: megaflow_stats
+        type: struct
+        struct: megaflow_stats
+      -
+        name: user_features
+        type: u32
+        enum: user_features
+        enum-as-flags: true
+      -
+        name: pad
+        type: unused
+      -
+        name: masks_cache_size
+        type: u32
+      -
+        name: per_cpu_pids
+        type: array-nest
+        sub-type: u32
+
+operations:
+  list:
+    -
+      name: dp-get
+      doc: Get / dump OVS data path configuration and state
+      value: 3
+      attribute-set: datapath
+      do: &dp-get-op
+        request:
+          attributes:
+            - name
+        reply:
+          attributes:
+            - name
+            - upcall_pid
+            - stats
+            - megaflow_stats
+            - user_features
+            - masks_cache_size
+            - per_cpu_pids
+      dump: *dp-get-op
+    -
+      name: dp-new
+      doc: Create new OVS data path
+      value: 1
+      attribute-set: datapath
+      do:
+        request:
+          attributes:
+            - dp_ifindex
+            - name
+            - upcall_pid
+            - user_features
+    -
+      name: dp-del
+      doc: Delete existing OVS data path
+      value: 2
+      attribute-set: datapath
+      do:
+        request:
+          attributes:
+            - dp_ifindex
+            - name
+
+mcast-groups:
+  list:
+    -
+      name: ovs_datapath
diff --git a/Documentation/netlink/specs/ovs_vport.yaml b/Documentation/netlink/specs/ovs_vport.yaml
new file mode 100644
index 000000000000..3913aded5e28
--- /dev/null
+++ b/Documentation/netlink/specs/ovs_vport.yaml
@@ -0,0 +1,141 @@ 
+# SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause)
+
+name: ovs_vport
+version: 2
+protocol: genetlink-legacy
+
+doc:
+  OVS vport configuration over generic netlink.
+
+definitions:
+  -
+    name: ovs_header
+    type: struct
+    members:
+      -
+        name: dp_ifindex
+        type: u32
+  -
+    name: vport_type
+    type: enum
+    entries: [ unspec, netdev, internal, gre, vxlan, geneve ]
+  -
+    name: vport_stats
+    type: struct
+    members:
+      -
+        name: rx_packets
+        type: u64
+      -
+        name: tx_packets
+        type: u64
+      -
+        name: rx_bytes
+        type: u64
+      -
+        name: tx_bytes
+        type: u64
+      -
+        name: rx_errors
+        type: u64
+      -
+        name: tx_errors
+        type: u64
+      -
+        name: rx_dropped
+        type: u64
+      -
+        name: tx_dropped
+        type: u64
+
+
+user-header: ovs_header
+
+attribute-sets:
+  -
+    name: vport-options
+    attributes:
+      -
+        name: dst_port
+        type: u32
+      -
+        name: extension
+        type: u32
+  -
+    name: upcall-stats
+    attributes:
+      -
+        name: success
+        type: u64
+        value: 0
+      -
+        name: fail
+        type: u64
+  -
+    name: vport
+    attributes:
+      -
+        name: port_no
+        type: u32
+      -
+        name: type
+        type: u32
+        enum: vport_type
+      -
+        name: name
+        type: string
+      -
+        name: options
+        type: nest
+        nested-attributes: vport-options
+      -
+        name: upcall_pid
+        type: array-nest
+        sub-type: u32
+      -
+        name: stats
+        type: struct
+        struct: vport_stats
+      -
+        name: pad
+        type: unused
+      -
+        name: ifindex
+        type: u32
+      -
+        name: netnsid
+        type: u32
+      -
+        name: upcall_stats
+        type: nest
+        nested-attributes: upcall-stats
+
+operations:
+  list:
+    -
+      name: vport-get
+      doc: Get / dump OVS vport configuration and state
+      value: 3
+      attribute-set: vport
+      do: &vport-get-op
+        request:
+          attributes:
+            - dp_ifindex
+            - name
+        reply: &dev-all
+          attributes:
+            - dp_ifindex
+            - port_no
+            - type
+            - name
+            - upcall_pid
+            - stats
+            - ifindex
+            - netnsid
+            - upcall_stats
+      dump: *vport-get-op
+
+mcast-groups:
+  list:
+    -
+      name: ovs_vport