blob: bd841f534405058fdd8be81ce6fbe4beebfeb574 [file] [log] [blame]
Jonathan Hart44bdbfc2020-04-14 17:45:47 -07001/*
2 * Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior University
3 * Copyright (c) 2011, 2012 Open Networking Foundation
4 * Copyright 2013, Big Switch Networks, Inc. This library was generated by the LoxiGen Compiler.
5 * Copyright 2018, Red Hat, Inc.
6 */
7// Automatically generated by LOXI from template module.go
8// Do not modify
9
10package of11
11
12import (
13 "bytes"
14 "encoding/binary"
15 "fmt"
16
17 "github.com/opencord/goloxi"
18)
19
20type Instruction struct {
21 Type uint16
22 Len uint16
23}
24
25type IInstruction interface {
26 goloxi.Serializable
27 GetType() uint16
28 GetLen() uint16
29}
30
31func (self *Instruction) GetType() uint16 {
32 return self.Type
33}
34
35func (self *Instruction) SetType(v uint16) {
36 self.Type = v
37}
38
39func (self *Instruction) GetLen() uint16 {
40 return self.Len
41}
42
43func (self *Instruction) SetLen(v uint16) {
44 self.Len = v
45}
46
47func (self *Instruction) Serialize(encoder *goloxi.Encoder) error {
48
49 encoder.PutUint16(uint16(self.Type))
50 encoder.PutUint16(uint16(self.Len))
51
52 return nil
53}
54
55func DecodeInstruction(decoder *goloxi.Decoder) (IInstruction, error) {
56 _instruction := &Instruction{}
57 if decoder.Length() < 4 {
58 return nil, fmt.Errorf("Instruction packet too short: %d < 4", decoder.Length())
59 }
60 _instruction.Type = uint16(decoder.ReadUint16())
61 _instruction.Len = uint16(decoder.ReadUint16())
62 oldDecoder := decoder
63 defer func() { decoder = oldDecoder }()
64 decoder = decoder.SliceDecoder(int(_instruction.Len), 2+2)
65
66 switch _instruction.Type {
67 case 1:
68 return DecodeInstructionGotoTable(_instruction, decoder)
69 case 2:
70 return DecodeInstructionWriteMetadata(_instruction, decoder)
71 case 3:
72 return DecodeInstructionWriteActions(_instruction, decoder)
73 case 4:
74 return DecodeInstructionApplyActions(_instruction, decoder)
75 case 5:
76 return DecodeInstructionClearActions(_instruction, decoder)
77 case 65535:
78 return DecodeInstructionExperimenter(_instruction, decoder)
79 default:
80 return nil, fmt.Errorf("Invalid type '%d' for 'Instruction'", _instruction.Type)
81 }
82}
83
84func NewInstruction(_type uint16) *Instruction {
85 obj := &Instruction{}
86 obj.Type = _type
87 return obj
88}
89
90type InstructionApplyActions struct {
91 *Instruction
92 Actions []goloxi.IAction
93}
94
95type IInstructionApplyActions interface {
96 IInstruction
97 GetActions() []goloxi.IAction
98}
99
100func (self *InstructionApplyActions) GetActions() []goloxi.IAction {
101 return self.Actions
102}
103
104func (self *InstructionApplyActions) SetActions(v []goloxi.IAction) {
105 self.Actions = v
106}
107
108func (self *InstructionApplyActions) Serialize(encoder *goloxi.Encoder) error {
109 startIndex := len(encoder.Bytes())
110 if err := self.Instruction.Serialize(encoder); err != nil {
111 return err
112 }
113
114 encoder.Write(bytes.Repeat([]byte{0}, 4))
115 for _, obj := range self.Actions {
116 if err := obj.Serialize(encoder); err != nil {
117 return err
118 }
119 }
120 length := len(encoder.Bytes()) - startIndex
121
122 binary.BigEndian.PutUint16(encoder.Bytes()[startIndex+2:startIndex+4], uint16(length))
123
124 return nil
125}
126
127func DecodeInstructionApplyActions(parent *Instruction, decoder *goloxi.Decoder) (*InstructionApplyActions, error) {
128 _instructionapplyactions := &InstructionApplyActions{Instruction: parent}
129 if decoder.Length() < 4 {
130 return nil, fmt.Errorf("InstructionApplyActions packet too short: %d < 4", decoder.Length())
131 }
132 decoder.Skip(4)
133
134 for decoder.Length() >= 8 {
135 item, err := DecodeAction(decoder)
136 if err != nil {
137 return nil, err
138 }
139 if item != nil {
140 _instructionapplyactions.Actions = append(_instructionapplyactions.Actions, item)
141 }
142 }
143 return _instructionapplyactions, nil
144}
145
146func NewInstructionApplyActions() *InstructionApplyActions {
147 obj := &InstructionApplyActions{
148 Instruction: NewInstruction(4),
149 }
150 return obj
151}
152
153type InstructionClearActions struct {
154 *Instruction
155}
156
157type IInstructionClearActions interface {
158 IInstruction
159}
160
161func (self *InstructionClearActions) Serialize(encoder *goloxi.Encoder) error {
162 startIndex := len(encoder.Bytes())
163 if err := self.Instruction.Serialize(encoder); err != nil {
164 return err
165 }
166
167 encoder.Write(bytes.Repeat([]byte{0}, 4))
168 length := len(encoder.Bytes()) - startIndex
169
170 binary.BigEndian.PutUint16(encoder.Bytes()[startIndex+2:startIndex+4], uint16(length))
171
172 return nil
173}
174
175func DecodeInstructionClearActions(parent *Instruction, decoder *goloxi.Decoder) (*InstructionClearActions, error) {
176 _instructionclearactions := &InstructionClearActions{Instruction: parent}
177 if decoder.Length() < 4 {
178 return nil, fmt.Errorf("InstructionClearActions packet too short: %d < 4", decoder.Length())
179 }
180 decoder.Skip(4)
181 return _instructionclearactions, nil
182}
183
184func NewInstructionClearActions() *InstructionClearActions {
185 obj := &InstructionClearActions{
186 Instruction: NewInstruction(5),
187 }
188 return obj
189}
190
191type InstructionExperimenter struct {
192 *Instruction
193 Experimenter uint32
194}
195
196type IInstructionExperimenter interface {
197 IInstruction
198 GetExperimenter() uint32
199}
200
201func (self *InstructionExperimenter) GetExperimenter() uint32 {
202 return self.Experimenter
203}
204
205func (self *InstructionExperimenter) SetExperimenter(v uint32) {
206 self.Experimenter = v
207}
208
209func (self *InstructionExperimenter) Serialize(encoder *goloxi.Encoder) error {
210 if err := self.Instruction.Serialize(encoder); err != nil {
211 return err
212 }
213
214 encoder.PutUint32(uint32(self.Experimenter))
215
216 return nil
217}
218
219func DecodeInstructionExperimenter(parent *Instruction, decoder *goloxi.Decoder) (IInstructionExperimenter, error) {
220 _instructionexperimenter := &InstructionExperimenter{Instruction: parent}
221 if decoder.Length() < 4 {
222 return nil, fmt.Errorf("InstructionExperimenter packet too short: %d < 4", decoder.Length())
223 }
224 _instructionexperimenter.Experimenter = uint32(decoder.ReadUint32())
225 return _instructionexperimenter, nil
226}
227
228func NewInstructionExperimenter(_experimenter uint32) *InstructionExperimenter {
229 obj := &InstructionExperimenter{
230 Instruction: NewInstruction(65535),
231 }
232 obj.Experimenter = _experimenter
233 return obj
234}
235
236type InstructionGotoTable struct {
237 *Instruction
238 TableId uint8
239}
240
241type IInstructionGotoTable interface {
242 IInstruction
243 GetTableId() uint8
244}
245
246func (self *InstructionGotoTable) GetTableId() uint8 {
247 return self.TableId
248}
249
250func (self *InstructionGotoTable) SetTableId(v uint8) {
251 self.TableId = v
252}
253
254func (self *InstructionGotoTable) Serialize(encoder *goloxi.Encoder) error {
255 startIndex := len(encoder.Bytes())
256 if err := self.Instruction.Serialize(encoder); err != nil {
257 return err
258 }
259
260 encoder.PutUint8(uint8(self.TableId))
261 encoder.Write(bytes.Repeat([]byte{0}, 3))
262 length := len(encoder.Bytes()) - startIndex
263
264 binary.BigEndian.PutUint16(encoder.Bytes()[startIndex+2:startIndex+4], uint16(length))
265
266 return nil
267}
268
269func DecodeInstructionGotoTable(parent *Instruction, decoder *goloxi.Decoder) (*InstructionGotoTable, error) {
270 _instructiongototable := &InstructionGotoTable{Instruction: parent}
271 if decoder.Length() < 4 {
272 return nil, fmt.Errorf("InstructionGotoTable packet too short: %d < 4", decoder.Length())
273 }
274 _instructiongototable.TableId = uint8(decoder.ReadByte())
275 decoder.Skip(3)
276 return _instructiongototable, nil
277}
278
279func NewInstructionGotoTable() *InstructionGotoTable {
280 obj := &InstructionGotoTable{
281 Instruction: NewInstruction(1),
282 }
283 return obj
284}
285
286type InstructionWriteActions struct {
287 *Instruction
288 Actions []goloxi.IAction
289}
290
291type IInstructionWriteActions interface {
292 IInstruction
293 GetActions() []goloxi.IAction
294}
295
296func (self *InstructionWriteActions) GetActions() []goloxi.IAction {
297 return self.Actions
298}
299
300func (self *InstructionWriteActions) SetActions(v []goloxi.IAction) {
301 self.Actions = v
302}
303
304func (self *InstructionWriteActions) Serialize(encoder *goloxi.Encoder) error {
305 startIndex := len(encoder.Bytes())
306 if err := self.Instruction.Serialize(encoder); err != nil {
307 return err
308 }
309
310 encoder.Write(bytes.Repeat([]byte{0}, 4))
311 for _, obj := range self.Actions {
312 if err := obj.Serialize(encoder); err != nil {
313 return err
314 }
315 }
316 length := len(encoder.Bytes()) - startIndex
317
318 binary.BigEndian.PutUint16(encoder.Bytes()[startIndex+2:startIndex+4], uint16(length))
319
320 return nil
321}
322
323func DecodeInstructionWriteActions(parent *Instruction, decoder *goloxi.Decoder) (*InstructionWriteActions, error) {
324 _instructionwriteactions := &InstructionWriteActions{Instruction: parent}
325 if decoder.Length() < 4 {
326 return nil, fmt.Errorf("InstructionWriteActions packet too short: %d < 4", decoder.Length())
327 }
328 decoder.Skip(4)
329
330 for decoder.Length() >= 8 {
331 item, err := DecodeAction(decoder)
332 if err != nil {
333 return nil, err
334 }
335 if item != nil {
336 _instructionwriteactions.Actions = append(_instructionwriteactions.Actions, item)
337 }
338 }
339 return _instructionwriteactions, nil
340}
341
342func NewInstructionWriteActions() *InstructionWriteActions {
343 obj := &InstructionWriteActions{
344 Instruction: NewInstruction(3),
345 }
346 return obj
347}
348
349type InstructionWriteMetadata struct {
350 *Instruction
351 Metadata uint64
352 MetadataMask uint64
353}
354
355type IInstructionWriteMetadata interface {
356 IInstruction
357 GetMetadata() uint64
358 GetMetadataMask() uint64
359}
360
361func (self *InstructionWriteMetadata) GetMetadata() uint64 {
362 return self.Metadata
363}
364
365func (self *InstructionWriteMetadata) SetMetadata(v uint64) {
366 self.Metadata = v
367}
368
369func (self *InstructionWriteMetadata) GetMetadataMask() uint64 {
370 return self.MetadataMask
371}
372
373func (self *InstructionWriteMetadata) SetMetadataMask(v uint64) {
374 self.MetadataMask = v
375}
376
377func (self *InstructionWriteMetadata) Serialize(encoder *goloxi.Encoder) error {
378 startIndex := len(encoder.Bytes())
379 if err := self.Instruction.Serialize(encoder); err != nil {
380 return err
381 }
382
383 encoder.Write(bytes.Repeat([]byte{0}, 4))
384 encoder.PutUint64(uint64(self.Metadata))
385 encoder.PutUint64(uint64(self.MetadataMask))
386 length := len(encoder.Bytes()) - startIndex
387
388 binary.BigEndian.PutUint16(encoder.Bytes()[startIndex+2:startIndex+4], uint16(length))
389
390 return nil
391}
392
393func DecodeInstructionWriteMetadata(parent *Instruction, decoder *goloxi.Decoder) (*InstructionWriteMetadata, error) {
394 _instructionwritemetadata := &InstructionWriteMetadata{Instruction: parent}
395 if decoder.Length() < 20 {
396 return nil, fmt.Errorf("InstructionWriteMetadata packet too short: %d < 20", decoder.Length())
397 }
398 decoder.Skip(4)
399 _instructionwritemetadata.Metadata = uint64(decoder.ReadUint64())
400 _instructionwritemetadata.MetadataMask = uint64(decoder.ReadUint64())
401 return _instructionwritemetadata, nil
402}
403
404func NewInstructionWriteMetadata() *InstructionWriteMetadata {
405 obj := &InstructionWriteMetadata{
406 Instruction: NewInstruction(2),
407 }
408 return obj
409}