skydive-project / skydive

An open source real-time network topology and protocols analyzer
https://skydive.network
Apache License 2.0
2.65k stars 400 forks source link

Autogenerate OVN Models #2374

Closed amorenoz closed 3 years ago

amorenoz commented 3 years ago

This PR aims to provide the following benefits to the ovn probe:

We do so by:

As an example, here is the file generated by the metadata generator (ovmetagen) for the table ACL:

//go:generate go run github.com/skydive-project/skydive/graffiti/gendecoder -package github.com/skydive-project/skydive/topology/probes/ovn/ovnmodel
//go:generate go run github.com/mailru/easyjson/easyjson $GOFILE

// Code generated by ovnmetagen
// DO NOT EDIT.

package ovnmodel

import (
    "encoding/json"
    "fmt"

    "github.com/skydive-project/skydive/graffiti/getter"
    "github.com/skydive-project/skydive/graffiti/graph"
)

// ACL defines the type used by both libovsdb and skydive for table ACL
// easyjson:json
// gendecoder
type ACL struct {
    UUID        string            `ovsdb:"_uuid" json:",omitempty" `
    Action      string            `ovsdb:"action" json:",omitempty" `
    Direction   string            `ovsdb:"direction" json:",omitempty" `
    ExternalIDs map[string]string `ovsdb:"external_ids" json:",omitempty" `
    Log         bool              `ovsdb:"log" json:",omitempty" `
    Match       string            `ovsdb:"match" json:",omitempty" `
    Meter       []string          `ovsdb:"meter" json:",omitempty" `
    Name        []string          `ovsdb:"name" json:",omitempty" `
    Priority    int               `ovsdb:"priority" json:",omitempty" `
    Severity    []string          `ovsdb:"severity" json:",omitempty" `

    ExternalIDsMeta graph.Metadata `json:",omitempty" field:"Metadata"`
}

func (t *ACL) Metadata() graph.Metadata {
    // Generate Metadata from maps
    t.ExternalIDsMeta = graph.NormalizeValue(t.ExternalIDs).(map[string]interface{})

    return graph.Metadata{
        "Type":    "ACL",
        "Manager": "ovn",
        "UUID":    t.GetUUID(),
        "Name":    t.GetName(),
        "OVN":     t,
    }
}

func (t *ACL) GetUUID() string {
    return t.UUID
}

func (t *ACL) GetName() string {
    if name := t.UUID; name != "" {
        return name
    }
    return t.GetUUID()
}

// ACLDecoder implements a json message raw decoder
func ACLDecoder(raw json.RawMessage) (getter.Getter, error) {
    var t ACL
    if err := json.Unmarshal(raw, &t); err != nil {
        return nil, fmt.Errorf("unable to unmarshal ACL metadata %s: %s", string(raw), err)
    }
    return &t, nil
}

Most of the struct can be used for both the Metadata and the OVSDB unmarshalling. The only exception is the map[string]string that need to be converted into graph.Metadata fields for things like MetadataIndexers to work.

Also, since the building of the ovn probe has become more complicated, this PR makes ovn probe building conditional, e.g: WITH_OVN=true is required to build OVN support

amorenoz commented 3 years ago

@lebauce I think this is ready for the first round of review, PTAL

safchain commented 3 years ago

I did a first quick review and tested it. Looks good to me.

lebauce commented 3 years ago

run tests

lebauce commented 3 years ago

run cdd-overview-tests

lebauce commented 3 years ago

run functional-tests-backend-elasticsearch

lebauce commented 3 years ago

run functional-tests-backend-elasticsearch

lebauce commented 3 years ago

run functional-tests-backend-elasticsearch

lebauce commented 3 years ago

run functional-tests-backend-elasticsearch run cdd-overview-tests run functional-tests-backend-orientdb

lebauce commented 3 years ago

run scale-tests