diff --git a/config/transformer/models_list b/config/transformer/models_list index 89ba79e9c..133a3bfa3 100644 --- a/config/transformer/models_list +++ b/config/transformer/models_list @@ -11,3 +11,7 @@ openconfig-if-aggregate.yang openconfig-mclag.yang openconfig-mclag-annot.yang openconfig-vlan.yang +gnsi-authz.yang +gnsi-pathz.yang +gnsi-certz.yang +gnsi-credentialz.yang diff --git a/models/yang/gnsi-authz.yang b/models/yang/gnsi-authz.yang new file mode 100644 index 000000000..cc1a3337d --- /dev/null +++ b/models/yang/gnsi-authz.yang @@ -0,0 +1,155 @@ +module gnsi-authz { + yang-version 1.1; + namespace "https://github.com/openconfig/gnsi/authz/yang"; + prefix gnsi-authz; + import openconfig-system { + prefix oc-sys; + } + import openconfig-system-grpc { + prefix oc-sys-grpc; + } + import openconfig-types { + prefix oc-types; + } + import openconfig-yang-types { + prefix oc-yang; + } + organization + "Google LLC"; + contact + "Google LLC"; + description + "This module provides a data model for the metadata of the gRPC + authorization policies installed on a networking device."; + revision 2022-10-30 { + description + "Adds success/failure counters."; + reference "0.3.0"; + } + revision 2022-08-01 { + description + "Single authz policy."; + reference "0.2.0"; + } + revision 2022-01-17 { + description + "Initial revision."; + reference "0.1.0"; + } + typedef version { + type string; + description + "The version ID of the gRPC authorization policy as provided by + the gRPC Authorization Policy Manager when the policy was pushed. + This leaf persists through a reboot."; + } + typedef created-on { + type oc-types:timeticks64; + description + "The creation time of the gRPC authorization policy as reported by + the gRPC Authorization Policy manager when the policy was pushed + to the device. This value is reported as nanoseconds since epoch + (January 1st, 1970 00:00:00 GMT). This leaf persists through + a reboot."; + } + // gRPC server authorization policy related definitions. + grouping counters { + description + "A collection of counters that were collected by the gNSI.authz + module while evaluating access to a RPC."; + leaf access-rejects { + type oc-yang:counter64; + description + "The total number of times the gNSI.authz module denied access + to a RPC."; + } + leaf last-access-reject { + type oc-types:timeticks64; + description + "A timestamp of the last time the gNSI.authz denied access to + a RPC."; + } + leaf access-accepts { + type oc-yang:counter64; + description + "The total number of times the gNSI.authz module allowed access + to a RPC."; + } + leaf last-access-accept { + type oc-types:timeticks64; + description + "A timestamp of the last time the gNSI.authz allowed access to + a RPC."; + } + } + grouping grpc-server-user-authz-policy-success-failure-counters { + description + "A collection of counters collected by the gNSI.authz module."; + container rpcs { + description + "A collection of counters collected by the gNSI.authz module + for each RPC separately."; + list rpc { + description + "A collection of counters collected by the gNSI.authz module + for a RPC identified by the `name`."; + key name; + leaf name { + type leafref { + path "../state/name"; + } + description + "The name of the RPC the counters were collected for."; + } + container state { + leaf name { + type string; + description + "The name of the RPC the counters were collected + for."; + } + uses counters; + } + } + } + } + grouping grpc-server-authz-policy-success-failure-counters { + description + "A collection of counters collected by the gNSI.authz module."; + container authz-policy-counters { + description + "A collection of counters collected by the gNSI.authz module."; + config false; + uses grpc-server-user-authz-policy-success-failure-counters; + } + } + grouping grpc-server-authz-policy-state { + description + "gNMI server's gRPC authorization policy freshness-related data."; + leaf grpc-authz-policy-version { + type version; + description + "The version of the gRPC authorization policy that is used by + this system."; + } + leaf grpc-authz-policy-created-on { + type created-on; + description + "The timestamp of the moment when the gRPC authorization policy + that is currently used by this system was created."; + } + } + // Augments section. + augment "/oc-sys:system/oc-sys:aaa/oc-sys:authorization/" + + "oc-sys:state" { + description + "A system's gRPC authorization policy freshness information."; + uses grpc-server-authz-policy-state; + } + augment "/oc-sys:system/oc-sys-grpc:grpc-servers/oc-sys-grpc:grpc-server" { + description + "Counters collected while evaluating access to a gRPC server using + the gNSI.authz authorization policy."; + uses grpc-server-authz-policy-success-failure-counters; + } +} diff --git a/models/yang/gnsi-certz.yang b/models/yang/gnsi-certz.yang new file mode 100644 index 000000000..fcc36375e --- /dev/null +++ b/models/yang/gnsi-certz.yang @@ -0,0 +1,187 @@ +module gnsi-certz { + yang-version 1.1; + namespace "https://github.com/openconfig/gnsi/certz/yang"; + prefix gnsi-certz; + + import openconfig-system { + prefix oc-sys; + } + import openconfig-system-grpc { + prefix oc-sys-grpc; + } + import openconfig-types { + prefix oc-types; + } + import openconfig-yang-types { + prefix oc-yang; + } + organization + "Google LLC"; + + contact + "Google LLC"; + + description + "This module provides a data model for the metadata of gRPC credentials + installed on a networking device."; + + revision 2023-02-13 { + description + "rename access/reject counters"; + reference "0.5.0"; + } + + revision 2023-08-24 { + description + "Adds ssl-profile-id leaf"; + reference "0.4.0"; + } + + revision 2023-05-10 { + description + "Adds authentication policy freshness information."; + reference "0.3.0"; + } + + revision 2022-10-30 { + description + "Adds success/failure counters."; + reference "0.2.0"; + } + + revision 2022-09-20 { + description + "Initial revision."; + reference "0.1.0"; + } + + typedef version { + type string; + description + "The version ID of the credential as provided by the credential + manager when the credential was pushed. This leaf persists through + a reboot."; + } + + typedef created-on { + type oc-types:timeticks64; + description + "The creation time of the credential as reported by the credential + manager when the credential was pushed to the device. This value is + reported as nanoseconds since epoch (January 1st, 1970 00:00:00 GMT). + This leaf persists through a reboot."; + } + // gRPC server related definitions. + // Success/failure counters. + grouping counters { + description + "A collection of counters that were collected while attempting + to establish connections to the gRPC server."; + + container counters { + config false; + description + "A collection of counters that were collected by the gRPC during + the authentication process."; + + leaf connection-rejects { + type oc-yang:counter64; + description + "The total number of times that gRPC clients have failed + in establishing a connection to the server."; + } + leaf last-connection-reject { + type oc-types:timeticks64; + description + "A timestamp of the last time a gRPC client failed + in establishing a connection to the server."; + } + leaf connection-accepts { + type oc-yang:counter64; + description + "The total number of times that gRPC clients have succeeded + in establishing a connection to the server."; + } + leaf last-connection-accept { + type oc-types:timeticks64; + description + "A timestamp of the last time a gRPC client succeeded + in establishing a connection to the server."; + } + } + } + + grouping grpc-server-credentials-state { + description + "gRPC server credentials freshness-related data."; + + leaf certificate-version { + type version; + description + "The version of the certificate (and associated + private key) that is used by this gRPC server."; + } + leaf certificate-created-on { + type created-on; + description + "The timestamp of the moment when the certificate + (and associated private key) that is currently used + by this gRPC server was created."; + } + leaf ca-trust-bundle-version { + type version; + description + "The version of the bundle of the Certificate + Authority certificates a.k.a. trust bundle used by + this gRPC server."; + } + leaf ca-trust-bundle-created-on { + type created-on; + description + "The timestamp of the moment when the bundle of + the Certificate Authority certificates (a.k.a. + trust bundle) was created."; + } + leaf certificate-revocation-list-bundle-version { + type version; + description + "The version of the Certificate Revocation List bundle used by + this gRPC server."; + } + leaf certificate-revocation-list-bundle-created-on { + type created-on; + description + "The timestamp of the moment when the Certificate Revocation + List bundle was created."; + } + leaf authentication-policy-version { + type version; + description + "The version of the authentication policy that is used by + this gRPC server."; + } + leaf authentication-policy-created-on { + type created-on; + description + "The timestamp of the moment when the authentication policy + that is currently used by this gRPC server was created."; + } + leaf ssl-profile-id { + type string; + description + "The ID of this gRPC server's SSL profile + as used by the gNSI Certz service"; + } + } + + // Augments section. + + augment "/oc-sys:system/oc-sys-grpc:grpc-servers/oc-sys-grpc:grpc-server/" + + "oc-sys-grpc:state" { + description + "A gRPC server credentials freshness information."; + + uses grpc-server-credentials-state; + uses counters; + } +} diff --git a/models/yang/gnsi-credentialz.yang b/models/yang/gnsi-credentialz.yang new file mode 100644 index 000000000..56f319e64 --- /dev/null +++ b/models/yang/gnsi-credentialz.yang @@ -0,0 +1,299 @@ +module gnsi-credentialz { + yang-version 1.1; + namespace "https://github.com/openconfig/gnsi/credentialz/yang"; + prefix gnsi-credz; + + import openconfig-system { + prefix oc-sys; + } + import openconfig-types { + prefix oc-types; + } + import openconfig-yang-types { + prefix oc-yang; + } + organization + "Google LLC"; + + contact + "Google LLC"; + + description + "This module provides a data model for the metadata of SSH and console + credentials installed on a networking device."; + + revision 2024-01-05 { + description + "Fix typo in YANG leaves"; + reference + "0.5.0"; + } + + revision 2023-10-03 { + description + "Added state leaves for admin-user"; + reference + "0.4.0"; + } + + revision 2023-08-18 { + description + "Fixed the canonical order of config field."; + reference + "0.3.0"; + } + + revision 2022-10-30 { + description + "Adds success/failure counters."; + reference + "0.2.0"; + } + + revision 2022-08-22 { + description + "Initial revision."; + reference + "0.1.0"; + } + + typedef version { + type string; + description + "The version ID of the credential as provided by the credential + manager when the credential was pushed. This leaf persists through + a reboot."; + } + + typedef created-on { + type oc-types:timeticks64; + description + "The creation time of the credential as reported by the credential + manager when the credential was pushed to the device. This value is + reported as nanoseconds since epoch (January 1st, 1970 00:00:00 GMT). + This leaf persists through a reboot."; + } + + // SSH server related definitions. + grouping ssh-server-credentials-version { + description + "SSH server credentials freshness-related data."; + + leaf active-trusted-user-ca-keys-version { + type version; + description + "The version of the Certificate Authority keys."; + } + + leaf active-trusted-user-ca-keys-created-on { + type created-on; + description + "The timestamp of the moment when the trusted user CA keys + were created."; + } + + leaf active-host-certificate-version { + type version; + description + "The version of the host certificate."; + } + + leaf active-host-certificate-created-on { + type created-on; + description + "The timestamp of the moment when the host certificate + was created."; + } + + leaf active-host-key-version { + type version; + description + "The version of the host public key."; + } + + leaf active-host-key-created-on { + type created-on; + description + "The timestamp of the moment when the host key was + created."; + } + } + + // Success/failure counters. + grouping counters { + description + "A collection of counters that were collected while evaluating + access to the target."; + + container counters { + config false; + description + "A collection of counters collected while authorizing users + accessing the target."; + leaf access-rejects { + type oc-yang:counter64; + description + "The total number of times access to the target has been + denied."; + } + leaf last-access-reject { + type oc-types:timeticks64; + description + "A timestamp of the last time access to the target has been + denied."; + } + leaf access-accepts { + type oc-yang:counter64; + description + "The total number of times access to the target has been + allowed."; + } + leaf last-access-accept { + type oc-types:timeticks64; + description + "A timestamp of the last time access to the target has been + allowed."; + } + } + } + + // GLOME related definitions. + + grouping glome-key-version { + description + "Version identifier for the configured GLOME key."; + + leaf active-glome-key-version { + type version; + description + "The version of the GLOME key."; + } + + leaf active-glome-key-created-on { + type created-on; + description + "The timestamp of the moment when the GLOME key + was created."; + } + } + + // System role SSH related definitions. + grouping user-ssh-credentials-version { + description + "System role credentials freshness-related data."; + + leaf authorized-principals-list-version { + type version; + description + "The version of the list of authorized principals currently + associated with this system role."; + } + + leaf authorized-principals-list-created-on { + type created-on; + description + "The timestamp of the moment the currently used list of + authorized principals has been created."; + } + + leaf authorized-keys-list-version { + type version; + description + "The version of the list of authorized keys that is currently + associated with this system role."; + } + + leaf authorized-keys-list-created-on { + type created-on; + description + "The timestamp of the moment the currently used list of + authorized keys has been created."; + } + } + + grouping console-config-state { + description + "Console-related configuration and state."; + container console { + description + "Console-related configuration and state."; + + container config { + description + "Console-related configuration."; + } + + container state { + config false; + description + "Console-related state."; + + uses counters; + + leaf enabled { + type boolean; + description + "Whether GLOME is enabled or not."; + } + } + } + } + // System role console related definitions. + grouping user-console-credentials-version { + description + "System role credentials freshness-related data."; + + leaf password-version { + type version; + description + "The version of the password that is currently used to + authenticate this user account."; + } + + leaf password-created-on { + type created-on; + description + "The timestamp of the moment the currently used password has + been created."; + } + } + + // Augments section. + augment "/oc-sys:system" { + description + "Console credentials freshness data."; + + uses console-config-state; + } + augment "/oc-sys:system/oc-sys:ssh-server/oc-sys:state" { + description + "SSH server credentials freshness data."; + + uses ssh-server-credentials-version; + uses counters; + } + augment "/oc-sys:system/oc-sys:aaa/oc-sys:authentication/oc-sys:users/" + + "oc-sys:user/oc-sys:state" { + description + "A system role credentials freshness information."; + + uses user-console-credentials-version; + uses user-ssh-credentials-version; + } + augment "/oc-sys:system/oc-sys:aaa/oc-sys:authentication/oc-sys:admin-user/" + + "oc-sys:state" { + description + "A system role credentials freshness information."; + + uses user-console-credentials-version; + uses user-ssh-credentials-version; + } + deviation "/oc-sys:system/oc-sys:aaa/oc-sys:authentication/oc-sys:users/" + + "oc-sys:user/oc-sys:config/oc-sys:ssh-key" { + deviate not-supported; + } + deviation "/oc-sys:system/oc-sys:aaa/oc-sys:authentication/oc-sys:users/" + + "oc-sys:user/oc-sys:state/oc-sys:ssh-key" { + deviate not-supported; + } +} diff --git a/models/yang/gnsi-pathz.yang b/models/yang/gnsi-pathz.yang new file mode 100644 index 000000000..ca9fa9239 --- /dev/null +++ b/models/yang/gnsi-pathz.yang @@ -0,0 +1,298 @@ +module gnsi-pathz { + yang-version 1.1; + namespace "https://github.com/openconfig/gnsi/pathz/yang"; + prefix gnsi-pathz; + + import openconfig-system { + prefix oc-sys; + } + import openconfig-system-grpc { + prefix oc-sys-grpc; + } + import openconfig-types { + prefix oc-types; + } + import openconfig-yang-types { + prefix oc-yang; + } + + organization + "Google LLC"; + + contact + "Google LLC"; + + description + "This module provides a data model for the metadata of + OpenConfig-path-based authorization policies installed on a networking + device."; + + revision 2022-10-30 { + description + "Adds success/failure counters."; + reference "0.2.0"; + } + + revision 2022-01-17 { + description + "Initial revision."; + reference "0.1.0"; + } + + typedef version { + type string; + description + "The version ID of the OpenConfig-path-based authorization policy + as provided by the OpenConfig-path-based Authorization Policy + Manager when the policy was pushed. This leaf persists through + a reboot."; + } + + typedef created-on { + type oc-types:timeticks64; + description + "The creation time of the OpenConfig-path-based authorization policy + as reported by the OpenConfig-path-based Authorization Policy + manager when the policy was pushed to the device. This value is + reported as nanoseconds since epoch (January 1st, 1970 00:00:00 GMT). + This leaf persists through a reboot."; + } + + // gRPC server related definitions. + grouping counters { + description + "A collection of counters that were collected by the gNSI.pathz + module while evaluating access to an OpenConfig path."; + + leaf access-rejects { + type oc-yang:counter64; + description + "The total number of times the gNSI.pathz module denied access + to an OpenConfig path."; + } + leaf last-access-reject { + type oc-types:timeticks64; + description + "A timestamp of the last time the gNSI.pathz denied access to + an OpenConfig path"; + } + leaf access-accepts { + type oc-yang:counter64; + description + "The total number of times the gNSI.pathz module allowed access + to an OpenConfig path."; + } + leaf last-access-accept { + type oc-types:timeticks64; + description + "A timestamp of the last time the gNSI.pathz allowed access to + an OpenConfig path"; + } + } + + grouping gnmi-pathz-policy-success-failure-counters { + description + "A collection of counters collected by the gNSI.pathz module."; + + container gnmi-pathz-policy-counters { + config false; + + uses gnmi-pathz-policy-xpath-success-failure-counters; + } + } + + grouping gnmi-pathz-policy-xpath-success-failure-counters { + description + "A collection of per-OpenConfig path counters."; + + container paths { + description + "A collection of per-OpenConfig path counters."; + + list path { + key xpath; + leaf xpath { + type leafref { + path "../state/xpath"; + } + description + "A OpenConfig schema path (xpath) the counter were + collected for."; + } + container state { + leaf xpath { + type string; + description + "A OpenConfig schema path (xpath) the counter were + collected for."; + } + container reads { + description + "The counter were collected while + performing a read operation on the + `xpath`."; + uses counters; + } + container writes { + description + "The counter were collected while + performing a write operation on the + `xpath`."; + uses counters; + } + } + } + } + } + + grouping grpc-server-gnmi-pathz-policy-state { + description + "gNMI server OpenConfig-path-based authorization policy + freshness-related data."; + + leaf gnmi-pathz-policy-version { + type version; + description + "The version of the OpenConfig-path-based authorization policy + that is used by this gNMI server."; + } + leaf gnmi-pathz-policy-created-on { + type created-on; + description + "The timestamp of the moment when the OpenConfig-path-based + authorization policy that is currently used by this gNMI server + was created."; + } + } + + grouping gnmi-pathz-policy-state { + description + "Operational state data for a gNMI OpenConfig-path-based + authorization policy."; + leaf instance { + type enumeration { + enum ACTIVE { + value 1; + description + "The policy that is currently used by the gNMI service + to authorize access."; + } + enum SANDBOX { + value 2; + description + "The most recent policy that has been uploaded during + the Rotation() RPC. If there is no Rotate() RPC in + progress, then referring to this instance of the policy + will result in an error."; + } + } + description + "The instance identifier of the gNMI OpenConfig-path-based + authorization policy."; + } + leaf version { + type version; + description + "The version of the gNMI OpenConfig-path-based authorization + policy."; + } + leaf created-on { + type created-on; + description + "The timestamp of the moment when the policy was + created."; + } + } + + grouping gnmi-pathz-policies { + description + "Collection of OpenConfig-path-based authorization policies that + have been installed on the device using the gNSI OpenConfig-path- + based authorization policy management service. + Each OpenConfig-path-based authorization policy listed here is + identified by its status (either ACTIVE or SANDBOX) and has its + version and creation date/time listed."; + + container policies { + config false; + description + "Information about freshness of an OpenConfig-path-based + authorization policy that have been installed + on the device using the gNSI OpenConfig-path-based + authorization policy management service."; + + list policy { + key instance; + ordered-by system; + description + "Information about the OpenConfig-path-based authorization + policy that is identified by the `instance`."; + leaf instance { + type leafref { + path "../state/instance"; + } + description + "The ID of the OpenConfig-path-based authorization + policy."; + } + container state { + description + "Operational state data for an OpenConfig-path-based + authorization policies."; + + uses gnmi-pathz-policy-state; + } + } + } + } + + grouping system-gnmi-pathz-policies { + description + "Collection of OpenConfig-path-based authorization policies that + have been installed on the device using the gNSI OpenConfig-path- + based authorization policy management service. + Each policy listed here is identified by its status (either ACTIVE + or SANDBOX) and has its version and creation date/time listed."; + + container gnmi-pathz-policies { + config false; + description + "Collection of OpenConfig-path-based authorization policies that + have been installed on the device using the gNSI OpenConfig- + path-based authorization policy management service. + Each policy listed here is identified by its status (either + ACTIVE or SANDBOX) and has its version and creation date/time + listed."; + + uses gnmi-pathz-policies; + } + } + + // Augments section. + + augment "/oc-sys:system" { + description + "Collection of OpenConfig-path-based authorization policies that + have been installed on the device using the gNSI OpenConfig-path- + based authorization policy management service. + Each policy listed here is identified by its status (either ACTIVE + or SANDBOX) and has its version and creation date/time listed."; + + uses system-gnmi-pathz-policies; + } + augment "/oc-sys:system/oc-sys-grpc:grpc-servers/oc-sys-grpc:grpc-server/" + + "oc-sys-grpc:state" { + description + "A gNMI server OpenConfig-path-based authorization policy freshness + information."; + + uses grpc-server-gnmi-pathz-policy-state; + } + augment "/oc-sys:system/oc-sys-grpc:grpc-servers/oc-sys-grpc:grpc-server" { + description + "A gNMI server OpenConfig-path-based authorization policy + success/failure counters."; + + uses gnmi-pathz-policy-success-failure-counters; + } +} diff --git a/translib/pfm_app.go b/translib/pfm_app.go index f2dab02a3..4dba490ea 100644 --- a/translib/pfm_app.go +++ b/translib/pfm_app.go @@ -20,24 +20,43 @@ package translib import ( "errors" + "fmt" "github.com/Azure/sonic-mgmt-common/translib/db" "github.com/Azure/sonic-mgmt-common/translib/ocbinds" "github.com/Azure/sonic-mgmt-common/translib/tlerr" log "github.com/golang/glog" "github.com/openconfig/ygot/ygot" + "math" "reflect" + "regexp" "strconv" + "strings" ) type PlatformApp struct { - path *PathInfo - reqData []byte - ygotRoot *ygot.GoStruct - ygotTarget *interface{} - eepromTs *db.TableSpec - eepromTable map[string]dbEntry + path *PathInfo + reqData []byte + ygotRoot *ygot.GoStruct + ygotTarget *interface{} + eepromTs *db.TableSpec + transceiverInfoTs *db.TableSpec + transceiverDomSensorTs *db.TableSpec + transceiverDomThresholdTs *db.TableSpec + applPortTs *db.TableSpec + eepromTable map[string]dbEntry + transceiverInfoTable map[string]dbEntry + transceiverDomSensorTable map[string]dbEntry + transceiverDomThresholdTable map[string]dbEntry + applPortTable map[string]dbEntry } +const ( + fractionDigits1 = 10 + fractionDigits2 = 100 + fractionDigits3 = 1000 + fractionDigits18 = 1000000000000000000 +) + func init() { log.Info("Init called for Platform module") err := register("/openconfig-platform:components", @@ -64,6 +83,10 @@ func (app *PlatformApp) initialize(data appData) { app.ygotRoot = data.ygotRoot app.ygotTarget = data.ygotTarget app.eepromTs = &db.TableSpec{Name: "EEPROM_INFO"} + app.transceiverInfoTs = &db.TableSpec{Name: "TRANSCEIVER_INFO"} + app.transceiverDomSensorTs = &db.TableSpec{Name: "TRANSCEIVER_DOM_SENSOR"} + app.transceiverDomThresholdTs = &db.TableSpec{Name: "TRANSCEIVER_DOM_THRESHOLD"} + app.applPortTs = &db.TableSpec{Name: "PORT_TABLE"} } @@ -160,10 +183,11 @@ func (app *PlatformApp) processGet(dbs [db.MaxDB]*db.DB, fmtType TranslibFmtType pathInfo.Template, pathInfo.Path, pathInfo.Vars) stateDb := dbs[db.StateDB] + applDb := dbs[db.ApplDB] var payload []byte - // Read eeprom info from DB + // Read eeprom info from STATE_DB app.eepromTable = make(map[string]dbEntry) tbl, derr := stateDb.GetTable(app.eepromTs) @@ -183,6 +207,86 @@ func (app *PlatformApp) processGet(dbs [db.MaxDB]*db.DB, fmtType TranslibFmtType app.eepromTable[key.Get(0)] = dbEntry{entry: e} } + // Read transceiver info from STATE_DB + app.transceiverInfoTable = make(map[string]dbEntry) + + transceiverInfoTbl, derr := stateDb.GetTable(app.transceiverInfoTs) + if derr != nil { + log.Error("TRANSCEIVER_INFO table get failed!") + return GetResponse{Payload: payload}, derr + } + + transceiverInfoTblKeys, _ := transceiverInfoTbl.GetKeys() + for _, key := range transceiverInfoTblKeys { + e, kerr := transceiverInfoTbl.GetEntry(key) + if kerr != nil { + log.Error("TRANSCEIVER_INFO entry get failed!") + return GetResponse{Payload: payload}, kerr + } + + app.transceiverInfoTable[key.Get(0)] = dbEntry{entry: e} + } + + // Read transceiver dom sensor from STATE_DB + app.transceiverDomSensorTable = make(map[string]dbEntry) + + transceiverDomSensorTbl, derr := stateDb.GetTable(app.transceiverDomSensorTs) + if derr != nil { + log.Error("TRANSCEIVER_DOM_SENSOR table get failed!") + return GetResponse{Payload: payload}, derr + } + + transceiverDomSensorTblKeys, _ := transceiverDomSensorTbl.GetKeys() + for _, key := range transceiverDomSensorTblKeys { + e, kerr := transceiverDomSensorTbl.GetEntry(key) + if kerr != nil { + log.Error("TRANSCEIVER_DOM_SENSOR entry get failed!") + return GetResponse{Payload: payload}, kerr + } + + app.transceiverDomSensorTable[key.Get(0)] = dbEntry{entry: e} + } + + // Read transceiver dom threshold from STATE_DB + app.transceiverDomThresholdTable = make(map[string]dbEntry) + + transceiverDomThresholdTbl, derr := stateDb.GetTable(app.transceiverDomThresholdTs) + if derr != nil { + log.Error("TRANSCEIVER_DOM_THRESHOLD table get failed!") + return GetResponse{Payload: payload}, derr + } + + transceiverDomThresholdTblKeys, _ := transceiverDomThresholdTbl.GetKeys() + for _, key := range transceiverDomThresholdTblKeys { + e, kerr := transceiverDomThresholdTbl.GetEntry(key) + if kerr != nil { + log.Error("TRANSCEIVER_DOM_THRESHOLD entry get failed!") + return GetResponse{Payload: payload}, kerr + } + + app.transceiverDomThresholdTable[key.Get(0)] = dbEntry{entry: e} + } + + // Read port from APPL_DB + app.applPortTable = make(map[string]dbEntry) + + applPortTbl, derr := applDb.GetTable(app.applPortTs) + if derr != nil { + log.Error("APPL PORT table get failed!") + return GetResponse{Payload: payload}, derr + } + + applPortTblKeys, _ := applPortTbl.GetKeys() + for _, key := range applPortTblKeys { + e, kerr := applPortTbl.GetEntry(key) + if kerr != nil { + log.Error("PORT entry get failed!") + return GetResponse{Payload: payload}, kerr + } + + app.applPortTable[key.Get(0)] = dbEntry{entry: e} + } + targetUriPath, perr := getYangPathFromUri(app.path.Path) if perr != nil { log.Infof("getYangPathFromUri failed.") @@ -192,7 +296,7 @@ func (app *PlatformApp) processGet(dbs [db.MaxDB]*db.DB, fmtType TranslibFmtType var err error if isSubtreeRequest(targetUriPath, "/openconfig-platform:components") { - err = app.doGetSysEeprom() + err = app.doGetPlatformInfo() } else { err = errors.New("Not supported component") } @@ -430,66 +534,1564 @@ func (app *PlatformApp) getSysEepromFromDb(eeprom *ocbinds.OpenconfigPlatform_Co return nil } -func (app *PlatformApp) doGetSysEeprom() error { +type CompStateDb struct { + Serial string + Model string +} - log.Infof("Preparing collection for system eeprom") +func (app *PlatformApp) getCompStateDbObj(ifName string) CompStateDb { + log.Infof("parseCompStateDb Enter ifName=%s", ifName) - var err error - pf_cpts := app.getAppRootObject() + var compStateDbObj CompStateDb + + transceiverInfoTable := app.transceiverInfoTable[ifName].entry + + compStateDbObj.Serial = transceiverInfoTable.Get("serial") + compStateDbObj.Model = transceiverInfoTable.Get("model") + + return compStateDbObj +} + +func (app *PlatformApp) getCompStateFromDb(oc_val *ocbinds.OpenconfigPlatform_Components_Component_State, all bool, compName string) error { + log.Infof("getCompStateFromDb Enter compName=%s", compName) + + ifName := strings.Replace(compName, "transceiver_", "", -1) + compStateDb := app.getCompStateDbObj(ifName) targetUriPath, _ := getYangPathFromUri(app.path.Path) - switch targetUriPath { - case "/openconfig-platform:components": - pf_comp, _ := pf_cpts.NewComponent("System Eeprom") - ygot.BuildEmptyTree(pf_comp) - err = app.getSysEepromFromDb(pf_comp.State, true) - case "/openconfig-platform:components/component": - compName := app.path.Var("name") - if compName == "" { - pf_comp, _ := pf_cpts.NewComponent("System Eeprom") - ygot.BuildEmptyTree(pf_comp) - err = app.getSysEepromFromDb(pf_comp.State, true) - } else { - if compName != "System Eeprom" { - err = errors.New("Invalid component name") - break - } - pf_comp := pf_cpts.Component[compName] - if pf_comp != nil { - ygot.BuildEmptyTree(pf_comp) - err = app.getSysEepromFromDb(pf_comp.State, true) + if all || targetUriPath == "/openconfig-platform:components/component/state/serial-no" { + transceiverInfoTable := app.transceiverInfoTable[ifName].entry + if transceiverInfoTable.Has("serial") { + oc_val.SerialNo = &compStateDb.Serial + } + } + if all || targetUriPath == "/openconfig-platform:components/component/state/part-no" { + transceiverInfoTable := app.transceiverInfoTable[ifName].entry + if transceiverInfoTable.Has("model") { + oc_val.PartNo = &compStateDb.Model + } + } + + return nil +} + +type CompTransceiverStateDb struct { + Connector string + Manufacturer string + Vendor_Oui string + Vendor_Rev string + Serial string + Vendor_Date string +} + +func (app *PlatformApp) getCompTransceiverStateDbObj(ifName string) CompTransceiverStateDb { + log.Infof("parseCompTransceiverStateDb Enter ifName=%s", ifName) + + var compTransceiverStateDbObj CompTransceiverStateDb + + transceiverInfoTable := app.transceiverInfoTable[ifName].entry + + compTransceiverStateDbObj.Connector = transceiverInfoTable.Get("connector") + compTransceiverStateDbObj.Manufacturer = transceiverInfoTable.Get("manufacturer") + compTransceiverStateDbObj.Vendor_Oui = transceiverInfoTable.Get("vendor_oui") + compTransceiverStateDbObj.Vendor_Rev = transceiverInfoTable.Get("vendor_rev") + compTransceiverStateDbObj.Serial = transceiverInfoTable.Get("serial") + compTransceiverStateDbObj.Vendor_Date = transceiverInfoTable.Get("vendor_date") + + return compTransceiverStateDbObj +} + +func (app *PlatformApp) getCompTransceiverStateFromDb(oc_val *ocbinds.OpenconfigPlatform_Components_Component_Transceiver_State, all bool, compName string) error { + log.Infof("getCompTransceiverStateFromDb Enter compName=%s", compName) + + ifName := strings.Replace(compName, "transceiver_", "", -1) + compTransceiverStateDb := app.getCompTransceiverStateDbObj(ifName) + + targetUriPath, _ := getYangPathFromUri(app.path.Path) + + if all || targetUriPath == "/openconfig-platform:components/component/openconfig-platform-transceiver:transceiver/state/connector-type" { + transceiverInfoTable := app.transceiverInfoTable[ifName].entry + if transceiverInfoTable.Has("connector") { + if strings.HasPrefix(compTransceiverStateDb.Connector, "AOC") { + oc_val.ConnectorType = ocbinds.OpenconfigTransportTypes_FIBER_CONNECTOR_TYPE_AOC_CONNECTOR + } else if strings.HasPrefix(compTransceiverStateDb.Connector, "DAC") { + oc_val.ConnectorType = ocbinds.OpenconfigTransportTypes_FIBER_CONNECTOR_TYPE_DAC_CONNECTOR + } else if strings.HasPrefix(compTransceiverStateDb.Connector, "LC") { + oc_val.ConnectorType = ocbinds.OpenconfigTransportTypes_FIBER_CONNECTOR_TYPE_LC_CONNECTOR + } else if strings.HasPrefix(compTransceiverStateDb.Connector, "MPO") { + oc_val.ConnectorType = ocbinds.OpenconfigTransportTypes_FIBER_CONNECTOR_TYPE_MPO_CONNECTOR + } else if strings.HasPrefix(compTransceiverStateDb.Connector, "SC") { + oc_val.ConnectorType = ocbinds.OpenconfigTransportTypes_FIBER_CONNECTOR_TYPE_SC_CONNECTOR } else { - err = errors.New("Invalid input component name") + oc_val.ConnectorType = ocbinds.OpenconfigTransportTypes_FIBER_CONNECTOR_TYPE_UNSET } } - case "/openconfig-platform:components/component/state": - compName := app.path.Var("name") - if compName != "" && compName == "System Eeprom" { - pf_comp := pf_cpts.Component[compName] - if pf_comp != nil { - ygot.BuildEmptyTree(pf_comp) - err = app.getSysEepromFromDb(pf_comp.State, true) - } else { - err = errors.New("Invalid input component name") + } + if all || targetUriPath == "/openconfig-platform:components/component/openconfig-platform-transceiver:transceiver/state/vendor" { + transceiverInfoTable := app.transceiverInfoTable[ifName].entry + if transceiverInfoTable.Has("manufacturer") { + oc_val.Vendor = &compTransceiverStateDb.Manufacturer + } + } + if all || targetUriPath == "/openconfig-platform:components/component/openconfig-platform-transceiver:transceiver/state/vendor-part" { + transceiverInfoTable := app.transceiverInfoTable[ifName].entry + if transceiverInfoTable.Has("vendor_oui") { + oc_val.VendorPart = &compTransceiverStateDb.Vendor_Oui + } + } + if all || targetUriPath == "/openconfig-platform:components/component/openconfig-platform-transceiver:transceiver/state/vendor-rev" { + transceiverInfoTable := app.transceiverInfoTable[ifName].entry + if transceiverInfoTable.Has("vendor_rev") { + oc_val.VendorRev = &compTransceiverStateDb.Vendor_Rev + } + } + if all || targetUriPath == "/openconfig-platform:components/component/openconfig-platform-transceiver:transceiver/state/serial-no" { + transceiverInfoTable := app.transceiverInfoTable[ifName].entry + if transceiverInfoTable.Has("serial") { + oc_val.SerialNo = &compTransceiverStateDb.Serial + } + } + if all || targetUriPath == "/openconfig-platform:components/component/openconfig-platform-transceiver:transceiver/state/date-code" { + transceiverInfoTable := app.transceiverInfoTable[ifName].entry + if transceiverInfoTable.Has("vendor_date") { + rex := regexp.MustCompile("[0-9]+") + subMatchString := rex.FindAllString(compTransceiverStateDb.Vendor_Date, -1) + if len(subMatchString) >= 3 { + if len(subMatchString[0]) == 4 && len(subMatchString[1]) == 2 && len(subMatchString[2]) == 2 { + vendorDate := fmt.Sprintf("%s-%s-%sT00:00:00.000Z", subMatchString[0], subMatchString[1], subMatchString[2]) + formatMatch, _ := regexp.MatchString("[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])[Tt]00:00:00\\.000Z", vendorDate) + if formatMatch { + oc_val.DateCode = &vendorDate + } + } } - } else { - err = errors.New("Invalid component name ") } + } - default: - if isSubtreeRequest(targetUriPath, "/openconfig-platform:components/component/state") { - compName := app.path.Var("name") - if compName == "" || compName != "System Eeprom" { - err = errors.New("Invalid input component name") - } else { - pf_comp := pf_cpts.Component[compName] - if pf_comp != nil { - ygot.BuildEmptyTree(pf_comp) - err = app.getSysEepromFromDb(pf_comp.State, false) - } else { - err = errors.New("Invalid input component name") - } + return nil +} + +type CompTransceiverStateSupplyVoltageDb struct { + voltage float64 +} + +func (app *PlatformApp) getCompTransceiverStateSupplyVoltageDbObj(ifName string) CompTransceiverStateSupplyVoltageDb { + log.Infof("parseCompTransceiverStateSupplyVoltageDb Enter ifName=%s", ifName) + + var compTransceiverStateSupplyVoltageDbObj CompTransceiverStateSupplyVoltageDb + + transceiverDomSensorTable := app.transceiverDomSensorTable[ifName].entry + + if transceiverDomSensorTable.Get("voltage") != "N/A" { + compTransceiverStateSupplyVoltageDbObj.voltage, _ = strconv.ParseFloat(transceiverDomSensorTable.Get("voltage"), 64) + } else { + compTransceiverStateSupplyVoltageDbObj.voltage, _ = strconv.ParseFloat("NaN", 64) + } + + return compTransceiverStateSupplyVoltageDbObj +} + +func (app *PlatformApp) getCompTransceiverStateSupplyVoltageFromDb(oc_val *ocbinds.OpenconfigPlatform_Components_Component_Transceiver_State_SupplyVoltage, all bool, compName string) error { + log.Infof("getCompTransceiverStateSupplyVoltageFromDb Enter compName=%s", compName) + + ifName := strings.Replace(compName, "transceiver_", "", -1) + compTransceiverStateSupplyVoltageDb := app.getCompTransceiverStateSupplyVoltageDbObj(ifName) + + targetUriPath, _ := getYangPathFromUri(app.path.Path) + + if all || targetUriPath == "/openconfig-platform:components/component/openconfig-platform-transceiver:transceiver/state/supply-voltage/instant" { + transceiverDomSensorTable := app.transceiverDomSensorTable[ifName].entry + if transceiverDomSensorTable.Has("voltage") { + voltage := math.Floor(compTransceiverStateSupplyVoltageDb.voltage*fractionDigits2) / fractionDigits2 + oc_val.Instant = &voltage + } + } + + return nil +} + +type CompTransceiverPhysicalChannelStateLaserTemperatureDb struct { + temperature float64 +} + +func (app *PlatformApp) getCompTransceiverPhysicalChannelStateLaserTemperatureDbObj(ifName string) CompTransceiverPhysicalChannelStateLaserTemperatureDb { + log.Infof("parseCompTransceiverPhysicalChannelStateLaserTemperatureDb Enter ifName=%s", ifName) + + var compTransceiverPhysicalChannelStateLaserTemperatureDbObj CompTransceiverPhysicalChannelStateLaserTemperatureDb + + transceiverDomSensorTable := app.transceiverDomSensorTable[ifName].entry + + if transceiverDomSensorTable.Get("temperature") != "N/A" { + compTransceiverPhysicalChannelStateLaserTemperatureDbObj.temperature, _ = strconv.ParseFloat(transceiverDomSensorTable.Get("temperature"), 64) + } else { + compTransceiverPhysicalChannelStateLaserTemperatureDbObj.temperature, _ = strconv.ParseFloat("NaN", 64) + } + + return compTransceiverPhysicalChannelStateLaserTemperatureDbObj +} + +func (app *PlatformApp) getCompTransceiverPhysicalChannelStateLaserTemperatureFromDb(oc_val *ocbinds.OpenconfigPlatform_Components_Component_Transceiver_PhysicalChannels_Channel_State_LaserTemperature, all bool, compName string) error { + log.Infof("getCompTransceiverPhysicalChannelStateLaserTemperatureFromDb Enter compName=%s", compName) + + ifName := strings.Replace(compName, "transceiver_", "", -1) + compTransceiverPhysicalChannelStateLaserTemperatureDb := app.getCompTransceiverPhysicalChannelStateLaserTemperatureDbObj(ifName) + + targetUriPath, _ := getYangPathFromUri(app.path.Path) + + if all || targetUriPath == "/openconfig-platform:components/component/openconfig-platform-transceiver:transceiver/physical-channels/channel/state/laser-temperature/instant" { + transceiverDomSensorTable := app.transceiverDomSensorTable[ifName].entry + if transceiverDomSensorTable.Has("temperature") { + temperature := math.Floor(compTransceiverPhysicalChannelStateLaserTemperatureDb.temperature*fractionDigits1) / fractionDigits1 + oc_val.Instant = &temperature + } + } + + return nil +} + +type CompTransceiverPhysicalChannelStateOutputPowerDb struct { + tx1power float64 + tx2power float64 + tx3power float64 + tx4power float64 + tx5power float64 + tx6power float64 + tx7power float64 + tx8power float64 +} + +func (app *PlatformApp) getCompTransceiverPhysicalChannelStateOutputPowerDbObj(ifName string) CompTransceiverPhysicalChannelStateOutputPowerDb { + log.Infof("parseCompTransceiverPhysicalChannelStateOutputPowerDb Enter ifName=%s", ifName) + + var compTransceiverPhysicalChannelStateOutputPowerDbObj CompTransceiverPhysicalChannelStateOutputPowerDb + + transceiverDomSensorTable := app.transceiverDomSensorTable[ifName].entry + + compTransceiverPhysicalChannelStateOutputPowerDbObj.tx1power, _ = strconv.ParseFloat(transceiverDomSensorTable.Get("tx1power"), 64) + compTransceiverPhysicalChannelStateOutputPowerDbObj.tx2power, _ = strconv.ParseFloat(transceiverDomSensorTable.Get("tx2power"), 64) + compTransceiverPhysicalChannelStateOutputPowerDbObj.tx3power, _ = strconv.ParseFloat(transceiverDomSensorTable.Get("tx3power"), 64) + compTransceiverPhysicalChannelStateOutputPowerDbObj.tx4power, _ = strconv.ParseFloat(transceiverDomSensorTable.Get("tx4power"), 64) + compTransceiverPhysicalChannelStateOutputPowerDbObj.tx5power, _ = strconv.ParseFloat(transceiverDomSensorTable.Get("tx5power"), 64) + compTransceiverPhysicalChannelStateOutputPowerDbObj.tx6power, _ = strconv.ParseFloat(transceiverDomSensorTable.Get("tx6power"), 64) + compTransceiverPhysicalChannelStateOutputPowerDbObj.tx7power, _ = strconv.ParseFloat(transceiverDomSensorTable.Get("tx7power"), 64) + compTransceiverPhysicalChannelStateOutputPowerDbObj.tx8power, _ = strconv.ParseFloat(transceiverDomSensorTable.Get("tx8power"), 64) + + return compTransceiverPhysicalChannelStateOutputPowerDbObj +} + +func (app *PlatformApp) getCompTransceiverPhysicalChannelStateOutputPowerFromDb(oc_val *ocbinds.OpenconfigPlatform_Components_Component_Transceiver_PhysicalChannels_Channel_State_OutputPower, all bool, compName string, laneIndex uint16) error { + log.Infof("getCompTransceiverPhysicalChannelStateOutputPowerFromDb Enter compName=%s laneIndex=%d", compName, laneIndex) + + ifName := strings.Replace(compName, "transceiver_", "", -1) + compTransceiverPhysicalChannelStateOutputPowerDb := app.getCompTransceiverPhysicalChannelStateOutputPowerDbObj(ifName) + + targetUriPath, _ := getYangPathFromUri(app.path.Path) + + if all || targetUriPath == "/openconfig-platform:components/component/openconfig-platform-transceiver:transceiver/physical-channels/channel/state/output-power/instant" { + switch laneIndex { + case 0: + transceiverDomSensorTable := app.transceiverDomSensorTable[ifName].entry + if transceiverDomSensorTable.Has("tx1power") { + tx1power := math.Floor(compTransceiverPhysicalChannelStateOutputPowerDb.tx1power*fractionDigits2) / fractionDigits2 + oc_val.Instant = &tx1power + } + case 1: + transceiverDomSensorTable := app.transceiverDomSensorTable[ifName].entry + if transceiverDomSensorTable.Has("tx2power") { + tx2power := math.Floor(compTransceiverPhysicalChannelStateOutputPowerDb.tx2power*fractionDigits2) / fractionDigits2 + oc_val.Instant = &tx2power + } + case 2: + transceiverDomSensorTable := app.transceiverDomSensorTable[ifName].entry + if transceiverDomSensorTable.Has("tx3power") { + tx3power := math.Floor(compTransceiverPhysicalChannelStateOutputPowerDb.tx3power*fractionDigits2) / fractionDigits2 + oc_val.Instant = &tx3power + } + case 3: + transceiverDomSensorTable := app.transceiverDomSensorTable[ifName].entry + if transceiverDomSensorTable.Has("tx4power") { + tx4power := math.Floor(compTransceiverPhysicalChannelStateOutputPowerDb.tx4power*fractionDigits2) / fractionDigits2 + oc_val.Instant = &tx4power + } + case 4: + transceiverDomSensorTable := app.transceiverDomSensorTable[ifName].entry + if transceiverDomSensorTable.Has("tx5power") { + tx5power := math.Floor(compTransceiverPhysicalChannelStateOutputPowerDb.tx5power*fractionDigits2) / fractionDigits2 + oc_val.Instant = &tx5power + } + case 5: + transceiverDomSensorTable := app.transceiverDomSensorTable[ifName].entry + if transceiverDomSensorTable.Has("tx6power") { + tx6power := math.Floor(compTransceiverPhysicalChannelStateOutputPowerDb.tx6power*fractionDigits2) / fractionDigits2 + oc_val.Instant = &tx6power + } + case 6: + transceiverDomSensorTable := app.transceiverDomSensorTable[ifName].entry + if transceiverDomSensorTable.Has("tx7power") { + tx7power := math.Floor(compTransceiverPhysicalChannelStateOutputPowerDb.tx7power*fractionDigits2) / fractionDigits2 + oc_val.Instant = &tx7power + } + case 7: + transceiverDomSensorTable := app.transceiverDomSensorTable[ifName].entry + if transceiverDomSensorTable.Has("tx8power") { + tx8power := math.Floor(compTransceiverPhysicalChannelStateOutputPowerDb.tx8power*fractionDigits2) / fractionDigits2 + oc_val.Instant = &tx8power + } + } + } + + return nil +} + +type CompTransceiverPhysicalChannelStateInputPowerDb struct { + rx1power float64 + rx2power float64 + rx3power float64 + rx4power float64 + rx5power float64 + rx6power float64 + rx7power float64 + rx8power float64 +} + +func (app *PlatformApp) getCompTransceiverPhysicalChannelStateInputPowerDbObj(ifName string) CompTransceiverPhysicalChannelStateInputPowerDb { + log.Infof("parseCompTransceiverPhysicalChannelStateInputPowerDb Enter ifName=%s", ifName) + + var compTransceiverPhysicalChannelStateInputPowerDbObj CompTransceiverPhysicalChannelStateInputPowerDb + + transceiverDomSensorTable := app.transceiverDomSensorTable[ifName].entry + + compTransceiverPhysicalChannelStateInputPowerDbObj.rx1power, _ = strconv.ParseFloat(transceiverDomSensorTable.Get("rx1power"), 64) + compTransceiverPhysicalChannelStateInputPowerDbObj.rx2power, _ = strconv.ParseFloat(transceiverDomSensorTable.Get("rx2power"), 64) + compTransceiverPhysicalChannelStateInputPowerDbObj.rx3power, _ = strconv.ParseFloat(transceiverDomSensorTable.Get("rx3power"), 64) + compTransceiverPhysicalChannelStateInputPowerDbObj.rx4power, _ = strconv.ParseFloat(transceiverDomSensorTable.Get("rx4power"), 64) + compTransceiverPhysicalChannelStateInputPowerDbObj.rx5power, _ = strconv.ParseFloat(transceiverDomSensorTable.Get("rx5power"), 64) + compTransceiverPhysicalChannelStateInputPowerDbObj.rx6power, _ = strconv.ParseFloat(transceiverDomSensorTable.Get("rx6power"), 64) + compTransceiverPhysicalChannelStateInputPowerDbObj.rx7power, _ = strconv.ParseFloat(transceiverDomSensorTable.Get("rx7power"), 64) + compTransceiverPhysicalChannelStateInputPowerDbObj.rx8power, _ = strconv.ParseFloat(transceiverDomSensorTable.Get("rx8power"), 64) + + return compTransceiverPhysicalChannelStateInputPowerDbObj +} + +func (app *PlatformApp) getCompTransceiverPhysicalChannelStateInputPowerFromDb(oc_val *ocbinds.OpenconfigPlatform_Components_Component_Transceiver_PhysicalChannels_Channel_State_InputPower, all bool, compName string, laneIndex uint16) error { + log.Infof("getCompTransceiverPhysicalChannelStateInputPowerFromDb Enter compName=%s laneIndex=%d", compName, laneIndex) + + ifName := strings.Replace(compName, "transceiver_", "", -1) + compTransceiverPhysicalChannelStateInputPowerDb := app.getCompTransceiverPhysicalChannelStateInputPowerDbObj(ifName) + + targetUriPath, _ := getYangPathFromUri(app.path.Path) + + if all || targetUriPath == "/openconfig-platform:components/component/openconfig-platform-transceiver:transceiver/physical-channels/channel/state/input-power/instant" { + switch laneIndex { + case 0: + transceiverDomSensorTable := app.transceiverDomSensorTable[ifName].entry + if transceiverDomSensorTable.Has("rx1power") { + rx1power := math.Floor(compTransceiverPhysicalChannelStateInputPowerDb.rx1power*fractionDigits2) / fractionDigits2 + oc_val.Instant = &rx1power + } + case 1: + transceiverDomSensorTable := app.transceiverDomSensorTable[ifName].entry + if transceiverDomSensorTable.Has("rx2power") { + rx2power := math.Floor(compTransceiverPhysicalChannelStateInputPowerDb.rx2power*fractionDigits2) / fractionDigits2 + oc_val.Instant = &rx2power + } + case 2: + transceiverDomSensorTable := app.transceiverDomSensorTable[ifName].entry + if transceiverDomSensorTable.Has("rx3power") { + rx3power := math.Floor(compTransceiverPhysicalChannelStateInputPowerDb.rx3power*fractionDigits2) / fractionDigits2 + oc_val.Instant = &rx3power + } + case 3: + transceiverDomSensorTable := app.transceiverDomSensorTable[ifName].entry + if transceiverDomSensorTable.Has("rx4power") { + rx4power := math.Floor(compTransceiverPhysicalChannelStateInputPowerDb.rx4power*fractionDigits2) / fractionDigits2 + oc_val.Instant = &rx4power + } + case 4: + transceiverDomSensorTable := app.transceiverDomSensorTable[ifName].entry + if transceiverDomSensorTable.Has("rx5power") { + rx5power := math.Floor(compTransceiverPhysicalChannelStateInputPowerDb.rx5power*fractionDigits2) / fractionDigits2 + oc_val.Instant = &rx5power + } + case 5: + transceiverDomSensorTable := app.transceiverDomSensorTable[ifName].entry + if transceiverDomSensorTable.Has("rx6power") { + rx6power := math.Floor(compTransceiverPhysicalChannelStateInputPowerDb.rx6power*fractionDigits2) / fractionDigits2 + oc_val.Instant = &rx6power + } + case 6: + transceiverDomSensorTable := app.transceiverDomSensorTable[ifName].entry + if transceiverDomSensorTable.Has("rx7power") { + rx7power := math.Floor(compTransceiverPhysicalChannelStateInputPowerDb.rx7power*fractionDigits2) / fractionDigits2 + oc_val.Instant = &rx7power + } + case 7: + transceiverDomSensorTable := app.transceiverDomSensorTable[ifName].entry + if transceiverDomSensorTable.Has("rx8power") { + rx8power := math.Floor(compTransceiverPhysicalChannelStateInputPowerDb.rx8power*fractionDigits2) / fractionDigits2 + oc_val.Instant = &rx8power + } + } + } + + return nil +} + +type CompTransceiverPhysicalChannelStateLaserBiasCurrentDb struct { + tx1bias float64 + tx2bias float64 + tx3bias float64 + tx4bias float64 + tx5bias float64 + tx6bias float64 + tx7bias float64 + tx8bias float64 +} + +func (app *PlatformApp) getCompTransceiverPhysicalChannelStateLaserBiasCurrentDbObj(ifName string) CompTransceiverPhysicalChannelStateLaserBiasCurrentDb { + log.Infof("parseCompTransceiverPhysicalChannelStateLaserBiasCurrentDb Enter ifName=%s", ifName) + + var compTransceiverPhysicalChannelStateLaserBiasCurrentDbObj CompTransceiverPhysicalChannelStateLaserBiasCurrentDb + + transceiverDomSensorTable := app.transceiverDomSensorTable[ifName].entry + + if transceiverDomSensorTable.Get("tx1bias") != "N/A" { + compTransceiverPhysicalChannelStateLaserBiasCurrentDbObj.tx1bias, _ = strconv.ParseFloat(transceiverDomSensorTable.Get("tx1bias"), 64) + } else { + compTransceiverPhysicalChannelStateLaserBiasCurrentDbObj.tx1bias, _ = strconv.ParseFloat("NaN", 64) + } + if transceiverDomSensorTable.Get("tx2bias") != "N/A" { + compTransceiverPhysicalChannelStateLaserBiasCurrentDbObj.tx2bias, _ = strconv.ParseFloat(transceiverDomSensorTable.Get("tx2bias"), 64) + } else { + compTransceiverPhysicalChannelStateLaserBiasCurrentDbObj.tx2bias, _ = strconv.ParseFloat("NaN", 64) + } + if transceiverDomSensorTable.Get("tx3bias") != "N/A" { + compTransceiverPhysicalChannelStateLaserBiasCurrentDbObj.tx3bias, _ = strconv.ParseFloat(transceiverDomSensorTable.Get("tx3bias"), 64) + } else { + compTransceiverPhysicalChannelStateLaserBiasCurrentDbObj.tx3bias, _ = strconv.ParseFloat("NaN", 64) + } + if transceiverDomSensorTable.Get("tx4bias") != "N/A" { + compTransceiverPhysicalChannelStateLaserBiasCurrentDbObj.tx4bias, _ = strconv.ParseFloat(transceiverDomSensorTable.Get("tx4bias"), 64) + } else { + compTransceiverPhysicalChannelStateLaserBiasCurrentDbObj.tx4bias, _ = strconv.ParseFloat("NaN", 64) + } + if transceiverDomSensorTable.Get("tx5bias") != "N/A" { + compTransceiverPhysicalChannelStateLaserBiasCurrentDbObj.tx5bias, _ = strconv.ParseFloat(transceiverDomSensorTable.Get("tx5bias"), 64) + } else { + compTransceiverPhysicalChannelStateLaserBiasCurrentDbObj.tx5bias, _ = strconv.ParseFloat("NaN", 64) + } + if transceiverDomSensorTable.Get("tx6bias") != "N/A" { + compTransceiverPhysicalChannelStateLaserBiasCurrentDbObj.tx6bias, _ = strconv.ParseFloat(transceiverDomSensorTable.Get("tx6bias"), 64) + } else { + compTransceiverPhysicalChannelStateLaserBiasCurrentDbObj.tx6bias, _ = strconv.ParseFloat("NaN", 64) + } + if transceiverDomSensorTable.Get("tx7bias") != "N/A" { + compTransceiverPhysicalChannelStateLaserBiasCurrentDbObj.tx7bias, _ = strconv.ParseFloat(transceiverDomSensorTable.Get("tx7bias"), 64) + } else { + compTransceiverPhysicalChannelStateLaserBiasCurrentDbObj.tx7bias, _ = strconv.ParseFloat("NaN", 64) + } + if transceiverDomSensorTable.Get("tx8bias") != "N/A" { + compTransceiverPhysicalChannelStateLaserBiasCurrentDbObj.tx8bias, _ = strconv.ParseFloat(transceiverDomSensorTable.Get("tx8bias"), 64) + } else { + compTransceiverPhysicalChannelStateLaserBiasCurrentDbObj.tx8bias, _ = strconv.ParseFloat("NaN", 64) + } + + return compTransceiverPhysicalChannelStateLaserBiasCurrentDbObj +} + +func (app *PlatformApp) getCompTransceiverPhysicalChannelStateLaserBiasCurrentFromDb(oc_val *ocbinds.OpenconfigPlatform_Components_Component_Transceiver_PhysicalChannels_Channel_State_LaserBiasCurrent, all bool, compName string, laneIndex uint16) error { + log.Infof("getCompTransceiverPhysicalChannelStateLaserBiasCurrentFromDb Enter compName=%s laneIndex=%d", compName, laneIndex) + + ifName := strings.Replace(compName, "transceiver_", "", -1) + compTransceiverPhysicalChannelStateLaserBiasCurrentDb := app.getCompTransceiverPhysicalChannelStateLaserBiasCurrentDbObj(ifName) + + targetUriPath, _ := getYangPathFromUri(app.path.Path) + + if all || targetUriPath == "/openconfig-platform:components/component/openconfig-platform-transceiver:transceiver/physical-channels/channel/state/laser-bias-current/instant" { + switch laneIndex { + case 0: + transceiverDomSensorTable := app.transceiverDomSensorTable[ifName].entry + if transceiverDomSensorTable.Has("tx1bias") { + tx1bias := math.Floor(compTransceiverPhysicalChannelStateLaserBiasCurrentDb.tx1bias*fractionDigits2) / fractionDigits2 + oc_val.Instant = &tx1bias + } + case 1: + transceiverDomSensorTable := app.transceiverDomSensorTable[ifName].entry + if transceiverDomSensorTable.Has("tx2bias") { + tx2bias := math.Floor(compTransceiverPhysicalChannelStateLaserBiasCurrentDb.tx2bias*fractionDigits2) / fractionDigits2 + oc_val.Instant = &tx2bias + } + case 2: + transceiverDomSensorTable := app.transceiverDomSensorTable[ifName].entry + if transceiverDomSensorTable.Has("tx3bias") { + tx3bias := math.Floor(compTransceiverPhysicalChannelStateLaserBiasCurrentDb.tx3bias*fractionDigits2) / fractionDigits2 + oc_val.Instant = &tx3bias + } + case 3: + transceiverDomSensorTable := app.transceiverDomSensorTable[ifName].entry + if transceiverDomSensorTable.Has("tx4bias") { + tx4bias := math.Floor(compTransceiverPhysicalChannelStateLaserBiasCurrentDb.tx4bias*fractionDigits2) / fractionDigits2 + oc_val.Instant = &tx4bias + } + case 4: + transceiverDomSensorTable := app.transceiverDomSensorTable[ifName].entry + if transceiverDomSensorTable.Has("tx5bias") { + tx5bias := math.Floor(compTransceiverPhysicalChannelStateLaserBiasCurrentDb.tx5bias*fractionDigits2) / fractionDigits2 + oc_val.Instant = &tx5bias + } + case 5: + transceiverDomSensorTable := app.transceiverDomSensorTable[ifName].entry + if transceiverDomSensorTable.Has("tx6bias") { + tx6bias := math.Floor(compTransceiverPhysicalChannelStateLaserBiasCurrentDb.tx6bias*fractionDigits2) / fractionDigits2 + oc_val.Instant = &tx6bias + } + case 6: + transceiverDomSensorTable := app.transceiverDomSensorTable[ifName].entry + if transceiverDomSensorTable.Has("tx7bias") { + tx7bias := math.Floor(compTransceiverPhysicalChannelStateLaserBiasCurrentDb.tx7bias*fractionDigits2) / fractionDigits2 + oc_val.Instant = &tx7bias + } + case 7: + transceiverDomSensorTable := app.transceiverDomSensorTable[ifName].entry + if transceiverDomSensorTable.Has("tx8bias") { + tx8bias := math.Floor(compTransceiverPhysicalChannelStateLaserBiasCurrentDb.tx8bias*fractionDigits2) / fractionDigits2 + oc_val.Instant = &tx8bias + } + } + } + + return nil +} + +type CompTransceiverThresholdStateDb struct { + temphighalarm float64 + templowalarm float64 + vcchighalarm float64 + vcclowalarm float64 + temphighwarning float64 + templowwarning float64 + vcchighwarning float64 + vcclowwarning float64 + txpowerhighalarm float64 + txpowerlowalarm float64 + rxpowerhighalarm float64 + rxpowerlowalarm float64 + txbiashighalarm float64 + txbiaslowalarm float64 + txpowerhighwarning float64 + txpowerlowwarning float64 + rxpowerhighwarning float64 + rxpowerlowwarning float64 + txbiashighwarning float64 + txbiaslowwarning float64 +} + +func (app *PlatformApp) getCompTransceiverThresholdStateDbObj(ifName string) CompTransceiverThresholdStateDb { + log.Infof("parseCompTransceiverThresholdStateDb Enter ifName=%s", ifName) + + var compTransceiverThresholdStateDbObj CompTransceiverThresholdStateDb + + transceiverDomThresholdTable := app.transceiverDomThresholdTable[ifName].entry + + compTransceiverThresholdStateDbObj.temphighalarm, _ = strconv.ParseFloat(transceiverDomThresholdTable.Get("temphighalarm"), 64) + compTransceiverThresholdStateDbObj.templowalarm, _ = strconv.ParseFloat(transceiverDomThresholdTable.Get("templowalarm"), 64) + compTransceiverThresholdStateDbObj.vcchighalarm, _ = strconv.ParseFloat(transceiverDomThresholdTable.Get("vcchighalarm"), 64) + compTransceiverThresholdStateDbObj.vcclowalarm, _ = strconv.ParseFloat(transceiverDomThresholdTable.Get("vcclowalarm"), 64) + compTransceiverThresholdStateDbObj.temphighwarning, _ = strconv.ParseFloat(transceiverDomThresholdTable.Get("temphighwarning"), 64) + compTransceiverThresholdStateDbObj.templowwarning, _ = strconv.ParseFloat(transceiverDomThresholdTable.Get("templowwarning"), 64) + compTransceiverThresholdStateDbObj.vcchighwarning, _ = strconv.ParseFloat(transceiverDomThresholdTable.Get("vcchighwarning"), 64) + compTransceiverThresholdStateDbObj.vcclowwarning, _ = strconv.ParseFloat(transceiverDomThresholdTable.Get("vcclowwarning"), 64) + compTransceiverThresholdStateDbObj.txpowerhighalarm, _ = strconv.ParseFloat(transceiverDomThresholdTable.Get("txpowerhighalarm"), 64) + compTransceiverThresholdStateDbObj.txpowerlowalarm, _ = strconv.ParseFloat(transceiverDomThresholdTable.Get("txpowerlowalarm"), 64) + compTransceiverThresholdStateDbObj.rxpowerhighalarm, _ = strconv.ParseFloat(transceiverDomThresholdTable.Get("rxpowerhighalarm"), 64) + compTransceiverThresholdStateDbObj.rxpowerlowalarm, _ = strconv.ParseFloat(transceiverDomThresholdTable.Get("rxpowerlowalarm"), 64) + compTransceiverThresholdStateDbObj.txbiashighalarm, _ = strconv.ParseFloat(transceiverDomThresholdTable.Get("txbiashighalarm"), 64) + compTransceiverThresholdStateDbObj.txbiaslowalarm, _ = strconv.ParseFloat(transceiverDomThresholdTable.Get("txbiaslowalarm"), 64) + compTransceiverThresholdStateDbObj.txpowerhighwarning, _ = strconv.ParseFloat(transceiverDomThresholdTable.Get("txpowerhighwarning"), 64) + compTransceiverThresholdStateDbObj.txpowerlowwarning, _ = strconv.ParseFloat(transceiverDomThresholdTable.Get("txpowerlowwarning"), 64) + compTransceiverThresholdStateDbObj.rxpowerhighwarning, _ = strconv.ParseFloat(transceiverDomThresholdTable.Get("rxpowerhighwarning"), 64) + compTransceiverThresholdStateDbObj.rxpowerlowwarning, _ = strconv.ParseFloat(transceiverDomThresholdTable.Get("rxpowerlowwarning"), 64) + compTransceiverThresholdStateDbObj.txbiashighwarning, _ = strconv.ParseFloat(transceiverDomThresholdTable.Get("txbiashighwarning"), 64) + compTransceiverThresholdStateDbObj.txbiaslowwarning, _ = strconv.ParseFloat(transceiverDomThresholdTable.Get("txbiaslowwarning"), 64) + + return compTransceiverThresholdStateDbObj +} + +func (app *PlatformApp) getCompTransceiverThresholdStateFromDb(oc_val *ocbinds.OpenconfigPlatform_Components_Component_Transceiver_Thresholds_Threshold_State, all bool, compName string, severityName string) error { + log.Infof("getCompTransceiverThresholdStateFromDb Enter compName=%s severityName=%s", compName, severityName) + + ifName := strings.Replace(compName, "transceiver_", "", -1) + compTransceiverThresholdStateDb := app.getCompTransceiverThresholdStateDbObj(ifName) + + targetUriPath, _ := getYangPathFromUri(app.path.Path) + + if severityName == "CRITICAL" { + if all || targetUriPath == "/openconfig-platform:components/component/openconfig-platform-transceiver:transceiver/thresholds/threshold/state/laser-temperature-upper" { + transceiverDomThresholdTable := app.transceiverDomThresholdTable[ifName].entry + if transceiverDomThresholdTable.Has("temphighalarm") { + temphighalarm := math.Floor(compTransceiverThresholdStateDb.temphighalarm*fractionDigits1) / fractionDigits1 + oc_val.LaserTemperatureUpper = &temphighalarm + } + } + if all || targetUriPath == "/openconfig-platform:components/component/openconfig-platform-transceiver:transceiver/thresholds/threshold/state/laser-temperature-lower" { + transceiverDomThresholdTable := app.transceiverDomThresholdTable[ifName].entry + if transceiverDomThresholdTable.Has("templowalarm") { + templowalarm := math.Floor(compTransceiverThresholdStateDb.templowalarm*fractionDigits1) / fractionDigits1 + oc_val.LaserTemperatureLower = &templowalarm + } + } + if all || targetUriPath == "/openconfig-platform:components/component/openconfig-platform-transceiver:transceiver/thresholds/threshold/state/supply-voltage-upper" { + transceiverDomThresholdTable := app.transceiverDomThresholdTable[ifName].entry + if transceiverDomThresholdTable.Has("vcchighalarm") { + vcchighalarm := math.Floor(compTransceiverThresholdStateDb.vcchighalarm*fractionDigits2) / fractionDigits2 + oc_val.SupplyVoltageUpper = &vcchighalarm + } + } + if all || targetUriPath == "/openconfig-platform:components/component/openconfig-platform-transceiver:transceiver/thresholds/threshold/state/supply-voltage-lower" { + transceiverDomThresholdTable := app.transceiverDomThresholdTable[ifName].entry + if transceiverDomThresholdTable.Has("vcclowalarm") { + vcclowalarm := math.Floor(compTransceiverThresholdStateDb.vcclowalarm*fractionDigits2) / fractionDigits2 + oc_val.SupplyVoltageLower = &vcclowalarm + } + } + if all || targetUriPath == "/openconfig-platform:components/component/openconfig-platform-transceiver:transceiver/thresholds/threshold/state/output-power-upper" { + transceiverDomThresholdTable := app.transceiverDomThresholdTable[ifName].entry + if transceiverDomThresholdTable.Has("txpowerhighalarm") { + txpowerhighalarm := math.Floor(compTransceiverThresholdStateDb.txpowerhighalarm*fractionDigits2) / fractionDigits2 + oc_val.OutputPowerUpper = &txpowerhighalarm + } + } + if all || targetUriPath == "/openconfig-platform:components/component/openconfig-platform-transceiver:transceiver/thresholds/threshold/state/output-power-lower" { + transceiverDomThresholdTable := app.transceiverDomThresholdTable[ifName].entry + if transceiverDomThresholdTable.Has("txpowerlowalarm") { + txpowerlowalarm := math.Floor(compTransceiverThresholdStateDb.txpowerlowalarm*fractionDigits2) / fractionDigits2 + oc_val.OutputPowerLower = &txpowerlowalarm + } + } + if all || targetUriPath == "/openconfig-platform:components/component/openconfig-platform-transceiver:transceiver/thresholds/threshold/state/input-power-upper" { + transceiverDomThresholdTable := app.transceiverDomThresholdTable[ifName].entry + if transceiverDomThresholdTable.Has("rxpowerhighalarm") { + rxpowerhighalarm := math.Floor(compTransceiverThresholdStateDb.rxpowerhighalarm*fractionDigits2) / fractionDigits2 + oc_val.InputPowerUpper = &rxpowerhighalarm + } + } + if all || targetUriPath == "/openconfig-platform:components/component/openconfig-platform-transceiver:transceiver/thresholds/threshold/state/input-power-lower" { + transceiverDomThresholdTable := app.transceiverDomThresholdTable[ifName].entry + if transceiverDomThresholdTable.Has("rxpowerlowalarm") { + rxpowerlowalarm := math.Floor(compTransceiverThresholdStateDb.rxpowerlowalarm*fractionDigits2) / fractionDigits2 + oc_val.InputPowerLower = &rxpowerlowalarm + } + } + if all || targetUriPath == "/openconfig-platform:components/component/openconfig-platform-transceiver:transceiver/thresholds/threshold/state/laser-bias-current-upper" { + transceiverDomThresholdTable := app.transceiverDomThresholdTable[ifName].entry + if transceiverDomThresholdTable.Has("txbiashighalarm") { + txbiashighalarm := math.Floor(compTransceiverThresholdStateDb.txbiashighalarm*fractionDigits2) / fractionDigits2 + oc_val.LaserBiasCurrentUpper = &txbiashighalarm + } + } + if all || targetUriPath == "/openconfig-platform:components/component/openconfig-platform-transceiver:transceiver/thresholds/threshold/state/laser-bias-current-lower" { + transceiverDomThresholdTable := app.transceiverDomThresholdTable[ifName].entry + if transceiverDomThresholdTable.Has("txbiaslowalarm") { + txbiaslowalarm := math.Floor(compTransceiverThresholdStateDb.txbiaslowalarm*fractionDigits2) / fractionDigits2 + oc_val.LaserBiasCurrentLower = &txbiaslowalarm + } + } + } + + if severityName == "WARNING" { + if all || targetUriPath == "/openconfig-platform:components/component/openconfig-platform-transceiver:transceiver/thresholds/threshold/state/laser-temperature-upper" { + transceiverDomThresholdTable := app.transceiverDomThresholdTable[ifName].entry + if transceiverDomThresholdTable.Has("temphighwarning") { + temphighwarning := math.Floor(compTransceiverThresholdStateDb.temphighwarning*fractionDigits1) / fractionDigits1 + oc_val.LaserTemperatureUpper = &temphighwarning + } + } + if all || targetUriPath == "/openconfig-platform:components/component/openconfig-platform-transceiver:transceiver/thresholds/threshold/state/laser-temperature-lower" { + transceiverDomThresholdTable := app.transceiverDomThresholdTable[ifName].entry + if transceiverDomThresholdTable.Has("templowwarning") { + templowwarning := math.Floor(compTransceiverThresholdStateDb.templowwarning*fractionDigits1) / fractionDigits1 + oc_val.LaserTemperatureLower = &templowwarning + } + } + if all || targetUriPath == "/openconfig-platform:components/component/openconfig-platform-transceiver:transceiver/thresholds/threshold/state/supply-voltage-upper" { + transceiverDomThresholdTable := app.transceiverDomThresholdTable[ifName].entry + if transceiverDomThresholdTable.Has("vcchighwarning") { + vcchighwarning := math.Floor(compTransceiverThresholdStateDb.vcchighwarning*fractionDigits2) / fractionDigits2 + oc_val.SupplyVoltageUpper = &vcchighwarning + } + } + if all || targetUriPath == "/openconfig-platform:components/component/openconfig-platform-transceiver:transceiver/thresholds/threshold/state/supply-voltage-lower" { + transceiverDomThresholdTable := app.transceiverDomThresholdTable[ifName].entry + if transceiverDomThresholdTable.Has("vcclowwarning") { + vcclowwarning := math.Floor(compTransceiverThresholdStateDb.vcclowwarning*fractionDigits2) / fractionDigits2 + oc_val.SupplyVoltageLower = &vcclowwarning + } + } + if all || targetUriPath == "/openconfig-platform:components/component/openconfig-platform-transceiver:transceiver/thresholds/threshold/state/output-power-upper" { + transceiverDomThresholdTable := app.transceiverDomThresholdTable[ifName].entry + if transceiverDomThresholdTable.Has("txpowerhighwarning") { + v := math.Floor(compTransceiverThresholdStateDb.txpowerhighwarning*fractionDigits2) / fractionDigits2 + oc_val.OutputPowerUpper = &v + } + } + if all || targetUriPath == "/openconfig-platform:components/component/openconfig-platform-transceiver:transceiver/thresholds/threshold/state/output-power-lower" { + transceiverDomThresholdTable := app.transceiverDomThresholdTable[ifName].entry + if transceiverDomThresholdTable.Has("txpowerlowwarning") { + v := math.Floor(compTransceiverThresholdStateDb.txpowerlowwarning*fractionDigits2) / fractionDigits2 + oc_val.OutputPowerLower = &v + } + } + if all || targetUriPath == "/openconfig-platform:components/component/openconfig-platform-transceiver:transceiver/thresholds/threshold/state/input-power-upper" { + transceiverDomThresholdTable := app.transceiverDomThresholdTable[ifName].entry + if transceiverDomThresholdTable.Has("rxpowerhighwarning") { + v := math.Floor(compTransceiverThresholdStateDb.rxpowerhighwarning*fractionDigits2) / fractionDigits2 + oc_val.InputPowerUpper = &v + } + } + if all || targetUriPath == "/openconfig-platform:components/component/openconfig-platform-transceiver:transceiver/thresholds/threshold/state/input-power-lower" { + transceiverDomThresholdTable := app.transceiverDomThresholdTable[ifName].entry + if transceiverDomThresholdTable.Has("rxpowerlowwarning") { + v := math.Floor(compTransceiverThresholdStateDb.rxpowerlowwarning*fractionDigits2) / fractionDigits2 + oc_val.InputPowerLower = &v + } + } + if all || targetUriPath == "/openconfig-platform:components/component/openconfig-platform-transceiver:transceiver/thresholds/threshold/state/laser-bias-current-upper" { + transceiverDomThresholdTable := app.transceiverDomThresholdTable[ifName].entry + if transceiverDomThresholdTable.Has("txbiashighwarning") { + v := math.Floor(compTransceiverThresholdStateDb.txbiashighwarning*fractionDigits2) / fractionDigits2 + oc_val.LaserBiasCurrentUpper = &v + } + } + if all || targetUriPath == "/openconfig-platform:components/component/openconfig-platform-transceiver:transceiver/thresholds/threshold/state/laser-bias-current-lower" { + transceiverDomThresholdTable := app.transceiverDomThresholdTable[ifName].entry + if transceiverDomThresholdTable.Has("txbiaslowwarning") { + v := math.Floor(compTransceiverThresholdStateDb.txbiaslowwarning*fractionDigits2) / fractionDigits2 + oc_val.LaserBiasCurrentLower = &v + } + } + } + + return nil +} + +func (app *PlatformApp) doGetPlatformInfo() error { + log.Infof("Preparing collection for platform info") + + var err error + pf_cpts := app.getAppRootObject() + var compName string + var severityName string + + targetUriPath, _ := getYangPathFromUri(app.path.Path) + switch targetUriPath { + case "/openconfig-platform:components": + log.Info("case /openconfig-platform:components root") + pf_comp, _ := pf_cpts.NewComponent("System Eeprom") + ygot.BuildEmptyTree(pf_comp) + err = app.getSysEepromFromDb(pf_comp.State, true) + if err != nil { + break + } + + for epItem, _ := range app.transceiverInfoTable { + compName = "transceiver_" + epItem + pf_comp, _ := pf_cpts.NewComponent(compName) + ygot.BuildEmptyTree(pf_comp) + + err = app.getCompStateFromDb(pf_comp.State, true, compName) + if err != nil { + break + } + err = app.getCompTransceiverStateFromDb(pf_comp.Transceiver.State, true, compName) + if err != nil { + break + } + err = app.getCompTransceiverStateSupplyVoltageFromDb(pf_comp.Transceiver.State.SupplyVoltage, true, compName) + if err != nil { + break + } + ifName := strings.Replace(compName, "transceiver_", "", -1) + applPortTable := app.applPortTable[ifName].entry + + pf_channel_0, _ := pf_comp.Transceiver.PhysicalChannels.NewChannel(0) + if pf_channel_0 != nil { + ygot.BuildEmptyTree(pf_channel_0) + err = app.getCompTransceiverPhysicalChannelStateLaserTemperatureFromDb(pf_channel_0.State.LaserTemperature, true, compName) + if err != nil { + break + } + } + + for index, lane := range strings.Split(applPortTable.Get("lanes"), ",") { + laneNum, _ := strconv.ParseUint(lane, 10, 16) + pf_channel, _ := pf_comp.Transceiver.PhysicalChannels.NewChannel(uint16(laneNum)) + if pf_channel != nil { + ygot.BuildEmptyTree(pf_channel) + err = app.getCompTransceiverPhysicalChannelStateOutputPowerFromDb(pf_channel.State.OutputPower, true, compName, uint16(index)) + if err != nil { + break + } + err = app.getCompTransceiverPhysicalChannelStateInputPowerFromDb(pf_channel.State.InputPower, true, compName, uint16(index)) + if err != nil { + break + } + err = app.getCompTransceiverPhysicalChannelStateLaserBiasCurrentFromDb(pf_channel.State.LaserBiasCurrent, true, compName, uint16(index)) + } + } + } + + case "/openconfig-platform:components/component": + log.Info("case /openconfig-platform:components/component root") + compName = app.path.Var("name") + if compName == "" { + pf_comp, _ := pf_cpts.NewComponent("System Eeprom") + ygot.BuildEmptyTree(pf_comp) + err = app.getSysEepromFromDb(pf_comp.State, true) + if err != nil { + break + } + + for epItem, _ := range app.transceiverInfoTable { + compName = "transceiver_" + epItem + pf_comp, _ := pf_cpts.NewComponent(compName) + ygot.BuildEmptyTree(pf_comp) + + err = app.getCompStateFromDb(pf_comp.State, true, compName) + if err != nil { + break + } + err = app.getCompTransceiverStateFromDb(pf_comp.Transceiver.State, true, compName) + if err != nil { + break + } + err = app.getCompTransceiverStateSupplyVoltageFromDb(pf_comp.Transceiver.State.SupplyVoltage, true, compName) + if err != nil { + break + } + ifName := strings.Replace(compName, "transceiver_", "", -1) + applPortTable := app.applPortTable[ifName].entry + + pf_channel_0, _ := pf_comp.Transceiver.PhysicalChannels.NewChannel(0) + if pf_channel_0 != nil { + ygot.BuildEmptyTree(pf_channel_0) + err = app.getCompTransceiverPhysicalChannelStateLaserTemperatureFromDb(pf_channel_0.State.LaserTemperature, true, compName) + if err != nil { + break + } + } + + for index, lane := range strings.Split(applPortTable.Get("lanes"), ",") { + laneNum, _ := strconv.ParseUint(lane, 10, 16) + pf_channel, _ := pf_comp.Transceiver.PhysicalChannels.NewChannel(uint16(laneNum)) + if pf_channel != nil { + ygot.BuildEmptyTree(pf_channel) + err = app.getCompTransceiverPhysicalChannelStateOutputPowerFromDb(pf_channel.State.OutputPower, true, compName, uint16(index)) + if err != nil { + break + } + err = app.getCompTransceiverPhysicalChannelStateInputPowerFromDb(pf_channel.State.InputPower, true, compName, uint16(index)) + if err != nil { + break + } + err = app.getCompTransceiverPhysicalChannelStateLaserBiasCurrentFromDb(pf_channel.State.LaserBiasCurrent, true, compName, uint16(index)) + } + } + } + } else { + if compName != "System Eeprom" && !strings.Contains(compName, "transceiver_Ethernet") { + err = errors.New("Invalid component name") + break + } + pf_comp := pf_cpts.Component[compName] + if pf_comp != nil { + ygot.BuildEmptyTree(pf_comp) + + if compName == "System Eeprom" { + err = app.getSysEepromFromDb(pf_comp.State, true) + } + + if strings.Contains(compName, "transceiver_Ethernet") { + err = app.getCompStateFromDb(pf_comp.State, true, compName) + if err != nil { + break + } + err = app.getCompTransceiverStateFromDb(pf_comp.Transceiver.State, true, compName) + if err != nil { + break + } + err = app.getCompTransceiverStateSupplyVoltageFromDb(pf_comp.Transceiver.State.SupplyVoltage, true, compName) + if err != nil { + break + } + ifName := strings.Replace(compName, "transceiver_", "", -1) + applPortTable := app.applPortTable[ifName].entry + + pf_channel_0, _ := pf_comp.Transceiver.PhysicalChannels.NewChannel(0) + if pf_channel_0 != nil { + ygot.BuildEmptyTree(pf_channel_0) + err = app.getCompTransceiverPhysicalChannelStateLaserTemperatureFromDb(pf_channel_0.State.LaserTemperature, true, compName) + if err != nil { + break + } + } + + for index, lane := range strings.Split(applPortTable.Get("lanes"), ",") { + laneNum, _ := strconv.ParseUint(lane, 10, 16) + pf_channel, _ := pf_comp.Transceiver.PhysicalChannels.NewChannel(uint16(laneNum)) + if pf_channel != nil { + ygot.BuildEmptyTree(pf_channel) + err = app.getCompTransceiverPhysicalChannelStateOutputPowerFromDb(pf_channel.State.OutputPower, true, compName, uint16(index)) + if err != nil { + break + } + err = app.getCompTransceiverPhysicalChannelStateInputPowerFromDb(pf_channel.State.InputPower, true, compName, uint16(index)) + if err != nil { + break + } + err = app.getCompTransceiverPhysicalChannelStateLaserBiasCurrentFromDb(pf_channel.State.LaserBiasCurrent, true, compName, uint16(index)) + } + } + } + } else { + err = errors.New("Invalid input component name") + } + } + case "/openconfig-platform:components/component/state": + log.Info("case /openconfig-platform:components/component/state root") + compName = app.path.Var("name") + if compName == "System Eeprom" { + pf_comp := pf_cpts.Component[compName] + if pf_comp != nil { + ygot.BuildEmptyTree(pf_comp) + err = app.getSysEepromFromDb(pf_comp.State, true) + } else { + err = errors.New("Invalid input component name") + } + } else if strings.Contains(compName, "transceiver_Ethernet") { + pf_comp := pf_cpts.Component[compName] + if pf_comp != nil { + ygot.BuildEmptyTree(pf_comp) + err = app.getCompStateFromDb(pf_comp.State, true, compName) + } else { + err = errors.New("Invalid input component name") + } + } else { + err = errors.New("Invalid component name ") + } + case "/openconfig-platform:components/component/openconfig-platform-transceiver:transceiver": + log.Info("case /openconfig-platform:components/component/openconfig-platform-transceiver:transceiver root") + compName = app.path.Var("name") + if strings.Contains(compName, "transceiver_Ethernet") { + pf_comp := pf_cpts.Component[compName] + if pf_comp != nil { + ygot.BuildEmptyTree(pf_comp.Transceiver) + err = app.getCompTransceiverStateFromDb(pf_comp.Transceiver.State, true, compName) + if err != nil { + break + } + err = app.getCompTransceiverStateSupplyVoltageFromDb(pf_comp.Transceiver.State.SupplyVoltage, true, compName) + if err != nil { + break + } + ifName := strings.Replace(compName, "transceiver_", "", -1) + applPortTable := app.applPortTable[ifName].entry + + pf_channel_0, _ := pf_comp.Transceiver.PhysicalChannels.NewChannel(0) + if pf_channel_0 != nil { + ygot.BuildEmptyTree(pf_channel_0) + err = app.getCompTransceiverPhysicalChannelStateLaserTemperatureFromDb(pf_channel_0.State.LaserTemperature, true, compName) + if err != nil { + break + } + } + + for index, lane := range strings.Split(applPortTable.Get("lanes"), ",") { + laneNum, _ := strconv.ParseUint(lane, 10, 16) + pf_channel, _ := pf_comp.Transceiver.PhysicalChannels.NewChannel(uint16(laneNum)) + if pf_channel != nil { + ygot.BuildEmptyTree(pf_channel) + err = app.getCompTransceiverPhysicalChannelStateOutputPowerFromDb(pf_channel.State.OutputPower, true, compName, uint16(index)) + if err != nil { + break + } + err = app.getCompTransceiverPhysicalChannelStateInputPowerFromDb(pf_channel.State.InputPower, true, compName, uint16(index)) + if err != nil { + break + } + err = app.getCompTransceiverPhysicalChannelStateLaserBiasCurrentFromDb(pf_channel.State.LaserBiasCurrent, true, compName, uint16(index)) + } + } + } else { + err = errors.New("Invalid input component name") + } + } else { + err = errors.New("Invalid component name ") + } + case "/openconfig-platform:components/component/openconfig-platform-transceiver:transceiver/state": + log.Info("case /openconfig-platform:components/component/openconfig-platform-transceiver:transceiver/state root") + compName = app.path.Var("name") + if strings.Contains(compName, "transceiver_Ethernet") { + pf_comp := pf_cpts.Component[compName] + if pf_comp != nil { + ygot.BuildEmptyTree(pf_comp.Transceiver.State) + err = app.getCompTransceiverStateFromDb(pf_comp.Transceiver.State, true, compName) + if err != nil { + break + } + err = app.getCompTransceiverStateSupplyVoltageFromDb(pf_comp.Transceiver.State.SupplyVoltage, true, compName) + } else { + err = errors.New("Invalid input component name") + } + } else { + err = errors.New("Invalid component name ") + } + case "/openconfig-platform:components/component/openconfig-platform-transceiver:transceiver/state/supply-voltage": + log.Info("case /openconfig-platform:components/component/openconfig-platform-transceiver:transceiver/state/supply-voltage root") + compName = app.path.Var("name") + if strings.Contains(compName, "transceiver_Ethernet") { + pf_comp := pf_cpts.Component[compName] + if pf_comp != nil { + ygot.BuildEmptyTree(pf_comp) + err = app.getCompTransceiverStateSupplyVoltageFromDb(pf_comp.Transceiver.State.SupplyVoltage, true, compName) + } else { + err = errors.New("Invalid input component name") + } + } else { + err = errors.New("Invalid component name ") + } + case "/openconfig-platform:components/component/openconfig-platform-transceiver:transceiver/physical-channels": + log.Info("case /openconfig-platform:components/component/openconfig-platform-transceiver:transceiver/physical-channels root") + compName = app.path.Var("name") + if strings.Contains(compName, "transceiver_Ethernet") { + pf_comp := pf_cpts.Component[compName] + if pf_comp != nil { + ygot.BuildEmptyTree(pf_comp) + ifName := strings.Replace(compName, "transceiver_", "", -1) + applPortTable := app.applPortTable[ifName].entry + + pf_channel_0, _ := pf_comp.Transceiver.PhysicalChannels.NewChannel(0) + if pf_channel_0 != nil { + ygot.BuildEmptyTree(pf_channel_0) + err = app.getCompTransceiverPhysicalChannelStateLaserTemperatureFromDb(pf_channel_0.State.LaserTemperature, true, compName) + if err != nil { + break + } + } + + for index, lane := range strings.Split(applPortTable.Get("lanes"), ",") { + laneNum, _ := strconv.ParseUint(lane, 10, 16) + pf_channel, _ := pf_comp.Transceiver.PhysicalChannels.NewChannel(uint16(laneNum)) + if pf_channel != nil { + ygot.BuildEmptyTree(pf_channel) + err = app.getCompTransceiverPhysicalChannelStateOutputPowerFromDb(pf_channel.State.OutputPower, true, compName, uint16(index)) + if err != nil { + break + } + err = app.getCompTransceiverPhysicalChannelStateInputPowerFromDb(pf_channel.State.InputPower, true, compName, uint16(index)) + if err != nil { + break + } + err = app.getCompTransceiverPhysicalChannelStateLaserBiasCurrentFromDb(pf_channel.State.LaserBiasCurrent, true, compName, uint16(index)) + } + } + } else { + err = errors.New("Invalid input component name") + } + } else { + err = errors.New("Invalid component name ") + } + case "/openconfig-platform:components/component/openconfig-platform-transceiver:transceiver/physical-channels/channel": + log.Info("case /openconfig-platform:components/component/openconfig-platform-transceiver:transceiver/physical-channels/channel root") + compName = app.path.Var("name") + if strings.Contains(compName, "transceiver_Ethernet") { + pf_comp := pf_cpts.Component[compName] + if pf_comp != nil { + ygot.BuildEmptyTree(pf_comp) + indexName := app.path.Var("index") + if indexName == "" { + ifName := strings.Replace(compName, "transceiver_", "", -1) + applPortTable := app.applPortTable[ifName].entry + + pf_channel_0, _ := pf_comp.Transceiver.PhysicalChannels.NewChannel(0) + if pf_channel_0 != nil { + ygot.BuildEmptyTree(pf_channel_0) + err = app.getCompTransceiverPhysicalChannelStateLaserTemperatureFromDb(pf_channel_0.State.LaserTemperature, true, compName) + if err != nil { + break + } + } + + for index, lane := range strings.Split(applPortTable.Get("lanes"), ",") { + laneNum, _ := strconv.ParseUint(lane, 10, 16) + pf_channel, _ := pf_comp.Transceiver.PhysicalChannels.NewChannel(uint16(laneNum)) + if pf_channel != nil { + ygot.BuildEmptyTree(pf_channel) + err = app.getCompTransceiverPhysicalChannelStateOutputPowerFromDb(pf_channel.State.OutputPower, true, compName, uint16(index)) + if err != nil { + break + } + err = app.getCompTransceiverPhysicalChannelStateInputPowerFromDb(pf_channel.State.InputPower, true, compName, uint16(index)) + if err != nil { + break + } + err = app.getCompTransceiverPhysicalChannelStateLaserBiasCurrentFromDb(pf_channel.State.LaserBiasCurrent, true, compName, uint16(index)) + } + } + } else { + compIndex, _ := strconv.ParseUint(indexName, 10, 16) + log.Info("compIndex =", compIndex) + ifName := strings.Replace(compName, "transceiver_", "", -1) + applPortTable := app.applPortTable[ifName].entry + + if compIndex == 0 { + pf_channel := pf_comp.Transceiver.PhysicalChannels.Channel[uint16(compIndex)] + if pf_channel != nil { + ygot.BuildEmptyTree(pf_channel) + err = app.getCompTransceiverPhysicalChannelStateLaserTemperatureFromDb(pf_channel.State.LaserTemperature, true, compName) + } else { + err = errors.New("Invalid input component index") + } + } else { + for index, lane := range strings.Split(applPortTable.Get("lanes"), ",") { + laneNum, _ := strconv.ParseUint(lane, 10, 16) + if uint16(laneNum) == uint16(compIndex) { + pf_channel := pf_comp.Transceiver.PhysicalChannels.Channel[uint16(compIndex)] + if pf_channel != nil { + ygot.BuildEmptyTree(pf_channel) + err = app.getCompTransceiverPhysicalChannelStateOutputPowerFromDb(pf_channel.State.OutputPower, true, compName, uint16(index)) + if err != nil { + break + } + err = app.getCompTransceiverPhysicalChannelStateInputPowerFromDb(pf_channel.State.InputPower, true, compName, uint16(index)) + if err != nil { + break + } + err = app.getCompTransceiverPhysicalChannelStateLaserBiasCurrentFromDb(pf_channel.State.LaserBiasCurrent, true, compName, uint16(index)) + } else { + err = errors.New("Invalid input component index") + } + break + } else { + err = errors.New("Invalid input component index") + } + } + } + } + } else { + err = errors.New("Invalid input component name") + } + } else { + err = errors.New("Invalid component name ") + } + case "/openconfig-platform:components/component/openconfig-platform-transceiver:transceiver/physical-channels/channel/state": + log.Info("case /openconfig-platform:components/component/openconfig-platform-transceiver:transceiver/physical-channels/channel/state root") + compName = app.path.Var("name") + if strings.Contains(compName, "transceiver_Ethernet") { + pf_comp := pf_cpts.Component[compName] + if pf_comp != nil { + ygot.BuildEmptyTree(pf_comp) + compIndex, _ := strconv.ParseUint(app.path.Var("index"), 10, 16) + log.Info("compIndex =", compIndex) + ifName := strings.Replace(compName, "transceiver_", "", -1) + applPortTable := app.applPortTable[ifName].entry + + if compIndex == 0 { + pf_channel := pf_comp.Transceiver.PhysicalChannels.Channel[uint16(compIndex)] + if pf_channel != nil { + ygot.BuildEmptyTree(pf_channel.State) + err = app.getCompTransceiverPhysicalChannelStateLaserTemperatureFromDb(pf_channel.State.LaserTemperature, true, compName) + } else { + err = errors.New("Invalid input component index") + } + } else { + for index, lane := range strings.Split(applPortTable.Get("lanes"), ",") { + laneNum, _ := strconv.ParseUint(lane, 10, 16) + if uint16(laneNum) == uint16(compIndex) { + pf_channel := pf_comp.Transceiver.PhysicalChannels.Channel[uint16(compIndex)] + if pf_channel != nil { + ygot.BuildEmptyTree(pf_channel.State) + err = app.getCompTransceiverPhysicalChannelStateOutputPowerFromDb(pf_channel.State.OutputPower, true, compName, uint16(index)) + if err != nil { + break + } + err = app.getCompTransceiverPhysicalChannelStateInputPowerFromDb(pf_channel.State.InputPower, true, compName, uint16(index)) + if err != nil { + break + } + err = app.getCompTransceiverPhysicalChannelStateLaserBiasCurrentFromDb(pf_channel.State.LaserBiasCurrent, true, compName, uint16(index)) + } else { + err = errors.New("Invalid input component index") + } + break + } else { + err = errors.New("Invalid input component index") + } + } + } + } else { + err = errors.New("Invalid input component name") + } + } else { + err = errors.New("Invalid component name ") + } + case "/openconfig-platform:components/component/openconfig-platform-transceiver:transceiver/physical-channels/channel/state/laser-temperature": + log.Info("case /openconfig-platform:components/component/openconfig-platform-transceiver:transceiver/physical-channels/channel/state/laser-temperature root") + compName = app.path.Var("name") + if strings.Contains(compName, "transceiver_Ethernet") { + pf_comp := pf_cpts.Component[compName] + if pf_comp != nil { + ygot.BuildEmptyTree(pf_comp) + compIndex, _ := strconv.ParseUint(app.path.Var("index"), 10, 16) + log.Info("compIndex =", compIndex) + + if compIndex == 0 { + pf_channel := pf_comp.Transceiver.PhysicalChannels.Channel[uint16(compIndex)] + if pf_channel != nil { + ygot.BuildEmptyTree(pf_channel.State) + err = app.getCompTransceiverPhysicalChannelStateLaserTemperatureFromDb(pf_channel.State.LaserTemperature, true, compName) + } else { + err = errors.New("Invalid input component index") + } + } else { + err = errors.New("Invalid input component index") + } + } else { + err = errors.New("Invalid input component name") + } + } else { + err = errors.New("Invalid component name ") + } + case "/openconfig-platform:components/component/openconfig-platform-transceiver:transceiver/physical-channels/channel/state/output-power": + log.Info("case /openconfig-platform:components/component/openconfig-platform-transceiver:transceiver/physical-channels/channel/state/output-power root") + compName = app.path.Var("name") + if strings.Contains(compName, "transceiver_Ethernet") { + pf_comp := pf_cpts.Component[compName] + if pf_comp != nil { + ygot.BuildEmptyTree(pf_comp) + compIndex, _ := strconv.ParseUint(app.path.Var("index"), 10, 16) + log.Info("compIndex =", compIndex) + ifName := strings.Replace(compName, "transceiver_", "", -1) + applPortTable := app.applPortTable[ifName].entry + + for index, lane := range strings.Split(applPortTable.Get("lanes"), ",") { + laneNum, _ := strconv.ParseUint(lane, 10, 16) + if uint16(laneNum) == uint16(compIndex) { + pf_channel := pf_comp.Transceiver.PhysicalChannels.Channel[uint16(compIndex)] + if pf_channel != nil { + ygot.BuildEmptyTree(pf_channel.State) + err = app.getCompTransceiverPhysicalChannelStateOutputPowerFromDb(pf_channel.State.OutputPower, true, compName, uint16(index)) + } else { + err = errors.New("Invalid input component index") + } + break + } else { + err = errors.New("Invalid input component index") + } + } + } else { + err = errors.New("Invalid input component name") + } + } else { + err = errors.New("Invalid component name ") + } + case "/openconfig-platform:components/component/openconfig-platform-transceiver:transceiver/physical-channels/channel/state/input-power": + log.Info("case /openconfig-platform:components/component/openconfig-platform-transceiver:transceiver/physical-channels/channel/state/input-power root") + compName = app.path.Var("name") + if strings.Contains(compName, "transceiver_Ethernet") { + pf_comp := pf_cpts.Component[compName] + if pf_comp != nil { + ygot.BuildEmptyTree(pf_comp) + compIndex, _ := strconv.ParseUint(app.path.Var("index"), 10, 16) + log.Info("compIndex =", compIndex) + ifName := strings.Replace(compName, "transceiver_", "", -1) + applPortTable := app.applPortTable[ifName].entry + + for index, lane := range strings.Split(applPortTable.Get("lanes"), ",") { + laneNum, _ := strconv.ParseUint(lane, 10, 16) + if uint16(laneNum) == uint16(compIndex) { + pf_channel := pf_comp.Transceiver.PhysicalChannels.Channel[uint16(compIndex)] + if pf_channel != nil { + ygot.BuildEmptyTree(pf_channel.State) + err = app.getCompTransceiverPhysicalChannelStateInputPowerFromDb(pf_channel.State.InputPower, true, compName, uint16(index)) + } else { + err = errors.New("Invalid input component index") + } + break + } else { + err = errors.New("Invalid input component index") + } + } + } else { + err = errors.New("Invalid input component name") + } + } else { + err = errors.New("Invalid component name ") + } + case "/openconfig-platform:components/component/openconfig-platform-transceiver:transceiver/physical-channels/channel/state/laser-bias-current": + log.Info("case /openconfig-platform:components/component/openconfig-platform-transceiver:transceiver/physical-channels/channel/state/laser-bias-current root") + compName = app.path.Var("name") + if strings.Contains(compName, "transceiver_Ethernet") { + pf_comp := pf_cpts.Component[compName] + if pf_comp != nil { + ygot.BuildEmptyTree(pf_comp) + compIndex, _ := strconv.ParseUint(app.path.Var("index"), 10, 16) + log.Info("compIndex =", compIndex) + ifName := strings.Replace(compName, "transceiver_", "", -1) + applPortTable := app.applPortTable[ifName].entry + + for index, lane := range strings.Split(applPortTable.Get("lanes"), ",") { + laneNum, _ := strconv.ParseUint(lane, 10, 16) + if uint16(laneNum) == uint16(compIndex) { + pf_channel := pf_comp.Transceiver.PhysicalChannels.Channel[uint16(compIndex)] + if pf_channel != nil { + ygot.BuildEmptyTree(pf_channel.State) + err = app.getCompTransceiverPhysicalChannelStateLaserBiasCurrentFromDb(pf_channel.State.LaserBiasCurrent, true, compName, uint16(index)) + } else { + err = errors.New("Invalid input component index") + } + break + } else { + err = errors.New("Invalid input component index") + } + } + } else { + err = errors.New("Invalid input component name") + } + } else { + err = errors.New("Invalid component name ") + } + case "/openconfig-platform:components/component/openconfig-platform-transceiver:transceiver/thresholds/threshold/state": + log.Info("case /openconfig-platform:components/component/openconfig-platform-transceiver:transceiver/thresholds/threshold/state root") + compName = app.path.Var("name") + if strings.Contains(compName, "transceiver_Ethernet") { + pf_comp := pf_cpts.Component[compName] + if pf_comp != nil { + ygot.BuildEmptyTree(pf_comp) + severityName = app.path.Var("severity") + if strings.Contains(severityName, "CRITICAL") { + pf_threshold := pf_comp.Transceiver.Thresholds.Threshold[ocbinds.OpenconfigAlarmTypes_OPENCONFIG_ALARM_SEVERITY_CRITICAL] + if pf_threshold != nil { + ygot.BuildEmptyTree(pf_threshold.State) + err = app.getCompTransceiverThresholdStateFromDb(pf_threshold.State, true, compName, severityName) + } else { + err = errors.New("Invalid input severity name") + } + } else if strings.Contains(severityName, "WARNING") { + pf_threshold := pf_comp.Transceiver.Thresholds.Threshold[ocbinds.OpenconfigAlarmTypes_OPENCONFIG_ALARM_SEVERITY_WARNING] + if pf_threshold != nil { + ygot.BuildEmptyTree(pf_threshold.State) + err = app.getCompTransceiverThresholdStateFromDb(pf_threshold.State, true, compName, severityName) + } else { + err = errors.New("Invalid input severity name") + } + } else { + err = errors.New("Invalid input severity name") + } + } else { + err = errors.New("Invalid input component name") + } + } else { + err = errors.New("Invalid component name ") + } + + default: + if isSubtreeRequest(targetUriPath, "/openconfig-platform:components/component/state") { + compName = app.path.Var("name") + if compName == "System Eeprom" { + pf_comp := pf_cpts.Component[compName] + if pf_comp != nil { + ygot.BuildEmptyTree(pf_comp) + err = app.getSysEepromFromDb(pf_comp.State, false) + } else { + err = errors.New("Invalid input component name") + } + } else if strings.Contains(compName, "transceiver_Ethernet") { + pf_comp := pf_cpts.Component[compName] + if pf_comp != nil { + ygot.BuildEmptyTree(pf_comp) + err = app.getCompStateFromDb(pf_comp.State, false, compName) + } else { + err = errors.New("Invalid input component name") + } + } else { + err = errors.New("Invalid input component name") + } + } else if isSubtreeRequest(targetUriPath, "/openconfig-platform:components/component/openconfig-platform-transceiver:transceiver/state/supply-voltage") { + compName = app.path.Var("name") + if strings.Contains(compName, "transceiver_Ethernet") { + pf_comp := pf_cpts.Component[compName] + if pf_comp != nil { + ygot.BuildEmptyTree(pf_comp) + err = app.getCompTransceiverStateSupplyVoltageFromDb(pf_comp.Transceiver.State.SupplyVoltage, false, compName) + } else { + err = errors.New("Invalid input component name") + } + } else { + err = errors.New("Invalid input component name") + } + } else if isSubtreeRequest(targetUriPath, "/openconfig-platform:components/component/openconfig-platform-transceiver:transceiver/state") { + compName = app.path.Var("name") + if strings.Contains(compName, "transceiver_Ethernet") { + pf_comp := pf_cpts.Component[compName] + if pf_comp != nil { + ygot.BuildEmptyTree(pf_comp) + err = app.getCompTransceiverStateFromDb(pf_comp.Transceiver.State, false, compName) + } else { + err = errors.New("Invalid input component name") + } + } else { + err = errors.New("Invalid input component name") + } + } else if isSubtreeRequest(targetUriPath, "/openconfig-platform:components/component/openconfig-platform-transceiver:transceiver/physical-channels/channel/state/laser-temperature") { + compName = app.path.Var("name") + if strings.Contains(compName, "transceiver_Ethernet") { + pf_comp := pf_cpts.Component[compName] + if pf_comp != nil { + ygot.BuildEmptyTree(pf_comp) + compIndex, _ := strconv.ParseUint(app.path.Var("index"), 10, 16) + + if compIndex == 0 { + pf_channel := pf_comp.Transceiver.PhysicalChannels.Channel[uint16(compIndex)] + if pf_channel != nil { + ygot.BuildEmptyTree(pf_channel.State) + err = app.getCompTransceiverPhysicalChannelStateLaserTemperatureFromDb(pf_channel.State.LaserTemperature, false, compName) + } else { + err = errors.New("Invalid input component index") + } + } else { + err = errors.New("Invalid input component index") + } + } else { + err = errors.New("Invalid input component name") + } + } else { + err = errors.New("Invalid input component name") + } + } else if isSubtreeRequest(targetUriPath, "/openconfig-platform:components/component/openconfig-platform-transceiver:transceiver/physical-channels/channel/state/output-power") { + compName = app.path.Var("name") + if strings.Contains(compName, "transceiver_Ethernet") { + pf_comp := pf_cpts.Component[compName] + if pf_comp != nil { + ygot.BuildEmptyTree(pf_comp) + compIndex, _ := strconv.ParseUint(app.path.Var("index"), 10, 16) + ifName := strings.Replace(compName, "transceiver_", "", -1) + applPortTable := app.applPortTable[ifName].entry + + for index, lane := range strings.Split(applPortTable.Get("lanes"), ",") { + laneNum, _ := strconv.ParseUint(lane, 10, 16) + if uint16(laneNum) == uint16(compIndex) { + pf_channel := pf_comp.Transceiver.PhysicalChannels.Channel[uint16(compIndex)] + if pf_channel != nil { + ygot.BuildEmptyTree(pf_channel.State) + err = app.getCompTransceiverPhysicalChannelStateOutputPowerFromDb(pf_channel.State.OutputPower, false, compName, uint16(index)) + } else { + err = errors.New("Invalid input component index") + } + break + } else { + err = errors.New("Invalid input component index") + } + } + } else { + err = errors.New("Invalid input component name") + } + } else { + err = errors.New("Invalid input component name") + } + } else if isSubtreeRequest(targetUriPath, "/openconfig-platform:components/component/openconfig-platform-transceiver:transceiver/physical-channels/channel/state/input-power") { + compName = app.path.Var("name") + if strings.Contains(compName, "transceiver_Ethernet") { + pf_comp := pf_cpts.Component[compName] + if pf_comp != nil { + ygot.BuildEmptyTree(pf_comp) + compIndex, _ := strconv.ParseUint(app.path.Var("index"), 10, 16) + ifName := strings.Replace(compName, "transceiver_", "", -1) + applPortTable := app.applPortTable[ifName].entry + + for index, lane := range strings.Split(applPortTable.Get("lanes"), ",") { + laneNum, _ := strconv.ParseUint(lane, 10, 16) + if uint16(laneNum) == uint16(compIndex) { + pf_channel := pf_comp.Transceiver.PhysicalChannels.Channel[uint16(compIndex)] + if pf_channel != nil { + ygot.BuildEmptyTree(pf_channel.State) + err = app.getCompTransceiverPhysicalChannelStateInputPowerFromDb(pf_channel.State.InputPower, false, compName, uint16(index)) + } else { + err = errors.New("Invalid input component index") + } + break + } else { + err = errors.New("Invalid input component index") + } + } + } else { + err = errors.New("Invalid input component name") + } + } else { + err = errors.New("Invalid input component name") + } + } else if isSubtreeRequest(targetUriPath, "/openconfig-platform:components/component/openconfig-platform-transceiver:transceiver/physical-channels/channel/state/laser-bias-current") { + compName = app.path.Var("name") + if strings.Contains(compName, "transceiver_Ethernet") { + pf_comp := pf_cpts.Component[compName] + if pf_comp != nil { + ygot.BuildEmptyTree(pf_comp) + compIndex, _ := strconv.ParseUint(app.path.Var("index"), 10, 16) + ifName := strings.Replace(compName, "transceiver_", "", -1) + applPortTable := app.applPortTable[ifName].entry + + for index, lane := range strings.Split(applPortTable.Get("lanes"), ",") { + laneNum, _ := strconv.ParseUint(lane, 10, 16) + if uint16(laneNum) == uint16(compIndex) { + pf_channel := pf_comp.Transceiver.PhysicalChannels.Channel[uint16(compIndex)] + if pf_channel != nil { + ygot.BuildEmptyTree(pf_channel.State) + err = app.getCompTransceiverPhysicalChannelStateLaserBiasCurrentFromDb(pf_channel.State.LaserBiasCurrent, false, compName, uint16(index)) + } else { + err = errors.New("Invalid input component index") + } + break + } else { + err = errors.New("Invalid input component index") + } + } + } else { + err = errors.New("Invalid input component name") + } + } else { + err = errors.New("Invalid input component name") + } + } else if isSubtreeRequest(targetUriPath, "/openconfig-platform:components/component/openconfig-platform-transceiver:transceiver/thresholds/threshold/state") { + compName = app.path.Var("name") + if strings.Contains(compName, "transceiver_Ethernet") { + pf_comp := pf_cpts.Component[compName] + if pf_comp != nil { + ygot.BuildEmptyTree(pf_comp) + severityName = app.path.Var("severity") + if strings.Contains(severityName, "CRITICAL") { + pf_threshold := pf_comp.Transceiver.Thresholds.Threshold[ocbinds.OpenconfigAlarmTypes_OPENCONFIG_ALARM_SEVERITY_CRITICAL] + if pf_threshold != nil { + ygot.BuildEmptyTree(pf_threshold.State) + err = app.getCompTransceiverThresholdStateFromDb(pf_threshold.State, false, compName, severityName) + } else { + err = errors.New("Invalid input severity name") + } + } else if strings.Contains(severityName, "WARNING") { + pf_threshold := pf_comp.Transceiver.Thresholds.Threshold[ocbinds.OpenconfigAlarmTypes_OPENCONFIG_ALARM_SEVERITY_WARNING] + if pf_threshold != nil { + ygot.BuildEmptyTree(pf_threshold.State) + err = app.getCompTransceiverThresholdStateFromDb(pf_threshold.State, false, compName, severityName) + } else { + err = errors.New("Invalid input severity name") + } + } else { + err = errors.New("Invalid input severity name") + } + } else { + err = errors.New("Invalid input component name") + } + } else { + err = errors.New("Invalid input component name") } } else { err = errors.New("Invalid Path")