// Module included in the following assemblies:
//
// * networking/k8s_nmstate/k8s-nmstate-updating-node-network-config.adoc

:_mod-docs-content-type: REFERENCE
[id="virt-example-vf-host-services_{context}"]
= Example: Node network configuration policy for virtual functions

[role="_abstract"]
You can update host network settings for Single Root I/O Virtualization (SR-IOV) network virtual functions (VF) in an existing cluster by applying a `NodeNetworkConfigurationPolicy` manifest.

You can apply a `NodeNetworkConfigurationPolicy` manifest to an existing cluster to complete the following tasks:

* Configure QoS host network settings for VFs to optimize performance.
* Add, remove, or update VFs for a network interface.
* Manage VF bonding configurations.

[NOTE]
====
To update host network settings for SR-IOV VFs by using NMState on physical functions that are also managed through the SR-IOV Network Operator, you must set the `externallyManaged` parameter in the relevant `SriovNetworkNodePolicy` resource to `true`. For more information, see the _Additional resources_ section.
====

The following YAML file is an example of a manifest that defines QoS policies for a VF.
This YAML includes samples values that you must replace with your own information.

[source,yaml]
----
apiVersion: nmstate.io/v1
kind: NodeNetworkConfigurationPolicy
metadata:
  name: qos
spec:
  nodeSelector:
    node-role.kubernetes.io/worker: ""
  desiredState:
    interfaces:
      - name: ens1f0
        description: Change QOS on VF0
        type: ethernet
        state: up
        ethernet:
         sr-iov:
           total-vfs: 3
           vfs:
           - id: 0
             max-tx-rate: 200
----

* `metadata.name` defines the name of the policy.
* `spec.nodeSelector` defines  the nodes in the cluster the networking policy is applied to. If not defined, the default is all nodes.
* `spec.nodeSelector.node-role.kubernetes.io/worker` defines that this example applies to all nodes with the `worker` role.
* `spec.desiredState.interfaces.name` defines the name of the physical function (PF) network interface.
* `spec.desiredState.interfaces.description` is optional and defines a human-readable description of the interface.
* `spec.desiredState.interfaces.type` defines the type of interface.
* `spec.desiredState.interfaces.state` defines the requested state for the interface after configuration.
* `spec.desiredState.interfaces.ethernet.sr-iov.total-vfs` defines the total number of VFs.
* `spec.desiredState.interfaces.ethernet.sr-iov.vfs.id` defines the VF ID. In this example, the VF has an ID of `0`.
* `spec.desiredState.interfaces.ethernet.sr-iov.vfs.max-tx-rate` defines a maximum transmission rate, in Mbps, for the VF. This sample value sets a rate of 200 Mbps.

The following YAML file is an example of a manifest that adds a VF for a network interface.

In this sample configuration, the `ens1f1v0` VF is created on the `ens1f1` physical interface, and this VF is added to a bonded network interface `bond0`. The bond uses `active-backup` mode for redundancy. In this example, the VF is configured to use hardware offloading to manage the VLAN directly on the physical interface.

[source,yaml]
----
apiVersion: nmstate.io/v1
kind: NodeNetworkConfigurationPolicy
metadata:
  name: addvf
spec:
  nodeSelector:
    node-role.kubernetes.io/worker: ""
  maxUnavailable: 3
  desiredState:
    interfaces:
      - name: ens1f1
        type: ethernet
        state: up
        ethernet:
            sr-iov:
              total-vfs: 1
              vfs:
                - id: 0
                  trust: true
                  vlan-id: 477
      - name: bond0
        description: Attach VFs to bond
        type: bond
        state: up
        link-aggregation:
          mode: active-backup
          options:
            primary: ens1f0v0
          port:
            - ens1f0v0
            - ens1f1v0
----

* `metadata.name` defines the name of the policy.
* `spec.nodeSelector` defines  the nodes in the cluster the networking policy is applied to. If not defined, the default is all nodes.
* `spec.nodeSelector.node-role.kubernetes.io/worker` defines that the example applies to all nodes with the `worker` role.
* `spec.desiredState.interfaces[0].name` defines the name of the VF network interface.
* `spec.desiredState.interfaces[0].ethernet.sr-iov.total-vfs` defines the number of VFs to create.
* `spec.desiredState.interfaces[0].ethernet.sr-iov.vfs.trust` defines a setting to allow failover bonding between the active and backup VFs.
* `spec.desiredState.interfaces[0].ethernet.sr-iov.vfs.vlan-id` defines the ID of the VLAN. The example uses hardware offloading to define a VLAN directly on the VF.
* `spec.desiredState.interfaces[1].name` defines the name of the bonding network interface.
* `spec.desiredState.interfaces[1].description` is optional and defines a human-readable description of the interface.
* `spec.desiredState.interfaces[1].type` defines the type of interface.
* `spec.desiredState.interfaces[1].state` defines the requested state for the interface after configuration.
* `spec.desiredState.interfaces[1].link-aggregation.mode` defines the bonding policy for the bond.
* `spec.desiredState.interfaces[1].link-aggregation.options.primary` defines the primary attached bonding port.
* `spec.desiredState.interfaces[1].link-aggregation.port` defines the ports for the bonded network interface. In this example, `ens1f1v0` is the VLAN network interface added as an additional interface to the bonded network interface.
