Skip to content

Commit

Permalink
Enable set_field with Metadata register
Browse files Browse the repository at this point in the history
WriteMetadata is write-action instruction which will be applied later
than apply-action. In some case, we need use resubmit to do pipeline in
the same table and set Metadata before resubmit at the same time.
WriteMetadata cannot do the job. We need enable set_field for Metadata
register.

Actually, WriteMetadata do the same thing with set_field Metadata
register in the OvS. From OpenFlow 1.5, Metadata register also can be
used with set_field to set, not stricted only using WriteMetadata instruction.

After this patch, ofnet can support WriteMetadata and set_field for
Metadata meanwhile. Caller can use SetMetadata() or WriteMetadata() API
to implement WriteMetadata action, and use SetMetadataAction() and
ApplyAction() to implement set_field for Metadata.

Signed-off-by: Jinjun Gao <[email protected]>
  • Loading branch information
commandgjj committed Mar 31, 2022
1 parent 9ec6cfc commit 781cf31
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.5.6
v0.5.7
7 changes: 4 additions & 3 deletions ofctrl/fgraphFlow.go
Original file line number Diff line number Diff line change
Expand Up @@ -843,12 +843,13 @@ func (self *Flow) installFlowActions(flowMod *openflow13.FlowMod,

log.Debugf("flow install. Added setTunnelId Action: %+v", setTunnelAction)

case "setMetadata":
// Set Metadata instruction
case ActTypeSetMetadata:
// Write Metadata instruction
metadataInstr := openflow13.NewInstrWriteMetadata(flowAction.metadata, flowAction.metadataMask)

// Add the instruction to flowmod
flowMod.AddInstruction(metadataInstr)
log.Debugf("flow install. Added writeMetadata Action: %+v", metadataInstr)

case ActTypeSetSrcIP:
// Set IP src
Expand Down Expand Up @@ -1587,7 +1588,7 @@ func (self *Flow) SetL4Field(port uint16, field string) error {
// Special actions on the flow to set metadata
func (self *Flow) SetMetadata(metadata, metadataMask uint64) error {
action := new(FlowAction)
action.ActionType = "setMetadata"
action.ActionType = ActTypeSetMetadata
action.metadata = metadata
action.metadataMask = metadataMask

Expand Down
16 changes: 15 additions & 1 deletion ofctrl/ofAction.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const (
ActTypeSetDstMac = "setMacDa"
ActTypeSetSrcMac = "setMacSa"
ActTypeSetTunnelID = "setTunnelId"
ActTypeMetatdata = "setMetadata"
ActTypeSetMetadata = "setMetadata"
ActTypeSetSrcIP = "setIPSa"
ActTypeSetDstIP = "setIPDa"
ActTypeSetTunnelSrcIP = "setTunSa"
Expand Down Expand Up @@ -160,6 +160,20 @@ func (a *SetTunnelIDAction) GetActionType() string {
return ActTypeSetTunnelID
}

type SetMetadataAction struct {
Metadata uint64
MetadataMask *uint64
}

func (a *SetMetadataAction) GetActionMessage() openflow13.Action {
field := openflow13.NewMetadataField(a.Metadata, a.MetadataMask)
return openflow13.NewActionSetField(*field)
}

func (a *SetMetadataAction) GetActionType() string {
return ActTypeSetMetadata
}

type SetTunnelDstAction struct {
IP net.IP
}
Expand Down

0 comments on commit 781cf31

Please sign in to comment.