Skip to content

Commit

Permalink
For ofnet v0.6.10 (#56)
Browse files Browse the repository at this point in the history
* Bump up golangci-lint version to 1.52.1 (#54)

Signed-off-by: wenyingd <wenyingd@vmware.com>

* Add concurrency control for tableDb,groupDb and meterDb in OFSwitch (#52)

Signed-off-by: Ruochen <ruoshens@vmware.com>
  • Loading branch information
tnqn authored Apr 18, 2023
1 parent 3a19720 commit f4a1e3d
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ test: docker-test-integration
# code linting
.golangci-bin:
@echo "===> Installing Golangci-lint <==="
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $@ v1.50.1
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $@ v1.52.2

.PHONY: golangci
golangci: .golangci-bin
Expand Down
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
18 changes: 18 additions & 0 deletions ofctrl/fgraphSwitch.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ func (self *OFSwitch) initFgraph() {

// Create a new table. return an error if it already exists
func (self *OFSwitch) NewTable(tableId uint8) (*Table, error) {
self.tableDbMux.Lock()
defer self.tableDbMux.Unlock()
// Check the parameters
if tableId == 0 {
return nil, errors.New("Table 0 already exists")
Expand Down Expand Up @@ -88,16 +90,22 @@ func (self *OFSwitch) DeleteTable(tableId uint8) error {

// GetTable Returns a table
func (self *OFSwitch) GetTable(tableId uint8) *Table {
self.tableDbMux.Lock()
defer self.tableDbMux.Unlock()
return self.tableDb[tableId]
}

// Return table 0 which is the starting table for all packets
func (self *OFSwitch) DefaultTable() *Table {
self.tableDbMux.Lock()
defer self.tableDbMux.Unlock()
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) {
self.groupDbMux.Lock()
defer self.groupDbMux.Unlock()
// check if the group already exists
if self.groupDb[groupId] != nil {
return nil, errors.New("group already exists")
Expand All @@ -114,17 +122,23 @@ func (self *OFSwitch) NewGroup(groupId uint32, groupType GroupType) (*Group, err
// Delete a group.
// Return an error if there are flows refer pointing at it
func (self *OFSwitch) DeleteGroup(groupId uint32) error {
self.groupDbMux.Lock()
defer self.groupDbMux.Unlock()
delete(self.groupDb, groupId)
return nil
}

// GetGroup Returns a group
func (self *OFSwitch) GetGroup(groupId uint32) *Group {
self.groupDbMux.Lock()
defer self.groupDbMux.Unlock()
return self.groupDb[groupId]
}

// Create a new meter. return an error if it already exists
func (self *OFSwitch) NewMeter(meterId uint32, flags MeterFlag) (*Meter, error) {
self.meterDbMux.Lock()
defer self.meterDbMux.Unlock()
// check if the meter already exists
if _, ok := self.meterDb[meterId]; ok {
return nil, errors.New("meter already exists")
Expand All @@ -141,12 +155,16 @@ func (self *OFSwitch) NewMeter(meterId uint32, flags MeterFlag) (*Meter, error)
// Delete a meter.
// Return an error if there are flows refer pointing at it
func (self *OFSwitch) DeleteMeter(meterId uint32) error {
self.meterDbMux.Lock()
defer self.meterDbMux.Unlock()
delete(self.meterDb, meterId)
return nil
}

// GetGroup Returns a meter
func (self *OFSwitch) GetMeter(meterId uint32) *Meter {
self.meterDbMux.Lock()
defer self.meterDbMux.Unlock()
return self.meterDb[meterId]
}

Expand Down
5 changes: 4 additions & 1 deletion ofctrl/ofSwitch.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,18 @@ type OFSwitch struct {
app AppInterface
// Following are fgraph state for the switch
tableDb map[uint8]*Table
tableDbMux sync.Mutex
dropAction *Output
sendToCtrler *Output
normalLookup *Output
ready bool
portMux sync.Mutex
statusMux sync.Mutex
outputPorts map[uint32]*Output
portMux sync.Mutex
groupDb map[uint32]*Group
groupDbMux sync.Mutex
meterDb map[uint32]*Meter
meterDbMux sync.Mutex
connCh chan int // Channel to notify controller connection status is changed
mQueue chan *openflow15.MultipartRequest
monitorEnabled bool
Expand Down
6 changes: 2 additions & 4 deletions ofctrl/ovsdbDriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,11 @@ func (self *OvsDriver) CreateBridge(bridgeName string) error {
}

// simple insert/delete operation
brOp := libovsdb.Operation{}
bridge := make(map[string]interface{})
bridge["name"] = bridgeName
bridge["protocols"], _ = libovsdb.NewOvsSet(protocols)
bridge["fail_mode"] = "secure"
brOp = libovsdb.Operation{
brOp := libovsdb.Operation{
Op: "insert",
Table: "Bridge",
Row: bridge,
Expand Down Expand Up @@ -211,9 +210,8 @@ func (self *OvsDriver) DeleteBridge(bridgeName string) error {
brUuid := []libovsdb.UUID{{GoUuid: namedUuidStr}}

// simple insert/delete operation
brOp := libovsdb.Operation{}
condition := libovsdb.NewCondition("name", "==", bridgeName)
brOp = libovsdb.Operation{
brOp := libovsdb.Operation{
Op: "delete",
Table: "Bridge",
Where: []interface{}{condition},
Expand Down

0 comments on commit f4a1e3d

Please sign in to comment.