typeinfo

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	SAITypeToProto = map[string]SAITypeInfo{
		"bool": {
			ProtoType: "bool",
		},
		"char": {
			ProtoType: "bytes",
		},
		"sai_uint8_t": {
			ProtoType: "uint32",
		},
		"sai_int8_t": {
			ProtoType: "int32",
		},
		"sai_uint16_t": {
			ProtoType: "uint32",
		},
		"sai_int16_t": {
			ProtoType: "int32",
		},
		"sai_uint32_t": {
			ProtoType: "uint32",
		},
		"sai_int32_t": {
			ProtoType: "uint32",
		},
		"sai_uint64_t": {
			ProtoType: "uint64",
		},
		"sai_int64_t": {
			ProtoType: "int64",
		},
		"sai_mac_t": {
			ProtoType: "bytes",
		},
		"sai_json_t": {
			ProtoType: "bytes",
		},
		"sai_ip4_t": {
			ProtoType: "bytes",
		},
		"sai_ip6_t": {
			ProtoType: "bytes",
		},
		"sai_s32_list_t": {
			Repeated:  true,
			ProtoType: "int32",
		},
		"sai_object_id_t": {
			ProtoType: "uint64",
		},
		"map_sai_object_id_t": {
			ProtoType: "map<uint64, uint64>",
			Required:  true,
		},
		"sai_object_list_t": {
			Repeated:  true,
			ProtoType: "uint64",
		},
		"sai_encrypt_key_t": {
			ProtoType: "bytes",
		},
		"sai_auth_key_t": {
			ProtoType: "bytes",
		},
		"sai_macsec_sak_t": {
			ProtoType: "bytes",
		},
		"sai_macsec_auth_key_t": {
			ProtoType: "bytes",
		},
		"sai_macsec_salt_t": {
			ProtoType: "bytes",
		},
		"sai_u32_list_t": {
			Repeated:  true,
			ProtoType: "uint32",
		},
		"sai_segment_list_t": {
			Repeated:  true,
			ProtoType: "bytes",
		},
		"sai_s8_list_t": {
			Repeated:  true,
			ProtoType: "int32",
		},
		"sai_u8_list_t": {
			Repeated:  true,
			ProtoType: "uint32",
		},
		"sai_port_err_status_list_t": {
			Repeated:  true,
			ProtoType: "PortErrStatus",
		},
		"sai_port_frequency_offset_ppm_list_t": {
			ProtoType: "bytes",
		},
		"sai_port_snr_list_t": {
			ProtoType: "bytes",
		},
		"sai_acl_chain_list_t": {
			ProtoType: "bytes",
		},
		"sai_vlan_list_t": {
			Repeated:  true,
			ProtoType: "uint32",
		},
		"sai_timespec_t": {
			ProtoType: "google.protobuf.Timestamp",
		},

		"sai_u32_range_t": {
			ProtoType: "Uint32Range",
			MessageDef: `message Uint32Range {
	uint64 min = 1;
	uint64 max = 2;
}`,
		},
		"sai_ip_address_t": {
			ProtoType: "bytes",
		},
		"sai_latch_status_t": {
			ProtoType: "LatchStatus",
			MessageDef: `message LatchStatus {
	bool current_status = 1;
	bool changed = 2;
}`,
		},
		"sai_port_lane_latch_status_list_t": {
			Repeated:  true,
			ProtoType: "PortLaneLatchStatus",
			MessageDef: `message PortLaneLatchStatus {
	uint32 lane = 1;
	LatchStatus value = 2;
}`,
		},
		"sai_map_list_t": {
			Repeated:  true,
			ProtoType: "UintMap",
			MessageDef: `message UintMap {
	map<uint32, uint32> uintmap = 1;
}`,
		},
		"sai_tlv_list_t": {
			Repeated:  true,
			ProtoType: "TLVEntry",
			MessageDef: `message HMAC {
	uint32 key_id = 1;
	repeated uint32 hmac = 2;
}

message TLVEntry {
	oneof entry {
		bytes ingress_node = 1; 
		bytes egress_node = 2;
		bytes opaque_container = 3;
		HMAC hmac = 4;
	}
}`,
		},
		"sai_qos_map_list_t": {
			Repeated:  true,
			ProtoType: "QOSMap",
			MessageDef: `
message	QOSMapParams {
	uint32 tc = 1;
	uint32 dscp = 2;
	uint32 dot1p = 3;
	uint32 prio = 4;
	uint32 pg = 5;
	uint32 queue_index = 6;
	PacketColor color = 7;
	uint32 mpls_exp = 8;
	uint32 fc = 9;
}

message QOSMap {
	QOSMapParams key = 1;
	QOSMapParams value = 2;
}`,
		},
		"sai_system_port_config_t": {
			ProtoType: "SystemPortConfig",
			MessageDef: `message SystemPortConfig {
	uint32 port_id = 1;
	uint32 attached_switch_id = 2;
	uint32 attached_core_index = 3;
	uint32 attached_core_port_index = 4;
	uint32 speed = 5;
	uint32 num_voq = 6;
}`,
		},
		"sai_system_port_config_list_t": {
			Repeated:  true,
			ProtoType: "SystemPortConfig",
		},
		"sai_ip_address_list_t": {
			Repeated:  true,
			ProtoType: "bytes",
		},
		"sai_port_eye_values_list_t": {
			Repeated:  true,
			ProtoType: "PortEyeValues",
			MessageDef: `message PortEyeValues {
	uint32 lane = 1;
	int32 left = 2;
	int32 right = 3;
	int32 up = 4;
	int32 down = 5;
}`,
		},
		"sai_prbs_rx_state_t": {
			ProtoType: "PRBS_RXState",
			MessageDef: `message PRBS_RXState {
	PortPrbsRxStatus rx_status = 1;
	uint32 error_count = 2;
}`,
		},
		"sai_fabric_port_reachability_t": {
			ProtoType: "FabricPortReachability",
			MessageDef: `message FabricPortReachability {
	uint32 switch_id = 1;
	bool reachable = 2;
}`,
		},
		"sai_acl_resource_list_t": {
			Repeated:  true,
			ProtoType: "ACLResource",
			MessageDef: `message ACLResource {
	AclStage stage = 1;
	AclBindPointType bind_point = 2;
	uint32 avail_num = 3;
}`,
		},
		"sai_acl_capability_t": {
			ProtoType: "ACLCapability",
			MessageDef: `message ACLCapability {
	bool is_action_list_mandatory = 1;
	repeated AclActionType action_list = 2;
}`,
		},
		"sai_acl_field_data_t": {
			ProtoType: "AclFieldData",
			MessageDef: `message AclFieldData {
	bool enable = 1;
	oneof mask {
		uint64 mask_uint = 2;
		int64 mask_int = 3;
		bytes mask_mac = 4;
		bytes mask_ip = 5;
		Uint64List mask_list = 6;
		bytes mask_u8list = 15;
	};
	oneof data {
		bool data_bool = 7;
		uint64 data_uint = 8;
		int64 data_int = 9;
		bytes data_mac = 10;
		bytes data_ip = 11;
		Uint64List data_list = 12;
		AclIpType data_ip_type = 13;
		uint64 data_oid = 14;
		bytes data_u8list = 16;
	};
}

message Uint64List {
	repeated uint64 list = 1;
}`,
		},
		"sai_acl_action_data_t": {
			ProtoType: "AclActionData",
			MessageDef: `message AclActionData {
	bool enable = 1;
	oneof parameter {
		uint64 uint = 2;
		uint64 int = 3;
		bytes mac = 4;
		bytes ip = 5;
		uint64 oid = 6;
		Uint64List objlist = 7;
		bytes ipaddr = 8;
		PacketAction packet_action = 9;
	};
}`,
		},
		"sai_fdb_entry_t": {
			ProtoType: "FdbEntry",
			MessageDef: `message FdbEntry {
	uint64 switch_id = 1;
	bytes mac_address = 2;
	uint64 bv_id = 3;
}`,
		},
		"sai_ipmc_entry_t": {
			ProtoType: "IpmcEntry",
			MessageDef: `message IpmcEntry {
	uint64 switch_id = 1;
	uint64 vr_id = 2;
	IpmcEntryType type = 3;
	bytes destination = 4;
	bytes source = 5;
}`,
		},
		"sai_l2mc_entry_t": {
			ProtoType: "L2mcEntry",
			MessageDef: `message L2mcEntry {
	uint64 switch_id = 1;
	uint64 bv_id = 2;
	L2mcEntryType type = 3;
	bytes destination = 4;
	bytes source = 5;
}`,
		},
		"sai_mcast_fdb_entry_t": {
			ProtoType: "McastFdbEntry",
			MessageDef: `message McastFdbEntry {
	uint64 switch_id = 1;
	bytes mac_address = 2;
	uint64 bv_id = 3;
}`,
		},
		"sai_inseg_entry_t": {
			ProtoType: "InsegEntry",
			MessageDef: `message InsegEntry {
	uint64 switch_id = 1;
	uint32 label = 2;
}`,
		},
		"sai_nat_entry_data_t": {
			ProtoType: "NatEntryData",
			MessageDef: `message NatEntryData{
	oneof key {
		bytes key_src_ip = 2;
		bytes key_dst_ip = 3;
		uint32 key_proto = 4;
		uint32 key_l4_src_port = 5;
		uint32 key_l4_dst_port = 6;
	};
	oneof mask {
		bytes mask_src_ip = 7;
		bytes mask_dst_ip = 8;
		uint32 mask_proto = 9;
		uint32 mask_l4_src_port = 10;
		uint32 mask_l4_dst_port = 11;
	};
}`,
		},
		"sai_nat_entry_t": {
			ProtoType: "NatEntry",
			MessageDef: `message NatEntry {
	uint64 switch_id = 1;
	uint64 vr_id = 2;
	NatType nat_type = 3;
	NatEntryData data = 4;
}`,
		},
		"sai_neighbor_entry_t": {
			ProtoType: "NeighborEntry",
			MessageDef: `message NeighborEntry {
	uint64 switch_id = 1;
	uint64 rif_id = 2;
	bytes ip_address = 3;
}`,
		},
		"sai_ip_prefix_t": {
			ProtoType: "IpPrefix",
			MessageDef: `message IpPrefix {
	bytes addr = 1;
	bytes mask = 2;
}`,
		},
		"sai_route_entry_t": {
			ProtoType: "RouteEntry",
			MessageDef: `message RouteEntry {
	uint64 switch_id = 1;
	uint64 vr_id = 2;
	IpPrefix destination = 3;
}`,
		},
		"sai_my_sid_entry_t": {
			ProtoType: "MySidEntry",
			MessageDef: `message MySidEntry {
	uint64 switch_id = 1;
	uint64 vr_id = 2;
	uint32 locator_block_len = 3;
	uint32 locator_node_len = 4;
	uint32 function_len = 5;
	uint32 args_len = 6;
	bytes sid = 7;
}`,
		},
		"sai_fdb_event_notification_data_t": {
			ProtoType: "FdbEventNotificationData",
			MessageDef: `
message FdbEventNotificationData {
    FdbEvent event_type = 1;
	FdbEntry fdb_entry = 2;
	repeated FdbEntryAttribute attrs = 3;
}`,
		},
		"sai_port_oper_status_notification_t": {
			ProtoType: "PortOperStatusNotification",
			MessageDef: `message PortOperStatusNotification {
	uint64 port_id = 1;
	PortOperStatus port_state = 2;
}`,
		},
		"sai_queue_deadlock_notification_data_t": {
			ProtoType: "QueueDeadlockNotificationData",
			MessageDef: `message QueueDeadlockNotificationData {
	uint64 queue_id = 1;
	QueuePfcDeadlockEventType event= 2;
	bool app_managed_recovery = 3;
}`,
		},
		"sai_bfd_session_state_notification_t": {
			ProtoType: "BfdSessionStateChangeNotificationData",
			MessageDef: `message BfdSessionStateChangeNotificationData {
	uint64 bfd_session_id = 1;
	BfdSessionState session_state = 2;
}`,
		},
		"sai_ipsec_sa_status_notification_t": {
			ProtoType: "IpsecSaStatusNotificationData",
			MessageDef: `message IpsecSaStatusNotificationData {
    uint64 ipsec_sa_id = 1;
	IpsecSaOctetCountStatus ipsec_sa_octet_count_status = 2;
	bool ipsec_egress_sn_at_max_limit = 3;
}`,
		},
	}
)

Functions

func CreateAttrs

func CreateAttrs(startIdx int, typeName string, xmlInfo *docparser.SAIInfo, attrs []*docparser.AttrTypeName) ([]protoTmplField, error)

func SaiTypeToProtoType

func SaiTypeToProtoType(saiType string, xmlInfo *docparser.SAIInfo) (string, bool, error)

saiTypeToProtoType returns the protobuf type string for a SAI type. example: sai_u8_list_t -> repeated uint32

Types

type APITemplate

type APITemplate struct {
	Types          []*GenType
	Funcs          []*GenFunc
	Enums          []ProtoEnum
	ServiceName    string
	ProtoPackage   string
	ProtoGoPackage string
	ProtoOutDir    string
	IncludeGuard   string
	Header         string
	ProtoInclude   string
	GRPCInclude    string
	APIType        string
	ProtoClass     string
	APIName        string
	Globals        []string
	ConvertFuncs   []*GenFunc
	CCOutDir       string
}

type AttrSwitch

type AttrSwitch struct {
	Var      string
	Attrs    []*AttrSwitchSmt
	ProtoVar string
}

type AttrSwitchSmt

type AttrSwitchSmt struct {
	// EnumValue is the name of enum value string. (eg SAI_HOSTIF_ATTR_OPER_STATUS).
	EnumValue string
	// ProtoFunc is the name of the protobuf getter or setter (eg set_obj_id() or obj_id()).
	ProtoFunc string
	// Args are the arguments to pass the ProtoFunc as comma seperated values.
	Args string
	// Var is the name of the variable that is used for assignment.
	Var string
	// ConvertFunc is a name the function that is called before assignment to var.
	ConvertFunc string
	// ConvertFuncArgs are the extra arguments to pass the convert func, in addition to ProtoFunc.
	ConvertFuncArgs string
	// CopyConvertFunc is the name of func to use. If set, then this function is used instead assignment.
	// For example, to copy a string, set this strncpy, since char arrays can't assigned be directly.
	CopyConvertFunc string
	// ConvertFuncArgs are the extra arguments to pass the copy convert func.
	CopyConvertFuncArgs string
	// CustomText is any text to include for in the case.
	CustomText string
}

type GenFunc

type GenFunc struct {
	ProtoRPCName          string
	ProtoRequestType      string
	ProtoResponseType     string
	ReturnType            string
	Name                  string
	Args                  string
	TypeName              string
	Operation             string
	Vars                  string
	UseCommonAPI          bool
	AttrSwitch            *AttrSwitch
	Client                string
	OidVar                string
	OidPointer            string
	AttrType              string
	AttrEnumType          string
	SwitchScoped          bool
	EntryConversionFunc   string
	EntryVar              string
	EntryConversionToFunc string
	ConvertFunc           string
	AttrConvertInsert     string
	IsStreaming           bool
}

type GenType

type GenType struct {
	Name   string
	Option string
	Fields []protoTmplField
}

type ProtoEnum

type ProtoEnum struct {
	Name   string
	Values []ProtoEnumValues
	Alias  bool
}

type ProtoEnumValues

type ProtoEnumValues struct {
	Index int
	Name  string
}

type ProtoTmplMessage

type ProtoTmplMessage struct {
	Name   string
	Option string
	Fields []protoTmplField
}

type SAITypeInfo

type SAITypeInfo struct {
	Repeated   bool
	ProtoType  string
	MessageDef string
	Required   bool
}

type TemplateData

type TemplateData struct {
	APIs map[string]*APITemplate
}

func Data

func Data(doc *docparser.SAIInfo, sai *saiast.SAIAPI, protoPackage, protoGoPackage, ccOutDir, protoOutDir string) (*TemplateData, error)

Jump to

Keyboard shortcuts

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