blob: 7a29e66015ccb6d2dd0e04f9107ae97d4b843447 [file] [log] [blame]
Don Newton98fd8812019-09-23 15:15:02 -04001/*
David K. Bainbridge157bdab2020-01-16 14:38:05 -08002 Copyright 2020 the original author or authors.
Don Newton98fd8812019-09-23 15:15:02 -04003
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17package openflow
18
19import (
20 "fmt"
Don Newtone0d34a82019-11-14 10:58:06 -050021 ofp "github.com/donNewtonAlpha/goloxi/of13"
David K. Bainbridgeaea73cd2020-01-27 10:44:50 -080022 "github.com/opencord/voltha-protos/v3/go/openflow_13"
David K. Bainbridge157bdab2020-01-16 14:38:05 -080023 "strings"
24 "sync"
Don Newton98fd8812019-09-23 15:15:02 -040025)
26
27var mu sync.Mutex
28var xid uint32 = 1
29
30func GetXid() uint32 {
31 mu.Lock()
32 defer mu.Unlock()
33 xid++
34 return xid
35}
36func PadString(value string, padSize int) string {
37 size := len(value)
38 nullsNeeded := padSize - size
39 null := fmt.Sprintf("%c", '\000')
40 padded := strings.Repeat(null, nullsNeeded)
41 return fmt.Sprintf("%s%s", value, padded)
42}
Don Newtone0d34a82019-11-14 10:58:06 -050043
44func extractAction(action ofp.IAction) *openflow_13.OfpAction {
45 var ofpAction openflow_13.OfpAction
46 switch action.GetType() {
47 case ofp.OFPATOutput:
48 var outputAction openflow_13.OfpAction_Output
49 loxiOutputAction := action.(*ofp.ActionOutput)
50 var output openflow_13.OfpActionOutput
Don Newtonb437c6f2019-12-18 11:51:57 -050051 output.Port = uint32(loxiOutputAction.GetPort())
52 /*
53 var maxLen uint16
54 maxLen = loxiOutputAction.GetMaxLen()
55 output.MaxLen = uint32(maxLen)
56
57 */
58 output.MaxLen = 0
Don Newtone0d34a82019-11-14 10:58:06 -050059 outputAction.Output = &output
60 ofpAction.Action = &outputAction
61 ofpAction.Type = openflow_13.OfpActionType_OFPAT_OUTPUT
62 case ofp.OFPATCopyTtlOut: //CopyTtltOut
63 case ofp.OFPATCopyTtlIn: //CopyTtlIn
64 case ofp.OFPATSetMplsTtl: //SetMplsTtl
65 case ofp.OFPATDecMplsTtl: //DecMplsTtl
66 case ofp.OFPATPushVLAN: //PushVlan
67 var pushVlan openflow_13.OfpAction_Push
68 loxiPushAction := action.(*ofp.ActionPushVlan)
Don Newtone0d34a82019-11-14 10:58:06 -050069 var push openflow_13.OfpActionPush
70 push.Ethertype = uint32(loxiPushAction.Ethertype) //TODO This should be available in the fields
71 pushVlan.Push = &push
72 ofpAction.Type = openflow_13.OfpActionType_OFPAT_PUSH_VLAN
73 ofpAction.Action = &pushVlan
74 case ofp.OFPATPopVLAN: //PopVlan
75 ofpAction.Type = openflow_13.OfpActionType_OFPAT_POP_VLAN
76 case ofp.OFPATPushMpls: //PushMpls
77 case ofp.OFPATPopMpls: //PopMpls
78 case ofp.OFPATSetQueue: //SetQueue
79 case ofp.OFPATGroup: //ActionGroup
80 case ofp.OFPATSetNwTtl: //SetNwTtl
81 case ofp.OFPATDecNwTtl: //DecNwTtl
82 case ofp.OFPATSetField: //SetField
83 ofpAction.Type = openflow_13.OfpActionType_OFPAT_SET_FIELD
84 var ofpAction_SetField openflow_13.OfpAction_SetField
85 var ofpActionSetField openflow_13.OfpActionSetField
86 var ofpOxmField openflow_13.OfpOxmField
87 ofpOxmField.OxmClass = openflow_13.OfpOxmClass_OFPXMC_OPENFLOW_BASIC
88 var ofpOxmField_OfbField openflow_13.OfpOxmField_OfbField
89 var ofpOxmOfbField openflow_13.OfpOxmOfbField
90 loxiSetField := action.(*ofp.ActionSetField)
91 oxmName := loxiSetField.Field.GetOXMName()
92 switch oxmName {
Don Newton7577f072020-01-06 12:41:11 -050093 //TODO handle set field sith other fields
Don Newtone0d34a82019-11-14 10:58:06 -050094 case "vlan_vid":
95 ofpOxmOfbField.Type = openflow_13.OxmOfbFieldTypes_OFPXMT_OFB_VLAN_VID
96 var vlanVid openflow_13.OfpOxmOfbField_VlanVid
97 var VlanVid = loxiSetField.Field.GetOXMValue().(uint16)
98 vlanVid.VlanVid = uint32(VlanVid)
99
100 ofpOxmOfbField.Value = &vlanVid
Don Newtone0d34a82019-11-14 10:58:06 -0500101 }
102 ofpOxmField_OfbField.OfbField = &ofpOxmOfbField
103 ofpOxmField.Field = &ofpOxmField_OfbField
104 ofpActionSetField.Field = &ofpOxmField
105 ofpAction_SetField.SetField = &ofpActionSetField
106 ofpAction.Action = &ofpAction_SetField
Don Newtonb437c6f2019-12-18 11:51:57 -0500107
Don Newtone0d34a82019-11-14 10:58:06 -0500108 case ofp.OFPATPushPbb: //PushPbb
109 case ofp.OFPATPopPbb: //PopPbb
110 case ofp.OFPATExperimenter: //Experimenter
111
112 }
113 return &ofpAction
114
115}