Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement stats fetch using dump-flows #130

Merged
merged 3 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ Neal Shrader <[email protected]>
Sangeetha Srikanth <[email protected]>
Franck Rupin <[email protected]>
Adam Simeth <[email protected]>
Manmeet Singh <[email protected]>
27 changes: 25 additions & 2 deletions ovs/flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const (
ProtocolUDPv6 Protocol = "udp6"
)

// A Flow is an OpenFlow flow meant for adding flows to a software bridge. It can be marshaled
// A Flow is an OpenFlow flow meant for adding/fetching flows to a software bridge. It can be marshaled
// to and from its textual form for use with Open vSwitch.
type Flow struct {
Priority int
Expand All @@ -64,6 +64,7 @@ type Flow struct {
IdleTimeout int
Cookie uint64
Actions []Action
Stats FlowStats
}

// A LearnedFlow is defined as part of the Learn action.
Expand Down Expand Up @@ -396,7 +397,29 @@ func (f *Flow) UnmarshalText(b []byte) error {
}
f.Table = int(table)
continue
case duration, nPackets, nBytes, hardAge, idleAge:
case nPackets:
// Parse nPackets into struct field.
pktCount, err := strconv.ParseUint(kv[1], 0, 64)
if err != nil {
return &FlowError{
Str: kv[1],
Err: err,
}
}
f.Stats.PacketCount = uint64(pktCount)
continue
case nBytes:
// Parse nBytes into struct field.
byteCount, err := strconv.ParseUint(kv[1], 0, 64)
if err != nil {
return &FlowError{
Str: kv[1],
Err: err,
}
}
f.Stats.ByteCount = uint64(byteCount)
continue
case duration, hardAge, idleAge:
// ignore those fields.
continue
}
Expand Down
8 changes: 8 additions & 0 deletions ovs/flow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,10 @@ func TestFlowUnmarshalText(t *testing.T) {
ModVLANVID(10),
Output(1),
},
Stats: FlowStats{
PacketCount: 6,
ByteCount: 480,
},
},
},
{
Expand Down Expand Up @@ -819,6 +823,10 @@ func TestFlowUnmarshalText(t *testing.T) {
Actions: []Action{
ConnectionTracking("commit,table=65"),
},
Stats: FlowStats{
PacketCount: 3,
ByteCount: 234,
},
},
},
{
Expand Down
72 changes: 72 additions & 0 deletions ovs/openflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,10 @@ func TestClientOpenFlowDumpFlows(t *testing.T) {
ModVLANVID(10),
Output(1),
},
Stats: FlowStats{
PacketCount: 6,
ByteCount: 480,
},
},
},
err: nil,
Expand All @@ -886,6 +890,10 @@ func TestClientOpenFlowDumpFlows(t *testing.T) {
ModVLANVID(10),
Output(1),
},
Stats: FlowStats{
PacketCount: 6,
ByteCount: 480,
},
},
{
Priority: 110,
Expand All @@ -897,6 +905,10 @@ func TestClientOpenFlowDumpFlows(t *testing.T) {
Actions: []Action{
ConnectionTracking("table=51"),
},
Stats: FlowStats{
PacketCount: 0,
ByteCount: 0,
},
},
{
Priority: 101,
Expand All @@ -912,6 +924,10 @@ func TestClientOpenFlowDumpFlows(t *testing.T) {
Actions: []Action{
ConnectionTracking("commit,table=65"),
},
Stats: FlowStats{
PacketCount: 3,
ByteCount: 234,
},
},
{
Priority: 4040,
Expand All @@ -925,6 +941,10 @@ func TestClientOpenFlowDumpFlows(t *testing.T) {
Actions: []Action{
Output(19),
},
Stats: FlowStats{
PacketCount: 0,
ByteCount: 0,
},
},
{
Priority: 4321,
Expand All @@ -940,6 +960,10 @@ func TestClientOpenFlowDumpFlows(t *testing.T) {
Actions: []Action{
Resubmit(0, 13),
},
Stats: FlowStats{
PacketCount: 0,
ByteCount: 0,
},
},
},
err: nil,
Expand All @@ -965,6 +989,10 @@ NXST_FLOW reply (xid=0x4):
ModVLANVID(10),
Output(1),
},
Stats: FlowStats{
PacketCount: 6,
ByteCount: 480,
},
},
{
Priority: 110,
Expand All @@ -976,6 +1004,10 @@ NXST_FLOW reply (xid=0x4):
Actions: []Action{
ConnectionTracking("table=51"),
},
Stats: FlowStats{
PacketCount: 0,
ByteCount: 0,
},
},
{
Priority: 101,
Expand All @@ -991,6 +1023,10 @@ NXST_FLOW reply (xid=0x4):
Actions: []Action{
ConnectionTracking("commit,table=65"),
},
Stats: FlowStats{
PacketCount: 3,
ByteCount: 234,
},
},
{
Priority: 4040,
Expand All @@ -1004,6 +1040,10 @@ NXST_FLOW reply (xid=0x4):
Actions: []Action{
Output(19),
},
Stats: FlowStats{
PacketCount: 0,
ByteCount: 0,
},
},
{
Priority: 4321,
Expand All @@ -1019,6 +1059,10 @@ NXST_FLOW reply (xid=0x4):
Actions: []Action{
Resubmit(0, 13),
},
Stats: FlowStats{
PacketCount: 0,
ByteCount: 0,
},
},
},
err: nil,
Expand Down Expand Up @@ -1089,6 +1133,10 @@ func TestClientOpenFlowDumpFlowsWithFlowArgs(t *testing.T) {
ModVLANVID(10),
Output(1),
},
Stats: FlowStats{
PacketCount: 6,
ByteCount: 480,
},
},
},
err: nil,
Expand All @@ -1114,6 +1162,10 @@ func TestClientOpenFlowDumpFlowsWithFlowArgs(t *testing.T) {
ModVLANVID(10),
Output(1),
},
Stats: FlowStats{
PacketCount: 6,
ByteCount: 480,
},
},
{
Priority: 110,
Expand All @@ -1125,6 +1177,10 @@ func TestClientOpenFlowDumpFlowsWithFlowArgs(t *testing.T) {
Actions: []Action{
ConnectionTracking("table=51"),
},
Stats: FlowStats{
PacketCount: 0,
ByteCount: 0,
},
},
},
err: nil,
Expand Down Expand Up @@ -1193,6 +1249,10 @@ func TestClientOpenFlowDumpFlows15(t *testing.T) {
Actions: []Action{
ConnectionTracking("table=1"),
},
Stats: FlowStats{
PacketCount: 1127501,
ByteCount: 1595250938,
},
},
},
err: nil,
Expand All @@ -1216,6 +1276,10 @@ func TestClientOpenFlowDumpFlows15(t *testing.T) {
Actions: []Action{
ConnectionTracking("table=1"),
},
Stats: FlowStats{
PacketCount: 1127501,
ByteCount: 1595250938,
},
},
{
Priority: 0,
Expand All @@ -1224,6 +1288,10 @@ func TestClientOpenFlowDumpFlows15(t *testing.T) {
Actions: []Action{
Normal(),
},
Stats: FlowStats{
PacketCount: 7370490,
ByteCount: 893401420,
},
},
{
Priority: 1000,
Expand All @@ -1236,6 +1304,10 @@ func TestClientOpenFlowDumpFlows15(t *testing.T) {
ConnectionTracking("commit"),
Normal(),
},
Stats: FlowStats{
PacketCount: 1068,
ByteCount: 388186,
},
},
},
err: nil,
Expand Down
Loading