feat(go): add 100k ingest hardening baseline
This commit is contained in:
53
go/vehicle-gateway/internal/loadsim/templates.go
Normal file
53
go/vehicle-gateway/internal/loadsim/templates.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package loadsim
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const sampleJT808LocationFrame = "7E020000320133077954250001000000000048000301D2C4C707376139000A00E6004F26063016235701040001900C2504000000000202000030011F31010F867E"
|
||||
|
||||
const sampleGB32960RealtimeFrame = "232302FE4C423941333241323152304C53313730370102ED1A070116091C0102030100000008297D161F27104C020007D0000002010104564E204E205815CA271003000A000000B40002666902800200000100A101000400FFFF001205000733444601E2B5DB06013A0F6C018E0F4001014B01054A07000000000000000000080101161F271000900001900F520F530F520F640F660F650F650F650F650F660F650F650F640F640F550F550F540F560F580F570F540F570F560F550F5A0F550F580F570F5C0F5F0F5E0F610F5E0F5D0F5E0F5F0F5E0F5D0F610F5F0F610F600F600F610F610F610F600F630F630F600F610F610F610F620F620F610F6A0F6C0F6B0F6A0F6C0F6B0F6A0F6B0F6B0F6B0F6A0F610F630F630F630F640F660F640F630F630F630F580F5A0F580F5B0F550F580F5A0F5A0F590F580F5A0F620F650F650F650F660F640F640F640F640F640F660F650F640F650F660F650F670F670F670F670F630F620F680F670F650F650F670F650F610F5F0F600F620F5E0F5C0F590F4C0F490F480F440F470F480F470F420F430F450F420F450F440F440F430F530F540F520F400F410F4109010100084B4B4B4B4A4A4B4A3001026907B2FF00FF00380002002800000008006C00016C00080008000000080008000800080008000800080008000800080008000800080008000800080008000800080008000800080008000800080008000800080008000800080008000800080008000800080008000800080008000800080008000800080008000800080008000800080008002800070007000700070007000700070007000700070007000700070007000700070007000700070007000700070007000700080008000800080008000800080008000800080008000800080008000800080008000800080008000800080008000800080008000831010E9C0005FFFFFFFF0E9CFFFFFFFF0083320E9C1B6115E212465733FFFFFFFFFF34FFFFFFFFFF002B800009690E9C2710000D000E83002402020500002700080001000000FD00000000FFFFFFFFFFFFFFFFFFFFFFFF1FFE1FF3001DBA"
|
||||
|
||||
func FrameTemplate(protocol Protocol, name string) ([]byte, error) {
|
||||
template := strings.ToLower(strings.TrimSpace(name))
|
||||
if template == "" {
|
||||
template = defaultTemplate(protocol)
|
||||
}
|
||||
var rawHex string
|
||||
switch protocol {
|
||||
case ProtocolJT808:
|
||||
switch template {
|
||||
case "0200", "location", "default":
|
||||
rawHex = sampleJT808LocationFrame
|
||||
default:
|
||||
return nil, fmt.Errorf("unsupported jt808 template %q", name)
|
||||
}
|
||||
case ProtocolGB32960:
|
||||
switch template {
|
||||
case "0200", "realtime", "default":
|
||||
rawHex = sampleGB32960RealtimeFrame
|
||||
default:
|
||||
return nil, fmt.Errorf("unsupported gb32960 template %q", name)
|
||||
}
|
||||
default:
|
||||
return nil, fmt.Errorf("unsupported protocol %q", protocol)
|
||||
}
|
||||
frame, err := hex.DecodeString(rawHex)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return frame, nil
|
||||
}
|
||||
|
||||
func defaultTemplate(protocol Protocol) string {
|
||||
switch protocol {
|
||||
case ProtocolJT808:
|
||||
return "0200"
|
||||
case ProtocolGB32960:
|
||||
return "realtime"
|
||||
default:
|
||||
return "default"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user