Protocol Documentation
Table of Contents
Top
SimService
Sim pool sub-system is responsible of:
- Populating sims data in DB from CSV
- Provide sim stats
- Provide sim on request
- Allows to add slice of sims
RPC Functions
Directory structure
├── Dockerfile
├── Int.Dockerfile
├── Makefile
├── README.md
├── bin
│ ├── sim-pool
├── cmd
│ ├── server
│ │ ├── main.go
│ ├── version
│ │ ├── version.go
├── go.mod
├── go.sum
├── mocks
│ ├── SimRepo.go
├── pb
│ ├── gen
│ │ ├── mocks
│ │ │ ├── SimServiceClient.go
│ │ │ ├── SimServiceServer.go
│ │ │ ├── UnsafeSimServiceServer.go
│ │ ├── sim.pb.go
│ │ ├── sim.validator.pb.go
│ │ ├── sim_grpc.pb.go
│ ├── sim.proto
├── pkg
│ ├── config.go
│ ├── db
│ │ ├── model.go
│ │ ├── sim_repo.go
│ │ ├── sim_repo_test.go
│ ├── global.go
│ ├── server
│ │ ├── sim.go
│ │ ├── sim_test.go
│ ├── utils
│ │ ├── utils.go
│ │ ├── utils_test.go
- cmd: Contains the server and system/sub-system version. Purpose of this file is to initialize the DB and start server. We use
make server
command to run this file.
- mocks: This directory contains the auto generated file which get generated based on
*.proto
. It contains functions which we can use to write test cases.
- pb: This directory contains the
*.proto
file. In proto file we define service with all the rpc's and messages.
- pkg/db: DB directory under pkg contains 2 files.
model.go
file contains the db model structure/s.
*_repo.go
is reponsible of communicating with db using gorm.
- pkg/server This directory contains the file in which all the RPC functions logic is implemented. Those functions call
pkg\*_repo.go
functions to perform db operations.
How to use?
Before using the repo make sure below tools are installed:
- Go 1.18
- PostgreSQL
- gRPC client
Then navigate into base-rate directory and run below command:
To Test
For unit tests run below commands:
make test
This command will run unit tests under all pb/sim.proto directories.
To Generate PB file
make gen
This command will generate protobuf files from pb/sim.proto.
To Run Server & Test RPC
make server
This command will run the server on port 9090
. It'll also create the database and table under it.
Server is running, Now we can use any gRPC client to interact with RPC handlers. We're using Evans. Run below command in new terminal tab:
evans --path /path/to --path . --proto pb/*.proto --host localhost --port 9090
Next run:
show rpc
This command will show all the available RPC calls under base-rate sub-system. To call any RPC function run call FUNCATION_NAME
.
pb/sim.proto
AddRequest
Field |
Type |
Label |
Description |
sim |
AddSim |
repeated |
Slice of sims to add in sim pool |
AddResponse
Field |
Type |
Label |
Description |
sim |
Sim |
repeated |
Slice of sims added in sim pool |
AddSim
DeleteRequest
Field |
Type |
Label |
Description |
id |
uint64 |
repeated |
Slice of sim id's to delete from sim pool |
DeleteResponse
Field |
Type |
Label |
Description |
id |
uint64 |
repeated |
Slice of sim id's deleted from sim pool |
GetRequest
Field |
Type |
Label |
Description |
IsPhysicalSim |
bool |
|
True/False |
GetResponse
Field |
Type |
Label |
Description |
sim |
Sim |
|
Sim object |
GetStatsRequest
Field |
Type |
Label |
Description |
simType |
SimType |
|
SimType string enum |
GetStatsResponse
Field |
Type |
Label |
Description |
total |
uint64 |
|
Total sims in sim pool |
available |
uint64 |
|
Available sims in sim pool |
consumed |
uint64 |
|
Consumed sims in sim pool |
failed |
uint64 |
|
Failed sims in sim pool |
Sim
UploadRequest
Field |
Type |
Label |
Description |
simData |
bytes |
|
Bytes of CSV file content |
simType |
SimType |
|
SimType of sim |
UploadResponse
Field |
Type |
Label |
Description |
sim |
Sim |
repeated |
Slice of sims added in sim pool |
SimType
Name |
Number |
Description |
ANY |
0 |
|
INTER_NONE |
1 |
|
INTER_MNO_DATA |
2 |
|
INTER_MNO_ALL |
3 |
|
INTER_UKAMA_ALL |
4 |
|
Scalar Value Types
.proto Type |
Notes |
C++ Type |
Java Type |
Python Type |
double |
|
double |
double |
float |
float |
|
float |
float |
float |
int32 |
Uses variable-length encoding. Inefficient for encoding negative numbers – if your field is likely to have negative values, use sint32 instead. |
int32 |
int |
int |
int64 |
Uses variable-length encoding. Inefficient for encoding negative numbers – if your field is likely to have negative values, use sint64 instead. |
int64 |
long |
int/long |
uint32 |
Uses variable-length encoding. |
uint32 |
int |
int/long |
uint64 |
Uses variable-length encoding. |
uint64 |
long |
int/long |
sint32 |
Uses variable-length encoding. Signed int value. These more efficiently encode negative numbers than regular int32s. |
int32 |
int |
int |
sint64 |
Uses variable-length encoding. Signed int value. These more efficiently encode negative numbers than regular int64s. |
int64 |
long |
int/long |
fixed32 |
Always four bytes. More efficient than uint32 if values are often greater than 2^28. |
uint32 |
int |
int |
fixed64 |
Always eight bytes. More efficient than uint64 if values are often greater than 2^56. |
uint64 |
long |
int/long |
sfixed32 |
Always four bytes. |
int32 |
int |
int |
sfixed64 |
Always eight bytes. |
int64 |
long |
int/long |
bool |
|
bool |
boolean |
boolean |
string |
A string must always contain UTF-8 encoded or 7-bit ASCII text. |
string |
String |
str/unicode |
bytes |
May contain any arbitrary sequence of bytes. |
string |
ByteString |
str |