VOL-4011:Initial commit changes for opendm-agnt
Added test target
building the opendm-agent inside the docker for jenkins
Change-Id: Id27be99dd1770404a94a49b357229a8b97f8a629
diff --git a/BUILDING.md b/BUILDING.md
new file mode 100644
index 0000000..5a5c2bc
--- /dev/null
+++ b/BUILDING.md
@@ -0,0 +1,99 @@
+## System Requirements
+
+**Hardware** :
+
+CPU: Dual-core (4 Threads) up.
+
+Memory: 6GB
+
+Storage: 50GB of free space.
+
+**Software** :
+
+1. opendm-agent builds on Debian GNU/Linux 8.11.1 (jessie)* . The ISO installer image is downloadble from [here](https://cdimage.debian.org/cdimage/archive/8.11.1/amd64/iso-cd/debian-8.11.1-amd64-netinst.iso)
+
+
+2. At least 4G of ram and 4G of swap - compilation is memory intensive
+
+3. Essential tools for building packages
+
+Install the following packages
+
+ `sudo apt-get update && sudo apt-get install -y git pkg-config build-essential autoconf libgflags-dev clang libc++-dev unzip libssl-dev gawk debhelper debhelper dh-systemd init-system-helpers curl cmake ccache g++-4.9 wget ca-certificates lcov libgoogle-glog-dev libpcap-dev`
+
+Run the below commands to ensure that g++-4.9 and gcc-4.9 are default g++ and gcc compiler versions.
+
+```shell
+sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.9 20
+sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 20
+```
+
+Follow the instructions [here](https://docs.docker.com/engine/install/debian/) to install `docker-ce`. It is not necessary to install `docker-ce-cli` and `containerd.io`.
+
+4. Install cmake version 3.5.1 or above.
+
+```shell
+cd /tmp
+git clone -b v3.5.1 https://gitlab.kitware.com/cmake/cmake.git
+cd /tmp/cmake
+./bootstrap
+make
+sudo make install
+```
+5. Install gRPC version v1.31.1
+
+```shell
+cd /tmp
+git clone -b v1.31.1 https://github.com/grpc/grpc
+cd /tmp/grpc
+git submodule update --init
+mkdir -p cmake/build
+cd cmake/build
+cmake ../.. -DgRPC_INSTALL=ON \
+ -DCMAKE_BUILD_TYPE=Release \
+ -DgRPC_ABSL_PROVIDER=module \
+ -DgRPC_CARES_PROVIDER=module \
+ -DgRPC_PROTOBUF_PROVIDER=module \
+ -DgRPC_RE2_PROVIDER=module \
+ -DgRPC_SSL_PROVIDER=module \
+ -DgRPC_ZLIB_PROVIDER=module
+make
+sudo make install
+# copy library and grpc_cpp_plugin to path below.
+sudo cp `find . -name "*.a"` /usr/local/lib/
+sudo cp `find . -name grpc_cpp_plugin` /usr/local/bin/
+```
+6. Install latest version of Git (optional)
+
+By default the apt-get install an older version of git (2.1.4) on debian jessie 8.11.1. This older version does not support some of the latest git options. You may want to install a later version of git using procedure below.
+
+```shell
+sudo apt-get remove --purge git ## Removes older verion of git
+sudo apt update
+sudo apt install make libssl-dev libghc-zlib-dev libcurl4-gnutls-dev libexpat1-dev gettext unzip
+wget https://github.com/git/git/archive/v2.18.0.zip -O git.zip
+unzip git.zip
+cd git-*
+make prefix=/usr/local all
+sudo make prefix=/usr/local install
+```
+
+## Build procedure
+
+clone `opendm-agent`:
+
+```shell
+git clone "https://gerrit.opencord.org/opendm-agent"
+cd opendm-agent
+make
+```
+
+NOTE: The above make build the ONL image well as docker, opendm-agent will be built on top of this.
+
+## Cleanup
+
+To cleanup the repository and start the build procedure again, run:
+
+```shell
+make clean
+```
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..8c75e17
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,117 @@
+#Copyright 2021-present Open Networking Foundation
+#
+#Licensed under the Apache License, Version 2.0 (the "License");
+#you may not use this file except in compliance with the License.
+#You may obtain a copy of the License at
+#
+#http://www.apache.org/licenses/LICENSE-2.0
+#
+#Unless required by applicable law or agreed to in writing, software
+#distributed under the License is distributed on an "AS IS" BASIS,
+#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#See the License for the specific language governing permissions and
+#limitations under the License.
+
+##################################################################################
+
+# This makefile builds a opendm-agent and libdmi_grpc library
+# Please refer ./README.md and ./BUILDING.md file for more details
+
+CURDIR := $(shell pwd)
+TARCHDIR ?= x86_64
+BUILD_DIR := build
+OBJDIR := $(CURDIR)
+DMI_SOURCE_DIR := $(BUILD_DIR)/device-management-interface/
+
+ifeq ($(DEB_CODENAME),jessie)
+CXX = g++-4.9
+else
+CXX = g++
+endif
+
+DOCKER ?= docker
+DOCKER_REGISTRY ?=
+DOCKER_REPOSITORY ?= voltha/
+DOCKER_EXTRA_ARGS ?=
+DOCKER_TAG ?= 2.1.1
+IMAGENAME = ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}openolt-test:${DOCKER_TAG}
+
+# Version of Open Network Linux (ONL).
+ONL_KERN_VER_MAJOR = 4.19
+
+CXXFLAGS += -ggdb -Werror -Wall -std=c++11
+CXXFLAGS += $(shell pkg-config --cflags-only-I grpc++)
+GRPCFLAGS += `pkg-config --libs grpc++ grpc`
+CXXFLAGS += -std=c++11 -fpermissive -Wno-write-strings -Wno-literal-suffix -I/usr/local/lib/
+LDFLAGS += -L./build/
+LDFLAGS += -lgrpc++_reflection -Wl,--as-needed -ldmi_grpc -lprotobuf -lpthread -ldl
+
+DMIAGENT_SRCS = src/main.cc \
+ src/dmi_phycomp_factory.cc \
+ src/dmi_hw_mgmt.cc \
+ src/dmi_sw_mgmt.cc \
+ src/dmi_server.cc
+
+DMIAGENT_INC = -I./inc/ \
+ -I./protos/ \
+ -I./protos/dmi/
+
+
+DMIAGENT_OBJS = $(DMIAGENT_SRCS:.cc=.o)
+
+all: onl opendm-agent
+ mv opendm-agent $(BUILD_DIR)
+
+opendm-agent: protos-lib $(DMIAGENT_OBJS)
+ $(CXX) $(CXXFLAGS) $(DMIAGENT_OBJS) $(GRPCFLAGS) $(LDFLAGS) -o $@
+
+src/%.o: src/%.cc
+ $(CXX) $(CXXFLAGS) $(LDFLAGS) $(DMIAGENT_INC) -c $< -o $@
+
+protos-lib: prereq
+ echo "Creating the libdmi_grpc.so using auto generated cpp-protos"
+ if [ ! -e "$(OBJDIR)/protos/" ]; then \
+ mkdir -p $(OBJDIR)/protos/; \
+ cp -r $(DMI_SOURCE_DIR)/cpp/dmi $(OBJDIR)/protos; \
+ g++ -shared -fPIC -g -ggdb -std=c++11 `pkg-config --cflags protobuf grpc` -I$(OBJDIR)/protos/ `find $(OBJDIR)/protos/ -name "*.cc"` -o $(OBJDIR)/$(BUILD_DIR)/libdmi_grpc.so; \
+ cp $(OBJDIR)/$(BUILD_DIR)/libdmi_grpc.so /usr/local/lib/; \
+ fi;
+
+prereq: device-management-interface
+
+device-management-interface:
+ if [ ! -e "$(DMI_SOURCE_DIR)" ]; then \
+ git clone https://github.com/opencord/device-management-interface.git $(DMI_SOURCE_DIR); \
+ fi;
+
+#########################################################################
+##
+##
+## ONL Target refered from openolt agent
+##
+###
+ONL_REPO = onl
+ONL_DIR = $(BUILD_DIR)/$(ONL_REPO)
+
+onl:
+ if [ ! -d "$(ONL_DIR)/OpenNetworkLinux" ]; then \
+ mkdir -p $(ONL_DIR); \
+ git clone https://github.com/opencomputeproject/OpenNetworkLinux.git $(ONL_DIR)/OpenNetworkLinux; \
+ cp download/Makefile.onl $(ONL_DIR)/Makefile; \
+ install -m 755 download/build-onl.sh $(ONL_DIR)/OpenNetworkLinux; \
+ make -C $(ONL_DIR) onl-$(ONL_KERN_VER_MAJOR) INBAND=n; \
+ else \
+ if [ "$(INBAND)" = n -a "$$(grep "inband" $(ONL_DIR)/onl_build.mode | cut -d= -f 2)" = y ]; then \
+ make -C $(ONL_DIR) onl-$(ONL_KERN_VER_MAJOR) INBAND=n; \
+ fi; \
+ fi;
+
+test:
+ ${DOCKER} run --rm -v $(shell pwd):/app $(shell test -t 0 && echo "-it") ${IMAGENAME} make -C unit_test test
+
+clean:
+ rm -rf $(OBJDIR)/protos/
+ rm -rf $(OBJDIR)/src/*.o
+ rm -rf $(BUILD_DIR)/*.so
+ rm -rf $(BUILD_DIR)/opendm-agent
+ rm -rf $(DMIAGENT_OBJS)
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..b4fa6e6
--- /dev/null
+++ b/README.md
@@ -0,0 +1,94 @@
+# opendm-agent
+The Open DM Agent runs on the OLT device and implements the below functionalities:
+
+Implementation of the gRPC Server on ONF/SEBA community defined DMI towards Open Device Manager/Operator NEM components.
+a. Hardware Management
+b. Software Management
+c. Events Management
+d. Metrics Management
+
+Implementation of the Device Context Management (Configuration, UUID generation, Inventory, States)
+Implementation of the FSM for pOLT Software upgrades
+Consume the Threshold configuration and generation of threshold based (TCA) events
+Send the Events, Metrics on GRPC Streams, if GRPC Streams RPC is performed
+Publish the Events, Metrics on Message Bus (Kafka) if Message Bus endpoint is configured
+Persistency of the northbound configuration and restoration of the configuration after device reboot
+
+```text
+Option 1:
+ +---------------------------------+
+ | |
+ | Operator NEM |
+ | Components |
+ | |
+ +-------+--------+---------+------+
+ | |
+ dmi gRPC API | |Kafka
+ | |
+ | |
+ | |
++--------------------- ---------------+
+| | |
+| +------------------+ |
+| | OpenDM agent | |
+| | | |
+| +--------+---------+ |
+| | |
+| onlp API | Linux utils |
+| | |
+| | |
+| +---------+ +----------+ |
+| | | | | |
+| |ONL/ONLP | |Linux cmds| |
+| +---------+ +----------+ |
+| |
+| White box OLT |
++-------------------------------------+
+
+```
+
+```text
+Option 2:
+
+ +---------------------------------+
+ | |
+ | Operator NEM |
+ | Components |
+ | |
+ +-------+--------+---------+------+
+ | |
+ dmi gRPC API | |Kafka
+ | |
+ +---------------------------------+
+ | Open Device Manager |
+ | |
+ | +------------------+ |
+ | | OpenDM adapter | |
+ +-------+--------+---------+------+
+ | |
+ dmi gRPC API | |grpc stream
+ | |
++--------------------- ---------------+
+| | |
+| +------------------+ |
+| | OpenDM agent | |
+| | | |
+| +--------+---------+ |
+| | |
+| onlp API | Linux utils |
+| | |
+| | |
+| +---------+ +----------+ |
+| | | | | |
+| |ONL/ONLP | |Linux cmds| |
+| +---------+ +----------+ |
+| |
+| White box OLT |
++-------------------------------------+
+```
+
+## How to Install:
+Copy the build/opendm-agent and build/libdmi_grpc.so to target.
+
+## How to Run:
+Run ./opendm-agent
diff --git a/VERSION b/VERSION
new file mode 100644
index 0000000..0d4d124
--- /dev/null
+++ b/VERSION
@@ -0,0 +1 @@
+0.1.0-dev
diff --git a/download/Makefile.onl b/download/Makefile.onl
new file mode 100644
index 0000000..3a46cdb
--- /dev/null
+++ b/download/Makefile.onl
@@ -0,0 +1,26 @@
+# Copyright (C) 2021 Makefile
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at:
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+COMMIT_ID = 72b95a7
+INBAND = "n"
+
+onl-4.14:
+ if [ $(INBAND) = y ]; then \
+ cd OpenNetworkLinux && git checkout -B $@ $(COMMIT_ID) && git apply inband-$(COMMIT_ID).patch && docker/tools/onlbuilder --non-interactive -8 -c ./build-onl.sh; \
+ else \
+ cd OpenNetworkLinux && git stash && git checkout -B $@ $(COMMIT_ID) && docker/tools/onlbuilder --non-interactive -8 -c ./build-onl.sh; \
+ fi;
+
+onl-4.19:
+ cd OpenNetworkLinux && git stash && git checkout -B $@ $(COMMIT_ID) && docker/tools/onlbuilder --non-interactive -9 -c ./build-onl.sh;
diff --git a/download/build-onl.sh b/download/build-onl.sh
new file mode 100644
index 0000000..f27bc32
--- /dev/null
+++ b/download/build-onl.sh
@@ -0,0 +1,18 @@
+#!/bin/bash
+
+# Copyright (C) 2021 Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at:
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+apt-cacher-ng && source setup.env && make amd64
+exit
diff --git a/inc/dmi_common.h b/inc/dmi_common.h
new file mode 100644
index 0000000..a8a6261
--- /dev/null
+++ b/inc/dmi_common.h
@@ -0,0 +1,34 @@
+ /*
+ * Copyright 2021-present Open Networking Foundation
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef DMI_COMMON_H_
+#define DMI_COMMON_H_
+
+#include <iostream>
+#include <string>
+#include <memory>
+#include <vector>
+#include <grpc/grpc.h>
+#include <grpc++/server.h>
+#include <grpc++/server_builder.h>
+#include <grpc++/server_context.h>
+#include <grpcpp/grpcpp.h>
+
+using grpc::Server;
+using grpc::ServerBuilder;
+using grpc::ServerContext;
+using grpc::ServerWriter;
+using grpc::Status;
+using grpc::ResourceQuota;
+
+#endif
diff --git a/inc/dmi_events_mgmt.h b/inc/dmi_events_mgmt.h
new file mode 100644
index 0000000..6a275dd
--- /dev/null
+++ b/inc/dmi_events_mgmt.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2021-present Open Networking Foundation
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef DMI_HW_MGMT_H_
+#define DMI_HH_MGMT_H_
+
+#include "hw_events_mgmt_service.grpc.pb.h"
+#include "hw_events_mgmt_service.pb.h"
+#include "dmi_common.h"
+
+class HWEventsMgmtService final : public dmi::NativeEventsManagementService::Service
+{
+ public:
+ static HWEventsMgmtService& getHwEventMgmtInstance()
+ {
+ static HWEventsMgmtService HwEventInstance;
+ return HwEventInstance;
+ }
+
+ grpc::Status ListEvents(
+ ServerContext* context,
+ const dmi::HardwareID* request,
+ dmi::ListEventsResponse* response)
+ {
+ //TODO write an internal API to handle the request
+ return Status(grpc::StatusCode::UNIMPLEMENTED, "RPC not implemented");
+ }
+
+ grpc::Status UpdateEventsConfiguration(
+ ServerContext* context,
+ const dmi::EventsConfigurationRequest* request,
+ dmi::EventsConfigurationResponse* response )
+ {
+ //TODO write an internal API to handle the request
+ return Status(grpc::StatusCode::UNIMPLEMENTED, "RPC not implemented");
+ }
+
+ private:
+ HWEventsMgmtService()
+ {
+ }
+
+ ~HWEventsMgmtService()
+ {
+ }
+};
+
+#endif
diff --git a/inc/dmi_hw_mgmt.h b/inc/dmi_hw_mgmt.h
new file mode 100644
index 0000000..2ff29ab
--- /dev/null
+++ b/inc/dmi_hw_mgmt.h
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2021-present Open Networking Foundation
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef DMI_HW_MGMT_H_
+#define DMI_HH_MGMT_H_
+
+#include "hw_management_service.grpc.pb.h"
+#include "hw_management_service.pb.h"
+#include "dmi_common.h"
+
+using grpc::ServerWriter;
+
+grpc::Status StartManagingDevice_(
+ const dmi::ModifiableComponent* request,
+ ServerWriter<dmi::StartManagingDeviceResponse>* writer
+ );
+grpc::Status StopManagingDevice_(dmi::StopManagingDeviceResponse* response);
+grpc::Status GetManagedDevices_(dmi::ManagedDevicesResponse* response);
+grpc::Status GetPhysicalInventory_(dmi::PhysicalInventoryResponse* response);
+
+class HWMgmtService final : public dmi::NativeHWManagementService::Service
+{
+ public:
+ static HWMgmtService& getHWInstance()
+ {
+ static HWMgmtService hwinstance;
+ return hwinstance;
+ }
+
+ grpc::Status StartManagingDevice(
+ ServerContext* context,
+ const dmi::ModifiableComponent* request,
+ ServerWriter<dmi::StartManagingDeviceResponse>* writer
+ )
+ {
+ return StartManagingDevice_(request, writer);
+ }
+
+ grpc::Status StopManagingDevice(
+ ServerContext* context,
+ const dmi::StopManagingDeviceRequest* request,
+ dmi::StopManagingDeviceResponse* response
+ )
+ {
+ return StopManagingDevice_(response);
+ }
+
+ grpc::Status GetManagedDevices(
+ ServerContext* context,
+ const google::protobuf::Empty* request,
+ dmi::ManagedDevicesResponse* response
+ )
+ {
+ return GetManagedDevices_(response);
+ }
+
+ grpc::Status GetPhysicalInventory(
+ ServerContext* context,
+ const dmi::PhysicalInventoryRequest* request,
+ dmi::PhysicalInventoryResponse* response
+ )
+ {
+ return GetPhysicalInventory_(response);
+ }
+
+ private:
+ HWMgmtService()
+ {
+ }
+
+ ~HWMgmtService()
+ {
+ }
+};
+
+#endif
diff --git a/inc/dmi_metrics_mgmt.h b/inc/dmi_metrics_mgmt.h
new file mode 100644
index 0000000..a60e21d
--- /dev/null
+++ b/inc/dmi_metrics_mgmt.h
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2021-present Open Networking Foundation
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef DMI_HW_MGMT_H_
+#define DMI_HH_MGMT_H_
+
+#include "hw_metrics_mgmt_service.grpc.pb.h"
+#include "hw_metrics_mgmt_service.pb.h"
+#include "dmi_common.h"
+
+using grpc::ServerWriter;
+
+
+class HWMetricsMgmtService final : public dmi::NativeMetricsManagementService::Service
+{
+ public:
+ static HWMetricsMgmtService& getHwMetricMgmtInstance()
+ {
+ static HWMetricsMgmtService HwMetrictInstance;
+ return HwMetrictInstance;
+ }
+
+ grpc::Status ListMetrics(
+ ServerContext* context,
+ const dmi::HardwareID* request,
+ dmi::ListMetricsResponse* response )
+ {
+ //TODO write an internal API to handle the request
+ return Status(grpc::StatusCode::UNIMPLEMENTED, "RPC not implemented");
+ }
+
+ grpc::Status UpdateMetricsConfiguration(
+ ServerContext* context,
+ const dmi::MetricsConfigurationRequest* request,
+ dmi::MetricsConfigurationResponse* response )
+ {
+ //TODO write an internal API to handle the request
+ return Status(grpc::StatusCode::UNIMPLEMENTED, "RPC not implemented");
+ }
+
+ grpc::Status GetMetric(
+ ServerContext* context,
+ const dmi::GetMetricRequest* request,
+ dmi::GetMetricResponse* response )
+ {
+ //TODO write an internal API to handle the request
+ return Status(grpc::StatusCode::UNIMPLEMENTED, "RPC not implemented");
+ }
+
+ private:
+ HWMetricsMgmtService()
+ {
+ }
+
+ ~HWMetricsMgmtService()
+ {
+ }
+};
+
+#endif
diff --git a/inc/dmi_phycomp_factory.h b/inc/dmi_phycomp_factory.h
new file mode 100644
index 0000000..e3711eb
--- /dev/null
+++ b/inc/dmi_phycomp_factory.h
@@ -0,0 +1,224 @@
+/*
+ * Copyright 2021-present Open Networking Foundation
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#ifndef DMI_PHYCOMP_FACTORY_H_
+#define DMI_PHYCOMP_FACTORY_H_
+
+#include "hw_management_service.grpc.pb.h"
+#include "hw_management_service.pb.h"
+#include <iostream>
+#include <string>
+/*
+ * PhyComponent
+ * PhyComponent implement the same interface so that the classes can refer
+ * to the interface not the concrete Component
+ */
+class PhyComponent
+{
+ public:
+ dmi::Component comp;
+ uint8_t comp_number;
+
+ /*Interfaces where each subclasses implements thier specific details*/
+ virtual uint8_t UpdateComp(uint8_t comp_number) = 0;
+ virtual uint8_t SetModifiableCompFields(dmi::ModifiableComponent mod_fields) = 0;
+
+ virtual ~PhyComponent() {}
+};
+
+
+/*
+ * Concrete Component
+ * define Component to be created
+ */
+class FanComp : public PhyComponent
+{
+ public:
+ FanComp()
+ {
+ /*Fill the default/common parameters here*/
+ this->comp.set_class_( dmi::ComponentType::COMPONENT_TYPE_FAN);
+ this->comp.set_is_fru( 1 );
+ }
+
+ uint8_t UpdateComp(uint8_t comp_number);
+ uint8_t SetModifiableCompFields(dmi::ModifiableComponent mod_fields);
+ ~FanComp() {}
+};
+
+
+
+/*
+ * Concrete Component
+ * define Component to be created
+ */
+class DiskComp : public PhyComponent
+{
+ public:
+ DiskComp()
+ {
+ this->comp.set_class_( dmi::ComponentType::COMPONENT_TYPE_STORAGE);
+ this->comp.set_is_fru( 0 );
+ }
+
+ uint8_t UpdateComp(uint8_t comp_number);
+ uint8_t SetModifiableCompFields(dmi::ModifiableComponent mod_fields);
+ ~DiskComp() {}
+};
+
+
+/*
+ * Concrete Component
+ * define Component to be created
+ */
+class ContainerComp : public PhyComponent
+{
+ public:
+ ContainerComp()
+ {
+ this->comp.set_class_( dmi::ComponentType::COMPONENT_TYPE_CONTAINER);
+ this->comp.set_is_fru( 0 );
+ //set the container attribute
+ }
+
+ uint8_t UpdateComp(uint8_t comp_number);
+ uint8_t SetModifiableCompFields(dmi::ModifiableComponent mod_fields);
+ ~ContainerComp() {}
+};
+
+
+
+/*
+ * Concrete Component
+ * define Component to be created
+ */
+class PortComp : public PhyComponent
+{
+ public:
+ PortComp()
+ {
+ this->comp.set_class_( dmi::ComponentType::COMPONENT_TYPE_PORT );
+ this->comp.set_is_fru( 0 );
+ }
+
+ uint8_t UpdateComp(uint8_t comp_number);
+ uint8_t SetModifiableCompFields(dmi::ModifiableComponent mod_fields);
+ ~PortComp() {}
+};
+
+
+/*
+ * Concrete Component
+ * define Component to be created
+ */
+class CPUComp : public PhyComponent
+{
+ public:
+ CPUComp()
+ {
+ this->comp.set_class_( dmi::ComponentType::COMPONENT_TYPE_CPU );
+ this->comp.set_is_fru( 0 );
+ }
+
+ uint8_t UpdateComp(uint8_t comp_number);
+ uint8_t SetModifiableCompFields(dmi::ModifiableComponent mod_fields);
+ ~CPUComp() {}
+};
+
+/*
+ * Concrete Component
+ * define Component to be created
+ */
+class TransceiverComp : public PhyComponent
+{
+ public:
+ TransceiverComp()
+ {
+ this->comp.set_class_( dmi::ComponentType::COMPONENT_TYPE_TRANSCEIVER );
+ this->comp.set_is_fru ( 1 );
+ }
+
+ uint8_t UpdateComp(uint8_t comp_number);
+ uint8_t SetModifiableCompFields(dmi::ModifiableComponent mod_fields);
+ ~TransceiverComp() {}
+};
+
+
+/*
+ * Creator
+ * contains the implementation for all of the methods
+ * to manipulate products except for the factory method
+ */
+class Creator
+{
+ public:
+
+ virtual PhyComponent* CreateFanCompInst() = 0;
+ virtual PhyComponent* CreateDiskCompInst() = 0;
+ virtual PhyComponent* CreateContainerCompInst() = 0;
+ virtual PhyComponent* CreatePortCompInst() = 0;
+ virtual PhyComponent* CreateCPUCompInst() = 0;
+ virtual PhyComponent* CreateTransceiverCompInst() = 0;
+ virtual void removeComponent( PhyComponent *comp ) = 0;
+ virtual ~Creator() {}
+};
+
+/*
+ * Concrete Creator
+ * implements factory method that is responsible for creating
+ * one or more concrete products ie. it is class that has
+ * the knowledge of how to create the products
+ */
+class ConcreteComp : public Creator
+{
+ public:
+ ~ConcreteComp() {}
+
+ PhyComponent* CreateFanCompInst()
+ {
+ return new FanComp();
+ }
+
+ PhyComponent* CreateDiskCompInst()
+ {
+ return new DiskComp();
+ }
+
+ PhyComponent* CreateContainerCompInst()
+ {
+ return new ContainerComp();
+ }
+
+ PhyComponent* CreatePortCompInst()
+ {
+ return new PortComp();
+ }
+
+ PhyComponent* CreateCPUCompInst()
+ {
+ return new CPUComp();
+ }
+
+ PhyComponent* CreateTransceiverCompInst()
+ {
+ return new TransceiverComp();
+ }
+
+ void removeComponent( PhyComponent *comp )
+ {
+ delete comp;
+ }
+};
+#endif
+
diff --git a/inc/dmi_server.h b/inc/dmi_server.h
new file mode 100644
index 0000000..5e79bb0
--- /dev/null
+++ b/inc/dmi_server.h
@@ -0,0 +1,21 @@
+ /*
+ * Copyright 2021-present Open Networking Foundation
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#ifndef DMI_SERVER_H_
+#define DMI_SERVER_H_
+
+extern void RunGrpcServer();
+
+#endif
+
diff --git a/inc/dmi_sw_mgmt.h b/inc/dmi_sw_mgmt.h
new file mode 100644
index 0000000..b699157
--- /dev/null
+++ b/inc/dmi_sw_mgmt.h
@@ -0,0 +1,96 @@
+ /*
+ * Copyright 2021-present Open Networking Foundation
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef DMI_SW_MGMT_H_
+#define DMI_SW_MGMT_H_
+
+#include "sw_management_service.grpc.pb.h"
+#include "sw_management_service.pb.h"
+#include "dmi_common.h"
+
+using grpc::ServerWriter;
+
+grpc::Status GetSoftwareVersion_(const dmi::HardwareID* request,
+ dmi::GetSoftwareVersionInformationResponse* response);
+
+class SWMgmtService final : public dmi::NativeSoftwareManagementService::Service
+{
+ public:
+ static SWMgmtService& getSWInstance()
+ {
+ static SWMgmtService swinstance;
+ return swinstance;
+ }
+
+ grpc::Status GetSoftwareVersion(
+ ServerContext* context,
+ const dmi::HardwareID* request,
+ dmi::GetSoftwareVersionInformationResponse* response )
+ {
+ return GetSoftwareVersion_(request, response);
+ }
+
+ grpc::Status DownloadImage(
+ ServerContext* context,
+ const dmi::DownloadImageRequest* request,
+ ServerWriter<dmi::ImageStatus>* writer )
+ {
+ //TODO write an internal API to handle the request
+ return Status(grpc::StatusCode::UNIMPLEMENTED, "RPC not implemented");
+ }
+
+ grpc::Status ActivateImage(
+ ServerContext* context,
+ const dmi::HardwareID* request,
+ ServerWriter<dmi::ImageStatus>* writer )
+ {
+ //TODO write an internal API to handle the request
+ return Status(grpc::StatusCode::UNIMPLEMENTED, "RPC not implemented");
+ }
+
+ grpc::Status RevertToStandbyImage(
+ ServerContext* context,
+ const dmi::HardwareID* request,
+ ServerWriter<dmi::ImageStatus>* writer )
+ {
+ //TODO write an internal API to handle the request
+ return Status(grpc::StatusCode::UNIMPLEMENTED, "RPC not implemented");
+ }
+
+ grpc::Status UpdateStartupConfiguration(
+ ServerContext* context,
+ const dmi::ConfigRequest* request,
+ ServerWriter<dmi::ConfigResponse>* writer )
+ {
+ //TODO write an internal API to handle the request
+ return Status(grpc::StatusCode::UNIMPLEMENTED, "RPC not implemented");
+ }
+
+ grpc::Status GetStartupConfigurationInfo(
+ ServerContext* context,
+ const dmi::StartupConfigInfoRequest* request,
+ dmi::StartupConfigInfoResponse* response )
+ {
+ //TODO write an internal API to handle the request
+ return Status(grpc::StatusCode::UNIMPLEMENTED, "RPC not implemented");
+ }
+ private:
+ SWMgmtService()
+ {
+ }
+
+ ~SWMgmtService()
+ {
+ }
+};
+#endif
diff --git a/inc/dmi_utils.h b/inc/dmi_utils.h
new file mode 100644
index 0000000..e806ca9
--- /dev/null
+++ b/inc/dmi_utils.h
@@ -0,0 +1,12 @@
+ /*
+ * Copyright 2021-present Open Networking Foundation
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
diff --git a/src/dmi_common.cc b/src/dmi_common.cc
new file mode 100644
index 0000000..35e32c0
--- /dev/null
+++ b/src/dmi_common.cc
@@ -0,0 +1,13 @@
+/*
+ * Copyright 2021-present Open Networking Foundation
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
diff --git a/src/dmi_events_mgmt.cc b/src/dmi_events_mgmt.cc
new file mode 100644
index 0000000..35e32c0
--- /dev/null
+++ b/src/dmi_events_mgmt.cc
@@ -0,0 +1,13 @@
+/*
+ * Copyright 2021-present Open Networking Foundation
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
diff --git a/src/dmi_hw_mgmt.cc b/src/dmi_hw_mgmt.cc
new file mode 100644
index 0000000..b256862
--- /dev/null
+++ b/src/dmi_hw_mgmt.cc
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2021-present Open Networking Foundation
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "dmi_hw_mgmt.h"
+
+grpc::Status StartManagingDevice_(
+ const dmi::ModifiableComponent* request,
+ ServerWriter<dmi::StartManagingDeviceResponse>* write)
+{
+ return Status(grpc::StatusCode::UNIMPLEMENTED, "RPC not implemented");
+}
+
+grpc::Status StopManagingDevice_(dmi::StopManagingDeviceResponse* response)
+{
+ return Status(grpc::StatusCode::UNIMPLEMENTED, "RPC not implemented");
+}
+
+grpc::Status GetManagedDevices_(dmi::ManagedDevicesResponse* response)
+{
+ return Status(grpc::StatusCode::UNIMPLEMENTED, "RPC not implemented");
+}
+
+grpc::Status GetPhysicalInventory_(dmi::PhysicalInventoryResponse* response)
+{
+ return Status(grpc::StatusCode::UNIMPLEMENTED, "RPC not implemented");
+}
+
+
diff --git a/src/dmi_metrics_mgmt.cc b/src/dmi_metrics_mgmt.cc
new file mode 100644
index 0000000..35e32c0
--- /dev/null
+++ b/src/dmi_metrics_mgmt.cc
@@ -0,0 +1,13 @@
+/*
+ * Copyright 2021-present Open Networking Foundation
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
diff --git a/src/dmi_phycomp_factory.cc b/src/dmi_phycomp_factory.cc
new file mode 100644
index 0000000..ee44286
--- /dev/null
+++ b/src/dmi_phycomp_factory.cc
@@ -0,0 +1,95 @@
+/*
+ * Copyright 2021-present Open Networking Foundation
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef DMI_PHYCOMP_FACTORY_H_
+#include "dmi_phycomp_factory.h"
+#endif
+
+
+
+uint8_t FanComp::UpdateComp(uint8_t comp_number)
+{
+ return 0;
+}
+
+uint8_t FanComp::SetModifiableCompFields(dmi::ModifiableComponent mod_fields)
+{
+ /*Set the Component feilds sent from the NEM/DM in mod_fields */
+ return 0;
+}
+
+uint8_t DiskComp::UpdateComp(uint8_t comp_number)
+{
+ /*Fetch the particular fan details from the onlp array and update the object*/
+ /*Update ComponentSensorData*/
+ return 0;
+}
+
+uint8_t DiskComp::SetModifiableCompFields(dmi::ModifiableComponent mod_fields)
+{
+ /*Set the Component feilds sent from the NEM/DM in mod_fields */
+ return 0;
+}
+
+uint8_t ContainerComp::UpdateComp(uint8_t comp_number)
+{
+ /*Fetch the particular fan details from the onlp array and update the object*/
+ /*Update ComponentSensorData*/
+ return 0;
+}
+
+uint8_t ContainerComp::SetModifiableCompFields(dmi::ModifiableComponent mod_fields)
+{
+ /*Set the Component feilds sent from the NEM/DM in mod_fields */
+ return 0;
+}
+
+uint8_t PortComp::UpdateComp(uint8_t comp_number)
+{
+ /*Fetch the particular fan details from the onlp array and update the object*/
+ /*Update ComponentSensorData*/
+ return 0;
+}
+
+uint8_t PortComp::SetModifiableCompFields(dmi::ModifiableComponent mod_fields)
+{
+ /*Set the Component feilds sent from the NEM/DM in mod_fields */
+ return 0;
+}
+
+uint8_t CPUComp::UpdateComp(uint8_t comp_number)
+{
+ /*Fetch the particular fan details from the onlp array and update the object*/
+ /*Update ComponentSensorData*/
+ return 0;
+}
+
+uint8_t CPUComp::SetModifiableCompFields(dmi::ModifiableComponent mod_fields)
+{
+ /*Set the Component feilds sent from the NEM/DM in mod_fields */
+ return 0;
+}
+
+uint8_t TransceiverComp::UpdateComp(uint8_t comp_number)
+{
+ /*Fetch the particular fan details from the onlp array and update the object*/
+ /*Update ComponentSensorData*/
+ return 0;
+}
+
+uint8_t TransceiverComp::SetModifiableCompFields(dmi::ModifiableComponent mod_fields)
+{
+ /*Set the Component feilds sent from the NEM/DM in mod_fields */
+ return 0;
+}
+
diff --git a/src/dmi_server.cc b/src/dmi_server.cc
new file mode 100644
index 0000000..c5ec9f6
--- /dev/null
+++ b/src/dmi_server.cc
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2021-present Open Networking Foundation
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef DMI_HW_MGMT_H_
+#include "dmi_hw_mgmt.h"
+#endif
+
+#include "dmi_sw_mgmt.h"
+#include "dmi_events_mgmt.h"
+#include "dmi_metrics_mgmt.h"
+
+#define GRPC_ADDRESS "0.0.0.0:9292"
+
+using namespace std;
+
+void RunGrpcServer() {
+ const char* address = GRPC_ADDRESS;
+ HWMgmtService &HWMgmtSrv = HWMgmtService::getHWInstance();
+ SWMgmtService &SWMgmtSrv = SWMgmtService::getSWInstance();
+ HWEventsMgmtService &EventMgmtSrv = HWEventsMgmtService::getHwEventMgmtInstance();
+ HWMetricsMgmtService &MetricMgmtSrv = HWMetricsMgmtService::getHwMetricMgmtInstance();
+
+ ServerBuilder builder;
+
+ builder.AddListeningPort(address, grpc::InsecureServerCredentials());
+ builder.RegisterService(&HWMgmtSrv);
+ builder.RegisterService(&SWMgmtSrv);
+ builder.RegisterService(&EventMgmtSrv);
+ builder.RegisterService(&MetricMgmtSrv);
+
+ std::unique_ptr<Server> server(builder.BuildAndStart());
+ std::cout << "opendm-agent GRPC server listening on port: " << address << std::endl;
+
+ server->Wait();
+}
diff --git a/src/dmi_sw_mgmt.cc b/src/dmi_sw_mgmt.cc
new file mode 100644
index 0000000..ef60bd8
--- /dev/null
+++ b/src/dmi_sw_mgmt.cc
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2021-present Open Networking Foundation
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "dmi_sw_mgmt.h"
+
+grpc::Status GetSoftwareVersion_(const dmi::HardwareID* request,
+ dmi::GetSoftwareVersionInformationResponse* response)
+{
+ return Status(grpc::StatusCode::UNIMPLEMENTED, "RPC not implemented");
+}
diff --git a/src/dmi_utils.cc b/src/dmi_utils.cc
new file mode 100644
index 0000000..35e32c0
--- /dev/null
+++ b/src/dmi_utils.cc
@@ -0,0 +1,13 @@
+/*
+ * Copyright 2021-present Open Networking Foundation
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
diff --git a/src/main.cc b/src/main.cc
new file mode 100644
index 0000000..7ba9ec2
--- /dev/null
+++ b/src/main.cc
@@ -0,0 +1,21 @@
+/*
+ * Copyright 2021-present Open Networking Foundation
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <iostream>
+#include <unistd.h>
+#include "dmi_server.h"
+
+int main(int argc, char** argv) {
+ RunGrpcServer();
+ return 0;
+}
diff --git a/unit_test/Makefile b/unit_test/Makefile
new file mode 100644
index 0000000..823c3db
--- /dev/null
+++ b/unit_test/Makefile
@@ -0,0 +1,18 @@
+# Copyright 2021-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+########################################################################
+
+test:
+ echo "Call unit test case suite"