[VOL-2848] : Protect concurrent access for PON resources
Flows currently were serialized on a per ONU basis. However flows
from different ONUs could add/remove concurrently. This meant
possible concurrent access of PON resources. In some tests it was
seen that two ONUs got same resource (like FlowID) and traffic
would fail.
This new change makes concurrent access to get/put/delete on shared PON resource pools
on KV store protected by locks. The adapter maintains certain data on
the KV store on a per ONU basis and this does not need any protection
as the key path are unique and provide inherant protection and moreover
any flow operation on a given ONU is serialized, this is not to worry.
Change-Id: I8a452a7ae84413741cbc2fa24ae42f4329748e32
(cherry picked from commit 38d533d9e90cd72e47ea4460f021694c7937281f)
diff --git a/internal/pkg/core/device_handler_test.go b/internal/pkg/core/device_handler_test.go
index 5f5ce2a..4db1b93 100644
--- a/internal/pkg/core/device_handler_test.go
+++ b/internal/pkg/core/device_handler_test.go
@@ -149,11 +149,22 @@
ep := &mocks.MockEventProxy{}
openOLT := &OpenOLT{coreProxy: cp, adapterProxy: ap, eventProxy: ep}
dh := NewDeviceHandler(cp, ap, ep, device, openOLT)
- deviceInf := &oop.DeviceInfo{Vendor: "openolt", Ranges: nil, Model: "openolt", DeviceId: dh.deviceID}
- dh.resourceMgr = &resourcemanager.OpenOltResourceMgr{DeviceID: dh.deviceID, DeviceType: dh.deviceType, DevInfo: deviceInf,
+ oopRanges := []*oop.DeviceInfo_DeviceResourceRanges{{
+ IntfIds: []uint32{0, 1},
+ Technology: "xgs-pon",
+ Pools: []*oop.DeviceInfo_DeviceResourceRanges_Pool{{}},
+ }}
+
+ deviceInf := &oop.DeviceInfo{Vendor: "openolt", Ranges: oopRanges, Model: "openolt", DeviceId: dh.deviceID, PonPorts: 2}
+ rsrMgr := resourcemanager.OpenOltResourceMgr{DeviceID: dh.deviceID, DeviceType: dh.deviceType, DevInfo: deviceInf,
KVStore: &db.Backend{
Client: &mocks.MockKVClient{},
}}
+ rsrMgr.AllocIDMgmtLock = make([]sync.RWMutex, deviceInf.PonPorts)
+ rsrMgr.GemPortIDMgmtLock = make([]sync.RWMutex, deviceInf.PonPorts)
+ rsrMgr.OnuIDMgmtLock = make([]sync.RWMutex, deviceInf.PonPorts)
+
+ dh.resourceMgr = &rsrMgr
dh.resourceMgr.ResourceMgrs = make(map[uint32]*ponrmgr.PONResourceManager)
ranges := make(map[string]interface{})
sharedIdxByType := make(map[string]string)
@@ -172,15 +183,15 @@
ponmgr := &ponrmgr.PONResourceManager{
DeviceID: "onu-1",
- IntfIDs: []uint32{1, 2},
+ IntfIDs: []uint32{0, 1},
KVStore: &db.Backend{
Client: &mocks.MockKVClient{},
},
PonResourceRanges: ranges,
SharedIdxByType: sharedIdxByType,
}
+ dh.resourceMgr.ResourceMgrs[0] = ponmgr
dh.resourceMgr.ResourceMgrs[1] = ponmgr
- dh.resourceMgr.ResourceMgrs[2] = ponmgr
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
dh.flowMgr = NewFlowManager(ctx, dh, dh.resourceMgr)
@@ -864,10 +875,10 @@
devicehandler *DeviceHandler
args args
}{
- {"activateONU-1", dh, args{intfID: 1, onuID: 1, serialNum: &oop.SerialNumber{VendorId: []byte("onu1")}}},
- {"activateONU-2", dh, args{intfID: 2, onuID: 2, serialNum: &oop.SerialNumber{VendorId: []byte("onu2")}}},
- {"activateONU-3", dh1, args{intfID: 1, onuID: 1, serialNum: &oop.SerialNumber{VendorId: []byte("onu1")}}},
- {"activateONU-4", dh1, args{intfID: 2, onuID: 2, serialNum: &oop.SerialNumber{VendorId: []byte("onu2")}}},
+ {"activateONU-1", dh, args{intfID: 0, onuID: 1, serialNum: &oop.SerialNumber{VendorId: []byte("onu1")}}},
+ {"activateONU-2", dh, args{intfID: 1, onuID: 2, serialNum: &oop.SerialNumber{VendorId: []byte("onu2")}}},
+ {"activateONU-3", dh1, args{intfID: 0, onuID: 1, serialNum: &oop.SerialNumber{VendorId: []byte("onu1")}}},
+ {"activateONU-4", dh1, args{intfID: 1, onuID: 2, serialNum: &oop.SerialNumber{VendorId: []byte("onu2")}}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {