Skip to content

Commit

Permalink
vpcagent: ovn: apply guestnetwork bw_limit
Browse files Browse the repository at this point in the history
For kernel datapath, this requires at least openvswitch 2.10, or linux
4.15
  • Loading branch information
yousong committed May 28, 2020
1 parent 4b29984 commit 4b44f21
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
60 changes: 60 additions & 0 deletions pkg/vpcagent/ovn/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func DumpOVNNorthbound(ctx context.Context, cli *ovnutil.OvnNbCtl) (*OVNNorthbou
&db.LogicalRouterStaticRoute,
&db.ACL,
&db.DHCPOptions,
&db.QoS,
}
args := []string{"--format=json", "list", "<tbl>"}
for _, itbl := range itbls {
Expand Down Expand Up @@ -315,6 +316,7 @@ func (keeper *OVNNorthboundKeeper) ClaimGuestnetwork(ctx context.Context, guestn
ocVersion = fmt.Sprintf("%s.%d", guestnetwork.UpdatedAt, guestnetwork.UpdateVersion)
ocGnrDefaultRef = fmt.Sprintf("gnrDefault/%s/%s/%s", vpc.Id, guestnetwork.GuestId, guestnetwork.Ifname)
ocAclRef = fmt.Sprintf("acl/%s/%s/%s", network.Id, guestnetwork.GuestId, guestnetwork.Ifname)
ocQosRef = fmt.Sprintf("qos/%s/%s/%s", network.Id, guestnetwork.GuestId, guestnetwork.Ifname)
dhcpOpt string
)

Expand Down Expand Up @@ -344,6 +346,41 @@ func (keeper *OVNNorthboundKeeper) ClaimGuestnetwork(ctx context.Context, guestn
Addresses: []string{fmt.Sprintf("%s %s", guestnetwork.MacAddr, guestnetwork.IpAddr)},
PortSecurity: []string{fmt.Sprintf("%s %s/%d", guestnetwork.MacAddr, guestnetwork.IpAddr, guestnetwork.Network.GuestIpMask)},
Dhcpv4Options: &dhcpOpt,
Options: map[string]string{},
}

var qosVif []*ovn_nb.QoS
if bwMbps := guestnetwork.BwLimit; bwMbps > 0 {
var (
kbps = int64(bwMbps * 1000)
kbur = int64(kbps * 2)
)
qosVif = []*ovn_nb.QoS{
&ovn_nb.QoS{
Priority: 2000,
Direction: "from-lport",
Match: fmt.Sprintf("inport == %q", lportName),
Bandwidth: map[string]int64{
"rate": kbps,
"burst": kbur,
},
ExternalIds: map[string]string{
externalKeyOcRef: ocQosRef,
},
},
&ovn_nb.QoS{
Priority: 1000,
Direction: "to-lport",
Match: fmt.Sprintf("outport == %q", lportName),
Bandwidth: map[string]int64{
"rate": kbps,
"burst": kbur,
},
ExternalIds: map[string]string{
externalKeyOcRef: ocQosRef,
},
},
}
}

var gnrDefault *ovn_nb.LogicalRouterStaticRoute
Expand Down Expand Up @@ -400,6 +437,9 @@ func (keeper *OVNNorthboundKeeper) ClaimGuestnetwork(ctx context.Context, guestn
for _, acl := range acls {
irows = append(irows, acl)
}
for _, qos := range qosVif {
irows = append(irows, qos)
}
allFound, args := cmp(&keeper.DB, ocVersion, irows...)
if allFound {
return nil
Expand All @@ -416,6 +456,11 @@ func (keeper *OVNNorthboundKeeper) ClaimGuestnetwork(ctx context.Context, guestn
args = append(args, ovnCreateArgs(acl, ref)...)
args = append(args, "--", "add", "Logical_Switch", netLsName(guestnetwork.NetworkId), "acls", "@"+ref)
}
for i, qos := range qosVif {
ref := fmt.Sprintf("qosVif%d", i)
args = append(args, ovnCreateArgs(qos, ref)...)
args = append(args, "--", "add", "Logical_Switch", netLsName(guestnetwork.NetworkId), "qos_rules", "@"+ref)
}
return keeper.cli.Must(ctx, "ClaimGuestnetwork", args)
}

Expand All @@ -429,6 +474,7 @@ func (keeper *OVNNorthboundKeeper) Mark(ctx context.Context) {
&db.LogicalRouterStaticRoute,
&db.ACL,
&db.DHCPOptions,
&db.QoS,
}
for _, itbl := range itbls {
for _, irow := range itbl.Rows() {
Expand Down Expand Up @@ -489,5 +535,19 @@ func (keeper *OVNNorthboundKeeper) Sweep(ctx context.Context) error {
keeper.cli.Must(ctx, "Sweep acls", args)
}
}
{ // remove unused QoS rows
var args []string
for _, irow := range db.QoS.Rows() {
_, ok := irow.GetExternalId(externalKeyOcVersion)
if !ok {
for _, ls := range db.LogicalSwitch.FindQoSReferrer_qos_rules(irow.OvsdbUuid()) {
args = append(args, "--", "--if-exists", "remove", "Logical_Switch", ls.Name, "qos_rules", irow.OvsdbUuid())
}
}
}
if len(args) > 0 {
keeper.cli.Must(ctx, "Sweep qos", args)
}
}
return nil
}
1 change: 1 addition & 0 deletions pkg/vpcagent/ovnutil/ovn_nbctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ func OvnNbctlArgsDestroy(irows []types.IRow) []string {
newArgs = []string{"--", "--if-exists", "lrp-del", irow.OvsdbUuid()}
case *ovn_nb.LogicalRouterStaticRoute:
case *ovn_nb.ACL:
case *ovn_nb.QoS:
default:
if !irow.OvsdbIsRoot() {
panic(irow.OvsdbTableName())
Expand Down

0 comments on commit 4b44f21

Please sign in to comment.