Commit Graph

62 Commits

Author SHA1 Message Date
29736a3d6b bugfix: bridgedomain sync
When a bridge-domain has a BVI, it will not sync/add the interfaces to
the bridge. As an example:

bridgedomains:
  bd1001:
    bvi: loop1001
    interfaces: [ tap1001 ]
    mtu: 9000

taps:
  tap1001:
    host:
      bridge: br0
      mac: 02:fe:83:97:f4:7f
      mtu: 9000
      name: vpp-bd1001

Before this change, the 'tap1001' would get created, but if the BVI
'loop1001' was correctly set up on the bridge, the code would continue
and skip over enumerating config_bridge_iface. After this change,
both the BVI will be checked (and added if not present), AND all
interfaces will be enumerated (and added if not present).
2022-06-22 15:32:33 +00:00
a9cff05ca4 vpp/reconciler: format diff with black
Signed-off-by: Dave Wallace <dwallacelf@gmail.com>
2022-04-26 21:30:06 -04:00
b09773ae75 vppcfg: add args to specify location of vpp api files
- refactor to address review comments.

Signed-off-by: Dave Wallace <dwallacelf@gmail.com>
2022-04-26 21:04:31 -04:00
5af27211f3 Add an initial stab at docstrings - enable docstring pylinter 2022-04-24 10:36:25 +00:00
bc0310e088 Study and respond to PyLint
Add a reasonably tolerant .pylintrc and fix most pylint errors and
warnings.

------------------------------------------------------------------
Your code has been rated at 9.78/10
2022-04-22 19:32:38 +00:00
baaaaa67b5 Initial formatting run with Black. Integration tests and unit tests pass before and after this change. 2022-04-22 13:05:55 +00:00
b375ddb433 Final f-string conversions that flynt did not catch. Tested: integration test before and after are clean 2022-04-22 11:48:08 +00:00
e13694a566 Move to f-strings
Used:
$ flynt -a -tc . vppcfg

Execution time:                            0.216s
Files checked:                             24
Files modified:                            13
Character count reduction:                 632 (0.36%)

Per expression type:
Old style (`%`) expressions attempted:     209/211 (99.1%)
No `.format(...)` calls attempted.
No concatenations attempted.
F-string expressions created:              205

Ran an integration test before and after. No diffs.
2022-04-22 10:58:41 +00:00
58cf9e6b0c A few cosmetic refactors
- add __vxlan_tunnel_has_diff() to align with the other _has_diff()
  methods
- factor out a few repetitive occurences of l2xc creations
- strictly make "cli=" the pattern instead of "cli = ", to help grepping :)
2022-04-14 12:15:06 +00:00
eee718c77c Refactor and clean up some repetitive code 2022-04-12 11:04:13 +00:00
594e21afa4 Remove redundant code - remove_interface() already removes TAP cache entries 2022-04-12 10:47:45 +00:00
2b1287f4ef Remove spurious logging 2022-04-12 09:11:56 +00:00
6637820021 Add TAP support
- based on previously submitted schema and validation, can add a TAP
  with host netns, bridge and MTU.
- detect diffs in __tap_has_diff(), used to prune TAPs that must change
- add prune_taps() and create_taps() in the reconciler
- add Dumper() logic to emit YAML config for TAPs
- Move tap_is_lcp() into the VPPApi() class, so it can be reused

Add lots of test cases in intest/*.yaml and example.yaml - full
regression and integration and unit/YAML tests pass on this change.
2022-04-12 08:57:05 +00:00
929fa7b546 bugfix: sync max frame size before packet MTU 2022-04-10 10:57:17 +00:00
a7545ac5af Add ability to manipulate MACs
Special care is taken for bondethernet, where the MAC changes when
the first member is added to it. BondEthernet requires its MAC to
be set in the bondethernets section, disallowing the MAC of individual
members to be set.

Also write a dumper for MACs of all types. Update integration test
cases to stress the MAC changes on loops, bonds, and phys.
2022-04-10 09:54:51 +00:00
656f2ce883 Only signal bondethernet diff if mode/lb are actually set in the config 2022-04-09 22:08:32 +00:00
2360d28d0a Add the ability to set any mode/lb on bonds
This requires a schema change, adding 'mode' and 'load-balance' fields,
a semantic invariant that 'load-balance' can only be set in the case of
LACP and XOR bonds, a mapper from the mode/lb strings, ie.
"round-robin" to their VPP numeric counterparts, a bunch of unit tests.

Then in the reconciler, changing bonds (__bond_has_diff()) will
invalidate any LCP or sub-interfaces built on them, so those will have
to be pruned. create_bondethernet() will now create (or re-create)
the bond with the correct flags.

Unit-tests, YAML tests and the integration test all pass.

Updated config-guide.
2022-04-05 15:05:03 +00:00
fdb732142a Add bridgedomain settings.
Bridges can be created with default settings, with specific settings,
and they can be sync'd at runtime with all of the settings in this
change.

Notably missing are two features:
- unknown unicast flooding into specific interfaces (as opposed to
  on/off on the bridge)
- learn-limit, which does not have an API getter, only a setter.
2022-04-05 12:01:13 +00:00
b461ef49bb Add 'state' field to interfaces and sub-interfaces
Assert that children cannot be 'up' of their parent is 'down'. Add tests. Update user-guide.
2022-04-05 11:06:33 +00:00
a561dc64b1 Correctly prune addresses from untagged and tagged VXLAN tunnels 2022-04-03 15:40:21 +00:00
50581f7171 Rename 'config' to 'cache' in the VPPApi.
This makes it clearer what its purpose is, in preparation of actual VPP
dataplane configuration changes. For example remove_lcp() refers
currently to the removal of the LCP from the cache, not the VPP
dataplane itself, so rename it and its siblings cache_remove_*()
instead.

In a future commit, the call remove_*() will refer to the removal of an
object _in VPP_.
2022-04-03 11:21:29 +00:00
566efe3596 Add a CLI output emitter (either to stdout or to filename), based on plan --output/-o flag 2022-04-03 09:49:27 +00:00
8499f2104e Clean up some debugging statements post-prune 2022-04-03 09:19:51 +00:00
f786a00e9a Check for the existence of LCP config statements, and if so, require linux-cp or lcpng plugins are enabled in VPP 2022-04-02 20:16:51 +00:00
f70bff400f Introduce a CLI object
Instead of writing the CLI calls to stderr as INFO loglines, now add
them to a list of messages by prune/create/sync.

Always close the VPP connection after finishing, by adding a destructor
to the VPPApi class.

At the end of each phase, print out what was gathered to stdout. Later,
I will make this more advanced (output to file, output directly to a
pipe of a running vppctl binary, etc).
2022-03-29 14:04:53 +00:00
2003a21068 Refactor prune_lcps()
Fold in the qinx, 1-tag sub, and phy/lookback into one loop, reducing
total LOC by 3x.

Tested by running a hippo integration test (ie 169 config-to-config
transitions), with no material diffs between the old and the new code:

@@ -182,9 +182,9 @@
 /tmp/vppcfg-exec_hippo1.yaml: lcp create HundredGigabitEthernet12/0/0.1235 host-if ice0.1234.1000
 /tmp/vppcfg-exec_hippo1.yaml_hippo10.yaml: lcp delete HundredGigabitEthernet12/0/0.1235
 /tmp/vppcfg-exec_hippo1.yaml_hippo10.yaml: lcp delete HundredGigabitEthernet12/0/0.1234
-/tmp/vppcfg-exec_hippo1.yaml_hippo10.yaml: lcp delete loop1
-/tmp/vppcfg-exec_hippo1.yaml_hippo10.yaml: lcp delete loop0
 /tmp/vppcfg-exec_hippo1.yaml_hippo10.yaml: lcp delete HundredGigabitEthernet12/0/0
+/tmp/vppcfg-exec_hippo1.yaml_hippo10.yaml: lcp delete loop0
+/tmp/vppcfg-exec_hippo1.yaml_hippo10.yaml: lcp delete loop1
 /tmp/vppcfg-exec_hippo1.yaml_hippo11.yaml: lcp delete HundredGigabitEthernet12/0/0.1235
 /tmp/vppcfg-exec_hippo1.yaml_hippo11.yaml: lcp delete HundredGigabitEthernet12/0/0.1234
 /tmp/vppcfg-exec_hippo1.yaml_hippo11.yaml: lcp delete loop1
@@ -202,8 +202,8 @@
 /tmp/vppcfg-exec_hippo1.yaml_hippo2.yaml: lcp delete HundredGigabitEthernet12/0/0.1235
 /tmp/vppcfg-exec_hippo1.yaml_hippo2.yaml: lcp delete HundredGigabitEthernet12/0/0.1234
 /tmp/vppcfg-exec_hippo1.yaml_hippo2.yaml: lcp delete loop1
-/tmp/vppcfg-exec_hippo1.yaml_hippo2.yaml: lcp delete loop0
 /tmp/vppcfg-exec_hippo1.yaml_hippo2.yaml: lcp delete BondEthernet0
+/tmp/vppcfg-exec_hippo1.yaml_hippo2.yaml: lcp delete loop0
 /tmp/vppcfg-exec_hippo1.yaml_hippo2.yaml: lcp delete HundredGigabitEthernet12/0/0
 /tmp/vppcfg-exec_hippo1.yaml_hippo3.yaml: lcp delete HundredGigabitEthernet12/0/0.1235
 /tmp/vppcfg-exec_hippo1.yaml_hippo3.yaml: lcp delete HundredGigabitEthernet12/0/0.1234
2022-03-28 16:43:55 +00:00
4704780362 Typofix in variable name 2022-03-27 22:09:35 +00:00
020c5f72e1 Also create loopback LCPs 2022-03-27 21:37:56 +00:00
fe49b89492 Bugfix - ensure BVI exists in VPP before trying to remove it 2022-03-27 21:32:02 +00:00
24547869c9 Avoid issuing 'pop 0' for untagged l2xc changes; just emit the exact CLI statement 2022-03-27 21:26:25 +00:00
2415d30c0a Second part of a BVI refactor
The handling of BVI is awkward, with the autoderived interface name
"bviXX" based on the bridgedomain bd_id. Lots of special casing happens
on account of this decision, and to make matters worse there is poor
interaction (leading to VPP crashes) when BVIs and Loopbacks are used
at the same time: https://lists.fd.io/g/vpp-dev/message/21116

In this commit, I reintroduce the ability to set bridgedomain virtual
interfaces by means of the 'bvi' keyword. The 'bvi' must:
- be a Loopback interface
- must be used at most once (bvi_unique())

When pruning, I now need to prune bridgedomains before pruning
loopbacks, because any given loopback might be a BVI for a bridge. So,
I'll remove the loop/BVI from the bridge (by setting it to L3) and only
then removing the loopback from VPP.

In the reconciler, remove BVIs that have changed in prune_bridgedomains()
and set it in sync_bridgedomains().
2022-03-27 20:50:39 +00:00
850b982f2a First part of a BVI refactor
The handling of BVI is awkward, with the autoderived interface name
"bviXX" based on the bridgedomain bd_id. Lots of special casing happens
on account of this decision, and to make matters worse there is poor
interaction (leading to VPP crashes) when BVIs and Loopbacks are used
at the same time: https://lists.fd.io/g/vpp-dev/message/21116

This is step one of a refactor of the logic. In this commit, I'm
removing all of the BVI logic from the codebase, rendering bridgedomains
unable to have IP interfaces. In the next commit, I will introduce new
behavior in the schema, allowing for 'bvi' to be a loopback
interfacename which will be used as BVI for a bridgedomain, restoring
the ability to use bridgedomains with IP interfaces (using a loop).
2022-03-27 20:09:22 +00:00
90c23cf987 Prune sub-ints that have a different encap than their config counterpart 2022-03-27 16:14:37 +00:00
9d6d99547f Do not append interfaces to bridge_members if their sw_if_index has been removed - this forces the interface to be re-added 2022-03-27 12:52:28 +00:00
176fd297aa Refactor phys_exist() into phys_exist_in_{config,vpp}(); Correct vppapi.get_phys() 2022-03-26 23:07:49 +00:00
cb6eafae3e Complete Sync Phase
IP Addresses and Admin State are now applied
2022-03-26 22:51:21 +00:00
a2d2476710 Make Sync Phase config-centric
What this means is that the synchronization will run based on loops over
the configuration, rather than over the VPP state. The benefit of this
approach is that no additional API calls have to be made after the
initial VPP configuration is read, making pre-flight checks and diffing
more obvious.

Further, make sync_link_mtu() direction-aware; first we will raise the
link_mtu for interfaces that are growing, and after setting all the
children up/down with sync_mtu_direction() we'll finally shrink
sync_link_mtu() where needed.

We can now do an entire reconciliation run with only one API read at the
beginning!
2022-03-26 22:18:54 +00:00
619c579561 Make vpp_readconfig() explicit again. I want to try to read the VPP config only once, and pathplan the entire prune/create/sync cycle with one set of API reads at the beginning. 2022-03-26 21:08:41 +00:00
7bb9fa5ac8 Assert that a QinX cannot have higher MTU than its intermediate interface 2022-03-26 17:18:10 +00:00
40c6b2d1c8 Sync Phase: Implement MTU syncing (for both packet MTU and Max Frame Size) 2022-03-26 17:09:07 +00:00
0c747dbfc3 Sync Phase: Implement bridgedomains 2022-03-26 15:43:55 +00:00
0a80801217 Always set interface up after MTU change; otherwise only set it up if it was down 2022-03-26 15:21:09 +00:00
e9bbd47407 Sync Phase: Implement bondethernets
Include special caveat on LCP MAC changes, for which I'll put in a
TODO for now with a VPP comment {} with the to be run command.

Also make the user aware of a quick in BondEthernets not being able
to have link_mtu != 9000 so if a packet MTU > 9000 is set, this will
work but is an undesirable configuration. Issue a warning in this
case.
2022-03-26 15:14:49 +00:00
abbabcf2d0 Skip deletion of TAP sub-ints belonging to LCP interfaces 2022-03-26 11:19:37 +00:00
90a97a3d7b Add Create Phase
This is rather straight forward: for each object (in correct order),
if the object exists in VPP, we can skip it. We know that it will exist
only if it was valid (ie correct encapsulation, tc). If it does not
exist in VPP, issue the correct creation request to VPP.

Implement the creation of all types, in the following order:
- create_loopbacks() and create_bvis()
- create_bondethernets()
- create_vxlan_tunnels()
- create_sub_interfaces() first 1-tag, then 2-tag
- create_bridgedomains()
- create_lcps() bottomsup: first 0-tag, then 1-tag, then 2-tag names.

Add a placeholder TODO to fix a bug with prune_sub_interfaces() which
should allow for TAPs belonging to LCPs; will fix in followup commit.
2022-03-26 11:14:30 +00:00
d5a7c59f4e Remove sub-ints before VXLANs. Report on interfaces thare are deleted before their addresses are. 2022-03-25 23:20:57 +00:00
661c7fc16c Implement pruning in config as well
After pruning elements from the VPP configuration, also remove them
from the configuration. The purpose of this is to leave a reasonable
representation of the VPP state in the configuration, so that subsequent
creates and syncs do not have to query the VPP API repeatedly.

The goal of this change is to be able to plan a complete path from
prune, create and sync, with only reading the initial VPP configuration
once, not multiple times.
2022-03-25 23:04:28 +00:00
1d7fd268e0 Add ability to delete sub-ints on BVI + Loopback
- Add a get_sub_interfaces() call to fetch all DPDK / Bond sub-ints
- In prune_bvis(), prune_loopbacks() and prune_sub_interfaces(),
  use sub_number_of_tags to go out-to-in (qinx, dot1x, untagged)
2022-03-25 18:43:46 +00:00
9aeb60ad98 Also bring down BVIs and Loopbacks if they do not exist in the config 2022-03-25 14:15:40 +00:00
152fa12099 Update to ordering
- Prune bridgedomains before pruning BVIs. The reason for this is that
  prune_bridgedomains() will set the BVI to L3 mode, and if the BVI is
  removed before the bridge is pruned, this is an error.
- When pruning bridge members, use the VPP configuration as the member
  may not exist in the config, upon which the call to interface.is_sub()
  will return False even if it is actually a VPP sub-int.

Update README.md, also take into account the previous change which calls
prune_addresses() before object deletion.
2022-03-25 13:56:04 +00:00