Skip to content

Commit

Permalink
add missing-hb-allowed
Browse files Browse the repository at this point in the history
  • Loading branch information
katayama committed Oct 26, 2017
1 parent b4522a7 commit d2b9e35
Show file tree
Hide file tree
Showing 24 changed files with 82 additions and 18 deletions.
1 change: 1 addition & 0 deletions dots_client/sampleSessionConfiguration.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"session-id": 1234543241,
"heartbeat-interval": 30,
"missing-hb-allowed": 5,
"max-retransmit": 7,
"ack-timeout": 50,
"ack-random-factor": 1.5
Expand Down
2 changes: 2 additions & 0 deletions dots_common/messages/signal.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ type SignalConfig struct {
SessionId int `json:"session-id" cbor:"session-id"`
// Heartbeat interval to check the DOTS peer health. This is an optional attribute.
HeartbeatInterval int `json:"heartbeat-interval" cbor:"heartbeat-interval"`
// Maximum number of missing heartbeat response allowed. This is an optional attribute.
MissingHbAllowed int `json:"missing-hb-allowed" cbor:"missing-hb-allowed"`
// Maximum number of retransmissions for a message (referred to as MAX_RETRANSMIT parameter in CoAP).
// This is an optional attribute.
MaxRetransmit int `json:"max-retransmit" cbor:"max-retransmit"`
Expand Down
3 changes: 3 additions & 0 deletions dots_common/schemas/session_configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
"heartbeat-interval": {
"type": "integer"
},
"missing-hb-allowed": {
"type": "integer"
},
"max-retransmit": {
"type": "integer"
},
Expand Down
4 changes: 4 additions & 0 deletions dots_server/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
"min_value": 15,
"max_value": 60
},
"missing_hb_allowed": {
"min_value": 3,
"max_value": 9
},
"max_retransmit": {
"min_value": 3,
"max_value": 15
Expand Down
3 changes: 3 additions & 0 deletions dots_server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type Storable interface {

type SignalConfigurationParameterNode struct {
HeartbeatInterval string `yaml:"heartbeatInterval"`
MissingHbAllowed string `yaml:"missingHbAllowed"`
MaxRetransmit string `yaml:"maxRetransmit"`
AckTimeout string `yaml:"ackTimeout"`
AckRandomFactor string `yaml:"ackRandomFactor"`
Expand All @@ -42,6 +43,7 @@ type SignalConfigurationParameterNode struct {
func (scpn SignalConfigurationParameterNode) Convert() (interface{}, error) {
return &SignalConfigurationParameter{
HeartbeatInterval: parseParameterRange(scpn.HeartbeatInterval),
MissingHbAllowed: parseParameterRange(scpn.MissingHbAllowed),
MaxRetransmit: parseParameterRange(scpn.MaxRetransmit),
AckTimeout: parseParameterRange(scpn.AckTimeout),
AckRandomFactor: parseParameterRange(scpn.AckRandomFactor),
Expand Down Expand Up @@ -395,6 +397,7 @@ func parseParameterRange(input string) *ParameterRange {

type SignalConfigurationParameter struct {
HeartbeatInterval *ParameterRange
MissingHbAllowed *ParameterRange
MaxRetransmit *ParameterRange
AckTimeout *ParameterRange
AckRandomFactor *ParameterRange
Expand Down
2 changes: 2 additions & 0 deletions dots_server/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ func TestParseConfig(t *testing.T) {
expected := &ServerSystemConfig{
SignalConfigurationParameter: &SignalConfigurationParameter{
&ParameterRange{60, 60},
&ParameterRange{5, 5},
&ParameterRange{3, 3},
&ParameterRange{30, 30},
&ParameterRange{8888, 8888},
Expand Down Expand Up @@ -55,6 +56,7 @@ var configText = `
system:
signalConfigurationParameter:
heartbeatInterval: 60
missingHbAllowed: 5
maxRetransmit: 3
ackTimeout: 30
ackRandomFactor: 8888
Expand Down
1 change: 1 addition & 0 deletions dots_server/controllers/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ var configText = `
system:
signalConfigurationParameter:
heartbeatInterval: 15-60
missingHbAllowed: 3-9
maxRetransmit: 3-15
ackTimeout: 1-30
ackRandomFactor: 1-4
Expand Down
3 changes: 2 additions & 1 deletion dots_server/controllers/session_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (m *SessionConfiguration) Post(request interface{}, customer *models.Custom

// validate
signalSessionConfiguration := models.NewSignalSessionConfiguration(payload.SessionId, payload.HeartbeatInterval,
payload.MaxRetransmit, payload.AckTimeout, payload.AckRandomFactor)
payload.MissingHbAllowed, payload.MaxRetransmit, payload.AckTimeout, payload.AckRandomFactor)
v := models.SignalConfigurationValidator{}
validateResult := v.Validate(signalSessionConfiguration, *customer)
if !validateResult {
Expand Down Expand Up @@ -75,6 +75,7 @@ func sessionConfigurationPayloadDisplay(data *messages.SignalConfig) {
var result string = "\n"
result += fmt.Sprintf(" \"%s\": %d\n", "session-id", data.SessionId)
result += fmt.Sprintf(" \"%s\": %d\n", "heartbeat-interval", data.HeartbeatInterval)
result += fmt.Sprintf(" \"%s\": %d\n", "missing-hb-allowed", data.MissingHbAllowed)
result += fmt.Sprintf(" \"%s\": %d\n", "max-retransmit", data.MaxRetransmit)
result += fmt.Sprintf(" \"%s\": %d\n", "ack-timeout", data.AckTimeout)
result += fmt.Sprintf(" \"%s\": %f\n", "ack-random-factor", data.AckRandomFactor)
Expand Down
1 change: 1 addition & 0 deletions dots_server/controllers/session_configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func TestSessionConfiguration_Post(t *testing.T) {
request := messages.SignalConfig{
SessionId: 1234567,
HeartbeatInterval: 15,
MissingHbAllowed: 5,
MaxRetransmit: 3,
AckTimeout: 1,
AckRandomFactor: 1.0,
Expand Down
1 change: 1 addition & 0 deletions dots_server/db_models/dump.sql
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ CREATE TABLE `signal_session_configuration` (
`customer_id` int(11) NOT NULL,
`session_id` int(11) NOT NULL,
`heartbeat_interval` int(11) DEFAULT NULL,
`missing_hb_allowed` int(11) DEFAULT NULL,
`max_retransmit` int(11) DEFAULT NULL,
`ack_timeout` int(11) DEFAULT NULL,
`ack_random_factor` double DEFAULT NULL,
Expand Down
1 change: 1 addition & 0 deletions dots_server/db_models/dump_docker.sql
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ CREATE TABLE `signal_session_configuration` (
`customer_id` int(11) NOT NULL,
`session_id` int(11) NOT NULL,
`heartbeat_interval` int(11) DEFAULT NULL,
`missing_hb_allowed` int(11) DEFAULT NULL,
`max_retransmit` int(11) DEFAULT NULL,
`ack_timeout` int(11) DEFAULT NULL,
`ack_random_factor` double DEFAULT NULL,
Expand Down
1 change: 1 addition & 0 deletions dots_server/db_models/signal_session_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type SignalSessionConfiguration struct {
CustomerId int `xorm:"'customer_id' not null index(idx_customer_id)"`
SessionId int `xorm:"'session_id' not null index(idx_session_id)"`
HeartbeatInterval int `xorm:"'heartbeat_interval'"`
MissingHbAllowed int `xorm:"'missing_hb_allowed'"`
MaxRetransmit int `xorm:"'max_retransmit'"`
AckTimeout int `xorm:"'ack_timeout'"`
AckRandomFactor float64 `xorm:"'ack_random_factor'"`
Expand Down
1 change: 1 addition & 0 deletions dots_server/db_models/template.sql
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ CREATE TABLE `signal_session_configuration` (
`customer_id` int(11) NOT NULL,
`session_id` int(11) NOT NULL,
`heartbeat_interval` int(11) DEFAULT NULL,
`missing_hb_allowed` int(11) DEFAULT NULL,
`max_retransmit` int(11) DEFAULT NULL,
`ack_timeout` int(11) DEFAULT NULL,
`ack_random_factor` double DEFAULT NULL,
Expand Down
1 change: 1 addition & 0 deletions dots_server/db_models/test_dump.sql
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ CREATE TABLE `signal_session_configuration` (
`customer_id` int(11) NOT NULL,
`session_id` int(11) NOT NULL,
`heartbeat_interval` int(11) DEFAULT NULL,
`missing_hb_allowed` int(11) DEFAULT NULL,
`max_retransmit` int(11) DEFAULT NULL,
`ack_timeout` int(11) DEFAULT NULL,
`ack_random_factor` double DEFAULT NULL,
Expand Down
1 change: 1 addition & 0 deletions dots_server/dots_server.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
system:
signalConfigurationParameter:
heartbeatInterval: 30-60
missingHbAllowed: 3-9
maxRetransmit: 3-10
ackTimeout: 30-120
ackRandomFactor: 0-8888
Expand Down
1 change: 1 addition & 0 deletions dots_server/dots_server.yaml.template
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
system:
signalConfigurationParameter:
heartbeatInterval: 30-60
missingHbAllowed: 3-9
maxRetransmit: 3-10
ackTimeout: 30-120
ackRandomFactor: 0-8888
Expand Down
6 changes: 5 additions & 1 deletion dots_server/models/mitigation_configuratin_parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func NewConfigurationParameterRange(min_value float64, max_value float64) *Confi
type SignalSessionConfiguration struct {
SessionId int
HeartbeatInterval int
MissingHbAllowed int
MaxRetransmit int
AckTimeout int
AckRandomFactor float64
Expand All @@ -71,16 +72,18 @@ type SignalSessionConfiguration struct {
* parameter:
* sessionId sessionId
* heartbeatInterval heartbeat_interval
* missingHbAllowed missing_hb_allowed
* maxRetransmit max_retransmit
* ackTimeout ack_timeout
* ackRandomFactor ack_random_factor
* return:
* s SignalSessionConfiguration
*/
func NewSignalSessionConfiguration(sessionId int, heartbeatInterval int, maxRetransmit int, ackTimeout int, ackRandomFactor float64) (s *SignalSessionConfiguration) {
func NewSignalSessionConfiguration(sessionId int, heartbeatInterval int, missingHbAllowed int, maxRetransmit int, ackTimeout int, ackRandomFactor float64) (s *SignalSessionConfiguration) {
s = &SignalSessionConfiguration{
SessionId: sessionId,
HeartbeatInterval: heartbeatInterval,
MissingHbAllowed: missingHbAllowed,
MaxRetransmit: maxRetransmit,
AckTimeout: ackTimeout,
AckRandomFactor: ackRandomFactor,
Expand All @@ -91,6 +94,7 @@ func NewSignalSessionConfiguration(sessionId int, heartbeatInterval int, maxRetr

type SignalConfigurationParameter struct {
heartbeat_interval ConfigurationParameterRange
missing_hb_allowed ConfigurationParameterRange
max_retransmit ConfigurationParameterRange
ack_timeout ConfigurationParameterRange
ack_random_factor ConfigurationParameterRange
Expand Down
1 change: 1 addition & 0 deletions dots_server/models/models_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ var configText = `
system:
signalConfigurationParameter:
heartbeatInterval: 15-60
missingHbAllowed: 3-9
maxRetransmit: 3-15
ackTimeout: 1-30
ackRandomFactor: 1-4
Expand Down
5 changes: 5 additions & 0 deletions dots_server/models/signal_configuration_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
type signalConfigurationParameterConfigJson struct {
ValidateValue struct {
HeartbeatInterval configurationParameterRangeJson `json:"heartbeat_interval"`
MissingHbAllowed configurationParameterRangeJson `json:"missing_hb_allowed"`
MaxRetransmit configurationParameterRangeJson `json:"max_retransmit"`
AckTimeout configurationParameterRangeJson `json:"ack_timeout"`
AckRandomFactor configurationParameterRangeJson `json:"ack_random_factor"`
Expand Down Expand Up @@ -36,6 +37,9 @@ func getCompareDataSource() *SignalConfigurationParameter {
heartbeat_interval: ConfigurationParameterRange{
min_value: float64(config.HeartbeatInterval.Start().(int)),
max_value: float64(config.HeartbeatInterval.End().(int))},
missing_hb_allowed: ConfigurationParameterRange{
min_value: float64(config.MissingHbAllowed.Start().(int)),
max_value: float64(config.MissingHbAllowed.End().(int))},
max_retransmit: ConfigurationParameterRange{
min_value: float64(config.MaxRetransmit.Start().(int)),
max_value: float64(config.MaxRetransmit.End().(int))},
Expand Down Expand Up @@ -67,6 +71,7 @@ func (v *SignalConfigurationValidator) Validate(m MessageEntity, c Customer) (re
// valid attribute value check
if compareSource != nil {
if !(compareSource.heartbeat_interval.Includes(float64(sc.HeartbeatInterval)) &&
compareSource.missing_hb_allowed.Includes(float64(sc.MissingHbAllowed)) &&
compareSource.max_retransmit.Includes(float64(sc.MaxRetransmit)) &&
compareSource.ack_timeout.Includes(float64(sc.AckTimeout)) &&
compareSource.ack_random_factor.Includes(sc.AckRandomFactor)) {
Expand Down
46 changes: 30 additions & 16 deletions dots_server/models/signal_configuration_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,70 +23,84 @@ func TestSignalConfigurationValidator(t *testing.T) {
customer.Id = 1234567890

// session_id is zero
var s1 = models.NewSignalSessionConfiguration(0, 15, 3, 1, 1.0)
var s1 = models.NewSignalSessionConfiguration(0, 15, 5, 3, 1, 1.0)
validRet := v.Validate(s1, models.Customer{})
if validRet {
t.Error("validation error: session_id is zero")
}

// heartbeat_interval out of range(min)
var s2 = models.NewSignalSessionConfiguration(2, 14, 3, 1, 1.0)
var s2 = models.NewSignalSessionConfiguration(2, 14, 5, 3, 1, 1.0)
validRet = v.Validate(s2, models.Customer{})
if validRet {
t.Error("validation error: heartbeat_interval out of range(min)")
}

// heartbeat_interval is out of range(max)
var s3 = models.NewSignalSessionConfiguration(3, 61, 15, 30, 4.0)
var s3 = models.NewSignalSessionConfiguration(3, 61, 5, 15, 30, 4.0)
validRet = v.Validate(s3, models.Customer{})
if validRet {
t.Error("validation error: heartbeat_interval out of range(max)")
}

// max_retransmit out of range(min)
var s4 = models.NewSignalSessionConfiguration(4, 15, 2, 1, 1.0)
// missing_hb_allowed out of range(min)
var s4 = models.NewSignalSessionConfiguration(2, 15, 2, 3, 1, 1.0)
validRet = v.Validate(s4, models.Customer{})
if validRet {
t.Error("validation error: missing_hb_allowed out of range(min)")
}

// missing_hb_allowed is out of range(max)
var s5 = models.NewSignalSessionConfiguration(3, 15, 10, 15, 30, 4.0)
validRet = v.Validate(s5, models.Customer{})
if validRet {
t.Error("validation error: missing_hb_allowed out of range(max)")
}

// max_retransmit out of range(min)
var s6 = models.NewSignalSessionConfiguration(4, 15, 5, 2, 1, 1.0)
validRet = v.Validate(s6, models.Customer{})
if validRet {
t.Error("validation error: max_retransmit out of range(min)")
}

// max_retransmit is out of range(max)
var s5 = models.NewSignalSessionConfiguration(5, 60, 16, 30, 4.0)
validRet = v.Validate(s5, models.Customer{})
var s7 = models.NewSignalSessionConfiguration(5, 60, 5, 16, 30, 4.0)
validRet = v.Validate(s7, models.Customer{})
if validRet {
t.Error("validation error: max_retransmit out of range(max)")
}

// ack_timeout out of range(min)
var s6 = models.NewSignalSessionConfiguration(6, 15, 3, 0, 1.0)
validRet = v.Validate(s6, models.Customer{})
var s8 = models.NewSignalSessionConfiguration(6, 15, 5, 3, 0, 1.0)
validRet = v.Validate(s8, models.Customer{})
if validRet {
t.Error("validation error: ack_timeout out of range(min)")
}

// ack_timeout is out of range(max)
var s7 = models.NewSignalSessionConfiguration(7, 60, 15, 31, 4.0)
validRet = v.Validate(s7, models.Customer{})
var s9 = models.NewSignalSessionConfiguration(7, 60, 5, 15, 31, 4.0)
validRet = v.Validate(s9, models.Customer{})
if validRet {
t.Error("validation error: ack_timeout out of range(max)")
}

// ack_random_factor out of range(min)
var s8 = models.NewSignalSessionConfiguration(8, 15, 3, 1, 0.9)
validRet = v.Validate(s8, models.Customer{})
var s10 = models.NewSignalSessionConfiguration(8, 15, 5, 3, 1, 0.9)
validRet = v.Validate(s10, models.Customer{})
if validRet {
t.Error("validation error: ack_random_factor out of range(min)")
}

// ack_random_factor is out of range(max)
var s9 = models.NewSignalSessionConfiguration(9, 60, 15, 30, 4.01)
validRet = v.Validate(s9, models.Customer{})
var s11 = models.NewSignalSessionConfiguration(9, 60, 5, 15, 30, 4.01)
validRet = v.Validate(s11, models.Customer{})
if validRet {
t.Error("validation error: ack_random_factor out of range(max)")
}

// no validate pattern
var s15 = models.NewSignalSessionConfiguration(15, 60, 15, 30, 4.0)
var s15 = models.NewSignalSessionConfiguration(15, 60, 5, 15, 30, 4.0)
validRet = v.Validate(s15, models.Customer{})
if !validRet {
t.Error("validation error: no validate pattern error wrong")
Expand Down
3 changes: 3 additions & 0 deletions dots_server/models/xorm_signal_session_configuration_dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func CreateSignalSessionConfiguration(signalSessionConfiguration SignalSessionCo
CustomerId: customer.Id,
SessionId: signalSessionConfiguration.SessionId,
HeartbeatInterval: signalSessionConfiguration.HeartbeatInterval,
MissingHbAllowed: signalSessionConfiguration.MissingHbAllowed,
MaxRetransmit: signalSessionConfiguration.MaxRetransmit,
AckTimeout: signalSessionConfiguration.AckTimeout,
AckRandomFactor: signalSessionConfiguration.AckRandomFactor,
Expand Down Expand Up @@ -104,6 +105,7 @@ func UpdateSignalSessionConfiguration(signalSessionConfiguration SignalSessionCo
}

updSignalSessionConfiguration.HeartbeatInterval = signalSessionConfiguration.HeartbeatInterval
updSignalSessionConfiguration.MissingHbAllowed = signalSessionConfiguration.MissingHbAllowed
updSignalSessionConfiguration.MaxRetransmit = signalSessionConfiguration.MaxRetransmit
updSignalSessionConfiguration.AckTimeout = signalSessionConfiguration.AckTimeout
updSignalSessionConfiguration.AckRandomFactor = signalSessionConfiguration.AckRandomFactor
Expand Down Expand Up @@ -154,6 +156,7 @@ func GetSignalSessionConfiguration(customerId int, sessionId int) (signalSession
}
signalSessionConfiguration.SessionId = dbSignalSessionConfiguration.SessionId
signalSessionConfiguration.HeartbeatInterval = dbSignalSessionConfiguration.HeartbeatInterval
signalSessionConfiguration.MissingHbAllowed = dbSignalSessionConfiguration.MissingHbAllowed
signalSessionConfiguration.MaxRetransmit = dbSignalSessionConfiguration.MaxRetransmit
signalSessionConfiguration.AckTimeout = dbSignalSessionConfiguration.AckTimeout
signalSessionConfiguration.AckRandomFactor = dbSignalSessionConfiguration.AckRandomFactor
Expand Down
10 changes: 10 additions & 0 deletions dots_server/models/xorm_signal_session_configuration_dao_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ func signalSessionConfigurationSampleDataCreate() {
// signal_session_configuration test data setting
testSignalSessionConfiguration.SessionId = 987
testSignalSessionConfiguration.HeartbeatInterval = 100
testSignalSessionConfiguration.MissingHbAllowed = 5
testSignalSessionConfiguration.MaxRetransmit = 10
testSignalSessionConfiguration.AckTimeout = 90
testSignalSessionConfiguration.AckRandomFactor = 99999

// signal_session_configuration update test data setting
testUpdateSignalSessionConfiguration.SessionId = 987
testUpdateSignalSessionConfiguration.HeartbeatInterval = 200
testUpdateSignalSessionConfiguration.MissingHbAllowed = 4
testUpdateSignalSessionConfiguration.MaxRetransmit = 20
testUpdateSignalSessionConfiguration.AckTimeout = 40
testUpdateSignalSessionConfiguration.AckRandomFactor = 12345
Expand Down Expand Up @@ -49,6 +51,10 @@ func TestGetSignalSessionConfiguration(t *testing.T) {
t.Errorf("got %s, want %s", signalSessionConfiguration.HeartbeatInterval, testSignalSessionConfiguration.HeartbeatInterval)
}

if signalSessionConfiguration.MissingHbAllowed != testSignalSessionConfiguration.MissingHbAllowed {
t.Errorf("got %s, want %s", signalSessionConfiguration.MissingHbAllowed, testSignalSessionConfiguration.MissingHbAllowed)
}

if signalSessionConfiguration.MaxRetransmit != testSignalSessionConfiguration.MaxRetransmit {
t.Errorf("got %s, want %s", signalSessionConfiguration.MaxRetransmit, testSignalSessionConfiguration.MaxRetransmit)
}
Expand Down Expand Up @@ -83,6 +89,10 @@ func TestUpdateSignalSessionConfiguration(t *testing.T) {
t.Errorf("got %s, want %s", signalSessionConfiguration.HeartbeatInterval, testUpdateSignalSessionConfiguration.HeartbeatInterval)
}

if signalSessionConfiguration.MissingHbAllowed != testUpdateSignalSessionConfiguration.MissingHbAllowed {
t.Errorf("got %s, want %s", signalSessionConfiguration.MissingHbAllowed, testUpdateSignalSessionConfiguration.MissingHbAllowed)
}

if signalSessionConfiguration.MaxRetransmit != testUpdateSignalSessionConfiguration.MaxRetransmit {
t.Errorf("got %s, want %s", signalSessionConfiguration.MaxRetransmit, testUpdateSignalSessionConfiguration.MaxRetransmit)
}
Expand Down
Loading

0 comments on commit d2b9e35

Please sign in to comment.