Skip to content

Commit

Permalink
add mulicast snoop switch
Browse files Browse the repository at this point in the history
  • Loading branch information
changluyi committed Aug 10, 2023
1 parent 68dc1c3 commit 4fef59a
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 0 deletions.
2 changes: 2 additions & 0 deletions charts/templates/kube-ovn-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1760,6 +1760,8 @@ spec:
type: boolean
enableEcmp:
type: boolean
enableMulticastSnoop:
type: boolean
routeTable:
type: string
scope: Cluster
Expand Down
2 changes: 2 additions & 0 deletions dist/images/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2299,6 +2299,8 @@ spec:
type: boolean
enableEcmp:
type: boolean
enableMulticastSnoop:
type: boolean
routeTable:
type: string
scope: Cluster
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/kubeovn/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ type SubnetSpec struct {
U2OInterconnection bool `json:"u2oInterconnection,omitempty"`
EnableLb *bool `json:"enableLb,omitempty"`
EnableEcmp bool `json:"enableEcmp,omitempty"`
EnableMulicastSnoop bool `json:"enableMulticastSnoop,omitempty"`

RouteTable string `json:"routeTable,omitempty"`
}
Expand Down
14 changes: 14 additions & 0 deletions pkg/controller/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ func (c *Controller) enqueueUpdateSubnet(old, new interface{}) {
oldSubnet.Spec.RouteTable != newSubnet.Spec.RouteTable ||
oldSubnet.Spec.Vpc != newSubnet.Spec.Vpc ||
oldSubnet.Spec.NatOutgoing != newSubnet.Spec.NatOutgoing ||
oldSubnet.Spec.EnableMulicastSnoop != newSubnet.Spec.EnableMulicastSnoop ||
!reflect.DeepEqual(oldSubnet.Spec.NatOutgoingPolicyRules, newSubnet.Spec.NatOutgoingPolicyRules) ||
(newSubnet.Spec.U2OInterconnection && newSubnet.Spec.U2OInterconnectionIP != "" &&
oldSubnet.Spec.U2OInterconnectionIP != newSubnet.Spec.U2OInterconnectionIP) {
Expand Down Expand Up @@ -758,6 +759,19 @@ func (c *Controller) handleAddOrUpdateSubnet(key string) error {
return err
}

multicastSnoopFlag := map[string]string{"mcast_snoop": "true", "mcast_querier": "false"}
if subnet.Spec.EnableMulicastSnoop {
if err := c.ovnClient.LogicalSwitchUpdateOtherConfig(subnet.Name, ovsdb.MutateOperationInsert, multicastSnoopFlag); err != nil {
klog.Errorf("enable logical switch multicast snoop %s: %v", subnet.Name, err)
return err
}
} else {
if err := c.ovnClient.LogicalSwitchUpdateOtherConfig(subnet.Name, ovsdb.MutateOperationDelete, multicastSnoopFlag); err != nil {
klog.Errorf("disable logical switch multicast snoop %s: %v", subnet.Name, err)
return err
}
}

subnet.Status.EnsureStandardConditions()

if err := c.updateSubnetDHCPOption(subnet, needRouter); err != nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/ovs/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type LogicalSwitch interface {
CreateLogicalSwitch(lsName, lrName, cidrBlock, gateway string, needRouter, randomAllocateGW bool) error
CreateBareLogicalSwitch(lsName string) error
LogicalSwitchUpdateLoadBalancers(lsName string, op ovsdb.Mutator, lbNames ...string) error
LogicalSwitchUpdateOtherConfig(lsName string, op ovsdb.Mutator, otherConfig map[string]string) error
DeleteLogicalSwitch(lsName string) error
ListLogicalSwitch(needVendorFilter bool, filter func(ls *ovnnb.LogicalSwitch) bool) ([]ovnnb.LogicalSwitch, error)
LogicalSwitchExists(lsName string) (bool, error)
Expand Down
38 changes: 38 additions & 0 deletions pkg/ovs/ovn-nb-logical_switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,25 @@ func (c *ovnClient) LogicalSwitchUpdateLoadBalancers(lsName string, op ovsdb.Mut
return nil
}

// LogicalSwitchUpdateOtherConfig add other config to or from logical switch once
func (c *ovnClient) LogicalSwitchUpdateOtherConfig(lsName string, op ovsdb.Mutator, otherConfig map[string]string) error {
if len(otherConfig) == 0 {
return nil
}

ops, err := c.LogicalSwitchUpdateOtherConfigOp(lsName, otherConfig, op)
if err != nil {
klog.Error(err)
return fmt.Errorf("generate operations for logical switch %s update other config %v: %v", lsName, otherConfig, err)
}

if err := c.Transact("ls-other-config-update", ops); err != nil {
return fmt.Errorf("logical switch %s update other config %v: %v", lsName, otherConfig, err)
}

return nil
}

// DeleteLogicalSwitch delete logical switch
func (c *ovnClient) DeleteLogicalSwitch(lsName string) error {
op, err := c.DeleteLogicalSwitchOp(lsName)
Expand Down Expand Up @@ -286,6 +305,25 @@ func (c *ovnClient) LogicalSwitchUpdatePortOp(lsName string, lspUUID string, op
return c.LogicalSwitchOp(lsName, mutation)
}

// LogicalSwitchUpdateOtherConfigOp create operations add otherConfig to or delete otherConfig from logical switch
func (c *ovnClient) LogicalSwitchUpdateOtherConfigOp(lsName string, otherConfig map[string]string, op ovsdb.Mutator) ([]ovsdb.Operation, error) {
if len(otherConfig) == 0 {
return nil, nil
}

mutation := func(ls *ovnnb.LogicalSwitch) *model.Mutation {
mutation := &model.Mutation{
Field: &ls.OtherConfig,
Value: otherConfig,
Mutator: op,
}

return mutation
}

return c.LogicalSwitchOp(lsName, mutation)
}

// LogicalSwitchUpdateLoadBalancerOp create operations add lb to or delete lb from logical switch
func (c *ovnClient) LogicalSwitchUpdateLoadBalancerOp(lsName string, lbUUIDs []string, op ovsdb.Mutator) ([]ovsdb.Operation, error) {
if len(lbUUIDs) == 0 {
Expand Down
2 changes: 2 additions & 0 deletions yamls/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2071,6 +2071,8 @@ spec:
type: boolean
enableEcmp:
type: boolean
enableMulticastSnoop:
type: boolean
scope: Cluster
names:
plural: subnets
Expand Down

0 comments on commit 4fef59a

Please sign in to comment.