-
Notifications
You must be signed in to change notification settings - Fork 26
/
config.go
145 lines (130 loc) · 4.62 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// Copyright 2018-2024 go-m3ua authors. All rights reserved.
// Use of this source code is governed by a MIT-style license that can be
// found in the LICENSE file.
package m3ua
import (
"time"
"github.com/wmnsk/go-m3ua/messages/params"
)
// HeartbeatInfo is a set of information for M3UA BEAT.
type HeartbeatInfo struct {
Enabled bool
Interval time.Duration
Timer time.Duration
Data []byte
}
// NewHeartbeatInfo creates a new HeartbeatInfo.
func NewHeartbeatInfo(interval, timer time.Duration, data []byte) *HeartbeatInfo {
return &HeartbeatInfo{
Enabled: true, Interval: interval, Timer: timer, Data: data,
}
}
// Config is a configration that defines a M3UA server.
type Config struct {
*HeartbeatInfo
AspIdentifier *params.Param
TrafficModeType *params.Param
NetworkAppearance *params.Param
RoutingContexts *params.Param
CorrelationID *params.Param
OriginatingPointCode uint32
DestinationPointCode uint32
ServiceIndicator uint8
NetworkIndicator uint8
MessagePriority uint8
SignalingLinkSelection uint8
}
// NewConfig creates a new Config.
//
// To set additional parameters, use constructors in param package or
// setters defined in this package. Note that the params left nil won't
// appear in the packets but the initialized params will, with zero
// values.
func NewConfig(opc, dpc uint32, si, ni, mp, sls uint8) *Config {
return &Config{
OriginatingPointCode: opc,
DestinationPointCode: dpc,
ServiceIndicator: si,
NetworkIndicator: ni,
MessagePriority: mp,
SignalingLinkSelection: sls,
}
}
// EnableHeartbeat enables M3UA BEAT with interval and expiration timer
// given.
//
// The data is hard-coded by default. Manipulate the exported field
// Config.HeartbeatInfo.Data to customize it such as including current
// time to identify the BEAT and BEAT ACK pair.
func (c *Config) EnableHeartbeat(interval, timer time.Duration) *Config {
c.HeartbeatInfo = NewHeartbeatInfo(
interval, timer,
[]byte("Hi, this is a BEAT from go-m3ua. Are you alive?"),
)
return c
}
// SetAspIdentifier sets AspIdentifier in Config.
func (c *Config) SetAspIdentifier(id uint32) *Config {
c.AspIdentifier = params.NewAspIdentifier(id)
return c
}
// SetTrafficModeType sets TrafficModeType in Config.
func (c *Config) SetTrafficModeType(tmType uint32) *Config {
c.TrafficModeType = params.NewTrafficModeType(tmType)
return c
}
// SetNetworkAppearance sets NetworkAppearance in Config.
func (c *Config) SetNetworkAppearance(nwApr uint32) *Config {
c.NetworkAppearance = params.NewNetworkAppearance(nwApr)
return c
}
// SetRoutingContexts sets RoutingContexts in Config.
func (c *Config) SetRoutingContexts(rtCtxs ...uint32) *Config {
c.RoutingContexts = params.NewRoutingContext(rtCtxs...)
return c
}
// SetCorrelationID sets CorrelationID in Config.
func (c *Config) SetCorrelationID(id uint32) *Config {
c.CorrelationID = params.NewCorrelationID(id)
return c
}
// NewClientConfig creates a new Config for Client.
//
// The optional parameters that is not required (like CorrelationID)
// can be omitted by setting it to nil after created *Config.
func NewClientConfig(hbInfo *HeartbeatInfo, opc, dpc, aspID, tmt, nwApr, corrID uint32, rtCtxs []uint32, si, ni, mp, sls uint8) *Config {
return &Config{
HeartbeatInfo: hbInfo,
AspIdentifier: params.NewAspIdentifier(aspID),
TrafficModeType: params.NewTrafficModeType(tmt),
NetworkAppearance: params.NewNetworkAppearance(nwApr),
RoutingContexts: params.NewRoutingContext(rtCtxs...),
CorrelationID: params.NewCorrelationID(corrID),
OriginatingPointCode: opc,
DestinationPointCode: dpc,
ServiceIndicator: si,
NetworkIndicator: ni,
MessagePriority: mp,
SignalingLinkSelection: sls,
}
}
// NewServerConfig creates a new Config for Server.
//
// The optional parameters that is not required (like CorrelationID)
// can be omitted by setting it to nil after created *Config.
func NewServerConfig(hbInfo *HeartbeatInfo, opc, dpc, aspID, tmt, nwApr, corrID uint32, rtCtxs []uint32, si, ni, mp, sls uint8) *Config {
return &Config{
HeartbeatInfo: hbInfo,
AspIdentifier: params.NewAspIdentifier(aspID),
TrafficModeType: params.NewTrafficModeType(tmt),
NetworkAppearance: params.NewNetworkAppearance(nwApr),
RoutingContexts: params.NewRoutingContext(rtCtxs...),
CorrelationID: params.NewCorrelationID(corrID),
OriginatingPointCode: opc,
DestinationPointCode: dpc,
ServiceIndicator: si,
NetworkIndicator: ni,
MessagePriority: mp,
SignalingLinkSelection: sls,
}
}