Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable set_field with Metadata register #16

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
17 changes: 11 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":
commandgjj marked this conversation as resolved.
Show resolved Hide resolved
// 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,14 @@ 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.
// By using this API, it will call `writeMetadata' instruction
// to write metadata register in installFlowActions().
// Instead, you can also use SetMetadataAction which uses
// `set_field' to write metadata register.
func (self *Flow) SetMetadata(metadata, metadataMask uint64) error {
action := new(FlowAction)
action.ActionType = "setMetadata"
action.ActionType = ActTypeWriteMetadata
action.metadata = metadata
action.metadataMask = metadataMask

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