Skip to content
generated.go 597 KiB
Newer Older
// Copyright 2022-2025 ETSI SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
Lluis Gifre Renom's avatar
Lluis Gifre Renom committed
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/*
Package gostruct is a generated package which contains definitions
of structs which represent a YANG schema. The generated schema can be
compressed by a series of transformations (compression was false
in this case).

This package was generated by /usr/share/gocode/src/github.com/openconfig/ygot/ygen/commongen.go
using the following YANG input files:
	- /root/public/release/models/optical-transport/openconfig-terminal-device.yang
	- /root/public/release/models/types/openconfig-types.yang
	- /root/public/release/models/openconfig-extensions.yang
	- /root/public/release/models/platform/openconfig-platform-types.yang
	- /root/public/release/models/system/openconfig-alarm-types.yang
	- /root/public/release/models/lldp/openconfig-lldp.yang
	- /root/public/release/models/interfaces/openconfig-interfaces.yang
Imported modules were sourced from:
*/
package gostruct

import (
	"encoding/json"
	"fmt"
	"reflect"

	"github.com/openconfig/ygot/ygot"
	"github.com/openconfig/goyang/pkg/yang"
	"github.com/openconfig/ygot/ytypes"
)

// Binary is a type that is used for fields that have a YANG type of
// binary. It is used such that binary fields can be distinguished from
// leaf-lists of uint8s (which are mapped to []uint8, equivalent to
// []byte in reflection).
type Binary []byte

// YANGEmpty is a type that is used for fields that have a YANG type of
// empty. It is used such that empty fields can be distinguished from boolean fields
// in the generated code.
type YANGEmpty bool

var (
	SchemaTree map[string]*yang.Entry
)

func init() {
	var err error
	if SchemaTree, err = UnzipSchema(); err != nil {
		panic("schema error: " +  err.Error())
	}
}

// Schema returns the details of the generated schema.
func Schema() (*ytypes.Schema, error) {
	uzp, err := UnzipSchema()
	if err != nil {
		return nil, fmt.Errorf("cannot unzip schema, %v", err)
	}

	return &ytypes.Schema{
		Root: &Device{},
		SchemaTree: uzp,
		Unmarshal: Unmarshal,
	}, nil
}

// UnzipSchema unzips the zipped schema and returns a map of yang.Entry nodes,
// keyed by the name of the struct that the yang.Entry describes the schema for.
func UnzipSchema() (map[string]*yang.Entry, error) {
	var schemaTree map[string]*yang.Entry
	var err error
	if schemaTree, err = ygot.GzipToSchema(ySchema); err != nil {
		return nil, fmt.Errorf("could not unzip the schema; %v", err)
	}
	return schemaTree, nil
}

// Unmarshal unmarshals data, which must be RFC7951 JSON format, into
// destStruct, which must be non-nil and the correct GoStruct type. It returns
// an error if the destStruct is not found in the schema or the data cannot be
// unmarshaled. The supplied options (opts) are used to control the behaviour
// of the unmarshal function - for example, determining whether errors are
// thrown for unknown fields in the input JSON.
func Unmarshal(data []byte, destStruct ygot.GoStruct, opts ...ytypes.UnmarshalOpt) error {
	tn := reflect.TypeOf(destStruct).Elem().Name()
	schema, ok := SchemaTree[tn]
	if !ok {
		return fmt.Errorf("could not find schema for type %s", tn )
	}
	var jsonTree interface{}
	if err := json.Unmarshal([]byte(data), &jsonTree); err != nil {
		return err
	}
	return ytypes.Unmarshal(schema, destStruct, jsonTree, opts...)
}

// Device represents the /device YANG schema element.
type Device struct {
	Components	*OpenconfigPlatform_Components	`path:"components" module:"openconfig-platform"`
	Interfaces	*OpenconfigInterfaces_Interfaces	`path:"interfaces" module:"openconfig-interfaces"`
	InterfacesState	*IETFInterfaces_InterfacesState	`path:"interfaces-state" module:"ietf-interfaces"`
	Lldp	*OpenconfigLldp_Lldp	`path:"lldp" module:"openconfig-lldp"`
	TerminalDevice	*OpenconfigTerminalDevice_TerminalDevice	`path:"terminal-device" module:"openconfig-terminal-device"`
}

// IsYANGGoStruct ensures that Device implements the yang.GoStruct
// interface. This allows functions that need to handle this struct to
// identify it as being generated by ygen.
func (*Device) IsYANGGoStruct() {}

// Validate validates s against the YANG schema corresponding to its type.
func (t *Device) Validate(opts ...ygot.ValidationOption) error {
	if err := ytypes.Validate(SchemaTree["Device"], t, opts...); err != nil {
		return err
	}
	return nil
}

// ΛEnumTypeMap returns a map, keyed by YANG schema path, of the enumerated types
// that are included in the generated code.
func (t *Device) ΛEnumTypeMap() map[string][]reflect.Type { return ΛEnumTypes }


// IETFInterfaces_InterfacesState represents the /ietf-interfaces/interfaces-state YANG schema element.
type IETFInterfaces_InterfacesState struct {
	Interface	map[string]*IETFInterfaces_InterfacesState_Interface	`path:"interface" module:"ietf-interfaces"`
}

// IsYANGGoStruct ensures that IETFInterfaces_InterfacesState implements the yang.GoStruct
// interface. This allows functions that need to handle this struct to
// identify it as being generated by ygen.
func (*IETFInterfaces_InterfacesState) IsYANGGoStruct() {}

// NewInterface creates a new entry in the Interface list of the
// IETFInterfaces_InterfacesState struct. The keys of the list are populated from the input
// arguments.
func (t *IETFInterfaces_InterfacesState) NewInterface(Name string) (*IETFInterfaces_InterfacesState_Interface, error){

	// Initialise the list within the receiver struct if it has not already been
	// created.
	if t.Interface == nil {
		t.Interface = make(map[string]*IETFInterfaces_InterfacesState_Interface)
	}

	key := Name

	// Ensure that this key has not already been used in the
	// list. Keyed YANG lists do not allow duplicate keys to
	// be created.
	if _, ok := t.Interface[key]; ok {
		return nil, fmt.Errorf("duplicate key %v for list Interface", key)
	}

	t.Interface[key] = &IETFInterfaces_InterfacesState_Interface{
		Name: &Name,
	}

	return t.Interface[key], nil
}

// Validate validates s against the YANG schema corresponding to its type.
func (t *IETFInterfaces_InterfacesState) Validate(opts ...ygot.ValidationOption) error {
	if err := ytypes.Validate(SchemaTree["IETFInterfaces_InterfacesState"], t, opts...); err != nil {
		return err
	}
	return nil
}

// ΛEnumTypeMap returns a map, keyed by YANG schema path, of the enumerated types
// that are included in the generated code.
func (t *IETFInterfaces_InterfacesState) ΛEnumTypeMap() map[string][]reflect.Type { return ΛEnumTypes }


// IETFInterfaces_InterfacesState_Interface represents the /ietf-interfaces/interfaces-state/interface YANG schema element.
type IETFInterfaces_InterfacesState_Interface struct {
	AdminStatus	E_IETFInterfaces_InterfacesState_Interface_AdminStatus	`path:"admin-status" module:"ietf-interfaces"`
	HigherLayerIf	[]string	`path:"higher-layer-if" module:"ietf-interfaces"`
	IfIndex	*int32	`path:"if-index" module:"ietf-interfaces"`
	LastChange	*string	`path:"last-change" module:"ietf-interfaces"`
	LowerLayerIf	[]string	`path:"lower-layer-if" module:"ietf-interfaces"`
	Name	*string	`path:"name" module:"ietf-interfaces"`
	OperStatus	E_IETFInterfaces_InterfacesState_Interface_OperStatus	`path:"oper-status" module:"ietf-interfaces"`
	PhysAddress	*string	`path:"phys-address" module:"ietf-interfaces"`
	Speed	*uint64	`path:"speed" module:"ietf-interfaces"`
	Statistics	*IETFInterfaces_InterfacesState_Interface_Statistics	`path:"statistics" module:"ietf-interfaces"`
	Type	E_IETFInterfaces_InterfaceType	`path:"type" module:"ietf-interfaces"`
}
Loading
Loading full blame...