Skip to content

Commit

Permalink
Add support for IPv6 network setting
Browse files Browse the repository at this point in the history
Add IPv6 setting in network setting page.
- Add IPv6 domain name, DNS servers, NTP servers enable/disable
- Add DHCPv6 enable/disable
- Add IPv6 default gateway
- Add IPv6 addresses
- Add IPv6 static addresses
- Add IPv6 static addresses adding and deleting

Tested:
- IPv6 domain name, DNS servers, NTP servers enable/disable function
- DHCPv6 enable/disable function
- Verified the IPv6 default gateway
- IPv6 addresses adding and deleting
- Verified the IPv6 addresses in IPv6 table

Change-Id: I9eebf6ef5f7de748f79779d8168b8dcfcdda2495
Signed-off-by: Sean Zhang <xiazhang@nvidia.com>
  • Loading branch information
seanzhangseu committed Jul 6, 2024
1 parent 8841b7d commit db47b7e
Show file tree
Hide file tree
Showing 7 changed files with 859 additions and 30 deletions.
11 changes: 11 additions & 0 deletions src/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -703,16 +703,21 @@
},
"pageNetwork": {
"dhcp": "DHCP",
"dhcp6": "DHCPv6",
"domainName": "domain name",
"dns": "DNS server",
"fqdn": "FQDN",
"hostname": "Hostname",
"ipVersion": "Version of IP",
"interfaceSection": "Interface settings",
"ipv4": "IPv4",
"ipv4Addresses": "IPv4 addresses",
"ipv6": "IPv6",
"ipv6Addresses": "IPv6 addresses",
"linkStatus": "Link status",
"macAddress": "MAC address",
"gateway": "Gateway",
"ipv6DefaultGateway": "IPv6 Default Gateway",
"network": "network",
"networkSettings": "Network settings",
"ntp": "NTP server",
Expand All @@ -728,19 +733,25 @@
"dhcpConfirmTitle": "%{dhcpState} DHCP",
"editHostnameTitle": "Edit hostname",
"editMacAddressTitle": "Edit MAC address",
"editIPv6DefaultGatewayTitle": "Edit IPv6 Default Gateway",
"gateway": "Gateway",
"prefixLength": "Prefix Length",
"ipAddress": "IP address",
"staticDns": "Static DNS",
"subnetMask": "Subnet mask"
},
"table": {
"addDnsAddress": "Add IP address",
"addIpv4Address": "Add static IPv4 address",
"addIpv6Address": "Add static IPv6 address",
"addressOrigin": "Address origin",
"prefixLength": "Prefix Length",
"deleteDns": "Delete DNS address",
"deleteIpv4": "Delete IPv4 address",
"deleteIpv6": "Delete IPv6 address",
"editDns": "Edit DNS address",
"editIpv4": "Edit IPv4 address",
"editIpv6": "Edit IPv6 address",
"gateway": "Gateway",
"ipAddress": "IP address",
"subnet": "Subnet mask"
Expand Down
172 changes: 151 additions & 21 deletions src/store/modules/Settings/NetworkStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,47 @@ const NetworkStore = {
state.globalNetworkSettings = data.map(({ data }) => {
const {
DHCPv4,
DHCPv6,
HostName,
IPv4Addresses,
IPv4StaticAddresses,
IPv6Addresses,
IPv6StaticAddresses,
LinkStatus,
MACAddress,
IPv6DefaultGateway,
} = data;
return {
defaultGateway: IPv4StaticAddresses[0]?.Gateway, //First static gateway is the default gateway
ipv6DefaultGateway: IPv6DefaultGateway,
dhcpAddress: IPv4Addresses.filter(
(ipv4) => ipv4.AddressOrigin === 'DHCP',
),
dhcpv6Address: IPv6Addresses.filter(
(ipv6) =>
ipv6.AddressOrigin === 'SLAAC' || ipv6.AddressOrigin === 'DHCPv6',
),
dhcpEnabled: DHCPv4.DHCPEnabled,
dhcp6Enabled: DHCPv6.OperatingMode,
hostname: HostName,
macAddress: MACAddress,
linkStatus: LinkStatus,
staticAddress: IPv4StaticAddresses[0]?.Address, // Display first static address on overview page
ipv6StaticAddress: IPv6StaticAddresses[0]?.Address,
useDnsEnabled: DHCPv4.UseDNSServers,
useDomainNameEnabled: DHCPv4.UseDomainName,
useNtpEnabled: DHCPv4.UseNTPServers,
useDnsEnabledIpv6: DHCPv6.UseDNSServers,
useDomainNameEnabledIpv6: DHCPv6.UseDomainName,
useNtpEnabledIpv6: DHCPv6.UseNTPServers,
};
});
},
setNtpState: (state, ntpState) => (state.ntpState = ntpState),
setDomainNameStateIpv6: (state, domainState) =>
(state.domainStateIpv6 = domainState),
setDnsStateIpv6: (state, dnsState) => (state.dnsStateIpv6 = dnsState),
setNtpStateIpv6: (state, ntpState) => (state.ntpStateIpv6 = ntpState),
setSelectedInterfaceId: (state, selectedInterfaceId) =>
(state.selectedInterfaceId = selectedInterfaceId),
setSelectedInterfaceIndex: (state, selectedInterfaceIndex) =>
Expand Down Expand Up @@ -114,13 +132,49 @@ const NetworkStore = {
);
});
},
async saveDomainNameState({ commit, state }, domainState) {
commit('setDomainNameState', domainState);
async saveDhcp6EnabledState({ state, dispatch }, dhcpState) {
const data = {
DHCPv4: {
UseDomainName: domainState,
DHCPv6: {
OperatingMode: dhcpState ? 'Enabled' : 'Disabled',
},
};
return api
.patch(
`${await this.dispatch('global/getBmcPath')}/EthernetInterfaces/${state.selectedInterfaceId}`,
data,
)
.then(dispatch('getEthernetData'))
.then(() => {
return i18n.t('pageNetwork.toast.successSaveNetworkSettings', {
setting: i18n.t('pageNetwork.dhcp6'),
});
})
.catch((error) => {
console.log(error);
throw new Error(
i18n.t('pageNetwork.toast.errorSaveNetworkSettings', {
setting: i18n.t('pageNetwork.dhcp6'),
}),
);
});
},
async saveDomainNameState({ commit, state }, { domainState, ipVersion }) {
var data;
if (ipVersion === 'IPv4') {
commit('setDomainNameState', domainState);
data = {
DHCPv4: {
UseDomainName: domainState,
},
};
} else if (ipVersion === 'IPv6') {
commit('setDomainNameStateIpv6', domainState);
data = {
DHCPv6: {
UseDomainName: domainState,
},
};
}
// Saving to the first interface automatically updates DHCPv4 and DHCPv6
// on all interfaces
return api
Expand All @@ -135,21 +189,33 @@ const NetworkStore = {
})
.catch((error) => {
console.log(error);
commit('setDomainNameState', !domainState);
if (ipVersion === 'IPv4') commit('setDomainNameState', !domainState);
else if (ipVersion === 'IPv6')
commit('setDomainNameStateIpv6', !domainState);
throw new Error(
i18n.t('pageNetwork.toast.errorSaveNetworkSettings', {
setting: i18n.t('pageNetwork.domainName'),
}),
);
});
},
async saveDnsState({ commit, state }, dnsState) {
commit('setDnsState', dnsState);
const data = {
DHCPv4: {
UseDNSServers: dnsState,
},
};
async saveDnsState({ commit, state }, { dnsState, ipVersion }) {
var data;
if (ipVersion === 'IPv4') {
commit('setDnsState', dnsState);
data = {
DHCPv4: {
UseDNSServers: dnsState,
},
};
} else if (ipVersion === 'IPv6') {
commit('setDnsStateIpv6', dnsState);
data = {
DHCPv6: {
UseDNSServers: dnsState,
},
};
}
// Saving to the first interface automatically updates DHCPv4 and DHCPv6
// on all interfaces
return api
Expand All @@ -164,21 +230,32 @@ const NetworkStore = {
})
.catch((error) => {
console.log(error);
commit('setDnsState', !dnsState);
if (ipVersion === 'IPv4') commit('setDnsState', !dnsState);
else if (ipVersion === 'IPv6') commit('setDnsStateIpv6', !dnsState);
throw new Error(
i18n.t('pageNetwork.toast.errorSaveNetworkSettings', {
setting: i18n.t('pageNetwork.dns'),
}),
);
});
},
async saveNtpState({ commit, state }, ntpState) {
commit('setNtpState', ntpState);
const data = {
DHCPv4: {
UseNTPServers: ntpState,
},
};
async saveNtpState({ commit, state }, { ntpState, ipVersion }) {
var data;
if (ipVersion === 'IPv4') {
commit('setNtpState', ntpState);
data = {
DHCPv4: {
UseNTPServers: ntpState,
},
};
} else if (ipVersion === 'IPv6') {
commit('setNtpStateIpv6', ntpState);
data = {
DHCPv6: {
UseNTPServers: ntpState,
},
};
}
// Saving to the first interface automatically updates DHCPv4 and DHCPv6
// on all interfaces
return api
Expand All @@ -193,7 +270,8 @@ const NetworkStore = {
})
.catch((error) => {
console.log(error);
commit('setNtpState', !ntpState);
if (ipVersion === 'IPv4') commit('setNtpState', !ntpState);
else if (ipVersion === 'IPv6') commit('setNtpStateIpv6', !ntpState);
throw new Error(
i18n.t('pageNetwork.toast.errorSaveNetworkSettings', {
setting: i18n.t('pageNetwork.ntp'),
Expand Down Expand Up @@ -239,6 +317,37 @@ const NetworkStore = {
);
});
},
async saveIpv6Address({ dispatch, state }, ipv6Form) {
const originalAddresses = state.ethernetData[
state.selectedInterfaceIndex
].IPv6StaticAddresses.map((ipv6) => {
const { Address, PrefixLength } = ipv6;
return {
Address,
PrefixLength,
};
});
const newAddress = [ipv6Form];
return api
.patch(
`${await this.dispatch('global/getBmcPath')}/EthernetInterfaces/${state.selectedInterfaceId}`,
{ IPv6StaticAddresses: originalAddresses.concat(newAddress) },
)
.then(dispatch('getEthernetData'))
.then(() => {
return i18n.t('pageNetwork.toast.successSaveNetworkSettings', {
setting: i18n.t('pageNetwork.ipv6'),
});
})
.catch((error) => {
console.log(error);
throw new Error(
i18n.t('pageNetwork.toast.errorSaveNetworkSettings', {
setting: i18n.t('pageNetwork.ipv6'),
}),
);
});
},
async editIpv4Address({ dispatch, state }, ipv4TableData) {
return api
.patch(
Expand All @@ -260,6 +369,27 @@ const NetworkStore = {
);
});
},
async editIpv6Address({ dispatch, state }, ipv6TableData) {
return api
.patch(
`${await this.dispatch('global/getBmcPath')}/EthernetInterfaces/${state.selectedInterfaceId}`,
{ IPv6StaticAddresses: ipv6TableData },
)
.then(dispatch('getEthernetData'))
.then(() => {
return i18n.t('pageNetwork.toast.successSaveNetworkSettings', {
setting: i18n.t('pageNetwork.ipv6'),
});
})
.catch((error) => {
console.log(error);
throw new Error(
i18n.t('pageNetwork.toast.errorSaveNetworkSettings', {
setting: i18n.t('pageNetwork.ipv6'),
}),
);
});
},
async saveSettings({ state, dispatch }, interfaceSettingsForm) {
return api
.patch(
Expand Down
Loading

0 comments on commit db47b7e

Please sign in to comment.