Skip to content

Commit aff8517

Browse files
committed
nff-go in Azure with failsafe
For example: config := flow.Config{ DPDKArgs: []string { "--vdev=net_vdev_netvsc0,iface=eth1", "--vdev=net_vdev_netvsc1,iface=eth2", }, } flow.CheckFatal(flow.SystemInit(&config)) Signed-off-by: Stefan Rinkes <[email protected]>
1 parent ce6c350 commit aff8517

File tree

4 files changed

+39
-31
lines changed

4 files changed

+39
-31
lines changed

flow/flow.go

+30-21
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import (
4545
)
4646

4747
var openFlowsNumber = uint32(0)
48-
var createdPorts []port
48+
var createdPorts map[uint16](*port)
4949
var portPair map[types.IPv4Address](*port)
5050
var schedState *scheduler
5151
var vEach [10][vBurstSize]uint8
@@ -725,14 +725,19 @@ func SystemInit(args *Config) error {
725725
return err
726726
}
727727
// Init Ports
728-
createdPorts = make([]port, low.GetPortsNumber(), low.GetPortsNumber())
729-
for i := range createdPorts {
730-
createdPorts[i].port = uint16(i)
728+
createdPorts = make(map[uint16](*port))
729+
i := low.GetNextPort(0)
730+
for i < low.RteMaxEthPorts {
731+
createdPorts[i] = &port{}
732+
createdPorts[i].port = i
733+
common.LogDebug(common.Initialization, "Found Port ID:", i)
734+
731735
if maxInIndex > low.CheckPortRSS(createdPorts[i].port) {
732736
createdPorts[i].InIndex = low.CheckPortRSS(createdPorts[i].port)
733737
} else {
734738
createdPorts[i].InIndex = maxInIndex
735739
}
740+
i = low.GetNextPort(i + 1)
736741
}
737742
portPair = make(map[types.IPv4Address](*port))
738743
ioDevices = make(map[string]interface{})
@@ -886,17 +891,18 @@ func SetReceiverFile(filename string, repcount int32) (OUT *Flow) {
886891
// Receive queue will be added to port automatically.
887892
// Returns new opened flow with received packets
888893
func SetReceiver(portId uint16) (OUT *Flow, err error) {
889-
if portId >= uint16(len(createdPorts)) {
890-
return nil, common.WrapWithNFError(nil, "Requested receive port exceeds number of ports which can be used by DPDK (bind to DPDK).", common.ReqTooManyPorts)
894+
port, ok := createdPorts[portId]
895+
if !ok {
896+
return nil, common.WrapWithNFError(nil, "Requested receive port not found.", common.ReqTooManyPorts)
891897
}
892-
if createdPorts[portId].willReceive {
898+
if port.willReceive {
893899
return nil, common.WrapWithNFError(nil, "Requested receive port was already set to receive. Two receives from one port are prohibited.", common.MultipleReceivePort)
894900
}
895-
createdPorts[portId].wasRequested = true
896-
createdPorts[portId].willReceive = true
897-
rings := low.CreateRings(burstSize*sizeMultiplier, createdPorts[portId].InIndex)
898-
addReceiver(portId, rings, createdPorts[portId].InIndex)
899-
return newFlow(rings, createdPorts[portId].InIndex), nil
901+
port.wasRequested = true
902+
port.willReceive = true
903+
rings := low.CreateRings(burstSize*sizeMultiplier, port.InIndex)
904+
addReceiver(portId, rings, port.InIndex)
905+
return newFlow(rings, port.InIndex), nil
900906
}
901907

902908
// SetReceiverOS adds function receive from Linux interface to flow graph.
@@ -1045,11 +1051,14 @@ func SetSender(IN *Flow, portId uint16) error {
10451051
if err := checkFlow(IN); err != nil {
10461052
return err
10471053
}
1048-
if portId >= uint16(len(createdPorts)) {
1049-
return common.WrapWithNFError(nil, "Requested send port exceeds number of ports which can be used by DPDK (bind to DPDK).", common.ReqTooManyPorts)
1054+
1055+
port, ok := createdPorts[portId]
1056+
if !ok {
1057+
return common.WrapWithNFError(nil, "Requested send port not found.", common.ReqTooManyPorts)
10501058
}
1051-
createdPorts[portId].wasRequested = true
1052-
if createdPorts[portId].sendRings == nil {
1059+
1060+
port.wasRequested = true
1061+
if port.sendRings == nil {
10531062
// To allow consequent sends to one port, we need to create a send ring
10541063
// for the first, and then all the consequent sends should be merged
10551064
// with already created send ring.
@@ -1062,13 +1071,13 @@ func SetSender(IN *Flow, portId uint16) error {
10621071
max = createdPorts[i].InIndex
10631072
}
10641073
}
1065-
createdPorts[portId].sendRings = low.CreateRings(burstSize*sizeMultiplier, max)
1066-
addSender(portId, createdPorts[portId].sendRings, IN.inIndexNumber)
1074+
port.sendRings = low.CreateRings(burstSize*sizeMultiplier, max)
1075+
addSender(portId, port.sendRings, IN.inIndexNumber)
10671076
}
10681077
// For a typical 40 GB card, like Intel 710 series, one core should be able
10691078
// to handle all the TX without problems. So we merged all income flows to created
10701079
// ring which will be send.
1071-
mergeOneFlow(IN, createdPorts[portId].sendRings)
1080+
mergeOneFlow(IN, port.sendRings)
10721081
return nil
10731082
}
10741083

@@ -1312,7 +1321,7 @@ func GetNameByPort(port uint16) (string, error) {
13121321
func SetIPForPort(port uint16, ip types.IPv4Address) error {
13131322
for i := range createdPorts {
13141323
if createdPorts[i].port == port && createdPorts[i].wasRequested {
1315-
portPair[ip] = &createdPorts[i]
1324+
portPair[ip] = createdPorts[i]
13161325
return nil
13171326
}
13181327
}
@@ -1554,7 +1563,7 @@ func recvXDP(parameters interface{}, inIndex []int32, flag *int32, coreID int) {
15541563
func processKNI(parameters interface{}, inIndex []int32, flag *int32, coreID int) {
15551564
srk := parameters.(*KNIParameters)
15561565
if srk.linuxCore == true {
1557-
coreID = schedState.cores[createdPorts[srk.port.PortId].KNICoreIndex].id
1566+
coreID = schedState.cores[createdPorts[uint16(srk.port.PortId)].KNICoreIndex].id
15581567
}
15591568
low.SrKNI(uint16(srk.port.PortId), flag, coreID, srk.recv, srk.out, srk.send, srk.in, &srk.stats)
15601569
}

internal/low/low.go

+8
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,14 @@ func FreeKNI(port uint16) error {
596596
return nil
597597
}
598598

599+
const (
600+
RteMaxEthPorts = C.RTE_MAX_ETHPORTS
601+
)
602+
603+
func GetNextPort(port uint16) uint16 {
604+
return uint16(C.rte_eth_find_next_owned_by(C.uint16_t(port), C.RTE_ETH_DEV_NO_OWNER))
605+
}
606+
599607
// GetPortsNumber gets total number of available Ethernet devices.
600608
func GetPortsNumber() int {
601609
return int(C.rte_eth_dev_count())

internal/low/low.h

-9
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,6 @@ int port_init(uint16_t port, bool willReceive, struct rte_mempool **mbuf_pools,
290290
rx_rings = 0;
291291
}
292292

293-
if (port >= rte_eth_dev_count())
294-
return -1;
295-
296293
struct rte_eth_conf port_conf_default = {
297294
.rxmode = { .max_rx_pkt_len = RTE_ETHER_MAX_LEN,
298295
.mq_mode = ETH_MQ_RX_RSS },
@@ -940,9 +937,6 @@ bool check_hwtxchecksum_capability(uint16_t port_id) {
940937
DEV_TX_OFFLOAD_TCP_CKSUM;
941938
struct rte_eth_dev_info dev_info;
942939

943-
if (port_id >= rte_eth_dev_count())
944-
return false;
945-
946940
memset(&dev_info, 0, sizeof(dev_info));
947941
rte_eth_dev_info_get(port_id, &dev_info);
948942
return (dev_info.tx_offload_capa & flags) == flags;
@@ -952,9 +946,6 @@ bool check_hwrxpackets_timestamp_capability(uint16_t port_id) {
952946
uint64_t flags = DEV_RX_OFFLOAD_TIMESTAMP;
953947
struct rte_eth_dev_info dev_info;
954948

955-
if (port_id >= rte_eth_dev_count())
956-
return false;
957-
958949
memset(&dev_info, 0, sizeof(dev_info));
959950
rte_eth_dev_info_get(port_id, &dev_info);
960951
return (dev_info.rx_offload_capa & flags) == flags;

internal/low/low_mlx.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
package low
88

99
/*
10-
#cgo LDFLAGS: -lrte_distributor -lrte_reorder -lrte_kni -lrte_pipeline -lrte_table -lrte_port -lrte_timer -lrte_jobstats -lrte_lpm -lrte_power -lrte_acl -lrte_meter -lrte_sched -lrte_vhost -lrte_ip_frag -lrte_cfgfile -Wl,--whole-archive -Wl,--start-group -lrte_kvargs -lrte_mbuf -lrte_hash -lrte_ethdev -lrte_mempool -lrte_ring -lrte_mempool_ring -lrte_eal -lrte_cmdline -lrte_net -lrte_bus_pci -lrte_pci -lrte_bus_vdev -lrte_timer -lrte_pmd_bond -lrte_pmd_vmxnet3_uio -lrte_pmd_virtio -lrte_pmd_cxgbe -lrte_pmd_enic -lrte_pmd_i40e -lrte_pmd_fm10k -lrte_pmd_ixgbe -lrte_pmd_e1000 -lrte_pmd_ena -lrte_pmd_ring -lrte_pmd_af_packet -lrte_pmd_null -libverbs -lmnl -lmlx4 -lmlx5 -lrte_pmd_mlx4 -lrte_pmd_mlx5 -Wl,--end-group -Wl,--no-whole-archive -lrt -lm -ldl -lnuma
10+
#cgo LDFLAGS: -lrte_distributor -lrte_reorder -lrte_kni -lrte_pipeline -lrte_table -lrte_port -lrte_timer -lrte_jobstats -lrte_lpm -lrte_power -lrte_acl -lrte_meter -lrte_sched -lrte_vhost -lrte_ip_frag -lrte_cfgfile -Wl,--whole-archive -Wl,--start-group -lrte_kvargs -lrte_mbuf -lrte_hash -lrte_ethdev -lrte_gso -lrte_mempool -lrte_ring -lrte_mempool_ring -lrte_eal -lrte_cmdline -lrte_net -lrte_bus_pci -lrte_pci -lrte_bus_vdev -lrte_timer -lrte_pmd_bond -lrte_pmd_vmxnet3_uio -lrte_pmd_virtio -lrte_pmd_cxgbe -lrte_pmd_enic -lrte_pmd_i40e -lrte_pmd_fm10k -lrte_pmd_ixgbe -lrte_pmd_e1000 -lrte_pmd_ena -lrte_pmd_ring -lrte_pmd_af_packet -lrte_pmd_null -lrte_pmd_failsafe -lrte_pmd_tap -lrte_pmd_vdev_netvsc -lrte_bus_vmbus -lrte_pmd_netvsc -libverbs -lmnl -lmlx4 -lmlx5 -lrte_pmd_mlx4 -lrte_pmd_mlx5 -Wl,--end-group -Wl,--no-whole-archive -lrt -lm -ldl -lnuma
1111
*/
1212
import "C"

0 commit comments

Comments
 (0)