diff --git a/AUTHORS b/AUTHORS index 3d08687..eb57d88 100644 --- a/AUTHORS +++ b/AUTHORS @@ -15,3 +15,4 @@ Neal Shrader Sangeetha Srikanth Franck Rupin Adam Simeth +Manmeet Singh \ No newline at end of file diff --git a/ovs/flow.go b/ovs/flow.go index 0de9337..522429d 100644 --- a/ovs/flow.go +++ b/ovs/flow.go @@ -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 @@ -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. @@ -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 } diff --git a/ovs/flow_test.go b/ovs/flow_test.go index 86f87f4..3b060d2 100644 --- a/ovs/flow_test.go +++ b/ovs/flow_test.go @@ -785,6 +785,10 @@ func TestFlowUnmarshalText(t *testing.T) { ModVLANVID(10), Output(1), }, + Stats: FlowStats{ + PacketCount: 6, + ByteCount: 480, + }, }, }, { @@ -819,6 +823,10 @@ func TestFlowUnmarshalText(t *testing.T) { Actions: []Action{ ConnectionTracking("commit,table=65"), }, + Stats: FlowStats{ + PacketCount: 3, + ByteCount: 234, + }, }, }, { diff --git a/ovs/openflow_test.go b/ovs/openflow_test.go index eaa408b..aea427c 100644 --- a/ovs/openflow_test.go +++ b/ovs/openflow_test.go @@ -862,6 +862,10 @@ func TestClientOpenFlowDumpFlows(t *testing.T) { ModVLANVID(10), Output(1), }, + Stats: FlowStats{ + PacketCount: 6, + ByteCount: 480, + }, }, }, err: nil, @@ -886,6 +890,10 @@ func TestClientOpenFlowDumpFlows(t *testing.T) { ModVLANVID(10), Output(1), }, + Stats: FlowStats{ + PacketCount: 6, + ByteCount: 480, + }, }, { Priority: 110, @@ -897,6 +905,10 @@ func TestClientOpenFlowDumpFlows(t *testing.T) { Actions: []Action{ ConnectionTracking("table=51"), }, + Stats: FlowStats{ + PacketCount: 0, + ByteCount: 0, + }, }, { Priority: 101, @@ -912,6 +924,10 @@ func TestClientOpenFlowDumpFlows(t *testing.T) { Actions: []Action{ ConnectionTracking("commit,table=65"), }, + Stats: FlowStats{ + PacketCount: 3, + ByteCount: 234, + }, }, { Priority: 4040, @@ -925,6 +941,10 @@ func TestClientOpenFlowDumpFlows(t *testing.T) { Actions: []Action{ Output(19), }, + Stats: FlowStats{ + PacketCount: 0, + ByteCount: 0, + }, }, { Priority: 4321, @@ -940,6 +960,10 @@ func TestClientOpenFlowDumpFlows(t *testing.T) { Actions: []Action{ Resubmit(0, 13), }, + Stats: FlowStats{ + PacketCount: 0, + ByteCount: 0, + }, }, }, err: nil, @@ -965,6 +989,10 @@ NXST_FLOW reply (xid=0x4): ModVLANVID(10), Output(1), }, + Stats: FlowStats{ + PacketCount: 6, + ByteCount: 480, + }, }, { Priority: 110, @@ -976,6 +1004,10 @@ NXST_FLOW reply (xid=0x4): Actions: []Action{ ConnectionTracking("table=51"), }, + Stats: FlowStats{ + PacketCount: 0, + ByteCount: 0, + }, }, { Priority: 101, @@ -991,6 +1023,10 @@ NXST_FLOW reply (xid=0x4): Actions: []Action{ ConnectionTracking("commit,table=65"), }, + Stats: FlowStats{ + PacketCount: 3, + ByteCount: 234, + }, }, { Priority: 4040, @@ -1004,6 +1040,10 @@ NXST_FLOW reply (xid=0x4): Actions: []Action{ Output(19), }, + Stats: FlowStats{ + PacketCount: 0, + ByteCount: 0, + }, }, { Priority: 4321, @@ -1019,6 +1059,10 @@ NXST_FLOW reply (xid=0x4): Actions: []Action{ Resubmit(0, 13), }, + Stats: FlowStats{ + PacketCount: 0, + ByteCount: 0, + }, }, }, err: nil, @@ -1089,6 +1133,10 @@ func TestClientOpenFlowDumpFlowsWithFlowArgs(t *testing.T) { ModVLANVID(10), Output(1), }, + Stats: FlowStats{ + PacketCount: 6, + ByteCount: 480, + }, }, }, err: nil, @@ -1114,6 +1162,10 @@ func TestClientOpenFlowDumpFlowsWithFlowArgs(t *testing.T) { ModVLANVID(10), Output(1), }, + Stats: FlowStats{ + PacketCount: 6, + ByteCount: 480, + }, }, { Priority: 110, @@ -1125,6 +1177,10 @@ func TestClientOpenFlowDumpFlowsWithFlowArgs(t *testing.T) { Actions: []Action{ ConnectionTracking("table=51"), }, + Stats: FlowStats{ + PacketCount: 0, + ByteCount: 0, + }, }, }, err: nil, @@ -1193,6 +1249,10 @@ func TestClientOpenFlowDumpFlows15(t *testing.T) { Actions: []Action{ ConnectionTracking("table=1"), }, + Stats: FlowStats{ + PacketCount: 1127501, + ByteCount: 1595250938, + }, }, }, err: nil, @@ -1216,6 +1276,10 @@ func TestClientOpenFlowDumpFlows15(t *testing.T) { Actions: []Action{ ConnectionTracking("table=1"), }, + Stats: FlowStats{ + PacketCount: 1127501, + ByteCount: 1595250938, + }, }, { Priority: 0, @@ -1224,6 +1288,10 @@ func TestClientOpenFlowDumpFlows15(t *testing.T) { Actions: []Action{ Normal(), }, + Stats: FlowStats{ + PacketCount: 7370490, + ByteCount: 893401420, + }, }, { Priority: 1000, @@ -1236,6 +1304,10 @@ func TestClientOpenFlowDumpFlows15(t *testing.T) { ConnectionTracking("commit"), Normal(), }, + Stats: FlowStats{ + PacketCount: 1068, + ByteCount: 388186, + }, }, }, err: nil,