|
64 | 64 |
|
65 | 65 | // errMoveEmpty is returned when Move is called with src and/or dst set to the empty string.
|
66 | 66 | errMoveEmpty = errors.New("src and/or dst field for action move are empty")
|
| 67 | + |
| 68 | + // errOutputFieldEmpty is returned when OutputField is called with field set to the empty string. |
| 69 | + errOutputFieldEmpty = errors.New("field for action output (output:field syntax) is empty") |
67 | 70 | )
|
68 | 71 |
|
69 | 72 | // Action strings in lower case, as those are compared to the lower case letters
|
@@ -184,6 +187,7 @@ const (
|
184 | 187 | patModTransportSourcePort = "mod_tp_src:%d"
|
185 | 188 | patModVLANVID = "mod_vlan_vid:%d"
|
186 | 189 | patOutput = "output:%d"
|
| 190 | + patOutputField = "output:%s" |
187 | 191 | patResubmitPort = "resubmit:%s"
|
188 | 192 | patResubmitPortTable = "resubmit(%s,%s)"
|
189 | 193 | )
|
@@ -403,6 +407,34 @@ func (a *outputAction) GoString() string {
|
403 | 407 | return fmt.Sprintf("ovs.Output(%d)", a.port)
|
404 | 408 | }
|
405 | 409 |
|
| 410 | +// OutputField outputs the packet to the switch port described by the specified field. |
| 411 | +// For example, when the `field` value is "in_port", the packet is output to the port |
| 412 | +// it came in on. |
| 413 | +func OutputField(field string) Action { |
| 414 | + return &outputFieldAction{ |
| 415 | + field: field, |
| 416 | + } |
| 417 | +} |
| 418 | + |
| 419 | +// An outputFieldAction is an Action which is used by OutputField. |
| 420 | +type outputFieldAction struct { |
| 421 | + field string |
| 422 | +} |
| 423 | + |
| 424 | +// MarshalText implements Action. |
| 425 | +func (a *outputFieldAction) MarshalText() ([]byte, error) { |
| 426 | + if a.field == "" { |
| 427 | + return nil, errOutputFieldEmpty |
| 428 | + } |
| 429 | + |
| 430 | + return bprintf(patOutputField, a.field), nil |
| 431 | +} |
| 432 | + |
| 433 | +// GoString implements Action. |
| 434 | +func (a *outputFieldAction) GoString() string { |
| 435 | + return fmt.Sprintf("ovs.OutputField(%q)", a.field) |
| 436 | +} |
| 437 | + |
406 | 438 | // Conjunction associates a flow with a certain conjunction ID to match on more than
|
407 | 439 | // one dimension across multiple set matches.
|
408 | 440 | func Conjunction(id int, dimensionNumber int, dimensionSize int) Action {
|
|
0 commit comments