blob: d87c338b1c8cf928f7bb82ca13cc1b0ba01326b4 [file] [log] [blame]
Don Newton98fd8812019-09-23 15:15:02 -04001/*
2 Copyright 2017 the original author or authors.
3
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"
21 "strings"
22 "sync"
Don Newtone0d34a82019-11-14 10:58:06 -050023
24 ofp "github.com/donNewtonAlpha/goloxi/of13"
Don Newtonb437c6f2019-12-18 11:51:57 -050025 "github.com/opencord/voltha-protos/v2/go/openflow_13"
Don Newton98fd8812019-09-23 15:15:02 -040026)
27
28var mu sync.Mutex
29var xid uint32 = 1
30
31func GetXid() uint32 {
32 mu.Lock()
33 defer mu.Unlock()
34 xid++
35 return xid
36}
37func PadString(value string, padSize int) string {
38 size := len(value)
39 nullsNeeded := padSize - size
40 null := fmt.Sprintf("%c", '\000')
41 padded := strings.Repeat(null, nullsNeeded)
42 return fmt.Sprintf("%s%s", value, padded)
43}
Don Newtone0d34a82019-11-14 10:58:06 -050044
45func extractAction(action ofp.IAction) *openflow_13.OfpAction {
46 var ofpAction openflow_13.OfpAction
47 switch action.GetType() {
48 case ofp.OFPATOutput:
49 var outputAction openflow_13.OfpAction_Output
50 loxiOutputAction := action.(*ofp.ActionOutput)
51 var output openflow_13.OfpActionOutput
Don Newtonb437c6f2019-12-18 11:51:57 -050052 output.Port = uint32(loxiOutputAction.GetPort())
53 /*
54 var maxLen uint16
55 maxLen = loxiOutputAction.GetMaxLen()
56 output.MaxLen = uint32(maxLen)
57
58 */
59 output.MaxLen = 0
Don Newtone0d34a82019-11-14 10:58:06 -050060 outputAction.Output = &output
61 ofpAction.Action = &outputAction
62 ofpAction.Type = openflow_13.OfpActionType_OFPAT_OUTPUT
63 case ofp.OFPATCopyTtlOut: //CopyTtltOut
64 case ofp.OFPATCopyTtlIn: //CopyTtlIn
65 case ofp.OFPATSetMplsTtl: //SetMplsTtl
66 case ofp.OFPATDecMplsTtl: //DecMplsTtl
67 case ofp.OFPATPushVLAN: //PushVlan
68 var pushVlan openflow_13.OfpAction_Push
69 loxiPushAction := action.(*ofp.ActionPushVlan)
Don Newtone0d34a82019-11-14 10:58:06 -050070 var push openflow_13.OfpActionPush
71 push.Ethertype = uint32(loxiPushAction.Ethertype) //TODO This should be available in the fields
72 pushVlan.Push = &push
73 ofpAction.Type = openflow_13.OfpActionType_OFPAT_PUSH_VLAN
74 ofpAction.Action = &pushVlan
75 case ofp.OFPATPopVLAN: //PopVlan
76 ofpAction.Type = openflow_13.OfpActionType_OFPAT_POP_VLAN
77 case ofp.OFPATPushMpls: //PushMpls
78 case ofp.OFPATPopMpls: //PopMpls
79 case ofp.OFPATSetQueue: //SetQueue
80 case ofp.OFPATGroup: //ActionGroup
81 case ofp.OFPATSetNwTtl: //SetNwTtl
82 case ofp.OFPATDecNwTtl: //DecNwTtl
83 case ofp.OFPATSetField: //SetField
84 ofpAction.Type = openflow_13.OfpActionType_OFPAT_SET_FIELD
85 var ofpAction_SetField openflow_13.OfpAction_SetField
86 var ofpActionSetField openflow_13.OfpActionSetField
87 var ofpOxmField openflow_13.OfpOxmField
88 ofpOxmField.OxmClass = openflow_13.OfpOxmClass_OFPXMC_OPENFLOW_BASIC
89 var ofpOxmField_OfbField openflow_13.OfpOxmField_OfbField
90 var ofpOxmOfbField openflow_13.OfpOxmOfbField
91 loxiSetField := action.(*ofp.ActionSetField)
92 oxmName := loxiSetField.Field.GetOXMName()
93 switch oxmName {
Don Newton7577f072020-01-06 12:41:11 -050094 //TODO handle set field sith other fields
Don Newtone0d34a82019-11-14 10:58:06 -050095 case "vlan_vid":
96 ofpOxmOfbField.Type = openflow_13.OxmOfbFieldTypes_OFPXMT_OFB_VLAN_VID
97 var vlanVid openflow_13.OfpOxmOfbField_VlanVid
98 var VlanVid = loxiSetField.Field.GetOXMValue().(uint16)
99 vlanVid.VlanVid = uint32(VlanVid)
100
101 ofpOxmOfbField.Value = &vlanVid
Don Newtone0d34a82019-11-14 10:58:06 -0500102 }
103 ofpOxmField_OfbField.OfbField = &ofpOxmOfbField
104 ofpOxmField.Field = &ofpOxmField_OfbField
105 ofpActionSetField.Field = &ofpOxmField
106 ofpAction_SetField.SetField = &ofpActionSetField
107 ofpAction.Action = &ofpAction_SetField
Don Newtonb437c6f2019-12-18 11:51:57 -0500108
Don Newtone0d34a82019-11-14 10:58:06 -0500109 case ofp.OFPATPushPbb: //PushPbb
110 case ofp.OFPATPopPbb: //PopPbb
111 case ofp.OFPATExperimenter: //Experimenter
112
113 }
114 return &ofpAction
115
116}