Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2022-present Open Networking Foundation |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | |
| 16 | package of |
| 17 | |
| 18 | import ( |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 19 | "voltha-go-controller/log" |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 20 | ofp "github.com/opencord/voltha-protos/v5/go/openflow_13" |
| 21 | // "github.com/opencord/voltha-protos/v5/go/voltha" |
| 22 | ) |
| 23 | |
| 24 | // The commands on groups avialable. Add is not expected to be used. |
| 25 | // The mod is used for both create and update. The delete is used to |
| 26 | // delete the group |
| 27 | |
| 28 | // GroupCommand type |
| 29 | type GroupCommand ofp.OfpGroupModCommand |
| 30 | |
| 31 | const ( |
| 32 | // GroupCommandAdd constant |
| 33 | GroupCommandAdd GroupCommand = 0 |
| 34 | // GroupCommandMod constant |
| 35 | GroupCommandMod GroupCommand = 1 |
| 36 | // GroupCommandDel constant |
| 37 | GroupCommandDel GroupCommand = 2 |
| 38 | ) |
| 39 | |
| 40 | const ( |
| 41 | // GroupOperSuccess constant |
| 42 | GroupOperSuccess = 0 |
| 43 | // GroupOperFailure constant |
| 44 | GroupOperFailure = 1 |
| 45 | // GroupOperPending constant |
| 46 | GroupOperPending = 2 |
| 47 | ) |
| 48 | |
| 49 | // The group modification record to be used by the controller |
| 50 | // to create a group. This is prepared by application and passed |
| 51 | // on to the controller |
| 52 | |
| 53 | // Group structure |
| 54 | type Group struct { |
| 55 | Device string |
| 56 | Command GroupCommand `json:"-"` |
| 57 | GroupID uint32 |
| 58 | Buckets []uint32 |
| 59 | SetVlan VlanType |
| 60 | IsPonVlanPresent bool |
| 61 | State uint8 |
| 62 | ErrorReason string |
| 63 | ForceAction bool |
| 64 | } |
| 65 | |
| 66 | // CreateGroupTableUpdate creates the logical group flow table update |
| 67 | // This is used by controller for building the final outgoing |
| 68 | // structure towards the VOLTHA |
| 69 | func CreateGroupTableUpdate(g *Group) *ofp.FlowGroupTableUpdate { |
| 70 | logger.Debugw(ctx, "Group Construction", log.Fields{"Group": g}) |
| 71 | groupUpdate := &ofp.FlowGroupTableUpdate{ |
| 72 | Id: g.Device, |
| 73 | GroupMod: &ofp.OfpGroupMod{ |
| 74 | Command: ofp.OfpGroupModCommand(g.Command), |
| 75 | Type: ofp.OfpGroupType_OFPGT_ALL, |
| 76 | GroupId: g.GroupID, |
| 77 | }, |
| 78 | } |
| 79 | logger.Debugw(ctx, "Adding Receivers", log.Fields{"Num": len(g.Buckets)}) |
| 80 | |
| 81 | // Since OLT doesnt support setvlan action during update, adding setVlan action |
| 82 | // during group creation itself even when bucketlist is empty |
| 83 | if len(g.Buckets) == 0 && g.IsPonVlanPresent { |
| 84 | bucket := &ofp.OfpBucket{} |
| 85 | bucket.Weight = 0 |
| 86 | bucket.Actions = []*ofp.OfpAction{ |
| 87 | { |
| 88 | Type: ofp.OfpActionType_OFPAT_SET_FIELD, |
| 89 | Action: &ofp.OfpAction_SetField{ |
| 90 | SetField: &ofp.OfpActionSetField{ |
| 91 | Field: &ofp.OfpOxmField{ |
| 92 | Field: &ofp.OfpOxmField_OfbField{ |
| 93 | OfbField: &ofp.OfpOxmOfbField{ |
| 94 | Type: ofp.OxmOfbFieldTypes_OFPXMT_OFB_VLAN_VID, |
| 95 | Value: &ofp.OfpOxmOfbField_VlanVid{ |
| 96 | VlanVid: uint32(g.SetVlan), |
| 97 | }, |
| 98 | }, |
| 99 | }, |
| 100 | }, |
| 101 | }, |
| 102 | }, |
| 103 | }, |
| 104 | } |
| 105 | groupUpdate.GroupMod.Buckets = append(groupUpdate.GroupMod.Buckets, bucket) |
| 106 | } |
| 107 | |
| 108 | for _, pon := range g.Buckets { |
| 109 | bucket := &ofp.OfpBucket{} |
| 110 | bucket.Weight = 0 |
| 111 | bucket.Actions = []*ofp.OfpAction{ |
| 112 | { |
| 113 | Type: ofp.OfpActionType_OFPAT_OUTPUT, |
| 114 | Action: &ofp.OfpAction_Output{ |
| 115 | Output: &ofp.OfpActionOutput{ |
| 116 | Port: pon, |
| 117 | MaxLen: 65535, |
| 118 | }, |
| 119 | }, |
| 120 | }, |
| 121 | } |
| 122 | if g.IsPonVlanPresent { |
| 123 | setVlanAction := &ofp.OfpAction{ |
| 124 | |
| 125 | Type: ofp.OfpActionType_OFPAT_SET_FIELD, |
| 126 | Action: &ofp.OfpAction_SetField{ |
| 127 | SetField: &ofp.OfpActionSetField{ |
| 128 | Field: &ofp.OfpOxmField{ |
| 129 | Field: &ofp.OfpOxmField_OfbField{ |
| 130 | OfbField: &ofp.OfpOxmOfbField{ |
| 131 | Type: ofp.OxmOfbFieldTypes_OFPXMT_OFB_VLAN_VID, |
| 132 | Value: &ofp.OfpOxmOfbField_VlanVid{ |
| 133 | VlanVid: uint32(g.SetVlan), |
| 134 | }, |
| 135 | }, |
| 136 | }, |
| 137 | }, |
| 138 | }, |
| 139 | }, |
| 140 | } |
| 141 | bucket.Actions = append(bucket.Actions, setVlanAction) |
| 142 | } |
| 143 | groupUpdate.GroupMod.Buckets = append(groupUpdate.GroupMod.Buckets, bucket) |
| 144 | } |
| 145 | |
| 146 | logger.Debugw(ctx, "Group Constructed", log.Fields{"Group": groupUpdate}) |
| 147 | return groupUpdate |
| 148 | } |