Skip to content

Commit 12e0112

Browse files
authored
Merge pull request #39 from digitalocean/nshrader/openflow-messages
ovs: do not attempt to parse NXST_FLOW in DumpFlows
2 parents bc7912d + ff5d2e1 commit 12e0112

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed

ovs/openflow.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,11 @@ func (o *OpenFlowService) DumpFlows(bridge string) ([]*Flow, error) {
266266

267267
var flows []*Flow
268268
err = parseEachLine(out, dumpFlowsPrefix, func(b []byte) error {
269+
// Do not attempt to parse NXST_FLOW messages.
270+
if bytes.HasPrefix(b, dumpFlowsPrefix) {
271+
return nil
272+
}
273+
269274
f := new(Flow)
270275
if err := f.UnmarshalText(b); err != nil {
271276
return err

ovs/openflow_test.go

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,85 @@ func TestClientOpenFlowDumpFlows(t *testing.T) {
875875
cookie=0x0, duration=83229.846s, table=51, n_packets=3, n_bytes=234, priority=101,ct_state=+new+rel+trk,ip actions=ct(commit,table=65)
876876
cookie=0x0, duration=1381314.983s, table=65, n_packets=0, n_bytes=0, priority=4040,ip,dl_dst=f1:f2:f3:f4:f5:f6,nw_src=169.254.169.254,nw_dst=169.254.0.0/16 actions=output:19
877877
cookie=0x0, duration=13.265s, table=12, n_packets=0, n_bytes=0, idle_age=13, priority=4321,tcp,tcp_flags=+syn-psh+ack actions=resubmit(,13)
878+
`,
879+
want: []*Flow{
880+
{
881+
Priority: 820,
882+
InPort: PortLOCAL,
883+
Matches: []Match{},
884+
Table: 0,
885+
Actions: []Action{
886+
ModVLANVID(10),
887+
Output(1),
888+
},
889+
},
890+
{
891+
Priority: 110,
892+
Protocol: ProtocolIPv4,
893+
Matches: []Match{
894+
DataLinkSource("f1:f2:f3:f4:f5:f6"),
895+
},
896+
Table: 50,
897+
Actions: []Action{
898+
ConnectionTracking("table=51"),
899+
},
900+
},
901+
{
902+
Priority: 101,
903+
Protocol: ProtocolIPv4,
904+
Matches: []Match{
905+
ConnectionTrackingState(
906+
SetState(CTStateNew),
907+
SetState(CTStateRelated),
908+
SetState(CTStateTracked),
909+
),
910+
},
911+
Table: 51,
912+
Actions: []Action{
913+
ConnectionTracking("commit,table=65"),
914+
},
915+
},
916+
{
917+
Priority: 4040,
918+
Protocol: ProtocolIPv4,
919+
Matches: []Match{
920+
DataLinkDestination("f1:f2:f3:f4:f5:f6"),
921+
NetworkSource("169.254.169.254"),
922+
NetworkDestination("169.254.0.0/16"),
923+
},
924+
Table: 65,
925+
Actions: []Action{
926+
Output(19),
927+
},
928+
},
929+
{
930+
Priority: 4321,
931+
Protocol: ProtocolTCPv4,
932+
Matches: []Match{
933+
TCPFlags(
934+
SetTCPFlag(TCPFlagSYN),
935+
UnsetTCPFlag(TCPFlagPSH),
936+
SetTCPFlag(TCPFlagACK),
937+
),
938+
},
939+
Table: 12,
940+
Actions: []Action{
941+
Resubmit(0, 13),
942+
},
943+
},
944+
},
945+
err: nil,
946+
},
947+
{
948+
name: "test multiple flows mid dump NXST_FLOW",
949+
input: "br0",
950+
flows: `NXST_FLOW reply (xid=0x4): flags=[more]
951+
cookie=0x0, duration=9215.748s, table=0, n_packets=6, n_bytes=480, idle_age=9206, priority=820,in_port=LOCAL actions=mod_vlan_vid:10,output:1
952+
cookie=0x0, duration=1121991.329s, table=50, n_packets=0, n_bytes=0, priority=110,ip,dl_src=f1:f2:f3:f4:f5:f6 actions=ct(table=51)
953+
NXST_FLOW reply (xid=0x4):
954+
cookie=0x0, duration=83229.846s, table=51, n_packets=3, n_bytes=234, priority=101,ct_state=+new+rel+trk,ip actions=ct(commit,table=65)
955+
cookie=0x0, duration=1381314.983s, table=65, n_packets=0, n_bytes=0, priority=4040,ip,dl_dst=f1:f2:f3:f4:f5:f6,nw_src=169.254.169.254,nw_dst=169.254.0.0/16 actions=output:19
956+
cookie=0x0, duration=13.265s, table=12, n_packets=0, n_bytes=0, idle_age=13, priority=4321,tcp,tcp_flags=+syn-psh+ack actions=resubmit(,13)
878957
`,
879958
want: []*Flow{
880959
{

0 commit comments

Comments
 (0)