blob: cfa9b67c53f0f7f5b357772fd5efb5abad17e587 [file] [log] [blame]
Naveen Sampath04696f72022-06-13 15:19:14 +05301/*
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.
Akash Sonib3abf522022-12-19 13:20:02 +053014 */
Naveen Sampath04696f72022-06-13 15:19:14 +053015
16package of
17
18import (
Tinoj Joseph1d108322022-07-13 10:07:39 +053019 "voltha-go-controller/log"
Akash Sonib3abf522022-12-19 13:20:02 +053020
Naveen Sampath04696f72022-06-13 15:19:14 +053021 ofp "github.com/opencord/voltha-protos/v5/go/openflow_13"
Akash Sonib3abf522022-12-19 13:20:02 +053022 // "github.com/opencord/voltha-protos/v5/go/voltha"
Naveen Sampath04696f72022-06-13 15:19:14 +053023)
24
vinokuma926cb3e2023-03-29 11:41:06 +053025// The commands on groups available. Add is not expected to be used.
Naveen Sampath04696f72022-06-13 15:19:14 +053026// The mod is used for both create and update. The delete is used to
27// delete the group
28
29// GroupCommand type
30type GroupCommand ofp.OfpGroupModCommand
31
32const (
33 // GroupCommandAdd constant
34 GroupCommandAdd GroupCommand = 0
35 // GroupCommandMod constant
36 GroupCommandMod GroupCommand = 1
37 // GroupCommandDel constant
38 GroupCommandDel GroupCommand = 2
39)
40
41const (
42 // GroupOperSuccess constant
43 GroupOperSuccess = 0
44 // GroupOperFailure constant
45 GroupOperFailure = 1
46 // GroupOperPending constant
47 GroupOperPending = 2
48)
49
50// The group modification record to be used by the controller
51// to create a group. This is prepared by application and passed
52// on to the controller
53
54// Group structure
55type Group struct {
56 Device string
Naveen Sampath04696f72022-06-13 15:19:14 +053057 ErrorReason string
vinokuma926cb3e2023-03-29 11:41:06 +053058 Buckets []uint32
59 GroupID uint32
60 SetVlan VlanType
61 Command GroupCommand `json:"-"`
62 State uint8
63 IsPonVlanPresent bool
Naveen Sampath04696f72022-06-13 15:19:14 +053064 ForceAction bool
65}
66
67// CreateGroupTableUpdate creates the logical group flow table update
68// This is used by controller for building the final outgoing
69// structure towards the VOLTHA
70func CreateGroupTableUpdate(g *Group) *ofp.FlowGroupTableUpdate {
71 logger.Debugw(ctx, "Group Construction", log.Fields{"Group": g})
72 groupUpdate := &ofp.FlowGroupTableUpdate{
73 Id: g.Device,
74 GroupMod: &ofp.OfpGroupMod{
75 Command: ofp.OfpGroupModCommand(g.Command),
76 Type: ofp.OfpGroupType_OFPGT_ALL,
77 GroupId: g.GroupID,
78 },
79 }
80 logger.Debugw(ctx, "Adding Receivers", log.Fields{"Num": len(g.Buckets)})
81
82 // Since OLT doesnt support setvlan action during update, adding setVlan action
83 // during group creation itself even when bucketlist is empty
84 if len(g.Buckets) == 0 && g.IsPonVlanPresent {
85 bucket := &ofp.OfpBucket{}
86 bucket.Weight = 0
87 bucket.Actions = []*ofp.OfpAction{
88 {
89 Type: ofp.OfpActionType_OFPAT_SET_FIELD,
90 Action: &ofp.OfpAction_SetField{
91 SetField: &ofp.OfpActionSetField{
92 Field: &ofp.OfpOxmField{
93 Field: &ofp.OfpOxmField_OfbField{
94 OfbField: &ofp.OfpOxmOfbField{
95 Type: ofp.OxmOfbFieldTypes_OFPXMT_OFB_VLAN_VID,
96 Value: &ofp.OfpOxmOfbField_VlanVid{
97 VlanVid: uint32(g.SetVlan),
98 },
99 },
100 },
101 },
102 },
103 },
104 },
105 }
106 groupUpdate.GroupMod.Buckets = append(groupUpdate.GroupMod.Buckets, bucket)
107 }
108
109 for _, pon := range g.Buckets {
110 bucket := &ofp.OfpBucket{}
111 bucket.Weight = 0
112 bucket.Actions = []*ofp.OfpAction{
113 {
114 Type: ofp.OfpActionType_OFPAT_OUTPUT,
115 Action: &ofp.OfpAction_Output{
116 Output: &ofp.OfpActionOutput{
117 Port: pon,
118 MaxLen: 65535,
119 },
120 },
121 },
122 }
123 if g.IsPonVlanPresent {
124 setVlanAction := &ofp.OfpAction{
125
126 Type: ofp.OfpActionType_OFPAT_SET_FIELD,
127 Action: &ofp.OfpAction_SetField{
128 SetField: &ofp.OfpActionSetField{
129 Field: &ofp.OfpOxmField{
130 Field: &ofp.OfpOxmField_OfbField{
131 OfbField: &ofp.OfpOxmOfbField{
132 Type: ofp.OxmOfbFieldTypes_OFPXMT_OFB_VLAN_VID,
133 Value: &ofp.OfpOxmOfbField_VlanVid{
134 VlanVid: uint32(g.SetVlan),
135 },
136 },
137 },
138 },
139 },
140 },
141 }
142 bucket.Actions = append(bucket.Actions, setVlanAction)
143 }
144 groupUpdate.GroupMod.Buckets = append(groupUpdate.GroupMod.Buckets, bucket)
145 }
146
147 logger.Debugw(ctx, "Group Constructed", log.Fields{"Group": groupUpdate})
148 return groupUpdate
149}