Skip to content

Commit

Permalink
feat(models): add EvpnObject interface
Browse files Browse the repository at this point in the history
Signed-off-by: Boris Glimcher <[email protected]>
  • Loading branch information
glimchb committed Oct 19, 2023
1 parent 4a6e6dd commit 5b20cdd
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/models/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ type Bridge struct {
VtepIP net.IPNet
}

// build time check that struct implements interface
var _ EvpnObject[*pb.LogicalBridge] = (*Bridge)(nil)

// NewBridge creates new SVI object from protobuf message
func NewBridge(in *pb.LogicalBridge) *Bridge {
// vtepip := make(net.IP, 4)
Expand Down
10 changes: 10 additions & 0 deletions pkg/models/interface.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright (c) 2022-2023 Dell Inc, or its subsidiaries.

// Package models translates frontend protobuf messages to backend messages
package models

// EvpnObject is an interface for all domain objects in evpn-gw
type EvpnObject[T any] interface {
ToPb() (T, error)
}
3 changes: 3 additions & 0 deletions pkg/models/port.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ type Port struct {
LogicalBridgeRefKeys []string
}

// build time check that struct implements interface
var _ EvpnObject[*pb.BridgePort] = (*Port)(nil)

// NewPort creates new SVI object from protobuf message
func NewPort(in *pb.BridgePort) *Port {
mac := net.HardwareAddr(in.Spec.MacAddress)
Expand Down
3 changes: 3 additions & 0 deletions pkg/models/svi.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ type Svi struct {
RemoteAs uint32
}

// build time check that struct implements interface
var _ EvpnObject[*pb.Svi] = (*Svi)(nil)

// NewSvi creates new SVI object from protobuf message
func NewSvi(in *pb.Svi) *Svi {
mac := net.HardwareAddr(in.Spec.MacAddress)
Expand Down
3 changes: 3 additions & 0 deletions pkg/models/vrf.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ type Vrf struct {
MacAddress net.HardwareAddr
}

// build time check that struct implements interface
var _ EvpnObject[*pb.Vrf] = (*Vrf)(nil)

// NewVrf creates new VRF object from protobuf message
func NewVrf(in *pb.Vrf) *Vrf {
mac := net.HardwareAddr(in.Status.Rmac)
Expand Down

0 comments on commit 5b20cdd

Please sign in to comment.