blob: a6d24fb2acb988baecad40599237c0f1f9c0d6ff [file] [log] [blame]
Matteo Scandoloa4285862020-12-01 18:10:10 -08001/*
2 * Copyright 2018-present Open Networking Foundation
3
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7
8 * http://www.apache.org/licenses/LICENSE-2.0
9
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package core
18
19import (
20 "context"
21 "fmt"
22 "github.com/opencord/voltha-lib-go/v4/pkg/log"
23 "sync"
24)
25
26type Store struct {
27 olts sync.Map
28 onus sync.Map
29 bps sync.Map
30}
31
32func NewStore() *Store {
33 return &Store{
34 olts: sync.Map{},
35 onus: sync.Map{},
36 bps: sync.Map{},
37 }
38}
39
40func (s *Store) addOlt(ctx context.Context, entry SadisOltEntry) {
41 logger.Debugw(ctx, "adding-olt", log.Fields{"olt": entry})
42 s.olts.Store(entry.ID, entry)
43}
44
45func (s *Store) addOnu(ctx context.Context, entry SadisOnuEntryV2) {
46 logger.Debugw(ctx, "adding-onu", log.Fields{"onu": entry})
47 s.onus.Store(entry.ID, entry)
48}
49
50func (s *Store) addBp(ctx context.Context, entry SadisBWPEntry) {
51 logger.Debugw(ctx, "adding-bp", log.Fields{"bp": entry})
52 s.bps.Store(entry.ID, entry)
53}
54
55func (s *Store) getOlt(ctx context.Context, id string) (*SadisOltEntry, error) {
56 logger.Debugw(ctx, "getting-olt", log.Fields{"olt": id})
57 if entry, ok := s.olts.Load(id); ok {
58 e := entry.(SadisOltEntry)
59 return &e, nil
60 }
61 return nil, fmt.Errorf("olt-not-found-in-store")
62}
63
64func (s *Store) getOnu(ctx context.Context, id string) (*SadisOnuEntryV2, error) {
65 logger.Debugw(ctx, "getting-onu", log.Fields{"onu": id})
66 if entry, ok := s.onus.Load(id); ok {
67 e := entry.(SadisOnuEntryV2)
68 return &e, nil
69 }
70 return nil, fmt.Errorf("onu-not-found-in-store")
71}
72
73func (s *Store) getBp(ctx context.Context, id string) (*SadisBWPEntry, error) {
74 logger.Debugw(ctx, "getting-bp", log.Fields{"bp": id})
75 if entry, ok := s.bps.Load(id); ok {
76 e := entry.(SadisBWPEntry)
77 return &e, nil
78 }
79 return nil, fmt.Errorf("bp-not-found-in-store")
80}