Skip to content

Commit

Permalink
Support parsing and status publishing for the new cellular APIs
Browse files Browse the repository at this point in the history
This is a first part in a series of commits implementing the new
cellular APIs in EVE. All parts together will provide many new
features for cellular connectivity, such as support for user
credentials, multiple modems, multiple SIM slots, switching between
5G/4G/3G, and much more.

Part I changelog:
* added support for parsing and status publishing for the new cellular
  APIs into zedagent
* extended JSON structs used to move config and status between NIM and
  wwan microservice to accommodate newly introduced attributes
* NIM and wwan microservice for now work only in the backward-compatible
  mode. Support for the new APIs will be added into these microservices
  in the next parts of this commit/PR series.
* added support for device models where cellular modems are referenced
  by USB or PCI address, not by interface name. Multiple modems can be
  initialized in different order on each boot, meaning that interface
  naming is not stable and therefore not suitable for modem
  identification.
* added publishing of port MTU. This is for every port, not just wwan.
  However, especially for wwan interfaces this is useful because MTU
  config comes from the networt and it can vary quite a bit.
* in DeviceNetworkStatus (DNS), errors collect from verification take
  precedence over whatever failures are detected when DNS is composed.
  For cellular connectivity, this ensures that we will not overwrite
  errors reported by the wwan microservice, which are much more useful
  than whatever NIM would report from its viewpoint.
* moved ip utils and generics to sub-packages of pillar/utils so that
  they can be used from pillar/types without circular dependencies
  (used them for methods of wwan structures)
* moved wwan types from zedroutertypes.go to a separate file wwan.go
  (these types are not used by zedrouter)

Signed-off-by: Milan Lenco <milan@zededa.com>
  • Loading branch information
milan-zededa committed Jul 21, 2023
1 parent 36ab7db commit ee339bb
Show file tree
Hide file tree
Showing 39 changed files with 1,426 additions and 856 deletions.
69 changes: 9 additions & 60 deletions pkg/pillar/cmd/zedagent/handlemetrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"github.com/lf-edge/eve/pkg/pillar/utils"
"github.com/lf-edge/eve/pkg/pillar/vault"
"github.com/lf-edge/eve/pkg/pillar/zedcloud"
uuid "github.com/satori/go.uuid"
"github.com/shirou/gopsutil/host"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/timestamppb"
Expand Down Expand Up @@ -343,18 +342,16 @@ func publishMetrics(ctx *zedagentContext, iteration int) {

// Use the network metrics from zedrouter subscription
// Only report stats for the ports in DeviceNetworkStatus
labelList := types.ReportLogicallabels(*deviceNetworkStatus)
for _, label := range labelList {
for _, p := range deviceNetworkStatus.Ports {
var metric *types.NetworkMetric
ports := deviceNetworkStatus.GetPortsByLogicallabel(label)
if len(ports) == 0 {
continue
}
p := ports[0]
if !p.IsL3Port {
// metrics for ports from lower layers are not reported
continue
}
if p.IfName == "" {
// Cannot associate metrics with the port until interface name is known.
continue
}
for _, m := range networkMetrics.MetricList {
if p.IfName == m.IfName {
metric = &m
Expand All @@ -366,7 +363,7 @@ func publishMetrics(ctx *zedagentContext, iteration int) {
}
networkDetails := new(metrics.NetworkMetric)
networkDetails.LocalName = metric.IfName
networkDetails.IName = label
networkDetails.IName = p.Logicallabel
networkDetails.Alias = p.Alias
networkDetails.TxPkts = metric.TxPkts
networkDetails.RxPkts = metric.RxPkts
Expand Down Expand Up @@ -1033,55 +1030,6 @@ func encodeProxyStatus(proxyConfig *types.ProxyConfig) *info.ProxyStatus {
return status
}

func encodeNetworkPortConfig(ctx *zedagentContext,
npc *types.NetworkPortConfig) *info.DevicePort {
aa := ctx.assignableAdapters

dp := new(info.DevicePort)
dp.Ifname = npc.IfName
// XXX rename the protobuf field Name to Logicallabel and add Phylabel?
dp.Name = npc.Logicallabel
// XXX Add Alias in proto file?
// dp.Alias = npc.Alias

ibPtr := aa.LookupIoBundlePhylabel(npc.Phylabel)
if ibPtr != nil {
dp.Usage = evecommon.PhyIoMemberUsage(ibPtr.Usage)
}

dp.IsMgmt = npc.IsMgmt
dp.Cost = uint32(npc.Cost)
dp.Free = npc.Cost == 0 // To be deprecated
// DhcpConfig
dp.DhcpType = uint32(npc.Dhcp)
dp.Subnet = npc.AddrSubnet

dp.DefaultRouters = make([]string, 0)
dp.DefaultRouters = append(dp.DefaultRouters, npc.Gateway.String())

dp.NtpServer = npc.NtpServer.String()

dp.Dns = new(info.ZInfoDNS)
dp.Dns.DNSdomain = npc.DomainName
dp.Dns.DNSservers = make([]string, 0)
for _, d := range npc.DnsServers {
dp.Dns.DNSservers = append(dp.Dns.DNSservers, d.String())
}
// XXX Not in definition. Remove?
// XXX string dhcpRangeLow = 17;
// XXX string dhcpRangeHigh = 18;

dp.Proxy = encodeProxyStatus(&npc.ProxyConfig)

dp.Err = encodeTestResults(npc.TestResults)

var nilUUID uuid.UUID
if npc.NetworkUUID != nilUUID {
dp.NetworkUUID = npc.NetworkUUID.String()
}
return dp
}

// This function is called per change, hence needs to try over all management ports
// When aiStatus is nil it means a delete and we send a message
// containing only the UUID to inform zedcloud about the delete.
Expand Down Expand Up @@ -1175,8 +1123,9 @@ func PublishAppInfoToZedCloud(ctx *zedagentContext, uuid string,
if niStatus != nil {
networkInfo.NtpServers = []string{}
if niStatus.NtpServer != nil {
networkInfo.NtpServers = append(networkInfo.NtpServers, niStatus.NtpServer.String())
} else {
networkInfo.NtpServers = append(networkInfo.NtpServers,
niStatus.NtpServer.String())
} else if niStatus.SelectedUplinkIntfName != "" {
ntpServers := types.GetNTPServers(*deviceNetworkStatus,
niStatus.SelectedUplinkIntfName)
for _, server := range ntpServers {
Expand Down
Loading

0 comments on commit ee339bb

Please sign in to comment.