diff --git a/.ci/.golangci-master.yml b/.ci/.golangci-master.yml new file mode 100644 index 0000000000000000000000000000000000000000..1a21937d63f0d30e5daf6bf57d4f35763bf42da4 --- /dev/null +++ b/.ci/.golangci-master.yml @@ -0,0 +1,23 @@ +run: + timeout: 5m + issues-exit-code: 1 +output: + format: code-climate + print-issued-lines: true + print-linter-name: true + uniq-by-line: true + path-prefix: "" +linters-settings: + gocyclo: + min-complexity: 15 + golint: + min-confidence: 0.8 +linters: + disable-all: true + enable: + - gofmt + - golint + - gocyclo + - govet +issues: + exclude-use-default: false diff --git a/.ci/.golangci.yml b/.ci/.golangci.yml new file mode 100644 index 0000000000000000000000000000000000000000..5c4c88e8338b257ad41a8b594d2aae8a27f82f2a --- /dev/null +++ b/.ci/.golangci.yml @@ -0,0 +1,21 @@ +run: + timeout: 5m + issues-exit-code: 1 +output: + format: code-climate + print-issued-lines: true + print-linter-name: true + uniq-by-line: true + path-prefix: "" +linters-settings: + gocyclo: + min-complexity: 15 + golint: + min-confidence: 0.8 +linters: + disable-all: true + enable: + - gofmt + - golint + - gocyclo + - govet diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e896eedf2d1f44497013bef3fb944427d4a4364b..a8c0a174ab74a7e531bc98c0923a4f879301433d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,16 +1,93 @@ +variables: + SECURE_ANALYZERS_PREFIX: registry.gitlab.com/gitlab-org/security-products/analyzers + +stages: + - test + - compliance + - build + +before_script: + - git config --global url."https://$GO_MODULES_USER:$GO_MODULES_ACCESS_TOKEN@code.fbi.h-da.de".insteadOf "https://code.fbi.h-da.de" + +code-quality-master: + image: golangci/golangci-lint:latest-alpine + tags: + - docker + stage: test + only: + - merge_requests + except: + variables: + - $CI_MERGE_REQUEST_TARGET_BRANCH_NAME != "master" + script: + - git config --global url."https://$GO_MODULES_USER:$GO_MODULES_ACCESS_TOKEN@code.fbi.h-da.de".insteadOf "https://code.fbi.h-da.de" + # writes golangci-lint output to gl-code-quality-report.json + - golangci-lint run --config .ci/.golangci-master.yml | tee gl-code-quality-report.json + artifacts: + reports: + codequality: gl-code-quality-report.json + + +code-quality: + image: golangci/golangci-lint:latest-alpine + tags: + - docker + stage: test + allow_failure: true + only: + - merge_requests + except: + variables: + - $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master" + script: + # writes golangci-lint output to gl-code-quality-report.json + - golangci-lint run --config .ci/.golangci.yml | tee gl-code-quality-report.json + artifacts: + reports: + codequality: gl-code-quality-report.json Documentation: + before_script: + - pwd image: name: pandoc/latex - entrypoint: [""] + entrypoint: + - '' + stage: build tags: - docker only: changes: - - documentation/design/*.md + - documentation/design/*.md script: - - cd documentation/design - - pandoc --filter pandoc-citeproc --bibliography=bibliography.bib --csl=acm-sig-proceedings.csl --variable papersize=a4paper -s *.md -o documentation.pdf + - cd documentation/design + - pandoc --filter pandoc-citeproc --bibliography=bibliography.bib --csl=acm-sig-proceedings.csl + --variable papersize=a4paper -s *.md -o documentation.pdf artifacts: paths: - - documentation/design/documentation.pdf \ No newline at end of file + - documentation/design/documentation.pdf + +sast: + variables: + SAST_ANALYZER_IMAGE_TAG: '2' + SAST_EXCLUDED_PATHS: spec, test, tests, tmp + SEARCH_MAX_DEPTH: '4' + stage: compliance + tags: + - docker + +license_scanning: + stage: compliance + tags: + - docker + +gemnasium-dependency_scanning: + stage: compliance + tags: + - docker + +include: + - template: Security/SAST.gitlab-ci.yml + - template: Dependency-Scanning.gitlab-ci.yml + - template: Security/License-Scanning.gitlab-ci.yml + diff --git a/cliInterface/gosdnCLI.pb.go b/cliInterface/gosdnCLI.pb.go index a7cec77003351d6a7234b2a963b75fc9e677c4cb..2095a2771e811732b7ef6b56b75930e7e21d27e7 100644 --- a/cliInterface/gosdnCLI.pb.go +++ b/cliInterface/gosdnCLI.pb.go @@ -79,7 +79,8 @@ type HelloReply struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"` + Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"` + GoSDNInfo string `protobuf:"bytes,2,opt,name=goSDNInfo,proto3" json:"goSDNInfo,omitempty"` } func (x *HelloReply) Reset() { @@ -121,6 +122,13 @@ func (x *HelloReply) GetMessage() string { return "" } +func (x *HelloReply) GetGoSDNInfo() string { + if x != nil { + return x.GoSDNInfo + } + return "" +} + // Request to shutdown goSDN type ShutdownRequest struct { state protoimpl.MessageState @@ -217,6 +225,102 @@ func (x *ShutdownReply) GetMessage() string { return "" } +// Request with no meaning by now +type TAPIRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` +} + +func (x *TAPIRequest) Reset() { + *x = TAPIRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_cliInterface_gosdnCLI_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *TAPIRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*TAPIRequest) ProtoMessage() {} + +func (x *TAPIRequest) ProtoReflect() protoreflect.Message { + mi := &file_cliInterface_gosdnCLI_proto_msgTypes[4] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use TAPIRequest.ProtoReflect.Descriptor instead. +func (*TAPIRequest) Descriptor() ([]byte, []int) { + return file_cliInterface_gosdnCLI_proto_rawDescGZIP(), []int{4} +} + +func (x *TAPIRequest) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +// The response message containing a string with no meaning by now +type TAPIReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"` +} + +func (x *TAPIReply) Reset() { + *x = TAPIReply{} + if protoimpl.UnsafeEnabled { + mi := &file_cliInterface_gosdnCLI_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *TAPIReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*TAPIReply) ProtoMessage() {} + +func (x *TAPIReply) ProtoReflect() protoreflect.Message { + mi := &file_cliInterface_gosdnCLI_proto_msgTypes[5] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use TAPIReply.ProtoReflect.Descriptor instead. +func (*TAPIReply) Descriptor() ([]byte, []int) { + return file_cliInterface_gosdnCLI_proto_rawDescGZIP(), []int{5} +} + +func (x *TAPIReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + var File_cliInterface_gosdnCLI_proto protoreflect.FileDescriptor var file_cliInterface_gosdnCLI_proto_rawDesc = []byte{ @@ -225,29 +329,49 @@ var file_cliInterface_gosdnCLI_proto_rawDesc = []byte{ 0x6c, 0x69, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x22, 0x22, 0x0a, 0x0c, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, - 0x26, 0x0a, 0x0a, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x18, 0x0a, + 0x44, 0x0a, 0x0a, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, - 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x25, 0x0a, 0x0f, 0x53, 0x68, 0x75, 0x74, 0x64, - 0x6f, 0x77, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, - 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x29, - 0x0a, 0x0d, 0x53, 0x68, 0x75, 0x74, 0x64, 0x6f, 0x77, 0x6e, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, - 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x32, 0x97, 0x01, 0x0a, 0x07, 0x47, 0x72, - 0x65, 0x65, 0x74, 0x65, 0x72, 0x12, 0x42, 0x0a, 0x08, 0x53, 0x61, 0x79, 0x48, 0x65, 0x6c, 0x6c, - 0x6f, 0x12, 0x1a, 0x2e, 0x63, 0x6c, 0x69, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, - 0x2e, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, - 0x63, 0x6c, 0x69, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x2e, 0x48, 0x65, 0x6c, - 0x6c, 0x6f, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x12, 0x48, 0x0a, 0x08, 0x53, 0x68, 0x75, - 0x74, 0x64, 0x6f, 0x77, 0x6e, 0x12, 0x1d, 0x2e, 0x63, 0x6c, 0x69, 0x49, 0x6e, 0x74, 0x65, 0x72, - 0x66, 0x61, 0x63, 0x65, 0x2e, 0x53, 0x68, 0x75, 0x74, 0x64, 0x6f, 0x77, 0x6e, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1b, 0x2e, 0x63, 0x6c, 0x69, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x66, - 0x61, 0x63, 0x65, 0x2e, 0x53, 0x68, 0x75, 0x74, 0x64, 0x6f, 0x77, 0x6e, 0x52, 0x65, 0x70, 0x6c, - 0x79, 0x22, 0x00, 0x42, 0x50, 0x0a, 0x1e, 0x64, 0x65, 0x2e, 0x68, 0x2d, 0x64, 0x61, 0x2e, 0x66, - 0x62, 0x69, 0x2e, 0x67, 0x6f, 0x73, 0x64, 0x6e, 0x2e, 0x63, 0x6c, 0x69, 0x49, 0x6e, 0x74, 0x65, - 0x72, 0x66, 0x61, 0x63, 0x65, 0x42, 0x0c, 0x63, 0x6c, 0x69, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x66, - 0x61, 0x63, 0x65, 0x50, 0x01, 0x5a, 0x1e, 0x67, 0x69, 0x74, 0x6c, 0x61, 0x62, 0x2e, 0x66, 0x62, - 0x69, 0x2e, 0x68, 0x2d, 0x64, 0x61, 0x2e, 0x64, 0x65, 0x2f, 0x63, 0x6f, 0x63, 0x73, 0x6e, 0x2f, - 0x67, 0x6f, 0x73, 0x64, 0x6e, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x67, 0x6f, 0x53, 0x44, 0x4e, + 0x49, 0x6e, 0x66, 0x6f, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x67, 0x6f, 0x53, 0x44, + 0x4e, 0x49, 0x6e, 0x66, 0x6f, 0x22, 0x25, 0x0a, 0x0f, 0x53, 0x68, 0x75, 0x74, 0x64, 0x6f, 0x77, + 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x29, 0x0a, 0x0d, + 0x53, 0x68, 0x75, 0x74, 0x64, 0x6f, 0x77, 0x6e, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x18, 0x0a, + 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, + 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x21, 0x0a, 0x0b, 0x54, 0x41, 0x50, 0x49, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x25, 0x0a, 0x09, 0x54, 0x41, + 0x50, 0x49, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, + 0x67, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, + 0x65, 0x32, 0xea, 0x02, 0x0a, 0x07, 0x47, 0x72, 0x70, 0x63, 0x43, 0x6c, 0x69, 0x12, 0x42, 0x0a, + 0x08, 0x53, 0x61, 0x79, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x12, 0x1a, 0x2e, 0x63, 0x6c, 0x69, 0x49, + 0x6e, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x2e, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x63, 0x6c, 0x69, 0x49, 0x6e, 0x74, 0x65, 0x72, + 0x66, 0x61, 0x63, 0x65, 0x2e, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, + 0x00, 0x12, 0x48, 0x0a, 0x08, 0x53, 0x68, 0x75, 0x74, 0x64, 0x6f, 0x77, 0x6e, 0x12, 0x1d, 0x2e, + 0x63, 0x6c, 0x69, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x2e, 0x53, 0x68, 0x75, + 0x74, 0x64, 0x6f, 0x77, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1b, 0x2e, 0x63, + 0x6c, 0x69, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x2e, 0x53, 0x68, 0x75, 0x74, + 0x64, 0x6f, 0x77, 0x6e, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x12, 0x43, 0x0a, 0x0b, 0x54, + 0x41, 0x50, 0x49, 0x47, 0x65, 0x74, 0x45, 0x64, 0x67, 0x65, 0x12, 0x19, 0x2e, 0x63, 0x6c, 0x69, + 0x49, 0x6e, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x2e, 0x54, 0x41, 0x50, 0x49, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x63, 0x6c, 0x69, 0x49, 0x6e, 0x74, 0x65, 0x72, + 0x66, 0x61, 0x63, 0x65, 0x2e, 0x54, 0x41, 0x50, 0x49, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, + 0x12, 0x47, 0x0a, 0x0f, 0x54, 0x41, 0x50, 0x49, 0x47, 0x65, 0x74, 0x45, 0x64, 0x67, 0x65, 0x4e, + 0x6f, 0x64, 0x65, 0x12, 0x19, 0x2e, 0x63, 0x6c, 0x69, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x66, 0x61, + 0x63, 0x65, 0x2e, 0x54, 0x41, 0x50, 0x49, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, + 0x2e, 0x63, 0x6c, 0x69, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x2e, 0x54, 0x41, + 0x50, 0x49, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x12, 0x43, 0x0a, 0x0b, 0x54, 0x41, 0x50, + 0x49, 0x47, 0x65, 0x74, 0x4c, 0x69, 0x6e, 0x6b, 0x12, 0x19, 0x2e, 0x63, 0x6c, 0x69, 0x49, 0x6e, + 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x2e, 0x54, 0x41, 0x50, 0x49, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x63, 0x6c, 0x69, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x66, 0x61, + 0x63, 0x65, 0x2e, 0x54, 0x41, 0x50, 0x49, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x42, 0x50, + 0x0a, 0x1e, 0x64, 0x65, 0x2e, 0x68, 0x2d, 0x64, 0x61, 0x2e, 0x66, 0x62, 0x69, 0x2e, 0x67, 0x6f, + 0x73, 0x64, 0x6e, 0x2e, 0x63, 0x6c, 0x69, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, + 0x42, 0x0c, 0x63, 0x6c, 0x69, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x50, 0x01, + 0x5a, 0x1e, 0x67, 0x69, 0x74, 0x6c, 0x61, 0x62, 0x2e, 0x66, 0x62, 0x69, 0x2e, 0x68, 0x2d, 0x64, + 0x61, 0x2e, 0x64, 0x65, 0x2f, 0x63, 0x6f, 0x63, 0x73, 0x6e, 0x2f, 0x67, 0x6f, 0x73, 0x64, 0x6e, + 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -262,20 +386,28 @@ func file_cliInterface_gosdnCLI_proto_rawDescGZIP() []byte { return file_cliInterface_gosdnCLI_proto_rawDescData } -var file_cliInterface_gosdnCLI_proto_msgTypes = make([]protoimpl.MessageInfo, 4) +var file_cliInterface_gosdnCLI_proto_msgTypes = make([]protoimpl.MessageInfo, 6) var file_cliInterface_gosdnCLI_proto_goTypes = []interface{}{ (*HelloRequest)(nil), // 0: cliInterface.HelloRequest (*HelloReply)(nil), // 1: cliInterface.HelloReply (*ShutdownRequest)(nil), // 2: cliInterface.ShutdownRequest (*ShutdownReply)(nil), // 3: cliInterface.ShutdownReply + (*TAPIRequest)(nil), // 4: cliInterface.TAPIRequest + (*TAPIReply)(nil), // 5: cliInterface.TAPIReply } var file_cliInterface_gosdnCLI_proto_depIdxs = []int32{ - 0, // 0: cliInterface.Greeter.SayHello:input_type -> cliInterface.HelloRequest - 2, // 1: cliInterface.Greeter.Shutdown:input_type -> cliInterface.ShutdownRequest - 1, // 2: cliInterface.Greeter.SayHello:output_type -> cliInterface.HelloReply - 3, // 3: cliInterface.Greeter.Shutdown:output_type -> cliInterface.ShutdownReply - 2, // [2:4] is the sub-list for method output_type - 0, // [0:2] is the sub-list for method input_type + 0, // 0: cliInterface.GrpcCli.SayHello:input_type -> cliInterface.HelloRequest + 2, // 1: cliInterface.GrpcCli.Shutdown:input_type -> cliInterface.ShutdownRequest + 4, // 2: cliInterface.GrpcCli.TAPIGetEdge:input_type -> cliInterface.TAPIRequest + 4, // 3: cliInterface.GrpcCli.TAPIGetEdgeNode:input_type -> cliInterface.TAPIRequest + 4, // 4: cliInterface.GrpcCli.TAPIGetLink:input_type -> cliInterface.TAPIRequest + 1, // 5: cliInterface.GrpcCli.SayHello:output_type -> cliInterface.HelloReply + 3, // 6: cliInterface.GrpcCli.Shutdown:output_type -> cliInterface.ShutdownReply + 5, // 7: cliInterface.GrpcCli.TAPIGetEdge:output_type -> cliInterface.TAPIReply + 5, // 8: cliInterface.GrpcCli.TAPIGetEdgeNode:output_type -> cliInterface.TAPIReply + 5, // 9: cliInterface.GrpcCli.TAPIGetLink:output_type -> cliInterface.TAPIReply + 5, // [5:10] is the sub-list for method output_type + 0, // [0:5] is the sub-list for method input_type 0, // [0:0] is the sub-list for extension type_name 0, // [0:0] is the sub-list for extension extendee 0, // [0:0] is the sub-list for field type_name @@ -335,6 +467,30 @@ func file_cliInterface_gosdnCLI_proto_init() { return nil } } + file_cliInterface_gosdnCLI_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*TAPIRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_cliInterface_gosdnCLI_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*TAPIReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } type x struct{} out := protoimpl.TypeBuilder{ @@ -342,7 +498,7 @@ func file_cliInterface_gosdnCLI_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_cliInterface_gosdnCLI_proto_rawDesc, NumEnums: 0, - NumMessages: 4, + NumMessages: 6, NumExtensions: 0, NumServices: 1, }, diff --git a/cliInterface/gosdnCLI.proto b/cliInterface/gosdnCLI.proto index 2139a330110a5b8c9909083370de24f5d10bbeca..fa76e03959152bed3829ff5f8e70b5379e3becca 100644 --- a/cliInterface/gosdnCLI.proto +++ b/cliInterface/gosdnCLI.proto @@ -9,11 +9,19 @@ option java_outer_classname = "cliInterface"; package cliInterface; // The greeting service definition. -service Greeter { +service GrpcCli { // Sends a greeting rpc SayHello (HelloRequest) returns (HelloReply) {} // Shutdown goSDN rpc Shutdown (ShutdownRequest) returns (ShutdownReply) {} + + // By now solely TAPI specific calls can be issued from the grpc-cli + // TAPIGetEdge + rpc TAPIGetEdge (TAPIRequest) returns (TAPIReply) {} + //TAPIGetEdgeNode + rpc TAPIGetEdgeNode (TAPIRequest) returns (TAPIReply) {} + // TAPIGetLink + rpc TAPIGetLink (TAPIRequest) returns (TAPIReply) {} } // The request message containing the user's name. @@ -24,6 +32,7 @@ message HelloRequest { // The response message containing the greetings message HelloReply { string message = 1; + string goSDNInfo = 2; } // Request to shutdown goSDN @@ -36,3 +45,14 @@ message ShutdownReply { string message = 1; } +// Request with no meaning by now +message TAPIRequest { + string name = 1; +} + +// The response message containing a string with no meaning by now +message TAPIReply { + string message = 1; +} + + diff --git a/cliInterface/gosdnCLI_grpc.pb.go b/cliInterface/gosdnCLI_grpc.pb.go index fc33744973ddcc04eaa456270648c3bcc16756be..600414a6a07222330fb9ebabee938dad31b82666 100644 --- a/cliInterface/gosdnCLI_grpc.pb.go +++ b/cliInterface/gosdnCLI_grpc.pb.go @@ -13,116 +13,232 @@ import ( // is compatible with the grpc package it is being compiled against. const _ = grpc.SupportPackageIsVersion6 -// GreeterClient is the client API for Greeter service. +// GrpcCliClient is the client API for GrpcCli service. // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. -type GreeterClient interface { +type GrpcCliClient interface { // Sends a greeting SayHello(ctx context.Context, in *HelloRequest, opts ...grpc.CallOption) (*HelloReply, error) // Shutdown goSDN Shutdown(ctx context.Context, in *ShutdownRequest, opts ...grpc.CallOption) (*ShutdownReply, error) + // By now solely TAPI specific calls can be issued from the grpc-cli + // TAPIGetEdge + TAPIGetEdge(ctx context.Context, in *TAPIRequest, opts ...grpc.CallOption) (*TAPIReply, error) + //TAPIGetEdgeNode + TAPIGetEdgeNode(ctx context.Context, in *TAPIRequest, opts ...grpc.CallOption) (*TAPIReply, error) + // TAPIGetLink + TAPIGetLink(ctx context.Context, in *TAPIRequest, opts ...grpc.CallOption) (*TAPIReply, error) } -type greeterClient struct { +type grpcCliClient struct { cc grpc.ClientConnInterface } -func NewGreeterClient(cc grpc.ClientConnInterface) GreeterClient { - return &greeterClient{cc} +func NewGrpcCliClient(cc grpc.ClientConnInterface) GrpcCliClient { + return &grpcCliClient{cc} } -func (c *greeterClient) SayHello(ctx context.Context, in *HelloRequest, opts ...grpc.CallOption) (*HelloReply, error) { +func (c *grpcCliClient) SayHello(ctx context.Context, in *HelloRequest, opts ...grpc.CallOption) (*HelloReply, error) { out := new(HelloReply) - err := c.cc.Invoke(ctx, "/cliInterface.Greeter/SayHello", in, out, opts...) + err := c.cc.Invoke(ctx, "/cliInterface.GrpcCli/SayHello", in, out, opts...) if err != nil { return nil, err } return out, nil } -func (c *greeterClient) Shutdown(ctx context.Context, in *ShutdownRequest, opts ...grpc.CallOption) (*ShutdownReply, error) { +func (c *grpcCliClient) Shutdown(ctx context.Context, in *ShutdownRequest, opts ...grpc.CallOption) (*ShutdownReply, error) { out := new(ShutdownReply) - err := c.cc.Invoke(ctx, "/cliInterface.Greeter/Shutdown", in, out, opts...) + err := c.cc.Invoke(ctx, "/cliInterface.GrpcCli/Shutdown", in, out, opts...) if err != nil { return nil, err } return out, nil } -// GreeterServer is the server API for Greeter service. -// All implementations must embed UnimplementedGreeterServer +func (c *grpcCliClient) TAPIGetEdge(ctx context.Context, in *TAPIRequest, opts ...grpc.CallOption) (*TAPIReply, error) { + out := new(TAPIReply) + err := c.cc.Invoke(ctx, "/cliInterface.GrpcCli/TAPIGetEdge", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *grpcCliClient) TAPIGetEdgeNode(ctx context.Context, in *TAPIRequest, opts ...grpc.CallOption) (*TAPIReply, error) { + out := new(TAPIReply) + err := c.cc.Invoke(ctx, "/cliInterface.GrpcCli/TAPIGetEdgeNode", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *grpcCliClient) TAPIGetLink(ctx context.Context, in *TAPIRequest, opts ...grpc.CallOption) (*TAPIReply, error) { + out := new(TAPIReply) + err := c.cc.Invoke(ctx, "/cliInterface.GrpcCli/TAPIGetLink", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// GrpcCliServer is the server API for GrpcCli service. +// All implementations must embed UnimplementedGrpcCliServer // for forward compatibility -type GreeterServer interface { +type GrpcCliServer interface { // Sends a greeting SayHello(context.Context, *HelloRequest) (*HelloReply, error) // Shutdown goSDN Shutdown(context.Context, *ShutdownRequest) (*ShutdownReply, error) - mustEmbedUnimplementedGreeterServer() + // By now solely TAPI specific calls can be issued from the grpc-cli + // TAPIGetEdge + TAPIGetEdge(context.Context, *TAPIRequest) (*TAPIReply, error) + //TAPIGetEdgeNode + TAPIGetEdgeNode(context.Context, *TAPIRequest) (*TAPIReply, error) + // TAPIGetLink + TAPIGetLink(context.Context, *TAPIRequest) (*TAPIReply, error) + mustEmbedUnimplementedGrpcCliServer() } -// UnimplementedGreeterServer must be embedded to have forward compatible implementations. -type UnimplementedGreeterServer struct { +// UnimplementedGrpcCliServer must be embedded to have forward compatible implementations. +type UnimplementedGrpcCliServer struct { } -func (*UnimplementedGreeterServer) SayHello(context.Context, *HelloRequest) (*HelloReply, error) { +func (*UnimplementedGrpcCliServer) SayHello(context.Context, *HelloRequest) (*HelloReply, error) { return nil, status.Errorf(codes.Unimplemented, "method SayHello not implemented") } -func (*UnimplementedGreeterServer) Shutdown(context.Context, *ShutdownRequest) (*ShutdownReply, error) { +func (*UnimplementedGrpcCliServer) Shutdown(context.Context, *ShutdownRequest) (*ShutdownReply, error) { return nil, status.Errorf(codes.Unimplemented, "method Shutdown not implemented") } -func (*UnimplementedGreeterServer) mustEmbedUnimplementedGreeterServer() {} +func (*UnimplementedGrpcCliServer) TAPIGetEdge(context.Context, *TAPIRequest) (*TAPIReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method TAPIGetEdge not implemented") +} +func (*UnimplementedGrpcCliServer) TAPIGetEdgeNode(context.Context, *TAPIRequest) (*TAPIReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method TAPIGetEdgeNode not implemented") +} +func (*UnimplementedGrpcCliServer) TAPIGetLink(context.Context, *TAPIRequest) (*TAPIReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method TAPIGetLink not implemented") +} +func (*UnimplementedGrpcCliServer) mustEmbedUnimplementedGrpcCliServer() {} -func RegisterGreeterServer(s *grpc.Server, srv GreeterServer) { - s.RegisterService(&_Greeter_serviceDesc, srv) +func RegisterGrpcCliServer(s *grpc.Server, srv GrpcCliServer) { + s.RegisterService(&_GrpcCli_serviceDesc, srv) } -func _Greeter_SayHello_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { +func _GrpcCli_SayHello_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(HelloRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(GreeterServer).SayHello(ctx, in) + return srv.(GrpcCliServer).SayHello(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/cliInterface.Greeter/SayHello", + FullMethod: "/cliInterface.GrpcCli/SayHello", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(GreeterServer).SayHello(ctx, req.(*HelloRequest)) + return srv.(GrpcCliServer).SayHello(ctx, req.(*HelloRequest)) } return interceptor(ctx, in, info, handler) } -func _Greeter_Shutdown_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { +func _GrpcCli_Shutdown_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(ShutdownRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(GreeterServer).Shutdown(ctx, in) + return srv.(GrpcCliServer).Shutdown(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/cliInterface.GrpcCli/Shutdown", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(GrpcCliServer).Shutdown(ctx, req.(*ShutdownRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _GrpcCli_TAPIGetEdge_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(TAPIRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(GrpcCliServer).TAPIGetEdge(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/cliInterface.Greeter/Shutdown", + FullMethod: "/cliInterface.GrpcCli/TAPIGetEdge", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(GreeterServer).Shutdown(ctx, req.(*ShutdownRequest)) + return srv.(GrpcCliServer).TAPIGetEdge(ctx, req.(*TAPIRequest)) } return interceptor(ctx, in, info, handler) } -var _Greeter_serviceDesc = grpc.ServiceDesc{ - ServiceName: "cliInterface.Greeter", - HandlerType: (*GreeterServer)(nil), +func _GrpcCli_TAPIGetEdgeNode_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(TAPIRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(GrpcCliServer).TAPIGetEdgeNode(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/cliInterface.GrpcCli/TAPIGetEdgeNode", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(GrpcCliServer).TAPIGetEdgeNode(ctx, req.(*TAPIRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _GrpcCli_TAPIGetLink_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(TAPIRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(GrpcCliServer).TAPIGetLink(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/cliInterface.GrpcCli/TAPIGetLink", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(GrpcCliServer).TAPIGetLink(ctx, req.(*TAPIRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _GrpcCli_serviceDesc = grpc.ServiceDesc{ + ServiceName: "cliInterface.GrpcCli", + HandlerType: (*GrpcCliServer)(nil), Methods: []grpc.MethodDesc{ { MethodName: "SayHello", - Handler: _Greeter_SayHello_Handler, + Handler: _GrpcCli_SayHello_Handler, }, { MethodName: "Shutdown", - Handler: _Greeter_Shutdown_Handler, + Handler: _GrpcCli_Shutdown_Handler, + }, + { + MethodName: "TAPIGetEdge", + Handler: _GrpcCli_TAPIGetEdge_Handler, + }, + { + MethodName: "TAPIGetEdgeNode", + Handler: _GrpcCli_TAPIGetEdgeNode_Handler, + }, + { + MethodName: "TAPIGetLink", + Handler: _GrpcCli_TAPIGetLink_Handler, }, }, Streams: []grpc.StreamDesc{}, diff --git a/database/database.go b/database/database.go index cdc2da22c8d84c33831485a62599d5c3070fabf9..8186ad8734a162df3946cc90b825f0d3f0520fdd 100644 --- a/database/database.go +++ b/database/database.go @@ -40,7 +40,9 @@ func createDriver(uri, username, password string, encrypted bool) neo4j.Driver { }, ) - logError("failed creating database Driver", err) + if err != nil { + log.Info("failed creating database Driver:", err) + } return driver } @@ -50,7 +52,9 @@ func createSession(driver neo4j.Driver) neo4j.Session { sessionConfig := neo4j.SessionConfig{AccessMode: neo4j.AccessModeWrite} session, err := driver.NewSession(sessionConfig) - logError("failed creating database session", err) + if err != nil { + log.Info("failed creating database session:", err) + } return session } @@ -111,7 +115,9 @@ func (d Database) StoreNodes(json string) { "pnd": testPND.name, }) - logError("failed storing Nodes into database", err) + if err != nil { + log.Info("failed storing Nodes into database:", err) + } log.Info("successfully added Nodes into database") } @@ -140,7 +146,9 @@ func (d Database) StoreNodeEdgePoints(json string) { "stringToAdd": json, }) - logError("failed storing NodeEdgePoints into database", err) + if err != nil { + log.Info("failed storing NodeEdgePoints into database:", err) + } setNodeNodeEdgePointsRelation(d.session) @@ -163,7 +171,9 @@ func setNodeNodeEdgePointsRelation(session neo4j.Session) { _, err := session.Run( query, map[string]interface{}{}) - logError("failed storing NodeNodeEdgePointsRelation into database", err) + if err != nil { + log.Info("failed storing NodeNodeEdgePointsRelation into database:", err) + } log.Info("successfully stored NodeNodeEdgePointsRelation into database") } @@ -181,7 +191,4 @@ func (d Database) Shutdown() { //logError logs error with custom and error message func logError(message string, err error) { - if err != nil { - log.Info("%v: %v", message, err) - } } diff --git a/go.mod b/go.mod index 3f041eb5b6bf48dc5efff1d244a67fd6f95418ae..eb95a65a8340c359295c54d4030bb21ad018440c 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,6 @@ require ( github.com/neo4j/neo4j-go-driver v1.8.3 github.com/rivo/tview v0.0.0-20200915114512-42866ecf6ca6 golang.org/x/net v0.0.0-20200904194848-62affa334b73 // indirect - golang.org/x/tools v0.0.0-20190617190820-da514acc4774 google.golang.org/genproto v0.0.0-20200519141106-08726f379972 // indirect google.golang.org/grpc v1.29.1 google.golang.org/protobuf v1.23.0 diff --git a/gosdn-cli/gosdn-cli.go b/gosdn-cli/gosdn-cli.go index da4cf175013b2ca484a6a57fe84fdb8e0a14df03..52e73a71def5bf1ce12ef8126b5161cc14bc8644 100644 --- a/gosdn-cli/gosdn-cli.go +++ b/gosdn-cli/gosdn-cli.go @@ -3,13 +3,13 @@ package main import ( pb "code.fbi.h-da.de/cocsn/gosdn/cliInterface" "context" + "flag" "fmt" "github.com/rivo/tview" "google.golang.org/grpc" "log" "os" "time" - "flag" ) const ( @@ -29,27 +29,30 @@ var ( type cliClientConfig struct { goSDNCLIAddr4 *string goSDNCLIPort4 *int - interactive *bool - goSDNCommand *string + interactive *bool + goSDNCommand *string } type commandOptions struct { - name string + name string description string - command func(conn *grpc.ClientConn) () + command func(conn *grpc.ClientConn) } -var commandList = map[string] commandOptions { - "hello": {"hello", "test connection to goSDN controller", goSDNSayHello}, +var commandList = map[string]commandOptions{ + "hello": {"hello", "test connection to goSDN controller", goSDNSayHello}, "shutdown": {"shutdown", "request goSDN controller to shutdown", goSDNShutdown}, "testdb" : {"testdb", "test all database connections", goSDNTestDB}, + "tapigetedge" : {"tapigetedge", "get list of edges", TAPIGetEdge}, + "tapigetedgenode" : {"tapigetedgenode", "get list of edgenodes", TAPIGetEdgeNode}, + "tapigetlink" : {"tapigetlink", "get list of links", TAPIGetLink}, } /* gosdn-cli allows to mode of operations: - interactive: text GUI to operate goSDN - non-interactive: basic CLI without text GUI - */ +*/ func main() { // This holds the basic configuration for gosdn-cli @@ -64,7 +67,7 @@ func main() { flag.Parse() // Print complete command list and exit - if (*printCommandList == true) { + if *printCommandList == true { for _, element := range commandList { fmt.Println(element.name + "\t" + element.description) } @@ -87,11 +90,11 @@ func main() { log.Println(("Connected to " + conn.Target())) // Check for non-interactive or interactive mode - if(*myConfiguration.interactive == false) { + if *myConfiguration.interactive == false { log.Println("starting in non-interactive mode") // Lookup command or die _, found := commandList[*myConfiguration.goSDNCommand] - if(found) { + if found { // Excecute desired command commandList[*myConfiguration.goSDNCommand].command(conn) } else { @@ -118,10 +121,8 @@ func main() { } } - func goSDNSayHello (conn *grpc.ClientConn) { - - c := pb.NewGreeterClient(conn) + c := pb.NewGrpcCliClient(conn) // Contact the server and print out its response. name := defaultName @@ -134,19 +135,18 @@ func goSDNSayHello (conn *grpc.ClientConn) { if err != nil { log.Fatalf("could not say hello: %v", err) } - log.Printf("Greeting: %s", r.GetMessage()) - + log.Printf("Greeting: %s", r.String()) } -func goSDNShutdown (conn *grpc.ClientConn) { +func goSDNShutdown(conn *grpc.ClientConn) { - c := pb.NewGreeterClient(conn) + c := pb.NewGrpcCliClient(conn) // Contact the server and print out its response. name := defaultName if len(os.Args) > 1 { - name = os.Args[1] + name = os.Args[0] } ctx, cancel := context.WithTimeout(context.Background(), time.Second) defer cancel() @@ -157,6 +157,60 @@ func goSDNShutdown (conn *grpc.ClientConn) { log.Printf("Greeting: %s", r.GetMessage()) } -func goSDNTestDB(conn *grpc.ClientConn){ - // TODO: fill with code +func goSDNTestDB(conn *grpc.ClientConn) { + // TODO: fill with code and also see if grpc interface has this stub implemented. +} + + +func TAPIGetEdge(conn *grpc.ClientConn) { + + c := pb.NewGrpcCliClient(conn) + + // Contact the server and print out its response. + name := defaultName + if len(os.Args) > 1 { + name = os.Args[0] + } + ctx, cancel := context.WithTimeout(context.Background(), time.Second) + defer cancel() + r, err := c.TAPIGetEdge(ctx, &pb.TAPIRequest{Name: name}) + if err != nil { + log.Fatalf("could not request shutdown: %v", err) + } + log.Printf("TAPIGetEdge said: %s", r.GetMessage()) +} + +func TAPIGetEdgeNode(conn *grpc.ClientConn) { + c := pb.NewGrpcCliClient(conn) + + // Contact the server and print out its response. + name := defaultName + if len(os.Args) > 1 { + name = os.Args[0] + } + ctx, cancel := context.WithTimeout(context.Background(), time.Second) + defer cancel() + r, err := c.TAPIGetEdgeNode(ctx, &pb.TAPIRequest{Name: name}) + if err != nil { + log.Fatalf("could not request shutdown: %v", err) + } + log.Printf("TAPIGetEdgeNode said: %s", r.GetMessage()) +} + +func TAPIGetLink(conn *grpc.ClientConn) { + + c := pb.NewGrpcCliClient(conn) + + // Contact the server and print out its response. + name := defaultName + if len(os.Args) > 1 { + name = os.Args[0] + } + ctx, cancel := context.WithTimeout(context.Background(), time.Second) + defer cancel() + r, err := c.TAPIGetLink(ctx, &pb.TAPIRequest{Name: name}) + if err != nil { + log.Fatalf("could not request shutdown: %v", err) + } + log.Printf("TAPIGetLink said: %s", r.GetMessage()) } \ No newline at end of file diff --git a/log/logger.go b/log/logger.go index ab258d8b731c5b8692ee8afe37b9c18012b712b2..060ded548d286d1a863f6bd33d9d0b9edd809fb4 100644 --- a/log/logger.go +++ b/log/logger.go @@ -45,27 +45,27 @@ func Output(out io.Writer) { } func Debug(args ...interface{}) { - log(DEBUG, args) + log(DEBUG, args...) } func Info(args ...interface{}) { - log(INFO, args) + log(INFO, args...) } func Warn(args ...interface{}) { - log(WARNING, args) + log(WARNING, args...) } func Error(args ...interface{}) { - log(ERROR, args) + log(ERROR, args...) } func Fatal(args ...interface{}) { - log(FATAL, args) + log(FATAL, args...) } func Panic(args ...interface{}) { - log(PANIC, args) + log(PANIC, args...) } func log(level Level, args ...interface{}) { diff --git a/main.go b/main.go index b04ddc031a21f6fa6c8d2a0ed4b9d438643f8dcb..7527c7d3e71b2c3548031f90f24772174560a41c 100644 --- a/main.go +++ b/main.go @@ -17,10 +17,12 @@ func main() { cliSocket := *cliListenAddr + ":" + *cliListenPort log.Loglevel(log.DEBUG) + + // Setup a channel to communicate if goSDN should shutdown. + IsRunningChannel := make(chan bool) + // hand off to cmd for further processing - nucleus.StartUp(cliSocket, *configFileName) - log.Info("Startup completed") - nucleus.Run() + nucleus.StartAndRun(cliSocket, *configFileName, IsRunningChannel) // nothing to see here, please move on! } diff --git a/nucleus/cli-handling.go b/nucleus/cli-handling.go new file mode 100644 index 0000000000000000000000000000000000000000..af0912ccd55bac6c97957911898e8af1a99f27ab --- /dev/null +++ b/nucleus/cli-handling.go @@ -0,0 +1,79 @@ +/* + This file contains the grpc cli server-side calls. + Functions here should call other functions in charge of the + particular task. + */ + + +package nucleus + +import ( + pb "code.fbi.h-da.de/cocsn/gosdn/cliInterface" + "code.fbi.h-da.de/cocsn/gosdn/restconf/client/ciena" + "context" + "google.golang.org/grpc" + "code.fbi.h-da.de/cocsn/gosdn/log" + "net" +) + +// server is used to implement the grcp cli server +type server struct { + pb.UnimplementedGrpcCliServer + core *Core +} + +func (s *server) SayHello(ctx context.Context, in *pb.HelloRequest) (*pb.HelloReply, error) { + log.Info("Received: %v", in.GetName()) + return &pb.HelloReply{Message: "Hello " + in.GetName(), GoSDNInfo: "goSDN in version: DEVELOP"}, nil +} + +func (s *server) Shutdown(ctx context.Context, in *pb.ShutdownRequest) (*pb.ShutdownReply, error) { + log.Info("Shutdown Received: %v", in.GetName()) + s.core.IsRunning <- false + return &pb.ShutdownReply{Message: "Shutdown " + in.GetName()}, nil +} + +func getCLIGoing(core *Core) { + log.Info("Starting: GetCLIGoing") + // Boot-up the control interface for the cli + cliControlListener, err := net.Listen("tcp", core.config.CliSocket) + if err != nil { + log.Fatal("failed to listen: %v", err) + } + + cliControlServer := grpc.NewServer() + + pb.RegisterGrpcCliServer(cliControlServer, &server{core: core}) + if err := cliControlServer.Serve(cliControlListener); err != nil { + log.Fatal("failed to serve: %v", err) + } + log.Info("Started: GetCLIGoing") +} + +// SBI specific calls, by now TAPI only +func (s *server) TAPIGetEdge(ctx context.Context, in *pb.TAPIRequest) (*pb.TAPIReply, error) { + log.Info("Received: %v", in.GetName()) + if err := s.core.clients["ciena-mcp"].(*ciena.MCPClient).GetNodes(); err != nil { + log.Error(err) + return &pb.TAPIReply{Message: "TAPI error"}, nil + } + return &pb.TAPIReply{Message: "Done"}, nil +} + +func (s *server) TAPIGetEdgeNode(ctx context.Context, in *pb.TAPIRequest) (*pb.TAPIReply, error) { + log.Info("Received: %v", in.GetName()) + if err := s.core.clients["ciena-mcp"].(*ciena.MCPClient).GetNodeEdgePoints(); err != nil { + log.Error(err) + return &pb.TAPIReply{Message: "TAPI error"}, nil + } + return &pb.TAPIReply{Message: "Done"}, nil +} + +func (s *server) TAPIGetLink(ctx context.Context, in *pb.TAPIRequest) (*pb.TAPIReply, error) { + log.Info("Received: %v", in.GetName()) + if err := s.core.clients["ciena-mcp"].(*ciena.MCPClient).GetLinks(); err != nil { + log.Error(err) + return &pb.TAPIReply{Message: "TAPI error"}, nil + } + return &pb.TAPIReply{Message: "Done"}, nil +} diff --git a/nucleus/controller.go b/nucleus/controller.go index 2b4cdb19219dc74bf77a48d02f3363df09d2ead3..4e659667dee655f3da7f2fb41c8abd9ec85e576c 100644 --- a/nucleus/controller.go +++ b/nucleus/controller.go @@ -23,9 +23,10 @@ type Core struct { clients map[string]interfaces.Client database database.Database config controllerConfig + IsRunning chan bool } -func (c *Core) Init(socket, configfile string) { +func (c *Core) Init(socket, configfile string, IsRunningChannel chan bool) { if configfile == "" { configfile = "gosdn.toml" } @@ -47,8 +48,11 @@ func (c *Core) Init(socket, configfile string) { c.AttachDatabase() + c.IsRunning = IsRunningChannel + //TODO: Create client config/CLI adapter - c.clients["ciena-mcp"] = ciena.NewMCPClient( "141.100.70.170", "", "", &c.database) + c.clients["ciena-mcp"] = ciena.NewMCPClient("141.100.70.170", "", "", &c.database) + } func (c *Core) AttachDatabase() { @@ -56,6 +60,15 @@ func (c *Core) AttachDatabase() { } func (c *Core) Shutdown() { + + stopIt := <- c.IsRunning + if(stopIt == false) { + log.Debug("Shutdown() received action to shutdown") + }else { + log.Debug("Shutdown() received something else.") + } + + f, err := os.Create(c.config.ConfigPath) if err != nil { log.Fatal(err) @@ -64,4 +77,6 @@ func (c *Core) Shutdown() { if err := enc.Encode(c.config); err != nil { log.Fatal(err) } + + os.Exit(0) } diff --git a/nucleus/nucleus-core.go b/nucleus/nucleus-core.go index 2c65edf25218f73c6b542dfcffae844077c38b06..20a504de5725d56ccc752bf5816c9c962bfed52d 100644 --- a/nucleus/nucleus-core.go +++ b/nucleus/nucleus-core.go @@ -1,82 +1,34 @@ package nucleus import ( - pb "code.fbi.h-da.de/cocsn/gosdn/cliInterface" "code.fbi.h-da.de/cocsn/gosdn/database" "code.fbi.h-da.de/cocsn/gosdn/log" "code.fbi.h-da.de/cocsn/gosdn/nucleus/interfaces" - "context" - _ "github.com/mattn/go-sqlite3" - "google.golang.org/grpc" - "net" "time" ) -// server is used to implement helloworld.GreeterServer. -type server struct { - pb.UnimplementedGreeterServer - core *Core -} - -// SayHello implements helloworld.GreeterServer -func (s *server) SayHello(ctx context.Context, in *pb.HelloRequest) (*pb.HelloReply, error) { - log.Debug("Received: %v", in.GetName()) - return &pb.HelloReply{Message: "Hello " + in.GetName()}, nil -} - -func (s *server) Shutdown(ctx context.Context, in *pb.ShutdownRequest) (*pb.ShutdownReply, error) { - log.Debug("Received: %v", in.GetName()) - isRunning = false - return &pb.ShutdownReply{Message: "Shutdown " + in.GetName()}, nil -} - -func getCLIGoing(core *Core) { - log.Info("Starting: GetCLIGoing") - // Boot-up the control interface for the cli - cliControlListener, err := net.Listen("tcp", core.config.CliSocket) - if err != nil { - log.Fatal("failed to listen: %v", err) - } - - cliControlServer := grpc.NewServer() - - pb.RegisterGreeterServer(cliControlServer, &server{core: core}) - if err := cliControlServer.Serve(cliControlListener); err != nil { - log.Fatal("failed to serve: %v", err) - } - log.Info("Started: GetCLIGoing") -} - /* * This function is used to start the core of the controller and any auxiliary services. */ -// Next-up: backend database. - -func StartUp(socket, filename string) { +func StartAndRun(socket, filename string, IsRunningChannel chan bool) { log.Info("This is the network superintendent...") log.Info("Starting my ducks") + // Init the Core core := Core{ clients: make(map[string]interfaces.Client), database: database.Database{}, } - core.Init(socket, filename) + core.Init(socket, filename, IsRunningChannel) // Start the GRCP CLI go getCLIGoing(&core) - log.Info("and ready for take off") - -} + go core.Shutdown() -/* - * nucleus.Run() is the "main loop" of the controller - */ - -var isRunning = true - -func Run() { + log.Info("and ready for take off") - for isRunning { + //Just to produce some signs of vitality... + for (true) { time.Sleep(10 * time.Second) log.Debug("Still alive...") } diff --git a/restconf/client/ciena/client.go b/restconf/client/ciena/client.go index cb514e37a39720734a94f29763a54eda9b821e2f..a4d09fd944da93599918329f932daa588d82a0d3 100644 --- a/restconf/client/ciena/client.go +++ b/restconf/client/ciena/client.go @@ -57,6 +57,14 @@ func (c *MCPClient) GetConnections() error { return err } +func (c *MCPClient) GetLinks() error { + defer c.buffer.Reset() + _, err := c.client.TapiTopologyCore.GetTapiCoreContextTopologyMcpBaseTopologyLink(nil) + c.database.StoreConnections(c.buffer.String()) + log.Debug(c.buffer.Next(25)) + return err +} + func (c *MCPClient) GetNodes() error { defer c.buffer.Reset() _, err := c.client.TapiTopologyCore.GetTapiCoreContextTopologyMcpBaseTopologyNode(nil) diff --git a/restconf/util/unmarshal.go b/restconf/util/unmarshal.go index 2386eec8e18bc61e08b71fc7cc782ebe9318bb06..fa195f9357e99b8353a04f66b0a1abffa6c2f9ab 100644 --- a/restconf/util/unmarshal.go +++ b/restconf/util/unmarshal.go @@ -9,7 +9,7 @@ type YANGConsumer struct { Data *bytes.Buffer } -func (yc YANGConsumer)Consume(reader io.Reader, _ interface{}) error { - _,err := yc.Data.ReadFrom(reader) +func (yc YANGConsumer) Consume(reader io.Reader, _ interface{}) error { + _, err := yc.Data.ReadFrom(reader) return err }