Skip to content

Commit

Permalink
Add a function to retrieve the service port numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-dennis committed Dec 8, 2023
1 parent 555b55e commit f7b49c0
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 7 deletions.
34 changes: 27 additions & 7 deletions entname/entname.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,20 +217,14 @@ func Fabric(dp *DeviceParams, index int) (string, error) {
// https://github.com/openconfig/entity-naming/blob/main/README.md#common-qos-queues
type QoSClass string

// QoS class enum constants.
const (
// QoSNC1 is the NC1 QoS class.
QoSNC1 = QoSClass("NC1")
// QoSAF4 is the AF4 QoS class.
QoSAF4 = QoSClass("AF4")
// QoSAF3 is the AF3 QoS class.
QoSAF3 = QoSClass("AF3")
// QoSAF2 is the AF2 QoS class.
QoSAF2 = QoSClass("AF2")
// QoSAF1 is the AF1 QoS class.
QoSAF1 = QoSClass("AF1")
// QoSBE1 is the BE1 QoS class.
QoSBE1 = QoSClass("BE1")
// QoSBE0 is the BE0 QoS class.
QoSBE0 = QoSClass("BE0")
)

Expand Down Expand Up @@ -344,3 +338,29 @@ func lookupNamer(dp *DeviceParams) (namer.Namer, error) {
}
return nf(dp.HardwareModel), nil
}

// Service is the name of an OpenConfig service.
type Service string

// Service enum constants.
const (
GNMI = Service("gnmi")
GNOI = Service("gnoi")
GRIBI = Service("gribi")
P4RT = Service("p4rt")
)

// ServicePorts returns the vendors-specific service port numbers.
func ServicePorts(dp *DeviceParams) (map[Service]int, error) {
n, err := lookupNamer(dp)
if err != nil {
return nil, err
}
sps := n.ServicePorts()
return map[Service]int{
GNMI: int(sps.GNMI),
GNOI: int(sps.GNOI),
GRIBI: int(sps.GRIBI),
P4RT: int(sps.P4RT),
}, nil
}
33 changes: 33 additions & 0 deletions entname/entname_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,34 @@ func TestCommonQoSQueues(t *testing.T) {
})
}

func TestServicePorts(t *testing.T) {
var want = &namer.ServicePorts{
GNMI: 1,
GNOI: 5,
GRIBI: 2,
P4RT: 10,
}
setFakeNamer(&fakeNamer{ServicePortsFn: func() *namer.ServicePorts {
return want
}})
got, err := ServicePorts(devParams)
if err != nil {
t.Errorf("ServicePorts(%v) got error %v", devParams, err)
}
if got, want := got[GNMI], want.GNMI; got != int(want) {
t.Errorf("ServicePorts(%v) GNMI got %q, want %q", devParams, got, want)
}
if got, want := got[GNOI], want.GNOI; got != int(want) {
t.Errorf("ServicePorts(%v) GNOI got %q, want %q", devParams, got, want)
}
if got, want := got[GRIBI], want.GRIBI; got != int(want) {
t.Errorf("ServicePorts(%v) GRIBI got %q, want %q", devParams, got, want)
}
if got, want := got[P4RT], want.P4RT; got != int(want) {
t.Errorf("ServicePorts(%v) P4RT got %q, want %q", devParams, got, want)
}
}

func setFakeNamer(fn *fakeNamer) {
namerFactories[fakeVendor] = func(string) namer.Namer { return fn }
}
Expand All @@ -423,6 +451,7 @@ type fakeNamer struct {
PortFn func(*namer.PortParams) (string, error)
IsFixedFormFactorFn func() bool
CommonQoSQueuesFn func(*namer.QoSParams) (*namer.CommonQoSQueueNames, error)
ServicePortsFn func() *namer.ServicePorts
}

func (fn *fakeNamer) LoopbackInterface(index uint) (string, error) {
Expand Down Expand Up @@ -460,3 +489,7 @@ func (fn *fakeNamer) IsFixedFormFactor() bool {
func (fn *fakeNamer) CommonQoSQueues(qp *namer.QoSParams) (*namer.CommonQoSQueueNames, error) {
return fn.CommonQoSQueuesFn(qp)
}

func (fn *fakeNamer) ServicePorts() *namer.ServicePorts {
return fn.ServicePortsFn()
}
10 changes: 10 additions & 0 deletions internal/arista/arista.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,13 @@ func (n *Namer) CommonQoSQueues(*namer.QoSParams) (*namer.CommonQoSQueueNames, e
BE0: "BE0",
}, nil
}

// ServicePorts is an implementation of namer.ServicePorts.
func (n *Namer) ServicePorts() *namer.ServicePorts {
return &namer.ServicePorts{
GNMI: 10162,
GNOI: 10162,
GRIBI: 10163,
P4RT: 9559,
}
}
10 changes: 10 additions & 0 deletions internal/cisco/cisco.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,13 @@ func (n *Namer) CommonQoSQueues(*namer.QoSParams) (*namer.CommonQoSQueueNames, e
BE0: "BE0",
}, nil
}

// ServicePorts is an implementation of namer.ServicePorts.
func (n *Namer) ServicePorts() *namer.ServicePorts {
return &namer.ServicePorts{
GNMI: 9339,
GNOI: 9339,
GRIBI: 9340,
P4RT: 9559,
}
}
10 changes: 10 additions & 0 deletions internal/juniper/juniper.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,13 @@ func (n *Namer) CommonQoSQueues(*namer.QoSParams) (*namer.CommonQoSQueueNames, e
BE0: "1",
}, nil
}

// ServicePorts is an implementation of namer.ServicePorts.
func (n *Namer) ServicePorts() *namer.ServicePorts {
return &namer.ServicePorts{
GNMI: 9339,
GNOI: 9339,
GRIBI: 9340,
P4RT: 9559,
}
}
12 changes: 12 additions & 0 deletions internal/namer/namer.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ type Namer interface {
// CommonQoSQueues returns the queue names for the common QoS classes, or an
// error if no such names exist.
CommonQoSQueues(qos *QoSParams) (*CommonQoSQueueNames, error)

//
ServicePorts() *ServicePorts
}

// PortParams are parameters of a network port.
Expand Down Expand Up @@ -96,3 +99,12 @@ type CommonQoSQueueNames struct {
func (qn *CommonQoSQueueNames) String() string {
return fmt.Sprintf("%+v", *qn)
}

// ServicePorts are the service port numbers.
type ServicePorts struct {
GNMI, GNOI, GRIBI, P4RT uint16
}

func (sp *ServicePorts) String() string {
return fmt.Sprintf("%+v", *sp)
}
10 changes: 10 additions & 0 deletions internal/nokia/nokia.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,13 @@ func (n *Namer) CommonQoSQueues(*namer.QoSParams) (*namer.CommonQoSQueueNames, e
BE0: "BE0",
}, nil
}

// ServicePorts is an implementation of namer.ServicePorts.
func (n *Namer) ServicePorts() *namer.ServicePorts {
return &namer.ServicePorts{
GNMI: 10162,
GNOI: 10162,
GRIBI: 10163,
P4RT: 9559,
}
}

0 comments on commit f7b49c0

Please sign in to comment.