Skip to content

mgd static routing API: restructure to reject nonsense path combinations? #739

Open

Description

@jgallagher

Property-based tests hitting the mgd static routing API produced some API calls that tried to set up multiple overlapping routes; e.g.,

        v4: {
            "0.0.0.0/2": [
                Path {
                    bgp: None,
                    nexthop: 1.2.3.4,
                    nexthop_interface: None,
                    rib_priority: 14,
                    shutdown: false,
                    vlan_id: None,
                },
                Path {
                    bgp: None,
                    nexthop: 1.2.3.4,
                    nexthop_interface: None,
                    rib_priority: 153,
                    shutdown: false,
                    vlan_id: None,
                },
            ],
        },

mgd returned an OK for adding these routes, but internally only kept the priority 14 one. The current structure of this API is a HashMap<String, Vec<Path>> where the key is a stringified prefix. @taspelund noted that the more accurate structure here would be a Map<(Prefix, Nexthop, VlanId), Properties> - we can have at most one entry for that triple. JSON (and therefore OpenAPI) requires keys be strings, but we can still use stronger types on the Rust side.

A technique we've used in other places in Omicron is to make the OpenAPI / JSON type a flat Vec, so in this case a Vec<(Prefix, Nexthop, VlanId, Properties)>, but serialize/deserialize from the stronger Map type (be that a HashMap/BTreeMap or any other map/set-like collection), and have the Deserialize implementation raise an error if there are any duplicate keys.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions