Skip to content

Commit

Permalink
Merge pull request #107 from Gowa2017/master
Browse files Browse the repository at this point in the history
add support of radius
  • Loading branch information
link1st committed Nov 14, 2022
2 parents 8217722 + ec72da0 commit ddf6bd3
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 1 deletion.
6 changes: 5 additions & 1 deletion model/request_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ const (
// FormTypeWebSocket webSocket 协议
FormTypeWebSocket = "webSocket"
// FormTypeGRPC grpc 协议
FormTypeGRPC = "grpc"
FormTypeGRPC = "grpc"
FormTypeRadius = "radius"
)

// 校验函数
Expand Down Expand Up @@ -160,6 +161,9 @@ func NewRequest(url string, verify string, code int, timeout time.Duration, debu
form = FormTypeWebSocket
} else if strings.HasPrefix(url, "grpc://") || strings.HasPrefix(url, "rpc://") {
form = FormTypeGRPC
} else if strings.HasPrefix(url, "radius://") {
form = FormTypeRadius
url = url[9:]
} else {
form = FormTypeHTTP
url = fmt.Sprintf("http://%s", url)
Expand Down
4 changes: 4 additions & 0 deletions server/dispose.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ func Dispose(ctx context.Context, concurrency, totalNumber uint64, request *mode
continue
}
go golink.Grpc(ctx, i, ch, totalNumber, &wg, request, ws)
case model.FormTypeRadius:
// Radius use udp, does not a connection
go golink.Radius(ctx, i, ch, totalNumber, &wg, request)

default:
// 类型不支持
wg.Done()
Expand Down
68 changes: 68 additions & 0 deletions server/golink/radius_link.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package golink

import (
"context"
"strings"
"sync"
"time"

"github.com/link1st/go-stress-testing/helper"
"layeh.com/radius"
"layeh.com/radius/rfc2865"

"github.com/link1st/go-stress-testing/model"
)

// Grpc grpc 接口请求
func Radius(ctx context.Context, chanID uint64, ch chan<- *model.RequestResults, totalNumber uint64, wg *sync.WaitGroup,
request *model.Request) {
defer func() {
wg.Done()
}()
for i := uint64(0); i < totalNumber; i++ {
authRequest(chanID, ch, i, request)
}
return
}

// grpcRequest 请求
func authRequest(chanID uint64, ch chan<- *model.RequestResults, i uint64, request *model.Request) {
var (
startTime = time.Now()
isSucceed = false
errCode = int(radius.CodeAccessAccept)
)
// 需要发送的数据
// fmt.Printf("rsp:%+v", rsp)
packet := radius.New(radius.CodeAccessRequest, []byte(`cisco`))
index := strings.Index(request.URL, "@")
username := "tim"
host := request.URL
if index != -1 {
username = username + "@" + request.URL[index+1:]
host = request.URL[:index]
}
rfc2865.UserName_SetString(packet, username)
rfc2865.UserPassword_SetString(packet, "12345678")
rfc2865.NASPortType_Set(packet, rfc2865.NASPortType_Value_Ethernet)
rfc2865.ServiceType_Set(packet, rfc2865.ServiceType_Value_FramedUser)
rfc2865.NASIdentifier_Set(packet, []byte(`benchmark`))
rsp, err := radius.Exchange(context.Background(), packet, host)
if err != nil {
errCode = model.RequestErr
} else {
if rsp.Code != radius.CodeAccessAccept {
errCode = int(rsp.Code)
} else {
isSucceed = true
}
}
requestTime := uint64(helper.DiffNano(startTime))
requestResults := &model.RequestResults{
Time: requestTime,
IsSucceed: isSucceed,
ErrCode: errCode,
}
requestResults.SetID(chanID, i)
ch <- requestResults
}

0 comments on commit ddf6bd3

Please sign in to comment.