optical

package
v1.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 20, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CustomFieldValue

func CustomFieldValue(fields map[string]any, names ...string) any

CustomFieldValue picks the first non-empty NetBox custom-field value among names (optical_role before optical_kind). Selection extras may be a bare string or {"value": "..."}.

func DeletePathForService

func DeletePathForService(tx *gorm.DB, serviceID uint) error

DeletePathForService removes path + hops for a service (used on service delete).

func FreqFromITU

func FreqFromITU(channel int, gridGHz float64) uint64

FreqFromITU maps a G.694.1 channel number on a grid (GHz) onto Hz. Anchor: channel 0 ≈ 193.1 THz on the 50 GHz grid is conventional for "type a channel" — we use 193.1 THz as channel 0 of the 50 GHz grid (ITU C-band often numbers from 190+). Default UI grid is 50 GHz.

Here channel N on a 50 GHz grid is 193.1 THz + N*50 GHz. Negative channels are allowed (below 193.1 THz).

func HzFromNm

func HzFromNm(nm float64) uint64

HzFromNm converts a wavelength in nm to Hz.

func HzFromTHz

func HzFromTHz(thz float64) uint64

HzFromTHz converts THz to Hz.

func LoadKindMaps

func LoadKindMaps(db *gorm.DB) (map[string]string, error)

LoadKindMaps returns netbox_role_name → optical_kind (names already lower).

func MarkStaleByConnection

func MarkStaleByConnection(db *gorm.DB, connectionID uint) error

MarkStaleByConnection marks paths whose hops reference the connection.

func MarkStaleByDevice added in v1.0.4

func MarkStaleByDevice(db *gorm.DB, deviceID uint) error

MarkStaleByDevice marks paths that hop through the chassis or its ports.

func MarkStaleByInterface

func MarkStaleByInterface(db *gorm.DB, interfaceID uint) error

MarkStaleByInterface marks paths whose hops reference the interface.

func Nm

func Nm(hz uint64) float64

Nm converts Hz to nanometres. Returns 0 if hz is 0.

func NormalizeOpticalKindCF

func NormalizeOpticalKindCF(raw any) string

NormalizeOpticalKindCF accepts a NetBox custom-field value: a bare string, or a map/struct with a "value" key (selection extras). Invalid or empty returns "". Aliases (transponder/muxponder) become wdm_shelf.

func NormalizeOpticalPortRole

func NormalizeOpticalPortRole(raw any) string

NormalizeOpticalPortRole accepts the same CF shapes as NormalizeOpticalKindCF for an interface optical_role. Invalid/empty → "".

func OpticalEnabled

func OpticalEnabled(db *gorm.DB) bool

OpticalEnabled reports Settings.OpticalEnabled (nil/false = off).

func RebuildPath

func RebuildPath(db *gorm.DB, g *Graph, serviceID uint) error

RebuildPath traces and replaces hops for one service.

func RebuildStale

func RebuildStale(db *gorm.DB) error

RebuildStale loads the graph once and rebuilds every stale/incomplete path.

func ReresolveAllKinds

func ReresolveAllKinds(db *gorm.DB) error

ReresolveAllKinds rewrites Device.OpticalKind from persisted CF then map.

func ResolveOpticalKind

func ResolveOpticalKind(cf, role string, maps map[string]string) string

ResolveOpticalKind is CF-then-map. maps keyed by lowercased role name.

func THz

func THz(hz uint64) float64

THz converts Hz to terahertz.

func ValidateXConnect

func ValidateXConnect(db *gorm.DB, xc *models.OpticalXConnect) error

ValidateXConnect checks one xconnect against the design rules.

Types

type ApplyResult added in v1.0.4

type ApplyResult struct {
	Kind              string   `json:"kind"`
	PortsUpserted     int      `json:"ports_upserted"`
	PortsSkipped      []string `json:"ports_skipped,omitempty"`
	XConnectsUpserted int      `json:"xconnects_upserted"`
	XConnectsDeleted  int      `json:"xconnects_deleted"`
	XConnectsSkipped  []string `json:"xconnects_skipped,omitempty"`
}

ApplyResult is what ApplyInventory changed (and skipped).

func ApplyInventory added in v1.0.4

func ApplyInventory(db *gorm.DB, deviceID uint, inv Inventory) (*ApplyResult, error)

ApplyInventory upserts Device.OpticalKind, OpticalPort rows, and driver-sourced OpticalXConnects for one chassis. Operator-created xconnects (Source empty) are left alone. Passthrough xconnects from inventory are skipped: ILA/passive walk uses OpticalKind, and ROADM internal-links are not λ adjacencies.

type DeviceImpact

type DeviceImpact struct {
	DeviceID      uint        `json:"device_id"`
	Status        string      `json:"status"`
	ServiceCount  int         `json:"service_count"`
	CustomerCount int         `json:"customer_count"`
	Services      []ImpactRow `json:"services"`
}

DeviceImpact is the payload for GET /api/device/:id/impact.

func DeviceDownImpact

func DeviceDownImpact(db *gorm.DB, deviceID uint) (DeviceImpact, error)

DeviceDownImpact unions ELINE endpoints and optical device hops.

type Graph

type Graph struct {
	Ifaces       map[uint]models.Interface
	Devices      map[uint]models.Device
	Ports        map[uint]models.OpticalPort // by interface
	ConnsByIface map[uint][]models.Connection
	XCsByIface   map[uint][]models.OpticalXConnect
	Conns        map[uint]models.Connection
	XCs          map[uint]models.OpticalXConnect
}

Graph is an in-memory adjacency list for one walk or a RebuildStale batch.

func LoadGraph

func LoadGraph(db *gorm.DB) (*Graph, error)

LoadGraph loads every connection, xconnect, optical port, and the devices/interfaces they touch.

type Hop

type Hop struct {
	Kind         string
	InterfaceID  *uint
	ConnectionID *uint
	XConnectID   *uint
	DeviceID     *uint
	FreqHz       uint64
	Label        string
}

Hop is one walk step (same shape as ServiceHop, without IDs).

type ImpactRow

type ImpactRow struct {
	ServiceID  uint   `json:"id"`
	ServiceRef string `json:"service_id"`
	Category   string `json:"category"`
	CustomerID uint   `json:"customer_id"`
	Customer   string `json:"customer"`
	Source     string `json:"source"`
}

ImpactRow is one affected service.

func ResourceImpact

func ResourceImpact(db *gorm.DB, resourceType string, resourceID uint) ([]ImpactRow, error)

ResourceImpact lists VL/VI/LF/LI services whose hops touch the resource, or the service itself when the resource is a wavelength/fiber service.

func ResourcesImpact added in v1.0.5

func ResourcesImpact(db *gorm.DB, resources []models.MaintenanceResource) ([]ImpactRow, error)

ResourcesImpact unions ResourceImpact across every attached resource, de-duplicated by services.id.

type Inventory added in v1.0.4

type Inventory struct {
	Kind      string              `json:"optical_kind"`
	Source    string              `json:"source"`
	Ports     []InventoryPort     `json:"ports"`
	XConnects []InventoryXConnect `json:"xconnects"`
}

Inventory is one device's optical ports and intra-device xconnects, as produced by a read-only driver (Open ROADM GetOpticalInventory) and applied onto Factum tables.

type InventoryPort added in v1.0.4

type InventoryPort struct {
	Name   string `json:"name"`
	Role   string `json:"role"`
	FreqHz uint64 `json:"freq_hz"`
}

type InventoryXConnect added in v1.0.4

type InventoryXConnect struct {
	Name   string `json:"name"`
	Kind   string `json:"kind"`
	PortA  string `json:"port_a"`
	PortB  string `json:"port_b"`
	FreqHz uint64 `json:"freq_hz"`
}

type Result

type Result struct {
	Status      string
	FreqHz      uint64
	Error       string
	Hops        []Hop
	Tributaries []uint
	StartKind   string
}

Result is the outcome of a walk.

func Walk

func Walk(g *Graph, startID, zID uint, mode string) Result

Walk traces from startID. If zID != 0 the walk is "complete" only if Z is reached.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL