Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test client and script to run it together with server and feeder #82

Merged
merged 3 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
535 changes: 535 additions & 0 deletions client/client-1.0/testClient/testClient.go

Large diffs are not rendered by default.

151 changes: 151 additions & 0 deletions client/client-1.0/testClient/testRequests.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
{
"http": [
{
"action": "get",
"path": "Vehicle.Speed"
},
{
"action": "get",
"path": "Incorrect.Path"
},
{
"action": "get",
"path": "Vehicle.ADAS",
"filter": {
"variant": "paths",
"parameter": [
"ABS.*",
"CruiseControl.IsError"
]
}
},
{
"action": "set",
"path": "Vehicle.Cabin.Door.Row1.DriverSide.IsOpen",
"value": "true"
}
],
"ws": [
{
"action": "get",
"path": "Vehicle.Speed",
"requestId": "232"
},
{
"action": "get",
"path": "Incorrect.Path",
"requestId": "1957"
},
{
"action": "get",
"path": "Vehicle.ADAS",
"filter": {
"variant": "paths",
"parameter": [
"ABS.*",
"CruiseControl.IsError"
]
},
"requestId": "237"
},
{
"action": "set",
"path": "Vehicle.Cabin.Door.Row1.DriverSide.IsOpen",
"value": "true",
"requestId": "245"
},
{
"action": "subscribe",
"path": "Vehicle.Cabin.Door.Row1.DriverSide.IsOpen",
"filter": {
"variant": "timebased",
"parameter": {
"period": "1000"
}
},
"requestId": "246"
}
],
"mqtt": [
{
"action": "get",
"path": "Vehicle.Speed",
"requestId": "232"
},
{
"action": "get",
"path": "Incorrect.Path",
"requestId": "1957"
},
{
"action": "get",
"path": "Vehicle.ADAS",
"filter": {
"variant": "paths",
"parameter": [
"ABS.*",
"CruiseControl.IsError"
]
},
"requestId": "237"
},
{
"action": "set",
"path": "Vehicle.Cabin.Door.Row1.DriverSide.IsOpen",
"value": "true",
"requestId": "245"
},
{
"action": "subscribe",
"path": "Vehicle.Cabin.Door.Row1.DriverSide.IsOpen",
"filter": {
"variant": "timebased",
"parameter": {
"period": "1000"
}
},
"requestId": "246"
}
],
"grpc": [
{
"action": "get",
"path": "Vehicle.Speed",
"requestId": "232"
},
{
"action": "get",
"path": "Incorrect.Path",
"requestId": "1957"
},
{
"action": "get",
"path": "Vehicle.ADAS",
"filter": {
"variant": "paths",
"parameter": [
"ABS.*",
"CruiseControl.IsError"
]
},
"requestId": "237"
},
{
"action": "set",
"path": "Vehicle.Cabin.Door.Row1.DriverSide.IsOpen",
"value": "true",
"requestId": "245"
},
{
"action": "subscribe",
"path": "Vehicle.Cabin.Door.Row1.DriverSide.IsOpen",
"filter": {
"variant": "timebased",
"parameter": {
"period": "1000"
}
},
"requestId": "246"
}
]
}
74 changes: 74 additions & 0 deletions client/client-1.0/testClient/transportSec.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/**
* (C) 2021 Geotab Inc
*
* All files and artifacts in the repository at https://github.com/GENIVI/ccs-w3c-client
* are licensed under the provisions of the license provided by the LICENSE file in this repository.
*
**/

package main

import (
"crypto/tls"
"crypto/x509"
"encoding/json"
"fmt"
//"io/ioutil"
"os"
)

//var trSecConfigPath string = "/client/client-1.0/testClient/transport_sec/" // relative path to the directory containing the transportSec.json file
var trSecConfigPath string = "/" // relative path to the directory containing the transportSec.json file
type SecConfig struct {
TransportSec string `json:"transportSec"` // "yes" or "no"
HttpSecPort string `json:"httpSecPort"` // HTTPS port number
WsSecPort string `json:"wsSecPort"` // WSS port number
MqttSecPort string `json:"mqttSecPort"` // MQTTS port number
GrpcSecPort string `json:"grpcSecPort"` // gRPC port number
AgtsSecPort string `json:"agtsSecPort"` // AGTS port number
AtsSecPort string `json:"atsSecPort"` // ATS port number
CaSecPath string `json:"caSecPath"` // relative path from the directory containing the transportSec.json file
ServerSecPath string `json:"serverSecPath"` // relative path from the directory containing the transportSec.json file
ServerCertOpt string `json:"serverCertOpt"` // one of "NoClientCert"/"ClientCertNoVerification"/"ClientCertVerification"
ClientSecPath string `json:"clientSecPath"` // relative path from the directory containing the transportSec.json file
}

var secConfig SecConfig

func readTransportSecConfig() {
path, err := os.Getwd()

data, err := os.ReadFile(path + trSecConfigPath + "transportSec.json")
if err != nil {
fmt.Printf("ReadTransportSecConfig():%stransportSec.json error=%s", trSecConfigPath, err)
secConfig.TransportSec = "no"
return
}
err = json.Unmarshal(data, &secConfig)
if err != nil {
fmt.Printf("ReadTransportSecConfig():Error unmarshal transportSec.json=%s", err)
secConfig.TransportSec = "no"
return
}
fmt.Printf("ReadTransportSecConfig():secConfig.TransportSec=%s", secConfig.TransportSec)
}

func prepareTransportSecConfig() *x509.CertPool {
var err error
clientCertFile := trSecConfigPath + secConfig.ClientSecPath + "client.crt"
clientKeyFile := trSecConfigPath + secConfig.ClientSecPath + "client.key"

clientCert, err = tls.LoadX509KeyPair(clientCertFile, clientKeyFile)
if err != nil {
fmt.Printf("Error creating x509 keypair from client cert file %s and client key file %s\n", clientCertFile, clientKeyFile)
os.Exit(1)
}
caCert, err := os.ReadFile(trSecConfigPath + secConfig.CaSecPath + "Root.CA.crt")
if err != nil {
fmt.Printf("Error opening cert file %s, Error: %s", trSecConfigPath+secConfig.CaSecPath+"Root.CA.crt", err)
os.Exit(1)
}
caCertPool := x509.NewCertPool()
caCertPool.AppendCertsFromPEM(caCert)
return caCertPool
}
11 changes: 11 additions & 0 deletions client/client-1.0/testClient/transportSec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"transportSec": "no",
"httpSecPort": "443",
"wsSecPort": "6443",
"mqttSecPort": "8883",
"grpcSecPort": "5443",
"caSecPath": "ca/",
"serverSecPath": "",
"serverCertOpt": "ClientCertVerification",
"clientSecPath": "client/"
}
48 changes: 48 additions & 0 deletions runtest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash

usage() {
echo "usage: $0 startme|stopme" >&2
}

startme() {
echo "Starting server"
screen -S vissv2server -dm bash -c "pushd server/vissv2server && go build && mkdir -p logs && ./vissv2server -m &> ./logs/vissv2server-log.txt && popd"

echo "Starting feederv3"
screen -S feederv3 -dm bash -c "pushd feeder/feeder-template/feederv3 && go build && mkdir -p logs && ./feederv3 -i vssjson &> ./logs/feederv3-log.txt && popd"

echo "Starting testClient"
screen -S testClient bash -c "pushd client/client-1.0/testClient && go build && ./testClient && popd"

screen -list
}

stopme() {
echo "Stopping feederv3"
screen -X -S feederv3 quit

echo "Stopping vissv2server"
screen -X -S vissv2server quit

sleep 1
screen -wipe
}

if [ $# -ne 1 ] && [ $# -ne 2 ]
then
usage $0
exit 1
fi

case "$1" in
startme)
stopme
startme $# $2;;
stopme)
stopme
;;
*)
usage
exit 1
;;
esac
2 changes: 1 addition & 1 deletion server/vissv2server/mqttMgr/mqttMgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func extractVin(response string) string {
vinStartIndex := strings.Index(response, "value")
if vinStartIndex == -1 {
utils.Error.Printf("VIN cannot be extracted in %s", response)
os.Exit(1)
return "ULF001" //???
}
vinStartIndex += 8 // value”:”
vinEndIndex := utils.NextQuoteMark([]byte(response), vinStartIndex)
Expand Down
3 changes: 1 addition & 2 deletions server/vissv2server/serviceMgr/serviceMgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -1464,12 +1464,11 @@ func ServiceMgrInit(mgrId int, serviceMgrChan chan map[string]interface{}, state
if ok == true {
status, subscriptionList = deactivateSubscription(subscriptionList, subscriptId)
if status != -1 {
responseMap["subscriptionId"] = subscriptId
dataChan <- responseMap
toFeeder <- utils.FinalizeMessage(requestMap)
break
}
requestMap["subscriptionId"] = subscriptId
delete(requestMap, "subscriptionId")
}
}
utils.SetErrorResponse(requestMap, errorResponseMap, 1, "") //invalid_data
Expand Down
9 changes: 6 additions & 3 deletions server/vissv2server/vissv2server.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var serverComponents []string = []string{
"httpMgr",
"wsMgr",
"wsMgrFT",
// "mqttMgr", //to avoid calls to the mosquitto broker if not used anyway
"mqttMgr",
"grpcMgr",
"atServer",
}
Expand Down Expand Up @@ -704,6 +704,7 @@ func main() {
Help: "statestorage database filename",
Default: "serviceMgr/statestorage.db"})
consentSupport := parser.Flag("c", "consentsupport", &argparse.Options{Required: false, Help: "try to connect to ECF", Default: false})
mqttEnable := parser.Flag("m", "mqttenable", &argparse.Options{Required: false, Help: "enable MQTT usage", Default: false})

// Parse input
err := parser.Parse(os.Args)
Expand Down Expand Up @@ -759,8 +760,10 @@ func main() {
case "wsMgrFT":
go wsMgrFT.WsMgrFTInit(ftChannel)
case "mqttMgr":
go mqttMgr.MqttMgrInit(2, transportMgrChannel[2])
go transportDataSession(transportMgrChannel[2], transportDataChan[2], backendChan[2])
if *mqttEnable {
go mqttMgr.MqttMgrInit(2, transportMgrChannel[2])
go transportDataSession(transportMgrChannel[2], transportDataChan[2], backendChan[2])
}
case "grpcMgr":
go grpcMgr.GrpcMgrInit(3, transportMgrChannel[3])
go transportDataSession(transportMgrChannel[3], transportDataChan[3], backendChan[3])
Expand Down
41 changes: 35 additions & 6 deletions tutorial/content/build-system/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,45 @@ Logging can be command line configured at startup.

The levels currently used are mainly info, warning, error. Info is appropriate during testing and debugging, while error is appropriate when performance is important.

### Testing
If modifications of the server code base is done it is recommended that the following test routine is performed before pushing
any commits to this repo.
To test the "VISSR tech stack", the server together with data store and feeder, the runtest.sh is available in the root directory.
This bash script starts the server and the feederv3 in the background, and then the testClient is started in the terminal window.
The testClient reads the testRequests.json file for the requests it will issue to the different transport protocols,
and then it prints the requests and the responses in the terminal window.
After each set of test requests for the same transport protocol it will wait until the keyboard return key is received,
allowing the operator to gett time to inspect the request/response logs before continuing.
When the MQTT protocol is run, the test.mosquitto.org broker is used which may lead to latencies between request and response.
In that case the testClient prompt for reading the return key may be found mixed into the log prints,
but hitting the return key will still make it continue.
If some logdata looks incorrect the operator can hit ctrl-C to terminate the testClient
and instead inspect the log files for the server and the feeder, found in the log directory of their respective start directories.
It is up to the operator to evaluate whether the logs look correct or not,
so it might be a good idea to run the script before doing any modifications lo learn how correct logs looks like.

Issue the following command in the root directory to run the tests:
```
$ ./runtest.sh startme
```
When the testing is completed the script should be run to terminate the server and feeder processes:
```
$ ./runtest.sh stopme
```

### Transport protocols
Besides the transport protocols
The following transport protocols are supported
* HTTP
* Websocke
* Websocket
* MQTT
that the specification lists, this server also supports
* gRPC
They are all except MQTT activated by the server per default.
To enable MQTT, or disable any other, the string array serverComponents in the vissv2server.go file contains a list of the components that are spawned on
separate threads by the main server process, and these can be commented in or out before building the server.

They are all except MQTT enabled by the server per default.

To enable MQTT add the CLI command "-m" when starting the VISS server.

To disable any other protocol, the string array serverComponents in the vissv2server.go file contains a list of the components that are spawned on
separate threads by the main server process, and these can be commented out before building the server.
For the server to be operationable, the service manager, and at least one transport protocol must not be commented out.

### Go modules
Expand Down
Loading
Loading