context

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2021 License: Apache-2.0 Imports: 20 Imported by: 1

Documentation

Index

Constants

View Source
const (
	MaxValueOfRanUeNgapID int64 = 4294967295
	MaxNumOfPDUSessions   int   = 256
)
View Source
const (
	AmfUeNgapIdUnspecified int64 = 0xffffffffff
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AMFOverloadContent

type AMFOverloadContent struct {
	Action     *ngapType.OverloadAction
	TrafficInd *int64
	NSSAIList  []SliceOverloadItem
}

type AMFSCTPAddresses

type AMFSCTPAddresses struct {
	IPAddresses []string `yaml:"IP"`
	Port        int      `yaml:"Port,omitempty"`
}

type AMFTNLAssociationItem

type AMFTNLAssociationItem struct {
	Ipv4                   string
	Ipv6                   string
	TNLAssociationUsage    *ngapType.TNLAssociationUsage
	TNLAddressWeightFactor *int64
}

type BroadcastPLMNItem

type BroadcastPLMNItem struct {
	PLMNID              PLMNID             `yaml:"PLMNID"`
	TAISliceSupportList []SliceSupportItem `yaml:"TAISliceSupportList"`
}

type ChildSecurityAssociation

type ChildSecurityAssociation struct {
	// SPI
	SPI uint32

	// IP address
	PeerPublicIPAddr  net.IP
	LocalPublicIPAddr net.IP

	// Traffic selector
	SelectedIPProtocol    uint8
	TrafficSelectorLocal  net.IPNet
	TrafficSelectorRemote net.IPNet

	// Security
	EncryptionAlgorithm               uint16
	InitiatorToResponderEncryptionKey []byte
	ResponderToInitiatorEncryptionKey []byte
	IntegrityAlgorithm                uint16
	InitiatorToResponderIntegrityKey  []byte
	ResponderToInitiatorIntegrityKey  []byte
	ESN                               bool

	// Encapsulate
	EnableEncapsulate bool
	N3IWFPort         int
	NATPort           int

	// UE context
	ThisUE *N3IWFUe
}

type GTPConnectionInfo

type GTPConnectionInfo struct {
	UPFIPAddr           string
	UPFUDPAddr          net.Addr
	IncomingTEID        uint32
	OutgoingTEID        uint32
	UserPlaneConnection *gtpv1.UPlaneConn
}

type GlobalN3IWFID

type GlobalN3IWFID struct {
	PLMNID  PLMNID `yaml:"PLMNID"`
	N3IWFID uint16 `yaml:"N3IWFID"` // with length 2 bytes
}

type IKESecurityAssociation

type IKESecurityAssociation struct {
	// SPI
	RemoteSPI uint64
	LocalSPI  uint64

	// Message ID
	MessageID uint32

	// Transforms for IKE SA
	EncryptionAlgorithm    *ike_message.Transform
	PseudorandomFunction   *ike_message.Transform
	IntegrityAlgorithm     *ike_message.Transform
	DiffieHellmanGroup     *ike_message.Transform
	ExpandedSequenceNumber *ike_message.Transform

	// Used for key generating
	ConcatenatedNonce      []byte
	DiffieHellmanSharedKey []byte

	// Keys
	SK_d  []byte // used for child SA key deriving
	SK_ai []byte // used by initiator for integrity checking
	SK_ar []byte // used by responder for integrity checking
	SK_ei []byte // used by initiator for encrypting
	SK_er []byte // used by responder for encrypting
	SK_pi []byte // used by initiator for IKE authentication
	SK_pr []byte // used by responder for IKE authentication

	// State for IKE_AUTH
	State uint8

	// Temporary data stored for the use in later exchange
	InitiatorID              *ike_message.IdentificationInitiator
	InitiatorCertificate     *ike_message.Certificate
	IKEAuthResponseSA        *ike_message.SecurityAssociation
	TrafficSelectorInitiator *ike_message.TrafficSelectorInitiator
	TrafficSelectorResponder *ike_message.TrafficSelectorResponder
	LastEAPIdentifier        uint8

	// Authentication data
	LocalUnsignedAuthentication  []byte
	RemoteUnsignedAuthentication []byte

	// NAT detection
	// If UEIsBehindNAT == true, N3IWF should enable NAT traversal and
	// TODO: should support dynamic updating network address (MOBIKE)
	UEIsBehindNAT bool
	// If N3IWFIsBehindNAT == true, N3IWF should send UDP keepalive periodically
	N3IWFIsBehindNAT bool

	// UE context
	ThisUE *N3IWFUe
}

type N3IWFAMF

type N3IWFAMF struct {
	SCTPAddr              string
	SCTPConn              *sctp.SCTPConn
	AMFName               *ngapType.AMFName
	ServedGUAMIList       *ngapType.ServedGUAMIList
	RelativeAMFCapacity   *ngapType.RelativeAMFCapacity
	PLMNSupportList       *ngapType.PLMNSupportList
	AMFTNLAssociationList map[string]*AMFTNLAssociationItem // v4+v6 as key
	// Overload related
	AMFOverloadContent *AMFOverloadContent
	// Relative Context
	N3iwfUeList map[int64]*N3IWFUe // ranUeNgapId as key
}

func (*N3IWFAMF) AddAMFTNLAssociationItem

func (amf *N3IWFAMF) AddAMFTNLAssociationItem(info ngapType.CPTransportLayerInformation) *AMFTNLAssociationItem

func (*N3IWFAMF) DeleteAMFTNLAssociationItem

func (amf *N3IWFAMF) DeleteAMFTNLAssociationItem(info ngapType.CPTransportLayerInformation)

func (*N3IWFAMF) FindAMFTNLAssociationItem

func (amf *N3IWFAMF) FindAMFTNLAssociationItem(info ngapType.CPTransportLayerInformation) *AMFTNLAssociationItem

func (*N3IWFAMF) FindAvalibleAMFByCompareGUAMI

func (amf *N3IWFAMF) FindAvalibleAMFByCompareGUAMI(ueSpecifiedGUAMI *ngapType.GUAMI) bool

FindAvalibleAMFByCompareGUAMI compares the incoming GUAMI with AMF served GUAMI and return if this AMF is avalible for UE

func (*N3IWFAMF) FindUeByAmfUeNgapID

func (amf *N3IWFAMF) FindUeByAmfUeNgapID(id int64) *N3IWFUe

func (*N3IWFAMF) RemoveAllRelatedUe

func (amf *N3IWFAMF) RemoveAllRelatedUe()

func (*N3IWFAMF) StopOverload

func (amf *N3IWFAMF) StopOverload()

type N3IWFContext

type N3IWFContext struct {
	NFInfo           N3IWFNFInfo
	AMFSCTPAddresses []*sctp.SCTPAddr

	// ID generator
	RANUENGAPIDGenerator *idgenerator.IDGenerator
	TEIDGenerator        *idgenerator.IDGenerator

	// Pools
	UePool                 sync.Map // map[int64]*N3IWFUe, RanUeNgapID as key
	AMFPool                sync.Map // map[string]*N3IWFAMF, SCTPAddr as key
	AMFReInitAvailableList sync.Map // map[string]bool, SCTPAddr as key
	IKESA                  sync.Map // map[uint64]*IKESecurityAssociation, SPI as key
	ChildSA                sync.Map // map[uint32]*ChildSecurityAssociation, SPI as key
	GTPConnectionWithUPF   sync.Map // map[string]*gtpv1.UPlaneConn, UPF address as key
	AllocatedUEIPAddress   sync.Map // map[string]*N3IWFUe, IPAddr as key
	AllocatedUETEID        sync.Map // map[uint32]*N3IWFUe, TEID as key

	// N3IWF FQDN
	FQDN string

	// Security data
	CertificateAuthority []byte
	N3IWFCertificate     []byte
	N3IWFPrivateKey      *rsa.PrivateKey

	// UEIPAddressRange
	Subnet *net.IPNet

	// Network interface mark for xfrm
	Mark uint32

	// N3IWF local address
	IKEBindAddress      string
	IPSecGatewayAddress string
	GTPBindAddress      string
	TCPPort             uint16

	// N3IWF NWu interface IPv4 packet connection
	NWuIPv4PacketConn *ipv4.PacketConn
}

func N3IWFSelf

func N3IWFSelf() *N3IWFContext

Create new N3IWF context

func (*N3IWFContext) AMFPoolLoad

func (context *N3IWFContext) AMFPoolLoad(sctpAddr string) (*N3IWFAMF, bool)

func (*N3IWFContext) AMFReInitAvailableListLoad

func (context *N3IWFContext) AMFReInitAvailableListLoad(sctpAddr string) (bool, bool)

func (*N3IWFContext) AMFReInitAvailableListStore

func (context *N3IWFContext) AMFReInitAvailableListStore(sctpAddr string, flag bool)

func (*N3IWFContext) AMFSelection

func (context *N3IWFContext) AMFSelection(ueSpecifiedGUAMI *ngapType.GUAMI) *N3IWFAMF

func (*N3IWFContext) AllocatedUEIPAddressLoad

func (context *N3IWFContext) AllocatedUEIPAddressLoad(ipAddr string) (*N3IWFUe, bool)

func (*N3IWFContext) AllocatedUETEIDLoad

func (context *N3IWFContext) AllocatedUETEIDLoad(teid uint32) (*N3IWFUe, bool)

func (*N3IWFContext) DeleteAMFReInitAvailableFlag

func (context *N3IWFContext) DeleteAMFReInitAvailableFlag(sctpAddr string)

func (*N3IWFContext) DeleteGTPConnection

func (context *N3IWFContext) DeleteGTPConnection(upfAddr string)

func (*N3IWFContext) DeleteIKESecurityAssociation

func (context *N3IWFContext) DeleteIKESecurityAssociation(spi uint64)

func (*N3IWFContext) DeleteInternalUEIPAddr

func (context *N3IWFContext) DeleteInternalUEIPAddr(ipAddr string)

func (*N3IWFContext) DeleteN3iwfAmf

func (context *N3IWFContext) DeleteN3iwfAmf(sctpAddr string)

func (*N3IWFContext) DeleteN3iwfUe

func (context *N3IWFContext) DeleteN3iwfUe(ranUeNgapId int64)

func (*N3IWFContext) DeleteTEID

func (context *N3IWFContext) DeleteTEID(teid uint32)

func (*N3IWFContext) GTPConnectionWithUPFLoad

func (context *N3IWFContext) GTPConnectionWithUPFLoad(upfAddr string) (*gtpv1.UPlaneConn, bool)

func (*N3IWFContext) GTPConnectionWithUPFStore

func (context *N3IWFContext) GTPConnectionWithUPFStore(upfAddr string, conn *gtpv1.UPlaneConn)

func (*N3IWFContext) IKESALoad

func (context *N3IWFContext) IKESALoad(spi uint64) (*IKESecurityAssociation, bool)

func (*N3IWFContext) NewIKESecurityAssociation

func (context *N3IWFContext) NewIKESecurityAssociation() *IKESecurityAssociation

func (*N3IWFContext) NewInternalUEIPAddr

func (context *N3IWFContext) NewInternalUEIPAddr(ue *N3IWFUe) net.IP

func (*N3IWFContext) NewN3iwfAmf

func (context *N3IWFContext) NewN3iwfAmf(sctpAddr string, conn *sctp.SCTPConn) *N3IWFAMF

func (*N3IWFContext) NewN3iwfUe

func (context *N3IWFContext) NewN3iwfUe() *N3IWFUe

func (*N3IWFContext) NewTEID

func (context *N3IWFContext) NewTEID(ue *N3IWFUe) uint32

func (*N3IWFContext) UePoolLoad

func (context *N3IWFContext) UePoolLoad(ranUeNgapId int64) (*N3IWFUe, bool)

type N3IWFNFInfo

type N3IWFNFInfo struct {
	GlobalN3IWFID   GlobalN3IWFID     `yaml:"GlobalN3IWFID"`
	RanNodeName     string            `yaml:"Name,omitempty"`
	SupportedTAList []SupportedTAItem `yaml:"SupportedTAList"`
}

type N3IWFUe

type N3IWFUe struct {
	/* UE identity */
	RanUeNgapId      int64
	AmfUeNgapId      int64
	IPAddrv4         string
	IPAddrv6         string
	PortNumber       int32
	MaskedIMEISV     *ngapType.MaskedIMEISV // TS 38.413 9.3.1.54
	Guti             string
	IPSecInnerIP     net.IP
	IPSecInnerIPAddr *net.IPAddr // Used to send UP packets to UE

	/* Relative Context */
	AMF *N3IWFAMF

	/* PDU Session */
	PduSessionList map[int64]*PDUSession // pduSessionId as key

	/* PDU Session Setup Temporary Data */
	TemporaryPDUSessionSetupData *PDUSessionSetupTemporaryData
	/* Temporary cached NAS message */
	// Used when NAS registration accept arrived before
	// UE setup NAS TCP connection with N3IWF
	TemporaryCachedNASMessage []byte

	/* Security */
	Kn3iwf               []uint8                          // 32 bytes (256 bits), value is from NGAP IE "Security Key"
	SecurityCapabilities *ngapType.UESecurityCapabilities // TS 38.413 9.3.1.86

	/* IKE Security Association */
	N3IWFIKESecurityAssociation   *IKESecurityAssociation
	N3IWFChildSecurityAssociation *ChildSecurityAssociation

	/* NAS IKE Connection */
	IKEConnection *UDPSocketInfo
	/* NAS TCP Connection */
	TCPConnection net.Conn

	/* Others */
	Guami                            *ngapType.GUAMI
	IndexToRfsp                      int64
	Ambr                             *ngapType.UEAggregateMaximumBitRate
	AllowedNssai                     *ngapType.AllowedNSSAI
	RadioCapability                  *ngapType.UERadioCapability                // TODO: This is for RRC, can be deleted
	CoreNetworkAssistanceInformation *ngapType.CoreNetworkAssistanceInformation // TS 38.413 9.3.1.15
	IMSVoiceSupported                int32
	RRCEstablishmentCause            int16
}

func (*N3IWFUe) AttachAMF

func (ue *N3IWFUe) AttachAMF(sctpAddr string) bool

func (*N3IWFUe) CreateIKEChildSecurityAssociation

func (ue *N3IWFUe) CreateIKEChildSecurityAssociation(
	chosenSecurityAssociation *ike_message.SecurityAssociation) (*ChildSecurityAssociation, error)

func (*N3IWFUe) CreatePDUSession

func (ue *N3IWFUe) CreatePDUSession(pduSessionID int64, snssai ngapType.SNSSAI) (*PDUSession, error)

func (*N3IWFUe) DetachAMF

func (ue *N3IWFUe) DetachAMF()

func (*N3IWFUe) FindPDUSession

func (ue *N3IWFUe) FindPDUSession(pduSessionID int64) *PDUSession

func (*N3IWFUe) Remove

func (ue *N3IWFUe) Remove()

type PDUSession

type PDUSession struct {
	Id                               int64 // PDU Session ID
	Type                             *ngapType.PDUSessionType
	Ambr                             *ngapType.PDUSessionAggregateMaximumBitRate
	Snssai                           ngapType.SNSSAI
	NetworkInstance                  *ngapType.NetworkInstance
	SecurityCipher                   bool
	SecurityIntegrity                bool
	MaximumIntegrityDataRateUplink   *ngapType.MaximumIntegrityProtectedDataRate
	MaximumIntegrityDataRateDownlink *ngapType.MaximumIntegrityProtectedDataRate
	GTPConnection                    *GTPConnectionInfo
	QFIList                          []uint8
	QosFlows                         map[int64]*QosFlow // QosFlowIdentifier as key
}

type PDUSessionSetupTemporaryData

type PDUSessionSetupTemporaryData struct {
	// Slice of unactivated PDU session
	UnactivatedPDUSession []int64 // PDUSessionID as content
	// NGAPProcedureCode is used to identify which type of
	// response shall be used
	NGAPProcedureCode ngapType.ProcedureCode
	// PDU session setup list response
	SetupListCxtRes  *ngapType.PDUSessionResourceSetupListCxtRes
	FailedListCxtRes *ngapType.PDUSessionResourceFailedToSetupListCxtRes
	SetupListSURes   *ngapType.PDUSessionResourceSetupListSURes
	FailedListSURes  *ngapType.PDUSessionResourceFailedToSetupListSURes
}

type PLMNID

type PLMNID struct {
	Mcc string `yaml:"MCC"`
	Mnc string `yaml:"MNC"`
}

type QosFlow

type QosFlow struct {
	Identifier int64
	Parameters ngapType.QosFlowLevelQosParameters
}

type SNSSAIItem

type SNSSAIItem struct {
	SST string `yaml:"SST"`
	SD  string `yaml:"SD,omitempty"`
}

type SliceOverloadItem

type SliceOverloadItem struct {
	SNssaiList []ngapType.SNSSAI
	Action     *ngapType.OverloadAction
	TrafficInd *int64
}

type SliceSupportItem

type SliceSupportItem struct {
	SNSSAI SNSSAIItem `yaml:"SNSSAI"`
}

type SupportedTAItem

type SupportedTAItem struct {
	TAC               string              `yaml:"TAC"`
	BroadcastPLMNList []BroadcastPLMNItem `yaml:"BroadcastPLMNList"`
}

type UDPSocketInfo

type UDPSocketInfo struct {
	Conn      *net.UDPConn
	N3IWFAddr *net.UDPAddr
	UEAddr    *net.UDPAddr
}

Jump to

Keyboard shortcuts

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