| /* |
| * Copyright 2022-present Open Networking Foundation |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| |
| package of |
| |
| import ( |
| "github.com/opencord/voltha-lib-go/v7/pkg/log" |
| ofp "github.com/opencord/voltha-protos/v5/go/openflow_13" |
| // "github.com/opencord/voltha-protos/v5/go/voltha" |
| ) |
| |
| // The commands on groups avialable. Add is not expected to be used. |
| // The mod is used for both create and update. The delete is used to |
| // delete the group |
| |
| // GroupCommand type |
| type GroupCommand ofp.OfpGroupModCommand |
| |
| const ( |
| // GroupCommandAdd constant |
| GroupCommandAdd GroupCommand = 0 |
| // GroupCommandMod constant |
| GroupCommandMod GroupCommand = 1 |
| // GroupCommandDel constant |
| GroupCommandDel GroupCommand = 2 |
| ) |
| |
| const ( |
| // GroupOperSuccess constant |
| GroupOperSuccess = 0 |
| // GroupOperFailure constant |
| GroupOperFailure = 1 |
| // GroupOperPending constant |
| GroupOperPending = 2 |
| ) |
| |
| // The group modification record to be used by the controller |
| // to create a group. This is prepared by application and passed |
| // on to the controller |
| |
| // Group structure |
| type Group struct { |
| Device string |
| Command GroupCommand `json:"-"` |
| GroupID uint32 |
| Buckets []uint32 |
| SetVlan VlanType |
| IsPonVlanPresent bool |
| State uint8 |
| ErrorReason string |
| ForceAction bool |
| } |
| |
| // CreateGroupTableUpdate creates the logical group flow table update |
| // This is used by controller for building the final outgoing |
| // structure towards the VOLTHA |
| func CreateGroupTableUpdate(g *Group) *ofp.FlowGroupTableUpdate { |
| logger.Debugw(ctx, "Group Construction", log.Fields{"Group": g}) |
| groupUpdate := &ofp.FlowGroupTableUpdate{ |
| Id: g.Device, |
| GroupMod: &ofp.OfpGroupMod{ |
| Command: ofp.OfpGroupModCommand(g.Command), |
| Type: ofp.OfpGroupType_OFPGT_ALL, |
| GroupId: g.GroupID, |
| }, |
| } |
| logger.Debugw(ctx, "Adding Receivers", log.Fields{"Num": len(g.Buckets)}) |
| |
| // Since OLT doesnt support setvlan action during update, adding setVlan action |
| // during group creation itself even when bucketlist is empty |
| if len(g.Buckets) == 0 && g.IsPonVlanPresent { |
| bucket := &ofp.OfpBucket{} |
| bucket.Weight = 0 |
| bucket.Actions = []*ofp.OfpAction{ |
| { |
| Type: ofp.OfpActionType_OFPAT_SET_FIELD, |
| Action: &ofp.OfpAction_SetField{ |
| SetField: &ofp.OfpActionSetField{ |
| Field: &ofp.OfpOxmField{ |
| Field: &ofp.OfpOxmField_OfbField{ |
| OfbField: &ofp.OfpOxmOfbField{ |
| Type: ofp.OxmOfbFieldTypes_OFPXMT_OFB_VLAN_VID, |
| Value: &ofp.OfpOxmOfbField_VlanVid{ |
| VlanVid: uint32(g.SetVlan), |
| }, |
| }, |
| }, |
| }, |
| }, |
| }, |
| }, |
| } |
| groupUpdate.GroupMod.Buckets = append(groupUpdate.GroupMod.Buckets, bucket) |
| } |
| |
| for _, pon := range g.Buckets { |
| bucket := &ofp.OfpBucket{} |
| bucket.Weight = 0 |
| bucket.Actions = []*ofp.OfpAction{ |
| { |
| Type: ofp.OfpActionType_OFPAT_OUTPUT, |
| Action: &ofp.OfpAction_Output{ |
| Output: &ofp.OfpActionOutput{ |
| Port: pon, |
| MaxLen: 65535, |
| }, |
| }, |
| }, |
| } |
| if g.IsPonVlanPresent { |
| setVlanAction := &ofp.OfpAction{ |
| |
| Type: ofp.OfpActionType_OFPAT_SET_FIELD, |
| Action: &ofp.OfpAction_SetField{ |
| SetField: &ofp.OfpActionSetField{ |
| Field: &ofp.OfpOxmField{ |
| Field: &ofp.OfpOxmField_OfbField{ |
| OfbField: &ofp.OfpOxmOfbField{ |
| Type: ofp.OxmOfbFieldTypes_OFPXMT_OFB_VLAN_VID, |
| Value: &ofp.OfpOxmOfbField_VlanVid{ |
| VlanVid: uint32(g.SetVlan), |
| }, |
| }, |
| }, |
| }, |
| }, |
| }, |
| } |
| bucket.Actions = append(bucket.Actions, setVlanAction) |
| } |
| groupUpdate.GroupMod.Buckets = append(groupUpdate.GroupMod.Buckets, bucket) |
| } |
| |
| logger.Debugw(ctx, "Group Constructed", log.Fields{"Group": groupUpdate}) |
| return groupUpdate |
| } |