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

Refactoring Rx-placement and Rx-mode #1344

Merged
merged 16 commits into from
May 17, 2019
Merged
Show file tree
Hide file tree
Changes from 14 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
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ examples:
cd examples/kvscheduler/l2 && go build -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS}
cd examples/kvscheduler/acl && go build -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS}
cd examples/kvscheduler/nat && go build -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS}
cd examples/kvscheduler/rxplacement && go build -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS}
cd examples/kvscheduler/vpp-l3 && go build -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS}
cd examples/kvscheduler/vrf && go build -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS}
cd examples/localclient_linux/tap && go build -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS}
cd examples/localclient_linux/veth && go build -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS}
cd examples/localclient_vpp/nat && go build -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS}
Expand Down
409 changes: 204 additions & 205 deletions api/models/vpp/interfaces/interface.pb.go

Large diffs are not rendered by default.

27 changes: 15 additions & 12 deletions api/models/vpp/interfaces/interface.proto
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,30 @@ message Interface {
}
Unnumbered unnumbered = 9;

message RxModeSettings {
message RxMode {
// from vpp/build-root/install-vpp-native/vpp/include/vnet/interface.h
enum RxModeType {
enum Type {
UNKNOWN = 0;
POLLING = 1;
INTERRUPT = 2;
ADAPTIVE = 3;
DEFAULT = 4;
};
RxModeType rx_mode = 1;
uint32 queue_id = 2;
uint32 queue_id_valid = 3;
uint32 queue = 1;
Type mode = 2;
bool default_mode = 3; // if enabled, <queue> will be ignored and the given
// <mode> will be used for all queues without explicitly
// selected Rx mode
}
RxModeSettings rx_mode_settings = 10;
repeated RxMode rx_modes = 10;

message RxPlacementSettings {
uint32 queue = 1;
uint32 worker = 2;
bool is_main = 3;
message RxPlacement {
uint32 queue = 1; // select from interval <0, number-of-queues)
uint32 worker = 2; // select from interval <0, number-of-workers)
bool main_thread = 3; // let the main thread to process the given queue
// - if enabled, value of <worker> is ignored
}
RxPlacementSettings rx_placement_settings = 11;
repeated RxPlacement rx_placements = 11;

oneof link {
SubInterface sub = 100; /* sub-interface configuration */
Expand All @@ -70,7 +73,7 @@ message Interface {
VxlanLink vxlan = 104; /* VXLAN-specific configuration */
IPSecLink ipsec = 105; /* IPSec tunnel-specific configuration */
VmxNet3Link vmx_net3 = 106; /* VmxNet3-specific configuration */
BondLink bond = 107; /* Bond interface-specific configuration */
BondLink bond = 107; /* Bond interface-specific configuration */
};
};

Expand Down
159 changes: 159 additions & 0 deletions api/models/vpp/interfaces/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,32 @@ const (
DHCPLeaseKeyPrefix = "vpp/interface/dhcp-lease/"
)

/* Interface Link State */

const (
// interface link states as described in the keys
linkUpState = "UP"
linkDownState = "DOWN"

// linkStateKeyTemplate is a template for keys representing
// the link state of VPP interfaces (up/down).
linkStateKeyTemplate = "vpp/interface/{ifName}/link-state/{linkState}"
)

/* Interface Rx-placement (derived) */
const (
// rxPlacementKeyTemplate is a template for (derived) key representing
// rx-placement configured for a given interface queue.
rxPlacementKeyTemplate = "vpp/interface/{iface}/rx-placement/queue/{queue}"
)

/* Interface Rx-mode (derived) */
const (
// rxModeKeyTemplate is a template for (derived) key representing
// rx-mode configuration for all queues of a given interface.
rxModeKeyTemplate = "vpp/interface/{iface}/rx-mode"
)

const (
// InvalidKeyPart is used in key for parts which are invalid
InvalidKeyPart = "<invalid>"
Expand Down Expand Up @@ -401,6 +427,139 @@ func ParseNameFromDHCPLeaseKey(key string) (iface string, isDHCPLeaseKey bool) {
return
}

/* Link State (notification) */

// LinkStateKey returns key representing link state of a VPP interface.
func LinkStateKey(ifaceName string, linkIsUp bool) string {
if ifaceName == "" {
ifaceName = InvalidKeyPart
}
linkState := linkDownState
if linkIsUp {
linkState = linkUpState
}
key := strings.Replace(linkStateKeyTemplate, "{ifName}", ifaceName, 1)
key = strings.Replace(key, "{linkState}", linkState, 1)
return key
}

// ParseLinkStateKey parses key representing link state of a VPP interface.
func ParseLinkStateKey(key string) (ifaceName string, isLinkUp bool, isLinkStateKey bool) {
if suffix := strings.TrimPrefix(key, "vpp/interface/"); suffix != key {
parts := strings.Split(suffix, "/")
linkState := -1
for i, part := range parts {
if part == "link-state" {
linkState = i
}
}
if linkState != len(parts)-2 {
return
}

switch parts[len(parts)-1] {
case linkDownState:
case linkUpState:
isLinkUp = true
default:
return
}

// beware: interface name may contain forward slashes
ifaceName = strings.Join(parts[:linkState], "/")
if ifaceName == InvalidKeyPart {
isLinkUp = false
ifaceName = ""
return
}
isLinkStateKey = true
}
return
}

/* Rx placement (derived) */

// RxPlacementKey returns a key representing rx-placement configured for a given
// interface queue.
func RxPlacementKey(ifaceName string, queue uint32) string {
if ifaceName == "" {
ifaceName = InvalidKeyPart
}
key := strings.Replace(rxPlacementKeyTemplate, "{iface}", ifaceName, 1)
key = strings.Replace(key, "{queue}", strconv.Itoa(int(queue)), 1)
return key
}

// ParseRxPlacementKey parses key representing rx-placement configured for a given
// interface queue.
func ParseRxPlacementKey(key string) (ifaceName string, queue uint32, isRxPlacementKey bool) {
if suffix := strings.TrimPrefix(key, "vpp/interface/"); suffix != key {
parts := strings.Split(suffix, "/")
rxPlacement := -1
for i, part := range parts {
if part == "rx-placement" {
rxPlacement = i
}
}
if rxPlacement != len(parts)-3 {
return
}

if parts[len(parts)-2] != "queue" {
return
}

queueID, err := strconv.Atoi(parts[len(parts)-1])
if err != nil || queueID < 0 {
return
}

// beware: interface name may contain forward slashes
ifaceName = strings.Join(parts[:rxPlacement], "/")
if ifaceName == InvalidKeyPart {
ifaceName = ""
return
}

queue = uint32(queueID)
isRxPlacementKey = true
}
return
}

/* Rx mode (derived) */

// RxModeKey returns a key representing rx-mode configuration for all queues
// of a given interface.
func RxModeKey(ifaceName string) string {
if ifaceName == "" {
ifaceName = InvalidKeyPart
}
return strings.Replace(rxModeKeyTemplate, "{iface}", ifaceName, 1)
}

// ParseRxModeKey parses key representing rx-mode configuration for all queues
// of a given interface.
func ParseRxModeKey(key string) (ifaceName string, isRxModeKey bool) {
if suffix := strings.TrimPrefix(key, "vpp/interface/"); suffix != key {
parts := strings.Split(suffix, "/")
if len(parts) == 0 || parts[len(parts)-1] != "rx-mode" {
isRxModeKey = false
return
}

// beware: interface name may contain forward slashes
ifaceName = strings.Join(parts[:len(parts)-1], "/")
if ifaceName == InvalidKeyPart {
ifaceName = ""
return
}

isRxModeKey = true
}
return
}

// MarshalJSON ensures that field of type 'oneOf' is correctly marshaled
// by using gogo lib marshaller
func (m *Interface) MarshalJSON() ([]byte, error) {
Expand Down
Loading