blob: c56d3748a35e0b83a39424cbedf9ad529368f345 [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.
14 */
15
16package application
17
18import (
19 "context"
20 "time"
21
22 "github.com/google/gopacket"
23)
24
25// ------------------------------------------------------------------
26// ********** Tasks
27//
28// IGMP related tasks which essentially process packets and the ticks
29// This is to serailize access to data structures and this also limits
30// the amount of CPU consumed. We can bring more capacity by running
31// more groups in parallel as we need to add parallelism
32
33// -----------------------------------------------------------------
34// ** Timer Task **
35//
36// Timer processing - Tick is a poke that the IGMP processing receives
37// from the timer thread. The entire IGMP processing receives a single
38// tick.
39
40// TickTask structure
41type TickTask struct {
42 ctx context.Context
Naveen Sampath04696f72022-06-13 15:19:14 +053043 ts string
vinokuma926cb3e2023-03-29 11:41:06 +053044 taskID uint8
Naveen Sampath04696f72022-06-13 15:19:14 +053045}
46
47// NewTickTask is constructor for TickTask
48func NewTickTask() *TickTask {
49 return &TickTask{}
50}
51
52// Name to return the name of the task
53func (tt *TickTask) Name() string {
54 return "Process Tick"
55}
56
57// TaskID to return the task id
58func (tt *TickTask) TaskID() uint8 {
59 return tt.taskID
60}
61
62// Timestamp to return the timestamp of task
63func (tt *TickTask) Timestamp() string {
64 return tt.ts
65}
66
67// Stop to stop the task
68func (tt *TickTask) Stop() {
69}
70
71// Start to start the task
72func (tt *TickTask) Start(ctx context.Context, taskID uint8) error {
73 tt.taskID = taskID
74 tt.ctx = ctx
Tinoj Joseph07cc5372022-07-18 22:53:51 +053075 GetApplication().IgmpTick(ctx)
Naveen Sampath04696f72022-06-13 15:19:14 +053076 return nil
77}
78
79// ---------------------------------------------------------------
80// ** Packet processing Task **
81//
82//
83
84// IgmpPacketTask structure
85type IgmpPacketTask struct {
86 ctx context.Context
vinokuma926cb3e2023-03-29 11:41:06 +053087 Pkt gopacket.Packet
Naveen Sampath04696f72022-06-13 15:19:14 +053088 Device string
89 Port string
Naveen Sampath04696f72022-06-13 15:19:14 +053090 ts string
vinokuma926cb3e2023-03-29 11:41:06 +053091 taskID uint8
Naveen Sampath04696f72022-06-13 15:19:14 +053092}
93
94// NewIgmpPacketTask is the constructor for IgmpPacketTask
95func NewIgmpPacketTask(device string, port string, pkt gopacket.Packet) *IgmpPacketTask {
96 var pt IgmpPacketTask
97 pt.Device = device
98 pt.Port = port
99 pt.Pkt = pkt
100 pt.ts = (time.Now()).Format(time.RFC3339Nano)
101 return &pt
102}
103
104// Name to return name of the task
105func (pt *IgmpPacketTask) Name() string {
106 return "Igmp Packet Task"
107}
108
109// TaskID to return the task id
110func (pt *IgmpPacketTask) TaskID() uint8 {
111 return pt.taskID
112}
113
114// Timestamp to return the timestamp for the task
115func (pt *IgmpPacketTask) Timestamp() string {
116 return pt.ts
117}
118
119// Stop to stop the task
120func (pt *IgmpPacketTask) Stop() {
121}
122
123// Start to start the task
124func (pt *IgmpPacketTask) Start(ctx context.Context, taskID uint8) error {
125 pt.taskID = taskID
126 pt.ctx = ctx
Tinoj Joseph07cc5372022-07-18 22:53:51 +0530127 GetApplication().IgmpProcessPkt(ctx, pt.Device, pt.Port, pt.Pkt)
Naveen Sampath04696f72022-06-13 15:19:14 +0530128 return nil
129}
130
131// UpdateMvlanTask structure
132type UpdateMvlanTask struct {
133 ctx context.Context
Naveen Sampath04696f72022-06-13 15:19:14 +0530134 mvp *MvlanProfile
vinokuma926cb3e2023-03-29 11:41:06 +0530135 DeviceID string
Naveen Sampath04696f72022-06-13 15:19:14 +0530136 ts string
vinokuma926cb3e2023-03-29 11:41:06 +0530137 taskID uint8
Naveen Sampath04696f72022-06-13 15:19:14 +0530138}
139
140// NewUpdateMvlanTask is the constructor for UpdateMvlanTask
141func NewUpdateMvlanTask(mvp *MvlanProfile, deviceID string) *UpdateMvlanTask {
142 var mt UpdateMvlanTask
143 mt.mvp = mvp
144 mt.DeviceID = deviceID
145 mt.ts = (time.Now()).Format(time.RFC3339Nano)
146 return &mt
147}
148
149// Name to retun the name of the task
150func (mt *UpdateMvlanTask) Name() string {
151 return "Update Mvlan Task"
152}
153
154// TaskID to return the task id of the task
155func (mt *UpdateMvlanTask) TaskID() uint8 {
156 return mt.taskID
157}
158
159// Timestamp to return the timestamp of the task
160func (mt *UpdateMvlanTask) Timestamp() string {
161 return mt.ts
162}
163
164// Stop to stop the task
165func (mt *UpdateMvlanTask) Stop() {
166}
167
168// Start to start the task
169func (mt *UpdateMvlanTask) Start(ctx context.Context, taskID uint8) error {
170 mt.taskID = taskID
171 mt.ctx = ctx
172 mvp := mt.mvp
Tinoj Joseph07cc5372022-07-18 22:53:51 +0530173 mvp.UpdateProfile(ctx, mt.DeviceID)
Naveen Sampath04696f72022-06-13 15:19:14 +0530174 return nil
175}