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 Apr 24, 2022
1 parent 6c2880d commit 4371814
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.5.7
v0.5.8
19 changes: 13 additions & 6 deletions ofctrl/fgraphFlow.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,15 @@ type FlowMatch struct {

// additional Actions in flow's instruction set
type FlowAction struct {
ActionType string // Type of action "setVlan", "setMetadata"
ActionType string // Type of action "setVlan", "writeMetadata"
vlanId uint16 // Vlan Id in case of "setVlan"
macAddr net.HardwareAddr // Mac address to set
mplsEtherType uint16 // mpls ether type to push or pop
ipAddr net.IP // IP address to be set
l4Port uint16 // Transport port to be set
arpOper uint16 // Arp operation type to be set
tunnelId uint64 // Tunnel Id (used for setting VNI)
metadata uint64 // Metadata in case of "setMetadata"
metadata uint64 // Metadata in case of "writeMetadata"
metadataMask uint64 // Metadata mask
dscp uint8 // DSCP field
loadAct *NXLoadAction // Load data into OXM/NXM fields, one or more Actions
Expand Down 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 ActTypeWriteMetadata:
// 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 @@ -1584,10 +1585,11 @@ func (self *Flow) SetL4Field(port uint16, field string) error {
return nil
}

// Special actions on the flow to set metadata
// Special actions on the flow to write metadata
// Deprecated: use below WriteMetadata API instead of this one
func (self *Flow) SetMetadata(metadata, metadataMask uint64) error {
action := new(FlowAction)
action.ActionType = "setMetadata"
action.ActionType = ActTypeWriteMetadata
action.metadata = metadata
action.metadataMask = metadataMask

Expand All @@ -1605,6 +1607,11 @@ func (self *Flow) SetMetadata(metadata, metadataMask uint64) error {
return nil
}

// Special actions on the flow to write metadata
func (self *Flow) WriteMetadata(metadata, metadataMask uint64) error {
return SetMetadata(metadata, metadataMask)
}

// Special actions on the flow to set vlan id
func (self *Flow) SetTunnelId(tunnelId uint64) error {
action := new(FlowAction)
Expand Down
17 changes: 16 additions & 1 deletion ofctrl/ofAction.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ const (
ActTypeSetDstMac = "setMacDa"
ActTypeSetSrcMac = "setMacSa"
ActTypeSetTunnelID = "setTunnelId"
ActTypeMetatdata = "setMetadata"
ActTypeSetMetadata = "setMetadata" // use set_field
ActTypeWriteMetadata = "writeMetadata" // use writeMetadata instruction
ActTypeSetSrcIP = "setIPSa"
ActTypeSetDstIP = "setIPDa"
ActTypeSetTunnelSrcIP = "setTunSa"
Expand Down Expand Up @@ -160,6 +161,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 4371814

Please sign in to comment.