Skip to content

Commit

Permalink
Improve TAP device handling for ironcore-in-a-box
Browse files Browse the repository at this point in the history
Signed-off-by: Guvenc Gulce <guevenc.guelce@sap.com>
  • Loading branch information
guvenc committed Feb 18, 2025
1 parent b6f01eb commit f18b6eb
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
26 changes: 23 additions & 3 deletions controllers/networkinterface_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,10 @@ func (r *NetworkInterfaceReconciler) reconcile(ctx context.Context, log logr.Log
log.V(1).Info("Bluefield detected. Converting PCI Bus to the host PCI bus", "PCIAddress", pciAddr)
}
if r.TapDeviceMode {
nic.Status.TAPDevice.Name = pciAddr.Device
pciAddr.Device = strings.ReplaceAll(strings.ReplaceAll(pciAddr.Device, ":", ""), ".", "")
nic.Status.TAPDevice = &metalnetv1alpha1.TAPDevice{
Name: pciAddr.Device,
}
} else {
nic.Status.PCIAddress = &metalnetv1alpha1.PCIAddress{
Bus: pciAddr.Bus,
Expand Down Expand Up @@ -1314,9 +1317,26 @@ func (r *NetworkInterfaceReconciler) applyInterface(ctx context.Context, log log
return addr, *iface.Spec.UnderlayRoute, false, nil
}

func (r *NetworkInterfaceReconciler) processTAPDeviceString(device string) (string, error) {
cleanedDevice := strings.ReplaceAll(strings.ReplaceAll(device, ":", ""), ".", "")

const prefix = "dtapvf_"
if strings.HasPrefix(cleanedDevice, prefix) {
numStr := cleanedDevice[len(prefix):]
number, err := strconv.Atoi(numStr)
if err != nil {
return "", fmt.Errorf("failed to parse device number in %q: %w", cleanedDevice, err)
}

return fmt.Sprintf("net_tap%d", number+2), nil
}

return cleanedDevice, nil
}

func (r *NetworkInterfaceReconciler) convertToDPDKDevice(addr ghw.PCIAddress) (string, error) {
if strings.Contains(addr.Device, "tap") {
return strings.ReplaceAll(strings.ReplaceAll(addr.Device, ":", ""), ".", ""), nil
if strings.Contains(addr.Device, "dtap") {
return r.processTAPDeviceString(addr.Device)
}
pciFunction, err := strconv.ParseUint(addr.Function, 8, 64)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ var _ = BeforeSuite(func() {
claimStore, err := netfns.NewFileClaimStore(filepath.Join(metalnetDir, "netfns", "claims"), true)
Expect(err).NotTo(HaveOccurred())

initAvailable, err := netfns.CollectTAPFunctions([]string{"net_tap4", "net_tap5"})
initAvailable, err := netfns.CollectTAPFunctions([]string{"dtapvf_2", "dtapvf_3"})
Expect(err).NotTo(HaveOccurred())

netFnsManager, err = netfns.NewManager(claimStore, initAvailable)
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func main() {
}
}
} else {
initAvailable, err = netfns.CollectTAPFunctions([]string{"net_tap3", "net_tap4", "net_tap5"})
initAvailable, err = netfns.CollectTAPFunctions([]string{"dtapvf_0", "dtapvf_1", "dtapvf_2", "dtapvf_3"})
if err != nil {
setupLog.Error(err, "unable to collect TAP functions")
os.Exit(1)
Expand Down
8 changes: 7 additions & 1 deletion netfns/netfns.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,13 @@ func (s *fileClaimStore) Create(uid types.UID, addr ghw.PCIAddress) error {
return ErrClaimAlreadyExists
}

data := []byte(addr.String())
var data []byte
if !s.isTAPStore {
data = []byte(addr.String())
} else {
data = []byte(addr.Device)
}

return os.WriteFile(filename, data, filePerm)
}

Expand Down

0 comments on commit f18b6eb

Please sign in to comment.