xAdded lock around the use of OnuOmciStateMap to prevent a concurrent map write issue.
I considered using a structure like sync.Map or other concurrency safe map, but those don't offer type safety like the built in map object.
Added some missing licensing and a VERSION file as Jenkins is requiring it.
Change-Id: I755709ab4678da12c7585824074a1877f98a5ea1
diff --git a/VERSION b/VERSION
new file mode 100644
index 0000000..c0ab82c
--- /dev/null
+++ b/VERSION
@@ -0,0 +1 @@
+0.0.1-dev
diff --git a/omci_anig.go b/omci_anig.go
index 99ebca7..49734a7 100644
--- a/omci_anig.go
+++ b/omci_anig.go
@@ -1,3 +1,19 @@
+/*
+ * 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 core
type AniGAttributes int
@@ -165,4 +181,4 @@
pkt[*pos] = 0x81
*pos++
return pkt, nil
-}
\ No newline at end of file
+}
diff --git a/omci_handlers.go b/omci_handlers.go
index c766c1a..67a57e7 100644
--- a/omci_handlers.go
+++ b/omci_handlers.go
@@ -46,6 +46,7 @@
"IntfId": key.IntfId,
"OnuId": key.OnuId,
}).Tracef("Omci MibReset")
+ OnuOmciStateMapLock.RLock()
if state, ok := OnuOmciStateMap[key]; ok {
log.WithFields(log.Fields{
"IntfId": key.IntfId,
@@ -53,6 +54,7 @@
}).Tracef("Reseting OnuOmciState")
state.ResetOnuOmciState()
}
+ OnuOmciStateMapLock.RUnlock()
pkt = []byte{
0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
@@ -88,9 +90,9 @@
func mibUploadNext(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) {
var pkt []byte
-
+ OnuOmciStateMapLock.RLock()
state := OnuOmciStateMap[key]
-
+ OnuOmciStateMapLock.RUnlock()
// commandNumber is the "Command number" attribute received in "MIB Upload Next" OMCI message
commandNumber := (uint16(content[1])) | (uint16(content[0])<<8)
log.WithFields(log.Fields{
@@ -407,6 +409,8 @@
var pkt []byte
if class == GEMPortNetworkCTP {
+ OnuOmciStateMapLock.RLock()
+ defer OnuOmciStateMapLock.RUnlock()
if onuOmciState, ok := OnuOmciStateMap[key]; !ok {
log.WithFields(log.Fields{
"IntfId": key.IntfId,
diff --git a/omci_pm_history_data.go b/omci_pm_history_data.go
index 15188fa..60ddd80 100644
--- a/omci_pm_history_data.go
+++ b/omci_pm_history_data.go
@@ -1,3 +1,19 @@
+/*
+ * 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 core
type PerformanceMonitoringHistoryData int
diff --git a/omci_sim.go b/omci_sim.go
index 6cc0708..a792911 100644
--- a/omci_sim.go
+++ b/omci_sim.go
@@ -51,9 +51,11 @@
}).Tracef("Processing OMCI pakcet")
key := OnuKey{intfId, onuId}
+ OnuOmciStateMapLock.Lock()
if _, ok := OnuOmciStateMap[key]; !ok {
OnuOmciStateMap[key] = NewOnuOmciState()
}
+ OnuOmciStateMapLock.Unlock()
if _, ok := Handlers[msgType]; !ok {
log.WithFields(log.Fields{
@@ -111,4 +113,4 @@
}).Tracef("OMCI-SIM Response")
return resp, nil
-}
\ No newline at end of file
+}
diff --git a/omci_state.go b/omci_state.go
index 34d5b5e..eb923ba 100644
--- a/omci_state.go
+++ b/omci_state.go
@@ -18,6 +18,7 @@
import (
"errors"
"fmt"
+ "sync"
log "github.com/sirupsen/logrus"
)
@@ -43,6 +44,7 @@
)
var OnuOmciStateMap = map[OnuKey]*OnuOmciState{}
+var OnuOmciStateMapLock = sync.RWMutex{}
func NewOnuOmciState() *OnuOmciState {
return &OnuOmciState{gemPortId: 0, mibUploadCtr: 0, uniGInstance: 1, tcontInstance: 0, pptpInstance: 1}
@@ -60,6 +62,8 @@
}
func GetOnuOmciState(intfId uint32, onuId uint32) istate {
key := OnuKey{intfId, onuId}
+ OnuOmciStateMapLock.RLock()
+ defer OnuOmciStateMapLock.RUnlock()
if onu, ok := OnuOmciStateMap[key]; ok {
return onu.state
} else {
@@ -69,6 +73,8 @@
func GetGemPortId(intfId uint32, onuId uint32) (uint16, error) {
key := OnuKey{intfId, onuId}
+ OnuOmciStateMapLock.RLock()
+ defer OnuOmciStateMapLock.RUnlock()
if OnuOmciState, ok := OnuOmciStateMap[key]; ok {
if OnuOmciState.state != DONE {
errmsg := fmt.Sprintf("ONU {intfid:%d, onuid:%d} - Not DONE (GemportID is not set)", intfId, onuId)