Skip to content
This repository has been archived by the owner on Oct 16, 2024. It is now read-only.

Commit

Permalink
support configure interface's metering params
Browse files Browse the repository at this point in the history
  • Loading branch information
byteocean authored and guvenc committed Jan 22, 2024
1 parent 6f0b94b commit 8f2199a
Show file tree
Hide file tree
Showing 5 changed files with 1,634 additions and 1,495 deletions.
24 changes: 24 additions & 0 deletions api/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ func ProtoInterfaceToInterface(dpdkIface *proto.Interface) (*Interface, error) {
IPv4: &primaryIpv4,
IPv6: &primaryIpv6,
UnderlayRoute: &underlayRoute,
Metering: ProtoMeteringParamsToInterfaceMeteringParams(dpdkIface.GetMeteringParams()),
},
}, nil
}
Expand Down Expand Up @@ -387,3 +388,26 @@ func ProtoIfaceInfoToCaptureIfaceInfo(request *proto.CapturedInterface) (string,
return "", fmt.Errorf("unsupported interface type")
}
}

func InterfaceMeteringParamsToProtoMeteringParams(meteringParams *MeteringParams) *proto.MeteringParams {

if meteringParams == nil {
return &proto.MeteringParams{
TotalRate: 0,
PublicRate: 0,
}
}

return &proto.MeteringParams{
TotalRate: meteringParams.TotalRate,
PublicRate: meteringParams.PublicRate,
}
}

func ProtoMeteringParamsToInterfaceMeteringParams(meteringParams *proto.MeteringParams) *MeteringParams {

return &MeteringParams{
TotalRate: meteringParams.TotalRate,
PublicRate: meteringParams.PublicRate,
}
}
6 changes: 6 additions & 0 deletions api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,11 @@ type PXE struct {
FileName string `json:"boot_filename,omitempty"`
}

type MeteringParams struct {
TotalRate uint64 `json:"total_rate,omitempty"`
PublicRate uint64 `json:"public_rate,omitempty"`
}

func (m *InterfaceMeta) GetName() string {
return m.ID
}
Expand All @@ -305,6 +310,7 @@ type InterfaceSpec struct {
PXE *PXE `json:"pxe,omitempty"`
Nat *Nat `json:"-"`
VIP *VirtualIP `json:"-"`
Metering *MeteringParams `json:"metering,omitempty"`
}

type VirtualFunction struct {
Expand Down
13 changes: 7 additions & 6 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,12 +344,13 @@ func (c *client) ListInterfaces(ctx context.Context, ignoredErrors ...[]uint32)

func (c *client) CreateInterface(ctx context.Context, iface *api.Interface, ignoredErrors ...[]uint32) (*api.Interface, error) {
req := dpdkproto.CreateInterfaceRequest{
InterfaceType: dpdkproto.InterfaceType_VIRTUAL,
InterfaceId: []byte(iface.ID),
Vni: iface.Spec.VNI,
Ipv4Config: api.NetIPAddrToProtoIPConfig(iface.Spec.IPv4),
Ipv6Config: api.NetIPAddrToProtoIPConfig(iface.Spec.IPv6),
DeviceName: iface.Spec.Device,
InterfaceType: dpdkproto.InterfaceType_VIRTUAL,
InterfaceId: []byte(iface.ID),
Vni: iface.Spec.VNI,
Ipv4Config: api.NetIPAddrToProtoIPConfig(iface.Spec.IPv4),
Ipv6Config: api.NetIPAddrToProtoIPConfig(iface.Spec.IPv6),
DeviceName: iface.Spec.Device,
MeteringParameters: api.InterfaceMeteringParamsToProtoMeteringParams(iface.Spec.Metering),
}
if iface.Spec.PXE != nil {
if iface.Spec.PXE.FileName != "" && iface.Spec.PXE.Server != "" {
Expand Down
6 changes: 6 additions & 0 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ var _ = Describe("interface", Label("interface"), func() {
IPv6: &ipv6,
VNI: positiveTestVNI,
Device: "net_tap5",
Metering: &api.MeteringParams{
TotalRate: 100,
PublicRate: 50,
},
},
}

Expand Down Expand Up @@ -72,6 +76,8 @@ var _ = Describe("interface", Label("interface"), func() {

Expect(res.Spec.IPv4.String()).To(Equal("10.200.1.5"))
Expect(res.Spec.IPv6.String()).To(Equal("2000:200:1::5"))
Expect(res.Spec.Metering.TotalRate).To(Equal(uint64(0))) //MeteringRarams shouldn't take any effect on tap devices
Expect(res.Spec.Metering.PublicRate).To(Equal(uint64(0)))
})

It("should list successfully", func() {
Expand Down
Loading

0 comments on commit 8f2199a

Please sign in to comment.