Skip to content

Commit e0e0c78

Browse files
authored
Merge pull request #99 from digitalocean/nshrader/GATEWAYS-1588/add-move-actionparser
ovs: add action parser for move
2 parents ccad788 + 7b3ba1a commit e0e0c78

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

ovs/actionparser.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ var (
160160
// with its parameters.
161161
loadRe = regexp.MustCompile(`load:(\S+)->(\S+)`)
162162

163+
// moveRe is the regex used to match the move action
164+
// with its parameters.
165+
moveRe = regexp.MustCompile(`move:(\S+)->(\S+)`)
166+
163167
// setFieldRe is the regex used to match the set_field action
164168
// with its parameters.
165169
setFieldRe = regexp.MustCompile(`set_field:(\S+)->(\S+)`)
@@ -369,6 +373,14 @@ func parseAction(s string) (Action, error) {
369373
return Load(ss[0][1], ss[0][2]), nil
370374
}
371375

376+
if ss := moveRe.FindAllStringSubmatch(s, 2); len(ss) > 0 && len(ss[0]) == 3 {
377+
// Results are:
378+
// - full string
379+
// - value
380+
// - field
381+
return Move(ss[0][1], ss[0][2]), nil
382+
}
383+
372384
if ss := setFieldRe.FindAllStringSubmatch(s, 2); len(ss) > 0 && len(ss[0]) == 3 {
373385
// Results are:
374386
// - full string

ovs/actionparser_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,18 @@ func Test_parseAction(t *testing.T) {
269269
s: "load:0x2->NXM_OF_ARP_OP[]",
270270
a: Load("0x2", "NXM_OF_ARP_OP[]"),
271271
},
272+
{
273+
s: "move:->NXM_OF_ARP_OP[]",
274+
invalid: true,
275+
},
276+
{
277+
s: "move:NXM_OF_ARP_SPA[]->",
278+
invalid: true,
279+
},
280+
{
281+
s: "move:NXM_OF_ARP_SPA[]->NXM_OF_ARP_TPA[]",
282+
a: Move("move:NXM_OF_ARP_SPA[]", "NXM_OF_ARP_TPA[]"),
283+
},
272284
{
273285
s: "set_field:->arp_spa",
274286
invalid: true,

0 commit comments

Comments
 (0)