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

Add support for REMOVE_BUCKET operation in group #45

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@

.idea/
.vscode/
vendor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why adds this line?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I run command go mod vendor in this project by accident and found that this project doesn't ignore this directory.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But no directory named as "vendor" exists in this repo.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Antrea, we also ignore this directory.

6 changes: 2 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
run:
tests: true
timeout: 5m
deadline: 5m
skip-files:
- ".*\\.pb\\.go"
skip-dirs-use-default: true
Expand All @@ -12,13 +13,10 @@ linters-settings:
linters:
disable-all: true
enable: # see https://golangci-lint.run/usage/linters/
- deadcode
- unused
- staticcheck
- govet
- gofmt
- goimports
- gosec
- misspell

run:
deadline: 5m
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.41.1
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $@ v1.50.0

.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.7
v0.6.9
1 change: 1 addition & 0 deletions ofctrl/dial.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build linux || darwin
// +build linux darwin

package ofctrl
Expand Down
3 changes: 2 additions & 1 deletion ofctrl/fgraph.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/***
/*
**
Copyright 2014 Cisco Systems Inc. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
3 changes: 2 additions & 1 deletion ofctrl/fgraphFlood.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/***
/*
**
Copyright 2014 Cisco Systems Inc. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
11 changes: 6 additions & 5 deletions ofctrl/fgraphFlow.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/***
/*
**
Copyright 2014 Cisco Systems Inc. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -1906,10 +1907,10 @@ func (self *Flow) ConnTrack(commit bool, force bool, tableID *uint8, zoneID *uin

// Special Actions to to the flow to set conjunctions
// Note:
// 1) nclause should be in [2, 64].
// 2) clause value should be less than or equals to ncluase, and its value should be started from 1.
// actual clause in libopenflow messages is started from 0, here would decrement 1 to keep the display
// value is consistent with expected configuration
// 1. nclause should be in [2, 64].
// 2. clause value should be less than or equals to ncluase, and its value should be started from 1.
// actual clause in libopenflow messages is started from 0, here would decrement 1 to keep the display
// value is consistent with expected configuration
func (self *Flow) AddConjunction(conjID uint32, clause uint8, nClause uint8) error {
conjunction, err := NewNXConjunctionAction(conjID, clause, nClause)
if err != nil {
Expand Down
18 changes: 14 additions & 4 deletions ofctrl/fgraphGroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,23 @@ func (self *Group) getGroupModMessage(command int) *openflow15.GroupMod {
groupMod.Type = openflow15.GT_FF
}

for _, bkt := range self.Buckets {
// Add the bucket to group
groupMod.AddBucket(*bkt)
// In a request of type OFPGC_REMOVE_BUCKET, bucket list should be empty.
if command != openflow15.OFPGC_REMOVE_BUCKET {
for _, bkt := range self.Buckets {
// Add the bucket to group
groupMod.AddBucket(*bkt)
}
}

if command == openflow15.OFPGC_INSERT_BUCKET {
// In a request of type OFPGC_INSERT_BUCKET, the command_bucket_id field is used to specify the position in the
// current installed bucket list to insert new buckets. Here place the buckets to the end of the current installed
// bucket list.
groupMod.CommandBucketId = openflow15.OFPG_BUCKET_LAST
} else if command == openflow15.OFPGC_REMOVE_BUCKET {
// In a request of type OFPGC_REMOVE_BUCKET, the CommandBucketId field is used to specify the identifier of the
// bucket to remove from current installed bucket list.
groupMod.CommandBucketId = self.Buckets[0].BucketId

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it mean a single bucket can be removed in one OFPGC_REMOVE_BUCKET request? Is it possible to remove multiple buckets in a request?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the document of Openflow 1.5, it cannot.

groupMod.Buckets = nil
hongliangl marked this conversation as resolved.
Show resolved Hide resolved
}
groupMod.Command = uint16(command)
return groupMod
Expand Down
3 changes: 2 additions & 1 deletion ofctrl/fgraphOutput.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/***
/*
**
Copyright 2014 Cisco Systems Inc. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
40 changes: 26 additions & 14 deletions ofctrl/fgraphSwitch.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/***
/*
**
Copyright 2014 Cisco Systems Inc. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -18,6 +19,7 @@ package ofctrl

import (
"errors"
"fmt"

"antrea.io/libOpenflow/openflow15"
)
Expand Down Expand Up @@ -96,31 +98,41 @@ 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 has already been cached, otherwise
// returns the group object; when not using cache, returns the new group object.
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
// Create a new group.
group := newGroup(groupId, groupType, self)
// Save it in the DB
self.groupDb[groupId] = group
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 {
if _, exists := self.groupDb[groupId]; !exists {
return fmt.Errorf("group %d does not exist in cache", groupId)
}
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
3 changes: 2 additions & 1 deletion ofctrl/fgraphTable.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/***
/*
**
Copyright 2014 Cisco Systems Inc. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
3 changes: 2 additions & 1 deletion ofctrl/ofSwitch.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/***
/*
**
Copyright 2014 Cisco Systems Inc. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
3 changes: 2 additions & 1 deletion ofctrl/ofctrl_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/***
/*
**
Copyright 2014 Cisco Systems Inc. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
3 changes: 2 additions & 1 deletion ofctrl/ofpacket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,8 @@ func generateTCPPacketOut(srcMAC, dstMAC net.HardwareAddr, srcIP net.IP, dstIP n
}

// keeping this in case it is useful later
//nolint:deadcode
//
//nolint:unused
func generatePacketOut(srcMAC net.HardwareAddr, dstMAC net.HardwareAddr, srcIP net.IP, dstIP net.IP, outputPort *uint32, actions []OFAction) *PacketOut {
var outPort uint32
if outputPort == nil {
Expand Down
3 changes: 2 additions & 1 deletion ofctrl/ovsdbDriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,8 @@ func (self *OvsDriver) RemoveController(target string) error {

// Check the local cache and see if the portname is taken already
// HACK alert: This is used to pick next port number instead of managing
// port number space actively across agent restarts
//
// port number space actively across agent restarts
func (self *OvsDriver) IsPortNamePresent(intfName string) bool {
// lock the cache for read
self.lock.RLock()
Expand Down