Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redundant Openflow messages are sent when syncing an updated group to OVS #4159

Closed
hongliangl opened this issue Aug 29, 2022 · 1 comment · Fixed by #4160
Closed

Redundant Openflow messages are sent when syncing an updated group to OVS #4159

hongliangl opened this issue Aug 29, 2022 · 1 comment · Fixed by #4160
Assignees
Labels
action/release-note Indicates a PR that should be included in release notes. area/proxy Issues or PRs related to proxy functions in Antrea kind/bug Categorizes issue or PR as related to a bug.

Comments

@hongliangl
Copy link
Contributor

hongliangl commented Aug 29, 2022

Describe the bug

For example, when syncing an ClusterIP Service whose Endpoints has been changed,

Function in the following is called in pkg/agent/openflow/client.go, we can see that variable group is returned by serviceEndpointGroup , then call the method Add() to sync the group to OVS.

func (c *client) InstallServiceGroup(groupID binding.GroupIDType, withSessionAffinity bool, endpoints []proxy.Endpoint) error {
	c.replayMutex.RLock()
	defer c.replayMutex.RUnlock()

	group := c.featureService.serviceEndpointGroup(groupID, withSessionAffinity, endpoints...)
	if err := group.Add(); err != nil {
		return fmt.Errorf("error when installing Service Endpoints Group: %w", err)
	}
	c.featureService.groupCache.Store(groupID, group)
	return nil
}

We can see the code of method Add() in pkg/ovs/openflow/ofctrl_group.go:

func (g *ofGroup) Add() error {
	return g.ofctrl.Install()
}

We can see the the method Install() of g.ofctrl in lib ofnet https://github.com/antrea-io/ofnet/blob/716e8ccd4ba3713d3b38ff2f808e698749d9de79/ofctrl/fgraphGroup.go#L76

func (self *Group) Install() error {
	command := openflow15.OFPGC_ADD
	if self.isInstalled {
		command = openflow15.OFPGC_MODIFY
	}
	groupMod := self.getGroupModMessage(command)

	if err := self.Switch.Send(groupMod); err != nil {
		return err
	}

	// Mark it as installed
	self.isInstalled = true

	return nil
}

However, in serviceEndpointGroup which is used to generate group in /pkg/agent/openflow/pipeline.go, we can see that when adding a new bucket, then Done() is called.

func (f *featureService) serviceEndpointGroup(groupID binding.GroupIDType, withSessionAffinity bool, endpoints ...proxy.Endpoint) binding.Group {
	group := f.bridge.CreateGroup(groupID).ResetBuckets()
	var resubmitTableID uint8
	if withSessionAffinity {
		resubmitTableID = ServiceLBTable.GetID()
	} else {
		resubmitTableID = EndpointDNATTable.GetID()
	}
	for _, endpoint := range endpoints {
		endpointPort, _ := endpoint.Port()
		endpointIP := net.ParseIP(endpoint.IP())
		portVal := util.PortToUint16(endpointPort)
		ipProtocol := getIPProtocol(endpointIP)

		if ipProtocol == binding.ProtocolIP {
			ipVal := binary.BigEndian.Uint32(endpointIP.To4())
			group = group.Bucket().Weight(100).
				LoadToRegField(EndpointIPField, ipVal).
				LoadToRegField(EndpointPortField, uint32(portVal)).
				ResubmitToTable(resubmitTableID).
				Done()
		} else if ipProtocol == binding.ProtocolIPv6 {
			ipVal := []byte(endpointIP)
			group = group.Bucket().Weight(100).
				LoadXXReg(EndpointIP6Field.GetRegID(), ipVal).
				LoadToRegField(EndpointPortField, uint32(portVal)).
				ResubmitToTable(resubmitTableID).
				Done()
		}
	}
	return group
}

We can see the code in Done() in /pkg/ovs/openflow/ofctrl_group.go, AddBuckets is called.

func (b *bucketBuilder) Done() Group {
	b.group.ofctrl.AddBuckets(b.bucket)
	return b.group
}

AddBuckets is defined in lib ofnet https://github.com/antrea-io/ofnet/blob/716e8ccd4ba3713d3b38ff2f808e698749d9de79/ofctrl/fgraphGroup.go#L58:

func (self *Group) AddBuckets(buckets ...*openflow15.Bucket) {
	if self.Buckets == nil {
		self.Buckets = make([]*openflow15.Bucket, 0)
	}
	self.Buckets = append(self.Buckets, buckets...)
	if self.isInstalled {
		self.Install()
	}
}

We can see that if self.isInstalled is true (this means that when updating the group), Install() is called.

Take a simple example, when syncing a updated Service which has 3 Endpoints, there are

  • Message to install the corresponding group which has bucket 0 (triggered by Done() to generate bucket 0)
  • Message to install the corresponding group which has bucket 0, 1 (triggered by Done() to generate bucket 1)
  • Message to install the corresponding group which has bucket 0, 1, 2 (triggered by Done() to generate bucket 2)
  • Message to install the corresponding group which has bucket 0, 1, 2 (triggered by Add() to install the group)

Only the last Openflow is needed when syncing an updated group to OVS. To fix the issue, the code in Done() could be:

func (b *bucketBuilder) Done() Group {
	b.group.ofctrl.Buckets = append(b.group.ofctrl.Buckets, b.bucket)
	return b.group
}
@hongliangl hongliangl added the kind/bug Categorizes issue or PR as related to a bug. label Aug 29, 2022
@hongliangl hongliangl changed the title n*(n+1)/2 Openflow messages are sent when syncing an updated OVS group that has n buckets. n Openflow messages are sent when syncing an updated OVS group that has n buckets. Aug 29, 2022
@hongliangl hongliangl changed the title n Openflow messages are sent when syncing an updated OVS group that has n buckets. Redundant Openflow messages are sent when syncing an updated group to OVS. Aug 29, 2022
@hongliangl hongliangl added the area/proxy Issues or PRs related to proxy functions in Antrea label Aug 29, 2022
@hongliangl hongliangl self-assigned this Aug 29, 2022
@hongliangl hongliangl changed the title Redundant Openflow messages are sent when syncing an updated group to OVS. Redundant Openflow messages are sent when syncing an updated group to OVS Aug 29, 2022
hongliangl added a commit to hongliangl/antrea that referenced this issue Aug 29, 2022
Fix antrea-io#4159

This PR fix the issue by appending buckets directly in `Done()` in
pkg/ovs/openflow/ofctrl_group.go instead of calling `AddBuckets` method
of `Group` defined in the ofnet which sends an Openflow message to install
the group.

Signed-off-by: Hongliang Liu <lhongliang@vmware.com>
@tnqn tnqn added this to the Antrea v1.9 release milestone Aug 29, 2022
@tnqn tnqn added the action/release-note Indicates a PR that should be included in release notes. label Aug 29, 2022
@tnqn
Copy link
Member

tnqn commented Aug 29, 2022

@hongliangl nice catch!

tnqn pushed a commit that referenced this issue Aug 29, 2022
#4160)

Fix #4159

This PR fix the issue by appending buckets directly in `Done()` in
pkg/ovs/openflow/ofctrl_group.go instead of calling `AddBuckets` method
of `Group` defined in the ofnet which sends an Openflow message to install
the group.

Signed-off-by: Hongliang Liu <lhongliang@vmware.com>
hongliangl added a commit to hongliangl/antrea that referenced this issue Aug 29, 2022
Fix antrea-io#4159

This PR fix the issue by appending buckets directly in `Done()` in
pkg/ovs/openflow/ofctrl_group.go instead of calling `AddBuckets` method
of `Group` defined in the ofnet which sends an Openflow message to install
the group.

Signed-off-by: Hongliang Liu <lhongliang@vmware.com>
hongliangl added a commit to hongliangl/antrea that referenced this issue Aug 29, 2022
Fix antrea-io#4159

This PR fix the issue by appending buckets directly in `Done()` in
pkg/ovs/openflow/ofctrl_group.go instead of calling `AddBuckets` method
of `Group` defined in the ofnet which sends an Openflow message to install
the group.

Signed-off-by: Hongliang Liu <lhongliang@vmware.com>
hongliangl added a commit to hongliangl/antrea that referenced this issue Aug 29, 2022
Fix antrea-io#4159

This PR fix the issue by appending buckets directly in `Done()` in
pkg/ovs/openflow/ofctrl_group.go instead of calling `AddBuckets` method
of `Group` defined in the ofnet which sends an Openflow message to install
the group.

Signed-off-by: Hongliang Liu <lhongliang@vmware.com>
hongliangl added a commit to hongliangl/antrea that referenced this issue Aug 29, 2022
Fix antrea-io#4159

This PR fix the issue by appending buckets directly in `Done()` in
pkg/ovs/openflow/ofctrl_group.go instead of calling `AddBuckets` method
of `Group` defined in the ofnet which sends an Openflow message to install
the group.

Signed-off-by: Hongliang Liu <lhongliang@vmware.com>
hongliangl added a commit to hongliangl/antrea that referenced this issue Aug 29, 2022
Fix antrea-io#4159

This PR fix the issue by appending buckets directly in `Done()` in
pkg/ovs/openflow/ofctrl_group.go instead of calling `AddBuckets` method
of `Group` defined in the ofnet which sends an Openflow message to install
the group.

Signed-off-by: Hongliang Liu <lhongliang@vmware.com>
hongliangl added a commit to hongliangl/antrea that referenced this issue Aug 29, 2022
Fix antrea-io#4159

This PR fix the issue by appending buckets directly in `Done()` in
pkg/ovs/openflow/ofctrl_group.go instead of calling `AddBuckets` method
of `Group` defined in the ofnet which sends an Openflow message to install
the group.

Signed-off-by: Hongliang Liu <lhongliang@vmware.com>
tnqn pushed a commit that referenced this issue Aug 30, 2022
#4161)

Fix #4159

This PR fix the issue by appending buckets directly in `Done()` in
pkg/ovs/openflow/ofctrl_group.go instead of calling `AddBuckets` method
of `Group` defined in the ofnet which sends an Openflow message to install
the group.

Signed-off-by: Hongliang Liu <lhongliang@vmware.com>
tnqn pushed a commit that referenced this issue Aug 30, 2022
#4162)

Fix #4159

This PR fix the issue by appending buckets directly in `Done()` in
pkg/ovs/openflow/ofctrl_group.go instead of calling `AddBuckets` method
of `Group` defined in the ofnet which sends an Openflow message to install
the group.

Signed-off-by: Hongliang Liu <lhongliang@vmware.com>
tnqn pushed a commit that referenced this issue Aug 30, 2022
#4163)

Fix #4159

This PR fix the issue by appending buckets directly in `Done()` in
pkg/ovs/openflow/ofctrl_group.go instead of calling `AddBuckets` method
of `Group` defined in the ofnet which sends an Openflow message to install
the group.

Signed-off-by: Hongliang Liu <lhongliang@vmware.com>
tnqn pushed a commit that referenced this issue Aug 30, 2022
#4164)

Fix #4159

This PR fix the issue by appending buckets directly in `Done()` in
pkg/ovs/openflow/ofctrl_group.go instead of calling `AddBuckets` method
of `Group` defined in the ofnet which sends an Openflow message to install
the group.

Signed-off-by: Hongliang Liu <lhongliang@vmware.com>
heanlan pushed a commit to heanlan/antrea that referenced this issue Mar 29, 2023
antrea-io#4160)

Fix antrea-io#4159

This PR fix the issue by appending buckets directly in `Done()` in
pkg/ovs/openflow/ofctrl_group.go instead of calling `AddBuckets` method
of `Group` defined in the ofnet which sends an Openflow message to install
the group.

Signed-off-by: Hongliang Liu <lhongliang@vmware.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action/release-note Indicates a PR that should be included in release notes. area/proxy Issues or PRs related to proxy functions in Antrea kind/bug Categorizes issue or PR as related to a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants