Skip to content

Commit

Permalink
Refactoring Rx-placement and Rx-mode (#1344)
Browse files Browse the repository at this point in the history
Refactoring Rx-placement and Rx-mode
  • Loading branch information
ondrej-fabry authored May 17, 2019
2 parents 8bb018f + a6c4803 commit 6240579
Show file tree
Hide file tree
Showing 43 changed files with 2,831 additions and 609 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,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
158 changes: 158 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-modes (derived) */
const (
// rxModeKeyTemplate is a template for (derived) key representing
// rx-mode configuration for all queues of a given interface.
rxModesKeyTemplate = "vpp/interface/{iface}/rx-modes"
)

const (
// InvalidKeyPart is used in key for parts which are invalid
InvalidKeyPart = "<invalid>"
Expand Down Expand Up @@ -401,6 +427,138 @@ 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 modes (derived) */

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

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

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

isRxModesKey = 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

0 comments on commit 6240579

Please sign in to comment.