VOL-1910 added techproile mock struct to cover openolt_flowmgr.go files
Change-Id: I0bd44890f02909da870771cc332f2a5de264020b
diff --git a/mocks/mockKVClient.go b/mocks/mockKVClient.go
index e11a756..2417f51 100644
--- a/mocks/mockKVClient.go
+++ b/mocks/mockKVClient.go
@@ -23,8 +23,12 @@
"strconv"
"strings"
+ "github.com/opencord/voltha-go/common/log"
+ "github.com/opencord/voltha-openolt-adapter/adaptercore/resourcemanager"
+
"github.com/opencord/voltha-go/db/kvstore"
ofp "github.com/opencord/voltha-protos/go/openflow_13"
+ openolt "github.com/opencord/voltha-protos/go/openolt"
)
const (
@@ -32,6 +36,16 @@
MeterConfig = "meter_id"
// TpIDPathSuffix to extract Techprofile
TpIDPathSuffix = "tp_id"
+ // FlowIDpool to extract Flow ids
+ FlowIDpool = "flow_id_pool"
+ // FlowIDs to extract flow_ids
+ FlowIDs = "flow_ids"
+ // FlowIDInfo to extract flowId info
+ FlowIDInfo = "flow_id_info"
+ // GemportIDs to gemport_ids
+ GemportIDs = "gemport_ids"
+ // AllocIDs to extract alloc_ids
+ AllocIDs = "alloc_ids"
)
// MockKVClient mocks the AdapterProxy interface.
@@ -50,8 +64,17 @@
// Get mock function implementation for KVClient
func (kvclient *MockKVClient) Get(key string, timeout int, lock ...bool) (*kvstore.KVPair, error) {
+ log.Debugw("Warning Warning Warning: Get of MockKVClient called", log.Fields{"key": key})
if key != "" {
-
+ log.Debug("Warning Key Not Blank")
+ if strings.Contains(key, "meter_id/{0,62,8}/{upstream}") {
+ meterConfig := ofp.OfpMeterConfig{
+ Flags: 0,
+ MeterId: 1,
+ }
+ str, _ := json.Marshal(meterConfig)
+ return kvstore.NewKVPair(key, string(str), "mock", 3000, 1), nil
+ }
if strings.Contains(key, MeterConfig) {
var bands []*ofp.OfpMeterBandHeader
bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DSCP_REMARK,
@@ -60,15 +83,23 @@
bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DSCP_REMARK,
Rate: 1024, Data: &ofp.OfpMeterBandHeader_DscpRemark{DscpRemark: &ofp.OfpMeterBandDscpRemark{PrecLevel: 3}}})
- // bands = append(bands, &ofp.OfpMeterBandHeader{})
- // Data: &ofp.OfpMeterBandHeader_Drop{Drop: &ofp.OfpMeterBandDrop{}}
sep := strings.Split(key, "/")[2]
val, _ := strconv.ParseInt(strings.Split(sep, ",")[1], 10, 32)
if uint32(val) > 1 {
meterConfig := &ofp.OfpMeterConfig{MeterId: uint32(val), Bands: bands}
str, _ := json.Marshal(meterConfig)
- //json.marshall()
- return kvstore.NewKVPair(key, string(str), "mock", 3000, 1), nil
+
+ return kvstore.NewKVPair(key, str, "mock", 3000, 1), nil
+ }
+
+ if strings.Contains(key, "meter_id/{1,1,1}/{downstream}") {
+
+ band1 := &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 1000, BurstSize: 5000}
+ band2 := &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 2000, BurstSize: 5000}
+ bands := []*ofp.OfpMeterBandHeader{band1, band2}
+ ofpMeterConfig := &ofp.OfpMeterConfig{Flags: 1, MeterId: 1, Bands: bands}
+ str, _ := json.Marshal(ofpMeterConfig)
+ return kvstore.NewKVPair(key, str, "mock", 3000, 1), nil
}
if uint32(val) == 1 {
return nil, nil
@@ -76,6 +107,43 @@
return nil, errors.New("invalid meter")
}
if strings.Contains(key, TpIDPathSuffix) {
+ str, _ := json.Marshal(64)
+ return kvstore.NewKVPair(key, str, "mock", 3000, 1), nil
+ }
+ if strings.Contains(key, FlowIDpool) {
+ log.Debug("Error Error Error Key:", FlowIDpool)
+ data := make(map[string]interface{})
+ data["pool"] = "1024"
+ data["start_idx"] = 1
+ data["end_idx"] = 1024
+ str, _ := json.Marshal(data)
+ return kvstore.NewKVPair(key, str, "mock", 3000, 1), nil
+ }
+ if strings.Contains(key, FlowIDs) {
+ data := []uint32{1, 2}
+ log.Debug("Error Error Error Key:", FlowIDs)
+ str, _ := json.Marshal(data)
+ return kvstore.NewKVPair(key, str, "mock", 3000, 1), nil
+ }
+ if strings.Contains(key, FlowIDInfo) {
+
+ data := []resourcemanager.FlowInfo{
+ {
+ Flow: &openolt.Flow{FlowId: 1, OnuId: 1, UniId: 1, GemportId: 1},
+ FlowStoreCookie: uint64(48132224281636694),
+ },
+ }
+ log.Debug("Error Error Error Key:", FlowIDs)
+ str, _ := json.Marshal(data)
+ return kvstore.NewKVPair(key, str, "mock", 3000, 1), nil
+ }
+ if strings.Contains(key, GemportIDs) {
+ log.Debug("Error Error Error Key:", GemportIDs)
+ str, _ := json.Marshal(1)
+ return kvstore.NewKVPair(key, str, "mock", 3000, 1), nil
+ }
+ if strings.Contains(key, AllocIDs) {
+ log.Debug("Error Error Error Key:", AllocIDs)
str, _ := json.Marshal(1)
return kvstore.NewKVPair(key, str, "mock", 3000, 1), nil
}
diff --git a/mocks/mockTechprofile.go b/mocks/mockTechprofile.go
new file mode 100644
index 0000000..138e7ea
--- /dev/null
+++ b/mocks/mockTechprofile.go
@@ -0,0 +1,103 @@
+/*
+ * Copyright 2018-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.
+ */
+
+//Package mocks provides the mocks for openolt-adapter.
+package mocks
+
+import (
+ "github.com/opencord/voltha-go/common/log"
+ tp "github.com/opencord/voltha-go/common/techprofile"
+ "github.com/opencord/voltha-go/db/model"
+ tp_pb "github.com/opencord/voltha-protos/go/tech_profile"
+)
+
+// MockTechProfile mock struct for OpenoltClient.
+type MockTechProfile struct {
+ TpID uint32
+}
+
+// SetKVClient to mock tefhprofile SetKVClient method
+func (m MockTechProfile) SetKVClient() *model.Backend {
+ return &model.Backend{Client: &MockKVClient{}}
+}
+
+// GetTechProfileInstanceKVPath to mock tefhprofile GetTechProfileInstanceKVPath method
+func (m MockTechProfile) GetTechProfileInstanceKVPath(techProfiletblID uint32, uniPortName string) string {
+ return ""
+
+}
+
+// GetTPInstanceFromKVStore to mock tefhprofile GetTPInstanceFromKVStore method
+func (m MockTechProfile) GetTPInstanceFromKVStore(techProfiletblID uint32, path string) (*tp.TechProfile, error) {
+ log.Debug("Warning Warning Warning: GetTPInstanceFromKVStore")
+ return nil, nil
+
+}
+
+// CreateTechProfInstance to mock tefhprofile CreateTechProfInstance method
+func (m MockTechProfile) CreateTechProfInstance(techProfiletblID uint32, uniPortName string, intfID uint32) *tp.TechProfile {
+
+ return &tp.TechProfile{
+ Name: "mock-tech-profile",
+ SubscriberIdentifier: "257",
+ ProfileType: "mock",
+ Version: 0,
+ NumGemPorts: 2,
+ NumTconts: 1,
+ UpstreamGemPortAttributeList: nil,
+ DownstreamGemPortAttributeList: nil,
+ }
+
+}
+
+// DeleteTechProfileInstance to mock tefhprofile DeleteTechProfileInstance method
+func (m MockTechProfile) DeleteTechProfileInstance(techProfiletblID uint32, uniPortName string) error {
+ return nil
+}
+
+// GetprotoBufParamValue to mock tefhprofile GetprotoBufParamValue method
+func (m MockTechProfile) GetprotoBufParamValue(paramType string, paramKey string) int32 {
+ return 0
+
+}
+
+// GetUsScheduler to mock tefhprofile GetUsScheduler method
+func (m MockTechProfile) GetUsScheduler(tpInstance *tp.TechProfile) *tp_pb.SchedulerConfig {
+ return &tp_pb.SchedulerConfig{}
+
+}
+
+// GetDsScheduler to mock tefhprofile GetDsScheduler method
+func (m MockTechProfile) GetDsScheduler(tpInstance *tp.TechProfile) *tp_pb.SchedulerConfig {
+ return &tp_pb.SchedulerConfig{}
+}
+
+// GetTrafficScheduler to mock tefhprofile GetTrafficScheduler method
+func (m MockTechProfile) GetTrafficScheduler(tpInstance *tp.TechProfile, SchedCfg *tp_pb.SchedulerConfig,
+ ShapingCfg *tp_pb.TrafficShapingInfo) *tp_pb.TrafficScheduler {
+ return &tp_pb.TrafficScheduler{}
+
+}
+
+// GetTrafficQueues to mock tefhprofile GetTrafficQueues method
+func (m MockTechProfile) GetTrafficQueues(tp *tp.TechProfile, Dir tp_pb.Direction) []*tp_pb.TrafficQueue {
+ return []*tp_pb.TrafficQueue{{}}
+}
+
+// GetGemportIDForPbit to mock tefhprofile GetGemportIDForPbit method
+func (m MockTechProfile) GetGemportIDForPbit(tp *tp.TechProfile, Dir tp_pb.Direction, pbit uint32) uint32 {
+ return 0
+}