diff --git a/README.md b/README.md index c0e9104..09d2632 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ This repository aims to promote the development of a multi-vendor management pla Run app using Docker Compose:
 user@user-laptop:~$ cd oktopus/deploy/compose
-user@user-laptop:~/oktopus/deploy/compose$ COMPOSE_PROFILES=nats,controller,mqtt,stomp,ws,adapter,frontend,portainer docker compose up -d
+user@user-laptop:~/oktopus/deploy/compose$ COMPOSE_PROFILES=nats,controller,cwmp,mqtt,stomp,ws,adapter,frontend,portainer docker compose up -d
 
Oktopus deployment in Kubernetes still is in beta phase: Instructions for Kubernetes deployment

UI will open at port 3000: diff --git a/backend/services/acs/cmd/acs/main.go b/backend/services/acs/cmd/acs/main.go index 53d9379..d192f7b 100644 --- a/backend/services/acs/cmd/acs/main.go +++ b/backend/services/acs/cmd/acs/main.go @@ -14,7 +14,7 @@ func main() { natsActions := nats.StartNatsClient(c.Nats) - h := handler.NewHandler(natsActions.Publish, natsActions.Subscribe) + h := handler.NewHandler(natsActions.Publish, natsActions.Subscribe, c.Acs) b := bridge.NewBridge( natsActions.Publish, diff --git a/backend/services/acs/internal/config/config.go b/backend/services/acs/internal/config/config.go index 9ad7d24..79b228b 100644 --- a/backend/services/acs/internal/config/config.go +++ b/backend/services/acs/internal/config/config.go @@ -6,6 +6,7 @@ import ( "log" "os" "strconv" + "time" "github.com/joho/godotenv" ) @@ -20,13 +21,15 @@ type Nats struct { } type Acs struct { - Port string - Tls bool - TlsPort bool - NoTls bool - Username string - Password string - Route string + Port string + Tls bool + TlsPort bool + NoTls bool + KeepAliveInterval time.Duration + Username string + Password string + Route string + DebugMode bool } type Config struct { @@ -44,6 +47,8 @@ func NewConfig() *Config { natsVerifyCertificates := flag.Bool("nats_verify_certificates", lookupEnvOrBool("NATS_VERIFY_CERTIFICATES", false), "verify validity of certificates from nats server") acsPort := flag.String("acs_port", lookupEnvOrString("ACS_PORT", ":9292"), "port for acs server") acsRoute := flag.String("acs_route", lookupEnvOrString("ACS_ROUTE", "/acs"), "route for acs server") + acsKeepAliveInterval := flag.Int("acs_keep_alive_interval", lookupEnvOrInt("KEEP_ALIVE_INTERVAL", 300), "keep alive interval in seconds for acs server") + cwmpDebugMode := flag.Bool("debug_mode", lookupEnvOrBool("CWMP_DEBUG", false), "enable or disable cwmp logs in debug mode") flHelp := flag.Bool("help", false, "Help") /* @@ -70,8 +75,10 @@ func NewConfig() *Config { Ctx: ctx, }, Acs: Acs{ - Port: *acsPort, - Route: *acsRoute, + Port: *acsPort, + Route: *acsRoute, + KeepAliveInterval: time.Duration(*acsKeepAliveInterval), + DebugMode: *cwmpDebugMode, }, } } @@ -99,6 +106,17 @@ func lookupEnvOrString(key string, defaultVal string) string { return defaultVal } +func lookupEnvOrInt(key string, defaultVal int) int { + if val, _ := os.LookupEnv(key); val != "" { + v, err := strconv.Atoi(val) + if err != nil { + log.Fatalf("LookupEnvOrInt[%s]: %v", key, err) + } + return v + } + return defaultVal +} + func lookupEnvOrBool(key string, defaultVal bool) bool { if val, _ := os.LookupEnv(key); val != "" { v, err := strconv.ParseBool(val) diff --git a/backend/services/acs/internal/server/handler/cwmp.go b/backend/services/acs/internal/server/handler/cwmp.go index c682353..bc8bff6 100644 --- a/backend/services/acs/internal/server/handler/cwmp.go +++ b/backend/services/acs/internal/server/handler/cwmp.go @@ -24,6 +24,10 @@ func (h *Handler) CwmpHandler(w http.ResponseWriter, r *http.Request) { tmp, _ := ioutil.ReadAll(r.Body) body := string(tmp) + if h.acsConfig.DebugMode { + log.Println("Received message: ", body) + } + var envelope cwmp.SoapEnvelope xml.Unmarshal(tmp, &envelope) diff --git a/backend/services/acs/internal/server/handler/handler.go b/backend/services/acs/internal/server/handler/handler.go index 5d1fd00..e99d60c 100644 --- a/backend/services/acs/internal/server/handler/handler.go +++ b/backend/services/acs/internal/server/handler/handler.go @@ -2,6 +2,7 @@ package handler import ( "encoding/json" + "oktopUSP/backend/services/acs/internal/config" "time" "github.com/nats-io/nats.go" @@ -53,9 +54,10 @@ type MsgCPEs struct { } type Handler struct { - pub func(string, []byte) error - sub func(string, func(*nats.Msg)) error - Cpes map[string]CPE + pub func(string, []byte) error + sub func(string, func(*nats.Msg)) error + Cpes map[string]CPE + acsConfig config.Acs } const ( @@ -64,10 +66,15 @@ const ( NATS_ADAPTER_SUBJECT_PREFIX = "adapter.v1." ) -func NewHandler(pub func(string, []byte) error, sub func(string, func(*nats.Msg)) error) *Handler { +func NewHandler( + pub func(string, []byte) error, + sub func(string, func(*nats.Msg)) error, + cAcs config.Acs, +) *Handler { return &Handler{ - pub: pub, - sub: sub, - Cpes: make(map[string]CPE), + pub: pub, + sub: sub, + Cpes: make(map[string]CPE), + acsConfig: cAcs, } } diff --git a/backend/services/acs/internal/server/handler/status.go b/backend/services/acs/internal/server/handler/status.go index ec4c7a1..8334b31 100644 --- a/backend/services/acs/internal/server/handler/status.go +++ b/backend/services/acs/internal/server/handler/status.go @@ -5,19 +5,13 @@ import ( "time" ) -// TODO: make these consts dynamic via config -const ( - CHECK_STATUS_INTERVAL = 10 * time.Second - KEEP_ALIVE_INTERVAL = 600 * time.Second -) - func (h *Handler) handleCpeStatus(cpe string) { for { - if time.Since(h.Cpes[cpe].LastConnection) > KEEP_ALIVE_INTERVAL { + if time.Since(h.Cpes[cpe].LastConnection) > h.acsConfig.KeepAliveInterval { delete(h.Cpes, cpe) break } - time.Sleep(CHECK_STATUS_INTERVAL) + time.Sleep(h.acsConfig.KeepAliveInterval) } log.Println("CPE", cpe, "is offline") h.pub("cwmp.v1."+cpe+".status", []byte("0")) diff --git a/deploy/compose/docker-compose.yaml b/deploy/compose/docker-compose.yaml index 97a5f6c..559a094 100644 --- a/deploy/compose/docker-compose.yaml +++ b/deploy/compose/docker-compose.yaml @@ -186,6 +186,7 @@ services: networks: usp_network: ipv4_address: 172.16.235.16 + profiles: [cwmp] networks: usp_network: diff --git a/frontend/src/sections/overview/overview-latest-orders.js b/frontend/src/sections/overview/overview-latest-orders.js index 7d4369f..6f85c03 100644 --- a/frontend/src/sections/overview/overview-latest-orders.js +++ b/frontend/src/sections/overview/overview-latest-orders.js @@ -97,18 +97,18 @@ export const OverviewLatestOrders = (props) => { - { - if (order.Status == 2){ - router.push("devices/"+order.SN+"/discovery") + { order.Status == 2 && (order.Mqtt == 0 && order.Websockets == 0 && order.Stomp == 0) ? : { + if (order.Status == 2){ + router.push("devices/"+order.SN+"/discovery") + } } } - } - > - - + > + + } );