Skip to content

Commit 88fd066

Browse files
committed
Update methods NewGroup, DeleteGroup and GetGroup of OFSwitch
Signed-off-by: Hongliang Liu <lhongliang@vmware.com>
1 parent 21f844c commit 88fd066

File tree

14 files changed

+42
-34
lines changed

14 files changed

+42
-34
lines changed

.golangci.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,10 @@ linters-settings:
1212
linters:
1313
disable-all: true
1414
enable: # see https://golangci-lint.run/usage/linters/
15-
- deadcode
15+
- unused
1616
- staticcheck
1717
- govet
1818
- gofmt
1919
- goimports
2020
- gosec
2121
- misspell
22-
23-
run:
24-
deadline: 5m

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ test: docker-test-integration
2020
# code linting
2121
.golangci-bin:
2222
@echo "===> Installing Golangci-lint <==="
23-
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $@ v1.41.1
23+
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $@ v1.50.1
2424

2525
.PHONY: golangci
2626
golangci: .golangci-bin

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v0.6.7
1+
v0.6.9

ofctrl/dial.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build linux || darwin
12
// +build linux darwin
23

34
package ofctrl

ofctrl/fgraph.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/***
1+
/*
22
Copyright 2014 Cisco Systems Inc. All rights reserved.
33
44
Licensed under the Apache License, Version 2.0 (the "License");

ofctrl/fgraphFlood.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/***
1+
/*
22
Copyright 2014 Cisco Systems Inc. All rights reserved.
33
44
Licensed under the Apache License, Version 2.0 (the "License");

ofctrl/fgraphFlow.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/***
1+
/*
22
Copyright 2014 Cisco Systems Inc. All rights reserved.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
@@ -1906,10 +1906,10 @@ func (self *Flow) ConnTrack(commit bool, force bool, tableID *uint8, zoneID *uin
19061906

19071907
// Special Actions to to the flow to set conjunctions
19081908
// Note:
1909-
// 1) nclause should be in [2, 64].
1910-
// 2) clause value should be less than or equals to ncluase, and its value should be started from 1.
1911-
// actual clause in libopenflow messages is started from 0, here would decrement 1 to keep the display
1912-
// value is consistent with expected configuration
1909+
// 1. nclause should be in [2, 64].
1910+
// 2. clause value should be less than or equals to ncluase, and its value should be started from 1.
1911+
// actual clause in libopenflow messages is started from 0, here would decrement 1 to keep the display
1912+
// value is consistent with expected configuration
19131913
func (self *Flow) AddConjunction(conjID uint32, clause uint8, nClause uint8) error {
19141914
conjunction, err := NewNXConjunctionAction(conjID, clause, nClause)
19151915
if err != nil {

ofctrl/fgraphOutput.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/***
1+
/*
22
Copyright 2014 Cisco Systems Inc. All rights reserved.
33
44
Licensed under the Apache License, Version 2.0 (the "License");

ofctrl/fgraphSwitch.go

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/***
1+
/*
22
Copyright 2014 Cisco Systems Inc. All rights reserved.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
@@ -18,6 +18,7 @@ package ofctrl
1818

1919
import (
2020
"errors"
21+
"fmt"
2122

2223
"antrea.io/libOpenflow/openflow15"
2324
)
@@ -96,31 +97,39 @@ func (self *OFSwitch) DefaultTable() *Table {
9697
return self.tableDb[0]
9798
}
9899

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

106-
// Create a new group
107-
group := newGroup(groupId, groupType, self)
108-
// Save it in the DB
109-
self.groupDb[groupId] = group
111+
// Create a new group.
112+
group := newGroup(groupID, groupType, self)
113+
if useCache {
114+
// Save it in cache.
115+
self.groupDb[groupID] = group
116+
}
110117

111118
return group, nil
112119
}
113120

114-
// Delete a group.
115-
// Return an error if there are flows refer pointing at it
121+
// DeleteGroup deletes a group in cache.
116122
func (self *OFSwitch) DeleteGroup(groupId uint32) error {
117123
delete(self.groupDb, groupId)
118124
return nil
119125
}
120126

121-
// GetGroup Returns a group
122-
func (self *OFSwitch) GetGroup(groupId uint32) *Group {
123-
return self.groupDb[groupId]
127+
// GetGroup returns a group if it is cached.
128+
func (self *OFSwitch) GetGroup(groupId uint32) (*Group, error) {
129+
if _, exists := self.groupDb[groupId]; !exists {
130+
return nil, fmt.Errorf("group %d does not exist in cache", groupId)
131+
}
132+
return self.groupDb[groupId], nil
124133
}
125134

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

ofctrl/fgraphTable.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/***
1+
/*
22
Copyright 2014 Cisco Systems Inc. All rights reserved.
33
44
Licensed under the Apache License, Version 2.0 (the "License");

0 commit comments

Comments
 (0)