@@ -45,7 +45,7 @@ import (
45
45
)
46
46
47
47
var openFlowsNumber = uint32 (0 )
48
- var createdPorts [] port
48
+ var createdPorts map [ uint16 ]( * port )
49
49
var portPair map [types.IPv4Address ](* port )
50
50
var schedState * scheduler
51
51
var vEach [10 ][vBurstSize ]uint8
@@ -725,14 +725,19 @@ func SystemInit(args *Config) error {
725
725
return err
726
726
}
727
727
// 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
+
731
735
if maxInIndex > low .CheckPortRSS (createdPorts [i ].port ) {
732
736
createdPorts [i ].InIndex = low .CheckPortRSS (createdPorts [i ].port )
733
737
} else {
734
738
createdPorts [i ].InIndex = maxInIndex
735
739
}
740
+ i = low .GetNextPort (i + 1 )
736
741
}
737
742
portPair = make (map [types.IPv4Address ](* port ))
738
743
ioDevices = make (map [string ]interface {})
@@ -886,17 +891,18 @@ func SetReceiverFile(filename string, repcount int32) (OUT *Flow) {
886
891
// Receive queue will be added to port automatically.
887
892
// Returns new opened flow with received packets
888
893
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 )
891
897
}
892
- if createdPorts [ portId ] .willReceive {
898
+ if port .willReceive {
893
899
return nil , common .WrapWithNFError (nil , "Requested receive port was already set to receive. Two receives from one port are prohibited." , common .MultipleReceivePort )
894
900
}
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
900
906
}
901
907
902
908
// SetReceiverOS adds function receive from Linux interface to flow graph.
@@ -1045,11 +1051,14 @@ func SetSender(IN *Flow, portId uint16) error {
1045
1051
if err := checkFlow (IN ); err != nil {
1046
1052
return err
1047
1053
}
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 )
1050
1058
}
1051
- createdPorts [portId ].wasRequested = true
1052
- if createdPorts [portId ].sendRings == nil {
1059
+
1060
+ port .wasRequested = true
1061
+ if port .sendRings == nil {
1053
1062
// To allow consequent sends to one port, we need to create a send ring
1054
1063
// for the first, and then all the consequent sends should be merged
1055
1064
// with already created send ring.
@@ -1062,13 +1071,13 @@ func SetSender(IN *Flow, portId uint16) error {
1062
1071
max = createdPorts [i ].InIndex
1063
1072
}
1064
1073
}
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 )
1067
1076
}
1068
1077
// For a typical 40 GB card, like Intel 710 series, one core should be able
1069
1078
// to handle all the TX without problems. So we merged all income flows to created
1070
1079
// ring which will be send.
1071
- mergeOneFlow (IN , createdPorts [ portId ] .sendRings )
1080
+ mergeOneFlow (IN , port .sendRings )
1072
1081
return nil
1073
1082
}
1074
1083
@@ -1312,7 +1321,7 @@ func GetNameByPort(port uint16) (string, error) {
1312
1321
func SetIPForPort (port uint16 , ip types.IPv4Address ) error {
1313
1322
for i := range createdPorts {
1314
1323
if createdPorts [i ].port == port && createdPorts [i ].wasRequested {
1315
- portPair [ip ] = & createdPorts [i ]
1324
+ portPair [ip ] = createdPorts [i ]
1316
1325
return nil
1317
1326
}
1318
1327
}
@@ -1554,7 +1563,7 @@ func recvXDP(parameters interface{}, inIndex []int32, flag *int32, coreID int) {
1554
1563
func processKNI (parameters interface {}, inIndex []int32 , flag * int32 , coreID int ) {
1555
1564
srk := parameters .(* KNIParameters )
1556
1565
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
1558
1567
}
1559
1568
low .SrKNI (uint16 (srk .port .PortId ), flag , coreID , srk .recv , srk .out , srk .send , srk .in , & srk .stats )
1560
1569
}
0 commit comments