Skip to content

Commit

Permalink
Update pillar to accommodate wwan microservice written in Go
Browse files Browse the repository at this point in the history
As we transition from the shell script managing cellular modems using
QMI/MBIM CLI tools to a proper EVE microservice, written in Go and using
pubsub for input/output, there are some changes that have to be done
across pillar to accomodate this new microservice.

Signed-off-by: Milan Lenco <milan@zededa.com>
  • Loading branch information
milan-zededa committed Oct 11, 2023
1 parent 90115dc commit 1793002
Show file tree
Hide file tree
Showing 23 changed files with 491 additions and 967 deletions.
37 changes: 20 additions & 17 deletions pkg/edgeview/src/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -1237,33 +1237,36 @@ func runWireless() {
}

printTitle("\n wwan config", colorCYAN, false)
retbytes, err = os.ReadFile("/run/wwan/config.json")
if err != nil {
return
}
var wwancfg types.WwanConfig
err = json.Unmarshal(retbytes, &wwancfg)
if err != nil {
return
retbytes, err = os.ReadFile("/run/nim/WwanConfig/global.json")
if err == nil {
var wwanConfig types.WwanConfig
err = json.Unmarshal(retbytes, &wwanConfig)
if err != nil {
return
}
fmt.Printf("%+v\n", wwanConfig)
}
fmt.Printf("%+v\n", wwancfg)

printTitle("\n wwan metrics", colorCYAN, false)
retbytes, err = os.ReadFile("/run/wwan/metrics.json")
retbytes, err = os.ReadFile("/run/wwan/WwanMetrics/global.json")
if err == nil {
prettyJSON, err := formatJSON(retbytes)
if err == nil {
fmt.Println(string(prettyJSON))
var wwanMetrics types.WwanMetrics
err = json.Unmarshal(retbytes, &wwanMetrics)
if err != nil {
return
}
fmt.Printf("%+v\n", wwanMetrics)
}

printTitle("\n wwan status", colorCYAN, false)
retbytes, err = os.ReadFile("/run/wwan/status.json")
retbytes, err = os.ReadFile("/run/wwan/WwanStatus/global.json")
if err == nil {
prettyJSON, err := formatJSON(retbytes)
if err == nil {
fmt.Println(string(prettyJSON))
var wwanStatus types.WwanStatus
err = json.Unmarshal(retbytes, &wwanStatus)
if err != nil {
return
}
fmt.Printf("%+v\n", wwanStatus)
}
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/pillar/base/logobjecttypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ const (
NetworkInstanceMetricsLogType LogObjectType = "network_instance_metrics"
// NetworkMetricsLogType:
NetworkMetricsLogType LogObjectType = "network_metrics"
// WwanConfigLogType:
WwanConfigLogType LogObjectType = "wwan_config"
// WwanStatusLogType:
WwanStatusLogType LogObjectType = "wwan_status"
// WwanMetricsLogType:
WwanMetricsLogType LogObjectType = "wwan_metrics"
// WwanLocationInfoLogType:
Expand Down
73 changes: 42 additions & 31 deletions pkg/pillar/cmd/nim/nim.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ type nim struct {
subZedAgentStatus pubsub.Subscription
subAssignableAdapters pubsub.Subscription
subOnboardStatus pubsub.Subscription
subWwanStatus pubsub.Subscription

// Publications
pubDummyDevicePortConfig pubsub.Publication // For logging
Expand All @@ -97,10 +98,8 @@ type nim struct {
pubDeviceNetworkStatus pubsub.Publication
pubZedcloudMetrics pubsub.Publication
pubCipherMetrics pubsub.Publication
pubWwanStatus pubsub.Publication
pubWwanMetrics pubsub.Publication
pubWwanLocationInfo pubsub.Publication
pubCachedResolvedIPs pubsub.Publication
pubWwanConfig pubsub.Publication

// Metrics
zedcloudMetrics *zedcloud.AgentMetrics
Expand Down Expand Up @@ -181,6 +180,7 @@ func (n *nim) init() (err error) {
SubControllerCert: n.subControllerCert,
SubEdgeNodeCert: n.subEdgeNodeCert,
PubCipherBlockStatus: n.pubCipherBlockStatus,
PubWwanConfig: n.pubWwanConfig,
CipherMetrics: n.cipherMetrics,
HVTypeKube: base.IsHVTypeKube(),
}
Expand All @@ -194,9 +194,6 @@ func (n *nim) init() (err error) {
PubDummyDevicePortConfig: n.pubDummyDevicePortConfig,
PubDevicePortConfigList: n.pubDevicePortConfigList,
PubDeviceNetworkStatus: n.pubDeviceNetworkStatus,
PubWwanStatus: n.pubWwanStatus,
PubWwanMetrics: n.pubWwanMetrics,
PubWwanLocationInfo: n.pubWwanLocationInfo,
ZedcloudMetrics: n.zedcloudMetrics,
}
return nil
Expand Down Expand Up @@ -315,6 +312,9 @@ func (n *nim) run(ctx context.Context) (err error) {
if err = n.subAssignableAdapters.Activate(); err != nil {
return err
}
if err = n.subWwanStatus.Activate(); err != nil {
return err
}
go n.runResolverCacheForController()
return nil
}
Expand Down Expand Up @@ -369,6 +369,9 @@ func (n *nim) run(ctx context.Context) (err error) {
case change := <-n.subOnboardStatus.MsgChan():
n.subOnboardStatus.ProcessChange(change)

case change := <-n.subWwanStatus.MsgChan():
n.subWwanStatus.ProcessChange(change)

case event := <-netEvents:
ifChange, isIfChange := event.(netmonitor.IfChange)
if isIfChange {
Expand Down Expand Up @@ -489,38 +492,19 @@ func (n *nim) initPublications() (err error) {
return err
}

n.pubWwanStatus, err = n.PubSub.NewPublication(
pubsub.PublicationOptions{
AgentName: agentName,
TopicType: types.WwanStatus{},
})
if err != nil {
return err
}

n.pubWwanMetrics, err = n.PubSub.NewPublication(
pubsub.PublicationOptions{
AgentName: agentName,
TopicType: types.WwanMetrics{},
})
if err != nil {
return err
}

n.pubWwanLocationInfo, err = n.PubSub.NewPublication(
n.pubCachedResolvedIPs, err = n.PubSub.NewPublication(
pubsub.PublicationOptions{
AgentName: agentName,
TopicType: types.WwanLocationInfo{},
TopicType: types.CachedResolvedIPs{},
})
if err != nil {
return err
}

n.pubCachedResolvedIPs, err = n.PubSub.NewPublication(
pubsub.PublicationOptions{
AgentName: agentName,
TopicType: types.CachedResolvedIPs{},
})
n.pubWwanConfig, err = n.PubSub.NewPublication(pubsub.PublicationOptions{
AgentName: agentName,
TopicType: types.WwanConfig{},
})
if err != nil {
return err
}
Expand Down Expand Up @@ -669,6 +653,20 @@ func (n *nim) initSubscriptions() (err error) {
if err != nil {
return err
}

n.subWwanStatus, err = n.PubSub.NewSubscription(pubsub.SubscriptionOptions{
AgentName: "wwan",
MyAgentName: agentName,
TopicImpl: types.WwanStatus{},
Activate: false,
CreateHandler: n.handleWwanStatusCreate,
ModifyHandler: n.handleWwanStatusModify,
WarningTime: warningTime,
ErrorTime: errorTime,
})
if err != nil {
return err
}
return nil
}

Expand Down Expand Up @@ -834,6 +832,19 @@ func (n *nim) handleOnboardStatusImpl(_ string, statusArg interface{}) {
n.dpcManager.UpdateDevUUID(status.DeviceUUID)
}

func (n *nim) handleWwanStatusCreate(_ interface{}, key string, statusArg interface{}) {
n.handleWwanStatusImpl(key, statusArg)
}

func (n *nim) handleWwanStatusModify(_ interface{}, key string, statusArg, _ interface{}) {
n.handleWwanStatusImpl(key, statusArg)
}

func (n *nim) handleWwanStatusImpl(_ string, statusArg interface{}) {
status := statusArg.(types.WwanStatus)
n.dpcManager.ProcessWwanStatus(status)
}

func (n *nim) isDeviceOnboarded() bool {
obj, err := n.subOnboardStatus.Get("global")
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/pillar/cmd/zedagent/handlemetrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ func publishMetrics(ctx *zedagentContext, iteration int) {
cipherMetricsDM,
cipherMetricsNim,
cipherMetricsZR,
cipherMetricsWwan,
}
for _, cm := range cipherMetrics {
log.Functionf("Cipher metrics for %s: %+v", cm.AgentName, cm)
Expand Down
28 changes: 25 additions & 3 deletions pkg/pillar/cmd/zedagent/zedagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ var cipherMetricsDL types.CipherMetrics
var cipherMetricsDM types.CipherMetrics
var cipherMetricsNim types.CipherMetrics
var cipherMetricsZR types.CipherMetrics
var cipherMetricsWwan types.CipherMetrics
var diagMetrics types.MetricsMap
var nimMetrics types.MetricsMap
var zrouterMetrics types.MetricsMap
Expand Down Expand Up @@ -153,6 +154,7 @@ type zedagentContext struct {
subCipherMetricsDM pubsub.Subscription
subCipherMetricsNim pubsub.Subscription
subCipherMetricsZR pubsub.Subscription
subCipherMetricsWwan pubsub.Subscription
zedcloudMetrics *zedcloud.AgentMetrics
fatalFlag bool // From command line arguments
hangFlag bool // From command line arguments
Expand Down Expand Up @@ -960,6 +962,15 @@ func mainEventLoop(zedagentCtx *zedagentContext, stillRunning *time.Ticker) {
cipherMetricsZR = m.(types.CipherMetrics)
}

case change := <-zedagentCtx.subCipherMetricsWwan.MsgChan():
zedagentCtx.subCipherMetricsWwan.ProcessChange(change)
m, err := zedagentCtx.subCipherMetricsWwan.Get("global")
if err != nil {
log.Errorf("subCipherMetricsWwan.Get failed: %s", err)
} else {
cipherMetricsWwan = m.(types.CipherMetrics)
}

case change := <-zedagentCtx.subNetworkInstanceStatus.MsgChan():
zedagentCtx.subNetworkInstanceStatus.ProcessChange(change)

Expand Down Expand Up @@ -1701,7 +1712,7 @@ func initPostOnboardSubs(zedagentCtx *zedagentContext) {
// Cellular modems used by configured network ports have status published
// as part of DeviceNetworkStatus.
zedagentCtx.subWwanStatus, err = ps.NewSubscription(pubsub.SubscriptionOptions{
AgentName: "nim",
AgentName: "wwan",
MyAgentName: agentName,
TopicImpl: types.WwanStatus{},
Activate: true,
Expand All @@ -1714,7 +1725,7 @@ func initPostOnboardSubs(zedagentCtx *zedagentContext) {
}

zedagentCtx.subWwanMetrics, err = ps.NewSubscription(pubsub.SubscriptionOptions{
AgentName: "nim",
AgentName: "wwan",
MyAgentName: agentName,
TopicImpl: types.WwanMetrics{},
Activate: true,
Expand All @@ -1727,7 +1738,7 @@ func initPostOnboardSubs(zedagentCtx *zedagentContext) {
}

zedagentCtx.subLocationInfo, err = ps.NewSubscription(pubsub.SubscriptionOptions{
AgentName: "nim",
AgentName: "wwan",
MyAgentName: agentName,
TopicImpl: types.WwanLocationInfo{},
Activate: true,
Expand Down Expand Up @@ -1862,6 +1873,17 @@ func initPostOnboardSubs(zedagentCtx *zedagentContext) {
log.Fatal(err)
}

zedagentCtx.subCipherMetricsWwan, err = ps.NewSubscription(pubsub.SubscriptionOptions{
AgentName: "wwan",
MyAgentName: agentName,
TopicImpl: types.CipherMetrics{},
Activate: true,
Ctx: zedagentCtx,
})
if err != nil {
log.Fatal(err)
}

zedagentCtx.subZFSPoolStatus, err = ps.NewSubscription(pubsub.SubscriptionOptions{
AgentName: "zfsmanager",
MyAgentName: agentName,
Expand Down
1 change: 0 additions & 1 deletion pkg/pillar/cmd/zedrouter/metadata_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,6 @@ func (hdl wwanStatusHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
status.Networks[i].SimCards[j].Name = ""
}
}
status.ConfigChecksum = ""
resp, err := json.Marshal(status)
if err != nil {
msg := fmt.Sprintf("Failed to marshal WWAN status: %v", err)
Expand Down
8 changes: 4 additions & 4 deletions pkg/pillar/cmd/zedrouter/zedrouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ func (z *zedrouter) initSubscriptions() (err error) {

// Look for geographic location reports
z.subLocationInfo, err = z.pubSub.NewSubscription(pubsub.SubscriptionOptions{
AgentName: "nim",
AgentName: "wwan",
MyAgentName: agentName,
TopicImpl: types.WwanLocationInfo{},
Activate: false,
Expand All @@ -761,7 +761,7 @@ func (z *zedrouter) initSubscriptions() (err error) {

// Look for cellular status
z.subWwanStatus, err = z.pubSub.NewSubscription(pubsub.SubscriptionOptions{
AgentName: "nim",
AgentName: "wwan",
MyAgentName: agentName,
TopicImpl: types.WwanStatus{},
Activate: false,
Expand All @@ -774,7 +774,7 @@ func (z *zedrouter) initSubscriptions() (err error) {

// Look for cellular metrics
z.subWwanMetrics, err = z.pubSub.NewSubscription(pubsub.SubscriptionOptions{
AgentName: "nim",
AgentName: "wwan",
MyAgentName: agentName,
TopicImpl: types.WwanMetrics{},
Activate: false,
Expand Down Expand Up @@ -921,7 +921,7 @@ func (z *zedrouter) processAppConnReconcileStatus(

func (z *zedrouter) ensureDir(path string) error {
if _, err := os.Stat(path); err != nil {
z.log.Functionf("Create directory %s", runDirname)
z.log.Functionf("Create directory %s", path)
if err := os.Mkdir(path, 0755); err != nil {
return err
}
Expand Down
11 changes: 10 additions & 1 deletion pkg/pillar/devicenetwork/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,17 @@ import (
"github.com/miekg/dns"
)

const (
// DhcpcdResolvConfDir : directory where dhcpcd stores resolv.conf
// files separately for every interface (named <interface>.dhcp).
DhcpcdResolvConfDir = "/run/dhcpcd/resolv.conf"
// WwanResolvConfDir : directory where wwan microservice stores resolv.conf
// files separately for every interface (named <interface>.dhcp).
WwanResolvConfDir = "/run/wwan/resolv.conf"
)

// ResolveConfDirs : directories where resolv.conf for an interface could be found.
var ResolveConfDirs = []string{"/run/dhcpcd/resolv.conf", "/run/wwan/resolv.conf"}
var ResolveConfDirs = []string{DhcpcdResolvConfDir, WwanResolvConfDir}

const (
// DNSMaxParallelRequests is the maximum amount of parallel DNS requests
Expand Down
30 changes: 18 additions & 12 deletions pkg/pillar/devicenetwork/wwan.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,22 @@

package devicenetwork

const (
// RunWwanDir : directory where config/status/metrics are exchanged between
// nim and wwan microservice.
RunWwanDir = "/run/wwan/"
// WwanConfigPath : LTE configuration submitted by NIM to wwan microservice.
WwanConfigPath = RunWwanDir + "config.json"
// WwanStatusPath : LTE status data published by wwan microservice.
WwanStatusPath = RunWwanDir + "status.json"
// WwanMetricsPath : LTE metrics published by wwan microservice.
WwanMetricsPath = RunWwanDir + "metrics.json"
// WwanLocationPath : Location info obtained from GNSS receiver by wwan microservice.
WwanLocationPath = RunWwanDir + "location.json"
import (
"time"

"github.com/lf-edge/eve/pkg/pillar/types"
)

// GetWwanConfigTimestamp : returns timestamp to associate with WwanConfig
// generated for the given DPC and RadioSilence config.
func GetWwanConfigTimestamp(
dpc *types.DevicePortConfig, rsConfig types.RadioSilence) time.Time {
var timestamp time.Time
if dpc != nil {
timestamp = dpc.TimePriority
}
if rsConfig.ChangeRequestedAt.After(timestamp) {
timestamp = rsConfig.ChangeRequestedAt
}
return timestamp
}
Loading

0 comments on commit 1793002

Please sign in to comment.