VOL-3419: Replicate voltha flows in openolt agent
- The scale-tester-app will adhere to new openolt.proto interface (version 4.0.2)
and will pass necessary information for openolt-agent to replicate the flows.
- upgrade to voltha-lib-go version 4.0.0
Change-Id: I9d862929ae8ac4468d4e93096f8cd8e16f26ec93
diff --git a/core/resource_manager.go b/core/resource_manager.go
index d8674c9..255e1be 100644
--- a/core/resource_manager.go
+++ b/core/resource_manager.go
@@ -18,20 +18,14 @@
package core
import (
- "strconv"
- "strings"
"sync"
- "github.com/opencord/voltha-lib-go/v3/pkg/log"
- ponrmgr "github.com/opencord/voltha-lib-go/v3/pkg/ponresourcemanager"
- "github.com/opencord/voltha-protos/v3/go/openolt"
+ "github.com/opencord/voltha-lib-go/v4/pkg/log"
+ ponrmgr "github.com/opencord/voltha-lib-go/v4/pkg/ponresourcemanager"
+ "github.com/opencord/voltha-protos/v4/go/openolt"
"golang.org/x/net/context"
)
-func init() {
- _, _ = log.AddPackage(log.JSON, log.DebugLevel, nil)
-}
-
// OpenOltResourceMgr holds resource related information as provided below for each field
type OpenOltResourceMgr struct {
deviceInfo *openolt.DeviceInfo
@@ -47,6 +41,8 @@
// array of pon resource managers per interface technology
ResourceMgrs map[uint32]*ponrmgr.PONResourceManager
+
+ flow_id uint64
}
// NewResourceMgr init a New resource manager instance which in turn instantiates pon resource manager
@@ -54,7 +50,7 @@
// the resources.
func NewResourceMgr(deviceID string, KVStoreHostPort string, kvStoreType string, deviceType string, devInfo *openolt.DeviceInfo) *OpenOltResourceMgr {
var ResourceMgr OpenOltResourceMgr
- log.Debugf("Init new resource manager")
+ logger.Debugf(nil, "Init new resource manager")
ResourceMgr.deviceInfo = devInfo
NumPONPorts := devInfo.GetPonPorts()
@@ -118,16 +114,14 @@
// each technology is represented by only a single range
var GlobalPONRsrcMgr *ponrmgr.PONResourceManager
var err error
- IPPort := strings.Split(KVStoreHostPort, ":")
for _, TechRange := range devInfo.Ranges {
technology := TechRange.Technology
- log.Debugf("Device info technology %s", technology)
+ logger.Debugf(nil, "Device info technology %s", technology)
Ranges[technology] = TechRange
- port, _ := strconv.Atoi(IPPort[1])
- RsrcMgrsByTech[technology], err = ponrmgr.NewPONResourceManager(technology, deviceType, deviceID,
- kvStoreType, IPPort[0], port)
+ RsrcMgrsByTech[technology], err = ponrmgr.NewPONResourceManager(nil, technology, deviceType, deviceID,
+ kvStoreType, KVStoreHostPort)
if err != nil {
- log.Errorf("Failed to create pon resource manager instance for technology %s", technology)
+ logger.Errorf(nil, "Failed to create pon resource manager instance for technology %s", technology)
return nil
}
// resource_mgrs_by_tech[technology] = resource_mgr
@@ -146,7 +140,7 @@
for _, PONRMgr := range RsrcMgrsByTech {
_ = PONRMgr.InitDeviceResourcePool(context.Background())
}
- log.Info("Initialization of resource manager success!")
+ logger.Info(nil, "Initialization of resource manager success!")
return &ResourceMgr
}
@@ -159,11 +153,11 @@
// init the resource range pool according to the sharing type
- log.Debugf("Resource range pool init for technology %s", ponRMgr.Technology)
+ logger.Debugf(nil, "Resource range pool init for technology %s", ponRMgr.Technology)
// first load from KV profiles
status := ponRMgr.InitResourceRangesFromKVStore(context.Background())
if !status {
- log.Debugf("Failed to load resource ranges from KV store for tech %s", ponRMgr.Technology)
+ logger.Debugf(nil, "Failed to load resource ranges from KV store for tech %s", ponRMgr.Technology)
}
/*
@@ -171,7 +165,7 @@
or is broader than the device, the device's information will
dictate the range limits
*/
- log.Debugf("Using device info to init pon resource ranges for tech", ponRMgr.Technology)
+ logger.Debugf(nil, "Using device info to init pon resource ranges for tech", ponRMgr.Technology)
ONUIDStart := devInfo.OnuIdStart
ONUIDEnd := devInfo.OnuIdEnd
@@ -236,7 +230,7 @@
}
}
- log.Debugw("Device info init", log.Fields{"technology": techRange.Technology,
+ logger.Debugw(nil, "Device info init", log.Fields{"technology": techRange.Technology,
"onu_id_start": ONUIDStart, "onu_id_end": ONUIDEnd, "onu_id_shared_pool_id": ONUIDSharedPoolID,
"alloc_id_start": AllocIDStart, "alloc_id_end": AllocIDEnd,
"alloc_id_shared_pool_id": AllocIDSharedPoolID,
@@ -250,7 +244,7 @@
"uni_id_end_idx": 1, /*MaxUNIIDperONU()*/
})
- ponRMgr.InitDefaultPONResourceRanges(ONUIDStart, ONUIDEnd, ONUIDSharedPoolID,
+ ponRMgr.InitDefaultPONResourceRanges(nil, ONUIDStart, ONUIDEnd, ONUIDSharedPoolID,
AllocIDStart, AllocIDEnd, AllocIDSharedPoolID,
GEMPortIDStart, GEMPortIDEnd, GEMPortIDSharedPoolID,
FlowIDStart, FlowIDEnd, FlowIDSharedPoolID, 0, 1,
@@ -259,44 +253,44 @@
// For global sharing, make sure to refresh both local and global resource manager instances' range
if ONUIDShared == openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH {
- globalPONRMgr.UpdateRanges(ponrmgr.ONU_ID_START_IDX, ONUIDStart, ponrmgr.ONU_ID_END_IDX, ONUIDEnd,
+ globalPONRMgr.UpdateRanges(nil, ponrmgr.ONU_ID_START_IDX, ONUIDStart, ponrmgr.ONU_ID_END_IDX, ONUIDEnd,
"", 0, nil)
- ponRMgr.UpdateRanges(ponrmgr.ONU_ID_START_IDX, ONUIDStart, ponrmgr.ONU_ID_END_IDX, ONUIDEnd,
+ ponRMgr.UpdateRanges(nil, ponrmgr.ONU_ID_START_IDX, ONUIDStart, ponrmgr.ONU_ID_END_IDX, ONUIDEnd,
"", 0, globalPONRMgr)
}
if AllocIDShared == openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH {
- globalPONRMgr.UpdateRanges(ponrmgr.ALLOC_ID_START_IDX, AllocIDStart, ponrmgr.ALLOC_ID_END_IDX, AllocIDEnd,
+ globalPONRMgr.UpdateRanges(nil, ponrmgr.ALLOC_ID_START_IDX, AllocIDStart, ponrmgr.ALLOC_ID_END_IDX, AllocIDEnd,
"", 0, nil)
- ponRMgr.UpdateRanges(ponrmgr.ALLOC_ID_START_IDX, AllocIDStart, ponrmgr.ALLOC_ID_END_IDX, AllocIDEnd,
+ ponRMgr.UpdateRanges(nil, ponrmgr.ALLOC_ID_START_IDX, AllocIDStart, ponrmgr.ALLOC_ID_END_IDX, AllocIDEnd,
"", 0, globalPONRMgr)
}
if GEMPortIDShared == openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH {
- globalPONRMgr.UpdateRanges(ponrmgr.GEMPORT_ID_START_IDX, GEMPortIDStart, ponrmgr.GEMPORT_ID_END_IDX, GEMPortIDEnd,
+ globalPONRMgr.UpdateRanges(nil, ponrmgr.GEMPORT_ID_START_IDX, GEMPortIDStart, ponrmgr.GEMPORT_ID_END_IDX, GEMPortIDEnd,
"", 0, nil)
- ponRMgr.UpdateRanges(ponrmgr.GEMPORT_ID_START_IDX, GEMPortIDStart, ponrmgr.GEMPORT_ID_END_IDX, GEMPortIDEnd,
+ ponRMgr.UpdateRanges(nil, ponrmgr.GEMPORT_ID_START_IDX, GEMPortIDStart, ponrmgr.GEMPORT_ID_END_IDX, GEMPortIDEnd,
"", 0, globalPONRMgr)
}
if FlowIDShared == openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH {
- globalPONRMgr.UpdateRanges(ponrmgr.FLOW_ID_START_IDX, FlowIDStart, ponrmgr.FLOW_ID_END_IDX, FlowIDEnd,
+ globalPONRMgr.UpdateRanges(nil, ponrmgr.FLOW_ID_START_IDX, FlowIDStart, ponrmgr.FLOW_ID_END_IDX, FlowIDEnd,
"", 0, nil)
- ponRMgr.UpdateRanges(ponrmgr.FLOW_ID_START_IDX, FlowIDStart, ponrmgr.FLOW_ID_END_IDX, FlowIDEnd,
+ ponRMgr.UpdateRanges(nil, ponrmgr.FLOW_ID_START_IDX, FlowIDStart, ponrmgr.FLOW_ID_END_IDX, FlowIDEnd,
"", 0, globalPONRMgr)
}
// Make sure loaded range fits the platform bit encoding ranges
- ponRMgr.UpdateRanges(ponrmgr.UNI_ID_START_IDX, 0, ponrmgr.UNI_ID_END_IDX /* TODO =OpenOltPlatform.MAX_UNIS_PER_ONU-1*/, 1, "", 0, nil)
+ ponRMgr.UpdateRanges(nil, ponrmgr.UNI_ID_START_IDX, 0, ponrmgr.UNI_ID_END_IDX /* TODO =OpenOltPlatform.MAX_UNIS_PER_ONU-1*/, 1, "", 0, nil)
}
// Delete clears used resources for the particular olt device being deleted
func (RsrcMgr *OpenOltResourceMgr) Delete() error {
for _, rsrcMgr := range RsrcMgr.ResourceMgrs {
if err := rsrcMgr.ClearDeviceResourcePool(context.Background()); err != nil {
- log.Debug("Failed to clear device resource pool")
+ logger.Debug(nil, "Failed to clear device resource pool")
return err
}
}
- log.Debug("Cleared device resource pool")
+ logger.Debug(nil, "Cleared device resource pool")
return nil
}
@@ -308,7 +302,7 @@
ONUIDs, err := RsrcMgr.ResourceMgrs[ponIntfID].GetResourceID(context.Background(), ponIntfID,
ponrmgr.ONU_ID, 1)
if err != nil {
- log.Errorf("Failed to get resource for interface %d for type %s",
+ logger.Errorf(nil, "Failed to get resource for interface %d for type %s",
ponIntfID, ponrmgr.ONU_ID)
return uint32(0), err
}
@@ -316,15 +310,9 @@
}
// GetFlowID return flow ID for a given pon interface id, onu id and uni id
-func (RsrcMgr *OpenOltResourceMgr) GetFlowID(ctx context.Context, ponIntfID uint32) (uint32, error) {
+func (RsrcMgr *OpenOltResourceMgr) GetFlowID(ctx context.Context, ponIntfID uint32) (uint64, error) {
RsrcMgr.FlowIDMgmtLock.Lock()
defer RsrcMgr.FlowIDMgmtLock.Unlock()
- FlowIDs, err := RsrcMgr.ResourceMgrs[ponIntfID].GetResourceID(context.Background(), ponIntfID,
- ponrmgr.FLOW_ID, 1)
- if err != nil {
- log.Errorf("Failed to get resource for interface %d for type %s",
- ponIntfID, ponrmgr.FLOW_ID)
- return uint32(0), err
- }
- return FlowIDs[0], err
+ RsrcMgr.flow_id++
+ return RsrcMgr.flow_id, nil
}