diameter

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2020 License: BSD-3-Clause Imports: 23 Imported by: 0

Documentation

Overview

Shared diameter settings across magma cloud

Index

Constants

View Source
const (
	DiamHost        = "magma-fedgw.magma.com"
	DiamRealm       = "magma.com"
	DiamProductName = "magma"
	Vendor3GPP      = uint32(10415) // diameter code for a 3GPP application

	AddrFlag              = "addr"
	NetworkFlag           = "network"
	HostFlag              = "host"
	RealmFlag             = "realm"
	ProductFlag           = "product"
	LocalAddrFlag         = "laddr"
	DestHostFlag          = "dest_host"
	DestRealmFlag         = "dest_realm"
	DisableDestHostFlag   = "disable_dest_host"
	OverwriteDestHostFlag = "overwrite_dest_host"

	DefaultWatchdogIntervalSeconds = 3
)
View Source
const (
	// SuccessCode is the result code returned from a successful diameter call
	SuccessCode                = 2001
	LimitedSuccessCode         = 2002
	DiameterRatingFailed       = 5031
	DiameterCreditLimitReached = 4012
)
View Source
const (
	ServiceContextIDDefault = "32251@3gpp.org" // Packet-Switch service context
	ServiceIDDefault        = 0
)

Variables

This section is empty.

Functions

func DecodeSessionID

func DecodeSessionID(diamSid string) string

DecodeSessionID extracts and returns session ID if available, or original diam SessionId (diamSid) string otherwise Input: OriginHost;rand1#;rand2#;IMSIxyz Returns: IMSIxyz-rand# rand# = rand1# + rand2#, where + means concatenation

func EncodePLMNID

func EncodePLMNID(plmn string) ([]byte, error)

EncodePLMNID encodes a PLMN into its byte encoding See https://www.arib.or.jp/english/html/overview/doc/STD-T63v10_70/5_Appendix/Rel11/29/29272-bb0.pdf#page=73

func EncodeSessionID

func EncodeSessionID(diamIdentity, sid string) string

EncodeSessionID encodes SessionID in rfc6733 compliant form: <DiameterIdentity>;<high 32 bits>;<low 32 bits>[;<optional value>] OriginHost/Realm;rand#;rand#;IMSIxyz

func EncodeUserLocation

func EncodeUserLocation(plmn string, tai uint16, eci uint32) ([]byte, error)

EncodeUserLocation encodes a PLMN ID, TAI, and ECI into the correct encoding for 3GPP-User-Location-Info. Normally this value is provided by the EPC, but this function can be used for command lines. Encoding defined in 3GPP 29.061 Section 16.4.7.2

func ExtractImsiFromSessionID

func ExtractImsiFromSessionID(diamSid string) (string, error)

ExtractImsiFromSessionID extracts and returns IMSI (without 'IMSI' prefix) from diameter session ID if available, or original diam SessionId (diamSid) string otherwise Input: OriginHost;[rand1#;rand2#;]IMSIxyz Returns: xyz

func GenSessionID

func GenSessionID(identity, protocol string) string

GenSessionID generates rfc6733 compliant session ID:

<DiameterIdentity>;<high 32 bits>;<low 32 bits>[;<optional value>]

Where <optional value> is base 16 uint32 random number

func GenSessionIDOpt

func GenSessionIDOpt(identity, protocol, opt string) string

GenSessionIDOpt generates rfc6733 compliant session ID:

<DiameterIdentity>;<high 32 bits>;<low 32 bits>[;<optional value>]

func GenSessionIdImsi

func GenSessionIdImsi(identity, protocol, imsi string) string

GenSessionIDOpt generates rfc6733 compliant session ID:

<DiameterIdentity>;<high 32 bits>;<low 32 bits>;IMSI<imsi value>

func GetBoolValueOrEnv

func GetBoolValueOrEnv(flagName string, envVariable string, defaultValue bool, idx ...int) bool

GetBoolValueOrEnv returns value of the flagValue if it exists, then the environment variable if it exists, or defaultValue if not. If idx parameter is passed, then if that idx > 1 defaultValue will be returned. Note in case of many idx are passed, only the first idx will be checked.

func GetValue

func GetValue(flagName, defaultValue string) string

GetValue returns value of the flagValue if it exists, or defaultValue if not

func GetValueOrEnv

func GetValueOrEnv(flagName, envVariable, defaultValue string, idx ...int) string

GetValueOrEnv returns value of the flagValue if it exists, then the environment variable if it exists, or defaultValue if not. If idx parameter is passed, then if that idx > 1 defaultValue will be returned. Note in case of many idx are passed, only the first idx will be checked.

func GetValueUint64

func GetValueUint64(flagName string, defaultValue uint64) uint64

GetValueUint64 returns value of the flagValue if it exists, or defaultValue if not

func NewProxiableRequest

func NewProxiableRequest(cmd uint32, appid uint32, dictionary *dict.Parser) *diam.Message

NewProxiableRequest creates a request with the proxy bit set, meaning that a diameter server can relay the request to another server. This is required by certain servers

func ParseDiamSessionID

func ParseDiamSessionID(sessionID string) (host, rnd1, rnd2, imsi, bearrerId string)

ParseDiamSessionID parses given session ID in the form of: // OriginHost;req#;rand#;IMSIxyz_BearerId and returns OriginHost, Request Number, Rand, IMSI (without prefix) and bearrerId if present

func TranslateDiamResultCode

func TranslateDiamResultCode(diamResult uint32) error

TranslateDiamResultCode maps Diameter Result Codes (both Base and Experimental) to GRPC Status Error. Diam success codes result in a nil error returned

Types

type ASA

type ASA struct {
	SessionID  string `avp:"Session-Id"`
	ResultCode uint32 `avp:"Result-Code"`
}
Abort-Session Answer (ASA)

< Session-Id > { Origin-Host } { Origin-Realm } [ Result-Code ] [ Experimental-Result ] [ Origin-State-Id ] [ Error-Message ] [ Error-Reporting-Host ] *[ Failed-AVP ] *[ Redirected-Host ] [ Redirected-Host-Usage ] [ Redirected-Max-Cache-Time ] *[ Proxy-Info ] *[ AVP ]

type ASR

type ASR struct {
	SessionID         string                    `avp:"Session-Id"`
	OriginHost        datatype.DiameterIdentity `avp:"Origin-Host"`
	OriginRealm       datatype.DiameterIdentity `avp:"Origin-Realm"`
	DestinationHost   datatype.DiameterIdentity `avp:"Destination-Host"`
	DestinationRealm  datatype.DiameterIdentity `avp:"Destination-Realm"`
	AuthApplicationId datatype.Unsigned32       `avp:"Auth-Application-Id"`
	UserName          datatype.UTF8String       `avp:"User-Name"`
	OriginStateId     datatype.Unsigned32       `avp:"Origin-State-Id"`
}

https://tools.ietf.org/html/rfc4005#page-16

Abort-Session Request (ASR)

< Session-Id > { Origin-Host } { Origin-Realm } { Destination-Realm } { Destination-Host } { Auth-Application-Id } [ User-Name ] [ Origin-State-Id ] * [ Proxy-Info ] * [ Route-Record ] * [ AVP ]

type AnswerHandler

type AnswerHandler func(message *diam.Message) KeyAndAnswer

AnswerHandler is called when an answer is received. The handler is responsible for parsing a raw message into a usable message and then returning it. The return value is used to untrack the request and send the answer to the given channel Input: message received Output: struct containing the related request key and parsed answer

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a wrapper around a sm.Client that handles connection management, request tracking, and configuration. Using this, the application should not know anything about the underlying diameter connection

func NewClient

func NewClient(clientCfg *DiameterClientConfig) *Client

NewClient creates a new client based on the config passed. Input: clientCfg containing relavent diameter settings

func (*Client) AddOriginAVPsToMessage

func (client *Client) AddOriginAVPsToMessage(message *diam.Message) *diam.Message

AddOriginAVPsToMessage adds the host/realm to the message

func (*Client) BeginConnection

func (client *Client) BeginConnection(server *DiameterServerConfig) error

BeginConnection attempts to begin a new connection with the server

func (*Client) DisableConnectionCreation

func (client *Client) DisableConnectionCreation(period time.Duration)

DisableConnectionCreation closes all existing connections and disables the connection manager to create new connections for the period of time specified

func (*Client) EnableConnectionCreation

func (client *Client) EnableConnectionCreation()

EnableConnectionCreation enables the connection manager to create new connections

func (*Client) IgnoreAnswer

func (client *Client) IgnoreAnswer(key interface{})

IgnoreAnswer untracks a request if the application, say, times out Input: key identifying request

func (*Client) OriginHost

func (c *Client) OriginHost() string

OriginHost returns client's config Host

func (*Client) OriginRealm

func (c *Client) OriginRealm() string

OriginRealm returns client's config Realm

func (*Client) OriginStateID

func (c *Client) OriginStateID() uint32

OriginStateID returns client's Origin-State-ID

func (*Client) RegisterAnswerHandler

func (client *Client) RegisterAnswerHandler(command uint32, handler AnswerHandler)

RegisterAnswerHandler registers a function to be called when an answer message matching the given command is received. The AnswerHandler is responsible for parsing the diameter message into something usable and extracting a key to identify the corresponding request Input: command - the diameter code for the command (like diam.CreditControl)

handler - the function to call when a message is received

func (*Client) RegisterAnswerHandlerForAppID

func (client *Client) RegisterAnswerHandlerForAppID(command uint32, appID uint32, handler AnswerHandler)

RegisterAnswerHandlerForAppID registers a function to be called when an answer message matching the given command is received. The AnswerHandler is responsible for parsing the diameter message into something usable and extracting a key to identify the corresponding request Input: command - the diameter code for the command (like diam.CreditControl)

handler - the function to call when a message is received

func (*Client) RegisterHandler

func (client *Client) RegisterHandler(command uint32, appID uint32, request bool, handler diam.Handler)

RegisterHandler registers diameter handler to be used for given command and app

func (*Client) RegisterRequestHandlerForAppID

func (client *Client) RegisterRequestHandlerForAppID(command uint32, appID uint32, handler diam.HandlerFunc)

RegisterRequestHandlerForAppID registers a function to be called when a request message matching the command is received. The RequestHandler is responsible for parsing the diameter message, taking any actions required, and sending a response back through the responder argument of the handler. This responder is given so that the response can happen asynchonously in another go routine. Input: command - the diameter code for the command (like diam.CreditControl)

handler - the function to call when a message is received

func (*Client) Retries

func (client *Client) Retries() uint

func (*Client) SendRequest

func (client *Client) SendRequest(
	server *DiameterServerConfig,
	done chan interface{},
	message *diam.Message,
	key interface{},
) error

SendRequest sends a diameter request message to the given server and sends back the answer on the given channel. A key is required to identify the corresponding answer. Additionally, SendRequest will add the OriginHost/Realm AVPs to the message because they are mandatory for all requests Input: server - cfg containing info on what server to send to

done - channel to send the answer to when received
message - request to send
key - something to uniquely identify the request

Output: error if message sending failed, nil otherwise

func (*Client) ServiceContextId

func (c *Client) ServiceContextId() string

ServiceContextId returns client's config ServiceContextId

type Connection

type Connection struct {
	// contains filtered or unexported fields
}

Connection is representing a diameter connection that you can send messages to and get metadata from (for building AVPs)

func (*Connection) SendAnswer

func (c *Connection) SendAnswer(message *diam.Message, retryCount uint) error

func (*Connection) SendRequest

func (c *Connection) SendRequest(message *diam.Message, retryCount uint) error

func (*Connection) SendRequestToServer

func (c *Connection) SendRequestToServer(message *diam.Message, retryCount uint, server *DiameterServerConfig) error

type ConnectionManager

type ConnectionManager struct {
	// contains filtered or unexported fields
}

ConnectionManager holds a map of connections keyed by the server ip/protocol pair

func NewConnectionManager

func NewConnectionManager() *ConnectionManager

func (*ConnectionManager) AddExistingConnection

func (cm *ConnectionManager) AddExistingConnection(conn diam.Conn, client *sm.Client, server *DiameterServerConfig) error

AddExistingConnection adds an already in-use connection to the connection manager. This is used for servers that need to maintain a connection mapping to clients If a connection already exists for the provided server config, update the connection manager with the new connection. This is threadsafe

func (*ConnectionManager) CleanupAllConnections

func (cm *ConnectionManager) CleanupAllConnections()

CleanupAllConnections does exactly that

func (*ConnectionManager) DisableFor

func (cm *ConnectionManager) DisableFor(period time.Duration)

DisableFor - cleans up all existing connections & disables new connection creations for given duration

func (*ConnectionManager) Enable

func (cm *ConnectionManager) Enable()

Enable - enables new connection creations

func (*ConnectionManager) GetConnection

func (cm *ConnectionManager) GetConnection(client *sm.Client, server *DiameterServerConfig) (*Connection, error)

GetConnection either gets the existing connection or creates a new one if it doesn't exist. This is threadsafe

type DiameterClientConfig

type DiameterClientConfig struct {
	Host               string // diameter host
	Realm              string // diameter realm
	ProductName        string
	AppID              uint32
	AuthAppID          uint32
	Retransmits        uint
	WatchdogInterval   uint
	RetryCount         uint // number of times to reconnect after connection lost
	SupportedVendorIDs string
	ServiceContextId   string
}

DiameterClientConfig holds information for connecting with a diameter server

func (*DiameterClientConfig) FillInDefaults

func (srcCfg *DiameterClientConfig) FillInDefaults() *DiameterClientConfig

func (*DiameterClientConfig) GenSessionID

func (client *DiameterClientConfig) GenSessionID(protocol string) string

GenSessionID generates rfc6733 compliant session ID:

<DiameterIdentity>;<high 32 bits>;<low 32 bits>[;<optional value>]

Where <DiameterIdentity> is client.Host|ProductName-protocol

and <optional value> is base 16 uint32 random number

func (*DiameterClientConfig) GenSessionIDOpt

func (client *DiameterClientConfig) GenSessionIDOpt(protocol, opt string) string

GenSessionIDOpt generates rfc6733 compliant session ID:

<DiameterIdentity>;<high 32 bits>;<low 32 bits>[;<optional value>]

Where <DiameterIdentity> is client.Host|ProductName-protocol

func (*DiameterClientConfig) GenSessionIdImsi

func (client *DiameterClientConfig) GenSessionIdImsi(protocol, imsi string) string

GenSessionIdImsi generates rfc6733 compliant session ID:

<DiameterIdentity>;<high 32 bits>;<low 32 bits>;IMSI<imsi>]

Where <DiameterIdentity> is client.Host|ProductName-protocol

and <optional value> is base 16 uint32 random number

func (*DiameterClientConfig) Validate

func (cfg *DiameterClientConfig) Validate() error

type DiameterServerConfig

type DiameterServerConfig struct {
	DiameterServerConnConfig
	DestHost          string
	DestRealm         string
	DisableDestHost   bool
	OverwriteDestHost bool
}

func (*DiameterServerConfig) Validate

func (cfg *DiameterServerConfig) Validate() error

type DiameterServerConnConfig

type DiameterServerConnConfig struct {
	Addr      string // host:port
	Protocol  string // tcp/sctp
	LocalAddr string // IP:port or :port
}

type KeyAndAnswer

type KeyAndAnswer struct{ Answer, Key interface{} }

KeyAndAnswer wraps the information to be returned to an AnswerHandler. When an answer is received, the handler should return a parsed answer (struct form) and the key that maps it to a request

type RequestTracker

type RequestTracker struct {
	// contains filtered or unexported fields
}

RequestTracker stores a mapping of keys to channels and is intended to be used to store unique identifiers of requests and channels to send answers to after they are received. The methods are thread safe and do not close the channel after use

func NewRequestTracker

func NewRequestTracker() *RequestTracker

func (*RequestTracker) DeregisterRequest

func (rt *RequestTracker) DeregisterRequest(key interface{}) chan interface{}

DeregisterRequest finds the channel in the map, removes and returns it. If no channel is found, nil is returned

func (*RequestTracker) RegisterRequest

func (rt *RequestTracker) RegisterRequest(key interface{}, ch chan interface{}) chan interface{}

RegisterRequest tracks a request in the map and returns the channel stored

Jump to

Keyboard shortcuts

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