[VOL-3069]Pass Context in methods which are performing logging and need the context
Change-Id: I3d9e1c3eff95d60dde46d44d16bed4805f7447f5
diff --git a/pkg/flows/flow_utils.go b/pkg/flows/flow_utils.go
index 3139144..66e719c 100644
--- a/pkg/flows/flow_utils.go
+++ b/pkg/flows/flow_utils.go
@@ -17,6 +17,7 @@
import (
"bytes"
+ "context"
"crypto/md5"
"encoding/binary"
"fmt"
@@ -503,7 +504,7 @@
}
//GetMetaData - legacy get method (only want lower 32 bits)
-func GetMetaData(flow *ofp.OfpFlowStats) uint32 {
+func GetMetaData(ctx context.Context, flow *ofp.OfpFlowStats) uint32 {
if flow == nil {
return 0
}
@@ -512,11 +513,11 @@
return uint32(field.GetTableMetadata() & 0xFFFFFFFF)
}
}
- logger.Debug("No-metadata-present")
+ logger.Debug(ctx, "No-metadata-present")
return 0
}
-func GetMetaData64Bit(flow *ofp.OfpFlowStats) uint64 {
+func GetMetaData64Bit(ctx context.Context, flow *ofp.OfpFlowStats) uint64 {
if flow == nil {
return 0
}
@@ -525,12 +526,12 @@
return field.GetTableMetadata()
}
}
- logger.Debug("No-metadata-present")
+ logger.Debug(ctx, "No-metadata-present")
return 0
}
// function returns write metadata value from write_metadata action field
-func GetMetadataFromWriteMetadataAction(flow *ofp.OfpFlowStats) uint64 {
+func GetMetadataFromWriteMetadataAction(ctx context.Context, flow *ofp.OfpFlowStats) uint64 {
if flow != nil {
for _, instruction := range flow.Instructions {
if instruction.Type == uint32(WRITE_METADATA) {
@@ -540,11 +541,11 @@
}
}
}
- logger.Debugw("No-write-metadata-present", log.Fields{"flow": flow})
+ logger.Debugw(ctx, "No-write-metadata-present", log.Fields{"flow": flow})
return 0
}
-func GetTechProfileIDFromWriteMetaData(metadata uint64) uint16 {
+func GetTechProfileIDFromWriteMetaData(ctx context.Context, metadata uint64) uint16 {
/*
Write metadata instruction value (metadata) is 8 bytes:
MS 2 bytes: C Tag
@@ -554,15 +555,15 @@
This is set in the ONOS OltPipeline as a write metadata instruction
*/
var tpId uint16 = 0
- logger.Debugw("Write metadata value for Techprofile ID", log.Fields{"metadata": metadata})
+ logger.Debugw(ctx, "Write metadata value for Techprofile ID", log.Fields{"metadata": metadata})
if metadata != 0 {
tpId = uint16((metadata >> 32) & 0xFFFF)
- logger.Debugw("Found techprofile ID from write metadata action", log.Fields{"tpid": tpId})
+ logger.Debugw(ctx, "Found techprofile ID from write metadata action", log.Fields{"tpid": tpId})
}
return tpId
}
-func GetEgressPortNumberFromWriteMetadata(flow *ofp.OfpFlowStats) uint32 {
+func GetEgressPortNumberFromWriteMetadata(ctx context.Context, flow *ofp.OfpFlowStats) uint32 {
/*
Write metadata instruction value (metadata) is 8 bytes:
MS 2 bytes: C Tag
@@ -571,17 +572,17 @@
This is set in the ONOS OltPipeline as a write metadata instruction
*/
var uniPort uint32 = 0
- md := GetMetadataFromWriteMetadataAction(flow)
- logger.Debugw("Metadata found for egress/uni port ", log.Fields{"metadata": md})
+ md := GetMetadataFromWriteMetadataAction(ctx, flow)
+ logger.Debugw(ctx, "Metadata found for egress/uni port ", log.Fields{"metadata": md})
if md != 0 {
uniPort = uint32(md & 0xFFFFFFFF)
- logger.Debugw("Found EgressPort from write metadata action", log.Fields{"egress_port": uniPort})
+ logger.Debugw(ctx, "Found EgressPort from write metadata action", log.Fields{"egress_port": uniPort})
}
return uniPort
}
-func GetInnerTagFromMetaData(flow *ofp.OfpFlowStats) uint16 {
+func GetInnerTagFromMetaData(ctx context.Context, flow *ofp.OfpFlowStats) uint16 {
/*
Write metadata instruction value (metadata) is 8 bytes:
MS 2 bytes: C Tag
@@ -590,10 +591,10 @@
This is set in the ONOS OltPipeline as a write metadata instruction
*/
var innerTag uint16 = 0
- md := GetMetadataFromWriteMetadataAction(flow)
+ md := GetMetadataFromWriteMetadataAction(ctx, flow)
if md != 0 {
innerTag = uint16((md >> 48) & 0xFFFF)
- logger.Debugw("Found CVLAN from write metadate action", log.Fields{"c_vlan": innerTag})
+ logger.Debugw(ctx, "Found CVLAN from write metadate action", log.Fields{"c_vlan": innerTag})
}
return innerTag
}
@@ -607,7 +608,7 @@
return 0
}
if md <= 0xffffffff {
- logger.Debugw("onos-upgrade-suggested", logger.Fields{"Metadata_ofp": md, "message": "Legacy MetaData detected form OltPipeline"})
+ logger.Debugw(ctx, "onos-upgrade-suggested", logger.Fields{"Metadata_ofp": md, "message": "Legacy MetaData detected form OltPipeline"})
return md
}
return (md >> 32) & 0xffffffff
@@ -937,12 +938,12 @@
}
// flowStatsEntryFromFlowModMessage maps an ofp_flow_mod message to an ofp_flow_stats message
-func MeterEntryFromMeterMod(meterMod *ofp.OfpMeterMod) *ofp.OfpMeterEntry {
+func MeterEntryFromMeterMod(ctx context.Context, meterMod *ofp.OfpMeterMod) *ofp.OfpMeterEntry {
bandStats := make([]*ofp.OfpMeterBandStats, 0)
meter := &ofp.OfpMeterEntry{Config: &ofp.OfpMeterConfig{},
Stats: &ofp.OfpMeterStats{BandStats: bandStats}}
if meterMod == nil {
- logger.Error("Invalid meter mod command")
+ logger.Error(ctx, "Invalid meter mod command")
return meter
}
// config init
@@ -964,7 +965,7 @@
bandStats = append(bandStats, band)
}
meter.Stats.BandStats = bandStats
- logger.Debugw("Allocated meter entry", log.Fields{"meter": *meter})
+ logger.Debugw(ctx, "Allocated meter entry", log.Fields{"meter": *meter})
return meter
}