Skip to content

Commit

Permalink
Update methods NewGroup, DeleteGroup and GetGroup of OFSwitch
Browse files Browse the repository at this point in the history
Signed-off-by: Hongliang Liu <[email protected]>
  • Loading branch information
hongliangl committed Mar 22, 2023
1 parent 3a19720 commit 2df2a11
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.6.9
v0.6.10
37 changes: 23 additions & 14 deletions ofctrl/fgraphSwitch.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package ofctrl

import (
"errors"
"fmt"

"antrea.io/libOpenflow/openflow15"
)
Expand Down Expand Up @@ -96,31 +97,39 @@ func (self *OFSwitch) DefaultTable() *Table {
return self.tableDb[0]
}

// Create a new group. return an error if it already exists
func (self *OFSwitch) NewGroup(groupId uint32, groupType GroupType) (*Group, error) {
// check if the group already exists
if self.groupDb[groupId] != nil {
return nil, errors.New("group already exists")
// NewGroup creates a new group; when using cache, returns an error if the group ID already exists, otherwise returns the
// group object; when not using cache, returns the new group object, and the caller should ensure the groupID is not
// duplicated.
func (self *OFSwitch) NewGroup(groupID uint32, groupType GroupType, useCache bool) (*Group, error) {
// Check if the group already exists.
if useCache {
if self.groupDb[groupID] != nil {
return nil, errors.New("group already exists")
}
}

// Create a new group
group := newGroup(groupId, groupType, self)
// Save it in the DB
self.groupDb[groupId] = group
// Create a new group.
group := newGroup(groupID, groupType, self)
if useCache {
// Save it in cache.
self.groupDb[groupID] = group
}

return group, nil
}

// Delete a group.
// Return an error if there are flows refer pointing at it
// DeleteGroup deletes a group in cache.
func (self *OFSwitch) DeleteGroup(groupId uint32) error {
delete(self.groupDb, groupId)
return nil
}

// GetGroup Returns a group
func (self *OFSwitch) GetGroup(groupId uint32) *Group {
return self.groupDb[groupId]
// GetGroup returns a group if it is cached.
func (self *OFSwitch) GetGroup(groupId uint32) (*Group, error) {
if _, exists := self.groupDb[groupId]; !exists {
return nil, fmt.Errorf("group %d does not exist in cache", groupId)
}
return self.groupDb[groupId], nil
}

// Create a new meter. return an error if it already exists
Expand Down

0 comments on commit 2df2a11

Please sign in to comment.