// Code generated by protoc-gen-go. DO NOT EDIT.
// source: nodeb_info.proto

package entities

import (
	fmt "fmt"
	proto "github.com/golang/protobuf/proto"
	math "math"
)

// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf

// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package

type E2ApplicationProtocol int32

const (
	E2ApplicationProtocol_UNKNOWN_E2_APPLICATION_PROTOCOL E2ApplicationProtocol = 0
	E2ApplicationProtocol_X2_SETUP_REQUEST                E2ApplicationProtocol = 1
	E2ApplicationProtocol_ENDC_X2_SETUP_REQUEST           E2ApplicationProtocol = 2
)

var E2ApplicationProtocol_name = map[int32]string{
	0: "UNKNOWN_E2_APPLICATION_PROTOCOL",
	1: "X2_SETUP_REQUEST",
	2: "ENDC_X2_SETUP_REQUEST",
}

var E2ApplicationProtocol_value = map[string]int32{
	"UNKNOWN_E2_APPLICATION_PROTOCOL": 0,
	"X2_SETUP_REQUEST":                1,
	"ENDC_X2_SETUP_REQUEST":           2,
}

func (x E2ApplicationProtocol) String() string {
	return proto.EnumName(E2ApplicationProtocol_name, int32(x))
}

func (E2ApplicationProtocol) EnumDescriptor() ([]byte, []int) {
	return fileDescriptor_04b920976079e56c, []int{0}
}

type ConnectionStatus int32

const (
	ConnectionStatus_UNKNOWN_CONNECTION_STATUS ConnectionStatus = 0
	ConnectionStatus_CONNECTED                 ConnectionStatus = 1
	ConnectionStatus_DISCONNECTED              ConnectionStatus = 2
	ConnectionStatus_CONNECTED_SETUP_FAILED    ConnectionStatus = 3
	ConnectionStatus_CONNECTING                ConnectionStatus = 4
	ConnectionStatus_SHUTTING_DOWN             ConnectionStatus = 5
	ConnectionStatus_SHUT_DOWN                 ConnectionStatus = 6
)

var ConnectionStatus_name = map[int32]string{
	0: "UNKNOWN_CONNECTION_STATUS",
	1: "CONNECTED",
	2: "DISCONNECTED",
	3: "CONNECTED_SETUP_FAILED",
	4: "CONNECTING",
	5: "SHUTTING_DOWN",
	6: "SHUT_DOWN",
}

var ConnectionStatus_value = map[string]int32{
	"UNKNOWN_CONNECTION_STATUS": 0,
	"CONNECTED":                 1,
	"DISCONNECTED":              2,
	"CONNECTED_SETUP_FAILED":    3,
	"CONNECTING":                4,
	"SHUTTING_DOWN":             5,
	"SHUT_DOWN":                 6,
}

func (x ConnectionStatus) String() string {
	return proto.EnumName(ConnectionStatus_name, int32(x))
}

func (ConnectionStatus) EnumDescriptor() ([]byte, []int) {
	return fileDescriptor_04b920976079e56c, []int{1}
}

type Node_Type int32

const (
	Node_UNKNOWN Node_Type = 0
	Node_ENB     Node_Type = 1
	Node_GNB     Node_Type = 2
)

var Node_Type_name = map[int32]string{
	0: "UNKNOWN",
	1: "ENB",
	2: "GNB",
}

var Node_Type_value = map[string]int32{
	"UNKNOWN": 0,
	"ENB":     1,
	"GNB":     2,
}

func (x Node_Type) String() string {
	return proto.EnumName(Node_Type_name, int32(x))
}

func (Node_Type) EnumDescriptor() ([]byte, []int) {
	return fileDescriptor_04b920976079e56c, []int{1, 0}
}

type Failure_Type int32

const (
	Failure_UNKNOWN_TYPE          Failure_Type = 0
	Failure_X2_SETUP_FAILURE      Failure_Type = 1
	Failure_ENDC_X2_SETUP_FAILURE Failure_Type = 2
)

var Failure_Type_name = map[int32]string{
	0: "UNKNOWN_TYPE",
	1: "X2_SETUP_FAILURE",
	2: "ENDC_X2_SETUP_FAILURE",
}

var Failure_Type_value = map[string]int32{
	"UNKNOWN_TYPE":          0,
	"X2_SETUP_FAILURE":      1,
	"ENDC_X2_SETUP_FAILURE": 2,
}

func (x Failure_Type) String() string {
	return proto.EnumName(Failure_Type_name, int32(x))
}

func (Failure_Type) EnumDescriptor() ([]byte, []int) {
	return fileDescriptor_04b920976079e56c, []int{2, 0}
}

type NodebInfo struct {
	RanName               string                `protobuf:"bytes,1,opt,name=ran_name,json=ranName,proto3" json:"ran_name,omitempty"`
	Ip                    string                `protobuf:"bytes,2,opt,name=ip,proto3" json:"ip,omitempty"`
	Port                  uint32                `protobuf:"varint,3,opt,name=port,proto3" json:"port,omitempty"`
	E2ApplicationProtocol E2ApplicationProtocol `protobuf:"varint,4,opt,name=e2_application_protocol,json=e2ApplicationProtocol,proto3,enum=entities.E2ApplicationProtocol" json:"e2_application_protocol,omitempty"`
	ConnectionStatus      ConnectionStatus      `protobuf:"varint,5,opt,name=connection_status,json=connectionStatus,proto3,enum=entities.ConnectionStatus" json:"connection_status,omitempty"`
	ConnectionAttempts    uint32                `protobuf:"varint,6,opt,name=connection_attempts,json=connectionAttempts,proto3" json:"connection_attempts,omitempty"`
	GlobalNbId            *GlobalNbId           `protobuf:"bytes,7,opt,name=global_nb_id,json=globalNbId,proto3" json:"global_nb_id,omitempty"`
	NodeType              Node_Type             `protobuf:"varint,8,opt,name=node_type,json=nodeType,proto3,enum=entities.Node_Type" json:"node_type,omitempty"`
	// Types that are valid to be assigned to Configuration:
	//	*NodebInfo_Enb
	//	*NodebInfo_Gnb
	Configuration        isNodebInfo_Configuration `protobuf_oneof:"configuration"`
	FailureType          Failure_Type              `protobuf:"varint,11,opt,name=failure_type,json=failureType,proto3,enum=entities.Failure_Type" json:"failure_type,omitempty"`
	SetupFailure         *SetupFailure             `protobuf:"bytes,12,opt,name=setup_failure,json=setupFailure,proto3" json:"setup_failure,omitempty"`
	XXX_NoUnkeyedLiteral struct{}                  `json:"-"`
	XXX_unrecognized     []byte                    `json:"-"`
	XXX_sizecache        int32                     `json:"-"`
}

func (m *NodebInfo) Reset()         { *m = NodebInfo{} }
func (m *NodebInfo) String() string { return proto.CompactTextString(m) }
func (*NodebInfo) ProtoMessage()    {}
func (*NodebInfo) Descriptor() ([]byte, []int) {
	return fileDescriptor_04b920976079e56c, []int{0}
}

func (m *NodebInfo) XXX_Unmarshal(b []byte) error {
	return xxx_messageInfo_NodebInfo.Unmarshal(m, b)
}
func (m *NodebInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
	return xxx_messageInfo_NodebInfo.Marshal(b, m, deterministic)
}
func (m *NodebInfo) XXX_Merge(src proto.Message) {
	xxx_messageInfo_NodebInfo.Merge(m, src)
}
func (m *NodebInfo) XXX_Size() int {
	return xxx_messageInfo_NodebInfo.Size(m)
}
func (m *NodebInfo) XXX_DiscardUnknown() {
	xxx_messageInfo_NodebInfo.DiscardUnknown(m)
}

var xxx_messageInfo_NodebInfo proto.InternalMessageInfo

func (m *NodebInfo) GetRanName() string {
	if m != nil {
		return m.RanName
	}
	return ""
}

func (m *NodebInfo) GetIp() string {
	if m != nil {
		return m.Ip
	}
	return ""
}

func (m *NodebInfo) GetPort() uint32 {
	if m != nil {
		return m.Port
	}
	return 0
}

func (m *NodebInfo) GetE2ApplicationProtocol() E2ApplicationProtocol {
	if m != nil {
		return m.E2ApplicationProtocol
	}
	return E2ApplicationProtocol_UNKNOWN_E2_APPLICATION_PROTOCOL
}

func (m *NodebInfo) GetConnectionStatus() ConnectionStatus {
	if m != nil {
		return m.ConnectionStatus
	}
	return ConnectionStatus_UNKNOWN_CONNECTION_STATUS
}

func (m *NodebInfo) GetConnectionAttempts() uint32 {
	if m != nil {
		return m.ConnectionAttempts
	}
	return 0
}

func (m *NodebInfo) GetGlobalNbId() *GlobalNbId {
	if m != nil {
		return m.GlobalNbId
	}
	return nil
}

func (m *NodebInfo) GetNodeType() Node_Type {
	if m != nil {
		return m.NodeType
	}
	return Node_UNKNOWN
}

type isNodebInfo_Configuration interface {
	isNodebInfo_Configuration()
}

type NodebInfo_Enb struct {
	Enb *Enb `protobuf:"bytes,9,opt,name=enb,proto3,oneof"`
}

type NodebInfo_Gnb struct {
	Gnb *Gnb `protobuf:"bytes,10,opt,name=gnb,proto3,oneof"`
}

func (*NodebInfo_Enb) isNodebInfo_Configuration() {}

func (*NodebInfo_Gnb) isNodebInfo_Configuration() {}

func (m *NodebInfo) GetConfiguration() isNodebInfo_Configuration {
	if m != nil {
		return m.Configuration
	}
	return nil
}

func (m *NodebInfo) GetEnb() *Enb {
	if x, ok := m.GetConfiguration().(*NodebInfo_Enb); ok {
		return x.Enb
	}
	return nil
}

func (m *NodebInfo) GetGnb() *Gnb {
	if x, ok := m.GetConfiguration().(*NodebInfo_Gnb); ok {
		return x.Gnb
	}
	return nil
}

func (m *NodebInfo) GetFailureType() Failure_Type {
	if m != nil {
		return m.FailureType
	}
	return Failure_UNKNOWN_TYPE
}

func (m *NodebInfo) GetSetupFailure() *SetupFailure {
	if m != nil {
		return m.SetupFailure
	}
	return nil
}

// XXX_OneofWrappers is for the internal use of the proto package.
func (*NodebInfo) XXX_OneofWrappers() []interface{} {
	return []interface{}{
		(*NodebInfo_Enb)(nil),
		(*NodebInfo_Gnb)(nil),
	}
}

type Node struct {
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (m *Node) Reset()         { *m = Node{} }
func (m *Node) String() string { return proto.CompactTextString(m) }
func (*Node) ProtoMessage()    {}
func (*Node) Descriptor() ([]byte, []int) {
	return fileDescriptor_04b920976079e56c, []int{1}
}

func (m *Node) XXX_Unmarshal(b []byte) error {
	return xxx_messageInfo_Node.Unmarshal(m, b)
}
func (m *Node) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
	return xxx_messageInfo_Node.Marshal(b, m, deterministic)
}
func (m *Node) XXX_Merge(src proto.Message) {
	xxx_messageInfo_Node.Merge(m, src)
}
func (m *Node) XXX_Size() int {
	return xxx_messageInfo_Node.Size(m)
}
func (m *Node) XXX_DiscardUnknown() {
	xxx_messageInfo_Node.DiscardUnknown(m)
}

var xxx_messageInfo_Node proto.InternalMessageInfo

type Failure struct {
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (m *Failure) Reset()         { *m = Failure{} }
func (m *Failure) String() string { return proto.CompactTextString(m) }
func (*Failure) ProtoMessage()    {}
func (*Failure) Descriptor() ([]byte, []int) {
	return fileDescriptor_04b920976079e56c, []int{2}
}

func (m *Failure) XXX_Unmarshal(b []byte) error {
	return xxx_messageInfo_Failure.Unmarshal(m, b)
}
func (m *Failure) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
	return xxx_messageInfo_Failure.Marshal(b, m, deterministic)
}
func (m *Failure) XXX_Merge(src proto.Message) {
	xxx_messageInfo_Failure.Merge(m, src)
}
func (m *Failure) XXX_Size() int {
	return xxx_messageInfo_Failure.Size(m)
}
func (m *Failure) XXX_DiscardUnknown() {
	xxx_messageInfo_Failure.DiscardUnknown(m)
}

var xxx_messageInfo_Failure proto.InternalMessageInfo

func init() {
	proto.RegisterEnum("entities.E2ApplicationProtocol", E2ApplicationProtocol_name, E2ApplicationProtocol_value)
	proto.RegisterEnum("entities.ConnectionStatus", ConnectionStatus_name, ConnectionStatus_value)
	proto.RegisterEnum("entities.Node_Type", Node_Type_name, Node_Type_value)
	proto.RegisterEnum("entities.Failure_Type", Failure_Type_name, Failure_Type_value)
	proto.RegisterType((*NodebInfo)(nil), "entities.NodebInfo")
	proto.RegisterType((*Node)(nil), "entities.Node")
	proto.RegisterType((*Failure)(nil), "entities.Failure")
}

func init() { proto.RegisterFile("nodeb_info.proto", fileDescriptor_04b920976079e56c) }

var fileDescriptor_04b920976079e56c = []byte{
	// 623 bytes of a gzipped FileDescriptorProto
	0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x53, 0xef, 0x6e, 0xda, 0x3e,
	0x14, 0x25, 0x81, 0x16, 0x72, 0x81, 0xfe, 0x5c, 0xf7, 0xcf, 0x2f, 0x45, 0x9a, 0xca, 0x98, 0x26,
	0xa1, 0x4a, 0x63, 0x53, 0x26, 0x4d, 0x9a, 0xf6, 0x89, 0x42, 0x4a, 0xa3, 0x55, 0x86, 0x25, 0x41,
	0xdd, 0x3e, 0x59, 0x09, 0x35, 0x28, 0x12, 0x38, 0x51, 0x62, 0xa4, 0xf5, 0x6d, 0xf6, 0x54, 0x7b,
	0x9e, 0xc9, 0x26, 0x10, 0xc6, 0xfa, 0xed, 0xfa, 0x9c, 0x73, 0xcf, 0xc9, 0xbd, 0x76, 0x00, 0xf1,
	0xf8, 0x89, 0x85, 0x34, 0xe2, 0xf3, 0xb8, 0x97, 0xa4, 0xb1, 0x88, 0x71, 0x8d, 0x71, 0x11, 0x89,
	0x88, 0x65, 0x2d, 0x63, 0xc1, 0xc3, 0x0d, 0xd8, 0x32, 0xd8, 0xae, 0xbc, 0xfe, 0x69, 0xd1, 0x8c,
	0x89, 0x75, 0x42, 0xe7, 0x41, 0xb4, 0x5c, 0xa7, 0x8c, 0xa6, 0x2c, 0x4b, 0x62, 0x9e, 0xb1, 0x5c,
	0x70, 0xca, 0x43, 0x1a, 0x3d, 0x29, 0x97, 0xe7, 0x0d, 0xd4, 0xf9, 0x5d, 0x01, 0x83, 0xc8, 0x20,
	0x87, 0xcf, 0x63, 0x7c, 0x05, 0xb5, 0x34, 0xe0, 0x94, 0x07, 0x2b, 0x66, 0x6a, 0x6d, 0xad, 0x6b,
	0xb8, 0xd5, 0x34, 0xe0, 0x24, 0x58, 0x31, 0x7c, 0x02, 0x7a, 0x94, 0x98, 0xba, 0x02, 0xf5, 0x28,
	0xc1, 0x18, 0x2a, 0x49, 0x9c, 0x0a, 0xb3, 0xdc, 0xd6, 0xba, 0x4d, 0x57, 0xd5, 0xf8, 0x11, 0xfe,
	0x67, 0x16, 0x0d, 0x92, 0x64, 0x19, 0xcd, 0x02, 0x11, 0xc5, 0x9c, 0xaa, 0x90, 0x59, 0xbc, 0x34,
	0x2b, 0x6d, 0xad, 0x7b, 0x62, 0x5d, 0xf7, 0xb6, 0x23, 0xf4, 0x6c, 0xab, 0x5f, 0xe8, 0x26, 0xb9,
	0xcc, 0xbd, 0x60, 0x2f, 0xc1, 0x78, 0x04, 0xa7, 0xb3, 0x98, 0x73, 0x36, 0x53, 0xa6, 0x99, 0x08,
	0xc4, 0x3a, 0x33, 0x8f, 0x94, 0x65, 0xab, 0xb0, 0x1c, 0xec, 0x24, 0x9e, 0x52, 0xb8, 0x68, 0x76,
	0x80, 0xe0, 0xf7, 0x70, 0xb6, 0x67, 0x14, 0x08, 0xc1, 0x56, 0x89, 0xc8, 0xcc, 0x63, 0x35, 0x04,
	0x2e, 0xa8, 0x7e, 0xce, 0xe0, 0x4f, 0xd0, 0x58, 0x2c, 0xe3, 0x30, 0x58, 0x52, 0xb5, 0x3b, 0xb3,
	0xda, 0xd6, 0xba, 0x75, 0xeb, 0xbc, 0x08, 0x1d, 0x29, 0x96, 0x84, 0xce, 0x93, 0x0b, 0x8b, 0x5d,
	0x8d, 0x3f, 0x80, 0x21, 0xef, 0x8f, 0x8a, 0xe7, 0x84, 0x99, 0x35, 0xf5, 0xa5, 0x67, 0x45, 0x93,
	0xdc, 0x78, 0xcf, 0x7f, 0x4e, 0x98, 0x5b, 0x93, 0x2a, 0x59, 0xe1, 0xd7, 0x50, 0x66, 0x3c, 0x34,
	0x0d, 0x15, 0xd0, 0xdc, 0x5b, 0x14, 0x0f, 0xef, 0x4b, 0xae, 0xe4, 0xa4, 0x64, 0xc1, 0x43, 0x13,
	0x0e, 0x25, 0xa3, 0x8d, 0x64, 0xc1, 0x43, 0xfc, 0x19, 0x1a, 0xdb, 0xcb, 0x57, 0xd1, 0x75, 0x15,
	0x7d, 0x59, 0x68, 0xef, 0x36, 0xec, 0x26, 0xbd, 0x9e, 0x6b, 0xd5, 0x07, 0x7c, 0x81, 0xe6, 0x5f,
	0xaf, 0xc7, 0x6c, 0xa8, 0x9c, 0xbd, 0x5e, 0x4f, 0xd2, 0xb9, 0x81, 0xdb, 0xc8, 0xf6, 0x4e, 0xb7,
	0xff, 0x41, 0x73, 0x16, 0xf3, 0x79, 0xb4, 0x58, 0xa7, 0xea, 0xea, 0x3a, 0xef, 0xa0, 0x22, 0xa7,
	0xec, 0xbc, 0x85, 0x8a, 0x72, 0xaf, 0x43, 0x75, 0x4a, 0xbe, 0x92, 0xf1, 0x23, 0x41, 0x25, 0x5c,
	0x85, 0xb2, 0x4d, 0x6e, 0x91, 0x26, 0x8b, 0x11, 0xb9, 0x45, 0x7a, 0xc7, 0x87, 0x6a, 0x6e, 0xd5,
	0x71, 0xf2, 0x0e, 0x04, 0x8d, 0xbc, 0x83, 0xfa, 0x3f, 0x26, 0x36, 0x2a, 0xe1, 0x73, 0x40, 0xdf,
	0x2d, 0xea, 0xd9, 0xfe, 0x74, 0x42, 0xef, 0xfa, 0xce, 0xc3, 0xd4, 0xb5, 0x91, 0x86, 0xaf, 0xe0,
	0xc2, 0x26, 0xc3, 0x01, 0xfd, 0x87, 0xd2, 0x6f, 0x56, 0x70, 0xf1, 0xe2, 0x3b, 0xc3, 0x6f, 0xe0,
	0x7a, 0xeb, 0x6d, 0x5b, 0xb4, 0x3f, 0x99, 0x3c, 0x38, 0x83, 0xbe, 0xef, 0x8c, 0x09, 0x9d, 0xb8,
	0x63, 0x7f, 0x3c, 0x18, 0x3f, 0x1c, 0xc4, 0xb9, 0xf6, 0xb7, 0xa9, 0xed, 0xf9, 0x2f, 0xc5, 0x6d,
	0x29, 0xfd, 0xe6, 0x97, 0x06, 0xe8, 0xf0, 0x11, 0xe2, 0x57, 0x70, 0xb5, 0x8d, 0x1a, 0x8c, 0x09,
	0xb1, 0x07, 0x2a, 0xc6, 0xf3, 0xfb, 0xfe, 0xd4, 0x43, 0x25, 0xdc, 0x04, 0x23, 0x87, 0xed, 0x21,
	0xd2, 0xe4, 0xd0, 0x43, 0xc7, 0x2b, 0x10, 0x1d, 0xb7, 0xe0, 0x72, 0x77, 0xdc, 0x1b, 0xd0, 0x1e,
	0xa2, 0x32, 0x3e, 0x01, 0xd8, 0x7a, 0x92, 0x11, 0xaa, 0xe0, 0x53, 0x68, 0x7a, 0xf7, 0x53, 0x5f,
	0x9e, 0xe8, 0x50, 0xae, 0xfa, 0x48, 0xfa, 0x4b, 0x68, 0x73, 0x3c, 0x0e, 0x8f, 0xd5, 0x1f, 0xf9,
	0xf1, 0x4f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x92, 0xa2, 0xb1, 0x67, 0x5e, 0x04, 0x00, 0x00,
}
