Skip to content

Commit

Permalink
ncm-network: nmstate: support ib interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
stdweird committed Mar 19, 2024
1 parent c35a1dc commit 659a179
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 3 deletions.
18 changes: 16 additions & 2 deletions ncm-network/src/main/perl/nmstate.pm
Original file line number Diff line number Diff line change
Expand Up @@ -355,15 +355,29 @@ sub generate_nmstate_config
# this will be empty if the interface isnt a bond interface.
# we can use this to determine if this interface is bond interface.
my $bonded_eth = get_bonded_eth($self, $name, $net->{interfaces});
if ($is_eth) {

my $vlan_id = $self->find_vlan_id($name, $iface->{device});

if (lc($iface->{type} || '') eq 'infiniband') {
$ifaceconfig->{type} = "infiniband";
my $ib = {};
my $pkey = $vlan_id || 65535;
if ($vlan_id) {
my $ibdev = $name;
$ibdev =~ s/\.\d+$//;
$ib->{'base-iface'} = $ibdev;
};
$ib->{pkey} = "0x" . sprintf("%04x", $pkey);
$ib->{mode} = 'datagram'; # TODO: add connected mode, but who still uses that
$ifaceconfig->{infiniband} = $ib;
} elsif ($is_eth) {
$ifaceconfig->{type} = "ethernet";
if ($is_partof_bond) {
# no ipv4 address for bonded eth, plus in nmstate bonded eth is controlled by controller. no config is required.
$ifaceconfig->{ipv4}->{enabled} = "false";
$ifaceconfig->{state} = "up";
}
} elsif ($is_vlan_eth) {
my $vlan_id = $self->find_vlan_id($name, $iface->{device});
# if vlan_id is empty, error
if (! $vlan_id) {
$self->error("Could not find vlan id for vlan device $name");
Expand Down
55 changes: 55 additions & 0 deletions ncm-network/src/test/perl/nmstate_advance.t
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,53 @@ routes:
EOF


Readonly my $IB_YML => <<EOF;
# File generated by NCM::Component::nmstate. Do not edit
---
interfaces:
- infiniband:
mode: datagram
pkey: 0xffff
ipv4:
address:
- ip: 10.11.12.13
prefix-length: 24
dhcp: false
enabled: true
name: ib0
profile-name: ib0
state: up
type: infiniband
routes:
config:
- next-hop-interface: ib0
state: absent
EOF

Readonly my $IBPKEY_YML => <<EOF;
# File generated by NCM::Component::nmstate. Do not edit
---
interfaces:
- infiniband:
base-iface: ib1
mode: datagram
pkey: 0x3039
ipv4:
address:
- ip: 10.11.15.13
prefix-length: 24
dhcp: false
enabled: true
name: ib1.12345
profile-name: ib1.12345
state: up
type: infiniband
routes:
config:
- next-hop-interface: ib1.12345
state: absent
EOF

Readonly my $RT => <<EOF;
#
# reserved values
Expand Down Expand Up @@ -218,4 +265,12 @@ is($vlanyml, $VLAN_YML, "Exact eth0.123 vlan yml config");

my $vlanyml2 = get_file_contents("/etc/nmstate/vlan0.yml");
is($vlanyml2, $VLAN0_YML, "Exact vlan0 yml config");

my $ibyml = get_file_contents("/etc/nmstate/ib0.yml");
is($ibyml, $IB_YML, "Exact ib0 yml config");

my $ibpkyml = get_file_contents("/etc/nmstate/ib1.12345.yml");
is($ibpkyml, $IBPKEY_YML, "Exact ib1 pkey yml config");


done_testing();
17 changes: 16 additions & 1 deletion ncm-network/src/test/resources/nmstate_advance.pan
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
object template nmstate_advance;

variable QUATTOR_TYPES_NETWORK_LEGACY = false;

include 'simple_base_profile';
include 'components/network/config-nmstate';

Expand Down Expand Up @@ -39,4 +41,17 @@ prefix "/system/network/interfaces/eth0.123";
prefix "/system/network/interfaces/vlan0";
"device" = "eth0.123";
"physdev" = "eth0";
"route/0" = dict("address", "1.2.3.4");
"route/0" = dict("address", "1.2.3.4");

# test ib interface (default and with pkey)
prefix "/system/network/interfaces/ib0";
"ip" = "10.11.12.13";
"netmask" = "255.255.255.0";
"broadcast" = "10.11.12.255";
"type" = "Infiniband";

prefix "/system/network/interfaces/ib1.12345";
"ip" = "10.11.15.13";
"netmask" = "255.255.255.0";
"broadcast" = "10.11.15.255";
"type" = "Infiniband";

0 comments on commit 659a179

Please sign in to comment.