[VOL-4756] Cleanup TODO context
Change-Id: I21d5ec8cc015154bc893e54c652d31562d8da5d9
diff --git a/database/database.go b/database/database.go
index fe88556..0344e7d 100644
--- a/database/database.go
+++ b/database/database.go
@@ -33,7 +33,6 @@
)
var logger log.CLogger
-var ctx = context.TODO()
// Database structure
type Database struct {
@@ -45,7 +44,7 @@
// Initialize the database module. The database module runs as a singleton
// object and is initialized when the adapter is created.
-func Initialize(storeType string, address string, timeout int) (*Database, error) {
+func Initialize(ctx context.Context, storeType string, address string, timeout int) (*Database, error) {
var err error
var database Database
logger.Infow(ctx, "kv-store-type", log.Fields{"store": storeType})
@@ -64,13 +63,13 @@
// as a string
// Put to add value to database
-func (db *Database) Put(fullKeyPath, value string) error {
- return db.kvc.Put(context.Background(), fullKeyPath, value)
+func (db *Database) Put(ctx context.Context, fullKeyPath, value string) error {
+ return db.kvc.Put(ctx, fullKeyPath, value)
}
// Get to retrieve value from database
-func (db *Database) Get(key string) (string, error) {
- kv, err := db.kvc.Get(context.Background(), key)
+func (db *Database) Get(ctx context.Context, key string) (string, error) {
+ kv, err := db.kvc.Get(ctx, key)
if err != nil {
return "", err
}
@@ -81,8 +80,8 @@
}
// Del to delete value from database
-func (db *Database) Del(fullPath string) error {
- if err := db.kvc.Delete(context.Background(), fullPath); err != nil {
+func (db *Database) Del(ctx context.Context, fullPath string) error {
+ if err := db.kvc.Delete(ctx, fullPath); err != nil {
logger.Errorw(ctx, "The path doesn't exist", log.Fields{"key": fullPath, "Error": err})
return err
}
@@ -90,8 +89,8 @@
}
// DeleteAll to delete all value from database
-func (db *Database) DeleteAll(fullPath string) error {
- if err := db.kvc.DeleteWithPrefix(context.Background(), fullPath); err != nil {
+func (db *Database) DeleteAll(ctx context.Context, fullPath string) error {
+ if err := db.kvc.DeleteWithPrefix(ctx, fullPath); err != nil {
logger.Errorw(ctx, "The key doesn't exist", log.Fields{"key": fullPath, "Error": err})
return err
}
@@ -99,8 +98,8 @@
}
// DeleteAllUnderHashKey to delete all values under hash key
-func (db *Database) DeleteAllUnderHashKey(hashKeyPrefix string) error {
- if err := db.kvc.Delete(context.Background(), hashKeyPrefix); err != nil {
+func (db *Database) DeleteAllUnderHashKey(ctx context.Context, hashKeyPrefix string) error {
+ if err := db.kvc.Delete(ctx, hashKeyPrefix); err != nil {
logger.Errorw(ctx, "The key path doesn't exist", log.Fields{"key": hashKeyPrefix, "Error": err})
return err
}
@@ -108,8 +107,8 @@
}
// List to list the values
-func (db *Database) List(key string) (map[string]*kvstore.KVPair, error) {
- kv, err := db.kvc.List(context.Background(), key)
+func (db *Database) List(ctx context.Context, key string) (map[string]*kvstore.KVPair, error) {
+ kv, err := db.kvc.List(ctx, key)
if err != nil {
return nil, err
}
@@ -122,21 +121,21 @@
// OLT specific database items
// GetOlt to get olt info
-func (db *Database) GetOlt(deviceID string) (string, error) {
+func (db *Database) GetOlt(ctx context.Context, deviceID string) (string, error) {
key := fmt.Sprintf(GetKeyPath(DevicePath), deviceID)
- return db.Get(key)
+ return db.Get(ctx, key)
}
// PutOlt to add olt info
-func (db *Database) PutOlt(deviceID string, value string) error {
+func (db *Database) PutOlt(ctx context.Context, deviceID string, value string) error {
key := fmt.Sprintf(GetKeyPath(DevicePath), deviceID)
- return db.kvc.Put(context.Background(), key, value)
+ return db.kvc.Put(ctx, key, value)
}
// DelOlt to delete olt info
-func (db *Database) DelOlt(deviceID string) error {
+func (db *Database) DelOlt(ctx context.Context, deviceID string) error {
key := fmt.Sprintf(GetKeyPath(DevicePath), deviceID)
- if err := db.kvc.Delete(context.Background(), key); err != nil {
+ if err := db.kvc.Delete(ctx, key); err != nil {
logger.Errorw(ctx, "The key doesn't exist", log.Fields{"key": key, "Error": err})
return err
}
@@ -146,27 +145,27 @@
// Flows specific database actions
// PutFlow to add flow
-func (db *Database) PutFlow(deviceID string, flowID uint64, value string) error {
+func (db *Database) PutFlow(ctx context.Context, deviceID string, flowID uint64, value string) error {
key := fmt.Sprintf(GetKeyPath(DeviceFlowPath), deviceID) + strconv.FormatUint(flowID, 10)
- return db.kvc.Put(context.Background(), key, value)
+ return db.kvc.Put(ctx, key, value)
}
// GetFlow to get flow
-func (db *Database) GetFlow(deviceID string, flowID uint64) (string, error) {
+func (db *Database) GetFlow(ctx context.Context, deviceID string, flowID uint64) (string, error) {
key := fmt.Sprintf(GetKeyPath(DeviceFlowPath), deviceID) + strconv.FormatUint(flowID, 10)
- return db.Get(key)
+ return db.Get(ctx, key)
}
// GetFlows to get multiple flows
-func (db *Database) GetFlows(deviceID string) (map[string]*kvstore.KVPair, error) {
+func (db *Database) GetFlows(ctx context.Context, deviceID string) (map[string]*kvstore.KVPair, error) {
key := fmt.Sprintf(GetKeyPath(DeviceFlowPath), deviceID)
- return db.List(key)
+ return db.List(ctx, key)
}
// DelFlow to delete flow
-func (db *Database) DelFlow(deviceID string, flowID uint64) error {
+func (db *Database) DelFlow(ctx context.Context, deviceID string, flowID uint64) error {
key := fmt.Sprintf(GetKeyPath(DeviceFlowPath), deviceID) + strconv.FormatUint(flowID, 10)
- if err := db.kvc.Delete(context.Background(), key); err != nil {
+ if err := db.kvc.Delete(ctx, key); err != nil {
logger.Errorw(ctx, "The key doesn't exist", log.Fields{"key": key, "Error": err})
return err
}
@@ -176,28 +175,28 @@
// Group specific database actions
// PutGroup to add group info
-func (db *Database) PutGroup(deviceID string, groupID uint32, value string) error {
+func (db *Database) PutGroup(ctx context.Context, deviceID string, groupID uint32, value string) error {
key := fmt.Sprintf(GetKeyPath(DeviceGroupPath), deviceID) + strconv.FormatUint(uint64(groupID), 10)
- return db.kvc.Put(context.Background(), key, value)
+ return db.kvc.Put(ctx, key, value)
}
// GetGroup to get group info
-func (db *Database) GetGroup(deviceID string, groupID uint32) (string, error) {
+func (db *Database) GetGroup(ctx context.Context, deviceID string, groupID uint32) (string, error) {
key := fmt.Sprintf(GetKeyPath(DeviceGroupPath), deviceID) + strconv.FormatUint(uint64(groupID), 10)
- return db.Get(key)
+ return db.Get(ctx, key)
}
// GetGroups to get multiple group info
-func (db *Database) GetGroups(deviceID string) (map[string]*kvstore.KVPair, error) {
+func (db *Database) GetGroups(ctx context.Context, deviceID string) (map[string]*kvstore.KVPair, error) {
key := fmt.Sprintf(GetKeyPath(DeviceGroupPath), deviceID)
logger.Infow(ctx, "key", log.Fields{"Key": key})
- return db.List(key)
+ return db.List(ctx, key)
}
// DelGroup to delete group info
-func (db *Database) DelGroup(deviceID string, groupID uint32) error {
+func (db *Database) DelGroup(ctx context.Context, deviceID string, groupID uint32) error {
key := fmt.Sprintf(GetKeyPath(DeviceGroupPath), deviceID) + strconv.FormatUint(uint64(groupID), 10)
- if err := db.kvc.Delete(context.Background(), key); err != nil {
+ if err := db.kvc.Delete(ctx, key); err != nil {
logger.Errorw(ctx, "The key doesn't exist", log.Fields{"key": key, "Error": err})
return err
}
@@ -205,9 +204,9 @@
}
// DelAllGroup to delete all group info
-func (db *Database) DelAllGroup(deviceID string) error {
+func (db *Database) DelAllGroup(ctx context.Context, deviceID string) error {
key := fmt.Sprintf(GetKeyPath(DeviceGroupPath), deviceID)
- if err := db.DeleteAllUnderHashKey(key); err != nil {
+ if err := db.DeleteAllUnderHashKey(ctx, key); err != nil {
logger.Warnw(ctx, "Delete All failed: The key doesn't exist", log.Fields{"key": key, "Error": err})
return err
}
@@ -216,9 +215,9 @@
}
// DelAllPorts to delete all ports info
-func (db *Database) DelAllPorts(device string) error {
+func (db *Database) DelAllPorts(ctx context.Context, device string) error {
key := fmt.Sprintf(GetKeyPath(DevicePortPath), device)
- if err := db.DeleteAllUnderHashKey(key); err != nil {
+ if err := db.DeleteAllUnderHashKey(ctx, key); err != nil {
logger.Warnw(ctx, "Delete All failed: The key doesn't exist", log.Fields{"key": key, "Error": err})
return err
}
@@ -229,27 +228,27 @@
// Ports specific database actions
// PutPort to add port info
-func (db *Database) PutPort(deviceID string, portID uint32, value string) error {
+func (db *Database) PutPort(ctx context.Context, deviceID string, portID uint32, value string) error {
key := fmt.Sprintf(GetKeyPath(DevicePortPath), deviceID) + strconv.FormatUint(uint64(portID), 10)
- return db.kvc.Put(context.Background(), key, value)
+ return db.kvc.Put(ctx, key, value)
}
// GetPort to get port info
-func (db *Database) GetPort(deviceID string, portID uint32) (string, error) {
+func (db *Database) GetPort(ctx context.Context, deviceID string, portID uint32) (string, error) {
key := fmt.Sprintf(GetKeyPath(DevicePortPath), deviceID) + strconv.FormatUint(uint64(portID), 10)
- return db.Get(key)
+ return db.Get(ctx, key)
}
// GetPorts to get multiple ports info
-func (db *Database) GetPorts(deviceID string) (map[string]*kvstore.KVPair, error) {
+func (db *Database) GetPorts(ctx context.Context, deviceID string) (map[string]*kvstore.KVPair, error) {
key := fmt.Sprintf(GetKeyPath(DevicePortPath), deviceID)
- return db.List(key)
+ return db.List(ctx, key)
}
// DelPort to delete port info
-func (db *Database) DelPort(deviceID string, portID uint32) error {
+func (db *Database) DelPort(ctx context.Context, deviceID string, portID uint32) error {
key := fmt.Sprintf(GetKeyPath(DevicePortPath), deviceID) + strconv.FormatUint(uint64(portID), 10)
- if err := db.kvc.Delete(context.Background(), key); err != nil {
+ if err := db.kvc.Delete(ctx, key); err != nil {
logger.Errorw(ctx, "The key doesn't exist", log.Fields{"key": key, "Error": err})
return err
}
@@ -259,27 +258,27 @@
// Device meter specific database actions
// PutDeviceMeter to add device meter info
-func (db *Database) PutDeviceMeter(deviceID string, meterID uint32, value string) error {
+func (db *Database) PutDeviceMeter(ctx context.Context, deviceID string, meterID uint32, value string) error {
key := fmt.Sprintf(GetKeyPath(DeviceMeterPath), deviceID) + strconv.FormatUint(uint64(meterID), 10)
- return db.kvc.Put(context.Background(), key, value)
+ return db.kvc.Put(ctx, key, value)
}
// GetDeviceMeter to get device meter info
-func (db *Database) GetDeviceMeter(deviceID string, meterID uint32) (string, error) {
+func (db *Database) GetDeviceMeter(ctx context.Context, deviceID string, meterID uint32) (string, error) {
key := fmt.Sprintf(GetKeyPath(DeviceMeterPath), deviceID) + strconv.FormatUint(uint64(meterID), 10)
- return db.Get(key)
+ return db.Get(ctx, key)
}
// GetDeviceMeters to get multiple device meter info
-func (db *Database) GetDeviceMeters(deviceID string) (map[string]*kvstore.KVPair, error) {
+func (db *Database) GetDeviceMeters(ctx context.Context, deviceID string) (map[string]*kvstore.KVPair, error) {
key := fmt.Sprintf(GetKeyPath(DeviceMeterPath), deviceID)
- return db.List(key)
+ return db.List(ctx, key)
}
// DelDeviceMeter to delete device meter info
-func (db *Database) DelDeviceMeter(deviceID string, meterID uint32) error {
+func (db *Database) DelDeviceMeter(ctx context.Context, deviceID string, meterID uint32) error {
key := fmt.Sprintf(GetKeyPath(DeviceMeterPath), deviceID) + strconv.FormatUint(uint64(meterID), 10)
- if err := db.kvc.Delete(context.Background(), key); err != nil {
+ if err := db.kvc.Delete(ctx, key); err != nil {
logger.Errorw(ctx, "The key doesn't exist", log.Fields{"key": key, "Error": err})
return err
}
@@ -289,27 +288,27 @@
// Service specific database actions
// GetServices to get multiple services info
-func (db *Database) GetServices() (map[string]*kvstore.KVPair, error) {
+func (db *Database) GetServices(ctx context.Context) (map[string]*kvstore.KVPair, error) {
key := GetKeyPath(ServicePath)
- return db.List(key)
+ return db.List(ctx, key)
}
// GetService to get service info
-func (db *Database) GetService(name string) (string, error) {
+func (db *Database) GetService(ctx context.Context, name string) (string, error) {
key := GetKeyPath(ServicePath) + name
- return db.Get(key)
+ return db.Get(ctx, key)
}
// PutService to add service info
-func (db *Database) PutService(name string, value string) error {
+func (db *Database) PutService(ctx context.Context, name string, value string) error {
key := GetKeyPath(ServicePath) + name
- return db.kvc.Put(context.Background(), key, value)
+ return db.kvc.Put(ctx, key, value)
}
// DelService to delete service info
-func (db *Database) DelService(name string) error {
+func (db *Database) DelService(ctx context.Context, name string) error {
key := GetKeyPath(ServicePath) + name
- if err := db.kvc.Delete(context.Background(), key); err != nil {
+ if err := db.kvc.Delete(ctx, key); err != nil {
logger.Errorw(ctx, "The key doesn't exist", log.Fields{"key": key, "Error": err})
return err
}
@@ -319,27 +318,27 @@
// Virtual networks specific database actions
// GetVnets to get multiple vnets info
-func (db *Database) GetVnets() (map[string]*kvstore.KVPair, error) {
+func (db *Database) GetVnets(ctx context.Context) (map[string]*kvstore.KVPair, error) {
key := GetKeyPath(VnetPath)
- return db.List(key)
+ return db.List(ctx, key)
}
// GetVnet to get vnet info
-func (db *Database) GetVnet(name string) (string, error) {
+func (db *Database) GetVnet(ctx context.Context, name string) (string, error) {
key := GetKeyPath(VnetPath) + name
- return db.Get(key)
+ return db.Get(ctx, key)
}
// PutVnet to add vnet info
-func (db *Database) PutVnet(name string, value string) error {
+func (db *Database) PutVnet(ctx context.Context, name string, value string) error {
key := GetKeyPath(VnetPath) + name
- return db.kvc.Put(context.Background(), key, value)
+ return db.kvc.Put(ctx, key, value)
}
// DelVnet to delete vnet info
-func (db *Database) DelVnet(name string) error {
+func (db *Database) DelVnet(ctx context.Context, name string) error {
key := GetKeyPath(VnetPath) + name
- if err := db.kvc.Delete(context.Background(), key); err != nil {
+ if err := db.kvc.Delete(ctx, key); err != nil {
logger.Errorw(ctx, "The key doesn't exist", log.Fields{"key": key, "Error": err})
return err
}
@@ -349,30 +348,30 @@
// Virtual networks on ports specific database actions
// GetVpvs to get multiple vpvs info
-func (db *Database) GetVpvs() (map[string]*kvstore.KVPair, error) {
+func (db *Database) GetVpvs(ctx context.Context) (map[string]*kvstore.KVPair, error) {
key := GetKeyPath(VpvPath)
- return db.List(key)
+ return db.List(ctx, key)
}
// GetVpv to get vpv info
-func (db *Database) GetVpv(port string, SVlan uint16, CVlan uint16, UniVlan uint16) (string, error) {
+func (db *Database) GetVpv(ctx context.Context, port string, SVlan uint16, CVlan uint16, UniVlan uint16) (string, error) {
name := port + fmt.Sprintf("-%v-%v-%v", SVlan, CVlan, UniVlan)
key := GetKeyPath(VpvPath) + name
- return db.Get(key)
+ return db.Get(ctx, key)
}
// PutVpv to add vpv info
-func (db *Database) PutVpv(port string, SVlan uint16, CVlan uint16, UniVlan uint16, value string) error {
+func (db *Database) PutVpv(ctx context.Context, port string, SVlan uint16, CVlan uint16, UniVlan uint16, value string) error {
name := port + fmt.Sprintf("-%v-%v-%v", SVlan, CVlan, UniVlan)
key := GetKeyPath(VpvPath) + name
- return db.kvc.Put(context.Background(), key, value)
+ return db.kvc.Put(ctx, key, value)
}
// DelVpv to delete vpv info
-func (db *Database) DelVpv(port string, SVlan uint16, CVlan uint16, UniVlan uint16) error {
+func (db *Database) DelVpv(ctx context.Context, port string, SVlan uint16, CVlan uint16, UniVlan uint16) error {
name := port + fmt.Sprintf("-%v-%v-%v", SVlan, CVlan, UniVlan)
key := GetKeyPath(VpvPath) + name
- if err := db.kvc.Delete(context.Background(), key); err != nil {
+ if err := db.kvc.Delete(ctx, key); err != nil {
logger.Errorw(ctx, "The key doesn't exist", log.Fields{"key": key, "Error": err})
return err
}
@@ -382,30 +381,30 @@
// Virtual networks on ports specific database actions
// GetMvlans to get multiple mvlans info
-func (db *Database) GetMvlans() (map[string]*kvstore.KVPair, error) {
+func (db *Database) GetMvlans(ctx context.Context) (map[string]*kvstore.KVPair, error) {
key := GetKeyPath(MvlanPath)
- return db.List(key)
+ return db.List(ctx, key)
}
// GetMvlan to get mvlan info
-func (db *Database) GetMvlan(mvlan uint16) (string, error) {
+func (db *Database) GetMvlan(ctx context.Context, mvlan uint16) (string, error) {
name := strconv.FormatInt(int64(mvlan), 10)
key := GetKeyPath(MvlanPath) + name
- return db.Get(key)
+ return db.Get(ctx, key)
}
// PutMvlan to add mvlan info
-func (db *Database) PutMvlan(mvlan uint16, value string) error {
+func (db *Database) PutMvlan(ctx context.Context, mvlan uint16, value string) error {
name := strconv.FormatInt(int64(mvlan), 10)
key := GetKeyPath(MvlanPath) + name
- return db.kvc.Put(context.Background(), key, value)
+ return db.kvc.Put(ctx, key, value)
}
// DelMvlan to delete mvlan info
-func (db *Database) DelMvlan(mvlan uint16) error {
+func (db *Database) DelMvlan(ctx context.Context, mvlan uint16) error {
name := strconv.FormatInt(int64(mvlan), 10)
key := GetKeyPath(MvlanPath) + name
- if err := db.kvc.Delete(context.Background(), key); err != nil {
+ if err := db.kvc.Delete(ctx, key); err != nil {
logger.Errorw(ctx, "The key doesn't exist", log.Fields{"key": key, "Error": err})
return err
}
@@ -415,9 +414,9 @@
// database specific actions on IGMP config
// DelIGMPCfg to delete icmp config
-func (db *Database) DelIGMPCfg() error {
+func (db *Database) DelIGMPCfg(ctx context.Context) error {
key := GetKeyPath(IgmpConfPath)
- if err := db.kvc.Delete(context.Background(), key); err != nil {
+ if err := db.kvc.Delete(ctx, key); err != nil {
logger.Errorw(ctx, "The key doesn't exist", log.Fields{"key": key, "Error": err})
return err
}
@@ -427,27 +426,27 @@
// database specific actions on IGMP Profile
// GetIgmpProfiles to get multiple igmp profile info
-func (db *Database) GetIgmpProfiles() (map[string]*kvstore.KVPair, error) {
+func (db *Database) GetIgmpProfiles(ctx context.Context) (map[string]*kvstore.KVPair, error) {
key := GetKeyPath(IgmpProfPath)
- return db.List(key)
+ return db.List(ctx, key)
}
// GetIgmpProfile to get igmp profile info
-func (db *Database) GetIgmpProfile(name string) (string, error) {
+func (db *Database) GetIgmpProfile(ctx context.Context, name string) (string, error) {
key := GetKeyPath(IgmpProfPath) + name
- return db.Get(key)
+ return db.Get(ctx, key)
}
// PutIgmpProfile to put igmp profile info
-func (db *Database) PutIgmpProfile(name string, value string) error {
+func (db *Database) PutIgmpProfile(ctx context.Context, name string, value string) error {
key := GetKeyPath(IgmpProfPath) + name
- return db.kvc.Put(context.Background(), key, value)
+ return db.kvc.Put(ctx, key, value)
}
// DelIgmpProfile to delete igmp profile
-func (db *Database) DelIgmpProfile(name string) error {
+func (db *Database) DelIgmpProfile(ctx context.Context, name string) error {
key := GetKeyPath(IgmpProfPath) + name
- if err := db.kvc.Delete(context.Background(), key); err != nil {
+ if err := db.kvc.Delete(ctx, key); err != nil {
logger.Errorw(ctx, "The key doesn't exist", log.Fields{"key": key, "Error": err})
return err
}
@@ -457,27 +456,27 @@
// database specific actions on Mcast config Info
// GetMcastConfigs to get multiple mcast config info
-func (db *Database) GetMcastConfigs() (map[string]*kvstore.KVPair, error) {
+func (db *Database) GetMcastConfigs(ctx context.Context) (map[string]*kvstore.KVPair, error) {
key := GetKeyPath(McastConfigPath)
- return db.List(key)
+ return db.List(ctx, key)
}
// GetMcastConfig to get igmp profile info
-func (db *Database) GetMcastConfig(name string) (string, error) {
+func (db *Database) GetMcastConfig(ctx context.Context, name string) (string, error) {
key := GetKeyPath(McastConfigPath) + name
- return db.Get(key)
+ return db.Get(ctx, key)
}
// PutMcastConfig to put igmp profile info
-func (db *Database) PutMcastConfig(name string, value string) error {
+func (db *Database) PutMcastConfig(ctx context.Context, name string, value string) error {
key := GetKeyPath(McastConfigPath) + name
- return db.kvc.Put(context.Background(), key, value)
+ return db.kvc.Put(ctx, key, value)
}
// DelMcastConfig to delete igmp profile
-func (db *Database) DelMcastConfig(name string) error {
+func (db *Database) DelMcastConfig(ctx context.Context, name string) error {
key := GetKeyPath(McastConfigPath) + name
- if err := db.kvc.Delete(context.Background(), key); err != nil {
+ if err := db.kvc.Delete(ctx, key); err != nil {
logger.Errorw(ctx, "The key doesn't exist", log.Fields{"key": key, "Error": err})
return err
}
@@ -487,21 +486,21 @@
// database specific actions on health
// GetHealth to get health info
-func (db *Database) GetHealth() (string, error) {
+func (db *Database) GetHealth(ctx context.Context) (string, error) {
key := GetKeyPath(HealthPath)
- return db.Get(key)
+ return db.Get(ctx,key)
}
// PutHealth to add health info
-func (db *Database) PutHealth(value string) error {
+func (db *Database) PutHealth(ctx context.Context, value string) error {
key := GetKeyPath(HealthPath)
- return db.kvc.Put(context.Background(), key, value)
+ return db.kvc.Put(ctx, key, value)
}
// DelHealth to delete health info
-func (db *Database) DelHealth() error {
+func (db *Database) DelHealth(ctx context.Context) error {
key := GetKeyPath(HealthPath)
- if err := db.kvc.Delete(context.Background(), key); err != nil {
+ if err := db.kvc.Delete(ctx, key); err != nil {
logger.Errorw(ctx, "The key doesn't exist", log.Fields{"key": key, "Error": err})
return err
}
@@ -511,27 +510,27 @@
// Meters
// GetMeters to get multiple meters info
-func (db *Database) GetMeters() (map[string]*kvstore.KVPair, error) {
+func (db *Database) GetMeters(ctx context.Context) (map[string]*kvstore.KVPair, error) {
key := GetKeyPath(MeterPath)
- return db.List(key)
+ return db.List(ctx, key)
}
// GetMeter to get meter info
-func (db *Database) GetMeter(name string) (string, error) {
+func (db *Database) GetMeter(ctx context.Context, name string) (string, error) {
key := GetKeyPath(MeterPath) + name
- return db.Get(key)
+ return db.Get(ctx, key)
}
// PutMeter to add meter info
-func (db *Database) PutMeter(name string, value string) error {
+func (db *Database) PutMeter(ctx context.Context, name string, value string) error {
key := GetKeyPath(MeterPath) + name
- return db.kvc.Put(context.Background(), key, value)
+ return db.kvc.Put(ctx, key, value)
}
// DelMeter to delete meter info
-func (db *Database) DelMeter(name string) error {
+func (db *Database) DelMeter(ctx context.Context, name string) error {
key := GetKeyPath(MeterPath) + name
- if err := db.kvc.Delete(context.Background(), key); err != nil {
+ if err := db.kvc.Delete(ctx, key); err != nil {
logger.Errorw(ctx, "The key doesn't exist", log.Fields{"key": key, "Error": err})
return err
}
@@ -539,9 +538,9 @@
}
// DelAllMeter to delete meter info
-func (db *Database) DelAllMeter(device string) error {
+func (db *Database) DelAllMeter(ctx context.Context, device string) error {
key := GetKeyPath(DevicePath) + device + "/" + MeterPath
- if err := db.DeleteAllUnderHashKey(key); err != nil {
+ if err := db.DeleteAllUnderHashKey(ctx, key); err != nil {
logger.Warnw(ctx, "Delete All failed: The key doesn't exist", log.Fields{"key": key, "Error": err})
return err
}
@@ -552,27 +551,27 @@
// IGMP groups
// GetIgmpGroups to get multiple igmp groups info
-func (db *Database) GetIgmpGroups() (map[string]*kvstore.KVPair, error) {
+func (db *Database) GetIgmpGroups(ctx context.Context) (map[string]*kvstore.KVPair, error) {
key := GetKeyPath(IgmpGroupPath)
- return db.List(key)
+ return db.List(ctx, key)
}
// GetIgmpGroup to get igmp group info
-func (db *Database) GetIgmpGroup(id string) (string, error) {
+func (db *Database) GetIgmpGroup(ctx context.Context, id string) (string, error) {
key := GetKeyPath(IgmpGroupPath) + id
- return db.Get(key)
+ return db.Get(ctx, key)
}
// PutIgmpGroup to add igmp group info
-func (db *Database) PutIgmpGroup(id string, value string) error {
+func (db *Database) PutIgmpGroup(ctx context.Context, id string, value string) error {
key := GetKeyPath(IgmpGroupPath) + id
- return db.kvc.Put(context.Background(), key, value)
+ return db.kvc.Put(ctx, key, value)
}
// DelIgmpGroup to delete igmp group info
-func (db *Database) DelIgmpGroup(id string) error {
+func (db *Database) DelIgmpGroup(ctx context.Context, id string) error {
key := GetKeyPath(IgmpGroupPath) + id
- if err := db.kvc.Delete(context.Background(), key); err != nil {
+ if err := db.kvc.Delete(ctx, key); err != nil {
logger.Warnw(ctx, "The key doesn't exist", log.Fields{"key": key, "Error": err})
return err
}
@@ -582,39 +581,39 @@
// IGMP group devices
// GetAllIgmpDevices to get multiple igmp devices info
-func (db *Database) GetAllIgmpDevices() (map[string]*kvstore.KVPair, error) {
+func (db *Database) GetAllIgmpDevices(ctx context.Context) (map[string]*kvstore.KVPair, error) {
key := GetKeyPath(IgmpDevicePath)
- return db.List(key)
+ return db.List(ctx, key)
}
// GetPrevIgmpDevices to get previous igmp devices
-func (db *Database) GetPrevIgmpDevices(mvlan of.VlanType, gid string) (map[string]*kvstore.KVPair, error) {
+func (db *Database) GetPrevIgmpDevices(ctx context.Context, mvlan of.VlanType, gid string) (map[string]*kvstore.KVPair, error) {
key := GetKeyPath(IgmpDevicePath) + mvlan.String() + "/" + gid + "/"
- return db.List(key)
+ return db.List(ctx, key)
}
// GetIgmpDevices to get igmp devices
-func (db *Database) GetIgmpDevices(mvlan of.VlanType, gid string, gip net.IP) (map[string]*kvstore.KVPair, error) {
+func (db *Database) GetIgmpDevices(ctx context.Context, mvlan of.VlanType, gid string, gip net.IP) (map[string]*kvstore.KVPair, error) {
key := GetKeyPath(IgmpDevicePath) + mvlan.String() + "/" + gid + "/" + gip.String() + "/"
- return db.List(key)
+ return db.List(ctx, key)
}
// GetIgmpDevice to get igmp device
-func (db *Database) GetIgmpDevice(mvlan of.VlanType, gid string, gip net.IP, device string) (string, error) {
+func (db *Database) GetIgmpDevice(ctx context.Context, mvlan of.VlanType, gid string, gip net.IP, device string) (string, error) {
key := GetKeyPath(IgmpDevicePath) + mvlan.String() + "/" + gid + "/" + gip.String() + "/" + device
- return db.Get(key)
+ return db.Get(ctx, key)
}
// PutIgmpDevice to add igmp device
-func (db *Database) PutIgmpDevice(mvlan of.VlanType, gid string, gip net.IP, device string, value string) error {
+func (db *Database) PutIgmpDevice(ctx context.Context, mvlan of.VlanType, gid string, gip net.IP, device string, value string) error {
key := GetKeyPath(IgmpDevicePath) + mvlan.String() + "/" + gid + "/" + gip.String() + "/" + device
- return db.kvc.Put(context.Background(), key, value)
+ return db.kvc.Put(ctx, key, value)
}
// DelIgmpDevice to delete igmp device
-func (db *Database) DelIgmpDevice(mvlan of.VlanType, gid string, gip net.IP, device string) error {
+func (db *Database) DelIgmpDevice(ctx context.Context, mvlan of.VlanType, gid string, gip net.IP, device string) error {
key := GetKeyPath(IgmpDevicePath) + mvlan.String() + "/" + gid + "/" + gip.String() + "/" + device
- if err := db.kvc.Delete(context.Background(), key); err != nil {
+ if err := db.kvc.Delete(ctx, key); err != nil {
logger.Warnw(ctx, "The key doesn't exist", log.Fields{"key": key, "Error": err})
return err
}
@@ -624,39 +623,39 @@
// IGMP group channels
// GetAllIgmpChannels to get all igmp channels
-func (db *Database) GetAllIgmpChannels() (map[string]*kvstore.KVPair, error) {
+func (db *Database) GetAllIgmpChannels(ctx context.Context) (map[string]*kvstore.KVPair, error) {
key := GetKeyPath(IgmpChannelPath)
- return db.List(key)
+ return db.List(ctx, key)
}
// GetPrevIgmpChannels to get previous igmp channels
-func (db *Database) GetPrevIgmpChannels(gName, device string) (map[string]*kvstore.KVPair, error) {
+func (db *Database) GetPrevIgmpChannels(ctx context.Context, gName, device string) (map[string]*kvstore.KVPair, error) {
key := GetKeyPath(IgmpChannelPath) + gName + "/" + device + "/"
- return db.List(key)
+ return db.List(ctx, key)
}
// GetIgmpChannels to get multiple igmp channels
-func (db *Database) GetIgmpChannels(mvlan of.VlanType, gName, device string) (map[string]*kvstore.KVPair, error) {
+func (db *Database) GetIgmpChannels(ctx context.Context, mvlan of.VlanType, gName, device string) (map[string]*kvstore.KVPair, error) {
key := GetKeyPath(IgmpChannelPath) + mvlan.String() + "/" + gName + "/" + device + "/"
- return db.List(key)
+ return db.List(ctx, key)
}
// GetIgmpChannel to get igmp channel
-func (db *Database) GetIgmpChannel(mvlan of.VlanType, gName string, device string, gip net.IP) (string, error) {
+func (db *Database) GetIgmpChannel(ctx context.Context, mvlan of.VlanType, gName string, device string, gip net.IP) (string, error) {
key := GetKeyPath(IgmpChannelPath) + mvlan.String() + "/" + gName + "/" + device + "/" + gip.String()
- return db.Get(key)
+ return db.Get(ctx, key)
}
// PutIgmpChannel to add igmp channel info
-func (db *Database) PutIgmpChannel(mvlan of.VlanType, gName string, device string, gip net.IP, value string) error {
+func (db *Database) PutIgmpChannel(ctx context.Context, mvlan of.VlanType, gName string, device string, gip net.IP, value string) error {
key := GetKeyPath(IgmpChannelPath) + mvlan.String() + "/" + gName + "/" + device + "/" + gip.String()
- return db.kvc.Put(context.Background(), key, value)
+ return db.kvc.Put(ctx, key, value)
}
// DelIgmpChannel to delete igmp channel info
-func (db *Database) DelIgmpChannel(mvlan of.VlanType, gName string, device string, gip net.IP) error {
+func (db *Database) DelIgmpChannel(ctx context.Context, mvlan of.VlanType, gName string, device string, gip net.IP) error {
key := GetKeyPath(IgmpChannelPath) + mvlan.String() + "/" + gName + "/" + device + "/" + gip.String()
- if err := db.kvc.Delete(context.Background(), key); err != nil {
+ if err := db.kvc.Delete(ctx, key); err != nil {
logger.Warnw(ctx, "The key doesn't exist", log.Fields{"key": key, "Error": err})
return err
}
@@ -666,39 +665,39 @@
// IGMP group receivers
// GetAllIgmpRcvrs to get all igmp receivers info
-func (db *Database) GetAllIgmpRcvrs() (map[string]*kvstore.KVPair, error) {
+func (db *Database) GetAllIgmpRcvrs(ctx context.Context) (map[string]*kvstore.KVPair, error) {
key := GetKeyPath(IgmpPortPath)
- return db.List(key)
+ return db.List(ctx, key)
}
// GetPrevIgmpRcvrs to get previous igmp receivers info
-func (db *Database) GetPrevIgmpRcvrs(gip net.IP, device string) (map[string]*kvstore.KVPair, error) {
+func (db *Database) GetPrevIgmpRcvrs(ctx context.Context, gip net.IP, device string) (map[string]*kvstore.KVPair, error) {
key := GetKeyPath(IgmpPortPath) + gip.String() + "/" + device + "/"
- return db.List(key)
+ return db.List(ctx, key)
}
// GetIgmpRcvrs to get multiple igmp receivers info
-func (db *Database) GetIgmpRcvrs(mvlan of.VlanType, gip net.IP, device string) (map[string]*kvstore.KVPair, error) {
+func (db *Database) GetIgmpRcvrs(ctx context.Context, mvlan of.VlanType, gip net.IP, device string) (map[string]*kvstore.KVPair, error) {
key := GetKeyPath(IgmpPortPath) + mvlan.String() + "/" + gip.String() + "/" + device + "/"
- return db.List(key)
+ return db.List(ctx, key)
}
// GetIgmpRcvr to get igmp receiver info
-func (db *Database) GetIgmpRcvr(mvlan of.VlanType, gip net.IP, device string, rcvr string) (string, error) {
+func (db *Database) GetIgmpRcvr(ctx context.Context, mvlan of.VlanType, gip net.IP, device string, rcvr string) (string, error) {
key := GetKeyPath(IgmpPortPath) + mvlan.String() + "/" + gip.String() + "/" + device + "/" + rcvr
- return db.Get(key)
+ return db.Get(ctx, key)
}
// PutIgmpRcvr to add igmp receiver info
-func (db *Database) PutIgmpRcvr(mvlan of.VlanType, gip net.IP, device string, rcvr string, value string) error {
+func (db *Database) PutIgmpRcvr(ctx context.Context, mvlan of.VlanType, gip net.IP, device string, rcvr string, value string) error {
key := GetKeyPath(IgmpPortPath) + mvlan.String() + "/" + gip.String() + "/" + device + "/" + rcvr
- return db.kvc.Put(context.Background(), key, value)
+ return db.kvc.Put(ctx, key, value)
}
// DelIgmpRcvr to delete igmp receiver info
-func (db *Database) DelIgmpRcvr(mvlan of.VlanType, gip net.IP, device string, rcvr string) error {
+func (db *Database) DelIgmpRcvr(ctx context.Context, mvlan of.VlanType, gip net.IP, device string, rcvr string) error {
key := GetKeyPath(IgmpPortPath) + mvlan.String() + "/" + gip.String() + "/" + device + "/" + rcvr
- if err := db.kvc.Delete(context.Background(), key); err != nil {
+ if err := db.kvc.Delete(ctx, key); err != nil {
logger.Warnw(ctx, "The key doesn't exist", log.Fields{"key": key, "Error": err})
return err
}
@@ -706,9 +705,9 @@
}
// DelAllIgmpRcvr to delete all igmp receiver info
-func (db *Database) DelAllIgmpRcvr(mvlan of.VlanType, gip net.IP, device string) error {
+func (db *Database) DelAllIgmpRcvr(ctx context.Context, mvlan of.VlanType, gip net.IP, device string) error {
key := GetKeyPath(IgmpPortPath) + mvlan.String() + "/" + gip.String() + "/" + device + "/"
- if err := db.DeleteAll(key); err != nil {
+ if err := db.DeleteAll(ctx, key); err != nil {
logger.Warnw(ctx, "Delete All failed: The key doesn't exist", log.Fields{"key": key, "Error": err})
return err
}
@@ -716,11 +715,11 @@
}
// DelAllRoutesForDevice to delete all routes for device
-func (db *Database) DelAllRoutesForDevice(device string) error {
+func (db *Database) DelAllRoutesForDevice(ctx context.Context, device string) error {
/* service/vgc/v1/devices/<deviceID>/flows/ */
logger.Infow(ctx, "Deleting all the flows for device", log.Fields{"device": device})
key := fmt.Sprintf(GetKeyPath(DeviceFlowPath), device)
- if err := db.DeleteAllUnderHashKey(key); err != nil {
+ if err := db.DeleteAllUnderHashKey(ctx, key); err != nil {
logger.Warnw(ctx, "Delete All failed: The key doesn't exist", log.Fields{"key": key, "Error": err})
return err
}
@@ -728,47 +727,47 @@
}
// PutNbDevicePort to add device port info
-func (db *Database) PutNbDevicePort(device string, ponPortID uint32, value string) {
+func (db *Database) PutNbDevicePort(ctx context.Context, device string, ponPortID uint32, value string) {
key := GetKeyPath(NbDevicePath) + device + "/pon-port/" + fmt.Sprintf("%v", ponPortID)
- if err := db.kvc.Put(context.Background(), key, value); err != nil {
+ if err := db.kvc.Put(ctx, key, value); err != nil {
logger.Warnw(ctx, "Put Device Port failed", log.Fields{"key": key})
}
}
// DelNbDevicePort to delete device port
-func (db *Database) DelNbDevicePort(device string, ponPortID uint32) {
+func (db *Database) DelNbDevicePort(ctx context.Context, device string, ponPortID uint32) {
key := GetKeyPath(NbDevicePath) + device + "/pon-port/" + fmt.Sprintf("%v", ponPortID)
- if err := db.kvc.Delete(context.Background(), key); err != nil {
+ if err := db.kvc.Delete(ctx, key); err != nil {
logger.Warnw(ctx, "Delete Device Port failed", log.Fields{"key": key})
}
}
// GetAllNbPorts to get all ports info
-func (db *Database) GetAllNbPorts(deviceID string) (map[string]*kvstore.KVPair, error) {
+func (db *Database) GetAllNbPorts(ctx context.Context, deviceID string) (map[string]*kvstore.KVPair, error) {
key := GetKeyPath(NbDevicePath) + deviceID + "/pon-port/"
- return db.List(key)
+ return db.List(ctx, key)
}
//Functions for migration database
// GetMigrationInfo to get migration info
-func (db *Database) GetMigrationInfo() (string, error) {
+func (db *Database) GetMigrationInfo(ctx context.Context) (string, error) {
key := GetKeyPath(MigrationInfoPath)
- return db.Get(key)
+ return db.Get(ctx, key)
}
// PutMigrationInfo to add migration info
-func (db *Database) PutMigrationInfo(value string) error {
+func (db *Database) PutMigrationInfo(ctx context.Context, value string) error {
key := GetKeyPath(MigrationInfoPath)
- return db.kvc.Put(context.Background(), key, value)
+ return db.kvc.Put(ctx, key, value)
}
// DelMigrationInfo to delete migration info
-func (db *Database) DelMigrationInfo() error {
+func (db *Database) DelMigrationInfo(ctx context.Context) error {
key := GetKeyPath(MigrationInfoPath)
- if err := db.kvc.Delete(context.Background(), key); err != nil {
+ if err := db.kvc.Delete(ctx, key); err != nil {
logger.Errorw(ctx, "The key doesn't exist", log.Fields{"key": key, "Error": err})
return err
}
@@ -778,27 +777,27 @@
//PON counters
// GetAllPonCounters to get all pon counters info
-func (db *Database) GetAllPonCounters(device string) (map[string]*kvstore.KVPair, error) {
+func (db *Database) GetAllPonCounters(ctx context.Context, device string) (map[string]*kvstore.KVPair, error) {
key := GetKeyPath(PonCounterPath) + device
- return db.List(key)
+ return db.List(ctx, key)
}
// GetPonCounter to get pon counter info
-func (db *Database) GetPonCounter(device, ponID string) (string, error) {
+func (db *Database) GetPonCounter(ctx context.Context, device, ponID string) (string, error) {
key := GetKeyPath(PonCounterPath) + device + "/" + ponID
- return db.Get(key)
+ return db.Get(ctx, key)
}
// PutPonCounter to add pon counter info
-func (db *Database) PutPonCounter(device, ponID, value string) error {
+func (db *Database) PutPonCounter(ctx context.Context, device, ponID, value string) error {
key := GetKeyPath(PonCounterPath) + device + "/" + ponID
- return db.kvc.Put(context.Background(), key, value)
+ return db.kvc.Put(ctx, key, value)
}
// DelPonCounter to delete pon counter info
-func (db *Database) DelPonCounter(device, ponID string) error {
+func (db *Database) DelPonCounter(ctx context.Context, device, ponID string) error {
key := GetKeyPath(PonCounterPath) + device + "/" + ponID
- if err := db.kvc.Delete(context.Background(), key); err != nil {
+ if err := db.kvc.Delete(ctx, key); err != nil {
logger.Errorw(ctx, "The key doesn't exist", log.Fields{"key": key, "Error": err})
return err
}
@@ -808,27 +807,27 @@
//PON Channel counters
// GetAllPonChannelCounters to get all pon channel counters
-func (db *Database) GetAllPonChannelCounters(device, ponID string) (map[string]*kvstore.KVPair, error) {
+func (db *Database) GetAllPonChannelCounters(ctx context.Context, device, ponID string) (map[string]*kvstore.KVPair, error) {
key := GetKeyPath(PonCounterPath) + device + "/" + ponID + "/" + ChannelCounterPath
- return db.List(key)
+ return db.List(ctx, key)
}
// GetPonChannelCounter to get pon channel counter
-func (db *Database) GetPonChannelCounter(device, ponID, channel string) (string, error) {
+func (db *Database) GetPonChannelCounter(ctx context.Context, device, ponID, channel string) (string, error) {
key := GetKeyPath(PonCounterPath) + device + "/" + ponID + "/" + ChannelCounterPath + channel
- return db.Get(key)
+ return db.Get(ctx, key)
}
// PutPonChannelCounter to add pon channel counter
-func (db *Database) PutPonChannelCounter(device, ponID, channel, value string) error {
+func (db *Database) PutPonChannelCounter(ctx context.Context, device, ponID, channel, value string) error {
key := GetKeyPath(PonCounterPath) + device + "/" + ponID + "/" + ChannelCounterPath + channel
- return db.kvc.Put(context.Background(), key, value)
+ return db.kvc.Put(ctx, key, value)
}
// DelPonChannelCounter to delete pon channel counter
-func (db *Database) DelPonChannelCounter(device, ponID, channel string) error {
+func (db *Database) DelPonChannelCounter(ctx context.Context, device, ponID, channel string) error {
key := GetKeyPath(PonCounterPath) + device + "/" + ponID + "/" + ChannelCounterPath + channel
- if err := db.kvc.Delete(context.Background(), key); err != nil {
+ if err := db.kvc.Delete(ctx, key); err != nil {
logger.Errorw(ctx, "The key doesn't exist", log.Fields{"key": key, "Error": err})
return err
}
@@ -836,56 +835,56 @@
}
// DelAllPONCounters to delete all pon channel counters
-func (db *Database) DelAllPONCounters(device string) error {
+func (db *Database) DelAllPONCounters(ctx context.Context, device string) error {
key := GetKeyPath(PonCounterPath) + device + "/"
- return db.DeleteAll(key)
+ return db.DeleteAll(ctx, key)
}
// DelPONCounters to delete pon counters
-func (db *Database) DelPONCounters(device string, ponID string) {
+func (db *Database) DelPONCounters(ctx context.Context, device string, ponID string) {
key := GetKeyPath(PonCounterPath) + device + "/" + ponID + "/"
- if err := db.DeleteAll(key); err != nil {
+ if err := db.DeleteAll(ctx, key); err != nil {
logger.Warnw(ctx, "Delete Pon counters failed", log.Fields{"key": key})
}
//DeletePonCounter(device, ponID)
}
// PutOltIgmpCounters to add Olt Igmp counter info
-func (db *Database) PutOltIgmpCounters(device, value string) error {
+func (db *Database) PutOltIgmpCounters(ctx context.Context, device, value string) error {
key := GetKeyPath(OltIgmpCounterPath) + device
- return db.kvc.Put(context.Background(), key, value)
+ return db.kvc.Put(ctx, key, value)
}
// GetOltIgmpCounter to get Olt Igmp counter info
-func (db *Database) GetOltIgmpCounter(device string) (string, error) {
+func (db *Database) GetOltIgmpCounter(ctx context.Context, device string) (string, error) {
key := GetKeyPath(OltIgmpCounterPath) + device
- return db.Get(key)
+ return db.Get(ctx, key)
}
//Service Channel counters
// GetAllServiceChannelCounters to get all service channel counters info
-func (db *Database) GetAllServiceChannelCounters(serviceName string) (map[string]*kvstore.KVPair, error) {
+func (db *Database) GetAllServiceChannelCounters(ctx context.Context, serviceName string) (map[string]*kvstore.KVPair, error) {
key := GetKeyPath(ServiceCounterPath) + serviceName + "/" + ChannelCounterPath
- return db.List(key)
+ return db.List(ctx, key)
}
// GetServiceChannelCounter to get service channel counter info
-func (db *Database) GetServiceChannelCounter(serviceName, channel string) (string, error) {
+func (db *Database) GetServiceChannelCounter(ctx context.Context, serviceName, channel string) (string, error) {
key := GetKeyPath(ServiceCounterPath) + serviceName + "/" + ChannelCounterPath + channel
- return db.Get(key)
+ return db.Get(ctx, key)
}
// PutServiceChannelCounter to add service channel counter
-func (db *Database) PutServiceChannelCounter(serviceName, channel, value string) error {
+func (db *Database) PutServiceChannelCounter(ctx context.Context, serviceName, channel, value string) error {
key := GetKeyPath(ServiceCounterPath) + serviceName + "/" + ChannelCounterPath + channel
- return db.kvc.Put(context.Background(), key, value)
+ return db.kvc.Put(ctx, key, value)
}
// DelServiceChannelCounter to delete service channel counter
-func (db *Database) DelServiceChannelCounter(serviceName, channel string) error {
+func (db *Database) DelServiceChannelCounter(ctx context.Context, serviceName, channel string) error {
key := GetKeyPath(ServiceCounterPath) + serviceName + "/" + ChannelCounterPath + channel
- if err := db.kvc.Delete(context.Background(), key); err != nil {
+ if err := db.kvc.Delete(ctx, key); err != nil {
logger.Errorw(ctx, "The key doesn't exist", log.Fields{"key": key, "Error": err})
return err
}
@@ -893,14 +892,14 @@
}
// DelAllServiceChannelCounter to delete all service channel counter
-func (db *Database) DelAllServiceChannelCounter(serviceName string) error {
+func (db *Database) DelAllServiceChannelCounter(ctx context.Context, serviceName string) error {
key := GetKeyPath(ServiceCounterPath) + serviceName + "/" + ChannelCounterPath
- return db.DeleteAllUnderHashKey(key)
+ return db.DeleteAllUnderHashKey(ctx, key)
}
// OltExists to know if the ONU is added to the database
-func (db *Database) OltExists(deviceID string) bool {
- if _, err := db.GetOlt(deviceID); err != nil {
+func (db *Database) OltExists(ctx context.Context, deviceID string) bool {
+ if _, err := db.GetOlt(ctx, deviceID); err != nil {
return false
}
return true
@@ -908,119 +907,119 @@
}
// PutFlowHash to add flowhash for the device
-func (db *Database) PutFlowHash(deviceID string, value string) error {
+func (db *Database) PutFlowHash(ctx context.Context, deviceID string, value string) error {
key := fmt.Sprintf(GetKeyPath(DeviceFlowPath), deviceID)
- return db.kvc.Put(context.Background(), key, value)
+ return db.kvc.Put(ctx, key, value)
}
// GetFlowHash gets the flow hash for the device
-func (db *Database) GetFlowHash(deviceID string) (string, error) {
+func (db *Database) GetFlowHash(ctx context.Context, deviceID string) (string, error) {
key := fmt.Sprintf(GetKeyPath(DeviceFlowPath), deviceID)
- return db.Get(key)
+ return db.Get(ctx, key)
}
// PutPortAlarmProfile to add port alarm profile
-func (db *Database) PutPortAlarmProfile(portAlarmProfileID string, value string) {
+func (db *Database) PutPortAlarmProfile(ctx context.Context, portAlarmProfileID string, value string) {
key := GetKeyPath(PortAlarmProfilePath) + fmt.Sprintf("%v", portAlarmProfileID)
- if err := db.kvc.Put(context.Background(), key, value); err != nil {
+ if err := db.kvc.Put(ctx, key, value); err != nil {
logger.Warnw(ctx, "Put PortAlarmProfile failed", log.Fields{"key": key})
}
}
// DelPortAlarmProfile to delete port alarm profile
-func (db *Database) DelPortAlarmProfile(portAlarmProfileID string) {
+func (db *Database) DelPortAlarmProfile(ctx context.Context, portAlarmProfileID string) {
key := GetKeyPath(PortAlarmProfilePath) + fmt.Sprintf("%v", portAlarmProfileID)
- if err := db.kvc.Delete(context.Background(), key); err != nil {
+ if err := db.kvc.Delete(ctx, key); err != nil {
logger.Warnw(ctx, "Delete PortAlarmProfile failed", log.Fields{"key": key})
}
}
// GetPortAlarmProfile to get port alarm profile
-func (db *Database) GetPortAlarmProfile(portAlarmProfileID string) (map[string]*kvstore.KVPair, error) {
+func (db *Database) GetPortAlarmProfile(ctx context.Context, portAlarmProfileID string) (map[string]*kvstore.KVPair, error) {
key := GetKeyPath(PortAlarmProfilePath) + fmt.Sprintf("%v", portAlarmProfileID)
- return db.List(key)
+ return db.List(ctx, key)
}
// PutPortAlarmData to add port alarm data
-func (db *Database) PutPortAlarmData(deviceID string, portID uint32, value string) {
+func (db *Database) PutPortAlarmData(ctx context.Context, deviceID string, portID uint32, value string) {
key := fmt.Sprintf(GetKeyPath(PortAlarmDataPath), deviceID) + fmt.Sprintf("%v", portID)
- if err := db.kvc.Put(context.Background(), key, value); err != nil {
+ if err := db.kvc.Put(ctx, key, value); err != nil {
logger.Warnw(ctx, "Put PortAlarmData failed", log.Fields{"key": key})
}
}
// DelPortAlarmData to delete port alarm data
-func (db *Database) DelPortAlarmData(deviceID string, portID uint32) {
+func (db *Database) DelPortAlarmData(ctx context.Context, deviceID string, portID uint32) {
key := fmt.Sprintf(GetKeyPath(PortAlarmDataPath), deviceID) + fmt.Sprintf("%v", portID)
- if err := db.kvc.Delete(context.Background(), key); err != nil {
+ if err := db.kvc.Delete(ctx, key); err != nil {
logger.Warnw(ctx, "Delete PortAlarmData failed", log.Fields{"key": key})
}
}
// GetPortAlarmData to get port alarm data
-func (db *Database) GetPortAlarmData(deviceID string, portID uint32) (string, error) {
+func (db *Database) GetPortAlarmData(ctx context.Context, deviceID string, portID uint32) (string, error) {
key := fmt.Sprintf(GetKeyPath(PortAlarmDataPath), deviceID) + fmt.Sprintf("%v", portID)
- return db.Get(key)
+ return db.Get(ctx, key)
}
// GetAllPortAlarmData to get port alarm data for all ports
-func (db *Database) GetAllPortAlarmData(deviceID string) (map[string]*kvstore.KVPair, error) {
+func (db *Database) GetAllPortAlarmData(ctx context.Context, deviceID string) (map[string]*kvstore.KVPair, error) {
key := fmt.Sprintf(GetKeyPath(PortAlarmDataPath), deviceID)
- return db.List(key)
+ return db.List(ctx, key)
}
// PutSubAlarmData to add subscriber alarm data
-func (db *Database) PutSubAlarmData(deviceID string, portName string, value string) {
+func (db *Database) PutSubAlarmData(ctx context.Context, deviceID string, portName string, value string) {
key := fmt.Sprintf(GetKeyPath(SubAlarmDataPath), deviceID) + fmt.Sprintf("%v", portName)
- if err := db.kvc.Put(context.Background(), key, value); err != nil {
+ if err := db.kvc.Put(ctx, key, value); err != nil {
logger.Warnw(ctx, "Put Subscriber AlarmData failed", log.Fields{"key": key})
}
}
// DelSubAlarmData to delete subscriber alarm data
-func (db *Database) DelSubAlarmData(deviceID string, portName string) {
+func (db *Database) DelSubAlarmData(ctx context.Context, deviceID string, portName string) {
key := fmt.Sprintf(GetKeyPath(SubAlarmDataPath), deviceID) + fmt.Sprintf("%v", portName)
- if err := db.kvc.Delete(context.Background(), key); err != nil {
+ if err := db.kvc.Delete(ctx, key); err != nil {
logger.Warnw(ctx, "Delete Subscriber AlarmData failed", log.Fields{"key": key})
}
}
// GetSubAlarmData to get subscriber alarm data
-func (db *Database) GetSubAlarmData(deviceID string, portName string) (string, error) {
+func (db *Database) GetSubAlarmData(ctx context.Context, deviceID string, portName string) (string, error) {
key := fmt.Sprintf(GetKeyPath(SubAlarmDataPath), deviceID) + fmt.Sprintf("%v", portName)
- return db.Get(key)
+ return db.Get(ctx, key)
}
// GetAllSubAlarmData to get sub alarm data for all subscribers
-func (db *Database) GetAllSubAlarmData(deviceID string) (map[string]*kvstore.KVPair, error) {
+func (db *Database) GetAllSubAlarmData(ctx context.Context, deviceID string) (map[string]*kvstore.KVPair, error) {
key := fmt.Sprintf(GetKeyPath(SubAlarmDataPath), deviceID)
- return db.List(key)
+ return db.List(ctx, key)
}
// Migrate Service req specific database actions
// PutMigrateServicesReq to add MigrateServicesReq info
-func (db *Database) PutMigrateServicesReq(deviceID string, vnet string, value string) error {
+func (db *Database) PutMigrateServicesReq(ctx context.Context, deviceID string, vnet string, value string) error {
key := fmt.Sprintf(GetKeyPath(ServicesMigrateReqPath), deviceID) + vnet
- return db.kvc.Put(context.Background(), key, value)
+ return db.kvc.Put(ctx, key, value)
}
// GetMigrateServicesReq to get MigrateServicesReq info
-func (db *Database) GetMigrateServicesReq(deviceID string, vnet string) (string, error) {
+func (db *Database) GetMigrateServicesReq(ctx context.Context, deviceID string, vnet string) (string, error) {
key := fmt.Sprintf(GetKeyPath(ServicesMigrateReqPath), deviceID) + vnet
- return db.Get(key)
+ return db.Get(ctx, key)
}
// GetAllMigrateServicesReq to get multiple MigrateServicesReq info
-func (db *Database) GetAllMigrateServicesReq(deviceID string) (map[string]*kvstore.KVPair, error) {
+func (db *Database) GetAllMigrateServicesReq(ctx context.Context, deviceID string) (map[string]*kvstore.KVPair, error) {
key := fmt.Sprintf(GetKeyPath(ServicesMigrateReqPath), deviceID)
- return db.List(key)
+ return db.List(ctx, key)
}
// DelMigrateServicesReq to delete MigrateServicesReq info
-func (db *Database) DelMigrateServicesReq(deviceID string, vnet string) error {
+func (db *Database) DelMigrateServicesReq(ctx context.Context, deviceID string, vnet string) error {
key := fmt.Sprintf(GetKeyPath(ServicesMigrateReqPath), deviceID) + vnet
- if err := db.kvc.Delete(context.Background(), key); err != nil {
+ if err := db.kvc.Delete(ctx, key); err != nil {
logger.Errorw(ctx, "The key doesn't exist", log.Fields{"key": key, "Error": err})
return err
}
@@ -1028,9 +1027,9 @@
}
// DelAllMigrateServicesReq to delete all MigrateServicesReq info
-func (db *Database) DelAllMigrateServicesReq(deviceID string) error {
+func (db *Database) DelAllMigrateServicesReq(ctx context.Context, deviceID string) error {
key := fmt.Sprintf(GetKeyPath(ServicesMigrateReqPath), deviceID)
- if err := db.DeleteAllUnderHashKey(key); err != nil {
+ if err := db.DeleteAllUnderHashKey(ctx, key); err != nil {
logger.Warnw(ctx, "Delete All failed: The key doesn't exist", log.Fields{"key": key, "Error": err})
return err
}
diff --git a/database/dbintf.go b/database/dbintf.go
index b8b491f..8a6a43b 100644
--- a/database/dbintf.go
+++ b/database/dbintf.go
@@ -17,6 +17,7 @@
import (
"net"
+ "context"
"voltha-go-controller/internal/pkg/of"
"github.com/opencord/voltha-lib-go/v7/pkg/db/kvstore"
@@ -26,132 +27,132 @@
// DBIntf defines db related methods
type DBIntf interface {
- Get(key string) (string, error)
- Put(fullKeyPath string, value string) error
- Del(path string) error
- List(key string) (map[string]*kvstore.KVPair, error)
- DeleteAll(path string) error
- DeleteAllUnderHashKey(hashKeyPrefix string) error
- GetOlt(deviceID string) (string, error)
- PutOlt(deviceID string, value string) error
- DelOlt(deviceID string) error
- GetFlow(deviceID string, flowID uint64) (string, error)
- GetFlows(deviceID string) (map[string]*kvstore.KVPair, error)
- PutFlow(deviceID string, flowID uint64, value string) error
- DelFlow(deviceID string, flowID uint64) error
- PutGroup(deviceID string, groupID uint32, value string) error
- GetGroup(deviceID string, groupID uint32) (string, error)
- GetGroups(deviceID string) (map[string]*kvstore.KVPair, error)
- DelGroup(deviceID string, groupID uint32) error
- DelAllGroup(string) error
- DelAllPorts(deviceID string) error
- DelPort(deviceID string, portID uint32) error
- PutPort(deviceID string, portID uint32, value string) error
- GetPort(deviceID string, portID uint32) (string, error)
- GetPorts(deviceID string) (map[string]*kvstore.KVPair, error)
- PutDeviceMeter(deviceID string, meterID uint32, value string) error
- GetDeviceMeter(deviceID string, meterID uint32) (string, error)
- GetDeviceMeters(deviceID string) (map[string]*kvstore.KVPair, error)
- DelDeviceMeter(deviceID string, meterID uint32) error
- GetService(name string) (string, error)
- GetServices() (map[string]*kvstore.KVPair, error)
- PutService(name string, value string) error
- DelService(name string) error
- GetVnets() (map[string]*kvstore.KVPair, error)
- GetVnet(name string) (string, error)
- PutVnet(name string, value string) error
- DelVnet(name string) error
- GetVpvs() (map[string]*kvstore.KVPair, error)
- GetVpv(port string, SVlan uint16, CVlan uint16, UniVlan uint16) (string, error)
- PutVpv(port string, SVlan uint16, CVlan uint16, UniVlan uint16, value string) error
- DelVpv(port string, SVlan uint16, CVlan uint16, UniVlan uint16) error
- GetMvlans() (map[string]*kvstore.KVPair, error)
- GetMvlan(mvlan uint16) (string, error)
- PutMvlan(mvlan uint16, value string) error
- DelMvlan(mvlan uint16) error
- DelIGMPCfg() error
- GetHealth() (string, error)
- PutHealth(value string) error
- DelHealth() error
- GetMeters() (map[string]*kvstore.KVPair, error)
- GetMeter(name string) (string, error)
- PutMeter(name string, value string) error
- DelMeter(name string) error
- DelAllMeter(device string) error
- GetIgmpGroups() (map[string]*kvstore.KVPair, error)
- GetIgmpGroup(id string) (string, error)
- PutIgmpGroup(id string, value string) error
- DelIgmpGroup(id string) error
- GetAllIgmpDevices() (map[string]*kvstore.KVPair, error)
- GetPrevIgmpDevices(mvlan of.VlanType, gid string) (map[string]*kvstore.KVPair, error)
- GetIgmpDevices(mvlan of.VlanType, gid string, gip net.IP) (map[string]*kvstore.KVPair, error)
- GetIgmpDevice(mvlan of.VlanType, gid string, gip net.IP, device string) (string, error)
- PutIgmpDevice(mvlan of.VlanType, gid string, gip net.IP, device string, value string) error
- DelIgmpDevice(mvlan of.VlanType, gid string, gip net.IP, device string) error
- GetAllIgmpChannels() (map[string]*kvstore.KVPair, error)
- GetPrevIgmpChannels(gname string, device string) (map[string]*kvstore.KVPair, error)
- GetIgmpChannels(mvlan of.VlanType, gname string, device string) (map[string]*kvstore.KVPair, error)
- GetIgmpChannel(mvlan of.VlanType, gName string, device string, gip net.IP) (string, error)
- PutIgmpChannel(mvlan of.VlanType, gName string, device string, gip net.IP, value string) error
- DelIgmpChannel(mvlan of.VlanType, gName string, device string, gip net.IP) error
- GetAllIgmpRcvrs() (map[string]*kvstore.KVPair, error)
- GetPrevIgmpRcvrs(gip net.IP, device string) (map[string]*kvstore.KVPair, error)
- GetIgmpRcvrs(mvlan of.VlanType, gip net.IP, device string) (map[string]*kvstore.KVPair, error)
- GetIgmpRcvr(mvlan of.VlanType, gip net.IP, device string, rcvr string) (string, error)
- PutIgmpRcvr(mvlan of.VlanType, gip net.IP, device string, rcvr string, value string) error
- DelIgmpRcvr(mvlan of.VlanType, gip net.IP, device string, rcvr string) error
- DelAllIgmpRcvr(mvlan of.VlanType, gip net.IP, device string) error
- DelAllRoutesForDevice(device string) error
- DelNbDevicePort(device string, ponPortID uint32)
- GetAllNbPorts(deviceID string) (map[string]*kvstore.KVPair, error)
- GetMigrationInfo() (string, error)
- PutMigrationInfo(value string) error
- DelMigrationInfo() error
- GetAllPonCounters(device string) (map[string]*kvstore.KVPair, error)
- GetPonCounter(device string, ponID string) (string, error)
- PutPonCounter(device string, ponID string, value string) error
- DelPonCounter(device string, ponID string) error
- GetAllPonChannelCounters(device string, ponID string) (map[string]*kvstore.KVPair, error)
- GetPonChannelCounter(device string, ponID string, channel string) (string, error)
- PutNbDevicePort(device string, ponPortID uint32, value string)
- PutPonChannelCounter(device string, ponID string, channel string, value string) error
- DelPonChannelCounter(device string, ponID string, channel string) error
- DelAllPONCounters(device string) error
- DelPONCounters(device string, ponID string)
- GetAllServiceChannelCounters(serviceName string) (map[string]*kvstore.KVPair, error)
- GetServiceChannelCounter(serviceName string, channel string) (string, error)
- PutServiceChannelCounter(serviceName string, channel string, value string) error
- DelServiceChannelCounter(serviceName string, channel string) error
- DelAllServiceChannelCounter(serviceName string) error
- PutOltIgmpCounters(device string, value string) error
- GetOltIgmpCounter(device string) (string, error)
- PutFlowHash(deviceID string, value string) error
- GetFlowHash(deviceID string) (string, error)
- OltExists(deviceID string) bool
- GetIgmpProfiles() (map[string]*kvstore.KVPair, error)
- GetIgmpProfile(name string) (string, error)
- PutIgmpProfile(name string, value string) error
- DelIgmpProfile(name string) error
- GetMcastConfigs() (map[string]*kvstore.KVPair, error)
- GetMcastConfig(name string) (string, error)
- PutMcastConfig(name string, value string) error
- DelMcastConfig(name string) error
- PutPortAlarmProfile(portAlarmProfileID string, value string)
- GetPortAlarmProfile(portAlarmProfileID string) (map[string]*kvstore.KVPair, error)
- DelPortAlarmProfile(portAlarmProfileID string)
- PutPortAlarmData(deviceID string, portID uint32, value string)
- GetPortAlarmData(deviceID string, portID uint32) (string, error)
- DelPortAlarmData(deviceID string, portID uint32)
- GetAllPortAlarmData(deviceID string) (map[string]*kvstore.KVPair, error)
- PutSubAlarmData(deviceID string, portName string, value string)
- GetSubAlarmData(deviceID string, portName string) (string, error)
- DelSubAlarmData(deviceID string, portName string)
- GetAllSubAlarmData(deviceID string) (map[string]*kvstore.KVPair, error)
- PutMigrateServicesReq(deviceID string, vlan string, value string) error
- GetMigrateServicesReq(deviceID string, vlan string) (string, error)
- GetAllMigrateServicesReq(deviceID string) (map[string]*kvstore.KVPair, error)
- DelMigrateServicesReq(deviceID string, vlan string) error
- DelAllMigrateServicesReq(deviceID string) error
+ Get(ctx context.Context, key string) (string, error)
+ Put(ctx context.Context, fullKeyPath string, value string) error
+ Del(ctx context.Context, path string) error
+ List(ctx context.Context, key string) (map[string]*kvstore.KVPair, error)
+ DeleteAll(ctx context.Context, path string) error
+ DeleteAllUnderHashKey(ctx context.Context, hashKeyPrefix string) error
+ GetOlt(ctx context.Context, deviceID string) (string, error)
+ PutOlt(ctx context.Context, deviceID string, value string) error
+ DelOlt(ctx context.Context, deviceID string) error
+ GetFlow(ctx context.Context, deviceID string, flowID uint64) (string, error)
+ GetFlows(ctx context.Context, deviceID string) (map[string]*kvstore.KVPair, error)
+ PutFlow(ctx context.Context, deviceID string, flowID uint64, value string) error
+ DelFlow(ctx context.Context, deviceID string, flowID uint64) error
+ PutGroup(ctx context.Context, deviceID string, groupID uint32, value string) error
+ GetGroup(ctx context.Context, deviceID string, groupID uint32) (string, error)
+ GetGroups(ctx context.Context, deviceID string) (map[string]*kvstore.KVPair, error)
+ DelGroup(ctx context.Context, deviceID string, groupID uint32) error
+ DelAllGroup(ctx context.Context, deviceID string) error
+ DelAllPorts(ctx context.Context, deviceID string) error
+ DelPort(ctx context.Context, deviceID string, portID uint32) error
+ PutPort(ctx context.Context, deviceID string, portID uint32, value string) error
+ GetPort(ctx context.Context, deviceID string, portID uint32) (string, error)
+ GetPorts(ctx context.Context, deviceID string) (map[string]*kvstore.KVPair, error)
+ PutDeviceMeter(ctx context.Context, deviceID string, meterID uint32, value string) error
+ GetDeviceMeter(ctx context.Context, deviceID string, meterID uint32) (string, error)
+ GetDeviceMeters(ctx context.Context, deviceID string) (map[string]*kvstore.KVPair, error)
+ DelDeviceMeter(ctx context.Context, deviceID string, meterID uint32) error
+ GetService(ctx context.Context, name string) (string, error)
+ GetServices(ctx context.Context) (map[string]*kvstore.KVPair, error)
+ PutService(ctx context.Context, name string, value string) error
+ DelService(ctx context.Context, name string) error
+ GetVnets(ctx context.Context) (map[string]*kvstore.KVPair, error)
+ GetVnet(ctx context.Context, name string) (string, error)
+ PutVnet(ctx context.Context, name string, value string) error
+ DelVnet(ctx context.Context, name string) error
+ GetVpvs(ctx context.Context) (map[string]*kvstore.KVPair, error)
+ GetVpv(ctx context.Context, port string, SVlan uint16, CVlan uint16, UniVlan uint16) (string, error)
+ PutVpv(ctx context.Context, port string, SVlan uint16, CVlan uint16, UniVlan uint16, value string) error
+ DelVpv(ctx context.Context, port string, SVlan uint16, CVlan uint16, UniVlan uint16) error
+ GetMvlans(ctx context.Context) (map[string]*kvstore.KVPair, error)
+ GetMvlan(ctx context.Context, mvlan uint16) (string, error)
+ PutMvlan(ctx context.Context, mvlan uint16, value string) error
+ DelMvlan(ctx context.Context, mvlan uint16) error
+ DelIGMPCfg(ctx context.Context) error
+ GetHealth(ctx context.Context) (string, error)
+ PutHealth(ctx context.Context, value string) error
+ DelHealth(ctx context.Context) error
+ GetMeters(ctx context.Context) (map[string]*kvstore.KVPair, error)
+ GetMeter(ctx context.Context, name string) (string, error)
+ PutMeter(ctx context.Context, name string, value string) error
+ DelMeter(ctx context.Context, name string) error
+ DelAllMeter(ctx context.Context, device string) error
+ GetIgmpGroups(ctx context.Context) (map[string]*kvstore.KVPair, error)
+ GetIgmpGroup(ctx context.Context, id string) (string, error)
+ PutIgmpGroup(ctx context.Context, id string, value string) error
+ DelIgmpGroup(ctx context.Context, id string) error
+ GetAllIgmpDevices(ctx context.Context) (map[string]*kvstore.KVPair, error)
+ GetPrevIgmpDevices(ctx context.Context, mvlan of.VlanType, gid string) (map[string]*kvstore.KVPair, error)
+ GetIgmpDevices(ctx context.Context, mvlan of.VlanType, gid string, gip net.IP) (map[string]*kvstore.KVPair, error)
+ GetIgmpDevice(ctx context.Context, mvlan of.VlanType, gid string, gip net.IP, device string) (string, error)
+ PutIgmpDevice(ctx context.Context, mvlan of.VlanType, gid string, gip net.IP, device string, value string) error
+ DelIgmpDevice(ctx context.Context, mvlan of.VlanType, gid string, gip net.IP, device string) error
+ GetAllIgmpChannels(ctx context.Context) (map[string]*kvstore.KVPair, error)
+ GetPrevIgmpChannels(ctx context.Context, gname string, device string) (map[string]*kvstore.KVPair, error)
+ GetIgmpChannels(ctx context.Context, mvlan of.VlanType, gname string, device string) (map[string]*kvstore.KVPair, error)
+ GetIgmpChannel(ctx context.Context, mvlan of.VlanType, gName string, device string, gip net.IP) (string, error)
+ PutIgmpChannel(ctx context.Context, mvlan of.VlanType, gName string, device string, gip net.IP, value string) error
+ DelIgmpChannel(ctx context.Context, mvlan of.VlanType, gName string, device string, gip net.IP) error
+ GetAllIgmpRcvrs(ctx context.Context) (map[string]*kvstore.KVPair, error)
+ GetPrevIgmpRcvrs(ctx context.Context, gip net.IP, device string) (map[string]*kvstore.KVPair, error)
+ GetIgmpRcvrs(ctx context.Context, mvlan of.VlanType, gip net.IP, device string) (map[string]*kvstore.KVPair, error)
+ GetIgmpRcvr(ctx context.Context, mvlan of.VlanType, gip net.IP, device string, rcvr string) (string, error)
+ PutIgmpRcvr(ctx context.Context, mvlan of.VlanType, gip net.IP, device string, rcvr string, value string) error
+ DelIgmpRcvr(ctx context.Context, mvlan of.VlanType, gip net.IP, device string, rcvr string) error
+ DelAllIgmpRcvr(ctx context.Context, mvlan of.VlanType, gip net.IP, device string) error
+ DelAllRoutesForDevice(ctx context.Context, device string) error
+ DelNbDevicePort(ctx context.Context, device string, ponPortID uint32)
+ GetAllNbPorts(ctx context.Context, deviceID string) (map[string]*kvstore.KVPair, error)
+ GetMigrationInfo(ctx context.Context) (string, error)
+ PutMigrationInfo(ctx context.Context, value string) error
+ DelMigrationInfo(ctx context.Context) error
+ GetAllPonCounters(ctx context.Context, device string) (map[string]*kvstore.KVPair, error)
+ GetPonCounter(ctx context.Context, device string, ponID string) (string, error)
+ PutPonCounter(ctx context.Context, device string, ponID string, value string) error
+ DelPonCounter(ctx context.Context, device string, ponID string) error
+ GetAllPonChannelCounters(ctx context.Context, device string, ponID string) (map[string]*kvstore.KVPair, error)
+ GetPonChannelCounter(ctx context.Context, device string, ponID string, channel string) (string, error)
+ PutNbDevicePort(ctx context.Context, device string, ponPortID uint32, value string)
+ PutPonChannelCounter(ctx context.Context, device string, ponID string, channel string, value string) error
+ DelPonChannelCounter(ctx context.Context, device string, ponID string, channel string) error
+ DelAllPONCounters(ctx context.Context, device string) error
+ DelPONCounters(ctx context.Context, device string, ponID string)
+ GetAllServiceChannelCounters(ctx context.Context, serviceName string) (map[string]*kvstore.KVPair, error)
+ GetServiceChannelCounter(ctx context.Context, serviceName string, channel string) (string, error)
+ PutServiceChannelCounter(ctx context.Context, serviceName string, channel string, value string) error
+ DelServiceChannelCounter(ctx context.Context, serviceName string, channel string) error
+ DelAllServiceChannelCounter(ctx context.Context, serviceName string) error
+ PutOltIgmpCounters(ctx context.Context, device string, value string) error
+ GetOltIgmpCounter(ctx context.Context, device string) (string, error)
+ PutFlowHash(ctx context.Context, deviceID string, value string) error
+ GetFlowHash(ctx context.Context, deviceID string) (string, error)
+ OltExists(ctx context.Context, deviceID string) bool
+ GetIgmpProfiles(ctx context.Context) (map[string]*kvstore.KVPair, error)
+ GetIgmpProfile(ctx context.Context, name string) (string, error)
+ PutIgmpProfile(ctx context.Context, name string, value string) error
+ DelIgmpProfile(ctx context.Context, name string) error
+ GetMcastConfigs(ctx context.Context) (map[string]*kvstore.KVPair, error)
+ GetMcastConfig(ctx context.Context, name string) (string, error)
+ PutMcastConfig(ctx context.Context, name string, value string) error
+ DelMcastConfig(ctx context.Context, name string) error
+ PutPortAlarmProfile(ctx context.Context, portAlarmProfileID string, value string)
+ GetPortAlarmProfile(ctx context.Context, portAlarmProfileID string) (map[string]*kvstore.KVPair, error)
+ DelPortAlarmProfile(ctx context.Context, portAlarmProfileID string)
+ PutPortAlarmData(ctx context.Context, deviceID string, portID uint32, value string)
+ GetPortAlarmData(ctx context.Context, deviceID string, portID uint32) (string, error)
+ DelPortAlarmData(ctx context.Context, deviceID string, portID uint32)
+ GetAllPortAlarmData(ctx context.Context, deviceID string) (map[string]*kvstore.KVPair, error)
+ PutSubAlarmData(ctx context.Context, deviceID string, portName string, value string)
+ GetSubAlarmData(ctx context.Context, deviceID string, portName string) (string, error)
+ DelSubAlarmData(ctx context.Context, deviceID string, portName string)
+ GetAllSubAlarmData(ctx context.Context, deviceID string) (map[string]*kvstore.KVPair, error)
+ PutMigrateServicesReq(ctx context.Context, deviceID string, vlan string, value string) error
+ GetMigrateServicesReq(ctx context.Context, deviceID string, vlan string) (string, error)
+ GetAllMigrateServicesReq(ctx context.Context, deviceID string) (map[string]*kvstore.KVPair, error)
+ DelMigrateServicesReq(ctx context.Context, deviceID string, vlan string) error
+ DelAllMigrateServicesReq(ctx context.Context, deviceID string) error
}
//GetDatabase - returns databse operation based on configuration
diff --git a/internal/pkg/application/application.go b/internal/pkg/application/application.go
index 9476e55..e7d2d04 100644
--- a/internal/pkg/application/application.go
+++ b/internal/pkg/application/application.go
@@ -84,7 +84,7 @@
var PacketHandlers map[string]CallBack
// CallBack : registered call back function for different protocol packets
-type CallBack func(device string, port string, pkt gopacket.Packet)
+type CallBack func(cntx context.Context, device string, port string, pkt gopacket.Packet)
const (
// ARP packet
@@ -338,7 +338,7 @@
}
// pushFlowsForUnis to send port-up-indication for uni ports.
-func (d *VoltDevice) pushFlowsForUnis() {
+func (d *VoltDevice) pushFlowsForUnis(cntx context.Context) {
logger.Info(ctx, "NNI Discovered, Sending Port UP Ind for UNIs")
d.Ports.Range(func(key, value interface{}) bool {
@@ -359,7 +359,7 @@
for _, vpv := range vnets.([]*VoltPortVnet) {
vpv.VpvLock.Lock()
- vpv.PortUpInd(d, port)
+ vpv.PortUpInd(cntx, d, port)
vpv.VpvLock.Unlock()
}
@@ -447,12 +447,12 @@
}
// RestoreNbDeviceFromDb restores the NB Device in case of VGC pod restart.
-func (va *VoltApplication) RestoreNbDeviceFromDb(deviceID string) *NbDevice {
+func (va *VoltApplication) RestoreNbDeviceFromDb(cntx context.Context, deviceID string) *NbDevice {
nbDevice := NewNbDevice()
nbDevice.SouthBoundID = deviceID
- nbPorts, _ := db.GetAllNbPorts(deviceID)
+ nbPorts, _ := db.GetAllNbPorts(cntx, deviceID)
for key, p := range nbPorts {
b, ok := p.Value.([]byte)
@@ -481,17 +481,17 @@
}
// WriteToDb writes nb device port config to kv store
-func (nbd *NbDevice) WriteToDb(portID uint32, ponPort *PonPortCfg) {
+func (nbd *NbDevice) WriteToDb(cntx context.Context, portID uint32, ponPort *PonPortCfg) {
b, err := json.Marshal(ponPort)
if err != nil {
logger.Errorw(ctx, "PonPortConfig-marshal-failed", log.Fields{"err": err})
return
}
- db.PutNbDevicePort(nbd.SouthBoundID, portID, string(b))
+ db.PutNbDevicePort(cntx, nbd.SouthBoundID, portID, string(b))
}
// AddPortToNbDevice Adds pon port to NB Device and DB
-func (nbd *NbDevice) AddPortToNbDevice(portID, allowedChannels uint32,
+func (nbd *NbDevice) AddPortToNbDevice(cntx context.Context, portID, allowedChannels uint32,
enableMulticastKPI bool, portAlarmProfileID string) *PonPortCfg {
ponPort := &PonPortCfg{
@@ -501,12 +501,12 @@
PortAlarmProfileID: portAlarmProfileID,
}
nbd.PonPorts.Store(portID, ponPort)
- nbd.WriteToDb(portID, ponPort)
+ nbd.WriteToDb(cntx, portID, ponPort)
return ponPort
}
// UpdatePortToNbDevice Adds pon port to NB Device and DB
-func (nbd *NbDevice) UpdatePortToNbDevice(portID, allowedChannels uint32, enableMulticastKPI bool, portAlarmProfileID string) *PonPortCfg {
+func (nbd *NbDevice) UpdatePortToNbDevice(cntx context.Context, portID, allowedChannels uint32, enableMulticastKPI bool, portAlarmProfileID string) *PonPortCfg {
p, exists := nbd.PonPorts.Load(portID)
if !exists {
@@ -521,17 +521,17 @@
}
nbd.PonPorts.Store(portID, port)
- nbd.WriteToDb(portID, port)
+ nbd.WriteToDb(cntx, portID, port)
return port
}
// DeletePortFromNbDevice Deletes pon port from NB Device and DB
-func (nbd *NbDevice) DeletePortFromNbDevice(portID uint32) {
+func (nbd *NbDevice) DeletePortFromNbDevice(cntx context.Context, portID uint32) {
if _, ok := nbd.PonPorts.Load(portID); ok {
nbd.PonPorts.Delete(portID)
}
- db.DelNbDevicePort(nbd.SouthBoundID, portID)
+ db.DelNbDevicePort(cntx, nbd.SouthBoundID, portID)
}
// GetApplication : Interface to access the singleton object
@@ -559,8 +559,8 @@
va.VnetsToDelete = make(map[string]bool)
va.ServicesToDelete = make(map[string]bool)
va.VoltPortVnetsToDelete = make(map[*VoltPortVnet]bool)
- go va.Start(TimerCfg{tick: 100 * time.Millisecond}, tickTimer)
- go va.Start(TimerCfg{tick: time.Duration(GroupExpiryTime) * time.Minute}, pendingPoolTimer)
+ go va.Start(context.Background(), TimerCfg{tick: 100 * time.Millisecond}, tickTimer)
+ go va.Start(context.Background(), TimerCfg{tick: time.Duration(GroupExpiryTime) * time.Minute}, pendingPoolTimer)
InitEventFuncMapper()
db = database.GetDatabase()
return &va
@@ -647,9 +647,9 @@
}
//RestoreUpgradeStatus - gets upgrade/migration status from DB and updates local flags
-func (va *VoltApplication) RestoreUpgradeStatus() {
+func (va *VoltApplication) RestoreUpgradeStatus(cntx context.Context) {
Migrate := new(DataMigration)
- if err := GetMigrationInfo(Migrate); err == nil {
+ if err := GetMigrationInfo(cntx, Migrate); err == nil {
if Migrate.Status == MigrationInProgress {
isUpgradeComplete = false
return
@@ -662,25 +662,25 @@
// ReadAllFromDb : If we are restarted, learn from the database the current execution
// stage
-func (va *VoltApplication) ReadAllFromDb() {
+func (va *VoltApplication) ReadAllFromDb(cntx context.Context) {
logger.Info(ctx, "Reading the meters from DB")
- va.RestoreMetersFromDb()
+ va.RestoreMetersFromDb(cntx)
logger.Info(ctx, "Reading the VNETs from DB")
- va.RestoreVnetsFromDb()
+ va.RestoreVnetsFromDb(cntx)
logger.Info(ctx, "Reading the VPVs from DB")
- va.RestoreVpvsFromDb()
+ va.RestoreVpvsFromDb(cntx)
logger.Info(ctx, "Reading the Services from DB")
- va.RestoreSvcsFromDb()
+ va.RestoreSvcsFromDb(cntx)
logger.Info(ctx, "Reading the MVLANs from DB")
- va.RestoreMvlansFromDb()
+ va.RestoreMvlansFromDb(cntx)
logger.Info(ctx, "Reading the IGMP profiles from DB")
- va.RestoreIGMPProfilesFromDb()
+ va.RestoreIGMPProfilesFromDb(cntx)
logger.Info(ctx, "Reading the Mcast configs from DB")
- va.RestoreMcastConfigsFromDb()
+ va.RestoreMcastConfigsFromDb(cntx)
logger.Info(ctx, "Reading the IGMP groups for DB")
- va.RestoreIgmpGroupsFromDb()
+ va.RestoreIgmpGroupsFromDb(cntx)
logger.Info(ctx, "Reading Upgrade status from DB")
- va.RestoreUpgradeStatus()
+ va.RestoreUpgradeStatus(cntx)
logger.Info(ctx, "Reconciled from DB")
}
@@ -723,7 +723,7 @@
// a single NNI port per OLT. This is true whether the network uses any
// protection mechanism (LAG, ERPS, etc.). The aggregate of the such protection
// is represented by a single NNI port
-func (va *VoltApplication) AddDevice(device string, slno, southBoundID string) {
+func (va *VoltApplication) AddDevice(cntx context.Context, device string, slno, southBoundID string) {
logger.Warnw(ctx, "Received Device Ind: Add", log.Fields{"Device": device, "SrNo": slno})
if _, ok := va.DevicesDisc.Load(device); ok {
logger.Warnw(ctx, "Device Exists", log.Fields{"Device": device})
@@ -742,7 +742,7 @@
nbDevice.(*NbDevice).PonPorts.Range(addPort)
} else {
// Check if NbPort exists in DB. VGC restart case.
- nbd := va.RestoreNbDeviceFromDb(southBoundID)
+ nbd := va.RestoreNbDeviceFromDb(cntx, southBoundID)
nbd.PonPorts.Range(addPort)
}
va.DevicesDisc.Store(device, d)
@@ -757,16 +757,16 @@
}
// DelDevice to delete a device.
-func (va *VoltApplication) DelDevice(device string) {
+func (va *VoltApplication) DelDevice(cntx context.Context, device string) {
logger.Warnw(ctx, "Received Device Ind: Delete", log.Fields{"Device": device})
if vdIntf, ok := va.DevicesDisc.Load(device); ok {
vd := vdIntf.(*VoltDevice)
va.DevicesDisc.Delete(device)
- _ = db.DelAllRoutesForDevice(device)
- va.HandleFlowClearFlag(device, vd.SerialNum, vd.SouthBoundID)
- _ = db.DelAllGroup(device)
- _ = db.DelAllMeter(device)
- _ = db.DelAllPorts(device)
+ _ = db.DelAllRoutesForDevice(cntx, device)
+ va.HandleFlowClearFlag(cntx, device, vd.SerialNum, vd.SouthBoundID)
+ _ = db.DelAllGroup(cntx, device)
+ _ = db.DelAllMeter(cntx, device)
+ _ = db.DelAllPorts(cntx, device)
logger.Debugw(ctx, "Device deleted", log.Fields{"Device": device})
} else {
logger.Warnw(ctx, "Device Doesn't Exist", log.Fields{"Device": device})
@@ -788,7 +788,7 @@
// PortAddInd : This is a PORT add indication coming from the VPAgent, which is essentially
// a request coming from VOLTHA. The device and identity of the port is provided
// in this request. Add them to the application for further use
-func (va *VoltApplication) PortAddInd(device string, id uint32, portName string) {
+func (va *VoltApplication) PortAddInd(cntx context.Context, device string, id uint32, portName string) {
logger.Infow(ctx, "Received Port Ind: Add", log.Fields{"Device": device, "Port": portName})
va.portLock.Lock()
if d := va.GetDevice(device); d != nil {
@@ -797,7 +797,7 @@
va.portLock.Unlock()
nni, _ := va.GetNniPort(device)
if nni == portName {
- d.pushFlowsForUnis()
+ d.pushFlowsForUnis(cntx)
}
} else {
va.portLock.Unlock()
@@ -807,13 +807,13 @@
// PortDelInd : Only the NNI ports are recorded in the device for now. When port delete
// arrives, only the NNI ports need adjustments.
-func (va *VoltApplication) PortDelInd(device string, port string) {
+func (va *VoltApplication) PortDelInd(cntx context.Context, device string, port string) {
logger.Infow(ctx, "Received Port Ind: Delete", log.Fields{"Device": device, "Port": port})
if d := va.GetDevice(device); d != nil {
p := d.GetPort(port)
if p != nil && p.State == PortStateUp {
logger.Infow(ctx, "Port state is UP. Trigerring Port Down Ind before deleting", log.Fields{"Port": p})
- va.PortDownInd(device, port)
+ va.PortDownInd(cntx, device, port)
}
va.portLock.Lock()
defer va.portLock.Unlock()
@@ -840,7 +840,7 @@
}
// AddNbPonPort Add pon port to nbDevice
-func (va *VoltApplication) AddNbPonPort(oltSbID string, portID, maxAllowedChannels uint32,
+func (va *VoltApplication) AddNbPonPort(cntx context.Context, oltSbID string, portID, maxAllowedChannels uint32,
enableMulticastKPI bool, portAlarmProfileID string) error {
var nbd *NbDevice
@@ -852,7 +852,7 @@
} else {
nbd = nbDevice.(*NbDevice)
}
- port := nbd.AddPortToNbDevice(portID, maxAllowedChannels, enableMulticastKPI, portAlarmProfileID)
+ port := nbd.AddPortToNbDevice(cntx, portID, maxAllowedChannels, enableMulticastKPI, portAlarmProfileID)
// Add this port to voltDevice
addPort := func(key, value interface{}) bool {
@@ -872,7 +872,7 @@
}
// UpdateNbPonPort update pon port to nbDevice
-func (va *VoltApplication) UpdateNbPonPort(oltSbID string, portID, maxAllowedChannels uint32, enableMulticastKPI bool, portAlarmProfileID string) error {
+func (va *VoltApplication) UpdateNbPonPort(cntx context.Context, oltSbID string, portID, maxAllowedChannels uint32, enableMulticastKPI bool, portAlarmProfileID string) error {
var nbd *NbDevice
nbDevice, ok := va.NbDevice.Load(oltSbID)
@@ -883,7 +883,7 @@
}
nbd = nbDevice.(*NbDevice)
- port := nbd.UpdatePortToNbDevice(portID, maxAllowedChannels, enableMulticastKPI, portAlarmProfileID)
+ port := nbd.UpdatePortToNbDevice(cntx, portID, maxAllowedChannels, enableMulticastKPI, portAlarmProfileID)
if port == nil {
return fmt.Errorf("Port-doesn't-exists-%v", portID)
}
@@ -913,10 +913,10 @@
}
// DeleteNbPonPort Delete pon port to nbDevice
-func (va *VoltApplication) DeleteNbPonPort(oltSbID string, portID uint32) error {
+func (va *VoltApplication) DeleteNbPonPort(cntx context.Context, oltSbID string, portID uint32) error {
nbDevice, ok := va.NbDevice.Load(oltSbID)
if ok {
- nbDevice.(*NbDevice).DeletePortFromNbDevice(portID)
+ nbDevice.(*NbDevice).DeletePortFromNbDevice(cntx, portID)
va.NbDevice.Store(oltSbID, nbDevice.(*NbDevice))
} else {
logger.Warnw(ctx, "Delete pon received for unknown device", log.Fields{"oltSbID": oltSbID})
@@ -954,19 +954,19 @@
}
// NniDownInd process for Nni down indication.
-func (va *VoltApplication) NniDownInd(deviceID string, devSrNo string) {
+func (va *VoltApplication) NniDownInd(cntx context.Context, deviceID string, devSrNo string) {
logger.Debugw(ctx, "NNI Down Ind", log.Fields{"device": devSrNo})
handleIgmpDsFlows := func(key interface{}, value interface{}) bool {
mvProfile := value.(*MvlanProfile)
- mvProfile.removeIgmpMcastFlows(devSrNo)
+ mvProfile.removeIgmpMcastFlows(cntx, devSrNo)
return true
}
va.MvlanProfilesByName.Range(handleIgmpDsFlows)
//Clear Static Group
- va.ReceiverDownInd(deviceID, StaticPort)
+ va.ReceiverDownInd(cntx, deviceID, StaticPort)
}
// DeviceUpInd changes device state to up.
@@ -990,7 +990,7 @@
}
// DeviceRebootInd process for handling flow clear flag for device reboot
-func (va *VoltApplication) DeviceRebootInd(device string, serialNum string, southBoundID string) {
+func (va *VoltApplication) DeviceRebootInd(cntx context.Context, device string, serialNum string, southBoundID string) {
logger.Warnw(ctx, "Received Device Ind: Reboot", log.Fields{"Device": device, "SerialNumber": serialNum})
if d := va.GetDevice(device); d != nil {
@@ -1000,12 +1000,12 @@
}
d.State = controller.DeviceStateREBOOTED
}
- va.HandleFlowClearFlag(device, serialNum, southBoundID)
+ va.HandleFlowClearFlag(cntx, device, serialNum, southBoundID)
}
// DeviceDisableInd handles device deactivation process
-func (va *VoltApplication) DeviceDisableInd(device string) {
+func (va *VoltApplication) DeviceDisableInd(cntx context.Context, device string) {
logger.Warnw(ctx, "Received Device Ind: Disable", log.Fields{"Device": device})
d := va.GetDevice(device)
@@ -1015,11 +1015,11 @@
}
d.State = controller.DeviceStateDISABLED
- va.HandleFlowClearFlag(device, d.SerialNum, d.SouthBoundID)
+ va.HandleFlowClearFlag(cntx, device, d.SerialNum, d.SouthBoundID)
}
// ProcessIgmpDSFlowForMvlan for processing Igmp DS flow for device
-func (va *VoltApplication) ProcessIgmpDSFlowForMvlan(d *VoltDevice, mvp *MvlanProfile, addFlow bool) {
+func (va *VoltApplication) ProcessIgmpDSFlowForMvlan(cntx context.Context, d *VoltDevice, mvp *MvlanProfile, addFlow bool) {
logger.Debugw(ctx, "Process IGMP DS Flows for MVlan", log.Fields{"device": d.Name, "Mvlan": mvp.Mvlan, "addFlow": addFlow})
portState := false
@@ -1030,20 +1030,20 @@
if addFlow {
if portState {
- mvp.pushIgmpMcastFlows(d.SerialNum)
+ mvp.pushIgmpMcastFlows(cntx, d.SerialNum)
}
} else {
- mvp.removeIgmpMcastFlows(d.SerialNum)
+ mvp.removeIgmpMcastFlows(cntx, d.SerialNum)
}
}
// ProcessIgmpDSFlowForDevice for processing Igmp DS flow for device
-func (va *VoltApplication) ProcessIgmpDSFlowForDevice(d *VoltDevice, addFlow bool) {
+func (va *VoltApplication) ProcessIgmpDSFlowForDevice(cntx context.Context, d *VoltDevice, addFlow bool) {
logger.Debugw(ctx, "Process IGMP DS Flows for device", log.Fields{"device": d.Name, "addFlow": addFlow})
handleIgmpDsFlows := func(key interface{}, value interface{}) bool {
mvProfile := value.(*MvlanProfile)
- va.ProcessIgmpDSFlowForMvlan(d, mvProfile, addFlow)
+ va.ProcessIgmpDSFlowForMvlan(cntx, d, mvProfile, addFlow)
return true
}
va.MvlanProfilesByName.Range(handleIgmpDsFlows)
@@ -1166,13 +1166,13 @@
// device - Device Obj
// vnet - vnet profile name
// enabled - vlan enabled/disabled - based on the status, the flow shall be added/removed
-func (va *VoltApplication) ProcessDevFlowForDevice(device *VoltDevice, vnet *VoltVnet, enabled bool) {
+func (va *VoltApplication) ProcessDevFlowForDevice(cntx context.Context, device *VoltDevice, vnet *VoltVnet, enabled bool) {
_, applied := device.ConfiguredVlanForDeviceFlows.Get(VnetKey(vnet.SVlan, vnet.CVlan, 0))
if enabled {
- va.PushDevFlowForVlan(vnet)
+ va.PushDevFlowForVlan(cntx, vnet)
} else if !enabled && applied {
//va.DeleteDevFlowForVlan(vnet)
- va.DeleteDevFlowForVlanFromDevice(vnet, device.SerialNum)
+ va.DeleteDevFlowForVlanFromDevice(cntx, vnet, device.SerialNum)
}
}
@@ -1212,7 +1212,7 @@
// Port UP indication is passed to all services associated with the port
// so that the services can configure flows applicable when the port goes
// up from down state
-func (va *VoltApplication) PortUpInd(device string, port string) {
+func (va *VoltApplication) PortUpInd(cntx context.Context, device string, port string) {
d := va.GetDevice(device)
if d == nil {
@@ -1264,9 +1264,9 @@
for _, vpv := range vpvs.([]*VoltPortVnet) {
vpv.VpvLock.Lock()
logger.Warnw(ctx, "Removing existing VPVs/Services flows for for Subscriber: UNI Detected on wrong PON", log.Fields{"Port": vpv.Port, "Vnet": vpv.VnetName})
- vpv.PortDownInd(device, port)
+ vpv.PortDownInd(cntx, device, port)
if vpv.IgmpEnabled {
- va.ReceiverDownInd(device, port)
+ va.ReceiverDownInd(cntx, device, port)
}
vpv.VpvLock.Unlock()
}
@@ -1288,7 +1288,7 @@
// part of service delete (during the lock wait duration)
// In that case, the services associated wil be zero
if vpv.servicesCount.Load() != 0 {
- vpv.PortUpInd(d, port)
+ vpv.PortUpInd(cntx, d, port)
}
vpv.VpvLock.Unlock()
}
@@ -1342,7 +1342,7 @@
// PortDownInd : Port down indication is passed on to the services so that the services
// can make changes at this transition.
-func (va *VoltApplication) PortDownInd(device string, port string) {
+func (va *VoltApplication) PortDownInd(cntx context.Context, device string, port string) {
logger.Infow(ctx, "Received SouthBound Port Ind: DOWN", log.Fields{"Device": device, "Port": port})
d := va.GetDevice(device)
@@ -1371,9 +1371,9 @@
if p.Type == VoltPortTypeNni {
logger.Warnw(ctx, "Received NNI Port Ind: DOWN", log.Fields{"Device": device, "Port": port})
- va.DeleteDevFlowForDevice(d)
- va.NniDownInd(device, d.SerialNum)
- va.RemovePendingGroups(device, true)
+ va.DeleteDevFlowForDevice(cntx, d)
+ va.NniDownInd(cntx, device, d.SerialNum)
+ va.RemovePendingGroups(cntx, device, true)
}
vpvs, ok := va.VnetsByPort.Load(port)
if !ok || nil == vpvs || len(vpvs.([]*VoltPortVnet)) == 0 {
@@ -1390,9 +1390,9 @@
*/
for _, vpv := range vpvs.([]*VoltPortVnet) {
vpv.VpvLock.Lock()
- vpv.PortDownInd(device, port)
+ vpv.PortDownInd(cntx, device, port)
if vpv.IgmpEnabled {
- va.ReceiverDownInd(device, port)
+ va.ReceiverDownInd(cntx, device, port)
}
vpv.VpvLock.Unlock()
}
@@ -1406,7 +1406,7 @@
// packet is decoded and the right processor is called. Currently, we
// plan to support only DHCP and IGMP. In future, we can add more
// capabilities as needed
-func (va *VoltApplication) PacketInInd(device string, port string, pkt []byte) {
+func (va *VoltApplication) PacketInInd(cntx context.Context, device string, port string, pkt []byte) {
// Decode the incoming packet
packetSide := US
if strings.Contains(port, NNI) {
@@ -1440,7 +1440,7 @@
arpl := gopkt.Layer(layers.LayerTypeARP)
if arpl != nil {
if callBack, ok := PacketHandlers[ARP]; ok {
- callBack(device, port, gopkt)
+ callBack(cntx, device, port, gopkt)
} else {
logger.Debugw(ctx, "ARP handler is not registered, dropping the packet", log.Fields{"Pkt": hex.EncodeToString(gopkt.Data())})
}
@@ -1455,7 +1455,7 @@
dhcpl := gopkt.Layer(layers.LayerTypeDHCPv4)
if dhcpl != nil {
if callBack, ok := PacketHandlers[DHCPv4]; ok {
- callBack(device, port, gopkt)
+ callBack(cntx, device, port, gopkt)
} else {
logger.Debugw(ctx, "DHCPv4 handler is not registered, dropping the packet", log.Fields{"Pkt": hex.EncodeToString(gopkt.Data())})
}
@@ -1463,7 +1463,7 @@
} else if ip.Protocol == layers.IPProtocolIGMP {
logger.Debugw(ctx, "Received Southbound IGMP packet in", log.Fields{"StreamSide": packetSide})
if callBack, ok := PacketHandlers[IGMP]; ok {
- callBack(device, port, gopkt)
+ callBack(cntx, device, port, gopkt)
} else {
logger.Debugw(ctx, "IGMP handler is not registered, dropping the packet", log.Fields{"Pkt": hex.EncodeToString(gopkt.Data())})
}
@@ -1478,7 +1478,7 @@
dhcpl := gopkt.Layer(layers.LayerTypeDHCPv6)
if dhcpl != nil {
if callBack, ok := PacketHandlers[DHCPv6]; ok {
- callBack(device, port, gopkt)
+ callBack(cntx, device, port, gopkt)
} else {
logger.Debugw(ctx, "DHCPv6 handler is not registered, dropping the packet", log.Fields{"Pkt": hex.EncodeToString(gopkt.Data())})
}
@@ -1491,7 +1491,7 @@
if pppoel != nil {
logger.Debugw(ctx, "Received Southbound PPPoE packet in", log.Fields{"StreamSide": packetSide})
if callBack, ok := PacketHandlers[PPPOE]; ok {
- callBack(device, port, gopkt)
+ callBack(cntx, device, port, gopkt)
} else {
logger.Debugw(ctx, "PPPoE handler is not registered, dropping the packet", log.Fields{"Pkt": hex.EncodeToString(gopkt.Data())})
}
@@ -1528,7 +1528,7 @@
}
// HandleFlowClearFlag to handle flow clear flag during reboot
-func (va *VoltApplication) HandleFlowClearFlag(deviceID string, serialNum, southBoundID string) {
+func (va *VoltApplication) HandleFlowClearFlag(cntx context.Context, deviceID string, serialNum, southBoundID string) {
logger.Warnw(ctx, "Clear All flags for Device", log.Fields{"Device": deviceID, "SerialNum": serialNum, "SBID": southBoundID})
dev, ok := va.DevicesDisc.Load(deviceID)
if ok && dev != nil {
@@ -1557,13 +1557,13 @@
logger.Infow(ctx, "Clear Flags for vpv",
log.Fields{"device": vpv.Device, "port": vpv.Port,
"svlan": vpv.SVlan, "cvlan": vpv.CVlan, "univlan": vpv.UniVlan})
- vpv.ClearAllServiceFlags()
- vpv.ClearAllVpvFlags()
+ vpv.ClearAllServiceFlags(cntx)
+ vpv.ClearAllVpvFlags(cntx)
if vpv.IgmpEnabled {
- va.ReceiverDownInd(vpv.Device, vpv.Port)
+ va.ReceiverDownInd(cntx, vpv.Device, vpv.Port)
//Also clear service igmp stats
- vpv.ClearServiceCounters()
+ vpv.ClearServiceCounters(cntx)
}
}
}
@@ -1572,12 +1572,12 @@
va.VnetsByPort.Range(getVpvs)
//Clear Static Group
- va.ReceiverDownInd(deviceID, StaticPort)
+ va.ReceiverDownInd(cntx, deviceID, StaticPort)
logger.Warnw(ctx, "All flags cleared for device", log.Fields{"Device": deviceID})
//Reset pending group pool
- va.RemovePendingGroups(deviceID, true)
+ va.RemovePendingGroups(cntx, deviceID, true)
//Process all Migrate Service Request - force udpate all profiles since resources are already cleaned up
if dev != nil {
@@ -1585,7 +1585,7 @@
msrList := value.(*util.ConcurrentMap)
forceUpdateServices := func(key, value interface{}) bool {
msr := value.(*MigrateServicesRequest)
- forceUpdateAllServices(msr)
+ forceUpdateAllServices(cntx, msr)
return true
}
msrList.Range(forceUpdateServices)
@@ -1593,7 +1593,7 @@
}
dev.(*VoltDevice).MigratingServices.Range(triggerForceUpdate)
} else {
- va.FetchAndProcessAllMigrateServicesReq(deviceID, forceUpdateAllServices)
+ va.FetchAndProcessAllMigrateServicesReq(cntx, deviceID, forceUpdateAllServices)
}
}
@@ -1604,7 +1604,7 @@
}
//ProcessFlowModResultIndication - Processes Flow mod operation indications from controller
-func (va *VoltApplication) ProcessFlowModResultIndication(flowStatus intf.FlowStatus) {
+func (va *VoltApplication) ProcessFlowModResultIndication(cntx context.Context, flowStatus intf.FlowStatus) {
d := va.GetDevice(flowStatus.Device)
if d == nil {
@@ -1612,7 +1612,7 @@
return
}
- cookieExists := ExecuteFlowEvent(d, flowStatus.Cookie, flowStatus)
+ cookieExists := ExecuteFlowEvent(cntx, d, flowStatus.Cookie, flowStatus)
if flowStatus.Flow != nil {
flowAdd := (flowStatus.FlowModType == of.CommandAdd)
@@ -1670,12 +1670,12 @@
}
//UpdateMvlanProfilesForDevice to update mvlan profile for device
-func (va *VoltApplication) UpdateMvlanProfilesForDevice(device string) {
+func (va *VoltApplication) UpdateMvlanProfilesForDevice(cntx context.Context, device string) {
checkAndAddMvlanUpdateTask := func(key, value interface{}) bool {
mvp := value.(*MvlanProfile)
if mvp.IsUpdateInProgressForDevice(device) {
- mvp.UpdateProfile(device)
+ mvp.UpdateProfile(cntx, device)
}
return true
}
@@ -1867,26 +1867,26 @@
}
//RemoveGroupsFromPendingPool - removes the group from global pending group pool
-func (va *VoltApplication) RemoveGroupsFromPendingPool(device string, mvlan of.VlanType) {
+func (va *VoltApplication) RemoveGroupsFromPendingPool(cntx context.Context, device string, mvlan of.VlanType) {
GetApplication().PendingPoolLock.Lock()
defer GetApplication().PendingPoolLock.Unlock()
logger.Infow(ctx, "Removing IgmpGroups from Global Pending Pool for given Deivce & Mvlan", log.Fields{"Device": device, "Mvlan": mvlan.String()})
key := getPendingPoolKey(mvlan, device)
- va.RemoveGroupListFromPendingPool(key)
+ va.RemoveGroupListFromPendingPool(cntx, key)
}
//RemoveGroupListFromPendingPool - removes the groups for provided key
// 1. Deletes the group from device
// 2. Delete the IgmpGroup obj and release the group ID to pool
// Note: Make sure to obtain PendingPoolLock lock before calling this func
-func (va *VoltApplication) RemoveGroupListFromPendingPool(key string) {
+func (va *VoltApplication) RemoveGroupListFromPendingPool(cntx context.Context, key string) {
if grpMap, ok := va.IgmpPendingPool[key]; ok {
delete(va.IgmpPendingPool, key)
for ig := range grpMap {
for device := range ig.Devices {
- ig.DeleteIgmpGroupDevice(device)
+ ig.DeleteIgmpGroupDevice(cntx, device)
}
}
}
@@ -1942,7 +1942,7 @@
// reference - mvlan/device ID
// isRefDevice - true - Device as reference
// false - Mvlan as reference
-func (va *VoltApplication) RemovePendingGroups(reference string, isRefDevice bool) {
+func (va *VoltApplication) RemovePendingGroups(cntx context.Context, reference string, isRefDevice bool) {
va.PendingPoolLock.Lock()
defer va.PendingPoolLock.Unlock()
@@ -1960,7 +1960,7 @@
for key := range va.IgmpPendingPool {
keyParams := strings.Split(key, "_")
if keyParams[paramPosition] == reference {
- va.RemoveGroupListFromPendingPool(key)
+ va.RemoveGroupListFromPendingPool(cntx, key)
}
}
}
@@ -1969,26 +1969,26 @@
return mvlan.String() + "_" + device
}
-func (va *VoltApplication) removeExpiredGroups() {
+func (va *VoltApplication) removeExpiredGroups(cntx context.Context) {
logger.Debug(ctx, "Check for expired Igmp Groups")
removeExpiredGroups := func(key interface{}, value interface{}) bool {
ig := value.(*IgmpGroup)
- ig.removeExpiredGroupFromDevice()
+ ig.removeExpiredGroupFromDevice(cntx)
return true
}
va.IgmpGroups.Range(removeExpiredGroups)
}
//TriggerPendingProfileDeleteReq - trigger pending profile delete request
-func (va *VoltApplication) TriggerPendingProfileDeleteReq(device string) {
- va.TriggerPendingServiceDeleteReq(device)
- va.TriggerPendingVpvDeleteReq(device)
- va.TriggerPendingVnetDeleteReq(device)
+func (va *VoltApplication) TriggerPendingProfileDeleteReq(cntx context.Context, device string) {
+ va.TriggerPendingServiceDeleteReq(cntx, device)
+ va.TriggerPendingVpvDeleteReq(cntx, device)
+ va.TriggerPendingVnetDeleteReq(cntx, device)
logger.Warnw(ctx, "All Pending Profile Delete triggered for device", log.Fields{"Device": device})
}
//TriggerPendingServiceDeleteReq - trigger pending service delete request
-func (va *VoltApplication) TriggerPendingServiceDeleteReq(device string) {
+func (va *VoltApplication) TriggerPendingServiceDeleteReq(cntx context.Context, device string) {
logger.Warnw(ctx, "Pending Services to be deleted", log.Fields{"Count": len(va.ServicesToDelete)})
for serviceName := range va.ServicesToDelete {
@@ -1996,9 +1996,9 @@
if vs := va.GetService(serviceName); vs != nil {
if vs.Device == device {
logger.Warnw(ctx, "Triggering Pending Service delete", log.Fields{"Service": vs.Name})
- vs.DelHsiaFlows()
+ vs.DelHsiaFlows(cntx)
if vs.ForceDelete {
- vs.DelFromDb()
+ vs.DelFromDb(cntx)
/*
portState := msgbus.PortDown
if d, err := va.GetDeviceFromPort(vs.Port); d != nil {
@@ -2027,19 +2027,19 @@
}
//TriggerPendingVpvDeleteReq - trigger pending VPV delete request
-func (va *VoltApplication) TriggerPendingVpvDeleteReq(device string) {
+func (va *VoltApplication) TriggerPendingVpvDeleteReq(cntx context.Context, device string) {
logger.Warnw(ctx, "Pending VPVs to be deleted", log.Fields{"Count": len(va.VoltPortVnetsToDelete)})
for vpv := range va.VoltPortVnetsToDelete {
if vpv.Device == device {
logger.Warnw(ctx, "Triggering Pending VPv flow delete", log.Fields{"Port": vpv.Port, "Device": vpv.Device, "Vnet": vpv.VnetName})
- va.DelVnetFromPort(vpv.Port, vpv)
+ va.DelVnetFromPort(cntx, vpv.Port, vpv)
}
}
}
//TriggerPendingVnetDeleteReq - trigger pending vnet delete request
-func (va *VoltApplication) TriggerPendingVnetDeleteReq(device string) {
+func (va *VoltApplication) TriggerPendingVnetDeleteReq(cntx context.Context, device string) {
logger.Warnw(ctx, "Pending Vnets to be deleted", log.Fields{"Count": len(va.VnetsToDelete)})
for vnetName := range va.VnetsToDelete {
@@ -2047,7 +2047,7 @@
vnet := vnetIntf.(*VoltVnet)
logger.Warnw(ctx, "Triggering Pending Vnet flows delete", log.Fields{"Vnet": vnet.Name})
if d := va.GetDeviceBySerialNo(vnet.PendingDeviceToDelete); d != nil && d.SerialNum == vnet.PendingDeviceToDelete {
- va.DeleteDevFlowForVlanFromDevice(vnet, vnet.PendingDeviceToDelete)
+ va.DeleteDevFlowForVlanFromDevice(cntx, vnet, vnet.PendingDeviceToDelete)
va.deleteVnetConfig(vnet)
} else {
logger.Warnw(ctx, "Vnet Delete Failed : Device Not Found", log.Fields{"Vnet": vnet.Name, "Device": vnet.PendingDeviceToDelete})
diff --git a/internal/pkg/application/dhcprelay.go b/internal/pkg/application/dhcprelay.go
index c57771c..b779f1f 100644
--- a/internal/pkg/application/dhcprelay.go
+++ b/internal/pkg/application/dhcprelay.go
@@ -17,6 +17,7 @@
import (
"encoding/hex"
+ "context"
"errors"
"net"
"sync"
@@ -93,9 +94,9 @@
GetDhcpv6State() Dhcpv6RelayState
SetDhcpState(DhcpRelayState)
SetDhcpv6State(Dhcpv6RelayState)
- SetMacAddr(net.HardwareAddr)
- DhcpResultInd(*layers.DHCPv4)
- Dhcpv6ResultInd(ipv6Addr net.IP, leaseTime uint32)
+ SetMacAddr(context.Context, net.HardwareAddr)
+ DhcpResultInd(context.Context, *layers.DHCPv4)
+ Dhcpv6ResultInd(cntx context.Context, ipv6Addr net.IP, leaseTime uint32)
}
// DhcpRelayVnet : The DHCP relay sessions are stored in a map to be retrieved from when
@@ -547,7 +548,7 @@
// session is derived from the list of DHCP sessions stored in the
// common map. The key for retrieval includes the VLAN tags in the
// the packet and the MAC address of the client.
-func (va *VoltApplication) ProcessDsDhcpv4Packet(device string, port string, pkt gopacket.Packet) {
+func (va *VoltApplication) ProcessDsDhcpv4Packet(cntx context.Context, device string, port string, pkt gopacket.Packet) {
// Retrieve the layers to build the outgoing packet. It is not
// possible to add/remove layers to the existing packet and thus
@@ -600,9 +601,9 @@
// flow installation request, VGC to update US HSIA flow with leanrt MAC.
// separate go rotuine is spawned to avoid drop of ACK packet
// as HSIA flows will be deleted if new MAC is learnt.
- go vpv.SetMacAddr(dhcp4.ClientHWAddr)
+ go vpv.SetMacAddr(cntx, dhcp4.ClientHWAddr)
}
- vpv.DhcpResultInd(dhcp4)
+ vpv.DhcpResultInd(cntx, dhcp4)
}
raiseDHCPv4Indication(msgType, vpv, dhcp4.ClientHWAddr, ipAddr, dsPbit, device, leaseTime)
@@ -761,7 +762,7 @@
// ProcessUsDhcpv4Packet : The US DHCPv4 packet is identified the DHCP OP in the packet. A request is considered upstream
// and the service associated with the packet is located by the port and VLANs in the packet
-func (va *VoltApplication) ProcessUsDhcpv4Packet(device string, port string, pkt gopacket.Packet) {
+func (va *VoltApplication) ProcessUsDhcpv4Packet(cntx context.Context, device string, port string, pkt gopacket.Packet) {
// We received the packet on an access port and the service for the packet can be
// gotten from the port and the packet
vpv, svc := va.GetVnetFromPkt(device, port, pkt)
@@ -819,7 +820,7 @@
if NonZeroMacAddress(vpv.MacAddr) && vpv.MacLearning == Learn {
// update learnt mac for debug purpose
vpv.LearntMacAddr = dhcp4.ClientHWAddr
- vpv.WriteToDb()
+ vpv.WriteToDb(cntx)
logger.Warnw(ctx, "Dropping the packet Mac relearn is disabled",
log.Fields{"vpv.MacAddr": vpv.MacAddr, "LearntMac": dhcp4.ClientHWAddr})
return
@@ -923,13 +924,13 @@
}
// ProcessUDP4Packet : CallBack function registered with application to handle DHCP packetIn
-func ProcessUDP4Packet(device string, port string, pkt gopacket.Packet) {
- GetApplication().ProcessUDP4Packet(device, port, pkt)
+func ProcessUDP4Packet(cntx context.Context, device string, port string, pkt gopacket.Packet) {
+ GetApplication().ProcessUDP4Packet(cntx, device, port, pkt)
}
// ProcessUDP4Packet : The packet is a UDP packet and currently only DHCP relay application is supported
// We determine the packet direction and process it based on the direction
-func (va *VoltApplication) ProcessUDP4Packet(device string, port string, pkt gopacket.Packet) {
+func (va *VoltApplication) ProcessUDP4Packet(cntx context.Context, device string, port string, pkt gopacket.Packet) {
// Currently DHCP is the only application supported by the application
// We check for DHCP before proceeding futher. In future, this could be
// based on registration and the callbacks
@@ -943,17 +944,17 @@
// This is treated as an upstream packet in the VOLT application
// as VOLT serves access subscribers who use DHCP to acquire IP
// address and these packets go upstream to the network
- va.ProcessUsDhcpv4Packet(device, port, pkt)
+ va.ProcessUsDhcpv4Packet(cntx, device, port, pkt)
} else {
// This is a downstream packet
- va.ProcessDsDhcpv4Packet(device, port, pkt)
+ va.ProcessDsDhcpv4Packet(cntx, device, port, pkt)
}
}
// ProcessUDP6Packet : CallBack function registered with application to handle DHCPv6 packetIn
-func ProcessUDP6Packet(device string, port string, pkt gopacket.Packet) {
- GetApplication().ProcessUDP6Packet(device, port, pkt)
+func ProcessUDP6Packet(cntx context.Context, device string, port string, pkt gopacket.Packet) {
+ GetApplication().ProcessUDP6Packet(cntx, device, port, pkt)
}
// ProcessUDP6Packet : As a LDRA node, we expect to see only RelayReply from the DHCP server and we always
@@ -962,7 +963,7 @@
// we should also see Renew. However, we should always pack the US message by adding
// additional option that identifies to the server that the DHCP packet is forwarded
// by an LDRA node.
-func (va *VoltApplication) ProcessUDP6Packet(device string, port string, pkt gopacket.Packet) []byte {
+func (va *VoltApplication) ProcessUDP6Packet(cntx context.Context, device string, port string, pkt gopacket.Packet) []byte {
dhcpl := pkt.Layer(layers.LayerTypeDHCPv6)
if dhcpl == nil {
return nil
@@ -973,14 +974,14 @@
case layers.DHCPv6MsgTypeSolicit, layers.DHCPv6MsgTypeRequest, layers.DHCPv6MsgTypeRenew,
layers.DHCPv6MsgTypeRelease, layers.DHCPv6MsgTypeRebind, layers.DHCPv6MsgTypeInformationRequest,
layers.DHCPv6MsgTypeDecline:
- va.ProcessUsDhcpv6Packet(device, port, pkt)
+ va.ProcessUsDhcpv6Packet(cntx, device, port, pkt)
case layers.DHCPv6MsgTypeAdvertise, layers.DHCPv6MsgTypeConfirm, layers.DHCPv6MsgTypeReconfigure:
logger.Warnw(ctx, "SouthBound DHCPv6 DS Messages Expected For a Relay Agent", log.Fields{"Type": dhcpv6.MsgType})
case layers.DHCPv6MsgTypeRelayForward:
logger.Warn(ctx, "As the first DHCPv6 Relay Agent, Unexpected Relay Forward")
case layers.DHCPv6MsgTypeRelayReply:
// We received a response from the server
- va.ProcessDsDhcpv6Packet(device, port, pkt)
+ va.ProcessDsDhcpv6Packet(cntx, device, port, pkt)
}
return nil
}
@@ -1017,7 +1018,7 @@
}
// ProcessUsDhcpv6Packet to rpocess upstream DHCPv6 packet
-func (va *VoltApplication) ProcessUsDhcpv6Packet(device string, port string, pkt gopacket.Packet) {
+func (va *VoltApplication) ProcessUsDhcpv6Packet(cntx context.Context, device string, port string, pkt gopacket.Packet) {
// We received the packet on an access port and the service for the packet can be
// gotten from the port and the packet
logger.Infow(ctx, "Processing Southbound US DHCPv6 packet", log.Fields{"Port": port})
@@ -1092,7 +1093,7 @@
if NonZeroMacAddress(vpv.MacAddr) && vpv.MacLearning == Learn {
// update learnt mac for debug purpose
vpv.LearntMacAddr = sourceMac
- vpv.WriteToDb()
+ vpv.WriteToDb(cntx)
logger.Warnw(ctx, "Dropping the packet Mac relearn is disabled",
log.Fields{"vpv.MacAddr": vpv.MacAddr, "LearntMac": sourceMac})
return
@@ -1191,7 +1192,7 @@
}
// ProcessDsDhcpv6Packet to process downstream dhcpv6 packet
-func (va *VoltApplication) ProcessDsDhcpv6Packet(device string, port string, pkt gopacket.Packet) {
+func (va *VoltApplication) ProcessDsDhcpv6Packet(cntx context.Context, device string, port string, pkt gopacket.Packet) {
logger.Infow(ctx, "Processing Southbound DS DHCPv6 packet", log.Fields{"Port": port})
logger.Debugw(ctx, "Packet IN", log.Fields{"Pkt": hex.EncodeToString(pkt.Data())})
@@ -1249,9 +1250,9 @@
// separate go rotuine is spawned to avoid drop of ACK packet
// as HSIA flows will be deleted if new MAC is learnt.
if len(vpvList) == 1 {
- go vpv.SetMacAddr(clientMac)
+ go vpv.SetMacAddr(cntx, clientMac)
}
- vpv.Dhcpv6ResultInd(ipv6Addr, leaseTime)
+ vpv.Dhcpv6ResultInd(cntx, ipv6Addr, leaseTime)
}
raiseDHCPv6Indication(dhcp6.MsgType, vpv, clientMac, ipv6Addr, dsPbit, device, leaseTime)
}
diff --git a/internal/pkg/application/flowevent.go b/internal/pkg/application/flowevent.go
index f6f3584..fe37b74 100644
--- a/internal/pkg/application/flowevent.go
+++ b/internal/pkg/application/flowevent.go
@@ -16,6 +16,8 @@
package application
import (
+ "context"
+
infraerrorcode "voltha-go-controller/internal/pkg/errorcodes/service"
"voltha-go-controller/internal/pkg/intf"
@@ -29,7 +31,7 @@
type FlowEventType string
//FlowEventHandler - Func prototype for flow event handling funcs
-type FlowEventHandler func(*FlowEvent, intf.FlowStatus)
+type FlowEventHandler func(context.Context, *FlowEvent, intf.FlowStatus)
var eventMapper map[FlowEventType]FlowEventHandler
@@ -74,7 +76,7 @@
}
//ExecuteFlowEvent - Process flow based event triggers
-func ExecuteFlowEvent(vd *VoltDevice, cookie string, flowStatus intf.FlowStatus) bool {
+func ExecuteFlowEvent(cntx context.Context, vd *VoltDevice, cookie string, flowStatus intf.FlowStatus) bool {
var event interface{}
flowEventMap, err := vd.GetFlowEventRegister(flowStatus.FlowModType)
@@ -92,12 +94,12 @@
flowEventMap.Remove(cookie)
flowEventMap.MapLock.Unlock()
flowEvent := event.(*FlowEvent)
- eventMapper[flowEvent.eType](flowEvent, flowStatus)
+ eventMapper[flowEvent.eType](cntx, flowEvent, flowStatus)
return true
}
//ProcessUsIgmpFlowAddEvent - Process Us Igmp Flow event trigger
-func ProcessUsIgmpFlowAddEvent(event *FlowEvent, flowStatus intf.FlowStatus) {
+func ProcessUsIgmpFlowAddEvent(cntx context.Context, event *FlowEvent, flowStatus intf.FlowStatus) {
logger.Infow(ctx, "Processing Post Flow Add Event for US Igmp", log.Fields{"Cookie": event.cookie, "event": event})
vpv := event.eventData.(*VoltPortVnet)
@@ -109,19 +111,19 @@
}
//ProcessServiceFlowAddEvent - Process Service Flow event trigger
-func ProcessServiceFlowAddEvent(event *FlowEvent, flowStatus intf.FlowStatus) {
+func ProcessServiceFlowAddEvent(cntx context.Context, event *FlowEvent, flowStatus intf.FlowStatus) {
logger.Infow(ctx, "Processing Post Flow Add Event for Service", log.Fields{"Cookie": event.cookie, "event": event})
vs := event.eventData.(*VoltService)
if isFlowStatusSuccess(flowStatus.Status, true) {
- vs.FlowInstallSuccess(event.cookie, flowStatus.AdditionalData)
+ vs.FlowInstallSuccess(cntx, event.cookie, flowStatus.AdditionalData)
} else {
vs.FlowInstallFailure(event.cookie, flowStatus.Status, flowStatus.Reason)
}
}
//ProcessControlFlowAddEvent - Process Control Flow event trigger
-func ProcessControlFlowAddEvent(event *FlowEvent, flowStatus intf.FlowStatus) {
+func ProcessControlFlowAddEvent(cntx context.Context, event *FlowEvent, flowStatus intf.FlowStatus) {
logger.Infow(ctx, "Processing Post Flow Add Event for VPV", log.Fields{"Cookie": event.cookie, "event": event})
vpv := event.eventData.(*VoltPortVnet)
@@ -131,50 +133,50 @@
}
//ProcessServiceFlowDelEvent - Process Service Flow event trigger
-func ProcessServiceFlowDelEvent(event *FlowEvent, flowStatus intf.FlowStatus) {
+func ProcessServiceFlowDelEvent(cntx context.Context, event *FlowEvent, flowStatus intf.FlowStatus) {
logger.Infow(ctx, "Processing Post Flow Remove Event for Service", log.Fields{"Cookie": event.cookie, "event": event})
vs := event.eventData.(*VoltService)
if isFlowStatusSuccess(flowStatus.Status, false) {
- vs.FlowRemoveSuccess(event.cookie)
+ vs.FlowRemoveSuccess(cntx, event.cookie)
} else {
- vs.FlowRemoveFailure(event.cookie, flowStatus.Status, flowStatus.Reason)
+ vs.FlowRemoveFailure(cntx, event.cookie, flowStatus.Status, flowStatus.Reason)
}
}
//ProcessControlFlowDelEvent - Process Control Flow event trigger
-func ProcessControlFlowDelEvent(event *FlowEvent, flowStatus intf.FlowStatus) {
+func ProcessControlFlowDelEvent(cntx context.Context, event *FlowEvent, flowStatus intf.FlowStatus) {
logger.Infow(ctx, "Processing Post Flow Remove Event for VPV", log.Fields{"Cookie": event.cookie, "event": event})
vpv := event.eventData.(*VoltPortVnet)
if isFlowStatusSuccess(flowStatus.Status, false) {
- vpv.FlowRemoveSuccess(event.cookie, event.device)
+ vpv.FlowRemoveSuccess(cntx, event.cookie, event.device)
} else {
- vpv.FlowRemoveFailure(event.cookie, event.device, flowStatus.Status, flowStatus.Reason)
+ vpv.FlowRemoveFailure(cntx, event.cookie, event.device, flowStatus.Status, flowStatus.Reason)
}
}
//ProcessMcastFlowDelEvent - Process Control Flow event trigger
-func ProcessMcastFlowDelEvent(event *FlowEvent, flowStatus intf.FlowStatus) {
+func ProcessMcastFlowDelEvent(cntx context.Context, event *FlowEvent, flowStatus intf.FlowStatus) {
logger.Infow(ctx, "Processing Post Flow Remove Event for Mcast/Igmp", log.Fields{"Cookie": event.cookie, "event": event})
mvp := event.eventData.(*MvlanProfile)
if isFlowStatusSuccess(flowStatus.Status, false) {
- mvp.FlowRemoveSuccess(event.cookie, event.device)
+ mvp.FlowRemoveSuccess(cntx, event.cookie, event.device)
} else {
mvp.FlowRemoveFailure(event.cookie, event.device, flowStatus.Status, flowStatus.Reason)
}
}
//ProcessDeviceFlowDelEvent - Process Control Flow event trigger
-func ProcessDeviceFlowDelEvent(event *FlowEvent, flowStatus intf.FlowStatus) {
+func ProcessDeviceFlowDelEvent(cntx context.Context, event *FlowEvent, flowStatus intf.FlowStatus) {
logger.Infow(ctx, "Processing Post Flow Remove Event for VNET", log.Fields{"Cookie": event.cookie, "event": event})
vnet := event.eventData.(*VoltVnet)
if isFlowStatusSuccess(flowStatus.Status, false) {
- vnet.FlowRemoveSuccess(event.cookie, event.device)
+ vnet.FlowRemoveSuccess(cntx, event.cookie, event.device)
} else {
- vnet.FlowRemoveFailure(event.cookie, event.device, flowStatus.Status, flowStatus.Reason)
+ vnet.FlowRemoveFailure(cntx, event.cookie, event.device, flowStatus.Status, flowStatus.Reason)
}
}
diff --git a/internal/pkg/application/igmp.go b/internal/pkg/application/igmp.go
index 32eed0d..2e49a41 100644
--- a/internal/pkg/application/igmp.go
+++ b/internal/pkg/application/igmp.go
@@ -16,6 +16,7 @@
package application
import (
+ "context"
"encoding/json"
"errors"
"net"
@@ -106,7 +107,7 @@
}
// ProcessIgmpPacket : CallBack function registered with application to handle IGMP packetIn
-func ProcessIgmpPacket(device string, port string, pkt gopacket.Packet) {
+func ProcessIgmpPacket(cntx context.Context, device string, port string, pkt gopacket.Packet) {
GetApplication().IgmpPacketInd(device, port, pkt)
}
@@ -420,7 +421,7 @@
}
//AddToPendingPool - adds Igmp Device obj to pending pool
-func AddToPendingPool(device string, groupKey string) bool {
+func AddToPendingPool(cntx context.Context, device string, groupKey string) bool {
logger.Infow(ctx, "Add Device to IgmpGroup Pending Pool", log.Fields{"Device": device, "GroupKey": groupKey})
if grp, ok := GetApplication().IgmpGroups.Load(groupKey); ok {
@@ -429,7 +430,7 @@
logger.Infow(ctx, "Adding Device to IgmpGroup Pending Pool", log.Fields{"Device": device, "GroupID": ig.GroupID, "GroupName": ig.GroupName, "GroupAddr": ig.GroupAddr.String()})
ig.PendingGroupForDevice[device] = time.Now().Add(time.Duration(GroupExpiryTime) * time.Minute)
ig.PendingPoolLock.Unlock()
- if err := ig.WriteToDb(); err != nil {
+ if err := ig.WriteToDb(cntx); err != nil {
logger.Errorw(ctx, "Igmp group Write to DB failed", log.Fields{"groupName": ig.GroupName})
}
return true
@@ -504,9 +505,9 @@
}
// RestoreIgmpGroupsFromDb to restore igmp groups from database
-func (va *VoltApplication) RestoreIgmpGroupsFromDb() {
+func (va *VoltApplication) RestoreIgmpGroupsFromDb(cntx context.Context) {
- groups, _ := db.GetIgmpGroups()
+ groups, _ := db.GetIgmpGroups(cntx)
for _, group := range groups {
b, ok := group.Value.([]byte)
if !ok {
@@ -532,7 +533,7 @@
if _, err := va.GetIgmpGroupID(ig.GroupID); err != nil {
logger.Warnw(ctx, "GetIgmpGroupID Failed", log.Fields{"igGroupID": ig.GroupID, "Error": err})
}
- ig.RestoreDevices()
+ ig.RestoreDevices(cntx)
if ig.NumDevicesActive() == 0 {
va.AddGroupToPendingPool(&ig)
@@ -544,16 +545,16 @@
// AddIgmpGroup : When the first IGMP packet is received, the MVLAN profile is identified
// for the IGMP group and grp obj is obtained from the available pending pool of groups.
// If not, new group obj will be created based on available group IDs
-func (va *VoltApplication) AddIgmpGroup(mvpName string, gip net.IP, device string) *IgmpGroup {
+func (va *VoltApplication) AddIgmpGroup(cntx context.Context, mvpName string, gip net.IP, device string) *IgmpGroup {
var ig *IgmpGroup
if mvp, grpName := va.GetMvlanProfileForMcIP(mvpName, gip); mvp != nil {
if ig = va.GetGroupFromPendingPool(mvp.Mvlan, device); ig != nil {
logger.Infow(ctx, "Igmp Group obtained from global pending pool", log.Fields{"MvlanProfile": mvpName, "GroupID": ig.GroupID, "Device": device, "GroupName": ig.GroupName, "GroupAddr": ig.GroupAddr.String()})
oldKey := mvp.generateGroupKey(ig.GroupName, ig.GroupAddr.String())
- ig.IgmpGroupReInit(grpName, gip)
+ ig.IgmpGroupReInit(cntx, grpName, gip)
ig.IsGroupStatic = mvp.Groups[grpName].IsStatic
- ig.UpdateIgmpGroup(oldKey, ig.getKey())
+ ig.UpdateIgmpGroup(cntx, oldKey, ig.getKey())
} else {
logger.Infow(ctx, "No Igmp Group available in global pending pool. Creating new Igmp Group", log.Fields{"MvlanProfile": mvpName, "Device": device, "GroupAddr": gip.String()})
if ig = va.GetAvailIgmpGroupID(); ig == nil {
@@ -564,7 +565,7 @@
grpKey := ig.getKey()
va.IgmpGroups.Store(grpKey, ig)
}
- if err := ig.WriteToDb(); err != nil {
+ if err := ig.WriteToDb(cntx); err != nil {
logger.Errorw(ctx, "Igmp group Write to DB failed", log.Fields{"groupName": ig.GroupName})
}
return ig
@@ -606,7 +607,7 @@
// DelIgmpGroup : When the last subscriber leaves the IGMP group across all the devices
// the IGMP group is removed.
-func (va *VoltApplication) DelIgmpGroup(ig *IgmpGroup) {
+func (va *VoltApplication) DelIgmpGroup(cntx context.Context, ig *IgmpGroup) {
profile, found := GetApplication().MvlanProfilesByTag.Load(ig.Mvlan)
if found {
@@ -621,11 +622,11 @@
logger.Debugw(ctx, "Deleting IGMP Group", log.Fields{"Group": grpKey})
va.PutIgmpGroupID(ig)
va.IgmpGroups.Delete(grpKey)
- _ = db.DelIgmpGroup(grpKey)
+ _ = db.DelIgmpGroup(cntx, grpKey)
} else {
logger.Infow(ctx, "Skipping IgmpGroup Device. Pending Igmp Group Devices present", log.Fields{"GroupID": ig.GroupID, "GroupName": ig.GroupName, "GroupAddr": ig.GroupAddr.String(), "PendingDevices": len(ig.Devices)})
va.AddGroupToPendingPool(ig)
- if err := ig.WriteToDb(); err != nil {
+ if err := ig.WriteToDb(cntx); err != nil {
logger.Errorw(ctx, "Igmp group Write to DB failed", log.Fields{"groupName": ig.GroupName})
}
}
@@ -807,7 +808,7 @@
}
// ProcessIgmpv2Pkt : This is IGMPv2 packet.
-func (va *VoltApplication) ProcessIgmpv2Pkt(device string, port string, pkt gopacket.Packet) {
+func (va *VoltApplication) ProcessIgmpv2Pkt(cntx context.Context, device string, port string, pkt gopacket.Packet) {
// First get the layers of interest
dot1Q := pkt.Layer(layers.LayerTypeDot1Q).(*layers.Dot1Q)
pktVlan := of.VlanType(dot1Q.VLANIdentifier)
@@ -868,11 +869,11 @@
ig.IgmpGroupLock.Unlock()
return
}
- ig.AddReceiver(device, port, igmpv2.GroupAddress, nil, IgmpVersion2, dot1Q.VLANIdentifier, dot1Q.Priority, ponPortID)
+ ig.AddReceiver(cntx, device, port, igmpv2.GroupAddress, nil, IgmpVersion2, dot1Q.VLANIdentifier, dot1Q.Priority, ponPortID)
ig.IgmpGroupLock.Unlock()
} else {
// Create the IGMP group and then add the receiver to the group
- if ig := va.AddIgmpGroup(vpv.MvlanProfileName, igmpv2.GroupAddress, device); ig != nil {
+ if ig := va.AddIgmpGroup(cntx, vpv.MvlanProfileName, igmpv2.GroupAddress, device); ig != nil {
logger.Infow(ctx, "New IGMP Group", log.Fields{"Group": ig.GroupID, "devices": ig.Devices})
ig.IgmpGroupLock.Lock()
// Check for port state to avoid race condition where PortDown event
@@ -885,7 +886,7 @@
ig.IgmpGroupLock.Unlock()
return
}
- ig.AddReceiver(device, port, igmpv2.GroupAddress, nil, IgmpVersion2, dot1Q.VLANIdentifier, dot1Q.Priority, ponPortID)
+ ig.AddReceiver(cntx, device, port, igmpv2.GroupAddress, nil, IgmpVersion2, dot1Q.VLANIdentifier, dot1Q.Priority, ponPortID)
ig.IgmpGroupLock.Unlock()
} else {
logger.Errorw(ctx, "IGMP Group Creation Failed", log.Fields{"Addr": igmpv2.GroupAddress})
@@ -914,10 +915,10 @@
if ig := va.GetIgmpGroup(mvlan, igmpv2.GroupAddress); ig != nil {
ig.IgmpGroupLock.Lock()
// Delete the receiver once the IgmpGroup is identified
- ig.DelReceiver(device, port, igmpv2.GroupAddress, nil, ponPortID)
+ ig.DelReceiver(cntx, device, port, igmpv2.GroupAddress, nil, ponPortID)
ig.IgmpGroupLock.Unlock()
if ig.NumDevicesActive() == 0 {
- va.DelIgmpGroup(ig)
+ va.DelIgmpGroup(cntx, ig)
}
}
} else {
@@ -936,13 +937,13 @@
defer mvp.mvpLock.RUnlock()
if net.ParseIP("0.0.0.0").Equal(igmpv2.GroupAddress) {
- va.processIgmpQueries(device, pktVlan, IgmpVersion2)
+ va.processIgmpQueries(cntx, device, pktVlan, IgmpVersion2)
} else {
if ig := va.GetIgmpGroup(pktVlan, igmpv2.GroupAddress); ig != nil {
ig.IgmpGroupLock.Lock()
igd, ok := ig.Devices[device]
if ok {
- igd.ProcessQuery(igmpv2.GroupAddress, IgmpVersion2)
+ igd.ProcessQuery(cntx, igmpv2.GroupAddress, IgmpVersion2)
} else {
logger.Warnw(ctx, "IGMP Device not found", log.Fields{"Device": device, "Group": igmpv2.GroupAddress})
}
@@ -953,7 +954,7 @@
}
// ProcessIgmpv3Pkt : Process IGMPv3 packet
-func (va *VoltApplication) ProcessIgmpv3Pkt(device string, port string, pkt gopacket.Packet) {
+func (va *VoltApplication) ProcessIgmpv3Pkt(cntx context.Context, device string, port string, pkt gopacket.Packet) {
// First get the layers of interest
dot1QLayer := pkt.Layer(layers.LayerTypeDot1Q)
@@ -1018,13 +1019,13 @@
ig.IgmpGroupLock.Unlock()
return
}
- ig.AddReceiver(device, port, group.MulticastAddress, &group, IgmpVersion3,
+ ig.AddReceiver(cntx, device, port, group.MulticastAddress, &group, IgmpVersion3,
dot1Q.VLANIdentifier, dot1Q.Priority, ponPortID)
ig.IgmpGroupLock.Unlock()
} else {
// Create the IGMP group and then add the receiver to the group
logger.Infow(ctx, "IGMP Join received for new group", log.Fields{"Addr": group.MulticastAddress, "Port": port})
- if ig := va.AddIgmpGroup(vpv.MvlanProfileName, group.MulticastAddress, device); ig != nil {
+ if ig := va.AddIgmpGroup(cntx, vpv.MvlanProfileName, group.MulticastAddress, device); ig != nil {
ig.IgmpGroupLock.Lock()
// Check for port state to avoid race condition where PortDown event
// acquired lock before packet processing
@@ -1036,7 +1037,7 @@
ig.IgmpGroupLock.Unlock()
return
}
- ig.AddReceiver(device, port, group.MulticastAddress, &group, IgmpVersion3,
+ ig.AddReceiver(cntx, device, port, group.MulticastAddress, &group, IgmpVersion3,
dot1Q.VLANIdentifier, dot1Q.Priority, ponPortID)
ig.IgmpGroupLock.Unlock()
} else {
@@ -1046,10 +1047,10 @@
} else if ig != nil {
logger.Infow(ctx, "IGMP Leave received for existing group", log.Fields{"Addr": group.MulticastAddress, "Port": port})
ig.IgmpGroupLock.Lock()
- ig.DelReceiver(device, port, group.MulticastAddress, &group, ponPortID)
+ ig.DelReceiver(cntx, device, port, group.MulticastAddress, &group, ponPortID)
ig.IgmpGroupLock.Unlock()
if ig.NumDevicesActive() == 0 {
- va.DelIgmpGroup(ig)
+ va.DelIgmpGroup(cntx, ig)
}
} else {
logger.Warnw(ctx, "IGMP Leave received for unknown group", log.Fields{"Addr": group.MulticastAddress})
@@ -1071,13 +1072,13 @@
defer mvp.mvpLock.RUnlock()
if net.ParseIP("0.0.0.0").Equal(igmpv3.GroupAddress) {
- va.processIgmpQueries(device, pktVlan, IgmpVersion3)
+ va.processIgmpQueries(cntx, device, pktVlan, IgmpVersion3)
} else {
if ig := va.GetIgmpGroup(pktVlan, igmpv3.GroupAddress); ig != nil {
ig.IgmpGroupLock.Lock()
igd, ok := ig.Devices[device]
if ok {
- igd.ProcessQuery(igmpv3.GroupAddress, IgmpVersion3)
+ igd.ProcessQuery(cntx, igmpv3.GroupAddress, IgmpVersion3)
} else {
logger.Warnw(ctx, "IGMP Device not found", log.Fields{"Device": device, "Group": igmpv3.GroupAddress})
}
@@ -1088,7 +1089,7 @@
}
// processIgmpQueries to process the igmp queries
-func (va *VoltApplication) processIgmpQueries(device string, pktVlan of.VlanType, version uint8) {
+func (va *VoltApplication) processIgmpQueries(cntx context.Context, device string, pktVlan of.VlanType, version uint8) {
// This is a generic query and respond with all the groups channels in currently being viewed.
processquery := func(key interface{}, value interface{}) bool {
ig := value.(*IgmpGroup)
@@ -1105,7 +1106,7 @@
}
processQueryForEachChannel := func(key interface{}, value interface{}) bool {
groupAddr := key.(string)
- igd.ProcessQuery(net.ParseIP(groupAddr), version)
+ igd.ProcessQuery(cntx, net.ParseIP(groupAddr), version)
return true
}
igd.GroupChannels.Range(processQueryForEachChannel)
@@ -1143,7 +1144,7 @@
// IgmpProcessPkt to process the IGMP packet received. The packet received brings along with it
// the port on which the packet is received and the device the port is in.
-func (va *VoltApplication) IgmpProcessPkt(device string, port string, pkt gopacket.Packet) {
+func (va *VoltApplication) IgmpProcessPkt(cntx context.Context, device string, port string, pkt gopacket.Packet) {
igmpl := pkt.Layer(layers.LayerTypeIGMP)
if igmpl == nil {
logger.Error(ctx, "Invalid IGMP packet arrived as IGMP packet")
@@ -1152,12 +1153,12 @@
if igmp, ok := igmpl.(*layers.IGMPv1or2); ok {
// This is an IGMPv2 packet.
logger.Debugw(ctx, "IGMPv2 Packet Received", log.Fields{"IPAddr": igmp.GroupAddress})
- va.ProcessIgmpv2Pkt(device, port, pkt)
+ va.ProcessIgmpv2Pkt(cntx, device, port, pkt)
return
}
if igmpv3, ok := igmpl.(*layers.IGMP); ok {
logger.Debugw(ctx, "IGMPv3 Packet Received", log.Fields{"NumOfGroups": igmpv3.NumberOfGroupRecords})
- va.ProcessIgmpv3Pkt(device, port, pkt)
+ va.ProcessIgmpv3Pkt(cntx, device, port, pkt)
}
}
@@ -1180,8 +1181,8 @@
}
// RestoreMvlansFromDb to read from the DB and restore all the MVLANs
-func (va *VoltApplication) RestoreMvlansFromDb() {
- mvlans, _ := db.GetMvlans()
+func (va *VoltApplication) RestoreMvlansFromDb(cntx context.Context) {
+ mvlans, _ := db.GetMvlans(cntx)
for _, mvlan := range mvlans {
b, ok := mvlan.Value.([]byte)
if !ok {
@@ -1223,7 +1224,7 @@
}
//UpdateMvlanProfile - only channel groups be updated
-func (va *VoltApplication) UpdateMvlanProfile(name string, vlan of.VlanType, groups map[string][]string, activeChannelCount int, proxy map[string]common.MulticastGroupProxy) error {
+func (va *VoltApplication) UpdateMvlanProfile(cntx context.Context, name string, vlan of.VlanType, groups map[string][]string, activeChannelCount int, proxy map[string]common.MulticastGroupProxy) error {
mvpIntf, ok := va.MvlanProfilesByName.Load(name)
if !ok {
@@ -1256,7 +1257,7 @@
logger.Info(ctx, "No change in groups config")
if uint32(activeChannelCount) != mvp.MaxActiveChannels {
mvp.MaxActiveChannels = uint32(activeChannelCount)
- if err := mvp.WriteToDb(); err != nil {
+ if err := mvp.WriteToDb(cntx); err != nil {
logger.Errorw(ctx, "Mvlan profile Write to DB failed", log.Fields{"ProfileName": mvp.Name})
}
if prevMaxActiveChannels != mvp.MaxActiveChannels {
@@ -1275,7 +1276,7 @@
mvp.oldGroups = existingGroup
mvp.oldProxy = existingProxy
va.storeMvlansMap(vlan, name, mvp)
- if err := mvp.WriteToDb(); err != nil {
+ if err := mvp.WriteToDb(cntx); err != nil {
logger.Errorw(ctx, "Mvlan profile Write to DB failed", log.Fields{"ProfileName": mvp.Name})
}
if prevMaxActiveChannels != mvp.MaxActiveChannels {
@@ -1321,7 +1322,7 @@
}
// AddMcastConfig for addition of a MVLAN profile
-func (va *VoltApplication) AddMcastConfig(MvlanProfileID string, IgmpProfileID string, IgmpProxyIP string, OltSerialNum string) error {
+func (va *VoltApplication) AddMcastConfig(cntx context.Context, MvlanProfileID string, IgmpProfileID string, IgmpProxyIP string, OltSerialNum string) error {
var mcastCfg *McastConfig
mcastCfg = va.GetMcastConfig(OltSerialNum, MvlanProfileID)
@@ -1371,61 +1372,61 @@
va.IgmpGroups.Range(iterIgmpGroups)
va.storeMcastConfig(OltSerialNum, MvlanProfileID, mcastCfg)
- if err := mcastCfg.WriteToDb(); err != nil {
+ if err := mcastCfg.WriteToDb(cntx); err != nil {
logger.Errorw(ctx, "McastConfig Write to DB failed", log.Fields{"OltSerialNum": mcastCfg.OltSerialNum, "MvlanProfileID": mcastCfg.MvlanProfileID})
}
- va.addOltToMvlan(MvlanProfileID, OltSerialNum)
+ va.addOltToMvlan(cntx, MvlanProfileID, OltSerialNum)
return nil
}
-func (va *VoltApplication) addOltToMvlan(MvlanProfileID string, OltSerialNum string) {
+func (va *VoltApplication) addOltToMvlan(cntx context.Context, MvlanProfileID string, OltSerialNum string) {
var mvp *MvlanProfile
if mvpIntf, ok := va.MvlanProfilesByName.Load(MvlanProfileID); ok {
servVersion := IgmpVersion0
mvp = mvpIntf.(*MvlanProfile)
mvp.DevicesList[OltSerialNum] = NoOp
mvp.IgmpServVersion[OltSerialNum] = &servVersion
- if err := mvp.WriteToDb(); err != nil {
+ if err := mvp.WriteToDb(cntx); err != nil {
logger.Errorw(ctx, "Mvlan profile Write to DB failed", log.Fields{"ProfileName": mvp.Name})
}
- mvp.pushIgmpMcastFlows(OltSerialNum)
+ mvp.pushIgmpMcastFlows(cntx, OltSerialNum)
}
}
-func (va *VoltApplication) delOltFromMvlan(MvlanProfileID string, OltSerialNum string) {
+func (va *VoltApplication) delOltFromMvlan(cntx context.Context, MvlanProfileID string, OltSerialNum string) {
var mvp *MvlanProfile
if mvpIntf, ok := va.MvlanProfilesByName.Load(MvlanProfileID); ok {
mvp = mvpIntf.(*MvlanProfile)
//Delete from mvp list
- mvp.removeIgmpMcastFlows(OltSerialNum)
+ mvp.removeIgmpMcastFlows(cntx, OltSerialNum)
delete(mvp.DevicesList, OltSerialNum)
- if err := mvp.WriteToDb(); err != nil {
+ if err := mvp.WriteToDb(cntx); err != nil {
logger.Errorw(ctx, "Mvlan profile Write to DB failed", log.Fields{"ProfileName": mvp.Name})
}
}
}
// DelMcastConfig for addition of a MVLAN profile
-func (va *VoltApplication) DelMcastConfig(MvlanProfileID string, IgmpProfileID string, IgmpProxyIP string, OltSerialNum string) {
+func (va *VoltApplication) DelMcastConfig(cntx context.Context, MvlanProfileID string, IgmpProfileID string, IgmpProxyIP string, OltSerialNum string) {
- va.delOltFromMvlan(MvlanProfileID, OltSerialNum)
+ va.delOltFromMvlan(cntx, MvlanProfileID, OltSerialNum)
va.deleteMcastConfig(OltSerialNum, MvlanProfileID)
- _ = db.DelMcastConfig(McastConfigKey(OltSerialNum, MvlanProfileID))
+ _ = db.DelMcastConfig(cntx, McastConfigKey(OltSerialNum, MvlanProfileID))
if d := va.GetDeviceBySerialNo(OltSerialNum); d != nil {
if mvp := va.GetMvlanProfileByName(MvlanProfileID); mvp != nil {
- va.RemoveGroupsFromPendingPool(d.Name, mvp.Mvlan)
+ va.RemoveGroupsFromPendingPool(cntx, d.Name, mvp.Mvlan)
}
}
}
// DelAllMcastConfig for deletion of all mcast config
-func (va *VoltApplication) DelAllMcastConfig(OltSerialNum string) error {
+func (va *VoltApplication) DelAllMcastConfig(cntx context.Context, OltSerialNum string) error {
deleteIndividualMcastConfig := func(key interface{}, value interface{}) bool {
mcastCfg := value.(*McastConfig)
if mcastCfg.OltSerialNum == OltSerialNum {
- va.DelMcastConfig(mcastCfg.MvlanProfileID, mcastCfg.IgmpProfileID, mcastCfg.IgmpProxyIP.String(), mcastCfg.OltSerialNum)
+ va.DelMcastConfig(cntx, mcastCfg.MvlanProfileID, mcastCfg.IgmpProfileID, mcastCfg.IgmpProxyIP.String(), mcastCfg.OltSerialNum)
}
return true
}
@@ -1434,7 +1435,7 @@
}
// UpdateMcastConfig for addition of a MVLAN profile
-func (va *VoltApplication) UpdateMcastConfig(MvlanProfileID string, IgmpProfileID string, IgmpProxyIP string, OltSerialNum string) error {
+func (va *VoltApplication) UpdateMcastConfig(cntx context.Context, MvlanProfileID string, IgmpProfileID string, IgmpProxyIP string, OltSerialNum string) error {
mcastCfg := va.GetMcastConfig(OltSerialNum, MvlanProfileID)
if mcastCfg == nil {
@@ -1463,7 +1464,7 @@
mcastCfg.IgmpGroupDevices.Range(updateIgdProxyCfg)
}
- if err := mcastCfg.WriteToDb(); err != nil {
+ if err := mcastCfg.WriteToDb(cntx); err != nil {
logger.Errorw(ctx, "McastConfig Write to DB failed", log.Fields{"OltSerialNum": mcastCfg.OltSerialNum, "MvlanProfileID": mcastCfg.MvlanProfileID})
}
@@ -1471,21 +1472,21 @@
}
// WriteToDb is utility to write Mcast config Info to database
-func (mc *McastConfig) WriteToDb() error {
+func (mc *McastConfig) WriteToDb(cntx context.Context) error {
mc.Version = database.PresentVersionMap[database.McastConfigPath]
b, err := json.Marshal(mc)
if err != nil {
return err
}
- if err1 := db.PutMcastConfig(McastConfigKey(mc.OltSerialNum, mc.MvlanProfileID), string(b)); err1 != nil {
+ if err1 := db.PutMcastConfig(cntx, McastConfigKey(mc.OltSerialNum, mc.MvlanProfileID), string(b)); err1 != nil {
return err1
}
return nil
}
// RestoreMcastConfigsFromDb to read from the DB and restore Mcast configs
-func (va *VoltApplication) RestoreMcastConfigsFromDb() {
- mcastConfigs, _ := db.GetMcastConfigs()
+func (va *VoltApplication) RestoreMcastConfigsFromDb(cntx context.Context) {
+ mcastConfigs, _ := db.GetMcastConfigs(cntx)
for hash, mcastConfig := range mcastConfigs {
b, ok := mcastConfig.Value.([]byte)
if !ok {
@@ -1504,7 +1505,7 @@
}
// AddMvlanProfile for addition of a MVLAN profile
-func (va *VoltApplication) AddMvlanProfile(name string, mvlan of.VlanType, ponVlan of.VlanType,
+func (va *VoltApplication) AddMvlanProfile(cntx context.Context, name string, mvlan of.VlanType, ponVlan of.VlanType,
groups map[string][]string, isChannelBasedGroup bool, OLTSerialNum []string, activeChannelsPerPon int, proxy map[string]common.MulticastGroupProxy) error {
var mvp *MvlanProfile
@@ -1518,7 +1519,7 @@
if mvp.DevicesList[serialNum] != Nil {
//This is backup restore scenario, just update the profile
logger.Info(ctx, "Add Mvlan : Profile Name already exists, update-the-profile")
- return va.UpdateMvlanProfile(name, mvlan, groups, activeChannelsPerPon, proxy)
+ return va.UpdateMvlanProfile(cntx, name, mvlan, groups, activeChannelsPerPon, proxy)
}
}
}
@@ -1546,7 +1547,7 @@
logger.Debugw(ctx, "Added MVLAN Profile", log.Fields{"MVLAN": mvp.Mvlan, "PonVlan": mvp.PonVlan, "Name": mvp.Name, "Grp IPs": mvp.Groups, "IsPonVlanPresent": mvp.IsPonVlanPresent})
mvp.mvpLock.Unlock()
- if err := mvp.WriteToDb(); err != nil {
+ if err := mvp.WriteToDb(cntx); err != nil {
logger.Errorw(ctx, "Mvlan profile Write to DB failed", log.Fields{"ProfileName": mvp.Name})
}
@@ -1570,7 +1571,7 @@
}
// IgmpTick for igmp tick info
-func (va *VoltApplication) IgmpTick() {
+func (va *VoltApplication) IgmpTick(cntx context.Context) {
tickCount++
if (tickCount % 1000) == 0 {
logger.Debugw(ctx, "Time @ Tick", log.Fields{"Tick": tickCount, "Time": time.Now()})
@@ -1580,10 +1581,10 @@
if ig.NumDevicesActive() != 0 {
if tickCount%10 == ig.Hash()%10 {
ig.IgmpGroupLock.Lock()
- ig.Tick()
+ ig.Tick(cntx)
ig.IgmpGroupLock.Unlock()
if ig.NumDevicesActive() == 0 {
- va.DelIgmpGroup(ig)
+ va.DelIgmpGroup(cntx, ig)
}
}
}
@@ -1600,12 +1601,12 @@
}
//AddIgmpProfile for addition of IGMP Profile
-func (va *VoltApplication) AddIgmpProfile(igmpProfileConfig *common.IGMPConfig) error {
+func (va *VoltApplication) AddIgmpProfile(cntx context.Context, igmpProfileConfig *common.IGMPConfig) error {
var igmpProfile *IgmpProfile
if igmpProfileConfig.ProfileID == DefaultIgmpProfID {
logger.Info(ctx, "Updating default IGMP profile")
- return va.UpdateIgmpProfile(igmpProfileConfig)
+ return va.UpdateIgmpProfile(cntx, igmpProfileConfig)
}
igmpProfile = va.checkIgmpProfileMap(igmpProfileConfig.ProfileID)
@@ -1618,7 +1619,7 @@
va.storeIgmpProfileMap(igmpProfileConfig.ProfileID, igmpProfile)
- if err := igmpProfile.WriteToDb(); err != nil {
+ if err := igmpProfile.WriteToDb(cntx); err != nil {
logger.Errorw(ctx, "Igmp profile Write to DB failed", log.Fields{"profileID": igmpProfile.ProfileID})
}
@@ -1633,7 +1634,7 @@
return nil
}
-func (va *VoltApplication) resetIgmpProfileToDefault() {
+func (va *VoltApplication) resetIgmpProfileToDefault(cntx context.Context) {
igmpProf := va.getIgmpProfileMap(DefaultIgmpProfID)
defIgmpProf := newDefaultIgmpProfile()
@@ -1651,7 +1652,7 @@
igmpProf.IgmpVerToServer = defIgmpProf.IgmpVerToServer
igmpProf.IgmpSourceIP = defIgmpProf.IgmpSourceIP
- if err := igmpProf.WriteToDb(); err != nil {
+ if err := igmpProf.WriteToDb(cntx); err != nil {
logger.Errorw(ctx, "Igmp profile Write to DB failed", log.Fields{"profileID": igmpProf.ProfileID})
}
}
@@ -1678,11 +1679,11 @@
}
//DelIgmpProfile for addition of IGMP Profile
-func (va *VoltApplication) DelIgmpProfile(igmpProfileConfig *common.IGMPConfig) error {
+func (va *VoltApplication) DelIgmpProfile(cntx context.Context, igmpProfileConfig *common.IGMPConfig) error {
// Deletion of default igmp profile is blocked from submgr. Keeping additional check for safety.
if igmpProfileConfig.ProfileID == DefaultIgmpProfID {
logger.Info(ctx, "Resetting default IGMP profile")
- va.resetIgmpProfileToDefault()
+ va.resetIgmpProfileToDefault(cntx)
return nil
}
igmpProfile := va.checkIgmpProfileMap(igmpProfileConfig.ProfileID)
@@ -1693,13 +1694,13 @@
va.deleteIgmpProfileMap(igmpProfileConfig.ProfileID)
- _ = db.DelIgmpProfile(igmpProfileConfig.ProfileID)
+ _ = db.DelIgmpProfile(cntx, igmpProfileConfig.ProfileID)
return nil
}
//UpdateIgmpProfile for addition of IGMP Profile
-func (va *VoltApplication) UpdateIgmpProfile(igmpProfileConfig *common.IGMPConfig) error {
+func (va *VoltApplication) UpdateIgmpProfile(cntx context.Context, igmpProfileConfig *common.IGMPConfig) error {
igmpProfile := va.checkIgmpProfileMap(igmpProfileConfig.ProfileID)
if igmpProfile == nil {
logger.Errorw(ctx, "Igmp Profile not found. Unable to update", log.Fields{"Profile ID": igmpProfileConfig.ProfileID})
@@ -1738,7 +1739,7 @@
igmpProfile.IgmpSourceIP = net.ParseIP(igmpProfileConfig.IgmpSourceIP)
}
- if err := igmpProfile.WriteToDb(); err != nil {
+ if err := igmpProfile.WriteToDb(cntx); err != nil {
logger.Errorw(ctx, "Igmp profile Write to DB failed", log.Fields{"profileID": igmpProfile.ProfileID})
}
@@ -1746,9 +1747,9 @@
}
// RestoreIGMPProfilesFromDb to read from the DB and restore IGMP Profiles
-func (va *VoltApplication) RestoreIGMPProfilesFromDb() {
+func (va *VoltApplication) RestoreIGMPProfilesFromDb(cntx context.Context) {
// Loading IGMP profiles
- igmpProfiles, _ := db.GetIgmpProfiles()
+ igmpProfiles, _ := db.GetIgmpProfiles(cntx)
for _, igmpProfile := range igmpProfiles {
b, ok := igmpProfile.Value.([]byte)
if !ok {
@@ -1777,13 +1778,13 @@
}
// DelMvlanProfile for deletion of a MVLAN group
-func (va *VoltApplication) DelMvlanProfile(name string) error {
+func (va *VoltApplication) DelMvlanProfile(cntx context.Context, name string) error {
if mvpIntf, ok := va.MvlanProfilesByName.Load(name); ok {
mvp := mvpIntf.(*MvlanProfile)
if len(mvp.DevicesList) == 0 {
mvp.DeleteInProgress = true
- mvp.DelFromDb()
+ mvp.DelFromDb(cntx)
va.deleteMvlansMap(mvp.Mvlan, name)
logger.Debugw(ctx, "Deleted MVLAN Profile", log.Fields{"Name": mvp.Name})
} else {
@@ -1839,7 +1840,7 @@
}
// ReceiverDownInd to send receiver down indication
-func (va *VoltApplication) ReceiverDownInd(device string, port string) {
+func (va *VoltApplication) ReceiverDownInd(cntx context.Context, device string, port string) {
logger.Infow(ctx, " Receiver Indication: DOWN", log.Fields{"device": device, "port": port})
ponPortID := va.GetPonPortID(device, port)
@@ -1847,10 +1848,10 @@
del := func(key interface{}, value interface{}) bool {
ig := value.(*IgmpGroup)
ig.IgmpGroupLock.Lock()
- ig.DelReceiveronDownInd(device, port, ponPortID)
+ ig.DelReceiveronDownInd(cntx, device, port, ponPortID)
ig.IgmpGroupLock.Unlock()
if ig.NumDevicesActive() == 0 {
- va.DelIgmpGroup(ig)
+ va.DelIgmpGroup(cntx, ig)
}
return true
}
diff --git a/internal/pkg/application/igmpgroup.go b/internal/pkg/application/igmpgroup.go
index 629d92c..a7107cd 100644
--- a/internal/pkg/application/igmpgroup.go
+++ b/internal/pkg/application/igmpgroup.go
@@ -16,6 +16,7 @@
package application
import (
+ "context"
"encoding/json"
"net"
"sync"
@@ -76,7 +77,7 @@
}
// IgmpGroupReInit to re-initialize igmp group members
-func (ig *IgmpGroup) IgmpGroupReInit(name string, gip net.IP) {
+func (ig *IgmpGroup) IgmpGroupReInit(cntx context.Context, name string, gip net.IP) {
logger.Infow(ctx, "Reinitialize Igmp Group", log.Fields{"GroupID": ig.GroupID, "OldName": ig.GroupName, "Name": name, "OldAddr": ig.GroupAddr.String(), "GroupAddr": gip.String()})
@@ -88,12 +89,12 @@
}
for _, igd := range ig.Devices {
- igd.IgmpGroupDeviceReInit(ig)
+ igd.IgmpGroupDeviceReInit(cntx, ig)
}
}
// updateGroupName to update group name
-func (ig *IgmpGroup) updateGroupName(newGroupName string) {
+func (ig *IgmpGroup) updateGroupName(cntx context.Context, newGroupName string) {
if !ig.IsChannelBasedGroup {
logger.Errorw(ctx, "Group name update not supported for GroupChannel based group", log.Fields{"Ig": ig})
return
@@ -101,36 +102,36 @@
oldKey := ig.getKey()
ig.GroupName = newGroupName
for _, igd := range ig.Devices {
- igd.updateGroupName(newGroupName)
+ igd.updateGroupName(cntx, newGroupName)
}
- if err := ig.WriteToDb(); err != nil {
+ if err := ig.WriteToDb(cntx); err != nil {
logger.Errorw(ctx, "Igmp group Write to DB failed", log.Fields{"groupName": ig.GroupName})
}
if !ig.IsChannelBasedGroup {
- _ = db.DelIgmpGroup(oldKey)
+ _ = db.DelIgmpGroup(cntx, oldKey)
}
}
//HandleGroupMigration - handles migration of group members between static & dynamic
-func (ig *IgmpGroup) HandleGroupMigration(deviceID string, groupAddr net.IP) {
+func (ig *IgmpGroup) HandleGroupMigration(cntx context.Context, deviceID string, groupAddr net.IP) {
var group *layers.IGMPv3GroupRecord
app := GetApplication()
if deviceID == "" {
logger.Infow(ctx, "Handle Group Migration Request for all devices", log.Fields{"DeviceID": deviceID, "GroupAddr": groupAddr, "IG": ig.GroupName, "Mvlan": ig.Mvlan})
for device := range ig.Devices {
- ig.HandleGroupMigration(device, groupAddr)
+ ig.HandleGroupMigration(cntx, device, groupAddr)
}
} else {
logger.Infow(ctx, "Handle Group Migration Request", log.Fields{"DeviceID": deviceID, "GroupAddr": groupAddr, "IG": ig.GroupName})
var newIg *IgmpGroup
- receivers := ig.DelIgmpChannel(deviceID, groupAddr)
+ receivers := ig.DelIgmpChannel(cntx, deviceID, groupAddr)
if ig.NumDevicesActive() == 0 {
- app.DelIgmpGroup(ig)
+ app.DelIgmpGroup(cntx, ig)
}
if newIg = app.GetIgmpGroup(ig.Mvlan, groupAddr); newIg == nil {
logger.Infow(ctx, "IG Group doesn't exist, creating new group", log.Fields{"DeviceID": deviceID, "GroupAddr": groupAddr, "IG": ig.GroupName, "Mvlan": ig.Mvlan})
- if newIg = app.AddIgmpGroup(app.GetMvlanProfileByTag(ig.Mvlan).Name, groupAddr, deviceID); newIg == nil {
+ if newIg = app.AddIgmpGroup(cntx, app.GetMvlanProfileByTag(ig.Mvlan).Name, groupAddr, deviceID); newIg == nil {
logger.Errorw(ctx, "Group Creation failed during group migration", log.Fields{"DeviceID": deviceID, "GroupAddr": groupAddr})
return
}
@@ -161,7 +162,7 @@
}
logger.Infow(ctx, "Adding receiver to new group", log.Fields{"DeviceID": deviceID, "GroupAddr": groupAddr, "newIg": newIg.GroupName, "IGP": igp})
ponPort := GetApplication().GetPonPortID(deviceID, port)
- newIg.AddReceiver(deviceID, port, groupAddr, group, igp.Version, igp.CVlan, igp.Pbit, ponPort)
+ newIg.AddReceiver(cntx, deviceID, port, groupAddr, group, igp.Version, igp.CVlan, igp.Pbit, ponPort)
}
newIg.IgmpGroupLock.Unlock()
}
@@ -169,11 +170,11 @@
// AddIgmpGroupDevice add a device to the group which happens when the first receiver of the device
// is added to the IGMP group.
-func (ig *IgmpGroup) AddIgmpGroupDevice(device string, id uint32, version uint8) *IgmpGroupDevice {
+func (ig *IgmpGroup) AddIgmpGroupDevice(cntx context.Context, device string, id uint32, version uint8) *IgmpGroupDevice {
logger.Infow(ctx, "Adding Device to IGMP group", log.Fields{"Device": device, "GroupName": ig.GroupName})
igd := NewIgmpGroupDevice(device, ig, id, version)
ig.Devices[device] = igd
- if err := igd.WriteToDb(); err != nil {
+ if err := igd.WriteToDb(cntx); err != nil {
logger.Errorw(ctx, "Igmp group device Write to DB failed", log.Fields{"Device": igd.Device, "GroupName": igd.GroupName, "GroupAddr": igd.GroupAddr.String()})
}
return igd
@@ -181,14 +182,14 @@
// DelIgmpGroupDevice delete the device from the group which happens when we receive a leave or when
// there is not response for IGMP query from the receiver
-func (ig *IgmpGroup) DelIgmpGroupDevice(igd *IgmpGroupDevice) {
+func (ig *IgmpGroup) DelIgmpGroupDevice(cntx context.Context, igd *IgmpGroupDevice) {
logger.Infow(ctx, "Deleting Device from IGMP group", log.Fields{"Device": igd.Device, "Name": ig.GroupName})
va := GetApplication()
countersToBeUpdated := false
if igd.NumReceivers() != 0 {
countersToBeUpdated = true
}
- igd.DelAllChannels()
+ igd.DelAllChannels(cntx)
//Clear all internal maps so that the groups can be reused
igd.PortChannelMap.Range(func(key, value interface{}) bool {
@@ -215,34 +216,34 @@
logger.Debugw(ctx, "Igd deleted from mcast config", log.Fields{"mvlan": mcastCfg.MvlanProfileID, "groupId": igd.GroupID})
}
if !igd.GroupInstalled {
- _ = db.DelIgmpDevice(igd.Mvlan, ig.GroupName, ig.GroupAddr, igd.Device)
+ _ = db.DelIgmpDevice(cntx, igd.Mvlan, ig.GroupName, ig.GroupAddr, igd.Device)
delete(ig.Devices, igd.Device)
}
}
// AddReceiver delete the device from the group which happens when we receive a leave or when
// there is not response for IGMP query from the receiver
-func (ig *IgmpGroup) AddReceiver(device string, port string, groupIP net.IP,
+func (ig *IgmpGroup) AddReceiver(cntx context.Context, device string, port string, groupIP net.IP,
group *layers.IGMPv3GroupRecord, ver uint8, cvlan uint16, pbit uint8, ponPort uint32) {
logger.Debugw(ctx, "Adding Receiver", log.Fields{"Port": port})
- if igd, ok := ig.getIgmpGroupDevice(device); !ok {
- igd = ig.AddIgmpGroupDevice(device, ig.GroupID, ver)
- igd.AddReceiver(port, groupIP, group, ver, cvlan, pbit, ponPort)
+ if igd, ok := ig.getIgmpGroupDevice(cntx, device); !ok {
+ igd = ig.AddIgmpGroupDevice(cntx, device, ig.GroupID, ver)
+ igd.AddReceiver(cntx, port, groupIP, group, ver, cvlan, pbit, ponPort)
} else {
logger.Infow(ctx, "IGMP Group Receiver", log.Fields{"IGD": igd.Device})
- igd.AddReceiver(port, groupIP, group, ver, cvlan, pbit, ponPort)
+ igd.AddReceiver(cntx, port, groupIP, group, ver, cvlan, pbit, ponPort)
}
}
-func (ig *IgmpGroup) getIgmpGroupDevice(device string) (*IgmpGroupDevice, bool) {
+func (ig *IgmpGroup) getIgmpGroupDevice(cntx context.Context, device string) (*IgmpGroupDevice, bool) {
ig.PendingPoolLock.Lock()
defer ig.PendingPoolLock.Unlock()
if _, ok := ig.PendingGroupForDevice[device]; ok {
logger.Infow(ctx, "Removing the IgmpGroupDevice from pending pool", log.Fields{"GroupID": ig.GroupID, "Device": device, "GroupName": ig.GroupName, "GroupAddr": ig.GroupAddr.String()})
delete(ig.PendingGroupForDevice, device)
- if err := ig.WriteToDb(); err != nil {
+ if err := ig.WriteToDb(cntx); err != nil {
logger.Errorw(ctx, "Igmp group Write to DB failed", log.Fields{"groupName": ig.GroupName})
}
}
@@ -252,7 +253,7 @@
// DelReceiveronDownInd deletes a receiver which is the combination of device (OLT)
// and port on Port Down event
-func (ig *IgmpGroup) DelReceiveronDownInd(device string, port string, ponPortID uint32) {
+func (ig *IgmpGroup) DelReceiveronDownInd(cntx context.Context, device string, port string, ponPortID uint32) {
logger.Debugw(ctx, "Deleting Receiver for Group", log.Fields{"Device": device, "port": port})
mvp := GetApplication().GetMvlanProfileByTag(ig.Mvlan)
@@ -274,23 +275,23 @@
for _, groupAddr := range ipsList {
logger.Debugw(ctx, "Port Channels", log.Fields{"Port": port, "IPsList": ipsList, "GroupAddr": groupAddr, "Len": len(ipsList)})
- igd.DelReceiver(groupAddr, port, nil, ponPortID)
+ igd.DelReceiver(cntx, groupAddr, port, nil, ponPortID)
}
if igd.NumReceivers() == 0 {
- ig.DelIgmpGroupDevice(igd)
+ ig.DelIgmpGroupDevice(cntx, igd)
}
}
// DelReceiver deletes a receiver which is the combination of device (OLT)
// and port
-func (ig *IgmpGroup) DelReceiver(device string, port string, groupAddr net.IP, group *layers.IGMPv3GroupRecord, ponPortID uint32) {
+func (ig *IgmpGroup) DelReceiver(cntx context.Context, device string, port string, groupAddr net.IP, group *layers.IGMPv3GroupRecord, ponPortID uint32) {
logger.Debugw(ctx, "Deleting Receiver for Group", log.Fields{"Device": device, "port": port, "GroupIP": groupAddr.String()})
if igd, ok := ig.Devices[device]; ok {
//igd.DelReceiverForGroupAddr(groupAddr, port)
- igd.DelReceiver(groupAddr, port, group, ponPortID)
+ igd.DelReceiver(cntx, groupAddr, port, group, ponPortID)
if igd.NumReceivers() == 0 {
- ig.DelIgmpGroupDevice(igd)
+ ig.DelIgmpGroupDevice(cntx, igd)
}
}
}
@@ -329,18 +330,18 @@
}
// DelIgmpChannel deletes all receivers for the provided igmp group channel for the given device
-func (ig *IgmpGroup) DelIgmpChannel(deviceID string, groupAddr net.IP) map[string]*IgmpGroupPort {
+func (ig *IgmpGroup) DelIgmpChannel(cntx context.Context, deviceID string, groupAddr net.IP) map[string]*IgmpGroupPort {
logger.Infow(ctx, "Deleting Channel from devices", log.Fields{"Device": deviceID, "Group": ig.GroupName, "Channel": groupAddr.String()})
if deviceID == "" {
for device := range ig.Devices {
- ig.DelIgmpChannel(device, groupAddr)
+ ig.DelIgmpChannel(cntx, device, groupAddr)
}
return nil
}
igd := ig.Devices[deviceID]
- receivers := igd.DelChannelReceiver(groupAddr)
+ receivers := igd.DelChannelReceiver(cntx, groupAddr)
if igd.NumReceivers() == 0 {
- ig.DelIgmpGroupDevice(igd)
+ ig.DelIgmpGroupDevice(cntx, igd)
}
return receivers
}
@@ -373,7 +374,7 @@
}
// Tick for Addition of groups to an MVLAN profile
-func (ig *IgmpGroup) Tick() {
+func (ig *IgmpGroup) Tick(cntx context.Context) {
now := time.Now()
for _, igd := range ig.Devices {
var igdChangeCnt uint8
@@ -399,14 +400,14 @@
igd.GroupChannels.Range(sendQueryForAllChannels)
}
if now.After(igd.QueryExpiryTime) {
- igd.QueryExpiry()
+ igd.QueryExpiry(cntx)
// This will keep it quiet till the next query time and then
// it will be reset to a value after the query initiation time
igd.QueryExpiryTime = igd.NextQueryTime
logger.Debugw(ctx, "Expiry", log.Fields{"NextQuery": igd.NextQueryTime, "Expiry": igd.QueryExpiryTime})
igdChangeCnt++
if igd.NumReceivers() == 0 {
- ig.DelIgmpGroupDevice(igd)
+ ig.DelIgmpGroupDevice(cntx, igd)
continue
}
}
@@ -414,7 +415,7 @@
igdChangeCnt += igd.Tick()
if igdChangeCnt > 0 {
- if err := igd.WriteToDb(); err != nil {
+ if err := igd.WriteToDb(cntx); err != nil {
logger.Errorw(ctx, "Igmp group device Write to DB failed", log.Fields{"Device": igd.Device,
"GroupName": igd.GroupName, "GroupAddr": igd.GroupAddr.String()})
}
@@ -426,12 +427,12 @@
// expiry, process the consolidated response for each of the devices participating
// in the MC stream. When a device has no receivers, the device is deleted
// from the group.
-func (ig *IgmpGroup) QueryExpiry() {
+func (ig *IgmpGroup) QueryExpiry(cntx context.Context) {
for _, igd := range ig.Devices {
if _, ok := GetApplication().DevicesDisc.Load(igd.Device); ok {
- igd.QueryExpiry()
+ igd.QueryExpiry(cntx)
if igd.NumReceivers() == 0 {
- ig.DelIgmpGroupDevice(igd)
+ ig.DelIgmpGroupDevice(cntx, igd)
}
} else {
@@ -496,10 +497,10 @@
}
// RestoreDevices : IGMP group write to DB
-func (ig *IgmpGroup) RestoreDevices() {
+func (ig *IgmpGroup) RestoreDevices(cntx context.Context) {
- ig.migrateIgmpDevices()
- devices, _ := db.GetIgmpDevices(ig.Mvlan, ig.GroupName, ig.GroupAddr)
+ ig.migrateIgmpDevices(cntx)
+ devices, _ := db.GetIgmpDevices(cntx, ig.Mvlan, ig.GroupName, ig.GroupAddr)
for _, device := range devices {
b, ok := device.Value.([]byte)
if !ok {
@@ -526,7 +527,7 @@
logger.Debugw(ctx, "VGC igd upgrade", log.Fields{"igd grp name": igd.GroupName})
igd.NextQueryTime = time.Now().Add(time.Duration(igd.proxyCfg.KeepAliveInterval) * time.Second)
igd.QueryExpiryTime = time.Now().Add(time.Duration(igd.proxyCfg.KeepAliveInterval) * time.Second)
- if err := igd.WriteToDb(); err != nil {
+ if err := igd.WriteToDb(cntx); err != nil {
logger.Errorw(ctx, "Igmp group device Write to DB failed", log.Fields{"Device": igd.Device,
"GroupName": igd.GroupName, "GroupAddr": igd.GroupAddr.String()})
}
@@ -534,10 +535,10 @@
ig.Devices[igd.Device] = igd
if ig.IsChannelBasedGroup {
- channel, _ := db.GetIgmpChannel(igd.Mvlan, igd.GroupName, igd.Device, igd.GroupAddr)
- igd.RestoreChannel([]byte(channel))
+ channel, _ := db.GetIgmpChannel(cntx, igd.Mvlan, igd.GroupName, igd.Device, igd.GroupAddr)
+ igd.RestoreChannel(cntx, []byte(channel))
} else {
- igd.RestoreChannels()
+ igd.RestoreChannels(cntx)
}
igd.PortChannelMap.Range(printPortChannel)
logger.Infow(ctx, "Group Device Restored", log.Fields{"IGD": igd})
@@ -558,20 +559,20 @@
}
// WriteToDb is utility to write Igmp Group Info to database
-func (ig *IgmpGroup) WriteToDb() error {
+func (ig *IgmpGroup) WriteToDb(cntx context.Context) error {
ig.Version = database.PresentVersionMap[database.IgmpGroupPath]
b, err := json.Marshal(ig)
if err != nil {
return err
}
- if err1 := db.PutIgmpGroup(ig.getKey(), string(b)); err1 != nil {
+ if err1 := db.PutIgmpGroup(cntx, ig.getKey(), string(b)); err1 != nil {
return err1
}
return nil
}
// UpdateIgmpGroup : When the pending group is allocated to new
-func (ig *IgmpGroup) UpdateIgmpGroup(oldKey, newKey string) {
+func (ig *IgmpGroup) UpdateIgmpGroup(cntx context.Context, oldKey, newKey string) {
//If the group is allocated to same McastGroup, no need to update the
//IgmpGroups map
@@ -581,15 +582,15 @@
logger.Infow(ctx, "Updating Igmp Group with new MVP Group Info", log.Fields{"OldKey": oldKey, "NewKey": newKey, "GroupID": ig.GroupID})
GetApplication().IgmpGroups.Delete(oldKey)
- _ = db.DelIgmpGroup(oldKey)
+ _ = db.DelIgmpGroup(cntx, oldKey)
GetApplication().IgmpGroups.Store(newKey, ig)
- if err := ig.WriteToDb(); err != nil {
+ if err := ig.WriteToDb(cntx); err != nil {
logger.Errorw(ctx, "Igmp group Write to DB failed", log.Fields{"groupName": ig.GroupName})
}
}
-func (ig *IgmpGroup) removeExpiredGroupFromDevice() {
+func (ig *IgmpGroup) removeExpiredGroupFromDevice(cntx context.Context) {
ig.PendingPoolLock.Lock()
defer ig.PendingPoolLock.Unlock()
@@ -613,13 +614,13 @@
// Remove the group entry from device and remove the IgmpDev Obj
// from IgmpGrp Pending pool
if groupExistsInPendingPool {
- ig.DeleteIgmpGroupDevice(device)
+ ig.DeleteIgmpGroupDevice(cntx, device)
}
}
}
//DeleteIgmpGroupDevice - removes the IgmpGroupDevice obj from IgmpGroup and database
-func (ig *IgmpGroup) DeleteIgmpGroupDevice(device string) {
+func (ig *IgmpGroup) DeleteIgmpGroupDevice(cntx context.Context, device string) {
logger.Infow(ctx, "Deleting IgmpGroupDevice from IG Pending Pool", log.Fields{"Device": device, "GroupID": ig.GroupID, "GroupName": ig.GroupName, "GroupAddr": ig.GroupAddr.String(), "PendingDevices": len(ig.Devices)})
@@ -627,24 +628,24 @@
igd.DelMcGroup(true)
delete(ig.Devices, device)
delete(ig.PendingGroupForDevice, device)
- _ = db.DelIgmpDevice(igd.Mvlan, igd.GroupName, igd.GroupAddr, igd.Device)
+ _ = db.DelIgmpDevice(cntx, igd.Mvlan, igd.GroupName, igd.GroupAddr, igd.Device)
//If the group is not associated to any other device, then the entire Igmp Group obj itself can be removed
if ig.NumDevicesAll() == 0 {
logger.Infow(ctx, "Deleting IgmpGroup as all pending groups has expired", log.Fields{"Device": device, "GroupID": ig.GroupID, "GroupName": ig.GroupName, "GroupAddr": ig.GroupAddr.String(), "PendingDevices": len(ig.Devices)})
- GetApplication().DelIgmpGroup(ig)
+ GetApplication().DelIgmpGroup(cntx, ig)
return
}
- if err := ig.WriteToDb(); err != nil {
+ if err := ig.WriteToDb(cntx); err != nil {
logger.Errorw(ctx, "Igmp group Write to DB failed", log.Fields{"groupName": ig.GroupName})
}
}
// DelIgmpGroup deletes all devices for the provided igmp group
-func (ig *IgmpGroup) DelIgmpGroup() {
+func (ig *IgmpGroup) DelIgmpGroup(cntx context.Context) {
logger.Infow(ctx, "Deleting All Device for Group", log.Fields{"Group": ig.GroupName})
for _, igd := range ig.Devices {
- ig.DelIgmpGroupDevice(igd)
+ ig.DelIgmpGroupDevice(cntx, igd)
}
- GetApplication().DelIgmpGroup(ig)
+ GetApplication().DelIgmpGroup(cntx, ig)
}
diff --git a/internal/pkg/application/igmpgroupchannel.go b/internal/pkg/application/igmpgroupchannel.go
index ed39d23..d17e209 100644
--- a/internal/pkg/application/igmpgroupchannel.go
+++ b/internal/pkg/application/igmpgroupchannel.go
@@ -16,6 +16,7 @@
package application
import (
+ "context"
"encoding/json"
"net"
@@ -77,10 +78,10 @@
}
// RestorePorts to restore ports
-func (igc *IgmpGroupChannel) RestorePorts() {
+func (igc *IgmpGroupChannel) RestorePorts(cntx context.Context) {
- igc.migrateIgmpPorts()
- ports, _ := db.GetIgmpRcvrs(igc.Mvlan, igc.GroupAddr, igc.Device)
+ igc.migrateIgmpPorts(cntx)
+ ports, _ := db.GetIgmpRcvrs(cntx, igc.Mvlan, igc.GroupAddr, igc.Device)
for _, port := range ports {
b, ok := port.Value.([]byte)
if !ok {
@@ -94,18 +95,18 @@
logger.Warn(ctx, "Failed to decode port from DB")
}
}
- if err := igc.WriteToDb(); err != nil {
+ if err := igc.WriteToDb(cntx); err != nil {
logger.Errorw(ctx, "Igmp group channel Write to DB failed", log.Fields{"mvlan": igc.Mvlan, "GroupAddr": igc.GroupAddr})
}
}
// WriteToDb is utility to write IGMPGroupChannel Info to database
-func (igc *IgmpGroupChannel) WriteToDb() error {
+func (igc *IgmpGroupChannel) WriteToDb(cntx context.Context) error {
b, err := json.Marshal(igc)
if err != nil {
return err
}
- if err1 := db.PutIgmpChannel(igc.Mvlan, igc.GroupName, igc.Device, igc.GroupAddr, string(b)); err1 != nil {
+ if err1 := db.PutIgmpChannel(cntx, igc.Mvlan, igc.GroupName, igc.Device, igc.GroupAddr, string(b)); err1 != nil {
return err1
}
logger.Info(ctx, "IGC Updated")
@@ -246,7 +247,7 @@
// ProcessSources process the received list of either included sources or the excluded sources
// The return value indicate sif the group is modified and needs to be informed
// to the upstream multicast servers
-func (igc *IgmpGroupChannel) ProcessSources(port string, ip []net.IP, incl bool) (bool, bool) {
+func (igc *IgmpGroupChannel) ProcessSources(cntx context.Context, port string, ip []net.IP, incl bool) (bool, bool) {
groupChanged := false
groupExclUpdated := false
receiverSrcListEmpty := false
@@ -341,7 +342,7 @@
}
groupExclUpdated = igc.UpdateExclSource(ip)
}
- if err := igp.WriteToDb(igc.Mvlan, igc.GroupAddr, igc.Device); err != nil {
+ if err := igp.WriteToDb(cntx, igc.Mvlan, igc.GroupAddr, igc.Device); err != nil {
logger.Errorw(ctx, "Igmp group port Write to DB failed", log.Fields{"mvlan": igc.Mvlan, "GroupAddr": igc.GroupAddr})
}
return (groupChanged || groupExclUpdated), receiverSrcListEmpty
@@ -359,7 +360,7 @@
// AddReceiver add the receiver to the device and perform other actions such as adding the group
// to the physical device, add members, add flows to point the MC packets to the
// group. Also, send a IGMP report upstream if there is a change in the group
-func (igc *IgmpGroupChannel) AddReceiver(port string, group *layers.IGMPv3GroupRecord, cvlan uint16, pbit uint8) bool {
+func (igc *IgmpGroupChannel) AddReceiver(cntx context.Context, port string, group *layers.IGMPv3GroupRecord, cvlan uint16, pbit uint8) bool {
var igp *IgmpGroupPort
var groupModified = false
@@ -409,7 +410,7 @@
logger.Debugw(ctx, "New IGMP receiver", log.Fields{"Group": igc.GroupAddr.String(), "Port": port})
if len(igc.NewReceivers) == 1 && len(igc.CurReceivers) == 0 {
groupModified = true
- igc.AddMcFlow()
+ igc.AddMcFlow(cntx)
logger.Debugw(ctx, "Added New Flow", log.Fields{"Group": igc.GroupAddr.String(), "Port": port})
}
if !incl {
@@ -419,7 +420,7 @@
}
// Process the include/exclude list which may end up modifying the group
- if change, _ := igc.ProcessSources(port, ip, incl); change {
+ if change, _ := igc.ProcessSources(cntx, port, ip, incl); change {
groupModified = true
}
igc.ProcessMode(port, incl)
@@ -435,10 +436,10 @@
logger.Debugw(ctx, "Channel Receiver Added", log.Fields{"Group Channel": igc.GroupAddr, "Group Port": igp})
- if err := igc.WriteToDb(); err != nil {
+ if err := igc.WriteToDb(cntx); err != nil {
logger.Errorw(ctx, "Igmp group channel Write to DB failed", log.Fields{"mvlan": igc.Mvlan, "GroupAddr": igc.GroupAddr})
}
- if err := igp.WriteToDb(igc.Mvlan, igc.GroupAddr, igc.Device); err != nil {
+ if err := igp.WriteToDb(cntx, igc.Mvlan, igc.GroupAddr, igc.Device); err != nil {
logger.Errorw(ctx, "Igmp group port Write to DB failed", log.Fields{"mvlan": igc.Mvlan, "GroupAddr": igc.GroupAddr})
}
return isNewReceiver
@@ -446,7 +447,7 @@
// DelReceiver is called when Query expiry happened for a receiver. This removes the receiver from the
// the group
-func (igc *IgmpGroupChannel) DelReceiver(port string, incl bool, srcList []net.IP) bool {
+func (igc *IgmpGroupChannel) DelReceiver(cntx context.Context, port string, incl bool, srcList []net.IP) bool {
// The receiver may exist either in NewReceiver list or
// the CurReceivers list. Find and remove it from either
// of the lists.
@@ -455,7 +456,7 @@
logger.Debugw(ctx, "Current Receivers", log.Fields{"Current": igc.CurReceivers})
receiversUpdated := false
- groupModified, receiverSrcListEmpty := igc.ProcessSources(port, srcList, incl)
+ groupModified, receiverSrcListEmpty := igc.ProcessSources(cntx, port, srcList, incl)
if len(srcList) == 0 || len(igc.IncludeList) == 0 || receiverSrcListEmpty {
if igp, ok := igc.NewReceivers[port]; ok {
@@ -478,11 +479,11 @@
return false
}
}
- _ = db.DelIgmpRcvr(igc.Mvlan, igc.GroupAddr, igc.Device, port)
+ _ = db.DelIgmpRcvr(cntx, igc.Mvlan, igc.GroupAddr, igc.Device, port)
}
if igc.NumReceivers() == 0 {
- igc.DelMcFlow()
+ igc.DelMcFlow(cntx)
mvp := GetApplication().GetMvlanProfileByTag(igc.Mvlan)
/* If proxy is configured and NumReceivers is 0, then we can reset the igc src list so that we send leave */
if _, ok := mvp.Proxy[igc.GroupName]; ok {
@@ -496,7 +497,7 @@
igc.SendReport(false)
logger.Infow(ctx, "Updated SourceList for Channel", log.Fields{"Current": igc.CurReceivers, "New": igc.NewReceivers})
}
- if err := igc.WriteToDb(); err != nil {
+ if err := igc.WriteToDb(cntx); err != nil {
logger.Errorw(ctx, "Igmp group channel Write to DB failed", log.Fields{"mvlan": igc.Mvlan, "GroupAddr": igc.GroupAddr})
}
logger.Infow(ctx, "Updated Receiver info for Channel", log.Fields{"Current": igc.CurReceivers, "New": igc.NewReceivers})
@@ -505,11 +506,11 @@
}
// DelAllReceivers deletes all receiver for the provided igmp device
-func (igc *IgmpGroupChannel) DelAllReceivers() {
+func (igc *IgmpGroupChannel) DelAllReceivers(cntx context.Context) {
logger.Infow(ctx, "Deleting All Receiver for Channel", log.Fields{"Device": igc.Device, "Channel": igc.GroupAddr.String()})
- _ = db.DelAllIgmpRcvr(igc.Mvlan, igc.GroupAddr, igc.Device)
+ _ = db.DelAllIgmpRcvr(cntx, igc.Mvlan, igc.GroupAddr, igc.Device)
igc.Exclude = 0
- igc.DelMcFlow()
+ igc.DelMcFlow(cntx)
igc.SendLeaveToServer()
logger.Infow(ctx, "MC Flow deleted and Leave sent", log.Fields{"Channel": igc.GroupAddr.String(), "Device": igc.Device})
}
@@ -581,18 +582,18 @@
}
// AddMcFlow adds flow to the device when the first receiver joins
-func (igc *IgmpGroupChannel) AddMcFlow() {
+func (igc *IgmpGroupChannel) AddMcFlow(cntx context.Context) {
flow, err := igc.BuildMcFlow()
if err != nil {
logger.Warnw(ctx, "MC Flow Build Failed", log.Fields{"Reason": err.Error()})
return
}
port, _ := GetApplication().GetNniPort(igc.Device)
- _ = cntlr.GetController().AddFlows(port, igc.Device, flow)
+ _ = cntlr.GetController().AddFlows(cntx, port, igc.Device, flow)
}
// DelMcFlow deletes flow from the device when the last receiver leaves
-func (igc *IgmpGroupChannel) DelMcFlow() {
+func (igc *IgmpGroupChannel) DelMcFlow(cntx context.Context) {
flow, err := igc.BuildMcFlow()
if err != nil {
logger.Warnw(ctx, "MC Flow Build Failed", log.Fields{"Reason": err.Error()})
@@ -603,7 +604,7 @@
if mvpIntf, _ := GetApplication().MvlanProfilesByTag.Load(igc.Mvlan); mvpIntf != nil {
mvp := mvpIntf.(*MvlanProfile)
- err := mvp.DelFlows(device, flow)
+ err := mvp.DelFlows(cntx, device, flow)
if err != nil {
logger.Warnw(ctx, "Delering IGMP Flow for device failed ", log.Fields{"Device": device, "err": err})
}
diff --git a/internal/pkg/application/igmpgroupdevice.go b/internal/pkg/application/igmpgroupdevice.go
index 07c2f82..0d59747 100644
--- a/internal/pkg/application/igmpgroupdevice.go
+++ b/internal/pkg/application/igmpgroupdevice.go
@@ -16,6 +16,7 @@
package application
import (
+ "context"
"encoding/json"
"net"
"sync"
@@ -103,12 +104,12 @@
// IgmpGroupDeviceReInit is re-initializer for a device. The default IGMP version is set to 3
// as the protocol defines the way to manage backward compatibility
-func (igd *IgmpGroupDevice) IgmpGroupDeviceReInit(ig *IgmpGroup) {
+func (igd *IgmpGroupDevice) IgmpGroupDeviceReInit(cntx context.Context, ig *IgmpGroup) {
logger.Infow(ctx, "Reinitialize Igmp Group Device", log.Fields{"Device": igd.Device, "GroupID": ig.GroupID, "OldName": igd.GroupName, "Name": ig.GroupName, "OldAddr": igd.GroupAddr.String(), "GroupAddr": ig.GroupAddr.String()})
if (igd.GroupName != ig.GroupName) || !igd.GroupAddr.Equal(ig.GroupAddr) {
- _ = db.DelIgmpDevice(igd.Mvlan, igd.GroupName, igd.GroupAddr, igd.Device)
+ _ = db.DelIgmpDevice(cntx, igd.Mvlan, igd.GroupName, igd.GroupAddr, igd.Device)
igd.GroupName = ig.GroupName
igd.GroupAddr = ig.GroupAddr
}
@@ -126,7 +127,7 @@
mcastCfg.IgmpGroupDevices.Store(ig.GroupID, igd)
logger.Debugw(ctx, "Igd added to mcast config", log.Fields{"mvlan": mcastCfg.MvlanProfileID, "groupId": ig.GroupID})
}
- if err := igd.WriteToDb(); err != nil {
+ if err := igd.WriteToDb(cntx); err != nil {
logger.Errorw(ctx, "Igmp group device Write to DB failed", log.Fields{"Device": igd.Device, "GroupName": igd.GroupName, "GroupAddr": igd.GroupAddr.String()})
}
}
@@ -144,24 +145,24 @@
}
// updateGroupName to update the group name
-func (igd *IgmpGroupDevice) updateGroupName(newGroupName string) {
+func (igd *IgmpGroupDevice) updateGroupName(cntx context.Context, newGroupName string) {
oldName := igd.GroupName
igd.GroupName = newGroupName
updateGroupName := func(key, value interface{}) bool {
igc := value.(*IgmpGroupChannel)
igc.GroupName = newGroupName
- if err := igc.WriteToDb(); err != nil {
+ if err := igc.WriteToDb(cntx); err != nil {
logger.Errorw(ctx, "Igmp group channel Write to DB failed", log.Fields{"mvlan": igc.Mvlan, "GroupAddr": igc.GroupAddr})
}
- _ = db.DelIgmpChannel(igc.Mvlan, oldName, igc.Device, igc.GroupAddr)
+ _ = db.DelIgmpChannel(cntx, igc.Mvlan, oldName, igc.Device, igc.GroupAddr)
return true
}
igd.GroupChannels.Range(updateGroupName)
- if err := igd.WriteToDb(); err != nil {
+ if err := igd.WriteToDb(cntx); err != nil {
logger.Errorw(ctx, "Igmp group device Write to DB failed", log.Fields{"Device": igd.Device, "GroupName": igd.GroupName, "GroupAddr": igd.GroupAddr.String()})
}
- _ = db.DelIgmpDevice(igd.Mvlan, oldName, igd.GroupAddr, igd.Device)
+ _ = db.DelIgmpDevice(cntx, igd.Mvlan, oldName, igd.GroupAddr, igd.Device)
}
// NewIgmpGroupDeviceFromBytes is to create the IGMP group port from a byte slice
@@ -184,14 +185,14 @@
}
// RestoreChannel to restore channel
-func (igd *IgmpGroupDevice) RestoreChannel(igmpGroupChannel []byte) {
+func (igd *IgmpGroupDevice) RestoreChannel(cntx context.Context, igmpGroupChannel []byte) {
if igc, err := NewIgmpGroupChannelFromBytes(igmpGroupChannel); err == nil {
igc.ServVersion = igd.ServVersion
igc.IgmpProxyIP = &igd.IgmpProxyIP
igc.proxyCfg = &igd.proxyCfg
igd.GroupChannels.Store(igc.GroupAddr.String(), igc)
- igc.RestorePorts()
+ igc.RestorePorts(cntx)
for port, igp := range igc.NewReceivers {
ipsList := []net.IP{}
@@ -215,10 +216,10 @@
}
// RestoreChannels to restore channels
-func (igd *IgmpGroupDevice) RestoreChannels() {
+func (igd *IgmpGroupDevice) RestoreChannels(cntx context.Context) {
- igd.migrateIgmpChannels()
- channels, _ := db.GetIgmpChannels(igd.Mvlan, igd.GroupName, igd.Device)
+ igd.migrateIgmpChannels(cntx)
+ channels, _ := db.GetIgmpChannels(cntx, igd.Mvlan, igd.GroupName, igd.Device)
for _, channel := range channels {
b, ok := channel.Value.([]byte)
@@ -226,19 +227,19 @@
logger.Warn(ctx, "The value type is not []byte")
continue
}
- igd.RestoreChannel(b)
+ igd.RestoreChannel(cntx, b)
}
}
// WriteToDb is utility to write IGMP Group Device Info to the database
-func (igd *IgmpGroupDevice) WriteToDb() error {
+func (igd *IgmpGroupDevice) WriteToDb(cntx context.Context) error {
b, err := json.Marshal(igd)
if err != nil {
return err
}
- if err1 := db.PutIgmpDevice(igd.Mvlan, igd.GroupName, igd.GroupAddr, igd.Device, string(b)); err1 != nil {
+ if err1 := db.PutIgmpDevice(cntx, igd.Mvlan, igd.GroupName, igd.GroupAddr, igd.Device, string(b)); err1 != nil {
return err1
}
logger.Info(ctx, "IGD Updated")
@@ -332,7 +333,7 @@
// AddReceiver add the receiver to the device and perform other actions such as adding the group
// to the physical device, add members, add flows to point the MC packets to the
// group. Also, send a IGMP report upstream if there is a change in the group
-func (igd *IgmpGroupDevice) AddReceiver(port string, groupAddr net.IP,
+func (igd *IgmpGroupDevice) AddReceiver(cntx context.Context, port string, groupAddr net.IP,
group *layers.IGMPv3GroupRecord, version uint8, cvlan uint16, pbit uint8, ponPortID uint32) {
var igc *IgmpGroupChannel
@@ -347,11 +348,11 @@
}
if !igd.GroupInstalled {
- igd.AddNewReceiver(port, groupAddr, group, cvlan, pbit, ponPortID)
+ igd.AddNewReceiver(cntx, port, groupAddr, group, cvlan, pbit, ponPortID)
return
}
- isNewReceiver := igc.AddReceiver(port, group, cvlan, pbit)
+ isNewReceiver := igc.AddReceiver(cntx, port, group, cvlan, pbit)
if isNewReceiver {
ipsList := []net.IP{}
ipsIntf, _ := igd.PortChannelMap.Load(port)
@@ -368,13 +369,13 @@
igd.ModMcGroup()
}
}
- if err := igd.WriteToDb(); err != nil {
+ if err := igd.WriteToDb(cntx); err != nil {
logger.Errorw(ctx, "Igmp group device Write to DB failed", log.Fields{"Device": igd.Device, "GroupName": igd.GroupName, "GroupAddr": igd.GroupAddr.String()})
}
}
// AddNewReceiver to add new receiver
-func (igd *IgmpGroupDevice) AddNewReceiver(port string, groupAddr net.IP, group *layers.IGMPv3GroupRecord, cvlan uint16, pbit uint8, ponPortID uint32) {
+func (igd *IgmpGroupDevice) AddNewReceiver(cntx context.Context, port string, groupAddr net.IP, group *layers.IGMPv3GroupRecord, cvlan uint16, pbit uint8, ponPortID uint32) {
logger.Debugw(ctx, "Adding New Device Receiver", log.Fields{"Channel": groupAddr, "Port": port, "Device": igd.Device})
igcIntf, _ := igd.GroupChannels.Load(groupAddr.String())
@@ -395,8 +396,8 @@
logger.Debugw(ctx, "Port Channel Updated", log.Fields{"Port": port, "NewChannelList": ipsList, "Addr": groupAddr})
igd.AddMcGroup()
- igc.AddReceiver(port, group, cvlan, pbit)
- if err := igd.WriteToDb(); err != nil {
+ igc.AddReceiver(cntx, port, group, cvlan, pbit)
+ if err := igd.WriteToDb(cntx); err != nil {
logger.Errorw(ctx, "Igmp group device Write to DB failed", log.Fields{"Device": igd.Device, "GroupName": igd.GroupName, "GroupAddr": igd.GroupAddr.String()})
}
}
@@ -415,7 +416,7 @@
// DelReceiver is called when Query expiry happened for a receiver. This removes the receiver from the
// the group
-func (igd *IgmpGroupDevice) DelReceiver(groupAddr net.IP, port string, group *layers.IGMPv3GroupRecord, ponPortID uint32) {
+func (igd *IgmpGroupDevice) DelReceiver(cntx context.Context, groupAddr net.IP, port string, group *layers.IGMPv3GroupRecord, ponPortID uint32) {
logger.Debugw(ctx, "Deleting Receiver for Device", log.Fields{"port": port, "GroupIP": groupAddr.String()})
var igc *IgmpGroupChannel
@@ -437,12 +438,12 @@
return
}
igc = igcIntf.(*IgmpGroupChannel)
- if ok := igc.DelReceiver(port, incl, srcList); !ok {
+ if ok := igc.DelReceiver(cntx, port, incl, srcList); !ok {
return
}
if igc.NumReceivers() == 0 {
- igd.DelIgmpGroupChannel(igc)
+ igd.DelIgmpGroupChannel(cntx, igc)
}
igd.DelPortFromChannel(port, groupAddr)
isGroupModified := igd.RemoveChannelFromChannelsPerPon(port, groupAddr, ponPortID)
@@ -451,14 +452,14 @@
if isGroupModified {
igd.ModMcGroup()
}
- if err := igd.WriteToDb(); err != nil {
+ if err := igd.WriteToDb(cntx); err != nil {
logger.Errorw(ctx, "Igmp group device Write to DB failed", log.Fields{"Device": igd.Device, "GroupName": igd.GroupName, "GroupAddr": igd.GroupAddr.String()})
}
}
// DelChannelReceiver is called when Query expiry happened for a receiver. This removes the receiver from the
// the group
-func (igd *IgmpGroupDevice) DelChannelReceiver(groupAddr net.IP) map[string]*IgmpGroupPort {
+func (igd *IgmpGroupDevice) DelChannelReceiver(cntx context.Context, groupAddr net.IP) map[string]*IgmpGroupPort {
portsRemoved := make(map[string]*IgmpGroupPort)
groupModified := false
@@ -471,7 +472,7 @@
igc := igcIntf.(*IgmpGroupChannel)
for port, igp := range igc.NewReceivers {
- _ = db.DelIgmpRcvr(igc.Mvlan, igc.GroupAddr, igc.Device, port) //TODO: Y not here
+ _ = db.DelIgmpRcvr(cntx, igc.Mvlan, igc.GroupAddr, igc.Device, port) //TODO: Y not here
igd.DelPortFromChannel(port, igc.GroupAddr)
ponPortID := GetApplication().GetPonPortID(igd.Device, port)
groupModified = igd.RemoveChannelFromChannelsPerPon(port, igc.GroupAddr, ponPortID)
@@ -479,7 +480,7 @@
portsRemoved[port] = igp
}
for port, igp := range igc.CurReceivers {
- _ = db.DelIgmpRcvr(igc.Mvlan, igc.GroupAddr, igc.Device, port)
+ _ = db.DelIgmpRcvr(cntx, igc.Mvlan, igc.GroupAddr, igc.Device, port)
igd.DelPortFromChannel(port, igc.GroupAddr)
ponPortID := GetApplication().GetPonPortID(igd.Device, port)
groupModified = igd.RemoveChannelFromChannelsPerPon(port, igc.GroupAddr, ponPortID)
@@ -487,15 +488,15 @@
portsRemoved[port] = igp
}
- igc.DelMcFlow()
- igd.DelIgmpGroupChannel(igc)
+ igc.DelMcFlow(cntx)
+ igd.DelIgmpGroupChannel(cntx, igc)
igc.Exclude = 0
igc.SendLeaveToServer()
if groupModified {
igd.ModMcGroup()
}
- if err := igd.WriteToDb(); err != nil {
+ if err := igd.WriteToDb(cntx); err != nil {
logger.Errorw(ctx, "Igmp group device Write to DB failed", log.Fields{"Device": igd.Device, "GroupName": igd.GroupName, "GroupAddr": igd.GroupAddr.String()})
}
logger.Debugw(ctx, "Deleted the receiver Flow", log.Fields{"Num Receivers": igc.NumReceivers()})
@@ -503,12 +504,12 @@
}
// DelIgmpGroupChannel to delete igmp group channel
-func (igd *IgmpGroupDevice) DelIgmpGroupChannel(igc *IgmpGroupChannel) {
+func (igd *IgmpGroupDevice) DelIgmpGroupChannel(cntx context.Context, igc *IgmpGroupChannel) {
if igc.NumReceivers() != 0 {
- igc.DelAllReceivers()
+ igc.DelAllReceivers(cntx)
}
- _ = db.DelIgmpChannel(igc.Mvlan, igc.GroupName, igc.Device, igc.GroupAddr)
+ _ = db.DelIgmpChannel(cntx, igc.Mvlan, igc.GroupName, igc.Device, igc.GroupAddr)
igd.GroupChannels.Delete(igc.GroupAddr.String())
logger.Infow(ctx, "Deleted the Channel from Device", log.Fields{"Channel": igc.GroupAddr.String()})
isLenZero := true
@@ -554,24 +555,24 @@
}
// DelAllChannels deletes all receiver for the provided igmp device
-func (igd *IgmpGroupDevice) DelAllChannels() {
+func (igd *IgmpGroupDevice) DelAllChannels(cntx context.Context) {
logger.Infow(ctx, "Deleting All Channel for Device", log.Fields{"Device": igd.Device, "Group": igd.GroupName})
delGroupChannels := func(key interface{}, value interface{}) bool {
igc := value.(*IgmpGroupChannel)
- igd.DelIgmpGroupChannel(igc)
+ igd.DelIgmpGroupChannel(cntx, igc)
return true
}
igd.GroupChannels.Range(delGroupChannels)
}
// ProcessQuery process query received from the upstream IGMP server
-func (igd *IgmpGroupDevice) ProcessQuery(groupAddr net.IP, ver uint8) {
+func (igd *IgmpGroupDevice) ProcessQuery(cntx context.Context, groupAddr net.IP, ver uint8) {
logger.Debugw(ctx, "Received Query From Server", log.Fields{"Version": ver})
if ver != *igd.ServVersion {
igd.ServVersionExpiry = time.Now().Add(time.Duration(2*igd.proxyCfg.KeepAliveInterval) * time.Second)
*igd.ServVersion = ver
mvp := GetApplication().GetMvlanProfileByTag(igd.Mvlan)
- if err := mvp.WriteToDb(); err != nil {
+ if err := mvp.WriteToDb(cntx); err != nil {
logger.Errorw(ctx, "Mvlan profile write to DB failed", log.Fields{"ProfileName": mvp.Name})
}
}
@@ -676,7 +677,7 @@
// QueryExpiry processes query expiry. Upon expiry, take stock of the situation
// add either retain/release the group based on number of receivers left
-func (igd *IgmpGroupDevice) QueryExpiry() {
+func (igd *IgmpGroupDevice) QueryExpiry(cntx context.Context) {
logger.Debugw(ctx, "Query Expiry", log.Fields{"Device": igd.Device})
@@ -695,7 +696,7 @@
logger.Debugw(ctx, "Expired Member Port State", log.Fields{"state": state})
ponPortID := GetApplication().GetPonPortID(igd.Device, portKey)
if err == nil && state == cntlr.PortStateDown {
- igd.DelReceiver(igc.GroupAddr, portKey, nil, ponPortID)
+ igd.DelReceiver(cntx, igc.GroupAddr, portKey, nil, ponPortID)
}
port.QueryTimeoutCount++
@@ -703,10 +704,10 @@
if port.QueryTimeoutCount >= (*igc.proxyCfg).KeepAliveCount {
logger.Errorw(ctx, "Expiry Timeout count exceeded. Trigger delete receiver", log.Fields{"PortKey": portKey,
"GroupAddr": igc.GroupAddr, "Count": port.QueryTimeoutCount})
- igd.DelReceiver(igc.GroupAddr, portKey, nil, ponPortID)
+ igd.DelReceiver(cntx, igc.GroupAddr, portKey, nil, ponPortID)
SendQueryExpiredEventGroupSpecific(portKey, igd, igc)
} else {
- _ = port.WriteToDb(igc.Mvlan, igc.GroupAddr, igc.Device)
+ _ = port.WriteToDb(cntx, igc.Mvlan, igc.GroupAddr, igc.Device)
}
}
return true
diff --git a/internal/pkg/application/igmpport.go b/internal/pkg/application/igmpport.go
index 5fe88e0..b22b901 100644
--- a/internal/pkg/application/igmpport.go
+++ b/internal/pkg/application/igmpport.go
@@ -16,6 +16,7 @@
package application
import (
+ "context"
"encoding/json"
"net"
@@ -100,12 +101,12 @@
}
// WriteToDb is utility to write IGMP Group Port Info to database
-func (igp *IgmpGroupPort) WriteToDb(mvlan of.VlanType, gip net.IP, device string) error {
+func (igp *IgmpGroupPort) WriteToDb(cntx context.Context, mvlan of.VlanType, gip net.IP, device string) error {
b, err := json.Marshal(igp)
if err != nil {
return err
}
- if err1 := db.PutIgmpRcvr(mvlan, gip, device, igp.Port, string(b)); err1 != nil {
+ if err1 := db.PutIgmpRcvr(cntx, mvlan, gip, device, igp.Port, string(b)); err1 != nil {
return err1
}
return nil
diff --git a/internal/pkg/application/igmpprofiles.go b/internal/pkg/application/igmpprofiles.go
index b5b24d4..192c8e2 100644
--- a/internal/pkg/application/igmpprofiles.go
+++ b/internal/pkg/application/igmpprofiles.go
@@ -16,6 +16,7 @@
package application
import (
+ "context"
"encoding/json"
"errors"
"net"
@@ -157,7 +158,7 @@
}
// WriteToDb is utility to write Mvlan Profile Info to database
-func (mvp *MvlanProfile) WriteToDb() error {
+func (mvp *MvlanProfile) WriteToDb(cntx context.Context) error {
if mvp.DeleteInProgress {
logger.Warnw(ctx, "Skipping Redis Update for MvlanProfile, MvlanProfile delete in progress", log.Fields{"Mvlan": mvp.Mvlan})
@@ -169,7 +170,7 @@
if err != nil {
return err
}
- if err1 := db.PutMvlan(uint16(mvp.Mvlan), string(b)); err1 != nil {
+ if err1 := db.PutMvlan(cntx, uint16(mvp.Mvlan), string(b)); err1 != nil {
return err1
}
return nil
@@ -288,12 +289,12 @@
}
// DelFromDb to delere mvlan from database
-func (mvp *MvlanProfile) DelFromDb() {
- _ = db.DelMvlan(uint16(mvp.Mvlan))
+func (mvp *MvlanProfile) DelFromDb(cntx context.Context) {
+ _ = db.DelMvlan(cntx, uint16(mvp.Mvlan))
}
//DelFlows - Triggers flow deletion after registering for flow indication event
-func (mvp *MvlanProfile) DelFlows(device *VoltDevice, flow *of.VoltFlow) error {
+func (mvp *MvlanProfile) DelFlows(cntx context.Context, device *VoltDevice, flow *of.VoltFlow) error {
mvp.mvpFlowLock.Lock()
defer mvp.mvpFlowLock.Unlock()
@@ -316,14 +317,14 @@
flowMap[cookie] = true
mvp.PendingDeleteFlow[device.Name] = flowMap
}
- if err := mvp.WriteToDb(); err != nil {
+ if err := mvp.WriteToDb(cntx); err != nil {
logger.Errorw(ctx, "Mvlan profile write to DB failed", log.Fields{"ProfileName": mvp.Name})
}
- return cntlr.GetController().DelFlows(device.NniPort, device.Name, flow)
+ return cntlr.GetController().DelFlows(cntx, device.NniPort, device.Name, flow)
}
//FlowRemoveSuccess - Process flow success indication
-func (mvp *MvlanProfile) FlowRemoveSuccess(cookie string, device string) {
+func (mvp *MvlanProfile) FlowRemoveSuccess(cntx context.Context, cookie string, device string) {
mvp.mvpFlowLock.Lock()
defer mvp.mvpFlowLock.Unlock()
@@ -333,7 +334,7 @@
delete(mvp.PendingDeleteFlow[device], cookie)
}
- if err := mvp.WriteToDb(); err != nil {
+ if err := mvp.WriteToDb(cntx); err != nil {
logger.Errorw(ctx, "Mvlan profile write to DB failed", log.Fields{"ProfileName": mvp.Name})
}
}
@@ -394,7 +395,7 @@
}
//pushIgmpMcastFlows - Adds all IGMP related flows (generic DS flow & static group flows)
-func (mvp *MvlanProfile) pushIgmpMcastFlows(OLTSerialNum string) {
+func (mvp *MvlanProfile) pushIgmpMcastFlows(cntx context.Context, OLTSerialNum string) {
mvp.mvpLock.RLock()
defer mvp.mvpLock.RUnlock()
@@ -416,7 +417,7 @@
logger.Infow(ctx, "NNI Port Status is: UP & Vlan Enabled", log.Fields{"Device": d, "port": p})
//Push Igmp DS Control Flows
- err := mvp.ApplyIgmpDSFlowForMvp(d.Name)
+ err := mvp.ApplyIgmpDSFlowForMvp(cntx, d.Name)
if err != nil {
logger.Errorw(ctx, "DS IGMP Flow Add Failed for device",
log.Fields{"Reason": err.Error(), "device": d.Name})
@@ -424,14 +425,14 @@
//Trigger Join for static channels
if channelList, containsStatic := mvp.getAllStaticChannels(); containsStatic {
- mvp.ProcessStaticGroup(d.Name, channelList, true)
+ mvp.ProcessStaticGroup(cntx, d.Name, channelList, true)
} else {
logger.Infow(ctx, "No Static Channels Present", log.Fields{"mvp": mvp.Name, "Mvlan": mvp.Mvlan})
}
}
}
//removeIgmpMcastFlows - Removes all IGMP related flows (generic DS flow & static group flows)
-func (mvp *MvlanProfile) removeIgmpMcastFlows(oltSerialNum string) {
+func (mvp *MvlanProfile) removeIgmpMcastFlows(cntx context.Context, oltSerialNum string) {
mvp.mvpLock.RLock()
defer mvp.mvpLock.RUnlock()
@@ -446,7 +447,7 @@
//Trigger Leave for static channels
if channelList, containsStatic := mvp.getAllStaticChannels(); containsStatic {
- mvp.ProcessStaticGroup(d.Name, channelList, false)
+ mvp.ProcessStaticGroup(cntx, d.Name, channelList, false)
} else {
logger.Infow(ctx, "No Static Channels Present", log.Fields{"mvp": mvp.Name, "Mvlan": mvp.Mvlan})
}
@@ -456,16 +457,16 @@
ig := value.(*IgmpGroup)
if ig.Mvlan == mvp.Mvlan {
igd := ig.Devices[d.Name]
- ig.DelIgmpGroupDevice(igd)
+ ig.DelIgmpGroupDevice(cntx, igd)
if ig.NumDevicesActive() == 0 {
- GetApplication().DelIgmpGroup(ig)
+ GetApplication().DelIgmpGroup(cntx, ig)
}
}
return true
})
//Remove DS Igmp trap flow
- err := mvp.RemoveIgmpDSFlowForMvp(d.Name)
+ err := mvp.RemoveIgmpDSFlowForMvp(cntx, d.Name)
if err != nil {
logger.Errorw(ctx, "DS IGMP Flow Del Failed", log.Fields{"Reason": err.Error(), "device": d.Name})
}
@@ -474,7 +475,7 @@
}
// ApplyIgmpDSFlowForMvp to apply Igmp DS flow for mvlan.
-func (mvp *MvlanProfile) ApplyIgmpDSFlowForMvp(device string) error {
+func (mvp *MvlanProfile) ApplyIgmpDSFlowForMvp(cntx context.Context, device string) error {
va := GetApplication()
dIntf, ok := va.DevicesDisc.Load(device)
if !ok {
@@ -487,7 +488,7 @@
if !ok || !flowAlreadyApplied {
flows, err := mvp.BuildIgmpDSFlows(device)
if err == nil {
- err = cntlr.GetController().AddFlows(d.NniPort, device, flows)
+ err = cntlr.GetController().AddFlows(cntx, d.NniPort, device, flows)
if err != nil {
logger.Warnw(ctx, "Configuring IGMP Flow for device failed ", log.Fields{"Device": device, "err": err})
return err
@@ -504,7 +505,7 @@
}
// RemoveIgmpDSFlowForMvp to remove Igmp DS flow for mvlan.
-func (mvp *MvlanProfile) RemoveIgmpDSFlowForMvp(device string) error {
+func (mvp *MvlanProfile) RemoveIgmpDSFlowForMvp(cntx context.Context, device string) error {
va := GetApplication()
mvlan := mvp.Mvlan
@@ -522,7 +523,7 @@
if err == nil {
flows.ForceAction = true
- err = mvp.DelFlows(d, flows)
+ err = mvp.DelFlows(cntx, d, flows)
if err != nil {
logger.Warnw(ctx, "De-Configuring IGMP Flow for device failed ", log.Fields{"Device": device, "err": err})
return err
@@ -572,7 +573,7 @@
}
//updateStaticGroups - Generates static joins & leaves for newly added and removed static channels respectively
-func (mvp *MvlanProfile) updateStaticGroups(deviceID string, added []net.IP, removed []net.IP) {
+func (mvp *MvlanProfile) updateStaticGroups(cntx context.Context, deviceID string, added []net.IP, removed []net.IP) {
//Update static group configs for all associated devices
updateGroups := func(key interface{}, value interface{}) bool {
@@ -583,8 +584,8 @@
return true
}
//TODO if mvp.IsChannelBasedGroup {
- mvp.ProcessStaticGroup(d.Name, added, true)
- mvp.ProcessStaticGroup(d.Name, removed, false)
+ mvp.ProcessStaticGroup(cntx, d.Name, added, true)
+ mvp.ProcessStaticGroup(cntx, d.Name, removed, false)
//}
return true
}
@@ -598,7 +599,7 @@
}
//updateDynamicGroups - Generates joins with updated sources for existing channels
-func (mvp *MvlanProfile) updateDynamicGroups(deviceID string, added []net.IP, removed []net.IP) {
+func (mvp *MvlanProfile) updateDynamicGroups(cntx context.Context, deviceID string, added []net.IP, removed []net.IP) {
//mvlan := mvp.Mvlan
va := GetApplication()
@@ -617,7 +618,7 @@
logger.Debugw(ctx, "IGMP Group", log.Fields{"Group": grpKey, "groupAddr": groupAddr})
if igIntf, ok := va.IgmpGroups.Load(grpKey); ok {
ig := igIntf.(*IgmpGroup)
- if igd, ok := ig.getIgmpGroupDevice(d.Name); ok {
+ if igd, ok := ig.getIgmpGroupDevice(cntx, d.Name); ok {
if igcIntf, ok := igd.GroupChannels.Load(groupAddr.String()); ok {
igc := igcIntf.(*IgmpGroupChannel)
incl := false
@@ -631,12 +632,12 @@
}
for port, igp := range igc.NewReceivers {
// Process the include/exclude list which may end up modifying the group
- if change, _ := igc.ProcessSources(port, ip, incl); change {
+ if change, _ := igc.ProcessSources(cntx, port, ip, incl); change {
groupModified = true
}
igc.ProcessMode(port, incl)
- if err := igp.WriteToDb(igc.Mvlan, igc.GroupAddr, igc.Device); err != nil {
+ if err := igp.WriteToDb(cntx, igc.Mvlan, igc.GroupAddr, igc.Device); err != nil {
logger.Errorw(ctx, "Igmp group port Write to DB failed", log.Fields{"mvlan": igc.Mvlan, "GroupAddr": igc.GroupAddr})
}
}
@@ -646,7 +647,7 @@
logger.Debug(ctx, "Group Modified and IGMP report sent to the upstream server")
igc.SendReport(false)
}
- if err := igc.WriteToDb(); err != nil {
+ if err := igc.WriteToDb(cntx); err != nil {
logger.Errorw(ctx, "Igmp group channel Write to DB failed", log.Fields{"mvlan": igc.Mvlan, "GroupAddr": igc.GroupAddr})
}
}
@@ -667,7 +668,7 @@
//GroupsUpdated - Handles removing of Igmp Groups, flows & group table entries for
//channels removed as part of update
-func (mvp *MvlanProfile) GroupsUpdated(deviceID string) {
+func (mvp *MvlanProfile) GroupsUpdated(cntx context.Context, deviceID string) {
deleteChannelIfRemoved := func(key interface{}, value interface{}) bool {
ig := value.(*IgmpGroup)
@@ -703,32 +704,32 @@
// If channel is not Static but existing Group is static - Migrate (from static to dynamic)
// (Channel removed from satic but part of dynamic)
if (staticChannel != mvp.IsStaticGroup(ig.GroupName)) || (ig.IsGroupStatic != mvp.IsStaticGroup(ig.GroupName)) { // Equivalent of XOR
- ig.HandleGroupMigration(deviceID, channelIP)
+ ig.HandleGroupMigration(cntx, deviceID, channelIP)
} else {
if (ig.IsGroupStatic) && mvp.IsStaticGroup(ig.GroupName) {
if ig.GroupName != mvp.GetStaticGroupName(channelIP) {
- ig.HandleGroupMigration(deviceID, channelIP)
+ ig.HandleGroupMigration(cntx, deviceID, channelIP)
}
}
continue
}
} else {
logger.Debugw(ctx, "Channel Removed", log.Fields{"Channel": channel, "Group": grpName})
- ig.DelIgmpChannel(deviceID, net.ParseIP(channel))
+ ig.DelIgmpChannel(cntx, deviceID, net.ParseIP(channel))
if ig.NumDevicesActive() == 0 {
- GetApplication().DelIgmpGroup(ig)
+ GetApplication().DelIgmpGroup(cntx, ig)
}
}
}
ig.IsGroupStatic = mvp.IsStaticGroup(ig.GroupName)
- if err := ig.WriteToDb(); err != nil {
+ if err := ig.WriteToDb(cntx); err != nil {
logger.Errorw(ctx, "Igmp group Write to DB failed", log.Fields{"groupName": ig.GroupName})
}
return true
}
}
logger.Debugw(ctx, "Group Removed", log.Fields{"Channel": ig.GroupAddr, "Group": grpName, "ChannelBasedGroup": ig.IsChannelBasedGroup})
- ig.DelIgmpGroup()
+ ig.DelIgmpGroup(cntx)
logger.Debugw(ctx, "Removed Igmp Group", log.Fields{"Channel": ig.GroupAddr, "Group": grpName})
return true
}
@@ -771,7 +772,7 @@
}
// ProcessStaticGroup - Process Static Join/Leave Req for static channels
-func (mvp *MvlanProfile) ProcessStaticGroup(device string, groupAddresses []net.IP, isJoin bool) {
+func (mvp *MvlanProfile) ProcessStaticGroup(cntx context.Context, device string, groupAddresses []net.IP, isJoin bool) {
logger.Debugw(ctx, "Received Static Group Request", log.Fields{"Device": device, "Join": isJoin, "Group Address List": groupAddresses})
@@ -790,9 +791,9 @@
if ig == nil {
// First time group Creation: Create the IGMP group and then add the receiver to the group
logger.Infow(ctx, "Static IGMP Add received for new group", log.Fields{"Addr": groupAddr, "Port": StaticPort})
- if ig := GetApplication().AddIgmpGroup(mvp.Name, groupAddr, device); ig != nil {
+ if ig := GetApplication().AddIgmpGroup(cntx, mvp.Name, groupAddr, device); ig != nil {
ig.IgmpGroupLock.Lock()
- ig.AddReceiver(device, StaticPort, groupAddr, nil, getVersion(ver),
+ ig.AddReceiver(cntx, device, StaticPort, groupAddr, nil, getVersion(ver),
0, 0, 0xFF)
ig.IgmpGroupLock.Unlock()
} else {
@@ -801,12 +802,12 @@
} else {
//Converting existing dynamic group to static group
if !mvp.IsStaticGroup(ig.GroupName) {
- ig.updateGroupName(ig.GroupName)
+ ig.updateGroupName(cntx, ig.GroupName)
}
// Update case: If the IGMP group is already created. just add the receiver
logger.Infow(ctx, "Static IGMP Add received for existing group", log.Fields{"Addr": groupAddr, "Port": StaticPort})
ig.IgmpGroupLock.Lock()
- ig.AddReceiver(device, StaticPort, groupAddr, nil, getVersion(ver),
+ ig.AddReceiver(cntx, device, StaticPort, groupAddr, nil, getVersion(ver),
0, 0, 0xFF)
ig.IgmpGroupLock.Unlock()
}
@@ -817,19 +818,19 @@
grpName := mvp.GetMvlanGroup(ig.GroupAddr)
if grpName != "" {
ig.IgmpGroupLock.Lock()
- ig.DelReceiver(device, StaticPort, groupAddr, nil, 0xFF)
+ ig.DelReceiver(cntx, device, StaticPort, groupAddr, nil, 0xFF)
ig.IgmpGroupLock.Unlock()
- ig.updateGroupName(grpName)
+ ig.updateGroupName(cntx, grpName)
} else {
- ig.DelIgmpGroup()
+ ig.DelIgmpGroup(cntx)
}
} else {
ig.IgmpGroupLock.Lock()
- ig.DelReceiver(device, StaticPort, groupAddr, nil, 0xFF)
+ ig.DelReceiver(cntx, device, StaticPort, groupAddr, nil, 0xFF)
ig.IgmpGroupLock.Unlock()
}
if ig.NumDevicesActive() == 0 {
- GetApplication().DelIgmpGroup(ig)
+ GetApplication().DelIgmpGroup(cntx, ig)
}
} else {
logger.Warnw(ctx, "Static IGMP Del received for unknown group", log.Fields{"Addr": groupAddr})
@@ -894,7 +895,7 @@
}
// UpdateProfile - Updates the group & member info w.r.t the mvlan profile for the given device
-func (mvp *MvlanProfile) UpdateProfile(deviceID string) {
+func (mvp *MvlanProfile) UpdateProfile(cntx context.Context, deviceID string) {
logger.Infow(ctx, "Update Mvlan Profile task triggered", log.Fields{"Mvlan": mvp.Mvlan})
var removedStaticChannels []net.IP
addedStaticChannels := []net.IP{}
@@ -922,12 +923,12 @@
logger.Debugw(ctx, "Update Task - Static Group Changes", log.Fields{"Added": addedStaticChannels, "Removed": removedStaticChannels})
if len(addedStaticChannels) > 0 || len(removedStaticChannels) > 0 {
- mvp.updateStaticGroups(deviceID, []net.IP{}, removedStaticChannels)
+ mvp.updateStaticGroups(cntx, deviceID, []net.IP{}, removedStaticChannels)
}
}
- mvp.GroupsUpdated(deviceID)
+ mvp.GroupsUpdated(cntx, deviceID)
if len(addedStaticChannels) > 0 {
- mvp.updateStaticGroups(deviceID, addedStaticChannels, []net.IP{})
+ mvp.updateStaticGroups(cntx, deviceID, addedStaticChannels, []net.IP{})
}
/* Need to handle if SSM params are modified for groups */
@@ -936,10 +937,10 @@
if mvp.checkStaticGrpSSMProxyDiff(mvp.oldProxy[key], mvp.Proxy[key]) {
if mvp.Groups[key].IsStatic {
/* Static group proxy modified, need to trigger membership report with new mode/src-list for existing channels */
- mvp.updateStaticGroups(deviceID, commonChannels, []net.IP{})
+ mvp.updateStaticGroups(cntx, deviceID, commonChannels, []net.IP{})
} else {
/* Dynamic group proxy modified, need to trigger membership report with new mode/src-list for existing channels */
- mvp.updateDynamicGroups(deviceID, commonChannels, []net.IP{})
+ mvp.updateDynamicGroups(cntx, deviceID, commonChannels, []net.IP{})
}
}
}
@@ -949,7 +950,7 @@
if deviceID == "" || !mvp.isUpdateInProgress() {
mvp.oldGroups = nil
}
- if err := mvp.WriteToDb(); err != nil {
+ if err := mvp.WriteToDb(cntx); err != nil {
logger.Errorw(ctx, "Mvlan profile write to DB failed", log.Fields{"ProfileName": mvp.Name})
}
logger.Debugw(ctx, "Updated MVLAN Profile", log.Fields{"VLAN": mvp.Mvlan, "Name": mvp.Name, "Grp IPs": mvp.Groups})
@@ -1055,7 +1056,7 @@
}
//TriggerAssociatedFlowDelete - Re-trigger delete for pending delete flows
-func (mvp *MvlanProfile) TriggerAssociatedFlowDelete(device string) bool {
+func (mvp *MvlanProfile) TriggerAssociatedFlowDelete(cntx context.Context, device string) bool {
mvp.mvpFlowLock.Lock()
cookieList := []uint64{}
@@ -1078,7 +1079,7 @@
subFlow.Cookie = cookie
flow.SubFlows[cookie] = subFlow
logger.Infow(ctx, "Retriggering Vnet Delete Flow", log.Fields{"Device": device, "Mvlan": mvp.Mvlan.String(), "Cookie": cookie})
- err := mvp.DelFlows(vd, flow)
+ err := mvp.DelFlows(cntx, vd, flow)
if err != nil {
logger.Warnw(ctx, "De-Configuring IGMP Flow for device failed ", log.Fields{"Device": device, "err": err})
}
@@ -1216,13 +1217,13 @@
}
// WriteToDb is utility to write Igmp Config Info to database
-func (igmpProfile *IgmpProfile) WriteToDb() error {
+func (igmpProfile *IgmpProfile) WriteToDb(cntx context.Context) error {
igmpProfile.Version = database.PresentVersionMap[database.IgmpProfPath]
b, err := json.Marshal(igmpProfile)
if err != nil {
return err
}
- if err1 := db.PutIgmpProfile(igmpProfile.ProfileID, string(b)); err1 != nil {
+ if err1 := db.PutIgmpProfile(cntx, igmpProfile.ProfileID, string(b)); err1 != nil {
return err1
}
return nil
diff --git a/internal/pkg/application/igmptasks.go b/internal/pkg/application/igmptasks.go
index af42562..268453c 100644
--- a/internal/pkg/application/igmptasks.go
+++ b/internal/pkg/application/igmptasks.go
@@ -72,7 +72,7 @@
func (tt *TickTask) Start(ctx context.Context, taskID uint8) error {
tt.taskID = taskID
tt.ctx = ctx
- GetApplication().IgmpTick()
+ GetApplication().IgmpTick(ctx)
return nil
}
@@ -124,7 +124,7 @@
func (pt *IgmpPacketTask) Start(ctx context.Context, taskID uint8) error {
pt.taskID = taskID
pt.ctx = ctx
- GetApplication().IgmpProcessPkt(pt.Device, pt.Port, pt.Pkt)
+ GetApplication().IgmpProcessPkt(ctx, pt.Device, pt.Port, pt.Pkt)
return nil
}
@@ -170,6 +170,6 @@
mt.taskID = taskID
mt.ctx = ctx
mvp := mt.mvp
- mvp.UpdateProfile(mt.DeviceID)
+ mvp.UpdateProfile(ctx, mt.DeviceID)
return nil
}
diff --git a/internal/pkg/application/major_upgrade.go b/internal/pkg/application/major_upgrade.go
index 639822b..b423b58 100644
--- a/internal/pkg/application/major_upgrade.go
+++ b/internal/pkg/application/major_upgrade.go
@@ -48,7 +48,7 @@
ModuleVer map[string]string // eg. "service": "v1"
}
-type paramsMigrationFunc func([]byte) string
+type paramsMigrationFunc func(context.Context, []byte) string
//map to store conversion functions
var migrationMap = map[string]paramsMigrationFunc{
@@ -79,32 +79,32 @@
}
// WriteToDb write a meter profile to DB
-func (md *DataMigration) WriteToDb() error {
+func (md *DataMigration) WriteToDb(cntx context.Context) error {
b, err := json.Marshal(md)
if err != nil {
return err
}
- if err1 := db.PutMigrationInfo(string(b)); err1 != nil {
+ if err1 := db.PutMigrationInfo(cntx, string(b)); err1 != nil {
return err1
}
return nil
}
// DelFromDb delete a meter profile from DB
-func (md *DataMigration) DelFromDb() {
- if err := db.DelMigrationInfo(); err != nil {
+func (md *DataMigration) DelFromDb(cntx context.Context) {
+ if err := db.DelMigrationInfo(cntx); err != nil {
logger.Warnw(ctx, "DelMigrationInfo Failed", log.Fields{"Error": err})
}
}
// GetMigrationInfo to get data migration info
-func GetMigrationInfo(dmInfo *DataMigration) error {
+func GetMigrationInfo(cntx context.Context, dmInfo *DataMigration) error {
var migrationInfo string
var err error
if db == nil {
db = database.GetDatabase()
}
- if migrationInfo, err = db.GetMigrationInfo(); err != nil {
+ if migrationInfo, err = db.GetMigrationInfo(cntx); err != nil {
return err
}
err = json.Unmarshal([]byte(migrationInfo), &dmInfo)
@@ -122,7 +122,7 @@
func CheckIfMigrationRequired(ctx context.Context) bool {
Migrate := new(DataMigration)
var NoDataInDB bool
- err := GetMigrationInfo(Migrate)
+ err := GetMigrationInfo(ctx, Migrate)
logger.Debugw(ctx, "Migration data", log.Fields{"DataMigration": Migrate})
// No DB entry represents N verison Bring Up for the First time
if err != nil {
@@ -135,7 +135,7 @@
Migrate.Version = database.PresentVersion
Migrate.Status = MigrationComplete
Migrate.ModuleVer = database.PresentVersionMap
- if err := Migrate.WriteToDb(); err != nil {
+ if err := Migrate.WriteToDb(ctx); err != nil {
logger.Errorw(ctx, "DB Write failed for Migration Path", log.Fields{"error": err})
}
//MigrateProbestatus has to be Updated to Complete when No Migration is Required
@@ -191,11 +191,11 @@
go func() {
logger.Debug(ctx, "Started Go Routine for data migration")
- err = MigrateDBData()
+ err = MigrateDBData(ctx)
if err != nil {
logger.Errorw(ctx, "Failed to Migrate the Data", log.Fields{"error": err})
Migrate.Status = MigrationFailed
- if err := Migrate.WriteToDb(); err != nil {
+ if err := Migrate.WriteToDb(ctx); err != nil {
logger.Errorw(ctx, "DB Write failed to Migration Path", log.Fields{"error": err})
}
}
@@ -205,7 +205,7 @@
Migrate.Version = database.PresentVersion
Migrate.Status = MigrationInProgress
Migrate.ModuleVer = database.PresentVersionMap
- if err = Migrate.WriteToDb(); err != nil {
+ if err = Migrate.WriteToDb(ctx); err != nil {
logger.Errorw(ctx, "DB Write failed for Migration Path", log.Fields{"error": err})
return
}
@@ -215,7 +215,7 @@
if err := recover(); err != nil {
logger.Errorw(ctx, "Migration failure due to Exception happend", log.Fields{"reason": err})
Migrate.Status = MigrationFailed
- if err := Migrate.WriteToDb(); err != nil {
+ if err := Migrate.WriteToDb(ctx); err != nil {
logger.Errorw(ctx, "DB Write failed for Migration Path", log.Fields{"error": err})
}
//probe.UpdateDBMigrationStatus(ctx, false)
@@ -226,14 +226,14 @@
migrationWG.Wait()
//probe.UpdateDBMigrationStatus(ctx, true)
Migrate.Status = MigrationComplete
- if err := Migrate.WriteToDb(); err != nil {
+ if err := Migrate.WriteToDb(ctx); err != nil {
logger.Errorw(ctx, "DB Write failed for Migration Path", log.Fields{"error": err})
}
logger.Infow(ctx, "Migration completed successfully", log.Fields{"Status": Migrate.Status})
}
// MigrateDBData to migrate database data
-func MigrateDBData() error {
+func MigrateDBData(cntx context.Context) error {
var err error
for module, currentVersion := range database.PresentVersionMap {
@@ -251,7 +251,7 @@
database.DeviceFlowHashPath:
err = FetchAndMigrateDeviceDBData(module)
default:
- err = FetchAndMigrateDBData(module)
+ err = FetchAndMigrateDBData(cntx, module)
}
} else {
logger.Infow(ctx, "No Data Migration handling found for module", log.Fields{"Table": module, "Version": currentVersion})
@@ -272,10 +272,10 @@
}
//FetchAndMigrateDBData fetchs the data from database and migrte the same to latest versions and store ot back ot database
-func FetchAndMigrateDBData(module string) error {
+func FetchAndMigrateDBData(cntx context.Context, module string) error {
previousPath := database.GetModuleKeypath(module, database.PreviousVersionMap[module])
- dbPathKeysValueMap, err := db.List(previousPath)
+ dbPathKeysValueMap, err := db.List(cntx, previousPath)
if err != nil {
logger.Errorw(ctx, "failed to Fetch the Keys from Redis", log.Fields{"error": err})
//No return required, Data might not be present in DB
@@ -296,7 +296,7 @@
return errors.New("Error-in-migration")
}
- presentParams := migrationMap[module](b)
+ presentParams := migrationMap[module](cntx, b)
logger.Infow(ctx, "Migrated data", log.Fields{"presentParams": presentParams})
if "" == presentParams {
logger.Error(ctx, "Error in migrating data\n")
@@ -306,7 +306,7 @@
}
presentPath := database.GetKeyPath(module) + hash
logger.Infow(ctx, "Before writing to DB", log.Fields{"presentParams": presentParams})
- if err := db.Put(presentPath, presentParams); err != nil {
+ if err := db.Put(cntx, presentPath, presentParams); err != nil {
logger.Errorw(ctx, "Update Params failed", log.Fields{"key": presentPath, "presentparams": presentParams})
return err
}
@@ -315,7 +315,7 @@
}
//MigrateServices modifyies the old data as per current version requirement and updates the database
-func MigrateServices(data []byte) string {
+func MigrateServices(cntx context.Context, data []byte) string {
var vs VoltService
var updatedData, updatedData1 []byte
var vsmap map[string]interface{}
@@ -356,43 +356,43 @@
}
//MigrateDevices modifyies the old data as per current version requirement and updates the database
-func MigrateDevices(data []byte) string {
+func MigrateDevices(cntx context.Context, data []byte) string {
logger.Error(ctx, "Data Migration not implemented for Devices")
return ""
}
//MigrateDevicePorts modifyies the old data as per current version requirement and updates the database
-func MigrateDevicePorts(data []byte) string {
+func MigrateDevicePorts(cntx context.Context, data []byte) string {
logger.Error(ctx, "Data Migration not implemented for Ports")
return ""
}
//MigrateDeviceFlows modifyies the old data as per current version requirement and updates the database
-func MigrateDeviceFlows(data []byte) string {
+func MigrateDeviceFlows(cntx context.Context, data []byte) string {
logger.Error(ctx, "Data Migration not implemented for Flows")
return ""
}
//MigrateDeviceGroups modifyies the old data as per current version requirement and updates the database
-func MigrateDeviceGroups(data []byte) string {
+func MigrateDeviceGroups(cntx context.Context, data []byte) string {
logger.Error(ctx, "Data Migration not implemented for Groups")
return ""
}
//MigrateDeviceMeters modifyies the old data as per current version requirement and updates the database
-func MigrateDeviceMeters(data []byte) string {
+func MigrateDeviceMeters(cntx context.Context, data []byte) string {
logger.Error(ctx, "Data Migration not implemented for Meters")
return ""
}
//MigrateDeviceFlowHash modifyies the old data as per current version requirement and updates the database
-func MigrateDeviceFlowHash(data []byte) string {
+func MigrateDeviceFlowHash(cntx context.Context, data []byte) string {
logger.Error(ctx, "Data Migration not implemented for FlowHash")
return ""
}
//MigrateVnets modifyies the old data as per current version requirement and updates the database
-func MigrateVnets(data []byte) string {
+func MigrateVnets(cntx context.Context, data []byte) string {
var vnet VoltVnet
var updatedData []byte
@@ -423,7 +423,7 @@
}
//MigrateVpvs modifyies the old data as per current version requirement and updates the database
-func MigrateVpvs(data []byte) string {
+func MigrateVpvs(cntx context.Context, data []byte) string {
var vpv VoltPortVnet
var updatedData, updatedData1 []byte
var vpvmap map[string]interface{}
@@ -479,7 +479,7 @@
}
//MigrateMvlans modifyies the old data as per current version requirement and updates the database
-func MigrateMvlans(data []byte) string {
+func MigrateMvlans(cntx context.Context, data []byte) string {
var mvp MvlanProfile
var updatedData []byte
@@ -504,13 +504,13 @@
}
//MigrateMeters modifyies the old data as per current version requirement and updates the database
-func MigrateMeters(data []byte) string {
+func MigrateMeters(cntx context.Context, data []byte) string {
logger.Error(ctx, "Data Migration not implemented for Meters")
return ""
}
//MigrateIgmpConfs modifyies the old data as per current version requirement and updates the database
-func MigrateIgmpConfs(data []byte) string {
+func MigrateIgmpConfs(cntx context.Context, data []byte) string {
var igmpProfile IgmpProfile
err := json.Unmarshal(data, &igmpProfile)
@@ -518,7 +518,7 @@
logger.Warn(ctx, "Unmarshal of IGMP failed")
return ""
}
- if err := igmpProfile.WriteToDb(); err != nil {
+ if err := igmpProfile.WriteToDb(cntx); err != nil {
logger.Errorw(ctx, "Igmp profile Write to DB failed", log.Fields{"profileID": igmpProfile.ProfileID})
}
@@ -527,73 +527,73 @@
}
//MigrateIgmpGroups modifyies the old data as per current version requirement and updates the database
-func MigrateIgmpGroups(data []byte) string {
+func MigrateIgmpGroups(cntx context.Context, data []byte) string {
logger.Error(ctx, "Data Migration not implemented for IGMP Groups")
return ""
}
//MigrateIgmpDevices modifyies the old data as per current version requirement and updates the database
-func MigrateIgmpDevices(data []byte) string {
+func MigrateIgmpDevices(cntx context.Context, data []byte) string {
logger.Error(ctx, "Data Migration not implemented for IGMP Device")
return ""
}
//MigrateIgmpChannels modifyies the old data as per current version requirement and updates the database
-func MigrateIgmpChannels(data []byte) string {
+func MigrateIgmpChannels(cntx context.Context, data []byte) string {
logger.Error(ctx, "Data Migration not implemented for IGMP Channels")
return ""
}
//MigrateIgmpPorts modifyies the old data as per current version requirement and updates the database
-func MigrateIgmpPorts(data []byte) string {
+func MigrateIgmpPorts(cntx context.Context, data []byte) string {
logger.Error(ctx, "Data Migration not implemented for IGMP Ports")
return ""
}
//MigrateIgmpProfs modifyies the old data as per current version requirement and updates the database
-func MigrateIgmpProfs(data []byte) string {
+func MigrateIgmpProfs(cntx context.Context, data []byte) string {
logger.Error(ctx, "Data Migration not implemented for IGMP Profs")
return ""
}
//MigrateMcastConfs modifyies the old data as per current version requirement and updates the database
-func MigrateMcastConfs(data []byte) string {
+func MigrateMcastConfs(cntx context.Context, data []byte) string {
logger.Error(ctx, "Data Migration not implemented for Mcast Confs")
return ""
}
//MigrateLogLevels modifyies the old data as per current version requirement and updates the database
-func MigrateLogLevels(data []byte) string {
+func MigrateLogLevels(cntx context.Context, data []byte) string {
logger.Error(ctx, "Data Migration not implemented for Log Levels")
return ""
}
//MigrateHealth modifyies the old data as per current version requirement and updates the database
-func MigrateHealth(data []byte) string {
+func MigrateHealth(cntx context.Context, data []byte) string {
logger.Error(ctx, "Data Migration not implemented for Health")
return ""
}
//MigratePonCounters modifyies the old data as per current version requirement and updates the database
-func MigratePonCounters(data []byte) string {
+func MigratePonCounters(cntx context.Context, data []byte) string {
logger.Error(ctx, "Data Migration not implemented for Pon Counters")
return ""
}
//MigrateChannelCounters modifyies the old data as per current version requirement and updates the database
-func MigrateChannelCounters(data []byte) string {
+func MigrateChannelCounters(cntx context.Context, data []byte) string {
logger.Error(ctx, "Data Migration not implemented for Channel Counters")
return ""
}
//MigrateServiceCounters modifyies the old data as per current version requirement and updates the database
-func MigrateServiceCounters(data []byte) string {
+func MigrateServiceCounters(cntx context.Context, data []byte) string {
logger.Error(ctx, "Data Migration not implemented for Service Counters")
return ""
}
//MigrateNbDevices modifyies the old data as per current version requirement and updates the database
-func MigrateNbDevices(data []byte) string {
+func MigrateNbDevices(cntx context.Context, data []byte) string {
logger.Error(ctx, "Data Migration not implemented for NB Devices")
return ""
}
@@ -605,11 +605,11 @@
}
//DeleteDbPathKeys Deleted the paths from DB
-func DeleteDbPathKeys(keyPath string) error {
+func DeleteDbPathKeys(cntx context.Context, keyPath string) error {
logger.Debugw(ctx, "Deleting paths for version", log.Fields{"Path": keyPath})
// Delete all the keys
- err := db.DeleteAll(keyPath)
+ err := db.DeleteAll(cntx, keyPath)
if err != nil && err.Error() != common.ErrEntryNotFound.Error() {
logger.Errorw(ctx, "Delete Key failed", log.Fields{"error": err})
return err
diff --git a/internal/pkg/application/meters.go b/internal/pkg/application/meters.go
index cd3e724..276fe99 100644
--- a/internal/pkg/application/meters.go
+++ b/internal/pkg/application/meters.go
@@ -18,6 +18,7 @@
import (
"encoding/json"
"errors"
+ "context"
"sync"
cntlr "voltha-go-controller/internal/pkg/controller"
@@ -87,21 +88,21 @@
}
// WriteToDb to write a meter profile to DB
-func (vm *VoltMeter) WriteToDb() error {
+func (vm *VoltMeter) WriteToDb(cntx context.Context) error {
vm.Version = database.PresentVersionMap[database.MeterPath]
b, err := json.Marshal(vm)
if err != nil {
return err
}
- if err1 := db.PutMeter(vm.Name, string(b)); err1 != nil {
+ if err1 := db.PutMeter(cntx, vm.Name, string(b)); err1 != nil {
return err1
}
return nil
}
// DelFromDb to delete a meter profile from DB
-func (vm *VoltMeter) DelFromDb() {
- _ = db.DelMeter(vm.Name)
+func (vm *VoltMeter) DelFromDb(cntx context.Context) {
+ _ = db.DelMeter(cntx, vm.Name)
}
// GetMeterByName to get meter by name
@@ -215,10 +216,10 @@
}
// RestoreMetersFromDb to read from the DB and restore all the services
-func (m *MeterMgr) RestoreMetersFromDb() {
+func (m *MeterMgr) RestoreMetersFromDb(cntx context.Context) {
// VNETS must be learnt first
logger.Infow(ctx, "LastMeterID on restart", log.Fields{"LastMeterID": m.LastMeterID})
- ms, _ := db.GetMeters()
+ ms, _ := db.GetMeters(cntx)
for _, mt := range ms {
b, ok := mt.Value.([]byte)
if !ok {
@@ -241,7 +242,7 @@
}
// AddMeterProf to add the meter profile name as key
-func (va *VoltApplication) AddMeterProf(cfg VoltMeter) {
+func (va *VoltApplication) AddMeterProf(cntx context.Context, cfg VoltMeter) {
mm := &va.MeterMgr
if _, ok := mm.GetMeterByName(cfg.Name); ok {
@@ -256,20 +257,20 @@
id := mm.LastMeterID
cfg.ID = id
mm.AddMeter(&cfg)
- if err := cfg.WriteToDb(); err != nil {
+ if err := cfg.WriteToDb(cntx); err != nil {
logger.Warnw(ctx, "MeterProf Write to DB Failed", log.Fields{"MeterConfig": cfg, "Error": err})
}
}
// UpdateMeterProf to update the meter profile
-func (va *VoltApplication) UpdateMeterProf(cfg VoltMeter) {
+func (va *VoltApplication) UpdateMeterProf(cntx context.Context, cfg VoltMeter) {
mm := &va.MeterMgr
if _, ok := mm.GetMeterByName(cfg.Name); !ok {
logger.Warnw(ctx, "Meter profile does not exist", log.Fields{"Name": cfg.Name})
return
}
mm.AddMeter(&cfg)
- if err := cfg.WriteToDb(); err != nil {
+ if err := cfg.WriteToDb(cntx); err != nil {
logger.Warnw(ctx, "MeterProf Write to DB Failed", log.Fields{"MeterConfig": cfg, "Error": err})
}
}
@@ -304,7 +305,7 @@
}
// DelMeterProf to delete meter profile
-func (va *VoltApplication) DelMeterProf(name string) error {
+func (va *VoltApplication) DelMeterProf(cntx context.Context, name string) error {
mm := &va.MeterMgr
if _, ok := mm.GetMeterByName(name); !ok {
logger.Warnw(ctx, "Meter profile does not exist", log.Fields{"Name": name})
@@ -324,7 +325,7 @@
return true
}
va.DevicesDisc.Range(delmeterFromDevice)
- cfg.DelFromDb()
+ cfg.DelFromDb(cntx)
//Delete meter from device will be invoked by caller separately
mm.DelMeter(cfg)
return nil
diff --git a/internal/pkg/application/minor_upgrade.go b/internal/pkg/application/minor_upgrade.go
index d8e7094..a0bba15 100644
--- a/internal/pkg/application/minor_upgrade.go
+++ b/internal/pkg/application/minor_upgrade.go
@@ -17,6 +17,7 @@
import (
"errors"
+ "context"
"net"
"voltha-go-controller/internal/pkg/types"
@@ -27,7 +28,7 @@
"voltha-go-controller/log"
)
-type paramsUpdationFunc func(hash string, value interface{}) error
+type paramsUpdationFunc func(cntx context.Context, hash string, value interface{}) error
//map to store conversion functions
var updationMap = map[string]paramsUpdationFunc{
@@ -41,9 +42,9 @@
}
// UpdateDbData to update database data
-func UpdateDbData(dbPath, hash string, value interface{}) error {
+func UpdateDbData(cntx context.Context, dbPath, hash string, value interface{}) error {
if migrationFunc, ok := updationMap[dbPath]; ok {
- err := migrationFunc(hash, value)
+ err := migrationFunc(cntx, hash, value)
if err != nil {
logger.Error(ctx, "Error in migrating data\n")
return errors.New("Error-in-migration")
@@ -54,7 +55,7 @@
//This function modifyies the old data as per current version requirement and also
//returns the new path on which the modified data has to be written
-func updateServices(hash string, value interface{}) error {
+func updateServices(cntx context.Context, hash string, value interface{}) error {
param := value.(*VoltService)
param.VnetID = VnetKey(param.SVlan, param.CVlan, param.UniVlan)
return nil
@@ -62,12 +63,12 @@
//This function modifyies the old data as per current version requirement and also
//returns the new path on which the modified data has to be written
-func updateVnets(hash string, value interface{}) error {
+func updateVnets(cntx context.Context, hash string, value interface{}) error {
param := value.(*VoltVnet)
newKey := VnetKey(param.SVlan, param.CVlan, param.UniVlan)
if newKey != hash {
//Delete the older key
- _ = db.DelVnet(hash)
+ _ = db.DelVnet(cntx, hash)
} else {
//Update SVlan Tag Protocol id param with default valud if not present
if param.SVlanTpid == 0 {
@@ -83,7 +84,7 @@
//This function modifyies the old data as per current version requirement and also
//returns the new path on which the modified data has to be written
-func updateVpvs(hash string, value interface{}) error {
+func updateVpvs(cntx context.Context, hash string, value interface{}) error {
//var param VoltPortVnet
param := value.(*VoltPortVnet)
@@ -99,20 +100,20 @@
}
//Add the vpv under new path
- param.WriteToDb()
+ param.WriteToDb(cntx)
//delete the older path
fullPath := database.BasePath + database.VpvPath + hash
- if err := db.Del(fullPath); err != nil {
+ if err := db.Del(cntx, fullPath); err != nil {
logger.Errorw(ctx, "Vpv Delete from DB failed", log.Fields{"Error": err, "key": fullPath})
}
return nil
}
-func updateMvlans(hash string, value interface{}) error {
+func updateMvlans(cntx context.Context, hash string, value interface{}) error {
param := value.(*MvlanProfile)
if param.DevicesList == nil || len(param.DevicesList) == 0 {
param.DevicesList = make(map[string]OperInProgress) //Empty OLT serial number as of now since submgr won't have proper serial num
- if err := param.WriteToDb(); err != nil {
+ if err := param.WriteToDb(cntx); err != nil {
logger.Errorw(ctx, "Mvlan profile write to DB failed", log.Fields{"ProfileName": param.Name})
}
@@ -125,14 +126,14 @@
//This function modifyies the old Igmp Group data as per current version requirement and also
//returns the new path on which the modified data has to be written
-func updateIgmpGroups(hash string, value interface{}) error {
+func updateIgmpGroups(cntx context.Context, hash string, value interface{}) error {
ig := value.(*IgmpGroup)
logger.Infow(ctx, "Group Data Migration", log.Fields{"ig": ig, "GroupAddr": ig.GroupAddr, "hash": hash})
if ig.GroupAddr == nil {
ig.GroupAddr = net.ParseIP("0.0.0.0")
}
- if err := ig.WriteToDb(); err != nil {
+ if err := ig.WriteToDb(cntx); err != nil {
logger.Errorw(ctx, "Igmp group Write to DB failed", log.Fields{"groupName": ig.GroupName})
}
@@ -141,13 +142,13 @@
//This function modifyies the old Igmp Device data as per current version requirement and also
//returns the new path on which the modified data has to be written
-func updateIgmpDevices(hash string, value interface{}) error {
+func updateIgmpDevices(cntx context.Context, hash string, value interface{}) error {
igd := value.(*IgmpGroupDevice)
logger.Infow(ctx, "Group Device Migration", log.Fields{"igd": igd, "GroupAddr": igd.GroupAddr, "hash": hash})
if igd.GroupAddr == nil {
igd.GroupAddr = net.ParseIP("0.0.0.0")
}
- if err := igd.WriteToDb(); err != nil {
+ if err := igd.WriteToDb(cntx); err != nil {
logger.Errorw(ctx, "Igmp group device Write to DB failed", log.Fields{"Device": igd.Device,
"GroupName": igd.GroupName, "GroupAddr": igd.GroupAddr.String()})
}
@@ -157,15 +158,15 @@
//This function modifyies the old Igmp Profile data as per current version requirement and also
//returns the new path on which the modified data has to be written
-func updateIgmpProfiles(hash string, value interface{}) error {
+func updateIgmpProfiles(cntx context.Context, hash string, value interface{}) error {
igmpProfile := value.(*IgmpProfile)
logger.Infow(ctx, "IGMP Profile Migration", log.Fields{"igmpProfile": igmpProfile, "hash": hash})
return nil
}
-func (ig *IgmpGroup) migrateIgmpDevices() {
+func (ig *IgmpGroup) migrateIgmpDevices(cntx context.Context) {
- devices, _ := db.GetPrevIgmpDevices(ig.Mvlan, ig.GroupName)
+ devices, _ := db.GetPrevIgmpDevices(cntx, ig.Mvlan, ig.GroupName)
logger.Infow(ctx, "Migratable Devices", log.Fields{"Devices": devices})
for _, device := range devices {
b, ok := device.Value.([]byte)
@@ -176,10 +177,10 @@
if igd, err := NewIgmpGroupDeviceFromBytes(b); err == nil {
key := database.BasePath + database.IgmpDevicePath + igd.Mvlan.String() + "/" + igd.GroupName + "/" + igd.Device
logger.Infow(ctx, "Deleting old entry", log.Fields{"Path": key, "igd": igd})
- if err := db.Del(key); err != nil {
+ if err := db.Del(cntx, key); err != nil {
logger.Errorw(ctx, "Igmp Group Delete from DB failed", log.Fields{"Error": err, "key": key})
}
- if err := UpdateDbData(database.IgmpDevicePath, key, igd); err != nil {
+ if err := UpdateDbData(cntx, database.IgmpDevicePath, key, igd); err != nil {
logger.Warnw(ctx, "Group Device Migration failed", log.Fields{"IGD": igd, "Error": err})
} else {
logger.Infow(ctx, "Group Device Migrated", log.Fields{"IGD": igd})
@@ -190,9 +191,9 @@
}
}
-func (igd *IgmpGroupDevice) migrateIgmpChannels() {
+func (igd *IgmpGroupDevice) migrateIgmpChannels(cntx context.Context) {
- channels, _ := db.GetPrevIgmpChannels(igd.GroupName, igd.Device)
+ channels, _ := db.GetPrevIgmpChannels(cntx, igd.GroupName, igd.Device)
logger.Infow(ctx, "Migratable Channels", log.Fields{"Channels": channels})
for _, channel := range channels {
@@ -204,10 +205,10 @@
if igc, err := NewIgmpGroupChannelFromBytes(b); err == nil {
key := database.BasePath + database.IgmpChannelPath + igc.GroupName + "/" + igc.Device + "/" + igc.GroupAddr.String()
logger.Infow(ctx, "Deleting old entry", log.Fields{"Path": key, "igc": igc})
- if err := db.Del(key); err != nil {
+ if err := db.Del(cntx, key); err != nil {
logger.Errorw(ctx, "Igmp Group Delete from DB failed", log.Fields{"Error": err, "key": key})
}
- if err := igc.WriteToDb(); err != nil {
+ if err := igc.WriteToDb(cntx); err != nil {
logger.Errorw(ctx, "Igmp group channel Write to DB failed", log.Fields{"mvlan": igc.Mvlan, "GroupAddr": igc.GroupAddr})
}
@@ -218,9 +219,9 @@
}
}
-func (igc *IgmpGroupChannel) migrateIgmpPorts() {
+func (igc *IgmpGroupChannel) migrateIgmpPorts(cntx context.Context) {
- ports, _ := db.GetPrevIgmpRcvrs(igc.GroupAddr, igc.Device)
+ ports, _ := db.GetPrevIgmpRcvrs(cntx, igc.GroupAddr, igc.Device)
logger.Infow(ctx, "Migratable Ports", log.Fields{"Ports": ports})
for _, port := range ports {
@@ -232,10 +233,10 @@
if igp, err := NewIgmpGroupPortFromBytes(b); err == nil {
key := database.BasePath + database.IgmpPortPath + igc.GroupAddr.String() + "/" + igc.Device + "/" + igp.Port
logger.Infow(ctx, "Deleting old entry", log.Fields{"Key": key, "Igp": igp})
- if err := db.Del(key); err != nil {
+ if err := db.Del(cntx, key); err != nil {
logger.Errorw(ctx, "Igmp Group port Delete from DB failed", log.Fields{"Error": err, "key": key})
}
- if err := igp.WriteToDb(igc.Mvlan, igc.GroupAddr, igc.Device); err != nil {
+ if err := igp.WriteToDb(cntx, igc.Mvlan, igc.GroupAddr, igc.Device); err != nil {
logger.Errorw(ctx, "Igmp group port Write to DB failed", log.Fields{"mvlan": igc.Mvlan, "GroupAddr": igc.GroupAddr})
}
diff --git a/internal/pkg/application/pppoeia.go b/internal/pkg/application/pppoeia.go
index 7c55b79..2d50033 100644
--- a/internal/pkg/application/pppoeia.go
+++ b/internal/pkg/application/pppoeia.go
@@ -77,7 +77,7 @@
GetNniVlans() (uint16, uint16)
GetPppoeIaState() PppoeIaState
SetPppoeIaState(PppoeIaState)
- SetMacAddr(net.HardwareAddr)
+ SetMacAddr(context.Context, net.HardwareAddr)
}
// PppoeIaRelayVnet : The PppoeIa relay sessions are stored in a map to be retrieved from when
@@ -280,7 +280,7 @@
// session is derived from the list of PppoeIa sessions stored in the
// common map. The key for retrieval includes the VLAN tags in the
// the packet and the MAC address of the client.
-func (va *VoltApplication) ProcessDsPppoeIaPacket(device string, port string, pkt gopacket.Packet) {
+func (va *VoltApplication) ProcessDsPppoeIaPacket(cntx context.Context, device string, port string, pkt gopacket.Packet) {
// Retrieve the layers to build the outgoing packet. It is not
// possible to add/remove layers to the existing packet and thus
@@ -319,7 +319,7 @@
} else if pppoe.Code == layers.PPPoECodePADT {
vpv.SetPppoeIaState(PppoeIaStatePADT)
}
- vpv.WriteToDb()
+ vpv.WriteToDb(cntx)
}
// Create the outgoing bufer and set the checksum in the packet
buff := gopacket.NewSerializeBuffer()
@@ -394,7 +394,7 @@
// ProcessUsPppoeIaPacket : The US PppoeIa packet is identified the PppoeIa OP in the packet. A request is considered upstream
// and the service associated with the packet is located by the port and VLANs in the packet
-func (va *VoltApplication) ProcessUsPppoeIaPacket(device string, port string, pkt gopacket.Packet) {
+func (va *VoltApplication) ProcessUsPppoeIaPacket(cntx context.Context, device string, port string, pkt gopacket.Packet) {
// We received the packet on an access port and the service for the packet can be
// gotten from the port and the packet
vpv, svc := va.GetVnetFromPkt(device, port, pkt)
@@ -443,7 +443,7 @@
return
}
}
- vpv.SetMacAddr(eth.SrcMAC)
+ vpv.SetMacAddr(cntx, eth.SrcMAC)
}
if pppoe.Code == layers.PPPoECodePADI {
@@ -451,7 +451,7 @@
} else if pppoe.Code == layers.PPPoECodePADR {
vpv.SetPppoeIaState(PppoeIaStatePADR)
}
- vpv.WriteToDb()
+ vpv.WriteToDb(cntx)
}
buff := gopacket.NewSerializeBuffer()
@@ -521,7 +521,7 @@
}
// ProcessPPPoEIaPacket to process Pppoeia packet
-func (va *VoltApplication) ProcessPPPoEIaPacket(device string, port string, pkt gopacket.Packet) {
+func (va *VoltApplication) ProcessPPPoEIaPacket(cntx context.Context, device string, port string, pkt gopacket.Packet) {
// Make some error checks before proceeding
pppoel := pkt.Layer(layers.LayerTypePPPoE)
if pppoel == nil {
@@ -544,10 +544,10 @@
// This is treated as an upstream packet in the VOLT application
// as VOLT serves access subscribers who use DHCP to acquire IP
// address and these packets go upstream to the network
- va.ProcessUsPppoeIaPacket(device, port, pkt)
+ va.ProcessUsPppoeIaPacket(cntx, device, port, pkt)
} else {
// This is a downstream packet
- va.ProcessDsPppoeIaPacket(device, port, pkt)
+ va.ProcessDsPppoeIaPacket(cntx, device, port, pkt)
}
}
@@ -566,7 +566,7 @@
}
// ProcessPPPoEPacket : CallBack function registered with application to handle PPPoE packetIn
-func ProcessPPPoEPacket(device string, port string, pkt gopacket.Packet) {
+func ProcessPPPoEPacket(cntx context.Context, device string, port string, pkt gopacket.Packet) {
GetApplication().ProcessPPPoEPacket(device, port, pkt)
}
@@ -613,6 +613,6 @@
func (dpt *PppoeIaPacketTask) Start(ctx context.Context, taskID uint8) error {
dpt.taskID = taskID
dpt.ctx = ctx
- GetApplication().ProcessPPPoEIaPacket(dpt.device, dpt.port, dpt.pkt)
+ GetApplication().ProcessPPPoEIaPacket(ctx, dpt.device, dpt.port, dpt.pkt)
return nil
}
diff --git a/internal/pkg/application/service.go b/internal/pkg/application/service.go
index b9ff4b2..690f348 100644
--- a/internal/pkg/application/service.go
+++ b/internal/pkg/application/service.go
@@ -19,6 +19,7 @@
"bytes"
"encoding/json"
"errors"
+ "context"
"net"
"reflect"
infraerrorCodes "voltha-go-controller/internal/pkg/errorcodes"
@@ -179,7 +180,7 @@
}
// WriteToDb commit a service to the DB if service delete is not in-progress
-func (vs *VoltService) WriteToDb() {
+func (vs *VoltService) WriteToDb(cntx context.Context) {
vs.ServiceLock.RLock()
defer vs.ServiceLock.RUnlock()
@@ -188,18 +189,18 @@
logger.Warnw(ctx, "Skipping Redis Update for Service, Service delete in progress", log.Fields{"Service": vs.Name})
return
}
- vs.ForceWriteToDb()
+ vs.ForceWriteToDb(cntx)
}
//ForceWriteToDb force commit a service to the DB
-func (vs *VoltService) ForceWriteToDb() {
+func (vs *VoltService) ForceWriteToDb(cntx context.Context) {
b, err := json.Marshal(vs)
if err != nil {
logger.Errorw(ctx, "Json Marshal Failed for Service", log.Fields{"Service": vs.Name})
return
}
- if err1 := db.PutService(vs.Name, string(b)); err1 != nil {
+ if err1 := db.PutService(cntx, vs.Name, string(b)); err1 != nil {
logger.Errorw(ctx, "DB write oper failed for Service", log.Fields{"Service": vs.Name})
}
}
@@ -210,12 +211,12 @@
}
// DelFromDb delete a service from DB
-func (vs *VoltService) DelFromDb() {
+func (vs *VoltService) DelFromDb(cntx context.Context) {
logger.Debugw(ctx, "Deleting Service from DB", log.Fields{"Name": vs.Name})
//TODO - Need to understand and delete the second call
//Calling twice has worked though don't know why
- _ = db.DelService(vs.Name)
- _ = db.DelService(vs.Name)
+ _ = db.DelService(cntx, vs.Name)
+ _ = db.DelService(cntx, vs.Name)
}
// MatchesVlans find the service that matches the VLANs. In this case it is
@@ -258,32 +259,32 @@
}
// AddHsiaFlows - Adds US & DS HSIA Flows for the service
-func (vs *VoltService) AddHsiaFlows() {
- if err := vs.AddUsHsiaFlows(); err != nil {
+func (vs *VoltService) AddHsiaFlows(cntx context.Context) {
+ if err := vs.AddUsHsiaFlows(cntx); err != nil {
statusCode, statusMessage := infraerrorCodes.GetErrorInfo(err)
vs.triggerServiceFailureInd(statusCode, statusMessage)
}
- if err := vs.AddDsHsiaFlows(); err != nil {
+ if err := vs.AddDsHsiaFlows(cntx); err != nil {
statusCode, statusMessage := infraerrorCodes.GetErrorInfo(err)
vs.triggerServiceFailureInd(statusCode, statusMessage)
}
}
//DelHsiaFlows - Deletes US & DS HSIA Flows for the service
-func (vs *VoltService) DelHsiaFlows() {
- if err := vs.DelUsHsiaFlows(); err != nil {
+func (vs *VoltService) DelHsiaFlows(cntx context.Context) {
+ if err := vs.DelUsHsiaFlows(cntx); err != nil {
statusCode, statusMessage := infraerrorCodes.GetErrorInfo(err)
vs.triggerServiceFailureInd(statusCode, statusMessage)
}
- if err := vs.DelDsHsiaFlows(); err != nil {
+ if err := vs.DelDsHsiaFlows(cntx); err != nil {
statusCode, statusMessage := infraerrorCodes.GetErrorInfo(err)
vs.triggerServiceFailureInd(statusCode, statusMessage)
}
}
// AddUsHsiaFlows - Add US HSIA Flows for the service
-func (vs *VoltService) AddUsHsiaFlows() error {
+func (vs *VoltService) AddUsHsiaFlows(cntx context.Context) error {
if vs.DeleteInProgress || vs.UpdateInProgress {
logger.Errorw(ctx, "Ignoring US HSIA Flow Push, Service deleteion In-Progress", log.Fields{"Device": vs.Device, "Service": vs.Name})
@@ -322,7 +323,7 @@
continue
}
usflows.MigrateCookie = vgcRebooted
- if err := vs.AddFlows(device, usflows); err != nil {
+ if err := vs.AddFlows(cntx, device, usflows); err != nil {
logger.Errorw(ctx, "Error adding HSIA US flows", log.Fields{"Reason": err.Error()})
statusCode, statusMessage := infraerrorCodes.GetErrorInfo(err)
vs.triggerServiceFailureInd(statusCode, statusMessage)
@@ -331,12 +332,12 @@
vs.UsHSIAFlowsApplied = true
logger.Infow(ctx, "Pushed US HSIA Service Flows", log.Fields{"ServiceName": vs.Name})
}
- vs.WriteToDb()
+ vs.WriteToDb(cntx)
return nil
}
// AddDsHsiaFlows - Add DS HSIA Flows for the service
-func (vs *VoltService) AddDsHsiaFlows() error {
+func (vs *VoltService) AddDsHsiaFlows(cntx context.Context) error {
if vs.DeleteInProgress {
logger.Errorw(ctx, "Ignoring DS HSIA Flow Push, Service deleteion In-Progress", log.Fields{"Device": vs.Device, "Service": vs.Name})
return nil
@@ -365,7 +366,7 @@
return err
}
dsflows.MigrateCookie = vgcRebooted
- if err = vs.AddFlows(device, dsflows); err != nil {
+ if err = vs.AddFlows(cntx, device, dsflows); err != nil {
logger.Errorw(ctx, "Failed to add HSIA DS flows", log.Fields{"Reason": err})
statusCode, statusMessage := infraerrorCodes.GetErrorInfo(err)
vs.triggerServiceFailureInd(statusCode, statusMessage)
@@ -380,7 +381,7 @@
}
logger.Debug(ctx, "Add-one-match-all-pbit-flow")
dsflows.MigrateCookie = vgcRebooted
- if err := vs.AddFlows(device, dsflows); err != nil {
+ if err := vs.AddFlows(cntx, device, dsflows); err != nil {
logger.Errorw(ctx, "Failed to add HSIA DS flows", log.Fields{"Reason": err})
statusCode, statusMessage := infraerrorCodes.GetErrorInfo(err)
vs.triggerServiceFailureInd(statusCode, statusMessage)
@@ -395,7 +396,7 @@
continue
}
dsflows.MigrateCookie = vgcRebooted
- if err := vs.AddFlows(device, dsflows); err != nil {
+ if err := vs.AddFlows(cntx, device, dsflows); err != nil {
logger.Errorw(ctx, "Failed to Add HSIA DS flows", log.Fields{"Reason": err})
statusCode, statusMessage := infraerrorCodes.GetErrorInfo(err)
vs.triggerServiceFailureInd(statusCode, statusMessage)
@@ -406,12 +407,12 @@
vs.DsHSIAFlowsApplied = true
logger.Infow(ctx, "Pushed DS HSIA Service Flows", log.Fields{"ServiceName": vs.Name})
}
- vs.WriteToDb()
+ vs.WriteToDb(cntx)
return nil
}
// DelUsHsiaFlows - Deletes US HSIA Flows for the service
-func (vs *VoltService) DelUsHsiaFlows() error {
+func (vs *VoltService) DelUsHsiaFlows(cntx context.Context) error {
logger.Infow(ctx, "Removing US HSIA Services", log.Fields{"Services": vs.Name})
if vs.UsHSIAFlowsApplied || vgcRebooted {
@@ -437,19 +438,19 @@
continue
}
usflows.MigrateCookie = vgcRebooted
- if err = vs.DelFlows(device, usflows); err != nil {
+ if err = vs.DelFlows(cntx, device, usflows); err != nil {
statusCode, statusMessage := infraerrorCodes.GetErrorInfo(err)
vs.triggerServiceFailureInd(statusCode, statusMessage)
}
}
vs.UsHSIAFlowsApplied = false
}
- vs.WriteToDb()
+ vs.WriteToDb(cntx)
return nil
}
// DelDsHsiaFlows - Deletes DS HSIA Flows for the service
-func (vs *VoltService) DelDsHsiaFlows() error {
+func (vs *VoltService) DelDsHsiaFlows(cntx context.Context) error {
logger.Infow(ctx, "Removing DS HSIA Services", log.Fields{"Services": vs.Name})
if vs.DsHSIAFlowsApplied || vgcRebooted {
@@ -469,7 +470,7 @@
return err
}
dsflows.MigrateCookie = vgcRebooted
- if err = vs.DelFlows(device, dsflows); err != nil {
+ if err = vs.DelFlows(cntx, device, dsflows); err != nil {
statusCode, statusMessage := infraerrorCodes.GetErrorInfo(err)
vs.triggerServiceFailureInd(statusCode, statusMessage)
}
@@ -480,7 +481,7 @@
return err
}
dsflows.MigrateCookie = vgcRebooted
- if err = vs.DelFlows(device, dsflows); err != nil {
+ if err = vs.DelFlows(cntx, device, dsflows); err != nil {
statusCode, statusMessage := infraerrorCodes.GetErrorInfo(err)
vs.triggerServiceFailureInd(statusCode, statusMessage)
}
@@ -494,7 +495,7 @@
continue
}
dsflows.MigrateCookie = vgcRebooted
- if err = vs.DelFlows(device, dsflows); err != nil {
+ if err = vs.DelFlows(cntx, device, dsflows); err != nil {
statusCode, statusMessage := infraerrorCodes.GetErrorInfo(err)
vs.triggerServiceFailureInd(statusCode, statusMessage)
}
@@ -504,7 +505,7 @@
}
logger.Infow(ctx, "Deleted HSIA DS flows from DB successfuly", log.Fields{"ServiceName": vs.Name})
// Post HSIA configuration success indication on message bus
- vs.WriteToDb()
+ vs.WriteToDb(cntx)
return nil
}
@@ -949,13 +950,13 @@
}
// SvcUpInd for service up indication
-func (vs *VoltService) SvcUpInd() {
- vs.AddHsiaFlows()
+func (vs *VoltService) SvcUpInd(cntx context.Context) {
+ vs.AddHsiaFlows(cntx)
}
// SvcDownInd for service down indication
-func (vs *VoltService) SvcDownInd() {
- vs.DelHsiaFlows()
+func (vs *VoltService) SvcDownInd(cntx context.Context) {
+ vs.DelHsiaFlows(cntx)
}
// SetIpv4Addr to set ipv4 address
@@ -987,7 +988,7 @@
// current implementation, a service is an entity that is identified by a
// unique L2 (MAC address + VLANs) or unique L3 (VLANs + IP address)
// FUNC: Add Service
-func (va *VoltApplication) AddService(cfg VoltServiceCfg, oper *VoltServiceOper) error {
+func (va *VoltApplication) AddService(cntx context.Context, cfg VoltServiceCfg, oper *VoltServiceOper) error {
var mmUs, mmDs *VoltMeter
var err error
@@ -1059,10 +1060,10 @@
if vnet != nil {
if vpv := va.GetVnetByPort(vs.Port, cfg.SVlan, cfg.CVlan, cfg.UniVlan); vpv != nil {
vpv.VpvLock.Lock()
- vpv.AddSvc(vs)
+ vpv.AddSvc(cntx, vs)
vpv.VpvLock.Unlock()
} else {
- va.AddVnetToPort(vs.Port, vnet, vs)
+ va.AddVnetToPort(cntx, vs.Port, vnet, vs)
}
} else {
logger.Errorw(ctx, "VNET-does-not-exist-for-service", log.Fields{"ServiceName": cfg.Name})
@@ -1072,7 +1073,7 @@
vs.Version = database.PresentVersionMap[database.ServicePath]
// Add the service to the volt application
va.ServiceByName.Store(vs.Name, vs)
- vs.WriteToDb()
+ vs.WriteToDb(cntx)
if nil == oper {
@@ -1082,10 +1083,10 @@
//Update meter profiles service count if service is being added from northbound
mmDs.AssociatedServices++
- va.UpdateMeterProf(*mmDs)
+ va.UpdateMeterProf(cntx, *mmDs)
if mmUs != nil {
mmUs.AssociatedServices++
- va.UpdateMeterProf(*mmUs)
+ va.UpdateMeterProf(cntx, *mmUs)
}
//mmAg.AssociatedServices++
//va.UpdateMeterProf(*mmAg)
@@ -1098,18 +1099,18 @@
//DelServiceWithPrefix - Deletes service with the provided prefix.
// Added for DT/TT usecase with sadis replica interface
-func (va *VoltApplication) DelServiceWithPrefix(prefix string) {
+func (va *VoltApplication) DelServiceWithPrefix(cntx context.Context, prefix string) {
va.ServiceByName.Range(func(key, value interface{}) bool {
srvName := key.(string)
vs := value.(*VoltService)
if strings.Contains(srvName, prefix) {
- va.DelService(srvName, true, nil, false)
+ va.DelService(cntx, srvName, true, nil, false)
vnetName := strconv.FormatUint(uint64(vs.SVlan), 10) + "-"
vnetName = vnetName + strconv.FormatUint(uint64(vs.CVlan), 10) + "-"
vnetName = vnetName + strconv.FormatUint(uint64(vs.UniVlan), 10)
- if err := va.DelVnet(vnetName, ""); err != nil {
+ if err := va.DelVnet(cntx, vnetName, ""); err != nil {
logger.Warnw(ctx, "Delete Vnet Failed", log.Fields{"Name": vnetName, "Error": err})
}
}
@@ -1118,7 +1119,7 @@
}
// DelService delete a service form the application
-func (va *VoltApplication) DelService(name string, forceDelete bool, newSvc *VoltServiceCfg, serviceMigration bool) {
+func (va *VoltApplication) DelService(cntx context.Context, name string, forceDelete bool, newSvc *VoltServiceCfg, serviceMigration bool) {
AppMutex.ServiceDataMutex.Lock()
defer AppMutex.ServiceDataMutex.Unlock()
@@ -1141,7 +1142,7 @@
//Set this to avoid race-condition during flow result processing
vs.DeleteInProgress = true
vs.ForceDelete = forceDelete
- vs.ForceWriteToDb()
+ vs.ForceWriteToDb(cntx)
if len(vs.AssociatedFlows) == 0 {
noFlowsPresent = true
@@ -1149,22 +1150,22 @@
vpv.VpvLock.Lock()
defer vpv.VpvLock.Unlock()
- vs.DelHsiaFlows()
+ vs.DelHsiaFlows(cntx)
if vpv.IgmpEnabled {
- va.ReceiverDownInd(vpv.Device, vpv.Port)
+ va.ReceiverDownInd(cntx, vpv.Device, vpv.Port)
}
logger.Infow(ctx, "Delete Service from VPV", log.Fields{"VPV_Port": vpv.Port, "VPV_SVlan": vpv.SVlan, "VPV_CVlan": vpv.CVlan, "VPV_UniVlan": vpv.UniVlan, "ServiceName": name})
- vpv.DelService(vs)
+ vpv.DelService(cntx, vs)
if vpv.servicesCount.Load() == 0 {
- va.DelVnetFromPort(vs.Port, vpv)
+ va.DelVnetFromPort(cntx, vs.Port, vpv)
}
// Delete the service immediately in case of Force Delete
// This will be enabled when profile reconciliation happens after restore
// of backedup data
if vs.ForceDelete {
- vs.DelFromDb()
+ vs.DelFromDb(cntx)
GetApplication().ServiceByName.Delete(vs.Name)
logger.Warnw(ctx, "Deleted service from DB/Cache successfully", log.Fields{"serviceName": vs.Name})
}
@@ -1209,25 +1210,25 @@
meter.AssociatedServices--
if meter.AssociatedServices == 0 && !skipMeterDeletion {
logger.Infow(ctx, "Meter should be deleted now\n", log.Fields{"MeterID": meter})
- va.UpdateMeterProf(*meter)
+ va.UpdateMeterProf(cntx, *meter)
}
}
}
if noFlowsPresent || vs.ForceDelete {
- vs.CheckAndDeleteService()
+ vs.CheckAndDeleteService(cntx)
}
//Delete the per service counter too
va.ServiceCounters.Delete(name)
if vs.IgmpEnabled && vs.EnableMulticastKPI {
- _ = db.DelAllServiceChannelCounter(name)
+ _ = db.DelAllServiceChannelCounter(cntx, name)
}
}
//AddFlows - Adds the flow to the service
// Triggers flow addition after registering for flow indication event
-func (vs *VoltService) AddFlows(device *VoltDevice, flow *of.VoltFlow) error {
+func (vs *VoltService) AddFlows(cntx context.Context, device *VoltDevice, flow *of.VoltFlow) error {
// Using locks instead of concurrent map for PendingFlows to avoid
// race condition during flow response indication processing
@@ -1245,12 +1246,12 @@
device.RegisterFlowAddEvent(cookie, fe)
vs.PendingFlows[cookie] = true
}
- return cntlr.GetController().AddFlows(vs.Port, device.Name, flow)
+ return cntlr.GetController().AddFlows(cntx, vs.Port, device.Name, flow)
}
//FlowInstallSuccess - Called when corresponding service flow installation is success
// If no more pending flows, HSIA indication wil be triggered
-func (vs *VoltService) FlowInstallSuccess(cookie string, bwAvailInfo of.BwAvailDetails) {
+func (vs *VoltService) FlowInstallSuccess(cntx context.Context, cookie string, bwAvailInfo of.BwAvailDetails) {
if vs.DeleteInProgress {
logger.Warnw(ctx, "Skipping Flow Add Success Notification. Service deletion in-progress", log.Fields{"Cookie": cookie, "Service": vs.Name})
return
@@ -1273,7 +1274,7 @@
vs.BwAvailInfo = prevBwAvail + "," + presentBwAvail
logger.Debugw(ctx, "Bandwidth-value-formed", log.Fields{"BwAvailInfo": vs.BwAvailInfo})
}
- vs.WriteToDb()
+ vs.WriteToDb(cntx)
if len(vs.PendingFlows) == 0 && vs.DsHSIAFlowsApplied {
@@ -1288,7 +1289,7 @@
if vs.Trigger == ServiceVlanUpdate {
vs.Trigger = NBActivate
- defer vs.WriteToDb()
+ defer vs.WriteToDb(cntx)
}
logger.Infow(ctx, "All Flows installed for Service", log.Fields{"Service": vs.Name})
return
@@ -1313,7 +1314,7 @@
//DelFlows - Deletes the flow from the service
// Triggers flow deletion after registering for flow indication event
-func (vs *VoltService) DelFlows(device *VoltDevice, flow *of.VoltFlow) error {
+func (vs *VoltService) DelFlows(cntx context.Context, device *VoltDevice, flow *of.VoltFlow) error {
if !vs.ForceDelete {
// Using locks instead of concurrent map for AssociatedFlows to avoid
@@ -1331,13 +1332,13 @@
device.RegisterFlowDelEvent(cookie, fe)
}
}
- return cntlr.GetController().DelFlows(vs.Port, device.Name, flow)
+ return cntlr.GetController().DelFlows(cntx, vs.Port, device.Name, flow)
}
//CheckAndDeleteService - remove service from DB is there are no pending flows to be removed
-func (vs *VoltService) CheckAndDeleteService() {
+func (vs *VoltService) CheckAndDeleteService(cntx context.Context) {
if vs.DeleteInProgress && len(vs.AssociatedFlows) == 0 && !vs.DsHSIAFlowsApplied {
- vs.DelFromDb()
+ vs.DelFromDb(cntx)
GetApplication().ServiceByName.Delete(vs.Name)
logger.Warnw(ctx, "Deleted service from DB/Cache successfully", log.Fields{"serviceName": vs.Name})
}
@@ -1345,7 +1346,7 @@
//FlowRemoveSuccess - Called when corresponding service flow removal is success
// If no more associated flows, DelHSIA indication wil be triggered
-func (vs *VoltService) FlowRemoveSuccess(cookie string) {
+func (vs *VoltService) FlowRemoveSuccess(cntx context.Context, cookie string) {
// if vs.DeleteInProgress {
// logger.Warnw(ctx, "Skipping Flow Remove Success Notification. Service deletion in-progress", log.Fields{"Cookie": cookie, "Service": vs.Name})
@@ -1364,7 +1365,7 @@
vs.ServiceLock.Unlock()
- vs.WriteToDb()
+ vs.WriteToDb(cntx)
if len(vs.AssociatedFlows) == 0 && !vs.DsHSIAFlowsApplied {
@@ -1378,12 +1379,12 @@
}
if vs.UpdateInProgress {
- vs.updateVnetProfile(vs.Device)
+ vs.updateVnetProfile(cntx, vs.Device)
//Not sending DEL_HSIA Indication since it wil be generated internally by SubMgr
return
}
logger.Infow(ctx, "All Flows removed for Service. Triggering Service De-activation Success indication to NB", log.Fields{"Service": vs.Name, "DeleteFlag": vs.DeleteInProgress})
- vs.CheckAndDeleteService()
+ vs.CheckAndDeleteService(cntx)
return
}
@@ -1392,7 +1393,7 @@
//FlowRemoveFailure - Called when corresponding service flow installation is failed
// Trigger service failure indication to NB
-func (vs *VoltService) FlowRemoveFailure(cookie string, errorCode uint32, errReason string) {
+func (vs *VoltService) FlowRemoveFailure(cntx context.Context, cookie string, errorCode uint32, errReason string) {
vs.ServiceLock.RLock()
if _, ok := vs.AssociatedFlows[cookie]; !ok {
@@ -1407,7 +1408,7 @@
logger.Errorw(ctx, "Service Flow Remove Failure Notification", log.Fields{"uniPort": vs.Port, "Cookie": cookie, "Service": vs.Name, "ErrorCode": errorCode, "ErrorReason": errReason})
vs.triggerServiceFailureInd(errorCode, errReason)
- vs.CheckAndDeleteService()
+ vs.CheckAndDeleteService(cntx)
}
func (vs *VoltService) triggerServiceFailureInd(errorCode uint32, errReason string) {
@@ -1422,9 +1423,9 @@
}
// RestoreSvcsFromDb read from the DB and restore all the services
-func (va *VoltApplication) RestoreSvcsFromDb() {
+func (va *VoltApplication) RestoreSvcsFromDb(cntx context.Context) {
// VNETS must be learnt first
- vss, _ := db.GetServices()
+ vss, _ := db.GetServices(cntx)
for _, vs := range vss {
b, ok := vs.Value.([]byte)
if !ok {
@@ -1438,7 +1439,7 @@
continue
}
logger.Debugw(ctx, "Retrieved Service", log.Fields{"Service": vvs.VoltServiceCfg})
- if err := va.AddService(vvs.VoltServiceCfg, &vvs.VoltServiceOper); err != nil {
+ if err := va.AddService(cntx, vvs.VoltServiceCfg, &vvs.VoltServiceOper); err != nil {
logger.Warnw(ctx, "Add New Service Failed", log.Fields{"Service": vvs.Name, "Error": err})
}
@@ -1551,10 +1552,10 @@
// }
//WriteToDB - writes the udpate vnet request details ot DB
-func (msr *MigrateServicesRequest) WriteToDB() {
+func (msr *MigrateServicesRequest) WriteToDB(cntx context.Context) {
logger.Debugw(ctx, "Adding Migrate Service Request to DB", log.Fields{"OldVnet": msr.OldVnetID, "NewVnet": msr.NewVnetID, "Device": msr.DeviceID, "RequestID": msr.ID, "ServiceCount": len(msr.ServicesList)})
if b, err := json.Marshal(msr); err == nil {
- if err = db.PutMigrateServicesReq(msr.DeviceID, msr.GetMsrKey(), string(b)); err != nil {
+ if err = db.PutMigrateServicesReq(cntx, msr.DeviceID, msr.GetMsrKey(), string(b)); err != nil {
logger.Warnw(ctx, "PutMigrateServicesReq Failed", log.Fields{"OldVnet": msr.OldVnetID, "NewVnet": msr.NewVnetID,
"Device": msr.DeviceID, "Error": err})
}
@@ -1562,7 +1563,7 @@
}
//MigrateServices - updated vnet profile for services
-func (va *VoltApplication) MigrateServices(serialNum string, reqID string, oldVnetID, newVnetID string, serviceList []string) error {
+func (va *VoltApplication) MigrateServices(cntx context.Context, serialNum string, reqID string, oldVnetID, newVnetID string, serviceList []string) error {
logger.Warnw(ctx, "Migrate Serviec Request Received", log.Fields{"SerialNum": serialNum, "RequestID": reqID, "OldVnet": oldVnetID, "NewVnet": newVnetID, "ServiceList": serviceList})
if _, ok := va.VnetsByName.Load(oldVnetID); !ok {
@@ -1584,22 +1585,22 @@
serviceMap[service] = false
}
msr := newMigrateServicesRequest(reqID, oldVnetID, newVnetID, serviceMap, d.Name)
- msr.WriteToDB()
+ msr.WriteToDB(cntx)
d.AddMigratingServices(msr)
- go msr.ProcessMigrateServicesProfRequest()
+ go msr.ProcessMigrateServicesProfRequest(cntx)
return nil
}
//ProcessMigrateServicesProfRequest - collects all associated profiles
-func (msr *MigrateServicesRequest) ProcessMigrateServicesProfRequest() {
+func (msr *MigrateServicesRequest) ProcessMigrateServicesProfRequest(cntx context.Context) {
va := GetApplication()
for srv, processed := range msr.ServicesList {
//Indicates new service is already created and only deletion of old one is pending
if processed {
- va.DelService(srv, true, nil, true)
- msr.serviceMigrated(srv)
+ va.DelService(cntx, srv, true, nil, true)
+ msr.serviceMigrated(cntx, srv)
continue
}
@@ -1628,11 +1629,11 @@
//vpv flows will be removed when last service is removed from it and
// new vpv flows will be installed when new service is added
if vs.UsHSIAFlowsApplied {
- vpv.DelTrapFlows()
- vs.DelHsiaFlows()
+ vpv.DelTrapFlows(cntx)
+ vs.DelHsiaFlows(cntx)
logger.Infow(ctx, "Remove Service Flows Triggered", log.Fields{"Service": srv, "US": vs.UsHSIAFlowsApplied, "DS": vs.DsHSIAFlowsApplied})
} else {
- vs.updateVnetProfile(msr.DeviceID)
+ vs.updateVnetProfile(cntx, msr.DeviceID)
}
} else {
logger.Warnw(ctx, "Migrate Service Failed: Service Not Found", log.Fields{"Service": srv, "Vnet": msr.OldVnetID})
@@ -1688,7 +1689,7 @@
//updateVnetProfile - Called on flow process completion
// Removes old service and creates new VPV & service with udpated vnet profile
-func (vs *VoltService) updateVnetProfile(deviceID string) {
+func (vs *VoltService) updateVnetProfile(cntx context.Context, deviceID string) {
logger.Infow(ctx, "Update Vnet Profile Triggering", log.Fields{"Service": vs.Name, "US": vs.UsHSIAFlowsApplied, "DS": vs.DsHSIAFlowsApplied})
@@ -1746,24 +1747,24 @@
//TODO:Nav Pass a copy, not the pointer
logger.Infow(ctx, "Add New Service Triggering", log.Fields{"Service": nvs.Name, "US": nvs.UsHSIAFlowsApplied, "DS": nvs.DsHSIAFlowsApplied, "DelFlag": nvs.DeleteInProgress})
- if err := va.AddService(nvs.VoltServiceCfg, &nvs.VoltServiceOper); err != nil {
+ if err := va.AddService(cntx, nvs.VoltServiceCfg, &nvs.VoltServiceOper); err != nil {
logger.Warnw(ctx, "Add New Service Failed", log.Fields{"Service": nvs.Name, "Error": err})
}
logger.Infow(ctx, "Add New Service Triggered", log.Fields{"Service": nvs.Name, "US": nvs.UsHSIAFlowsApplied, "DS": nvs.DsHSIAFlowsApplied, "DelFlag": nvs.DeleteInProgress})
msr.ServicesList[oldSrvName] = true
va.updateMigrateServicesRequest(deviceID, oldVnetID, id, msr)
- msr.WriteToDB()
+ msr.WriteToDB(cntx)
logger.Infow(ctx, "Del Old Service Triggering", log.Fields{"Service": oldSrvName, "US": vs.UsHSIAFlowsApplied, "DS": vs.DsHSIAFlowsApplied, "DelFlag": vs.DeleteInProgress})
- va.DelService(oldSrvName, true, nil, true)
+ va.DelService(cntx, oldSrvName, true, nil, true)
logger.Infow(ctx, "Del Old Service Triggered", log.Fields{"Service": oldSrvName, "US": vs.UsHSIAFlowsApplied, "DS": vs.DsHSIAFlowsApplied, "DelFlag": vs.DeleteInProgress})
- msr.serviceMigrated(oldSrvName)
+ msr.serviceMigrated(cntx, oldSrvName)
}
//serviceMigrated - called on successful service updation
// Removes the service entry from servicelist and deletes the request on process completion
-func (msr *MigrateServicesRequest) serviceMigrated(serviceName string) {
+func (msr *MigrateServicesRequest) serviceMigrated(cntx context.Context, serviceName string) {
msr.MigrateServicesLock.Lock()
defer msr.MigrateServicesLock.Unlock()
@@ -1771,22 +1772,22 @@
delete(msr.ServicesList, serviceName)
if len(msr.ServicesList) == 0 {
- _ = db.DelMigrateServicesReq(msr.DeviceID, msr.GetMsrKey())
+ _ = db.DelMigrateServicesReq(cntx, msr.DeviceID, msr.GetMsrKey())
return
}
- msr.WriteToDB()
+ msr.WriteToDB(cntx)
//TODO:Nav - Need for any Response to SubMgr?
}
//TriggerPendingMigrateServicesReq - trigger pending service request
-func (va *VoltApplication) TriggerPendingMigrateServicesReq(device string) {
- va.FetchAndProcessAllMigrateServicesReq(device, storeAndProcessMigrateSrvRequest)
+func (va *VoltApplication) TriggerPendingMigrateServicesReq(cntx context.Context, device string) {
+ va.FetchAndProcessAllMigrateServicesReq(cntx, device, storeAndProcessMigrateSrvRequest)
}
//FetchAndProcessAllMigrateServicesReq - fetch all pending migrate services req from DB and process based on provided func
-func (va *VoltApplication) FetchAndProcessAllMigrateServicesReq(device string, msrAction func(*MigrateServicesRequest)) {
+func (va *VoltApplication) FetchAndProcessAllMigrateServicesReq(cntx context.Context, device string, msrAction func(context.Context, *MigrateServicesRequest)) {
- msrList, _ := db.GetAllMigrateServicesReq(device)
+ msrList, _ := db.GetAllMigrateServicesReq(cntx, device)
for _, msr := range msrList {
b, ok := msr.Value.([]byte)
if !ok {
@@ -1794,7 +1795,7 @@
continue
}
msr := va.createMigrateServicesFromString(b)
- msrAction(msr)
+ msrAction(cntx, msr)
logger.Warnw(ctx, "Triggering Pending Migrate Services Req", log.Fields{"OldVnet": msr.OldVnetID, "NewVnet": msr.NewVnetID, "Device": device, "PendingProfiles": len(msr.ServicesList)})
}
@@ -1813,20 +1814,20 @@
}
//storeAndProcessMigrateSrvRequest - stores the msr info in device obj and triggers req
-func storeAndProcessMigrateSrvRequest(msr *MigrateServicesRequest) {
+func storeAndProcessMigrateSrvRequest(cntx context.Context, msr *MigrateServicesRequest) {
d := GetApplication().GetDevice(msr.DeviceID)
d.AddMigratingServices(msr)
- msr.ProcessMigrateServicesProfRequest()
+ msr.ProcessMigrateServicesProfRequest(cntx)
}
//forceUpdateAllServices - force udpate services with new vnet profile
-func forceUpdateAllServices(msr *MigrateServicesRequest) {
+func forceUpdateAllServices(cntx context.Context, msr *MigrateServicesRequest) {
for srv := range msr.ServicesList {
if vsIntf, ok := GetApplication().ServiceByName.Load(srv); ok {
- vsIntf.(*VoltService).updateVnetProfile(msr.DeviceID)
+ vsIntf.(*VoltService).updateVnetProfile(cntx, msr.DeviceID)
}
}
- _ = db.DelMigrateServicesReq(msr.DeviceID, msr.GetMsrKey())
+ _ = db.DelMigrateServicesReq(cntx, msr.DeviceID, msr.GetMsrKey())
}
//DeepEqualServicecfg - checks if the given service cfgs are same
@@ -1929,18 +1930,18 @@
}
//TriggerAssociatedFlowDelete - re-trigger service flow delete for pending delete flows
-func (vs *VoltService) TriggerAssociatedFlowDelete() bool {
+func (vs *VoltService) TriggerAssociatedFlowDelete(cntx context.Context) bool {
//Clear the Flows flag if already set
//This case happens only in case of some race condition
if vs.UsHSIAFlowsApplied {
- if err := vs.DelUsHsiaFlows(); err != nil {
+ if err := vs.DelUsHsiaFlows(cntx); err != nil {
logger.Errorw(ctx, "DelUsHsiaFlows Failed", log.Fields{"Device": vs.Device, "Service": vs.Name, "Error": err})
}
}
if vs.DsHSIAFlowsApplied {
- if err := vs.DelDsHsiaFlows(); err != nil {
+ if err := vs.DelDsHsiaFlows(cntx); err != nil {
logger.Errorw(ctx, "DelDsHsiaFlows Failed", log.Fields{"Device": vs.Device, "Service": vs.Name, "Error": err})
}
}
@@ -1965,7 +1966,7 @@
subFlow.Cookie = cookie
flow.SubFlows[cookie] = subFlow
logger.Infow(ctx, "Retriggering Service Delete Flow", log.Fields{"Device": vs.Device, "Service": vs.Name, "Cookie": cookie})
- if err := vs.DelFlows(vd, flow); err != nil {
+ if err := vs.DelFlows(cntx, vd, flow); err != nil {
logger.Errorw(ctx, "DelFlows Failed", log.Fields{"Device": vs.Device, "Service": vs.Name, "Cookie": cookie, "Error": err})
}
}
diff --git a/internal/pkg/application/timer.go b/internal/pkg/application/timer.go
index 1a80cb5..aa156a8 100644
--- a/internal/pkg/application/timer.go
+++ b/internal/pkg/application/timer.go
@@ -16,6 +16,7 @@
package application
import (
+ "context"
"time"
)
@@ -40,7 +41,7 @@
}
// Start to start timer
-func (va *VoltApplication) Start(cfg TimerCfg, timerType TimerType) {
+func (va *VoltApplication) Start(cntx context.Context, cfg TimerCfg, timerType TimerType) {
if timerMap[timerType] {
logger.Warn(ctx, "Duplicate Timer!!! Timer already running")
return
@@ -54,7 +55,7 @@
case tickTimer:
va.Tick()
case pendingPoolTimer:
- va.removeExpiredGroups()
+ va.removeExpiredGroups(cntx)
}
case <- timerChannels[timerType]:
return
diff --git a/internal/pkg/application/vnets.go b/internal/pkg/application/vnets.go
index 78fe54f..e11960c 100644
--- a/internal/pkg/application/vnets.go
+++ b/internal/pkg/application/vnets.go
@@ -18,6 +18,7 @@
import (
"encoding/json"
"errors"
+ "context"
"net"
infraerrorCodes "voltha-go-controller/internal/pkg/errorcodes"
"strconv"
@@ -162,7 +163,7 @@
}
//disassociatePortFromVnet - disassociate a port from Vnet and return true if the association map is empty
-func (vv *VoltVnet) disassociatePortFromVnet(device string, port string) {
+func (vv *VoltVnet) disassociatePortFromVnet(cntx context.Context, device string, port string) {
vv.VnetPortLock.Lock()
delete(vv.AssociatedPorts, port)
logger.Infow(ctx, "Disassociated Port from Vnet", log.Fields{"Device": device, "Port": port, "Vnet": vv.Name, "PendingDeleteFlow": vv.PendingDeleteFlow, "AssociatedPorts": vv.AssociatedPorts, "DeleteFlag": vv.DeleteInProgress})
@@ -173,7 +174,7 @@
if len(vv.PendingDeleteFlow[device]) == 0 {
logger.Warnw(ctx, "Deleting Vnet", log.Fields{"Name": vv.Name})
GetApplication().deleteVnetConfig(vv)
- _ = db.DelVnet(vv.Name)
+ _ = db.DelVnet(cntx, vv.Name)
} else {
logger.Warnw(ctx, "Skipping Del Vnet", log.Fields{"Name": vv.Name, "PendingDeleteFlow": vv.PendingDeleteFlow})
}
@@ -192,23 +193,23 @@
}
// WriteToDb commit the VNET to the database
-func (vv *VoltVnet) WriteToDb() {
+func (vv *VoltVnet) WriteToDb(cntx context.Context) {
if vv.DeleteInProgress {
logger.Warnw(ctx, "Skipping Redis Update for Vnet, Vnet delete in progress", log.Fields{"Vnet": vv.Name})
return
}
- vv.ForceWriteToDb()
+ vv.ForceWriteToDb(cntx)
}
//ForceWriteToDb force commit a vnet to the DB
-func (vv *VoltVnet) ForceWriteToDb() {
+func (vv *VoltVnet) ForceWriteToDb(cntx context.Context) {
vv.VnetPortLock.RLock()
defer vv.VnetPortLock.RUnlock()
vv.Version = database.PresentVersionMap[database.VnetPath]
logger.Debugw(ctx, "Updating VNET....", log.Fields{"vnet": vv})
if b, err := json.Marshal(vv); err == nil {
- if err:= db.PutVnet(vv.Name, string(b)); err != nil {
+ if err:= db.PutVnet(cntx, vv.Name, string(b)); err != nil {
logger.Warnw(ctx, "Add Vnet to DB failed", log.Fields{"vnet name": vv.Name, "Error": err})
}
}
@@ -275,7 +276,7 @@
}
// AddVnet to add a VNET to the list of VNETs configured.
-func (va *VoltApplication) AddVnet(cfg VnetConfig, oper *VnetOper) error {
+func (va *VoltApplication) AddVnet(cntx context.Context, cfg VnetConfig, oper *VnetOper) error {
AppMutex.VnetMutex.Lock()
var vv *VoltVnet
@@ -312,7 +313,7 @@
}
va.storeVnetConfig(cfg, vv)
- vv.WriteToDb()
+ vv.WriteToDb(cntx)
logger.Infow(ctx, "Added VNET TO DB", log.Fields{"cfg": cfg, "devicesToHandle": devicesToHandle})
@@ -322,7 +323,7 @@
}
// DelVnet to delete a VNET from the list of VNETs configured
-func (va *VoltApplication) DelVnet(name, deviceSerialNum string) error {
+func (va *VoltApplication) DelVnet(cntx context.Context, name, deviceSerialNum string) error {
logger.Infow(ctx, "Deleting Vnet", log.Fields{"Vnet": name})
AppMutex.VnetMutex.Lock()
if vnetIntf, ok := va.VnetsByName.Load(name); ok {
@@ -330,23 +331,23 @@
//Delete from mvp list
vnet.DevicesList = util.RemoveFromSlice(vnet.DevicesList, deviceSerialNum)
- va.DeleteDevFlowForVlanFromDevice(vnet, deviceSerialNum)
+ va.DeleteDevFlowForVlanFromDevice(cntx, vnet, deviceSerialNum)
if len(vnet.DevicesList) == 0 {
vnet.DeleteInProgress = true
vnet.PendingDeviceToDelete = deviceSerialNum
- vnet.ForceWriteToDb()
+ vnet.ForceWriteToDb(cntx)
vnet.VnetPortLock.RLock()
if len(vnet.PendingDeleteFlow) == 0 && !vnet.isAssociatedPortsPresent() {
logger.Warnw(ctx, "Deleting Vnet", log.Fields{"Name": vnet.Name, "AssociatedPorts": vnet.AssociatedPorts, "PendingDelFlows": vnet.PendingDeleteFlow})
va.deleteVnetConfig(vnet)
- _ = db.DelVnet(vnet.Name)
+ _ = db.DelVnet(cntx, vnet.Name)
} else {
logger.Warnw(ctx, "Skipping Del Vnet", log.Fields{"Name": vnet.Name, "AssociatedPorts": vnet.AssociatedPorts, "PendingDelFlows": vnet.PendingDeleteFlow})
}
vnet.VnetPortLock.RUnlock()
} else {
//Update the devicelist in db
- vnet.WriteToDb()
+ vnet.WriteToDb(cntx)
}
}
//TODO: if no vnets are present on device remove icmpv6 group from device
@@ -355,9 +356,9 @@
}
// UpdateVnet to update the VNET with associated service count
-func (va *VoltApplication) UpdateVnet(vv *VoltVnet) error {
+func (va *VoltApplication) UpdateVnet(cntx context.Context, vv *VoltVnet) error {
va.storeVnetConfig(vv.VnetConfig, vv)
- vv.WriteToDb()
+ vv.WriteToDb(cntx)
logger.Infow(ctx, "Updated VNET TO DB", log.Fields{"vv": vv.VnetConfig})
return nil
}
@@ -577,13 +578,13 @@
}
// DhcpResultInd for dhcp result indication
-func (vpv *VoltPortVnet) DhcpResultInd(res *layers.DHCPv4) {
- vpv.ProcessDhcpResult(res)
+func (vpv *VoltPortVnet) DhcpResultInd(cntx context.Context, res *layers.DHCPv4) {
+ vpv.ProcessDhcpResult(cntx, res)
}
// Dhcpv6ResultInd for dhcpv6 result indication
-func (vpv *VoltPortVnet) Dhcpv6ResultInd(ipv6Addr net.IP, leaseTime uint32) {
- vpv.ProcessDhcpv6Result(ipv6Addr, leaseTime)
+func (vpv *VoltPortVnet) Dhcpv6ResultInd(cntx context.Context, ipv6Addr net.IP, leaseTime uint32) {
+ vpv.ProcessDhcpv6Result(cntx, ipv6Addr, leaseTime)
}
// GetNniVlans to get nni vlans
@@ -611,20 +612,20 @@
}
// AddService to add service
-func (vpv *VoltPortVnet) AddService(service *VoltService) {
+func (vpv *VoltPortVnet) AddService(cntx context.Context, service *VoltService) {
vpv.services.Store(service.Name, service)
vpv.servicesCount.Inc()
logger.Infow(ctx, "Service added/updated to VPV", log.Fields{"Port": vpv.Port, "SVLAN": vpv.SVlan, "CVLAN": vpv.CVlan, "UNIVlan": vpv.UniVlan, "Service": service.Name, "Count": vpv.servicesCount.Load()})
}
// DelService to delete service
-func (vpv *VoltPortVnet) DelService(service *VoltService) {
+func (vpv *VoltPortVnet) DelService(cntx context.Context, service *VoltService) {
vpv.services.Delete(service.Name)
vpv.servicesCount.Dec()
// If the only Igmp Enabled service is removed, remove the Igmp trap flow along with it
if service.IgmpEnabled {
- if err := vpv.DelIgmpFlows(); err != nil {
+ if err := vpv.DelIgmpFlows(cntx); err != nil {
statusCode, statusMessage := infraerrorCodes.GetErrorInfo(err)
vpv.FlowInstallFailure("VGC processing failure", statusCode, statusMessage)
}
@@ -635,26 +636,33 @@
}
// ProcessDhcpResult to process dhcp results
-func (vpv *VoltPortVnet) ProcessDhcpResult(res *layers.DHCPv4) {
+func (vpv *VoltPortVnet) ProcessDhcpResult(cntx context.Context, res *layers.DHCPv4) {
msgType := DhcpMsgType(res)
if msgType == layers.DHCPMsgTypeAck {
- vpv.ProcessDhcpSuccess(res)
+ vpv.ProcessDhcpSuccess(cntx, res)
} else if msgType == layers.DHCPMsgTypeNak {
vpv.DhcpStatus = DhcpStatusNacked
}
- vpv.WriteToDb()
+ vpv.WriteToDb(cntx)
+}
+
+// RangeOnServices to call a function on all services on the vpv
+func (vpv *VoltPortVnet) RangeOnServices(cntx context.Context, callback func(cntx context.Context, key, value interface{}) bool) {
+ vpv.services.Range(func(key, value interface{}) bool {
+ return callback(cntx, key, value)
+ })
}
// ProcessDhcpSuccess : Learn the IPv4 address allocated to the services and update the
// the services with the same. This also calls for adding flows
// for the services as the DHCP procedure is completed
-func (vpv *VoltPortVnet) ProcessDhcpSuccess(res *layers.DHCPv4) {
+func (vpv *VoltPortVnet) ProcessDhcpSuccess(cntx context.Context, res *layers.DHCPv4) {
vpv.DhcpStatus = DhcpStatusAcked
vpv.Ipv4Addr, _ = GetIpv4Addr(res)
logger.Infow(ctx, "Received IPv4 Address", log.Fields{"IP Address": vpv.Ipv4Addr.String()})
logger.Infow(ctx, "Services Configured", log.Fields{"Count": vpv.servicesCount.Load()})
- vpv.services.Range(vpv.updateIPv4AndProvisionFlows)
+ vpv.RangeOnServices(cntx, vpv.updateIPv4AndProvisionFlows)
vpv.ProcessDhcpv4Options(res)
}
@@ -675,17 +683,17 @@
// VNET. The same IPv6 address is also passed to the services. When a
// service is fetched all the associated information such as MAC address,
// IPv4 address and IPv6 addresses can be provided.
-func (vpv *VoltPortVnet) ProcessDhcpv6Result(ipv6Addr net.IP, leaseTime uint32) {
+func (vpv *VoltPortVnet) ProcessDhcpv6Result(cntx context.Context, ipv6Addr net.IP, leaseTime uint32) {
// TODO: Status based hanlding of flows
vpv.Dhcp6ExpiryTime = time.Now().Add((time.Duration(leaseTime) * time.Second))
vpv.Ipv6Addr = ipv6Addr
- vpv.services.Range(vpv.updateIPv6AndProvisionFlows)
- vpv.WriteToDb()
+ vpv.RangeOnServices(cntx, vpv.updateIPv6AndProvisionFlows)
+ vpv.WriteToDb(cntx)
}
// AddSvcUsMeterToDevice to add service upstream meter info to device
-func AddSvcUsMeterToDevice(key, value interface{}) bool {
+func AddSvcUsMeterToDevice(cntx context.Context, key, value interface{}) bool {
svc := value.(*VoltService)
logger.Infow(ctx, "Adding upstream meter profile to device", log.Fields{"ServiceName": svc.Name})
if device, _ := GetApplication().GetDeviceFromPort(svc.Port); device != nil {
@@ -697,7 +705,7 @@
}
// PushFlowsForPortVnet - triggers flow construction and push for provided VPV
-func (vpv *VoltPortVnet) PushFlowsForPortVnet(d *VoltDevice) {
+func (vpv *VoltPortVnet) PushFlowsForPortVnet(cntx context.Context, d *VoltDevice) {
vp := d.GetPort(vpv.Port)
@@ -717,7 +725,7 @@
// vpv.DsFlowsApplied = false
// vpv.UsFlowsApplied = false
vpv.VpvLock.Lock()
- vpv.PortUpInd(d, vpv.Port)
+ vpv.PortUpInd(cntx, d, vpv.Port)
vpv.VpvLock.Unlock()
}
@@ -726,7 +734,7 @@
// again here to apply the latest configuration if the configuration
// changed. Thus, a reboot of ONT forces the new configuration to get
// applied.
-func (vpv *VoltPortVnet) PortUpInd(device *VoltDevice, port string) {
+func (vpv *VoltPortVnet) PortUpInd(cntx context.Context, device *VoltDevice, port string) {
if vpv.DeleteInProgress {
logger.Errorw(ctx, "Ignoring VPV Port UP Ind, VPV deleteion In-Progress", log.Fields{"Device": device, "Port": port, "Vnet": vpv.VnetName})
@@ -760,16 +768,16 @@
logger.Infow(ctx, "Port Up - Trap Flows", log.Fields{"Device": device.Name, "Port": port})
// no HSIA flows for multicast service
if !vpv.McastService {
- vpv.services.Range(AddUsHsiaFlows)
+ vpv.RangeOnServices(cntx, AddUsHsiaFlows)
}
- vpv.AddTrapFlows()
+ vpv.AddTrapFlows(cntx)
if vpv.MacLearning == MacLearningNone || NonZeroMacAddress(vpv.MacAddr) {
logger.Infow(ctx, "Port Up - DS Flows", log.Fields{"Device": device.Name, "Port": port})
// US & DS DHCP, US HSIA flows are already installed
// install only DS HSIA flow here.
// no HSIA flows for multicast service
if !vpv.McastService {
- vpv.services.Range(AddDsHsiaFlows)
+ vpv.RangeOnServices(cntx, AddDsHsiaFlows)
}
}
@@ -781,50 +789,50 @@
// however is not seen as a real use case.
logger.Infow(ctx, "Port Up - Service Flows", log.Fields{"Device": device.Name, "Port": port})
if !vpv.McastService {
- vpv.services.Range(AddUsHsiaFlows)
+ vpv.RangeOnServices(cntx, AddUsHsiaFlows)
}
- vpv.AddTrapFlows()
+ vpv.AddTrapFlows(cntx)
if !vpv.McastService {
- vpv.services.Range(AddDsHsiaFlows)
+ vpv.RangeOnServices(cntx, AddDsHsiaFlows)
}
}
// Process IGMP proxy - install IGMP trap rules before DHCP trap rules
if vpv.IgmpEnabled {
logger.Infow(ctx, "Port Up - IGMP Flows", log.Fields{"Device": device.Name, "Port": port})
- vpv.services.Range(AddSvcUsMeterToDevice)
- if err := vpv.AddIgmpFlows(); err != nil {
+ vpv.RangeOnServices(cntx, AddSvcUsMeterToDevice)
+ if err := vpv.AddIgmpFlows(cntx); err != nil {
statusCode, statusMessage := infraerrorCodes.GetErrorInfo(err)
vpv.FlowInstallFailure("VGC processing failure", statusCode, statusMessage)
}
if vpv.McastService {
- vpv.services.Range(PostAccessConfigSuccessInd)
+ vpv.RangeOnServices(cntx, PostAccessConfigSuccessInd)
}
}
- vpv.WriteToDb()
+ vpv.WriteToDb(cntx)
}
// PortDownInd : When the port status changes to down, we delete all configured flows
// The same indication is also passed to the services enqueued for them
// to take appropriate actions
-func (vpv *VoltPortVnet) PortDownInd(device string, port string) {
+func (vpv *VoltPortVnet) PortDownInd(cntx context.Context, device string, port string) {
logger.Infow(ctx, "VPV Port DOWN Ind, deleting all flows for services",
log.Fields{"service count": vpv.servicesCount.Load()})
- //vpv.services.Range(DelAllFlows)
- vpv.DelTrapFlows()
- vpv.DelHsiaFlows()
- vpv.WriteToDb()
- vpv.ClearServiceCounters()
+ //vpv.RangeOnServices(cntx, DelAllFlows)
+ vpv.DelTrapFlows(cntx)
+ vpv.DelHsiaFlows(cntx)
+ vpv.WriteToDb(cntx)
+ vpv.ClearServiceCounters(cntx)
}
// SetMacAddr : The MAC address is set when a MAC address is learnt through the
// packets received from the network. Currently, DHCP packets are
// only packets we learn the MAC address from
-func (vpv *VoltPortVnet) SetMacAddr(addr net.HardwareAddr) {
+func (vpv *VoltPortVnet) SetMacAddr(cntx context.Context, addr net.HardwareAddr) {
//Store Learnt MAC address and return if MACLearning is not enabled
vpv.LearntMacAddr = addr
@@ -852,15 +860,15 @@
// may have been changed
// Atleast one HSIA flow should be present in adapter to retain the TP and GEM
// hence delete one after the other
- vpv.services.Range(DelUsHsiaFlows)
+ vpv.RangeOnServices(cntx, DelUsHsiaFlows)
vpv.MacAddr = addr
- vpv.services.Range(vpv.setLearntMAC)
- vpv.services.Range(AddUsHsiaFlows)
- vpv.services.Range(DelDsHsiaFlows)
+ vpv.RangeOnServices(cntx, vpv.setLearntMAC)
+ vpv.RangeOnServices(cntx, AddUsHsiaFlows)
+ vpv.RangeOnServices(cntx, DelDsHsiaFlows)
GetApplication().DeleteMacInPortMap(vpv.MacAddr)
} else {
vpv.MacAddr = addr
- vpv.services.Range(vpv.setLearntMAC)
+ vpv.RangeOnServices(cntx, vpv.setLearntMAC)
logger.Infow(ctx, "MAC Address learnt from DHCP or ARP", log.Fields{"Learnt MAC": addr.String(), "Port": vpv.Port})
}
GetApplication().UpdateMacInPortMap(vpv.MacAddr, vpv.Port)
@@ -879,10 +887,10 @@
if vpv.FlowsApplied {
// no HSIA flows for multicast service
if !vpv.McastService {
- vpv.services.Range(AddDsHsiaFlows)
+ vpv.RangeOnServices(cntx, AddDsHsiaFlows)
}
}
- vpv.WriteToDb()
+ vpv.WriteToDb(cntx)
}
// MatchesVlans : If the VNET matches both S and C VLANs, return true. Else, return false
@@ -954,10 +962,10 @@
// AddSvc adds a service on the VNET on a port. The addition is
// triggered when NB requests for service addition
-func (vpv *VoltPortVnet) AddSvc(svc *VoltService) {
+func (vpv *VoltPortVnet) AddSvc(cntx context.Context, svc *VoltService) {
//vpv.services = append(vpv.services, svc)
- vpv.AddService(svc)
+ vpv.AddService(cntx, svc)
logger.Debugw(ctx, "Added Service to VPV", log.Fields{"Num of SVCs": vpv.servicesCount.Load(), "SVC": svc})
// Learn the circuit-id and remote-id from the service
@@ -1034,9 +1042,9 @@
//to which the serivce is associated
if vpv.FlowsApplied {
if NonZeroMacAddress(vpv.MacAddr) || svc.MacLearning == MacLearningNone {
- svc.AddHsiaFlows()
+ svc.AddHsiaFlows(cntx)
} else {
- if err:= svc.AddUsHsiaFlows(); err != nil {
+ if err:= svc.AddUsHsiaFlows(cntx); err != nil {
logger.Warnw(ctx, "Add US hsia flow failed", log.Fields{"service": svc.Name, "Error": err})
}
}
@@ -1047,71 +1055,71 @@
// service with Igmp Enabled needs to be installed
if svc.IgmpEnabled && vpv.FlowsApplied {
logger.Infow(ctx, "Add Service - IGMP Flows", log.Fields{"Device": vpv.Device, "Port": vpv.Port})
- if err := vpv.AddIgmpFlows(); err != nil {
+ if err := vpv.AddIgmpFlows(cntx); err != nil {
statusCode, statusMessage := infraerrorCodes.GetErrorInfo(err)
vpv.FlowInstallFailure("VGC processing failure", statusCode, statusMessage)
}
if vpv.McastService {
//For McastService, send Service Activated indication once IGMP US flow is pushed
- vpv.services.Range(PostAccessConfigSuccessInd)
+ vpv.RangeOnServices(cntx, PostAccessConfigSuccessInd)
}
}
- vpv.WriteToDb()
+ vpv.WriteToDb(cntx)
}
// setLearntMAC to set learnt mac
-func (vpv *VoltPortVnet) setLearntMAC(key, value interface{}) bool {
+func (vpv *VoltPortVnet) setLearntMAC(cntx context.Context, key, value interface{}) bool {
svc := value.(*VoltService)
svc.SetMacAddr(vpv.MacAddr)
- svc.WriteToDb()
+ svc.WriteToDb(cntx)
return true
}
// PostAccessConfigSuccessInd for posting access config success indication
-func PostAccessConfigSuccessInd(key, value interface{}) bool {
+func PostAccessConfigSuccessInd(cntx context.Context, key, value interface{}) bool {
return true
}
// updateIPv4AndProvisionFlows to update ipv4 and provisional flows
-func (vpv *VoltPortVnet) updateIPv4AndProvisionFlows(key, value interface{}) bool {
+func (vpv *VoltPortVnet) updateIPv4AndProvisionFlows(cntx context.Context, key, value interface{}) bool {
svc := value.(*VoltService)
logger.Infow(ctx, "Updating Ipv4 address for service", log.Fields{"ServiceName": svc.Name})
svc.SetIpv4Addr(vpv.Ipv4Addr)
- svc.WriteToDb()
+ svc.WriteToDb(cntx)
return true
}
// updateIPv6AndProvisionFlows to update ipv6 and provisional flow
-func (vpv *VoltPortVnet) updateIPv6AndProvisionFlows(key, value interface{}) bool {
+func (vpv *VoltPortVnet) updateIPv6AndProvisionFlows(cntx context.Context, key, value interface{}) bool {
svc := value.(*VoltService)
svc.SetIpv6Addr(vpv.Ipv6Addr)
- svc.WriteToDb()
+ svc.WriteToDb(cntx)
return true
}
// AddUsHsiaFlows to add upstream hsia flows
-func AddUsHsiaFlows(key, value interface{}) bool {
+func AddUsHsiaFlows(cntx context.Context, key, value interface{}) bool {
svc := value.(*VoltService)
- if err:= svc.AddUsHsiaFlows(); err != nil {
+ if err:= svc.AddUsHsiaFlows(cntx); err != nil {
logger.Warnw(ctx, "Add US hsia flow failed", log.Fields{"service": svc.Name, "Error": err})
}
return true
}
// AddDsHsiaFlows to add downstream hsia flows
-func AddDsHsiaFlows(key, value interface{}) bool {
+func AddDsHsiaFlows(cntx context.Context, key, value interface{}) bool {
svc := value.(*VoltService)
- if err:= svc.AddDsHsiaFlows(); err != nil {
+ if err:= svc.AddDsHsiaFlows(cntx); err != nil {
logger.Warnw(ctx, "Add DS hsia flow failed", log.Fields{"service": svc.Name, "Error": err})
}
return true
}
// ClearFlagsInService to clear the flags used in service
-func ClearFlagsInService(key, value interface{}) bool {
+func ClearFlagsInService(cntx context.Context, key, value interface{}) bool {
svc := value.(*VoltService)
svc.ServiceLock.Lock()
svc.IgmpFlowsApplied = false
@@ -1123,50 +1131,50 @@
svc.PendingFlows = make(map[string]bool)
svc.AssociatedFlows = make(map[string]bool)
svc.ServiceLock.Unlock()
- svc.WriteToDb()
+ svc.WriteToDb(cntx)
logger.Debugw(ctx, "Cleared Flow Flags for service", log.Fields{"name": svc.Name})
return true
}
// DelDsHsiaFlows to delete hsia flows
-func DelDsHsiaFlows(key, value interface{}) bool {
+func DelDsHsiaFlows(cntx context.Context, key, value interface{}) bool {
svc := value.(*VoltService)
- if err:= svc.DelDsHsiaFlows(); err != nil {
+ if err:= svc.DelDsHsiaFlows(cntx); err != nil {
logger.Warnw(ctx, "Delete DS hsia flow failed", log.Fields{"service": svc.Name, "Error": err})
}
return true
}
// DelUsHsiaFlows to delete upstream hsia flows
-func DelUsHsiaFlows(key, value interface{}) bool {
+func DelUsHsiaFlows(cntx context.Context, key, value interface{}) bool {
svc := value.(*VoltService)
- if err:= svc.DelUsHsiaFlows(); err != nil {
+ if err:= svc.DelUsHsiaFlows(cntx); err != nil {
logger.Warnw(ctx, "Delete US hsia flow failed", log.Fields{"service": svc.Name, "Error": err})
}
return true
}
// ClearServiceCounters to clear the service counters
-func ClearServiceCounters(key, value interface{}) bool {
+func ClearServiceCounters(cntx context.Context, key, value interface{}) bool {
svc := value.(*VoltService)
//Delete the per service counter too
GetApplication().ServiceCounters.Delete(svc.Name)
if svc.IgmpEnabled && svc.EnableMulticastKPI {
- _ = db.DelAllServiceChannelCounter(svc.Name)
+ _ = db.DelAllServiceChannelCounter(cntx, svc.Name)
}
return true
}
//AddTrapFlows - Adds US & DS Trap flows
-func (vpv *VoltPortVnet) AddTrapFlows() {
+func (vpv *VoltPortVnet) AddTrapFlows(cntx context.Context) {
if !vpv.FlowsApplied || vgcRebooted {
if vpv.DhcpRelay {
- if err := vpv.AddUsDhcpFlows(); err != nil {
+ if err := vpv.AddUsDhcpFlows(cntx); err != nil {
statusCode, statusMessage := infraerrorCodes.GetErrorInfo(err)
vpv.FlowInstallFailure("VGC processing failure", statusCode, statusMessage)
}
- if err := vpv.AddDsDhcpFlows(); err != nil {
+ if err := vpv.AddDsDhcpFlows(cntx); err != nil {
statusCode, statusMessage := infraerrorCodes.GetErrorInfo(err)
vpv.FlowInstallFailure("VGC processing failure", statusCode, statusMessage)
}
@@ -1174,85 +1182,85 @@
log.Fields{"port": vpv.Port})
//vpv.updateICMPv6McGroup(true)
} else if vpv.ArpRelay {
- if err := vpv.AddUsArpFlows(); err != nil {
+ if err := vpv.AddUsArpFlows(cntx); err != nil {
statusCode, statusMessage := infraerrorCodes.GetErrorInfo(err)
vpv.FlowInstallFailure("VGC processing failure", statusCode, statusMessage)
}
logger.Info(ctx, "ARP trap rules not added in downstream direction")
} else if vpv.PppoeIa {
- if err := vpv.AddUsPppoeFlows(); err != nil {
+ if err := vpv.AddUsPppoeFlows(cntx); err != nil {
statusCode, statusMessage := infraerrorCodes.GetErrorInfo(err)
vpv.FlowInstallFailure("VGC processing failure", statusCode, statusMessage)
}
- if err := vpv.AddDsPppoeFlows(); err != nil {
+ if err := vpv.AddDsPppoeFlows(cntx); err != nil {
statusCode, statusMessage := infraerrorCodes.GetErrorInfo(err)
vpv.FlowInstallFailure("VGC processing failure", statusCode, statusMessage)
}
}
vpv.FlowsApplied = true
- vpv.WriteToDb()
+ vpv.WriteToDb(cntx)
}
}
//DelTrapFlows - Removes all US & DS DHCP, IGMP trap flows.
-func (vpv *VoltPortVnet) DelTrapFlows() {
+func (vpv *VoltPortVnet) DelTrapFlows(cntx context.Context) {
// Delete HSIA & DHCP flows before deleting IGMP flows
if vpv.FlowsApplied || vgcRebooted {
if vpv.DhcpRelay {
- if err:= vpv.DelUsDhcpFlows(); err != nil {
+ if err:= vpv.DelUsDhcpFlows(cntx); err != nil {
logger.Warnw(ctx, "Delete US hsia flow failed", log.Fields{"port": vpv.Port, "SVlan": vpv.SVlan, "CVlan": vpv.CVlan,
"UniVlan": vpv.UniVlan, "Error": err})
}
logger.Infow(ctx, "ICMPv6 MC Group modification will not be triggered to rwcore for ",
log.Fields{"port": vpv.Port})
- if err := vpv.DelDsDhcpFlows(); err != nil {
+ if err := vpv.DelDsDhcpFlows(cntx); err != nil {
statusCode, statusMessage := infraerrorCodes.GetErrorInfo(err)
vpv.FlowInstallFailure("VGC processing failure", statusCode, statusMessage)
}
//vpv.updateICMPv6McGroup(false)
} else if vpv.ArpRelay {
- if err := vpv.DelUsArpFlows(); err != nil {
+ if err := vpv.DelUsArpFlows(cntx); err != nil {
statusCode, statusMessage := infraerrorCodes.GetErrorInfo(err)
vpv.FlowInstallFailure("VGC processing failure", statusCode, statusMessage)
}
} else if vpv.PppoeIa {
- if err := vpv.DelUsPppoeFlows(); err != nil {
+ if err := vpv.DelUsPppoeFlows(cntx); err != nil {
statusCode, statusMessage := infraerrorCodes.GetErrorInfo(err)
vpv.FlowInstallFailure("VGC processing failure", statusCode, statusMessage)
}
- if err := vpv.DelDsPppoeFlows(); err != nil {
+ if err := vpv.DelDsPppoeFlows(cntx); err != nil {
statusCode, statusMessage := infraerrorCodes.GetErrorInfo(err)
vpv.FlowInstallFailure("VGC processing failure", statusCode, statusMessage)
}
}
vpv.FlowsApplied = false
- vpv.WriteToDb()
+ vpv.WriteToDb(cntx)
}
- if err:= vpv.DelIgmpFlows(); err != nil {
+ if err:= vpv.DelIgmpFlows(cntx); err != nil {
logger.Warnw(ctx, "Delete igmp flow failed", log.Fields{"port": vpv.Port, "SVlan": vpv.SVlan, "CVlan": vpv.CVlan,
"UniVlan": vpv.UniVlan, "Error": err})
}
}
// DelHsiaFlows deletes the service flows
-func (vpv *VoltPortVnet) DelHsiaFlows() {
+func (vpv *VoltPortVnet) DelHsiaFlows(cntx context.Context) {
// no HSIA flows for multicast service
if !vpv.McastService {
- vpv.services.Range(DelUsHsiaFlows)
- vpv.services.Range(DelDsHsiaFlows)
+ vpv.RangeOnServices(cntx, DelUsHsiaFlows)
+ vpv.RangeOnServices(cntx, DelDsHsiaFlows)
}
}
//ClearServiceCounters - Removes all igmp counters for a service
-func (vpv *VoltPortVnet) ClearServiceCounters() {
+func (vpv *VoltPortVnet) ClearServiceCounters(cntx context.Context) {
//send flows deleted indication to submgr
- vpv.services.Range(ClearServiceCounters)
+ vpv.RangeOnServices(cntx, ClearServiceCounters)
}
// AddUsDhcpFlows pushes the DHCP flows to the VOLTHA via the controller
-func (vpv *VoltPortVnet) AddUsDhcpFlows() error {
+func (vpv *VoltPortVnet) AddUsDhcpFlows(cntx context.Context) error {
var vd *VoltDevice
device := vpv.Device
@@ -1269,7 +1277,7 @@
flows, err := vpv.BuildUsDhcpFlows()
if err == nil {
logger.Debugw(ctx, "Adding US DHCP flows", log.Fields{"Device": device})
- if err1 := vpv.PushFlows(vd, flows); err1 != nil {
+ if err1 := vpv.PushFlows(cntx, vd, flows); err1 != nil {
//push ind here ABHI
statusCode, statusMessage := infraerrorCodes.GetErrorInfo(err1)
vpv.FlowInstallFailure("VGC processing failure", statusCode, statusMessage)
@@ -1302,7 +1310,7 @@
}
// AddDsDhcpFlows function pushes the DHCP flows to the VOLTHA via the controller
-func (vpv *VoltPortVnet) AddDsDhcpFlows() error {
+func (vpv *VoltPortVnet) AddDsDhcpFlows(cntx context.Context) error {
var vd *VoltDevice
device := vpv.Device
@@ -1322,7 +1330,7 @@
flows, err := vpv.BuildDsDhcpFlows()
if err == nil {
- if err1 := vpv.PushFlows(vd, flows); err1 != nil {
+ if err1 := vpv.PushFlows(cntx, vd, flows); err1 != nil {
//push ind here and procced
statusCode, statusMessage := infraerrorCodes.GetErrorInfo(err1)
vpv.FlowInstallFailure("VGC processing failure", statusCode, statusMessage)
@@ -1358,13 +1366,13 @@
}
// DelDhcpFlows deletes both US & DS DHCP flows applied for this Vnet instantiated on the port
-func (vpv *VoltPortVnet) DelDhcpFlows() {
- if err := vpv.DelUsDhcpFlows(); err != nil {
+func (vpv *VoltPortVnet) DelDhcpFlows(cntx context.Context) {
+ if err := vpv.DelUsDhcpFlows(cntx); err != nil {
statusCode, statusMessage := infraerrorCodes.GetErrorInfo(err)
vpv.FlowInstallFailure("VGC processing failure", statusCode, statusMessage)
}
- if err := vpv.DelDsDhcpFlows(); err != nil {
+ if err := vpv.DelDsDhcpFlows(cntx); err != nil {
statusCode, statusMessage := infraerrorCodes.GetErrorInfo(err)
vpv.FlowInstallFailure("VGC processing failure", statusCode, statusMessage)
}
@@ -1373,13 +1381,13 @@
// DelUsDhcpFlows delete the DHCP flows applied for this Vnet instantiated on the port
// Write the status of the VPV to the DB once the delete is scheduled
// for dispatch
-func (vpv *VoltPortVnet) DelUsDhcpFlows() error {
+func (vpv *VoltPortVnet) DelUsDhcpFlows(cntx context.Context) error {
device, err := GetApplication().GetDeviceFromPort(vpv.Port)
if err != nil {
return err
}
- err = vpv.delDhcp4Flows(device)
+ err = vpv.delDhcp4Flows(cntx, device)
if err != nil {
statusCode, statusMessage := infraerrorCodes.GetErrorInfo(err)
vpv.FlowInstallFailure("VGC processing failure", statusCode, statusMessage)
@@ -1393,10 +1401,10 @@
return nil
}
-func (vpv *VoltPortVnet) delDhcp4Flows(device *VoltDevice) error {
+func (vpv *VoltPortVnet) delDhcp4Flows(cntx context.Context, device *VoltDevice) error {
flows, err := vpv.BuildUsDhcpFlows()
if err == nil {
- return vpv.RemoveFlows(device, flows)
+ return vpv.RemoveFlows(cntx, device, flows)
}
logger.Errorw(ctx, "US DHCP Flow Delete Failed", log.Fields{"Reason": err.Error()})
return err
@@ -1415,12 +1423,12 @@
// DelDsDhcpFlows delete the DHCP flows applied for this Vnet instantiated on the port
// Write the status of the VPV to the DB once the delete is scheduled
// for dispatch
-func (vpv *VoltPortVnet) DelDsDhcpFlows() error {
+func (vpv *VoltPortVnet) DelDsDhcpFlows(cntx context.Context) error {
device, err := GetApplication().GetDeviceFromPort(vpv.Port)
if err != nil {
return err
}
- err = vpv.delDsDhcp4Flows(device)
+ err = vpv.delDsDhcp4Flows(cntx, device)
if err != nil {
statusCode, statusMessage := infraerrorCodes.GetErrorInfo(err)
vpv.FlowInstallFailure("VGC processing failure", statusCode, statusMessage)
@@ -1434,10 +1442,10 @@
return nil
}
-func (vpv *VoltPortVnet) delDsDhcp4Flows(device *VoltDevice) error {
+func (vpv *VoltPortVnet) delDsDhcp4Flows(cntx context.Context, device *VoltDevice) error {
flows, err := vpv.BuildDsDhcpFlows()
if err == nil {
- return vpv.RemoveFlows(device, flows)
+ return vpv.RemoveFlows(cntx, device, flows)
}
logger.Errorw(ctx, "DS DHCP Flow Delete Failed", log.Fields{"Reason": err.Error()})
return err
@@ -1454,7 +1462,7 @@
}*/
// AddUsArpFlows pushes the ARP flows to the VOLTHA via the controller
-func (vpv *VoltPortVnet) AddUsArpFlows() error {
+func (vpv *VoltPortVnet) AddUsArpFlows(cntx context.Context) error {
var vd *VoltDevice
device := vpv.Device
@@ -1471,7 +1479,7 @@
flows, err := vpv.BuildUsArpFlows()
if err == nil {
logger.Debugw(ctx, "Adding US ARP flows", log.Fields{"Device": device})
- if err1 := vpv.PushFlows(vd, flows); err1 != nil {
+ if err1 := vpv.PushFlows(cntx, vd, flows); err1 != nil {
return err1
}
} else {
@@ -1484,21 +1492,21 @@
// DelUsArpFlows delete the ARP flows applied for this Vnet instantiated on the port
// Write the status of the VPV to the DB once the delete is scheduled
// for dispatch
-func (vpv *VoltPortVnet) DelUsArpFlows() error {
+func (vpv *VoltPortVnet) DelUsArpFlows(cntx context.Context) error {
device, err := GetApplication().GetDeviceFromPort(vpv.Port)
if err != nil {
return err
}
flows, err := vpv.BuildUsArpFlows()
if err == nil {
- return vpv.RemoveFlows(device, flows)
+ return vpv.RemoveFlows(cntx, device, flows)
}
logger.Errorw(ctx, "US ARP Flow Delete Failed", log.Fields{"Reason": err.Error()})
return err
}
// AddUsPppoeFlows pushes the PPPoE flows to the VOLTHA via the controller
-func (vpv *VoltPortVnet) AddUsPppoeFlows() error {
+func (vpv *VoltPortVnet) AddUsPppoeFlows(cntx context.Context) error {
logger.Debugw(ctx, "Adding US PPPoE flows", log.Fields{"STAG": vpv.SVlan, "CTAG": vpv.CVlan, "Device": vpv.Device})
var vd *VoltDevice
@@ -1517,7 +1525,7 @@
if flows, err := vpv.BuildUsPppoeFlows(); err == nil {
logger.Debugw(ctx, "Adding US PPPoE flows", log.Fields{"Device": device})
- if err1 := vpv.PushFlows(vd, flows); err1 != nil {
+ if err1 := vpv.PushFlows(cntx, vd, flows); err1 != nil {
return err1
}
} else {
@@ -1528,7 +1536,7 @@
}
// AddDsPppoeFlows to add downstream pppoe flows
-func (vpv *VoltPortVnet) AddDsPppoeFlows() error {
+func (vpv *VoltPortVnet) AddDsPppoeFlows(cntx context.Context) error {
logger.Debugw(ctx, "Adding DS PPPoE flows", log.Fields{"STAG": vpv.SVlan, "CTAG": vpv.CVlan, "Device": vpv.Device})
var vd *VoltDevice
device := vpv.Device
@@ -1546,7 +1554,7 @@
flows, err := vpv.BuildDsPppoeFlows()
if err == nil {
- if err1 := vpv.PushFlows(vd, flows); err1 != nil {
+ if err1 := vpv.PushFlows(cntx, vd, flows); err1 != nil {
return err1
}
} else {
@@ -1559,7 +1567,7 @@
// DelUsPppoeFlows delete the PPPoE flows applied for this Vnet instantiated on the port
// Write the status of the VPV to the DB once the delete is scheduled
// for dispatch
-func (vpv *VoltPortVnet) DelUsPppoeFlows() error {
+func (vpv *VoltPortVnet) DelUsPppoeFlows(cntx context.Context) error {
logger.Debugw(ctx, "Deleting US PPPoE flows", log.Fields{"STAG": vpv.SVlan, "CTAG": vpv.CVlan, "Device": vpv.Device})
device, err := GetApplication().GetDeviceFromPort(vpv.Port)
if err != nil {
@@ -1567,7 +1575,7 @@
}
flows, err := vpv.BuildUsPppoeFlows()
if err == nil {
- return vpv.RemoveFlows(device, flows)
+ return vpv.RemoveFlows(cntx, device, flows)
}
logger.Errorw(ctx, "US PPPoE Flow Delete Failed", log.Fields{"Reason": err.Error()})
return err
@@ -1576,7 +1584,7 @@
// DelDsPppoeFlows delete the PPPoE flows applied for this Vnet instantiated on the port
// Write the status of the VPV to the DB once the delete is scheduled
// for dispatch
-func (vpv *VoltPortVnet) DelDsPppoeFlows() error {
+func (vpv *VoltPortVnet) DelDsPppoeFlows(cntx context.Context) error {
logger.Debugw(ctx, "Deleting DS PPPoE flows", log.Fields{"STAG": vpv.SVlan, "CTAG": vpv.CVlan, "Device": vpv.Device})
device, err := GetApplication().GetDeviceFromPort(vpv.Port)
if err != nil {
@@ -1584,14 +1592,14 @@
}
flows, err := vpv.BuildDsPppoeFlows()
if err == nil {
- return vpv.RemoveFlows(device, flows)
+ return vpv.RemoveFlows(cntx, device, flows)
}
logger.Errorw(ctx, "DS PPPoE Flow Delete Failed", log.Fields{"Reason": err.Error()})
return err
}
// AddIgmpFlows function pushes the IGMP flows to the VOLTHA via the controller
-func (vpv *VoltPortVnet) AddIgmpFlows() error {
+func (vpv *VoltPortVnet) AddIgmpFlows(cntx context.Context) error {
if !vpv.IgmpFlowsApplied || vgcRebooted {
if vpv.MvlanProfileName == "" {
@@ -1619,7 +1627,7 @@
vd.RegisterFlowAddEvent(cookie, fe)
}
}
- if err1 := cntlr.GetController().AddFlows(vpv.Port, device.Name, flows); err1 != nil {
+ if err1 := cntlr.GetController().AddFlows(cntx, vpv.Port, device.Name, flows); err1 != nil {
return err1
}
} else {
@@ -1627,7 +1635,7 @@
return err
}
vpv.IgmpFlowsApplied = true
- vpv.WriteToDb()
+ vpv.WriteToDb(cntx)
}
return nil
}
@@ -1635,7 +1643,7 @@
// DelIgmpFlows delete the IGMP flows applied for this Vnet instantiated on the port
// Write the status of the VPV to the DB once the delete is scheduled
// for dispatch
-func (vpv *VoltPortVnet) DelIgmpFlows() error {
+func (vpv *VoltPortVnet) DelIgmpFlows(cntx context.Context) error {
if vpv.IgmpFlowsApplied || vgcRebooted {
device, err := GetApplication().GetDeviceFromPort(vpv.Port)
@@ -1645,7 +1653,7 @@
}
flows, err := vpv.BuildIgmpFlows()
if err == nil {
- if err1 := vpv.RemoveFlows(device, flows); err1 != nil {
+ if err1 := vpv.RemoveFlows(cntx, device, flows); err1 != nil {
return err1
}
} else {
@@ -1653,7 +1661,7 @@
return err
}
vpv.IgmpFlowsApplied = false
- vpv.WriteToDb()
+ vpv.WriteToDb(cntx)
}
return nil
}
@@ -2111,21 +2119,21 @@
}
// WriteToDb for writing to database
-func (vpv *VoltPortVnet) WriteToDb() {
+func (vpv *VoltPortVnet) WriteToDb(cntx context.Context) {
if vpv.DeleteInProgress {
logger.Warnw(ctx, "Skipping Redis Update for VPV, VPV delete in progress", log.Fields{"Vnet": vpv.VnetName, "Port": vpv.Port})
return
}
- vpv.ForceWriteToDb()
+ vpv.ForceWriteToDb(cntx)
}
//ForceWriteToDb force commit a VPV to the DB
-func (vpv *VoltPortVnet) ForceWriteToDb() {
+func (vpv *VoltPortVnet) ForceWriteToDb(cntx context.Context) {
vpv.PendingFlowLock.RLock()
defer vpv.PendingFlowLock.RUnlock()
vpv.Version = database.PresentVersionMap[database.VpvPath]
if b, err := json.Marshal(vpv); err == nil {
- if err := db.PutVpv(vpv.Port, uint16(vpv.SVlan), uint16(vpv.CVlan), uint16(vpv.UniVlan), string(b)); err != nil {
+ if err := db.PutVpv(cntx, vpv.Port, uint16(vpv.SVlan), uint16(vpv.CVlan), uint16(vpv.UniVlan), string(b)); err != nil {
logger.Warnw(ctx, "VPV write to DB failed", log.Fields{"port": vpv.Port, "SVlan": vpv.SVlan, "CVlan": vpv.CVlan,
"UniVlan": vpv.UniVlan, "Error": err})
}
@@ -2133,24 +2141,24 @@
}
// DelFromDb for deleting from database
-func (vpv *VoltPortVnet) DelFromDb() {
+func (vpv *VoltPortVnet) DelFromDb(cntx context.Context) {
logger.Debugw(ctx, "Deleting VPV from DB", log.Fields{"Port": vpv.Port, "SVLAN": vpv.SVlan, "CVLAN": vpv.CVlan})
- _ = db.DelVpv(vpv.Port, uint16(vpv.SVlan), uint16(vpv.CVlan), uint16(vpv.UniVlan))
+ _ = db.DelVpv(cntx, vpv.Port, uint16(vpv.SVlan), uint16(vpv.CVlan), uint16(vpv.UniVlan))
}
// ClearAllServiceFlags to clear all service flags
-func (vpv *VoltPortVnet) ClearAllServiceFlags() {
- vpv.services.Range(ClearFlagsInService)
+func (vpv *VoltPortVnet) ClearAllServiceFlags(cntx context.Context) {
+ vpv.RangeOnServices(cntx, ClearFlagsInService)
}
// ClearAllVpvFlags to clear all vpv flags
-func (vpv *VoltPortVnet) ClearAllVpvFlags() {
+func (vpv *VoltPortVnet) ClearAllVpvFlags(cntx context.Context) {
vpv.PendingFlowLock.Lock()
vpv.FlowsApplied = false
vpv.IgmpFlowsApplied = false
vpv.PendingDeleteFlow = make(map[string]bool)
vpv.PendingFlowLock.Unlock()
- vpv.WriteToDb()
+ vpv.WriteToDb(cntx)
logger.Debugw(ctx, "Cleared Flow Flags for VPV",
log.Fields{"device": vpv.Device, "port": vpv.Port,
"svlan": vpv.SVlan, "cvlan": vpv.CVlan, "univlan": vpv.UniVlan})
@@ -2183,9 +2191,9 @@
}
// RestoreVpvsFromDb to restore vpvs from database
-func (va *VoltApplication) RestoreVpvsFromDb() {
+func (va *VoltApplication) RestoreVpvsFromDb(cntx context.Context) {
// VNETS must be learnt first
- vpvs, _ := db.GetVpvs()
+ vpvs, _ := db.GetVpvs(cntx)
for hash, vpv := range vpvs {
b, ok := vpv.Value.([]byte)
if !ok {
@@ -2214,7 +2222,7 @@
}
// AddVnetToPort to add vnet to port
-func (va *VoltApplication) AddVnetToPort(port string, vvnet *VoltVnet, vs *VoltService) *VoltPortVnet {
+func (va *VoltApplication) AddVnetToPort(cntx context.Context, port string, vvnet *VoltVnet, vs *VoltService) *VoltPortVnet {
// The VNET is not on the port and is to be added
logger.Debugw(ctx, "Adding VNET to Port", log.Fields{"Port": port, "VNET": vvnet.Name})
vpv := NewVoltPortVnet(vvnet)
@@ -2234,7 +2242,7 @@
defer vpv.VpvLock.Unlock()
// Add the service that is causing the VNET to be added to the port
- vpv.AddSvc(vs)
+ vpv.AddSvc(cntx, vs)
// Process the PORT UP if the port is already up
d, err := va.GetDeviceFromPort(port)
@@ -2248,17 +2256,17 @@
} else {
logger.Infow(ctx, "Checking UNI port state", log.Fields{"State": p.State})
if d.State == controller.DeviceStateUP && p.State == PortStateUp {
- vpv.PortUpInd(d, port)
+ vpv.PortUpInd(cntx, d, port)
}
}
}
}
- vpv.WriteToDb()
+ vpv.WriteToDb(cntx)
return vpv
}
// DelVnetFromPort for deleting vnet from port
-func (va *VoltApplication) DelVnetFromPort(port string, vpv *VoltPortVnet) {
+func (va *VoltApplication) DelVnetFromPort(cntx context.Context, port string, vpv *VoltPortVnet) {
//Delete DHCP Session
delDhcpSessions(vpv.LearntMacAddr, vpv.SVlan, vpv.CVlan, vpv.DHCPv6DUID)
@@ -2283,18 +2291,18 @@
vpvs = append(vpvs[0:i], vpvs[i+1:]...)
vpv.DeleteInProgress = true
- vpv.ForceWriteToDb()
+ vpv.ForceWriteToDb(cntx)
va.VnetsByPort.Store(port, vpvs)
- vpv.DelTrapFlows()
- vpv.DelHsiaFlows()
+ vpv.DelTrapFlows(cntx)
+ vpv.DelHsiaFlows(cntx)
va.DisassociateVpvsFromDevice(vpv.Device, vpv)
vpv.PendingFlowLock.RLock()
if len(vpv.PendingDeleteFlow) == 0 {
- vpv.DelFromDb()
+ vpv.DelFromDb(cntx)
}
if vnet := va.GetVnetByName(vpv.VnetName); vnet != nil {
- vnet.disassociatePortFromVnet(vpv.Device, vpv.Port)
+ vnet.disassociatePortFromVnet(cntx, vpv.Device, vpv.Port)
}
vpv.PendingFlowLock.RUnlock()
return
@@ -2303,9 +2311,9 @@
}
// RestoreVnetsFromDb to restore vnet from port
-func (va *VoltApplication) RestoreVnetsFromDb() {
+func (va *VoltApplication) RestoreVnetsFromDb(cntx context.Context) {
// VNETS must be learnt first
- vnets, _ := db.GetVnets()
+ vnets, _ := db.GetVnets(cntx)
for _, net := range vnets {
b, ok := net.Value.([]byte)
if !ok {
@@ -2319,7 +2327,7 @@
continue
}
logger.Debugw(ctx, "Retrieved VNET", log.Fields{"VNET": vnet.VnetConfig})
- if err := va.AddVnet(vnet.VnetConfig, &vnet.VnetOper); err != nil {
+ if err := va.AddVnet(cntx, vnet.VnetConfig, &vnet.VnetOper); err != nil {
logger.Warnw(ctx, "Add Vnet Failed", log.Fields{"Config": vnet.VnetConfig, "Error": err})
}
@@ -2454,7 +2462,7 @@
}
// PushDevFlowForVlan to push icmpv6 flows for vlan
-func (va *VoltApplication) PushDevFlowForVlan(vnet *VoltVnet) {
+func (va *VoltApplication) PushDevFlowForVlan(cntx context.Context, vnet *VoltVnet) {
logger.Infow(ctx, "PushDevFlowForVlan", log.Fields{"SVlan": vnet.SVlan, "CVlan": vnet.CVlan})
pushflow := func(key interface{}, value interface{}) bool {
device := value.(*VoltDevice)
@@ -2492,7 +2500,7 @@
//Pushing ICMPv6 Flow
flow := BuildICMPv6Flow(portID, vnet)
- err = cntlr.GetController().AddFlows(device.NniPort, device.Name, flow)
+ err = cntlr.GetController().AddFlows(cntx, device.NniPort, device.Name, flow)
if err != nil {
logger.Warnw(ctx, "Configuring ICMPv6 Flow for device failed ", log.Fields{"Device": device.Name, "err": err})
return true
@@ -2501,7 +2509,7 @@
// Pushing ARP Flow
flow = BuildDSArpFlow(portID, vnet)
- err = cntlr.GetController().AddFlows(device.NniPort, device.Name, flow)
+ err = cntlr.GetController().AddFlows(cntx, device.NniPort, device.Name, flow)
if err != nil {
logger.Warnw(ctx, "Configuring ARP Flow for device failed ", log.Fields{"Device": device.Name, "err": err})
return true
@@ -2518,7 +2526,7 @@
}
// PushDevFlowForDevice to push icmpv6 flows for device
-func (va *VoltApplication) PushDevFlowForDevice(device *VoltDevice) {
+func (va *VoltApplication) PushDevFlowForDevice(cntx context.Context, device *VoltDevice) {
logger.Infow(ctx, "PushDevFlowForDevice", log.Fields{"device": device})
logger.Debugw(ctx, "Configuring ICMPv6 Group for device ", log.Fields{"Device": device.Name})
@@ -2545,7 +2553,7 @@
return true
}
flow := BuildICMPv6Flow(nniPortID, vnet)
- err = cntlr.GetController().AddFlows(device.NniPort, device.Name, flow)
+ err = cntlr.GetController().AddFlows(cntx, device.NniPort, device.Name, flow)
if err != nil {
logger.Warnw(ctx, "Configuring ICMPv6 Flow for device failed ", log.Fields{"Device": device.Name, "err": err})
return true
@@ -2553,7 +2561,7 @@
logger.Infow(ctx, "ICMP Flow Added to Queue", log.Fields{"flow": flow})
flow = BuildDSArpFlow(nniPortID, vnet)
- err = cntlr.GetController().AddFlows(device.NniPort, device.Name, flow)
+ err = cntlr.GetController().AddFlows(cntx, device.NniPort, device.Name, flow)
if err != nil {
logger.Warnw(ctx, "Configuring ARP Flow for device failed ", log.Fields{"Device": device.Name, "err": err})
return true
@@ -2569,7 +2577,7 @@
}
// DeleteDevFlowForVlan to delete icmpv6 flow for vlan
-func (va *VoltApplication) DeleteDevFlowForVlan(vnet *VoltVnet) {
+func (va *VoltApplication) DeleteDevFlowForVlan(cntx context.Context, vnet *VoltVnet) {
logger.Infow(ctx, "DeleteDevFlowForVlan", log.Fields{"SVlan": vnet.SVlan, "CVlan": vnet.CVlan})
delflows := func(key interface{}, value interface{}) bool {
device := value.(*VoltDevice)
@@ -2591,7 +2599,7 @@
//Pushing ICMPv6 Flow
flow := BuildICMPv6Flow(portID, vnet)
flow.ForceAction = true
- err := vnet.RemoveFlows(device, flow)
+ err := vnet.RemoveFlows(cntx, device, flow)
if err != nil {
logger.Warnw(ctx, "De-Configuring ICMPv6 Flow for device failed ", log.Fields{"Device": device.Name, "err": err})
return true
@@ -2601,7 +2609,7 @@
//Pushing ARP Flow
flow = BuildDSArpFlow(portID, vnet)
flow.ForceAction = true
- err = vnet.RemoveFlows(device, flow)
+ err = vnet.RemoveFlows(cntx, device, flow)
if err != nil {
logger.Warnw(ctx, "De-Configuring ARP Flow for device failed ", log.Fields{"Device": device.Name, "err": err})
return true
@@ -2616,7 +2624,7 @@
}
// DeleteDevFlowForDevice to delete icmpv6 flow for device
-func (va *VoltApplication) DeleteDevFlowForDevice(device *VoltDevice) {
+func (va *VoltApplication) DeleteDevFlowForDevice(cntx context.Context, device *VoltDevice) {
logger.Infow(ctx, "DeleteDevFlowForDevice", log.Fields{"Device": device})
delicmpv6 := func(key, value interface{}) bool {
vnet := value.(*VoltVnet)
@@ -2638,7 +2646,7 @@
}
flow := BuildICMPv6Flow(nniPortID, vnet)
flow.ForceAction = true
- err = vnet.RemoveFlows(device, flow)
+ err = vnet.RemoveFlows(cntx, device, flow)
if err != nil {
logger.Warnw(ctx, "De-Configuring ICMPv6 Flow for device failed ", log.Fields{"Device": device.Name, "err": err})
return true
@@ -2646,7 +2654,7 @@
flow = BuildDSArpFlow(nniPortID, vnet)
flow.ForceAction = true
- err = vnet.RemoveFlows(device, flow)
+ err = vnet.RemoveFlows(cntx, device, flow)
if err != nil {
logger.Warnw(ctx, "De-Configuring ARP Flow for device failed ", log.Fields{"Device": device.Name, "err": err})
return true
@@ -2666,7 +2674,7 @@
}
// DeleteDevFlowForVlanFromDevice to delete icmpv6 flow for vlan from device
-func (va *VoltApplication) DeleteDevFlowForVlanFromDevice(vnet *VoltVnet, deviceSerialNum string) {
+func (va *VoltApplication) DeleteDevFlowForVlanFromDevice(cntx context.Context, vnet *VoltVnet, deviceSerialNum string) {
logger.Infow(ctx, "DeleteDevFlowForVlanFromDevice", log.Fields{"Device-serialNum": deviceSerialNum, "SVlan": vnet.SVlan, "CVlan": vnet.CVlan})
delflows := func(key interface{}, value interface{}) bool {
device := value.(*VoltDevice)
@@ -2701,14 +2709,14 @@
}
flow := BuildICMPv6Flow(portID, vnet)
flow.ForceAction = true
- if err := vnet.RemoveFlows(device, flow); err != nil {
+ if err := vnet.RemoveFlows(cntx, device, flow); err != nil {
logger.Warnw(ctx, "Delete Flow Failed", log.Fields{"Device": device, "Flow": flow, "Error": err})
}
logger.Infow(ctx, "ICMP Flow Delete Added to Queue", log.Fields{"flow": flow})
flow = BuildDSArpFlow(portID, vnet)
flow.ForceAction = true
- if err := vnet.RemoveFlows(device, flow); err != nil {
+ if err := vnet.RemoveFlows(cntx, device, flow); err != nil {
logger.Warnw(ctx, "Delete Flow Failed", log.Fields{"Device": device, "Flow": flow, "Error": err})
}
logger.Infow(ctx, "ARP Flow Delete Added to Queue", log.Fields{"flow": flow})
@@ -2859,7 +2867,7 @@
}
//PushFlows - Triggers flow addition after registering for flow indication event
-func (vpv *VoltPortVnet) PushFlows(device *VoltDevice, flow *of.VoltFlow) error {
+func (vpv *VoltPortVnet) PushFlows(cntx context.Context, device *VoltDevice, flow *of.VoltFlow) error {
for cookie := range flow.SubFlows {
cookie := strconv.FormatUint(cookie, 10)
@@ -2870,7 +2878,7 @@
}
device.RegisterFlowAddEvent(cookie, fe)
}
- return cntlr.GetController().AddFlows(vpv.Port, device.Name, flow)
+ return cntlr.GetController().AddFlows(cntx, vpv.Port, device.Name, flow)
}
//FlowInstallFailure - Process flow failure indication and triggers HSIA failure for all associated services
@@ -2886,7 +2894,7 @@
}
//RemoveFlows - Triggers flow deletion after registering for flow indication event
-func (vpv *VoltPortVnet) RemoveFlows(device *VoltDevice, flow *of.VoltFlow) error {
+func (vpv *VoltPortVnet) RemoveFlows(cntx context.Context, device *VoltDevice, flow *of.VoltFlow) error {
vpv.PendingFlowLock.Lock()
defer vpv.PendingFlowLock.Unlock()
@@ -2902,11 +2910,11 @@
device.RegisterFlowDelEvent(cookie, fe)
vpv.PendingDeleteFlow[cookie] = true
}
- return cntlr.GetController().DelFlows(vpv.Port, device.Name, flow)
+ return cntlr.GetController().DelFlows(cntx, vpv.Port, device.Name, flow)
}
//CheckAndDeleteVpv - remove VPV from DB is there are no pending flows to be removed
-func (vpv *VoltPortVnet) CheckAndDeleteVpv() {
+func (vpv *VoltPortVnet) CheckAndDeleteVpv(cntx context.Context) {
vpv.PendingFlowLock.RLock()
defer vpv.PendingFlowLock.RUnlock()
if !vpv.DeleteInProgress {
@@ -2914,24 +2922,24 @@
}
if len(vpv.PendingDeleteFlow) == 0 && !vpv.FlowsApplied {
logger.Infow(ctx, "All Flows removed for VPV. Triggering VPV Deletion from DB", log.Fields{"VPV Port": vpv.Port, "Device": vpv.Device, "Vnet": vpv.VnetName})
- vpv.DelFromDb()
+ vpv.DelFromDb(cntx)
logger.Infow(ctx, "Deleted VPV from DB/Cache successfully", log.Fields{"VPV Port": vpv.Port, "Device": vpv.Device, "Vnet": vpv.VnetName})
}
}
//FlowRemoveSuccess - Process flow success indication
-func (vpv *VoltPortVnet) FlowRemoveSuccess(cookie string, device string) {
+func (vpv *VoltPortVnet) FlowRemoveSuccess(cntx context.Context, cookie string, device string) {
vpv.PendingFlowLock.Lock()
logger.Infow(ctx, "VPV Flow Remove Success Notification", log.Fields{"Port": vpv.Port, "Cookie": cookie, "Device": device})
delete(vpv.PendingDeleteFlow, cookie)
vpv.PendingFlowLock.Unlock()
- vpv.CheckAndDeleteVpv()
- vpv.WriteToDb()
+ vpv.CheckAndDeleteVpv(cntx)
+ vpv.WriteToDb(cntx)
}
//FlowRemoveFailure - Process flow failure indication and triggers Del HSIA failure for all associated services
-func (vpv *VoltPortVnet) FlowRemoveFailure(cookie string, device string, errorCode uint32, errReason string) {
+func (vpv *VoltPortVnet) FlowRemoveFailure(cntx context.Context, cookie string, device string, errorCode uint32, errReason string) {
vpv.PendingFlowLock.Lock()
logger.Errorw(ctx, "VPV Flow Remove Failure Notification", log.Fields{"Port": vpv.Port, "Cookie": cookie, "ErrorCode": errorCode, "ErrorReason": errReason, "Device": device})
@@ -2947,15 +2955,15 @@
if vpv.DeleteInProgress {
delete(vpv.PendingDeleteFlow, cookie)
vpv.PendingFlowLock.Unlock()
- vpv.CheckAndDeleteVpv()
+ vpv.CheckAndDeleteVpv(cntx)
} else {
vpv.PendingFlowLock.Unlock()
- vpv.WriteToDb()
+ vpv.WriteToDb(cntx)
}
}
//RemoveFlows - Triggers flow deletion after registering for flow indication event
-func (vv *VoltVnet) RemoveFlows(device *VoltDevice, flow *of.VoltFlow) error {
+func (vv *VoltVnet) RemoveFlows(cntx context.Context, device *VoltDevice, flow *of.VoltFlow) error {
vv.VnetLock.Lock()
defer vv.VnetLock.Unlock()
@@ -2978,12 +2986,12 @@
flowMap[cookie] = true
vv.PendingDeleteFlow[device.Name] = flowMap
}
- vv.WriteToDb()
- return cntlr.GetController().DelFlows(device.NniPort, device.Name, flow)
+ vv.WriteToDb(cntx)
+ return cntlr.GetController().DelFlows(cntx, device.NniPort, device.Name, flow)
}
//CheckAndDeleteVnet - remove Vnet from DB is there are no pending flows to be removed
-func (vv *VoltVnet) CheckAndDeleteVnet(device string) {
+func (vv *VoltVnet) CheckAndDeleteVnet(cntx context.Context, device string) {
if !vv.DeleteInProgress {
return
}
@@ -2991,7 +2999,7 @@
if len(vv.PendingDeleteFlow[device]) == 0 && !vv.isAssociatedPortsPresent() {
logger.Warnw(ctx, "Deleting Vnet : All flows removed", log.Fields{"Name": vv.Name, "AssociatedPorts": vv.AssociatedPorts, "Device": device})
GetApplication().deleteVnetConfig(vv)
- _ = db.DelVnet(vv.Name)
+ _ = db.DelVnet(cntx, vv.Name)
logger.Infow(ctx, "Deleted Vnet from DB/Cache successfully", log.Fields{"Device": device, "Vnet": vv.Name})
} else {
logger.Warnw(ctx, "Skipping Del Vnet", log.Fields{"Name": vv.Name, "AssociatedPorts": vv.AssociatedPorts, "PendingDelFlows": vv.PendingDeleteFlow[device]})
@@ -3000,7 +3008,7 @@
}
//FlowRemoveSuccess - Process flow success indication
-func (vv *VoltVnet) FlowRemoveSuccess(cookie string, device string) {
+func (vv *VoltVnet) FlowRemoveSuccess(cntx context.Context, cookie string, device string) {
vv.VnetLock.Lock()
defer vv.VnetLock.Unlock()
@@ -3014,14 +3022,14 @@
if d := GetApplication().GetDevice(device); d != nil {
_, present := d.ConfiguredVlanForDeviceFlows.Get(VnetKey(vv.SVlan, vv.CVlan, 0))
if !present && len(vv.PendingDeleteFlow[device]) == 0 {
- vv.CheckAndDeleteVnet(device)
+ vv.CheckAndDeleteVnet(cntx, device)
}
}
- vv.WriteToDb()
+ vv.WriteToDb(cntx)
}
//FlowRemoveFailure - Process flow failure indication
-func (vv *VoltVnet) FlowRemoveFailure(cookie string, device string, errorCode uint32, errReason string) {
+func (vv *VoltVnet) FlowRemoveFailure(cntx context.Context, cookie string, device string, errorCode uint32, errReason string) {
vv.VnetLock.Lock()
defer vv.VnetLock.Unlock()
@@ -3032,7 +3040,7 @@
if vv.DeleteInProgress {
delete(vv.PendingDeleteFlow[device], cookie)
- vv.CheckAndDeleteVnet(device)
+ vv.CheckAndDeleteVnet(cntx, device)
}
return
}
@@ -3107,7 +3115,7 @@
}
//TriggerAssociatedFlowDelete - Re-trigger delete for pending delete flows
-func (vv *VoltVnet) TriggerAssociatedFlowDelete(device string) bool {
+func (vv *VoltVnet) TriggerAssociatedFlowDelete(cntx context.Context, device string) bool {
vv.VnetLock.Lock()
cookieList := []uint64{}
flowMap := vv.PendingDeleteFlow[device]
@@ -3129,7 +3137,7 @@
subFlow.Cookie = cookie
flow.SubFlows[cookie] = subFlow
logger.Infow(ctx, "Retriggering Vnet Delete Flow", log.Fields{"Device": device, "Vnet": vv.Name, "Cookie": cookie})
- if err := vv.RemoveFlows(vd, flow); err != nil {
+ if err := vv.RemoveFlows(cntx, vd, flow); err != nil {
logger.Warnw(ctx, "Vnet Delete Flow Failed", log.Fields{"Device": device, "Vnet": vv.Name, "Cookie": cookie, "Error": err})
}
}
diff --git a/internal/pkg/controller/addflows.go b/internal/pkg/controller/addflows.go
index 0d6c27a..a4bf35c 100644
--- a/internal/pkg/controller/addflows.go
+++ b/internal/pkg/controller/addflows.go
@@ -84,7 +84,7 @@
logger.Infow(ctx, "Flow Mod Request", log.Fields{"Cookie": flow.Cookie, "Oper": aft.flow.Command, "Port": aft.flow.PortID})
if aft.flow.Command == of.CommandAdd {
flow.State = of.FlowAddPending
- if err := aft.device.AddFlow(flow); err != nil {
+ if err := aft.device.AddFlow(ctx, flow); err != nil {
logger.Warnw(ctx, "Add Flow Error", log.Fields{"Cookie": flow.Cookie, "Reason": err.Error()})
// If flow already exists in cache, check for flow state
@@ -93,7 +93,7 @@
if err.Error() == ErrDuplicateFlow {
dbFlow, _ := aft.device.GetFlow(flow.Cookie)
if dbFlow.State == of.FlowAddSuccess {
- aft.device.triggerFlowNotification(flow.Cookie, aft.flow.Command, of.BwAvailDetails{}, nil)
+ aft.device.triggerFlowNotification(ctx, flow.Cookie, aft.flow.Command, of.BwAvailDetails{}, nil)
flowsPresent++
}
}
@@ -108,7 +108,7 @@
// aft.device.AddFlowToDb(dbFlow)
flowsToProcess[flow.Cookie] = dbFlow
}
- aft.device.triggerFlowNotification(flow.Cookie, aft.flow.Command, of.BwAvailDetails{}, nil)
+ aft.device.triggerFlowNotification(ctx, flow.Cookie, aft.flow.Command, of.BwAvailDetails{}, nil)
}
}
@@ -124,7 +124,7 @@
for _, flow := range aft.flow.SubFlows {
logger.Errorw(ctx, "Skip Flow Update", log.Fields{"Reason": "Port Deleted", "PortName": aft.flow.PortName, "PortNo": aft.flow.PortID, "Cookie": flow.Cookie, "Operation": aft.flow.Command})
if aft.flow.Command == of.CommandDel {
- aft.device.triggerFlowNotification(flow.Cookie, aft.flow.Command, of.BwAvailDetails{}, nil)
+ aft.device.triggerFlowNotification(ctx, flow.Cookie, aft.flow.Command, of.BwAvailDetails{}, nil)
}
}
return nil
@@ -160,7 +160,7 @@
}
break
}
- aft.device.triggerFlowNotification(flow.FlowMod.Cookie, aft.flow.Command, of.BwAvailDetails{}, nil)
+ aft.device.triggerFlowNotification(ctx, flow.FlowMod.Cookie, aft.flow.Command, of.BwAvailDetails{}, nil)
} else {
logger.Errorw(ctx, "Update Flow Table Failed: Voltha Client Unavailable", log.Fields{"Flow": flow})
diff --git a/internal/pkg/controller/auditdevice.go b/internal/pkg/controller/auditdevice.go
index 2cabffc..33be2e5 100644
--- a/internal/pkg/controller/auditdevice.go
+++ b/internal/pkg/controller/auditdevice.go
@@ -119,12 +119,12 @@
// This port exists in the received list and the map at
// VGC. This is common so delete it
logger.Infow(ctx, "Port State Mismatch", log.Fields{"Port": vgcPort.ID, "OfpPort": ofpPort.PortNo, "ReceivedState": ofpPort.State, "CurrentState": vgcPort.State})
- ad.device.ProcessPortState(ofpPort.PortNo, ofpPort.State)
+ ad.device.ProcessPortState(ctx, ofpPort.PortNo, ofpPort.State)
} else {
//To ensure the flows are in sync with port status and no mismatch due to reboot,
// repush/delete flows based on current port status
logger.Infow(ctx, "Port State Processing", log.Fields{"Port": vgcPort.ID, "OfpPort": ofpPort.PortNo, "ReceivedState": ofpPort.State, "CurrentState": vgcPort.State})
- ad.device.ProcessPortStateAfterReboot(ofpPort.PortNo, ofpPort.State)
+ ad.device.ProcessPortStateAfterReboot(ctx, ofpPort.PortNo, ofpPort.State)
}
delete(missingPorts, id)
} else {
@@ -158,15 +158,15 @@
logger.Errorw(ctx, "Audit Device Task Cancelled", log.Fields{"Context": ad.ctx, "Task": ad.taskID})
return tasks.ErrTaskCancelError
}
- ad.AddMissingPorts(missingPorts)
- ad.DelExcessPorts(excessPorts)
+ ad.AddMissingPorts(ctx, missingPorts)
+ ad.DelExcessPorts(ctx, excessPorts)
ad.device.deviceAuditInProgress = false
logger.Warnw(ctx, "Audit Device Task Completed", log.Fields{"Context": ctx, "taskId": taskID, "Device": ad.device.ID})
return nil
}
// AddMissingPorts to add the missing ports
-func (ad *AuditDevice) AddMissingPorts(mps map[uint32]*ofp.OfpPort) {
+func (ad *AuditDevice) AddMissingPorts(cntx context.Context, mps map[uint32]*ofp.OfpPort) {
logger.Debugw(ctx, "Device Audit - Add Missing Ports", log.Fields{"NumPorts": len(mps)})
addMissingPort := func(mp *ofp.OfpPort) {
@@ -174,11 +174,11 @@
// Error is ignored as it only drops duplicate ports
logger.Infow(ctx, "Calling AddPort", log.Fields{"No": mp.PortNo, "Name": mp.Name})
- if err := ad.device.AddPort(mp.PortNo, mp.Name); err != nil {
+ if err := ad.device.AddPort(cntx, mp.PortNo, mp.Name); err != nil {
logger.Warnw(ctx, "AddPort Failed", log.Fields{"No": mp.PortNo, "Name": mp.Name, "Reason": err})
}
if mp.State == uint32(ofp.OfpPortState_OFPPS_LIVE) {
- ad.device.ProcessPortState(mp.PortNo, mp.State)
+ ad.device.ProcessPortState(cntx, mp.PortNo, mp.State)
}
logger.Debugw(ctx, "Processed Port Add Ind", log.Fields{"Port No": mp.PortNo, "Port Name": mp.Name})
@@ -198,12 +198,12 @@
}
// DelExcessPorts to delete the excess ports
-func (ad *AuditDevice) DelExcessPorts(eps []uint32) {
+func (ad *AuditDevice) DelExcessPorts(cntx context.Context, eps []uint32) {
logger.Debugw(ctx, "Device Audit - Delete Excess Ports", log.Fields{"NumPorts": len(eps)})
for _, id := range eps {
// Now delete the port from the device @ VGC
logger.Infow(ctx, "Device Audit - Deleting Port", log.Fields{"PortId": id})
- if err := ad.device.DelPort(id); err != nil {
+ if err := ad.device.DelPort(cntx, id); err != nil {
logger.Warnw(ctx, "DelPort Failed", log.Fields{"PortId": id, "Reason": err})
}
}
diff --git a/internal/pkg/controller/audittables.go b/internal/pkg/controller/audittables.go
index 1afad05..079ff2f 100644
--- a/internal/pkg/controller/audittables.go
+++ b/internal/pkg/controller/audittables.go
@@ -97,7 +97,7 @@
}
// Audit the flows
- if err = att.AuditFlows(); err != nil {
+ if err = att.AuditFlows(ctx); err != nil {
logger.Errorw(ctx, "Audit Flows Failed", log.Fields{"Reason": err.Error()})
errInfo = err
}
@@ -211,7 +211,7 @@
// voltha and identifying the delta between the ones held here and the
// ones held at VOLTHA. The delta must be cleaned up to keep both the
// components in sync
-func (att *AuditTablesTask) AuditFlows() error {
+func (att *AuditTablesTask) AuditFlows(cntx context.Context) error {
if att.stop {
return tasks.ErrTaskCancelError
@@ -267,7 +267,7 @@
defaultSuccessFlowStatus.Cookie = strconv.FormatUint(flow.Cookie, 10)
logger.Infow(ctx, "Triggering Internal Flow Notification", log.Fields{"Flow Status": defaultSuccessFlowStatus})
- GetController().ProcessFlowModResultIndication(defaultSuccessFlowStatus)
+ GetController().ProcessFlowModResultIndication(cntx, defaultSuccessFlowStatus)
} else {
// The flow exists at the controller but not at the device
// Push the flow to the device
@@ -280,9 +280,9 @@
if !att.stop {
// The flows remaining in the received flows are the excess flows at
// the device. Delete those flows
- att.DelExcessFlows(rcvdFlows)
+ att.DelExcessFlows(cntx, rcvdFlows)
// Add the flows missing at the device
- att.AddMissingFlows(flowsToAdd)
+ att.AddMissingFlows(cntx, flowsToAdd)
} else {
err = tasks.ErrTaskCancelError
}
@@ -291,7 +291,7 @@
// AddMissingFlows : The flows missing from the device are reinstalled att the audit
// The flows are added into a VoltFlow structure.
-func (att *AuditTablesTask) AddMissingFlows(mflow *of.VoltFlow) {
+func (att *AuditTablesTask) AddMissingFlows(cntx context.Context, mflow *of.VoltFlow) {
logger.Debugw(ctx, "Add Missing Flows", log.Fields{"Number": len(mflow.SubFlows)})
mflow.Command = of.CommandAdd
ofFlows := of.ProcessVoltFlow(att.device.ID, mflow.Command, mflow.SubFlows)
@@ -314,12 +314,12 @@
if _, err = vc.UpdateLogicalDeviceFlowTable(att.ctx, flow); err != nil {
logger.Errorw(ctx, "Update Flow Table Failed", log.Fields{"Reason": err.Error()})
}
- att.device.triggerFlowResultNotification(flow.FlowMod.Cookie, dbFlow, of.CommandAdd, bwConsumedInfo, err)
+ att.device.triggerFlowResultNotification(cntx, flow.FlowMod.Cookie, dbFlow, of.CommandAdd, bwConsumedInfo, err)
}
}
// DelExcessFlows delete the excess flows held at the VOLTHA
-func (att *AuditTablesTask) DelExcessFlows(flows map[uint64]*ofp.OfpFlowStats) {
+func (att *AuditTablesTask) DelExcessFlows(cntx context.Context, flows map[uint64]*ofp.OfpFlowStats) {
logger.Debugw(ctx, "Deleting Excess Flows", log.Fields{"Number of Flows": len(flows)})
var vc voltha.VolthaServiceClient
@@ -362,7 +362,7 @@
if _, err = vc.UpdateLogicalDeviceFlowTable(att.ctx, flowUpdate); err != nil {
logger.Errorw(ctx, "Flow Audit Delete Failed", log.Fields{"Reason": err.Error()})
}
- att.device.triggerFlowResultNotification(flow.Cookie, nil, of.CommandDel, of.BwAvailDetails{}, err)
+ att.device.triggerFlowResultNotification(cntx, flow.Cookie, nil, of.CommandDel, of.BwAvailDetails{}, err)
}
}
diff --git a/internal/pkg/controller/changeevent.go b/internal/pkg/controller/changeevent.go
index 21ed05d..46b1be5 100644
--- a/internal/pkg/controller/changeevent.go
+++ b/internal/pkg/controller/changeevent.go
@@ -74,16 +74,16 @@
state := status.PortStatus.Desc.State
logger.Infow(ctx, "Process Port Change Event", log.Fields{"Port No": portNo, "Port Name": portName, "State": state, "Reason": status.PortStatus.Reason})
if status.PortStatus.Reason == ofp.OfpPortReason_OFPPR_ADD {
- _ = cet.device.AddPort(portNo, portName)
+ _ = cet.device.AddPort(ctx, portNo, portName)
if state == uint32(ofp.OfpPortState_OFPPS_LIVE) {
- cet.device.ProcessPortState(portNo, state)
+ cet.device.ProcessPortState(ctx, portNo, state)
}
} else if status.PortStatus.Reason == ofp.OfpPortReason_OFPPR_DELETE {
- if err := cet.device.DelPort(portNo); err != nil {
+ if err := cet.device.DelPort(ctx, portNo); err != nil {
logger.Warnw(ctx, "DelPort Failed", log.Fields{"Port No": portNo, "Error": err})
}
} else if status.PortStatus.Reason == ofp.OfpPortReason_OFPPR_MODIFY {
- cet.device.ProcessPortUpdate(portName, portNo, state)
+ cet.device.ProcessPortUpdate(ctx, portName, portNo, state)
}
logger.Infow(ctx, "Processed Port Change Event", log.Fields{"Port No": portNo, "Port Name": portName, "State": state, "Reason": status.PortStatus.Reason})
return nil
diff --git a/internal/pkg/controller/controller.go b/internal/pkg/controller/controller.go
index 9abbd42..f08f7e1 100644
--- a/internal/pkg/controller/controller.go
+++ b/internal/pkg/controller/controller.go
@@ -89,16 +89,16 @@
}
// AddDevice to add device
-func (v *VoltController) AddDevice(config *intf.VPClientCfg) intf.IVPClient {
+func (v *VoltController) AddDevice(cntx context.Context, config *intf.VPClientCfg) intf.IVPClient {
- d := NewDevice(config.DeviceID, config.SerialNum, config.VolthaClient, config.SouthBoundID)
+ d := NewDevice(cntx, config.DeviceID, config.SerialNum, config.VolthaClient, config.SouthBoundID)
v.devices[config.DeviceID] = d
- v.app.AddDevice(d.ID, d.SerialNum, config.SouthBoundID)
+ v.app.AddDevice(cntx, d.ID, d.SerialNum, config.SouthBoundID)
- d.RestoreMetersFromDb()
- d.RestoreGroupsFromDb()
- d.RestoreFlowsFromDb()
- d.RestorePortsFromDb()
+ d.RestoreMetersFromDb(cntx)
+ d.RestoreGroupsFromDb(cntx)
+ d.RestoreFlowsFromDb(cntx)
+ d.RestorePortsFromDb(cntx)
d.ConnectInd(context.TODO(), intf.DeviceDisc)
d.packetOutChannel = config.PacketOutChannel
@@ -108,13 +108,13 @@
}
// DelDevice to delete device
-func (v *VoltController) DelDevice(id string) {
+func (v *VoltController) DelDevice(cntx context.Context, id string) {
d, ok := v.devices[id]
if ok {
delete(v.devices, id)
d.Delete()
}
- v.app.DelDevice(id)
+ v.app.DelDevice(cntx, id)
d.cancel() // To stop the device tables sync routine
logger.Warnw(ctx, "Deleted device", log.Fields{"Device": id})
}
@@ -193,27 +193,27 @@
}
// DeviceRebootInd is device reboot indication
-func (v *VoltController) DeviceRebootInd(dID string, srNo string, sbID string) {
- v.app.DeviceRebootInd(dID, srNo, sbID)
- _ = db.DelAllRoutesForDevice(dID)
- _ = db.DelAllGroup(dID)
- _ = db.DelAllMeter(dID)
- _ = db.DelAllPONCounters(dID)
+func (v *VoltController) DeviceRebootInd(cntx context.Context, dID string, srNo string, sbID string) {
+ v.app.DeviceRebootInd(cntx, dID, srNo, sbID)
+ _ = db.DelAllRoutesForDevice(cntx, dID)
+ _ = db.DelAllGroup(cntx, dID)
+ _ = db.DelAllMeter(cntx, dID)
+ _ = db.DelAllPONCounters(cntx, dID)
}
// DeviceDisableInd is device deactivation indication
-func (v *VoltController) DeviceDisableInd(dID string) {
- v.app.DeviceDisableInd(dID)
+func (v *VoltController) DeviceDisableInd(cntx context.Context, dID string) {
+ v.app.DeviceDisableInd(cntx, dID)
}
//TriggerPendingProfileDeleteReq - trigger pending profile delete requests
-func (v *VoltController) TriggerPendingProfileDeleteReq(device string) {
- v.app.TriggerPendingProfileDeleteReq(device)
+func (v *VoltController) TriggerPendingProfileDeleteReq(cntx context.Context, device string) {
+ v.app.TriggerPendingProfileDeleteReq(cntx, device)
}
//TriggerPendingMigrateServicesReq - trigger pending services migration requests
-func (v *VoltController) TriggerPendingMigrateServicesReq(device string) {
- v.app.TriggerPendingMigrateServicesReq(device)
+func (v *VoltController) TriggerPendingMigrateServicesReq(cntx context.Context, device string) {
+ v.app.TriggerPendingMigrateServicesReq(cntx, device)
}
// SetAuditFlags to set the audit flags
@@ -229,8 +229,8 @@
}
//ProcessFlowModResultIndication - send flow mod result notification
-func (v *VoltController) ProcessFlowModResultIndication(flowStatus intf.FlowStatus) {
- v.app.ProcessFlowModResultIndication(flowStatus)
+func (v *VoltController) ProcessFlowModResultIndication(cntx context.Context, flowStatus intf.FlowStatus) {
+ v.app.ProcessFlowModResultIndication(cntx, flowStatus)
}
// AddVPAgent to add the vpagent
@@ -259,7 +259,7 @@
}
// AddFlows to add flows
-func (v *VoltController) AddFlows(port string, device string, flow *of.VoltFlow) error {
+func (v *VoltController) AddFlows(cntx context.Context, port string, device string, flow *of.VoltFlow) error {
d, err := v.GetDevice(device)
if err != nil {
logger.Errorw(ctx, "Device Not Found", log.Fields{"Device": device})
@@ -292,10 +292,10 @@
// Actual flow deletion and addition at voltha will happen during flow tables audit.
for _, subFlow := range flow.SubFlows {
logger.Debugw(ctx, "Cookie Migration Required", log.Fields{"OldCookie": subFlow.OldCookie, "NewCookie": subFlow.Cookie})
- if err := d.DelFlowWithOldCookie(subFlow); err != nil {
+ if err := d.DelFlowWithOldCookie(cntx, subFlow); err != nil {
logger.Errorw(ctx, "Delete flow with old cookie failed", log.Fields{"Error": err, "OldCookie": subFlow.OldCookie})
}
- if err := d.AddFlow(subFlow); err != nil {
+ if err := d.AddFlow(cntx, subFlow); err != nil {
logger.Errorw(ctx, "Flow Add Failed", log.Fields{"Error": err, "Cookie": subFlow.Cookie})
}
}
@@ -310,7 +310,7 @@
}
// DelFlows to delete flows
-func (v *VoltController) DelFlows(port string, device string, flow *of.VoltFlow) error {
+func (v *VoltController) DelFlows(cntx context.Context, port string, device string, flow *of.VoltFlow) error {
d, err := v.GetDevice(device)
if err != nil {
logger.Errorw(ctx, "Device Not Found", log.Fields{"Device": device})
@@ -343,7 +343,7 @@
// Actual flow deletion at voltha will happen during flow tables audit.
for _, subFlow := range flow.SubFlows {
logger.Debugw(ctx, "Old Cookie delete Required", log.Fields{"OldCookie": subFlow.OldCookie})
- if err := d.DelFlowWithOldCookie(subFlow); err != nil {
+ if err := d.DelFlowWithOldCookie(cntx, subFlow); err != nil {
logger.Errorw(ctx, "DelFlowWithOldCookie failed", log.Fields{"OldCookie": subFlow.OldCookie, "Error": err})
}
}
@@ -400,13 +400,13 @@
}
// PortAddInd for port add indication
-func (v *VoltController) PortAddInd(device string, id uint32, name string) {
- v.app.PortAddInd(device, id, name)
+func (v *VoltController) PortAddInd(cntx context.Context, device string, id uint32, name string) {
+ v.app.PortAddInd(cntx, device, id, name)
}
// PortDelInd for port delete indication
-func (v *VoltController) PortDelInd(device string, port string) {
- v.app.PortDelInd(device, port)
+func (v *VoltController) PortDelInd(cntx context.Context, device string, port string) {
+ v.app.PortDelInd(cntx, device, port)
}
// PortUpdateInd for port update indication
@@ -415,13 +415,13 @@
}
// PortUpInd for port up indication
-func (v *VoltController) PortUpInd(device string, port string) {
- v.app.PortUpInd(device, port)
+func (v *VoltController) PortUpInd(cntx context.Context, device string, port string) {
+ v.app.PortUpInd(cntx, device, port)
}
// PortDownInd for port down indication
-func (v *VoltController) PortDownInd(device string, port string) {
- v.app.PortDownInd(device, port)
+func (v *VoltController) PortDownInd(cntx context.Context, device string, port string) {
+ v.app.PortDownInd(cntx, device, port)
}
// DeviceUpInd for device up indication
@@ -435,8 +435,8 @@
}
// PacketInInd for packet in indication
-func (v *VoltController) PacketInInd(device string, port string, data []byte) {
- v.app.PacketInInd(device, port, data)
+func (v *VoltController) PacketInInd(cntx context.Context, device string, port string, data []byte) {
+ v.app.PacketInInd(cntx, device, port, data)
}
// GetPortState to get port status
@@ -450,8 +450,8 @@
}
// UpdateMvlanProfiles for update mvlan profiles
-func (v *VoltController) UpdateMvlanProfiles(device string) {
- v.app.UpdateMvlanProfilesForDevice(device)
+func (v *VoltController) UpdateMvlanProfiles(cntx context.Context, device string) {
+ v.app.UpdateMvlanProfilesForDevice(cntx, device)
}
// GetController to get controller
diff --git a/internal/pkg/controller/controllertasks.go b/internal/pkg/controller/controllertasks.go
index 50a51ee..586999c 100644
--- a/internal/pkg/controller/controllertasks.go
+++ b/internal/pkg/controller/controllertasks.go
@@ -68,7 +68,7 @@
logger.Infow(ctx, "Add Device Task Triggered", log.Fields{"Device": adt.config.DeviceID, "SerialNum": adt.config.SerialNum})
- device := GetController().AddDevice(adt.config)
+ device := GetController().AddDevice(ctx, adt.config)
vpagent.GetVPAgent().AddClientToClientMap(adt.config.DeviceID, device)
logger.Infow(ctx, "Add Device Task Completed", log.Fields{"Device": adt.config.DeviceID, "SerialNum": adt.config.SerialNum})
diff --git a/internal/pkg/controller/device.go b/internal/pkg/controller/device.go
index cea6960..b410490 100644
--- a/internal/pkg/controller/device.go
+++ b/internal/pkg/controller/device.go
@@ -130,7 +130,7 @@
}
// NewDevice is the constructor for Device
-func NewDevice(id string, slno string, vclientHldr *holder.VolthaServiceClientHolder, southBoundID string) *Device {
+func NewDevice(cntx context.Context, id string, slno string, vclientHldr *holder.VolthaServiceClientHolder, southBoundID string) *Device {
var device Device
device.ID = id
device.SerialNum = slno
@@ -143,7 +143,7 @@
device.flowQueue = make(map[uint32]*UniIDFlowQueue)
//Get the flowhash from db and update the flowhash variable in the device.
device.SouthBoundID = southBoundID
- flowHash, err := db.GetFlowHash(id)
+ flowHash, err := db.GetFlowHash(cntx, id)
if err != nil {
device.flowHash = DefaultMaxFlowQueues
} else {
@@ -177,7 +177,7 @@
}
// AddFlow - Adds the flow to the device and also to the database
-func (d *Device) AddFlow(flow *of.VoltSubFlow) error {
+func (d *Device) AddFlow(cntx context.Context, flow *of.VoltSubFlow) error {
d.flowLock.Lock()
defer d.flowLock.Unlock()
logger.Infow(ctx, "AddFlow to device", log.Fields{"Cookie": flow.Cookie})
@@ -185,34 +185,34 @@
return errors.New(ErrDuplicateFlow)
}
d.flows[flow.Cookie] = flow
- d.AddFlowToDb(flow)
+ d.AddFlowToDb(cntx, flow)
return nil
}
// AddFlowToDb is the utility to add the flow to the device
-func (d *Device) AddFlowToDb(flow *of.VoltSubFlow) {
+func (d *Device) AddFlowToDb(cntx context.Context, flow *of.VoltSubFlow) {
if b, err := json.Marshal(flow); err == nil {
- if err = db.PutFlow(d.ID, flow.Cookie, string(b)); err != nil {
+ if err = db.PutFlow(cntx, d.ID, flow.Cookie, string(b)); err != nil {
logger.Errorw(ctx, "Write Flow to DB failed", log.Fields{"device": d.ID, "cookie": flow.Cookie, "Reason": err})
}
}
}
// DelFlow - Deletes the flow from the device and the database
-func (d *Device) DelFlow(flow *of.VoltSubFlow) error {
+func (d *Device) DelFlow(cntx context.Context, flow *of.VoltSubFlow) error {
d.flowLock.Lock()
defer d.flowLock.Unlock()
if _, ok := d.flows[flow.Cookie]; ok {
delete(d.flows, flow.Cookie)
- d.DelFlowFromDb(flow.Cookie)
+ d.DelFlowFromDb(cntx, flow.Cookie)
return nil
}
return errors.New("Flow does not Exist")
}
// DelFlowFromDb is utility to delete the flow from the device
-func (d *Device) DelFlowFromDb(flowID uint64) {
- _ = db.DelFlow(d.ID, flowID)
+func (d *Device) DelFlowFromDb(cntx context.Context, flowID uint64) {
+ _ = db.DelFlow(cntx, d.ID, flowID)
}
// IsFlowPresentWithOldCookie is to check whether there is any flow with old cookie.
@@ -231,22 +231,22 @@
}
// DelFlowWithOldCookie is to delete flow with old cookie.
-func (d *Device) DelFlowWithOldCookie(flow *of.VoltSubFlow) error {
+func (d *Device) DelFlowWithOldCookie(cntx context.Context, flow *of.VoltSubFlow) error {
d.flowLock.Lock()
defer d.flowLock.Unlock()
if _, ok := d.flows[flow.OldCookie]; ok {
logger.Infow(ctx, "Flow was added before vgc upgrade. Trying to delete with old cookie",
log.Fields{"OldCookie": flow.OldCookie})
delete(d.flows, flow.OldCookie)
- d.DelFlowFromDb(flow.OldCookie)
+ d.DelFlowFromDb(cntx, flow.OldCookie)
return nil
}
return errors.New("Flow does not Exist")
}
// RestoreFlowsFromDb to restore flows from database
-func (d *Device) RestoreFlowsFromDb() {
- flows, _ := db.GetFlows(d.ID)
+func (d *Device) RestoreFlowsFromDb(cntx context.Context) {
+ flows, _ := db.GetFlows(cntx, d.ID)
for _, flow := range flows {
b, ok := flow.Value.([]byte)
if !ok {
@@ -277,41 +277,41 @@
// Group operations at the device which include update and delete
// UpdateGroupEntry - Adds/Updates the group to the device and also to the database
-func (d *Device) UpdateGroupEntry(group *of.Group) {
+func (d *Device) UpdateGroupEntry(cntx context.Context, group *of.Group) {
logger.Infow(ctx, "Update Group to device", log.Fields{"ID": group.GroupID})
d.groups.Store(group.GroupID, group)
- d.AddGroupToDb(group)
+ d.AddGroupToDb(cntx, group)
}
// AddGroupToDb - Utility to add the group to the device DB
-func (d *Device) AddGroupToDb(group *of.Group) {
+func (d *Device) AddGroupToDb(cntx context.Context, group *of.Group) {
if b, err := json.Marshal(group); err == nil {
logger.Infow(ctx, "Adding Group to DB", log.Fields{"grp": group, "Json": string(b)})
- if err = db.PutGroup(d.ID, group.GroupID, string(b)); err != nil {
+ if err = db.PutGroup(cntx, d.ID, group.GroupID, string(b)); err != nil {
logger.Errorw(ctx, "Write Group to DB failed", log.Fields{"device": d.ID, "groupID": group.GroupID, "Reason": err})
}
}
}
// DelGroupEntry - Deletes the group from the device and the database
-func (d *Device) DelGroupEntry(group *of.Group) {
+func (d *Device) DelGroupEntry(cntx context.Context, group *of.Group) {
if _, ok := d.groups.Load(group.GroupID); ok {
d.groups.Delete(group.GroupID)
- d.DelGroupFromDb(group.GroupID)
+ d.DelGroupFromDb(cntx, group.GroupID)
}
}
// DelGroupFromDb - Utility to delete the Group from the device
-func (d *Device) DelGroupFromDb(groupID uint32) {
- _ = db.DelGroup(d.ID, groupID)
+func (d *Device) DelGroupFromDb(cntx context.Context, groupID uint32) {
+ _ = db.DelGroup(cntx, d.ID, groupID)
}
//RestoreGroupsFromDb - restores all groups from DB
-func (d *Device) RestoreGroupsFromDb() {
+func (d *Device) RestoreGroupsFromDb(cntx context.Context) {
logger.Info(ctx, "Restoring Groups")
- groups, _ := db.GetGroups(d.ID)
+ groups, _ := db.GetGroups(cntx, d.ID)
for _, group := range groups {
b, ok := group.Value.([]byte)
if !ok {
@@ -338,14 +338,14 @@
}
// AddMeter to add meter
-func (d *Device) AddMeter(meter *of.Meter) error {
+func (d *Device) AddMeter(cntx context.Context, meter *of.Meter) error {
d.meterLock.Lock()
defer d.meterLock.Unlock()
if _, ok := d.meters[meter.ID]; ok {
return errors.New("Duplicate Meter")
}
d.meters[meter.ID] = meter
- go d.AddMeterToDb(meter)
+ go d.AddMeterToDb(cntx, meter)
return nil
}
@@ -360,34 +360,34 @@
}
// DelMeter to delete meter
-func (d *Device) DelMeter(meter *of.Meter) bool {
+func (d *Device) DelMeter(cntx context.Context, meter *of.Meter) bool {
d.meterLock.Lock()
defer d.meterLock.Unlock()
if _, ok := d.meters[meter.ID]; ok {
delete(d.meters, meter.ID)
- go d.DelMeterFromDb(meter.ID)
+ go d.DelMeterFromDb(cntx, meter.ID)
return true
}
return false
}
// AddMeterToDb is utility to add the Group to the device
-func (d *Device) AddMeterToDb(meter *of.Meter) {
+func (d *Device) AddMeterToDb(cntx context.Context, meter *of.Meter) {
if b, err := json.Marshal(meter); err == nil {
- if err = db.PutDeviceMeter(d.ID, meter.ID, string(b)); err != nil {
+ if err = db.PutDeviceMeter(cntx, d.ID, meter.ID, string(b)); err != nil {
logger.Errorw(ctx, "Write Meter to DB failed", log.Fields{"device": d.ID, "meterID": meter.ID, "Reason": err})
}
}
}
// DelMeterFromDb to delete meter from db
-func (d *Device) DelMeterFromDb(id uint32) {
- _ = db.DelDeviceMeter(d.ID, id)
+func (d *Device) DelMeterFromDb(cntx context.Context, id uint32) {
+ _ = db.DelDeviceMeter(cntx, d.ID, id)
}
// RestoreMetersFromDb to restore meters from db
-func (d *Device) RestoreMetersFromDb() {
- meters, _ := db.GetDeviceMeters(d.ID)
+func (d *Device) RestoreMetersFromDb(cntx context.Context) {
+ meters, _ := db.GetDeviceMeters(cntx, d.ID)
for _, meter := range meters {
b, ok := meter.Value.([]byte)
if !ok {
@@ -420,7 +420,7 @@
// AddPort to add the port as requested by the device/VOLTHA
// Inform the application if the port is successfully added
-func (d *Device) AddPort(id uint32, name string) error {
+func (d *Device) AddPort(cntx context.Context, id uint32, name string) error {
d.portLock.Lock()
defer d.portLock.Unlock()
@@ -434,36 +434,36 @@
p := NewDevicePort(id, name)
d.PortsByID[id] = p
d.PortsByName[name] = p
- d.WritePortToDb(p)
- GetController().PortAddInd(d.ID, p.ID, p.Name)
+ d.WritePortToDb(cntx, p)
+ GetController().PortAddInd(cntx, d.ID, p.ID, p.Name)
logger.Infow(ctx, "Added Port", log.Fields{"Device": d.ID, "Port": id})
return nil
}
// DelPort to delete the port as requested by the device/VOLTHA
// Inform the application if the port is successfully deleted
-func (d *Device) DelPort(id uint32) error {
+func (d *Device) DelPort(cntx context.Context, id uint32) error {
p := d.GetPortByID(id)
if p == nil {
return errors.New("Unknown Port")
}
if p.State == PortStateUp {
- GetController().PortDownInd(d.ID, p.Name)
+ GetController().PortDownInd(cntx, d.ID, p.Name)
}
d.portLock.Lock()
defer d.portLock.Unlock()
- GetController().PortDelInd(d.ID, p.Name)
+ GetController().PortDelInd(cntx, d.ID, p.Name)
delete(d.PortsByID, p.ID)
delete(d.PortsByName, p.Name)
- d.DelPortFromDb(p.ID)
+ d.DelPortFromDb(cntx, p.ID)
logger.Infow(ctx, "Deleted Port", log.Fields{"Device": d.ID, "Port": id})
return nil
}
// UpdatePortByName is utility to update the port by Name
-func (d *Device) UpdatePortByName(name string, port uint32) {
+func (d *Device) UpdatePortByName(cntx context.Context, name string, port uint32) {
d.portLock.Lock()
defer d.portLock.Unlock()
@@ -474,7 +474,7 @@
delete(d.PortsByID, p.ID)
p.ID = port
d.PortsByID[port] = p
- d.WritePortToDb(p)
+ d.WritePortToDb(cntx, p)
GetController().PortUpdateInd(d.ID, p.Name, p.ID)
logger.Infow(ctx, "Updated Port", log.Fields{"Device": d.ID, "Port": p.ID, "PortName": name})
}
@@ -539,42 +539,42 @@
}
// WritePortToDb to add the port to the database
-func (d *Device) WritePortToDb(port *DevicePort) {
+func (d *Device) WritePortToDb(ctx context.Context, port *DevicePort) {
port.Version = database.PresentVersionMap[database.DevicePortPath]
if b, err := json.Marshal(port); err == nil {
- if err = db.PutPort(d.ID, port.ID, string(b)); err != nil {
+ if err = db.PutPort(ctx, d.ID, port.ID, string(b)); err != nil {
logger.Errorw(ctx, "Write port to DB failed", log.Fields{"device": d.ID, "port": port.ID, "Reason": err})
}
}
}
// DelPortFromDb to delete port from database
-func (d *Device) DelPortFromDb(id uint32) {
- _ = db.DelPort(d.ID, id)
+func (d *Device) DelPortFromDb(cntx context.Context, id uint32) {
+ _ = db.DelPort(cntx, d.ID, id)
}
// RestorePortsFromDb to restore ports from database
-func (d *Device) RestorePortsFromDb() {
- ports, _ := db.GetPorts(d.ID)
+func (d *Device) RestorePortsFromDb(cntx context.Context) {
+ ports, _ := db.GetPorts(cntx, d.ID)
for _, port := range ports {
b, ok := port.Value.([]byte)
if !ok {
logger.Warn(ctx, "The value type is not []byte")
continue
}
- d.CreatePortFromString(b)
+ d.CreatePortFromString(cntx, b)
}
}
// CreatePortFromString to create port from string
-func (d *Device) CreatePortFromString(b []byte) {
+func (d *Device) CreatePortFromString(cntx context.Context, b []byte) {
var port DevicePort
if err := json.Unmarshal(b, &port); err == nil {
if _, ok := d.PortsByID[port.ID]; !ok {
logger.Debugw(ctx, "Adding Port From Db", log.Fields{"ID": port.ID})
d.PortsByID[port.ID] = &port
d.PortsByName[port.Name] = &port
- GetController().PortAddInd(d.ID, port.ID, port.Name)
+ GetController().PortAddInd(cntx, d.ID, port.ID, port.Name)
} else {
logger.Warnw(ctx, "Duplicate Port", log.Fields{"ID": port.ID})
}
@@ -662,7 +662,7 @@
}
// DeviceRebootInd is called when the logical device is rebooted.
-func (d *Device) DeviceRebootInd() {
+func (d *Device) DeviceRebootInd(cntx context.Context) {
logger.Warnw(ctx, "Device State change Ind: Rebooted", log.Fields{"Device": d.ID})
if d.State == DeviceStateREBOOTED {
@@ -673,19 +673,19 @@
d.State = DeviceStateREBOOTED
GetController().SetRebootInProgressForDevice(d.ID)
- GetController().DeviceRebootInd(d.ID, d.SerialNum, d.SouthBoundID)
- d.ReSetAllPortStates()
+ GetController().DeviceRebootInd(cntx, d.ID, d.SerialNum, d.SouthBoundID)
+ d.ReSetAllPortStates(cntx)
}
// DeviceDisabledInd is called when the logical device is disabled
-func (d *Device) DeviceDisabledInd() {
+func (d *Device) DeviceDisabledInd(cntx context.Context) {
logger.Warnw(ctx, "Device State change Ind: Disabled", log.Fields{"Device": d.ID})
d.State = DeviceStateDISABLED
- GetController().DeviceDisableInd(d.ID)
+ GetController().DeviceDisableInd(cntx, d.ID)
}
//ReSetAllPortStates - Set all logical device port status to DOWN
-func (d *Device) ReSetAllPortStates() {
+func (d *Device) ReSetAllPortStates(cntx context.Context) {
logger.Warnw(ctx, "Resetting all Ports State to DOWN", log.Fields{"Device": d.ID, "State": d.State})
d.portLock.Lock()
@@ -694,15 +694,15 @@
for _, port := range d.PortsByID {
if port.State != PortStateDown {
logger.Infow(ctx, "Resetting Port State to DOWN", log.Fields{"Device": d.ID, "Port": port})
- GetController().PortDownInd(d.ID, port.Name)
+ GetController().PortDownInd(cntx, d.ID, port.Name)
port.State = PortStateDown
- d.WritePortToDb(port)
+ d.WritePortToDb(cntx, port)
}
}
}
//ReSetAllPortStatesInDb - Set all logical device port status to DOWN in DB and skip indication to application
-func (d *Device) ReSetAllPortStatesInDb() {
+func (d *Device) ReSetAllPortStatesInDb(cntx context.Context) {
logger.Warnw(ctx, "Resetting all Ports State to DOWN In DB", log.Fields{"Device": d.ID, "State": d.State})
d.portLock.Lock()
@@ -712,14 +712,14 @@
if port.State != PortStateDown {
logger.Infow(ctx, "Resetting Port State to DOWN and Write to DB", log.Fields{"Device": d.ID, "Port": port})
port.State = PortStateDown
- d.WritePortToDb(port)
+ d.WritePortToDb(cntx, port)
}
}
}
// ProcessPortUpdate deals with the change in port id (ONU movement) and taking action
// to update only when the port state is DOWN
-func (d *Device) ProcessPortUpdate(portName string, port uint32, state uint32) {
+func (d *Device) ProcessPortUpdate(cntx context.Context, portName string, port uint32, state uint32) {
if p := d.GetPortByName(portName); p != nil {
if p.ID != port {
logger.Infow(ctx, "Port ID update indication", log.Fields{"Port": p.Name, "Old PortID": p.ID, "New Port ID": port})
@@ -727,10 +727,10 @@
logger.Errorw(ctx, "Port ID update failed. Port State UP", log.Fields{"Port": p})
return
}
- d.UpdatePortByName(portName, port)
+ d.UpdatePortByName(cntx, portName, port)
logger.Errorw(ctx, "Port ID Updated", log.Fields{"Port": p})
}
- d.ProcessPortState(port, state)
+ d.ProcessPortState(cntx, port, state)
}
}
@@ -750,7 +750,7 @@
// ProcessPortState deals with the change in port status and taking action
// based on the new state and the old state
-func (d *Device) ProcessPortState(port uint32, state uint32) {
+func (d *Device) ProcessPortState(cntx context.Context, port uint32, state uint32) {
if d.State != DeviceStateUP && !util.IsNniPort(port) {
logger.Warnw(ctx, "Ignore Port State Processing - Device not UP", log.Fields{"Device": d.ID, "Port": port, "DeviceState": d.State})
return
@@ -765,15 +765,15 @@
if state == uint32(ofp.OfpPortState_OFPPS_LIVE) && p.State == PortStateDown {
// Transition from DOWN to UP
logger.Infow(ctx, "Port State Change to UP", log.Fields{"Device": d.ID, "Port": port})
- GetController().PortUpInd(d.ID, p.Name)
+ GetController().PortUpInd(cntx, d.ID, p.Name)
p.State = PortStateUp
- d.WritePortToDb(p)
+ d.WritePortToDb(cntx, p)
} else if (state != uint32(ofp.OfpPortState_OFPPS_LIVE)) && (p.State != PortStateDown) {
// Transition from UP to Down
logger.Infow(ctx, "Port State Change to Down", log.Fields{"Device": d.ID, "Port": port})
- GetController().PortDownInd(d.ID, p.Name)
+ GetController().PortDownInd(cntx, d.ID, p.Name)
p.State = PortStateDown
- d.WritePortToDb(p)
+ d.WritePortToDb(cntx, p)
} else {
logger.Warnw(ctx, "Dropping Port Ind: No Change in Port State", log.Fields{"PortName": p.Name, "ID": port, "Device": d.ID, "PortState": p.State, "IncomingState": state})
}
@@ -781,7 +781,7 @@
}
// ProcessPortStateAfterReboot - triggers the port state indication to sort out configu mismatch due to reboot
-func (d *Device) ProcessPortStateAfterReboot(port uint32, state uint32) {
+func (d *Device) ProcessPortStateAfterReboot(cntx context.Context, port uint32, state uint32) {
if d.State != DeviceStateUP && !util.IsNniPort(port) {
logger.Warnw(ctx, "Ignore Port State Processing - Device not UP", log.Fields{"Device": d.ID, "Port": port, "DeviceState": d.State})
return
@@ -791,10 +791,10 @@
p.Tasks.Initialize(d.ctx)
if p.State == PortStateUp {
logger.Infow(ctx, "Port State: UP", log.Fields{"Device": d.ID, "Port": port})
- GetController().PortUpInd(d.ID, p.Name)
+ GetController().PortUpInd(cntx, d.ID, p.Name)
} else if p.State == PortStateDown {
logger.Infow(ctx, "Port State: Down", log.Fields{"Device": d.ID, "Port": port})
- GetController().PortDownInd(d.ID, p.Name)
+ GetController().PortDownInd(cntx, d.ID, p.Name)
}
}
}
@@ -810,7 +810,7 @@
// PacketIn handle the incoming packet-in and deliver to the application for the
// actual processing
-func (d *Device) PacketIn(pkt *ofp.PacketIn) {
+func (d *Device) PacketIn(cntx context.Context, pkt *ofp.PacketIn) {
logger.Debugw(ctx, "Received a Packet-In", log.Fields{"Device": d.ID})
if pkt.PacketIn.Reason != ofp.OfpPacketInReason_OFPR_ACTION {
logger.Warnw(ctx, "Unsupported PacketIn Reason", log.Fields{"Reason": pkt.PacketIn.Reason})
@@ -819,7 +819,7 @@
data := pkt.PacketIn.Data
port := PacketInGetPort(pkt.PacketIn)
if pName, err := d.GetPortName(port); err == nil {
- GetController().PacketInInd(d.ID, pName, data)
+ GetController().PacketInInd(cntx, d.ID, pName, data)
} else {
logger.Warnw(ctx, "Unknown Port", log.Fields{"Reason": err.Error()})
}
@@ -954,21 +954,21 @@
}
// SetFlowHash sets the device flow hash and writes to the DB.
-func (d *Device) SetFlowHash(hash uint32) {
+func (d *Device) SetFlowHash(cntx context.Context, hash uint32) {
d.flowQueueLock.Lock()
defer d.flowQueueLock.Unlock()
d.flowHash = hash
- d.writeFlowHashToDB()
+ d.writeFlowHashToDB(cntx)
}
-func (d *Device) writeFlowHashToDB() {
+func (d *Device) writeFlowHashToDB(cntx context.Context) {
hash, err := json.Marshal(d.flowHash)
if err != nil {
logger.Errorw(ctx, "failed to marshal flow hash", log.Fields{"hash": d.flowHash})
return
}
- if err := db.PutFlowHash(d.ID, string(hash)); err != nil {
+ if err := db.PutFlowHash(cntx, d.ID, string(hash)); err != nil {
logger.Errorw(ctx, "Failed to add flow hash to DB", log.Fields{"device": d.ID, "hash": d.flowHash})
}
}
@@ -987,12 +987,12 @@
return false
}
-func (d *Device) triggerFlowNotification(cookie uint64, oper of.Command, bwDetails of.BwAvailDetails, err error) {
+func (d *Device) triggerFlowNotification(cntx context.Context, cookie uint64, oper of.Command, bwDetails of.BwAvailDetails, err error) {
flow, _ := d.GetFlow(cookie)
- d.triggerFlowResultNotification(cookie, flow, oper, bwDetails, err)
+ d.triggerFlowResultNotification(cntx, cookie, flow, oper, bwDetails, err)
}
-func (d *Device) triggerFlowResultNotification(cookie uint64, flow *of.VoltSubFlow, oper of.Command, bwDetails of.BwAvailDetails, err error) {
+func (d *Device) triggerFlowResultNotification(cntx context.Context, cookie uint64, flow *of.VoltSubFlow, oper of.Command, bwDetails of.BwAvailDetails, err error) {
statusCode, statusMsg := infraerror.GetErrorInfo(err)
success := isFlowOperSuccess(statusCode, oper)
@@ -1001,7 +1001,7 @@
if dbFlow, ok := d.GetFlow(cookie); ok {
dbFlow.State = uint8(state)
dbFlow.ErrorReason = reason
- d.AddFlowToDb(dbFlow)
+ d.AddFlowToDb(cntx, dbFlow)
}
}
@@ -1019,7 +1019,7 @@
logger.Debugw(ctx, "Updated Flow to DB", log.Fields{"Cookie": cookie, "State": state})
} else {
if success && flow != nil {
- if err := d.DelFlow(flow); err != nil {
+ if err := d.DelFlow(cntx, flow); err != nil {
logger.Warnw(ctx, "Delete Flow Error", log.Fields{"Cookie": flow.Cookie, "Reason": err.Error()})
}
} else if !success {
@@ -1038,5 +1038,5 @@
}
logger.Infow(ctx, "Sending Flow Notification", log.Fields{"Cookie": cookie, "Error Code": statusCode, "FlowOp": oper})
- GetController().ProcessFlowModResultIndication(flowResult)
+ GetController().ProcessFlowModResultIndication(cntx, flowResult)
}
diff --git a/internal/pkg/controller/modgroup.go b/internal/pkg/controller/modgroup.go
index e51a347..065c161 100644
--- a/internal/pkg/controller/modgroup.go
+++ b/internal/pkg/controller/modgroup.go
@@ -95,9 +95,9 @@
if grp.group.Command != of.GroupCommandDel {
grp.group.State = of.GroupOperPending
- grp.device.UpdateGroupEntry(grp.group)
+ grp.device.UpdateGroupEntry(ctx, grp.group)
} else {
- grp.device.DelGroupEntry(grp.group)
+ grp.device.DelGroupEntry(ctx, grp.group)
}
if !grp.device.isSBOperAllowed(grp.group.ForceAction) {
diff --git a/internal/pkg/controller/modmeter.go b/internal/pkg/controller/modmeter.go
index b5ce86c..62d2f40 100644
--- a/internal/pkg/controller/modmeter.go
+++ b/internal/pkg/controller/modmeter.go
@@ -89,12 +89,12 @@
// First add/delete the flows first locally before passing them to actual device
if mmt.command == of.MeterCommandAdd {
mmt.meter.State = of.MeterOperPending
- if err := mmt.device.AddMeter(mmt.meter); err != nil {
+ if err := mmt.device.AddMeter(ctx, mmt.meter); err != nil {
// Meter already exists so we dont have to do anything here
return nil
}
} else {
- if !mmt.device.DelMeter(mmt.meter) {
+ if !mmt.device.DelMeter(ctx, mmt.meter) {
// Meter doesn't exist so we dont have to do anything here
return nil
}
diff --git a/internal/pkg/controller/pendingprofiles.go b/internal/pkg/controller/pendingprofiles.go
index a97cdfa..97bb238 100644
--- a/internal/pkg/controller/pendingprofiles.go
+++ b/internal/pkg/controller/pendingprofiles.go
@@ -69,19 +69,19 @@
//Trigger Pending Service Delete Tasks
logger.Warnw(ctx, "Pending Service Delete Task Triggered", log.Fields{"Device": ppt.device.ID})
- GetController().TriggerPendingProfileDeleteReq(ppt.device.ID)
+ GetController().TriggerPendingProfileDeleteReq(ctx, ppt.device.ID)
logger.Warnw(ctx, "Pending Service Delete Task Completed", log.Fields{"Device": ppt.device.ID})
//Trigger Pending Migrate Services Tasks
logger.Warnw(ctx, "Pending Migrate Services Task Triggered", log.Fields{"Device": ppt.device.ID})
- GetController().TriggerPendingMigrateServicesReq(ppt.device.ID)
+ GetController().TriggerPendingMigrateServicesReq(ctx, ppt.device.ID)
logger.Warnw(ctx, "Pending Migrate Services Task Completed", log.Fields{"Device": ppt.device.ID})
GetController().ResetAuditFlags(ppt.device)
// Updating Mvlan Profile
logger.Warnw(ctx, "Pending Update Mvlan Task Triggered", log.Fields{"Device": ppt.device.ID})
- if err := ppt.UpdateMvlanProfiles(); err != nil {
+ if err := ppt.UpdateMvlanProfiles(ctx); err != nil {
logger.Errorw(ctx, "Update Mvlan Profile Failed", log.Fields{"Reason": err.Error()})
errInfo = err
}
@@ -92,7 +92,7 @@
}
// UpdateMvlanProfiles to update the mvlan profiles
-func (ppt *PendingProfilesTask) UpdateMvlanProfiles() error {
- GetController().UpdateMvlanProfiles(ppt.device.ID)
+func (ppt *PendingProfilesTask) UpdateMvlanProfiles(cntx context.Context) error {
+ GetController().UpdateMvlanProfiles(cntx, ppt.device.ID)
return nil
}
diff --git a/internal/pkg/intf/appif.go b/internal/pkg/intf/appif.go
index 76ea4d4..8ad364e 100644
--- a/internal/pkg/intf/appif.go
+++ b/internal/pkg/intf/appif.go
@@ -15,23 +15,25 @@
package intf
+import "context"
+
// App Interface
type App interface {
- PortAddInd(string, uint32, string)
- PortDelInd(string, string)
+ PortAddInd(context.Context, string, uint32, string)
+ PortDelInd(context.Context, string, string)
PortUpdateInd(string, string, uint32)
- PacketInInd(string, string, []byte)
- PortUpInd(string, string)
- PortDownInd(string, string)
- AddDevice(string, string, string)
+ PacketInInd(context.Context, string, string, []byte)
+ PortUpInd(context.Context, string, string)
+ PortDownInd(context.Context, string, string)
+ AddDevice(context.Context, string, string, string)
DeviceUpInd(string)
DeviceDownInd(string)
- DelDevice(string)
+ DelDevice(context.Context, string)
SetRebootFlag(bool)
- ProcessFlowModResultIndication(FlowStatus)
- DeviceRebootInd(string, string, string)
- DeviceDisableInd(string)
- UpdateMvlanProfilesForDevice(string)
- TriggerPendingProfileDeleteReq(string)
- TriggerPendingMigrateServicesReq(string)
+ ProcessFlowModResultIndication(context.Context, FlowStatus)
+ DeviceRebootInd(context.Context, string, string, string)
+ DeviceDisableInd(context.Context, string)
+ UpdateMvlanProfilesForDevice(context.Context, string)
+ TriggerPendingProfileDeleteReq(context.Context, string)
+ TriggerPendingMigrateServicesReq(context.Context, string)
}
diff --git a/internal/pkg/intf/vpagent.go b/internal/pkg/intf/vpagent.go
index f255d13..094c58b 100644
--- a/internal/pkg/intf/vpagent.go
+++ b/internal/pkg/intf/vpagent.go
@@ -45,7 +45,7 @@
// IVPClient interface
type IVPClient interface {
ChangeEvent(*ofp.ChangeEvent) error
- PacketIn(*ofp.PacketIn)
+ PacketIn(context.Context, *ofp.PacketIn)
ConnectInd(cxt context.Context, DiscType DiscoveryType)
Stop()
}
@@ -59,7 +59,7 @@
// IVPClientAgent interface
type IVPClientAgent interface {
AddNewDevice(cfg *VPClientCfg)
- DelDevice(id string)
+ DelDevice(cntx context.Context, id string)
IsRebootInProgressForDevice(device string) bool
// RebootInd(string, string, string)
IsBlockedDevice(string) bool
diff --git a/internal/pkg/vpagent/packetIn.go b/internal/pkg/vpagent/packetIn.go
index 81f6ff2..33a63b4 100644
--- a/internal/pkg/vpagent/packetIn.go
+++ b/internal/pkg/vpagent/packetIn.go
@@ -88,7 +88,7 @@
break top
case packet := <-vpa.packetInChannel:
if vpc := vpa.getVPClient(packet.Id); vpc != nil {
- vpc.PacketIn(packet)
+ vpc.PacketIn(ctx, packet)
}
}
}
diff --git a/internal/pkg/vpagent/refresh.go b/internal/pkg/vpagent/refresh.go
index 83792d0..2761408 100644
--- a/internal/pkg/vpagent/refresh.go
+++ b/internal/pkg/vpagent/refresh.go
@@ -33,7 +33,7 @@
}
// Refresh once to get everything started
- vpa.refreshDeviceList()
+ vpa.refreshDeviceList(ctx)
tick := time.NewTicker(vpa.DeviceListRefreshInterval)
loop:
@@ -43,13 +43,13 @@
logger.Errorw(ctx, "Context Done", log.Fields{"Context": ctx})
break loop
case <-tick.C:
- vpa.refreshDeviceList()
+ vpa.refreshDeviceList(ctx)
}
}
tick.Stop()
}
-func (vpa *VPAgent) refreshDeviceList() {
+func (vpa *VPAgent) refreshDeviceList(cntx context.Context) {
// If we exit, assume disconnected
if vpa.volthaClient == nil {
logger.Error(ctx, "no-voltha-connection")
@@ -93,7 +93,7 @@
}
for i := 0; i < len(toDel); i++ {
- vpa.VPClientAgent.DelDevice(toDel[i])
+ vpa.VPClientAgent.DelDevice(cntx, toDel[i])
vpa.mapLock.Lock()
delete(vpa.clientMap, toDel[i])
vpa.mapLock.Unlock()
diff --git a/voltha-go-controller/main.go b/voltha-go-controller/main.go
index 59424e7..91327ef 100644
--- a/voltha-go-controller/main.go
+++ b/voltha-go-controller/main.go
@@ -115,6 +115,10 @@
if config.Banner {
printBanner()
}
+ // Create a context adding the status update channel
+ p := &probe.Probe{}
+ ctx := context.WithValue(context.Background(), probe.ProbeContextKey, p)
+
pc.Init()
@@ -140,7 +144,7 @@
logger.Errorw(ctx, "KVClient Establishment Failure", log.Fields{"Reason": err})
}
- if dbHandler, err = db.Initialize(config.KVStoreType, config.KVStoreEndPoint, config.KVStoreTimeout); err != nil {
+ if dbHandler, err = db.Initialize(ctx, config.KVStoreType, config.KVStoreEndPoint, config.KVStoreTimeout); err != nil {
logger.Errorw(ctx, "unable-to-connect-to-db", log.Fields{"error": err})
return
}
@@ -150,10 +154,6 @@
"port": config.KVStorePort, "retries": config.ConnectionMaxRetries,
"retryInterval": config.ConnectionRetryDelay})
- // Create a context adding the status update channel
- p := &probe.Probe{}
- ctx := context.WithValue(context.Background(), probe.ProbeContextKey, p)
-
err = waitUntilKVStoreReachableOrMaxTries(ctx, config)
if err != nil {
logger.Fatalw(ctx, "Unable-to-connect-to-KV-store", log.Fields{"KVStoreType": config.KVStoreType, "Address": config.KVStoreEndPoint})
@@ -161,7 +161,7 @@
logger.Info(ctx, "KV-store-reachable")
//Read if log-level is stored in DB
- if logLevel, err := dbHandler.Get(db.GetKeyPath(db.LogLevelPath)); err == nil {
+ if logLevel, err := dbHandler.Get(ctx, db.GetKeyPath(db.LogLevelPath)); err == nil {
logger.Infow(ctx, "Read log-level from db", log.Fields{"logLevel": logLevel})
storedLogLevel, _ := log.StringToLogLevel(logLevel)
log.SetAllLogLevel(int(storedLogLevel))
@@ -191,7 +191,7 @@
*/
go p.ListenAndServe(ctx, config.ProbeEndPoint)
- app.GetApplication().ReadAllFromDb()
+ app.GetApplication().ReadAllFromDb(ctx)
app.GetApplication().InitStaticConfig()
app.GetApplication().SetVendorID(config.VendorID)
ofca := controller.NewController(ctx, app.GetApplication())
diff --git a/voltha-go-controller/nbi/flow_hash.go b/voltha-go-controller/nbi/flow_hash.go
index a3a6115..75b3e8b 100644
--- a/voltha-go-controller/nbi/flow_hash.go
+++ b/voltha-go-controller/nbi/flow_hash.go
@@ -54,7 +54,7 @@
logger.Errorw(ctx, "Failed to get device", log.Fields{"device": id})
return
}
- device.SetFlowHash(uint32(flowhash))
+ device.SetFlowHash(ctx, uint32(flowhash))
}
logger.Debugw(ctx, "flowhash data is ", log.Fields{"vars": vars, "value": string(reqBody)})
diff --git a/voltha-go-controller/nbi/sadisbwprofile.go b/voltha-go-controller/nbi/sadisbwprofile.go
index d0f404b..2cf4cb5 100644
--- a/voltha-go-controller/nbi/sadisbwprofile.go
+++ b/voltha-go-controller/nbi/sadisbwprofile.go
@@ -17,6 +17,7 @@
import (
"bytes"
+ "context"
"encoding/json"
"net/http"
@@ -51,18 +52,18 @@
logger.Infow(ctx, "Received-northbound-request", log.Fields{"Method": r.Method, "URL": r.URL})
switch r.Method {
case "GET":
- mh.GetProfile(w, r)
+ mh.GetProfile(context.Background(), w, r)
case "POST":
- mh.AddProfile(w, r)
+ mh.AddProfile(context.Background(), w, r)
case "DELETE":
- mh.DelProfile(w, r)
+ mh.DelProfile(context.Background(), w, r)
default:
logger.Warnw(ctx, "Unsupported Method", log.Fields{"Method": r.Method})
}
}
// AddProfile to add meter
-func (mh *ProfileHandle) AddProfile(w http.ResponseWriter, r *http.Request) {
+func (mh *ProfileHandle) AddProfile(cntx context.Context, w http.ResponseWriter, r *http.Request) {
// Get the payload to process the request
d := new(bytes.Buffer)
if _, err := d.ReadFrom(r.Body); err != nil {
@@ -89,16 +90,16 @@
Eir: req.ExceededInformationRate,
Ebs: req.ExceededBurstSize,
}
- app.GetApplication().AddMeterProf(metercfg)
+ app.GetApplication().AddMeterProf(cntx, metercfg)
logger.Debugw(ctx, "northbound-add-meter-successful", log.Fields{"req": req})
}
// GetProfile to get meter
-func (mh *ProfileHandle) GetProfile(w http.ResponseWriter, r *http.Request) {
+func (mh *ProfileHandle) GetProfile(cntx context.Context, w http.ResponseWriter, r *http.Request) {
}
// DelProfile to delete meter
-func (mh *ProfileHandle) DelProfile(w http.ResponseWriter, r *http.Request) {
+func (mh *ProfileHandle) DelProfile(cntx context.Context, w http.ResponseWriter, r *http.Request) {
//TODO : Change the URL and Mux to fetch meter id from the request
d := new(bytes.Buffer)
if _, err := d.ReadFrom(r.Body); err != nil {
@@ -115,7 +116,7 @@
logger.Debugw(ctx, "Received-northbound-del-meter-request", log.Fields{"req": req})
meterName := req.ID
- if err := app.GetApplication().DelMeterProf(meterName); err != nil {
+ if err := app.GetApplication().DelMeterProf(cntx, meterName); err != nil {
logger.Errorw(ctx, "northbound-del-meter-failed", log.Fields{"req": req})
http.Error(w, err.Error(), http.StatusConflict)
return
diff --git a/voltha-go-controller/nbi/sadisigmpproxy.go b/voltha-go-controller/nbi/sadisigmpproxy.go
index 6c8f27d..5d07229 100644
--- a/voltha-go-controller/nbi/sadisigmpproxy.go
+++ b/voltha-go-controller/nbi/sadisigmpproxy.go
@@ -17,6 +17,7 @@
import (
"bytes"
+ "context"
"encoding/json"
"net/http"
"strings"
@@ -56,16 +57,16 @@
logger.Infow(ctx, "Received-northbound-request", log.Fields{"Method": r.Method, "URL": r.URL})
switch r.Method {
case "POST":
- iph.AddIgmpProxyInfo(w, r)
+ iph.AddIgmpProxyInfo(context.Background(), w, r)
case "DELETE":
- iph.DelIgmpProxyInfo(w, r)
+ iph.DelIgmpProxyInfo(context.Background(), w, r)
default:
logger.Warnw(ctx, "Unsupported Method", log.Fields{"Method": r.Method})
}
}
// AddIgmpProxyInfo to add igmp proxy info
-func (iph *IgmpProxyHandle) AddIgmpProxyInfo(w http.ResponseWriter, r *http.Request) {
+func (iph *IgmpProxyHandle) AddIgmpProxyInfo(cntx context.Context, w http.ResponseWriter, r *http.Request) {
// Get the payload to process the request
d := new(bytes.Buffer)
@@ -88,15 +89,15 @@
}
logger.Debugw(ctx, "Received-northbound-add-service-request", log.Fields{"req": req})
- go iph.addIgmpProxy(w, req)
+ go iph.addIgmpProxy(cntx, w, req)
}
// DelIgmpProxyInfo to delete igmp proxy info
-func (iph *IgmpProxyHandle) DelIgmpProxyInfo(w http.ResponseWriter, r *http.Request) {
+func (iph *IgmpProxyHandle) DelIgmpProxyInfo(cntx context.Context, w http.ResponseWriter, r *http.Request) {
}
-func (iph *IgmpProxyHandle) addIgmpProxy(w http.ResponseWriter, req *IgmpProxy) {
+func (iph *IgmpProxyHandle) addIgmpProxy(cntx context.Context, w http.ResponseWriter, req *IgmpProxy) {
var config McastConfig
config.OltSerialNum = req.SourceDeviceAndPort
@@ -109,7 +110,7 @@
logger.Errorw(ctx, "IgmpProxy", log.Fields{"config":config})
- if err := app.GetApplication().AddMcastConfig(config.MvlanProfileID, config.IgmpProfileID,
+ if err := app.GetApplication().AddMcastConfig(cntx, config.MvlanProfileID, config.IgmpProfileID,
config.IgmpProxyIP, config.OltSerialNum); err != nil {
logger.Errorw(ctx, "northbound-add-mcast-config-failed", log.Fields{"config": config, "Error": err})
http.Error(w, err.Error(), http.StatusConflict)
diff --git a/voltha-go-controller/nbi/sadismvlan.go b/voltha-go-controller/nbi/sadismvlan.go
index 28fa1d5..2242188 100644
--- a/voltha-go-controller/nbi/sadismvlan.go
+++ b/voltha-go-controller/nbi/sadismvlan.go
@@ -17,6 +17,7 @@
import (
"bytes"
+ "context"
"encoding/json"
"net/http"
"strconv"
@@ -76,16 +77,16 @@
logger.Infow(ctx, "Received-northbound-request", log.Fields{"Method": r.Method, "URL": r.URL})
switch r.Method {
case "POST":
- iph.AddMvlanInfo(w, r)
+ iph.AddMvlanInfo(context.Background(), w, r)
case "DELETE":
- iph.DelMvlanInfo(w, r)
+ iph.DelMvlanInfo(context.Background(), w, r)
default:
logger.Warnw(ctx, "Unsupported Method", log.Fields{"Method": r.Method})
}
}
// AddMvlanInfo to add igmp proxy info
-func (iph *MulticastHandle) AddMvlanInfo(w http.ResponseWriter, r *http.Request) {
+func (iph *MulticastHandle) AddMvlanInfo(cntx context.Context, w http.ResponseWriter, r *http.Request) {
// Get the payload to process the request
d := new(bytes.Buffer)
@@ -104,15 +105,15 @@
}
logger.Debugw(ctx, "Received-northbound-add-service-request", log.Fields{"req": req})
- go iph.addMvlan(w, req)
+ go iph.addMvlan(cntx, w, req)
}
// DelMvlanInfo to delete igmp proxy info
-func (iph *MulticastHandle) DelMvlanInfo(w http.ResponseWriter, r *http.Request) {
+func (iph *MulticastHandle) DelMvlanInfo(cntx context.Context, w http.ResponseWriter, r *http.Request) {
}
-func (iph *MulticastHandle) addMvlan(w http.ResponseWriter, req *Mvlan) {
+func (iph *MulticastHandle) addMvlan(cntx context.Context, w http.ResponseWriter, req *Mvlan) {
var config MvlanProfile
var groups []string
@@ -123,7 +124,7 @@
config.Groups = make(map[string][]string)
config.Groups["default"] = groups
- if err := app.GetApplication().AddMvlanProfile(config.Name, config.Mvlan, config.PonVlan, config.Groups,
+ if err := app.GetApplication().AddMvlanProfile(cntx, config.Name, config.Mvlan, config.PonVlan, config.Groups,
config.IsChannelBasedGroup, config.OLTSerialNum,
255, config.Proxy); err != nil {
logger.Errorw(ctx, "northbound-add-mvlan-failed", log.Fields{"mvlan": config.Name, "Reason": err.Error()})
diff --git a/voltha-go-controller/nbi/sadissubscriber.go b/voltha-go-controller/nbi/sadissubscriber.go
index 86d9b2b..db27a95 100644
--- a/voltha-go-controller/nbi/sadissubscriber.go
+++ b/voltha-go-controller/nbi/sadissubscriber.go
@@ -17,6 +17,7 @@
import (
"bytes"
+ "context"
"encoding/json"
"net"
"net/http"
@@ -75,16 +76,16 @@
logger.Infow(ctx, "Received-northbound-request", log.Fields{"Method": r.Method, "URL": r.URL})
switch r.Method {
case "POST":
- sh.AddSubscriberInfo(w, r)
+ sh.AddSubscriberInfo(context.Background(), w, r)
case "DELETE":
- sh.DelSubscriberInfo(w, r)
+ sh.DelSubscriberInfo(context.Background(), w, r)
default:
logger.Warnw(ctx, "Unsupported Method", log.Fields{"Method": r.Method})
}
}
// AddSubscriberInfo to add service
-func (sh *SubscriberHandle) AddSubscriberInfo(w http.ResponseWriter, r *http.Request) {
+func (sh *SubscriberHandle) AddSubscriberInfo(cntx context.Context, w http.ResponseWriter, r *http.Request) {
// Get the payload to process the request
d := new(bytes.Buffer)
@@ -104,10 +105,10 @@
//vsCfgList := getVoltServiceFromSrvInfo(req)
- go addAllService(req)
+ go addAllService(cntx, req)
}
-func addAllService(srvInfo *SubscriberDeviceInfo) {
+func addAllService(cntx context.Context, srvInfo *SubscriberDeviceInfo) {
//vsCfgList := getVoltServiceFromSrvInfo(srvInfo)
@@ -178,10 +179,10 @@
vnetcfg.VlanControl = app.OLTSVlan
}
- if err := app.GetApplication().AddVnet(vnetcfg, nil); err != nil {
+ if err := app.GetApplication().AddVnet(cntx, vnetcfg, nil); err != nil {
logger.Errorw(ctx, "AddVnet Failed", log.Fields{"VnetName": vnetName, "Error": err})
}
- if err := app.GetApplication().AddService(vs, nil); err != nil {
+ if err := app.GetApplication().AddService(cntx, vs, nil); err != nil {
logger.Errorw(ctx, "AddService Failed", log.Fields{"Service": vs.Name, "Error": err})
}
@@ -189,7 +190,7 @@
}
// DelSubscriberInfo to delete service
-func (sh *SubscriberHandle) DelSubscriberInfo(w http.ResponseWriter, r *http.Request) {
+func (sh *SubscriberHandle) DelSubscriberInfo(cntx context.Context, w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
id := vars["id"]
@@ -200,5 +201,5 @@
w.WriteHeader(http.StatusAccepted)
logger.Warnw(ctx, "northbound-del-service-req", log.Fields{"ServiceName": id})
- go app.GetApplication().DelServiceWithPrefix(id)
+ go app.GetApplication().DelServiceWithPrefix(cntx, id)
}